Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: media/base/audio_renderer_mixer_unittest.cc

Issue 1487983002: Forward the number of skipped frames by the OS in audio playout. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review fixes, compile fixes, rebase. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 22 matching lines...) Expand all
33 const int kLowLatencyBufferSize = 256; 33 const int kLowLatencyBufferSize = 256;
34 34
35 // Number of full sine wave cycles for each Render() call. 35 // Number of full sine wave cycles for each Render() call.
36 const int kSineCycles = 4; 36 const int kSineCycles = 4;
37 37
38 // Default device ID. 38 // Default device ID.
39 const std::string kDefaultDeviceId; 39 const std::string kDefaultDeviceId;
40 const url::Origin kDefaultSecurityOrigin; 40 const url::Origin kDefaultSecurityOrigin;
41 41
42 // Input sample frequencies for testing. 42 // Input sample frequencies for testing.
43 std::vector<int> kTestInputLower(1, 44100); 43 std::vector<int> kTestInputLower(1, 44100);
tommi (sloooow) - chröme 2015/12/08 10:08:09 fyi (I know this is only a rebase, but since this
o1ka 2015/12/08 10:57:45 This one I mine, I'll fix it (https://code.google.
Henrik Grunell 2015/12/08 11:12:32 Thanks for pointing out this should be avoided in
44 std::vector<int> kTestInputHigher(1, 48000); 44 std::vector<int> kTestInputHigher(1, 48000);
45 const int kSampleRates[] = {22050, 44100, 48000}; 45 const int kSampleRates[] = {22050, 44100, 48000};
46 std::vector<int> kTestInput3Rates(kSampleRates, 46 std::vector<int> kTestInput3Rates(kSampleRates,
47 kSampleRates + 47 kSampleRates +
48 sizeof(kSampleRates) / 48 sizeof(kSampleRates) /
49 sizeof(kSampleRates[0])); 49 sizeof(kSampleRates[0]));
50 50
51 // Tuple of <input sampling rates, output sampling rate, epsilon>. 51 // Tuple of <input sampling rates, output sampling rate, epsilon>.
52 typedef std::tr1::tuple<std::vector<int>, int, double> 52 typedef std::tr1::tuple<std::vector<int>, int, double>
53 AudioRendererMixerTestData; 53 AudioRendererMixerTestData;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (half_fill_) { 155 if (half_fill_) {
156 for (size_t i = 0; i < fake_callbacks_.size(); ++i) 156 for (size_t i = 0; i < fake_callbacks_.size(); ++i)
157 fake_callbacks_[i]->set_half_fill(true); 157 fake_callbacks_[i]->set_half_fill(true);
158 expected_callback_->set_half_fill(true); 158 expected_callback_->set_half_fill(true);
159 // Initialize the AudioBus completely or we'll run into Valgrind problems 159 // Initialize the AudioBus completely or we'll run into Valgrind problems
160 // during the verification step below. 160 // during the verification step below.
161 expected_audio_bus_->Zero(); 161 expected_audio_bus_->Zero();
162 } 162 }
163 163
164 // Render actual audio data. 164 // Render actual audio data.
165 int frames = mixer_callback_->Render(audio_bus_.get(), 0); 165 int frames = mixer_callback_->Render(audio_bus_.get(), 0, 0);
166 if (frames != audio_bus_->frames()) 166 if (frames != audio_bus_->frames())
167 return false; 167 return false;
168 168
169 // Render expected audio data (without scaling). 169 // Render expected audio data (without scaling).
170 expected_callback_->Render(expected_audio_bus_.get(), 0); 170 expected_callback_->Render(expected_audio_bus_.get(), 0, 0);
171 171
172 if (half_fill_) { 172 if (half_fill_) {
173 // In this case, just verify that every frame was initialized, this will 173 // In this case, just verify that every frame was initialized, this will
174 // only fail under tooling such as valgrind. 174 // only fail under tooling such as valgrind.
175 return ValidateAudioData( 175 return ValidateAudioData(
176 0, frames, 0, std::numeric_limits<double>::max()); 176 0, frames, 0, std::numeric_limits<double>::max());
177 } else { 177 } else {
178 return ValidateAudioData(0, frames, scale); 178 return ValidateAudioData(0, frames, scale);
179 } 179 }
180 } 180 }
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 484
485 base::WaitableEvent pause_event(true, false); 485 base::WaitableEvent pause_event(true, false);
486 EXPECT_CALL(*sink_.get(), Pause()).Times(2) 486 EXPECT_CALL(*sink_.get(), Pause()).Times(2)
487 .WillRepeatedly(SignalEvent(&pause_event)); 487 .WillRepeatedly(SignalEvent(&pause_event));
488 InitializeInputs(1); 488 InitializeInputs(1);
489 489
490 // Ensure never playing the input results in a sink pause. 490 // Ensure never playing the input results in a sink pause.
491 const base::TimeDelta kSleepTime = base::TimeDelta::FromMilliseconds(100); 491 const base::TimeDelta kSleepTime = base::TimeDelta::FromMilliseconds(100);
492 base::TimeTicks start_time = base::TimeTicks::Now(); 492 base::TimeTicks start_time = base::TimeTicks::Now();
493 while (!pause_event.IsSignaled()) { 493 while (!pause_event.IsSignaled()) {
494 mixer_callback_->Render(audio_bus_.get(), 0); 494 mixer_callback_->Render(audio_bus_.get(), 0, 0);
495 base::PlatformThread::Sleep(kSleepTime); 495 base::PlatformThread::Sleep(kSleepTime);
496 ASSERT_TRUE(base::TimeTicks::Now() - start_time < kTestTimeout); 496 ASSERT_TRUE(base::TimeTicks::Now() - start_time < kTestTimeout);
497 } 497 }
498 pause_event.Reset(); 498 pause_event.Reset();
499 499
500 // Playing the input for the first time should cause a sink play. 500 // Playing the input for the first time should cause a sink play.
501 mixer_inputs_[0]->Start(); 501 mixer_inputs_[0]->Start();
502 EXPECT_CALL(*sink_.get(), Play()); 502 EXPECT_CALL(*sink_.get(), Play());
503 mixer_inputs_[0]->Play(); 503 mixer_inputs_[0]->Play();
504 mixer_inputs_[0]->Pause(); 504 mixer_inputs_[0]->Pause();
505 505
506 // Ensure once the input is paused the sink eventually pauses. 506 // Ensure once the input is paused the sink eventually pauses.
507 start_time = base::TimeTicks::Now(); 507 start_time = base::TimeTicks::Now();
508 while (!pause_event.IsSignaled()) { 508 while (!pause_event.IsSignaled()) {
509 mixer_callback_->Render(audio_bus_.get(), 0); 509 mixer_callback_->Render(audio_bus_.get(), 0, 0);
510 base::PlatformThread::Sleep(kSleepTime); 510 base::PlatformThread::Sleep(kSleepTime);
511 ASSERT_TRUE(base::TimeTicks::Now() - start_time < kTestTimeout); 511 ASSERT_TRUE(base::TimeTicks::Now() - start_time < kTestTimeout);
512 } 512 }
513 513
514 mixer_inputs_[0]->Stop(); 514 mixer_inputs_[0]->Stop();
515 } 515 }
516 516
517 INSTANTIATE_TEST_CASE_P( 517 INSTANTIATE_TEST_CASE_P(
518 AudioRendererMixerTest, 518 AudioRendererMixerTest,
519 AudioRendererMixerTest, 519 AudioRendererMixerTest,
(...skipping 21 matching lines...) Expand all
541 // parameter set. 541 // parameter set.
542 INSTANTIATE_TEST_CASE_P( 542 INSTANTIATE_TEST_CASE_P(
543 AudioRendererMixerBehavioralTest, 543 AudioRendererMixerBehavioralTest,
544 AudioRendererMixerBehavioralTest, 544 AudioRendererMixerBehavioralTest,
545 testing::ValuesIn(std::vector<AudioRendererMixerTestData>( 545 testing::ValuesIn(std::vector<AudioRendererMixerTestData>(
546 1, 546 1,
547 std::tr1::make_tuple(kTestInputLower, 547 std::tr1::make_tuple(kTestInputLower,
548 kTestInputLower[0], 548 kTestInputLower[0],
549 0.00000048)))); 549 0.00000048))));
550 } // namespace media 550 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698