diff options
Diffstat (limited to 'libmpcodecs/vd_ffmpeg.c')
-rw-r--r-- | libmpcodecs/vd_ffmpeg.c | 149 |
1 files changed, 67 insertions, 82 deletions
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c index 1a25a84959..d4a43a5724 100644 --- a/libmpcodecs/vd_ffmpeg.c +++ b/libmpcodecs/vd_ffmpeg.c @@ -6,6 +6,7 @@ #include "config.h" #include "mp_msg.h" #include "help_mp.h" +#include "options.h" #include "av_opts.h" #include "libavutil/common.h" @@ -14,7 +15,7 @@ #include "vd_internal.h" -static vd_info_t info = { +static const vd_info_t info = { "FFmpeg's libavcodec codec family", "ffmpeg", "A'rpi", @@ -48,6 +49,7 @@ typedef struct { int ip_count; int b_count; AVRational last_sample_aspect_ratio; + int lowres; } vd_ffmpeg_ctx; //#ifdef CONFIG_LIBPOSTPROC @@ -65,52 +67,32 @@ static enum PixelFormat get_format(struct AVCodecContext * avctx, 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, - AVFrame *src, int offset[4], + const AVFrame *src, int offset[4], int y, int type, int height); #endif -static int lavc_param_workaround_bugs= FF_BUG_AUTODETECT; -static int lavc_param_error_resilience=2; -static int lavc_param_error_concealment=3; -static int lavc_param_gray=0; -static int lavc_param_vstats=0; -static int lavc_param_idct_algo=0; -static int lavc_param_debug=0; -static int lavc_param_vismv=0; -static int lavc_param_skip_top=0; -static int lavc_param_skip_bottom=0; -static int lavc_param_fast=0; -static int lavc_param_lowres=0; -static char *lavc_param_lowres_str=NULL; -static char *lavc_param_skip_loop_filter_str = NULL; -static char *lavc_param_skip_idct_str = NULL; -static char *lavc_param_skip_frame_str = NULL; -static int lavc_param_threads=1; -static int lavc_param_bitexact=0; -static char *lavc_avopt = NULL; - const m_option_t lavc_decode_opts_conf[]={ - {"bug", &lavc_param_workaround_bugs, CONF_TYPE_INT, CONF_RANGE, -1, 999999, NULL}, - {"er", &lavc_param_error_resilience, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, - {"gray", &lavc_param_gray, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_PART, NULL}, - {"idct", &lavc_param_idct_algo, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, - {"ec", &lavc_param_error_concealment, CONF_TYPE_INT, CONF_RANGE, 0, 99, NULL}, - {"vstats", &lavc_param_vstats, CONF_TYPE_FLAG, 0, 0, 1, NULL}, - {"debug", &lavc_param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 9999999, NULL}, - {"vismv", &lavc_param_vismv, CONF_TYPE_INT, CONF_RANGE, 0, 9999999, NULL}, - {"st", &lavc_param_skip_top, CONF_TYPE_INT, CONF_RANGE, 0, 999, NULL}, - {"sb", &lavc_param_skip_bottom, CONF_TYPE_INT, CONF_RANGE, 0, 999, NULL}, + OPT_INTRANGE("bug", lavc_param.workaround_bugs, 0, -1, 999999), + OPT_INTRANGE("er", lavc_param.error_resilience, 0, 0, 99), + OPT_FLAG_ON("gray", lavc_param.gray, 0), + OPT_INTRANGE("idct", lavc_param.idct_algo, 0, 0, 99), + OPT_INTRANGE("ec", lavc_param.error_concealment, 0, 0, 99), + OPT_FLAG_ON("vstats", lavc_param.vstats, 0), + OPT_INTRANGE("debug", lavc_param.debug, 0, 0, 9999999), + 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 - {"fast", &lavc_param_fast, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG2_FAST, NULL}, + OPT_FLAG_CONSTANTS("fast", lavc_param.fast, 0, 0, CODEC_FLAG2_FAST), #endif - {"lowres", &lavc_param_lowres_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"skiploopfilter", &lavc_param_skip_loop_filter_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"skipidct", &lavc_param_skip_idct_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"skipframe", &lavc_param_skip_frame_str, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"threads", &lavc_param_threads, CONF_TYPE_INT, CONF_RANGE, 1, 8, NULL}, - {"bitexact", &lavc_param_bitexact, CONF_TYPE_FLAG, 0, 0, CODEC_FLAG_BITEXACT, NULL}, - {"o", &lavc_avopt, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {NULL, NULL, 0, 0, 0, 0, NULL} + 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), + OPT_STRING("skipframe", lavc_param.skip_frame_str, 0), + OPT_INTRANGE("threads", lavc_param.threads, 0, 1, 8), + OPT_FLAG_CONSTANTS("bitexact", lavc_param.bitexact, 0, 0, CODEC_FLAG_BITEXACT), + OPT_STRING("o", lavc_param.avopt, 0), + {NULL, NULL, 0, 0, 0, 0, NULL} }; static enum AVDiscard str2AVDiscard(char *str) { @@ -161,7 +143,7 @@ static int control(sh_video_t *sh,int cmd,void* arg,...){ return CONTROL_UNKNOWN; } -void mp_msp_av_log_callback(void* ptr, int level, const char* fmt, va_list vl) +static void mp_msp_av_log_callback(void* ptr, int level, const char* fmt, va_list vl) { static int print_prefix=1; AVClass* avc= ptr ? *(AVClass**)ptr : NULL; @@ -213,11 +195,12 @@ void mp_msp_av_log_callback(void* ptr, int level, const char* fmt, va_list vl) // init driver static int init(sh_video_t *sh){ + struct lavc_param *lavc_param = &sh->opts->lavc_param; AVCodecContext *avctx; vd_ffmpeg_ctx *ctx; AVCodec *lavc_codec; int lowres_w=0; - int do_vis_debug= lavc_param_vismv || (lavc_param_debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP)); + int do_vis_debug= lavc_param->vismv || (lavc_param->debug&(FF_DEBUG_VIS_MB_TYPE|FF_DEBUG_VIS_QP)); if(!avcodec_initialized){ avcodec_init(); @@ -238,7 +221,7 @@ static int init(sh_video_t *sh){ return 0; } - if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug) + if(sh->opts->vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug) 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) @@ -278,40 +261,40 @@ static int init(sh_video_t *sh){ #ifdef CODEC_FLAG_NOT_TRUNCATED avctx->flags|= CODEC_FLAG_NOT_TRUNCATED; #endif - avctx->flags|= lavc_param_bitexact; + 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; + 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; + 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; - avctx->error_concealment= lavc_param_error_concealment; - avctx->debug= lavc_param_debug; - if (lavc_param_debug) + avctx->idct_algo= lavc_param->idct_algo; + avctx->error_concealment= lavc_param->error_concealment; + avctx->debug= lavc_param->debug; + if (lavc_param->debug) av_log_set_level(AV_LOG_DEBUG); - avctx->debug_mv= lavc_param_vismv; - avctx->skip_top = lavc_param_skip_top; - avctx->skip_bottom= lavc_param_skip_bottom; - if(lavc_param_lowres_str != NULL) + avctx->debug_mv= lavc_param->vismv; + avctx->skip_top = lavc_param->skip_top; + avctx->skip_bottom= lavc_param->skip_bottom; + if(lavc_param->lowres_str != NULL) { - sscanf(lavc_param_lowres_str, "%d,%d", &lavc_param_lowres, &lowres_w); - if(lavc_param_lowres < 1 || lavc_param_lowres > 16 || (lowres_w > 0 && avctx->width < lowres_w)) - lavc_param_lowres = 0; - avctx->lowres = lavc_param_lowres; + sscanf(lavc_param->lowres_str, "%d,%d", &ctx->lowres, &lowres_w); + if(ctx->lowres < 1 || ctx->lowres > 16 || (lowres_w > 0 && avctx->width < lowres_w)) + ctx->lowres = 0; + avctx->lowres = ctx->lowres; } - avctx->skip_loop_filter = str2AVDiscard(lavc_param_skip_loop_filter_str); - avctx->skip_idct = str2AVDiscard(lavc_param_skip_idct_str); - avctx->skip_frame = str2AVDiscard(lavc_param_skip_frame_str); + avctx->skip_loop_filter = str2AVDiscard(lavc_param->skip_loop_filter_str); + avctx->skip_idct = str2AVDiscard(lavc_param->skip_idct_str); + avctx->skip_frame = str2AVDiscard(lavc_param->skip_frame_str); - if(lavc_avopt){ - if(parse_avopts(avctx, lavc_avopt) < 0){ - mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Your options /%s/ look like gibberish to me pal\n", lavc_avopt); + if(lavc_param->avopt){ + if(parse_avopts(avctx, lavc_param->avopt) < 0){ + mp_msg(MSGT_DECVIDEO,MSGL_ERR, "Your options /%s/ look like gibberish to me pal\n", lavc_param->avopt); uninit(sh); return 0; } @@ -403,8 +386,8 @@ static int init(sh_video_t *sh){ if(sh->bih) avctx->bits_per_coded_sample= sh->bih->biBitCount; - if(lavc_param_threads > 1) - avcodec_thread_init(avctx, lavc_param_threads); + if(lavc_param->threads > 1) + avcodec_thread_init(avctx, lavc_param->threads); /* open it */ if (avcodec_open(avctx, lavc_codec) < 0) { mp_msg(MSGT_DECVIDEO,MSGL_ERR, MSGTR_CantOpenCodec); @@ -420,7 +403,7 @@ static void uninit(sh_video_t *sh){ vd_ffmpeg_ctx *ctx = sh->context; AVCodecContext *avctx = ctx->avctx; - if(lavc_param_vstats){ + 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]); @@ -447,14 +430,15 @@ static void uninit(sh_video_t *sh){ } static void draw_slice(struct AVCodecContext *s, - AVFrame *src, int offset[4], + const AVFrame *src, int offset[4], 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 int start=0, i; int width= s->width; - int skip_stride= ((width<<lavc_param_lowres)+15)>>4; + vd_ffmpeg_ctx *ctx = sh->context; + int skip_stride= ((width << ctx->lowres)+15)>>4; uint8_t *skip= &s->coded_frame->mbskip_table[(y>>4)*skip_stride]; int threshold= s->coded_frame->age; if(s->pict_type!=B_TYPE){ @@ -492,8 +476,8 @@ 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>>lavc_param_lowres; - height = sh->bih->biHeight>>lavc_param_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() @@ -720,7 +704,7 @@ typedef struct dp_hdr_s { uint32_t chunktab; // offset to chunk offset array } dp_hdr_t; -void swap_palette(void *pal) { +static void swap_palette(void *pal) { int i; uint32_t *p = pal; for (i = 0; i < AVPALETTE_COUNT; i++) @@ -734,6 +718,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ vd_ffmpeg_ctx *ctx = sh->context; AVFrame *pic= ctx->pic; AVCodecContext *avctx = ctx->avctx; + struct lavc_param *lavc_param = &sh->opts->lavc_param; mp_image_t* mpi=NULL; int dr1= ctx->do_dr1; @@ -764,7 +749,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ || sh->format == mmioFOURCC('R', 'V', '4', '0')) { dp_hdr_t *hdr= (dp_hdr_t*)data; - uint32_t *offsets = (uint32_t*)(data + hdr->chunktab); + uint32_t *offsets = (uint32_t*)((char *)data + hdr->chunktab); uint8_t *offstab = av_malloc((hdr->chunks+1) * 8); uint8_t *buf = data; int chunks = hdr->chunks; @@ -772,7 +757,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ buf[0] = chunks; memcpy(offstab, offsets, (chunks + 1) * 8); - memmove(buf + 1 + (chunks + 1) * 8, data + sizeof(dp_hdr_t), dlen); + memmove(buf + 1 + (chunks + 1) * 8, (char *)data + sizeof(dp_hdr_t), dlen); memcpy(buf + 1, offstab, (chunks + 1) * 8); av_free(offstab); } @@ -786,7 +771,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ if(ret<0) mp_msg(MSGT_DECVIDEO,MSGL_WARN, "Error while decoding frame!\n"); //printf("repeat: %d\n", pic->repeat_pict); //-- vstats generation - while(lavc_param_vstats){ // always one time loop + while(lavc_param->vstats){ // always one time loop static FILE *fvstats=NULL; char filename[20]; static long long int all_len=0; @@ -805,7 +790,7 @@ static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ fvstats = fopen(filename,"w"); if(!fvstats) { perror("fopen"); - lavc_param_vstats=0; // disable block + lavc_param->vstats=0; // disable block break; /*exit(1);*/ } @@ -814,8 +799,8 @@ 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 << lavc_param_lowres)+15) >> 4; - int h = ((avctx->height << lavc_param_lowres)+15) >> 4; + 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++ ) @@ -1057,7 +1042,7 @@ static void mc_release_buffer(AVCodecContext *avctx, AVFrame *pic){ } static void mc_render_slice(struct AVCodecContext *s, - AVFrame *src, int offset[4], + const AVFrame *src, int offset[4], int y, int type, int height){ int width= s->width; sh_video_t * sh = s->opaque; |