X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=ff13f95dbd2197be7be681ff520b29ab1ef4422b;hb=996b0c06e23bcb6b300d7b8799df94993692e07d;hp=eb704f7332fe5ce90b515038ed0c177466d495fa;hpb=596441a4e8cf03a88113646ca6da2f90e721a38b;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index eb704f733..ff13f95db 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -30,10 +30,14 @@ #include "playlist.h" #include "job.h" #include "image.h" +#include "null_content.h" +#include "black_decoder.h" +#include "silence_decoder.h" using std::list; using std::cout; using std::min; +using std::max; using std::vector; using boost::shared_ptr; using boost::weak_ptr; @@ -56,11 +60,9 @@ Player::Player (shared_ptr f, shared_ptr p) , _video (true) , _audio (true) , _subtitles (true) - , _have_valid_decoders (false) + , _have_valid_pieces (false) , _position (0) - , _audio_buffers (MAX_AUDIO_CHANNELS, 0) - , _last_video (0) - , _last_was_black (false) + , _audio_buffers (f->dcp_audio_channels(), 0) , _next_audio (0) { _playlist->Changed.connect (bind (&Player::playlist_changed, this)); @@ -101,12 +103,18 @@ Player::pass () shared_ptr earliest; for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { - if ((*i)->content->end(_film) < _position) { + cout << "check " << (*i)->content->file() << " start=" << (*i)->content->start() << ", next=" << (*i)->decoder->next() << ", end=" << (*i)->content->end() << "\n"; + if (((*i)->decoder->next() + (*i)->content->start()) >= (*i)->content->end()) { + continue; + } + + if (!_audio && dynamic_pointer_cast ((*i)->content)) { continue; } Time const t = (*i)->content->start() + (*i)->decoder->next(); if (t < earliest_t) { + cout << "\t candidate; " << t << " " << (t / TIME_HZ) << ".\n"; earliest_t = t; earliest = *i; } @@ -115,48 +123,61 @@ Player::pass () if (!earliest) { return true; } - - earliest->decoder->pass (); - - /* Move position to earliest active next emission */ - - for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { - if ((*i)->content->end(_film) < _position) { - continue; - } - - Time const t = (*i)->content->start() + (*i)->decoder->next(); - if (t < _position) { - _position = t; - } + cout << "PASS:\n"; + cout << "\tpass " << earliest->content->file() << " "; + if (dynamic_pointer_cast (earliest->content)) { + cout << " FFmpeg.\n"; + } else if (dynamic_pointer_cast (earliest->content)) { + cout << " ImageMagickContent.\n"; + } else if (dynamic_pointer_cast (earliest->content)) { + cout << " SndfileContent.\n"; + } else if (dynamic_pointer_cast (earliest->decoder)) { + cout << " Black.\n"; + } else if (dynamic_pointer_cast (earliest->decoder)) { + cout << " Silence.\n"; } + + earliest->decoder->pass (); + _position = earliest->content->start() + earliest->decoder->next (); + cout << "\tpassed to " << _position << " " << (_position / TIME_HZ) << "\n"; return false; } void -Player::process_video (shared_ptr piece, shared_ptr image, bool same, shared_ptr sub, Time time) +Player::process_video (weak_ptr weak_content, shared_ptr image, bool same, shared_ptr sub, Time time) { - time += piece->start (); + cout << "[V]\n"; + + shared_ptr content = weak_content.lock (); + if (!content) { + return; + } + + time += content->start (); Video (image, same, sub, time); } void -Player::process_audio (shared_ptr piece, shared_ptr audio, Time time) +Player::process_audio (weak_ptr weak_content, shared_ptr audio, Time time) { - /* XXX: mapping */ - + shared_ptr content = weak_content.lock (); + if (!content) { + return; + } + /* The time of this audio may indicate that some of our buffered audio is not going to be added to any more, so it can be emitted. */ - time += piece->start (); + time += content->start (); if (time > _next_audio) { /* We can emit some audio from our buffers */ - OutputAudioFrame const N = min (_film->time_to_audio_frames (time - _next_audio), static_cast (_audio_buffers.frames())); + assert (_film->time_to_audio_frames (time - _next_audio) <= _audio_buffers.frames()); + OutputAudioFrame const N = _film->time_to_audio_frames (time - _next_audio); shared_ptr emit (new AudioBuffers (_audio_buffers.channels(), N)); emit->copy_from (&_audio_buffers, N, 0, 0); Audio (emit, _next_audio); @@ -170,12 +191,12 @@ Player::process_audio (shared_ptr piece, shared_ptr a } /* Now accumulate the new audio into our buffers */ - _audio_buffers.ensure_size (time - _next_audio + audio->frames()); - _audio_buffers.accumulate (audio.get(), 0, _film->time_to_audio_frames (time - _next_audio)); + _audio_buffers.ensure_size (_audio_buffers.frames() + audio->frames()); + _audio_buffers.accumulate_frames (audio.get(), 0, 0, audio->frames ()); } /** @return true on error */ -bool +void Player::seek (Time t) { if (!_have_valid_pieces) { @@ -184,44 +205,54 @@ Player::seek (Time t) } if (_pieces.empty ()) { - return true; + return; } - /* XXX: don't seek audio because we don't need to... */ + cout << "seek to " << t << " " << (t / TIME_HZ) << "\n"; - return false; + for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { + Time s = t - (*i)->content->start (); + s = max (static_cast