| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/environment.h" | 6 #include "base/environment.h" |
| 7 #include "base/test/test_timeouts.h" | 7 #include "base/test/test_timeouts.h" |
| 8 #include "base/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
| 9 #include "media/audio/audio_io.h" | 9 #include "media/audio/audio_io.h" |
| 10 #include "media/audio/audio_manager.h" | 10 #include "media/audio/audio_manager.h" |
| 11 #include "media/audio/mac/audio_low_latency_input_mac.h" | 11 #include "media/audio/mac/audio_low_latency_input_mac.h" |
| 12 #include "media/base/seekable_buffer.h" | 12 #include "media/base/seekable_buffer.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 using ::testing::_; |
| 16 using ::testing::AnyNumber; | 17 using ::testing::AnyNumber; |
| 17 using ::testing::Between; | 18 using ::testing::Between; |
| 19 using ::testing::Ge; |
| 18 using ::testing::NotNull; | 20 using ::testing::NotNull; |
| 19 | 21 |
| 20 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { | 22 class MockAudioInputCallback : public AudioInputStream::AudioInputCallback { |
| 21 public: | 23 public: |
| 22 MOCK_METHOD4(OnData, void(AudioInputStream* stream, | 24 MOCK_METHOD4(OnData, void(AudioInputStream* stream, |
| 23 const uint8* src, uint32 size, | 25 const uint8* src, uint32 size, |
| 24 uint32 hardware_delay_bytes)); | 26 uint32 hardware_delay_bytes)); |
| 25 MOCK_METHOD1(OnClose, void(AudioInputStream* stream)); | 27 MOCK_METHOD1(OnClose, void(AudioInputStream* stream)); |
| 26 MOCK_METHOD2(OnError, void(AudioInputStream* stream, int code)); | 28 MOCK_METHOD2(OnError, void(AudioInputStream* stream, int code)); |
| 27 }; | 29 }; |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 int samples_per_packet = fs / 100; | 210 int samples_per_packet = fs / 100; |
| 209 int bits_per_sample = 16; | 211 int bits_per_sample = 16; |
| 210 uint32 bytes_per_packet = samples_per_packet * (bits_per_sample / 8); | 212 uint32 bytes_per_packet = samples_per_packet * (bits_per_sample / 8); |
| 211 | 213 |
| 212 MockAudioInputCallback sink; | 214 MockAudioInputCallback sink; |
| 213 | 215 |
| 214 // We use 10ms packets and will run the test for ~100ms. Given that the | 216 // We use 10ms packets and will run the test for ~100ms. Given that the |
| 215 // startup sequence takes some time, it is reasonable to expect 5-10 | 217 // startup sequence takes some time, it is reasonable to expect 5-10 |
| 216 // callbacks in this time period. All should contain valid packets of | 218 // callbacks in this time period. All should contain valid packets of |
| 217 // the same size. | 219 // the same size. |
| 218 EXPECT_CALL(sink, OnData(ais, NotNull(), bytes_per_packet, bytes_per_packet)) | 220 EXPECT_CALL(sink, OnData(ais, NotNull(), bytes_per_packet, |
| 221 Ge(bytes_per_packet))) |
| 219 .Times(Between(5, 10)); | 222 .Times(Between(5, 10)); |
| 220 | 223 |
| 221 ais->Start(&sink); | 224 ais->Start(&sink); |
| 222 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms()); | 225 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms()); |
| 223 ais->Stop(); | 226 ais->Stop(); |
| 224 | 227 |
| 225 // Verify that the sink receieves OnClose() call when calling Close(). | 228 // Verify that the sink receieves OnClose() call when calling Close(). |
| 226 EXPECT_CALL(sink, OnClose(ais)) | 229 EXPECT_CALL(sink, OnClose(ais)) |
| 227 .Times(1); | 230 .Times(1); |
| 228 ais->Close(); | 231 ais->Close(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 241 int samples_per_packet = fs / 100; | 244 int samples_per_packet = fs / 100; |
| 242 int bits_per_sample = 16; | 245 int bits_per_sample = 16; |
| 243 uint32 bytes_per_packet = 2 * samples_per_packet * (bits_per_sample / 8); | 246 uint32 bytes_per_packet = 2 * samples_per_packet * (bits_per_sample / 8); |
| 244 | 247 |
| 245 MockAudioInputCallback sink; | 248 MockAudioInputCallback sink; |
| 246 | 249 |
| 247 // We use 10ms packets and will run the test for ~100ms. Given that the | 250 // We use 10ms packets and will run the test for ~100ms. Given that the |
| 248 // startup sequence takes some time, it is reasonable to expect 5-10 | 251 // startup sequence takes some time, it is reasonable to expect 5-10 |
| 249 // callbacks in this time period. All should contain valid packets of | 252 // callbacks in this time period. All should contain valid packets of |
| 250 // the same size. | 253 // the same size. |
| 251 EXPECT_CALL(sink, OnData(ais, NotNull(), bytes_per_packet, bytes_per_packet)) | 254 EXPECT_CALL(sink, OnData(ais, NotNull(), bytes_per_packet, |
| 255 Ge(bytes_per_packet))) |
| 252 .Times(Between(5, 10)); | 256 .Times(Between(5, 10)); |
| 253 | 257 |
| 254 ais->Start(&sink); | 258 ais->Start(&sink); |
| 255 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms()); | 259 base::PlatformThread::Sleep(TestTimeouts::tiny_timeout_ms()); |
| 256 ais->Stop(); | 260 ais->Stop(); |
| 257 | 261 |
| 258 // Verify that the sink receieves OnClose() call when calling Close(). | 262 // Verify that the sink receieves OnClose() call when calling Close(). |
| 259 EXPECT_CALL(sink, OnClose(ais)) | 263 EXPECT_CALL(sink, OnClose(ais)) |
| 260 .Times(1); | 264 .Times(1); |
| 261 ais->Close(); | 265 ais->Close(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 280 fprintf(stderr, " Sample rate: %d\n", fs); | 284 fprintf(stderr, " Sample rate: %d\n", fs); |
| 281 WriteToFileAudioSink file_sink(file_name); | 285 WriteToFileAudioSink file_sink(file_name); |
| 282 fprintf(stderr, " >> Speak into the mic while recording...\n"); | 286 fprintf(stderr, " >> Speak into the mic while recording...\n"); |
| 283 ais->Start(&file_sink); | 287 ais->Start(&file_sink); |
| 284 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); | 288 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); |
| 285 ais->Stop(); | 289 ais->Stop(); |
| 286 fprintf(stderr, " >> Recording has stopped.\n"); | 290 fprintf(stderr, " >> Recording has stopped.\n"); |
| 287 ais->Close(); | 291 ais->Close(); |
| 288 } | 292 } |
| 289 | 293 |
| OLD | NEW |