Tidy up a bit more. 1771-resample-glitches
authorCarl Hetherington <cth@carlh.net>
Mon, 26 Apr 2021 19:33:25 +0000 (21:33 +0200)
committerCarl Hetherington <cth@carlh.net>
Mon, 26 Apr 2021 19:33:25 +0000 (21:33 +0200)
src/lib/audio_decoder.cc
src/lib/resampler_manager.cc
src/lib/resampler_manager.h

index 5f7ec37300a53770212626a880a0f5451e6deda7..d97de38d88cdd1cf0c2dc9fb58f24b06cdc7d5e0 100644 (file)
@@ -176,7 +176,7 @@ AudioDecoder::seek ()
 void
 AudioDecoder::flush ()
 {
-       _resampler_manager->maybe_flush (this);
+       _resampler_manager->flush (this);
 
        if (_content->delay() < 0) {
                /* Finish off with the gap caused by the delay */
index 4b736aa8479365bb4f8b2ec498fe008e2bd7062d..90ec1bfbcada39e9144c50b191e7274e2bc236c1 100644 (file)
@@ -9,6 +9,7 @@
 
 using std::vector;
 using std::shared_ptr;
+using std::make_shared;
 using namespace dcpomatic;
 
 
@@ -34,14 +35,14 @@ ResamplerManager::coalesce ()
 bool
 ResamplerManager::can_share (Group const& a, Group const& b) const
 {
-       vector<AudioStreamPtr> as = a.contents[0]->streams();
-       vector<AudioStreamPtr> bs = b.contents[0]->streams();
+       auto as = a.contents[0]->streams();
+       auto bs = b.contents[0]->streams();
 
        if (a.contents[0]->streams().size() != b.contents[0]->streams().size()) {
                return false;
        }
 
-       shared_ptr<const Film> film = _film.lock ();
+       auto film = _film.lock ();
        DCPOMATIC_ASSERT (film);
        if (a.contents[0]->resampled_frame_rate(film) != b.contents[0]->resampled_frame_rate(film)) {
                return false;
@@ -49,8 +50,8 @@ ResamplerManager::can_share (Group const& a, Group const& b) const
 
        /* The first, second, etc. streams in a and b must be the same */
 
-       vector<AudioStreamPtr>::const_iterator i = as.begin();
-       vector<AudioStreamPtr>::const_iterator j = bs.begin();
+       auto i = as.begin();
+       auto j = bs.begin();
 
        while (i != as.end()) {
                if (
@@ -93,14 +94,14 @@ ResamplerManager::coalesce_pass ()
 shared_ptr<Resampler>
 ResamplerManager::get (AudioDecoder* decoder, AudioStreamPtr stream, bool fast)
 {
-       shared_ptr<const Film> film = _film.lock();
+       auto film = _film.lock();
        DCPOMATIC_ASSERT (film);
 
-       BOOST_FOREACH (Group& g, _groups) {
+       for (auto& g: _groups) {
                for (size_t i = 0; i < g.decoders.size(); ++i) {
                        if (g.decoders[i].get() == decoder) {
-                               vector<AudioStreamPtr> content_streams = g.contents[i]->streams();
-                               ptrdiff_t index = find(content_streams.begin(), content_streams.end(), stream) - content_streams.begin();
+                               auto content_streams = g.contents[i]->streams();
+                               auto index = find(content_streams.begin(), content_streams.end(), stream) - content_streams.begin();
                                DCPOMATIC_ASSERT (index < static_cast<ptrdiff_t>(content_streams.size()));
                                if (!g.resamplers[index] && stream->frame_rate() != g.contents[i]->resampled_frame_rate(film)) {
                                        LOG_GENERAL (
@@ -110,7 +111,7 @@ ResamplerManager::get (AudioDecoder* decoder, AudioStreamPtr stream, bool fast)
                                                stream->channels()
                                                );
 
-                                       g.resamplers[index].reset (new Resampler(stream->frame_rate(), g.contents[i]->resampled_frame_rate(film), stream->channels()));
+                                       g.resamplers[index] = make_shared<Resampler>(stream->frame_rate(), g.contents[i]->resampled_frame_rate(film), stream->channels());
                                        if (fast) {
                                                g.resamplers[index]->set_fast ();
                                        }
@@ -121,22 +122,21 @@ ResamplerManager::get (AudioDecoder* decoder, AudioStreamPtr stream, bool fast)
        }
 
        DCPOMATIC_ASSERT (false);
-       return shared_ptr<Resampler>();
+       return {};
 }
 
 
 void
-ResamplerManager::maybe_flush (AudioDecoder* decoder)
+ResamplerManager::flush (AudioDecoder* decoder)
 {
-       BOOST_FOREACH (Group& g, _groups) {
-               BOOST_FOREACH (shared_ptr<AudioDecoder> d, g.decoders) {
-                       if (d.get() == decoder) {
-                               BOOST_FOREACH (shared_ptr<Resampler> r, g.resamplers) {
-                                       shared_ptr<const AudioBuffers> ro = r->flush ();
-                                       /* XXX: err... which content do these samples belong to?  Won't
-                                        * the player throw the samples away if they appear to come from the
-                                        * wrong place?
-                                        */
+       for (auto& g: _groups) {
+               if (find(g.decoders.begin(), g.decoders.end(), [decoder](shared_ptr<Decoder> d) { return d->audio.get() == decoder; }) != g.decoders.end()) {
+                       for (auto r: g.resamplers) {
+                               auto ro = r->flush ();
+                               /* XXX: err... which content do these samples belong to?  Won't
+                                * the player throw the samples away if they appear to come from the
+                                * wrong place?
+                                */
                        }
                }
        }
index ae470d537acd008f6f608b2051f2e311c57cc4ff..fb10d96b661aefaf6d3a95d7d7c0cdf6c2b3fa71 100644 (file)
@@ -25,6 +25,8 @@ public:
        void add (dcpomatic::DCPTime start, dcpomatic::DCPTime end, std::shared_ptr<AudioContent> content, std::shared_ptr<AudioDecoder> decoder);
        std::shared_ptr<Resampler> get (AudioDecoder* decoder, AudioStreamPtr stream, bool fast);
 
+       void flush (AudioDecoder* decoder)
+
 private:
        friend struct resampler_manager_setup_test;