| OLD | NEW | 
|---|
| 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 #include <stdint.h> | 5 #include <stdint.h> | 
| 6 | 6 | 
| 7 #include <memory> | 7 #include <memory> | 
| 8 | 8 | 
| 9 #include "base/environment.h" | 9 #include "base/environment.h" | 
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" | 
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 127 | 127 | 
| 128   // Convenience method which creates a default AudioInputStream object using | 128   // Convenience method which creates a default AudioInputStream object using | 
| 129   // a 10ms frame size and a sample rate which is set to the hardware sample | 129   // a 10ms frame size and a sample rate which is set to the hardware sample | 
| 130   // rate. | 130   // rate. | 
| 131   AudioInputStream* CreateDefaultAudioInputStream() { | 131   AudioInputStream* CreateDefaultAudioInputStream() { | 
| 132     int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 132     int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 
| 133     int samples_per_packet = fs / 100; | 133     int samples_per_packet = fs / 100; | 
| 134     AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 134     AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 
| 135         AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 135         AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, | 
| 136                         CHANNEL_LAYOUT_STEREO, fs, 16, samples_per_packet), | 136                         CHANNEL_LAYOUT_STEREO, fs, 16, samples_per_packet), | 
| 137         AudioDeviceDescription::kDefaultDeviceId); | 137         AudioDeviceDescription::kDefaultDeviceId, | 
|  | 138         base::Bind(&MacAudioInputTest::OnLogMessage, base::Unretained(this))); | 
| 138     EXPECT_TRUE(ais); | 139     EXPECT_TRUE(ais); | 
| 139     return ais; | 140     return ais; | 
| 140   } | 141   } | 
| 141 | 142 | 
| 142   // Convenience method which creates an AudioInputStream object with a | 143   // Convenience method which creates an AudioInputStream object with a | 
| 143   // specified channel layout. | 144   // specified channel layout. | 
| 144   AudioInputStream* CreateAudioInputStream(ChannelLayout channel_layout) { | 145   AudioInputStream* CreateAudioInputStream(ChannelLayout channel_layout) { | 
| 145     int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 146     int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 
| 146     int samples_per_packet = fs / 100; | 147     int samples_per_packet = fs / 100; | 
| 147     AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 148     AudioInputStream* ais = audio_manager_->MakeAudioInputStream( | 
| 148         AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 149         AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 
| 149                         fs, 16, samples_per_packet), | 150                         fs, 16, samples_per_packet), | 
| 150         AudioDeviceDescription::kDefaultDeviceId); | 151         AudioDeviceDescription::kDefaultDeviceId, | 
|  | 152         base::Bind(&MacAudioInputTest::OnLogMessage, base::Unretained(this))); | 
| 151     EXPECT_TRUE(ais); | 153     EXPECT_TRUE(ais); | 
| 152     return ais; | 154     return ais; | 
| 153   } | 155   } | 
| 154 | 156 | 
|  | 157   void OnLogMessage(const std::string& message) { log_message_ = message; } | 
|  | 158 | 
| 155   base::MessageLoop message_loop_; | 159   base::MessageLoop message_loop_; | 
| 156   ScopedAudioManagerPtr audio_manager_; | 160   ScopedAudioManagerPtr audio_manager_; | 
|  | 161   std::string log_message_; | 
| 157 }; | 162 }; | 
| 158 | 163 | 
| 159 // Test Create(), Close(). | 164 // Test Create(), Close(). | 
| 160 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { | 165 TEST_F(MacAudioInputTest, AUAudioInputStreamCreateAndClose) { | 
| 161   ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 166   ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 
| 162   AudioInputStream* ais = CreateDefaultAudioInputStream(); | 167   AudioInputStream* ais = CreateDefaultAudioInputStream(); | 
| 163   ais->Close(); | 168   ais->Close(); | 
| 164 } | 169 } | 
| 165 | 170 | 
| 166 // Test Open(), Close(). | 171 // Test Open(), Close(). | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 209   // estimate. | 214   // estimate. | 
| 210   base::RunLoop run_loop; | 215   base::RunLoop run_loop; | 
| 211   EXPECT_CALL(sink, OnData(ais, NotNull(), _, _)) | 216   EXPECT_CALL(sink, OnData(ais, NotNull(), _, _)) | 
| 212       .Times(AtLeast(10)) | 217       .Times(AtLeast(10)) | 
| 213       .WillRepeatedly(CheckCountAndPostQuitTask( | 218       .WillRepeatedly(CheckCountAndPostQuitTask( | 
| 214           &count, 10, &message_loop_, run_loop.QuitClosure())); | 219           &count, 10, &message_loop_, run_loop.QuitClosure())); | 
| 215   ais->Start(&sink); | 220   ais->Start(&sink); | 
| 216   run_loop.Run(); | 221   run_loop.Run(); | 
| 217   ais->Stop(); | 222   ais->Stop(); | 
| 218   ais->Close(); | 223   ais->Close(); | 
|  | 224 | 
|  | 225   EXPECT_FALSE(log_message_.empty()); | 
| 219 } | 226 } | 
| 220 | 227 | 
| 221 // Verify that recording starts and stops correctly in mono using mocked sink. | 228 // Verify that recording starts and stops correctly in mono using mocked sink. | 
| 222 TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyStereoRecording) { | 229 TEST_F(MacAudioInputTest, AUAudioInputStreamVerifyStereoRecording) { | 
| 223   ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 230   ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 
| 224 | 231 | 
| 225   int count = 0; | 232   int count = 0; | 
| 226 | 233 | 
| 227   // Create an audio input stream which records in stereo. | 234   // Create an audio input stream which records in stereo. | 
| 228   AudioInputStream* ais = CreateAudioInputStream(CHANNEL_LAYOUT_STEREO); | 235   AudioInputStream* ais = CreateAudioInputStream(CHANNEL_LAYOUT_STEREO); | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 242   // more analysis of the delay estimates are done. | 249   // more analysis of the delay estimates are done. | 
| 243   base::RunLoop run_loop; | 250   base::RunLoop run_loop; | 
| 244   EXPECT_CALL(sink, OnData(ais, NotNull(), _, _)) | 251   EXPECT_CALL(sink, OnData(ais, NotNull(), _, _)) | 
| 245       .Times(AtLeast(10)) | 252       .Times(AtLeast(10)) | 
| 246       .WillRepeatedly(CheckCountAndPostQuitTask( | 253       .WillRepeatedly(CheckCountAndPostQuitTask( | 
| 247           &count, 10, &message_loop_, run_loop.QuitClosure())); | 254           &count, 10, &message_loop_, run_loop.QuitClosure())); | 
| 248   ais->Start(&sink); | 255   ais->Start(&sink); | 
| 249   run_loop.Run(); | 256   run_loop.Run(); | 
| 250   ais->Stop(); | 257   ais->Stop(); | 
| 251   ais->Close(); | 258   ais->Close(); | 
|  | 259 | 
|  | 260   EXPECT_FALSE(log_message_.empty()); | 
| 252 } | 261 } | 
| 253 | 262 | 
| 254 // This test is intended for manual tests and should only be enabled | 263 // This test is intended for manual tests and should only be enabled | 
| 255 // when it is required to store the captured data on a local file. | 264 // when it is required to store the captured data on a local file. | 
| 256 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 265 // By default, GTest will print out YOU HAVE 1 DISABLED TEST. | 
| 257 // To include disabled tests in test execution, just invoke the test program | 266 // To include disabled tests in test execution, just invoke the test program | 
| 258 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS | 267 // with --gtest_also_run_disabled_tests or set the GTEST_ALSO_RUN_DISABLED_TESTS | 
| 259 // environment variable to a value greater than 0. | 268 // environment variable to a value greater than 0. | 
| 260 TEST_F(MacAudioInputTest, DISABLED_AUAudioInputStreamRecordToFile) { | 269 TEST_F(MacAudioInputTest, DISABLED_AUAudioInputStreamRecordToFile) { | 
| 261   ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 270   ABORT_AUDIO_TEST_IF_NOT(InputDevicesAvailable()); | 
| 262   const char* file_name = "out_stereo_10sec.pcm"; | 271   const char* file_name = "out_stereo_10sec.pcm"; | 
| 263 | 272 | 
| 264   int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 273   int fs = static_cast<int>(AUAudioInputStream::HardwareSampleRate()); | 
| 265   AudioInputStream* ais = CreateDefaultAudioInputStream(); | 274   AudioInputStream* ais = CreateDefaultAudioInputStream(); | 
| 266   EXPECT_TRUE(ais->Open()); | 275   EXPECT_TRUE(ais->Open()); | 
| 267 | 276 | 
| 268   fprintf(stderr, "               File name  : %s\n", file_name); | 277   fprintf(stderr, "               File name  : %s\n", file_name); | 
| 269   fprintf(stderr, "               Sample rate: %d\n", fs); | 278   fprintf(stderr, "               Sample rate: %d\n", fs); | 
| 270   WriteToFileAudioSink file_sink(file_name); | 279   WriteToFileAudioSink file_sink(file_name); | 
| 271   fprintf(stderr, "               >> Speak into the mic while recording...\n"); | 280   fprintf(stderr, "               >> Speak into the mic while recording...\n"); | 
| 272   ais->Start(&file_sink); | 281   ais->Start(&file_sink); | 
| 273   base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 282   base::PlatformThread::Sleep(TestTimeouts::action_timeout()); | 
| 274   ais->Stop(); | 283   ais->Stop(); | 
| 275   fprintf(stderr, "               >> Recording has stopped.\n"); | 284   fprintf(stderr, "               >> Recording has stopped.\n"); | 
| 276   ais->Close(); | 285   ais->Close(); | 
| 277 } | 286 } | 
| 278 | 287 | 
| 279 }  // namespace media | 288 }  // namespace media | 
| OLD | NEW | 
|---|