diff options
author | dalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-11 08:16:53 +0000 |
---|---|---|
committer | dalecurtis@google.com <dalecurtis@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-11 08:16:53 +0000 |
commit | a6e742967c375b0d1a85659048c4604a67633712 (patch) | |
tree | 0a8f75e50ff6b8f5056869942f724bbc1310c8b2 /media/base/sinc_resampler_unittest.cc | |
parent | b7eb5c97ad78d918b287fbb27deb378eddb646f4 (diff) | |
download | chromium_src-a6e742967c375b0d1a85659048c4604a67633712.zip chromium_src-a6e742967c375b0d1a85659048c4604a67633712.tar.gz chromium_src-a6e742967c375b0d1a85659048c4604a67633712.tar.bz2 |
As titled! AudioOutputResampler is a single stream output resampler which uses
the existing AudioOutputDispatcherImpl to handle the heavy lifting. It intercepts
the AudioSourceCallback provided during OpenStream() and replaces it with a
call to itself.
An AudioFifo object is used to ensure we interface with the renderer and
downstream components using the same buffer size they were configured with.
A MultiChannelResampler object interfaces with a provided callback method
which pulls data from the AudioFifo if available and otherwise retrieves more
data from the client (using the buffer size the client expects).
The pending bytes value is scaled according to the input / output sample rate
and bits per channel values. Outstanding data is tracked between OnMoreData()
calls in order to provide the client with an accurate delay estimate.
Feature is behind the "--enable-audio-output-resampler" for a/b testing. Will be
removed from behind the flag after tuning and functionality can be verified by
the Pepper Flash team.
BUG=147572
TEST=PepperFlash + 192kHz->44kHz, 48kHz->44kHz, 44kHz->96kHz. Manual
testing by various parties.
Review URL: https://chromiumcodereview.appspot.com/10918098
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@155968 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/sinc_resampler_unittest.cc')
-rw-r--r-- | media/base/sinc_resampler_unittest.cc | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/media/base/sinc_resampler_unittest.cc b/media/base/sinc_resampler_unittest.cc index fa358e1..77a963e 100644 --- a/media/base/sinc_resampler_unittest.cc +++ b/media/base/sinc_resampler_unittest.cc @@ -33,6 +33,14 @@ class MockSource { MOCK_METHOD2(ProvideInput, void(float* destination, int frames)); }; +ACTION(ClearBuffer) { + memset(arg0, 0, arg1 * sizeof(float)); +} + +ACTION(FillBuffer) { + memset(arg0, 1, arg1 * sizeof(float)); +} + // Test requesting multiples of ChunkSize() frames results in the proper number // of callbacks. TEST(SincResamplerTest, ChunkedResample) { @@ -49,15 +57,41 @@ TEST(SincResamplerTest, ChunkedResample) { scoped_array<float> resampled_destination(new float[max_chunk_size]); // Verify requesting ChunkSize() frames causes a single callback. - EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(1); + EXPECT_CALL(mock_source, ProvideInput(_, _)) + .Times(1).WillOnce(ClearBuffer()); resampler.Resample(resampled_destination.get(), resampler.ChunkSize()); // Verify requesting kChunks * ChunkSize() frames causes kChunks callbacks. testing::Mock::VerifyAndClear(&mock_source); - EXPECT_CALL(mock_source, ProvideInput(_, _)).Times(kChunks); + EXPECT_CALL(mock_source, ProvideInput(_, _)) + .Times(kChunks).WillRepeatedly(ClearBuffer()); resampler.Resample(resampled_destination.get(), max_chunk_size); } +// Test flush resets the internal state properly. +TEST(SincResamplerTest, Flush) { + MockSource mock_source; + SincResampler resampler( + kSampleRateRatio, + base::Bind(&MockSource::ProvideInput, base::Unretained(&mock_source))); + scoped_array<float> resampled_destination(new float[resampler.ChunkSize()]); + + // Fill the resampler with junk data. + EXPECT_CALL(mock_source, ProvideInput(_, _)) + .Times(1).WillOnce(FillBuffer()); + resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); + ASSERT_NE(resampled_destination[0], 0); + + // Flush and request more data, which should all be zeros now. + resampler.Flush(); + testing::Mock::VerifyAndClear(&mock_source); + EXPECT_CALL(mock_source, ProvideInput(_, _)) + .Times(1).WillOnce(ClearBuffer()); + resampler.Resample(resampled_destination.get(), resampler.ChunkSize() / 2); + for (int i = 0; i < resampler.ChunkSize() / 2; ++i) + ASSERT_EQ(resampled_destination[i], 0); +} + // Ensure various optimized Convolve() methods return the same value. Only run // this test if other optimized methods exist, otherwise the default Convolve() // will be tested by the parameterized SincResampler tests below. |