X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=ff13f95dbd2197be7be681ff520b29ab1ef4422b;hb=996b0c06e23bcb6b300d7b8799df94993692e07d;hp=b0a408c1016a1cfd9bf5307a44975f2fa65e3b72;hpb=8c6fe8e1e8c8f6d5932606f2a5b6e1b87681ae38;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index b0a408c10..ff13f95db 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -37,6 +37,7 @@ using std::list; using std::cout; using std::min; +using std::max; using std::vector; using boost::shared_ptr; using boost::weak_ptr; @@ -61,9 +62,7 @@ Player::Player (shared_ptr f, shared_ptr p) , _subtitles (true) , _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)); @@ -104,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; } @@ -118,22 +123,24 @@ 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; } @@ -141,6 +148,8 @@ Player::pass () void Player::process_video (weak_ptr weak_content, shared_ptr image, bool same, shared_ptr sub, Time time) { + cout << "[V]\n"; + shared_ptr content = weak_content.lock (); if (!content) { return; @@ -159,8 +168,6 @@ Player::process_audio (weak_ptr weak_content, shared_ptr weak_content, shared_ptr _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); @@ -183,8 +191,8 @@ Player::process_audio (weak_ptr weak_content, shared_ptrframes()); - _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 */ @@ -200,6 +208,16 @@ Player::seek (Time t) return; } + cout << "seek to " << t << " " << (t / TIME_HZ) << "\n"; + + for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { + Time s = t - (*i)->content->start (); + s = max (static_cast