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
76 typedef long init_function(struct XA_CODEC_HDR
*);
77 typedef unsigned int decode_function(unsigned char *, unsigned char *,
78 unsigned int, struct XA_DEC_INFO
*);
84 init_function
*iq_func
; /* init/query function */
85 decode_function
*dec_func
; /* opt decode function */
88 #define XAVID_WHAT_NO_MORE 0x0000
89 #define XAVID_AVI_QUERY 0x0001
90 #define XAVID_QT_QUERY 0x0002
91 #define XAVID_DEC_FUNC 0x0100
93 #define XAVID_API_REV 0x0003
103 unsigned int num_funcs
;
104 XAVID_FUNC_HDR
*funcs
;
108 typedef struct XA_CODEC_HDR
111 unsigned int compression
;
115 unsigned int xapi_rev
;
116 decode_function
*decoder
;
118 unsigned int avi_ctab_flag
;
119 unsigned int (*avi_read_ext
)(void);
122 #define CODEC_SUPPORTED 1
123 #define CODEC_UNKNOWN 0
124 #define CODEC_UNSUPPORTED -1
126 /* fuckin colormap structures for xanim */
130 unsigned short green
;
135 typedef struct XA_ACTION_STRUCT
140 struct XA_ACTION_STRUCT
*next
;
141 struct XA_CHDR_STRUCT
*chdr
;
144 struct XA_ACTION_STRUCT
*next_same_chdr
;
147 typedef struct XA_CHDR_STRUCT
151 unsigned int csize
, coff
;
153 unsigned int msize
, moff
;
154 struct XA_CHDR_STRUCT
*next
;
156 struct XA_CHDR_STRUCT
*new_chdr
;
159 typedef struct XA_DEC_INFO
162 unsigned int skip_flag
;
163 unsigned int imagex
, imagey
; /* image buffer size */
164 unsigned int imaged
; /* image depth */
165 XA_CHDR
*chdr
; /* color map header */
166 unsigned int map_flag
;
170 unsigned int special
;
176 unsigned int file_num
;
177 unsigned int anim_type
;
185 XA_DEC_INFO
*decinfo
;
187 init_function
*iq_func
;
188 decode_function
*dec_func
;
194 typedef short xaSHORT
;
197 typedef unsigned char xaUBYTE
;
198 typedef unsigned short xaUSHORT
;
199 typedef unsigned int xaULONG
;
205 #define ACT_DLTA_NORM 0x00000000
206 #define ACT_DLTA_BODY 0x00000001
207 #define ACT_DLTA_XOR 0x00000002
208 #define ACT_DLTA_NOP 0x00000004
209 #define ACT_DLTA_MAPD 0x00000008
210 #define ACT_DLTA_DROP 0x00000010
211 #define ACT_DLTA_BAD 0x80000000
213 #define XA_CLOSE_FUNCS 5
214 int xa_close_funcs
= 0;
215 void *xa_close_func
[XA_CLOSE_FUNCS
];
217 /* load, init and query */
218 static int xacodec_load(sh_video_t
*sh
, char *filename
)
220 vd_xanim_ctx
*priv
= sh
->context
;
221 void *(*what_the
)(void);
223 XAVID_MOD_HDR
*mod_hdr
;
224 XAVID_FUNC_HDR
*func
;
227 // priv->file_handler = dlopen(filename, RTLD_NOW|RTLD_GLOBAL);
228 priv
->file_handler
= dlopen(filename
, RTLD_LAZY
);
229 if (!priv
->file_handler
)
233 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: failed to dlopen %s while %s\n", filename
, error
);
235 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: failed to dlopen %s\n", filename
);
239 what_the
= dlsym(priv
->file_handler
, "What_The");
240 if ((error
= dlerror()) != NULL
)
242 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: failed to init %s while %s\n", filename
, error
);
243 dlclose(priv
->file_handler
);
247 mod_hdr
= what_the();
250 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: initializer function failed in %s\n", filename
);
251 dlclose(priv
->file_handler
);
255 mp_msg(MSGT_DECVIDEO
, MSGL_V
, "=== XAnim Codec ===\n");
256 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " Filename: %s (API revision: %x)\n", filename
, mod_hdr
->api_rev
);
257 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " Codec: %s. Rev: %s\n", mod_hdr
->desc
, mod_hdr
->rev
);
258 if (mod_hdr
->copyright
)
259 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " %s\n", mod_hdr
->copyright
);
260 if (mod_hdr
->mod_author
)
261 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " Module Author(s): %s\n", mod_hdr
->mod_author
);
262 if (mod_hdr
->authors
)
263 mp_msg(MSGT_DECVIDEO
, MSGL_V
, " Codec Author(s): %s\n", mod_hdr
->authors
);
265 if (mod_hdr
->api_rev
> XAVID_API_REV
)
267 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: not supported api revision (%d) in %s\n",
268 mod_hdr
->api_rev
, filename
);
269 dlclose(priv
->file_handler
);
273 func
= mod_hdr
->funcs
;
276 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: function table error in %s\n", filename
);
277 dlclose(priv
->file_handler
);
281 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "Exported functions by codec: [functable: %p entries: %d]\n",
282 mod_hdr
->funcs
, mod_hdr
->num_funcs
);
283 for (i
= 0; i
< (int)mod_hdr
->num_funcs
; i
++)
285 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, " %d: %d %d [iq:%p d:%p]\n",
286 i
, func
[i
].what
, func
[i
].id
, func
[i
].iq_func
, func
[i
].dec_func
);
287 if (func
[i
].what
& XAVID_AVI_QUERY
)
289 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, " %p: avi init/query func (id: %d)\n",
290 func
[i
].iq_func
, func
[i
].id
);
291 priv
->iq_func
= func
[i
].iq_func
;
293 if (func
[i
].what
& XAVID_QT_QUERY
)
295 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, " %p: qt init/query func (id: %d)\n",
296 func
[i
].iq_func
, func
[i
].id
);
297 priv
->iq_func
= func
[i
].iq_func
;
299 if (func
[i
].what
& XAVID_DEC_FUNC
)
301 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, " %p: decoder func (init/query: %p) (id: %d)\n",
302 func
[i
].dec_func
, func
[i
].iq_func
, func
[i
].id
);
303 priv
->dec_func
= func
[i
].dec_func
;
309 static int xacodec_query(sh_video_t
*sh
, XA_CODEC_HDR
*codec_hdr
)
311 vd_xanim_ctx
*priv
= sh
->context
;
318 codec_hdr
->decoder
= priv
->dec_func
;
319 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "We got decoder's address at init! %p\n", codec_hdr
->decoder
);
324 ret
= priv
->iq_func(codec_hdr
);
327 case CODEC_SUPPORTED
:
328 priv
->dec_func
= codec_hdr
->decoder
;
329 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "Codec is supported: found decoder for %s at %p\n",
330 codec_hdr
->description
, codec_hdr
->decoder
);
332 case CODEC_UNSUPPORTED
:
333 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "Codec (%s) is unsupported by dll\n",
334 codec_hdr
->description
);
338 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "Codec (%s) is unknown by dll\n",
339 codec_hdr
->description
);
344 /* These functions are required for loading XAnim binary libs.
345 * Add forward declarations to avoid warnings with -Wmissing-prototypes. */
346 void XA_Print(char *fmt
, ...);
347 void TheEnd1(char *err_mess
);
348 void XA_Add_Func_To_Free_Chain(XA_ANIM_HDR
*anim_hdr
, void (*function
)(void));
349 unsigned long XA_Time_Read(void);
350 void XA_Gen_YUV_Tabs(XA_ANIM_HDR
*anim_hdr
);
351 void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR
*anim_hdr
);
352 void JPG_Alloc_MCU_Bufs(XA_ANIM_HDR
*anim_hdr
, unsigned int width
,
353 unsigned int height
, unsigned int full_flag
);
354 void *YUV2x2_Blk_Func(unsigned int image_type
, int blks
,
355 unsigned int dith_flag
);
356 void *YUV2x2_Map_Func(unsigned int image_type
, unsigned int dith_type
);
357 void *XA_YUV1611_Func(unsigned int image_type
);
358 void *XA_YUV221111_Func(unsigned int image_type
);
360 void XA_Print(char *fmt
, ...)
365 va_start(vallist
, fmt
);
366 vsnprintf(buf
, 1024, fmt
, vallist
);
367 mp_msg(MSGT_XACODEC
, MSGL_DBG2
, "[xacodec] %s\n", buf
);
373 /* 0 is no debug (needed by 3ivX) */
376 void TheEnd1(char *err_mess
)
378 XA_Print("error: %s - exiting\n", err_mess
);
379 /* we should exit here... */
384 void XA_Add_Func_To_Free_Chain(XA_ANIM_HDR
*anim_hdr
, void (*function
)(void))
386 // XA_Print("XA_Add_Func_To_Free_Chain('anim_hdr: %08x', 'function: %08x')",
387 // anim_hdr, function);
388 xa_close_func
[xa_close_funcs
] = function
;
389 if (xa_close_funcs
+1 < XA_CLOSE_FUNCS
)
395 unsigned long XA_Time_Read(void)
397 return GetTimer(); //(GetRelativeTime());
400 static void XA_dummy(void)
402 XA_Print("dummy() called");
405 void XA_Gen_YUV_Tabs(XA_ANIM_HDR
*anim_hdr
)
407 XA_Print("XA_Gen_YUV_Tabs('anim_hdr: %08x')", anim_hdr
);
411 void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR
*anim_hdr
)
413 XA_Print("JPG_Setup_Samp_Limit_Table('anim_hdr: %08x')", anim_hdr
);
417 void JPG_Alloc_MCU_Bufs(XA_ANIM_HDR
*anim_hdr
, unsigned int width
,
418 unsigned int height
, unsigned int full_flag
)
420 XA_Print("JPG_Alloc_MCU_Bufs('anim_hdr: %08x', 'width: %d', 'height: %d', 'full_flag: %d')",
421 anim_hdr
, width
, height
, full_flag
);
425 /* --------------- 4x4 pixel YUV block fillers [CVID] ----------------- */
429 unsigned char r0
, g0
, b0
;
430 unsigned char r1
, g1
, b1
;
431 unsigned char r2
, g2
, b2
;
432 unsigned char r3
, g3
, b3
;
433 unsigned int clr0_0
, clr0_1
, clr0_2
, clr0_3
;
434 unsigned int clr1_0
, clr1_1
, clr1_2
, clr1_3
;
435 unsigned int clr2_0
, clr2_1
, clr2_2
, clr2_3
;
436 unsigned int clr3_0
, clr3_1
, clr3_2
, clr3_3
;
439 #define SET_4_YUV_PIXELS(image,x,y,cmap2x2) \
440 image->planes[0][((x)+0)+((y)+0)*image->stride[0]]=cmap2x2->clr0_0;\
441 image->planes[0][((x)+1)+((y)+0)*image->stride[0]]=cmap2x2->clr0_1;\
442 image->planes[0][((x)+0)+((y)+1)*image->stride[0]]=cmap2x2->clr0_2;\
443 image->planes[0][((x)+1)+((y)+1)*image->stride[0]]=cmap2x2->clr0_3;\
444 image->planes[1][((x)>>1)+((y)>>1)*image->stride[1]]=cmap2x2->clr1_0;\
445 image->planes[2][((x)>>1)+((y)>>1)*image->stride[2]]=cmap2x2->clr1_1;
447 static void XA_2x2_OUT_1BLK_Convert(unsigned char *image_p
, unsigned int x
, unsigned int y
,
448 unsigned int imagex
, XA_2x2_Color
*cmap2x2
)
450 mp_image_t
*mpi
= (mp_image_t
*)image_p
;
453 SET_4_YUV_PIXELS(mpi
,x
,y
,cmap2x2
)
455 SET_4_YUV_PIXELS(mpi
,x
,y
,cmap2x2
)
456 SET_4_YUV_PIXELS(mpi
,x
+2,y
,cmap2x2
)
457 SET_4_YUV_PIXELS(mpi
,x
,y
+2,cmap2x2
)
458 SET_4_YUV_PIXELS(mpi
,x
+2,y
+2,cmap2x2
)
464 static void XA_2x2_OUT_4BLKS_Convert(unsigned char *image_p
, unsigned int x
, unsigned int y
,
465 unsigned int imagex
, XA_2x2_Color
*cm0
, XA_2x2_Color
*cm1
, XA_2x2_Color
*cm2
,
468 mp_image_t
*mpi
= (mp_image_t
*)image_p
;
470 SET_4_YUV_PIXELS(mpi
,x
,y
,cm0
)
471 SET_4_YUV_PIXELS(mpi
,x
+2,y
,cm1
)
472 SET_4_YUV_PIXELS(mpi
,x
,y
+2,cm2
)
473 SET_4_YUV_PIXELS(mpi
,x
+2,y
+2,cm3
)
477 void *YUV2x2_Blk_Func(unsigned int image_type
, int blks
, unsigned int dith_flag
)
479 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
, "YUV2x2_Blk_Func(image_type=%d, blks=%d, dith_flag=%d)\n",
480 image_type
, blks
, dith_flag
);
483 return (void*) XA_2x2_OUT_1BLK_Convert
;
485 return (void*) XA_2x2_OUT_4BLKS_Convert
;
488 mp_msg(MSGT_DECVIDEO
,MSGL_WARN
,"Unimplemented: YUV2x2_Blk_Func(image_type=%d blks=%d dith=%d)\n",image_type
,blks
,dith_flag
);
489 return (void*) XA_dummy
;
492 // Take Four Y's and UV and put them into a 2x2 Color structure.
494 static void XA_YUV_2x2_clr(XA_2x2_Color
*cmap2x2
, unsigned int Y0
, unsigned int Y1
,
495 unsigned int Y2
, unsigned int Y3
, unsigned int U
, unsigned int V
,
496 unsigned int map_flag
, unsigned int *map
, XA_CHDR
*chdr
)
499 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "XA_YUV_2x2_clr(%p [%d,%d,%d,%d][%d][%d] %d %p %p)\n",
500 cmap2x2
,Y0
,Y1
,Y2
,Y3
,U
,V
,map_flag
,map
,chdr
);
511 void *YUV2x2_Map_Func(unsigned int image_type
, unsigned int dith_type
)
513 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
, "YUV2x2_Map_Func('image_type: %d', 'dith_type: %d')",
514 image_type
, dith_type
);
515 return (void*)XA_YUV_2x2_clr
;
518 /* -------------------- whole YUV frame converters ------------------------- */
525 unsigned char *the_buf
;
526 unsigned int the_buf_size
;
527 unsigned short y_w
, y_h
;
528 unsigned short uv_w
, uv_h
;
533 unsigned long Uskip_mask
;
542 YUVTabs def_yuv_tabs
;
544 /* -------------- YUV 4x4 1x1 1x1 (4:1:0 aka YVU9) [Indeo 3,4,5] ------------------ */
546 static void XA_YUV1611_Convert(unsigned char *image_p
, unsigned int imagex
, unsigned int imagey
,
547 unsigned int i_x
, unsigned int i_y
, YUVBufs
*yuv
, YUVTabs
*yuv_tabs
,
548 unsigned int map_flag
, unsigned int *map
, XA_CHDR
*chdr
)
550 sh_video_t
*sh
= (sh_video_t
*)image_p
;
551 vd_xanim_ctx
*priv
= sh
->context
;
554 int ystride
=(yuv
->y_w
)?yuv
->y_w
:imagex
;
555 int uvstride
=(yuv
->uv_w
)?yuv
->uv_w
:(imagex
/4);
557 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "YUVTabs: %d %p %p %p %p %p\n",yuv_tabs
->Uskip_mask
,
559 yuv_tabs
->YUV_UB_tab
,
560 yuv_tabs
->YUV_VR_tab
,
561 yuv_tabs
->YUV_UG_tab
,
562 yuv_tabs
->YUV_VG_tab
);
564 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')",
565 image_p
, imagex
, imagey
, i_x
, i_y
, yuv
, yuv_tabs
, map_flag
, map
, chdr
);
567 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "YUV: %p %p %p %X (%d) %dx%d %dx%d\n",
568 yuv
->Ybuf
,yuv
->Ubuf
,yuv
->Vbuf
,yuv
->the_buf
,yuv
->the_buf_size
,
569 yuv
->y_w
,yuv
->y_h
,yuv
->uv_w
,yuv
->uv_h
);
571 if(!yuv_tabs
->YUV_Y_tab
){
572 // standard YVU9 - simply export it!
573 mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_EXPORT
, 0,
574 sh
->disp_w
, sh
->disp_h
);
575 priv
->mpi
=mpi
; if(!mpi
) return; // ERROR!
576 mpi
->planes
[0]=yuv
->Ybuf
;
577 mpi
->planes
[1]=yuv
->Ubuf
;
578 mpi
->planes
[2]=yuv
->Vbuf
;
580 mpi
->stride
[0]=ystride
; //i_x; // yuv->y_w
581 mpi
->stride
[1]=mpi
->stride
[2]=uvstride
; //i_x/4; // yuv->uv_w
585 // allocate TEMP buffer and convert the image:
586 mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
587 sh
->disp_w
, sh
->disp_h
);
588 priv
->mpi
=mpi
; if(!mpi
) return; // ERROR!
590 // convert the Y plane:
591 for(y
=0;y
<(int)imagey
;y
++){
593 unsigned char* s
=yuv
->Ybuf
+ystride
*y
;
594 unsigned char* d
=mpi
->planes
[0]+mpi
->stride
[0]*y
;
595 for(x
=0;x
<imagex
;x
++) d
[x
]=s
[x
]<<1;
601 // convert the U plane:
602 for(y
=0;y
<(int)imagey
;y
++){
604 unsigned char* s
=yuv
->Ubuf
+uvstride
*y
;
605 unsigned char* d
=mpi
->planes
[1]+mpi
->stride
[1]*y
;
606 for(x
=0;x
<imagex
;x
++) d
[x
]=s
[x
]<<1;
609 // convert the V plane:
610 for(y
=0;y
<(int)imagey
;y
++){
612 unsigned char* s
=yuv
->Vbuf
+uvstride
*y
;
613 unsigned char* d
=mpi
->planes
[2]+mpi
->stride
[2]*y
;
614 for(x
=0;x
<imagex
;x
++) d
[x
]=s
[x
]<<1;
618 void *XA_YUV1611_Func(unsigned int image_type
)
620 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
, "XA_YUV1611_Func('image_type: %d')", image_type
);
621 return (void *)XA_YUV1611_Convert
;
624 /* --------------- YUV 2x2 1x1 1x1 (4:2:0 aka YV12) [3ivX,H263] ------------ */
626 static void XA_YUV221111_Convert(unsigned char *image_p
, unsigned int imagex
, unsigned int imagey
,
627 unsigned int i_x
, unsigned int i_y
, YUVBufs
*yuv
, YUVTabs
*yuv_tabs
, unsigned int map_flag
,
628 unsigned int *map
, XA_CHDR
*chdr
)
630 sh_video_t
*sh
= (sh_video_t
*)image_p
;
631 vd_xanim_ctx
*priv
= sh
->context
;
633 // note: 3ivX codec doesn't set y_w, uv_w, they are random junk :(
634 int ystride
=imagex
; //(yuv->y_w)?yuv->y_w:imagex;
635 int uvstride
=imagex
/2; //(yuv->uv_w)?yuv->uv_w:(imagex/2);
637 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "XA_YUV221111_Convert(%p %dx%d %d;%d [%dx%d] %p %p %d %p %p)\n",
638 image_p
,imagex
,imagey
,i_x
,i_y
, sh
->disp_w
, sh
->disp_h
,
639 yuv
,yuv_tabs
,map_flag
,map
,chdr
);
641 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG3
, "YUV: %p %p %p %X (%X) %Xx%X %Xx%X\n",
642 yuv
->Ybuf
,yuv
->Ubuf
,yuv
->Vbuf
,yuv
->the_buf
,yuv
->the_buf_size
,
643 yuv
->y_w
,yuv
->y_h
,yuv
->uv_w
,yuv
->uv_h
);
645 // standard YV12 - simply export it!
646 mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_EXPORT
, 0, sh
->disp_w
, sh
->disp_h
);
647 priv
->mpi
=mpi
; if(!mpi
) return; // ERROR!
648 mpi
->planes
[0]=yuv
->Ybuf
;
649 mpi
->planes
[1]=yuv
->Ubuf
;
650 mpi
->planes
[2]=yuv
->Vbuf
;
652 mpi
->stride
[0]=ystride
; //i_x; // yuv->y_w
653 mpi
->stride
[1]=mpi
->stride
[2]=uvstride
; //=i_x/4; // yuv->uv_w
656 void *XA_YUV221111_Func(unsigned int image_type
)
658 mp_dbg(MSGT_DECVIDEO
,MSGL_DBG2
, "XA_YUV221111_Func('image_type: %d')\n",image_type
);
659 return (void *)XA_YUV221111_Convert
;
662 /* *** EOF XANIM *** */
664 // to set/get/query special features/parameters
665 static int control(sh_video_t
*sh
,int cmd
,void* arg
,...){
666 return CONTROL_UNKNOWN
;
670 static int init(sh_video_t
*sh
)
674 XA_CODEC_HDR codec_hdr
;
677 priv
= malloc(sizeof(vd_xanim_ctx
));
681 memset(priv
, 0, sizeof(vd_xanim_ctx
));
683 if(!mpcodecs_config_vo(sh
,sh
->disp_w
,sh
->disp_h
,IMGFMT_YV12
)) return 0;
685 priv
->iq_func
= NULL
;
686 priv
->dec_func
= NULL
;
688 for (i
=0; i
< XA_CLOSE_FUNCS
; i
++)
689 xa_close_func
[i
] = NULL
;
691 snprintf(dll
, 1024, "%s/%s", codec_path
, sh
->codec
->dll
);
692 if (xacodec_load(sh
, dll
) == 0)
695 codec_hdr
.xapi_rev
= XAVID_API_REV
;
696 codec_hdr
.anim_hdr
= malloc(4096);
697 codec_hdr
.description
= sh
->codec
->info
;
698 codec_hdr
.compression
= bswap_32(sh
->bih
->biCompression
);
699 codec_hdr
.decoder
= NULL
;
700 codec_hdr
.x
= sh
->bih
->biWidth
; /* ->disp_w */
701 codec_hdr
.y
= sh
->bih
->biHeight
; /* ->disp_h */
702 /* extra fields to store palette */
703 codec_hdr
.avi_ctab_flag
= 0;
704 codec_hdr
.avi_read_ext
= NULL
;
705 codec_hdr
.extra
= NULL
;
707 switch(sh
->codec
->outfmt
[sh
->outfmtidx
])
710 codec_hdr
.depth
= 32;
713 codec_hdr
.depth
= 24;
718 codec_hdr
.depth
= 12;
724 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: not supported image out format (%s)\n",
725 vo_format_name(sh
->codec
->outfmt
[sh
->outfmtidx
]));
728 mp_msg(MSGT_DECVIDEO
, MSGL_INFO
, "xacodec: querying for input %dx%d %dbit [fourcc: %4x] (%s)...\n",
729 codec_hdr
.x
, codec_hdr
.y
, codec_hdr
.depth
, codec_hdr
.compression
, codec_hdr
.description
);
731 if (xacodec_query(sh
, &codec_hdr
) == 0)
734 // free(codec_hdr.anim_hdr);
736 priv
->decinfo
= malloc(sizeof(XA_DEC_INFO
));
737 if (priv
->decinfo
== NULL
)
739 mp_msg(MSGT_DECVIDEO
, MSGL_FATAL
, "xacodec: memory allocation error: %s\n",
743 priv
->decinfo
->cmd
= 0;
744 priv
->decinfo
->skip_flag
= 0;
745 priv
->decinfo
->imagex
= priv
->decinfo
->xe
= codec_hdr
.x
;
746 priv
->decinfo
->imagey
= priv
->decinfo
->ye
= codec_hdr
.y
;
747 priv
->decinfo
->imaged
= codec_hdr
.depth
;
748 priv
->decinfo
->chdr
= NULL
;
749 priv
->decinfo
->map_flag
= 0; /* xaFALSE */
750 priv
->decinfo
->map
= NULL
;
751 priv
->decinfo
->xs
= priv
->decinfo
->ys
= 0;
752 priv
->decinfo
->special
= 0;
753 priv
->decinfo
->extra
= codec_hdr
.extra
;
754 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "decinfo->extra, filled by codec: %p [%s]\n",
755 &priv
->decinfo
->extra
, (char *)priv
->decinfo
->extra
);
761 static void uninit(sh_video_t
*sh
)
763 vd_xanim_ctx
*priv
= sh
->context
;
765 void (*close_func
)(void);
767 for (i
=0; i
< XA_CLOSE_FUNCS
; i
++)
768 if (xa_close_func
[i
])
770 close_func
= xa_close_func
[i
];
773 dlclose(priv
->file_handler
);
774 if (priv
->decinfo
!= NULL
)
779 // unsigned int (*dec_func)(unsigned char *image, unsigned char *delta,
780 // unsigned int dsize, XA_DEC_INFO *dec_info);
783 static mp_image_t
* decode(sh_video_t
*sh
, void *data
, int len
, int flags
)
785 vd_xanim_ctx
*priv
= sh
->context
;
789 return NULL
; // skipped frame
791 priv
->decinfo
->skip_flag
= (flags
&3)?1:0;
793 if(sh
->codec
->outflags
[sh
->outfmtidx
] & CODECS_FLAG_STATIC
){
794 // allocate static buffer for cvid-like codecs:
795 priv
->mpi
= mpcodecs_get_image(sh
, MP_IMGTYPE_STATIC
,
796 MP_IMGFLAG_ACCEPT_STRIDE
|MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
797 (sh
->disp_w
+3)&(~3), (sh
->disp_h
+3)&(~3));
798 if (!priv
->mpi
) return NULL
;
799 ret
= priv
->dec_func((uint8_t*)priv
->mpi
, data
, len
, priv
->decinfo
);
801 // left the buffer allocation to the codecs, pass sh_video && priv
803 ret
= priv
->dec_func((uint8_t*)sh
, data
, len
, priv
->decinfo
);
806 if (ret
== ACT_DLTA_NORM
)
809 if (ret
& ACT_DLTA_MAPD
)
810 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "mapd\n");
812 if (!(ret & ACT_DLT_MAPD))
813 xacodec_driver->decinfo->map_flag = 0;
816 xacodec_driver->decinfo->map_flag = 1;
817 xacodec_driver->decinfo->map = ...
821 if (ret
& ACT_DLTA_XOR
)
823 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "xor\n");
827 /* nothing changed */
828 if (ret
& ACT_DLTA_NOP
)
830 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "nop\n");
834 /* frame dropped (also display latest frame) */
835 if (ret
& ACT_DLTA_DROP
)
837 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "drop\n");
841 if (ret
& ACT_DLTA_BAD
)
843 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "bad\n");
847 /* used for double buffer */
848 if (ret
& ACT_DLTA_BODY
)
850 mp_msg(MSGT_DECVIDEO
, MSGL_DBG2
, "body\n");