From patchwork Wed Aug 22 23:44:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Thompson X-Patchwork-Id: 10060 Delivered-To: ffmpegpatchwork@gmail.com Received: by 2002:a02:12c4:0:0:0:0:0 with SMTP id 65-v6csp1440853jap; Wed, 22 Aug 2018 16:45:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaKlQpeLkEK3xEKod2MUDb4STcNdLZ6nA30PNEMH6HgQKKH5sNNbfykkHU7I0XYmVPgHZeE X-Received: by 2002:a1c:760d:: with SMTP id r13-v6mr3225393wmc.22.1534981559294; Wed, 22 Aug 2018 16:45:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534981559; cv=none; d=google.com; s=arc-20160816; b=uWhWzus2HFZwPB4c6EXBR0MrlgJiNyBSIrbE/V5UkSRZHVnEOqV+A11cLSZvEdHh1r 5qbGbUNXKVH6bPUvxsZ7wkFo1xyOFzuCEv7hjxjzR6hCQV6xBkeTBanr3QkYV+MfZn8e RSca/qvTINYWHSf7xPxLoe+ybCFhRxuE9KKFC+xdfCYfG8+9nRORIERYCpGD00nGh8r3 CfLtfby7xKWm4YZtqTXp4UsEjJxo4SbUkzzYXGN3PazzqXMtivbu51DLaL6mo6lNJtJP uJy9xC/tEWy+EF9Ika3qPKJ0QYzwIO3AjTKhKKFy6Qw3QqvFXSNtCzUgg0okVQAmILOR uDjA== 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=inNstpD4vjLj7RPkF6hdXsrxTfHUcjHmVwvkkXUPdZY=; b=rltZy7yLqbOn4PdaqjGE5YUMtmbTJbWkj1F01PcdiSJc5KQarZtnCiWycXHg5ZD/vH +VkNSO0GuojJLQ+h+/FaCko9HZpRJvpUdaCfCRK5JFULu26XdJ2yREDnX/H/8VZtO4Zx 6EWxMTWAzkbo9mCYMNIvsTLCninML8pPtOxAmOZco6K7MlXTxnbzrdrUP5SkQS7OruKj zt3kza0TfjXp+mn/PlpMh33RBeqOccOuFiPXJ6o5lNhFkhGN5qqacg9YJro1zQWy2TWF pAxf08z/aeCz04JURYnN2kpBlGnWj7gCSIK51es2C1cgoBfmURVWfJrTixiQXz4axbPL RGnA== 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=iK+jq+Q+; 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 k9-v6si2351152wri.24.2018.08.22.16.45.58; Wed, 22 Aug 2018 16:45:59 -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=iK+jq+Q+; 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 94D85689C54; Thu, 23 Aug 2018 02:45:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4FE29689C16 for ; Thu, 23 Aug 2018 02:45:23 +0300 (EEST) Received: by mail-wr1-f45.google.com with SMTP id z96-v6so2984508wrb.8 for ; Wed, 22 Aug 2018 16:45:24 -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=FHbJmgWtJCf2oF9+ZZMEKVfB0dRhrHVKGC8X4WvxHI4=; b=iK+jq+Q+NjE6YtiRkL3KhHiyVuQDh1Ph34qqaG8wTpIDOwVnWB2ZtzRW9YnNPz7d43 5YvfKL4gVWgMJYrvfX9Nebcee0AI7NMhQNvBWP6QvRGpUKnPKHlk+5pawh9zxy6RJJZ4 NGB8AeYyeb1GoFUAdhUyPGbJoQR8M7DSSba8xLtInLMOt77cEaKJTWiLp/mURhrhU8CJ UVj1aArKDirUjKRL1/LocRNa0rh6JL8eWKMbijqNM1LwX9l5bzD4ahH0DHczA5GRk296 HBTzamlY+voTv5pTqJmyaIPlV5qKd+pgpAxgaXcyCAXu+gXomiWMn7/GBtO/ogfTWd2M Daog== 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=FHbJmgWtJCf2oF9+ZZMEKVfB0dRhrHVKGC8X4WvxHI4=; b=eyKFHeZgUtC9oD05eX2iiQC/7c+r8EQxpaRaXZZMYeTkSEwpfkpWIC+VuzysJWL6FH r8O9qgNFrzga5B3htCH/Df9mmcT3VuxTQ8sO38Zq6j88eg5fBCjJrAAAU9hWLdGJsd6I Cm/asGamw8aIDEvBXjuFl/SeOyeSpVtRYx+WXhOgXyzpMHRjQ00fQ+9cpp7xJwYqLE8r Wuuxg75sKtNiio8bo9M7RPShHMN0ugWWV7Nj3I9+VeiPdAhwqftU/Hfnf6AcWfALLt9i /vCzklKJVtWJ+45n4latChgpNFI9ycgN64cKb5UQG08GbkFhlNExOgRSTh+xMwqVHS2C a/rw== X-Gm-Message-State: APzg51DM2HGX1BjrY54oI5T+QT944uyYi++tZ7LSAR6dCTOUSUFnuR2X PnwJHubTrGneLOlyzukMoDFtuSD5oDI= X-Received: by 2002:a5d:4e8b:: with SMTP id e11-v6mr5783883wru.32.1534981523967; Wed, 22 Aug 2018 16:45:23 -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 x82-v6sm8184537wmd.11.2018.08.22.16.45.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Aug 2018 16:45:23 -0700 (PDT) From: Mark Thompson To: ffmpeg-devel@ffmpeg.org Date: Thu, 23 Aug 2018 00:44:37 +0100 Message-Id: <20180822234514.10571-5-sw@jkqxz.net> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180822234514.10571-1-sw@jkqxz.net> References: <20180822234514.10571-1-sw@jkqxz.net> Subject: [FFmpeg-devel] [PATCH v3 04/41] 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,