Merge master.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index ce6fb1984e60d5a8568cc80efcf05bbb61ba0b03..15443c346b3d302cce263165588044e641879160 100644 (file)
@@ -23,7 +23,6 @@
 
 #include <stdexcept>
 #include <vector>
-#include <sstream>
 #include <iomanip>
 #include <iostream>
 #include <stdint.h>
@@ -43,8 +42,9 @@ extern "C" {
 #include "filter_graph.h"
 #include "audio_buffers.h"
 #include "ffmpeg_content.h"
-#include "image_proxy.h"
+#include "raw_image_proxy.h"
 #include "film.h"
+#include "timer.h"
 
 #include "i18n.h"
 
@@ -55,10 +55,10 @@ extern "C" {
 using std::cout;
 using std::string;
 using std::vector;
-using std::stringstream;
 using std::list;
 using std::min;
 using std::pair;
+using std::make_pair;
 using boost::shared_ptr;
 using boost::optional;
 using boost::dynamic_pointer_cast;
@@ -140,7 +140,7 @@ FFmpegDecoder::pass ()
        }
 
        int const si = _packet.stream_index;
-       
+
        if (si == _video_stream) {
                decode_video_packet ();
        } else if (_ffmpeg_content->audio_stream() && _ffmpeg_content->audio_stream()->uses_index (_format_context, si)) {
@@ -293,11 +293,12 @@ FFmpegDecoder::seek (ContentTime time, bool accurate)
        */
 
        ContentTime pre_roll = accurate ? ContentTime::from_seconds (2) : ContentTime (0);
-       time - pre_roll;
-       if (time < ContentTime (0)) {
-               time = ContentTime (0);
-       }
+       time -= pre_roll;
 
+       /* XXX: it seems debatable whether PTS should be used here...
+          http://www.mjbshaw.com/2012/04/seeking-in-ffmpeg-know-your-timestamp.html
+       */
+       
        ContentTime const u = time - _pts_offset;
        int64_t s = u.seconds() / av_q2d (_format_context->streams[_video_stream]->time_base);
 
@@ -307,12 +308,6 @@ FFmpegDecoder::seek (ContentTime time, bool accurate)
                        );
        }
 
-       /* Ridiculous empirical hack */
-       s--;
-       if (s < 0) {
-               s = 0;
-       }
-
        av_seek_frame (_format_context, _video_stream, s, 0);
 
        avcodec_flush_buffers (video_codec_context());
@@ -479,8 +474,8 @@ FFmpegDecoder::decode_subtitle_packet ()
        avsubtitle_free (&sub);
 }
 
-bool
-FFmpegDecoder::has_subtitle_during (ContentTimePeriod p) const
+list<ContentTimePeriod>
+FFmpegDecoder::subtitles_during (ContentTimePeriod p, bool starting) const
 {
-       return _ffmpeg_content->has_subtitle_during (p);
+       return _ffmpeg_content->subtitles_during (p, starting);
 }