From patchwork Sat Dec 1 19:28:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11241 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 6DF8744D3E3 for ; Sat, 1 Dec 2018 21:30:49 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 01454689E62; Sat, 1 Dec 2018 21:30:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5021D689B79 for ; Sat, 1 Dec 2018 21:30:43 +0200 (EET) Received: by mail-wm1-f68.google.com with SMTP id r11-v6so2061522wmb.2 for ; Sat, 01 Dec 2018 11:30:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FDC8iD6sXj9FaqPmkisk7unlgUkaGbhLXV6HS/hBw64=; b=TfSiPjVgskUrLHjfTFbFM1fXa7s5qeP0q64rTKMIEL7Qyo6Mixy4Hlg96QE6WXCVkq +PN/lC556nQuzmOo0GhiTj8L+Og2jZapValBJGnHOXFDQaTFZ4D0NfgEFO8b9Kamp8Fl rfADLVW76at9EkjK1RTuVl8HH7w05TSrRTyuzZU0CVQ7ZXY/HWRXWiud6Ow4YP30rEjC GiFJKGcV9OetkG+v7EnrrbUHtjIDLGduJLMPNpaAhl8u1KVrZ9moIAICjODbYAAdJdyP 6hy4F6+oUlcaz1DHy52Sekv5gU9WrRB0KSL9hIkNoOetP13hblG6oMqAF/bINEqkDvdW zB4Q== 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=FDC8iD6sXj9FaqPmkisk7unlgUkaGbhLXV6HS/hBw64=; b=Nm1upYQroxVLSKo62mMKUGHbbni5HgDBeITbrz2NHiLLwpnQwZnBBQ4kVYAZk6O7g1 plRu3Cb1UgwN4lCZwctoPNDnjwD0xD4mqzIH3oJgHfKyhk9nAHGGXwQAT4Idgyd2AelE jv8v4aqwhxq9DIE1CFOobsFaJr5roV2ke+JSRP8kHqyHUt2u0Hj4Q7qphrRe+VVFZcoW yjhqrI0uTm7N8h6QnwOdm1238m+uvFHB2naP43yrSzpuFDUN7dhwStr8UcVRsR/ct6V1 vVG4HypMD+pBzT0BWbTSUtpMLpfV5w6udI4LPIX/wbpwY12VtB+NiL/wsK/K0hsEPpSy RnFA== X-Gm-Message-State: AA+aEWbp91JypQQ0yqvCIfJZygdzWu9vbDRNKihzbdXAl7SDOvX0DaNn CuvHJhE4Qk6EvMcRI1KyK9h2PMyP X-Google-Smtp-Source: AFSGD/V9rcbYvwjTR0eKX2+SYIJpxu9QXkcj1VE4QfR72FXqs6JUxLqOx3rIAuToV3x/ta8hhlYYBg== X-Received: by 2002:a1c:9950:: with SMTP id b77mr2896404wme.4.1543692649486; Sat, 01 Dec 2018 11:30:49 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id 5sm5045686wmw.8.2018.12.01.11.30.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Dec 2018 11:30:48 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 1 Dec 2018 20:28:03 +0100 Message-Id: <20181201192810.852-2-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181201192810.852-1-andreas.rheinhardt@googlemail.com> References: <20181201192810.852-1-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/8] cbs: Add function to update video codec parameters 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 any of the *_metadata filter based upon cbs currently updates a video codec parameter like the color information, the AVCodecParameters are not updated accordingly, so that e.g. muxers write header values based upon outdated information that may precede the new values on the bitstream level. This commit adds a function to also update the video codec parameters so that the above situation can be fixed in a unified manner. Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs.c | 35 +++++++++++++++++++++++++++++++++++ libavcodec/cbs.h | 15 +++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index ecbf57c293..d8f4b67a00 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -340,6 +340,41 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, return 0; } +void ff_cbs_update_video_parameters(CodedBitstreamContext *ctx, + AVCodecParameters *par, int profile, + int level, int width, int height, + int field_order, int color_range, + int color_primaries, int color_trc, + int color_space, int chroma_location, + int video_delay) +{ + #define SET_IF_NONNEGATIVE(elem) \ + if (elem >= 0) \ + par->elem = elem; + SET_IF_NONNEGATIVE(profile) + SET_IF_NONNEGATIVE(level) + SET_IF_NONNEGATIVE(width) + SET_IF_NONNEGATIVE(height) + SET_IF_NONNEGATIVE(field_order) + SET_IF_NONNEGATIVE(video_delay) + #undef SET_IF_NONNEGATIVE + + #define SET_IF_VALID(elem, upper_bound) \ + if (0 <= elem && elem < upper_bound) \ + par->elem = elem; + SET_IF_VALID(color_range, AVCOL_RANGE_NB) + SET_IF_VALID(color_trc, AVCOL_TRC_NB) + SET_IF_VALID(color_space, AVCOL_SPC_NB) + SET_IF_VALID(chroma_location, AVCHROMA_LOC_NB) + #undef SET_IF_VALID + + if (0 <= color_primaries && color_primaries <= AVCOL_PRI_SMPTE432 + || color_primaries == AVCOL_PRI_JEDEC_P22) + par->color_primaries = color_primaries; + + return; +} + int ff_cbs_write_packet(CodedBitstreamContext *ctx, AVPacket *pkt, CodedBitstreamFragment *frag) diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 53ac360bb1..068ed15e9c 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -285,6 +285,21 @@ int ff_cbs_write_extradata(CodedBitstreamContext *ctx, AVCodecParameters *par, CodedBitstreamFragment *frag); +/** + * Update the parameters of an AVCodecParameters structure + * + * If a parameter is negative, the corresponding member is not + * modified. For the color/chroma parameters, only values that + * are part of the relevant enumeration are written. + */ +void ff_cbs_update_video_parameters(CodedBitstreamContext *ctx, + AVCodecParameters *par, int profile, + int level, int width, int height, + int field_order, int color_range, + int color_primaries, int color_trc, + int color_space, int chroma_location, + int video_delay); + /** * Write the bitstream of a fragment to a packet. */