From patchwork Thu Jun 7 23:43:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 9292 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:11c:0:0:0:0:0 with SMTP id c28-v6csp192949jad; Thu, 7 Jun 2018 16:44:48 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJeIKThkSYukzH17ZzkVN/A9B/iizW8+t1OM/CAI5XjufSUXVuw2fNOdXAKOfFY+TvQsU5W X-Received: by 2002:adf:c32b:: with SMTP id n40-v6mr3281704wrf.91.1528415088171; Thu, 07 Jun 2018 16:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528415088; cv=none; d=google.com; s=arc-20160816; b=UwrtFUw6sGLgLEqF8qZ1lRn/qA3I7RbsYtOuF9lB+d0FyStkVkbRWn7mUkylZim7TP ZaOFmpOdTuuF4oBtn/wEBRTEcmLRg2x0yqCQWh1MMzX2kH7bOOipwqyMV3Htw9c8WTDE jDZ6gbxvB+2+CUhOKz1Ns/hvzdW0LgH1inCluGhld33lRNueKBIhZguq0+aYiKvw/M+6 RIRWYrDe0yHbGsJtE7wTrGRlk6AG5I/qWqwrNfTby6c7wR8YMt4lkr8B6ImH0068/Ml7 oebHUv3tqmcihGOC+K43wu0B2WxcWUjzxCVNKTKTMz9a/UDjojW/qnA0kNYEMfAsAV0V L0XA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=ozuaeV1dRlp1Hql4QNEv24wIFj4Bcy47GXETYF1+4fE=; b=K+gGwQsJKOJiWrAxe0V9hVGlobNoTrZUAoUWAX76lFUcZM+XTS615C9ORSehgV6NTg vFjwnd7ByX00VT1apSIpvL3gAHwcYSSNnyuKbz+MhqJEX6celu7SG8SektUkZO2t73pE JtsDm6aMdqPRE8NOc7zm+AIEZlhh9A2cMbHCGXwvwi/6GHaV6jo/qB6ivr2fD0Q27BnT i6rt1WDTMZlnHggcp0vAEsL148LaxPs23AC7CTl9gOSfJe74DKo0QwnPdUK+EwtYOIkk z3RuuAIpjFTb6jYh5LSVaLaoBeXQK91eEa5/3s6w9C2WNoLua0KdGAQLVMhncUFID1u/ 9HBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=z+viJFnz; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z6-v6si19558403wrn.224.2018.06.07.16.44.47; Thu, 07 Jun 2018 16:44:48 -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; dkim=neutral (body hash did not verify) header.i=@jkqxz-net.20150623.gappssmtp.com header.s=20150623 header.b=z+viJFnz; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A83BF68A75F; Fri, 8 Jun 2018 02:43:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f179.google.com (mail-wr0-f179.google.com [209.85.128.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE19A68A643 for ; Fri, 8 Jun 2018 02:42:56 +0300 (EEST) Received: by mail-wr0-f179.google.com with SMTP id d8-v6so11535531wro.4 for ; Thu, 07 Jun 2018 16:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jkqxz-net.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=eILKBma1cVnf3N7z4HqHhRmCoVbHg8cD4hW4R4+xqGA=; b=z+viJFnzOtIfshj+8xepTehz+wImCHL2rVBszJVaqi0RmshfEFCkYdekOOTUTrnvL9 ZBzpF9IHCo4Uvf+V7ameqCFUNESiKb6qG0nE0HtXjFBffRzwiCmOG7T3Xn5hleFq0Xlg O3+Xtc1jSJ9Zgi5LFUjccdyNK8ib3DF6/+mRsVVNb1HU9bs1WctvO2BxhARPdCvXl3m5 PXQnPCHNCD0UUE9roSqF41mXFSSk9RW9UZGPsQnVFyAaCaESyPMZJwUVkxy1VePhltVG BmrLng4/X+YZiYNlTxJnlLvU/c9KLdmJKzpg2tWh45fy+ODDqi5WYSwV1+lm65oIyDPk jxcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=eILKBma1cVnf3N7z4HqHhRmCoVbHg8cD4hW4R4+xqGA=; b=M9avi00H3a0gl+Y7AjnFuuwWLgFLWlSrNojnR4ptKqQLrTdlCs03KHLa9mIxnRvyOc kUEnmL2Bz5L69Mfm6Y4+RAc5UcVY+Vs6kplL7DLk7wYOT0Q5Q6WHmJ9D9Ts8fU4Z+ms4 1sEP/KjpPY4jU6pP8fdfcQ5Qg71GumAlqu+Gyx2UoJrJq44+/qcvS+akq3yqj1OmzseH WhDvWHT7F8HSTaOVtFdZx3J9ZJZKNyt3eFZjx4AQzwx1Ftx1rpziesTglwTZ3lK+yeYc IMrh9HxLM6DmEtoUjcQOBbc4t9LlrSGmXuI9c7r5O2IuHL1ZI81n+IsUr4av01Wd3hO+ zgJw== X-Gm-Message-State: APt69E0YNS7Uv1WL6RPFdAG0yWYTiMhdiCCE/uBNntBXX7iInxYlIxgt z/zUZbd+ZoxabLcZ+r0UbHbY3Uy7 X-Received: by 2002:adf:f8c2:: with SMTP id f2-v6mr3008325wrq.237.1528415024103; Thu, 07 Jun 2018 16:43:44 -0700 (PDT) Received: from rywe.jkqxz.net (cpc91242-cmbg18-2-0-cust650.5-4.cable.virginm.net. [82.8.130.139]) by smtp.gmail.com with ESMTPSA id r2-v6sm18640545wrq.55.2018.06.07.16.43.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Jun 2018 16:43:43 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Jun 2018 00:43:00 +0100 Message-Id: <20180607234331.32139-6-sw@jkqxz.net> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180607234331.32139-1-sw@jkqxz.net> References: <20180607234331.32139-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH v2 05/36] vaapi_encode_mpeg2: Move common structure into context 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" --- libavcodec/vaapi_encode_mpeg2.c | 53 +++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/libavcodec/vaapi_encode_mpeg2.c b/libavcodec/vaapi_encode_mpeg2.c index 42df77ea49..ae77a9ce76 100644 --- a/libavcodec/vaapi_encode_mpeg2.c +++ b/libavcodec/vaapi_encode_mpeg2.c @@ -28,6 +28,9 @@ #include "vaapi_encode.h" typedef struct VAAPIEncodeMPEG2Context { + VAAPIEncodeContext common; + + // Derived settings. int mb_width; int mb_height; @@ -35,15 +38,6 @@ typedef struct VAAPIEncodeMPEG2Context { int quant_p; int quant_b; - MPEG2RawSequenceHeader sequence_header; - MPEG2RawExtensionData sequence_extension; - MPEG2RawExtensionData sequence_display_extension; - MPEG2RawGroupOfPicturesHeader gop_header; - MPEG2RawPictureHeader picture_header; - MPEG2RawExtensionData picture_coding_extension; - - int64_t last_i_frame; - unsigned int bit_rate; unsigned int vbv_buffer_size; @@ -52,6 +46,17 @@ typedef struct VAAPIEncodeMPEG2Context { unsigned int f_code_horizontal; unsigned int f_code_vertical; + // Stream state. + int64_t last_i_frame; + + // Writer structures. + MPEG2RawSequenceHeader sequence_header; + MPEG2RawExtensionData sequence_extension; + MPEG2RawExtensionData sequence_display_extension; + MPEG2RawGroupOfPicturesHeader gop_header; + MPEG2RawPictureHeader picture_header; + MPEG2RawExtensionData picture_coding_extension; + CodedBitstreamContext *cbc; CodedBitstreamFragment current_fragment; } VAAPIEncodeMPEG2Context; @@ -61,8 +66,7 @@ static int vaapi_encode_mpeg2_write_fragment(AVCodecContext *avctx, char *data, size_t *data_len, CodedBitstreamFragment *frag) { - VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; int err; err = ff_cbs_write_fragment_data(priv->cbc, frag); @@ -88,8 +92,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx, CodedBitstreamFragment *frag, int type, void *header) { - VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; int err; err = ff_cbs_insert_unit_content(priv->cbc, frag, -1, type, header, NULL); @@ -105,8 +108,7 @@ static int vaapi_encode_mpeg2_add_header(AVCodecContext *avctx, static int vaapi_encode_mpeg2_write_sequence_header(AVCodecContext *avctx, char *data, size_t *data_len) { - VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; CodedBitstreamFragment *frag = &priv->current_fragment; int err; @@ -140,8 +142,7 @@ static int vaapi_encode_mpeg2_write_picture_header(AVCodecContext *avctx, VAAPIEncodePicture *pic, char *data, size_t *data_len) { - VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; CodedBitstreamFragment *frag = &priv->current_fragment; int err; @@ -164,7 +165,7 @@ fail: static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; MPEG2RawSequenceHeader *sh = &priv->sequence_header; MPEG2RawSequenceExtension *se = &priv->sequence_extension.data.sequence; MPEG2RawSequenceDisplayExtension *sde = &priv->sequence_display_extension.data.sequence_display; @@ -416,8 +417,7 @@ static int vaapi_encode_mpeg2_init_sequence_params(AVCodecContext *avctx) static int vaapi_encode_mpeg2_init_picture_params(AVCodecContext *avctx, VAAPIEncodePicture *pic) { - VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; MPEG2RawPictureHeader *ph = &priv->picture_header; MPEG2RawPictureCodingExtension *pce = &priv->picture_coding_extension.data.picture_coding; VAEncPictureParameterBufferMPEG2 *vpic = pic->codec_picture_params; @@ -482,9 +482,8 @@ static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx, VAAPIEncodePicture *pic, VAAPIEncodeSlice *slice) { - VAAPIEncodeContext *ctx = avctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; VAEncSliceParameterBufferMPEG2 *vslice = slice->codec_slice_params; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; int qp; vslice->macroblock_address = priv->mb_width * slice->index; @@ -515,7 +514,7 @@ static int vaapi_encode_mpeg2_init_slice_params(AVCodecContext *avctx, static av_cold int vaapi_encode_mpeg2_configure(AVCodecContext *avctx) { VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; int err; err = ff_cbs_init(&priv->cbc, AV_CODEC_ID_MPEG2VIDEO, avctx); @@ -638,11 +637,9 @@ static av_cold int vaapi_encode_mpeg2_init(AVCodecContext *avctx) static av_cold int vaapi_encode_mpeg2_close(AVCodecContext *avctx) { - VAAPIEncodeContext *ctx = avctx->priv_data; - VAAPIEncodeMPEG2Context *priv = ctx->priv_data; + VAAPIEncodeMPEG2Context *priv = avctx->priv_data; - if (priv) - ff_cbs_close(&priv->cbc); + ff_cbs_close(&priv->cbc); return ff_vaapi_encode_close(avctx); } @@ -665,7 +662,7 @@ AVCodec ff_mpeg2_vaapi_encoder = { .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 (VAAPI)"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_MPEG2VIDEO, - .priv_data_size = sizeof(VAAPIEncodeContext), + .priv_data_size = sizeof(VAAPIEncodeMPEG2Context), .init = &vaapi_encode_mpeg2_init, .encode2 = &ff_vaapi_encode2, .close = &vaapi_encode_mpeg2_close,