From patchwork Sun Nov 25 21:05:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11157 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 E2CEB44CB53 for ; Sun, 25 Nov 2018 23:12:54 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 61BA968A324; Sun, 25 Nov 2018 23:12:55 +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 A19D768A245 for ; Sun, 25 Nov 2018 23:12:48 +0200 (EET) Received: by mail-wm1-f66.google.com with SMTP id c126so16309105wmh.0 for ; Sun, 25 Nov 2018 13:12:53 -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=wN26qe75fXYYudYtV1hd0tBVxnnGlOTfqnw3VADvjbA=; b=cf8YPRRr1grxYQklpNCAh0zY97VMdJ/7QZv+lWvud19V9GA3P4EBYtHgTxnavSYHFs jOxKwRdVry06N+oCtutStxvfSzNrKWZZnHbwadN5ulU7PKdilPusMPDA1lWMyLeMMRk2 0JrUGs615r1FB/YpXe2tOVHC6j0yer3DwCsL+M/jtdumekwjjmyxDifobr0Vr++L2x9A x8XCr0/0FwUQj6fj3lURXkEOly0sRWLepedBOmhabo4VKeok2TKfIuzF07aOE0N0xn57 QW11xrU2XdJml7SrvD6FY5aTZ6tE6C7/kCEEp2sUs40HraTH0vPjA+go6gh1rMzMiyk+ q5Sg== 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=wN26qe75fXYYudYtV1hd0tBVxnnGlOTfqnw3VADvjbA=; b=rVvyRl/CO0c56CIZaLXi5q1wBu/k5qK1aNkNDcJl2I/EX0dWiLwEubC8RDIaAgfUWq O+yOwci7KQjSxGFZvaAkuo//8y0/WOhg+KtBp5gWAZF0QR/qJP3tT/e260OhlmeMOm7U 7zXl0iCbbn4+7zYxYnzDODZ8k69ScYwP4nGuQosNWn8aNkrwFmCJuoSyMy14Ax8cEEsk 7/RXF14t6Kr6TvsjDei1tHIUFw7UdBbO6nuz4ArHiCsZb4hxpGheVBNKsLZcpV3hx6fV kqUvUeDb4EF9vZpiBHM3njk/gIdH4xYnHX9SobSn4FKM1HcS33+C8gEfcLD7gaWYtmwh LBYA== X-Gm-Message-State: AGRZ1gK4HoK3t6tKZWX2EmrIq13V1q1MdB0Tiq5WN8P3c2N21T0jdDor in4vB4PBd9WzlH3mN0qf2cPYFA/J X-Google-Smtp-Source: AJdET5dsNilcfamE2ud6FjtBweQ+eRerczLsEEddryKwbQeZdoqzrODkE4O0F7tDSYhM2LvgKbyxMw== X-Received: by 2002:a1c:b58b:: with SMTP id e133mr22098142wmf.0.1543179990616; Sun, 25 Nov 2018 13:06:30 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id 6-v6sm13496133wmg.19.2018.11.25.13.06.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Nov 2018 13:06:30 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 25 Nov 2018 22:05:59 +0100 Message-Id: <20181125210559.2332-1-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181124015539.7164-2-andreas.rheinhardt@googlemail.com> References: <20181124015539.7164-2-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 --- This is a slight extension to my previous patch. In lots of cases where this function will be applied, the user will already have a pointer to the unit's content and this addition updates the pointer automatically. libavcodec/cbs.c | 21 +++++++++++++++++++++ libavcodec/cbs.h | 9 +++++++++ libavcodec/cbs_av1.c | 1 + libavcodec/cbs_h2645.c | 2 ++ libavcodec/cbs_internal.h | 4 ++++ libavcodec/cbs_jpeg.c | 1 + libavcodec/cbs_mpeg2.c | 1 + libavcodec/cbs_vp9.c | 1 + 8 files changed, 40 insertions(+) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index ecbf57c293..cb2ee3a769 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) + *content = unit->content; + } + + return 0; +} diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index 53ac360bb1..9bdc6aa5fd 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -352,5 +352,14 @@ int ff_cbs_delete_unit(CodedBitstreamContext *ctx, CodedBitstreamFragment *frag, int position); +/** + * Make the content of a unit writable. + * + * If content is supplied, *content will point to the unit's content on success. + */ +int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, + CodedBitstreamUnit *unit, + void **content); + #endif /* AVCODEC_CBS_H */ diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index e02bc7027a..ce8ee3faaa 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -1305,6 +1305,7 @@ const CodedBitstreamType ff_cbs_type_av1 = { .split_fragment = &cbs_av1_split_fragment, .read_unit = &cbs_av1_read_unit, + .make_writable = NULL, .write_unit = &cbs_av1_write_unit, .assemble_fragment = &cbs_av1_assemble_fragment, diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 666970ed03..7296c4cf29 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1545,6 +1545,7 @@ const CodedBitstreamType ff_cbs_type_h264 = { .split_fragment = &cbs_h2645_split_fragment, .read_unit = &cbs_h264_read_nal_unit, + .make_writable = NULL, .write_unit = &cbs_h2645_write_nal_unit, .assemble_fragment = &cbs_h2645_assemble_fragment, @@ -1558,6 +1559,7 @@ const CodedBitstreamType ff_cbs_type_h265 = { .split_fragment = &cbs_h2645_split_fragment, .read_unit = &cbs_h265_read_nal_unit, + .make_writable = NULL, .write_unit = &cbs_h2645_write_nal_unit, .assemble_fragment = &cbs_h2645_assemble_fragment, 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); diff --git a/libavcodec/cbs_jpeg.c b/libavcodec/cbs_jpeg.c index 5a72f0e2e7..f3706e7575 100644 --- a/libavcodec/cbs_jpeg.c +++ b/libavcodec/cbs_jpeg.c @@ -513,6 +513,7 @@ const CodedBitstreamType ff_cbs_type_jpeg = { .split_fragment = &cbs_jpeg_split_fragment, .read_unit = &cbs_jpeg_read_unit, + .make_writable = NULL, .write_unit = &cbs_jpeg_write_unit, .assemble_fragment = &cbs_jpeg_assemble_fragment, diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c index 8b8b266563..3e6a109550 100644 --- a/libavcodec/cbs_mpeg2.c +++ b/libavcodec/cbs_mpeg2.c @@ -414,6 +414,7 @@ const CodedBitstreamType ff_cbs_type_mpeg2 = { .split_fragment = &cbs_mpeg2_split_fragment, .read_unit = &cbs_mpeg2_read_unit, + .make_writable = NULL, .write_unit = &cbs_mpeg2_write_unit, .assemble_fragment = &cbs_mpeg2_assemble_fragment, diff --git a/libavcodec/cbs_vp9.c b/libavcodec/cbs_vp9.c index c03ce986c0..e939ec10ba 100644 --- a/libavcodec/cbs_vp9.c +++ b/libavcodec/cbs_vp9.c @@ -685,6 +685,7 @@ const CodedBitstreamType ff_cbs_type_vp9 = { .split_fragment = &cbs_vp9_split_fragment, .read_unit = &cbs_vp9_read_unit, + .make_writable = NULL, .write_unit = &cbs_vp9_write_unit, .assemble_fragment = &cbs_vp9_assemble_fragment,