From a9b1e72ef2f6da931bdbd2e8e50424183869698c Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 28 May 2015 21:55:16 +0200 Subject: vd_lavc: allocate hw surfaces using the coded size ...instead of relying on the hw decoding API to align it for us. The old method could in theory have gone wrong if the video is cropped by an amount large enough to step over several blocks. --- video/decode/vd_lavc.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'video/decode') diff --git a/video/decode/vd_lavc.c b/video/decode/vd_lavc.c index c0209cab21..7c95f00e2c 100644 --- a/video/decode/vd_lavc.c +++ b/video/decode/vd_lavc.c @@ -514,12 +514,12 @@ static enum AVPixelFormat get_format_hwdec(struct AVCodecContext *avctx, // There could be more reasons for a change, and it's possible // that we miss some. (Might also depend on the hwaccel type.) bool change = - ctx->hwdec_w != avctx->width || - ctx->hwdec_h != avctx->height || + ctx->hwdec_w != avctx->coded_width || + ctx->hwdec_h != avctx->coded_height || ctx->hwdec_fmt != ctx->hwdec->image_format || ctx->hwdec_profile != avctx->profile; - ctx->hwdec_w = avctx->width; - ctx->hwdec_h = avctx->height; + ctx->hwdec_w = avctx->coded_width; + ctx->hwdec_h = avctx->coded_height; ctx->hwdec_fmt = ctx->hwdec->image_format; ctx->hwdec_profile = avctx->profile; if (ctx->hwdec->init_decoder && change) { @@ -568,12 +568,11 @@ static int get_buffer2_hwdec(AVCodecContext *avctx, AVFrame *pic, int flags) if (!IMGFMT_IS_HWACCEL(imgfmt) || !ctx->hwdec) return -1; - // Using frame->width/height is bad. For non-mod 16 video (which would - // require alignment of frame sizes) we want the decoded size, not the - // aligned size. At least vdpau needs this: the video mixer is created - // with decoded size, and the video surfaces must have matching size. - int w = ctx->avctx->width; - int h = ctx->avctx->height; + // We expect it to use the exact size used to create the hw decoder in + // get_format_hwdec(). For cropped video, this is expected to be the + // uncropped size (usually coded_width/coded_height). + int w = pic->width; + int h = pic->height; if (ctx->hwdec->init_decoder) { if (imgfmt != ctx->hwdec_fmt && w != ctx->hwdec_w && h != ctx->hwdec_h) -- cgit v1.2.3