Chromium Code Reviews| Index: chromecast/media/cma/backend/alsa/stream_mixer_alsa_unittest.cc |
| diff --git a/chromecast/media/cma/backend/alsa/stream_mixer_alsa_unittest.cc b/chromecast/media/cma/backend/alsa/stream_mixer_alsa_unittest.cc |
| index 2b7b358343a5b3a2acffba6dfefc9273d1890a3a..c5ef460660b966b9a350cf9dd258674972b0702a 100644 |
| --- a/chromecast/media/cma/backend/alsa/stream_mixer_alsa_unittest.cc |
| +++ b/chromecast/media/cma/backend/alsa/stream_mixer_alsa_unittest.cc |
| @@ -27,7 +27,7 @@ namespace { |
| // Testing constants that are common to multiple test cases. |
| const int kNumChannels = 2; |
| -const int kBytesPerSample = 4; |
| +const int kBytesPerSample = sizeof(int32_t); |
| const int kTestMaxReadSize = 4096; |
| const int kTestSamplesPerSecond = 12345; |
| @@ -36,73 +36,77 @@ const int kTestSamplesPerSecond = 12345; |
| #define NUM_DATA_SETS 2u |
| #define NUM_SAMPLES 64u |
| -float kTestData[NUM_DATA_SETS][NUM_SAMPLES] = { |
| +// Note: Test data should be represented as 32-bit integers and copied into |
| +// ::media::AudioBus instances, rather than wrapping statically declared float |
| +// arrays. The latter method is brittle, as ::media::AudioBus requires 16-bit |
| +// alignment for internal data. |
| +const int32_t kTestData[NUM_DATA_SETS][NUM_SAMPLES] = { |
| { |
| - 0.034619, -0.62082, |
| - -0.633705, 0.530298, |
| - 0.89957, 0.864411, |
| - 0.302309, 0.262931, |
| - 0.780742, 0.0109042, |
| - -0.602219, 0.255149, |
| - -0.454606, 0.857073, |
| - 0.798388, 0.167035, |
| - 0.458046, 0.588998, |
| - 0.206043, 0.569494, |
| - 0.147803, 0.170857, |
| - 0.648797, -0.475908, |
| - -0.95678, -0.0743951, |
| - 0.524809, -0.924101, |
| - 0.65518, -0.322856, |
| - -0.721563, 0.573805, |
| - 0.451849, -0.814982, |
| - -0.364712, 0.573464, |
| - 0.537977, -0.381851, |
| - 0.53816, -0.516168, |
| - -0.0700984, 0.481362, |
| - 0.98778, 0.852158, |
| - -0.8815, -0.381422, |
| - -0.230589, 0.466485, |
| - -0.67107, 0.322319, |
| - 0.892472, -0.320276, |
| - -0.424015, 0.789646, |
| - 0.462945, 0.826759, |
| - 0.423481, 0.229418, |
| - -0.354715, -0.961272, |
| - 0.632236, -0.735754, |
| - 0.872045, -0.709881, |
| + 74343736, -1333200799, |
| + -1360871126, 1138806283, |
| + 1931811865, 1856308487, |
| + 649203634, 564640023, |
| + 1676630678, 23416591, |
| + -1293255456, 547928305, |
| + -976258952, 1840550252, |
| + 1714525174, 358704931, |
| + 983646295, 1264863573, |
| + 442473973, 1222979052, |
| + 317404525, 366912613, |
| + 1393280948, -1022004648, |
| + -2054669405, -159762261, |
| + 1127018745, -1984491787, |
| + 1406988336, -693327981, |
| + -1549544744, 1232236854, |
| + 970338338, -1750160519, |
| + -783213057, 1231504562, |
| + 1155296810, -820018779, |
| + 1155689800, -1108462340, |
| + -150535168, 1033717023, |
| + 2121241397, 1829995370, |
| + -1893006836, -819097508, |
| + -495186107, 1001768909, |
| + -1441111852, 692174781, |
| + 1916569026, -687787473, |
| + -910565280, 1695751872, |
| + 994166817, 1775451433, |
| + 909418522, 492671403, |
| + -761744663, -2064315902, |
| + 1357716471, -1580019684, |
| + 1872702377, -1524457840, |
| }, { |
| - 0.908805, 0.331583, |
| - 0.514689, 0.803509, |
| - -0.459579, 0.106887, |
| - 0.48557, 0.879381, |
| - 0.688156, 0.692105, |
| - -0.158415, -0.851542, |
| - 0.660676, -0.33735, |
| - -0.49228, 0.655911, |
| - -0.014641, 0.66197, |
| - -0.573276, 0.254189, |
| - 0.666018, 0.98153, |
| - -0.967202, -0.525433, |
| - -0.838106, -0.484799, |
| - 0.889906, -0.548501, |
| - -0.889936, -0.432651, |
| - 0.590209, 0.0801954, |
| - -0.953734, -0.994462, |
| - 0.341957, 0.565746, |
| - 0.605983, -0.152254, |
| - -0.232025, -0.54384, |
| - -0.274306, 0.275652, |
| - 0.276137, -0.367112, |
| - -0.000647, 0.68271, |
| - 0.179821, 0.646818, |
| - 0.435898, -0.669994, |
| - 0.624382, -0.752883, |
| - -0.396175, 0.776021, |
| - 0.600866, -0.2293, |
| - 0.306964, -0.252563, |
| - -0.055882, 0.480061, |
| - -0.408798, -0.405238, |
| - 0.61592, -0.16056, |
| + 1951643876, 712069070, |
| + 1105286211, 1725522438, |
| + -986938388, 229538084, |
| + 1042753634, 1888456317, |
| + 1477803757, 1486284170, |
| + -340193623, -1828672521, |
| + 1418790906, -724453609, |
| + -1057163251, 1408558147, |
| + -31441309, 1421569750, |
| + -1231100836, 545866721, |
| + 1430262764, 2107819625, |
| + -2077050480, -1128358776, |
| + -1799818931, -1041097926, |
| + 1911058583, -1177896929, |
| + -1911123008, -929110948, |
| + 1267464176, 172218310, |
| + -2048128170, -2135590884, |
| + 734347065, 1214930283, |
| + 1301338583, -326962976, |
| + -498269894, -1167887508, |
| + -589067650, 591958162, |
| + 592999692, -788367017, |
| + -1389422, 1466108561, |
| + 386162657, 1389031078, |
| + 936083827, -1438801160, |
| + 1340850135, -1616803932, |
| + -850779335, 1666492408, |
| + 1290349909, -492418001, |
| + 659200170, -542374913, |
| + -120005682, 1030923147, |
| + -877887021, -870241979, |
| + 1322678128, -344799975, |
| } |
| }; |
| @@ -110,8 +114,8 @@ float kTestData[NUM_DATA_SETS][NUM_SAMPLES] = { |
| scoped_ptr<::media::AudioBus> GetTestData(size_t index) { |
| CHECK_LT(index, NUM_DATA_SETS); |
| int frames = NUM_SAMPLES / kNumChannels; |
| - auto data = |
| - ::media::AudioBus::WrapMemory(kNumChannels, frames, kTestData[index]); |
| + auto data = ::media::AudioBus::Create(kNumChannels, frames); |
| + data->FromInterleaved(kTestData[index], frames, kBytesPerSample); |
| return data; |
| } |
| @@ -394,6 +398,8 @@ TEST_F(StreamMixerAlsaTest, OneStreamMixesProperly) { |
| const int kNumFrames = 32; |
| input->SetData(GetTestData(0)); |
| + ASSERT_EQ(mock_alsa()->data().size(), 0u); |
| + |
| // Write the stream to ALSA. |
| EXPECT_CALL(*input, GetResampledData(_, kNumFrames)); |
| EXPECT_CALL(*input, AfterWriteFrames(_)); |
| @@ -405,8 +411,7 @@ TEST_F(StreamMixerAlsaTest, OneStreamMixesProperly) { |
| ASSERT_GT(mock_alsa()->data().size(), 0u); |
| actual->FromInterleaved( |
| &(mock_alsa()->data()[0]), kNumFrames, kBytesPerSample); |
| - auto expected = GetMixedAudioData(input); |
| - CompareAudioData(*expected, *actual); |
| + CompareAudioData(input->data(), *actual); |
| } |
| TEST_F(StreamMixerAlsaTest, OneStreamIsScaledDownProperly) { |
| @@ -422,8 +427,7 @@ TEST_F(StreamMixerAlsaTest, OneStreamIsScaledDownProperly) { |
| const int kNumFrames = 32; |
| ASSERT_EQ((int)sizeof(kTestData[0]), |
| kNumChannels * kNumFrames * kBytesPerSample); |
| - auto data = |
| - ::media::AudioBus::WrapMemory(kNumChannels, kNumFrames, kTestData[0]); |
| + auto data = GetTestData(0); |
| input->SetData(std::move(data)); |
| // Set a volume multiplier on the stream. |
| @@ -497,36 +501,42 @@ TEST_F(StreamMixerAlsaTest, TwoUnscaledStreamsMixProperlyWithEdgeCases) { |
| } |
| // Create edge case data for the inputs. By mixing these two short streams, |
| - // every combination of {-1.0, 0.0, 1.0} is tested. Note that this test case |
| - // is intended to be a hand-checkable gut check. |
| + // every combination of {-(2^31), 0, 2^31-1} is tested. Note that this test |
|
cleichner
2016/01/12 18:15:27
seriously nitty nit: You have two notes in a row.
slan
2016/01/12 18:30:04
Done.
|
| + // case is intended to be a hand-checkable gut check. |
| + // Note: Test data should be represented as 32-bit integers and copied into |
| + // ::media::AudioBus instances, rather than wrapping statically declared float |
| + // arrays. The latter method is brittle, as ::media::AudioBus requires 16-bit |
| + // alignment for internal data. |
| const int kNumFrames = 3; |
| - float kEdgeData[2][8] = { |
| + const int32_t kMaxSample = std::numeric_limits<int32_t>::max(); |
| + const int32_t kMinSample = std::numeric_limits<int32_t>::min(); |
| + const int32_t kEdgeData[2][8] = { |
| { |
| - -1.0, -1.0, |
| - -1.0, 0.0, |
| - 0.0, 1.0, |
| - 0.0, 0.0, |
| + kMinSample, kMinSample, |
| + kMinSample, 0.0, |
| + 0.0, kMaxSample, |
| + 0.0, 0.0, |
| }, { |
| - -1.0, 0.0, |
| - 1.0, 0.0, |
| - 1.0, 1.0, |
| - 0.0, 0.0, |
| + kMinSample, 0.0, |
| + kMaxSample, 0.0, |
| + kMaxSample, kMaxSample, |
| + 0.0, 0.0, |
| } |
| }; |
| - // Hand-calculate the results. Index 0 is clamped to -1.0 from -2.0. Index |
| - // 5 is clamped from 2.0 to 1.0. |
| - float kResult[8] = { |
| - -1.0, -1.0, |
| - 0.0, 0.0, |
| - 1.0, 1.0, |
| - 0.0, 0.0, |
| + // Hand-calculate the results. Index 0 is clamped to -(2^31). Index 5 is |
| + // clamped to 2^31-1. |
| + const int32_t kResult[8] = { |
| + kMinSample, kMinSample, |
| + 0.0, 0.0, |
| + kMaxSample, kMaxSample, |
| + 0.0, 0.0, |
| }; |
| for (size_t i = 0; i < inputs.size(); ++i) { |
| - auto test_data = |
| - ::media::AudioBus::WrapMemory(kNumChannels, kNumFrames, kEdgeData[i]); |
| + auto test_data = ::media::AudioBus::Create(kNumChannels, kNumFrames); |
| + test_data->FromInterleaved(kEdgeData[i], kNumFrames, kBytesPerSample); |
| inputs[i]->SetData(std::move(test_data)); |
| EXPECT_CALL(*inputs[i], GetResampledData(_, kNumFrames)); |
| EXPECT_CALL(*inputs[i], AfterWriteFrames(_)); |
| @@ -536,8 +546,8 @@ TEST_F(StreamMixerAlsaTest, TwoUnscaledStreamsMixProperlyWithEdgeCases) { |
| mixer->WriteFramesForTest(); |
| // Use the hand-calculated results above. |
| - auto expected = |
| - ::media::AudioBus::WrapMemory(kNumChannels, kNumFrames, kResult); |
| + auto expected = ::media::AudioBus::Create(kNumChannels, kNumFrames); |
| + expected->FromInterleaved(kResult, kNumFrames, kBytesPerSample); |
| // Get the actual stream rendered to ALSA, and compare it against the |
| // expected stream. The stream should match exactly. |