Make subtitle addition optional.
authorCarl Hetherington <cth@carlh.net>
Tue, 9 Oct 2012 14:56:55 +0000 (15:56 +0100)
committerCarl Hetherington <cth@carlh.net>
Tue, 9 Oct 2012 14:56:55 +0000 (15:56 +0100)
src/lib/decoder.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/lib/film.cc
src/lib/film.h
src/lib/film_state.cc
src/lib/film_state.h
src/lib/imagemagick_decoder.h
src/lib/tiff_decoder.h
src/wx/film_editor.cc
src/wx/film_editor.h

index 7ca9bb1df070c8bee702714956a7246fbd02fbec..9a4c7695eaba4e4c7ec718b62f31ffc8691f0bd4 100644 (file)
@@ -66,6 +66,7 @@ public:
        /** @return format of audio samples */
        virtual AVSampleFormat audio_sample_format () const = 0;
        virtual int64_t audio_channel_layout () const = 0;
+       virtual bool has_subtitles () const = 0;
 
        void process_begin ();
        bool pass ();
index 808e5ac9b573b82f98734c7eaa1cccf577c212bd..7bc579ba6d1a40751e80f4a807591cae5b47386c 100644 (file)
@@ -249,7 +249,7 @@ FFmpegDecoder::do_pass ()
                        process_audio (_frame->data[0], data_size);
                }
 
-       } else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream) {
+       } else if (_subtitle_stream >= 0 && _packet.stream_index == _subtitle_stream && _fs->with_subtitles) {
 
                if (_have_subtitle) {
                        avsubtitle_free (&_subtitle);
@@ -453,3 +453,8 @@ FFmpegDecoder::overlay (shared_ptr<Image> image) const
        }
 }
     
+bool
+FFmpegDecoder::has_subtitles () const
+{
+       return (_subtitle_stream != -1);
+}
index 18c2e2aeb316fa937a253a5dbc70a9bdd7535f96..59ec7573d1691b2d524f872f76e99ff557d8a6f1 100644 (file)
@@ -63,6 +63,7 @@ public:
        int audio_sample_rate () const;
        AVSampleFormat audio_sample_format () const;
        int64_t audio_channel_layout () const;
+       bool has_subtitles () const;
 
 private:
 
index e2b3d4bc31391cb4a226caa64442102abd6f7cf7..96dc3d3a45c22d63bbbc588ff3001e77d1d07e34 100644 (file)
@@ -217,6 +217,7 @@ Film::set_content (string c)
        _state.audio_channels = d->audio_channels ();
        _state.audio_sample_rate = d->audio_sample_rate ();
        _state.audio_sample_format = d->audio_sample_format ();
+       _state.has_subtitles = d->has_subtitles ();
 
        _state.content_digest = md5_digest (s->content_path ());
        _state.content = c;
@@ -658,3 +659,10 @@ Film::encoded_frames () const
 
        return N;
 }
+
+void
+Film::set_with_subtitles (bool w)
+{
+       _state.with_subtitles = w;
+       signal_changed (WITH_SUBTITLES);
+}
index cd3b1b8a8dac19c830c088bc383afbb5cbadad4f..919cecc220c552688931148f0ffced1efa55ceda 100644 (file)
@@ -119,6 +119,10 @@ public:
        int still_duration () const {
                return _state.still_duration;
        }
+
+       bool with_subtitles () const {
+               return _state.with_subtitles;
+       }
        
        void set_filters (std::vector<Filter const *> const &);
 
@@ -144,6 +148,7 @@ public:
        void set_audio_gain (float);
        void set_audio_delay (int);
        void set_still_duration (int);
+       void set_with_subtitles (bool);
 
        /** @return size, in pixels, of the source (ignoring cropping) */
        Size size () const {
@@ -174,6 +179,10 @@ public:
        AVSampleFormat audio_sample_format () const {
                return _state.audio_sample_format;
        }
+
+       bool has_subtitles () const {
+               return _state.has_subtitles;
+       }
        
        std::string j2k_dir () const;
 
@@ -218,7 +227,8 @@ public:
                FRAMES_PER_SECOND,
                AUDIO_CHANNELS,
                AUDIO_SAMPLE_RATE,
-               STILL_DURATION
+               STILL_DURATION,
+               WITH_SUBTITLES,
        };
 
        boost::shared_ptr<FilmState> state_copy () const;
index 3cd7091ca69ebdb62a8706c652dc7113d63f8779..1872d9e763b4f07ecf551c0317527a7619e09068 100644 (file)
@@ -80,6 +80,7 @@ FilmState::write_metadata (ofstream& f) const
        f << "audio_gain " << audio_gain << "\n";
        f << "audio_delay " << audio_delay << "\n";
        f << "still_duration " << still_duration << "\n";
+       f << "with_subtitles " << with_subtitles << "\n";
 
        /* Cached stuff; this is information about our content; we could
           look it up each time, but that's slow.
@@ -94,6 +95,7 @@ FilmState::write_metadata (ofstream& f) const
        f << "audio_sample_rate " << audio_sample_rate << "\n";
        f << "audio_sample_format " << audio_sample_format_to_string (audio_sample_format) << "\n";
        f << "content_digest " << content_digest << "\n";
+       f << "has_subtitles " << has_subtitles << "\n";
 }
 
 /** Read state from a key / value pair.
@@ -142,6 +144,8 @@ FilmState::read_metadata (string k, string v)
                audio_delay = atoi (v.c_str ());
        } else if (k == "still_duration") {
                still_duration = atoi (v.c_str ());
+       } else if (k == "with_subtitles") {
+               with_subtitles = (v == "1");
        }
        
        /* Cached stuff */
