From 8373579009c2033eccf062d9ec36a26ebbce3415 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sat, 24 Apr 2021 13:23:34 +0100 Subject: [PATCH 1/4] audioparams: cache channel_count --- app/render/audioparams.cpp | 2 +- app/render/audioparams.h | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/render/audioparams.cpp b/app/render/audioparams.cpp index 304f4cba3..062cf5be5 100644 --- a/app/render/audioparams.cpp +++ b/app/render/audioparams.cpp @@ -141,7 +141,7 @@ rational AudioParams::bytes_to_time(const qint64 &bytes) const int AudioParams::channel_count() const { - return av_get_channel_layout_nb_channels(channel_layout()); + return channel_count_; } int AudioParams::bytes_per_sample_per_channel() const diff --git a/app/render/audioparams.h b/app/render/audioparams.h index a2d4ea3c5..7cfda60f3 100644 --- a/app/render/audioparams.h +++ b/app/render/audioparams.h @@ -66,6 +66,9 @@ public: format_(kFormatInvalid) { set_default_footage_parameters(); + + // Cache channel count + channel_count_ = av_get_channel_layout_nb_channels(channel_layout()); } AudioParams(const int& sample_rate, const uint64_t& channel_layout, const Format& format) : @@ -75,6 +78,9 @@ public: { set_default_footage_parameters(); timebase_ = sample_rate_as_time_base(); + + // Cache channel count + channel_count_ = av_get_channel_layout_nb_channels(this->channel_layout()); } int sample_rate() const @@ -201,6 +207,8 @@ private: uint64_t channel_layout_; + int channel_count_; + Format format_; // Footage-specific From 59163e81276d229f117701c150af83811ffad818 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sat, 24 Apr 2021 14:26:07 +0100 Subject: [PATCH 2/4] audioplaybackcache: optimise writing to PCM --- app/render/audioplaybackcache.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/render/audioplaybackcache.cpp b/app/render/audioplaybackcache.cpp index e83417e31..df2d334d1 100644 --- a/app/render/audioplaybackcache.cpp +++ b/app/render/audioplaybackcache.cpp @@ -64,10 +64,14 @@ void AudioPlaybackCache::WritePCM(const TimeRange &range, SampleBufferPtr sample // Ensure if we have enough segments to write this data, creating more if not qint64 length_diff = params_.time_to_bytes(range.out()) - playlist_.GetLength(); - while (length_diff > 0) { - qint64 seg_sz = qMin(kDefaultSegmentSize, length_diff); - playlist_.push_back(CreateSegment(seg_sz, playlist_.GetLength())); - length_diff -= seg_sz; + qint64 whole_segments = length_diff / kDefaultSegmentSize; + qint64 remainder = length_diff % kDefaultSegmentSize; + + for (int i = 0; i < whole_segments; i++) { + playlist_.push_back(CreateSegment(kDefaultSegmentSize, playlist_.GetLength())); + } + if (remainder > 0) { + playlist_.push_back(CreateSegment(remainder, playlist_.GetLength())); } // Convert to packed data, which is what we store on disk so it can be played back easily From 7ee6d52651ba5b633574b8378e69e0dec096c310 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sun, 25 Apr 2021 21:03:35 +0100 Subject: [PATCH 3/4] audioparams: move channel count calculation to its own function --- app/render/audioparams.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/render/audioparams.h b/app/render/audioparams.h index 7cfda60f3..b79c14ede 100644 --- a/app/render/audioparams.h +++ b/app/render/audioparams.h @@ -68,7 +68,7 @@ public: set_default_footage_parameters(); // Cache channel count - channel_count_ = av_get_channel_layout_nb_channels(channel_layout()); + calculate_channel_count(); } AudioParams(const int& sample_rate, const uint64_t& channel_layout, const Format& format) : @@ -80,7 +80,7 @@ public: timebase_ = sample_rate_as_time_base(); // Cache channel count - channel_count_ = av_get_channel_layout_nb_channels(this->channel_layout()); + calculate_channel_count(); } int sample_rate() const @@ -101,6 +101,7 @@ public: void set_channel_layout(uint64_t channel_layout) { channel_layout_ = channel_layout; + calculate_channel_count(); } rational time_base() const @@ -203,6 +204,11 @@ private: duration_ = 0; } + void calculate_channel_count() + { + channel_count_ = av_get_channel_layout_nb_channels(channel_layout()); + } + int sample_rate_; uint64_t channel_layout_; From b4670d6cffd0a332a4664250407e901d1492c097 Mon Sep 17 00:00:00 2001 From: Thomas Wilshaw Date: Sun, 25 Apr 2021 21:08:28 +0100 Subject: [PATCH 4/4] Revert "audioplaybackcache: optimise writing to PCM" This reverts commit 59163e81276d229f117701c150af83811ffad818. --- app/render/audioplaybackcache.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/render/audioplaybackcache.cpp b/app/render/audioplaybackcache.cpp index df2d334d1..e83417e31 100644 --- a/app/render/audioplaybackcache.cpp +++ b/app/render/audioplaybackcache.cpp @@ -64,14 +64,10 @@ void AudioPlaybackCache::WritePCM(const TimeRange &range, SampleBufferPtr sample // Ensure if we have enough segments to write this data, creating more if not qint64 length_diff = params_.time_to_bytes(range.out()) - playlist_.GetLength(); - qint64 whole_segments = length_diff / kDefaultSegmentSize; - qint64 remainder = length_diff % kDefaultSegmentSize; - - for (int i = 0; i < whole_segments; i++) { - playlist_.push_back(CreateSegment(kDefaultSegmentSize, playlist_.GetLength())); - } - if (remainder > 0) { - playlist_.push_back(CreateSegment(remainder, playlist_.GetLength())); + while (length_diff > 0) { + qint64 seg_sz = qMin(kDefaultSegmentSize, length_diff); + playlist_.push_back(CreateSegment(seg_sz, playlist_.GetLength())); + length_diff -= seg_sz; } // Convert to packed data, which is what we store on disk so it can be played back easily