Hopefully much cleaner handling of PTS changes under resample.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index d8319723a3538f03cdb6bb94fe3ec41cb1082287..58745598a9fae69969409e40d3777424ef18edf1 100644 (file)
@@ -60,7 +60,7 @@ using libdcp::Size;
 FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegContent> c, bool video, bool audio)
        : Decoder (f)
        , VideoDecoder (f, c)
-       , AudioDecoder (f, c)
+       , AudioDecoder (f)
        , SubtitleDecoder (f)
        , FFmpeg (c)
        , _subtitle_codec_context (0)
@@ -120,7 +120,30 @@ FFmpegDecoder::~FFmpegDecoder ()
        if (_subtitle_codec_context) {
                avcodec_close (_subtitle_codec_context);
        }
-}      
+}
+
+void
+FFmpegDecoder::flush ()
+{
+       /* Get any remaining frames */
+       
+       _packet.data = 0;
+       _packet.size = 0;
+       
+       /* XXX: should we reset _packet.data and size after each *_decode_* call? */
+       
+       if (_decode_video) {
+               while (decode_video_packet ()) {}
+       }
+       
+       if (_ffmpeg_content->audio_stream() && _decode_audio) {
+               decode_audio_packet ();
+       }
+
+       /* Stop us being asked for any more data */
+       _video_position = _ffmpeg_content->video_length ();
+       _audio_position = _ffmpeg_content->audio_length ();
+}
 
 void
 FFmpegDecoder::pass ()
@@ -137,24 +160,7 @@ FFmpegDecoder::pass ()
                        film->log()->log (String::compose (N_("error on av_read_frame (%1) (%2)"), buf, r));
                }
 
-               /* Get any remaining frames */
-               
-               _packet.data = 0;
-               _packet.size = 0;
-               
-               /* XXX: should we reset _packet.data and size after each *_decode_* call? */
-               
-               if (_decode_video) {
-                       while (decode_video_packet ()) {}
-               }
-
-               if (_ffmpeg_content->audio_stream() && _decode_audio) {
-                       decode_audio_packet ();
-               }
-
-               /* Stop us being asked for any more data */
-               _video_position = _ffmpeg_content->video_length ();
-               _audio_position = _ffmpeg_content->audio_length ();
+               flush ();
                return;
        }