diff mbox series

[FFmpeg-devel,v2,02/18] avformat/utils: Always leave parse_pkt in blank state, avoid resetting

Message ID 20210319144754.2322451-1-andreas.rheinhardt@gmail.com
State Accepted
Commit 258a88dfe48e0eea1dd62ff196db36180d02a16e
Headers show
Series None | expand

Commit Message

Andreas Rheinhardt March 19, 2021, 2:47 p.m. UTC
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_packets() here.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
Indeed an improvement. Thanks.

 libavformat/utils.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

James Almer March 19, 2021, 3:36 p.m. UTC | #1
On 3/19/2021 11:47 AM, Andreas Rheinhardt wrote:
> 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_packets() here.
> 
> Reviewed-by: James Almer <jamrial@gmail.com>
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> Indeed an improvement. Thanks.
> 
>   libavformat/utils.c | 10 ++++------
>   1 file changed, 4 insertions(+), 6 deletions(-)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index d9a08c9ccd..2bd6f45f1e 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -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;
>   }

LGTM.
diff mbox series

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index d9a08c9ccd..2bd6f45f1e 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -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;
 }