From patchwork Sun Jun 2 22:37:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13382 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 5BAD64484F8 for ; Mon, 3 Jun 2019 01:38:50 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 3FE9768990B; Mon, 3 Jun 2019 01:38:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2559A6802F6 for ; Mon, 3 Jun 2019 01:38:43 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id w13so10027692wru.11 for ; Sun, 02 Jun 2019 15:38:43 -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:mime-version :content-transfer-encoding; bh=ZyeG5r6Xa3SjvxC/kvo3MkwtuMKyHveWxAq/DHlYhuc=; b=iTZjJ/plS6BeVey+pmxzAnDfC7f4/x/HKWa8rXJcnvrVXAvplN7KleBPpHqt1ZumWg GwHnvvHBDCCCgrbr9v2gxklVEUyRviCLv0gd+buRVxntxI6va/h1VBCLDk9YMKM/4tWy G083kbU0uYXGkz+2lzOvwUttYQOlSZJxnUI/p6KcKVd8u8BmRmuTvV0CsChmm67XrRRR s44AkQ5IK1zH+cZTKIkrUnd53Hc8G3BU4biM/UQoW1H1JesIWhwI6eXW7CoSN7/AIY+c dN5rl5c8dMd5LMEWs8UzBQsL0MrADse1MHaqBhrMgWia9u6PCNoSdueWPXOphep/NItg ov7A== 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:mime-version :content-transfer-encoding; bh=ZyeG5r6Xa3SjvxC/kvo3MkwtuMKyHveWxAq/DHlYhuc=; b=n0xF1MqlfZCTfUECbToARw0kdzmsPM8LeAN5Qlog4beyzJDIBhdSkRlRQmm+qIBu+k jozNIAi+KtxBmyzu3dy8IjngQNN1H4BB8YoXO0Sjw8e/qWnTAs4DbnvpeZFQrl7+E3Nt YU4905LTFVFwuRhPC46AzsCcHGOyaaSBCILXwpxnMCyp8LY7k0Z2NrcfMDmRBQdP4UFO 9fFVMu12glK0XW+Jhl8hdfgGNRxHChmJSNgiVQ7CJvbKrFtZ0fbvNjPKPGgo0cd32zcB kYHnX/j0m7tRgSRXOcI40vTM4bLw6tJiSh5LV5vh5mgwz5Yck7M5N5/WpID+AjMxrFbT 79Rw== X-Gm-Message-State: APjAAAWOuQML0OuTG6uc5tiUJuB8ooh+dl7ET7yTrpHuKlhraIa+CuaR rrl2MF5Ja44VU9xGJ3to6xjrnbYy8EU= X-Google-Smtp-Source: APXvYqxYan6TbzuIVyoWWYwW6GcQ5vttK5sakCyB3BDWfIuy8V/BrhMfKbBd3TWR0WDHb5nIF0hgbA== X-Received: by 2002:a5d:6b90:: with SMTP id n16mr14180623wrx.206.1559515122451; Sun, 02 Jun 2019 15:38:42 -0700 (PDT) Received: from localhost.localdomain (ipbcc063db.dynamic.kabel-deutschland.de. [188.192.99.219]) by smtp.gmail.com with ESMTPSA id o1sm23913501wre.76.2019.06.02.15.38.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 02 Jun 2019 15:38:41 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Jun 2019 00:37:27 +0200 Message-Id: <20190602223730.10992-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] mpeg2_metadata, cbs_mpeg2: Fix handling of colour_description 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 sequence display extension is read with colour_description equal to zero, but a user wants to add one or more of the colour_description elements, then the colour_description elements the user did not explicitly request to be set are set to zero and not to the value equal to unknown/unspecified (namely 2). A value of zero is not only inappropriate, but explicitly forbidden. This is fixed by inferring the right default values during the reading process if the elements are absent; moreover, changing any of the colour_description elements to zero is now no longer possible. 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 --- I implemented your solution, because it is easy to add the check I just removed back in should it be needed some day because of the AVCodecParameter stuff. libavcodec/cbs_mpeg2.c | 15 +++++++++++++ libavcodec/cbs_mpeg2_syntax_template.c | 4 ++++ libavcodec/mpeg2_metadata_bsf.c | 30 +++++++++++--------------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index ce22e32c15..5e971f3a54 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -82,6 +82,10 @@ (get_bits_left(rw) >= width && \ (var = show_bits(rw, width)) == (compare)) +#define infer(name, value) do { \ + current->name = value; \ + } while (0) + #include "cbs_mpeg2_syntax_template.c" #undef READ @@ -91,6 +95,7 @@ #undef xsi #undef marker_bit #undef nextbits +#undef infer #define WRITE @@ -116,6 +121,15 @@ #define nextbits(width, compare, var) (var) +#define infer(name, value) do { \ + if (current->name != (value)) { \ + av_log(ctx->log_ctx, AV_LOG_WARNING, "Warning: " \ + "%s does not match inferred value: " \ + "%"PRId64", but should be %"PRId64".\n", \ + #name, (int64_t)current->name, (int64_t)(value)); \ + } \ + } while (0) + #include "cbs_mpeg2_syntax_template.c" #undef READ @@ -125,6 +139,7 @@ #undef xsi #undef marker_bit #undef nextbits +#undef infer static void cbs_mpeg2_free_user_data(void *unit, uint8_t *content) diff --git a/libavcodec/cbs_mpeg2_syntax_template.c b/libavcodec/cbs_mpeg2_syntax_template.c index e0cf716874..d9ef480f39 100644 --- a/libavcodec/cbs_mpeg2_syntax_template.c +++ b/libavcodec/cbs_mpeg2_syntax_template.c @@ -144,6 +144,10 @@ static int FUNC(sequence_display_extension)(CodedBitstreamContext *ctx, RWContex uir(8, transfer_characteristics); uir(8, matrix_coefficients); #endif + } else { + infer(colour_primaries, 2); + infer(transfer_characteristics, 2); + infer(matrix_coefficients, 2); } ui(14, display_horizontal_size); diff --git a/libavcodec/mpeg2_metadata_bsf.c b/libavcodec/mpeg2_metadata_bsf.c index ba3a74afda..57eded0808 100644 --- a/libavcodec/mpeg2_metadata_bsf.c +++ b/libavcodec/mpeg2_metadata_bsf.c @@ -111,9 +111,9 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf, } if (ctx->video_format >= 0 || - ctx->colour_primaries >= 0 || - ctx->transfer_characteristics >= 0 || - ctx->matrix_coefficients >= 0) { + ctx->colour_primaries > 0 || + ctx->transfer_characteristics > 0 || + ctx->matrix_coefficients > 0) { if (!sde) { add_sde = 1; ctx->sequence_display_extension.extension_start_code = @@ -140,25 +140,19 @@ static int mpeg2_metadata_update_fragment(AVBSFContext *bsf, if (ctx->video_format >= 0) sde->video_format = ctx->video_format; - if (ctx->colour_primaries >= 0 || - ctx->transfer_characteristics >= 0 || - ctx->matrix_coefficients >= 0) { + if (ctx->colour_primaries > 0 || + ctx->transfer_characteristics > 0 || + ctx->matrix_coefficients > 0) { sde->colour_description = 1; - if (ctx->colour_primaries >= 0) + if (ctx->colour_primaries > 0) sde->colour_primaries = ctx->colour_primaries; - else if (add_sde) - sde->colour_primaries = 2; - if (ctx->transfer_characteristics >= 0) + if (ctx->transfer_characteristics > 0) sde->transfer_characteristics = ctx->transfer_characteristics; - else if (add_sde) - sde->transfer_characteristics = 2; - if (ctx->matrix_coefficients >= 0) + if (ctx->matrix_coefficients > 0) sde->matrix_coefficients = ctx->matrix_coefficients; - else if (add_sde) - sde->matrix_coefficients = 2; } } @@ -283,13 +277,13 @@ static const AVOption mpeg2_metadata_options[] = { { .i64 = -1 }, -1, 7, FLAGS }, { "colour_primaries", "Set colour primaries (table 6-7)", OFFSET(colour_primaries), AV_OPT_TYPE_INT, - { .i64 = -1 }, -1, 255, FLAGS }, + { .i64 = 0 }, 0, 255, FLAGS }, { "transfer_characteristics", "Set transfer characteristics (table 6-8)", OFFSET(transfer_characteristics), AV_OPT_TYPE_INT, - { .i64 = -1 }, -1, 255, FLAGS }, + { .i64 = 0 }, 0, 255, FLAGS }, { "matrix_coefficients", "Set matrix coefficients (table 6-9)", OFFSET(matrix_coefficients), AV_OPT_TYPE_INT, - { .i64 = -1 }, -1, 255, FLAGS }, + { .i64 = 0 }, 0, 255, FLAGS }, { NULL } };