Commit 54de179c authored by Hendrik Leppkes's avatar Hendrik Leppkes

Merge commit 'd584533c'

* commit 'd584533c':
  avformat: Rework add_to_pktbuf
Merged-by: 's avatarHendrik Leppkes <h.leppkes@gmail.com>
parents c0483038 d584533c
...@@ -361,12 +361,23 @@ static int init_input(AVFormatContext *s, const char *filename, ...@@ -361,12 +361,23 @@ static int init_input(AVFormatContext *s, const char *filename,
s, 0, s->format_probesize); s, 0, s->format_probesize);
} }
static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt, static int add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
AVPacketList **plast_pktl) AVPacketList **plast_pktl, int ref)
{ {
AVPacketList *pktl = av_mallocz(sizeof(AVPacketList)); AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
int ret;
if (!pktl) if (!pktl)
return NULL; return AVERROR(ENOMEM);
if (ref) {
if ((ret = av_packet_ref(&pktl->pkt, pkt)) < 0) {
av_free(pktl);
return ret;
}
} else {
pktl->pkt = *pkt;
}
if (*packet_buffer) if (*packet_buffer)
(*plast_pktl)->next = pktl; (*plast_pktl)->next = pktl;
...@@ -375,29 +386,27 @@ static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt, ...@@ -375,29 +386,27 @@ static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
/* Add the packet in the buffered packet list. */ /* Add the packet in the buffered packet list. */
*plast_pktl = pktl; *plast_pktl = pktl;
pktl->pkt = *pkt; return 0;
return &pktl->pkt;
} }
int avformat_queue_attached_pictures(AVFormatContext *s) int avformat_queue_attached_pictures(AVFormatContext *s)
{ {
int i; int i, ret;
for (i = 0; i < s->nb_streams; i++) for (i = 0; i < s->nb_streams; i++)
if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC && if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
s->streams[i]->discard < AVDISCARD_ALL) { s->streams[i]->discard < AVDISCARD_ALL) {
AVPacket copy = s->streams[i]->attached_pic; if (s->streams[i]->attached_pic.size <= 0) {
if (copy.size <= 0) {
av_log(s, AV_LOG_WARNING, av_log(s, AV_LOG_WARNING,
"Attached picture on stream %d has invalid size, " "Attached picture on stream %d has invalid size, "
"ignoring\n", i); "ignoring\n", i);
continue; continue;
} }
copy.buf = av_buffer_ref(copy.buf);
if (!copy.buf)
return AVERROR(ENOMEM);
add_to_pktbuf(&s->internal->raw_packet_buffer, &copy, ret = add_to_pktbuf(&s->internal->raw_packet_buffer,
&s->internal->raw_packet_buffer_end); &s->streams[i]->attached_pic,
&s->internal->raw_packet_buffer_end, 1);
if (ret < 0)
return ret;
} }
return 0; return 0;
} }
...@@ -729,8 +738,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -729,8 +738,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt)
if (!pktl && st->request_probe <= 0) if (!pktl && st->request_probe <= 0)
return ret; return ret;
add_to_pktbuf(&s->internal->raw_packet_buffer, pkt, err = add_to_pktbuf(&s->internal->raw_packet_buffer, pkt,
&s->internal->raw_packet_buffer_end); &s->internal->raw_packet_buffer_end, 0);
if (err)
return err;
s->internal->raw_packet_buffer_remaining_size -= pkt->size; s->internal->raw_packet_buffer_remaining_size -= pkt->size;
if ((err = probe_codec(s, st, pkt)) < 0) if ((err = probe_codec(s, st, pkt)) < 0)
...@@ -1274,16 +1285,10 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) ...@@ -1274,16 +1285,10 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index)
compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts); compute_pkt_fields(s, st, st->parser, &out_pkt, next_dts, next_pts);
if (out_pkt.data == pkt->data && out_pkt.size == pkt->size) { if ((ret = add_to_pktbuf(&s->internal->parse_queue, &out_pkt,
out_pkt.buf = pkt->buf; &s->internal->parse_queue_end,
pkt->buf = NULL; 1))) {
}
if ((ret = av_dup_packet(&out_pkt)) < 0)
goto fail;
if (!add_to_pktbuf(&s->internal->parse_queue, &out_pkt, &s->internal->parse_queue_end)) {
av_packet_unref(&out_pkt); av_packet_unref(&out_pkt);
ret = AVERROR(ENOMEM);
goto fail; goto fail;
} }
} }
...@@ -1553,9 +1558,10 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) ...@@ -1553,9 +1558,10 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt)
return ret; return ret;
} }
if (av_dup_packet(add_to_pktbuf(&s->internal->packet_buffer, pkt, ret = add_to_pktbuf(&s->internal->packet_buffer, pkt,
&s->internal->packet_buffer_end)) < 0) &s->internal->packet_buffer_end, 1);
return AVERROR(ENOMEM); if (ret < 0)
return ret;
} }
return_packet: return_packet:
...@@ -3270,17 +3276,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ...@@ -3270,17 +3276,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options)
break; break;
} }
if (ic->flags & AVFMT_FLAG_NOBUFFER) pkt = &pkt1;
free_packet_buffer(&ic->internal->packet_buffer,
&ic->internal->packet_buffer_end); if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) {
{ ret = add_to_pktbuf(&ic->internal->packet_buffer, pkt,
pkt = add_to_pktbuf(&ic->internal->packet_buffer, &pkt1, &ic->internal->packet_buffer_end, 0);
&ic->internal->packet_buffer_end); if (ret < 0)
if (!pkt) {
ret = AVERROR(ENOMEM);
goto find_stream_info_err;
}
if ((ret = av_dup_packet(pkt)) < 0)
goto find_stream_info_err; goto find_stream_info_err;
} }
......
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