From patchwork Sat May 30 16:05:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 20010 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 78A4F44AA6F for ; Sat, 30 May 2020 19:10:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id DFC4168AE41; Sat, 30 May 2020 19:06:51 +0300 (EEST) 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 3529368B08F for ; Sat, 30 May 2020 19:06:41 +0300 (EEST) Received: by mail-wr1-f66.google.com with SMTP id l10so7154071wrr.10 for ; Sat, 30 May 2020 09:06:41 -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=UYfhXXOFTG4qMnZAHdpfEolmdwsFmdzGIqJlPI0ncD8=; b=LRIBCgrUmtfCWCIdd85nFUjVXnjKVPjv+vQGT1nDe9SWKYlv448dKa6WhH2pUnkPLP 15cEYkT0uDFZ+KXkevW6wUCZbxbdBna5xB9TIiuOiB1Ntg5VlxxaYpcA74ceDW9nJ/Ap FcJGPZt6pROkJJ8NhVE157ByEZa9gFDKsKMSX6sbgHqzwQZ9MhM2qLRA1Wak505GkD33 MDyOsYbeKaFKBO62Xcxv24Q75DjXs9TO4O7yArBkvHi9xEAJhbcSZyqrM4RuYwEBsVxQ FlP4IShhOjky+l+yji9ibAYo/pphBhhCevHnzEsXrELeqEGRGDs7XgZJbJHFSnCtqdQf XXYQ== 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=UYfhXXOFTG4qMnZAHdpfEolmdwsFmdzGIqJlPI0ncD8=; b=p/UaN/mwRSNkacf9lXPu8H9YWq/N5+5r9NZLdZkk98lyA+NQF/h32TF7OX44vhMI95 3kiroIKT9HNA/Eb3XwXiaeXz7zdYmMmgKaVfNZk465lGM8pfJGWnpEWoatzBMDe1hYov wOlERhgu0hWhh7tXK4wApDbiBbWIvINEnu3/abJYx1vge0O4lQUQWW/xHuj9xkA2CQNC CNhWRz3nBQtc9C/T+G6M6ChlkTSkPpG1ZtwoPrmVg4Dy3rGSfLbPrPUkpYWnptrWf9xQ PeFlqkkQZFrXM0OoF1x0Ji86IOQsMLZn3k4i+6DzWIsADEedvjkedKqhHLJW4QN6zQ+S qa8g== X-Gm-Message-State: AOAM532zz9MylwDFCILAiWr8adUWXweL2JbWQcy8OrWREJLxHb5aKhWt DSIuzVuPdAD+gimJaVgPOG2Mbp6l X-Google-Smtp-Source: ABdhPJzC4bnhLc7DKLJmrhpCbZPOsAXmbreXwg5/NzGBltClB2sahjpijfFwkPT1zf40Sz1aUn5WCA== X-Received: by 2002:a5d:604b:: with SMTP id j11mr13771196wrt.193.1590854800306; Sat, 30 May 2020 09:06:40 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1ab57.dynamic.kabel-deutschland.de. [188.193.171.87]) by smtp.gmail.com with ESMTPSA id v27sm15186517wrv.81.2020.05.30.09.06.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 May 2020 09:06:39 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 30 May 2020 18:05:29 +0200 Message-Id: <20200530160541.29517-24-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> References: <20200530160541.29517-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 24/36] avcodec/h264_mp4toannexb_bsf: Remove intermediate packet 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 commit ends using separate packets for in- and output. Instead, the input is read directly into the packet destined for output via ff_bsf_get_packet_ref() and only the buffer-related fields are modified; the others are not touched. Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_mp4toannexb_bsf.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/libavcodec/h264_mp4toannexb_bsf.c b/libavcodec/h264_mp4toannexb_bsf.c index 91cabcf170..75b38e1be3 100644 --- a/libavcodec/h264_mp4toannexb_bsf.c +++ b/libavcodec/h264_mp4toannexb_bsf.c @@ -166,35 +166,33 @@ static int h264_mp4toannexb_init(AVBSFContext *ctx) return 0; } -static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) +static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *pkt) { H264BSFContext *s = ctx->priv_data; - AVPacket *in; uint8_t unit_type, new_idr, sps_seen, pps_seen; const uint8_t *buf; const uint8_t *buf_end; + AVBufferRef *out_buf = NULL; uint8_t *out; uint64_t out_size; int ret; - ret = ff_bsf_get_packet(ctx, &in); + ret = ff_bsf_get_packet_ref(ctx, pkt); if (ret < 0) return ret; /* nothing to filter */ if (!s->extradata_parsed) { - av_packet_move_ref(opkt, in); - av_packet_free(&in); return 0; } - buf_end = in->data + in->size; + buf_end = pkt->data + pkt->size; #define LOG_ONCE(...) \ if (j) \ av_log(__VA_ARGS__) for (int j = 0; j < 2; j++) { - buf = in->data; + buf = pkt->data; new_idr = s->new_idr; sps_seen = s->idr_sps_seen; pps_seen = s->idr_pps_seen; @@ -273,28 +271,25 @@ static int h264_mp4toannexb_filter(AVBSFContext *ctx, AVPacket *opkt) ret = AVERROR(ERANGE); goto fail; } - ret = av_new_packet(opkt, out_size); + ret = ff_buffer_padded_realloc(&out_buf, out_size); if (ret < 0) goto fail; - out = opkt->data; + out = out_buf->data; } } #undef LOG_ONCE - av_assert1(out_size == opkt->size); + ff_packet_replace_buffer(pkt, out_buf); + + av_assert1(out_size == pkt->size); s->new_idr = new_idr; s->idr_sps_seen = sps_seen; s->idr_pps_seen = pps_seen; - ret = av_packet_copy_props(opkt, in); - if (ret < 0) - goto fail; - fail: if (ret < 0) - av_packet_unref(opkt); - av_packet_free(&in); + av_packet_unref(pkt); return ret; }