Some subtitle renaming.
[dcpomatic.git] / src / lib / player.cc
index 831d503f9e6824279a3f82aaadafe651b256823f..68b3365ea5845eb9ddfce38a4c5ba622da4d880a 100644 (file)
@@ -89,7 +89,9 @@ Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist
        , _playlist (playlist)
        , _have_valid_pieces (false)
        , _ignore_video (false)
+       , _ignore_audio (false)
        , _ignore_text (false)
+       , _always_burn_open_subtitles (false)
        , _fast (false)
        , _play_referenced (false)
        , _audio_merger (_film->audio_frame_rate())
@@ -125,6 +127,11 @@ Player::setup_pieces ()
                        continue;
                }
 
+               if (_ignore_video && _ignore_audio && i->text.empty()) {
+                       /* We're only interested in text and this content has none */
+                       continue;
+               }
+
                shared_ptr<Decoder> decoder = decoder_factory (i, _film->log(), _fast);
                FrameRateChange frc (i->active_video_frame_rate(), _film->video_frame_rate());
 
@@ -137,6 +144,10 @@ Player::setup_pieces ()
                        decoder->video->set_ignore (true);
                }
 
+               if (decoder->audio && _ignore_audio) {
+                       decoder->audio->set_ignore (true);
+               }
+
                if (_ignore_text) {
                        BOOST_FOREACH (shared_ptr<TextDecoder> i, decoder->text) {
                                i->set_ignore (true);
@@ -228,7 +239,11 @@ Player::playlist_content_changed (weak_ptr<Content> w, int property, bool freque
                property == FFmpegContentProperty::FILTERS
                ) {
 
-               _have_valid_pieces = false;
+               {
+                       boost::mutex::scoped_lock lm (_mutex);
+                       _have_valid_pieces = false;
+               }
+
                Changed (property, frequent);
 
        } else if (
@@ -257,14 +272,18 @@ Player::playlist_content_changed (weak_ptr<Content> w, int property, bool freque
 void
 Player::set_video_container_size (dcp::Size s)
 {
-       if (s == _video_container_size) {
-               return;
-       }
+       {
+               boost::mutex::scoped_lock lm (_mutex);
 
-       _video_container_size = s;
+               if (s == _video_container_size) {
+                       return;
+               }
 
-       _black_image.reset (new Image (AV_PIX_FMT_RGB24, _video_container_size, true));
-       _black_image->make_black ();
+               _video_container_size = s;
+
+               _black_image.reset (new Image (AV_PIX_FMT_RGB24, _video_container_size, true));
+               _black_image->make_black ();
+       }
 
        Changed (PlayerProperty::VIDEO_CONTAINER_SIZE, false);
 }
@@ -272,7 +291,11 @@ Player::set_video_container_size (dcp::Size s)
 void
 Player::playlist_changed ()
 {
-       _have_valid_pieces = false;
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+               _have_valid_pieces = false;
+       }
+
        Changed (PlayerProperty::PLAYLIST, false);
 }
 
@@ -290,13 +313,18 @@ Player::film_changed (Film::Property p)
                /* Pieces contain a FrameRateChange which contains the DCP frame rate,
                   so we need new pieces here.
                */
-               _have_valid_pieces = false;
+               {
+                       boost::mutex::scoped_lock lm (_mutex);
+                       _have_valid_pieces = false;
+               }
                Changed (PlayerProperty::FILM_VIDEO_FRAME_RATE, false);
        } else if (p == Film::AUDIO_PROCESSOR) {
                if (_film->audio_processor ()) {
+                       boost::mutex::scoped_lock lm (_mutex);
                        _audio_processor = _film->audio_processor()->clone (_film->audio_frame_rate ());
                }
        } else if (p == Film::AUDIO_CHANNELS) {
+               boost::mutex::scoped_lock lm (_mutex);
                _audio_merger.clear ();
        }
 }
@@ -413,6 +441,8 @@ Player::content_time_to_dcp (shared_ptr<const Piece> piece, ContentTime t) const
 list<shared_ptr<Font> >
 Player::get_subtitle_fonts ()
 {
+       /* Does not require a lock on _mutex as it's only called from DCPEncoder */
+
        if (!_have_valid_pieces) {
                setup_pieces ();
        }
@@ -435,12 +465,23 @@ Player::get_subtitle_fonts ()
 void
 Player::set_ignore_video ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _ignore_video = true;
+       _have_valid_pieces = false;
+}
+
+void
+Player::set_ignore_audio ()
+{
+       boost::mutex::scoped_lock lm (_mutex);
+       _ignore_audio = true;
+       _have_valid_pieces = false;
 }
 
 void
 Player::set_ignore_text ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _ignore_text = true;
 }
 
@@ -448,6 +489,7 @@ Player::set_ignore_text ()
 void
 Player::set_always_burn_open_subtitles ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _always_burn_open_subtitles = true;
 }
 
@@ -455,6 +497,7 @@ Player::set_always_burn_open_subtitles ()
 void
 Player::set_fast ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _fast = true;
        _have_valid_pieces = false;
 }
