From b1f143193d519de536f228e0f1413d638dda1ea5 Mon Sep 17 00:00:00 2001 From: Alex Chronopoulos Date: Tue, 30 Jun 2020 12:14:48 +0000 Subject: [PATCH] Bug 1647956 - Import cubeb from upstream to 575bd44. r=padenot pick commits: 575bd44 - resampler: avoid overflow on uint arithmetics 7bc4f13 - Add in header doc the switching devices behavior. Differential Revision: https://phabricator.services.mozilla.com/D81695 --- media/libcubeb/gtest/test_resampler.cpp | 18 ++++++++++++++++++ media/libcubeb/include/cubeb.h | 10 ++++++++-- media/libcubeb/moz.yaml | 2 +- media/libcubeb/src/cubeb_resampler_internal.h | 6 ++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/media/libcubeb/gtest/test_resampler.cpp b/media/libcubeb/gtest/test_resampler.cpp index 7fb133d58216..8ac878fc3d5a 100644 --- a/media/libcubeb/gtest/test_resampler.cpp +++ b/media/libcubeb/gtest/test_resampler.cpp @@ -1061,3 +1061,21 @@ TEST(cubeb, passthrough_resampler_fill_input_left) { ASSERT_EQ(input_frame_count, output_frame_count - 8); } +TEST(cubeb, individual_methods) { + const uint32_t channels = 2; + const uint32_t sample_rate = 44100; + const uint32_t frames = 256; + + delay_line dl(10, channels, sample_rate); + uint32_t frames_needed1 = dl.input_needed_for_output(0); + ASSERT_EQ(frames_needed1, 0u); + + cubeb_resampler_speex_one_way one_way(channels, sample_rate, sample_rate, CUBEB_RESAMPLER_QUALITY_DEFAULT); + float buffer[channels * frames] = {0.0}; + // Add all frames in the resampler's internal buffer. + one_way.input(buffer, frames); + // Ask for less than the existing frames, this would create a uint overlflow without the fix. + uint32_t frames_needed2 = one_way.input_needed_for_output(0); + ASSERT_EQ(frames_needed2, 0u); +} + diff --git a/media/libcubeb/include/cubeb.h b/media/libcubeb/include/cubeb.h index f3728311ff9c..f8abfcece779 100644 --- a/media/libcubeb/include/cubeb.h +++ b/media/libcubeb/include/cubeb.h @@ -487,11 +487,17 @@ CUBEB_EXPORT void cubeb_destroy(cubeb * context); cubeb stream. @param stream_name A name for this stream. @param input_device Device for the input side of the stream. If NULL the - default input device is used. + default input device is used. Passing a valid cubeb_devid + means the stream only ever uses that device. Passing a NULL + cubeb_devid allows the stream to follow that device type's + OS default. @param input_stream_params Parameters for the input side of the stream, or NULL if this stream is output only. @param output_device Device for the output side of the stream. If NULL the - default output device is used. + default output device is used. Passing a valid cubeb_devid + means the stream only ever uses that device. Passing a NULL + cubeb_devid allows the stream to follow that device type's + OS default. @param output_stream_params Parameters for the output side of the stream, or NULL if this stream is input only. @param latency_frames Stream latency in frames. Valid range diff --git a/media/libcubeb/moz.yaml b/media/libcubeb/moz.yaml index e4e9054fb613..dfecd3b6b71f 100644 --- a/media/libcubeb/moz.yaml +++ b/media/libcubeb/moz.yaml @@ -19,5 +19,5 @@ origin: license: "ISC" # update.sh will update this value - release: "e2ffb10843c5456212f480c658edfc29930e4f55 (2020-06-10 13:03:04 +1200)" + release: "575bd443893638da4a88468576e4e10b706c7a6c (2020-06-30 22:57:45 +1200)" diff --git a/media/libcubeb/src/cubeb_resampler_internal.h b/media/libcubeb/src/cubeb_resampler_internal.h index 8e6b7f1552bc..4ed6c7501c8e 100644 --- a/media/libcubeb/src/cubeb_resampler_internal.h +++ b/media/libcubeb/src/cubeb_resampler_internal.h @@ -283,8 +283,9 @@ public: * exactly `output_frame_count` resampled frames. This can return a number * slightly bigger than what is strictly necessary, but it guaranteed that the * number of output frames will be exactly equal. */ - uint32_t input_needed_for_output(uint32_t output_frame_count) const + uint32_t input_needed_for_output(int32_t output_frame_count) const { + assert(output_frame_count >= 0); // Check overflow int32_t unresampled_frames_left = samples_to_frames(resampling_in_buffer.length()); int32_t resampled_frames_left = samples_to_frames(resampling_out_buffer.length()); float input_frames_needed = @@ -462,8 +463,9 @@ public: * @parameter frames_needed the number of frames one want to write into the * delay_line * @returns the number of frames one will get. */ - size_t input_needed_for_output(uint32_t frames_needed) const + uint32_t input_needed_for_output(int32_t frames_needed) const { + assert(frames_needed >= 0); // Check overflow return frames_needed; } /** Returns the number of frames produces for `input_frames` frames in input */