Ticket #949: remove-support-buz-kernel2-6-38.diff

File remove-support-buz-kernel2-6-38.diff, 25.7 KB (added by feranick, 15 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 \ 
    311310                    vdevicev4l.C \ 
  • cinelerra/reversemake

    diff -Nru cinelerra.orig//cinelerra/reversemake cinelerra/cinelerra/reversemake
    old new  
    3535make $OBJDIR/vdevicev4l.o 
    3636make $OBJDIR/vdeviceprefs.o 
    3737make $OBJDIR/vdevicelml.o 
    38 make $OBJDIR/vdevicebuz.o 
    3938make $OBJDIR/vdevicebase.o 
    4039make $OBJDIR/vdevice1394.o 
    4140make $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/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" 
    4444#include "vdevicev4l.h" 
    4545#include "vdevicev4l2.h" 
  • 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" 
    4545#include "vdevicev4l.inc" 
    4646#include "vdevicex11.inc"