From patchwork Mon Nov 26 13:39:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11171 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 80C4544D29F for ; Mon, 26 Nov 2018 15:40:07 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0B07068A66E; Mon, 26 Nov 2018 15:40:08 +0200 (EET) 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 6506068A667 for ; Mon, 26 Nov 2018 15:40:01 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id q18so18939987wrx.9 for ; Mon, 26 Nov 2018 05:40:06 -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=oMJR7bM1AUz4d4E6N0CIHfjQbsK8VkOlBcGeZ9wAxlE=; b=ar+c7UVljQhv4Aqsz7IVyMh7mCjgUH9zOGRyS3/yg4E6wNK7Z420K+zx3S8iFNuSdX /7EEtgy2fBg7ZYzcKyWlrI94GHWSz+q0NJkEi8Lrlf1Kdg+epdDHwauuERKEz7Ll7Tdv VD/6RlA54tn+0qNiQ+eV2Msvj2CSJGIYqow7r4dbklN+wgE7glsYD37GtwTgPVhpqY25 iql4p9bE6z9e9t9HgqPSS6kXbGW6ADTQKbEMhEtNyey1G+WNFmudgwMnRWr4S4pj4nuv f+bGm12YOIS4NzkCIhriObjsyrsMPgwLm/3B2BhZHzkdfcZ0pNENvWACV0vFKhzoG13J wsaQ== 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=oMJR7bM1AUz4d4E6N0CIHfjQbsK8VkOlBcGeZ9wAxlE=; b=pTGghJxtyXfF85gevbqIpiMWvxUSTMQs+1mdgExkRQQp6+5Hsfz14EUnocU2nrANVV 2+Zq3JbsXxO+iR1w3GPnH2wwhOb3I5uKJvRtrVCuOHtYTXjsZGSCTAA90KD22x+Dv8Gr YXm8/KMRtaAELxWhOA0vO7kH9SDBL3t0NF9Yzx8xGOCJdKNraqhOdSOoIGHWHAuKAhjH LzdXIKL/tOZZnHd3fRzv5mGCgB4CwNDv4Ue/SK2fKGmlm/+/XKBzMJhikUHktWm86cdH b9zDlzFVstjd2mRlz+hvdhfBsREdA2ki7vcMBxu4lqk5TFX+RJkQONWgJvLTG5vO4A0j jHow== X-Gm-Message-State: AA+aEWYf7k+URdBC+THZQfcHUxNPDQpPtCe0mymojf6N3rvyngN/Khyf Nvoxrgz8itpCPJs7S1nuple+XAwn X-Google-Smtp-Source: AFSGD/Xa1nV2Qn3iG+h81keawzq8JCK/L79PXL9urmu81L5jnONDUX8mhwyTts/69tnW5sKj9NyD9Q== X-Received: by 2002:a5d:4d46:: with SMTP id a6mr23992060wru.28.1543239605335; Mon, 26 Nov 2018 05:40:05 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id 142sm1184169wmw.27.2018.11.26.05.40.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 05:40:04 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 26 Nov 2018 14:39:12 +0100 Message-Id: <20181126133913.2356-4-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/5] cbs_h2645: Implement functions to make a unit's content writable 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" These functions (which are only implemented for parameter sets) make it possible to change the contents of the parameter sets as one pleases without changing/breaking the parsing process of future access units. Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_h2645.c | 65 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 559290bd91..931c7fb2af 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1062,6 +1062,69 @@ static int cbs_h265_read_nal_unit(CodedBitstreamContext *ctx, return 0; } +static int cbs_h264_make_unit_writable(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ + AVBufferRef *ref; + + switch (unit->type) { + case H264_NAL_SPS: + { + ref = cbs_h264_copy_sps(unit->content); + break; + } + case H264_NAL_PPS: + { + ref = cbs_h264_copy_pps(unit->content); + break; + } + default: + return AVERROR_PATCHWELCOME; + } + if (!ref) + return AVERROR(ENOMEM); + + av_buffer_unref(&unit->content_ref); + unit->content = ref->data; + unit->content_ref = ref; + + return 0; +} + +static int cbs_h265_make_unit_writable(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit) +{ + AVBufferRef *ref; + + switch (unit->type) { + case HEVC_NAL_VPS: + { + ref = cbs_h265_copy_vps(unit->content); + break; + } + case HEVC_NAL_SPS: + { + ref = cbs_h265_copy_sps(unit->content); + break; + } + case HEVC_NAL_PPS: + { + ref = cbs_h265_copy_pps(unit->content); + break; + } + default: + return AVERROR_PATCHWELCOME; + } + if (!ref) + return AVERROR(ENOMEM); + + av_buffer_unref(&unit->content_ref); + unit->content = ref->data; + unit->content_ref = ref; + + return 0; +} + static int cbs_h2645_write_slice_data(CodedBitstreamContext *ctx, PutBitContext *pbc, const uint8_t *data, size_t data_size, int data_bit_start) @@ -1534,6 +1597,7 @@ const CodedBitstreamType ff_cbs_type_h264 = { .split_fragment = &cbs_h2645_split_fragment, .read_unit = &cbs_h264_read_nal_unit, + .make_writable = &cbs_h264_make_unit_writable, .write_unit = &cbs_h2645_write_nal_unit, .assemble_fragment = &cbs_h2645_assemble_fragment, @@ -1547,6 +1611,7 @@ const CodedBitstreamType ff_cbs_type_h265 = { .split_fragment = &cbs_h2645_split_fragment, .read_unit = &cbs_h265_read_nal_unit, + .make_writable = &cbs_h265_make_unit_writable, .write_unit = &cbs_h2645_write_nal_unit, .assemble_fragment = &cbs_h2645_assemble_fragment,