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

Side by Side Diff: webrtc/modules/audio_device/android/audio_device_unittest.cc

Issue 1316523002: Convert channel counts to size_t. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Fix compile Created 4 years, 11 months 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 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 play_count_(0), 376 play_count_(0),
377 rec_count_(0), 377 rec_count_(0),
378 audio_stream_(nullptr) {} 378 audio_stream_(nullptr) {}
379 379
380 virtual ~MockAudioTransport() {} 380 virtual ~MockAudioTransport() {}
381 381
382 MOCK_METHOD10(RecordedDataIsAvailable, 382 MOCK_METHOD10(RecordedDataIsAvailable,
383 int32_t(const void* audioSamples, 383 int32_t(const void* audioSamples,
384 const size_t nSamples, 384 const size_t nSamples,
385 const size_t nBytesPerSample, 385 const size_t nBytesPerSample,
386 const uint8_t nChannels, 386 const size_t nChannels,
387 const uint32_t samplesPerSec, 387 const uint32_t samplesPerSec,
388 const uint32_t totalDelayMS, 388 const uint32_t totalDelayMS,
389 const int32_t clockDrift, 389 const int32_t clockDrift,
390 const uint32_t currentMicLevel, 390 const uint32_t currentMicLevel,
391 const bool keyPressed, 391 const bool keyPressed,
392 uint32_t& newMicLevel)); 392 uint32_t& newMicLevel));
393 MOCK_METHOD8(NeedMorePlayData, 393 MOCK_METHOD8(NeedMorePlayData,
394 int32_t(const size_t nSamples, 394 int32_t(const size_t nSamples,
395 const size_t nBytesPerSample, 395 const size_t nBytesPerSample,
396 const uint8_t nChannels, 396 const size_t nChannels,
397 const uint32_t samplesPerSec, 397 const uint32_t samplesPerSec,
398 void* audioSamples, 398 void* audioSamples,
399 size_t& nSamplesOut, 399 size_t& nSamplesOut,
400 int64_t* elapsed_time_ms, 400 int64_t* elapsed_time_ms,
401 int64_t* ntp_time_ms)); 401 int64_t* ntp_time_ms));
402 402
403 // Set default actions of the mock object. We are delegating to fake 403 // Set default actions of the mock object. We are delegating to fake
404 // implementations (of AudioStreamInterface) here. 404 // implementations (of AudioStreamInterface) here.
405 void HandleCallbacks(EventWrapper* test_is_done, 405 void HandleCallbacks(EventWrapper* test_is_done,
406 AudioStreamInterface* audio_stream, 406 AudioStreamInterface* audio_stream,
407 int num_callbacks) { 407 int num_callbacks) {
408 test_is_done_ = test_is_done; 408 test_is_done_ = test_is_done;
409 audio_stream_ = audio_stream; 409 audio_stream_ = audio_stream;
410 num_callbacks_ = num_callbacks; 410 num_callbacks_ = num_callbacks;
411 if (play_mode()) { 411 if (play_mode()) {
412 ON_CALL(*this, NeedMorePlayData(_, _, _, _, _, _, _, _)) 412 ON_CALL(*this, NeedMorePlayData(_, _, _, _, _, _, _, _))
413 .WillByDefault( 413 .WillByDefault(
414 Invoke(this, &MockAudioTransport::RealNeedMorePlayData)); 414 Invoke(this, &MockAudioTransport::RealNeedMorePlayData));
415 } 415 }
416 if (rec_mode()) { 416 if (rec_mode()) {
417 ON_CALL(*this, RecordedDataIsAvailable(_, _, _, _, _, _, _, _, _, _)) 417 ON_CALL(*this, RecordedDataIsAvailable(_, _, _, _, _, _, _, _, _, _))
418 .WillByDefault( 418 .WillByDefault(
419 Invoke(this, &MockAudioTransport::RealRecordedDataIsAvailable)); 419 Invoke(this, &MockAudioTransport::RealRecordedDataIsAvailable));
420 } 420 }
421 } 421 }
422 422
423 int32_t RealRecordedDataIsAvailable(const void* audioSamples, 423 int32_t RealRecordedDataIsAvailable(const void* audioSamples,
424 const size_t nSamples, 424 const size_t nSamples,
425 const size_t nBytesPerSample, 425 const size_t nBytesPerSample,
426 const uint8_t nChannels, 426 const size_t nChannels,
427 const uint32_t samplesPerSec, 427 const uint32_t samplesPerSec,
428 const uint32_t totalDelayMS, 428 const uint32_t totalDelayMS,
429 const int32_t clockDrift, 429 const int32_t clockDrift,
430 const uint32_t currentMicLevel, 430 const uint32_t currentMicLevel,
431 const bool keyPressed, 431 const bool keyPressed,
432 uint32_t& newMicLevel) { 432 uint32_t& newMicLevel) {
433 EXPECT_TRUE(rec_mode()) << "No test is expecting these callbacks."; 433 EXPECT_TRUE(rec_mode()) << "No test is expecting these callbacks.";
434 rec_count_++; 434 rec_count_++;
435 // Process the recorded audio stream if an AudioStreamInterface 435 // Process the recorded audio stream if an AudioStreamInterface
436 // implementation exists. 436 // implementation exists.
437 if (audio_stream_) { 437 if (audio_stream_) {
438 audio_stream_->Write(audioSamples, nSamples); 438 audio_stream_->Write(audioSamples, nSamples);
439 } 439 }
440 if (ReceivedEnoughCallbacks()) { 440 if (ReceivedEnoughCallbacks()) {
441 test_is_done_->Set(); 441 test_is_done_->Set();
442 } 442 }
443 return 0; 443 return 0;
444 } 444 }
445 445
446 int32_t RealNeedMorePlayData(const size_t nSamples, 446 int32_t RealNeedMorePlayData(const size_t nSamples,
447 const size_t nBytesPerSample, 447 const size_t nBytesPerSample,
448 const uint8_t nChannels, 448 const size_t nChannels,
449 const uint32_t samplesPerSec, 449 const uint32_t samplesPerSec,
450 void* audioSamples, 450 void* audioSamples,
451 size_t& nSamplesOut, 451 size_t& nSamplesOut,
452 int64_t* elapsed_time_ms, 452 int64_t* elapsed_time_ms,
453 int64_t* ntp_time_ms) { 453 int64_t* ntp_time_ms) {
454 EXPECT_TRUE(play_mode()) << "No test is expecting these callbacks."; 454 EXPECT_TRUE(play_mode()) << "No test is expecting these callbacks.";
455 play_count_++; 455 play_count_++;
456 nSamplesOut = nSamples; 456 nSamplesOut = nSamples;
457 // Read (possibly processed) audio stream samples to be played out if an 457 // Read (possibly processed) audio stream samples to be played out if an
458 // AudioStreamInterface implementation exists. 458 // AudioStreamInterface implementation exists.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 virtual ~AudioDeviceTest() { 514 virtual ~AudioDeviceTest() {
515 EXPECT_EQ(0, audio_device_->Terminate()); 515 EXPECT_EQ(0, audio_device_->Terminate());
516 } 516 }
517 517
518 int playout_sample_rate() const { 518 int playout_sample_rate() const {
519 return playout_parameters_.sample_rate(); 519 return playout_parameters_.sample_rate();
520 } 520 }
521 int record_sample_rate() const { 521 int record_sample_rate() const {
522 return record_parameters_.sample_rate(); 522 return record_parameters_.sample_rate();
523 } 523 }
524 int playout_channels() const { 524 size_t playout_channels() const {
525 return playout_parameters_.channels(); 525 return playout_parameters_.channels();
526 } 526 }
527 int record_channels() const { 527 size_t record_channels() const {
528 return record_parameters_.channels(); 528 return record_parameters_.channels();
529 } 529 }
530 size_t playout_frames_per_10ms_buffer() const { 530 size_t playout_frames_per_10ms_buffer() const {
531 return playout_parameters_.frames_per_10ms_buffer(); 531 return playout_parameters_.frames_per_10ms_buffer();
532 } 532 }
533 size_t record_frames_per_10ms_buffer() const { 533 size_t record_frames_per_10ms_buffer() const {
534 return record_parameters_.frames_per_10ms_buffer(); 534 return record_parameters_.frames_per_10ms_buffer();
535 } 535 }
536 536
537 int total_delay_ms() const { 537 int total_delay_ms() const {
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 test_is_done_->Wait(kTestTimeOutInMilliseconds); 924 test_is_done_->Wait(kTestTimeOutInMilliseconds);
925 StopRecording(); 925 StopRecording();
926 StopPlayout(); 926 StopPlayout();
927 } 927 }
928 928
929 // Start playout and read audio from an external PCM file when the audio layer 929 // Start playout and read audio from an external PCM file when the audio layer
930 // asks for data to play out. Real audio is played out in this test but it does 930 // asks for data to play out. Real audio is played out in this test but it does
931 // not contain any explicit verification that the audio quality is perfect. 931 // not contain any explicit verification that the audio quality is perfect.
932 TEST_F(AudioDeviceTest, RunPlayoutWithFileAsSource) { 932 TEST_F(AudioDeviceTest, RunPlayoutWithFileAsSource) {
933 // TODO(henrika): extend test when mono output is supported. 933 // TODO(henrika): extend test when mono output is supported.
934 EXPECT_EQ(1, playout_channels()); 934 EXPECT_EQ(1u, playout_channels());
935 NiceMock<MockAudioTransport> mock(kPlayout); 935 NiceMock<MockAudioTransport> mock(kPlayout);
936 const int num_callbacks = kFilePlayTimeInSec * kNumCallbacksPerSecond; 936 const int num_callbacks = kFilePlayTimeInSec * kNumCallbacksPerSecond;
937 std::string file_name = GetFileName(playout_sample_rate()); 937 std::string file_name = GetFileName(playout_sample_rate());
938 rtc::scoped_ptr<FileAudioStream> file_audio_stream( 938 rtc::scoped_ptr<FileAudioStream> file_audio_stream(
939 new FileAudioStream(num_callbacks, file_name, playout_sample_rate())); 939 new FileAudioStream(num_callbacks, file_name, playout_sample_rate()));
940 mock.HandleCallbacks(test_is_done_.get(), 940 mock.HandleCallbacks(test_is_done_.get(),
941 file_audio_stream.get(), 941 file_audio_stream.get(),
942 num_callbacks); 942 num_callbacks);
943 // SetMaxPlayoutVolume(); 943 // SetMaxPlayoutVolume();
944 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock)); 944 EXPECT_EQ(0, audio_device()->RegisterAudioCallback(&mock));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 StopPlayout(); 1009 StopPlayout();
1010 StopRecording(); 1010 StopRecording();
1011 // Verify that the correct number of transmitted impulses are detected. 1011 // Verify that the correct number of transmitted impulses are detected.
1012 EXPECT_EQ(latency_audio_stream->num_latency_values(), 1012 EXPECT_EQ(latency_audio_stream->num_latency_values(),
1013 static_cast<size_t>( 1013 static_cast<size_t>(
1014 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1)); 1014 kImpulseFrequencyInHz * kMeasureLatencyTimeInSec - 1));
1015 latency_audio_stream->PrintResults(); 1015 latency_audio_stream->PrintResults();
1016 } 1016 }
1017 1017
1018 } // namespace webrtc 1018 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698