From 269c1e1f41f6daf4ff17ffd47f5dfe78884b8ec7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 16 Mar 2014 14:54:21 +0100 Subject: vd_lavc: reduce hardware decoder mid-stream reinitializations Instead of doing it on every seek (libavcodec calls get_format on every seek), reinitialize the decoder only if the video resolution changes. Note that this may be relatively naive, since we e.g. (or: in particular) don't check for profile changes. But it's not worse than the state before the get_format change, and at least it paints over the current vaapi breakage (issue #646). --- video/decode/vd_lavc.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'video/decode') diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index b49f3c6c44..4914d04f20 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -465,10 +465,15 @@ static enum AVPixelFormat get_format_hwdec(struct AVCodecContext *avctx, if (ctx->hwdec->image_format) { for (int i = 0; fmt[i] != AV_PIX_FMT_NONE; i++) { if (ctx->hwdec->image_format == pixfmt2imgfmt(fmt[i])) { + // There could be more reasons for a change, e.g. profile change. + bool change = + ctx->hwdec_w != avctx->width || + ctx->hwdec_h != avctx->height || + ctx->hwdec_fmt != ctx->hwdec->image_format; ctx->hwdec_w = avctx->width; ctx->hwdec_h = avctx->height; ctx->hwdec_fmt = ctx->hwdec->image_format; - if (ctx->hwdec->init_decoder) { + if (ctx->hwdec->init_decoder && change) { if (ctx->hwdec->init_decoder(ctx, ctx->hwdec_fmt, ctx->hwdec_w, ctx->hwdec_h) < 0) { -- cgit v1.2.3