Merge master.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index 0dae2a4edc41be11d70855d94e93b9594dc27c39..42be8227e95e57ebd0481e5b500566b1fd6cafb4 100644 (file)
@@ -70,8 +70,6 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<const FFmpegContent> c, shared_ptr<Log>
        , SubtitleDecoder (c)
        , FFmpeg (c)
        , _log (log)
-       , _subtitle_codec_context (0)
-       , _subtitle_codec (0)
 {
        /* Audio and video frame PTS values may not start with 0.  We want
           to fiddle them so that:
@@ -106,15 +104,6 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<const FFmpegContent> c, shared_ptr<Log>
        }
 }
 
-FFmpegDecoder::~FFmpegDecoder ()
-{
-       boost::mutex::scoped_lock lm (_mutex);
-
-       if (_subtitle_codec_context) {
-               avcodec_close (_subtitle_codec_context);
-       }
-}
-
 void
 FFmpegDecoder::flush ()
 {
@@ -317,7 +306,7 @@ FFmpegDecoder::minimal_run (boost::function<bool (optional<ContentTime>, optiona
 
                if (_packet.stream_index == _video_stream) {
 
-                       avcodec_get_frame_defaults (_frame);
+                       av_frame_unref (_frame);
                        
                        int got_picture = 0;
                        r = avcodec_decode_video2 (video_codec_context(), _frame, &got_picture, &_packet);
@@ -382,8 +371,8 @@ FFmpegDecoder::seek_and_flush (ContentTime t)
        if (audio_codec_context ()) {
                avcodec_flush_buffers (audio_codec_context ());
        }
-       if (_subtitle_codec_context) {
-               avcodec_flush_buffers (_subtitle_codec_context);
+       if (subtitle_codec_context ()) {
+               avcodec_flush_buffers (subtitle_codec_context ());
        }
 }
 
@@ -508,7 +497,7 @@ FFmpegDecoder::decode_subtitle_packet ()
 {
        int got_subtitle;
        AVSubtitle sub;
-       if (avcodec_decode_subtitle2 (_subtitle_codec_context, &sub, &got_subtitle, &_packet) < 0 || !got_subtitle) {
+       if (avcodec_decode_subtitle2 (subtitle_codec_context(), &sub, &got_subtitle, &_packet) < 0 || !got_subtitle) {
                return;
        }
 
@@ -575,3 +564,9 @@ FFmpegDecoder::decode_subtitle_packet ()
        
        avsubtitle_free (&sub);
 }
+
+bool
+FFmpegDecoder::has_subtitle_during (ContentTimePeriod p) const
+{
+       return _ffmpeg_content->has_subtitle_during (p);
+}