ref: 199dd44080fcdf260be46b56669670b04fbd3248
parent: 2076827f848f595b5506bc5927db1489e8e896be
author: rrt <rrt>
date: Mon Jun 8 09:21:40 EDT 2009
Fix some deprecated calls. In case of error during decoding, skip the rest of the packet, not just the frame. Despite the comment in ffplay.c about it skipping the frame, it actually loads a new packet when there’s an error.
--- a/src/ffmpeg.c
+++ b/src/ffmpeg.c
@@ -126,16 +126,17 @@
for (;;) {
/* NOTE: the audio packet can contain several frames */
while (ffmpeg->audio_pkt_size > 0) {
+ AVPacket avpkt;
+ av_init_packet(&avpkt);
+ avpkt.data = ffmpeg->audio_pkt_data;
+ avpkt.size = ffmpeg->audio_pkt_size;
data_size = buf_size;
- len1 = avcodec_decode_audio2(ffmpeg->audio_st->codec,
- (int16_t *)audio_buf, &data_size,
- ffmpeg->audio_pkt_data, ffmpeg->audio_pkt_size);
- if (len1 < 0) {
- /* if error, we skip the frame */
- ffmpeg->audio_pkt_size = 0;
- break;
- }
+ len1 = avcodec_decode_audio3(ffmpeg->audio_st->codec,
+ (int16_t *)audio_buf, &data_size, &avpkt);
+ if (len1 < 0) /* if error, we skip the rest of the packet */
+ return 0;
+
ffmpeg->audio_pkt_data += len1;
ffmpeg->audio_pkt_size -= len1;
if (data_size <= 0)
@@ -223,7 +224,8 @@
do {
/* If input buffer empty, read more data */
if (ffmpeg->audio_buf_index * 2 >= ffmpeg->audio_buf_size) {
- if ((ret = av_read_frame(ffmpeg->ctxt, pkt)) < 0)
+ if ((ret = av_read_frame(ffmpeg->ctxt, pkt)) < 0 &&
+ (ret == AVERROR_EOF || url_ferror(ffmpeg->ctxt->pb)))
break;
ffmpeg->audio_buf_size = audio_decode_frame(ffmpeg, ffmpeg->audio_buf, AVCODEC_MAX_AUDIO_FRAME_SIZE);
ffmpeg->audio_buf_index = 0;
@@ -346,7 +348,7 @@
}
/* allocate the output media context */
- ffmpeg->ctxt = av_alloc_format_context();
+ ffmpeg->ctxt = avformat_alloc_context();
if (!ffmpeg->ctxt) {
fprintf(stderr, "ffmpeg out of memory error");
return SOX_EOF;