From patchwork Tue Apr 28 17:37:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 19338 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 9D86244B549 for ; Tue, 28 Apr 2020 20:37:41 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6BC5A68C596; Tue, 28 Apr 2020 20:37:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CDB3B68BEBE for ; Tue, 28 Apr 2020 20:37:34 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id A2057E3E28; Tue, 28 Apr 2020 19:37:34 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4S9NDK998c1T; Tue, 28 Apr 2020 19:37:32 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 575E0E3E19; Tue, 28 Apr 2020 19:37:32 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Tue, 28 Apr 2020 19:37:18 +0200 Message-Id: <20200428173725.12482-1-cus@passwd.hu> X-Mailer: git-send-email 2.16.4 Subject: [FFmpeg-devel] [PATCH v4 1/8] avformat/mux: move interleaved packet functions upwards 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: Marton Balint MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Will be needed later to avoid a forward declaration. Signed-off-by: Marton Balint --- libavformat/mux.c | 208 +++++++++++++++++++++++++++--------------------------- 1 file changed, 104 insertions(+), 104 deletions(-) diff --git a/libavformat/mux.c b/libavformat/mux.c index 3d1f71ab1a..df0d9e993a 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -809,110 +809,6 @@ static int prepare_input_packet(AVFormatContext *s, AVPacket *pkt) return 0; } -static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) { - AVStream *st = s->streams[pkt->stream_index]; - int ret; - - if (!(s->flags & AVFMT_FLAG_AUTO_BSF)) - return 1; - - if (s->oformat->check_bitstream) { - if (!st->internal->bitstream_checked) { - if ((ret = s->oformat->check_bitstream(s, pkt)) < 0) - return ret; - else if (ret == 1) - st->internal->bitstream_checked = 1; - } - } - - if (st->internal->bsfc) { - AVBSFContext *ctx = st->internal->bsfc; - // TODO: when any bitstream filter requires flushing at EOF, we'll need to - // flush each stream's BSF chain on write_trailer. - if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) { - av_log(ctx, AV_LOG_ERROR, - "Failed to send packet to filter %s for stream %d\n", - ctx->filter->name, pkt->stream_index); - return ret; - } - // TODO: when any automatically-added bitstream filter is generating multiple - // output packets for a single input one, we'll need to call this in a loop - // and write each output packet. - if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) { - if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) - return 0; - av_log(ctx, AV_LOG_ERROR, - "Failed to receive packet from filter %s for stream %d\n", - ctx->filter->name, pkt->stream_index); - if (s->error_recognition & AV_EF_EXPLODE) - return ret; - return 0; - } - } - return 1; -} - -int av_write_frame(AVFormatContext *s, AVPacket *in) -{ - AVPacket local_pkt, *pkt = &local_pkt; - int ret; - - if (!in) { - if (s->oformat->flags & AVFMT_ALLOW_FLUSH) { - ret = s->oformat->write_packet(s, NULL); - flush_if_needed(s); - if (ret >= 0 && s->pb && s->pb->error < 0) - ret = s->pb->error; - return ret; - } - return 1; - } - - if (in->flags & AV_PKT_FLAG_UNCODED_FRAME) { - pkt = in; - } else { - /* We don't own in, so we have to make sure not to modify it. - * The following avoids copying in's data unnecessarily. - * Copying side data is unavoidable as a bitstream filter - * may change it, e.g. free it on errors. */ - pkt->buf = NULL; - pkt->data = in->data; - pkt->size = in->size; - ret = av_packet_copy_props(pkt, in); - if (ret < 0) - return ret; - if (in->buf) { - pkt->buf = av_buffer_ref(in->buf); - if (!pkt->buf) { - ret = AVERROR(ENOMEM); - goto fail; - } - } - } - - ret = prepare_input_packet(s, pkt); - if (ret < 0) - goto fail; - - ret = do_packet_auto_bsf(s, pkt); - if (ret <= 0) - goto fail; - -#if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX - ret = compute_muxer_pkt_fields(s, s->streams[pkt->stream_index], pkt); - - if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) - goto fail; -#endif - - ret = write_packet(s, pkt); - -fail: - // Uncoded frames using the noninterleaved codepath are also freed here - av_packet_unref(pkt); - return ret; -} - #define CHUNK_START 0x1000 int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, @@ -1181,6 +1077,110 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in return ff_interleave_packet_per_dts(s, out, in, flush); } +static int do_packet_auto_bsf(AVFormatContext *s, AVPacket *pkt) { + AVStream *st = s->streams[pkt->stream_index]; + int ret; + + if (!(s->flags & AVFMT_FLAG_AUTO_BSF)) + return 1; + + if (s->oformat->check_bitstream) { + if (!st->internal->bitstream_checked) { + if ((ret = s->oformat->check_bitstream(s, pkt)) < 0) + return ret; + else if (ret == 1) + st->internal->bitstream_checked = 1; + } + } + + if (st->internal->bsfc) { + AVBSFContext *ctx = st->internal->bsfc; + // TODO: when any bitstream filter requires flushing at EOF, we'll need to + // flush each stream's BSF chain on write_trailer. + if ((ret = av_bsf_send_packet(ctx, pkt)) < 0) { + av_log(ctx, AV_LOG_ERROR, + "Failed to send packet to filter %s for stream %d\n", + ctx->filter->name, pkt->stream_index); + return ret; + } + // TODO: when any automatically-added bitstream filter is generating multiple + // output packets for a single input one, we'll need to call this in a loop + // and write each output packet. + if ((ret = av_bsf_receive_packet(ctx, pkt)) < 0) { + if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) + return 0; + av_log(ctx, AV_LOG_ERROR, + "Failed to receive packet from filter %s for stream %d\n", + ctx->filter->name, pkt->stream_index); + if (s->error_recognition & AV_EF_EXPLODE) + return ret; + return 0; + } + } + return 1; +} + +int av_write_frame(AVFormatContext *s, AVPacket *in) +{ + AVPacket local_pkt, *pkt = &local_pkt; + int ret; + + if (!in) { + if (s->oformat->flags & AVFMT_ALLOW_FLUSH) { + ret = s->oformat->write_packet(s, NULL); + flush_if_needed(s); + if (ret >= 0 && s->pb && s->pb->error < 0) + ret = s->pb->error; + return ret; + } + return 1; + } + + if (in->flags & AV_PKT_FLAG_UNCODED_FRAME) { + pkt = in; + } else { + /* We don't own in, so we have to make sure not to modify it. + * The following avoids copying in's data unnecessarily. + * Copying side data is unavoidable as a bitstream filter + * may change it, e.g. free it on errors. */ + pkt->buf = NULL; + pkt->data = in->data; + pkt->size = in->size; + ret = av_packet_copy_props(pkt, in); + if (ret < 0) + return ret; + if (in->buf) { + pkt->buf = av_buffer_ref(in->buf); + if (!pkt->buf) { + ret = AVERROR(ENOMEM); + goto fail; + } + } + } + + ret = prepare_input_packet(s, pkt); + if (ret < 0) + goto fail; + + ret = do_packet_auto_bsf(s, pkt); + if (ret <= 0) + goto fail; + +#if FF_API_COMPUTE_PKT_FIELDS2 && FF_API_LAVF_AVCTX + ret = compute_muxer_pkt_fields(s, s->streams[pkt->stream_index], pkt); + + if (ret < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) + goto fail; +#endif + + ret = write_packet(s, pkt); + +fail: + // Uncoded frames using the noninterleaved codepath are also freed here + av_packet_unref(pkt); + return ret; +} + int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt) { int ret, flush = 0;