Ticket #949: remove-support-v4l-buzz-3.diff

File remove-support-v4l-buzz-3.diff, 45.2 KB (added by feranick, 13 months ago)
  • cinelerra/channelpicker.C

    diff -Nru cinelerra.orig//cinelerra/channelpicker.C cinelerra/cinelerra/channelpicker.C
    old new  
    3939#include "recordgui.h" 
    4040#include "recordmonitor.h" 
    4141#include "theme.h" 
    42 #include "vdevicebuz.h" 
     42//#include "vdevicebuz.h" 
    4343#include "vdeviceprefs.h" 
    4444#include "videodevice.h" 
    4545 
     
    280280//      printf("PrefsChannelPicker::PrefsChannelPicker 1\n"); 
    281281        this->mwindow = mwindow; 
    282282        this->prefs = prefs; 
    283         VDeviceBUZ::get_inputs(&input_sources); 
     283//      VDeviceBUZ::get_inputs(&input_sources); 
    284284} 
    285285 
    286286PrefsChannelPicker::~PrefsChannelPicker() 
  • cinelerra/Makefile.am

    diff -Nru cinelerra.orig//cinelerra/Makefile.am cinelerra/cinelerra/Makefile.am
    old new  
    305305                    vattachmentpoint.C \ 
    306306                    vautomation.C \ 
    307307                    vdevicebase.C \ 
    308                     vdevicebuz.C \ 
    309308                    vdevicedvb.C \ 
    310309                    vdeviceprefs.C \ 
    311                     vdevicev4l.C \ 
    312310                    vdevicev4l2.C \ 
    313311                    vdevicev4l2jpeg.C \ 
    314312                    vdevicex11.C \ 
     
    630628                 vautomation.h \ 
    631629                 vdevice1394.h \ 
    632630                 vdevicebase.h \ 
    633                  vdevicebuz.h \ 
    634631                 vdevicedvb.h \ 
    635632                 vdevicelml.h \ 
    636633                 vdeviceprefs.h \ 
    637                  vdevicev4l.h \ 
    638634                 vdevicev4l2.h \ 
    639635                 vdevicev4l2jpeg.h \ 
    640636                 vdevicex11.h \ 
  • cinelerra/reversemake

    diff -Nru cinelerra.orig//cinelerra/reversemake cinelerra/cinelerra/reversemake
    old new  
    3232make $OBJDIR/vedits.o 
    3333make $OBJDIR/vedit.o 
    3434make $OBJDIR/vdevicex11.o 
    35 make $OBJDIR/vdevicev4l.o 
    3635make $OBJDIR/vdeviceprefs.o 
    3736make $OBJDIR/vdevicelml.o 
    38 make $OBJDIR/vdevicebuz.o 
    3937make $OBJDIR/vdevicebase.o 
    4038make $OBJDIR/vdevice1394.o 
    4139make $OBJDIR/vautomation.o 
  • cinelerra/vdevicebuz.C

    diff -Nru cinelerra.orig//cinelerra/vdevicebuz.C cinelerra/cinelerra/vdevicebuz.C
    old new  
    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 // ALPHA C++ can't compile 64 bit headers 
    23 #undef _LARGEFILE_SOURCE 
    24 #undef _LARGEFILE64_SOURCE 
    25 #undef _FILE_OFFSET_BITS 
    26  
    27 #include "assets.h" 
    28 #include "bcsignals.h" 
    29 #include "channel.h" 
    30 #include "chantables.h" 
    31 #include "condition.h" 
    32 #include "file.inc" 
    33 #include "mutex.h" 
    34 #include "picture.h" 
    35 #include "playbackconfig.h" 
    36 #include "preferences.h" 
    37 #include "recordconfig.h" 
    38 #include "strategies.inc" 
    39 #include "vdevicebuz.h" 
    40 #include "vframe.h" 
    41 #include "videoconfig.h" 
    42 #include "videodevice.h" 
    43  
    44 #include <errno.h> 
    45 #include <stdint.h> 
    46 #include <linux/kernel.h> 
    47 //#include <linux/videodev2.h> 
    48 #include <linux/videodev.h> 
    49 #include <fcntl.h> 
    50 #include <sys/ioctl.h> 
    51 #include <sys/mman.h> 
    52 #include <unistd.h> 
    53  
    54  
    55  
    56 #define READ_TIMEOUT 5000000 
    57  
    58  
    59 VDeviceBUZInput::VDeviceBUZInput(VDeviceBUZ *device) 
    60  : Thread(1, 1, 0) 
    61 { 
    62         this->device = device; 
    63         buffer = 0; 
    64         buffer_size = 0; 
    65         total_buffers = 0; 
    66         current_inbuffer = 0; 
    67         current_outbuffer = 0; 
    68         done = 0; 
    69         output_lock = new Condition(0, "VDeviceBUZInput::output_lock"); 
    70         buffer_lock = new Mutex("VDeviceBUZInput::buffer_lock"); 
    71 } 
    72  
    73 VDeviceBUZInput::~VDeviceBUZInput() 
    74 { 
    75         if(Thread::running()) 
    76         { 
    77                 done = 1; 
    78                 Thread::cancel(); 
    79                 Thread::join(); 
    80         } 
    81  
    82         if(buffer) 
    83         { 
    84                 for(int i = 0; i < total_buffers; i++) 
    85                 { 
    86                         delete [] buffer[i]; 
    87                 } 
    88                 delete [] buffer; 
    89                 delete [] buffer_size; 
    90         } 
    91         delete output_lock; 
    92         delete buffer_lock; 
    93 } 
    94  
    95 void VDeviceBUZInput::start() 
    96 { 
    97 // Create buffers 
    98         total_buffers = device->device->in_config->capture_length; 
    99         buffer = new char*[total_buffers]; 
    100         buffer_size = new int[total_buffers]; 
    101         bzero(buffer_size, sizeof(int) * total_buffers); 
    102         for(int i = 0; i < total_buffers; i++) 
    103         { 
    104                 buffer[i] = new char[INPUT_BUFFER_SIZE]; 
    105         } 
    106  
    107         Thread::start(); 
    108 } 
    109  
    110 void VDeviceBUZInput::run() 
    111 { 
    112     struct buz_sync bsync; 
    113  
    114 // Wait for frame 
    115         while(1) 
    116         { 
    117                 Thread::enable_cancel(); 
    118                 if(ioctl(device->jvideo_fd, BUZIOC_SYNC, &bsync) < 0) 
    119                 { 
    120                         perror("VDeviceBUZInput::run BUZIOC_SYNC"); 
    121                         if(done) return; 
    122                         Thread::disable_cancel(); 
    123                 } 
    124                 else 
    125                 { 
    126                         Thread::disable_cancel(); 
    127  
    128  
    129  
    130                         int new_buffer = 0; 
    131                         buffer_lock->lock("VDeviceBUZInput::run"); 
    132 // Save only if the current buffer is free. 
    133                         if(!buffer_size[current_inbuffer]) 
    134                         { 
    135                                 new_buffer = 1; 
    136 // Copy to input buffer 
    137                                 memcpy(buffer[current_inbuffer],  
    138                                         device->input_buffer + bsync.frame * device->breq.size, 
    139                                         bsync.length); 
    140  
    141 // Advance input buffer number and decrease semaphore. 
    142                                 buffer_size[current_inbuffer] = bsync.length; 
    143                                 increment_counter(&current_inbuffer); 
    144                         } 
    145  
    146                         buffer_lock->unlock(); 
    147  
    148                         if(ioctl(device->jvideo_fd, BUZIOC_QBUF_CAPT, &bsync.frame)) 
    149                                 perror("VDeviceBUZInput::run BUZIOC_QBUF_CAPT"); 
    150  
    151                         if(new_buffer) output_lock->unlock(); 
    152                 } 
    153         } 
    154 } 
    155  
    156 void VDeviceBUZInput::get_buffer(char **ptr, int *size) 
    157 { 
    158 // Increase semaphore to wait for buffer. 
    159         int result = output_lock->timed_lock(READ_TIMEOUT, "VDeviceBUZInput::get_buffer"); 
    160  
    161  
    162 // The driver has its own timeout routine but it doesn't work because 
    163 // because the tuner lock is unlocked and relocked with no delay. 
    164 //      int result = 0; 
    165 //      output_lock->lock("VDeviceBUZInput::get_buffer"); 
    166  
    167         if(!result) 
    168         { 
    169 // Take over buffer table 
    170                 buffer_lock->lock("VDeviceBUZInput::get_buffer"); 
    171                 *ptr = buffer[current_outbuffer]; 
    172                 *size = buffer_size[current_outbuffer]; 
    173                 buffer_lock->unlock(); 
    174         } 
    175         else 
    176         { 
    177 //printf("VDeviceBUZInput::get_buffer 1\n"); 
    178                 output_lock->unlock(); 
    179         } 
    180 } 
    181  
    182 void VDeviceBUZInput::put_buffer() 
    183 { 
    184         buffer_lock->lock("VDeviceBUZInput::put_buffer"); 
    185         buffer_size[current_outbuffer] = 0; 
    186         buffer_lock->unlock(); 
    187         increment_counter(&current_outbuffer); 
    188 } 
    189  
    190 void VDeviceBUZInput::increment_counter(int *counter) 
    191 { 
    192         (*counter)++; 
    193         if(*counter >= total_buffers) *counter = 0; 
    194 } 
    195  
    196 void VDeviceBUZInput::decrement_counter(int *counter) 
    197 { 
    198         (*counter)--; 
    199         if(*counter < 0) *counter = total_buffers - 1; 
    200 } 
    201  
    202  
    203  
    204  
    205  
    206  
    207  
    208  
    209  
    210  
    211  
    212  
    213  
    214  
    215  
    216 VDeviceBUZ::VDeviceBUZ(VideoDevice *device) 
    217  : VDeviceBase(device) 
    218 { 
    219         reset_parameters(); 
    220         render_strategies.append(VRENDER_MJPG); 
    221         tuner_lock = new Mutex("VDeviceBUZ::tuner_lock"); 
    222 } 
    223  
    224 VDeviceBUZ::~VDeviceBUZ() 
    225 { 
    226         close_all(); 
    227         delete tuner_lock; 
    228 } 
    229  
    230 int VDeviceBUZ::reset_parameters() 
    231 { 
    232         jvideo_fd = 0; 
    233         input_buffer = 0; 
    234         output_buffer = 0; 
    235         frame_buffer = 0; 
    236         frame_size = 0; 
    237         frame_allocated = 0; 
    238         input_error = 0; 
    239         last_frame_no = 0; 
    240         temp_frame = 0; 
    241         user_frame = 0; 
    242         mjpeg = 0; 
    243         total_loops = 0; 
    244         output_number = 0; 
    245         input_thread = 0; 
    246         brightness = 32768; 
    247         hue = 32768; 
    248         color = 32768; 
    249         contrast = 32768; 
    250         whiteness = 32768; 
    251 } 
    252  
    253 int VDeviceBUZ::close_input_core() 
    254 { 
    255         if(input_thread) 
    256         { 
    257                 delete input_thread; 
    258                 input_thread = 0; 
    259         } 
    260  
    261  
    262         if(device->r) 
    263         { 
    264                 if(jvideo_fd) close(jvideo_fd); 
    265                 jvideo_fd = 0; 
    266         } 
    267  
    268         if(input_buffer) 
    269         { 
    270                 if(input_buffer > 0) 
    271                         munmap(input_buffer, breq.count * breq.size); 
    272                 input_buffer = 0; 
    273         } 
    274 } 
    275  
    276 int VDeviceBUZ::close_output_core() 
    277 { 
    278 //printf("VDeviceBUZ::close_output_core 1\n"); 
    279         if(device->w) 
    280         { 
    281                 int n = -1; 
    282 //              if(ioctl(jvideo_fd, BUZIOC_QBUF_PLAY, &n) < 0) 
    283 //                      perror("VDeviceBUZ::close_output_core BUZIOC_QBUF_PLAY"); 
    284                 if(jvideo_fd) close(jvideo_fd); 
    285                 jvideo_fd = 0; 
    286         } 
    287         if(output_buffer) 
    288         { 
    289                 if(output_buffer > 0) 
    290                         munmap(output_buffer, breq.count * breq.size); 
    291                 output_buffer = 0; 
    292         } 
    293         if(temp_frame) 
    294         { 
    295                 delete temp_frame; 
    296                 temp_frame = 0; 
    297         } 
    298         if(mjpeg) 
    299         { 
    300                 mjpeg_delete(mjpeg); 
    301                 mjpeg = 0; 
    302         } 
    303         if(user_frame) 
    304         { 
    305                 delete user_frame; 
    306                 user_frame = 0; 
    307         } 
    308 //printf("VDeviceBUZ::close_output_core 2\n"); 
    309         return 0; 
    310 } 
    311  
    312  
    313 int VDeviceBUZ::close_all() 
    314 { 
    315 //printf("VDeviceBUZ::close_all 1\n"); 
    316         close_input_core(); 
    317 //printf("VDeviceBUZ::close_all 1\n"); 
    318         close_output_core(); 
    319 //printf("VDeviceBUZ::close_all 1\n"); 
    320         if(frame_buffer) delete frame_buffer; 
    321 //printf("VDeviceBUZ::close_all 1\n"); 
    322         reset_parameters(); 
    323 //printf("VDeviceBUZ::close_all 2\n"); 
    324         return 0; 
    325 } 
    326  
    327 #define COMPOSITE_TEXT "Composite" 
    328 #define SVIDEO_TEXT "S-Video" 
    329 #define BUZ_COMPOSITE 0 
    330 #define BUZ_SVIDEO 1 
    331  
    332 void VDeviceBUZ::get_inputs(ArrayList<Channel*> *input_sources) 
    333 { 
    334         Channel *new_source = new Channel; 
    335  
    336         new_source = new Channel; 
    337         strcpy(new_source->device_name, COMPOSITE_TEXT); 
    338         input_sources->append(new_source); 
    339  
    340         new_source = new Channel; 
    341         strcpy(new_source->device_name, SVIDEO_TEXT); 
    342         input_sources->append(new_source); 
    343 } 
    344  
    345 int VDeviceBUZ::open_input() 
    346 { 
    347         device->channel->use_norm = 1; 
    348         device->channel->use_input = 1; 
    349  
    350         device->picture->use_brightness = 1; 
    351         device->picture->use_contrast = 1; 
    352         device->picture->use_color = 1; 
    353         device->picture->use_hue = 1; 
    354         device->picture->use_whiteness = 1; 
    355  
    356 // Can't open input until after the channel is set 
    357         return 0; 
    358 } 
    359  
    360 int VDeviceBUZ::open_output() 
    361 { 
    362 // Can't open output until after the channel is set 
    363         return 0; 
    364 } 
    365  
    366 int VDeviceBUZ::set_channel(Channel *channel) 
    367 { 
    368         if(!channel) return 0; 
    369  
    370         tuner_lock->lock("VDeviceBUZ::set_channel"); 
    371  
    372         if(device->r) 
    373         { 
    374                 close_input_core(); 
    375                 open_input_core(channel); 
    376         } 
    377         else 
    378         { 
    379                 close_output_core(); 
    380                 open_output_core(channel); 
    381         } 
    382  
    383         tuner_lock->unlock(); 
    384  
    385  
    386         return 0; 
    387 } 
    388  
    389 void VDeviceBUZ::create_channeldb(ArrayList<Channel*> *channeldb) 
    390 { 
    391         ; 
    392 } 
    393  
    394 int VDeviceBUZ::set_picture(PictureConfig *picture) 
    395 { 
    396         this->brightness = (int)((float)picture->brightness / 100 * 32767 + 32768); 
    397         this->hue = (int)((float)picture->hue / 100 * 32767 + 32768); 
    398         this->color = (int)((float)picture->color / 100 * 32767 + 32768); 
    399         this->contrast = (int)((float)picture->contrast / 100 * 32767 + 32768); 
    400         this->whiteness = (int)((float)picture->whiteness / 100 * 32767 + 32768); 
    401  
    402  
    403         tuner_lock->lock("VDeviceBUZ::set_picture"); 
    404         if(device->r) 
    405         { 
    406                 close_input_core(); 
    407                 open_input_core(0); 
    408         } 
    409         else 
    410         { 
    411                 close_output_core(); 
    412                 open_output_core(0); 
    413         } 
    414         tuner_lock->unlock(); 
    415 //  
    416 //  
    417 // TRACE("VDeviceBUZ::set_picture 1"); 
    418 //      tuner_lock->lock("VDeviceBUZ::set_picture"); 
    419 // TRACE("VDeviceBUZ::set_picture 2"); 
    420 //  
    421 //  
    422 //  
    423 //      struct video_picture picture_params; 
    424 // // This call takes a long time in 2.4.22 
    425 //      if(ioctl(jvideo_fd, VIDIOCGPICT, &picture_params) < 0) 
    426 //              perror("VDeviceBUZ::set_picture VIDIOCGPICT"); 
    427 //      picture_params.brightness = brightness; 
    428 //      picture_params.hue = hue; 
    429 //      picture_params.colour = color; 
    430 //      picture_params.contrast = contrast; 
    431 //      picture_params.whiteness = whiteness; 
    432 // // This call takes a long time in 2.4.22 
    433 //      if(ioctl(jvideo_fd, VIDIOCSPICT, &picture_params) < 0) 
    434 //              perror("VDeviceBUZ::set_picture VIDIOCSPICT"); 
    435 //      if(ioctl(jvideo_fd, VIDIOCGPICT, &picture_params) < 0) 
    436 //              perror("VDeviceBUZ::set_picture VIDIOCGPICT"); 
    437 //  
    438 //  
    439 // TRACE("VDeviceBUZ::set_picture 10"); 
    440 //  
    441 //  
    442 //      tuner_lock->unlock(); 
    443  
    444         return 0; 
    445 } 
    446  
    447 int VDeviceBUZ::get_norm(int norm) 
    448 { 
    449         switch(norm) 
    450         { 
    451                 case NTSC:          return VIDEO_MODE_NTSC;      break; 
    452                 case PAL:           return VIDEO_MODE_PAL;       break; 
    453                 case SECAM:         return VIDEO_MODE_SECAM;     break; 
    454         } 
    455 } 
    456  
    457 int VDeviceBUZ::read_buffer(VFrame *frame) 
    458 { 
    459         tuner_lock->lock("VDeviceBUZ::read_buffer"); 
    460         if(!jvideo_fd) open_input_core(0); 
    461  
    462 // Get buffer from thread 
    463         char *buffer = 0; 
    464         int buffer_size = 0; 
    465         if(input_thread)  
    466                 input_thread->get_buffer(&buffer, &buffer_size); 
    467  
    468         if(buffer) 
    469         { 
    470                 frame->allocate_compressed_data(buffer_size); 
    471                 frame->set_compressed_size(buffer_size); 
    472  
    473 // Transfer fields to frame 
    474                 if(device->odd_field_first) 
    475                 { 
    476                         long field2_offset = mjpeg_get_field2((unsigned char*)buffer, buffer_size); 
    477                         long field1_len = field2_offset; 
    478                         long field2_len = buffer_size - field2_offset; 
    479  
    480                         memcpy(frame->get_data(), buffer + field2_offset, field2_len); 
    481                         memcpy(frame->get_data() + field2_len, buffer, field1_len); 
    482                 } 
    483                 else 
    484                 { 
    485                         bcopy(buffer, frame->get_data(), buffer_size); 
    486                 } 
    487  
    488                 input_thread->put_buffer(); 
    489                 tuner_lock->unlock(); 
    490         } 
    491         else 
    492         { 
    493                 tuner_lock->unlock(); 
    494                 Timer timer; 
    495 // Allow other threads to lock the tuner_lock under NPTL. 
    496                 timer.delay(100); 
    497         } 
    498  
    499  
    500         return 0; 
    501 } 
    502  
    503 int VDeviceBUZ::open_input_core(Channel *channel) 
    504 { 
    505         jvideo_fd = open(device->in_config->buz_in_device, O_RDONLY); 
    506  
    507         if(jvideo_fd <= 0) 
    508         { 
    509                 fprintf(stderr, "VDeviceBUZ::open_input %s: %s\n",  
    510                         device->in_config->buz_in_device, 
    511                         strerror(errno)); 
    512                 jvideo_fd = 0; 
    513                 return 1; 
    514         } 
    515  
    516 // Create input sources 
    517         get_inputs(&device->input_sources); 
    518  
    519 // Set current input source 
    520         if(channel) 
    521         { 
    522                 for(int i = 0; i < 2; i++) 
    523                 { 
    524                         struct video_channel vch; 
    525                         vch.channel = channel->input; 
    526                         vch.norm = get_norm(channel->norm); 
    527  
    528 //printf("VDeviceBUZ::open_input_core 2 %d %d\n", vch.channel, vch.norm); 
    529                         if(ioctl(jvideo_fd, VIDIOCSCHAN, &vch) < 0) 
    530                                 perror("VDeviceBUZ::open_input_core VIDIOCSCHAN "); 
    531                 } 
    532         } 
    533  
    534  
    535 // Throw away 
    536 //     struct video_capability vc; 
    537 //      if(ioctl(jvideo_fd, VIDIOCGCAP, &vc) < 0) 
    538 //              perror("VDeviceBUZ::open_input VIDIOCGCAP"); 
    539  
    540 // API dependant initialization 
    541         if(ioctl(jvideo_fd, BUZIOC_G_PARAMS, &bparm) < 0) 
    542                 perror("VDeviceBUZ::open_input BUZIOC_G_PARAMS"); 
    543  
    544         bparm.HorDcm = 1; 
    545         bparm.VerDcm = 1; 
    546         bparm.TmpDcm = 1; 
    547         bparm.field_per_buff = 2; 
    548         bparm.img_width = device->in_config->w; 
    549         bparm.img_height = device->in_config->h / bparm.field_per_buff; 
    550         bparm.img_x = 0; 
    551         bparm.img_y = 0; 
    552 //      bparm.APPn = 0; 
    553 //      bparm.APP_len = 14; 
    554         bparm.APP_len = 0; 
    555         bparm.odd_even = 0; 
    556     bparm.decimation = 0; 
    557     bparm.quality = device->quality; 
    558     bzero(bparm.APP_data, sizeof(bparm.APP_data)); 
    559  
    560         if(ioctl(jvideo_fd, BUZIOC_S_PARAMS, &bparm) < 0) 
    561                 perror("VDeviceBUZ::open_input BUZIOC_S_PARAMS"); 
    562  
    563 // printf("open_input %d %d %d %d %d %d %d %d %d %d %d %d\n",  
    564 //              bparm.HorDcm, 
    565 //              bparm.VerDcm, 
    566 //              bparm.TmpDcm, 
    567 //              bparm.field_per_buff, 
    568 //              bparm.img_width, 
    569 //              bparm.img_height, 
    570 //              bparm.img_x, 
    571 //              bparm.img_y, 
    572 //              bparm.APP_len, 
    573 //              bparm.odd_even, 
    574 //      bparm.decimation, 
    575 //      bparm.quality); 
    576  
    577         breq.count = device->in_config->capture_length; 
    578         breq.size = INPUT_BUFFER_SIZE; 
    579         if(ioctl(jvideo_fd, BUZIOC_REQBUFS, &breq) < 0) 
    580                 perror("VDeviceBUZ::open_input BUZIOC_REQBUFS"); 
    581  
    582 //printf("open_input %s %d %d %d %d\n", device->in_config->buz_in_device, breq.count, breq.size, bparm.img_width, bparm.img_height); 
    583         if((input_buffer = (char*)mmap(0,  
    584                 breq.count * breq.size,  
    585                 PROT_READ,  
    586                 MAP_SHARED,  
    587                 jvideo_fd,  
    588                 0)) == MAP_FAILED) 
    589                 perror("VDeviceBUZ::open_input mmap"); 
    590  
    591  
    592 // Set picture quality 
    593         struct video_picture picture_params; 
    594 // This call takes a long time in 2.4.22 
    595         if(ioctl(jvideo_fd, VIDIOCGPICT, &picture_params) < 0) 
    596                 perror("VDeviceBUZ::set_picture VIDIOCGPICT"); 
    597         picture_params.brightness = brightness; 
    598         picture_params.hue = hue; 
    599         picture_params.colour = color; 
    600         picture_params.contrast = contrast; 
    601         picture_params.whiteness = whiteness; 
    602 // This call takes a long time in 2.4.22 
    603         if(ioctl(jvideo_fd, VIDIOCSPICT, &picture_params) < 0) 
    604                 perror("VDeviceBUZ::set_picture VIDIOCSPICT"); 
    605         if(ioctl(jvideo_fd, VIDIOCGPICT, &picture_params) < 0) 
    606                 perror("VDeviceBUZ::set_picture VIDIOCGPICT"); 
    607  
    608  
    609  
    610  
    611 // Start capturing 
    612         for(int i = 0; i < breq.count; i++) 
    613         { 
    614         if(ioctl(jvideo_fd, BUZIOC_QBUF_CAPT, &i) < 0) 
    615                         perror("VDeviceBUZ::open_input BUZIOC_QBUF_CAPT"); 
    616         } 
    617  
    618  
    619         input_thread = new VDeviceBUZInput(this); 
    620         input_thread->start(); 
    621 //printf("VDeviceBUZ::open_input_core 2\n"); 
    622         return 0; 
    623 } 
    624  
    625 int VDeviceBUZ::open_output_core(Channel *channel) 
    626 { 
    627 //printf("VDeviceBUZ::open_output 1\n"); 
    628         total_loops = 0; 
    629         output_number = 0; 
    630         jvideo_fd = open(device->out_config->buz_out_device, O_RDWR); 
    631         if(jvideo_fd <= 0) 
    632         { 
    633                 perror("VDeviceBUZ::open_output"); 
    634                 return 1; 
    635         } 
    636  
    637  
    638 // Set current input source 
    639         if(channel) 
    640         { 
    641                 struct video_channel vch; 
    642                 vch.channel = channel->input; 
    643                 vch.norm = get_norm(channel->norm); 
    644  
    645                 if(ioctl(jvideo_fd, VIDIOCSCHAN, &vch) < 0) 
    646                         perror("VDeviceBUZ::open_output_core VIDIOCSCHAN "); 
    647         } 
    648  
    649         breq.count = 10; 
    650         breq.size = INPUT_BUFFER_SIZE; 
    651         if(ioctl(jvideo_fd, BUZIOC_REQBUFS, &breq) < 0) 
    652                 perror("VDeviceBUZ::open_output BUZIOC_REQBUFS"); 
    653         if((output_buffer = (char*)mmap(0,  
    654                 breq.count * breq.size,  
    655                 PROT_READ | PROT_WRITE,  
    656                 MAP_SHARED,  
    657                 jvideo_fd,  
    658                 0)) == MAP_FAILED) 
    659                 perror("VDeviceBUZ::open_output mmap"); 
    660  
    661         if(ioctl(jvideo_fd, BUZIOC_G_PARAMS, &bparm) < 0) 
    662                 perror("VDeviceBUZ::open_output BUZIOC_G_PARAMS"); 
    663  
    664         bparm.decimation = 1; 
    665         bparm.HorDcm = 1; 
    666         bparm.field_per_buff = 2; 
    667         bparm.TmpDcm = 1; 
    668         bparm.VerDcm = 1; 
    669         bparm.img_width = device->out_w; 
    670         bparm.img_height = device->out_h / bparm.field_per_buff; 
    671         bparm.img_x = 0; 
    672         bparm.img_y = 0; 
    673         bparm.odd_even = 0; 
    674  
    675         if(ioctl(jvideo_fd, BUZIOC_S_PARAMS, &bparm) < 0) 
    676                 perror("VDeviceBUZ::open_output BUZIOC_S_PARAMS"); 
    677 //printf("VDeviceBUZ::open_output 2\n"); 
    678         return 0; 
    679 } 
    680  
    681  
    682  
    683 int VDeviceBUZ::write_buffer(VFrame *frame, EDL *edl) 
    684 { 
    685 //printf("VDeviceBUZ::write_buffer 1\n"); 
    686         tuner_lock->lock("VDeviceBUZ::write_buffer"); 
    687  
    688         if(!jvideo_fd) open_output_core(0); 
    689  
    690         VFrame *ptr = 0; 
    691         if(frame->get_color_model() != BC_COMPRESSED) 
    692         { 
    693                 if(!temp_frame) temp_frame = new VFrame; 
    694                 if(!mjpeg) 
    695                 { 
    696                         mjpeg = mjpeg_new(device->out_w, device->out_h, 2); 
    697                         mjpeg_set_quality(mjpeg, device->quality); 
    698                         mjpeg_set_float(mjpeg, 0); 
    699                 } 
    700                 ptr = temp_frame; 
    701                 mjpeg_compress(mjpeg,  
    702                         frame->get_rows(),  
    703                         frame->get_y(),  
    704                         frame->get_u(),  
    705                         frame->get_v(), 
    706                         frame->get_color_model(), 
    707                         device->cpus); 
    708                 temp_frame->allocate_compressed_data(mjpeg_output_size(mjpeg)); 
    709                 temp_frame->set_compressed_size(mjpeg_output_size(mjpeg)); 
    710                 bcopy(mjpeg_output_buffer(mjpeg), temp_frame->get_data(), mjpeg_output_size(mjpeg)); 
    711         } 
    712         else 
    713                 ptr = frame; 
    714  
    715 // Wait for frame to become available 
    716 // Caused close_output_core to lock up. 
    717 //      if(total_loops >= 1) 
    718 //      { 
    719 //              if(ioctl(jvideo_fd, BUZIOC_SYNC, &output_number) < 0) 
    720 //                      perror("VDeviceBUZ::write_buffer BUZIOC_SYNC"); 
    721 //      } 
    722  
    723         if(device->out_config->buz_swap_fields) 
    724         { 
    725                 long field2_offset = mjpeg_get_field2((unsigned char*)ptr->get_data(),  
    726                         ptr->get_compressed_size()); 
    727                 long field2_len = ptr->get_compressed_size() - field2_offset; 
    728                 memcpy(output_buffer + output_number * breq.size,  
    729                         ptr->get_data() + field2_offset,  
    730                         field2_len); 
    731                 memcpy(output_buffer + output_number * breq.size +field2_len, 
    732                         ptr->get_data(),  
    733                         field2_offset); 
    734         } 
    735         else 
    736         { 
    737                 bcopy(ptr->get_data(),  
    738                         output_buffer + output_number * breq.size,  
    739                         ptr->get_compressed_size()); 
    740         } 
    741  
    742         if(ioctl(jvideo_fd, BUZIOC_QBUF_PLAY, &output_number) < 0) 
    743                 perror("VDeviceBUZ::write_buffer BUZIOC_QBUF_PLAY"); 
    744  
    745         output_number++; 
    746         if(output_number >= breq.count) 
    747         { 
    748                 output_number = 0; 
    749                 total_loops++; 
    750         } 
    751         tuner_lock->unlock(); 
    752 //printf("VDeviceBUZ::write_buffer 2\n"); 
    753  
    754         return 0; 
    755 } 
    756  
    757 void VDeviceBUZ::new_output_buffer(VFrame *output, 
    758         int colormodel) 
    759 { 
    760 //printf("VDeviceBUZ::new_output_buffer 1 %d\n", colormodel); 
    761         if(user_frame) 
    762         { 
    763                 if(colormodel != user_frame->get_color_model()) 
    764                 { 
    765                         delete user_frame; 
    766                         user_frame = 0; 
    767                 } 
    768         } 
    769  
    770         if(!user_frame) 
    771         { 
    772                 switch(colormodel) 
    773                 { 
    774                         case BC_COMPRESSED: 
    775                                 user_frame = new VFrame; 
    776                                 break; 
    777                         default: 
    778                                 user_frame = new VFrame(0, 
    779                                         device->out_w, 
    780                                         device->out_h, 
    781                                         colormodel, 
    782                                         -1); 
    783                                 break; 
    784                 } 
    785         } 
    786         user_frame->set_shm_offset(0); 
    787         output = user_frame; 
    788 //printf("VDeviceBUZ::new_output_buffer 2\n"); 
    789 } 
    790  
    791  
    792 ArrayList<int>* VDeviceBUZ::get_render_strategies() 
    793 { 
    794         return &render_strategies; 
    795 } 
    796  
  • cinelerra/vdevicebuz.h

    diff -Nru cinelerra.orig//cinelerra/vdevicebuz.h cinelerra/cinelerra/vdevicebuz.h
    old new  
    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 #ifndef VDEVICEBUZ_H 
    23 #define VDEVICEBUZ_H 
    24  
    25 #include "buz.h" 
    26 #include "channel.inc" 
    27 #include "condition.inc" 
    28 #include "guicast.h" 
    29 #include "libmjpeg.h" 
    30 #include "mutex.inc" 
    31 #include "thread.h" 
    32 #include "vdevicebase.h" 
    33 #include "vdevicebuz.inc" 
    34 #include "vframe.inc" 
    35  
    36  
    37 #define INPUT_BUFFER_SIZE 0x40000 
    38  
    39 // Let's get real.  The Buz driver doesn't work.  If the buffers overflow 
    40 // for enough time it locks up and can't be recovered except by a 
    41 // SIGINT and restart.  We need to cascade the buffer reading in another 
    42 // ring buffer thread, have it read continuously, and cancel it if it  
    43 // dies.  How about if we do this in SCHED_RR and wait for it to die before  
    44 // implementing cancellation? 
    45  
    46  
    47 class VDeviceBUZInput : public Thread 
    48 { 
    49 public: 
    50         VDeviceBUZInput(VDeviceBUZ *device); 
    51         ~VDeviceBUZInput(); 
    52         void start(); 
    53         void run(); 
    54         void get_buffer(char **ptr, int *size); 
    55         void put_buffer(); 
    56         void increment_counter(int *counter); 
    57         void decrement_counter(int *counter); 
    58         VDeviceBUZ *device; 
    59  
    60         char **buffer; 
    61         int *buffer_size; 
    62         int total_buffers; 
    63         int current_inbuffer; 
    64         int current_outbuffer; 
    65         Condition *output_lock; 
    66         Mutex *buffer_lock; 
    67         int done; 
    68 }; 
    69  
    70  
    71 class VDeviceBUZ : public VDeviceBase 
    72 { 
    73 public: 
    74         VDeviceBUZ(VideoDevice *device); 
    75         ~VDeviceBUZ(); 
    76  
    77         friend class VDeviceBUZInput; 
    78  
    79         int open_input(); 
    80         int open_output(); 
    81         int close_all(); 
    82         int read_buffer(VFrame *frame); 
    83         int write_buffer(VFrame *frames, EDL *edl); 
    84         int reset_parameters(); 
    85         ArrayList<int>* get_render_strategies(); 
    86         int set_channel(Channel *channel); 
    87         int get_norm(int norm); 
    88         static void get_inputs(ArrayList<Channel*> *input_sources); 
    89         int set_picture(PictureConfig *picture); 
    90         int get_best_colormodel(int colormodel); 
    91         void create_channeldb(ArrayList<Channel*> *channeldb); 
    92         void new_output_buffer(VFrame *output, int colormodel); 
    93  
    94  
    95 private: 
    96         int open_input_core(Channel *channel); 
    97         int close_input_core(); 
    98         int open_output_core(Channel *channel); 
    99         int close_output_core(); 
    100  
    101         int jvideo_fd; 
    102         char *input_buffer, *frame_buffer, *output_buffer; 
    103         long frame_size, frame_allocated; 
    104         int input_error; 
    105 //      quicktime_mjpeg_hdr jpeg_header; 
    106         long last_frame_no; 
    107         ArrayList<int> render_strategies; 
    108 // Temporary frame for compressing output data 
    109         VFrame *temp_frame; 
    110 // Frame given to user to acquire data 
    111         VFrame *user_frame; 
    112         mjpeg_t *mjpeg; 
    113         Mutex *tuner_lock; 
    114         VDeviceBUZInput *input_thread; 
    115  
    116         struct buz_params bparm; 
    117         struct buz_requestbuffers breq; 
    118 // Can't CSYNC the first loop 
    119         int total_loops; 
    120 // Number of output frame to load 
    121         int output_number; 
    122  
    123         int brightness; 
    124         int hue; 
    125         int color; 
    126         int contrast; 
    127         int whiteness; 
    128 }; 
    129  
    130 #endif 
  • cinelerra/vdevicebuz.inc

    diff -Nru cinelerra.orig//cinelerra/vdevicebuz.inc cinelerra/cinelerra/vdevicebuz.inc
    old new  
    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 #ifndef VDEVICEBUZ_INC 
    23 #define VDEVICEBUZ_INC 
    24  
    25 class VDeviceBUZ; 
    26 class VDeviceBUZInput; 
    27  
    28 #endif 
  • cinelerra/vdevicev4l.C

    diff -Nru cinelerra.orig//cinelerra/vdevicev4l.C cinelerra/cinelerra/vdevicev4l.C
    old new  
    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 // V4L2 is incompatible with large file support 
    23 // ALPHA C++ can't compile 64 bit headers 
    24 #undef _FILE_OFFSET_BITS 
    25 #undef _LARGEFILE_SOURCE 
    26 #undef _LARGEFILE64_SOURCE 
    27  
    28  
    29 #include "assets.h" 
    30 #include "bcsignals.h" 
    31 #include "channel.h" 
    32 #include "chantables.h" 
    33 #include "clip.h" 
    34 #include "file.h" 
    35 #include "picture.h" 
    36 #include "preferences.h" 
    37 #include "quicktime.h" 
    38 #include "recordconfig.h" 
    39 #include "vdevicev4l.h" 
    40 #include "vframe.h" 
    41 #include "videodevice.h" 
    42  
    43 #include <unistd.h> 
    44 #include <sys/ioctl.h> 
    45 #include <fcntl.h> 
    46 #include <sys/mman.h> 
    47 #include <string.h> 
    48  
    49 VDeviceV4L::VDeviceV4L(VideoDevice *device) 
    50  : VDeviceBase(device) 
    51 { 
    52         initialize(); 
    53 } 
    54  
    55 VDeviceV4L::~VDeviceV4L() 
    56 { 
    57 } 
    58  
    59 int VDeviceV4L::initialize() 
    60 { 
    61         capture_buffer = 0; 
    62         capture_frame_number = 0; 
    63         read_frame_number = 0; 
    64         shared_memory = 0; 
    65         initialization_complete = 0; 
    66         return 0; 
    67 } 
    68  
    69 int VDeviceV4L::open_input() 
    70 { 
    71         device->channel->use_frequency = 1; 
    72         device->channel->use_fine = 1; 
    73         device->channel->use_norm = 1; 
    74         device->channel->use_input = 1; 
    75  
    76  
    77         device->picture->use_brightness = 1; 
    78         device->picture->use_contrast = 1; 
    79         device->picture->use_color = 1; 
    80         device->picture->use_hue = 1; 
    81         device->picture->use_whiteness = 1; 
    82  
    83         if((input_fd = open(device->in_config->v4l_in_device, O_RDWR)) < 0) 
    84         { 
    85                 perror("VDeviceV4L::open_input"); 
    86                 return 1; 
    87         } 
    88         else 
    89         { 
    90                 v4l1_get_inputs(); 
    91                 close(input_fd); 
    92         } 
    93         return 0; 
    94 } 
    95  
    96 int VDeviceV4L::close_all() 
    97 { 
    98         close_v4l(); 
    99         return 0; 
    100 } 
    101  
    102 int VDeviceV4L::close_v4l() 
    103 { 
    104         unmap_v4l_shmem(); 
    105         if(input_fd != -1) close(input_fd); 
    106         return 0; 
    107 } 
    108  
    109 int VDeviceV4L::unmap_v4l_shmem() 
    110 { 
    111         if(capture_buffer) 
    112         { 
    113                 if(shared_memory) 
    114                         munmap(capture_buffer, capture_params.size); 
    115                 else 
    116                         delete capture_buffer; 
    117                 capture_buffer = 0; 
    118         } 
    119         return 0; 
    120 } 
    121  
    122 int VDeviceV4L::v4l_init() 
    123 { 
    124         int i; 
    125  
    126         input_fd = open(device->in_config->v4l_in_device, O_RDWR); 
    127  
    128         if(input_fd < 0) 
    129                 perror("VDeviceV4L::v4l_init"); 
    130         else 
    131         { 
    132                 set_cloexec_flag(input_fd, 1); 
    133                 set_mute(0); 
    134                 if(ioctl(input_fd, VIDIOCGWIN, &window_params) < 0) 
    135                         perror("VDeviceV4L::v4l_init VIDIOCGWIN"); 
    136                 window_params.x = 0; 
    137                 window_params.y = 0; 
    138                 window_params.width = device->in_config->w; 
    139                 window_params.height = device->in_config->h; 
    140                 window_params.chromakey = 0; 
    141                 window_params.flags = 0; 
    142                 window_params.clipcount = 0; 
    143                 if(ioctl(input_fd, VIDIOCSWIN, &window_params) < 0) 
    144                         perror("VDeviceV4L::v4l_init VIDIOCSWIN"); 
    145                 if(ioctl(input_fd, VIDIOCGWIN, &window_params) < 0) 
    146                         perror("VDeviceV4L::v4l_init VIDIOCGWIN"); 
    147  
    148                 device->in_config->w = window_params.width; 
    149                 device->in_config->h = window_params.height; 
    150  
    151                 PictureConfig picture(0); 
    152                 set_picture(&picture); 
    153  
    154                 if(ioctl(input_fd, VIDIOCGMBUF, &capture_params) < 0) 
    155                         perror("VDeviceV4L::v4l_init VIDIOCGMBUF"); 
    156  
    157                 capture_buffer = (char*)mmap(0,  
    158                         capture_params.size,  
    159                         PROT_READ|PROT_WRITE,  
    160                         MAP_SHARED,  
    161                         input_fd,  
    162                         0); 
    163  
    164                 capture_frame_number = 0; 
    165  
    166                 if(capture_buffer == MAP_FAILED) 
    167                 { 
    168 // Use read instead. 
    169                         perror("VDeviceV4L::v4l_init mmap"); 
    170                         shared_memory = 0; 
    171                         capture_buffer = new char[capture_params.size]; 
    172                 } 
    173                 else 
    174                 { 
    175 // Get all frames capturing 
    176                         shared_memory = 1; 
    177                 } 
    178         } 
    179         got_first_frame = 0; 
    180         return 0; 
    181 } 
    182  
    183 void VDeviceV4L::v4l1_start_capture() 
    184 { 
    185         for(int i = 0; i < MIN(capture_params.frames, device->in_config->capture_length); i++) 
    186                 capture_frame(i); 
    187 } 
    188  
    189  
    190  
    191  
    192  
    193  
    194  
    195  
    196 int VDeviceV4L::v4l1_get_inputs() 
    197 { 
    198         struct video_channel channel_struct; 
    199         int i = 0, done = 0; 
    200         char *new_source; 
    201  
    202         while(!done && i < 20) 
    203         { 
    204                 channel_struct.channel = i; 
    205                 if(ioctl(input_fd, VIDIOCGCHAN, &channel_struct) < 0) 
    206                 { 
    207 // Finished 
    208                         done = 1; 
    209                 } 
    210                 else 
    211                 { 
    212                         Channel *channel = new Channel; 
    213                         strcpy(channel->device_name, channel_struct.name); 
    214                         device->input_sources.append(channel); 
    215                 } 
    216                 i++; 
    217         } 
    218         return 0; 
    219 } 
    220  
    221 int VDeviceV4L::set_mute(int muted) 
    222 { 
    223 // Open audio, which obviously is controlled by the video driver. 
    224 // and apparently resets the input source. 
    225         v4l1_set_mute(muted); 
    226 } 
    227  
    228 int VDeviceV4L::v4l1_set_mute(int muted) 
    229 { 
    230         struct video_audio audio; 
    231  
    232     if(ioctl(input_fd, VIDIOCGAUDIO, &audio)) 
    233         if(ioctl(input_fd, VIDIOCGAUDIO, &audio) < 0) 
    234             perror("VDeviceV4L::ioctl VIDIOCGAUDIO"); 
    235  
    236         audio.volume = 65535; 
    237         audio.bass = 65535; 
    238         audio.treble = 65535; 
    239         if(muted) 
    240                 audio.flags |= VIDEO_AUDIO_MUTE | VIDEO_AUDIO_VOLUME; 
    241         else 
    242                 audio.flags &= ~VIDEO_AUDIO_MUTE; 
    243  
    244     if(ioctl(input_fd, VIDIOCSAUDIO, &audio) < 0) 
    245                 perror("VDeviceV4L::ioctl VIDIOCSAUDIO"); 
    246         return 0; 
    247 } 
    248  
    249  
    250 int VDeviceV4L::set_cloexec_flag(int desc, int value) 
    251 { 
    252         int oldflags = fcntl(desc, F_GETFD, 0); 
    253         if(oldflags < 0) return oldflags; 
    254         if(value != 0)  
    255                 oldflags |= FD_CLOEXEC; 
    256         else 
    257                 oldflags &= ~FD_CLOEXEC; 
    258         return fcntl(desc, F_SETFD, oldflags); 
    259 } 
    260  
    261  
    262  
    263  
    264  
    265 int VDeviceV4L::get_best_colormodel(Asset *asset) 
    266 { 
    267         int result = BC_RGB888; 
    268  
    269 // Get best colormodel for hardware acceleration 
    270  
    271         result = File::get_best_colormodel(asset, device->in_config->driver); 
    272  
    273  
    274 // Need to get color model before opening device but don't call this 
    275 // unless you want to open the device either. 
    276         if(!initialization_complete) 
    277         { 
    278                 device_colormodel = translate_colormodel(result); 
    279                 this->colormodel = result; 
    280                 v4l_init(); 
    281                 initialization_complete = 1; 
    282         } 
    283 // printf("VDeviceV4L::get_best_colormodel %c%c%c%c\n",  
    284 //      ((char*)&device_colormodel)[0], 
    285 //      ((char*)&device_colormodel)[1], 
    286 //      ((char*)&device_colormodel)[2], 
    287 //      ((char*)&device_colormodel)[3]); 
    288         return result; 
    289 } 
    290  
    291 unsigned long VDeviceV4L::translate_colormodel(int colormodel) 
    292 { 
    293         unsigned long result = 0; 
    294         switch(colormodel) 
    295         { 
    296                 case BC_YUV422:      result = VIDEO_PALETTE_YUV422;      break; 
    297                 case BC_YUV420P:     result = VIDEO_PALETTE_YUV420P;     break; 
    298                 case BC_YUV422P:     result = VIDEO_PALETTE_YUV422P;     break; 
    299                 case BC_YUV411P:     result = VIDEO_PALETTE_YUV411P;     break; 
    300                 case BC_RGB888:      result = VIDEO_PALETTE_RGB24;       break; 
    301                 default: result = VIDEO_PALETTE_RGB24; break; 
    302         } 
    303 //printf("VDeviceV4L::translate_colormodel %d\n", result); 
    304         return result; 
    305 } 
    306  
    307 int VDeviceV4L::set_channel(Channel *channel) 
    308 { 
    309         return v4l1_set_channel(channel); 
    310 } 
    311  
    312 int VDeviceV4L::v4l1_set_channel(Channel *channel) 
    313 { 
    314         struct video_channel channel_struct; 
    315         struct video_tuner tuner_struct; 
    316         unsigned long new_freq; 
    317  
    318 // Mute changed the input to TV 
    319 //      set_mute(1); 
    320  
    321 //printf("VDeviceV4L::v4l1_set_channel 1 %d\n", channel->input); 
    322 // Read norm/input defaults 
    323         channel_struct.channel = channel->input; 
    324         if(ioctl(input_fd, VIDIOCGCHAN, &channel_struct) < 0) 
    325                 perror("VDeviceV4L::v4l1_set_channel VIDIOCGCHAN"); 
    326  
    327 // Set norm/input 
    328         channel_struct.channel = channel->input; 
    329         channel_struct.norm = v4l1_get_norm(channel->norm); 
    330         if(ioctl(input_fd, VIDIOCSCHAN, &channel_struct) < 0) 
    331                 perror("VDeviceV4L::v4l1_set_channel VIDIOCSCHAN"); 
    332  
    333         if(channel_struct.flags & VIDEO_VC_TUNER) 
    334         { 
    335 // Read tuner defaults 
    336                 tuner_struct.tuner = channel->input; 
    337                 if(ioctl(input_fd, VIDIOCGTUNER, &tuner_struct) < 0) 
    338                         perror("VDeviceV4L::v4l1_set_channel VIDIOCGTUNER"); 
    339  
    340 // Set tuner 
    341                 tuner_struct.mode = v4l1_get_norm(channel->norm); 
    342                 if(ioctl(input_fd, VIDIOCSTUNER, &tuner_struct) < 0) 
    343                         perror("VDeviceV4L::v4l1_set_channel VIDIOCSTUNER"); 
    344  
    345                 new_freq = chanlists[channel->freqtable].list[channel->entry].freq; 
    346                 new_freq = (int)(new_freq * 0.016); 
    347                 new_freq += channel->fine_tune; 
    348  
    349                 if(ioctl(input_fd, VIDIOCSFREQ, &new_freq) < 0) 
    350                         perror("VDeviceV4L::v4l1_set_channel VIDIOCSFREQ"); 
    351         } 
    352 //      set_mute(0); 
    353         return 0; 
    354 } 
    355  
    356 int VDeviceV4L::v4l1_get_norm(int norm) 
    357 { 
    358         switch(norm) 
    359         { 
    360                 case NTSC:         return VIDEO_MODE_NTSC;         break; 
    361                 case PAL:          return VIDEO_MODE_PAL;          break; 
    362                 case SECAM:        return VIDEO_MODE_SECAM;        break; 
    363         } 
    364         return 0; 
    365 } 
    366  
    367 int VDeviceV4L::set_picture(PictureConfig *picture) 
    368 { 
    369         v4l1_set_picture(picture); 
    370 } 
    371  
    372  
    373 int VDeviceV4L::v4l1_set_picture(PictureConfig *picture) 
    374 { 
    375         int brightness = (int)((float)picture->brightness / 100 * 32767 + 32768); 
    376         int hue = (int)((float)picture->hue / 100 * 32767 + 32768); 
    377         int color = (int)((float)picture->color / 100 * 32767 + 32768); 
    378         int contrast = (int)((float)picture->contrast / 100 * 32767 + 32768); 
    379         int whiteness = (int)((float)picture->whiteness / 100 * 32767 + 32768); 
    380  
    381         if(ioctl(input_fd, VIDIOCGPICT, &picture_params) < 0) 
    382                 perror("VDeviceV4L::v4l1_set_picture VIDIOCGPICT"); 
    383         picture_params.brightness = brightness; 
    384         picture_params.hue = hue; 
    385         picture_params.colour = color; 
    386         picture_params.contrast = contrast; 
    387         picture_params.whiteness = whiteness; 
    388 // Bogus.  Values are only set in the capture routine. 
    389         picture_params.depth = 3; 
    390         picture_params.palette = device_colormodel; 
    391         if(ioctl(input_fd, VIDIOCSPICT, &picture_params) < 0) 
    392                 perror("VDeviceV4L::v4l1_set_picture VIDIOCSPICT"); 
    393         if(ioctl(input_fd, VIDIOCGPICT, &picture_params) < 0) 
    394                 perror("VDeviceV4L::v4l1_set_picture VIDIOCGPICT"); 
    395         return 0; 
    396 } 
    397  
    398  
    399 int VDeviceV4L::capture_frame(int capture_frame_number) 
    400 { 
    401         struct video_mmap params; 
    402         params.frame = capture_frame_number; 
    403         params.width = device->in_config->w; 
    404         params.height = device->in_config->h; 
    405 // Required to actually set the palette. 
    406         params.format = device_colormodel; 
    407 // Tells the driver the buffer is available for writing 
    408         if(ioctl(input_fd, VIDIOCMCAPTURE, &params) < 0) 
    409                 perror("VDeviceV4L::capture_frame VIDIOCMCAPTURE"); 
    410         return 0; 
    411 } 
    412  
    413 int VDeviceV4L::wait_v4l_frame() 
    414 { 
    415 //printf("VDeviceV4L::wait_v4l_frame 1 %d\n", capture_frame_number); 
    416         if(ioctl(input_fd, VIDIOCSYNC, &capture_frame_number)) 
    417                 perror("VDeviceV4L::wait_v4l_frame VIDIOCSYNC"); 
    418 //printf("VDeviceV4L::wait_v4l_frame 2 %d\n", capture_frame_number); 
    419         return 0; 
    420 } 
    421  
    422 int VDeviceV4L::read_v4l_frame(VFrame *frame) 
    423 { 
    424         frame_to_vframe(frame, (unsigned char*)capture_buffer + capture_params.offsets[capture_frame_number]); 
    425         return 0; 
    426 } 
    427  
    428 #ifndef MIN 
    429 #define MIN(x, y) ((x) < (y) ? (x) : (y)) 
    430 #endif 
    431  
    432 int VDeviceV4L::frame_to_vframe(VFrame *frame, unsigned char *input) 
    433 { 
    434         int inwidth, inheight; 
    435         int width, height; 
    436  
    437         inwidth = window_params.width; 
    438         inheight = window_params.height; 
    439  
    440         width = MIN(inwidth, frame->get_w()); 
    441         height = MIN(inheight, frame->get_h()); 
    442 //printf("VDeviceV4L::frame_to_vframe %d %d\n", colormodel, frame->get_color_model()); 
    443  
    444         if(frame->get_color_model() == colormodel) 
    445         { 
    446                 switch(frame->get_color_model()) 
    447                 { 
    448                         case BC_RGB888: 
    449                         { 
    450                                 unsigned char *row_in; 
    451                                 unsigned char *row_out_start, *row_out_end; 
    452                                 int bytes_per_inrow = inwidth * 3; 
    453                                 int bytes_per_outrow = frame->get_bytes_per_line(); 
    454                                 unsigned char **rows_out = frame->get_rows(); 
    455  
    456                                 for(int i = 0; i < frame->get_h(); i++) 
    457                                 { 
    458                                         row_in = input + bytes_per_inrow * i; 
    459                                         row_out_start = rows_out[i]; 
    460                                         row_out_end = row_out_start +  
    461                                                 MIN(bytes_per_outrow, bytes_per_inrow); 
    462  
    463                                         while(row_out_start < row_out_end) 
    464                                         { 
    465                                                 *row_out_start++ = row_in[2]; 
    466                                                 *row_out_start++ = row_in[1]; 
    467                                                 *row_out_start++ = row_in[0]; 
    468                                                 row_in += 3; 
    469                                         } 
    470                                 } 
    471                                 break; 
    472                         } 
    473  
    474                         case BC_YUV420P: 
    475                         case BC_YUV411P: 
    476                                 memcpy(frame->get_y(), input, width * height); 
    477                                 memcpy(frame->get_u(), input + width * height, width * height / 4); 
    478                                 memcpy(frame->get_v(), input + width * height + width * height / 4, width * height / 4); 
    479                                 break; 
    480  
    481                         case BC_YUV422P: 
    482                                 memcpy(frame->get_y(), input, width * height); 
    483                                 memcpy(frame->get_u(), input + width * height, width * height / 2); 
    484                                 memcpy(frame->get_v(), input + width * height + width * height / 2, width * height / 2); 
    485                                 break; 
    486  
    487                         case BC_YUV422: 
    488                                 memcpy(frame->get_data(),  
    489                                         input,  
    490                                         VFrame::calculate_data_size(width,  
    491                                                 height,  
    492                                                 -1,  
    493                                                 frame->get_color_model())); 
    494                                 break; 
    495                 } 
    496         } 
    497         else 
    498         { 
    499                 VFrame *in_frame = new VFrame(input,  
    500                         inwidth,  
    501                         inheight,  
    502                         colormodel,  
    503                         -1); 
    504                 cmodel_transfer(frame->get_rows(),  
    505                         in_frame->get_rows(), 
    506                         frame->get_y(), 
    507                         frame->get_u(), 
    508                         frame->get_v(), 
    509                         in_frame->get_y(), 
    510                         in_frame->get_u(), 
    511                         in_frame->get_v(), 
    512                         0,  
    513                         0,  
    514                         inwidth,  
    515                         inheight, 
    516                         0,  
    517                         0,  
    518                         frame->get_w(),  
    519                         frame->get_h(), 
    520                         colormodel,  
    521                         frame->get_color_model(), 
    522                         0, 
    523                         inwidth, 
    524                         inheight); 
    525         } 
    526         return 0; 
    527 } 
    528  
    529  
    530  
    531 int VDeviceV4L::next_frame(int previous_frame) 
    532 { 
    533         int result = previous_frame + 1; 
    534  
    535         if(result >= MIN(capture_params.frames, device->in_config->capture_length)) result = 0; 
    536         return result; 
    537 } 
    538  
    539 int VDeviceV4L::read_buffer(VFrame *frame) 
    540 { 
    541         int result = 0; 
    542  
    543 SET_TRACE 
    544         if(shared_memory) 
    545         { 
    546 // Read the current frame 
    547                 if(!got_first_frame) v4l1_start_capture(); 
    548                 wait_v4l_frame(); 
    549                 read_v4l_frame(frame); 
    550 // Free this frame up for capturing 
    551                 capture_frame(capture_frame_number); 
    552 // Advance the frame to capture. 
    553                 capture_frame_number = next_frame(capture_frame_number); 
    554         } 
    555         else 
    556         { 
    557                 read(input_fd, capture_buffer, capture_params.size); 
    558         } 
    559         got_first_frame = 1; 
    560 SET_TRACE 
    561  
    562         return 0; 
    563 } 
    564  
    565  
    566  
    567  
    568  
    569  
    570  
    571  
    572  
    573  
    574  
  • cinelerra/vdevicev4l.h

    diff -Nru cinelerra.orig//cinelerra/vdevicev4l.h cinelerra/cinelerra/vdevicev4l.h
    old new  
    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 #ifndef VDEVICEV4L_H 
    23 #define VDEVICEV4L_H 
    24  
    25 #include "vdevicebase.h" 
    26 #include <linux/videodev.h> 
    27 #include "videodevice.inc" 
    28  
    29 class VDeviceV4L : public VDeviceBase 
    30 { 
    31 public: 
    32         VDeviceV4L(VideoDevice *device); 
    33         ~VDeviceV4L(); 
    34  
    35         int initialize(); 
    36         int open_input(); 
    37         int close_all(); 
    38         int read_buffer(VFrame *frame); 
    39         int get_best_colormodel(Asset *asset); 
    40         int set_channel(Channel *channel); 
    41         int set_picture(PictureConfig *picture); 
    42  
    43 private: 
    44         int set_cloexec_flag(int desc, int value); 
    45         int set_mute(int muted); 
    46         int v4l1_get_inputs(); 
    47         int v4l1_set_mute(int muted); 
    48         unsigned long translate_colormodel(int colormodel); 
    49         int v4l1_set_channel(Channel *channel); 
    50         int v4l1_get_norm(int norm); 
    51         int v4l1_set_picture(PictureConfig *picture); 
    52         void v4l1_start_capture(); 
    53         int capture_frame(int capture_frame_number); 
    54         int wait_v4l_frame(); 
    55         int read_v4l_frame(VFrame *frame); 
    56         int frame_to_vframe(VFrame *frame, unsigned char *input); 
    57         int next_frame(int previous_frame); 
    58         int close_v4l(); 
    59         int unmap_v4l_shmem(); 
    60         int v4l_init(); 
    61  
    62         int input_fd, output_fd; 
    63 // FourCC Colormodel for device 
    64         unsigned long device_colormodel; 
    65 // BC colormodel for device 
    66         int colormodel; 
    67  
    68 // Video4Linux 
    69         struct video_capability cap1; 
    70         struct video_window window_params; 
    71         struct video_picture picture_params; 
    72         struct video_mbuf capture_params;  // Capture for Video4Linux 
    73  
    74 // Common 
    75         char *capture_buffer;      // sequentual capture buffers for v4l1 or read buffer for v4l2 
    76         int capture_frame_number;    // number of frame to capture into 
    77         int read_frame_number;       // number of the captured frame to read 
    78         int shared_memory;   // Capturing directly to memory 
    79         int initialization_complete; 
    80         int got_first_frame; 
    81 }; 
    82  
    83 #endif 
  • cinelerra/vdevicev4l.inc

    diff -Nru cinelerra.orig//cinelerra/vdevicev4l.inc cinelerra/cinelerra/vdevicev4l.inc
    old new  
    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 #ifndef VDEVICEV4L_INC 
    23 #define VDEVICEV4L_INC 
    24  
    25 class VDeviceV4L; 
    26  
    27 #endif 
  • cinelerra/videodevice.C

    diff -Nru cinelerra.orig//cinelerra/videodevice.C cinelerra/cinelerra/videodevice.C
    old new  
    3939#ifdef HAVE_FIREWIRE 
    4040#include "vdevice1394.h" 
    4141#endif 
    42 #include "vdevicebuz.h" 
     42//#include "vdevicebuz.h" 
    4343#include "vdevicedvb.h" 
    44 #include "vdevicev4l.h" 
     44//#include "vdevicev4l.h" 
    4545#include "vdevicev4l2.h" 
    4646#include "vdevicev4l2jpeg.h" 
    4747#include "vdevicex11.h" 
     
    203203                        result = input_base->open_input(); 
    204204                        break; 
    205205 
    206  
    207206#ifdef HAVE_VIDEO4LINUX2 
    208207                case VIDEO4LINUX2: 
    209208                        new_device_base(); 
     
    250249{ 
    251250        switch(in_config->driver) 
    252251        { 
    253                 case VIDEO4LINUX: 
    254                         return input_base = new VDeviceV4L(this); 
     252                //case VIDEO4LINUX: 
     253                //      return input_base = new VDeviceV4L(this); 
    255254 
    256255#ifdef HAVE_VIDEO4LINUX2 
    257256                case VIDEO4LINUX2: 
     
    264263                case SCREENCAPTURE: 
    265264                        return input_base = new VDeviceX11(this, 0); 
    266265 
    267                 case CAPTURE_BUZ: 
    268                         return input_base = new VDeviceBUZ(this); 
     266                //case CAPTURE_BUZ: 
     267                //      return input_base = new VDeviceBUZ(this); 
    269268 
    270269#ifdef HAVE_FIREWIRE 
    271270                case CAPTURE_FIREWIRE: 
     
    662661//printf("VideoDevice::open_output 1 %d\n", out_config->driver); 
    663662        switch(out_config->driver) 
    664663        { 
    665                 case PLAYBACK_BUZ: 
    666                         output_base = new VDeviceBUZ(this); 
    667                         break; 
     664                //case PLAYBACK_BUZ: 
     665                //      output_base = new VDeviceBUZ(this); 
     666                //      break; 
    668667                case PLAYBACK_X11: 
    669668                case PLAYBACK_X11_XV: 
    670669                case PLAYBACK_X11_GL: 
  • cinelerra/videodevice.h

    diff -Nru cinelerra.orig//cinelerra/videodevice.h cinelerra/cinelerra/videodevice.h
    old new  
    4040#include "thread.h" 
    4141#include "picture.inc" 
    4242#include "vdevicebase.inc" 
    43 #include "vdevicebuz.inc" 
     43//#include "vdevicebuz.inc" 
    4444#include "vdevicelml.inc" 
    45 #include "vdevicev4l.inc" 
     45//#include "vdevicev4l.inc" 
    4646#include "vdevicex11.inc" 
    4747#include "videoconfig.inc" 
    4848#include "videowindow.inc"