@@ -462,6 +505,7 @@ Player::set_fast ()
 void
 Player::set_play_referenced ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
        _play_referenced = true;
        _have_valid_pieces = false;
 }
@@ -469,6 +513,8 @@ Player::set_play_referenced ()
 list<ReferencedReelAsset>
 Player::get_reel_assets ()
 {
+       /* Does not require a lock on _mutex as it's only called from DCPEncoder */
+
        list<ReferencedReelAsset> a;
 
        BOOST_FOREACH (shared_ptr<Content> i, _playlist->content ()) {
@@ -545,6 +591,8 @@ Player::get_reel_assets ()
 bool
 Player::pass ()
 {
+       boost::mutex::scoped_lock lm (_mutex);
+
        if (!_have_valid_pieces) {
                setup_pieces ();
        }
@@ -679,6 +727,7 @@ Player::pass ()
 list<PlayerText>
 Player::closed_captions_for_frame (DCPTime time) const
 {
+       boost::mutex::scoped_lock _lm (_mutex);
        return _active_texts[TEXT_CLOSED_CAPTION].get (
                DCPTimePeriod(time, time + DCPTime::from_frames(1, _film->video_frame_rate()))
                );
@@ -696,13 +745,13 @@ Player::open_subtitles_for_frame (DCPTime time) const
                _active_texts[TEXT_OPEN_SUBTITLE].get_burnt(DCPTimePeriod(time, time + DCPTime::from_frames(1, vfr)), _always_burn_open_subtitles)
                ) {
 
-               /* Image subtitles */
-               list<PositionImage> c = transform_bitmap_texts (j.image);
+               /* Bitmap subtitles */
+               list<PositionImage> c = transform_bitmap_texts (j.bitmap);
                copy (c.begin(), c.end(), back_inserter (captions));
 
-               /* Text subtitles (rendered to an image) */
-               if (!j.text.empty ()) {
-                       list<PositionImage> s = render_text (j.text, j.fonts, _video_container_size, time, vfr);
+               /* String subtitles (rendered to an image) */
+               if (!j.string.empty ()) {
+                       list<PositionImage> s = render_text (j.string, j.fonts, _video_container_size, time, vfr);
                        copy (s.begin(), s.end(), back_inserter (captions));
                }
        }
@@ -891,7 +940,7 @@ Player::bitmap_text_start (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, C
        subtitle.sub.rectangle.height *= text->y_scale ();
 
        PlayerText ps;
-       ps.image.push_back (subtitle.sub);
+       ps.bitmap.push_back (subtitle.sub);
        DCPTime from (content_time_to_dcp (piece, subtitle.from()));
 
        _active_texts[subtitle.type()].add_from (wc, ps, from);
@@ -934,7 +983,7 @@ Player::plain_text_start (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, Co
                }
 
                s.set_in (dcp::Time(from.seconds(), 1000));
-               ps.text.push_back (StringText (s, text->outline_width()));
+               ps.string.push_back (StringText (s, text->outline_width()));
                ps.add_fonts (text->fonts ());
        }
 
@@ -962,7 +1011,7 @@ Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, Conte
 
        pair<PlayerText, DCPTime> from = _active_texts[type].add_to (wc, dcp_to);
 
-       bool const always = type == TEXT_OPEN_SUBTITLE && _always_burn_open_subtitles;
+       bool const always = (type == TEXT_OPEN_SUBTITLE && _always_burn_open_subtitles);
        if (text->use() && !always && !text->burn()) {
                Text (from.first, type, DCPTimePeriod (from.second, dcp_to));
        }
@@ -971,6 +1020,8 @@ Player::subtitle_stop (weak_ptr<Piece> wp, weak_ptr<const TextContent> wc, Conte
 void
 Player::seek (DCPTime time, bool accurate)
 {
+       boost::mutex::scoped_lock lm (_mutex);
+
        if (!_have_valid_pieces) {
                setup_pieces ();
        }
@@ -1119,18 +1170,25 @@ Player::discard_audio (shared_ptr<const AudioBuffers> audio, DCPTime time, DCPTi
 void
 Player::set_dcp_decode_reduction (optional<int> reduction)
 {
-       if (reduction == _dcp_decode_reduction) {
-               return;
+       {
+               boost::mutex::scoped_lock lm (_mutex);
+
+               if (reduction == _dcp_decode_reduction) {
+                       return;
+               }
+
+               _dcp_decode_reduction = reduction;
+               _have_valid_pieces = false;
        }
 
-       _dcp_decode_reduction = reduction;
-       _have_valid_pieces = false;
        Changed (PlayerProperty::DCP_DECODE_REDUCTION, false);
 }
 
 DCPTime
 Player::content_time_to_dcp (shared_ptr<Content> content, ContentTime t)
 {
+       boost::mutex::scoped_lock lm (_mutex);
+
        if (_have_valid_pieces) {
                setup_pieces ();
        }