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 #include "../hvirtual_config.h"
23 #ifdef HAVE_VIDEO4LINUX2
27 #include "preferences.h"
28 #include "recordconfig.h"
29 #include "vdevicev4l2jpeg.h"
31 #include "videodevice.h"
35 VDeviceV4L2JPEG::VDeviceV4L2JPEG(VideoDevice *device)
36 : VDeviceBase(device), DeviceV4L2Base()
40 VDeviceV4L2JPEG::~VDeviceV4L2JPEG()
45 int VDeviceV4L2JPEG::close_all()
51 int VDeviceV4L2JPEG::open_input()
53 int result = get_sources();
57 int VDeviceV4L2JPEG::get_best_colormodel(Asset *asset)
62 int VDeviceV4L2JPEG::has_signal()
64 return !status_dev() ? dev_signal() : 0;
67 int VDeviceV4L2JPEG::read_buffer(VFrame *frame)
73 if(device->channel_changed || device->picture_changed)
79 result = open_dev(frame->get_color_model());
82 device->channel_changed = 0;
83 device->picture_changed = 0;
87 // Get buffer from thread
90 int bfr = get_buffer();
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());
98 // Transfer fields to frame
99 if(device->odd_field_first)
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() -
107 memcpy(frame->get_data(),
108 buffer->get_data() + field2_offset,
110 memcpy(frame->get_data() + field2_len,
116 bcopy(buffer->get_data(),
118 buffer->get_compressed_size());