From patchwork Fri Jan 20 09:41:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Huang, Zhengxu" X-Patchwork-Id: 2264 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.89.21 with SMTP id n21csp673919vsb; Fri, 20 Jan 2017 01:48:07 -0800 (PST) X-Received: by 10.28.152.79 with SMTP id a76mr2511035wme.16.1484905687756; Fri, 20 Jan 2017 01:48:07 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v36si7277743wrb.289.2017.01.20.01.48.07; Fri, 20 Jan 2017 01:48:07 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 39B8F68A655; Fri, 20 Jan 2017 11:47:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 90FA168A61D for ; Fri, 20 Jan 2017 11:47:47 +0200 (EET) Received: by mail-pf0-f195.google.com with SMTP id f144so5176126pfa.2 for ; Fri, 20 Jan 2017 01:47:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version; bh=9RJ+0hY2boO2wIc2SZhKWrHZpslP3cdNXR+YNpOJObA=; b=jX2aFyWD97gFHVX+VUGPW4sTNiZHyZOcN3jG32CUFdOBsfHu5CmSnnX4a7YuXxA/yz PVzuZ8cSiPS1duN4m64mFFJZBjFOrildsDBx4E9pLfOPFBfbQOdSDazQz+f24rxr47X/ MEuyB5cOIXny3gCwuSVICuYm9IxSfzYviyFqIuAwPJX51/9gNyWRZEczWPG7GY3PNPKK Yh00T/nMgPrETvFaKBcefXey3UTcvWIdmYpHcF3YRUBPIFDwNPe5m0l5GuMYeNGENW3z +e9AC6P1jD1a0HnijuXGy3T/yisan9542lE+uBCvMukKXyiv2o2O8dFbgHWgrDT4DFKt YSTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:subject:message-id:date:user-agent :mime-version; bh=9RJ+0hY2boO2wIc2SZhKWrHZpslP3cdNXR+YNpOJObA=; b=YE2ZNUl2KMjqPXvn6CzxjFNRbSq+joe/2QtFsibRDJq5OfXVnXHzRa4Au1MYideZWR TkUYnfjfL9e81aFFo9Os/M7PZN+zGfNXNFkydWySqTbUqCl0MDvR2mVOcjTpv83zhPIs ZTatbFqvzl75L5rzqKVROIa/3npKPkntBvB+r5mPrE+NMRzWkPQsQgpWb3ADfRzaJvah jUD960nbUscQv/gKZ4HhLG+FRQo2dDDpr1OP9HAzQJBAFqLeWmS10AjBt7E+PZ8ZfRL4 x3bBc0eBp7ZM0IJCNLJwwX9jyT3PZz5eopL3YIdNsrGeg3/h4T/ma35HzV/SpL3nD1H2 mXwA== X-Gm-Message-State: AIkVDXIucFWXbJano72OSLPRYGuBHWLiCvbOC9m3JcVfh0gp/TOyZvs7rozLSd2Go0qg8g== X-Received: by 10.99.149.66 with SMTP id t2mr15773080pgn.156.1484905266682; Fri, 20 Jan 2017 01:41:06 -0800 (PST) Received: from [10.239.204.246] ([192.55.54.40]) by smtp.gmail.com with ESMTPSA id t129sm15163645pgc.32.2017.01.20.01.41.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jan 2017 01:41:05 -0800 (PST) To: sw@jkqxz.net, FFmpeg development discussions and patches , chaox.a.liu@gmail.com, huazh407@gmail.com, zhengxu.maxwell@gmail.com From: "Huang, Zhengxu" Message-ID: Date: Fri, 20 Jan 2017 17:41:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] ffmpeg_qsv.c: Init an hwframes_context for decoder instead of encoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From 2149f87637ab941be14828f7ae2c224908784c7d Mon Sep 17 00:00:00 2001 From: Zhengxu Date: Wed, 4 Jan 2017 16:43:43 +0800 Subject: [PATCH] ffmpeg_qsv.c: Init an hwframes_context for decoder instead of encoder. We consider that encoder is the last stage in the pipeline. Thinking about filters, they get hwframes_context from their inputs. Likewise, encoder should get hwframes_context from its input instead creating a new faker one. Encoder can get acuurate parameters by doing so. Signed-off-by: ChaoX A Liu Signed-off-by: Huang, Zhengxu Signed-off-by: Andrew, Zhang --- ffmpeg_qsv.c | 95 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 43 insertions(+), 52 deletions(-) diff --git a/ffmpeg_qsv.c b/ffmpeg_qsv.c index 86824b6..8cedb7e 100644 --- a/ffmpeg_qsv.c +++ b/ffmpeg_qsv.c @@ -81,25 +81,26 @@ int qsv_init(AVCodecContext *s) return ret; } - av_buffer_unref(&ist->hw_frames_ctx); - ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx); - if (!ist->hw_frames_ctx) - return AVERROR(ENOMEM); - - frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data; - frames_hwctx = frames_ctx->hwctx; - - frames_ctx->width = FFALIGN(s->coded_width, 32); - frames_ctx->height = FFALIGN(s->coded_height, 32); - frames_ctx->format = AV_PIX_FMT_QSV; - frames_ctx->sw_format = s->sw_pix_fmt; - frames_ctx->initial_pool_size = 64; - frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; - - ret = av_hwframe_ctx_init(ist->hw_frames_ctx); - if (ret < 0) { - av_log(NULL, AV_LOG_ERROR, "Error initializing a QSV frame pool\n"); - return ret; + if(!ist->hw_frames_ctx) { + ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx); + if (!ist->hw_frames_ctx) + return AVERROR(ENOMEM); + + frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data; + frames_hwctx = frames_ctx->hwctx; + + frames_ctx->width = FFALIGN(s->coded_width, 32); + frames_ctx->height = FFALIGN(s->coded_height, 32); + frames_ctx->format = AV_PIX_FMT_QSV; + frames_ctx->sw_format = s->sw_pix_fmt; + frames_ctx->initial_pool_size = 64; + frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; + + ret = av_hwframe_ctx_init(ist->hw_frames_ctx); + if (ret < 0) { + av_log(NULL, AV_LOG_ERROR, "Error initializing a QSV frame pool\n"); + return ret; + } } ist->hwaccel_get_buffer = qsv_get_buffer; @@ -114,9 +115,8 @@ int qsv_transcode_init(OutputStream *ost) const enum AVPixelFormat *pix_fmt; int err, i; - AVBufferRef *encode_frames_ref = NULL; - AVHWFramesContext *encode_frames; - AVQSVFramesContext *qsv_frames; + AVHWFramesContext *frames_ctx; + AVQSVFramesContext *frames_hwctx; /* check if the encoder supports QSV */ if (!ost->enc->pix_fmts) @@ -150,42 +150,33 @@ int qsv_transcode_init(OutputStream *ost) if (!hw_device_ctx) { err = qsv_device_init(ist); if (err < 0) - goto fail; - } - - // This creates a dummy hw_frames_ctx for the encoder to be - // suitably initialised. It only contains one real frame, so - // hopefully doesn't waste too much memory. - - encode_frames_ref = av_hwframe_ctx_alloc(hw_device_ctx); - if (!encode_frames_ref) { - err = AVERROR(ENOMEM); - goto fail; + return err; } - encode_frames = (AVHWFramesContext*)encode_frames_ref->data; - qsv_frames = encode_frames->hwctx; - encode_frames->width = FFALIGN(ist->resample_width, 32); - encode_frames->height = FFALIGN(ist->resample_height, 32); - encode_frames->format = AV_PIX_FMT_QSV; - encode_frames->sw_format = AV_PIX_FMT_NV12; - encode_frames->initial_pool_size = 1; + ist->dec_ctx->pix_fmt = AV_PIX_FMT_QSV; + ist->resample_pix_fmt = AV_PIX_FMT_QSV; + ist->hw_frames_ctx = av_hwframe_ctx_alloc(hw_device_ctx); + if (!ist->hw_frames_ctx) + return AVERROR(ENOMEM); - qsv_frames->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; + frames_ctx = (AVHWFramesContext*)ist->hw_frames_ctx->data; + frames_hwctx = frames_ctx->hwctx; - err = av_hwframe_ctx_init(encode_frames_ref); - if (err < 0) - goto fail; + frames_ctx->width = FFALIGN(ist->resample_width, 32); + frames_ctx->height = FFALIGN(ist->resample_height, 32); + frames_ctx->format = AV_PIX_FMT_QSV; + frames_ctx->sw_format = AV_PIX_FMT_NV12; + frames_ctx->initial_pool_size = 64; + frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; - ist->dec_ctx->pix_fmt = AV_PIX_FMT_QSV; - ist->resample_pix_fmt = AV_PIX_FMT_QSV; + err = av_hwframe_ctx_init(ist->hw_frames_ctx); + if (err < 0) { + av_buffer_unref(&ist->hw_frames_ctx); + av_log(NULL, AV_LOG_ERROR, "Error initializing a QSV frame pool\n"); + return err; + } - ost->enc_ctx->pix_fmt = AV_PIX_FMT_QSV; - ost->enc_ctx->hw_frames_ctx = encode_frames_ref; + ost->enc_ctx->pix_fmt = AV_PIX_FMT_QSV; return 0; - -fail: - av_buffer_unref(&encode_frames_ref); - return err; }