Setup fast state of decoder after creation.
authorCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2019 11:29:01 +0000 (12:29 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 25 Jul 2019 11:29:01 +0000 (12:29 +0100)
15 files changed:
src/lib/audio_decoder.cc
src/lib/audio_decoder.h
src/lib/dcp_content.cc
src/lib/dcp_decoder.cc
src/lib/dcp_decoder.h
src/lib/decoder.cc
src/lib/decoder.h
src/lib/decoder_factory.cc
src/lib/decoder_factory.h
src/lib/ffmpeg_decoder.cc
src/lib/ffmpeg_decoder.h
src/lib/player.cc
src/lib/resampler.cc
src/lib/resampler.h
src/wx/text_panel.cc

index e0fb20b7eec172dbff61ff1e68bae2f8196d4310..d0ff5efec1fdaf52026a6904f71f3cf5bcfb9aca 100644 (file)
@@ -37,10 +37,10 @@ using boost::shared_ptr;
 using boost::optional;
 using namespace dcpomatic;
 
-AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> content, bool fast)
+AudioDecoder::AudioDecoder (Decoder* parent, shared_ptr<const AudioContent> content)
        : DecoderPart (parent)
        , _content (content)
-       , _fast (fast)
+       , _fast (false)
 {
        /* Set up _positions so that we have one for each stream */
        BOOST_FOREACH (AudioStreamPtr i, content->streams ()) {
@@ -83,9 +83,7 @@ AudioDecoder::emit (shared_ptr<const Film> film, AudioStreamPtr stream, shared_p
                                );
 
                        resampler.reset (new Resampler (stream->frame_rate(), _content->resampled_frame_rate(film), stream->channels()));
-                       if (_fast) {
-                               resampler->set_fast ();
-                       }
+                       resampler->set_fast (_fast);
                        _resamplers[stream] = resampler;
                }
        }
@@ -165,3 +163,12 @@ AudioDecoder::silence (int milliseconds)
                Data (i, ContentAudio (silence, _positions[i]));
        }
 }
