| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 } | 45 } |
| 46 | 46 |
| 47 class MockUnifiedSourceCallback | 47 class MockUnifiedSourceCallback |
| 48 : public AudioOutputStream::AudioSourceCallback { | 48 : public AudioOutputStream::AudioSourceCallback { |
| 49 public: | 49 public: |
| 50 MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, | 50 MOCK_METHOD2(OnMoreData, int(AudioBus* audio_bus, |
| 51 AudioBuffersState buffers_state)); | 51 AudioBuffersState buffers_state)); |
| 52 MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, | 52 MOCK_METHOD3(OnMoreIOData, int(AudioBus* source, |
| 53 AudioBus* dest, | 53 AudioBus* dest, |
| 54 AudioBuffersState buffers_state)); | 54 AudioBuffersState buffers_state)); |
| 55 MOCK_METHOD2(OnError, void(AudioOutputStream* stream, int code)); | 55 MOCK_METHOD1(OnError, void(AudioOutputStream* stream)); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // AudioOutputStream::AudioSourceCallback implementation which enables audio | 58 // AudioOutputStream::AudioSourceCallback implementation which enables audio |
| 59 // play-through. It also creates a text file that contains times between two | 59 // play-through. It also creates a text file that contains times between two |
| 60 // successive callbacks. Units are in milliseconds. This file can be used for | 60 // successive callbacks. Units are in milliseconds. This file can be used for |
| 61 // off-line analysis of the callback sequence. | 61 // off-line analysis of the callback sequence. |
| 62 class UnifiedSourceCallback : public AudioOutputStream::AudioSourceCallback { | 62 class UnifiedSourceCallback : public AudioOutputStream::AudioSourceCallback { |
| 63 public: | 63 public: |
| 64 explicit UnifiedSourceCallback() | 64 explicit UnifiedSourceCallback() |
| 65 : previous_call_time_(base::Time::Now()), | 65 : previous_call_time_(base::Time::Now()), |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 if (elements_to_write_ < kMaxDeltaSamples) { | 102 if (elements_to_write_ < kMaxDeltaSamples) { |
| 103 delta_times_[elements_to_write_] = diff; | 103 delta_times_[elements_to_write_] = diff; |
| 104 ++elements_to_write_; | 104 ++elements_to_write_; |
| 105 } | 105 } |
| 106 | 106 |
| 107 // Play out the recorded audio samples in loop back. | 107 // Play out the recorded audio samples in loop back. |
| 108 source->CopyTo(dest); | 108 source->CopyTo(dest); |
| 109 return source->frames(); | 109 return source->frames(); |
| 110 }; | 110 }; |
| 111 | 111 |
| 112 virtual void OnError(AudioOutputStream* stream, int code) { | 112 virtual void OnError(AudioOutputStream* stream) { |
| 113 NOTREACHED(); | 113 NOTREACHED(); |
| 114 } | 114 } |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 base::Time previous_call_time_; | 117 base::Time previous_call_time_; |
| 118 scoped_array<int> delta_times_; | 118 scoped_array<int> delta_times_; |
| 119 FILE* text_file_; | 119 FILE* text_file_; |
| 120 size_t elements_to_write_; | 120 size_t elements_to_write_; |
| 121 }; | 121 }; |
| 122 | 122 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 TEST(WASAPIUnifiedStreamTest, OpenStartAndClose) { | 191 TEST(WASAPIUnifiedStreamTest, OpenStartAndClose) { |
| 192 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 192 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 193 if (!CanRunUnifiedAudioTests(audio_manager.get())) | 193 if (!CanRunUnifiedAudioTests(audio_manager.get())) |
| 194 return; | 194 return; |
| 195 | 195 |
| 196 MockUnifiedSourceCallback source; | 196 MockUnifiedSourceCallback source; |
| 197 AudioUnifiedStreamWrapper ausw(audio_manager.get()); | 197 AudioUnifiedStreamWrapper ausw(audio_manager.get()); |
| 198 WASAPIUnifiedStream* wus = ausw.Create(); | 198 WASAPIUnifiedStream* wus = ausw.Create(); |
| 199 | 199 |
| 200 EXPECT_TRUE(wus->Open()); | 200 EXPECT_TRUE(wus->Open()); |
| 201 EXPECT_CALL(source, OnError(wus, _)) | 201 EXPECT_CALL(source, OnError(wus)) |
| 202 .Times(0); | 202 .Times(0); |
| 203 EXPECT_CALL(source, OnMoreIOData(NotNull(), NotNull(), _)) | 203 EXPECT_CALL(source, OnMoreIOData(NotNull(), NotNull(), _)) |
| 204 .Times(Between(0, 1)) | 204 .Times(Between(0, 1)) |
| 205 .WillOnce(Return(ausw.frames_per_buffer())); | 205 .WillOnce(Return(ausw.frames_per_buffer())); |
| 206 wus->Start(&source); | 206 wus->Start(&source); |
| 207 wus->Close(); | 207 wus->Close(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 // Verify that IO callbacks starts as they should. | 210 // Verify that IO callbacks starts as they should. |
| 211 TEST(WASAPIUnifiedStreamTest, StartLoopbackAudio) { | 211 TEST(WASAPIUnifiedStreamTest, StartLoopbackAudio) { |
| 212 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 212 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 213 if (!CanRunUnifiedAudioTests(audio_manager.get())) | 213 if (!CanRunUnifiedAudioTests(audio_manager.get())) |
| 214 return; | 214 return; |
| 215 | 215 |
| 216 MessageLoopForUI loop; | 216 MessageLoopForUI loop; |
| 217 MockUnifiedSourceCallback source; | 217 MockUnifiedSourceCallback source; |
| 218 AudioUnifiedStreamWrapper ausw(audio_manager.get()); | 218 AudioUnifiedStreamWrapper ausw(audio_manager.get()); |
| 219 WASAPIUnifiedStream* wus = ausw.Create(); | 219 WASAPIUnifiedStream* wus = ausw.Create(); |
| 220 | 220 |
| 221 // Set up expected minimum delay estimation where we use a minium delay | 221 // Set up expected minimum delay estimation where we use a minium delay |
| 222 // which is equal to the sum of render and capture sizes. We can never | 222 // which is equal to the sum of render and capture sizes. We can never |
| 223 // reach a delay lower than this value. | 223 // reach a delay lower than this value. |
| 224 AudioBuffersState min_total_audio_delay(0, 2 * ausw.bytes_per_buffer()); | 224 AudioBuffersState min_total_audio_delay(0, 2 * ausw.bytes_per_buffer()); |
| 225 | 225 |
| 226 EXPECT_TRUE(wus->Open()); | 226 EXPECT_TRUE(wus->Open()); |
| 227 EXPECT_CALL(source, OnError(wus, _)) | 227 EXPECT_CALL(source, OnError(wus)) |
| 228 .Times(0); | 228 .Times(0); |
| 229 EXPECT_CALL(source, OnMoreIOData( | 229 EXPECT_CALL(source, OnMoreIOData( |
| 230 NotNull(), NotNull(), DelayGreaterThan(min_total_audio_delay))) | 230 NotNull(), NotNull(), DelayGreaterThan(min_total_audio_delay))) |
| 231 .Times(AtLeast(2)) | 231 .Times(AtLeast(2)) |
| 232 .WillOnce(Return(ausw.frames_per_buffer())) | 232 .WillOnce(Return(ausw.frames_per_buffer())) |
| 233 .WillOnce(DoAll( | 233 .WillOnce(DoAll( |
| 234 QuitLoop(loop.message_loop_proxy()), | 234 QuitLoop(loop.message_loop_proxy()), |
| 235 Return(ausw.frames_per_buffer()))); | 235 Return(ausw.frames_per_buffer()))); |
| 236 wus->Start(&source); | 236 wus->Start(&source); |
| 237 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 237 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 255 | 255 |
| 256 EXPECT_TRUE(wus->Open()); | 256 EXPECT_TRUE(wus->Open()); |
| 257 wus->Start(&source); | 257 wus->Start(&source); |
| 258 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 258 loop.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
| 259 base::TimeDelta::FromMilliseconds(10000)); | 259 base::TimeDelta::FromMilliseconds(10000)); |
| 260 loop.Run(); | 260 loop.Run(); |
| 261 wus->Close(); | 261 wus->Close(); |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace media | 264 } // namespace media |
| OLD | NEW |