X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=7e3a1bdcf15e072ce740236fe0c30755aae529d3;hb=111c05bebe5bc2b6f0031f66e429390ffe704556;hp=eb92bbab1a390ac6defc17f3c16654ad0b6fd292;hpb=c2febf6895f80b2d75cceb01bf0f9b0970c1b7d5;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index eb92bbab1..7e3a1bdcf 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -47,7 +47,6 @@ #include "playlist.h" #include "ratio.h" #include "raw_image_proxy.h" -#include "referenced_reel_asset.h" #include "render_text.h" #include "shuffler.h" #include "text_content.h" @@ -103,7 +102,9 @@ Player::Player (shared_ptr film, Image::Alignment subtitle_alignment , _ignore_audio(false) , _ignore_text(false) , _always_burn_open_subtitles(false) + , _fast(false) , _tolerant (film->tolerant()) + , _play_referenced(false) , _audio_merger (_film->audio_frame_rate()) , _subtitle_alignment (subtitle_alignment) { @@ -119,7 +120,9 @@ Player::Player (shared_ptr film, shared_ptr playlist , _ignore_audio(false) , _ignore_text(false) , _always_burn_open_subtitles(false) + , _fast(false) , _tolerant (film->tolerant()) + , _play_referenced(false) , _audio_merger (_film->audio_frame_rate()) { construct (); @@ -144,14 +147,6 @@ Player::construct () } -void -Player::setup_pieces () -{ - boost::mutex::scoped_lock lm (_mutex); - setup_pieces_unlocked (); -} - - bool have_video (shared_ptr content) { @@ -167,8 +162,10 @@ have_audio (shared_ptr content) void -Player::setup_pieces_unlocked () +Player::setup_pieces () { + boost::mutex::scoped_lock lm (_mutex); + _playback_length = _playlist ? _playlist->length(_film) : _film->length(); auto old_pieces = _pieces; @@ -310,10 +307,9 @@ Player::playlist_content_change (ChangeType type, int property, bool frequent) { if (property == VideoContentProperty::CROP) { if (type == ChangeType::DONE) { - auto const vcs = video_container_size(); boost::mutex::scoped_lock lm (_mutex); for (auto const& i: _delay) { - i.first->reset_metadata (_film, vcs); + i.first->reset_metadata(_film, _video_container_size); } } } else { @@ -341,17 +337,15 @@ Player::set_video_container_size (dcp::Size s) { Change (ChangeType::PENDING, PlayerProperty::VIDEO_CONTAINER_SIZE, false); - { - boost::mutex::scoped_lock lm (_mutex); - - if (s == _video_container_size) { - lm.unlock (); - Change (ChangeType::CANCELLED, PlayerProperty::VIDEO_CONTAINER_SIZE, false); - return; - } + if (s == _video_container_size) { + Change(ChangeType::CANCELLED, PlayerProperty::VIDEO_CONTAINER_SIZE, false); + return; + } - _video_container_size = s; + _video_container_size = s; + { + boost::mutex::scoped_lock lm(_black_image_mutex); _black_image = make_shared(AV_PIX_FMT_RGB24, _video_container_size, Image::Alignment::PADDED); _black_image->make_black (); } @@ -405,6 +399,8 @@ Player::film_change (ChangeType type, Film::Property p) shared_ptr Player::black_player_video_frame (Eyes eyes) const { + boost::mutex::scoped_lock lm(_black_image_mutex); + return std::make_shared ( std::make_shared(_black_image), Crop(), @@ -539,110 +535,16 @@ Player::set_always_burn_open_subtitles () void Player::set_fast () { - boost::mutex::scoped_lock lm (_mutex); _fast = true; - setup_pieces_unlocked (); + setup_pieces(); } void Player::set_play_referenced () { - boost::mutex::scoped_lock lm (_mutex); _play_referenced = true; - setup_pieces_unlocked (); -} - - -static void -maybe_add_asset (list& a, shared_ptr r, Frame reel_trim_start, Frame reel_trim_end, DCPTime from, int const ffr) -{ - DCPOMATIC_ASSERT (r); - r->set_entry_point (r->entry_point().get_value_or(0) + reel_trim_start); - r->set_duration (r->actual_duration() - reel_trim_start - reel_trim_end); - if (r->actual_duration() > 0) { - a.push_back ( - ReferencedReelAsset(r, DCPTimePeriod(from, from + DCPTime::from_frames(r->actual_duration(), ffr))) - ); - } -} - - -list -Player::get_reel_assets () -{ - /* Does not require a lock on _mutex as it's only called from DCPEncoder */ - - list reel_assets; - - for (auto content: playlist()->content()) { - auto dcp = dynamic_pointer_cast(content); - if (!dcp) { - continue; - } - - if (!dcp->reference_video() && !dcp->reference_audio() && !dcp->reference_text(TextType::OPEN_SUBTITLE) && !dcp->reference_text(TextType::CLOSED_CAPTION)) { - continue; - } - - scoped_ptr decoder; - try { - decoder.reset (new DCPDecoder(_film, dcp, false, false, shared_ptr())); - } catch (...) { - return reel_assets; - } - - auto const frame_rate = _film->video_frame_rate(); - DCPOMATIC_ASSERT (dcp->video_frame_rate()); - /* We should only be referencing if the DCP rate is the same as the film rate */ - DCPOMATIC_ASSERT (std::round(dcp->video_frame_rate().get()) == frame_rate); - - Frame const trim_start = dcp->trim_start().frames_round(frame_rate); - Frame const trim_end = dcp->trim_end().frames_round(frame_rate); - - /* position in the asset from the start */ - int64_t offset_from_start = 0; - /* position i the asset from the end */ - int64_t offset_from_end = 0; - for (auto reel: decoder->reels()) { - /* Assume that main picture duration is the length of the reel */ - offset_from_end += reel->main_picture()->actual_duration(); - } - - for (auto reel: decoder->reels()) { - - /* Assume that main picture duration is the length of the reel */ - int64_t const reel_duration = reel->main_picture()->actual_duration(); - - /* See doc/design/trim_reels.svg */ - Frame const reel_trim_start = min(reel_duration, max(int64_t(0), trim_start - offset_from_start)); - Frame const reel_trim_end = min(reel_duration, max(int64_t(0), reel_duration - (offset_from_end - trim_end))); - - auto const from = content->position() + std::max(DCPTime(), DCPTime::from_frames(offset_from_start - trim_start, frame_rate)); - if (dcp->reference_video()) { - maybe_add_asset (reel_assets, reel->main_picture(), reel_trim_start, reel_trim_end, from, frame_rate); - } - - if (dcp->reference_audio()) { - maybe_add_asset (reel_assets, reel->main_sound(), reel_trim_start, reel_trim_end, from, frame_rate); - } - - if (dcp->reference_text(TextType::OPEN_SUBTITLE)) { - maybe_add_asset (reel_assets, reel->main_subtitle(), reel_trim_start, reel_trim_end, from, frame_rate); - } - - if (dcp->reference_text(TextType::CLOSED_CAPTION)) { - for (auto caption: reel->closed_captions()) { - maybe_add_asset (reel_assets, caption, reel_trim_start, reel_trim_end, from, frame_rate); - } - } - - offset_from_start += reel_duration; - offset_from_end -= reel_duration; - } - } - - return reel_assets; + setup_pieces(); } @@ -657,7 +559,7 @@ Player::pass () return false; } - if (_playback_length == DCPTime()) { + if (_playback_length.load() == DCPTime()) { /* Special; just give one black frame */ emit_video (black_player_video_frame(Eyes::BOTH), DCPTime()); return true; @@ -795,7 +697,7 @@ Player::pass () } } - auto pull_to = _playback_length; + auto pull_to = _playback_length.load(); for (auto const& i: alive_stream_states) { if (!i.second.piece->done && i.second.last_push_end < pull_to) { pull_to = i.second.last_push_end; @@ -858,7 +760,7 @@ Player::open_subtitles_for_frame (DCPTime time) const for ( auto j: - _active_texts[static_cast(TextType::OPEN_SUBTITLE)].get_burnt(DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_open_subtitles) + _active_texts[TextType::OPEN_SUBTITLE].get_burnt(DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_open_subtitles) ) { /* Bitmap subtitles */ @@ -868,14 +770,14 @@ Player::open_subtitles_for_frame (DCPTime time) const } /* i.image will already have been scaled to fit _video_container_size */ - dcp::Size scaled_size (i.rectangle.width * _video_container_size.width, i.rectangle.height * _video_container_size.height); + dcp::Size scaled_size (i.rectangle.width * _video_container_size.load().width, i.rectangle.height * _video_container_size.load().height); captions.push_back ( PositionImage ( i.image, Position ( - lrint(_video_container_size.width * i.rectangle.x), - lrint(_video_container_size.height * i.rectangle.y) + lrint(_video_container_size.load().width * i.rectangle.x), + lrint(_video_container_size.load().height * i.rectangle.y) ) ) ); @@ -1138,8 +1040,8 @@ Player::bitmap_text_start (weak_ptr weak_piece, weak_ptr weak_piece, weak_ptr(content->type())].add_from(weak_content, ps, from); + _active_texts[content->type()].add_from(weak_content, ps, from); } @@ -1197,7 +1099,7 @@ Player::plain_text_start (weak_ptr weak_piece, weak_ptr(content->type())].add_from(weak_content, ps, from); + _active_texts[content->type()].add_from(weak_content, ps, from); } @@ -1213,7 +1115,7 @@ Player::subtitle_stop (weak_ptr weak_piece, weak_ptr w return; } - if (!_active_texts[static_cast(content->type())].have(weak_content)) { + if (!_active_texts[content->type()].have(weak_content)) { return; } @@ -1228,7 +1130,7 @@ Player::subtitle_stop (weak_ptr weak_piece, weak_ptr w return; } - auto from = _active_texts[static_cast(content->type())].add_to(weak_content, dcp_to); + auto from = _active_texts[content->type()].add_to(weak_content, dcp_to); bool const always = (content->type() == TextType::OPEN_SUBTITLE && _always_burn_open_subtitles); if (content->use() && !always && !content->burn()) { @@ -1259,9 +1161,7 @@ Player::seek (DCPTime time, bool accurate) } _audio_merger.clear (); - for (int i = 0; i < static_cast(TextType::COUNT); ++i) { - _active_texts[i].clear (); - } + std::for_each(_active_texts.begin(), _active_texts.end(), [](ActiveText& a) { a.clear(); }); for (auto i: _pieces) { if (time < i->content->position()) { @@ -1336,9 +1236,7 @@ void Player::do_emit_video (shared_ptr pv, DCPTime time) { if (pv->eyes() == Eyes::BOTH || pv->eyes() == Eyes::RIGHT) { - for (int i = 0; i < static_cast(TextType::COUNT); ++i) { - _active_texts[i].clear_before (time); - } + std::for_each(_active_texts.begin(), _active_texts.end(), [time](ActiveText& a) { a.clear_before(time); }); } auto subtitles = open_subtitles_for_frame (time); @@ -1414,25 +1312,20 @@ Player::set_dcp_decode_reduction (optional reduction) { Change (ChangeType::PENDING, PlayerProperty::DCP_DECODE_REDUCTION, false); - { - boost::mutex::scoped_lock lm (_mutex); - - if (reduction == _dcp_decode_reduction) { - lm.unlock (); - Change (ChangeType::CANCELLED, PlayerProperty::DCP_DECODE_REDUCTION, false); - return; - } - - _dcp_decode_reduction = reduction; - setup_pieces_unlocked (); + if (reduction == _dcp_decode_reduction.load()) { + Change(ChangeType::CANCELLED, PlayerProperty::DCP_DECODE_REDUCTION, false); + return; } + _dcp_decode_reduction = reduction; + setup_pieces(); + Change (ChangeType::DONE, PlayerProperty::DCP_DECODE_REDUCTION, false); } optional -Player::content_time_to_dcp (shared_ptr content, ContentTime t) +Player::content_time_to_dcp (shared_ptr content, ContentTime t) const { boost::mutex::scoped_lock lm (_mutex); @@ -1448,7 +1341,7 @@ Player::content_time_to_dcp (shared_ptr content, ContentTime t) optional -Player::dcp_to_content_time (shared_ptr content, DCPTime t) +Player::dcp_to_content_time (shared_ptr content, DCPTime t) const { boost::mutex::scoped_lock lm (_mutex);