diff mbox series

[FFmpeg-devel,3/8] avformat/mux: factorize interleaved write_packet

Message ID 20200328181515.5333-3-cus@passwd.hu
State Accepted
Headers show
Series [FFmpeg-devel,1/8] fftools/ffmpeg: also flush encoders which have a variable frame size
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Marton Balint March 28, 2020, 6:15 p.m. UTC
Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libavformat/mux.c | 58 +++++++++++++++++++++++--------------------------------
 1 file changed, 24 insertions(+), 34 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/mux.c b/libavformat/mux.c
index dfb21c8aa5..f68f962a92 100644
--- a/libavformat/mux.c
+++ b/libavformat/mux.c
@@ -1187,6 +1187,28 @@  static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in
         return ff_interleave_packet_per_dts(s, out, in, flush);
 }
 
+static int interleaved_write_packet(AVFormatContext *s, AVPacket *pkt, int flush)
+{
+    for (;; ) {
+        AVPacket opkt;
+        int ret = interleave_packet(s, &opkt, pkt, flush);
+        if (pkt) {
+            memset(pkt, 0, sizeof(*pkt));
+            av_init_packet(pkt);
+            pkt = NULL;
+        }
+        if (ret <= 0) //FIXME cleanup needed for ret<0 ?
+            return ret;
+
+        ret = write_packet(s, &opkt);
+
+        av_packet_unref(&opkt);
+
+        if (ret < 0)
+            return ret;
+    }
+}
+
 int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
 {
     int ret, flush = 0;
@@ -1221,25 +1243,8 @@  int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt)
         av_log(s, AV_LOG_TRACE, "av_interleaved_write_frame FLUSH\n");
         flush = 1;
     }
+    return interleaved_write_packet(s, pkt, flush);
 
-    for (;; ) {
-        AVPacket opkt;
-        int ret = interleave_packet(s, &opkt, pkt, flush);
-        if (pkt) {
-            memset(pkt, 0, sizeof(*pkt));
-            av_init_packet(pkt);
-            pkt = NULL;
-        }
-        if (ret <= 0) //FIXME cleanup needed for ret<0 ?
-            return ret;
-
-        ret = write_packet(s, &opkt);
-
-        av_packet_unref(&opkt);
-
-        if (ret < 0)
-            return ret;
-    }
 fail:
     av_packet_unref(pkt);
     return ret;
@@ -1249,23 +1254,8 @@  int av_write_trailer(AVFormatContext *s)
 {
     int ret, i;
 
-    for (;; ) {
-        AVPacket pkt;
-        ret = interleave_packet(s, &pkt, NULL, 1);
-        if (ret < 0)
-            goto fail;
-        if (!ret)
-            break;
-
-        ret = write_packet(s, &pkt);
+    ret = interleaved_write_packet(s, NULL, 1);
 
-        av_packet_unref(&pkt);
-
-        if (ret < 0)
-            goto fail;
-    }
-
-fail:
     if (s->oformat->write_trailer) {
         if (!(s->oformat->flags & AVFMT_NOFILE) && s->pb)
             avio_write_marker(s->pb, AV_NOPTS_VALUE, AVIO_DATA_MARKER_TRAILER);