X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=d60dfb6a9b339508fd2bf1fb5fe1f9586674f036;hb=060a980527bc0b39e12494fec3c0baaab4c9d086;hp=7f500b3d6f358a1e786b4ee61f5ddf281a7e9e71;hpb=24d5048ae8787ff1802333c6ce91a79ed3c3a5ce;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index 7f500b3d6..d60dfb6a9 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -45,69 +45,20 @@ using std::map; using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; +using boost::optional; class Piece { public: - Piece (shared_ptr c) - : content (c) - , video_position (c->position ()) - , audio_position (c->position ()) - , repeat_to_do (0) - , repeat_done (0) - {} - - Piece (shared_ptr c, shared_ptr d) + Piece (shared_ptr c, shared_ptr d, FrameRateChange f) : content (c) , decoder (d) - , video_position (c->position ()) - , audio_position (c->position ()) + , frc (f) {} - /** Set this piece to repeat a video frame a given number of times */ - void set_repeat (IncomingVideo video, int num) - { - repeat_video = video; - repeat_to_do = num; - repeat_done = 0; - } - - void reset_repeat () - { - repeat_video.image.reset (); - repeat_to_do = 0; - repeat_done = 0; - } - - bool repeating () const - { - return repeat_done != repeat_to_do; - } - - void repeat (Player* player) - { - player->process_video ( - repeat_video.weak_piece, - repeat_video.image, - repeat_video.eyes, - repeat_done > 0, - repeat_video.frame, - (repeat_done + 1) * (TIME_HZ / player->_film->video_frame_rate ()) - ); - - ++repeat_done; - } - shared_ptr content; shared_ptr decoder; - /** Time of the last video we emitted relative to the start of the DCP */ - Time video_position; - /** Time of the last audio we emitted relative to the start of the DCP */ - Time audio_position; - - IncomingVideo repeat_video; - int repeat_to_do; - int repeat_done; + FrameRateChange frc; }; Player::Player (shared_ptr f, shared_ptr p) @@ -120,6 +71,7 @@ Player::Player (shared_ptr f, shared_ptr p) , _audio_position (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) + , _just_did_inaccurate_seek (false) { _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)); @@ -146,110 +98,97 @@ Player::pass () setup_pieces (); } - Time earliest_t = TIME_MAX; - shared_ptr earliest; - enum { - VIDEO, - AUDIO - } type = VIDEO; + /* Interrogate all our pieces to find the one with the earliest decoded data */ + + shared_ptr earliest_piece; + shared_ptr earliest_decoded; + DCPTime earliest_time = TIME_MAX; + DCPTime earliest_audio = TIME_MAX; for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { - if ((*i)->decoder->done ()) { - continue; - } - shared_ptr vd = dynamic_pointer_cast ((*i)->decoder); - shared_ptr ad = dynamic_pointer_cast ((*i)->decoder); + shared_ptr dec = (*i)->decoder->peek (); - if (_video && vd) { - if ((*i)->video_position < earliest_t) { - earliest_t = (*i)->video_position; - earliest = *i; - type = VIDEO; - } + if (dec) { + dec->set_dcp_times ((*i)->frc.speed_up, (*i)->content->position()); } - if (_audio && ad && ad->has_audio ()) { - if ((*i)->audio_position < earliest_t) { - earliest_t = (*i)->audio_position; - earliest = *i; - type = AUDIO; + /* XXX: don't know what to do with this */ +#if 0 + if (ad->done()) { + shared_ptr ac = dynamic_pointer_cast ((*i)->content); + assert (ac); + shared_ptr re = resampler (ac, false); + if (re) { + shared_ptr b = re->flush (); + if (b->frames ()) { + process_audio (earliest, b, ac->audio_length ()); + } } } - } +#endif - if (!earliest) { + if (dec && dec->dcp_time < earliest_time) { + earliest_piece = *i; + earliest_decoded = dec; + earliest_time = dec->dcp_time; + } + + if (dynamic_pointer_cast (dec) && dec->dcp_time < earliest_audio) { + earliest_audio = dec->dcp_time; + } + } + + if (!earliest_piece) { flush (); return true; } - switch (type) { - case VIDEO: - if (earliest_t > _video_position) { + if (earliest_audio != TIME_MAX) { + TimedAudioBuffers tb = _audio_merger.pull (earliest_audio); + Audio (tb.audio, tb.time); + _audio_position += _film->audio_frames_to_time (tb.audio->frames ()); + } + + /* Emit the earliest thing */ + + shared_ptr dv = dynamic_pointer_cast (earliest_decoded); + shared_ptr da = dynamic_pointer_cast (earliest_decoded); + shared_ptr ds = dynamic_pointer_cast (earliest_decoded); + + if (dv) { + if (!_just_did_inaccurate_seek && earliest_time > _video_position) { + /* XXX: if we're inside some content, repeat the last frame... otherwise emit black */ emit_black (); } else { - if (earliest->repeating ()) { - earliest->repeat (this); - } else { - earliest->decoder->pass (); - } + emit_video (earliest_piece, dv); + earliest_piece->decoder->get (); } - break; - - case AUDIO: - if (earliest_t > _audio_position) { - emit_silence (_film->time_to_audio_frames (earliest_t - _audio_position)); + } else if (da) { + if (!_just_did_inaccurate_seek && earliest_time > _audio_position) { + emit_silence (earliest_time - _audio_position); } else { - earliest->decoder->pass (); - - if (earliest->decoder->done()) { - shared_ptr ac = dynamic_pointer_cast (earliest->content); - assert (ac); - shared_ptr re = resampler (ac, false); - if (re) { - shared_ptr b = re->flush (); - if (b->frames ()) { - process_audio (earliest, b, ac->audio_length ()); - } - } - } + emit_audio (earliest_piece, da); + earliest_piece->decoder->get (); } - break; + } else if (ds) { + _in_subtitle.piece = earliest_piece; + _in_subtitle.subtitle = ds; + update_subtitle (); + earliest_piece->decoder->get (); } - if (_audio) { - boost::optional