X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=ae16290f57d7343297bde3e3a5ed9c307991f3be;hb=ad1ef39eda58b3a919ea3b7084401a0439409ec6;hp=15f274e988625d6a67eab1f5eb5cf9d78f3b8884;hpb=63a1ada934c258dfa60a92f7a406b084531856d9;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index 15f274e98..ae16290f5 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -60,8 +60,6 @@ #include "i18n.h" -#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL); - using std::list; using std::cout; using std::min; @@ -123,6 +121,18 @@ Player::setup_pieces () setup_pieces_unlocked (); } +bool +have_video (shared_ptr piece) +{ + return piece->decoder && piece->decoder->video; +} + +bool +have_audio (shared_ptr piece) +{ + return piece->decoder && piece->decoder->audio; +} + void Player::setup_pieces_unlocked () { @@ -143,8 +153,8 @@ Player::setup_pieces_unlocked () continue; } - shared_ptr decoder = decoder_factory (i, _film->log(), _fast); - FrameRateChange frc (i->active_video_frame_rate(), _film->video_frame_rate()); + shared_ptr decoder = decoder_factory (_film, i, _fast); + FrameRateChange frc (_film, i); if (!decoder) { /* Not something that we can decode; e.g. Atmos content */ @@ -215,8 +225,8 @@ Player::setup_pieces_unlocked () } } - _black = Empty (_film->content(), _film->length(), bind(&Content::video, _1)); - _silent = Empty (_film->content(), _film->length(), bind(&Content::audio, _1)); + _black = Empty (_film, _pieces, bind(&have_video, _1)); + _silent = Empty (_film, _pieces, bind(&have_audio, _1)); _last_video_time = DCPTime (); _last_video_eyes = EYES_BOTH; @@ -238,6 +248,7 @@ Player::playlist_content_change (ChangeType type, int property, bool frequent) /* A change in our content has gone through. Re-build our pieces. */ setup_pieces (); } else if (type == CHANGE_TYPE_CANCELLED) { + boost::mutex::scoped_lock lm (_mutex); _suspended = false; } @@ -330,7 +341,7 @@ Frame Player::dcp_to_content_video (shared_ptr piece, DCPTime t) const { DCPTime s = t - piece->content->position (); - s = min (piece->content->length_after_trim(), s); + s = min (piece->content->length_after_trim(_film), s); s = max (DCPTime(), s + DCPTime (piece->content->trim_start(), piece->frc)); /* It might seem more logical here to convert s to a ContentTime (using the FrameRateChange) @@ -355,7 +366,7 @@ Frame Player::dcp_to_resampled_audio (shared_ptr piece, DCPTime t) const { DCPTime s = t - piece->content->position (); - s = min (piece->content->length_after_trim(), s); + s = min (piece->content->length_after_trim(_film), s); /* See notes in dcp_to_content_video */ return max (DCPTime (), DCPTime (piece->content->trim_start (), piece->frc) + s).frames_floor (_film->audio_frame_rate ()); } @@ -373,7 +384,7 @@ ContentTime Player::dcp_to_content_time (shared_ptr piece, DCPTime t) const { DCPTime s = t - piece->content->position (); - s = min (piece->content->length_after_trim(), s); + s = min (piece->content->length_after_trim(_film), s); return max (ContentTime (), ContentTime (s, piece->frc) + piece->content->trim_start()); } @@ -467,7 +478,7 @@ Player::get_reel_assets () scoped_ptr decoder; try { - decoder.reset (new DCPDecoder (j, _film->log(), false)); + decoder.reset (new DCPDecoder (_film, j, false)); } catch (...) { return a; } @@ -541,7 +552,7 @@ Player::pass () return false; } - if (_playlist->length() == DCPTime()) { + if (_playlist->length(_film) == DCPTime()) { /* Special case of an empty Film; just give one black frame */ emit_video (black_player_video_frame(EYES_BOTH), DCPTime()); return true; @@ -558,7 +569,7 @@ Player::pass () } DCPTime const t = content_time_to_dcp (i, max(i->decoder->position(), i->content->trim_start())); - if (t > i->content->end()) { + if (t > i->content->end(_film)) { i->done = true; } else { @@ -722,7 +733,7 @@ Player::video (weak_ptr wp, ContentVideo video) return; } - FrameRateChange frc(piece->content->active_video_frame_rate(), _film->video_frame_rate()); + FrameRateChange frc (_film, piece->content); if (frc.skip && (video.frame % 2) == 1) { return; } @@ -741,7 +752,7 @@ Player::video (weak_ptr wp, ContentVideo video) /* Fill gaps that we discover now that we have some video which needs to be emitted. This is where we need to fill to. */ - DCPTime fill_to = min (time, piece->content->end()); + DCPTime fill_to = min (time, piece->content->end(_film)); if (_last_video_time) { DCPTime fill_from = max (*_last_video_time, piece->content->position()); @@ -751,7 +762,7 @@ Player::video (weak_ptr wp, ContentVideo video) if (fill_to_eyes == EYES_BOTH) { fill_to_eyes = EYES_LEFT; } - if (fill_to == piece->content->end()) { + if (fill_to == piece->content->end(_film)) { /* Don't fill after the end of the content */ fill_to_eyes = EYES_LEFT; } @@ -788,7 +799,7 @@ Player::video (weak_ptr wp, ContentVideo video) new PlayerVideo ( video.image, piece->content->video->crop (), - piece->content->video->fade (video.frame), + piece->content->video->fade (_film, video.frame), piece->content->video->scale().size ( piece->content->video, _video_container_size, _film->frame_size () ), @@ -803,7 +814,7 @@ Player::video (weak_ptr wp, ContentVideo video) DCPTime t = time; for (int i = 0; i < frc.repeat; ++i) { - if (t < piece->content->end()) { + if (t < piece->content->end(_film)) { emit_video (_last_video[wp], t); } t += one_video_frame (); @@ -826,7 +837,7 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a /* Compute time in the DCP */ DCPTime time = resampled_audio_to_dcp (piece, content_audio.frame); /* And the end of this block in the DCP */ - DCPTime end = time + DCPTime::from_frames(content_audio.audio->frames(), content->resampled_frame_rate()); + DCPTime end = time + DCPTime::from_frames(content_audio.audio->frames(), content->resampled_frame_rate(_film)); /* Remove anything that comes before the start or after the end of the content */ if (time < piece->content->position()) { @@ -837,11 +848,11 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a } content_audio.audio = cut.first; time = cut.second; - } else if (time > piece->content->end()) { + } else if (time > piece->content->end(_film)) { /* Discard it all */ return; - } else if (end > piece->content->end()) { - Frame const remaining_frames = DCPTime(piece->content->end() - time).frames_round(_film->audio_frame_rate()); + } else if (end > piece->content->end(_film)) { + Frame const remaining_frames = DCPTime(piece->content->end(_film) - time).frames_round(_film->audio_frame_rate()); if (remaining_frames == 0) { return; } @@ -920,7 +931,7 @@ Player::plain_text_start (weak_ptr wp, weak_ptr wc, Co PlayerText ps; DCPTime const from (content_time_to_dcp (piece, subtitle.from())); - if (from > piece->content->end()) { + if (from > piece->content->end(_film)) { return; } @@ -971,7 +982,7 @@ Player::subtitle_stop (weak_ptr wp, weak_ptr wc, Conte DCPTime const dcp_to = content_time_to_dcp (piece, to); - if (dcp_to > piece->content->end()) { + if (dcp_to > piece->content->end(_film)) { return; } @@ -1013,7 +1024,7 @@ Player::seek (DCPTime time, bool accurate) /* Before; seek to the start of the content */ i->decoder->seek (dcp_to_content_time (i, i->content->position()), accurate); i->done = false; - } else if (i->content->position() <= time && time < i->content->end()) { + } else if (i->content->position() <= time && time < i->content->end(_film)) { /* During; seek to position */ i->decoder->seek (dcp_to_content_time (i, time), accurate); i->done = false;