prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / cinelerra / vdevicev4l2jpeg.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 #include "../hvirtual_config.h"
23 #ifdef HAVE_VIDEO4LINUX2
24 #include "channel.h"
25 #include "file.h"
26 #include "libmjpeg.h"
27 #include "preferences.h"
28 #include "recordconfig.h"
29 #include "vdevicev4l2jpeg.h"
30 #include "vframe.h"
31 #include "videodevice.h"
32
33 #include <string.h>
34
35 VDeviceV4L2JPEG::VDeviceV4L2JPEG(VideoDevice *device)
36  : VDeviceBase(device), DeviceV4L2Base()
37 {
38 }
39
40 VDeviceV4L2JPEG::~VDeviceV4L2JPEG()
41 {
42         close_all();
43 }
44
45 int VDeviceV4L2JPEG::close_all()
46 {
47         close_dev();
48         return 0;
49 }
50
51 int VDeviceV4L2JPEG::open_input()
52 {
53         int result = get_sources();
54         return result;
55 }
56
57 int VDeviceV4L2JPEG::get_best_colormodel(Asset *asset)
58 {
59         return BC_COMPRESSED;
60 }
61
62 int VDeviceV4L2JPEG::has_signal()
63 {
64         return !status_dev() ? dev_signal() : 0;
65 }
66
67 int VDeviceV4L2JPEG::read_buffer(VFrame *frame)
68 {
69         int result = 0;
70
71         if(is_opened())
72         {
73                 if(device->channel_changed || device->picture_changed)
74                         close_dev();
75         }
76
77         if(!is_opened())
78         {
79                 result = open_dev(frame->get_color_model());
80                 if( !result )
81                 {
82                         device->channel_changed = 0;
83                         device->picture_changed = 0;
84                 }
85         }
86
87 // Get buffer from thread
88         if( !result )
89         {
90                 int bfr = get_buffer();
91                 if(bfr >= 0)
92                 {
93                         VFrame *buffer = device_buffer(bfr);
94                         frame->set_timestamp(buffer->get_timestamp());
95                         frame->allocate_compressed_data(buffer->get_compressed_size());
96                         frame->set_compressed_size(buffer->get_compressed_size());
97         
98 // Transfer fields to frame
99                         if(device->odd_field_first)
100                         {
101                                 int field2_offset = mjpeg_get_field2((unsigned char*)buffer->get_data(), 
102                                         buffer->get_compressed_size());
103                                 int field1_len = field2_offset;
104                                 int field2_len = buffer->get_compressed_size() - 
105                                         field2_offset;
106
107                                 memcpy(frame->get_data(), 
108                                         buffer->get_data() + field2_offset, 
109                                         field2_len);
110                                 memcpy(frame->get_data() + field2_len, 
111                                         buffer->get_data(), 
112                                         field1_len);
113                         }
114                         else
115                         {
116                                 bcopy(buffer->get_data(), 
117                                         frame->get_data(), 
118                                         buffer->get_compressed_size());
119                         }
120
121                         put_buffer(bfr);
122                 }
123                 else
124                         result = 1;
125         }
126
127         if( result )
128                 close_dev();
129
130         return result;
131 }
132
133 #endif