@@ -165,6 +169,8 @@ FilmState::read_metadata (string k, string v)
                audio_sample_format = audio_sample_format_from_string (v);
        } else if (k == "content_digest") {
                content_digest = v;
+       } else if (k == "has_subtitles") {
+               has_subtitles = (v == "1");
        }
 }
 
index 16a1b0508d80f6daaced489fb6b0e34819399515..2b792694c59e77edde928297022a18e91e679716 100644 (file)
@@ -62,10 +62,12 @@ public:
                , audio_gain (0)
                , audio_delay (0)
                , still_duration (10)
+               , with_subtitles (false)
                , length (0)
                , audio_channels (0)
                , audio_sample_rate (0)
                , audio_sample_format (AV_SAMPLE_FMT_NONE)
+               , has_subtitles (false)
        {}
 
        std::string file (std::string f) const;
@@ -126,6 +128,7 @@ public:
        int audio_delay;
        /** Duration to make still-sourced films (in seconds) */
        int still_duration;
+       bool with_subtitles;
 
        /* Data which is cached to speed things up */
 
@@ -143,6 +146,8 @@ public:
        AVSampleFormat audio_sample_format;
        /** MD5 digest of our content file */
        std::string content_digest;
+       /** true if the source has subtitles */
+       bool has_subtitles;
 
 private:
        std::string thumb_file_for_frame (int) const;
index aca91ef5562d7392b1456942c6611df8b8c2aba1..05dc7f113386caef7384493e0ff9bdf8e9114fe8 100644 (file)
@@ -35,6 +35,10 @@ public:
                return 0;
        }
 
+       bool has_subtitles () const {
+               return false;
+       }
+
        static float static_frames_per_second () {
                return 24;
        }
index d9b5b3969934b3000ef44368a9fa2e8a4f1eef1e..b9849a2591f7af04b4396b9932c93c52c02c6b4d 100644 (file)
@@ -53,6 +53,9 @@ public:
        int audio_sample_rate () const;
        AVSampleFormat audio_sample_format () const;
        int64_t audio_channel_layout () const;
+       bool has_subtitles () const {
+               return false;
+       }
 
 private:
        bool do_pass ();
index 3b26a5537e3bf3327f80e42bb048bcb20e9e065c..bc7414c41325603babaa2c72f9cd462ff68e177c 100644 (file)
@@ -130,6 +130,11 @@ FilmEditor::FilmEditor (Film* f, wxWindow* parent)
                _sizer->Add (s);
        }
 
+       _with_subtitles = new wxCheckBox (this, wxID_ANY, wxT("With Subtitles"));
+       video_control (_with_subtitles);
+       _sizer->Add (_with_subtitles, 1);
+       _sizer->AddSpacer (0);
+
        video_control (add_label_to_sizer (_sizer, this, "Frames Per Second"));
        _frames_per_second = new wxStaticText (this, wxID_ANY, wxT (""));
        _sizer->Add (video_control (_frames_per_second), 1, wxALIGN_CENTER_VERTICAL);
@@ -292,6 +297,7 @@ FilmEditor::content_changed (wxCommandEvent &)
 
        setup_visibility ();
        setup_formats ();
+       setup_subtitle_button ();
 }
 
 /** Called when the DCP A/B switch has been toggled */
@@ -340,6 +346,7 @@ FilmEditor::film_changed (Film::Property p)
                _content->SetPath (std_to_wx (_film->content ()));
                setup_visibility ();
                setup_formats ();
+               setup_subtitle_button ();
                break;
        case Film::FORMAT:
        {
@@ -437,6 +444,9 @@ FilmEditor::film_changed (Film::Property p)
        case Film::STILL_DURATION:
                _still_duration->SetValue (_film->still_duration ());
                break;
+       case Film::WITH_SUBTITLES:
+               _with_subtitles->SetValue (_film->with_subtitles ());
+               break;
        }
 }
 
@@ -702,3 +712,25 @@ FilmEditor::setup_formats ()
 
        _sizer->Layout ();
 }
+
+void
+FilmEditor::with_subtitles_toggled (wxCommandEvent &)
+{
+       if (!_film) {
+               return;
+       }
+
+       _ignore_changes = Film::WITH_SUBTITLES;
+       _film->set_with_subtitles (_with_subtitles->GetValue ());
+       _ignore_changes = Film::NONE;
+}
+
+void
+FilmEditor::setup_subtitle_button ()
+{
+       _with_subtitles->Enable (_film->has_subtitles ());
+       if (!_film->has_subtitles ()) {
+               _with_subtitles->SetValue (false);
+       }
+}
+
index c599cd285c97e0b8ffb4d39b70ac5aba41a5704f..720e71902c9c4b804e6d9b15a498ca46a7466c98 100644 (file)
@@ -58,6 +58,7 @@ private:
        void audio_gain_changed (wxCommandEvent &);
        void audio_gain_calculate_button_clicked (wxCommandEvent &);
        void audio_delay_changed (wxCommandEvent &);
+       void with_subtitles_toggled (wxCommandEvent &);
        void still_duration_changed (wxCommandEvent &);
 
        /* Handle changes to the model */
@@ -69,6 +70,7 @@ private:
 
        void set_things_sensitive (bool);
        void setup_formats ();
+       void setup_subtitle_button ();
        
        wxControl* video_control (wxControl *);
        wxControl* still_control (wxControl *);
@@ -103,6 +105,7 @@ private:
        wxButton* _audio_gain_calculate_button;
        /** The Film's audio delay */
        wxSpinCtrl* _audio_delay;
+       wxCheckBox* _with_subtitles;
        /** The Film's DCP content type */
        wxComboBox* _dcp_content_type;
        /** The Film's frames per second */