diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2009-02-13 03:52:51 +0200 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2009-02-13 03:52:51 +0200 |
commit | 738f66b1bc98073d74af7031c4454322157a15ec (patch) | |
tree | 25d69a5d92ea4440f7e08e3c82cc5bb3a1d4598e /libmpcodecs/vd_ffmpeg.c | |
parent | 1e869638280f962fb80f372d152234f21246c2af (diff) | |
parent | 9f8792e639fee0b706dc5ec83e9b9fa0cf432e61 (diff) | |
download | mpv-738f66b1bc98073d74af7031c4454322157a15ec.tar.bz2 mpv-738f66b1bc98073d74af7031c4454322157a15ec.tar.xz |
Merge svn changes up to r28549
Diffstat (limited to 'libmpcodecs/vd_ffmpeg.c')
-rw-r--r-- | libmpcodecs/vd_ffmpeg.c | 401 |
1 files changed, 193 insertions, 208 deletions
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c index 159136eac1..1395f524ee 100644 --- a/libmpcodecs/vd_ffmpeg.c +++ b/libmpcodecs/vd_ffmpeg.c @@ -16,11 +16,11 @@ #include "vd_internal.h" static const vd_info_t info = { - "FFmpeg's libavcodec codec family", - "ffmpeg", - "A'rpi", - "A'rpi, Michael, Alex", - "native codecs" + "FFmpeg's libavcodec codec family", + "ffmpeg", + "A'rpi", + "A'rpi, Michael, Alex", + "native codecs" }; LIBVD_EXTERN(ffmpeg) @@ -52,10 +52,6 @@ typedef struct { int lowres; } vd_ffmpeg_ctx; -//#ifdef CONFIG_LIBPOSTPROC -//unsigned int lavc_pp=0; -//#endif - #include "m_option.h" static int get_buffer(AVCodecContext *avctx, AVFrame *pic); @@ -68,7 +64,7 @@ static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic); static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic); static void mc_render_slice(struct AVCodecContext *s, const AVFrame *src, int offset[4], - int y, int type, int height); + int y, int type, int height); #endif const m_option_t lavc_decode_opts_conf[]={ @@ -82,9 +78,7 @@ const m_option_t lavc_decode_opts_conf[]={ OPT_INTRANGE("vismv", lavc_param.vismv, 0, 0, 9999999), OPT_INTRANGE("st", lavc_param.skip_top, 0, 0, 999), OPT_INTRANGE("sb", lavc_param.skip_bottom, 0, 0, 999), -#ifdef CODEC_FLAG2_FAST OPT_FLAG_CONSTANTS("fast", lavc_param.fast, 0, 0, CODEC_FLAG2_FAST), -#endif OPT_STRING("lowres", lavc_param.lowres_str, 0), OPT_STRING("skiploopfilter", lavc_param.skip_loop_filter_str, 0), OPT_STRING("skipidct", lavc_param.skip_idct_str, 0), @@ -115,30 +109,30 @@ static int control(sh_video_t *sh,int cmd,void* arg,...){ case VDCTRL_QUERY_FORMAT: { int format =(*((int*)arg)); - if( format == ctx->best_csp ) return CONTROL_TRUE;//supported - // possible conversions: - switch( format ){ + if( format == ctx->best_csp ) return CONTROL_TRUE;//supported + // possible conversions: + switch( format ){ case IMGFMT_YV12: case IMGFMT_IYUV: case IMGFMT_I420: - // "converted" using pointer/stride modification - if(avctx->pix_fmt==PIX_FMT_YUV420P) return CONTROL_TRUE;// u/v swap - if(avctx->pix_fmt==PIX_FMT_YUV422P && !ctx->do_dr1) return CONTROL_TRUE;// half stride - break; + // "converted" using pointer/stride modification + if(avctx->pix_fmt==PIX_FMT_YUV420P) return CONTROL_TRUE;// u/v swap + if(avctx->pix_fmt==PIX_FMT_YUV422P && !ctx->do_dr1) return CONTROL_TRUE;// half stride + break; #if CONFIG_XVMC case IMGFMT_XVMC_IDCT_MPEG2: case IMGFMT_XVMC_MOCO_MPEG2: if(avctx->pix_fmt==PIX_FMT_XVMC_MPEG2_IDCT) return CONTROL_TRUE; #endif - } + } return CONTROL_FALSE; } break; case VDCTRL_RESYNC_STREAM: avcodec_flush_buffers(avctx); - return CONTROL_TRUE; + return CONTROL_TRUE; case VDCTRL_QUERY_UNSEEN_FRAMES: - return avctx->has_b_frames + 10; + return avctx->has_b_frames + 10; } return CONTROL_UNKNOWN; } @@ -211,21 +205,21 @@ static int init(sh_video_t *sh){ ctx = sh->context = malloc(sizeof(vd_ffmpeg_ctx)); if (!ctx) - return 0; + return 0; memset(ctx, 0, sizeof(vd_ffmpeg_ctx)); - + lavc_codec = (AVCodec *)avcodec_find_decoder_by_name(sh->codec->dll); if(!lavc_codec){ - mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); + mp_msg(MSGT_DECVIDEO,MSGL_ERR,MSGTR_MissingLAVCcodec,sh->codec->dll); uninit(sh); - return 0; + return 0; } if(sh->opts->vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug) - ctx->do_slices=1; - + ctx->do_slices=1; + if(lavc_codec->capabilities&CODEC_CAP_DR1 && !do_vis_debug && lavc_codec->id != CODEC_ID_H264 && lavc_codec->id != CODEC_ID_INTERPLAY_VIDEO && lavc_codec->id != CODEC_ID_ROQ) - ctx->do_dr1=1; + ctx->do_dr1=1; ctx->b_age= ctx->ip_age[0]= ctx->ip_age[1]= 256*256*256*64; ctx->ip_count= ctx->b_count= 0; @@ -235,11 +229,7 @@ static int init(sh_video_t *sh){ #if CONFIG_XVMC -#ifdef CODEC_CAP_HWACCEL if(lavc_codec->capabilities & CODEC_CAP_HWACCEL){ -#else - if(lavc_codec->id == CODEC_ID_MPEG2VIDEO_XVMC){ -#endif /* CODEC_CAP_HWACCEL */ mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_XVMCAcceleratedCodec); assert(ctx->do_dr1);//these are must to! assert(ctx->do_slices); //it is (vo_)ffmpeg bug if this fails @@ -252,25 +242,20 @@ static int init(sh_video_t *sh){ }else #endif /* CONFIG_XVMC */ if(ctx->do_dr1){ - avctx->flags|= CODEC_FLAG_EMU_EDGE; + avctx->flags|= CODEC_FLAG_EMU_EDGE; avctx->get_buffer= get_buffer; avctx->release_buffer= release_buffer; avctx->reget_buffer= get_buffer; } -#ifdef CODEC_FLAG_NOT_TRUNCATED - avctx->flags|= CODEC_FLAG_NOT_TRUNCATED; -#endif avctx->flags|= lavc_param->bitexact; - + avctx->width = sh->disp_w; avctx->height= sh->disp_h; avctx->workaround_bugs= lavc_param->workaround_bugs; avctx->error_recognition= lavc_param->error_resilience; if(lavc_param->gray) avctx->flags|= CODEC_FLAG_GRAY; -#ifdef CODEC_FLAG2_FAST avctx->flags2|= lavc_param->fast; -#endif avctx->codec_tag= sh->format; avctx->stream_codec_tag= sh->video.fccHandler; avctx->idct_algo= lavc_param->idct_algo; @@ -306,37 +291,37 @@ static int init(sh_video_t *sh){ /* SVQ3 extradata can show up as sh->ImageDesc if demux_mov is used, or in the phony AVI header if demux_lavf is used. The first case is handled here; the second case falls through to the next section. */ - if (sh->ImageDesc) { - avctx->extradata_size = (*(int*)sh->ImageDesc) - sizeof(int); - avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size); - break; - } - /* fallthrough */ + if (sh->ImageDesc) { + avctx->extradata_size = (*(int*)sh->ImageDesc) - sizeof(int); + avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(avctx->extradata, ((int*)sh->ImageDesc)+1, avctx->extradata_size); + break; + } + /* fallthrough */ case mmioFOURCC('A','V','R','n'): case mmioFOURCC('M','J','P','G'): /* AVRn stores huffman table in AVI header */ /* Pegasus MJPEG stores it also in AVI header, but it uses the common MJPG fourcc :( */ - if (!sh->bih || sh->bih->biSize <= sizeof(BITMAPINFOHEADER)) - break; - avctx->flags |= CODEC_FLAG_EXTERN_HUFF; - avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); - avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); + if (!sh->bih || sh->bih->biSize <= sizeof(BITMAPINFOHEADER)) + break; + avctx->flags |= CODEC_FLAG_EXTERN_HUFF; + avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); + avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); #if 0 - { - int x; - uint8_t *p = avctx->extradata; - - for (x=0; x<avctx->extradata_size; x++) - mp_msg(MSGT_DECVIDEO, MSGL_INFO,"[%x] ", p[x]); - mp_msg(MSGT_DECVIDEO, MSGL_INFO,"\n"); - } + { + int x; + uint8_t *p = avctx->extradata; + + for (x=0; x<avctx->extradata_size; x++) + mp_msg(MSGT_DECVIDEO, MSGL_INFO,"[%x] ", p[x]); + mp_msg(MSGT_DECVIDEO, MSGL_INFO,"\n"); + } #endif - break; + break; case mmioFOURCC('R', 'V', '1', '0'): case mmioFOURCC('R', 'V', '1', '3'): @@ -347,27 +332,27 @@ static int init(sh_video_t *sh){ /* only 1 packet per frame & sub_id from fourcc */ avctx->extradata_size= 8; avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - ((uint32_t*)avctx->extradata)[0] = 0; - ((uint32_t*)avctx->extradata)[1] = - (sh->format == mmioFOURCC('R', 'V', '1', '3')) ? 0x10003001 : 0x10000000; + ((uint32_t*)avctx->extradata)[0] = 0; + ((uint32_t*)avctx->extradata)[1] = + (sh->format == mmioFOURCC('R', 'V', '1', '3')) ? 0x10003001 : 0x10000000; } else { - /* has extra slice header (demux_rm or rm->avi streamcopy) */ - avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); - avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); - } - avctx->sub_id= AV_RB32(avctx->extradata+4); + /* has extra slice header (demux_rm or rm->avi streamcopy) */ + avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); + avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); + } + avctx->sub_id= AV_RB32(avctx->extradata+4); // printf("%X %X %d %d\n", extrahdr[0], extrahdr[1]); break; default: - if (!sh->bih || sh->bih->biSize <= sizeof(BITMAPINFOHEADER)) - break; - avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); - avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); - memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); - break; + if (!sh->bih || sh->bih->biSize <= sizeof(BITMAPINFOHEADER)) + break; + avctx->extradata_size = sh->bih->biSize-sizeof(BITMAPINFOHEADER); + avctx->extradata = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(avctx->extradata, sh->bih+1, avctx->extradata_size); + break; } /* Pass palette to codec */ if (sh->bih && (sh->bih->biBitCount <= 8)) { @@ -381,10 +366,10 @@ static int init(sh_video_t *sh){ /* Palette size in biClrUsed */ memcpy(avctx->palctrl->palette, sh->bih+1, FFMIN(sh->bih->biClrUsed * 4, AVPALETTE_SIZE)); - } + } if(sh->bih) - avctx->bits_per_coded_sample= sh->bih->biBitCount; + avctx->bits_per_coded_sample= sh->bih->biBitCount; if(lavc_param->threads > 1) avcodec_thread_init(avctx, lavc_param->threads); @@ -402,13 +387,13 @@ static int init(sh_video_t *sh){ static void uninit(sh_video_t *sh){ vd_ffmpeg_ctx *ctx = sh->context; AVCodecContext *avctx = ctx->avctx; - + if(sh->opts->lavc_param.vstats){ int i; for(i=1; i<32; i++){ mp_msg(MSGT_DECVIDEO, MSGL_INFO,"QP: %d, count: %d\n", i, ctx->qp_stat[i]); } - mp_msg(MSGT_DECVIDEO, MSGL_INFO,MSGTR_MPCODECS_ArithmeticMeanOfQP, + mp_msg(MSGT_DECVIDEO, MSGL_INFO,MSGTR_MPCODECS_ArithmeticMeanOfQP, ctx->qp_sum / avctx->coded_frame->coded_picture_number, 1.0/(ctx->inv_qp_sum / avctx->coded_frame->coded_picture_number) ); @@ -426,12 +411,12 @@ static void uninit(sh_video_t *sh){ av_freep(&avctx); av_freep(&ctx->pic); if (ctx) - free(ctx); + free(ctx); } static void draw_slice(struct AVCodecContext *s, const AVFrame *src, int offset[4], - int y, int type, int height){ + int y, int type, int height){ sh_video_t * sh = s->opaque; uint8_t *source[3]= {src->data[0] + offset[0], src->data[1] + offset[1], src->data[2] + offset[2]}; #if 0 @@ -442,18 +427,18 @@ static void draw_slice(struct AVCodecContext *s, uint8_t *skip= &s->coded_frame->mbskip_table[(y>>4)*skip_stride]; int threshold= s->coded_frame->age; if(s->pict_type!=B_TYPE){ - for(i=0; i*16<width+16; i++){ + for(i=0; i*16<width+16; i++){ if(i*16>=width || skip[i]>=threshold){ if(start==i) start++; else{ - uint8_t *src2[3]= {src[0] + start*16, - src[1] + start*8, + uint8_t *src2[3]= {src[0] + start*16, + src[1] + start*8, src[2] + start*8}; //printf("%2d-%2d x %d\n", start, i, y); mpcodecs_draw_slice (sh,src2, stride, (i-start)*16, height, start*16, y); start= i+1; } - } + } } }else #endif @@ -476,57 +461,57 @@ static int init_vo(sh_video_t *sh, enum PixelFormat pix_fmt){ // if sh->ImageDesc is non-NULL, it means we decode QuickTime(tm) video. // use dimensions from BIH to avoid black borders at the right and bottom. if (sh->bih && sh->ImageDesc) { - width = sh->bih->biWidth >> ctx->lowres; - height = sh->bih->biHeight >> ctx->lowres; + width = sh->bih->biWidth >> ctx->lowres; + height = sh->bih->biHeight >> ctx->lowres; } - + // it is possible another vo buffers to be used after vo config() // lavc reset its buffers on width/heigh change but not on aspect change!!! if (av_cmp_q(avctx->sample_aspect_ratio, ctx->last_sample_aspect_ratio) || - width != sh->disp_w || - height != sh->disp_h || - pix_fmt != ctx->pix_fmt || - !ctx->vo_initialized) + width != sh->disp_w || + height != sh->disp_h || + pix_fmt != ctx->pix_fmt || + !ctx->vo_initialized) { - mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] aspect_ratio: %f\n", aspect); - if (sh->aspect == 0 || - av_cmp_q(avctx->sample_aspect_ratio, - ctx->last_sample_aspect_ratio)) - sh->aspect = aspect; - ctx->last_sample_aspect_ratio = avctx->sample_aspect_ratio; - sh->disp_w = width; - sh->disp_h = height; - ctx->pix_fmt = pix_fmt; - switch(pix_fmt){ - // YUVJ are YUV formats that use the full Y range and not just - // 16 - 235 (see colorspaces.txt). - // Currently they are all treated the same way. - case PIX_FMT_YUV410P: ctx->best_csp=IMGFMT_YVU9;break; //svq1 - case PIX_FMT_YUVJ420P: - case PIX_FMT_YUV420P: ctx->best_csp=IMGFMT_YV12;break; //mpegs - case PIX_FMT_YUVJ422P: - case PIX_FMT_YUV422P: ctx->best_csp=IMGFMT_422P;break; //mjpeg / huffyuv - case PIX_FMT_YUVJ444P: - case PIX_FMT_YUV444P: ctx->best_csp=IMGFMT_444P;break; //photo jpeg - case PIX_FMT_YUV411P: ctx->best_csp=IMGFMT_411P;break; //dv ntsc - case PIX_FMT_YUYV422: ctx->best_csp=IMGFMT_YUY2;break; //huffyuv perhaps in the future - case PIX_FMT_RGB24 : ctx->best_csp=IMGFMT_RGB24;break; //qtrle - case PIX_FMT_RGB32: ctx->best_csp=IMGFMT_BGR32;break; //huffyuv / mjpeg - case PIX_FMT_BGR24 : ctx->best_csp=IMGFMT_BGR24;break; //8bps - case PIX_FMT_RGB555: ctx->best_csp=IMGFMT_BGR15;break; //rpza,cram - case PIX_FMT_RGB565: ctx->best_csp=IMGFMT_BGR16;break; //4xm - case PIX_FMT_GRAY8: ctx->best_csp=IMGFMT_Y800;break; // gray jpeg - case PIX_FMT_PAL8: ctx->best_csp=IMGFMT_BGR8;break; //8bps,mrle,cram + mp_msg(MSGT_DECVIDEO, MSGL_V, "[ffmpeg] aspect_ratio: %f\n", aspect); + if (sh->aspect == 0 || + av_cmp_q(avctx->sample_aspect_ratio, + ctx->last_sample_aspect_ratio)) + sh->aspect = aspect; + ctx->last_sample_aspect_ratio = avctx->sample_aspect_ratio; + sh->disp_w = width; + sh->disp_h = height; + ctx->pix_fmt = pix_fmt; + switch(pix_fmt){ + // YUVJ are YUV formats that use the full Y range and not just + // 16 - 235 (see colorspaces.txt). + // Currently they are all treated the same way. + case PIX_FMT_YUV410P: ctx->best_csp=IMGFMT_YVU9;break; //svq1 + case PIX_FMT_YUVJ420P: + case PIX_FMT_YUV420P: ctx->best_csp=IMGFMT_YV12;break; //mpegs + case PIX_FMT_YUVJ422P: + case PIX_FMT_YUV422P: ctx->best_csp=IMGFMT_422P;break; //mjpeg / huffyuv + case PIX_FMT_YUVJ444P: + case PIX_FMT_YUV444P: ctx->best_csp=IMGFMT_444P;break; //photo jpeg + case PIX_FMT_YUV411P: ctx->best_csp=IMGFMT_411P;break; //dv ntsc + case PIX_FMT_YUYV422: ctx->best_csp=IMGFMT_YUY2;break; //huffyuv perhaps in the future + case PIX_FMT_RGB24 : ctx->best_csp=IMGFMT_RGB24;break; //qtrle + case PIX_FMT_RGB32: ctx->best_csp=IMGFMT_BGR32;break; //huffyuv / mjpeg + case PIX_FMT_BGR24 : ctx->best_csp=IMGFMT_BGR24;break; //8bps + case PIX_FMT_RGB555: ctx->best_csp=IMGFMT_BGR15;break; //rpza,cram + case PIX_FMT_RGB565: ctx->best_csp=IMGFMT_BGR16;break; //4xm + case PIX_FMT_GRAY8: ctx->best_csp=IMGFMT_Y800;break; // gray jpeg + case PIX_FMT_PAL8: ctx->best_csp=IMGFMT_BGR8;break; //8bps,mrle,cram #if CONFIG_XVMC case PIX_FMT_XVMC_MPEG2_MC:ctx->best_csp=IMGFMT_XVMC_MOCO_MPEG2;break; case PIX_FMT_XVMC_MPEG2_IDCT:ctx->best_csp=IMGFMT_XVMC_IDCT_MPEG2;break; #endif - default: - ctx->best_csp=0; - } - if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h, ctx->best_csp)) - return -1; - ctx->vo_initialized = 1; + default: + ctx->best_csp=0; + } + if (!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h, ctx->best_csp)) + return -1; + ctx->vo_initialized = 1; } return 0; } @@ -596,32 +581,32 @@ static int get_buffer(AVCodecContext *avctx, AVFrame *pic){ } mpi= mpcodecs_get_image(sh,type, flags, - (width+align)&(~align), (height+align)&(~align)); + (width+align)&(~align), (height+align)&(~align)); // ok, let's see what did we get: if( mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && !(mpi->flags&MP_IMGFLAG_DIRECT)){ - // nice, filter/vo likes draw_callback :) - avctx->draw_horiz_band= draw_slice; + // nice, filter/vo likes draw_callback :) + avctx->draw_horiz_band= draw_slice; } else - avctx->draw_horiz_band= NULL; + avctx->draw_horiz_band= NULL; - // Palette support: libavcodec copies palette to *data[1] - if (mpi->bpp == 8) - mpi->planes[1] = av_malloc(AVPALETTE_SIZE); + // Palette support: libavcodec copies palette to *data[1] + if (mpi->bpp == 8) + mpi->planes[1] = av_malloc(AVPALETTE_SIZE); pic->data[0]= mpi->planes[0]; pic->data[1]= mpi->planes[1]; pic->data[2]= mpi->planes[2]; -#if 0 +#if 0 assert(mpi->width >= ((width +align)&(~align))); assert(mpi->height >= ((height+align)&(~align))); assert(mpi->stride[0] >= mpi->width); if(mpi->imgfmt==IMGFMT_I420 || mpi->imgfmt==IMGFMT_YV12 || mpi->imgfmt==IMGFMT_IYUV){ const int y_size= mpi->stride[0] * (mpi->h-1) + mpi->w; const int c_size= mpi->stride[1] * ((mpi->h>>1)-1) + (mpi->w>>1); - + assert(mpi->planes[0] > mpi->planes[1] || mpi->planes[0] + y_size <= mpi->planes[1]); assert(mpi->planes[0] > mpi->planes[2] || mpi->planes[0] + y_size <= mpi->planes[2]); assert(mpi->planes[1] > mpi->planes[0] || mpi->planes[1] + c_size <= mpi->planes[0]); @@ -650,13 +635,13 @@ else #endif if(pic->reference){ pic->age= ctx->ip_age[0]; - + ctx->ip_age[0]= ctx->ip_age[1]+1; ctx->ip_age[1]= 1; ctx->b_age++; }else{ pic->age= ctx->b_age; - + ctx->ip_age[0]++; ctx->ip_age[1]++; ctx->b_age=1; @@ -671,7 +656,7 @@ static void release_buffer(struct AVCodecContext *avctx, AVFrame *pic){ vd_ffmpeg_ctx *ctx = sh->context; int i; -//printf("release buffer %d %d %d\n", mpi ? mpi->flags&MP_IMGFLAG_PRESERVE : -99, ctx->ip_count, ctx->b_count); +//printf("release buffer %d %d %d\n", mpi ? mpi->flags&MP_IMGFLAG_PRESERVE : -99, ctx->ip_count, ctx->b_count); if(ctx->ip_count <= 2 && ctx->b_count<=1){ if(mpi->flags&MP_IMGFLAG_PRESERVE) @@ -680,9 +665,9 @@ static void release_buffer(struct AVCodecContext *avctx, AVFrame *pic){ ctx->b_count--; } - // Palette support: free palette buffer allocated in get_buffer - if ( mpi && (mpi->bpp == 8)) - av_freep(&mpi->planes[1]); + // Palette support: free palette buffer allocated in get_buffer + if ( mpi && (mpi->bpp == 8)) + av_freep(&mpi->planes[1]); if(pic->type!=FF_BUFFER_TYPE_USER){ avcodec_default_release_buffer(avctx, pic); @@ -698,10 +683,10 @@ static void release_buffer(struct AVCodecContext *avctx, AVFrame *pic){ // copypaste from demux_real.c - it should match to get it working! //FIXME put into some header typedef struct dp_hdr_s { - uint32_t chunks; // number of chunks + uint32_t chunks; // number of chunks uint32_t timestamp; // timestamp from packet header - uint32_t len; // length of actual data - uint32_t chunktab; // offset to chunk offset array + uint32_t len; // length of actual data + uint32_t chunktab; // offset to chunk offset array } dp_hdr_t; static void swap_palette(void *pal) { @@ -729,13 +714,13 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ avctx->draw_horiz_band=NULL; avctx->opaque=sh; if(ctx->vo_initialized && !(flags&3) && !dr1){ - mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE | - (ctx->do_slices?MP_IMGFLAG_DRAW_CALLBACK:0), - sh->disp_w, sh->disp_h); - if(mpi && mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){ - // vd core likes slices! - avctx->draw_horiz_band=draw_slice; - } + mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE | + (ctx->do_slices?MP_IMGFLAG_DRAW_CALLBACK:0), + sh->disp_w, sh->disp_h); + if(mpi && mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){ + // vd core likes slices! + avctx->draw_horiz_band=draw_slice; + } } avctx->hurry_up=(flags&3)?((flags&2)?2:1):0; @@ -743,7 +728,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ mp_msg(MSGT_DECVIDEO, MSGL_DBG2, "vd_ffmpeg data: %04x, %04x, %04x, %04x\n", ((int *)data)[0], ((int *)data)[1], ((int *)data)[2], ((int *)data)[3]); ret = avcodec_decode_video(avctx, pic, - &got_picture, data, len); + &got_picture, data, len); dr1= ctx->do_dr1; if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); @@ -756,7 +741,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ static int frame_number=0; static double all_frametime=0.0; AVFrame *pic= avctx->coded_frame; - double quality=0.0; + double quality=0.0; if(!fvstats) { time_t today2; @@ -774,19 +759,19 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ } } - // average MB quantizer - { - int x, y; - int w = ((avctx->width << ctx->lowres)+15) >> 4; - int h = ((avctx->height << ctx->lowres)+15) >> 4; - int8_t *q = pic->qscale_table; - for( y = 0; y < h; y++ ) { - for( x = 0; x < w; x++ ) - quality += (double)*(q+x); - q += pic->qstride; - } - quality /= w * h; - } + // average MB quantizer + { + int x, y; + int w = ((avctx->width << ctx->lowres)+15) >> 4; + int h = ((avctx->height << ctx->lowres)+15) >> 4; + int8_t *q = pic->qscale_table; + for( y = 0; y < h; y++ ) { + for( x = 0; x < w; x++ ) + quality += (double)*(q+x); + q += pic->qstride; + } + quality /= w * h; + } all_len+=len; all_frametime+=sh->frametime; @@ -795,48 +780,48 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ fprintf(fvstats, "time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", all_frametime, (double)(len*8)/sh->frametime/1000.0, (double)(all_len*8)/all_frametime/1000.0); - switch(pic->pict_type){ - case FF_I_TYPE: + switch(pic->pict_type){ + case FF_I_TYPE: fprintf(fvstats, "type= I\n"); - break; - case FF_P_TYPE: + break; + case FF_P_TYPE: fprintf(fvstats, "type= P\n"); - break; - case FF_S_TYPE: + break; + case FF_S_TYPE: fprintf(fvstats, "type= S\n"); - break; - case FF_B_TYPE: + break; + case FF_B_TYPE: fprintf(fvstats, "type= B\n"); - break; - default: + break; + default: fprintf(fvstats, "type= ? (%d)\n", pic->pict_type); - break; - } - + break; + } + ctx->qp_stat[(int)(quality+0.5)]++; ctx->qp_sum += quality; ctx->inv_qp_sum += 1.0/(double)quality; - + break; } //-- - if(!got_picture) return NULL; // skipped image + if(!got_picture) return NULL; // skipped image if(init_vo(sh,avctx->pix_fmt) < 0) return NULL; if(dr1 && pic->opaque){ mpi= (mp_image_t*)pic->opaque; } - + if(!mpi) mpi=mpcodecs_get_image(sh, MP_IMGTYPE_EXPORT, MP_IMGFLAG_PRESERVE, - avctx->width, avctx->height); - if(!mpi){ // temporary! - mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_CouldntAllocateImageForCodec); - return NULL; + avctx->width, avctx->height); + if(!mpi){ // temporary! + mp_msg(MSGT_DECVIDEO, MSGL_WARN, MSGTR_MPCODECS_CouldntAllocateImageForCodec); + return NULL; } - + if(!dr1){ mpi->planes[0]=pic->data[0]; mpi->planes[1]=pic->data[1]; @@ -845,16 +830,16 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ mpi->stride[1]=pic->linesize[1]; mpi->stride[2]=pic->linesize[2]; } - + if (!mpi->planes[0]) - return NULL; + return NULL; if(avctx->pix_fmt==PIX_FMT_YUV422P && mpi->chroma_y_shift==1){ - // we have 422p but user wants 420p - mpi->stride[1]*=2; - mpi->stride[2]*=2; + // we have 422p but user wants 420p + mpi->stride[1]*=2; + mpi->stride[2]*=2; } - + #ifdef WORDS_BIGENDIAN // FIXME: this might cause problems for buffers with FF_BUFFER_HINTS_PRESERVE if (mpi->bpp == 8) @@ -867,14 +852,14 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ mpi->qscale_type= pic->qscale_type; mpi->fields = MP_IMGFIELD_ORDERED; if(pic->interlaced_frame) mpi->fields |= MP_IMGFIELD_INTERLACED; - if(pic->top_field_first ) mpi->fields |= MP_IMGFIELD_TOP_FIRST; + if(pic->top_field_first ) mpi->fields |= MP_IMGFIELD_TOP_FIRST; if(pic->repeat_pict == 1) mpi->fields |= MP_IMGFIELD_REPEAT_FIRST; return mpi; } #if CONFIG_XVMC -static enum PixelFormat get_format(struct AVCodecContext * avctx, +static enum PixelFormat get_format(struct AVCodecContext * avctx, const enum PixelFormat * fmt){ sh_video_t * sh = avctx->opaque; int i; @@ -893,7 +878,7 @@ int i; for(i=0;fmt[i]!=-1;i++){ mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_TryingPixfmt,i); if( init_vo(sh,fmt[i]) >= 0) - return fmt[i]; + return fmt[i]; } return fmt[0]; } @@ -903,9 +888,9 @@ static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic){ vd_ffmpeg_ctx *ctx = sh->context; mp_image_t* mpi=NULL; struct xvmc_render_state * render; - int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE| + int flags= MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE| MP_IMGFLAG_DRAW_CALLBACK; - + // printf("vd_ffmpeg::mc_get_buffer (xvmc) %d %d %d\n", pic->reference, ctx->ip_count, ctx->b_count); if(!avctx->xvmc_acceleration){ mp_msg(MSGT_DECVIDEO, MSGL_INFO, MSGTR_MPCODECS_McGetBufferShouldWorkOnlyWithXVMC); @@ -941,14 +926,14 @@ static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic){ exit(1); // return -1;//!!fixme check error conditions in ffmpeg }; - + if( (mpi->flags & MP_IMGFLAG_DIRECT) == 0){ mp_msg(MSGT_DECVIDEO, MSGL_ERR, MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed); assert(0); exit(1); // return -1;//!!fixme check error conditions in ffmpeg } - + pic->data[0]= mpi->planes[0]; pic->data[1]= mpi->planes[1]; pic->data[2]= mpi->planes[2]; @@ -966,14 +951,14 @@ static int mc_get_buffer(AVCodecContext *avctx, AVFrame *pic){ if(pic->reference){ //I or P frame pic->age= ctx->ip_age[0]; - + ctx->ip_age[0]= ctx->ip_age[1]+1; ctx->ip_age[1]= 1; ctx->b_age++; }else{ //B frame pic->age= ctx->b_age; - + ctx->ip_age[0]++; ctx->ip_age[1]++; ctx->b_age=1; @@ -1021,14 +1006,14 @@ static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic){ static void mc_render_slice(struct AVCodecContext *s, const AVFrame *src, int offset[4], - int y, int type, int height){ + int y, int type, int height){ int width= s->width; sh_video_t * sh = s->opaque; uint8_t *source[3]= {src->data[0], src->data[1], src->data[2]}; - + assert(src->linesize[0]==0 && src->linesize[1]==0 && src->linesize[2]==0); assert(offset[0]==0 && offset[1]==0 && offset[2]==0); - + mpcodecs_draw_slice (sh, source, src->linesize, width, height, 0, y); } |