Fix subtitle controls in the viewer.
authorCarl Hetherington <cth@carlh.net>
Sun, 16 Jun 2013 14:52:32 +0000 (15:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 16 Jun 2013 14:52:32 +0000 (15:52 +0100)
src/lib/ffmpeg_content.cc
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/lib/player.cc
src/lib/player.h
src/lib/transcoder.cc
src/lib/video_decoder.cc
src/wx/film_viewer.cc

index 7a67ee5b8b5475cbb7e19b10baf02a37586b0393..4a1534887d2170ad1fe1bf7ef57c106ddbaacf98 100644 (file)
@@ -132,7 +132,7 @@ FFmpegContent::examine (shared_ptr<Job> job)
        shared_ptr<const Film> film = _film.lock ();
        assert (film);
 
-       shared_ptr<FFmpegDecoder> decoder (new FFmpegDecoder (film, shared_from_this (), true, false, false));
+       shared_ptr<FFmpegDecoder> decoder (new FFmpegDecoder (film, shared_from_this (), true, false));
 
        ContentVideoFrame video_length = 0;
        video_length = decoder->video_length ();
index 2f890c0cd669067204bede8da26160f43e150ac4..7ebb31084799b252e8d6cf3cd6d3c34c68c2fa0e 100644 (file)
@@ -63,7 +63,7 @@ using libdcp::Size;
 
 boost::mutex FFmpegDecoder::_mutex;
 
-FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegContent> c, bool video, bool audio, bool subtitles)
+FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegContent> c, bool video, bool audio)
        : Decoder (f)
        , VideoDecoder (f, c)
        , AudioDecoder (f, c)
@@ -79,7 +79,6 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> f, shared_ptr<const FFmpegC
        , _subtitle_codec (0)
        , _decode_video (video)
        , _decode_audio (audio)
-       , _decode_subtitles (subtitles)
 {
        setup_general ();
        setup_video ();
@@ -259,7 +258,7 @@ FFmpegDecoder::pass ()
                decode_video_packet ();
        } else if (_ffmpeg_content->audio_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;
index 2d295db7b68b7bf3a1e6dd18fd604b77090f0e9f..3cfb54e09561dbc5995d7fad424b16c6b378ac03 100644 (file)
@@ -59,7 +59,7 @@ class Film;
 class FFmpegDecoder : public VideoDecoder, public AudioDecoder
 {
 public:
-       FFmpegDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const FFmpegContent>, bool video, bool audio, bool subtitles);
+       FFmpegDecoder (boost::shared_ptr<const Film>, boost::shared_ptr<const FFmpegContent>, 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
index 1931ec0f54e821245397f4ec8c7344938bd814bc..6d7c3cfbdd8ffe9d32cb400620d856055b5425f8 100644 (file)
@@ -58,7 +58,6 @@ Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> 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<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
                if (fc) {
-                       shared_ptr<FFmpegDecoder> fd (new FFmpegDecoder (_film, fc, _video, _audio, _subtitles));
+                       shared_ptr<FFmpegDecoder> 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;
index 95f419b5e4a6b65d9ad55155b4a31423a7e6680e..60cf88422fa6279f8b7187c25b48b85cff32b140 100644 (file)
@@ -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;
index d4c5210dc5dfab2b48af067ebabbb8a959eeabbe..847be2f1c9f6b61d2cde0bdd3d53185a47132a89 100644 (file)
@@ -48,10 +48,6 @@ Transcoder::Transcoder (shared_ptr<Film> f, shared_ptr<Job> j)
        , _player (f->player ())
        , _encoder (new Encoder (f, j))
 {
-       if (!f->with_subtitles ()) {
-               _player->disable_subtitles ();
-       }
-
        _player->connect_video (_encoder);
        _player->connect_audio (_encoder);
 }
index 58aceb4077cfc4ebfc9fdecc0bf2e2b90ad90681..54d14e2c68ab2562b6d6e8945fd1723661047065 100644 (file)
@@ -61,20 +61,22 @@ VideoDecoder::video (shared_ptr<Image> image, bool same, Time t)
        
        shared_ptr<Image> out = image->scale_and_convert_to_rgb (image_size, film->scaler(), true);
 
-       shared_ptr<Subtitle> 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<Image> im = sub->image()->scale (tx.size(), film->scaler(), true);
-               out->alpha_blend (im, tx.position());
+       if (film->with_subtitles ()) {
+               shared_ptr<Subtitle> 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<Image> im = sub->image()->scale (tx.size(), film->scaler(), true);
+                       out->alpha_blend (im, tx.position());
+               }
        }
 
        if (image_size != container_size) {
index d2ec01de748f8d564a071fd938894a33aa09ece0..c7a44364fc407dff03278bad6e270f0846caeffc 100644 (file)
@@ -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<Film> 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));