From 6e52f83418c64d5cbd0e613a5fc96ea32881d4d9 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 16 Jun 2013 15:52:32 +0100 Subject: [PATCH] Fix subtitle controls in the viewer. --- src/lib/ffmpeg_content.cc | 2 +- src/lib/ffmpeg_decoder.cc | 5 ++--- src/lib/ffmpeg_decoder.h | 3 +-- src/lib/player.cc | 15 +++++++-------- src/lib/player.h | 2 -- src/lib/transcoder.cc | 4 ---- src/lib/video_decoder.cc | 30 ++++++++++++++++-------------- src/wx/film_viewer.cc | 5 +---- 8 files changed, 28 insertions(+), 38 deletions(-) diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 7a67ee5b8..4a1534887 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -132,7 +132,7 @@ FFmpegContent::examine (shared_ptr job) shared_ptr film = _film.lock (); assert (film); - shared_ptr decoder (new FFmpegDecoder (film, shared_from_this (), true, false, false)); + shared_ptr decoder (new FFmpegDecoder (film, shared_from_this (), true, false)); ContentVideoFrame video_length = 0; video_length = decoder->video_length (); diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 2f890c0cd..7ebb31084 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -63,7 +63,7 @@ using libdcp::Size; boost::mutex FFmpegDecoder::_mutex; -FFmpegDecoder::FFmpegDecoder (shared_ptr f, shared_ptr c, bool video, bool audio, bool subtitles) +FFmpegDecoder::FFmpegDecoder (shared_ptr f, shared_ptr c, bool video, bool audio) : Decoder (f) , VideoDecoder (f, c) , AudioDecoder (f, c) @@ -79,7 +79,6 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr f, shared_ptraudio_stream() && _packet.stream_index == _ffmpeg_content->audio_stream()->id && _decode_audio) { decode_audio_packet (); - } else if (_ffmpeg_content->subtitle_stream() && _packet.stream_index == _ffmpeg_content->subtitle_stream()->id && _decode_subtitles) { + } else if (_ffmpeg_content->subtitle_stream() && _packet.stream_index == _ffmpeg_content->subtitle_stream()->id) { int got_subtitle; AVSubtitle sub; diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 2d295db7b..3cfb54e09 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -59,7 +59,7 @@ class Film; class FFmpegDecoder : public VideoDecoder, public AudioDecoder { public: - FFmpegDecoder (boost::shared_ptr, boost::shared_ptr, bool video, bool audio, bool subtitles); + FFmpegDecoder (boost::shared_ptr, boost::shared_ptr, bool video, bool audio); ~FFmpegDecoder (); /* Decoder */ @@ -139,7 +139,6 @@ private: bool _decode_video; bool _decode_audio; - bool _decode_subtitles; /* It would appear (though not completely verified) that one must have a mutex around calls to avcodec_open* and avcodec_close... and here diff --git a/src/lib/player.cc b/src/lib/player.cc index 1931ec0f5..6d7c3cfbd 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -58,7 +58,6 @@ Player::Player (shared_ptr f, shared_ptr p) , _playlist (p) , _video (true) , _audio (true) - , _subtitles (true) , _have_valid_pieces (false) , _position (0) , _audio_buffers (f->dcp_audio_channels(), 0) @@ -80,12 +79,6 @@ Player::disable_audio () _audio = false; } -void -Player::disable_subtitles () -{ - _subtitles = false; -} - bool Player::pass () { @@ -291,10 +284,13 @@ Player::setup_pieces () shared_ptr fc = dynamic_pointer_cast (*i); if (fc) { - shared_ptr fd (new FFmpegDecoder (_film, fc, _video, _audio, _subtitles)); + shared_ptr fd (new FFmpegDecoder (_film, fc, _video, _audio)); fd->Video.connect (bind (&Player::process_video, this, *i, _1, _2, _3)); fd->Audio.connect (bind (&Player::process_audio, this, *i, _1, _2)); + if (_video_container_size) { + fd->set_video_container_size (_video_container_size.get ()); + } decoder = fd; cout << "\tFFmpeg @ " << fc->start() << " -- " << fc->end() << "\n"; @@ -315,6 +311,9 @@ Player::setup_pieces () if (!id) { id.reset (new ImageMagickDecoder (_film, ic)); id->Video.connect (bind (&Player::process_video, this, *i, _1, _2, _3)); + if (_video_container_size) { + id->set_video_container_size (_video_container_size.get ()); + } } decoder = id; diff --git a/src/lib/player.h b/src/lib/player.h index 95f419b5e..60cf88422 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -49,7 +49,6 @@ public: void disable_video (); void disable_audio (); - void disable_subtitles (); bool pass (); void seek (Time); @@ -80,7 +79,6 @@ private: bool _video; bool _audio; - bool _subtitles; /** Our pieces are ready to go; if this is false the pieces must be (re-)created before they are used */ bool _have_valid_pieces; diff --git a/src/lib/transcoder.cc b/src/lib/transcoder.cc index d4c5210dc..847be2f1c 100644 --- a/src/lib/transcoder.cc +++ b/src/lib/transcoder.cc @@ -48,10 +48,6 @@ Transcoder::Transcoder (shared_ptr f, shared_ptr j) , _player (f->player ()) , _encoder (new Encoder (f, j)) { - if (!f->with_subtitles ()) { - _player->disable_subtitles (); - } - _player->connect_video (_encoder); _player->connect_audio (_encoder); } diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc index 58aceb407..54d14e2c6 100644 --- a/src/lib/video_decoder.cc +++ b/src/lib/video_decoder.cc @@ -61,20 +61,22 @@ VideoDecoder::video (shared_ptr image, bool same, Time t) shared_ptr out = image->scale_and_convert_to_rgb (image_size, film->scaler(), true); - shared_ptr sub; - if (_timed_subtitle && _timed_subtitle->displayed_at (t)) { - sub = _timed_subtitle->subtitle (); - } - - if (sub) { - dcpomatic::Rect const tx = subtitle_transformed_area ( - float (image_size.width) / video_size().width, - float (image_size.height) / video_size().height, - sub->area(), film->subtitle_offset(), film->subtitle_scale() - ); - - shared_ptr im = sub->image()->scale (tx.size(), film->scaler(), true); - out->alpha_blend (im, tx.position()); + if (film->with_subtitles ()) { + shared_ptr sub; + if (_timed_subtitle && _timed_subtitle->displayed_at (t)) { + sub = _timed_subtitle->subtitle (); + } + + if (sub) { + dcpomatic::Rect const tx = subtitle_transformed_area ( + float (image_size.width) / video_size().width, + float (image_size.height) / video_size().height, + sub->area(), film->subtitle_offset(), film->subtitle_scale() + ); + + shared_ptr im = sub->image()->scale (tx.size(), film->scaler(), true); + out->alpha_blend (im, tx.position()); + } } if (image_size != container_size) { diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index d2ec01de7..c7a44364f 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -129,6 +129,7 @@ FilmViewer::film_changed (Film::Property p) case Film::WITH_SUBTITLES: case Film::SUBTITLE_OFFSET: case Film::SUBTITLE_SCALE: + update_from_decoder (); raw_to_display (); _panel->Refresh (); _panel->Update (); @@ -161,10 +162,6 @@ FilmViewer::set_film (shared_ptr f) _player = f->player (); _player->disable_audio (); - /* Don't disable subtitles here as we may need them, and it's nice to be able to turn them - on and off without needing obtain a new Player. - */ - _player->Video.connect (bind (&FilmViewer::process_video, this, _1, _2, _3)); _film->Changed.connect (boost::bind (&FilmViewer::film_changed, this, _1)); -- 2.30.2