From patchwork Mon Dec 3 17:35:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11264 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 84F2144DE51 for ; Mon, 3 Dec 2018 19:41:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 21EEA68A39E; Mon, 3 Dec 2018 19:41:35 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9807568A273 for ; Mon, 3 Dec 2018 19:41:28 +0200 (EET) Received: by mail-wm1-f66.google.com with SMTP id r24so7518052wmh.0 for ; Mon, 03 Dec 2018 09:41:36 -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=jE+VVrJwPdvTC+Ou9FSxc1j2Bc7Wp/ws86FZP631P2w=; b=Ev7lN8P4SZfWPdmIrSH7V86hbFEkEX0m3EywT+e4fHBQJQ18LC7tWUNSjkj122eMly AK4Ma2S9mLKsE0amCmIhMFHaC+aAocO08qO50VGHi0x9uJOUkDdncpDgPhHYNSa5S0dA i+opJVWBN4aUXXfX9+o4GU7bkxJnYkojLxZb2s4UbR4JDRSVpkQsFWr9ZJ+6mppjBkVY GFi0e4xFCQYuyd/0ZHTu0SX/2xbT0kRi37RG9pDupfWhojhiMe0/NYO7xywrYv+/Yfak DsO8xY1vWdCcSJOrYV/qy9w+GRu/vIjnWTb4GERS8EL6Ryz81ICb6aZ1FtlR4T2Wpile G57A== 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=jE+VVrJwPdvTC+Ou9FSxc1j2Bc7Wp/ws86FZP631P2w=; b=OuMlg7ulTTKUKXkw5HuTlIddOZFT5bQiDBBdfQYumB7xrZ69xK2CNOVba8qadd/3KI FNA3fGT6VkQxMVyCbafN2K3aaXiTvXo333qHEbNH7/5xqbhCk8K7A5QZsIhQEgHsAPs2 Qz+y3Uy6pYiheZtKdocR3u3ywqZSvOZhgXmkocE2i/FNlMVCugaJjFQrivCaVbG+hppd BLVmrLYk/6U9dyl417zgjoZSiHkGJFA7awepOiMX3kstFSUzgk+XWmyrcNrxJATNweNd vjrFkUWD36cLMCcloJIu0pTu/txU95AgtAVGRKTmWghoceTGMSbuY5y3+lSOmpdgL38t 3LjQ== X-Gm-Message-State: AA+aEWbmR1nCtRnc0uEWU/QFxPp2xeGOCJQ+pn8vUXDvw5ittdYSAb4c 9X18/ew5SMyHeweOfV+tFEzYLpi9 X-Google-Smtp-Source: AFSGD/X/W42alZkiFt8LoWLNEXGJd9GZbynFBPdrPiP3GadA39723B9tqhkziTyNr9AKyXdleYlIQg== X-Received: by 2002:a1c:70e:: with SMTP id 14mr9625820wmh.139.1543858553632; Mon, 03 Dec 2018 09:35:53 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id l3sm19473726wma.44.2018.12.03.09.35.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 03 Dec 2018 09:35:53 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 3 Dec 2018 18:35:28 +0100 Message-Id: <20181203173528.736-1-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181126133913.2356-1-andreas.rheinhardt@googlemail.com> References: <20181126133913.2356-1-andreas.rheinhardt@googlemail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] cbs: Add function to make content of a unit 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" This will enable us to change e.g. the parameter sets of H.2645 in ways that would change the parsing process of future units. An example of this is the h264_redundant_pps bsf. The actual implementation of the underlying codec-dependent make_writable functions is not contained in this commit. Signed-off-by: Andreas Rheinhardt --- Unfortunately I messed up the function parameters and made the content parameter pretty much unusable. This version fixes this. Notice that it supposes that both pointer to void as well as pointer to structures have the same size and object representation. Other functions like several memory-related ones (that use a void * argument for a pointer to a pointer) make the same assumption, so I guess that it is ok. libavcodec/cbs.c | 21 +++++++++++++++++++++ libavcodec/cbs.h | 10 ++++++++++ libavcodec/cbs_internal.h | 4 ++++ 3 files changed, 35 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index ecbf57c293..13bcbb722f 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -665,3 +665,24 @@ int ff_cbs_delete_unit(CodedBitstreamContext *ctx, return 0; } + +int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit, + void *content) +{ + if (unit->content && (!unit->content_ref || + !av_buffer_is_writable(unit->content_ref))) { + int err; + if (!ctx->codec->make_writable) + return AVERROR_PATCHWELCOME; + + err = ctx->codec->make_writable(ctx, unit); + if (err < 0) + return err; + + if (content) + memcpy(content, &unit->content, sizeof(content)); + } + + return 0; +} diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 53ac360bb1..a17c43dae4 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -352,5 +352,15 @@ int ff_cbs_delete_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position); +/** + * Make the content of a unit writable. + * + * If content is supplied, it is supposed to be a pointer to a pointer + * and *content will point to the content of the unit on success. + */ +int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit, + void *content); + #endif /* AVCODEC_CBS_H */ diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index 53f2e5d187..62a836af90 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -44,6 +44,10 @@ typedef struct CodedBitstreamType { int (*read_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit); + // Make a unit's content writable. + int (*make_writable)(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit); + // Write the unit->data bitstream from unit->content. int (*write_unit)(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit);