diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-05-22 00:20:29 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-05-22 00:20:29 +0100 |
| commit | 11c70b0e3051517e7bb96a7d6fa53053dab6e978 (patch) | |
| tree | 83a40cd91bb9ec4a276026d2ea936144c832d04b /src/lib | |
| parent | 62c15e24fcaa54a936b0e86cacce07616fea8c8e (diff) | |
Half-way through trying to make seek work again.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/decoder.cc | 6 | ||||
| -rw-r--r-- | src/lib/decoder.h | 2 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 37 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.h | 4 | ||||
| -rw-r--r-- | src/lib/player.cc | 27 | ||||
| -rw-r--r-- | src/lib/player.h | 1 | ||||
| -rw-r--r-- | src/lib/video_decoder.h | 4 |
7 files changed, 62 insertions, 19 deletions
diff --git a/src/lib/decoder.cc b/src/lib/decoder.cc index 082ad5076..2308bbd98 100644 --- a/src/lib/decoder.cc +++ b/src/lib/decoder.cc @@ -41,11 +41,9 @@ Decoder::Decoder (shared_ptr<const Film> f) _film_connection = f->Changed.connect (bind (&Decoder::film_changed, this, _1)); } -/** Seek to a position as a content timestamp in seconds. - * @return true on error. - */ +/** @return true on error */ bool -Decoder::seek (double) +Decoder::seek (Time) { throw DecodeError (N_("decoder does not support seek")); } diff --git a/src/lib/decoder.h b/src/lib/decoder.h index ae0d0c671..3876e6c1a 100644 --- a/src/lib/decoder.h +++ b/src/lib/decoder.h @@ -54,7 +54,7 @@ public: virtual ~Decoder () {} virtual bool pass () = 0; - virtual bool seek (double); + virtual bool seek (Time); virtual bool seek_back () { return true; } diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index fcb2e82ba..0ca9fc535 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -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"); } diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 7aadef105..1c3f252fd 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -78,7 +78,7 @@ public: return _audio_streams; } - bool seek (double); + bool seek (Time); bool seek_forward (); bool seek_back (); bool pass (); @@ -96,7 +96,7 @@ private: PixelFormat pixel_format () const; AVSampleFormat audio_sample_format () const; int bytes_per_audio_sample () const; - bool do_seek (double, bool, bool); + bool do_seek (Time, bool, bool); void setup_general (); void setup_video (); diff --git a/src/lib/player.cc b/src/lib/player.cc index 5d4635e5a..dd250d2e1 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -109,9 +109,11 @@ Player::pass () } if (earliest) { + cout << "pass on decoder...\n"; earliest->decoder->pass (); _position = earliest->last; } else if (next_wait < TIME_MAX) { + cout << "nw " << next_wait << " for " << _position << "\n"; _position += next_wait; } else { return true; @@ -126,8 +128,10 @@ Player::process_video (shared_ptr<DecoderRecord> dr, shared_ptr<const Image> ima shared_ptr<VideoDecoder> vd = dynamic_pointer_cast<VideoDecoder> (dr->decoder); Time const global_time = dr->content->time() + time; + cout << "need to fill in " << global_time << " vs " << _last_video << "\n"; while ((global_time - _last_video) > 1) { /* Fill in with black */ + cout << "(b)\n"; emit_black_frame (); } @@ -188,7 +192,28 @@ Player::seek (Time t) return true; } - /* XXX */ + cout << "seek to " << t << "\n"; + + Time current_time = 0; + shared_ptr<VideoDecoder> current; + for (list<shared_ptr<DecoderRecord> >::iterator i = _decoders.begin(); i != _decoders.end(); ++i) { + shared_ptr<VideoDecoder> v = dynamic_pointer_cast<VideoDecoder> ((*i)->decoder); + if (!v) { + continue; + } + + if ((*i)->content->time() < t && (*i)->content->time() >= current_time) { + current_time = (*i)->content->time(); + current = v; + } + } + + if (current) { + cout << "got a decoder to seek to " << (t - current_time) << ".\n"; + current->seek (t - current_time); + _position = t; + _last_video = t; + } /* XXX: don't seek audio because we don't need to... */ diff --git a/src/lib/player.h b/src/lib/player.h index 44b95e076..4b9635157 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -92,6 +92,7 @@ private: bool _have_valid_decoders; std::list<boost::shared_ptr<DecoderRecord> > _decoders; + /* XXX: position and last_video? Need both? */ Time _position; AudioBuffers _audio_buffers; Time _last_video; diff --git a/src/lib/video_decoder.h b/src/lib/video_decoder.h index 286a0d6e4..147dc60be 100644 --- a/src/lib/video_decoder.h +++ b/src/lib/video_decoder.h @@ -48,7 +48,7 @@ public: return _video_frame; } - double last_content_time () const { + Time last_content_time () const { return _last_content_time; } @@ -62,7 +62,7 @@ protected: private: boost::shared_ptr<const VideoContent> _video_content; int _video_frame; - double _last_content_time; + Time _last_content_time; boost::shared_ptr<TimedSubtitle> _timed_subtitle; }; |
