From patchwork Wed Jun 23 03:03:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xiang, Haihao" X-Patchwork-Id: 28864 Delivered-To: andriy.gelman@gmail.com Received: by 2002:a25:bbc9:0:0:0:0:0 with SMTP id c9csp5480006ybk; Tue, 22 Jun 2021 20:04:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVwM7j0gKG4x16ktBmN6/UygtL3llQUv6T2hCR4fY9muiS5kXc3ikZaPU9gJqfgLTCBcCZ X-Received: by 2002:a17:906:28c2:: with SMTP id p2mr7492258ejd.41.1624417495460; Tue, 22 Jun 2021 20:04:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624417495; cv=none; d=google.com; s=arc-20160816; b=ogmqWr+QrzV9HwC31tEijv251ykmIqteHTNobNNfEDB+jiW0wQlfOLsk4iVQ51r0kg +AZ0MDmTG0PD/K5sAGa9/QuF0Fta6uRCaYV5BZM/VmM2AFGKgWIMZRIX/nQH5ocScnPE gQT4IRYaeUwxlGuPbeq+LdHf9Ad3mSQypSMnkPjirLowkRpTmAn9x1qKtpIK7C5t/Xw6 GnDkhh4By0Yl2qkhMKju3sBTSnsaWNacCpE3l1rbY3yk2Dr8cPuyVXoTW0o+z1PJZ/L4 /7j/ZTkkNbYYMzfte/EB8HFTByPxO73pgHXnZlxI8iYd9s+Qx54wUYYxJGjnFY/04xhD eCzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:ironport-sdr:ironport-sdr:delivered-to; bh=wPCxLanyOsXHi449lpz/SzdVFft6Bzyr7xpmS3NCmVw=; b=nepseaPt+De6ZmSlI7CrbKMSdMa8emT2P3/esruml54OtVduyJEkLrU32M+VoJI7G0 sHTbIKdho4xonKjipSv0oliqI1fnZSuq7ga6cvzqahlobCGiqZRHK8+pNcHbiq5HsN7v FR9ryAL1EwIEKoZnFnsbWfuH4gf2y9psn9tc03Rrml/c0MCWZ5DPDBRYGY7zmrJeeizd nG5D6c4x5TEPefHwLz1yiOPkXoMj0aKe+H4u1TKdSSSn3Nhq55tF8f48dAfrSA0ZnaZ2 5q4wm6D/hbShtABug1BG/mIHf4jQ8NbKjF1d54HpZwfgioxYmlVRSQC2eUv72A1d0UrT 0RSg== ARC-Authentication-Results: i=1; mx.google.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=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 24si6743928edv.35.2021.06.22.20.04.54; Tue, 22 Jun 2021 20:04:55 -0700 (PDT) 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; 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=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 20C22689E5B; Wed, 23 Jun 2021 06:04:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 490BD680BBB for ; Wed, 23 Jun 2021 06:04:41 +0300 (EEST) IronPort-SDR: 384OE+Qx1zURa7QN9tLT2mbqwNd5p/Y0tCPWPBfJS2hFS9X6A2g16SLMg98QO6V0pmEd9pl5Se Gv3wyqzvFUAg== X-IronPort-AV: E=McAfee;i="6200,9189,10023"; a="205355674" X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="205355674" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2021 20:04:17 -0700 IronPort-SDR: Ma3hzLymZipNidGzj2zzTloGNJFkjWxLQkVFN29ZvFZhBh5FcuuCA8yc8dbo51yw45Aq4lgH+L kq0nL19AUMOw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,293,1616482800"; d="scan'208";a="641844718" Received: from xhh-tgl64.sh.intel.com ([10.239.159.53]) by fmsmga005.fm.intel.com with ESMTP; 22 Jun 2021 20:03:54 -0700 From: Haihao Xiang To: ffmpeg-devel@ffmpeg.org Date: Wed, 23 Jun 2021 11:03:46 +0800 Message-Id: <20210623030346.2025933-2-haihao.xiang@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210623030346.2025933-1-haihao.xiang@intel.com> References: <20210623030346.2025933-1-haihao.xiang@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] doc/examples/qsvdec: simplify this example via hw_device_ctx interface X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Haihao Xiang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wkJi9wnbLdl8 Content-Length: 4340 --- doc/examples/qsvdec.c | 45 +++++++++---------------------------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/doc/examples/qsvdec.c b/doc/examples/qsvdec.c index 7415eefca5..571d868f93 100644 --- a/doc/examples/qsvdec.c +++ b/doc/examples/qsvdec.c @@ -44,38 +44,10 @@ #include "libavutil/hwcontext_qsv.h" #include "libavutil/mem.h" -typedef struct DecodeContext { - AVBufferRef *hw_device_ref; -} DecodeContext; - static int get_format(AVCodecContext *avctx, const enum AVPixelFormat *pix_fmts) { while (*pix_fmts != AV_PIX_FMT_NONE) { if (*pix_fmts == AV_PIX_FMT_QSV) { - DecodeContext *decode = avctx->opaque; - AVHWFramesContext *frames_ctx; - AVQSVFramesContext *frames_hwctx; - int ret; - - /* create a pool of surfaces to be used by the decoder */ - avctx->hw_frames_ctx = av_hwframe_ctx_alloc(decode->hw_device_ref); - if (!avctx->hw_frames_ctx) - return AV_PIX_FMT_NONE; - frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data; - frames_hwctx = frames_ctx->hwctx; - - frames_ctx->format = AV_PIX_FMT_QSV; - frames_ctx->sw_format = avctx->sw_pix_fmt; - frames_ctx->width = FFALIGN(avctx->coded_width, 32); - frames_ctx->height = FFALIGN(avctx->coded_height, 32); - frames_ctx->initial_pool_size = 32; - - frames_hwctx->frame_type = MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET; - - ret = av_hwframe_ctx_init(avctx->hw_frames_ctx); - if (ret < 0) - return AV_PIX_FMT_NONE; - return AV_PIX_FMT_QSV; } @@ -87,7 +59,7 @@ static int get_format(AVCodecContext *avctx, const enum AVPixelFormat *pix_fmts) return AV_PIX_FMT_NONE; } -static int decode_packet(DecodeContext *decode, AVCodecContext *decoder_ctx, +static int decode_packet(AVCodecContext *decoder_ctx, AVFrame *frame, AVFrame *sw_frame, AVPacket *pkt, AVIOContext *output_ctx) { @@ -144,12 +116,12 @@ int main(int argc, char **argv) AVPacket pkt = { 0 }; AVFrame *frame = NULL, *sw_frame = NULL; - DecodeContext decode = { NULL }; - AVIOContext *output_ctx = NULL; int ret, i; + AVBufferRef *device_ref = NULL; + if (argc < 3) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; @@ -177,7 +149,7 @@ int main(int argc, char **argv) } /* open the hardware device */ - ret = av_hwdevice_ctx_create(&decode.hw_device_ref, AV_HWDEVICE_TYPE_QSV, + ret = av_hwdevice_ctx_create(&device_ref, AV_HWDEVICE_TYPE_QSV, "auto", NULL, 0); if (ret < 0) { fprintf(stderr, "Cannot open the hardware device\n"); @@ -209,7 +181,8 @@ int main(int argc, char **argv) decoder_ctx->extradata_size = video_st->codecpar->extradata_size; } - decoder_ctx->opaque = &decode; + + decoder_ctx->hw_device_ctx = av_buffer_ref(device_ref); decoder_ctx->get_format = get_format; ret = avcodec_open2(decoder_ctx, NULL, NULL); @@ -239,7 +212,7 @@ int main(int argc, char **argv) break; if (pkt.stream_index == video_st->index) - ret = decode_packet(&decode, decoder_ctx, frame, sw_frame, &pkt, output_ctx); + ret = decode_packet(decoder_ctx, frame, sw_frame, &pkt, output_ctx); av_packet_unref(&pkt); } @@ -247,7 +220,7 @@ int main(int argc, char **argv) /* flush the decoder */ pkt.data = NULL; pkt.size = 0; - ret = decode_packet(&decode, decoder_ctx, frame, sw_frame, &pkt, output_ctx); + ret = decode_packet(decoder_ctx, frame, sw_frame, &pkt, output_ctx); finish: if (ret < 0) { @@ -263,7 +236,7 @@ finish: avcodec_free_context(&decoder_ctx); - av_buffer_unref(&decode.hw_device_ref); + av_buffer_unref(&device_ref); avio_close(output_ctx);