@@ -830,6 +830,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;
@@ -847,9 +851,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);
@@ -1448,6 +1449,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;
@@ -1462,7 +1465,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);
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> --- libavformat/utils.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)