diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2019-09-20 22:39:11 +0200 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2019-09-28 18:32:43 -0300 |
commit | 47a4528abc9702da02b2115c4ad235e70138648a (patch) | |
tree | d6e2924a78d52cfd6bd50903d8ba1dbbf42d4d90 /libavformat/utils.c | |
parent | 551e8dc145939f575fbe4f71200c6442c9869cdf (diff) |
avformat/utils: Don't initialize in loops
Since the recent changes to ff_packet_list_put, the source packet will
be automatically reset when the reference is moved to the packet list,
so that it is unnecessary to reinitialize the packet in the loops in
parse_packet and ff_read_packet; initializing once at the beginning is
enough.
This also fixes a potential, but currently unexisting problem: If the
raw packet buffer was initially not empty and probe_codec() failed,
then the packet returned would not be initialized. But given that
probe_codec() currently can't fail (always returns 0) this was not an
acute danger.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavformat/utils.c')
-rw-r--r-- | libavformat/utils.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/libavformat/utils.c b/libavformat/utils.c index 9f8a5bfb63..3d42243805 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -835,6 +835,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) int ret, i, err; AVStream *st; + pkt->data = NULL; + pkt->size = 0; + av_init_packet(pkt); + for (;;) { AVPacketList *pktl = s->internal->raw_packet_buffer; const AVPacket *pkt1; @@ -852,9 +856,6 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) } } - pkt->data = NULL; - pkt->size = 0; - av_init_packet(pkt); ret = s->iformat->read_packet(s, pkt); if (ret < 0) { av_packet_unref(pkt); @@ -1450,6 +1451,8 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) int size = pkt ? pkt->size : 0; int ret = 0, got_output = 0; + av_init_packet(&out_pkt); + if (!pkt) { av_init_packet(&flush_pkt); pkt = &flush_pkt; @@ -1464,7 +1467,6 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) int64_t next_pts = pkt->pts; int64_t next_dts = pkt->dts; - av_init_packet(&out_pkt); len = av_parser_parse2(st->parser, st->internal->avctx, &out_pkt.data, &out_pkt.size, data, size, pkt->pts, pkt->dts, pkt->pos); |