From 57bafcdb06a3a41d8ba3050de0cc94fe1c5bb865 Mon Sep 17 00:00:00 2001 From: melanson Date: Sat, 2 Mar 2002 06:40:26 +0000 Subject: [PATCH] Native Cinepak decoder: Added YV12 support (which is so very close to working), reworked YUY2 support for speed, cleaned up compiler warnings, replaced printf()'s with mp_msg()'s git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@4912 b3059339-0415-0410-9bf9-f77b7e298cf2 --- cinepak.c | 269 +++++++++--- dec_video.c | 1123 ++++++++++++++++++++++++++++++++++++++++++++++- etc/codecs.conf | 1 + 3 files changed, 1330 insertions(+), 63 deletions(-) diff --git a/cinepak.c b/cinepak.c index 62a721b077..d3f5b31a84 100644 --- a/cinepak.c +++ b/cinepak.c @@ -20,6 +20,7 @@ #include #include "config.h" +#include "mp_msg.h" #define DBUG 0 #define MAX_STRIPS 32 @@ -29,7 +30,36 @@ typedef struct { unsigned char y0, y1, y2, y3; char u, v; - unsigned long rgb0, rgb1, rgb2, rgb3; /* should be a union */ + + // These variables are for YV12 output: The v1 vars are for + // when the vector is doublesized and used by itself to paint a + // 4x4 block. + // This quad (y0 y0 y1 y1) is used on the 2 upper rows. + unsigned long yv12_v1_u; + // This quad (y2 y2 y3 y3) is used on the 2 lower rows. + unsigned long yv12_v1_l; + // The v4 vars are for when the vector is used as 1 of 4 vectors + // to paint a 4x4 block. + // Upper pair (y0 y1): + unsigned short yv12_v4_u; + // Lower pair (y2 y3): + unsigned short yv12_v4_l; + + // These longs are for YUYV output: The v1 vars are for when the + // vector is doublesized and used by itself to paint a 4x4 block. + // The names stand for the upper-left, upper-right, + // lower-left, and lower-right YUYV pixel pairs. + unsigned long yuyv_v1_ul, yuyv_v1_ur; + unsigned long yuyv_v1_ll, yuyv_v1_lr; + // The v4 vars are for when the vector is used as 1 of 4 vectors + // to paint a 4x4 block. The names stand for upper and lower + // YUYV pixel pairs. + unsigned long yuyv_v4_u, yuyv_v4_l; + + // These longs are for BGR32 output + unsigned long rgb0, rgb1, rgb2, rgb3; + + // These char arrays are for BGR24 output unsigned char r[4], g[4], b[4]; } cvid_codebook; @@ -58,6 +88,134 @@ static long CU_Y_tab[256], CV_Y_tab[256], CU_Cb_tab[256], CV_Cb_tab[256], /* ---------------------------------------------------------------------- */ + +#define PACK_YV12_V1_Y(cb,y0,y1) ((((unsigned char)cb->y1)<<24)|(cb->y1<<16)|(((unsigned char)cb->y0)<<8)|(cb->y0)) +#define PACK_YV12_V4_Y(cb,y0,y1) ((((unsigned char)cb->y1)<<8)|(cb->y0)) + +static inline void read_codebook_yv12(cvid_codebook *c, int mode) +{ +unsigned char y0, y1, y2, y3, u, v; +int y_uv; + + if(mode) /* black and white */ + { + c->y0 = get_byte(); + c->y1 = get_byte(); + c->y2 = get_byte(); + c->y3 = get_byte(); + c->u = c->v = 128; + } + else /* colour */ + { + y0 = get_byte(); /* luma */ + y1 = get_byte(); + y2 = get_byte(); + y3 = get_byte(); + u = 128+get_byte(); /* chroma */ + v = 128+get_byte(); + + /* YUV * inv(CinYUV) + * | Y | | 1 -0.0655 0.0110 | | CY | + * | Cb | = | 0 1.1656 -0.0062 | | CU | + * | Cr | | 0 0.0467 1.4187 | | CV | + */ + y_uv = (int)((CU_Y_tab[u] + CV_Y_tab[v]) >> SCALEBITS); + c->y0 = uiclp[y0 + y_uv]; + c->y1 = uiclp[y1 + y_uv]; + c->y2 = uiclp[y2 + y_uv]; + c->y3 = uiclp[y3 + y_uv]; + c->u = uiclp[(int)((CU_Cb_tab[u] + CV_Cb_tab[v]) >> SCALEBITS)]; + c->v = uiclp[(int)((CU_Cr_tab[u] + CV_Cr_tab[v]) >> SCALEBITS)]; + + c->yv12_v1_u = PACK_YV12_V1_Y(c, y0, y1); + c->yv12_v1_l = PACK_YV12_V1_Y(c, y2, y3); + c->yv12_v4_u = PACK_YV12_V4_Y(c, y0, y1); + c->yv12_v4_l = PACK_YV12_V4_Y(c, y2, y3); + } +} + +/* ---------------------------------------------------------------------- */ + +static unsigned char *yv12_y_plane = NULL; +static unsigned char *yv12_v_plane = NULL; +static unsigned char *yv12_u_plane = NULL; + +inline void cvid_v1_yv12(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb) +{ +int uv_offset = (frm - yv12_y_plane) / 4; +int row_inc = stride / sizeof(unsigned long); +unsigned long *y_ptr = (unsigned long *)frm; +unsigned char *v_ptr = yv12_v_plane + uv_offset; +unsigned char *u_ptr = yv12_u_plane + uv_offset; +int uv_stride = stride / 2; + + // take care of the luminance + if(y_ptr > (unsigned long *)end) return; + *y_ptr = cb->yv12_v1_u; + y_ptr += row_inc; if(y_ptr > (unsigned long *)end) return; + *y_ptr = cb->yv12_v1_u; + y_ptr += row_inc; if(y_ptr > (unsigned long *)end) return; + *y_ptr = cb->yv12_v1_l; + y_ptr += row_inc; if(y_ptr > (unsigned long *)end) return; + *y_ptr = cb->yv12_v1_l; + + // now for the chrominance + v_ptr[0] = cb->v; + v_ptr[1] = cb->v; + v_ptr += uv_stride; + v_ptr[0] = cb->v; + v_ptr[1] = cb->v; + + u_ptr[0] = cb->u; + u_ptr[1] = cb->u; + u_ptr += uv_stride; + u_ptr[0] = cb->u; + u_ptr[1] = cb->u; +} + +/* ---------------------------------------------------------------------- */ +inline void cvid_v4_yv12(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb0, + cvid_codebook *cb1, cvid_codebook *cb2, cvid_codebook *cb3) +{ +int uv_offset = (frm - yv12_y_plane) / 4; +int row_inc = stride / sizeof(unsigned short); +unsigned short *y_ptr = (unsigned short *)frm; +unsigned char *v_ptr = yv12_v_plane + uv_offset; +unsigned char *u_ptr = yv12_u_plane + uv_offset; +int uv_stride = stride / 2; + + // take care of the luminance + if(y_ptr > (unsigned short *)end) return; + y_ptr[0] = cb0->yv12_v4_u; + y_ptr[1] = cb1->yv12_v4_u; + y_ptr += row_inc; if(y_ptr > (unsigned short *)end) return; + y_ptr[0] = cb0->yv12_v4_l; + y_ptr[1] = cb1->yv12_v4_l; + y_ptr += row_inc; if(y_ptr > (unsigned short *)end) return; + y_ptr[0] = cb2->yv12_v4_u; + y_ptr[1] = cb3->yv12_v4_u; + y_ptr += row_inc; if(y_ptr > (unsigned short *)end) return; + y_ptr[0] = cb2->yv12_v4_l; + y_ptr[1] = cb3->yv12_v4_l; + + // now for the chrominance + v_ptr[0] = cb0->v; + v_ptr[1] = cb1->v; + v_ptr += uv_stride; + v_ptr[0] = cb2->v; + v_ptr[1] = cb3->v; + + u_ptr[0] = cb0->u; + u_ptr[1] = cb1->u; + u_ptr += uv_stride; + u_ptr[0] = cb2->u; + u_ptr[1] = cb3->u; +} + +/* ---------------------------------------------------------------------- */ + +#define PACK_YUYV(cb,y0,y1,u,v) ((((unsigned char)cb->v)<<24)|(cb->y1<<16)|(((unsigned char)cb->u)<<8)|(cb->y0)) + static inline void read_codebook_yuy2(cvid_codebook *c, int mode) { unsigned char y0, y1, y2, y3, u, v; @@ -92,40 +250,37 @@ int y_uv; c->y3 = uiclp[y3 + y_uv]; c->u = uiclp[(int)((CU_Cb_tab[u] + CV_Cb_tab[v]) >> SCALEBITS)]; c->v = uiclp[(int)((CU_Cr_tab[u] + CV_Cr_tab[v]) >> SCALEBITS)]; + + c->yuyv_v4_u = PACK_YUYV(c, y0, y1, u, v); + c->yuyv_v4_l = PACK_YUYV(c, y2, y3, u, v); + c->yuyv_v1_ul = PACK_YUYV(c, y0, y0, u, v); + c->yuyv_v1_ur = PACK_YUYV(c, y1, y1, u, v); + c->yuyv_v1_ll = PACK_YUYV(c, y2, y2, u, v); + c->yuyv_v1_lr = PACK_YUYV(c, y3, y3, u, v); } } -//#define PACK_YUV(cb,y0,y1,u,v) ((cb->y0<<24)|(((unsigned char)cb->u)<<16)|(cb->y1<<8)|(((unsigned char)cb->v))) -#define PACK_YUV(cb,y0,y1,u,v) ((((unsigned char)cb->v)<<24)|(cb->y1<<16)|(((unsigned char)cb->u)<<8)|(cb->y0)) - -#define TO_YUY2_U0(cb) PACK_YUV(cb,y0,y0,u,v) -#define TO_YUY2_U1(cb) PACK_YUV(cb,y1,y1,u,v) -#define TO_YUY2_L0(cb) PACK_YUV(cb,y2,y2,u,v) -#define TO_YUY2_L1(cb) PACK_YUV(cb,y3,y3,u,v) - -#define TO_YUY2_U(cb) PACK_YUV(cb,y0,y1,u,v) -#define TO_YUY2_L(cb) PACK_YUV(cb,y2,y3,u,v) - /* ------------------------------------------------------------------------ */ inline void cvid_v1_yuy2(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb) { -unsigned long *vptr = (unsigned long *)frm, rgb; +unsigned long *vptr = (unsigned long *)frm; int row_inc = stride/4; - vptr[0] = TO_YUY2_U0(cb); - vptr[1] = TO_YUY2_U1(cb); - vptr += row_inc; if(vptr > (unsigned long *)end) return; + if(vptr > (unsigned long *)end) return; + vptr[0] = cb->yuyv_v1_ul; + vptr[1] = cb->yuyv_v1_ur; - vptr[0] = TO_YUY2_U0(cb); - vptr[1] = TO_YUY2_U1(cb); vptr += row_inc; if(vptr > (unsigned long *)end) return; + vptr[0] = cb->yuyv_v1_ul; + vptr[1] = cb->yuyv_v1_ur; - vptr[0] = TO_YUY2_L0(cb); - vptr[1] = TO_YUY2_L1(cb); vptr += row_inc; if(vptr > (unsigned long *)end) return; + vptr[0] = cb->yuyv_v1_ll; + vptr[1] = cb->yuyv_v1_lr; - vptr[0] = TO_YUY2_L0(cb); - vptr[1] = TO_YUY2_L1(cb); + vptr += row_inc; if(vptr > (unsigned long *)end) return; + vptr[0] = cb->yuyv_v1_ll; + vptr[1] = cb->yuyv_v1_lr; } @@ -136,21 +291,21 @@ inline void cvid_v4_yuy2(unsigned char *frm, unsigned char *end, int stride, cvi unsigned long *vptr = (unsigned long *)frm; int row_inc = stride/4; - vptr[0] = TO_YUY2_U(cb0); - vptr[1] = TO_YUY2_U(cb1); + if(vptr > (unsigned long *)end) return; + vptr[0] = cb0->yuyv_v4_u; + vptr[1] = cb1->yuyv_v4_u; + vptr += row_inc; if(vptr > (unsigned long *)end) return; + vptr[0] = cb0->yuyv_v4_l; + vptr[1] = cb1->yuyv_v4_l; - vptr[0] = TO_YUY2_L(cb0); - vptr[1] = TO_YUY2_L(cb1); vptr += row_inc; if(vptr > (unsigned long *)end) return; + vptr[0] = cb2->yuyv_v4_u; + vptr[1] = cb3->yuyv_v4_u; - vptr[0] = TO_YUY2_U(cb2); - vptr[1] = TO_YUY2_U(cb3); vptr += row_inc; if(vptr > (unsigned long *)end) return; - - vptr[0] = TO_YUY2_L(cb2); - vptr[1] = TO_YUY2_L(cb3); - + vptr[0] = cb2->yuyv_v4_l; + vptr[1] = cb3->yuyv_v4_l; } @@ -377,13 +532,17 @@ int i, x; * context - the context created by decode_cinepak_init(). * buf - the input buffer to be decoded * size - the size of the input buffer - * frame - the output frame buffer (24 or 32 bit per pixel) + * frame - the output frame buffer * width - the width of the output frame * height - the height of the output frame * bit_per_pixel - the number of bits per pixel allocated to the output - * frame (only 24 or 32 bpp are supported) + * frame; depths support: + * 32: BGR32 + * 24: BGR24 + * 16: YUYV + * 12: YV12 */ -void decode_cinepak(void *context, unsigned char *buf, int size, unsigned char *frame, int width, int height, int bit_per_pixel, int stride_) +void decode_cinepak(void *context, unsigned char *buf, int size, unsigned char *frame, unsigned int width, unsigned int height, int bit_per_pixel, int stride_) { cinepak_info *cvinfo = (cinepak_info *)context; cvid_codebook *v4_codebook, *v1_codebook, *codebook = NULL; @@ -391,7 +550,7 @@ unsigned long x, y, y_bottom, frame_flags, strips, cv_width, cv_height, cnum, strip_id, chunk_id, x0, y0, x1, y1, ci, flag, mask; long len, top_size, chunk_size; unsigned char *frm_ptr, *frm_end; -int i, cur_strip, d0, d1, d2, d3, frm_stride, bpp = 3; +unsigned int i, cur_strip, d0, d1, d2, d3, frm_stride, bpp = 3; int modulo; void (*read_codebook)(cvid_codebook *c, int mode) = read_codebook_24; void (*cvid_v1)(unsigned char *frm, unsigned char *end, int stride, cvid_codebook *cb) = cvid_v1_24; @@ -409,19 +568,29 @@ void (*cvid_v4)(unsigned char *frm, unsigned char *end, int stride, cvid_codeboo switch(bit_per_pixel) { - case 16: + case 12: // YV12 + bpp = 1; // for the purposes of stride + read_codebook = read_codebook_yv12; + cvid_v1 = cvid_v1_yv12; + cvid_v4 = cvid_v4_yv12; + yv12_y_plane = frame; + yv12_v_plane = frame + width * height; + yv12_u_plane = frame + (width * height) + + (width * height / 4); + break; + case 16: // YUYV bpp = 2; read_codebook = read_codebook_yuy2; cvid_v1 = cvid_v1_yuy2; cvid_v4 = cvid_v4_yuy2; break; - case 24: + case 24: // BGR24 bpp = 3; read_codebook = read_codebook_24; cvid_v1 = cvid_v1_24; cvid_v4 = cvid_v4_24; break; - case 32: + case 32: // BGR32 bpp = 4; read_codebook = read_codebook_32; cvid_v1 = cvid_v1_32; @@ -438,7 +607,7 @@ void (*cvid_v4)(unsigned char *frm, unsigned char *end, int stride, cvid_codeboo if(len & 0x01) len++; /* AVIs tend to have a size mismatch */ if(len != size) { - printf("CVID: corruption %d (QT/AVI) != %ld (CV)\n", size, len); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, "CVID: corruption %d (QT/AVI) != %ld (CV)\n", size, len); // return; } } @@ -451,7 +620,7 @@ void (*cvid_v4)(unsigned char *frm, unsigned char *end, int stride, cvid_codeboo { if(strips >= MAX_STRIPS) { - printf("CVID: strip overflow (more than %d)\n", MAX_STRIPS); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, "CVID: strip overflow (more than %d)\n", MAX_STRIPS); return; } @@ -459,13 +628,13 @@ void (*cvid_v4)(unsigned char *frm, unsigned char *end, int stride, cvid_codeboo { if((cvinfo->v4_codebook[i] = (cvid_codebook *)calloc(sizeof(cvid_codebook), 260)) == NULL) { - printf("CVID: codebook v4 alloc err\n"); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, "CVID: codebook v4 alloc err\n"); return; } if((cvinfo->v1_codebook[i] = (cvid_codebook *)calloc(sizeof(cvid_codebook), 260)) == NULL) { - printf("CVID: codebook v1 alloc err\n"); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, "CVID: codebook v1 alloc err\n"); return; } } @@ -473,7 +642,7 @@ void (*cvid_v4)(unsigned char *frm, unsigned char *end, int stride, cvid_codeboo cvinfo->strip_num = strips; #if DBUG - printf("CVID: <%ld,%ld> strips %ld\n", cv_width, cv_height, strips); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, "CVID: <%ld,%ld> strips %ld\n", cv_width, cv_height, strips); #endif for(cur_strip = 0; cur_strip < strips; cur_strip++) @@ -498,10 +667,10 @@ void (*cvid_v4)(unsigned char *frm, unsigned char *end, int stride, cvid_codeboo top_size -= 12; x = 0; if(x1 != width) - printf("CVID: Warning x1 (%ld) != width (%d)\n", x1, width); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, "CVID: Warning x1 (%ld) != width (%d)\n", x1, width); x1 = width; #if DBUG - printf(" %d) %04lx %04ld <%ld,%ld> <%ld,%ld> yt %ld %d\n", + mp_msg(MSGT_DECVIDEO, MSGL_WARN, " %d) %04lx %04ld <%ld,%ld> <%ld,%ld> yt %ld %d\n", cur_strip, strip_id, top_size, x0, y0, x1, y1, y_bottom); #endif @@ -511,7 +680,7 @@ x1 = width; chunk_size = get_word(); #if DBUG - printf(" %04lx %04ld\n", chunk_id, chunk_size); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, " %04lx %04ld\n", chunk_id, chunk_size); #endif top_size -= chunk_size; chunk_size -= 4; @@ -526,7 +695,7 @@ x1 = width; cnum = (chunk_size - modulo) / 6; for(i = 0; i < cnum; i++) read_codebook(codebook+i, 0); while (modulo--) - get_byte(); + in_buffer++; break; case 0x2400: @@ -689,7 +858,7 @@ x1 = width; break; default: - printf("CVID: unknown chunk_id %08lx\n", chunk_id); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, "CVID: unknown chunk_id %08lx\n", chunk_id); while(chunk_size > 0) { skip_byte(); chunk_size--; } break; } @@ -706,7 +875,7 @@ x1 = width; xlen = get_byte() << 16; xlen |= get_byte() << 8; xlen |= get_byte(); /* Read Len */ - printf("CVID: END INFO chunk size %d cvid size1 %ld cvid size2 %ld\n", size, len, xlen); + mp_msg(MSGT_DECVIDEO, MSGL_WARN, "CVID: END INFO chunk size %d cvid size1 %ld cvid size2 %ld\n", size, len, xlen); } } } diff --git a/dec_video.c b/dec_video.c index 6a0c2fb20d..0e6e6f42b8 100644 --- a/dec_video.c +++ b/dec_video.c @@ -1,4 +1,6 @@ +#define USE_MP_IMAGE + #include "config.h" #include @@ -22,12 +24,18 @@ extern int verbose; // defined in mplayer.c #include "codec-cfg.h" +#ifdef USE_LIBVO2 +#include "libvo2/libvo2.h" +#else #include "libvo/video_out.h" +#endif #include "stheader.h" #include "dec_video.h" +#include "roqav.h" + // =================================================================== extern int benchmark; @@ -39,19 +47,268 @@ extern double cur_video_time_usage; extern double cur_vout_time_usage; extern vo_vaa_t vo_vaa; +extern int frameratecode2framerate[16]; + +#include "dll_init.h" + +//#include +//#include "libvo/img_format.h" + +#include "libmpeg2/mpeg2.h" +#include "libmpeg2/mpeg2_internal.h" + #include "postproc/postprocess.h" #include "cpudetect.h" +extern picture_t *picture; // exported from libmpeg2/decode.c + int divx_quality=0; +#ifdef USE_DIRECTSHOW +#include "loader/dshow/DS_VideoDecoder.h" +static DS_VideoDecoder* ds_vdec=NULL; +#endif + +#ifdef USE_LIBAVCODEC +#ifdef USE_LIBAVCODEC_SO +#include +#else +#include "libavcodec/avcodec.h" +#endif + static AVCodec *lavc_codec=NULL; + static AVCodecContext lavc_context; + static AVPicture lavc_picture; + int avcodec_inited=0; +#endif +#ifdef FF_POSTPROCESS + unsigned int lavc_pp=0; +#endif + +#ifdef USE_DIVX +#ifndef NEW_DECORE +#include "opendivx/decore.h" +#else +#include +#endif +#endif + +#ifdef USE_XANIM +#include "xacodec.h" +#endif + +#ifdef USE_TV +#include "libmpdemux/tv.h" +extern int tv_param_on; +extern tvi_handle_t *tv_handler; +#endif + +void AVI_Decode_RLE8(char *image,char *delta,int tdsize, + unsigned int *map,int imagex,int imagey,unsigned char x11_bytes_pixel); + +void AVI_Decode_Video1_16( + char *encoded, + int encoded_size, + char *decoded, + int width, + int height, + int bytes_per_pixel); + +void AVI_Decode_Video1_8( + char *encoded, + int encoded_size, + char *decoded, + int width, + int height, + unsigned char *palette_map, + int bytes_per_pixel); + +void *init_fli_decoder(int width, int height); + +void decode_fli_frame( + unsigned char *encoded, + int encoded_size, + unsigned char *decoded, + int width, + int height, + int bytes_per_pixel, + void *context); + +void qt_decode_rle( + unsigned char *encoded, + int encoded_size, + unsigned char *decoded, + int width, + int height, + int encoded_bpp, + int bytes_per_pixel); + +void decode_nuv( + unsigned char *encoded, + int encoded_size, + unsigned char *decoded, + int width, + int height); + +void *decode_cinepak_init(void); + +void decode_cinepak( + void *context, + unsigned char *buf, + int size, + unsigned char *frame, + unsigned int width, + unsigned int height, + int bit_per_pixel, + int stride); + +void decode_cyuv( + unsigned char *buf, + int size, + unsigned char *frame, + int width, + int height, + int bit_per_pixel); + +int qt_init_decode_smc(void); + +void qt_decode_smc( + unsigned char *encoded, + int encoded_size, + unsigned char *decoded, + int width, + int height, + unsigned char *palette_map, + int bytes_per_pixel); + +void decode_duck_tm1( + unsigned char *encoded, + int encoded_size, + unsigned char *decoded, + int width, + int height, + int bytes_per_pixel); + +#ifdef HAVE_PNG +void decode_mpng( + unsigned char *encoded, + int encoded_size, + unsigned char *decoded, + int width, + int height, + int bytes_per_pixel); +#endif + +void qt_decode_rpza( + unsigned char *encoded, + int encoded_size, + unsigned char *decoded, + int width, + int height, + int bytes_per_pixel); + +//**************************************************************************// +// The OpenDivX stuff: +//**************************************************************************// + +#ifndef NEW_DECORE + +static unsigned char *opendivx_src[3]; +static int opendivx_stride[3]; + +// callback, the opendivx decoder calls this for each frame: +void convert_linux(unsigned char *puc_y, int stride_y, + unsigned char *puc_u, unsigned char *puc_v, int stride_uv, + unsigned char *bmp, int width_y, int height_y){ + +// printf("convert_yuv called %dx%d stride: %d,%d\n",width_y,height_y,stride_y,stride_uv); + + opendivx_src[0]=puc_y; + opendivx_src[1]=puc_u; + opendivx_src[2]=puc_v; + + opendivx_stride[0]=stride_y; + opendivx_stride[1]=stride_uv; + opendivx_stride[2]=stride_uv; +} +#endif + int get_video_quality_max(sh_video_t *sh_video){ -// switch(sh_video->codec->driver){ + switch(sh_video->codec->driver){ +#ifdef USE_WIN32DLL + case VFM_VFW: + case VFM_VFWEX: + return 9; // for Divx.dll (divx4) +#endif +#ifdef USE_DIRECTSHOW + case VFM_DSHOW: + return 4; +#endif +#ifdef MPEG12_POSTPROC + case VFM_MPEG: + return GET_PP_QUALITY_MAX; +#endif +#ifdef FF_POSTPROCESS + case VFM_FFMPEG: + return GET_PP_QUALITY_MAX; +#endif +#ifdef USE_DIVX + case VFM_DIVX4: + case VFM_ODIVX: +#ifdef NEW_DECORE + return 9; // for divx4linux +#else + return GET_PP_QUALITY_MAX; // for opendivx +#endif +#endif + } return 0; } void set_video_quality(sh_video_t *sh_video,int quality){ -// switch(sh_video->codec->driver){ + switch(sh_video->codec->driver){ +#ifdef USE_WIN32DLL + case VFM_VFW: + case VFM_VFWEX: + vfw_set_postproc(sh_video,10*quality); + break; +#endif +#ifdef USE_DIRECTSHOW + case VFM_DSHOW: { + if(quality<0 || quality>4) quality=4; + DS_VideoDecoder_SetValue(ds_vdec,"Quality",quality); + } + break; +#endif +#ifdef MPEG12_POSTPROC + case VFM_MPEG: { + if(quality<0 || quality>GET_PP_QUALITY_MAX) quality=GET_PP_QUALITY_MAX; + picture->pp_options=getPpModeForQuality(quality); + } + break; +#endif +#ifdef FF_POSTPROCESS + case VFM_FFMPEG: + if(quality<0 || quality>GET_PP_QUALITY_MAX) quality=GET_PP_QUALITY_MAX; + lavc_pp=getPpModeForQuality(quality); + break; +#endif +#ifdef USE_DIVX + case VFM_DIVX4: + case VFM_ODIVX: { + DEC_SET dec_set; +#ifdef NEW_DECORE + if(quality<0 || quality>9) quality=9; + dec_set.postproc_level=quality*10; +#else + if(quality<0 || quality>GET_PP_QUALITY_MAX) quality=GET_PP_QUALITY_MAX; + dec_set.postproc_level=getPpModeForQuality(quality); +#endif + decore(0x123,DEC_OPT_SETPP,&dec_set,NULL); + } +#endif + break; + } } int set_video_colors(sh_video_t *sh_video,char *item,int value) @@ -103,15 +360,93 @@ int set_video_colors(sh_video_t *sh_video,char *item,int value) } } try_sw_control: +#ifdef USE_DIRECTSHOW + if(sh_video->codec->driver==VFM_DSHOW){ + DS_VideoDecoder_SetValue(ds_vdec,item,value); + return 1; + } +#endif +#ifdef NEW_DECORE +#ifdef DECORE_VERSION +#if DECORE_VERSION >= 20011010 + if(sh_video->codec->driver==VFM_DIVX4){ + int option; + if(!strcmp(item,"Brightness")) option=DEC_GAMMA_BRIGHTNESS; + else if(!strcmp(item, "Contrast")) option=DEC_GAMMA_CONTRAST; + else if(!strcmp(item,"Saturation")) option=DEC_GAMMA_SATURATION; + else return 0; + value = (value * 256) / 100 - 128; + decore(0x123, DEC_OPT_GAMMA, (void *)option, (void *) value); + return 1; + } +#endif +#endif +#endif +#ifdef USE_TV + + if (tv_param_on == 1) + { + if (!strcmp(item, "Brightness")) + { + tv_set_color_options(tv_handler, TV_COLOR_BRIGHTNESS, value); + return(1); + } + if (!strcmp(item, "Hue")) + { + tv_set_color_options(tv_handler, TV_COLOR_HUE, value); + return(1); + } + if (!strcmp(item, "Saturation")) + { + tv_set_color_options(tv_handler, TV_COLOR_SATURATION, value); + return(1); + } + if (!strcmp(item, "Contrast")) + { + tv_set_color_options(tv_handler, TV_COLOR_CONTRAST, value); + return(1); + } + } +#endif return 0; } void uninit_video(sh_video_t *sh_video){ if(!sh_video->inited) return; mp_msg(MSGT_DECVIDEO,MSGL_V,"uninit video: %d \n",sh_video->codec->driver); -// switch(sh_video->codec->driver){ + switch(sh_video->codec->driver){ +#ifdef USE_LIBAVCODEC + case VFM_FFMPEG: + if (avcodec_close(&lavc_context) < 0) + mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantCloseCodec); + break; +#endif +#ifdef USE_DIRECTSHOW + case VFM_DSHOW: // Win32/DirectShow + if(ds_vdec){ DS_VideoDecoder_Destroy(ds_vdec); ds_vdec=NULL; } + break; +#endif + case VFM_MPEG: + mpeg2_free_image_buffers (picture); + break; +#ifdef USE_XANIM + case VFM_XANIM: + xacodec_exit(); + break; +#endif +#ifdef USE_DIVX + case VFM_DIVX4: + case VFM_ODIVX: + decore(0x123,DEC_OPT_RELEASE,NULL,NULL); + break; +#endif + } + if(sh_video->our_out_buffer){ + free(sh_video->our_out_buffer); + sh_video->our_out_buffer=NULL; + } sh_video->inited=0; } @@ -126,9 +461,328 @@ sh_video->our_out_buffer_size=0U; sh_video->image=new_mp_image(sh_video->disp_w,sh_video->disp_h); mp_image_setfmt(sh_video->image,out_fmt); -//switch(sh_video->codec->driver) +switch(sh_video->codec->driver){ + case VFM_ROQVIDEO: +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; +#else + sh_video->our_out_buffer_size = sh_video->disp_w * sh_video->disp_h * 1.5; + sh_video->our_out_buffer = (char*)memalign(64, sh_video->our_out_buffer_size); +#endif + sh_video->context = roq_decode_video_init(); + break; + case VFM_CINEPAK: { +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; +#else + int bpp=((out_fmt&255)+7)/8; + sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp; + sh_video->our_out_buffer = (char*)memalign(64, sh_video->our_out_buffer_size); +#endif + sh_video->context = decode_cinepak_init(); + break; + } + case VFM_XANIM: { +#ifdef USE_XANIM + int ret=xacodec_init_video(sh_video,out_fmt); + if(!ret) return 0; +#else +// mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_NoXAnimSupport); + mp_msg(MSGT_DECVIDEO, MSGL_ERR, "MPlayer was compiled WIHTOUT XAnim support!\n"); + return 0; +#endif + break; + } +#ifdef USE_WIN32DLL + case VFM_VFW: { + if(!init_vfw_video_codec(sh_video,0)) { + return 0; + } + mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32 video codec init OK!\n"); + /* Warning: these pitches tested only with YUY2 fourcc */ + pitches[0] = 16; pitches[1] = pitches[2] = 8; + break; + } + case VFM_VFWEX: { + if(!init_vfw_video_codec(sh_video,1)) { + return 0; + } + mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32Ex video codec init OK!\n"); + /* Warning: these pitches tested only with YUY2 fourcc */ + pitches[0] = 16; pitches[1] = pitches[2] = 8; + break; + } + case VFM_DSHOW: { // Win32/DirectShow +#ifndef USE_DIRECTSHOW + mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_NoDShowSupport); + return 0; +#else + int bpp; + if(!(ds_vdec=DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, 0))){ +// if(DS_VideoDecoder_Open(sh_video->codec->dll,&sh_video->codec->guid, sh_video->bih, 0, NULL)){ + mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingDLLcodec,sh_video->codec->dll); + mp_msg(MSGT_DECVIDEO,MSGL_HINT,"Maybe you forget to upgrade your win32 codecs?? It's time to download the new\n"); + mp_msg(MSGT_DECVIDEO,MSGL_HINT,"package from: ftp://mplayerhq.hu/MPlayer/releases/w32codec.zip !\n"); +// mp_msg(MSGT_DECVIDEO,MSGL_HINT,"Or you should disable DShow support: make distclean;make -f Makefile.No-DS\n"); + return 0; + } +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; + bpp=sh_video->image->bpp; + if(sh_video->image->flags&MP_IMGFLAG_YUV){ + DS_VideoDecoder_SetDestFmt(ds_vdec,bpp,out_fmt); // YUV + } else { + DS_VideoDecoder_SetDestFmt(ds_vdec,out_fmt&255,0); // RGB/BGR + } +#else + switch(out_fmt){ + case IMGFMT_YUY2: + case IMGFMT_UYVY: + bpp=16; + DS_VideoDecoder_SetDestFmt(ds_vdec,16,out_fmt);break; // packed YUV + case IMGFMT_YV12: + case IMGFMT_I420: + case IMGFMT_IYUV: + bpp=12; + DS_VideoDecoder_SetDestFmt(ds_vdec,12,out_fmt);break; // planar YUV + default: + bpp=((out_fmt&255)+7)&(~7); + DS_VideoDecoder_SetDestFmt(ds_vdec,out_fmt&255,0); // RGB/BGR + } + sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp/8; // FIXME!!! + sh_video->our_out_buffer = (char*)memalign(64,sh_video->our_out_buffer_size); +#endif + /* Warning: these pitches tested only with YUY2 fourcc */ + pitches[0] = 16; pitches[1] = pitches[2] = 8; + DS_SetAttr_DivX("Quality",divx_quality); + DS_VideoDecoder_StartInternal(ds_vdec); +// printf("DivX setting result = %d\n", DS_SetAttr_DivX("Quality",divx_quality) ); +// printf("DivX setting result = %d\n", DS_SetValue_DivX("Brightness",60) ); + + mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: Win32/DShow video codec init OK!\n"); + break; +#endif + } +#else /* !USE_WIN32DLL */ + case VFM_VFW: + case VFM_DSHOW: + case VFM_VFWEX: + mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_NoWfvSupport); + return 0; +#endif /* !USE_WIN32DLL */ + case VFM_ODIVX: { // OpenDivX +#ifndef USE_DIVX + mp_msg(MSGT_DECVIDEO,MSGL_ERR,"MPlayer was compiled WITHOUT OpenDivx support!\n"); + return 0; +#else + mp_msg(MSGT_DECVIDEO,MSGL_V,"OpenDivX video codec\n"); + { DEC_PARAM dec_param; + DEC_SET dec_set; + memset(&dec_param,0,sizeof(dec_param)); +#ifdef NEW_DECORE + dec_param.output_format=DEC_USER; +#else + dec_param.color_depth = 32; +#endif + dec_param.x_dim = sh_video->bih->biWidth; + dec_param.y_dim = sh_video->bih->biHeight; + decore(0x123, DEC_OPT_INIT, &dec_param, NULL); + dec_set.postproc_level = divx_quality; + decore(0x123, DEC_OPT_SETPP, &dec_set, NULL); + } + mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: OpenDivX video codec init OK!\n"); + break; +#endif + } + case VFM_DIVX4: { // DivX4Linux +#ifndef NEW_DECORE + mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_NoDivx4Support); + return 0; +#else + mp_msg(MSGT_DECVIDEO,MSGL_V,"DivX4Linux video codec\n"); + { DEC_PARAM dec_param; + DEC_SET dec_set; + int bits=16; + memset(&dec_param,0,sizeof(dec_param)); + switch(out_fmt){ + case IMGFMT_YV12: dec_param.output_format=DEC_YV12;bits=12;break; + case IMGFMT_YUY2: dec_param.output_format=DEC_YUY2;break; + case IMGFMT_UYVY: dec_param.output_format=DEC_UYVY;break; + case IMGFMT_I420: dec_param.output_format=DEC_420;bits=12;break; + case IMGFMT_BGR15: dec_param.output_format=DEC_RGB555_INV;break; + case IMGFMT_BGR16: dec_param.output_format=DEC_RGB565_INV;break; + case IMGFMT_BGR24: dec_param.output_format=DEC_RGB24_INV;bits=24;break; + case IMGFMT_BGR32: dec_param.output_format=DEC_RGB32_INV;bits=32;break; + default: + mp_msg(MSGT_DECVIDEO,MSGL_ERR,"Unsupported out_fmt: 0x%X\n",out_fmt); + return 0; + } + dec_param.x_dim = sh_video->bih->biWidth; + dec_param.y_dim = sh_video->bih->biHeight; + decore(0x123, DEC_OPT_INIT, &dec_param, NULL); + dec_set.postproc_level = divx_quality; + decore(0x123, DEC_OPT_SETPP, &dec_set, NULL); +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; +#else + sh_video->our_out_buffer_size = ((bits*dec_param.x_dim+7)/8)*dec_param.y_dim; + sh_video->our_out_buffer = (char*)memalign(64,sh_video->our_out_buffer_size); +// sh_video->our_out_buffer = shmem_alloc(dec_param.x_dim*dec_param.y_dim*5); +#endif + } + mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: OpenDivX video codec init OK!\n"); + break; +#endif + } + case VFM_FFMPEG: { // FFmpeg's libavcodec +#ifndef USE_LIBAVCODEC + mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_NoLAVCsupport); + return 0; +#else + /* Just because we know that */ + pitches[0] = 16; + pitches[1] = pitches[2] = 8; + mp_msg(MSGT_DECVIDEO,MSGL_V,"FFmpeg's libavcodec video codec\n"); + if(!avcodec_inited){ + avcodec_init(); + avcodec_register_all(); + avcodec_inited=1; + } + lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh_video->codec->dll); + if(!lavc_codec){ + mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh_video->codec->dll); + return 0; + } + memset(&lavc_context, 0, sizeof(lavc_context)); +// sh_video->disp_h/=2; // !! + lavc_context.width=sh_video->disp_w; + lavc_context.height=sh_video->disp_h; + mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"libavcodec.size: %d x %d\n",lavc_context.width,lavc_context.height); + if (sh_video->format == mmioFOURCC('R', 'V', '1', '3')) + lavc_context.sub_id = 3; + /* open it */ + if (avcodec_open(&lavc_context, lavc_codec) < 0) { + mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); + return 0; + } +#ifdef FF_POSTPROCESS + lavc_pp=divx_quality; +#endif + mp_msg(MSGT_DECVIDEO,MSGL_V,"INFO: libavcodec init OK!\n"); + break; +#endif + } + + case VFM_MPEG: { + // init libmpeg2: + mpeg2_init(); +#ifdef MPEG12_POSTPROC + picture->pp_options=divx_quality; +#else + if(divx_quality) mp_msg(MSGT_DECVIDEO,MSGL_HINT,MSGTR_MpegPPhint); +#endif + /* Just because we know that */ + pitches[0] = 16; + pitches[1] = pitches[2] = 8; + // send seq header to the decoder: + mpeg2_decode_data(NULL,videobuffer,videobuffer+videobuf_len,0); + mpeg2_allocate_image_buffers (picture); + break; + } + case VFM_RAW: { + if (sh_video->format != 0x0) + /* set out_fmt */ + sh_video->codec->outfmt[sh_video->outfmtidx] = sh_video->format; + break; + } + case VFM_RLE: { + int bpp=((out_fmt&255)+7)/8; // RGB only +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; +#else + sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp; // FIXME!!! + sh_video->our_out_buffer = (char*)memalign(64,sh_video->our_out_buffer_size); +#endif + if(bpp==2){ // 15 or 16 bpp ==> palette conversion! + unsigned int* pal=(unsigned int*)(((char*)sh_video->bih)+40); + int cols=(sh_video->bih->biSize-40)/4; + //int cols=1<<(sh_video->bih->biBitCount); + int i; + if(cols>256) cols=256; + mp_msg(MSGT_DECVIDEO,MSGL_V,"RLE: converting palette for %d colors.\n",cols); + for(i=0;i>8)&255; + unsigned int r=(c>>16)&255; + if((out_fmt&255)==15) + pal[i]=((r>>3)<<10)|((g>>3)<<5)|((b>>3)); + else + pal[i]=((r>>3)<<11)|((g>>2)<<5)|((b>>3)); + } + } + break; + case VFM_FLI: + sh_video->context = init_fli_decoder(sh_video->disp_w, sh_video->disp_h); + case VFM_MSVIDC: + case VFM_QTRLE: + case VFM_DUCKTM1: +#ifdef HAVE_PNG + case VFM_MPNG: +#endif + case VFM_QTRPZA: + { +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; +#else + int bpp=((out_fmt&255)+7)/8; // RGB only + sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp; // FIXME!!! + sh_video->our_out_buffer = (char*)memalign(64,sh_video->our_out_buffer_size); +#endif +if ((sh_video->codec->driver == VFM_QTRLE) && (sh_video->bih->biBitCount != 24)) + printf ( + " *** FYI: This Quicktime file is using %d-bit RLE Animation\n" \ + " encoding, which is not yet supported by MPlayer. But if you upload\n" \ + " this Quicktime file to the MPlayer FTP, the team could look at it.\n", + sh_video->bih->biBitCount); + + break; + } + case VFM_QTSMC: + { + if (qt_init_decode_smc() != 0) + mp_msg(MSGT_DECVIDEO, MSGL_ERR, "SMC decoder could not allocate enough memory"); +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; +#else + int bpp=((out_fmt&255)+7)/8; // RGB only + sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*bpp; // FIXME!!! + sh_video->our_out_buffer = (char*)memalign(64, sh_video->our_out_buffer_size); +#endif + break; + } + case VFM_NUV: +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; +#else + sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*3/2; + sh_video->our_out_buffer = (char *)memalign(64,sh_video->our_out_buffer_size); +#endif + break; + case VFM_CYUV: { +// int bpp=((out_fmt&255)+7)/8; +#ifdef USE_MP_IMAGE + sh_video->image->type=MP_IMGTYPE_STATIC; +#else + sh_video->our_out_buffer_size = sh_video->disp_w*sh_video->disp_h*3; + sh_video->our_out_buffer = (char*)memalign(64, sh_video->our_out_buffer_size); +#endif + break; + } + } +} sh_video->inited=1; return 1; } @@ -154,14 +808,407 @@ void init_video_vaa( unsigned width ) } } +#ifdef USE_LIBVO2 +int decode_video(vo2_handle_t *video_out,sh_video_t *sh_video,unsigned char *start,int in_size,int drop_frame){ +#else int decode_video(vo_functions_t *video_out,sh_video_t *sh_video,unsigned char *start,int in_size,int drop_frame){ -mp_image_t *mpi=NULL; +#endif + +mp_image_t *mpi=sh_video->image; +unsigned int out_fmt=mpi->imgfmt; //sh_video->codec->outfmt[sh_video->outfmtidx]; +int planar=(mpi->flags&MP_IMGFLAG_PLANAR)!=0; //(out_fmt==IMGFMT_YV12||out_fmt==IMGFMT_IYUV||out_fmt==IMGFMT_I420); int blit_frame=0; +void *vmem; +int painted; +static int double_buff_num = 0; + +//uint8_t* planes_[3]; +//uint8_t** planes=planes_; +//int stride_[3]; +//int* stride=stride_; + unsigned int t=GetTimer(); unsigned int t2; double tt; - + painted = 0; +#ifdef USE_MP_IMAGE +if(mpi->type!=MP_IMGTYPE_EXPORT) +if( !(mpi->flags&MP_IMGFLAG_ALLOCATED) && !(mpi->flags&MP_IMGFLAG_DIRECT) ){ + // allocate image buffer: + sh_video->our_out_buffer = (char *)memalign(64, mpi->width*mpi->height*mpi->bpp/8); + if((mpi->flags|MP_IMGFLAG_PLANAR) && (mpi->flags|MP_IMGFLAG_YUV)){ + // planar YUV + mpi->stride[0]=mpi->width; + mpi->stride[1]=mpi->stride[2]=mpi->width/2; + mpi->planes[0]=sh_video->our_out_buffer; + mpi->planes[1]=mpi->planes[0]+mpi->stride[0]*mpi->height; + mpi->planes[2]=mpi->planes[1]+mpi->stride[0]*mpi->height/4; + } else { + // packed YUV / RGB + mpi->stride[0]=mpi->width*mpi->bpp; + mpi->planes[0]=sh_video->our_out_buffer; + } + mpi->flags|=MP_IMGFLAG_ALLOCATED; + mp_msg(MSGT_DECVIDEO,MSGL_INFO,"mp_image: allocated %d bytes for %dx%dx%d [0x%X] image\n", + mpi->width*mpi->height*mpi->bpp/8, mpi->width, mpi->height, mpi->bpp, mpi->imgfmt); +} +#endif + +//printf("decode_frame(start: %p, size: %d, w: %d, h: %d)\n", +// start, in_size, sh_video->disp_w, sh_video->disp_h); + + //-------------------- Decode a frame: ----------------------- +switch(sh_video->codec->driver){ + case VFM_CINEPAK: + if (in_size == 0) + blit_frame = 0; + else + { + decode_cinepak(sh_video->context, start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, (out_fmt==IMGFMT_YV12)?12:(out_fmt==IMGFMT_YUY2)?16:(out_fmt&255), 0); + blit_frame = 3; + } + break; +#ifdef USE_XANIM + case VFM_XANIM: { + xacodec_image_t* image=xacodec_decode_frame(start,in_size,drop_frame?1:0); + if(image){ + blit_frame=2; + //planes=image->planes; + //stride=image->stride; + 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]; + } + break; + } +#endif +#ifdef USE_DIVX + case VFM_ODIVX: { + // OpenDivX + DEC_FRAME dec_frame; +#ifdef NEW_DECORE + DEC_PICTURE dec_pic; +#endif + // let's decode + dec_frame.length = in_size; + dec_frame.bitstream = start; + dec_frame.render_flag = drop_frame?0:1; + +#ifdef NEW_DECORE + dec_frame.bmp=&dec_pic; + dec_pic.y=dec_pic.u=dec_pic.v=NULL; + decore(0x123, (sh_video->format==mmioFOURCC('D','I','V','3'))?DEC_OPT_FRAME_311:DEC_OPT_FRAME, &dec_frame, NULL); +#else + opendivx_src[0]=NULL; + decore(0x123, 0, &dec_frame, NULL); +#endif + + if(!drop_frame) + + // let's display +#ifdef NEW_DECORE + if(dec_pic.y){ + mpi->planes[0]=dec_pic.y; + mpi->planes[1]=dec_pic.u; + mpi->planes[2]=dec_pic.v; + mpi->stride[0]=dec_pic.stride_y; + mpi->stride[1]=mpi->stride[2]=dec_pic.stride_uv; + blit_frame=2; + } +#else + if(opendivx_src[0]){ +// planes=opendivx_src; +// stride=opendivx_stride; + mpi->planes[0]=opendivx_src[0]; + mpi->planes[1]=opendivx_src[1]; + mpi->planes[2]=opendivx_src[2]; + mpi->stride[0]=opendivx_stride[0]; + mpi->stride[1]=opendivx_stride[1]; + mpi->stride[2]=opendivx_stride[2]; + blit_frame=2; + } +#endif + + break; + } +#endif +#ifdef NEW_DECORE + case VFM_DIVX4: { + // DivX4Linux + DEC_FRAME dec_frame; + // let's decode + dec_frame.length = in_size; + dec_frame.bitstream = start; + dec_frame.render_flag = drop_frame?0:1; + dec_frame.bmp=sh_video->our_out_buffer; + dec_frame.stride=sh_video->disp_w; +// printf("Decoding DivX4 frame\n"); + decore(0x123, (sh_video->format==mmioFOURCC('D','I','V','3'))?DEC_OPT_FRAME_311:DEC_OPT_FRAME, &dec_frame, NULL); + if(!drop_frame) blit_frame=3; + break; + } +#endif +#ifdef USE_DIRECTSHOW + case VFM_DSHOW: { // W32/DirectShow + if(drop_frame<2) + { + /* FIXME: WILL WORK ONLY FOR PACKED FOURCC. BUT WHAT ABOUT PLANAR? */ + vmem = 0; + if(use_dr_422) + { + vmem = bda.dga_addr + bda.offsets[0] + bda.offset.y; + if(vo_doublebuffering && bda.num_frames>1) + { + if(double_buff_num) vmem = bda.dga_addr + bda.offsets[1] + bda.offset.y; + else vmem = bda.dga_addr + bda.offsets[0] + bda.offset.y; + double_buff_num = double_buff_num ? 0 : 1; + } + } + DS_VideoDecoder_DecodeInternal(ds_vdec, start, in_size, 0, drop_frame ? 0 : vmem ? vmem : sh_video->our_out_buffer); + if(vmem) painted = 1; + } + if(!drop_frame && sh_video->our_out_buffer) blit_frame=3; + break; + } +#endif +#ifdef USE_LIBAVCODEC + case VFM_FFMPEG: { // libavcodec + int got_picture=0; + mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"Calling ffmpeg...\n"); + if(drop_frame<2 && in_size>0){ + int ret = avcodec_decode_video(&lavc_context, &lavc_picture, + &got_picture, start, in_size); +if(verbose>1){ + unsigned char *x="???"; + switch(lavc_context.pix_fmt){ + case PIX_FMT_YUV420P: x="YUV420P";break; + case PIX_FMT_YUV422: x="YUV422";break; + case PIX_FMT_RGB24: x="RGB24";break; + case PIX_FMT_BGR24: x="BGR24";break; +#ifdef PIX_FMT_YUV422P + case PIX_FMT_YUV422P: x="YUV422P";break; + case PIX_FMT_YUV444P: x="YUV444P";break; +#endif + } + mp_dbg(MSGT_DECVIDEO,MSGL_DBG2,"DONE -> got_picture=%d format=0x%X (%s) \n",got_picture, + lavc_context.pix_fmt,x); +} + if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); + if(!drop_frame && got_picture){ +// if(!drop_frame){ + if(planar){ +#ifdef FF_POSTPROCESS +#ifdef MBC + if(lavc_pp){ + // postprocess + int w=(sh_video->disp_w+15)&(~15); + int h=(sh_video->disp_h+15)&(~15); + int xoff=0; //(w-sh_video->disp_w)/2; + int yoff=0; //(h-sh_video->disp_h)/2; + if(!sh_video->our_out_buffer){ + sh_video->our_out_buffer = (char*)memalign(64,w*h*3/2); + memset(sh_video->our_out_buffer,0,w*h*3/2); + } + mpi->stride[0]=w; + mpi->stride[1]=mpi->stride[2]=w/2; + mpi->planes[0]=sh_video->our_out_buffer+mpi->stride[0]*yoff+xoff; + mpi->planes[2]=sh_video->our_out_buffer+w*h+mpi->stride[2]*(yoff>>1)+(xoff>>1); + mpi->planes[1]=mpi->planes[2]+w*h/4; + postprocess(lavc_picture.data,lavc_picture.linesize[0], + mpi->planes,mpi->stride[0], + sh_video->disp_w,sh_video->disp_h, + &quant_store[0][0],MBC+1,lavc_pp); + } else +#endif +#endif + { + //planes=lavc_picture.data; + //stride=lavc_picture.linesize; + mpi->planes[0]=lavc_picture.data[0]; + mpi->planes[1]=lavc_picture.data[1]; + mpi->planes[2]=lavc_picture.data[2]; + mpi->stride[0]=lavc_picture.linesize[0]; + mpi->stride[1]=lavc_picture.linesize[1]; + mpi->stride[2]=lavc_picture.linesize[2]; + if(lavc_context.pix_fmt==PIX_FMT_YUV422P){ + mpi->stride[1]*=2; + mpi->stride[2]*=2; + } + + //stride[1]=stride[2]=0; + //stride[0]/=2; + } + blit_frame=2; + } else { + int y; + // temporary hack - FIXME + if(!sh_video->our_out_buffer) + sh_video->our_out_buffer = (char*)memalign(64,sh_video->disp_w*sh_video->disp_h*2); + for(y=0;ydisp_h;y++){ + unsigned char *s0=lavc_picture.data[0]+lavc_picture.linesize[0]*y; + unsigned char *s1=lavc_picture.data[1]+lavc_picture.linesize[1]*y; + unsigned char *s2=lavc_picture.data[2]+lavc_picture.linesize[2]*y; + unsigned char *d=sh_video->our_out_buffer+y*2*sh_video->disp_w; + int x; + for(x=0;xdisp_w/2;x++){ + d[4*x+0]=s0[2*x+0]; + d[4*x+1]=s1[x]; + d[4*x+2]=s0[2*x+1]; + d[4*x+3]=s2[x]; + } + } + blit_frame=3; + } + + } + } + break; + } +#endif +#ifdef USE_WIN32DLL + case VFM_VFWEX: + case VFM_VFW: + { + int ret; + if(!in_size) break; + /* FIXME: WILL WORK ONLY FOR PACKED FOURCC. BUT WHAT ABOUT PLANAR? */ + vmem = 0; + if(use_dr_422) + { + vmem = bda.dga_addr + bda.offsets[0] + bda.offset.y; + if(vo_doublebuffering && bda.num_frames>1) + { + if(double_buff_num) vmem = bda.dga_addr + bda.offsets[1] + bda.offset.y; + else vmem = bda.dga_addr + bda.offsets[0] + bda.offset.y; + double_buff_num = double_buff_num ? 0 : 1; + } + sh_video->our_out_buffer = vmem; + } + if((ret=vfw_decode_video(sh_video,start,in_size,drop_frame,(sh_video->codec->driver==VFM_VFWEX) ))){ + mp_msg(MSGT_DECVIDEO,MSGL_WARN,"Error decompressing frame, err=%d\n",ret); + break; + } + if(vmem) painted=1; + if(!drop_frame) blit_frame=3; + break; + } +#endif + case VFM_MPEG: + if(out_fmt==IMGFMT_MPEGPES){ + // hardware decoding: + static vo_mpegpes_t packet; + mpeg2_decode_data(video_out, start, start+in_size,3); // parse headers + packet.data=start; + packet.size=in_size-4; + packet.timestamp=sh_video->timer*90000.0; + packet.id=0x1E0; //+sh_video->ds->id; + mpi->planes[0]=(uint8_t*)(&packet); + blit_frame=2; + } else { + // software decoding: + if( + mpeg2_decode_data(video_out, start, start+in_size,drop_frame) > 0 // decode + && (!drop_frame) + ) blit_frame=1; + } + break; + case VFM_RAW: +// planes[0]=start; +// blit_frame=2; + sh_video->our_out_buffer = start; + blit_frame=3; + break; + case VFM_RLE: +//void AVI_Decode_RLE8(char *image,char *delta,int tdsize, +// unsigned int *map,int imagex,int imagey,unsigned char x11_bytes_pixel); + AVI_Decode_RLE8(sh_video->our_out_buffer,start,in_size, + (int*)(((char*)sh_video->bih)+40), + sh_video->disp_w,sh_video->disp_h,((out_fmt&255)+7)/8); + blit_frame=3; + break; + case VFM_MSVIDC: + if (sh_video->bih->biBitCount == 16) + AVI_Decode_Video1_16( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, + ((out_fmt&255)+7)/8); + else + AVI_Decode_Video1_8( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, + (char *)sh_video->bih+40, ((out_fmt&255)+7)/8); + blit_frame = 3; + break; + case VFM_FLI: + decode_fli_frame( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, + ((out_fmt&255)+7)/8, + sh_video->context); + blit_frame = 3; + break; + case VFM_NUV: + decode_nuv( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h); + blit_frame = 3; + break; + case VFM_QTRLE: + qt_decode_rle( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, + sh_video->bih->biBitCount, + ((out_fmt&255)+7)/8); + blit_frame = 3; + break; + case VFM_QTSMC: + qt_decode_smc( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, + (unsigned char *)sh_video->bih+40, + ((out_fmt&255)+7)/8); + blit_frame = 3; + break; + case VFM_DUCKTM1: + decode_duck_tm1( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, + ((out_fmt&255)+7)/8); + blit_frame = 3; + break; +#ifdef HAVE_PNG + case VFM_MPNG: + decode_mpng( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w,sh_video->disp_h, + ((out_fmt&255)+7)/8 + ); + blit_frame = 3; + break; +#endif + case VFM_CYUV: + decode_cyuv(start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, (out_fmt==IMGFMT_YUY2)?16:(out_fmt&255)); + blit_frame = 3; + break; + case VFM_ROQVIDEO: + roq_decode_video(start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, sh_video->context); + blit_frame = 3; + break; + case VFM_QTRPZA: + qt_decode_rpza( + start, in_size, sh_video->our_out_buffer, + sh_video->disp_w, sh_video->disp_h, + ((out_fmt&255)+7)/8); + blit_frame = 3; + break; +} // switch //------------------------ frame decoded. -------------------- #ifdef ARCH_X86 @@ -183,13 +1230,62 @@ if(benchmark) if(tt > max_video_time_usage) max_video_time_usage=tt; cur_video_time_usage=tt; } - -if(mpi){ -// if(planar) -// video_out->draw_slice(mpi->planes,mpi->stride,sh_video->disp_w,sh_video->disp_h,0,0); -// else -// video_out->draw_frame(mpi->planes); - +if(painted) return 1; +switch(blit_frame){ +case 3: + if(planar){ + mpi->stride[0]=sh_video->disp_w; + mpi->stride[1]=mpi->stride[2]=sh_video->disp_w/2; + mpi->planes[0]=sh_video->our_out_buffer; + mpi->planes[2]=mpi->planes[0]+sh_video->disp_w*sh_video->disp_h; + mpi->planes[1]=mpi->planes[2]+sh_video->disp_w*sh_video->disp_h/4; + } else { + mpi->planes[0]=sh_video->our_out_buffer; + mpi->stride[0]=sh_video->disp_w*mpi->bpp; + if(sh_video->bih && sh_video->bih->biSize==1064) + mpi->planes[1]=&sh_video->bih[1]; // pointer to palette + else + mpi->planes[1]=NULL; + } +//#define VFM_RAW_POSTPROC +#ifdef VFM_RAW_POSTPROC + if (sh_video->codec->driver == VFM_RAW) + { + mp_dbg(MSGT_DECVIDEO, MSGL_V, "Postprocessing raw %s!\n", + vo_format_name(out_fmt)); + switch(out_fmt) + { + case IMGFMT_YV12: + postprocess(planes, stride[0], planes, stride[0], + sh_video->disp_w, sh_video->disp_h, planes[0], + 0, /*0x20000*/divx_quality); + break; +// case IMGFMT_UYVY: +// uyvytoyv12(start, planes[0], planes[1], planes[2], +// sh_video->disp_w, sh_video->disp_h, stride[0], stride[1], +// sh_video->disp_w*2); +// postprocess(planes, stride[0], planes, stride[0], +// sh_video->disp_w, sh_video->disp_h, planes[0], +// 0, /*0x20000*/divx_quality); +// break; + default: + mp_dbg(MSGT_DECVIDEO, MSGL_DBG2, "Unsuitable outformat (%s) for raw pp!\n", + vo_format_name(out_fmt)); + } + } +#endif +case 2: +#ifdef USE_LIBVO2 + if(planar) + vo2_draw_slice(video_out,planes,stride,sh_video->disp_w,sh_video->disp_h,0,0); + else + vo2_draw_frame(video_out,planes[0],sh_video->disp_w,sh_video->disp_w,sh_video->disp_h); +#else + if(planar) + video_out->draw_slice(mpi->planes,mpi->stride,sh_video->disp_w,sh_video->disp_h,0,0); + else + video_out->draw_frame(mpi->planes); +#endif t2=GetTimer()-t2; tt=t2*0.000001f; vout_time_usage+=tt; @@ -199,6 +1295,7 @@ if(mpi){ cur_vout_time_usage=tt; } blit_frame=1; + break; } return blit_frame; diff --git a/etc/codecs.conf b/etc/codecs.conf index 708c72de93..4714117df4 100644 --- a/etc/codecs.conf +++ b/etc/codecs.conf @@ -284,6 +284,7 @@ videocodec cvid status working fourcc cvid,CVID driver cinepak +; out YV12 out YUY2 out BGR32,BGR24