# HG changeset patch # User alex # Date 1031331076 0 # Node ID 641b287f8b07ec13dbf574327e37d3d0fad81100 # Parent 832298d8c84dfafbcce39c4a09421bf8afa16d4b removed xacodec_driver, using sh->context instead, removed xacodec_image, using mpi instead, some warning fixes. note: mpi optimisations are still pending diff -r 832298d8c84d -r 641b287f8b07 libmpcodecs/vd_xanim.c --- a/libmpcodecs/vd_xanim.c Fri Sep 06 14:32:57 2002 +0000 +++ b/libmpcodecs/vd_xanim.c Fri Sep 06 16:51:16 2002 +0000 @@ -1,9 +1,13 @@ /* - xacodec.c -- XAnim Video Codec DLL support + XAnim Video Codec DLL support + + It partly emulates the Xanim codebase. + You need the -rdynamic flag to use this with gcc. (C) 2001 Alex Beregszaszi and Arpad Gereoffy */ + #include #include #include /* strerror */ @@ -39,6 +43,19 @@ #include "linux/timer.h" #include "libvo/fastmemcpy.h" +#if 0 +/* this should be removed */ +#ifndef RTLD_NOW +#define RLTD_NOW 2 +#endif +#ifndef RTLD_LAZY +#define RLTD_LAZY 1 +#endif +#ifndef RTLD_GLOBAL +#define RLTD_GLOBAL 256 +#endif +#endif + typedef struct { unsigned int what; @@ -143,19 +160,13 @@ unsigned int imaged; } XA_ANIM_HDR; -// Added by A'rpi typedef struct { - unsigned int out_fmt; - int bpp; - int width,height; - unsigned char* planes[3]; - int stride[3]; - unsigned char *mem; -} xacodec_image_t; - -int xacodec_init_video(sh_video_t *vidinfo, int out_format); -xacodec_image_t* xacodec_decode_frame(uint8_t *frame, int frame_size, int skip_flag); -int xacodec_exit(); + XA_DEC_INFO *decinfo; + void *file_handler; + long (*iq_func)(XA_CODEC_HDR *codec_hdr); + unsigned int (*dec_func)(unsigned char *image, unsigned char *delta, + unsigned int dsize, XA_DEC_INFO *dec_info); +} vd_xanim_ctx; #if 0 typedef char xaBYTE; @@ -170,33 +181,144 @@ #define xaFALSE 0 #define xaTRUE 1 -#ifndef RTLD_NOW -#define RLTD_NOW 2 -#endif -#ifndef RTLD_LAZY -#define RLTD_LAZY 1 -#endif -#ifndef RTLD_GLOBAL -#define RLTD_GLOBAL 256 -#endif +#define ACT_DLTA_NORM 0x00000000 +#define ACT_DLTA_BODY 0x00000001 +#define ACT_DLTA_XOR 0x00000002 +#define ACT_DLTA_NOP 0x00000004 +#define ACT_DLTA_MAPD 0x00000008 +#define ACT_DLTA_DROP 0x00000010 +#define ACT_DLTA_BAD 0x80000000 #define XA_CLOSE_FUNCS 5 -int xa_close_func = 0; +int xa_close_funcs = 0; +void *xa_close_func[XA_CLOSE_FUNCS]; -typedef struct xacodec_driver +/* load, init and query */ +static int xacodec_load(sh_video_t *sh, char *filename) { - XA_DEC_INFO *decinfo; - void *file_handler; - long (*iq_func)(XA_CODEC_HDR *codec_hdr); - unsigned int (*dec_func)(unsigned char *image, unsigned char *delta, - unsigned int dsize, XA_DEC_INFO *dec_info); - void *close_func[XA_CLOSE_FUNCS]; - xacodec_image_t image; -} xacodec_driver_t; + vd_xanim_ctx *priv = sh->context; + void *(*what_the)(); + char *error; + XAVID_MOD_HDR *mod_hdr; + XAVID_FUNC_HDR *func; + int i; + + priv->file_handler = dlopen(filename, RTLD_NOW|RTLD_GLOBAL); + if (!priv->file_handler) + { + error = dlerror(); + if (error) + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to dlopen %s while %s\n", filename, error); + else + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to dlopen %s\n", filename); + return(0); + } + + what_the = dlsym(priv->file_handler, "What_The"); + if ((error = dlerror()) != NULL) + { + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to init %s while %s\n", filename, error); + dlclose(priv->file_handler); + return(0); + } + + mod_hdr = what_the(); + if (!mod_hdr) + { + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: initializer function failed in %s\n", filename); + dlclose(priv->file_handler); + return(0); + } + + mp_msg(MSGT_DECVIDEO, MSGL_V, "=== XAnim Codec ===\n"); + mp_msg(MSGT_DECVIDEO, MSGL_V, " Filename: %s (API revision: %x)\n", filename, mod_hdr->api_rev); + mp_msg(MSGT_DECVIDEO, MSGL_V, " Codec: %s. Rev: %s\n", mod_hdr->desc, mod_hdr->rev); + if (mod_hdr->copyright) + mp_msg(MSGT_DECVIDEO, MSGL_V, " %s\n", mod_hdr->copyright); + if (mod_hdr->mod_author) + mp_msg(MSGT_DECVIDEO, MSGL_V, " Module Author(s): %s\n", mod_hdr->mod_author); + if (mod_hdr->authors) + mp_msg(MSGT_DECVIDEO, MSGL_V, " Codec Author(s): %s\n", mod_hdr->authors); + + if (mod_hdr->api_rev > XAVID_API_REV) + { + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported api revision (%d) in %s\n", + mod_hdr->api_rev, filename); + dlclose(priv->file_handler); + return(0); + } -xacodec_driver_t *xacodec_driver = NULL; + func = mod_hdr->funcs; + if (!func) + { + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: function table error in %s\n", filename); + dlclose(priv->file_handler); + return(0); + } + + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Exported functions by codec: [functable: 0x%08x entries: %d]\n", + mod_hdr->funcs, mod_hdr->num_funcs); + for (i = 0; i < (int)mod_hdr->num_funcs; i++) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %d: %d %d [iq:0x%08x d:0x%08x]\n", + i, func[i].what, func[i].id, func[i].iq_func, func[i].dec_func); + if (func[i].what & XAVID_AVI_QUERY) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " 0x%08x: avi init/query func (id: %d)\n", + func[i].iq_func, func[i].id); + priv->iq_func = (void *)func[i].iq_func; + } + if (func[i].what & XAVID_QT_QUERY) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " 0x%08x: qt init/query func (id: %d)\n", + func[i].iq_func, func[i].id); + priv->iq_func = (void *)func[i].iq_func; + } + if (func[i].what & XAVID_DEC_FUNC) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " 0x%08x: decoder func (init/query: 0x%08x) (id: %d)\n", + func[i].dec_func, func[i].iq_func, func[i].id); + priv->dec_func = (void *)func[i].dec_func; + } + } + return(1); +} -/* Needed by XAnim DLLs */ +static int xacodec_query(sh_video_t *sh, XA_CODEC_HDR *codec_hdr) +{ + vd_xanim_ctx *priv = sh->context; + long ret; + +#if 0 + /* the brute one */ + if (priv->dec_func) + { + codec_hdr->decoder = priv->dec_func; + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "We got decoder's address at init! %p\n", codec_hdr->decoder); + return(1); + } +#endif + + ret = priv->iq_func(codec_hdr); + switch(ret) + { + case CODEC_SUPPORTED: + priv->dec_func = (void *)codec_hdr->decoder; + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Codec is supported: found decoder for %s at 0x%08x\n", + codec_hdr->description, codec_hdr->decoder); + return(1); + case CODEC_UNSUPPORTED: + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unsupported by dll\n", + codec_hdr->description); + return(0); + case CODEC_UNKNOWN: + default: + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unknown by dll\n", + codec_hdr->description); + return(0); + } +} + void XA_Print(char *fmt, ...) { va_list vallist; @@ -216,7 +338,7 @@ void TheEnd1(char *err_mess) { XA_Print("error: %s - exiting\n", err_mess); - xacodec_exit(); + /* we should exit here... */ return; } @@ -225,373 +347,13 @@ { // XA_Print("XA_Add_Func_To_Free_Chain('anim_hdr: %08x', 'function: %08x')", // anim_hdr, function); - xacodec_driver->close_func[xa_close_func] = function; - if (xa_close_func+1 < XA_CLOSE_FUNCS) - xa_close_func++; + xa_close_func[xa_close_funcs] = function; + if (xa_close_funcs+1 < XA_CLOSE_FUNCS) + xa_close_funcs++; return; } -/* end of crap */ -/* load, init and query */ -int xacodec_init(char *filename, xacodec_driver_t *codec_driver) -{ - void *(*what_the)(); - char *error; - XAVID_MOD_HDR *mod_hdr; - XAVID_FUNC_HDR *func; - int i; - - codec_driver->file_handler = dlopen(filename, RTLD_NOW|RTLD_GLOBAL); - if (!codec_driver->file_handler) - { - error = dlerror(); - if (error) - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to dlopen %s while %s\n", filename, error); - else - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to dlopen %s\n", filename); - return(0); - } - - what_the = dlsym(codec_driver->file_handler, "What_The"); - if ((error = dlerror()) != NULL) - { - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: failed to init %s while %s\n", filename, error); - dlclose(codec_driver->file_handler); - return(0); - } - - mod_hdr = what_the(); - if (!mod_hdr) - { - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: initializer function failed in %s\n", filename); - dlclose(codec_driver->file_handler); - return(0); - } - - mp_msg(MSGT_DECVIDEO, MSGL_INFO, "=== XAnim Codec ===\n"); - mp_msg(MSGT_DECVIDEO, MSGL_INFO, " Filename: %s (API revision: %x)\n", filename, mod_hdr->api_rev); - mp_msg(MSGT_DECVIDEO, MSGL_INFO, " Codec: %s. Rev: %s\n", mod_hdr->desc, mod_hdr->rev); - if (mod_hdr->copyright) - mp_msg(MSGT_DECVIDEO, MSGL_INFO, " %s\n", mod_hdr->copyright); - if (mod_hdr->mod_author) - mp_msg(MSGT_DECVIDEO, MSGL_INFO, " Module Author(s): %s\n", mod_hdr->mod_author); - if (mod_hdr->authors) - mp_msg(MSGT_DECVIDEO, MSGL_INFO, " Codec Author(s): %s\n", mod_hdr->authors); - - if (mod_hdr->api_rev > XAVID_API_REV) - { - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported api revision (%d) in %s\n", - mod_hdr->api_rev, filename); - dlclose(codec_driver->file_handler); - return(0); - } - - func = mod_hdr->funcs; - if (!func) - { - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: function table error in %s\n", filename); - dlclose(codec_driver->file_handler); - return(0); - } - - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Exported functions by codec: [functable: 0x%08x entries: %d]\n", - mod_hdr->funcs, mod_hdr->num_funcs); - for (i = 0; i < mod_hdr->num_funcs; i++) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " %d: %d %d [iq:0x%08x d:0x%08x]\n", - i, func[i].what, func[i].id, func[i].iq_func, func[i].dec_func); - if (func[i].what & XAVID_AVI_QUERY) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " 0x%08x: avi init/query func (id: %d)\n", - func[i].iq_func, func[i].id); - codec_driver->iq_func = (void *)func[i].iq_func; - } - if (func[i].what & XAVID_QT_QUERY) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " 0x%08x: qt init/query func (id: %d)\n", - func[i].iq_func, func[i].id); - codec_driver->iq_func = (void *)func[i].iq_func; - } - if (func[i].what & XAVID_DEC_FUNC) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, " 0x%08x: decoder func (init/query: 0x%08x) (id: %d)\n", - func[i].dec_func, func[i].iq_func, func[i].id); - codec_driver->dec_func = (void *)func[i].dec_func; - } - } - return(1); -} - -int xacodec_query(xacodec_driver_t *codec_driver, XA_CODEC_HDR *codec_hdr) -{ - long codec_ret; - -#if 0 - /* the brute one */ - if (codec_driver->dec_func) - { - codec_hdr->decoder = codec_driver->dec_func; - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "We got decoder's address at init! %p\n", codec_hdr->decoder); - return(1); - } -#endif - codec_ret = codec_driver->iq_func(codec_hdr); - switch(codec_ret) - { - case CODEC_SUPPORTED: - codec_driver->dec_func = (void *)codec_hdr->decoder; - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "Codec is supported: found decoder for %s at 0x%08x\n", - codec_hdr->description, codec_hdr->decoder); - return(1); - case CODEC_UNSUPPORTED: - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unsupported by driver\n", - codec_hdr->description); - return(0); - case CODEC_UNKNOWN: - default: - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "Codec (%s) is unknown by driver\n", - codec_hdr->description); - return(0); - } -} - -char *xacodec_def_path = XACODEC_PATH; - -int xacodec_init_video(sh_video_t *vidinfo, int out_format) -{ - char dll[1024]; - XA_CODEC_HDR codec_hdr; - int i; - - xacodec_driver = realloc(xacodec_driver, sizeof(struct xacodec_driver)); - if (xacodec_driver == NULL) - { - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: memory allocation error: %s\n", - strerror(errno)); - return(0); - } - - xacodec_driver->iq_func = NULL; - xacodec_driver->dec_func = NULL; - - for (i=0; i < XA_CLOSE_FUNCS; i++) - xacodec_driver->close_func[i] = NULL; - - if (getenv("XANIM_MOD_DIR")) - xacodec_def_path = getenv("XANIM_MOD_DIR"); - - snprintf(dll, 1024, "%s/%s", xacodec_def_path, vidinfo->codec->dll); - if (xacodec_init(dll, xacodec_driver) == 0) - return(0); - - codec_hdr.xapi_rev = XAVID_API_REV; - codec_hdr.anim_hdr = malloc(4096); - codec_hdr.description = vidinfo->codec->info; - codec_hdr.compression = bswap_32(vidinfo->bih->biCompression); - codec_hdr.decoder = NULL; - codec_hdr.x = vidinfo->bih->biWidth; /* ->disp_w */ - codec_hdr.y = vidinfo->bih->biHeight; /* ->disp_h */ - /* extra fields to store palette */ - codec_hdr.avi_ctab_flag = 0; - codec_hdr.avi_read_ext = NULL; - codec_hdr.extra = NULL; - - switch(out_format) - { - case IMGFMT_IYUV: - case IMGFMT_I420: - case IMGFMT_YV12: - codec_hdr.depth = 12; - break; - case IMGFMT_YVU9: - if (vidinfo->bih->biCompression == mmioFOURCC('I','V','3','2') || - vidinfo->bih->biCompression == mmioFOURCC('i','v','3','2') || - vidinfo->bih->biCompression == mmioFOURCC('I','V','3','1') || - vidinfo->bih->biCompression == mmioFOURCC('i','v','3','2')) - { - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supporting YVU9 output with Indeo3\n"); - return(0); - } - codec_hdr.depth = 9; - break; - default: - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported image out format (%s)\n", - vo_format_name(out_format)); - return(0); - } - mp_msg(MSGT_DECVIDEO, MSGL_INFO, "xacodec: querying for input %dx%d %dbit [fourcc: %4x] (%s)...\n", - codec_hdr.x, codec_hdr.y, codec_hdr.depth, codec_hdr.compression, codec_hdr.description); - - if (xacodec_query(xacodec_driver, &codec_hdr) == 0) - return(0); - -// free(codec_hdr.anim_hdr); - - xacodec_driver->decinfo = malloc(sizeof(XA_DEC_INFO)); - if (xacodec_driver->decinfo == NULL) - { - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: memory allocation error: %s\n", - strerror(errno)); - return(0); - } - xacodec_driver->decinfo->cmd = 0; - xacodec_driver->decinfo->skip_flag = 0; - xacodec_driver->decinfo->imagex = xacodec_driver->decinfo->xe = codec_hdr.x; - xacodec_driver->decinfo->imagey = xacodec_driver->decinfo->ye = codec_hdr.y; - xacodec_driver->decinfo->imaged = codec_hdr.depth; - xacodec_driver->decinfo->chdr = NULL; - xacodec_driver->decinfo->map_flag = 0; /* xaFALSE */ - xacodec_driver->decinfo->map = NULL; - xacodec_driver->decinfo->xs = xacodec_driver->decinfo->ys = 0; - xacodec_driver->decinfo->special = 0; - xacodec_driver->decinfo->extra = codec_hdr.extra; - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "decinfo->extra, filled by codec: 0x%08x [%s]\n", - &xacodec_driver->decinfo->extra, xacodec_driver->decinfo->extra); - -// vidinfo->our_out_buffer = malloc(codec_hdr.y * codec_hdr.x * ((codec_hdr.depth+7)/8)); -// vidinfo->our_out_buffer = malloc(codec_hdr.y * codec_hdr.x * codec_hdr.depth); - xacodec_driver->image.out_fmt = out_format; - xacodec_driver->image.bpp = codec_hdr.depth; - xacodec_driver->image.width = codec_hdr.x; - xacodec_driver->image.height = codec_hdr.y; - xacodec_driver->image.mem = malloc(codec_hdr.y * codec_hdr.x * ((codec_hdr.depth+7)/8)); - - if (xacodec_driver->image.mem == NULL) - { - mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: memory allocation error: %s\n", - strerror(errno)); - return(0); - } - - return(1); -} - -#define ACT_DLTA_NORM 0x00000000 -#define ACT_DLTA_BODY 0x00000001 -#define ACT_DLTA_XOR 0x00000002 -#define ACT_DLTA_NOP 0x00000004 -#define ACT_DLTA_MAPD 0x00000008 -#define ACT_DLTA_DROP 0x00000010 -#define ACT_DLTA_BAD 0x80000000 - -// unsigned int (*dec_func)(unsigned char *image, unsigned char *delta, -// unsigned int dsize, XA_DEC_INFO *dec_info); - -xacodec_image_t* xacodec_decode_frame(uint8_t *frame, int frame_size, int skip_flag) -{ - unsigned int ret; - xacodec_image_t *image=&xacodec_driver->image; - -// ugyis kiirja a vegen h dropped vagy nem.. -// if (skip_flag > 0) -// mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "frame will be dropped..\n"); - - xacodec_driver->decinfo->skip_flag = skip_flag; - - image->planes[0]=image->mem; - image->stride[0]=image->width; - switch(image->out_fmt){ - case IMGFMT_YV12: - image->planes[2]=image->planes[0]+image->width*image->height; - image->planes[1]=image->planes[2]+image->width*image->height/4; - image->stride[1]=image->stride[2]=image->width/2; - break; - case IMGFMT_I420: - case IMGFMT_IYUV: - image->planes[1]=image->planes[0]+image->width*image->height; - image->planes[2]=image->planes[1]+image->width*image->height/4; - image->stride[1]=image->stride[2]=image->width/2; - break; - case IMGFMT_YVU9: - image->planes[2]=image->planes[0]+image->width*image->height; - image->planes[1]=image->planes[2]+(image->width>>2)*(image->height>>2); - image->stride[1]=image->stride[2]=image->width/4; - break; - } - -// printf("frame: %08x (size: %d) - dest: %08x\n", frame, frame_size, dest); - - ret = xacodec_driver->dec_func((uint8_t*)&xacodec_driver->image, frame, frame_size, xacodec_driver->decinfo); - -// printf("ret: %lu : ", ret); - - - if (ret == ACT_DLTA_NORM) - { -// mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "norm\n"); - return &xacodec_driver->image; - } - - if (ret & ACT_DLTA_MAPD) - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "mapd\n"); -/* - if (!(ret & ACT_DLT_MAPD)) - xacodec_driver->decinfo->map_flag = 0; - else - { - xacodec_driver->decinfo->map_flag = 1; - xacodec_driver->decinfo->map = ... - } -*/ - - if (ret & ACT_DLTA_XOR) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "xor\n"); - return &xacodec_driver->image; - } - - /* nothing changed */ - if (ret & ACT_DLTA_NOP) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "nop\n"); - return NULL; - } - - /* frame dropped (also display latest frame) */ - if (ret & ACT_DLTA_DROP) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "drop\n"); - return NULL; - } - - if (ret & ACT_DLTA_BAD) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "bad\n"); - return NULL; - } - - /* used for double buffer */ - if (ret & ACT_DLTA_BODY) - { - mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "body\n"); - return NULL; - } - - return NULL; -} - -int xacodec_exit() -{ - int i; - void (*close_func)(); - - for (i=0; i < XA_CLOSE_FUNCS; i++) - if (xacodec_driver->close_func[i]) - { - close_func = xacodec_driver->close_func[i]; - close_func(); - } - dlclose(xacodec_driver->file_handler); - if (xacodec_driver->decinfo != NULL) - free(xacodec_driver->decinfo); - free(xacodec_driver); - return(TRUE); -} - - -/* *** XANIM Conversions *** */ -/* like loader/win32.c - mini XANIM library */ unsigned long XA_Time_Read() { @@ -606,17 +368,12 @@ void XA_Gen_YUV_Tabs(XA_ANIM_HDR *anim_hdr) { XA_Print("XA_Gen_YUV_Tabs('anim_hdr: %08x')", anim_hdr); - -// XA_Print("anim type: %d - img[x: %d, y: %d, c: %d, d: %d]", -// anim_hdr->anim_type, anim_hdr->imagex, anim_hdr->imagey, -// anim_hdr->imagec, anim_hdr->imaged); return; } void JPG_Setup_Samp_Limit_Table(XA_ANIM_HDR *anim_hdr) { XA_Print("JPG_Setup_Samp_Limit_Table('anim_hdr: %08x')", anim_hdr); -// xa_byte_limit = jpg_samp_limit + (MAXJSAMPLE + 1); return; } @@ -653,16 +410,17 @@ void XA_2x2_OUT_1BLK_Convert(unsigned char *image_p, unsigned int x, unsigned int y, unsigned int imagex, XA_2x2_Color *cmap2x2) { - xacodec_image_t *image=(xacodec_image_t*)image_p; + mp_image_t *mpi = (mp_image_t *)image_p; #if 0 - SET_4_YUV_PIXELS(image,x,y,cmap2x2) + SET_4_YUV_PIXELS(mpi,x,y,cmap2x2) #else - SET_4_YUV_PIXELS(image,x,y,cmap2x2) - SET_4_YUV_PIXELS(image,x+2,y,cmap2x2) - SET_4_YUV_PIXELS(image,x,y+2,cmap2x2) - SET_4_YUV_PIXELS(image,x+2,y+2,cmap2x2) + SET_4_YUV_PIXELS(mpi,x,y,cmap2x2) + SET_4_YUV_PIXELS(mpi,x+2,y,cmap2x2) + SET_4_YUV_PIXELS(mpi,x,y+2,cmap2x2) + SET_4_YUV_PIXELS(mpi,x+2,y+2,cmap2x2) #endif + return; } @@ -670,12 +428,12 @@ unsigned int imagex, XA_2x2_Color *cm0, XA_2x2_Color *cm1, XA_2x2_Color *cm2, XA_2x2_Color *cm3) { - xacodec_image_t *image=(xacodec_image_t*)image_p; + mp_image_t *mpi = (mp_image_t *)image_p; - SET_4_YUV_PIXELS(image,x,y,cm0) - SET_4_YUV_PIXELS(image,x+2,y,cm1) - SET_4_YUV_PIXELS(image,x,y+2,cm2) - SET_4_YUV_PIXELS(image,x+2,y+2,cm3) + SET_4_YUV_PIXELS(mpi,x,y,cm0) + SET_4_YUV_PIXELS(mpi,x+2,y,cm1) + SET_4_YUV_PIXELS(mpi,x,y+2,cm2) + SET_4_YUV_PIXELS(mpi,x+2,y+2,cm3) return; } @@ -752,7 +510,8 @@ unsigned int i_x, unsigned int i_y, YUVBufs *yuv, YUVTabs *yuv_tabs, unsigned int map_flag, unsigned int *map, XA_CHDR *chdr) { - xacodec_image_t *image=(xacodec_image_t*)image_p; + mp_image_t *mpi = (mp_image_t *)image_p; + mp_image_t *image = (mp_image_t *)image_p; int y; int uvstride; @@ -764,28 +523,28 @@ yuv_tabs->YUV_VG_tab ); 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')", - image, imagex, imagey, i_x, i_y, yuv, yuv_tabs, map_flag, map, chdr); + image_p, imagex, imagey, i_x, i_y, yuv, yuv_tabs, map_flag, map, chdr); mp_dbg(MSGT_DECVIDEO,MSGL_DBG3, "YUV: %p %p %p %X (%d) %dx%d %dx%d\n", yuv->Ybuf,yuv->Ubuf,yuv->Vbuf,yuv->the_buf,yuv->the_buf_size, yuv->y_w,yuv->y_h,yuv->uv_w,yuv->uv_h); - if(image->out_fmt == IMGFMT_YVU9 && !yuv_tabs->YUV_Y_tab) + if(mpi->imgfmt == IMGFMT_YVU9 && !yuv_tabs->YUV_Y_tab) { - if(i_x==image->width && i_y==image->height){ - image->planes[0]=yuv->Ybuf; - image->planes[1]=yuv->Ubuf; - image->planes[2]=yuv->Vbuf; - image->stride[0]=i_x; // yuv->y_w - image->stride[1]=image->stride[2]=i_x/4; // yuv->uv_w + if(((int)i_x==mpi->width) && ((int)i_y==mpi->height)){ + mpi->planes[0]=yuv->Ybuf; + mpi->planes[1]=yuv->Ubuf; + mpi->planes[2]=yuv->Vbuf; + mpi->stride[0]=i_x; // yuv->y_w + mpi->stride[1]=mpi->stride[2]=i_x/4; // yuv->uv_w } else { int y; - for(y=0;yplanes[0]+y*image->stride[0],yuv->Ybuf+y*i_x,i_x); + for(y=0;y<(int)i_y;y++) + memcpy(mpi->planes[0]+y*mpi->stride[0],yuv->Ybuf+y*i_x,i_x); i_x>>=2; i_y>>=2; - for(y=0;yplanes[1]+y*image->stride[1],yuv->Ubuf+y*i_x,i_x); - memcpy(image->planes[2]+y*image->stride[2],yuv->Vbuf+y*i_x,i_x); + for(y=0;y<(int)i_y;y++){ + memcpy(mpi->planes[1]+y*mpi->stride[1],yuv->Ubuf+y*i_x,i_x); + memcpy(mpi->planes[2]+y*mpi->stride[2],yuv->Vbuf+y*i_x,i_x); } } return; @@ -793,10 +552,10 @@ // copy Y plane: if(yuv_tabs->YUV_Y_tab){ // dirty hack to detect iv32: - for(y=0;yplanes[0][y]=yuv->Ybuf[y]<<1; + for(y=0;y<(int)(imagey*imagex);y++) + mpi->planes[0][y]=yuv->Ybuf[y]<<1; } else - memcpy(image->planes[0],yuv->Ybuf,imagex*imagey); + memcpy(mpi->planes[0],yuv->Ybuf,imagex*imagey); // scale U,V planes by 2: imagex>>=2; @@ -804,26 +563,27 @@ uvstride=(yuv->uv_w)?yuv->uv_w:imagex; - for(y=0;yUbuf+uvstride*y; unsigned char *sv=yuv->Vbuf+uvstride*y; - unsigned int strideu=image->stride[1]; - unsigned int stridev=image->stride[2]; - unsigned char *du=image->planes[1]+2*y*strideu; - unsigned char *dv=image->planes[2]+2*y*stridev; + unsigned int strideu=mpi->stride[1]; + unsigned int stridev=mpi->stride[2]; + unsigned char *du=mpi->planes[1]+2*y*strideu; + unsigned char *dv=mpi->planes[2]+2*y*stridev; int x; if(yuv_tabs->YUV_Y_tab){ // dirty hack to detect iv32: - for(x=0;xwidth,image->height, + image_p,imagex,imagey,i_x,i_y, mpi->width,mpi->height, yuv,yuv_tabs,map_flag,map,chdr); mp_dbg(MSGT_DECVIDEO,MSGL_DBG3, "YUV: %p %p %p %X (%X) %Xx%X %Xx%X\n", yuv->Ybuf,yuv->Ubuf,yuv->Vbuf,yuv->the_buf,yuv->the_buf_size, yuv->y_w,yuv->y_h,yuv->uv_w,yuv->uv_h); -if(i_x==image->width && i_y==image->height){ -// printf("Direct render!!!\n"); - image->planes[0]=yuv->Ybuf; - if(image->out_fmt==IMGFMT_YV12){ - image->planes[1]=yuv->Ubuf; - image->planes[2]=yuv->Vbuf; +if(((int)i_x==mpi->width) && ((int)i_y==mpi->height)){ + mpi->planes[0]=yuv->Ybuf; + if(mpi->imgfmt==IMGFMT_YV12){ + mpi->planes[1]=yuv->Ubuf; + mpi->planes[2]=yuv->Vbuf; } else { - image->planes[1]=yuv->Vbuf; - image->planes[2]=yuv->Ubuf; + mpi->planes[1]=yuv->Vbuf; + mpi->planes[2]=yuv->Ubuf; } - image->stride[0]=i_x; // yuv->y_w - image->stride[1]=image->stride[2]=i_x/2; // yuv->uv_w + mpi->stride[0]=i_x; // yuv->y_w + mpi->stride[1]=mpi->stride[2]=i_x/2; // yuv->uv_w } else { int y; - for(y=0;yplanes[0]+y*image->stride[0],yuv->Ybuf+y*i_x,i_x); + for(y=0;y<(int)i_y;y++) + memcpy(mpi->planes[0]+y*mpi->stride[0],yuv->Ybuf+y*i_x,i_x); i_x>>=1; i_y>>=1; - for(y=0;yplanes[1]+y*image->stride[1],yuv->Ubuf+y*i_x,i_x); - memcpy(image->planes[2]+y*image->stride[2],yuv->Vbuf+y*i_x,i_x); + for(y=0;y<(int)i_y;y++){ + memcpy(mpi->planes[1]+y*mpi->stride[1],yuv->Ubuf+y*i_x,i_x); + memcpy(mpi->planes[2]+y*mpi->stride[2],yuv->Vbuf+y*i_x,i_x); } } return; @@ -904,41 +667,205 @@ return CONTROL_UNKNOWN; } +//int xacodec_init_video(sh_video_t *vidinfo, int out_format); +/* out_format = sh->codec->outfmt[sh->codec->outfmtidx]; */ + // init driver -static int init(sh_video_t *sh){ +static int init(sh_video_t *sh) +{ + vd_xanim_ctx *priv; + char *def_path = XACODEC_PATH; + char dll[1024]; + XA_CODEC_HDR codec_hdr; + int i; + + priv = malloc(sizeof(vd_xanim_ctx)); + if (!priv) + return 0; + sh->context = priv; + memset(priv, 0, sizeof(vd_xanim_ctx)); + if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YV12)) return 0; - return xacodec_init_video(sh,sh->codec->outfmt[sh->outfmtidx]); + + priv->iq_func = NULL; + priv->dec_func = NULL; + + for (i=0; i < XA_CLOSE_FUNCS; i++) + xa_close_func[i] = NULL; + + if (getenv("XANIM_MOD_DIR")) + def_path = getenv("XANIM_MOD_DIR"); + + snprintf(dll, 1024, "%s/%s", def_path, sh->codec->dll); + if (xacodec_load(sh, dll) == 0) + return(0); + + codec_hdr.xapi_rev = XAVID_API_REV; + codec_hdr.anim_hdr = malloc(4096); + codec_hdr.description = sh->codec->info; + codec_hdr.compression = bswap_32(sh->bih->biCompression); + codec_hdr.decoder = NULL; + codec_hdr.x = sh->bih->biWidth; /* ->disp_w */ + codec_hdr.y = sh->bih->biHeight; /* ->disp_h */ + /* extra fields to store palette */ + codec_hdr.avi_ctab_flag = 0; + codec_hdr.avi_read_ext = NULL; + codec_hdr.extra = NULL; + + switch(sh->codec->outfmt[sh->outfmtidx]) + { + case IMGFMT_BGR32: + codec_hdr.depth = 32; + break; + case IMGFMT_BGR24: + codec_hdr.depth = 24; + break; + case IMGFMT_IYUV: + case IMGFMT_I420: + case IMGFMT_YV12: + codec_hdr.depth = 12; + break; + case IMGFMT_YVU9: +#if 0 + if (sh->bih->biCompression == mmioFOURCC('I','V','3','2') || + sh->bih->biCompression == mmioFOURCC('i','v','3','2') || + sh->bih->biCompression == mmioFOURCC('I','V','3','1') || + sh->bih->biCompression == mmioFOURCC('i','v','3','2')) + { + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supporting YVU9 output with Indeo3\n"); + return(0); + } +#endif + codec_hdr.depth = 9; + break; + default: + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: not supported image out format (%s)\n", + vo_format_name(sh->codec->outfmt[sh->outfmtidx])); + return(0); + } + mp_msg(MSGT_DECVIDEO, MSGL_INFO, "xacodec: querying for input %dx%d %dbit [fourcc: %4x] (%s)...\n", + codec_hdr.x, codec_hdr.y, codec_hdr.depth, codec_hdr.compression, codec_hdr.description); + + if (xacodec_query(sh, &codec_hdr) == 0) + return(0); + +// free(codec_hdr.anim_hdr); + + priv->decinfo = malloc(sizeof(XA_DEC_INFO)); + if (priv->decinfo == NULL) + { + mp_msg(MSGT_DECVIDEO, MSGL_FATAL, "xacodec: memory allocation error: %s\n", + strerror(errno)); + return(0); + } + priv->decinfo->cmd = 0; + priv->decinfo->skip_flag = 0; + priv->decinfo->imagex = priv->decinfo->xe = codec_hdr.x; + priv->decinfo->imagey = priv->decinfo->ye = codec_hdr.y; + priv->decinfo->imaged = codec_hdr.depth; + priv->decinfo->chdr = NULL; + priv->decinfo->map_flag = 0; /* xaFALSE */ + priv->decinfo->map = NULL; + priv->decinfo->xs = priv->decinfo->ys = 0; + priv->decinfo->special = 0; + priv->decinfo->extra = codec_hdr.extra; + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "decinfo->extra, filled by codec: 0x%08x [%s]\n", + &priv->decinfo->extra, priv->decinfo->extra); + + return(1); } // uninit driver -static void uninit(sh_video_t *sh){ - xacodec_exit(); +static void uninit(sh_video_t *sh) +{ + vd_xanim_ctx *priv = sh->context; + int i; + void (*close_func)(); + + for (i=0; i < XA_CLOSE_FUNCS; i++) + if (xa_close_func[i]) + { + close_func = xa_close_func[i]; + close_func(); + } + dlclose(priv->file_handler); + if (priv->decinfo != NULL) + free(priv->decinfo); + free(priv); } //mp_image_t* mpcodecs_get_image(sh_video_t *sh, int mp_imgtype, int mp_imgflag, int w, int h); +// unsigned int (*dec_func)(unsigned char *image, unsigned char *delta, +// unsigned int dsize, XA_DEC_INFO *dec_info); + // decode a frame -static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ - mp_image_t* mpi; - xacodec_image_t* image; +static mp_image_t* decode(sh_video_t *sh, void *data, int len, int flags) +{ + vd_xanim_ctx *priv = sh->context; + mp_image_t *mpi; + unsigned int ret; - if(len<=0) return NULL; // skipped frame + if (len <= 0) + return NULL; // skipped frame - image=xacodec_decode_frame(data,len,(flags&3)?1:0); - if(!image) return NULL; + mpi = mpcodecs_get_image(sh, MP_IMGTYPE_TEMP, 0, + sh->disp_w, sh->disp_h); + if (!mpi) + return NULL; + + priv->decinfo->skip_flag = (flags&3)?1:0; + + ret = priv->dec_func((uint8_t*)mpi, data, len, priv->decinfo); + + if (ret == ACT_DLTA_NORM) + return mpi; - mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, - sh->disp_w, sh->disp_h); - if(!mpi) return NULL; + if (ret & ACT_DLTA_MAPD) + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "mapd\n"); +/* + if (!(ret & ACT_DLT_MAPD)) + xacodec_driver->decinfo->map_flag = 0; + else + { + xacodec_driver->decinfo->map_flag = 1; + xacodec_driver->decinfo->map = ... + } +*/ + + if (ret & ACT_DLTA_XOR) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "xor\n"); + return mpi; + } - mpi->planes[0]=image->planes[0]; - mpi->planes[1]=image->planes[1]; - mpi->planes[2]=image->planes[2]; - mpi->stride[0]=image->stride[0]; - mpi->stride[1]=image->stride[1]; - mpi->stride[2]=image->stride[2]; + /* nothing changed */ + if (ret & ACT_DLTA_NOP) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "nop\n"); + return NULL; + } + + /* frame dropped (also display latest frame) */ + if (ret & ACT_DLTA_DROP) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "drop\n"); + return NULL; + } + + if (ret & ACT_DLTA_BAD) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "bad\n"); + return NULL; + } + + /* used for double buffer */ + if (ret & ACT_DLTA_BODY) + { + mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "body\n"); + return NULL; + } return mpi; } - #endif