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