Half-way through trying to make seek work again.
[dcpomatic.git] / src / lib / ffmpeg_decoder.cc
index fcb2e82baabd84de4b0f6d53169a92831b920809..0ca9fc53585f31e090eb1f866116fc19313d317a 100644 (file)
@@ -224,7 +224,9 @@ FFmpegDecoder::setup_subtitle ()
 bool
 FFmpegDecoder::pass ()
 {
+       cout << "ffd pass.\n";
        int r = av_read_frame (_format_context, &_packet);
+       cout << "A " << r << "\n";
 
        if (r < 0) {
                if (r != AVERROR_EOF) {
@@ -255,7 +257,9 @@ FFmpegDecoder::pass ()
        avcodec_get_frame_defaults (_frame);
 
        if (_packet.stream_index == _video_stream && _decode_video) {
+               cout << "dvp\n";
                decode_video_packet ();
+               cout << "ok.\n";
        } else if (_ffmpeg_content->audio_stream() && _packet.stream_index == _ffmpeg_content->audio_stream()->id && _decode_audio) {
                decode_audio_packet ();
        } else if (_ffmpeg_content->subtitle_stream() && _packet.stream_index == _ffmpeg_content->subtitle_stream()->id && _decode_subtitles) {
@@ -279,7 +283,8 @@ FFmpegDecoder::pass ()
                        avsubtitle_free (&sub);
                }
        }
-       
+
+       cout << "out.\n";
        av_free_packet (&_packet);
        return false;
 }
@@ -472,9 +477,9 @@ FFmpegDecoder::bytes_per_audio_sample () const
 }
 
 bool
-FFmpegDecoder::seek (double p)
+FFmpegDecoder::seek (Time t)
 {
-       return do_seek (p, false, false);
+       return do_seek (t, false, false);
 }
 
 bool
@@ -484,7 +489,7 @@ FFmpegDecoder::seek_back ()
                return true;
        }
        
-       return do_seek (last_content_time() - 2.5 / video_frame_rate(), true, true);
+       return do_seek (last_content_time() - 2.5 * TIME_HZ / video_frame_rate(), true, true);
 }
 
 bool
@@ -494,13 +499,15 @@ FFmpegDecoder::seek_forward ()
                return true;
        }
        
-       return do_seek (last_content_time() - 0.5 / video_frame_rate(), true, true);
+       return do_seek (last_content_time() - 0.5 * TIME_HZ / video_frame_rate(), true, true);
 }
 
 bool
-FFmpegDecoder::do_seek (double p, bool backwards, bool accurate)
+FFmpegDecoder::do_seek (Time t, bool backwards, bool accurate)
 {
-       int64_t const vt = p / av_q2d (_format_context->streams[_video_stream]->time_base);
+       int64_t const vt = t / (av_q2d (_format_context->streams[_video_stream]->time_base) * TIME_HZ);
+
+       cout << "seek to " << vt << " (acc=" << accurate << ") (sec " << (vt * av_q2d (_format_context->streams[_video_stream]->time_base)) << "\n";
 
        int const r = av_seek_frame (_format_context, _video_stream, vt, backwards ? AVSEEK_FLAG_BACKWARD : 0);
 
@@ -532,7 +539,8 @@ FFmpegDecoder::do_seek (double p, bool backwards, bool accurate)
                        av_free_packet (&_packet);
                }
        }
-               
+
+       cout << "seek ok.\n";
        return r < 0;
 }
 
@@ -597,11 +605,15 @@ bool
 FFmpegDecoder::decode_video_packet ()
 {
        int frame_finished;
+       cout << "avc decode v2\n";
        if (avcodec_decode_video2 (_video_codec_context, _frame, &frame_finished, &_packet) < 0 || !frame_finished) {
                return false;
        }
+       cout << "done that.\n";
                
        boost::mutex::scoped_lock lm (_filter_graphs_mutex);
+
+       cout << "got lock.\n";
        
        shared_ptr<FilterGraph> graph;
        
@@ -609,6 +621,8 @@ FFmpegDecoder::decode_video_packet ()
        while (i != _filter_graphs.end() && !(*i)->can_process (libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format)) {
                ++i;
        }
+
+       cout << "found graph.\n";
        
        if (i == _filter_graphs.end ()) {
                graph.reset (new FilterGraph (_film, this, libdcp::Size (_frame->width, _frame->height), (AVPixelFormat) _frame->format));
@@ -617,8 +631,11 @@ FFmpegDecoder::decode_video_packet ()
        } else {
                graph = *i;
        }
-       
+
+
+       cout << "pushed in.\n";
        list<shared_ptr<Image> > images = graph->process (_frame);
+       cout << "got " << images.size() << "\n";
        
        for (list<shared_ptr<Image> >::iterator i = images.begin(); i != images.end(); ++i) {
                int64_t const bet = av_frame_get_best_effort_timestamp (_frame);
@@ -626,7 +643,9 @@ FFmpegDecoder::decode_video_packet ()
                        /* XXX: may need to insert extra frames / remove frames here ...
                           (as per old Matcher)
                        */
+                       cout << "emitting.\n";
                        emit_video (*i, false, bet * av_q2d (_format_context->streams[_video_stream]->time_base) * TIME_HZ);
+                       cout << "emitted.\n";
                } else {
                        _film->log()->log ("Dropping frame without PTS");
                }