prevent popup deactivation while button_down
[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 "recordconfig.h"
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <stdint.h>
38 #include <unistd.h>
39 #include <string.h>
40 #include <errno.h>
41 #include <fcntl.h>
42
43 #ifdef HAVE_VIDEO4LINUX2
44 #include <linux/videodev2.h>
45 #endif
46 #include <sys/ioctl.h>
47 #include <sys/mman.h>
48
49
50 DeviceV4L2Input::DeviceV4L2Input(const char *name, int no)
51  : DeviceV4L2Base(), DeviceMPEGInput(name, no)
52 {
53         device_channel = 0;
54         status_v4l2 = new DeviceV4L2Status(this);
55         status_v4l2->start();
56 }
57
58 DeviceMPEGInput *DeviceV4L2Input::
59 NewV4L2Input(const char *name, int no)
60 {
61         return (DeviceMPEGInput *) new DeviceV4L2Input(name, no);
62 }
63
64 DeviceV4L2Input::~DeviceV4L2Input()
65 {
66         delete status_v4l2;
67 }
68
69 DeviceMPEGInput* DeviceV4L2Input::get_mpeg_input(VideoDevice *device)
70 {
71         DeviceMPEGInput *mpeg_device = get_mpeg_video(device, NewV4L2Input, "video", 0);
72         if( mpeg_device )
73         {
74                 device->channel->use_norm = 1;
75                 device->channel->use_input = 1;
76                 mpeg_device->set_device_number(0);
77                 Channel *channel = device->new_input_source((char*)"video0");
78                 channel->device_index = 0;
79                 channel->tuner = 0;
80         }
81         return mpeg_device;
82 }
83
84
85 DeviceMPEGInput* DeviceV4L2Input::get_mpeg_input(AudioDevice *device)
86 {
87         DeviceMPEGInput *mpeg_device = get_mpeg_audio(device, NewV4L2Input, "video", 0);
88         return mpeg_device;
89 }
90
91 int DeviceV4L2Input::mpeg_fd()
92 {
93         return v4l2_fd();
94 }
95
96 int DeviceV4L2Input::open_dev(int color_model)
97 {
98         return DeviceV4L2Base::open_dev(color_model);
99 }
100
101 void DeviceV4L2Input::close_dev()
102 {
103         DeviceV4L2Base::close_dev();
104 }
105
106 int DeviceV4L2Input::status_dev()
107 {
108         return DeviceV4L2Base::status_dev();
109 }
110
111 int DeviceV4L2Input::start_dev()
112 {
113         return 0;
114 }
115
116 int DeviceV4L2Input::stop_dev()
117 {
118         return 0;
119 }
120
121 VideoDevice *DeviceV4L2Input::v4l2_device()
122 {
123         return video_device;
124 }
125
126
127 DeviceV4L2Status::DeviceV4L2Status(DeviceV4L2Input *in_v4l2)
128  : Thread(1, 0, 0)
129 {
130         this->in_v4l2 = in_v4l2;
131 }
132
133 DeviceV4L2Status::~DeviceV4L2Status()
134 {
135         done = 1;
136         Thread::cancel();
137         Thread::join();
138 }
139
140 void DeviceV4L2Status::run()
141 {
142         done = 0;
143         Thread::enable_cancel();
144         while( !done )
145         {
146                 Thread::disable_cancel();
147                 in_v4l2->status_dev();
148                 Thread::enable_cancel();
149                 sleep(3);
150         }
151 }
152  
153