Fix assumption of 48kHz DCP audio in AudioRingBuffers consistency check (#1436).
authorCarl Hetherington <cth@carlh.net>
Sat, 22 Dec 2018 23:32:59 +0000 (23:32 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 22 Dec 2018 23:32:59 +0000 (23:32 +0000)
src/lib/audio_ring_buffers.cc
src/lib/audio_ring_buffers.h
src/lib/butler.cc
src/lib/butler.h
src/lib/player.cc
src/lib/player.h
test/audio_ring_buffers_test.cc

index 012ab0718022bab0fcf7ceca540f7d84e7459b43..d26fb9eb7907b8a31790530225b335405d2841c5 100644 (file)
@@ -38,17 +38,18 @@ AudioRingBuffers::AudioRingBuffers ()
 
 }
 
+/** @param frame_rate Frame rate in use; this is only used to check timing consistency of the incoming data */
 void
-AudioRingBuffers::put (shared_ptr<const AudioBuffers> data, DCPTime time)
+AudioRingBuffers::put (shared_ptr<const AudioBuffers> data, DCPTime time, int frame_rate)
 {
        boost::mutex::scoped_lock lm (_mutex);
 
        if (!_buffers.empty()) {
                DCPOMATIC_ASSERT (_buffers.front().first->channels() == data->channels());
-               if ((_buffers.back().second + DCPTime::from_frames(_buffers.back().first->frames(), 48000)) != time) {
+               if ((_buffers.back().second + DCPTime::from_frames(_buffers.back().first->frames(), frame_rate)) != time) {
                        cout << "bad put " << to_string(_buffers.back().second) << " " << _buffers.back().first->frames() << " " << to_string(time) << "\n";
                }
-               DCPOMATIC_ASSERT ((_buffers.back().second + DCPTime::from_frames(_buffers.back().first->frames(), 48000)) == time);
+               DCPOMATIC_ASSERT ((_buffers.back().second + DCPTime::from_frames(_buffers.back().first->frames(), frame_rate)) == time);
        }
 
        _buffers.push_back(make_pair(data, time));
index 53236cb3226f508a46d04b21272ff882dcb0c4e7..ce0efd3e2c585569ccdc7f127618a69700083dde 100644 (file)
@@ -33,7 +33,7 @@ class AudioRingBuffers : public boost::noncopyable
 public:
        AudioRingBuffers ();
 
-       void put (boost::shared_ptr<const AudioBuffers> data, DCPTime time);
+       void put (boost::shared_ptr<const AudioBuffers> data, DCPTime time, int frame_rate);
        boost::optional<DCPTime> get (float* out, int channels, int frames);
 
        void clear ();
index 94230d0942b7b65dd910766495d94c850cb0392f..f3e9f73f13775ba31123800bafe80ad091841aa9 100644 (file)
@@ -76,7 +76,7 @@ Butler::Butler (
        , _fast (fast)
 {
        _player_video_connection = _player->Video.connect (bind (&Butler::video, this, _1, _2));
-       _player_audio_connection = _player->Audio.connect (bind (&Butler::audio, this, _1, _2));
+       _player_audio_connection = _player->Audio.connect (bind (&Butler::audio, this, _1, _2, _3));
        _player_text_connection = _player->Text.connect (bind (&Butler::text, this, _1, _2, _3, _4));
        /* The butler must hear about things first, otherwise it might not sort out suspensions in time for
           get_video() to be called in response to this signal.
@@ -296,7 +296,7 @@ Butler::video (shared_ptr<PlayerVideo> video, DCPTime time)
 }
 
 void
-Butler::audio (shared_ptr<AudioBuffers> audio, DCPTime time)
+Butler::audio (shared_ptr<AudioBuffers> audio, DCPTime time, int frame_rate)
 {
        {
                boost::mutex::scoped_lock lm (_mutex);
@@ -307,7 +307,7 @@ Butler::audio (shared_ptr<AudioBuffers> audio, DCPTime time)
        }
 
        boost::mutex::scoped_lock lm2 (_buffers_mutex);
-       _audio.put (remap (audio, _audio_channels, _audio_mapping), time);
+       _audio.put (remap (audio, _audio_channels, _audio_mapping), time, frame_rate);
 }
 
 /** Try to get `frames' frames of audio and copy it into `out'.  Silence
index 4f4e508843d8cb04f45fc545a4f13119b8b5ecdd..f1b86a1ab14aa9a3fa390fac16dc00a1b5958cb4 100644 (file)
@@ -65,7 +65,7 @@ public:
 private:
        void thread ();
        void video (boost::shared_ptr<PlayerVideo> video, DCPTime time);
-       void audio (boost::shared_ptr<AudioBuffers> audio, DCPTime time);
+       void audio (boost::shared_ptr<AudioBuffers> audio, DCPTime time, int frame_rate);
        void text (PlayerText pt, TextType type, boost::optional<DCPTextTrack> track, DCPTimePeriod period);
        bool should_run () const;
        void prepare (boost::weak_ptr<PlayerVideo> video) const;
index ae16290f57d7343297bde3e3a5ed9c307991f3be..fa6c1b055a6670750ed10388eb6d2a6f01e24386 100644 (file)
@@ -1099,7 +1099,7 @@ Player::emit_audio (shared_ptr<AudioBuffers> data, DCPTime time)
 
        /* This audio must follow on from the previous */
        DCPOMATIC_ASSERT (!_last_audio_time || time == *_last_audio_time);
-       Audio (data, time);
+       Audio (data, time, _film->audio_frame_rate());
        _last_audio_time = time + DCPTime::from_frames (data->frames(), _film->audio_frame_rate());
 }
 
index b3c4e82b42394453677f886a47b7f7f3899d03f2..8a81146c9547fb7d7612dc59e38d3f1b0d289880 100644 (file)
@@ -92,7 +92,7 @@ public:
 
        /** Emitted when a video frame is ready.  These emissions happen in the correct order. */
        boost::signals2::signal<void (boost::shared_ptr<PlayerVideo>, DCPTime)> Video;
-       boost::signals2::signal<void (boost::shared_ptr<AudioBuffers>, DCPTime)> Audio;
+       boost::signals2::signal<void (boost::shared_ptr<AudioBuffers>, DCPTime, int)> Audio;
        /** Emitted when a text is ready.  This signal may be emitted considerably
         *  after the corresponding Video.
         */
index 6ec5e22359b93584c94000a734956ccc9d525dc6..9ebd64ded972bde2bf93d1d824a3bf1ccf3a649c 100644 (file)
@@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE (audio_ring_buffers_test1)
                        data->data(j)[i] = value++;
                }
        }
-       rb.put (data, DCPTime());
+       rb.put (data, DCPTime(), 48000);
        BOOST_CHECK_EQUAL (rb.size(), 91);
 
        /* Get part of it out */
@@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE (audio_ring_buffers_test2)
                        data->data(j)[i] = value++;
                }
        }
-       rb.put (data, DCPTime());
+       rb.put (data, DCPTime(), 48000);
        BOOST_CHECK_EQUAL (rb.size(), 91);
 
        /* Get part of it out */
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE (audio_ring_buffers_test3)
                        data->data(j)[i] = value++;
                }
        }
-       rb.put (data, DCPTime ());
+       rb.put (data, DCPTime(), 48000);
        BOOST_CHECK_EQUAL (rb.size(), 91);
 
        /* Get part of it out */