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

Side by Side Diff: media/audio/android/audio_android_unittest.cc

Issue 1304973005: Refactor AudioParameters member setting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dalecurtis comments. Created 5 years, 3 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 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #include "base/android/build_info.h" 5 #include "base/android/build_info.h"
6 #include "base/basictypes.h" 6 #include "base/basictypes.h"
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 AudioAndroidInputTest() : audio_input_stream_(NULL) {} 582 AudioAndroidInputTest() : audio_input_stream_(NULL) {}
583 583
584 protected: 584 protected:
585 const AudioParameters& audio_input_parameters() { 585 const AudioParameters& audio_input_parameters() {
586 return audio_input_parameters_; 586 return audio_input_parameters_;
587 } 587 }
588 588
589 AudioParameters GetInputStreamParameters() { 589 AudioParameters GetInputStreamParameters() {
590 GetDefaultInputStreamParametersOnAudioThread(); 590 GetDefaultInputStreamParametersOnAudioThread();
591 591
592 AudioParameters params = audio_input_parameters();
592 // Override the platform effects setting to use the AudioRecord or OpenSLES 593 // Override the platform effects setting to use the AudioRecord or OpenSLES
593 // path as requested. 594 // path as requested.
594 int effects = GetParam() ? AudioParameters::ECHO_CANCELLER : 595 params.set_effects(GetParam() ? AudioParameters::ECHO_CANCELLER
595 AudioParameters::NO_EFFECTS; 596 : AudioParameters::NO_EFFECTS);
596 AudioParameters params(audio_input_parameters().format(),
597 audio_input_parameters().channel_layout(),
598 audio_input_parameters().sample_rate(),
599 audio_input_parameters().bits_per_sample(),
600 audio_input_parameters().frames_per_buffer(),
601 effects);
602 return params; 597 return params;
603 } 598 }
604 599
605 void GetDefaultInputStreamParametersOnAudioThread() { 600 void GetDefaultInputStreamParametersOnAudioThread() {
606 RunOnAudioThread( 601 RunOnAudioThread(
607 base::Bind(&AudioAndroidInputTest::GetDefaultInputStreamParameters, 602 base::Bind(&AudioAndroidInputTest::GetDefaultInputStreamParameters,
608 base::Unretained(this))); 603 base::Unretained(this)));
609 } 604 }
610 605
611 void MakeAudioInputStreamOnAudioThread(const AudioParameters& params) { 606 void MakeAudioInputStreamOnAudioThread(const AudioParameters& params) {
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacks) { 784 TEST_P(AudioAndroidInputTest, DISABLED_StartInputStreamCallbacks) {
790 AudioParameters native_params = GetInputStreamParameters(); 785 AudioParameters native_params = GetInputStreamParameters();
791 StartInputStreamCallbacks(native_params); 786 StartInputStreamCallbacks(native_params);
792 } 787 }
793 788
794 // Start input streaming using non default input parameters and ensure that the 789 // Start input streaming using non default input parameters and ensure that the
795 // callback sequence is sane. The only change we make in this test is to select 790 // callback sequence is sane. The only change we make in this test is to select
796 // a 10ms buffer size instead of the default size. 791 // a 10ms buffer size instead of the default size.
797 TEST_P(AudioAndroidInputTest, 792 TEST_P(AudioAndroidInputTest,
798 DISABLED_StartInputStreamCallbacksNonDefaultParameters) { 793 DISABLED_StartInputStreamCallbacksNonDefaultParameters) {
799 AudioParameters native_params = GetInputStreamParameters(); 794 AudioParameters params = GetInputStreamParameters();
800 AudioParameters params(native_params.format(), 795 params.set_frames_per_buffer(params.sample_rate() / 100);
801 native_params.channel_layout(),
802 native_params.sample_rate(),
803 native_params.bits_per_sample(),
804 native_params.sample_rate() / 100,
805 native_params.effects());
806 StartInputStreamCallbacks(params); 796 StartInputStreamCallbacks(params);
807 } 797 }
808 798
809 // Start output streaming using default output parameters and ensure that the 799 // Start output streaming using default output parameters and ensure that the
810 // callback sequence is sane. 800 // callback sequence is sane.
811 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacks) { 801 TEST_F(AudioAndroidOutputTest, StartOutputStreamCallbacks) {
812 GetDefaultOutputStreamParametersOnAudioThread(); 802 GetDefaultOutputStreamParametersOnAudioThread();
813 StartOutputStreamCallbacks(audio_output_parameters()); 803 StartOutputStreamCallbacks(audio_output_parameters());
814 } 804 }
815 805
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 // automatized test on bots. 916 // automatized test on bots.
927 TEST_P(AudioAndroidInputTest, 917 TEST_P(AudioAndroidInputTest,
928 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) { 918 DISABLED_RunSymmetricInputAndOutputStreamsInFullDuplex) {
929 // Get native audio parameters for the input side. 919 // Get native audio parameters for the input side.
930 AudioParameters default_input_params = GetInputStreamParameters(); 920 AudioParameters default_input_params = GetInputStreamParameters();
931 921
932 // Modify the parameters so that both input and output can use the same 922 // Modify the parameters so that both input and output can use the same
933 // parameters by selecting 10ms as buffer size. This will also ensure that 923 // parameters by selecting 10ms as buffer size. This will also ensure that
934 // the output stream will be a mono stream since mono is default for input 924 // the output stream will be a mono stream since mono is default for input
935 // audio on Android. 925 // audio on Android.
936 AudioParameters io_params(default_input_params.format(), 926 AudioParameters io_params = default_input_params;
937 default_input_params.channel_layout(), 927 default_input_params.set_frames_per_buffer(io_params.sample_rate() / 100);
938 ChannelLayoutToChannelCount(
939 default_input_params.channel_layout()),
940 default_input_params.sample_rate(),
941 default_input_params.bits_per_sample(),
942 default_input_params.sample_rate() / 100,
943 default_input_params.effects());
944 DVLOG(1) << io_params; 928 DVLOG(1) << io_params;
945 929
946 // Create input and output streams using the common audio parameters. 930 // Create input and output streams using the common audio parameters.
947 MakeAudioInputStreamOnAudioThread(io_params); 931 MakeAudioInputStreamOnAudioThread(io_params);
948 MakeAudioOutputStreamOnAudioThread(io_params); 932 MakeAudioOutputStreamOnAudioThread(io_params);
949 933
950 FullDuplexAudioSinkSource full_duplex(io_params); 934 FullDuplexAudioSinkSource full_duplex(io_params);
951 935
952 // Start a full duplex audio session and print out estimates of the extra 936 // Start a full duplex audio session and print out estimates of the extra
953 // delay we should expect from the FIFO. If real-time delay measurements are 937 // delay we should expect from the FIFO. If real-time delay measurements are
954 // performed, the result should be reduced by this extra delay since it is 938 // performed, the result should be reduced by this extra delay since it is
955 // something that has been added by the test. 939 // something that has been added by the test.
956 OpenAndStartAudioInputStreamOnAudioThread(&full_duplex); 940 OpenAndStartAudioInputStreamOnAudioThread(&full_duplex);
957 OpenAndStartAudioOutputStreamOnAudioThread(&full_duplex); 941 OpenAndStartAudioOutputStreamOnAudioThread(&full_duplex);
958 DVLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated " 942 DVLOG(1) << "HINT: an estimate of the extra FIFO delay will be updated "
959 << "once per second during this test."; 943 << "once per second during this test.";
960 DVLOG(0) << ">> Speak into the mic and listen to the audio in loopback..."; 944 DVLOG(0) << ">> Speak into the mic and listen to the audio in loopback...";
961 fflush(stdout); 945 fflush(stdout);
962 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20)); 946 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(20));
963 printf("\n"); 947 printf("\n");
964 StopAndCloseAudioOutputStreamOnAudioThread(); 948 StopAndCloseAudioOutputStreamOnAudioThread();
965 StopAndCloseAudioInputStreamOnAudioThread(); 949 StopAndCloseAudioInputStreamOnAudioThread();
966 } 950 }
967 951
968 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest, 952 INSTANTIATE_TEST_CASE_P(AudioAndroidInputTest, AudioAndroidInputTest,
969 testing::ValuesIn(RunAudioRecordInputPathTests())); 953 testing::ValuesIn(RunAudioRecordInputPathTests()));
970 954
971 } // namespace media 955 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698