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