X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=2793bd62a9e70583b5961f08506fa05f08e2d017;hb=1c09ae94a4b94395ce2c13020a71526a65b9ce7e;hp=b2db2b3ef9c7afdc5df73eefb87daebdbdfd33a7;hpb=d5c059a2ff9bab5c2973db6bc4860591679dd42b;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index b2db2b3ef..2793bd62a 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -99,7 +99,13 @@ int const PlayerProperty::PLAYBACK_LENGTH = 705; Player::Player (shared_ptr film, Image::Alignment subtitle_alignment) : _film (film) , _suspended (0) + , _ignore_video(false) + , _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) { @@ -111,7 +117,13 @@ Player::Player (shared_ptr film, shared_ptr playlist : _film (film) , _playlist (playlist_) , _suspended (0) + , _ignore_video(false) + , _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 (); @@ -136,14 +148,6 @@ Player::construct () } -void -Player::setup_pieces () -{ - boost::mutex::scoped_lock lm (_mutex); - setup_pieces_unlocked (); -} - - bool have_video (shared_ptr content) { @@ -154,20 +158,33 @@ have_video (shared_ptr content) bool have_audio (shared_ptr content) { - return static_cast(content->audio); + return static_cast(content->audio) && content->can_be_played(); } 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; _pieces.clear (); - _shuffler.reset (new Shuffler()); - _shuffler->Video.connect(bind(&Player::video, this, _1, _2)); + auto playlist_content = playlist()->content(); + bool const have_threed = std::any_of( + playlist_content.begin(), + playlist_content.end(), + [](shared_ptr c) { + return c->video && (c->video->frame_type() == VideoFrameType::THREE_D_LEFT || c->video->frame_type() == VideoFrameType::THREE_D_RIGHT); + }); + + + if (have_threed) { + _shuffler.reset(new Shuffler()); + _shuffler->Video.connect(bind(&Player::video, this, _1, _2)); + } for (auto i: playlist()->content()) { @@ -219,7 +236,7 @@ Player::setup_pieces_unlocked () _pieces.push_back (piece); if (decoder->video) { - if (i->video->frame_type() == VideoFrameType::THREE_D_LEFT || i->video->frame_type() == VideoFrameType::THREE_D_RIGHT) { + if (have_threed) { /* We need a Shuffler to cope with 3D L/R video data arriving out of sequence */ decoder->video->Data.connect (bind(&Shuffler::video, _shuffler.get(), weak_ptr(piece), _1)); } else { @@ -261,17 +278,17 @@ Player::setup_pieces_unlocked () } } + auto ignore_overlap = [](shared_ptr v) { + return v && v->use() && v->frame_type() != VideoFrameType::THREE_D_LEFT && v->frame_type() != VideoFrameType::THREE_D_RIGHT; + }; + for (auto i = _pieces.begin(); i != _pieces.end(); ++i) { - if (auto video = (*i)->content->video) { - if (video->use() && video->frame_type() != VideoFrameType::THREE_D_LEFT && video->frame_type() != VideoFrameType::THREE_D_RIGHT) { - /* Look for content later in the content list with in-use video that overlaps this */ - auto period = DCPTimePeriod((*i)->content->position(), (*i)->content->end(_film)); - auto j = i; - ++j; - for (; j != _pieces.end(); ++j) { - if ((*j)->content->video && (*j)->content->video->use()) { - (*i)->ignore_video = DCPTimePeriod((*j)->content->position(), (*j)->content->end(_film)).overlap(period); - } + if (ignore_overlap((*i)->content->video)) { + /* Look for content later in the content list with in-use video that overlaps this */ + auto const period = DCPTimePeriod((*i)->content->position(), (*i)->content->end(_film)); + for (auto j = std::next(i); j != _pieces.end(); ++j) { + if ((*j)->content->video && ignore_overlap((*j)->content->video)) { + (*i)->ignore_video = DCPTimePeriod((*j)->content->position(), (*j)->content->end(_film)).overlap(period); } } } @@ -322,17 +339,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 (_mutex); _black_image = make_shared(AV_PIX_FMT_RGB24, _video_container_size, Image::Alignment::PADDED); _black_image->make_black (); } @@ -466,18 +481,17 @@ Player::content_time_to_dcp (shared_ptr piece, ContentTime t) const } -vector +vector> Player::get_subtitle_fonts () { boost::mutex::scoped_lock lm (_mutex); - vector fonts; - for (auto i: _pieces) { - /* XXX: things may go wrong if there are duplicate font IDs - with different font files. - */ - auto f = i->decoder->fonts (); - copy (f.begin(), f.end(), back_inserter(fonts)); + vector> fonts; + for (auto piece: _pieces) { + for (auto text: piece->content->text) { + auto text_fonts = text->fonts(); + copy (text_fonts.begin(), text_fonts.end(), back_inserter(fonts)); + } } return fonts; @@ -488,27 +502,24 @@ Player::get_subtitle_fonts () void Player::set_ignore_video () { - boost::mutex::scoped_lock lm (_mutex); _ignore_video = true; - setup_pieces_unlocked (); + setup_pieces(); } void Player::set_ignore_audio () { - boost::mutex::scoped_lock lm (_mutex); _ignore_audio = true; - setup_pieces_unlocked (); + setup_pieces(); } void Player::set_ignore_text () { - boost::mutex::scoped_lock lm (_mutex); _ignore_text = true; - setup_pieces_unlocked (); + setup_pieces(); } @@ -516,7 +527,6 @@ Player::set_ignore_text () void Player::set_always_burn_open_subtitles () { - boost::mutex::scoped_lock lm (_mutex); _always_burn_open_subtitles = true; } @@ -525,18 +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 (); + setup_pieces(); } @@ -604,7 +612,7 @@ Player::get_reel_assets () 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 = max(DCPTime(), content->position() + DCPTime::from_frames(offset_from_start, frame_rate) - DCPTime::from_frames(trim_start, frame_rate)); + 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); } @@ -768,7 +776,7 @@ Player::pass () ); if (latest_last_push_end != _stream_states.end()) { - LOG_DEBUG_PLAYER("Leading stream is in %1 at %2", latest_last_push_end->second.piece->content->path(0), to_string(latest_last_push_end->second.last_push_end)); + LOG_DEBUG_PLAYER("Leading audio stream is in %1 at %2", latest_last_push_end->second.piece->content->path(0), to_string(latest_last_push_end->second.last_push_end)); } /* Now make a list of those streams that are less than ignore_streams_behind behind the leader */ @@ -810,7 +818,9 @@ Player::pass () } if (done) { - _shuffler->flush (); + if (_shuffler) { + _shuffler->flush (); + } for (auto const& i: _delay) { do_emit_video(i.first, i.second); } @@ -852,14 +862,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) ) ) ); @@ -867,7 +877,7 @@ Player::open_subtitles_for_frame (DCPTime time) const /* String subtitles (rendered to an image) */ if (!j.string.empty()) { - auto s = render_text (j.string, j.fonts, _video_container_size, time, vfr); + auto s = render_text(j.string, _video_container_size, time, vfr); copy (s.begin(), s.end(), back_inserter (captions)); } } @@ -1122,8 +1132,8 @@ Player::bitmap_text_start (weak_ptr weak_piece, weak_ptr weak_piece, weak_ptroutline_width())); - ps.add_fonts (content->fonts ()); + ps.string.push_back (s); } _active_texts[static_cast(content->type())].add_from(weak_content, ps, from); @@ -1399,25 +1408,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); @@ -1433,7 +1437,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);