From patchwork Mon Jun 17 03:42:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13569 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 8E0DB447BCA for ; Mon, 17 Jun 2019 06:49:23 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 771E1689B2C; Mon, 17 Jun 2019 06:49:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 36D756899F9 for ; Mon, 17 Jun 2019 06:49:17 +0300 (EEST) Received: by mail-wm1-f67.google.com with SMTP id c66so7646604wmf.0 for ; Sun, 16 Jun 2019 20:49:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kyu5Au+QaJfmbYgZPE9Qbw4z197P0RIuL8+4n6mOpFE=; b=JADFG4JncN/LVz4tbg44T6VQeXNewLbBYNc+10ffJXfBsdU/1paaXzHp4xiExJRR0W ME4aGJ2LHbPNDhbVqj+ItKf4g+8QP221W9lgs/PUi3NCXepA2SUYABZxc7K/UfZzJJ5c 75CzXNnevwe72/nS0QUTCeTF8AnPH7tTpty3a5jmRRbznPFY+bKZxoku1qvrny+Ox7+i iZO0c1iZg+DY/7IgsH4WQgeFsa3M9aV0SMIFeAPTiHQxquOPGXCugFbnsxOFXyPQZj3q 97CY39LBUuJBBNlg7WKjLEtFs+CljHF8kclOz/mkIEApZfrYp5JYFDpvtDnsEgqmtFjj AVaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kyu5Au+QaJfmbYgZPE9Qbw4z197P0RIuL8+4n6mOpFE=; b=KoYckej2GcsSPwIDVERg5FEFJtX2g9A2fxh6zWXMoKnJsIZI4hua3NNcGBSDAZ9wrp 2RZC8L2kX0w4wEiSGaDS76VMTWApZdgRMMQ/9O7FoCFU3fn9cYR+z5DP5THTxQr4pllJ OesIKYYtGye34M/U+n4QWz1GXl+uPi5am5dSxH+WohOFKGic//VIdQEv7JTlqAnjqCNL BZ8ulpBhNYpK1Tle+quW11iqEcNsu2RHiAyLcjfOfiFElJb8q0kY2J9ic/KYdDteMGqg 574GPc/a61/0WmzhTKQcDtKxy+Noc0C4XZ93w5PaCzy9POhQ0FzFema2BiDl0fqKKc1y hf5w== X-Gm-Message-State: APjAAAWcS9dDyunZiurxJzwNjKELcpcSXU9ZXBAwndbwQVoskYTYOM27 9VfwcDgBfNVwKLpDVFkq3Lz96Ivq X-Google-Smtp-Source: APXvYqw0xbSyEBUVDmQ11tsuIBMQk/ap5YOX4NXP9RfgqwUo1LsTm0DNqlVBhissKRSL6bLGB5Xb6Q== X-Received: by 2002:a1c:99c6:: with SMTP id b189mr17108957wme.57.1560743047259; Sun, 16 Jun 2019 20:44:07 -0700 (PDT) Received: from localhost.localdomain (ipbcc063db.dynamic.kabel-deutschland.de. [188.192.99.219]) by smtp.gmail.com with ESMTPSA id x83sm9632889wmb.42.2019.06.16.20.44.06 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 16 Jun 2019 20:44:06 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Jun 2019 05:42:22 +0200 Message-Id: <20190617034223.21195-18-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> References: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 17/18] mpeg2_metadata: Localize inserting of sequence display extensions 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" If a new sequence display extension had to be added, this was up until now done at two places: One where a sequence display extension was initialized with default values and one where the actual sequence display extension was inserted into the fragment. This division of labour is unnecessary and pointless; it has been changed. Furthermore, if a sequence display extension has to be added, the earlier code set some fields to their default value twice. This has been changed, too. Signed-off-by: Andreas Rheinhardt --- This patch of course partially overlaps with [1]. Will rebase later. [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2019-June/244952.html libavcodec/mpeg2_metadata_bsf.c | 34 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c index 082137d786..6779ffd4c4 100644 --- a/libavcodec/mpeg2_metadata_bsf.c +++ b/libavcodec/mpeg2_metadata_bsf.c @@ -53,7 +53,7 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf, MPEG2RawSequenceHeader *sh = NULL; MPEG2RawSequenceExtension *se = NULL; MPEG2RawSequenceDisplayExtension *sde = NULL; - int i, se_pos, add_sde = 0; + int i, se_pos; for (i = 0; i < frag->nb_units; i++) { if (frag->units[i].type == MPEG2_START_SEQUENCE_HEADER) { @@ -115,7 +115,7 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf, ctx->transfer_characteristics >= 0 || ctx->matrix_coefficients >= 0) { if (!sde) { - add_sde = 1; + int err; ctx->sequence_display_extension.extension_start_code = MPEG2_START_EXTENSION; ctx->sequence_display_extension.extension_start_code_identifier = @@ -135,6 +135,16 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf, .display_vertical_size = se->vertical_size_extension << 12 | sh->vertical_size_value, }; + + err = ff_cbs_insert_unit_content(ctx->cbc, frag, se_pos + 1, + MPEG2_START_EXTENSION, + &ctx->sequence_display_extension, + NULL); + if (err < 0) { + av_log(bsf, AV_LOG_ERROR, "Failed to insert new sequence " + "display extension.\n"); + return err; + } } if (ctx->video_format >= 0) @@ -147,32 +157,12 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf, if (ctx->colour_primaries >= 0) sde->colour_primaries = ctx->colour_primaries; - else if (add_sde) - sde->colour_primaries = 2; if (ctx->transfer_characteristics >= 0) sde->transfer_characteristics = ctx->transfer_characteristics; - else if (add_sde) - sde->transfer_characteristics = 2; if (ctx->matrix_coefficients >= 0) sde->matrix_coefficients = ctx->matrix_coefficients; - else if (add_sde) - sde->matrix_coefficients = 2; - } - } - - if (add_sde) { - int err; - - err = ff_cbs_insert_unit_content(ctx->cbc, frag, se_pos + 1, - MPEG2_START_EXTENSION, - &ctx->sequence_display_extension, - NULL); - if (err < 0) { - av_log(bsf, AV_LOG_ERROR, "Failed to insert new sequence " - "display extension.\n"); - return err; } }