diff mbox series

[FFmpeg-devel,v4,1/8] avformat/mux: move interleaved packet functions upwards

Message ID 20200428173725.12482-1-cus@passwd.hu
State Accepted
Commit 7a8a5c200bd4a3960e3524d14697656c3696beea
Headers show
Series [FFmpeg-devel,v4,1/8] avformat/mux: move interleaved packet functions upwards | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Marton Balint April 28, 2020, 5:37 p.m. UTC
Will be needed later to avoid a forward declaration.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mux.c | 208 +++++++++++++++++++++++++++---------------------------
 1 file changed, 104 insertions(+), 104 deletions(-)

Comments

Marton Balint May 4, 2020, 9:22 p.m. UTC | #1
On Tue, 28 Apr 2020, Marton Balint wrote:

> Will be needed later to avoid a forward declaration.

Will apply the series soon, this has been delayed for a very long time 
now...

Regards,
Marton

>
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
> 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;
> -- 
> 2.16.4
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Andreas Rheinhardt May 4, 2020, 9:29 p.m. UTC | #2
Marton Balint:
> 
> 
> On Tue, 28 Apr 2020, Marton Balint wrote:
> 
>> Will be needed later to avoid a forward declaration.
> 
> Will apply the series soon, this has been delayed for a very long time
> now...
> 
Sorry for this, will try to look over it this night.

- Andreas
diff mbox series

Patch

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;