Fix segfault if an 'strf' chunk couldn't be found in avi
[mplayer/glamo.git] / libvo / vosub_vidix.c
blob3ecce32f83d66afa346fcb73636567089ec87872
1 /*
2 * vosub_vidix.c
4 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - 2002
5 * Copyright (C) Alex Beregszaszi
7 * You can redistribute this file under terms and conditions
8 * of GNU General Public licence v2.
10 * This file contains vidix interface to any mplayer's VO plugin.
11 * (Partly based on vesa_lvo.c from mplayer's package)
14 #include <inttypes.h>
15 #include <unistd.h>
16 #include <fcntl.h>
17 #ifndef __MINGW32__
18 #include <sys/ioctl.h>
19 #include <sys/mman.h>
20 #endif
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <errno.h>
26 #include "config.h"
27 #include "mp_msg.h"
28 #include "help_mp.h"
30 #include "vosub_vidix.h"
31 #include "vidix/vidixlib.h"
32 #include "fastmemcpy.h"
33 #include "osd.h"
34 #include "video_out.h"
35 #include "sub.h"
37 #include "libmpcodecs/vfcap.h"
38 #include "libmpcodecs/mp_image.h"
40 #define NUM_FRAMES VID_PLAY_MAXFRAMES /* Temporary: driver will overwrite it */
42 static VDL_HANDLE vidix_handler = NULL;
43 static uint8_t *vidix_mem = NULL;
44 static uint8_t next_frame;
45 static unsigned image_Bpp,image_height,image_width,src_format,forced_fourcc=0;
46 static int video_on=0;
48 static vidix_capability_t vidix_cap;
49 static vidix_playback_t vidix_play;
50 static vidix_fourcc_t vidix_fourcc;
51 static vo_functions_t * vo_server;
52 static vidix_yuv_t dstrides;
53 /*static uint32_t (*server_control)(uint32_t request, void *data, ...);*/
55 static int vidix_get_video_eq(vidix_video_eq_t *info);
56 static int vidix_set_video_eq(const vidix_video_eq_t *info);
57 static int vidix_get_num_fx(unsigned *info);
58 static int vidix_get_oem_fx(vidix_oem_fx_t *info);
59 static int vidix_set_oem_fx(const vidix_oem_fx_t *info);
60 static int vidix_set_deint(const vidix_deinterlace_t *info);
62 int vidix_start(void)
64 int err;
65 if((err=vdlPlaybackOn(vidix_handler))!=0)
67 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CantStartPlayback,strerror(err));
68 return -1;
70 video_on=1;
71 return 0;
74 int vidix_stop(void)
76 int err;
77 if((err=vdlPlaybackOff(vidix_handler))!=0)
79 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CantStopPlayback,strerror(err));
80 return -1;
82 video_on=0;
83 return 0;
86 void vidix_term( void )
88 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
89 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_term() was called\n"); }
90 vidix_stop();
91 vdlClose(vidix_handler);
92 // ((vo_functions_t *)vo_server)->control=server_control;
95 static uint32_t vidix_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y)
97 uint8_t *src;
98 uint8_t *dest;
99 int i;
101 /* Plane Y */
102 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
103 dest += dstrides.y*y + x;
104 src = image[0];
105 for(i=0;i<h;i++){
106 memcpy(dest,src,w);
107 src+=stride[0];
108 dest += dstrides.y;
111 if (vidix_play.flags & VID_PLAY_INTERLEAVED_UV)
113 int hi,wi;
114 uint8_t *src2;
115 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.v;
116 dest += dstrides.y*y/2 + x; // <- is this correct ?
117 h/=2;
118 w/=2;
119 src = image[1];
120 src2 = image[2];
121 for(hi = 0; hi < h; hi++)
123 for(wi = 0; wi < w; wi++)
125 dest[2*wi+0] = src[wi];
126 dest[2*wi+1] = src2[wi];
128 dest += dstrides.y;
129 src += stride[1];
130 src2+= stride[2];
133 else
135 /* Plane V */
136 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.v;
137 dest += dstrides.v*y/4 + x;
138 src = image[1];
139 for(i=0;i<h/2;i++){
140 memcpy(dest,src,w/2);
141 src+=stride[1];
142 dest+=dstrides.v/2;
145 /* Plane U */
146 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.u;
147 dest += dstrides.u*y/4 + x;
148 src = image[2];
149 for(i=0;i<h/2;i++){
150 memcpy(dest,src,w/2);
151 src+=stride[2];
152 dest += dstrides.u/2;
154 return 0;
156 return -1;
159 static uint32_t vidix_draw_slice_410(uint8_t *image[], int stride[], int w,int h,int x,int y)
161 uint8_t *src;
162 uint8_t *dest;
163 int i;
165 /* Plane Y */
166 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
167 dest += dstrides.y*y + x;
168 src = image[0];
169 for(i=0;i<h;i++){
170 memcpy(dest,src,w);
171 src+=stride[0];
172 dest += dstrides.y;
175 if (vidix_play.flags & VID_PLAY_INTERLEAVED_UV)
177 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_SUB_VIDIX_InterleavedUvForYuv410pNotSupported);
179 else
181 /* Plane V */
182 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.v;
183 dest += dstrides.v*y/8 + x;
184 src = image[1];
185 for(i=0;i<h/4;i++){
186 memcpy(dest,src,w/4);
187 src+=stride[1];
188 dest+=dstrides.v/4;
191 /* Plane U */
192 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.u;
193 dest += dstrides.u*y/8 + x;
194 src = image[2];
195 for(i=0;i<h/4;i++){
196 memcpy(dest,src,w/4);
197 src+=stride[2];
198 dest += dstrides.u/4;
200 return 0;
202 return -1;
205 static uint32_t vidix_draw_slice_410_fast(uint8_t *image[], int stride[], int w, int h, int x, int y)
207 uint8_t *src;
208 uint8_t *dest;
210 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
211 dest += dstrides.y*y + x;
212 src = image[0];
213 memcpy(dest, src, dstrides.y*h*9/8);
214 return 0;
217 static uint32_t vidix_draw_slice_400(uint8_t *image[], int stride[], int w,int h,int x,int y)
219 uint8_t *src;
220 uint8_t *dest;
221 int i;
223 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
224 dest += dstrides.y*y + x;
225 src = image[0];
226 for(i=0;i<h;i++){
227 memcpy(dest,src,w);
228 src+=stride[0];
229 dest += dstrides.y;
231 return 0;
234 static uint32_t vidix_draw_slice_packed(uint8_t *image[], int stride[], int w,int h,int x,int y)
236 uint8_t *src;
237 uint8_t *dest;
238 int i;
240 dest = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
241 dest += dstrides.y*y + x;
242 src = image[0];
243 for(i=0;i<h;i++){
244 memcpy(dest,src,w*image_Bpp);
245 src+=stride[0];
246 dest += dstrides.y;
248 return 0;
251 uint32_t vidix_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y)
253 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_SUB_VIDIX_DummyVidixdrawsliceWasCalled);
254 return -1;
257 static uint32_t vidix_draw_image(mp_image_t *mpi){
258 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
259 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_draw_image() was called\n"); }
261 // if -dr or -slices then do nothing:
262 if(mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK)) return VO_TRUE;
264 vo_server->draw_slice(mpi->planes,mpi->stride,
265 vidix_play.src.w,vidix_play.src.h,vidix_play.src.x,vidix_play.src.y);
266 return VO_TRUE;
269 uint32_t vidix_draw_frame(uint8_t *image[])
271 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_SUB_VIDIX_DummyVidixdrawframeWasCalled);
272 return -1;
275 void vidix_flip_page(void)
277 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
278 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_flip_page() was called\n"); }
279 if(vo_doublebuffering)
281 vdlPlaybackFrameSelect(vidix_handler,next_frame);
282 next_frame=(next_frame+1)%vidix_play.num_frames;
286 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)
288 uint32_t apitch,bespitch;
289 void *lvo_mem;
290 lvo_mem = vidix_mem + vidix_play.offsets[next_frame] + vidix_play.offset.y;
291 apitch = vidix_play.dest.pitch.y-1;
292 switch(vidix_play.fourcc){
293 case IMGFMT_YV12:
294 case IMGFMT_IYUV:
295 case IMGFMT_I420:
296 case IMGFMT_YVU9:
297 case IMGFMT_IF09:
298 case IMGFMT_Y8:
299 case IMGFMT_Y800:
300 bespitch = (vidix_play.src.w + apitch) & (~apitch);
301 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch);
302 break;
303 case IMGFMT_YUY2:
304 bespitch = (vidix_play.src.w*2 + apitch) & (~apitch);
305 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+bespitch*y0+2*x0,bespitch);
306 break;
307 case IMGFMT_UYVY:
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+1,bespitch);
310 break;
311 case IMGFMT_RGB32:
312 case IMGFMT_BGR32:
313 bespitch = (vidix_play.src.w*4 + apitch) & (~apitch);
314 vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+y0*bespitch+4*x0,bespitch);
315 break;
316 case IMGFMT_RGB24:
317 case IMGFMT_BGR24:
318 bespitch = (vidix_play.src.w*3 + apitch) & (~apitch);
319 vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+y0*bespitch+3*x0,bespitch);
320 break;
321 case IMGFMT_RGB16:
322 case IMGFMT_BGR16:
323 bespitch = (vidix_play.src.w*2 + apitch) & (~apitch);
324 vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+y0*bespitch+2*x0,bespitch);
325 break;
326 case IMGFMT_RGB15:
327 case IMGFMT_BGR15:
328 bespitch = (vidix_play.src.w*2 + apitch) & (~apitch);
329 vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+y0*bespitch+2*x0,bespitch);
330 break;
331 default:
332 return;
336 void vidix_draw_osd(void)
338 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
339 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_draw_osd() was called\n"); }
340 /* TODO: hw support */
341 vo_draw_text(vidix_play.src.w,vidix_play.src.h,draw_alpha);
344 uint32_t vidix_query_fourcc(uint32_t format)
346 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
347 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: query_format was called: %x (%s)\n",format,vo_format_name(format)); }
348 vidix_fourcc.fourcc = format;
349 vdlQueryFourcc(vidix_handler,&vidix_fourcc);
350 if (vidix_fourcc.depth == VID_DEPTH_NONE)
351 return 0;
352 return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN|VFCAP_OSD|VFCAP_ACCEPT_STRIDE;
355 int vidix_grkey_support(void)
357 return(vidix_fourcc.flags & VID_CAP_COLORKEY);
360 int vidix_grkey_get(vidix_grkey_t *gr_key)
362 return(vdlGetGrKeys(vidix_handler, gr_key));
365 int vidix_grkey_set(const vidix_grkey_t *gr_key)
367 return(vdlSetGrKeys(vidix_handler, gr_key));
371 static int vidix_get_video_eq(vidix_video_eq_t *info)
373 if(!video_on) return EPERM;
374 return vdlPlaybackGetEq(vidix_handler, info);
377 static int vidix_set_video_eq(const vidix_video_eq_t *info)
379 if(!video_on) return EPERM;
380 return vdlPlaybackSetEq(vidix_handler, info);
383 static int vidix_get_num_fx(unsigned *info)
385 if(!video_on) return EPERM;
386 return vdlQueryNumOemEffects(vidix_handler, info);
389 static int vidix_get_oem_fx(vidix_oem_fx_t *info)
391 if(!video_on) return EPERM;
392 return vdlGetOemEffect(vidix_handler, info);
395 static int vidix_set_oem_fx(const vidix_oem_fx_t *info)
397 if(!video_on) return EPERM;
398 return vdlSetOemEffect(vidix_handler, info);
401 static int vidix_set_deint(const vidix_deinterlace_t *info)
403 if(!video_on) return EPERM;
404 return vdlPlaybackSetDeint(vidix_handler, info);
407 static int is_422_planes_eq=0;
408 int vidix_init(unsigned src_width,unsigned src_height,
409 unsigned x_org,unsigned y_org,unsigned dst_width,
410 unsigned dst_height,unsigned format,unsigned dest_bpp,
411 unsigned vid_w,unsigned vid_h)
413 void *tmp, *tmpa;
414 size_t i;
415 int err;
416 uint32_t sstride,apitch;
417 if( mp_msg_test(MSGT_VO,MSGL_DBG2) )
418 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_init() was called\n"
419 "src_w=%u src_h=%u dest_x_y_w_h = %u %u %u %u\n"
420 "format=%s dest_bpp=%u vid_w=%u vid_h=%u\n"
421 ,src_width,src_height,x_org,y_org,dst_width,dst_height
422 ,vo_format_name(format),dest_bpp,vid_w,vid_h);
424 if(vidix_query_fourcc(format) == 0)
426 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_UnsupportedFourccForThisVidixDriver,
427 format,vo_format_name(format));
428 return -1;
431 if(((vidix_cap.maxwidth != -1) && (vid_w > vidix_cap.maxwidth)) ||
432 ((vidix_cap.minwidth != -1) && (vid_w < vidix_cap.minwidth)) ||
433 ((vidix_cap.maxheight != -1) && (vid_h > vidix_cap.maxheight)) ||
434 ((vidix_cap.minwidth != -1 ) && (vid_h < vidix_cap.minheight)))
436 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_VideoServerHasUnsupportedResolution,
437 vid_w, vid_h, vidix_cap.minwidth, vidix_cap.minheight,
438 vidix_cap.maxwidth, vidix_cap.maxheight);
439 return -1;
442 err = 0;
443 switch(dest_bpp)
445 case 1: err = ((vidix_fourcc.depth & VID_DEPTH_1BPP) != VID_DEPTH_1BPP); break;
446 case 2: err = ((vidix_fourcc.depth & VID_DEPTH_2BPP) != VID_DEPTH_2BPP); break;
447 case 4: err = ((vidix_fourcc.depth & VID_DEPTH_4BPP) != VID_DEPTH_4BPP); break;
448 case 8: err = ((vidix_fourcc.depth & VID_DEPTH_8BPP) != VID_DEPTH_8BPP); break;
449 case 12:err = ((vidix_fourcc.depth & VID_DEPTH_12BPP) != VID_DEPTH_12BPP); break;
450 case 15:err = ((vidix_fourcc.depth & VID_DEPTH_15BPP) != VID_DEPTH_15BPP); break;
451 case 16:err = ((vidix_fourcc.depth & VID_DEPTH_16BPP) != VID_DEPTH_16BPP); break;
452 case 24:err = ((vidix_fourcc.depth & VID_DEPTH_24BPP) != VID_DEPTH_24BPP); break;
453 case 32:err = ((vidix_fourcc.depth & VID_DEPTH_32BPP) != VID_DEPTH_32BPP); break;
454 default: err=1; break;
456 if(err)
458 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_VideoServerHasUnsupportedColorDepth
459 ,vidix_fourcc.depth);
460 return -1;
462 if((dst_width > src_width || dst_height > src_height) && (vidix_cap.flags & FLAG_UPSCALER) != FLAG_UPSCALER)
464 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_DriverCantUpscaleImage,
465 src_width, src_height, dst_width, dst_height);
466 return -1;
468 if((dst_width > src_width || dst_height > src_height) && (vidix_cap.flags & FLAG_DOWNSCALER) != FLAG_DOWNSCALER)
470 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_DriverCantDownscaleImage,
471 src_width, src_height, dst_width, dst_height);
472 return -1;
474 image_width = src_width;
475 image_height = src_height;
476 src_format = format;
477 if(forced_fourcc) format = forced_fourcc;
478 memset(&vidix_play,0,sizeof(vidix_playback_t));
479 vidix_play.fourcc = format;
480 vidix_play.capability = vidix_cap.flags; /* every ;) */
481 vidix_play.blend_factor = 0; /* for now */
482 /* display the full picture.
483 Nick: we could implement here zooming to a specified area -- alex */
484 vidix_play.src.x = vidix_play.src.y = 0;
485 vidix_play.src.w = src_width;
486 vidix_play.src.h = src_height;
487 vidix_play.dest.x = x_org;
488 vidix_play.dest.y = y_org;
489 vidix_play.dest.w = dst_width;
490 vidix_play.dest.h = dst_height;
491 // vidix_play.num_frames=vo_doublebuffering?NUM_FRAMES-1:1;
492 /* we aren't mad...3 buffers are more than enough */
493 vidix_play.num_frames=vo_doublebuffering?3:1;
494 vidix_play.src.pitch.y = vidix_play.src.pitch.u = vidix_play.src.pitch.v = 0;
496 if((err=vdlConfigPlayback(vidix_handler,&vidix_play))!=0)
498 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CantConfigurePlayback,strerror(err));
499 return -1;
501 if ( mp_msg_test(MSGT_VO,MSGL_V) ) {
502 mp_msg(MSGT_VO,MSGL_V, "vosub_vidix: using %d buffer(s)\n", vidix_play.num_frames); }
504 vidix_mem = vidix_play.dga_addr;
506 tmp = calloc(image_width, image_height);
507 tmpa = malloc(image_width * image_height);
508 memset(tmpa, 1, image_width * image_height);
509 /* clear every frame with correct address and frame_size */
510 /* HACK: use draw_alpha to clear Y component */
511 for (i = 0; i < vidix_play.num_frames; i++) {
512 next_frame = i;
513 memset(vidix_mem + vidix_play.offsets[i], 0x80,
514 vidix_play.frame_size);
515 draw_alpha(0, 0, image_width, image_height, tmp, tmpa, image_width);
517 free(tmp);
518 free(tmpa);
519 /* show one of the "clear" frames */
520 vidix_flip_page();
522 switch(format)
524 case IMGFMT_YV12:
525 case IMGFMT_I420:
526 case IMGFMT_IYUV:
527 case IMGFMT_YVU9:
528 case IMGFMT_IF09:
529 case IMGFMT_Y800:
530 case IMGFMT_Y8:
531 apitch = vidix_play.dest.pitch.y-1;
532 dstrides.y = (image_width + apitch) & ~apitch;
533 apitch = vidix_play.dest.pitch.v-1;
534 dstrides.v = (image_width + apitch) & ~apitch;
535 apitch = vidix_play.dest.pitch.u-1;
536 dstrides.u = (image_width + apitch) & ~apitch;
537 image_Bpp=1;
538 break;
539 case IMGFMT_RGB32:
540 case IMGFMT_BGR32:
541 apitch = vidix_play.dest.pitch.y-1;
542 dstrides.y = (image_width*4 + apitch) & ~apitch;
543 dstrides.u = dstrides.v = 0;
544 image_Bpp=4;
545 break;
546 case IMGFMT_RGB24:
547 case IMGFMT_BGR24:
548 apitch = vidix_play.dest.pitch.y-1;
549 dstrides.y = (image_width*3 + apitch) & ~apitch;
550 dstrides.u = dstrides.v = 0;
551 image_Bpp=3;
552 break;
553 default:
554 apitch = vidix_play.dest.pitch.y-1;
555 dstrides.y = (image_width*2 + apitch) & ~apitch;
556 dstrides.u = dstrides.v = 0;
557 image_Bpp=2;
558 break;
560 /* tune some info here */
561 sstride = src_width*image_Bpp;
562 if(!forced_fourcc)
564 is_422_planes_eq = sstride == dstrides.y;
566 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV)
567 vo_server->draw_slice = vidix_draw_slice_420;
568 else if (src_format == IMGFMT_YVU9 || src_format == IMGFMT_IF09)
569 vo_server->draw_slice = vidix_draw_slice_410;
570 else vo_server->draw_slice = vidix_draw_slice_packed;
572 return 0;
575 static uint32_t vidix_get_image(mp_image_t *mpi)
577 if(mpi->type==MP_IMGTYPE_STATIC && vidix_play.num_frames>1) return VO_FALSE;
578 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; /* slow video ram */
579 if(( (mpi->stride[0]==dstrides.y && (!(mpi->flags&MP_IMGFLAG_PLANAR) ||
580 (mpi->stride[1]==dstrides.u && mpi->stride[2]==dstrides.v)) )
581 || (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))) &&
582 (!forced_fourcc && !(vidix_play.flags & VID_PLAY_INTERLEAVED_UV)))
584 if(mpi->flags&MP_IMGFLAG_ACCEPT_WIDTH){
585 // check if only width is enough to represent strides:
586 if(mpi->flags&MP_IMGFLAG_PLANAR){
587 if((dstrides.y>>1)!=dstrides.v || dstrides.v!=dstrides.u) return VO_FALSE;
588 } else {
589 if(dstrides.y % (mpi->bpp/8)) return VO_FALSE;
592 mpi->planes[0]=vidix_mem+vidix_play.offsets[next_frame]+vidix_play.offset.y;
593 mpi->width=mpi->stride[0]=dstrides.y;
594 if(mpi->flags&MP_IMGFLAG_PLANAR)
596 mpi->planes[1]=vidix_mem+vidix_play.offsets[next_frame]+vidix_play.offset.v;
597 mpi->stride[1]=dstrides.v >> mpi->chroma_x_shift;
598 mpi->planes[2]=vidix_mem+vidix_play.offsets[next_frame]+vidix_play.offset.u;
599 mpi->stride[2]=dstrides.u >> mpi->chroma_x_shift;
600 } else
601 mpi->width/=mpi->bpp/8;
602 mpi->flags|=MP_IMGFLAG_DIRECT;
603 return VO_TRUE;
605 return VO_FALSE;
608 uint32_t vidix_control(uint32_t request, void *data, ...)
610 switch (request) {
611 case VOCTRL_QUERY_FORMAT:
612 return vidix_query_fourcc(*((uint32_t*)data));
613 case VOCTRL_GET_IMAGE:
614 return vidix_get_image(data);
615 case VOCTRL_DRAW_IMAGE:
616 return vidix_draw_image(data);
617 case VOCTRL_GET_FRAME_NUM:
618 *(uint32_t *)data = next_frame;
619 return VO_TRUE;
620 case VOCTRL_SET_FRAME_NUM:
621 next_frame = *(uint32_t *)data;
622 return VO_TRUE;
623 case VOCTRL_GET_NUM_FRAMES:
624 *(uint32_t *)data = vidix_play.num_frames;
625 return VO_TRUE;
626 case VOCTRL_SET_EQUALIZER:
628 va_list ap;
629 int value;
630 vidix_video_eq_t info;
632 if(!video_on) return VO_FALSE;
633 va_start(ap, data);
634 value = va_arg(ap, int);
635 va_end(ap);
637 // printf("vidix seteq %s -> %d \n",data,value);
639 /* vidix eq ranges are -1000..1000 */
640 if (!strcasecmp(data, "brightness"))
642 info.brightness = value*10;
643 info.cap = VEQ_CAP_BRIGHTNESS;
645 else if (!strcasecmp(data, "contrast"))
647 info.contrast = value*10;
648 info.cap = VEQ_CAP_CONTRAST;
650 else if (!strcasecmp(data, "saturation"))
652 info.saturation = value*10;
653 info.cap = VEQ_CAP_SATURATION;
655 else if (!strcasecmp(data, "hue"))
657 info.hue = value*10;
658 info.cap = VEQ_CAP_HUE;
661 if (vdlPlaybackSetEq(vidix_handler, &info) == 0)
662 return VO_TRUE;
663 return VO_FALSE;
665 case VOCTRL_GET_EQUALIZER:
667 va_list ap;
668 int *value;
669 vidix_video_eq_t info;
671 if(!video_on) return VO_FALSE;
672 if (vdlPlaybackGetEq(vidix_handler, &info) != 0)
673 return VO_FALSE;
675 va_start(ap, data);
676 value = va_arg(ap, int*);
677 va_end(ap);
679 /* vidix eq ranges are -1000..1000 */
680 if (!strcasecmp(data, "brightness"))
682 if (info.cap & VEQ_CAP_BRIGHTNESS)
683 *value = info.brightness/10;
685 else if (!strcasecmp(data, "contrast"))
687 if (info.cap & VEQ_CAP_CONTRAST)
688 *value = info.contrast/10;
690 else if (!strcasecmp(data, "saturation"))
692 if (info.cap & VEQ_CAP_SATURATION)
693 *value = info.saturation/10;
695 else if (!strcasecmp(data, "hue"))
697 if (info.cap & VEQ_CAP_HUE)
698 *value = info.hue/10;
701 return VO_TRUE;
704 return VO_NOTIMPL;
705 // WARNING: we drop extra parameters (...) here!
706 // return server_control(request,data); //VO_NOTIMPL;
709 int vidix_preinit(const char *drvname,void *server)
711 int err;
712 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) {
713 mp_msg(MSGT_VO,MSGL_DBG2, "vosub_vidix: vidix_preinit(%s) was called\n",drvname); }
714 if(vdlGetVersion() != VIDIX_VERSION)
716 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_YouHaveWrongVersionOfVidixLibrary);
717 return -1;
719 #ifndef __MINGW32__
720 vidix_handler = vdlOpen(MP_VIDIX_PFX,
721 drvname ? drvname[0] == ':' ? &drvname[1] : drvname[0] ? drvname : NULL : NULL,
722 TYPE_OUTPUT,
723 verbose);
724 #else
725 vidix_handler = vdlOpen(get_path("vidix/"),
726 drvname ? drvname[0] == ':' ? &drvname[1] : drvname[0] ? drvname : NULL : NULL,
727 TYPE_OUTPUT,
728 verbose);
729 #endif
731 if(vidix_handler == NULL)
733 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CouldntFindWorkingVidixDriver);
734 return -1;
736 if((err=vdlGetCapability(vidix_handler,&vidix_cap)) != 0)
738 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SUB_VIDIX_CouldntGetCapability,strerror(err));
739 return -1;
741 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SUB_VIDIX_Description, vidix_cap.name);
742 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SUB_VIDIX_Author, vidix_cap.author);
743 /* we are able to tune up this stuff depend on fourcc format */
744 ((vo_functions_t *)server)->draw_slice=vidix_draw_slice;
745 ((vo_functions_t *)server)->draw_frame=vidix_draw_frame;
746 ((vo_functions_t *)server)->flip_page=vidix_flip_page;
747 ((vo_functions_t *)server)->draw_osd=vidix_draw_osd;
748 // server_control = ((vo_functions_t *)server)->control;
749 // ((vo_functions_t *)server)->control=vidix_control;
750 vo_server = server;
751 return 0;