initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / devicev4l2input.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  * 
20  */
21
22
23
24 #include "../hvirtual_config.h"
25 #include "bctimer.h"
26 #include "channel.h"
27 #include "chantables.h"
28 #include "condition.h"
29 #include "devicev4l2input.h"
30 #include "devicempeginput.h"
31 #include "picture.h"
32 #include "preferences.h"
33 #include "quicktime.h"
34 #include "recordconfig.h"
35
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <stdint.h>
39 #include <unistd.h>
40 #include <string.h>
41 #include <errno.h>
42 #include <fcntl.h>
43
44 #ifdef HAVE_VIDEO4LINUX2
45 #include <linux/videodev2.h>
46 #endif
47 #include <sys/ioctl.h>
48 #include <sys/mman.h>
49
50
51 DeviceV4L2Input::DeviceV4L2Input(const char *name, int no)
52  : DeviceV4L2Base(), DeviceMPEGInput(name, no)
53 {
54         device_channel = 0;
55         status_v4l2 = new DeviceV4L2Status(this);
56         status_v4l2->start();
57 }
58
59 DeviceMPEGInput *DeviceV4L2Input::
60 NewV4L2Input(const char *name, int no)
61 {
62         return (DeviceMPEGInput *) new DeviceV4L2Input(name, no);
63 }
64
65 DeviceV4L2Input::~DeviceV4L2Input()
66 {
67         delete status_v4l2;
68 }
69
70 DeviceMPEGInput* DeviceV4L2Input::get_mpeg_input(VideoDevice *device)
71 {
72         DeviceMPEGInput *mpeg_device = get_mpeg_video(device, NewV4L2Input, "video", 0);
73         if( mpeg_device )
74         {
75                 device->channel->use_norm = 1;
76                 device->channel->use_input = 1;
77                 mpeg_device->set_device_number(0);
78                 Channel *channel = device->new_input_source((char*)"video0");
79                 channel->device_index = 0;
80                 channel->tuner = 0;
81         }
82         return mpeg_device;
83 }
84
85
86 DeviceMPEGInput* DeviceV4L2Input::get_mpeg_input(AudioDevice *device)
87 {
88         DeviceMPEGInput *mpeg_device = get_mpeg_audio(device, NewV4L2Input, "video", 0);
89         return mpeg_device;
90 }
91
92 int DeviceV4L2Input::mpeg_fd()
93 {
94         return v4l2_fd();
95 }
96
97 int DeviceV4L2Input::open_dev(int color_model)
98 {
99         return DeviceV4L2Base::open_dev(color_model);
100 }
101
102 void DeviceV4L2Input::close_dev()
103 {
104         DeviceV4L2Base::close_dev();
105 }
106
107 int DeviceV4L2Input::status_dev()
108 {
109         return DeviceV4L2Base::status_dev();
110 }
111
112 int DeviceV4L2Input::start_dev()
113 {
114         return 0;
115 }
116
117 int DeviceV4L2Input::stop_dev()
118 {
119         return 0;
120 }
121
122 VideoDevice *DeviceV4L2Input::v4l2_device()
123 {
124         return video_device;
125 }
126
127
128 DeviceV4L2Status::DeviceV4L2Status(DeviceV4L2Input *in_v4l2)
129  : Thread(1, 0, 0)
130 {
131         this->in_v4l2 = in_v4l2;
132 }
133
134 DeviceV4L2Status::~DeviceV4L2Status()
135 {
136         done = 1;
137         Thread::cancel();
138         Thread::join();
139 }
140
141 void DeviceV4L2Status::run()
142 {
143         done = 0;
144         Thread::enable_cancel();
145         while( !done )
146         {
147                 Thread::disable_cancel();
148                 in_v4l2->status_dev();
149                 Thread::enable_cancel();
150                 sleep(3);
151         }
152 }
153  
154