X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=ecf37b57662b6b89c198a15f3035626ba3b5dce7;hb=1c996bf18ee3731e3533c82dae98e5abaa336a32;hp=5e0d3b315b01f96d6d7e92f947d1e0e025b2f3f6;hpb=daba5abc608788795de727121bcd1a83ef9caecb;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index 5e0d3b315..ecf37b576 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -46,6 +46,7 @@ #include "dcp_subtitle_decoder.h" #include "audio_processor.h" #include "playlist.h" +#include "referenced_reel_asset.h" #include #include #include @@ -57,7 +58,7 @@ #include "i18n.h" -#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL); +#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL); using std::list; using std::cout; @@ -73,6 +74,7 @@ using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; using boost::optional; +using boost::scoped_ptr; Player::Player (shared_ptr film, shared_ptr playlist) : _film (film) @@ -167,6 +169,11 @@ Player::setup_pieces () } } + /* It's questionable whether subtitle content should have a video frame rate; perhaps + it should be assumed that any subtitle content has been prepared at the same rate + as simultaneous video content (like we do with audio). + */ + /* SubRipContent */ shared_ptr rc = dynamic_pointer_cast (i); if (rc) { @@ -212,7 +219,10 @@ Player::playlist_content_changed (weak_ptr w, int property, bool freque property == ContentProperty::TRIM_END || property == ContentProperty::PATH || property == VideoContentProperty::VIDEO_FRAME_TYPE || - property == DCPContentProperty::CAN_BE_PLAYED + property == DCPContentProperty::CAN_BE_PLAYED || + property == SubRipContentProperty::SUBTITLE_COLOUR || + property == SubRipContentProperty::SUBTITLE_OUTLINE || + property == SubRipContentProperty::SUBTITLE_OUTLINE_COLOUR ) { _have_valid_pieces = false; @@ -242,7 +252,7 @@ Player::set_video_container_size (dcp::Size s) { _video_container_size = s; - _black_image.reset (new Image (PIX_FMT_RGB24, _video_container_size, true)); + _black_image.reset (new Image (AV_PIX_FMT_RGB24, _video_container_size, true)); _black_image->make_black (); } @@ -351,7 +361,7 @@ Player::get_video (DCPTime time, bool accurate) /* Find subtitles for possible burn-in */ - PlayerSubtitles ps = get_subtitles (time, DCPTime::from_frames (1, _film->video_frame_rate ()), false, true); + PlayerSubtitles ps = get_subtitles (time, DCPTime::from_frames (1, _film->video_frame_rate ()), false, true, accurate); list sub_images; @@ -374,7 +384,7 @@ Player::get_video (DCPTime time, bool accurate) list > ov = overlaps ( time, - time + DCPTime::from_frames (1, _film->video_frame_rate ()) - DCPTime::delta() + time + DCPTime::from_frames (1, _film->video_frame_rate ()) ); list > pvf; @@ -613,7 +623,7 @@ Player::content_subtitle_to_dcp (shared_ptr piece, ContentTime t) c * _always_burn_subtitles is true; in this case, all subtitles will be returned. */ PlayerSubtitles -Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt) +Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt, bool accurate) { list > subs = overlaps (time, time + length); @@ -635,7 +645,7 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt) /* XXX: this video_frame_rate() should be the rate that the subtitle content has been prepared for */ ContentTime const to = from + ContentTime::from_frames (1, _film->video_frame_rate ()); - list image = subtitle_decoder->get_image_subtitles (ContentTimePeriod (from, to), starting); + list image = subtitle_decoder->get_image_subtitles (ContentTimePeriod (from, to), starting, accurate); for (list::iterator i = image.begin(); i != image.end(); ++i) { /* Apply content's subtitle offsets */ @@ -653,7 +663,7 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt) ps.image.push_back (i->sub); } - list text = subtitle_decoder->get_text_subtitles (ContentTimePeriod (from, to), starting); + list text = subtitle_decoder->get_text_subtitles (ContentTimePeriod (from, to), starting, accurate); BOOST_FOREACH (ContentTextSubtitle& ts, text) { BOOST_FOREACH (dcp::SubtitleString s, ts.subs) { s.set_h_position (s.h_position() + subtitle_content->subtitle_x_offset ()); @@ -665,8 +675,8 @@ Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt) if (fabs (1.0 - xs / ys) > dcp::ASPECT_ADJUST_EPSILON) { s.set_aspect_adjust (xs / ys); } - s.set_in (dcp::Time(content_subtitle_to_dcp (*j, ts.period().from).seconds())); - s.set_out (dcp::Time(content_subtitle_to_dcp (*j, ts.period().to).seconds())); + s.set_in (dcp::Time(content_subtitle_to_dcp (*j, ts.period().from).seconds(), 1000)); + s.set_out (dcp::Time(content_subtitle_to_dcp (*j, ts.period().to).seconds(), 1000)); ps.text.push_back (s); ps.add_fonts (subtitle_content->fonts ()); } @@ -736,26 +746,57 @@ Player::set_play_referenced () _have_valid_pieces = false; } -list > +list Player::get_reel_assets () { - list > a; + list a; BOOST_FOREACH (shared_ptr i, _playlist->content ()) { shared_ptr j = dynamic_pointer_cast (i); if (!j) { continue; } - /* XXX: hack hack hack */ - DCPDecoder decoder (j, false); - if (j->reference_video ()) { - a.push_back (decoder.reels().front()->main_picture ()); - } - if (j->reference_audio ()) { - a.push_back (decoder.reels().front()->main_sound ()); + + scoped_ptr decoder; + try { + decoder.reset (new DCPDecoder (j, false)); + } catch (...) { + return a; } - if (j->reference_subtitle ()) { - a.push_back (decoder.reels().front()->main_subtitle ()); + + int64_t offset = 0; + BOOST_FOREACH (shared_ptr k, decoder->reels()) { + DCPTime const from = i->position() + DCPTime::from_frames (offset, _film->video_frame_rate()); + if (j->reference_video ()) { + a.push_back ( + ReferencedReelAsset ( + k->main_picture (), + DCPTimePeriod (from, from + DCPTime::from_frames (k->main_picture()->duration(), _film->video_frame_rate())) + ) + ); + } + + if (j->reference_audio ()) { + a.push_back ( + ReferencedReelAsset ( + k->main_sound (), + DCPTimePeriod (from, from + DCPTime::from_frames (k->main_sound()->duration(), _film->video_frame_rate())) + ) + ); + } + + if (j->reference_subtitle ()) { + DCPOMATIC_ASSERT (k->main_subtitle ()); + a.push_back ( + ReferencedReelAsset ( + k->main_subtitle (), + DCPTimePeriod (from, from + DCPTime::from_frames (k->main_subtitle()->duration(), _film->video_frame_rate())) + ) + ); + } + + /* Assume that main picture duration is the length of the reel */ + offset += k->main_picture()->duration (); } }