Message ID | 20210319055904.2264501-2-andreas.rheinhardt@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | [FFmpeg-devel,01/18] libavformat/utils: Fix indentation | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
andriy/PPC64_make_fate | success | Make fate finished |
On 3/19/2021 2:58 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. > > Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> > --- > libavformat/utils.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/libavformat/utils.c b/libavformat/utils.c > index d9a08c9ccd..0c167d0cb9 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); > } > @@ -1525,6 +1523,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, > } > > fail: > + out_pkt->data = NULL; > + out_pkt->size = 0; Move the av_packet_unref(out_pkt) from the failure path of the avpriv_packet_list_put() call here instead, and put it behind a ret < 0 check. It communicates the intention more clearly than just resetting two fields out of a dozen, which could be wrongly interpreted as "We want the rest intact here". On success avpriv_packet_list_put() will have moved the reference to the list, so the packet will be already clean. > av_packet_unref(pkt); > return ret; > } >
diff --git a/libavformat/utils.c b/libavformat/utils.c index d9a08c9ccd..0c167d0cb9 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); } @@ -1525,6 +1523,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, } fail: + out_pkt->data = NULL; + out_pkt->size = 0; av_packet_unref(pkt); return ret; }
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. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> --- libavformat/utils.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)