Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

vdevicev4l2jpeg.C

Go to the documentation of this file.
00001 // V4L2 is incompatible with large file support
00002 #undef _FILE_OFFSET_BITS
00003 #undef _LARGEFILE_SOURCE
00004 #undef _LARGEFILE64_SOURCE
00005 
00006 
00007 #include "assets.h"
00008 #include "channel.h"
00009 #include "chantables.h"
00010 #include "clip.h"
00011 #include "condition.h"
00012 #include "file.h"
00013 #include "libmjpeg.h"
00014 #include "picture.h"
00015 #include "preferences.h"
00016 #include "quicktime.h"
00017 #include "recordconfig.h"
00018 #include "vdevicev4l2jpeg.h"
00019 #include "vdevicev4l2.h"
00020 #include "vframe.h"
00021 #include "videodevice.h"
00022 
00023 #ifdef HAVE_VIDEO4LINUX2
00024 
00025 #include <fcntl.h>
00026 #include <string.h>
00027 #include <sys/ioctl.h>
00028 #include <sys/mman.h>
00029 #include <unistd.h>
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 VDeviceV4L2JPEG::VDeviceV4L2JPEG(VideoDevice *device)
00039  : VDeviceBase(device)
00040 {
00041         initialize();
00042 }
00043 
00044 VDeviceV4L2JPEG::~VDeviceV4L2JPEG()
00045 {
00046         close_all();
00047 }
00048 
00049 int VDeviceV4L2JPEG::initialize()
00050 {
00051         thread = 0;
00052 }
00053 
00054 
00055 int VDeviceV4L2JPEG::open_input()
00056 {
00057         return VDeviceV4L2::get_sources(device,
00058                 device->in_config->v4l2jpeg_in_device);
00059 }
00060 
00061 int VDeviceV4L2JPEG::close_all()
00062 {
00063         if(thread) delete thread;
00064         thread = 0;
00065         return 0;
00066 }
00067 
00068 int VDeviceV4L2JPEG::get_best_colormodel(Asset *asset)
00069 {
00070         return BC_COMPRESSED;
00071 }
00072 
00073 int VDeviceV4L2JPEG::read_buffer(VFrame *frame)
00074 {
00075         int result = 0;
00076 
00077         if((device->channel_changed || device->picture_changed) && thread)
00078         {
00079                 delete thread;
00080                 thread = 0;
00081         }
00082 
00083         if(!thread)
00084         {
00085                 device->channel_changed = 0;
00086                 device->picture_changed = 0;
00087                 thread = new VDeviceV4L2Thread(device, BC_COMPRESSED);
00088                 thread->start();
00089         }
00090 
00091 
00092 // Get buffer from thread
00093         int timed_out;
00094         VFrame *buffer = thread->get_buffer(&timed_out);
00095 
00096 
00097 
00098         if(buffer)
00099         {
00100                 frame->allocate_compressed_data(buffer->get_compressed_size());
00101                 frame->set_compressed_size(buffer->get_compressed_size());
00102 
00103 // Transfer fields to frame
00104                 if(device->odd_field_first)
00105                 {
00106                         int field2_offset = mjpeg_get_field2((unsigned char*)buffer->get_data(), 
00107                                 buffer->get_compressed_size());
00108                         int field1_len = field2_offset;
00109                         int field2_len = buffer->get_compressed_size() - 
00110                                 field2_offset;
00111 
00112                         memcpy(frame->get_data(), 
00113                                 buffer->get_data() + field2_offset, 
00114                                 field2_len);
00115                         memcpy(frame->get_data() + field2_len, 
00116                                 buffer->get_data(), 
00117                                 field1_len);
00118                 }
00119                 else
00120                 {
00121                         bcopy(buffer->get_data(), 
00122                                 frame->get_data(), 
00123                                 buffer->get_compressed_size());
00124                 }
00125 
00126                 thread->put_buffer();
00127         }
00128         else
00129         {
00130 // Driver in 2.6.3 needs to be restarted when it loses sync.
00131                 if(timed_out)
00132                 {
00133                         delete thread;
00134                         thread = 0;
00135                 }
00136                 result = 1;
00137         }
00138 
00139 
00140         return result;
00141 }
00142 
00143 
00144 
00145 #endif
00146 
00147 

Generated on Sun Jan 8 13:39:01 2006 for Cinelerra-svn by  doxygen 1.4.4