Don't get stuck in an infinite loop when avcodec_decode_audio4 returns an error.
authorCarl Hetherington <cth@carlh.net>
Tue, 18 Jun 2013 18:35:24 +0000 (19:35 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 18 Jun 2013 18:35:24 +0000 (19:35 +0100)
src/lib/ffmpeg_decoder.cc

index bcfbea4316df8999af3d7b31440aa2ffcaf48047..cad247e5a360d48fe5fd4897061764b972ad814a 100644 (file)
@@ -691,23 +691,26 @@ FFmpegDecoder::decode_audio_packet ()
 
                int frame_finished;
                int const decode_result = avcodec_decode_audio4 (_audio_codec_context, _frame, &frame_finished, &copy_packet);
-               if (decode_result >= 0) {
-                       if (frame_finished) {
+               if (decode_result < 0) {
+                       /* error */
+                       break;
+               }
+               
+               if (frame_finished) {
                        
-                               /* Where we are in the source, in seconds */
-                               double const source_pts_seconds = av_q2d (_format_context->streams[copy_packet.stream_index]->time_base)
-                                       * av_frame_get_best_effort_timestamp(_frame);
-                               
-                               int const data_size = av_samples_get_buffer_size (
-                                       0, _audio_codec_context->channels, _frame->nb_samples, audio_sample_format (), 1
-                                       );
-                               
-                               assert (_audio_codec_context->channels == _film->audio_channels());
-                               Audio (deinterleave_audio (_frame->data, data_size), source_pts_seconds);
-                       }
+                       /* Where we are in the source, in seconds */
+                       double const source_pts_seconds = av_q2d (_format_context->streams[copy_packet.stream_index]->time_base)
+                               * av_frame_get_best_effort_timestamp(_frame);
                        
-                       copy_packet.data += decode_result;
-                       copy_packet.size -= decode_result;
+                       int const data_size = av_samples_get_buffer_size (
+                               0, _audio_codec_context->channels, _frame->nb_samples, audio_sample_format (), 1
+                               );
+                       
+                       assert (_audio_codec_context->channels == _film->audio_channels());
+                       Audio (deinterleave_audio (_frame->data, data_size), source_pts_seconds);
                }
+               
+               copy_packet.data += decode_result;
+               copy_packet.size -= decode_result;
        }
 }