X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=d13ae5f3cb8588fbb6b96dab72ed9f54c22745d4;hb=a1b0ed4ac0753b420ce8ab8467165e220bdb4b05;hp=37f172f1da72ea922f7a69dc018e9151bbdd3dc1;hpb=0c01a21ffc4cf9eea71a662916cc3095f2634216;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index 37f172f1d..d13ae5f3c 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -24,6 +24,8 @@ #include "ffmpeg_content.h" #include "still_image_decoder.h" #include "still_image_content.h" +#include "moving_image_decoder.h" +#include "moving_image_content.h" #include "sndfile_decoder.h" #include "sndfile_content.h" #include "subtitle_content.h" @@ -53,15 +55,15 @@ class Piece public: Piece (shared_ptr c) : content (c) - , video_position (c->start ()) - , audio_position (c->start ()) + , video_position (c->position ()) + , audio_position (c->position ()) {} Piece (shared_ptr c, shared_ptr d) : content (c) , decoder (d) - , video_position (c->start ()) - , audio_position (c->start ()) + , video_position (c->position ()) + , audio_position (c->position ()) {} shared_ptr content; @@ -81,7 +83,7 @@ std::ostream& operator<<(std::ostream& s, Piece const & p) s << "\tsndfile "; } - s << " at " << p.content->start() << " until " << p.content->end(); + s << " at " << p.content->position() << " until " << p.content->end(); return s; } @@ -95,12 +97,13 @@ Player::Player (shared_ptr f, shared_ptr p) , _have_valid_pieces (false) , _video_position (0) , _audio_position (0) - , _audio_buffers (f->audio_channels(), 0) + , _audio_merger (f->audio_channels(), bind (&Film::time_to_audio_frames, f.get(), _1), bind (&Film::audio_frames_to_time, f.get(), _1)) + , _last_emit_was_black (false) { - _playlist->Changed.connect (bind (&Player::playlist_changed, this)); - _playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2, _3)); - _film->Changed.connect (bind (&Player::film_changed, this, _1)); - set_video_container_size (_film->container()->size (_film->full_frame ())); + _playlist_changed_connection = _playlist->Changed.connect (bind (&Player::playlist_changed, this)); + _playlist_content_changed_connection = _playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2, _3)); + _film_changed_connection = _film->Changed.connect (bind (&Player::film_changed, this, _1)); + set_video_container_size (fit_ratio_within (_film->container()->ratio (), _film->full_frame ())); } void @@ -174,7 +177,7 @@ Player::pass () emit_black (); } else { #ifdef DEBUG_PLAYER - cout << "Pass " << *earliest << "\n"; + cout << "Pass video " << *earliest << "\n"; #endif earliest->decoder->pass (); } @@ -183,15 +186,15 @@ Player::pass () case AUDIO: if (earliest_t > _audio_position) { #ifdef DEBUG_PLAYER - cout << "no audio here; emitting silence.\n"; + cout << "no audio here (none until " << earliest_t << "); emitting silence.\n"; #endif emit_silence (_film->time_to_audio_frames (earliest_t - _audio_position)); } else { #ifdef DEBUG_PLAYER - cout << "Pass " << *earliest << "\n"; -#endif + cout << "Pass audio " << *earliest << "\n"; +#endif earliest->decoder->pass (); - + if (earliest->decoder->done()) { shared_ptr ac = dynamic_pointer_cast (earliest->content); assert (ac); @@ -207,8 +210,21 @@ Player::pass () break; } + if (_audio) { + Time audio_done_up_to = TIME_MAX; + for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { + if (dynamic_pointer_cast ((*i)->decoder)) { + audio_done_up_to = min (audio_done_up_to, (*i)->audio_position); + } + } + + TimedAudioBuffers