+
+void
+AudioDecoder::set_fast (bool fast)
+{
+       _fast = fast;
+       for (ResamplerMap::iterator i = _resamplers.begin(); i != _resamplers.end(); ++i) {
+               i->second->set_fast (_fast);
+       }
+}
index 32d71c0671b849d57c5a4bfa921110fca57526d0..0c9b292174a8014e14c7a06d59d1b9ec0b4e519b 100644 (file)
@@ -45,13 +45,15 @@ class Resampler;
 class AudioDecoder : public boost::enable_shared_from_this<AudioDecoder>, public DecoderPart
 {
 public:
-       AudioDecoder (Decoder* parent, boost::shared_ptr<const AudioContent> content, bool fast);
+       AudioDecoder (Decoder* parent, boost::shared_ptr<const AudioContent> content);
 
        dcpomatic::ContentTime position (boost::shared_ptr<const Film> film) const;
        void emit (boost::shared_ptr<const Film> film, AudioStreamPtr stream, boost::shared_ptr<const AudioBuffers>, dcpomatic::ContentTime);
        void seek ();
        void flush ();
 
+       void set_fast (bool fast);
+
        dcpomatic::ContentTime stream_position (boost::shared_ptr<const Film> film, AudioStreamPtr stream) const;
 
        /** @return Number of frames of data that were accepted */
index dc1a463c5bcf907938c45b648417958e3e39ad4b..68e94df7983964f91da0652e6c516cdd922f110a 100644 (file)
@@ -625,7 +625,7 @@ DCPContent::can_reference_audio (shared_ptr<const Film> film, string& why_not) c
 {
        shared_ptr<DCPDecoder> decoder;
        try {
-               decoder.reset (new DCPDecoder (film, shared_from_this(), false));
+               decoder.reset (new DCPDecoder (film, shared_from_this()));
        } catch (dcp::DCPReadError &) {
                /* We couldn't read the DCP, so it's probably missing */
                return false;
@@ -660,7 +660,7 @@ DCPContent::can_reference_text (shared_ptr<const Film> film, TextType type, stri
 {
        shared_ptr<DCPDecoder> decoder;
        try {
-               decoder.reset (new DCPDecoder (film, shared_from_this(), false));
+               decoder.reset (new DCPDecoder (film, shared_from_this()));
        } catch (dcp::DCPReadError &) {
                /* We couldn't read the DCP, so it's probably missing */
                return false;
index b6947211c1d8ddf05461a62e5b78605088c39121..1e5be88005dcdddd8a0e0ffaa9cfeaff5a85e53a 100644 (file)
@@ -56,7 +56,7 @@ using boost::dynamic_pointer_cast;
 using boost::optional;
 using namespace dcpomatic;
 
-DCPDecoder::DCPDecoder (shared_ptr<const Film> film, shared_ptr<const DCPContent> c, bool fast, shared_ptr<DCPDecoder> old)
+DCPDecoder::DCPDecoder (shared_ptr<const Film> film, shared_ptr<const DCPContent> c, shared_ptr<DCPDecoder> old)
        : DCP (c)
        , Decoder (film)
        , _decode_referenced (false)
@@ -66,7 +66,7 @@ DCPDecoder::DCPDecoder (shared_ptr<const Film> film, shared_ptr<const DCPContent
                        video.reset (new VideoDecoder (this, c));
                }
                if (c->audio) {
-                       audio.reset (new AudioDecoder (this, c->audio, fast));
+                       audio.reset (new AudioDecoder (this, c->audio));
                }
                BOOST_FOREACH (shared_ptr<TextContent> i, c->text) {
                        /* XXX: this time here should be the time of the first subtitle, not 0 */
index f31d28053c3b3fc987190585fab451633a6ffa38..37a95a314f0d76496e00ac96532bb3279e142210 100644 (file)
@@ -43,7 +43,6 @@ public:
        DCPDecoder (
                boost::shared_ptr<const Film> film,
                boost::shared_ptr<const DCPContent>,
-               bool fast,
                boost::shared_ptr<DCPDecoder> old = boost::shared_ptr<DCPDecoder>()
                );
 
index 3cadcca47198c1c79c801585b425e04971146bca..976f97fa99f89bb190fbfa0176860d0f9a36c6ee 100644 (file)
@@ -101,3 +101,11 @@ Decoder::film () const
        DCPOMATIC_ASSERT (f);
        return f;
 }
+
+void
+Decoder::set_fast (bool fast)
+{
+       if (audio) {
+               audio->set_fast (fast);
+       }
+}
index 92082ca18b105a62f9dd9aec909625c12ac875c9..b731fe32c85d7e77fa22a91675a3395a73e783d8 100644 (file)
@@ -50,6 +50,7 @@ public:
        std::list<boost::shared_ptr<TextDecoder> > text;
 
        boost::shared_ptr<TextDecoder> only_text () const;
+       void set_fast (bool fast);
 
        /** Do some decoding and perhaps emit video, audio or subtitle data.
         *  @return true if this decoder will emit no more data unless a seek() happens.
index 5d758956d76071fffe172229578b6efb83ad94b8..917c1747be8806266eaf9e70f7700d9d1c0d49ae 100644 (file)
@@ -49,17 +49,17 @@ maybe_cast (shared_ptr<Decoder> d)
 
 /** @param old_decoder A `used' decoder that has been previously made for this piece of content, or 0 */
 shared_ptr<Decoder>
-decoder_factory (shared_ptr<const Film> film, shared_ptr<const Content> content, bool fast, shared_ptr<Decoder> old_decoder)
+decoder_factory (shared_ptr<const Film> film, shared_ptr<const Content> content, shared_ptr<Decoder> old_decoder)
 {
        shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (content);
        if (fc) {
-               return shared_ptr<Decoder> (new FFmpegDecoder(film, fc, fast));
+               return shared_ptr<Decoder> (new FFmpegDecoder(film, fc));
        }
 
        shared_ptr<const DCPContent> dc = dynamic_pointer_cast<const DCPContent> (content);
        if (dc) {
                try {
-                       return shared_ptr<Decoder> (new DCPDecoder(film, dc, fast, maybe_cast<DCPDecoder>(old_decoder)));
+                       return shared_ptr<Decoder> (new DCPDecoder(film, dc, maybe_cast<DCPDecoder>(old_decoder)));
                } catch (KDMError& e) {
                        /* This will be found and reported to the user when the content is examined */
                        return shared_ptr<Decoder>();
index cb145c8a90a4f7c7dacc4e1ad728d8d4e3c4ae5a..e6c8f749e6ea0f4e650a7016cb676b36c7a1eca2 100644 (file)
@@ -23,6 +23,5 @@ class ImageDecoder;
 extern boost::shared_ptr<Decoder> decoder_factory (
        boost::shared_ptr<const Film> film,
        boost::shared_ptr<const Content> content,
-       bool fast,
        boost::shared_ptr<Decoder> old_decoder
        );
index 62d4d2655f59c84af57f96c8c3d25e747794a352..d703f776dd614279dfe777384f319d63f82dc715 100644 (file)
@@ -75,7 +75,7 @@ using boost::dynamic_pointer_cast;
 using dcp::Size;
 using namespace dcpomatic;
 
-FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> film, shared_ptr<const FFmpegContent> c, bool fast)
+FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> film, shared_ptr<const FFmpegContent> c)
        : FFmpeg (c)
        , Decoder (film)
        , _have_current_subtitle (false)
@@ -91,7 +91,7 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr<const Film> film, shared_ptr<const FFmp
        }
 
        if (c->audio) {
-               audio.reset (new AudioDecoder (this, c->audio, fast));
+               audio.reset (new AudioDecoder (this, c->audio));
        }
 
        if (c->only_text()) {
index 65f36a00461b9115ca67fea8e7ee60c60a944ef8..e9d40195381e675d5eafdc4aac41d2b5e07172a1 100644 (file)
@@ -45,7 +45,7 @@ struct ffmpeg_pts_offset_test;
 class FFmpegDecoder : public FFmpeg, public Decoder
 {
 public:
-       FFmpegDecoder (boost::shared_ptr<const Film> film, boost::shared_ptr<const FFmpegContent>, bool fast);
+       FFmpegDecoder (boost::shared_ptr<const Film> film, boost::shared_ptr<const FFmpegContent>);
 
        bool pass ();
        void seek (dcpomatic::ContentTime time, bool);
index acde910be24936f7873b03895b59084def5e87d1..16d17138f52e0c29e1b667985cd16d4e83ec6ac2 100644 (file)
@@ -164,7 +164,7 @@ Player::setup_pieces_unlocked ()
                        }
                }
 
-               shared_ptr<Decoder> decoder = decoder_factory (_film, i, _fast, old_decoder);
+               shared_ptr<Decoder> decoder = decoder_factory (_film, i, old_decoder);
                FrameRateChange frc (_film, i);
 
                if (!decoder) {
@@ -172,6 +172,8 @@ Player::setup_pieces_unlocked ()
                        continue;
                }
 
+               decoder->set_fast (_fast);
+
                if (decoder->video && _ignore_video) {
                        decoder->video->set_ignore (true);
                }
@@ -503,7 +505,7 @@ Player::get_reel_assets ()
 
                scoped_ptr<DCPDecoder> decoder;
                try {
-                       decoder.reset (new DCPDecoder (_film, j, false));
+                       decoder.reset (new DCPDecoder (_film, j));
                } catch (...) {
                        return a;
                }
index 322c00c136779f009ad1163119bce5496a191dad..b27d7c9668dda9f4bbb0419fcf1a2ed381f42c75 100644 (file)
@@ -43,6 +43,7 @@ Resampler::Resampler (int in, int out, int channels)
        : _in_rate (in)
        , _out_rate (out)
        , _channels (channels)
+       , _fast (false)
 {
        int error;
        _src = src_new (SRC_SINC_BEST_QUALITY, _channels, &error);
@@ -59,13 +60,19 @@ Resampler::~Resampler ()
 }
 
 void
-Resampler::set_fast ()
+Resampler::set_fast (bool fast)
 {
+       if (fast == _fast) {
+               return;
+       }
+
+       _fast = fast;
+
        src_delete (_src);
        _src = 0;
 
        int error;
-       _src = src_new (SRC_LINEAR, _channels, &error);
+       _src = src_new (_fast ? SRC_LINEAR : SRC_SINC_BEST_QUALITY, _channels, &error);
        if (!_src) {
                throw runtime_error (String::compose (N_("could not create sample-rate converter (%1)"), error));
        }
index 4b19dc511b891e988c33b4a89b22af8c78da4eb9..dfd3ffd089f8ec7861910965b7fdcf5429e5b316 100644 (file)
@@ -34,11 +34,12 @@ public:
        boost::shared_ptr<const AudioBuffers> run (boost::shared_ptr<const AudioBuffers>);
        boost::shared_ptr<const AudioBuffers> flush ();
        void reset ();
-       void set_fast ();
+       void set_fast (bool fast);
 
 private:
        SRC_STATE* _src;
        int _in_rate;
        int _out_rate;
        int _channels;
+       bool _fast;
 };
index 98398aaa69d7aace690b2d539d62eeea585f7d57..63500f7c6b6011b2f363e06671b4f154dbca49b7 100644 (file)
@@ -667,7 +667,7 @@ TextPanel::text_view_clicked ()
        ContentList c = _parent->selected_text ();
        DCPOMATIC_ASSERT (c.size() == 1);
 
-       shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), false, shared_ptr<Decoder>());
+       shared_ptr<Decoder> decoder = decoder_factory (_parent->film(), c.front(), shared_ptr<Decoder>());
 
        if (decoder) {
                _text_view = new TextView (this, _parent->film(), c.front(), c.front()->text_of_original_type(_original_type), decoder, _parent->film_viewer());