Get rid of completely pointless vt_doit variable
[mplayer/glamo.git] / libvo / vosub_vidix.c
bloba6f261130b2599b108bb2863372c99a7e6b7b8f9
1 /*
2 * vidix interface to any mplayer vo driver
3 * (partly based on vesa_lvo.c)
5 * copyright (C) 2002 Nick Kurshev <nickols_k@mail.ru>
6 * copyright (C) Alex Beregszaszi
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include <inttypes.h>
26 #include <unistd.h>
27 #include <fcntl.h>
28 #ifndef __MINGW32__
29 #include <sys/ioctl.h>
30 #include <sys/mman.h>
31 #endif
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <errno.h>
37 #include "config.h"
38 #include "mp_msg.h"
39 #include "help_mp.h"
41 #include "vidix/vidix.h"
42 #include "fastmemcpy.h"
43 #include "osd.h"
44 #include "video_out.h"
45 #include "sub.h"
46 #include "vosub_vidix.h"
48 #include "libmpcodecs/vfcap.h"
49 #include "libmpcodecs/mp_image.h"
51 #define NUM_FRAMES VID_PLAY_MAXFRAMES /* Temporary: driver will overwrite it */
53 static VDXContext *vidix_handler = NULL;
54 static uint8_t *vidix_mem = NULL;
55 static uint8_t next_frame;
56 static unsigned image_Bpp,image_height,image_width,src_format,forced_fourcc=0;
57 static int video_on=0;
59 static vidix_capability_t vidix_cap;
60 static vidix_playback_t vidix_play;
61 static vidix_fourcc_t vidix_fourcc;
62 static vo_functions_t * vo_server;
63 static vidix_yuv_t dstrides;
64 /*static uint32_t (*server_control)(uint32_t request, void *data, ...);*/
66 int vidix_start(void)
68 int err;
69 if((err=vdlPlaybackOn(vidix_handler))!=0)
71 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CantStartPlayback,strerror(err));
72 return -1;
74 video_on=1;
75 return 0;
78 int vidix_stop(void)
80 int err;
81 if((err=vdlPlaybackOff(vidix_handler))!=0)
83 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CantStopPlayback,strerror(err));
84 return -1;
86 video_on=0;
87 return 0;
90 void vidix_term( void )
92 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
93 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_term() was called\n"); }
94 vidix_stop();
95 vdlClose(vidix_handler);
96 // vo_server->control=server_control;
99 static uint32_t vidix_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y)
101 uint8_t *src;
102 uint8_t *dest;
103 int i;
105 /* Plane Y */
106 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
107 dest += dstrides.y*y + x;
108 src = image[0];
109 for(i=0;i<h;i++){
110 memcpy(dest,src,w);
111 src+=stride[0];
112 dest += dstrides.y;
115 if (vidix_play.flags & VID_PLAY_INTERLEAVED_UV)
117 int hi,wi;
118 uint8_t *src2;
119 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.v;
120 dest += dstrides.y*y/2 + x; // <- is this correct ?
121 h/=2;
122 w/=2;
123 src = image[1];
124 src2 = image[2];
125 for(hi = 0; hi < h; hi++)
127 for(wi = 0; wi < w; wi++)
129 dest[2*wi+0] = src[wi];
130 dest[2*wi+1] = src2[wi];
132 dest += dstrides.y;
133 src += stride[1];
134 src2+= stride[2];
137 else
139 /* Plane V */
140 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.v;
141 dest += dstrides.v*y/4 + x;
142 src = image[1];
143 for(i=0;i<h/2;i++){
144 memcpy(dest,src,w/2);
145 src+=stride[1];
146 dest+=dstrides.v/2;
149 /* Plane U */
150 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.u;
151 dest += dstrides.u*y/4 + x;
152 src = image[2];
153 for(i=0;i<h/2;i++){
154 memcpy(dest,src,w/2);
155 src+=stride[2];
156 dest += dstrides.u/2;
158 return 0;
160 return -1;
163 static uint32_t vidix_draw_slice_410(uint8_t *image[], int stride[], int w,int h,int x,int y)
165 uint8_t *src;
166 uint8_t *dest;
167 int i;
169 /* Plane Y */
170 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
171 dest += dstrides.y*y + x;
172 src = image[0];
173 for(i=0;i<h;i++){
174 memcpy(dest,src,w);
175 src+=stride[0];
176 dest += dstrides.y;
179 if (vidix_play.flags & VID_PLAY_INTERLEAVED_UV)
181 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_SUB_VIDIX_InterleavedUvForYuv410pNotSupported);
183 else
185 /* Plane V */
186 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.v;
187 dest += dstrides.v*y/8 + x;
188 src = image[1];
189 for(i=0;i<h/4;i++){
190 memcpy(dest,src,w/4);
191 src+=stride[1];
192 dest+=dstrides.v/4;
195 /* Plane U */
196 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.u;
197 dest += dstrides.u*y/8 + x;
198 src = image[2];
199 for(i=0;i<h/4;i++){
200 memcpy(dest,src,w/4);
201 src+=stride[2];
202 dest += dstrides.u/4;
204 return 0;
206 return -1;
209 static uint32_t vidix_draw_slice_packed(uint8_t *image[], int stride[], int w,int h,int x,int y)
211 uint8_t *src;
212 uint8_t *dest;
213 int i;
215 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
216 dest += dstrides.y*y + x;
217 src = image[0];
218 for(i=0;i<h;i++){
219 memcpy(dest,src,w*image_Bpp);
220 src+=stride[0];
221 dest += dstrides.y;
223 return 0;
226 static uint32_t vidix_draw_slice_nv12(uint8_t *image[], int stride[], int w,int h,int x,int y)
228 uint8_t *src;
229 uint8_t *dest;
230 int i;
232 /* Plane Y */
233 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
234 dest += dstrides.y*y + x;
235 src = image[0];
236 for(i=0;i<h;i++){
237 memcpy(dest,src,w);
238 src+=stride[0];
239 dest += dstrides.y;
242 /* Plane UV */
243 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.u;
244 dest += dstrides.u*y/2 + x;
245 src = image[1];
246 for(i=0;i<h/2;i++){
247 memcpy(dest,src,w);
248 src+=stride[1];
249 dest+=dstrides.u;
251 return 0;
254 static uint32_t vidix_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
256 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_SUB_VIDIX_DummyVidixdrawsliceWasCalled);
257 return -1;
260 static uint32_t vidix_draw_image(mp_image_t *mpi){
261 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
262 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_draw_image() was called\n"); }
264 // if -dr or -slices then do nothing:
265 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE;
267 vo_server->draw_slice(mpi->planes,mpi->stride,
268 vidix_play.src.w,vidix_play.src.h,vidix_play.src.x,vidix_play.src.y);
269 return VO_TRUE;
272 static uint32_t vidix_draw_frame(uint8_t *image[])
274 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_SUB_VIDIX_DummyVidixdrawframeWasCalled);
275 return -1;
278 static void vidix_flip_page(void)
280 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
281 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_flip_page() was called\n"); }
282 if(vo_doublebuffering)
284 vdlPlaybackFrameSelect(vidix_handler,next_frame);
285 next_frame=(next_frame+1)%vidix_play.num_frames;
289 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
291 uint32_t apitch,bespitch;
292 char *lvo_mem;
293 lvo_mem = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
294 apitch = vidix_play.dest.pitch.y-1;
295 switch(vidix_play.fourcc){
296 case IMGFMT_NV12:
297 case IMGFMT_YV12:
298 case IMGFMT_IYUV:
299 case IMGFMT_I420:
300 case IMGFMT_YVU9:
301 case IMGFMT_IF09:
302 case IMGFMT_Y8:
303 case IMGFMT_Y800:
304 bespitch = (vidix_play.src.w + apitch) & (~apitch);
305 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch);
306 break;
307 case IMGFMT_YUY2:
308 bespitch = (vidix_play.src.w*2 + apitch) & (~apitch);
309 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+bespitch*y0+2*x0,bespitch);
310 break;
311 case IMGFMT_UYVY:
312 bespitch = (vidix_play.src.w*2 + apitch) & (~apitch);
313 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+bespitch*y0+2*x0+1,bespitch);
314 break;
315 case IMGFMT_RGB32:
316 case IMGFMT_BGR32:
317 bespitch = (vidix_play.src.w*4 + apitch) & (~apitch);
318 vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+y0*bespitch+4*x0,bespitch);
319 break;
320 case IMGFMT_RGB24:
321 case IMGFMT_BGR24:
322 bespitch = (vidix_play.src.w*3 + apitch) & (~apitch);
323 vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+y0*bespitch+3*x0,bespitch);
324 break;
325 case IMGFMT_RGB16:
326 case IMGFMT_BGR16:
327 bespitch = (vidix_play.src.w*2 + apitch) & (~apitch);
328 vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+y0*bespitch+2*x0,bespitch);
329 break;
330 case IMGFMT_RGB15:
331 case IMGFMT_BGR15:
332 bespitch = (vidix_play.src.w*2 + apitch) & (~apitch);
333 vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+y0*bespitch+2*x0,bespitch);
334 break;
335 default:
336 return;
340 static void vidix_draw_osd(void)
342 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
343 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_draw_osd() was called\n"); }
344 /* TODO: hw support */
345 vo_draw_text(vidix_play.src.w,vidix_play.src.h,draw_alpha);
348 uint32_t vidix_query_fourcc(uint32_t format)
350 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
351 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: query_format was called: %x (%s)\n",format,vo_format_name(format)); }
352 vidix_fourcc.fourcc = format;
353 vdlQueryFourcc(vidix_handler,&vidix_fourcc);
354 if (vidix_fourcc.depth == VID_DEPTH_NONE)
355 return 0;
356 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
359 int vidix_grkey_support(void)
361 return vidix_fourcc.flags & VID_CAP_COLORKEY;
364 int vidix_grkey_get(vidix_grkey_t *gr_key)
366 return vdlGetGrKeys(vidix_handler, gr_key);
369 int vidix_grkey_set(const vidix_grkey_t *gr_key)
371 return vdlSetGrKeys(vidix_handler, gr_key);
375 static int is_422_planes_eq=0;
376 int vidix_init(unsigned src_width,unsigned src_height,
377 unsigned x_org,unsigned y_org,unsigned dst_width,
378 unsigned dst_height,unsigned format,unsigned dest_bpp,
379 unsigned vid_w,unsigned vid_h)
381 void *tmp, *tmpa;
382 size_t i;
383 int err;
384 uint32_t sstride,apitch;
385 if( mp_msg_test(MSGT_VO,MSGL_DBG2) )
386 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_init() was called\n"
387 "src_w=%u src_h=%u dest_x_y_w_h = %u %u %u %u\n"
388 "format=%s dest_bpp=%u vid_w=%u vid_h=%u\n"
389 ,src_width,src_height,x_org,y_org,dst_width,dst_height
390 ,vo_format_name(format),dest_bpp,vid_w,vid_h);
392 if(vidix_query_fourcc(format) == 0)
394 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_UnsupportedFourccForThisVidixDriver,
395 format,vo_format_name(format));
396 return -1;
399 if(((vidix_cap.maxwidth != -1) && (vid_w > vidix_cap.maxwidth)) ||
400 ((vidix_cap.minwidth != -1) && (vid_w < vidix_cap.minwidth)) ||
401 ((vidix_cap.maxheight != -1) && (vid_h > vidix_cap.maxheight)) ||
402 ((vidix_cap.minwidth != -1 ) && (vid_h < vidix_cap.minheight)))
404 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_VideoServerHasUnsupportedResolution,
405 vid_w, vid_h, vidix_cap.minwidth, vidix_cap.minheight,
406 vidix_cap.maxwidth, vidix_cap.maxheight);
407 return -1;
410 err = 0;
411 switch(dest_bpp)
413 case 1: err = ((vidix_fourcc.depth & VID_DEPTH_1BPP) != VID_DEPTH_1BPP); break;
414 case 2: err = ((vidix_fourcc.depth & VID_DEPTH_2BPP) != VID_DEPTH_2BPP); break;
415 case 4: err = ((vidix_fourcc.depth & VID_DEPTH_4BPP) != VID_DEPTH_4BPP); break;
416 case 8: err = ((vidix_fourcc.depth & VID_DEPTH_8BPP) != VID_DEPTH_8BPP); break;
417 case 12:err = ((vidix_fourcc.depth & VID_DEPTH_12BPP) != VID_DEPTH_12BPP); break;
418 case 15:err = ((vidix_fourcc.depth & VID_DEPTH_15BPP) != VID_DEPTH_15BPP); break;
419 case 16:err = ((vidix_fourcc.depth & VID_DEPTH_16BPP) != VID_DEPTH_16BPP); break;
420 case 24:err = ((vidix_fourcc.depth & VID_DEPTH_24BPP) != VID_DEPTH_24BPP); break;
421 case 32:err = ((vidix_fourcc.depth & VID_DEPTH_32BPP) != VID_DEPTH_32BPP); break;
422 default: err=1; break;
424 if(err)
426 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_VideoServerHasUnsupportedColorDepth
427 ,vidix_fourcc.depth);
428 return -1;
430 if((dst_width > src_width || dst_height > src_height) && (vidix_cap.flags & FLAG_UPSCALER) != FLAG_UPSCALER)
432 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_DriverCantUpscaleImage,
433 src_width, src_height, dst_width, dst_height);
434 return -1;
436 if((dst_width > src_width || dst_height > src_height) && (vidix_cap.flags & FLAG_DOWNSCALER) != FLAG_DOWNSCALER)
438 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_DriverCantDownscaleImage,
439 src_width, src_height, dst_width, dst_height);
440 return -1;
442 image_width = src_width;
443 image_height = src_height;
444 src_format = format;
445 if(forced_fourcc) format = forced_fourcc;
446 memset(&vidix_play,0,sizeof(vidix_playback_t));
447 vidix_play.fourcc = format;
448 vidix_play.capability = vidix_cap.flags; /* every ;) */
449 vidix_play.blend_factor = 0; /* for now */
450 /* display the full picture.
451 Nick: we could implement here zooming to a specified area -- alex */
452 vidix_play.src.x = vidix_play.src.y = 0;
453 vidix_play.src.w = src_width;
454 vidix_play.src.h = src_height;
455 vidix_play.dest.x = x_org;
456 vidix_play.dest.y = y_org;
457 vidix_play.dest.w = dst_width;
458 vidix_play.dest.h = dst_height;
459 // vidix_play.num_frames=vo_doublebuffering?NUM_FRAMES-1:1;
460 /* we aren't mad...3 buffers are more than enough */
461 vidix_play.num_frames=vo_doublebuffering?3:1;
462 vidix_play.src.pitch.y = vidix_play.src.pitch.u = vidix_play.src.pitch.v = 0;
464 if((err=vdlConfigPlayback(vidix_handler,&vidix_play))!=0)
466 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CantConfigurePlayback,strerror(err));
467 return -1;
469 if ( mp_msg_test(MSGT_VO,MSGL_V) ) {
470 mp_msg(MSGT_VO,MSGL_V, "vosub_vidix: using %d buffer(s)\n", vidix_play.num_frames); }
472 vidix_mem = vidix_play.dga_addr;
474 tmp = calloc(image_width, image_height);
475 tmpa = malloc(image_width * image_height);
476 memset(tmpa, 1, image_width * image_height);
477 /* clear every frame with correct address and frame_size */
478 /* HACK: use draw_alpha to clear Y component */
479 for (i = 0; i < vidix_play.num_frames; i++) {
480 next_frame = i;
481 memset(vidix_mem + vidix_play.offsets[i], 0x80,
482 vidix_play.frame_size);
483 draw_alpha(0, 0, image_width, image_height, tmp, tmpa, image_width);
485 free(tmp);
486 free(tmpa);
487 /* show one of the "clear" frames */
488 vidix_flip_page();
490 switch(format)
492 case IMGFMT_NV12:
493 case IMGFMT_YV12:
494 case IMGFMT_I420:
495 case IMGFMT_IYUV:
496 case IMGFMT_YVU9:
497 case IMGFMT_IF09:
498 case IMGFMT_Y800:
499 case IMGFMT_Y8:
500 apitch = vidix_play.dest.pitch.y-1;
501 dstrides.y = (image_width + apitch) & ~apitch;
502 apitch = vidix_play.dest.pitch.v-1;
503 dstrides.v = (image_width + apitch) & ~apitch;
504 apitch = vidix_play.dest.pitch.u-1;
505 dstrides.u = (image_width + apitch) & ~apitch;
506 image_Bpp=1;
507 break;
508 case IMGFMT_RGB32:
509 case IMGFMT_BGR32:
510 apitch = vidix_play.dest.pitch.y-1;
511 dstrides.y = (image_width*4 + apitch) & ~apitch;
512 dstrides.u = dstrides.v = 0;
513 image_Bpp=4;
514 break;
515 case IMGFMT_RGB24:
516 case IMGFMT_BGR24:
517 apitch = vidix_play.dest.pitch.y-1;
518 dstrides.y = (image_width*3 + apitch) & ~apitch;
519 dstrides.u = dstrides.v = 0;
520 image_Bpp=3;
521 break;
522 default:
523 apitch = vidix_play.dest.pitch.y-1;
524 dstrides.y = (image_width*2 + apitch) & ~apitch;
525 dstrides.u = dstrides.v = 0;
526 image_Bpp=2;
527 break;
529 /* tune some info here */
530 sstride = src_width*image_Bpp;
531 if(!forced_fourcc)
533 is_422_planes_eq = sstride == dstrides.y;
535 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV)
536 vo_server->draw_slice = vidix_draw_slice_420;
537 else if (src_format == IMGFMT_YVU9 || src_format == IMGFMT_IF09)
538 vo_server->draw_slice = vidix_draw_slice_410;
539 else if (src_format == IMGFMT_NV12)
540 vo_server->draw_slice = vidix_draw_slice_nv12;
541 else vo_server->draw_slice = vidix_draw_slice_packed;
543 return 0;
546 static uint32_t vidix_get_image(mp_image_t *mpi)
548 if(mpi->type==MP_IMGTYPE_STATIC && vidix_play.num_frames>1) return VO_FALSE;
549 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; /* slow video ram */
550 if(( (mpi->stride[0]==dstrides.y && (!(mpi->flags&MP_IMGFLAG_PLANAR) ||
551 (mpi->stride[1]==dstrides.u && mpi->stride[2]==dstrides.v)) )
552 || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))) &&
553 (!forced_fourcc && !(vidix_play.flags & VID_PLAY_INTERLEAVED_UV)))
555 if(mpi->flags&MP_IMGFLAG_ACCEPT_WIDTH){
556 // check if only width is enough to represent strides:
557 if(mpi->flags&MP_IMGFLAG_PLANAR){
558 if((dstrides.y>>1)!=dstrides.v || dstrides.v!=dstrides.u) return VO_FALSE;
559 } else {
560 if(dstrides.y % (mpi->bpp/8)) return VO_FALSE;
563 mpi->planes[0]=vidix_mem+vidix_play.offsets[next_frame]+vidix_play.offset.y;
564 mpi->width=mpi->stride[0]=dstrides.y;
565 if(mpi->flags&MP_IMGFLAG_PLANAR)
567 mpi->planes[1]=vidix_mem+vidix_play.offsets[next_frame]+vidix_play.offset.v;
568 mpi->stride[1]=dstrides.v >> mpi->chroma_x_shift;
569 mpi->planes[2]=vidix_mem+vidix_play.offsets[next_frame]+vidix_play.offset.u;
570 mpi->stride[2]=dstrides.u >> mpi->chroma_x_shift;
571 } else
572 mpi->width/=mpi->bpp/8;
573 mpi->flags|=MP_IMGFLAG_DIRECT;
574 return VO_TRUE;
576 return VO_FALSE;
579 uint32_t vidix_control(uint32_t request, void *data, ...)
581 switch (request) {
582 case VOCTRL_QUERY_FORMAT:
583 return vidix_query_fourcc(*((uint32_t*)data));
584 case VOCTRL_GET_IMAGE:
585 return vidix_get_image(data);
586 case VOCTRL_DRAW_IMAGE:
587 return vidix_draw_image(data);
588 case VOCTRL_GET_FRAME_NUM:
589 *(uint32_t *)data = next_frame;
590 return VO_TRUE;
591 case VOCTRL_SET_FRAME_NUM:
592 next_frame = *(uint32_t *)data;
593 return VO_TRUE;
594 case VOCTRL_GET_NUM_FRAMES:
595 *(uint32_t *)data = vidix_play.num_frames;
596 return VO_TRUE;
597 case VOCTRL_SET_EQUALIZER:
599 va_list ap;
600 int value;
601 vidix_video_eq_t info;
603 if(!video_on) return VO_FALSE;
604 va_start(ap, data);
605 value = va_arg(ap, int);
606 va_end(ap);
608 // printf("vidix seteq %s -> %d \n",data,value);
610 /* vidix eq ranges are -1000..1000 */
611 if (!strcasecmp(data, "brightness"))
613 info.brightness = value*10;
614 info.cap = VEQ_CAP_BRIGHTNESS;
616 else if (!strcasecmp(data, "contrast"))
618 info.contrast = value*10;
619 info.cap = VEQ_CAP_CONTRAST;
621 else if (!strcasecmp(data, "saturation"))
623 info.saturation = value*10;
624 info.cap = VEQ_CAP_SATURATION;
626 else if (!strcasecmp(data, "hue"))
628 info.hue = value*10;
629 info.cap = VEQ_CAP_HUE;
632 if (vdlPlaybackSetEq(vidix_handler, &info) == 0)
633 return VO_TRUE;
634 return VO_FALSE;
636 case VOCTRL_GET_EQUALIZER:
638 va_list ap;
639 int *value;
640 vidix_video_eq_t info;
642 if(!video_on) return VO_FALSE;
643 if (vdlPlaybackGetEq(vidix_handler, &info) != 0)
644 return VO_FALSE;
646 va_start(ap, data);
647 value = va_arg(ap, int*);
648 va_end(ap);
650 /* vidix eq ranges are -1000..1000 */
651 if (!strcasecmp(data, "brightness"))
653 if (info.cap & VEQ_CAP_BRIGHTNESS)
654 *value = info.brightness/10;
656 else if (!strcasecmp(data, "contrast"))
658 if (info.cap & VEQ_CAP_CONTRAST)
659 *value = info.contrast/10;
661 else if (!strcasecmp(data, "saturation"))
663 if (info.cap & VEQ_CAP_SATURATION)
664 *value = info.saturation/10;
666 else if (!strcasecmp(data, "hue"))
668 if (info.cap & VEQ_CAP_HUE)
669 *value = info.hue/10;
672 return VO_TRUE;
675 return VO_NOTIMPL;
676 // WARNING: we drop extra parameters (...) here!
677 // return server_control(request,data); //VO_NOTIMPL;
680 int vidix_preinit(const char *drvname,vo_functions_t *server)
682 int err;
683 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
684 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_preinit(%s) was called\n",drvname); }
686 vidix_handler = vdlOpen(drvname ? drvname[0] == ':' ? &drvname[1] : drvname[0] ? drvname : NULL : NULL,
687 TYPE_OUTPUT,
688 verbose);
690 if(vidix_handler == NULL)
692 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CouldntFindWorkingVidixDriver);
693 return -1;
695 if((err=vdlGetCapability(vidix_handler,&vidix_cap)) != 0)
697 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CouldntGetCapability,strerror(err));
698 return -1;
700 mp_msg(MSGT_VO,MSGL_V, "[VO_SUB_VIDIX] Description: %s.\n", vidix_cap.name);
701 mp_msg(MSGT_VO,MSGL_V, "[VO_SUB_VIDIX] Author: %s.\n", vidix_cap.author);
702 /* we are able to tune up this stuff depend on fourcc format */
703 server->draw_slice=vidix_draw_slice;
704 server->draw_frame=vidix_draw_frame;
705 server->flip_page=vidix_flip_page;
706 server->draw_osd=vidix_draw_osd;
707 // server_control = server->control;
708 // server->control=vidix_control;
709 vo_server = server;
710 return 0;