]> git.sesse.net Git - ffmpeg/commitdiff
avformat/utils: Always leave parse_pkt in blank state, avoid resetting
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Thu, 18 Mar 2021 03:59:54 +0000 (04:59 +0100)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Sat, 20 Mar 2021 03:23:05 +0000 (04:23 +0100)
Always leaving said packet in a blank state after having used it
allows to avoid having to reset it before one uses it; and it also
allows to use it in more places than just in parse_packet() here.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavformat/utils.c

index 295e676c9c4a2603ce2418bb74e14a7462260bbe..ee947c195d8b2bec059aa66e6c27e98f88f3bfe1 100644 (file)
@@ -1427,9 +1427,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
     int size      = pkt->size;
     int ret = 0, got_output = flush;
 
-    if (size || flush) {
-        av_packet_unref(out_pkt);
-    } else if (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
+    if (!size && !flush && st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) {
         // preserve 0-size sync packets
         compute_pkt_fields(s, st, st->parser, pkt, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
     }
@@ -1512,10 +1510,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
         ret = avpriv_packet_list_put(&s->internal->parse_queue,
                                  &s->internal->parse_queue_end,
                                  out_pkt, NULL, 0);
-        if (ret < 0) {
-            av_packet_unref(out_pkt);
+        if (ret < 0)
             goto fail;
-        }
     }
 
     /* end of the stream => close and free the parser */
@@ -1525,6 +1521,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt,
     }
 
 fail:
+    if (ret < 0)
+        av_packet_unref(out_pkt);
     av_packet_unref(pkt);
     return ret;
 }