Commit fc20ba9e authored by Andreas Rheinhardt's avatar Andreas Rheinhardt Committed by James Almer

avformat/utils: Move the reference to the packet list

Up until now, ff_packet_list_put had a flaw: When it moved a packet to
the list (meaning, when it ought to move the reference to the packet
list instead of creating a new one via av_packet_ref), it did not reset
the original packet, confusing the ownership of the data in the packet.
This has been done because some callers of this function were not
compatible with resetting the packet.

This commit changes these callers and fixes this flaw. In order to
indicate that the ownership of the packet has moved to the packet list,
pointers to constant AVPackets are used whenever the target of the
pointer might already be owned by the packet list.
Signed-off-by: 's avatarAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: 's avatarJames Almer <jamrial@gmail.com>
parent bae8844e
...@@ -460,10 +460,7 @@ int ff_packet_list_put(AVPacketList **packet_buffer, ...@@ -460,10 +460,7 @@ int ff_packet_list_put(AVPacketList **packet_buffer,
return ret; return ret;
} }
} else { } else {
// TODO: Adapt callers in this file so the line below can use av_packet_move_ref(&pktl->pkt, pkt);
// av_packet_move_ref() to effectively move the reference
// to the list.
pktl->pkt = *pkt;
} }
if (*packet_buffer) if (*packet_buffer)
...@@ -835,6 +832,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -835,6 +832,7 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
for (;;) { for (;;) {
AVPacketList *pktl = s->internal->raw_packet_buffer; AVPacketList *pktl = s->internal->raw_packet_buffer;
const AVPacket *pkt1;
if (pktl) { if (pktl) {
st = s->streams[pktl->pkt.stream_index]; st = s->streams[pktl->pkt.stream_index];
...@@ -922,9 +920,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -922,9 +920,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
av_packet_unref(pkt); av_packet_unref(pkt);
return err; return err;
} }
s->internal->raw_packet_buffer_remaining_size -= pkt->size; pkt1 = &s->internal->raw_packet_buffer_end->pkt;
s->internal->raw_packet_buffer_remaining_size -= pkt1->size;
if ((err = probe_codec(s, st, pkt)) < 0) if ((err = probe_codec(s, st, pkt1)) < 0)
return err; return err;
} }
} }
...@@ -3032,8 +3031,8 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr) ...@@ -3032,8 +3031,8 @@ static int has_codec_parameters(AVStream *st, const char **errmsg_ptr)
} }
/* returns 1 or 0 if or if not decoded data was returned, or a negative error */ /* returns 1 or 0 if or if not decoded data was returned, or a negative error */
static int try_decode_frame(AVFormatContext *s, AVStream *st, AVPacket *avpkt, static int try_decode_frame(AVFormatContext *s, AVStream *st,
AVDictionary **options) const AVPacket *avpkt, AVDictionary **options)
{ {
AVCodecContext *avctx = st->internal->avctx; AVCodecContext *avctx = st->internal->avctx;
const AVCodec *codec; const AVCodec *codec;
...@@ -3525,7 +3524,7 @@ fail: ...@@ -3525,7 +3524,7 @@ fail:
return ret; return ret;
} }
static int extract_extradata(AVStream *st, AVPacket *pkt) static int extract_extradata(AVStream *st, const AVPacket *pkt)
{ {
AVStreamInternal *sti = st->internal; AVStreamInternal *sti = st->internal;
AVPacket *pkt_ref; AVPacket *pkt_ref;
...@@ -3588,7 +3587,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ...@@ -3588,7 +3587,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
int64_t read_size; int64_t read_size;
AVStream *st; AVStream *st;
AVCodecContext *avctx; AVCodecContext *avctx;
AVPacket pkt1, *pkt; AVPacket pkt1;
int64_t old_offset = avio_tell(ic->pb); int64_t old_offset = avio_tell(ic->pb);
// new streams might appear, no options for those // new streams might appear, no options for those
int orig_nb_streams = ic->nb_streams; int orig_nb_streams = ic->nb_streams;
...@@ -3707,6 +3706,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -3707,6 +3706,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
read_size = 0; read_size = 0;
for (;;) { for (;;) {
const AVPacket *pkt;
int analyzed_all_streams; int analyzed_all_streams;
if (ff_check_interrupt(&ic->interrupt_callback)) { if (ff_check_interrupt(&ic->interrupt_callback)) {
ret = AVERROR_EXIT; ret = AVERROR_EXIT;
...@@ -3800,14 +3800,16 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -3800,14 +3800,16 @@ FF_ENABLE_DEPRECATION_WARNINGS
break; break;
} }
pkt = &pkt1;
if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) { if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) {
ret = ff_packet_list_put(&ic->internal->packet_buffer, ret = ff_packet_list_put(&ic->internal->packet_buffer,
&ic->internal->packet_buffer_end, &ic->internal->packet_buffer_end,
pkt, 0); &pkt1, 0);
if (ret < 0) if (ret < 0)
goto find_stream_info_err; goto find_stream_info_err;
pkt = &ic->internal->packet_buffer_end->pkt;
} else {
pkt = &pkt1;
} }
st = ic->streams[pkt->stream_index]; st = ic->streams[pkt->stream_index];
...@@ -3885,7 +3887,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -3885,7 +3887,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
limit, limit,
t, pkt->stream_index); t, pkt->stream_index);
if (ic->flags & AVFMT_FLAG_NOBUFFER) if (ic->flags & AVFMT_FLAG_NOBUFFER)
av_packet_unref(pkt); av_packet_unref(&pkt1);
break; break;
} }
if (pkt->duration) { if (pkt->duration) {
...@@ -3922,7 +3924,7 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -3922,7 +3924,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
(options && i < orig_nb_streams) ? &options[i] : NULL); (options && i < orig_nb_streams) ? &options[i] : NULL);
if (ic->flags & AVFMT_FLAG_NOBUFFER) if (ic->flags & AVFMT_FLAG_NOBUFFER)
av_packet_unref(pkt); av_packet_unref(&pkt1);
st->codec_info_nb_frames++; st->codec_info_nb_frames++;
count++; count++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment