[FFmpeg-devel] [PATCH 19/21] avformat/tiertexseq: Simplify cleanup after read_header error

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Sun Mar 22 05:47:54 EET 2020


by setting the FF_INPUTFORMAT_HEADER_CLEANUP flag. Also check error
conditions for being negative instead of only nonzero (they couldn't be
positive here anyway).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
---
 libavformat/tiertexseq.c | 19 ++++++-------------
 1 file changed, 6 insertions(+), 13 deletions(-)

diff --git a/libavformat/tiertexseq.c b/libavformat/tiertexseq.c
index d7719e5acb..07c939a4d4 100644
--- a/libavformat/tiertexseq.c
+++ b/libavformat/tiertexseq.c
@@ -161,7 +161,7 @@ static int seq_parse_frame_data(SeqDemuxContext *seq, AVIOContext *pb)
             err = seq_fill_buffer(seq, pb, buffer_num[1 + i],
               offset_table[i],
               offset_table[e] - offset_table[i]);
-            if (err)
+            if (err < 0)
                 return err;
         }
     }
@@ -202,20 +202,16 @@ static int seq_read_header(AVFormatContext *s)
 
     /* init internal buffers */
     rc = seq_init_frame_buffers(seq, pb);
-    if (rc) {
-        seq_read_close(s);
+    if (rc < 0)
         return rc;
-    }
 
     seq->current_frame_offs = 0;
 
     /* preload (no audio data, just buffer operations related data) */
     for (i = 1; i <= 100; i++) {
         rc = seq_parse_frame_data(seq, pb);
-        if (rc) {
-            seq_read_close(s);
+        if (rc < 0)
             return rc;
-        }
     }
 
     seq->current_frame_pts = 0;
@@ -224,10 +220,8 @@ static int seq_read_header(AVFormatContext *s)
 
     /* initialize the video decoder stream */
     st = avformat_new_stream(s, NULL);
-    if (!st) {
-        seq_read_close(s);
+    if (!st)
         return AVERROR(ENOMEM);
-    }
 
     avpriv_set_pts_info(st, 32, 1, SEQ_FRAME_RATE);
     seq->video_stream_index = st->index;
@@ -239,10 +233,8 @@ static int seq_read_header(AVFormatContext *s)
 
     /* initialize the audio decoder stream */
     st = avformat_new_stream(s, NULL);
-    if (!st) {
-        seq_read_close(s);
+    if (!st)
         return AVERROR(ENOMEM);
-    }
 
     st->start_time = 0;
     avpriv_set_pts_info(st, 32, 1, SEQ_SAMPLE_RATE);
@@ -324,4 +316,5 @@ AVInputFormat ff_tiertexseq_demuxer = {
     .read_header    = seq_read_header,
     .read_packet    = seq_read_packet,
     .read_close     = seq_read_close,
+    .flags_internal = FF_INPUTFORMAT_HEADER_CLEANUP,
 };
-- 
2.20.1



More information about the ffmpeg-devel mailing list