History

avformat: Rework add_to_pktbuf

Make it return an error and check its return value when it is used. Simplify the usage by calling `av_packet_ref` internally when needed.

Luca Barbato committed 11 years ago

Commit d5845331 parent ce70f281 file · +38 −32Browse files

Unified · Split

libavformat/utils.c+38−32
@@ -209,12 +209,23 @@ static int init_input(AVFormatContext *s, const char *filename, · 208 unmodified lines
209 s, 0, s->probesize);209 s, 0, s->probesize);
210}210}
211 211
212static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,212static int add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
213 AVPacketList **plast_pktl)213 AVPacketList **plast_pktl, int ref)
214{214{
215 AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));215 AVPacketList *pktl = av_mallocz(sizeof(AVPacketList));
216 int ret;
217
216 if (!pktl)218 if (!pktl)
217 return NULL;219 return AVERROR(ENOMEM);
220
221 if (ref) {
222 if ((ret = av_packet_ref(&pktl->pkt, pkt)) < 0) {
223 av_free(pktl);
224 return ret;
225 }
226 } else {
227 pktl->pkt = *pkt;
228 }
218 229
219 if (*packet_buffer)230 if (*packet_buffer)
220 (*plast_pktl)->next = pktl;231 (*plast_pktl)->next = pktl;
@@ -223,23 +234,21 @@ static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt, · 2 unmodified lines
223 234
224 /* Add the packet in the buffered packet list. */235 /* Add the packet in the buffered packet list. */
225 *plast_pktl = pktl;236 *plast_pktl = pktl;
226 pktl->pkt = *pkt;237 return 0;
227 return &pktl->pkt;
228}238}
229 239
230static int queue_attached_pictures(AVFormatContext *s)240static int queue_attached_pictures(AVFormatContext *s)
231{241{
232 int i;242 int i, ret;
233 for (i = 0; i < s->nb_streams; i++)243 for (i = 0; i < s->nb_streams; i++)
234 if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&244 if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
235 s->streams[i]->discard < AVDISCARD_ALL) {245 s->streams[i]->discard < AVDISCARD_ALL) {
236 AVPacket copy = s->streams[i]->attached_pic;
237 copy.buf = av_buffer_ref(copy.buf);
238 if (!copy.buf)
239 return AVERROR(ENOMEM);
240 246
241 add_to_pktbuf(&s->internal->raw_packet_buffer, &copy,247 ret = add_to_pktbuf(&s->internal->raw_packet_buffer,
242 &s->internal->raw_packet_buffer_end);248 &s->streams[i]->attached_pic,
249 &s->internal->raw_packet_buffer_end, 1);
250 if (ret < 0)
251 return ret;
243 }252 }
244 return 0;253 return 0;
245}254}
@@ -451,8 +460,10 @@ int ff_read_packet(AVFormatContext *s, AVPacket *pkt) · 205 unmodified lines
451 !st->probe_packets))460 !st->probe_packets))
452 return ret;461 return ret;
453 462
454 add_to_pktbuf(&s->internal->raw_packet_buffer, pkt,463 err = add_to_pktbuf(&s->internal->raw_packet_buffer, pkt,
455 &s->internal->raw_packet_buffer_end);464 &s->internal->raw_packet_buffer_end, 0);
465 if (err)
466 return err;
456 s->internal->raw_packet_buffer_remaining_size -= pkt->size;467 s->internal->raw_packet_buffer_remaining_size -= pkt->size;
457 468
458 if ((err = probe_codec(s, st, pkt)) < 0)469 if ((err = probe_codec(s, st, pkt)) < 0)
@@ -837,16 +848,10 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, int stream_index) · 378 unmodified lines
837 0, 0, AVINDEX_KEYFRAME);848 0, 0, AVINDEX_KEYFRAME);
838 }849 }
839 850
840 if (out_pkt.data == pkt->data && out_pkt.size == pkt->size) {851 if ((ret = add_to_pktbuf(&s->internal->parse_queue, &out_pkt,
841 out_pkt.buf = pkt->buf;852 &s->internal->parse_queue_end,
842 pkt->buf = NULL;853 1))) {
843 }
844 if ((ret = av_dup_packet(&out_pkt)) < 0)
845 goto fail;
846
847 if (!add_to_pktbuf(&s->internal->parse_queue, &out_pkt, &s->internal->parse_queue_end)) {
848 av_packet_unref(&out_pkt);854 av_packet_unref(&out_pkt);
849 ret = AVERROR(ENOMEM);
850 goto fail;855 goto fail;
851 }856 }
852 }857 }
@@ -1022,9 +1027,10 @@ int av_read_frame(AVFormatContext *s, AVPacket *pkt) · 169 unmodified lines
1022 return ret;1027 return ret;
1023 }1028 }
1024 1029
1025 if (av_dup_packet(add_to_pktbuf(&s->internal->packet_buffer, pkt,1030 ret = add_to_pktbuf(&s->internal->packet_buffer, pkt,
1026 &s->internal->packet_buffer_end)) < 0)1031 &s->internal->packet_buffer_end, 1);
1027 return AVERROR(ENOMEM);1032 if (ret < 0)
1033 return ret;
1028 }1034 }
1029}1035}
1030 1036
@@ -2181,12 +2187,12 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) · 1150 unmodified lines
2181 break;2187 break;
2182 }2188 }
2183 2189
2184 if (ic->flags & AVFMT_FLAG_NOBUFFER) {2190 pkt = &pkt1;
2185 pkt = &pkt1;2191
2186 } else {2192 if (!(ic->flags & AVFMT_FLAG_NOBUFFER)) {
2187 pkt = add_to_pktbuf(&ic->internal->packet_buffer, &pkt1,2193 ret = add_to_pktbuf(&ic->internal->packet_buffer, pkt,
2188 &ic->internal->packet_buffer_end);2194 &ic->internal->packet_buffer_end, 0);
2189 if ((ret = av_dup_packet(pkt)) < 0)2195 if (ret < 0)
2190 goto find_stream_info_err;2196 goto find_stream_info_err;
2191 }2197 }
2192 2198

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t