4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #ifdef HAVE_VIDEO4LINUX2
26 #include "preferences.h"
27 #include "recordconfig.h"
28 #include "vdevicev4l2jpeg.h"
30 #include "videodevice.h"
34 VDeviceV4L2JPEG::VDeviceV4L2JPEG(VideoDevice *device)
35 : VDeviceBase(device), DeviceV4L2Base()
39 VDeviceV4L2JPEG::~VDeviceV4L2JPEG()
44 int VDeviceV4L2JPEG::close_all()
50 int VDeviceV4L2JPEG::open_input()
52 int result = get_sources();
56 int VDeviceV4L2JPEG::get_best_colormodel(Asset *asset)
61 int VDeviceV4L2JPEG::has_signal()
63 return !status_dev() ? dev_signal() : 0;
66 int VDeviceV4L2JPEG::read_buffer(VFrame *frame)
72 if(device->channel_changed || device->picture_changed)
78 result = open_dev(frame->get_color_model());
81 device->channel_changed = 0;
82 device->picture_changed = 0;
86 // Get buffer from thread
89 int bfr = get_buffer();
92 VFrame *buffer = device_buffer(bfr);
93 frame->set_timestamp(buffer->get_timestamp());
94 frame->allocate_compressed_data(buffer->get_compressed_size());
95 frame->set_compressed_size(buffer->get_compressed_size());
97 // Transfer fields to frame
98 if(device->odd_field_first)
100 int field2_offset = mjpeg_get_field2((unsigned char*)buffer->get_data(),
101 buffer->get_compressed_size());
102 int field1_len = field2_offset;
103 int field2_len = buffer->get_compressed_size() -
106 memcpy(frame->get_data(),
107 buffer->get_data() + field2_offset,
109 memcpy(frame->get_data() + field2_len,
115 bcopy(buffer->get_data(),
117 buffer->get_compressed_size());