From patchwork Wed Jun 19 23:45:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13625 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 8976C448AA5 for ; Thu, 20 Jun 2019 02:55:47 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 783E668AB2E; Thu, 20 Jun 2019 02:55:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2C7C668AB0C for ; Thu, 20 Jun 2019 02:55:42 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id m3so1067454wrv.2 for ; Wed, 19 Jun 2019 16:55:42 -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=SCHggT4wlnepn7TvxSUAX+s5v4DK4c0tbXLdTYW9EPA=; b=TKlECTGOsHFs6XrvRcNPJtnnhwJagCE/DCtdyymkFnb6b1J5RN14FkdsCHdCK77mEg kDu8hmmFJR++s2s0toutw3H0Fdwf9wASdHN8RMYqYiUd4IRg5z0cSDIeNo2B6+zi0JEd r+jquuzDixNB97Y5rXRWsCgiXQu0kw5p3s7T34LA8zMbH1hxoOY2jKg/oE8tkKFn2ilT i1BTt+sFotS982GDw6mAmLfPvyywepaMG/gIr3oVPeIwZWCuwkQBlUXXO65nacdF8POb AftLe3AvdLMGeSJERekYEGj9h8yo334bl43ZbJNSXMKGbZHTQ9qe0AggP1V7IayUNzX2 mcTg== 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=SCHggT4wlnepn7TvxSUAX+s5v4DK4c0tbXLdTYW9EPA=; b=Ptn5TsWiEiN1PG09kImNuyb0I8kgRHfSqyQ3LhZxyRR2T2sujKamI/xEn4kpHrO8wx JCxwjGO0J8kR+QkNEBKPrjNUR1LDaLzWEmtlXUOmVtHjt3xawFS2GW8lruBLy8LIi6G4 1eDY2ppiXVGLKTZG8Sa1wP1hRHsbnUQIi/54tX4RyRPwDBypKt1UjvdyKe0dq0WEmJ4G 1evO8QDA7cqBL/t7ooN59cWimIy0qhiZWTky1F7lNPKHbTcJg0/a0jikQEFDVlhrhzHr jQKknThh/6sg44Yj9DhVo39cg2nVHB6LoUgoXWsVeSaJQW3PTevlE2oA80rJMPFgx3yG 3xAQ== X-Gm-Message-State: APjAAAVK8dSSMTXhWcDA7Sg+xKIyR0royT6WXmDu/Y1EIdkoAexVBaaW JSU/VCmTld7YPLQW/SNQO+S1NuA6 X-Google-Smtp-Source: APXvYqwflOZESNhmok23gFNE6DufNOEp0b/2Xe4L3uU1j0fOMphJd2EY/8ZezQSE4FNvZapxnrqf6Q== X-Received: by 2002:adf:efc5:: with SMTP id i5mr78531073wrp.158.1560988541504; Wed, 19 Jun 2019 16:55:41 -0700 (PDT) Received: from localhost.localdomain (ipbcc063db.dynamic.kabel-deutschland.de. [188.192.99.219]) by smtp.gmail.com with ESMTPSA id t63sm2758989wmt.6.2019.06.19.16.55.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 16:55:41 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jun 2019 01:45:08 +0200 Message-Id: <20190619234521.15619-10-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190619234521.15619-1-andreas.rheinhardt@gmail.com> References: <20190617034223.21195-1-andreas.rheinhardt@gmail.com> <20190619234521.15619-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 18/31] 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 --- 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; } }