2 * XAnim Video Codec DLL support
4 * It partly emulates the Xanim codebase.
5 * You need the -rdynamic flag to use this with gcc.
7 * Copyright (C) 2001-2002 Alex Beregszaszi
8 * Arpad Gereoffy <arpi@thot.banki.hu>
10 * This file is part of MPlayer.
12 * MPlayer is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * MPlayer is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <string.h> /* strerror */
35 #include "vd_internal.h"
37 static const vd_info_t info
= {
41 "Xanim (http://xanim.va.pubnix.com/)",
42 "binary codec plugins"
51 #include <dlfcn.h> /* dlsym, dlopen, dlclose */
52 #include <stdarg.h> /* va_alist, va_start, va_end */
53 #include <errno.h> /* strerror, errno */
58 #include "osdep/timer.h"
61 /* this should be removed */
69 #define RLTD_GLOBAL 256
77 int (*iq_func
)(); /* init/query function */
78 unsigned int (*dec_func
)(); /* opt decode function */
81 #define XAVID_WHAT_NO_MORE 0x0000
82 #define XAVID_AVI_QUERY 0x0001
83 #define XAVID_QT_QUERY 0x0002
84 #define XAVID_DEC_FUNC 0x0100
86 #define XAVID_API_REV 0x0003
96 unsigned int num_funcs
;
97 XAVID_FUNC_HDR
*funcs
;
104 unsigned int compression
;
108 unsigned int xapi_rev
;
109 unsigned int (*decoder
)();
111 unsigned int avi_ctab_flag
;
112 unsigned int (*avi_read_ext
)();
115 #define CODEC_SUPPORTED 1
116 #define CODEC_UNKNOWN 0
117 #define CODEC_UNSUPPORTED -1
119 /* fuckin colormap structures for xanim */
123 unsigned short green
;
128 typedef struct XA_ACTION_STRUCT
133 struct XA_ACTION_STRUCT
*next
;
134 struct XA_CHDR_STRUCT
*chdr
;
137 struct XA_ACTION_STRUCT
*next_same_chdr
;
140 typedef struct XA_CHDR_STRUCT
144 unsigned int csize
, coff
;
146 unsigned int msize
, moff
;
147 struct XA_CHDR_STRUCT
*next
;
149 struct XA_CHDR_STRUCT
*new_chdr
;
155 unsigned int skip_flag
;
156 unsigned int imagex
, imagey
; /* image buffer size */
157 unsigned int imaged
; /* image depth */
158 XA_CHDR
*chdr
; /* color map header */
159 unsigned int map_flag
;
163 unsigned int special
;
169 unsigned int file_num
;
170 unsigned int anim_type
;
178 XA_DEC_INFO
*decinfo
;
180 long (*iq_func
)(XA_CODEC_HDR
*codec_hdr
);
181 unsigned int (*dec_func
)(unsigned char *image
, unsigned char *delta
,
182 unsigned int dsize
, XA_DEC_INFO
*dec_info
);
188 typedef short xaSHORT
;
191 typedef unsigned char xaUBYTE
;
192 typedef unsigned short xaUSHORT
;
193 typedef unsigned int xaULONG
;
199 #define ACT_DLTA_NORM 0x00000000
200 #define ACT_DLTA_BODY 0x00000001
201 #define ACT_DLTA_XOR 0x00000002
202 #define ACT_DLTA_NOP 0x00000004
203 #define ACT_DLTA_MAPD 0x00000008
204 #define ACT_DLTA_DROP 0x00000010
205 #define ACT_DLTA_BAD 0x80000000
207 #define XA_CLOSE_FUNCS 5
208 int xa_close_funcs
= 0;
209 void *xa_close_func
[XA_CLOSE_FUNCS
];
211 /* load, init and query */
212 static int xacodec_load(sh_video_t
*sh
, char *filename
)
214 vd_xanim_ctx
*priv
= sh
->context
;
217 XAVID_MOD_HDR
*mod_hdr
;
218 XAVID_FUNC_HDR
*func
;
221 // priv->file_handler = dlopen(filename, RTLD_NOW|RTLD_GLOBAL);
222 priv
->file_handler
= dlopen(filename
, RTLD_LAZY
);
223 if (!priv
->file_handler
)
227 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: failed to dlopen %s while %s\n", filename
, error
);
229 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: failed to dlopen %s\n", filename
);
233 what_the
= dlsym(priv
->file_handler
, "What_The");
234 if ((error
= dlerror()) != NULL
)
236 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: failed to init %s while %s\n", filename
, error
);
237 dlclose(priv
->file_handler
);
241 mod_hdr
= what_the();
244 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: initializer function failed in %s\n", filename
);
245 dlclose(priv
->file_handler
);
249 mp_msg(MSGT_DECVIDEO
, MSGL_V
, "=== XAnim Codec ===\n");
250 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " Filename: %s (API revision: %x)\n", filename
, mod_hdr
->api_rev
);
251 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " Codec: %s. Rev: %s\n", mod_hdr
->desc
, mod_hdr
->rev
);
252 if (mod_hdr
->copyright
)
253 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " %s\n", mod_hdr
->copyright
);
254 if (mod_hdr
->mod_author
)
255 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " Module Author(s): %s\n", mod_hdr
->mod_author
);
256 if (mod_hdr
->authors
)
257 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " Codec Author(s): %s\n", mod_hdr
->authors
);
259 if (mod_hdr
->api_rev
> XAVID_API_REV
)
261 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: not supported api revision (%d) in %s\n",
262 mod_hdr
->api_rev
, filename
);
263 dlclose(priv
->file_handler
);
267 func
= mod_hdr
->funcs
;
270 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: function table error in %s\n", filename
);
271 dlclose(priv
->file_handler
);
275 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "Exported functions by codec: [functable: %p entries: %d]\n",
276 mod_hdr
->funcs
, mod_hdr
->num_funcs
);
277 for (i
= 0; i
< (int)mod_hdr
->num_funcs
; i
++)
279 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, " %d: %d %d [iq:%p d:%p]\n",
280 i
, func
[i
].what
, func
[i
].id
, func
[i
].iq_func
, func
[i
].dec_func
);
281 if (func
[i
].what
& XAVID_AVI_QUERY
)
283 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, " %p: avi init/query func (id: %d)\n",
284 func
[i
].iq_func
, func
[i
].id
);
285 priv
->iq_func
= (void *)func
[i
].iq_func
;
287 if (func
[i
].what
& XAVID_QT_QUERY
)
289 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, " %p: qt init/query func (id: %d)\n",
290 func
[i
].iq_func
, func
[i
].id
);
291 priv
->iq_func
= (void *)func
[i
].iq_func
;
293 if (func
[i
].what
& XAVID_DEC_FUNC
)
295 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, " %p: decoder func (init/query: %p) (id: %d)\n",
296 func
[i
].dec_func
, func
[i
].iq_func
, func
[i
].id
);
297 priv
->dec_func
= (void *)func
[i
].dec_func
;
303 static int xacodec_query(sh_video_t
*sh
, XA_CODEC_HDR
*codec_hdr
)
305 vd_xanim_ctx
*priv
= sh
->context
;
312 codec_hdr
->decoder
= priv
->dec_func
;
313 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "We got decoder's address at init! %p\n", codec_hdr
->decoder
);
318 ret
= priv
->iq_func(codec_hdr
);
321 case CODEC_SUPPORTED
:
322 priv
->dec_func
= (void *)codec_hdr
->decoder
;
323 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "Codec is supported: found decoder for %s at %p\n",
324 codec_hdr
->description
, codec_hdr
->decoder
);
326 case CODEC_UNSUPPORTED
:
327 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "Codec (%s) is unsupported by dll\n",
328 codec_hdr
->description
);
332 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "Codec (%s) is unknown by dll\n",
333 codec_hdr
->description
);
338 /* These functions are required for loading XAnim binary libs.
339 * Add forward declarations to avoid warnings with -Wmissing-prototypes. */
340 void XA_Print(char *fmt
, ...);
341 void TheEnd1(char *err_mess
);
342 void XA_Add_Func_To_Free_Chain(XA_ANIM_HDR
*anim_hdr
, void (*function
)());
343 unsigned long XA_Time_Read(void);
344 void XA_Gen_YUV_Tabs(XA_ANIM_HDR
*anim_hdr
);
345 void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR
*anim_hdr
);
346 void JPG_Alloc_MCU_Bufs(XA_ANIM_HDR
*anim_hdr
, unsigned int width
,
347 unsigned int height
, unsigned int full_flag
);
348 void *YUV2x2_Blk_Func(unsigned int image_type
, int blks
,
349 unsigned int dith_flag
);
350 void *YUV2x2_Map_Func(unsigned int image_type
, unsigned int dith_type
);
351 void *XA_YUV1611_Func(unsigned int image_type
);
352 void *XA_YUV221111_Func(unsigned int image_type
);
354 void XA_Print(char *fmt
, ...)
359 va_start(vallist
, fmt
);
360 vsnprintf(buf
, 1024, fmt
, vallist
);
361 mp_msg(MSGT_XACODEC
, MSGL_DBG2
, "[xacodec] %s\n", buf
);
367 /* 0 is no debug (needed by 3ivX) */
370 void TheEnd1(char *err_mess
)
372 XA_Print("error: %s - exiting\n", err_mess
);
373 /* we should exit here... */
378 void XA_Add_Func_To_Free_Chain(XA_ANIM_HDR
*anim_hdr
, void (*function
)())
380 // XA_Print("XA_Add_Func_To_Free_Chain('anim_hdr: %08x', 'function: %08x')",
381 // anim_hdr, function);
382 xa_close_func
[xa_close_funcs
] = function
;
383 if (xa_close_funcs
+1 < XA_CLOSE_FUNCS
)
389 unsigned long XA_Time_Read(void)
391 return GetTimer(); //(GetRelativeTime());
394 static void XA_dummy(void)
396 XA_Print("dummy() called");
399 void XA_Gen_YUV_Tabs(XA_ANIM_HDR
*anim_hdr
)
401 XA_Print("XA_Gen_YUV_Tabs('anim_hdr: %08x')", anim_hdr
);
405 void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR
*anim_hdr
)
407 XA_Print("JPG_Setup_Samp_Limit_Table('anim_hdr: %08x')", anim_hdr
);
411 void JPG_Alloc_MCU_Bufs(XA_ANIM_HDR
*anim_hdr
, unsigned int width
,
412 unsigned int height
, unsigned int full_flag
)
414 XA_Print("JPG_Alloc_MCU_Bufs('anim_hdr: %08x', 'width: %d', 'height: %d', 'full_flag: %d')",
415 anim_hdr
, width
, height
, full_flag
);
419 /* --------------- 4x4 pixel YUV block fillers [CVID] ----------------- */
423 unsigned char r0
, g0
, b0
;
424 unsigned char r1
, g1
, b1
;
425 unsigned char r2
, g2
, b2
;
426 unsigned char r3
, g3
, b3
;
427 unsigned int clr0_0
, clr0_1
, clr0_2
, clr0_3
;
428 unsigned int clr1_0
, clr1_1
, clr1_2
, clr1_3
;
429 unsigned int clr2_0
, clr2_1
, clr2_2
, clr2_3
;
430 unsigned int clr3_0
, clr3_1
, clr3_2
, clr3_3
;
433 #define SET_4_YUV_PIXELS(image,x,y,cmap2x2) \
434 image->planes[0][((x)+0)+((y)+0)*image->stride[0]]=cmap2x2->clr0_0;\
435 image->planes[0][((x)+1)+((y)+0)*image->stride[0]]=cmap2x2->clr0_1;\
436 image->planes[0][((x)+0)+((y)+1)*image->stride[0]]=cmap2x2->clr0_2;\
437 image->planes[0][((x)+1)+((y)+1)*image->stride[0]]=cmap2x2->clr0_3;\
438 image->planes[1][((x)>>1)+((y)>>1)*image->stride[1]]=cmap2x2->clr1_0;\
439 image->planes[2][((x)>>1)+((y)>>1)*image->stride[2]]=cmap2x2->clr1_1;
441 static void XA_2x2_OUT_1BLK_Convert(unsigned char *image_p
, unsigned int x
, unsigned int y
,
442 unsigned int imagex
, XA_2x2_Color
*cmap2x2
)
444 mp_image_t
*mpi
= (mp_image_t
*)image_p
;
447 SET_4_YUV_PIXELS(mpi
,x
,y
,cmap2x2
)
449 SET_4_YUV_PIXELS(mpi
,x
,y
,cmap2x2
)
450 SET_4_YUV_PIXELS(mpi
,x
+2,y
,cmap2x2
)
451 SET_4_YUV_PIXELS(mpi
,x
,y
+2,cmap2x2
)
452 SET_4_YUV_PIXELS(mpi
,x
+2,y
+2,cmap2x2
)
458 static void XA_2x2_OUT_4BLKS_Convert(unsigned char *image_p
, unsigned int x
, unsigned int y
,
459 unsigned int imagex
, XA_2x2_Color
*cm0
, XA_2x2_Color
*cm1
, XA_2x2_Color
*cm2
,
462 mp_image_t
*mpi
= (mp_image_t
*)image_p
;
464 SET_4_YUV_PIXELS(mpi
,x
,y
,cm0
)
465 SET_4_YUV_PIXELS(mpi
,x
+2,y
,cm1
)
466 SET_4_YUV_PIXELS(mpi
,x
,y
+2,cm2
)
467 SET_4_YUV_PIXELS(mpi
,x
+2,y
+2,cm3
)
471 void *YUV2x2_Blk_Func(unsigned int image_type
, int blks
, unsigned int dith_flag
)
473 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
, "YUV2x2_Blk_Func(image_type=%d, blks=%d, dith_flag=%d)\n",
474 image_type
, blks
, dith_flag
);
477 return (void*) XA_2x2_OUT_1BLK_Convert
;
479 return (void*) XA_2x2_OUT_4BLKS_Convert
;
482 mp_msg(MSGT_DECVIDEO
,MSGL_WARN
,"Unimplemented: YUV2x2_Blk_Func(image_type=%d blks=%d dith=%d)\n",image_type
,blks
,dith_flag
);
483 return (void*) XA_dummy
;
486 // Take Four Y's and UV and put them into a 2x2 Color structure.
488 static void XA_YUV_2x2_clr(XA_2x2_Color
*cmap2x2
, unsigned int Y0
, unsigned int Y1
,
489 unsigned int Y2
, unsigned int Y3
, unsigned int U
, unsigned int V
,
490 unsigned int map_flag
, unsigned int *map
, XA_CHDR
*chdr
)
493 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "XA_YUV_2x2_clr(%p [%d,%d,%d,%d][%d][%d] %d %p %p)\n",
494 cmap2x2
,Y0
,Y1
,Y2
,Y3
,U
,V
,map_flag
,map
,chdr
);
505 void *YUV2x2_Map_Func(unsigned int image_type
, unsigned int dith_type
)
507 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
, "YUV2x2_Map_Func('image_type: %d', 'dith_type: %d')",
508 image_type
, dith_type
);
509 return (void*)XA_YUV_2x2_clr
;
512 /* -------------------- whole YUV frame converters ------------------------- */
519 unsigned char *the_buf
;
520 unsigned int the_buf_size
;
521 unsigned short y_w
, y_h
;
522 unsigned short uv_w
, uv_h
;
527 unsigned long Uskip_mask
;
536 YUVTabs def_yuv_tabs
;
538 /* -------------- YUV 4x4 1x1 1x1 (4:1:0 aka YVU9) [Indeo 3,4,5] ------------------ */
540 static void XA_YUV1611_Convert(unsigned char *image_p
, unsigned int imagex
, unsigned int imagey
,
541 unsigned int i_x
, unsigned int i_y
, YUVBufs
*yuv
, YUVTabs
*yuv_tabs
,
542 unsigned int map_flag
, unsigned int *map
, XA_CHDR
*chdr
)
544 sh_video_t
*sh
= (sh_video_t
*)image_p
;
545 vd_xanim_ctx
*priv
= sh
->context
;
548 int ystride
=(yuv
->y_w
)?yuv
->y_w
:imagex
;
549 int uvstride
=(yuv
->uv_w
)?yuv
->uv_w
:(imagex
/4);
551 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "YUVTabs: %d %p %p %p %p %p\n",yuv_tabs
->Uskip_mask
,
553 yuv_tabs
->YUV_UB_tab
,
554 yuv_tabs
->YUV_VR_tab
,
555 yuv_tabs
->YUV_UG_tab
,
556 yuv_tabs
->YUV_VG_tab
);
558 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "XA_YUV1611_Convert('image: %08x', 'imagex: %d', 'imagey: %d', 'i_x: %d', 'i_y: %d', 'yuv_bufs: %08x', 'yuv_tabs: %08x', 'map_flag: %d', 'map: %08x', 'chdr: %08x')",
559 image_p
, imagex
, imagey
, i_x
, i_y
, yuv
, yuv_tabs
, map_flag
, map
, chdr
);
561 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "YUV: %p %p %p %X (%d) %dx%d %dx%d\n",
562 yuv
->Ybuf
,yuv
->Ubuf
,yuv
->Vbuf
,yuv
->the_buf
,yuv
->the_buf_size
,
563 yuv
->y_w
,yuv
->y_h
,yuv
->uv_w
,yuv
->uv_h
);
565 if(!yuv_tabs
->YUV_Y_tab
){
566 // standard YVU9 - simply export it!
567 mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_EXPORT
, 0,
568 sh
->disp_w
, sh
->disp_h
);
569 priv
->mpi
=mpi
; if(!mpi
) return; // ERROR!
570 mpi
->planes
[0]=yuv
->Ybuf
;
571 mpi
->planes
[1]=yuv
->Ubuf
;
572 mpi
->planes
[2]=yuv
->Vbuf
;
574 mpi
->stride
[0]=ystride
; //i_x; // yuv->y_w
575 mpi
->stride
[1]=mpi
->stride
[2]=uvstride
; //i_x/4; // yuv->uv_w
579 // allocate TEMP buffer and convert the image:
580 mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
581 sh
->disp_w
, sh
->disp_h
);
582 priv
->mpi
=mpi
; if(!mpi
) return; // ERROR!
584 // convert the Y plane:
585 for(y
=0;y
<(int)imagey
;y
++){
587 unsigned char* s
=yuv
->Ybuf
+ystride
*y
;
588 unsigned char* d
=mpi
->planes
[0]+mpi
->stride
[0]*y
;
589 for(x
=0;x
<imagex
;x
++) d
[x
]=s
[x
]<<1;
595 // convert the U plane:
596 for(y
=0;y
<(int)imagey
;y
++){
598 unsigned char* s
=yuv
->Ubuf
+uvstride
*y
;
599 unsigned char* d
=mpi
->planes
[1]+mpi
->stride
[1]*y
;
600 for(x
=0;x
<imagex
;x
++) d
[x
]=s
[x
]<<1;
603 // convert the V plane:
604 for(y
=0;y
<(int)imagey
;y
++){
606 unsigned char* s
=yuv
->Vbuf
+uvstride
*y
;
607 unsigned char* d
=mpi
->planes
[2]+mpi
->stride
[2]*y
;
608 for(x
=0;x
<imagex
;x
++) d
[x
]=s
[x
]<<1;
612 void *XA_YUV1611_Func(unsigned int image_type
)
614 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
, "XA_YUV1611_Func('image_type: %d')", image_type
);
615 return (void *)XA_YUV1611_Convert
;
618 /* --------------- YUV 2x2 1x1 1x1 (4:2:0 aka YV12) [3ivX,H263] ------------ */
620 static void XA_YUV221111_Convert(unsigned char *image_p
, unsigned int imagex
, unsigned int imagey
,
621 unsigned int i_x
, unsigned int i_y
, YUVBufs
*yuv
, YUVTabs
*yuv_tabs
, unsigned int map_flag
,
622 unsigned int *map
, XA_CHDR
*chdr
)
624 sh_video_t
*sh
= (sh_video_t
*)image_p
;
625 vd_xanim_ctx
*priv
= sh
->context
;
627 // note: 3ivX codec doesn't set y_w, uv_w, they are random junk :(
628 int ystride
=imagex
; //(yuv->y_w)?yuv->y_w:imagex;
629 int uvstride
=imagex
/2; //(yuv->uv_w)?yuv->uv_w:(imagex/2);
631 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "XA_YUV221111_Convert(%p %dx%d %d;%d [%dx%d] %p %p %d %p %p)\n",
632 image_p
,imagex
,imagey
,i_x
,i_y
, sh
->disp_w
, sh
->disp_h
,
633 yuv
,yuv_tabs
,map_flag
,map
,chdr
);
635 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "YUV: %p %p %p %X (%X) %Xx%X %Xx%X\n",
636 yuv
->Ybuf
,yuv
->Ubuf
,yuv
->Vbuf
,yuv
->the_buf
,yuv
->the_buf_size
,
637 yuv
->y_w
,yuv
->y_h
,yuv
->uv_w
,yuv
->uv_h
);
639 // standard YV12 - simply export it!
640 mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_EXPORT
, 0, sh
->disp_w
, sh
->disp_h
);
641 priv
->mpi
=mpi
; if(!mpi
) return; // ERROR!
642 mpi
->planes
[0]=yuv
->Ybuf
;
643 mpi
->planes
[1]=yuv
->Ubuf
;
644 mpi
->planes
[2]=yuv
->Vbuf
;
646 mpi
->stride
[0]=ystride
; //i_x; // yuv->y_w
647 mpi
->stride
[1]=mpi
->stride
[2]=uvstride
; //=i_x/4; // yuv->uv_w
650 void *XA_YUV221111_Func(unsigned int image_type
)
652 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
, "XA_YUV221111_Func('image_type: %d')\n",image_type
);
653 return (void *)XA_YUV221111_Convert
;
656 /* *** EOF XANIM *** */
658 // to set/get/query special features/parameters
659 static int control(sh_video_t
*sh
,int cmd
,void* arg
,...){
660 return CONTROL_UNKNOWN
;
664 static int init(sh_video_t
*sh
)
667 char *def_path
= XACODEC_PATH
;
669 XA_CODEC_HDR codec_hdr
;
672 priv
= malloc(sizeof(vd_xanim_ctx
));
676 memset(priv
, 0, sizeof(vd_xanim_ctx
));
678 if(!mpcodecs_config_vo(sh
,sh
->disp_w
,sh
->disp_h
,IMGFMT_YV12
)) return 0;
680 priv
->iq_func
= NULL
;
681 priv
->dec_func
= NULL
;
683 for (i
=0; i
< XA_CLOSE_FUNCS
; i
++)
684 xa_close_func
[i
] = NULL
;
686 if (getenv("XANIM_MOD_DIR"))
687 def_path
= getenv("XANIM_MOD_DIR");
689 snprintf(dll
, 1024, "%s/%s", def_path
, sh
->codec
->dll
);
690 if (xacodec_load(sh
, dll
) == 0)
693 codec_hdr
.xapi_rev
= XAVID_API_REV
;
694 codec_hdr
.anim_hdr
= malloc(4096);
695 codec_hdr
.description
= sh
->codec
->info
;
696 codec_hdr
.compression
= bswap_32(sh
->bih
->biCompression
);
697 codec_hdr
.decoder
= NULL
;
698 codec_hdr
.x
= sh
->bih
->biWidth
; /* ->disp_w */
699 codec_hdr
.y
= sh
->bih
->biHeight
; /* ->disp_h */
700 /* extra fields to store palette */
701 codec_hdr
.avi_ctab_flag
= 0;
702 codec_hdr
.avi_read_ext
= NULL
;
703 codec_hdr
.extra
= NULL
;
705 switch(sh
->codec
->outfmt
[sh
->outfmtidx
])
708 codec_hdr
.depth
= 32;
711 codec_hdr
.depth
= 24;
716 codec_hdr
.depth
= 12;
722 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: not supported image out format (%s)\n",
723 vo_format_name(sh
->codec
->outfmt
[sh
->outfmtidx
]));
726 mp_msg(MSGT_DECVIDEO
, MSGL_INFO
, "xacodec: querying for input %dx%d %dbit [fourcc: %4x] (%s)...\n",
727 codec_hdr
.x
, codec_hdr
.y
, codec_hdr
.depth
, codec_hdr
.compression
, codec_hdr
.description
);
729 if (xacodec_query(sh
, &codec_hdr
) == 0)
732 // free(codec_hdr.anim_hdr);
734 priv
->decinfo
= malloc(sizeof(XA_DEC_INFO
));
735 if (priv
->decinfo
== NULL
)
737 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: memory allocation error: %s\n",
741 priv
->decinfo
->cmd
= 0;
742 priv
->decinfo
->skip_flag
= 0;
743 priv
->decinfo
->imagex
= priv
->decinfo
->xe
= codec_hdr
.x
;
744 priv
->decinfo
->imagey
= priv
->decinfo
->ye
= codec_hdr
.y
;
745 priv
->decinfo
->imaged
= codec_hdr
.depth
;
746 priv
->decinfo
->chdr
= NULL
;
747 priv
->decinfo
->map_flag
= 0; /* xaFALSE */
748 priv
->decinfo
->map
= NULL
;
749 priv
->decinfo
->xs
= priv
->decinfo
->ys
= 0;
750 priv
->decinfo
->special
= 0;
751 priv
->decinfo
->extra
= codec_hdr
.extra
;
752 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "decinfo->extra, filled by codec: %p [%s]\n",
753 &priv
->decinfo
->extra
, (char *)priv
->decinfo
->extra
);
759 static void uninit(sh_video_t
*sh
)
761 vd_xanim_ctx
*priv
= sh
->context
;
763 void (*close_func
)();
765 for (i
=0; i
< XA_CLOSE_FUNCS
; i
++)
766 if (xa_close_func
[i
])
768 close_func
= xa_close_func
[i
];
771 dlclose(priv
->file_handler
);
772 if (priv
->decinfo
!= NULL
)
777 // unsigned int (*dec_func)(unsigned char *image, unsigned char *delta,
778 // unsigned int dsize, XA_DEC_INFO *dec_info);
781 static mp_image_t
* decode(sh_video_t
*sh
, void *data
, int len
, int flags
)
783 vd_xanim_ctx
*priv
= sh
->context
;
787 return NULL
; // skipped frame
789 priv
->decinfo
->skip_flag
= (flags
&3)?1:0;
791 if(sh
->codec
->outflags
[sh
->outfmtidx
] & CODECS_FLAG_STATIC
){
792 // allocate static buffer for cvid-like codecs:
793 priv
->mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_STATIC
,
794 MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
795 (sh
->disp_w
+3)&(~3), (sh
->disp_h
+3)&(~3));
796 if (!priv
->mpi
) return NULL
;
797 ret
= priv
->dec_func((uint8_t*)priv
->mpi
, data
, len
, priv
->decinfo
);
799 // left the buffer allocation to the codecs, pass sh_video && priv
801 ret
= priv
->dec_func((uint8_t*)sh
, data
, len
, priv
->decinfo
);
804 if (ret
== ACT_DLTA_NORM
)
807 if (ret
& ACT_DLTA_MAPD
)
808 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "mapd\n");
810 if (!(ret & ACT_DLT_MAPD))
811 xacodec_driver->decinfo->map_flag = 0;
814 xacodec_driver->decinfo->map_flag = 1;
815 xacodec_driver->decinfo->map = ...
819 if (ret
& ACT_DLTA_XOR
)
821 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "xor\n");
825 /* nothing changed */
826 if (ret
& ACT_DLTA_NOP
)
828 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "nop\n");
832 /* frame dropped (also display latest frame) */
833 if (ret
& ACT_DLTA_DROP
)
835 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "drop\n");
839 if (ret
& ACT_DLTA_BAD
)
841 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "bad\n");
845 /* used for double buffer */
846 if (ret
& ACT_DLTA_BODY
)
848 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "body\n");