From patchwork Wed Jun 19 23:45:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13632 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 56DA5448AA5 for ; Thu, 20 Jun 2019 02:55:56 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 49B0068AB76; Thu, 20 Jun 2019 02:55:56 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 22B7A68AB43 for ; Thu, 20 Jun 2019 02:55:48 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id d18so1046050wrs.5 for ; Wed, 19 Jun 2019 16:55:48 -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=5Zb6uZVp55B/qzpF+ZcH3D6Cu+XBDP8St5ofVdvRsO4=; b=WybCISEmXR/4OlTQFNQQ6ed8l8o4EJMQVH/GD+AjGJf0vDbXJOAjUsVoTbcID/1a0A WJUawG3MSeQ0Nj7vSH9qBKiiRetuuh9zxqvX3VhLZXIZVMSHfiLxaDb+vIs6DGM31DCy 7oxYIjblLbygBBx7BINAaUa1S0DFxfWNmsHy3W8Wl7HMGbLO6DZQ8+yTBXcobuG6zCFs dC9Kfv9sD63bVxoV4HHLgYtlqIPKsS75Bib+3cSwU1KF1RWuinyjw8r3NpgfBaHdMr9L J5dSkuPlqVDIkzZbQ7Hn7i2rI6RhpMiMY4YRvuE0+YMrELj/NaLGWmIDJzCXMYd2yeh9 vvoA== 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=5Zb6uZVp55B/qzpF+ZcH3D6Cu+XBDP8St5ofVdvRsO4=; b=MqfQhElemrL7+ClsJbvKHcLo2V8TfpxGTNqez5jZyJiIgGkNba4QofAdLs7MqKjimX mUmhFDR2SjffyAQqoO0Eu0j4o3DzizdPVwM2PuZ+QSFnCv4fH/U/0bIIo4fD6Xr5e3m5 n45BXODYtr8Hi46O1k3fw80Fe4aLwzRuIofPwufV29VaNik96jbTbhR5VQpazDBffXXl xof44NtxKIYM0PoUuPLRPR4olmHGxdP7zoO2PKn40/kk21K54NV0mRBoDAN/OB8adxOy 61josJLBICCbOSfBo4KkjK9suQeRDFG4oHD19whPOtT0gLIOwiBCZu+CLq9wMgI17f60 Z+iQ== X-Gm-Message-State: APjAAAWX68Cjlf2z+2z3b2jbqxTmxLGNaMgNyjpVFueCUqoImqSPJzfW /7Z1Bnhnvb7F9L4L7/vKs1V8RZj4 X-Google-Smtp-Source: APXvYqz946BCNG5uW8/kKmO0jogEE3ur45kTAD9Ys+uwtS0yxF0MCLeQ44YsxyMDtvJ4QiFnxN4ZnA== X-Received: by 2002:adf:ec12:: with SMTP id x18mr55991132wrn.145.1560988547465; Wed, 19 Jun 2019 16:55:47 -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.46 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 19 Jun 2019 16:55:47 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 20 Jun 2019 01:45:15 +0200 Message-Id: <20190619234521.15619-17-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 25/31] 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 color information, the AVCodecParameters are not updated accordingly, so that e.g. muxers write header values based upon outdated information that may precede and thereby nullify 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 47679eca1b..37b080b5ba 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -342,6 +342,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 e1e6055ceb..1655f790cd 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -304,6 +304,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. *