| 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 "media/audio/audio_output_controller.h" | 5 #include "media/audio/audio_output_controller.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/bind.h" | 12 #include "base/bind.h" |
| 12 #include "base/environment.h" | 13 #include "base/environment.h" |
| 13 #include "base/location.h" | 14 #include "base/location.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 17 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
| 19 #include "base/test/test_message_loop.h" | 20 #include "base/test/test_message_loop.h" |
| 20 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/time/time.h" |
| 21 #include "media/audio/audio_device_description.h" | 23 #include "media/audio/audio_device_description.h" |
| 22 #include "media/audio/audio_source_diverter.h" | 24 #include "media/audio/audio_source_diverter.h" |
| 23 #include "media/base/audio_bus.h" | 25 #include "media/base/audio_bus.h" |
| 24 #include "media/base/audio_parameters.h" | 26 #include "media/base/audio_parameters.h" |
| 25 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 27 | 29 |
| 28 using ::testing::_; | 30 using ::testing::_; |
| 29 using ::testing::AtLeast; | 31 using ::testing::AtLeast; |
| 30 using ::testing::DoAll; | 32 using ::testing::DoAll; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 } | 194 } |
| 193 | 195 |
| 194 void StartDuplicating(MockAudioPushSink* sink) { | 196 void StartDuplicating(MockAudioPushSink* sink) { |
| 195 controller_->StartDuplicating(sink); | 197 controller_->StartDuplicating(sink); |
| 196 base::RunLoop().RunUntilIdle(); | 198 base::RunLoop().RunUntilIdle(); |
| 197 } | 199 } |
| 198 | 200 |
| 199 void ReadDivertedAudioData() { | 201 void ReadDivertedAudioData() { |
| 200 std::unique_ptr<AudioBus> dest = AudioBus::Create(params_); | 202 std::unique_ptr<AudioBus> dest = AudioBus::Create(params_); |
| 201 ASSERT_TRUE(mock_stream_.callback()); | 203 ASSERT_TRUE(mock_stream_.callback()); |
| 202 const int frames_read = | 204 const int frames_read = mock_stream_.callback()->OnMoreData( |
| 203 mock_stream_.callback()->OnMoreData(dest.get(), 0, 0); | 205 base::TimeDelta(), base::TimeTicks::Now(), 0, dest.get()); |
| 204 EXPECT_LT(0, frames_read); | 206 EXPECT_LT(0, frames_read); |
| 205 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); | 207 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); |
| 206 } | 208 } |
| 207 | 209 |
| 208 void ReadDuplicatedAudioData(const std::vector<MockAudioPushSink*>& sinks) { | 210 void ReadDuplicatedAudioData(const std::vector<MockAudioPushSink*>& sinks) { |
| 209 for (size_t i = 0; i < sinks.size(); i++) { | 211 for (size_t i = 0; i < sinks.size(); i++) { |
| 210 EXPECT_CALL(*sinks[i], OnDataCheck(kBufferNonZeroData)); | 212 EXPECT_CALL(*sinks[i], OnDataCheck(kBufferNonZeroData)); |
| 211 } | 213 } |
| 212 | 214 |
| 213 std::unique_ptr<AudioBus> dest = AudioBus::Create(params_); | 215 std::unique_ptr<AudioBus> dest = AudioBus::Create(params_); |
| 214 | 216 |
| 215 // It is this OnMoreData() call that triggers |sink|'s OnData(). | 217 // It is this OnMoreData() call that triggers |sink|'s OnData(). |
| 216 const int frames_read = controller_->OnMoreData(dest.get(), 0, 0); | 218 const int frames_read = controller_->OnMoreData( |
| 219 base::TimeDelta(), base::TimeTicks::Now(), 0, dest.get()); |
| 217 | 220 |
| 218 EXPECT_LT(0, frames_read); | 221 EXPECT_LT(0, frames_read); |
| 219 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); | 222 EXPECT_EQ(kBufferNonZeroData, dest->channel(0)[0]); |
| 220 | 223 |
| 221 base::RunLoop().RunUntilIdle(); | 224 base::RunLoop().RunUntilIdle(); |
| 222 } | 225 } |
| 223 | 226 |
| 224 void Revert(bool was_playing) { | 227 void Revert(bool was_playing) { |
| 225 if (was_playing) { | 228 if (was_playing) { |
| 226 // Expect the handler to receive one OnPlaying() call as a result of the | 229 // Expect the handler to receive one OnPlaying() call as a result of the |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 // Switching device would trigger a read, and in turn it would trigger a push | 429 // Switching device would trigger a read, and in turn it would trigger a push |
| 427 // to sink. | 430 // to sink. |
| 428 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); | 431 EXPECT_CALL(mock_sink, OnDataCheck(kBufferNonZeroData)); |
| 429 SwitchDevice(false); | 432 SwitchDevice(false); |
| 430 | 433 |
| 431 StopDuplicating(&mock_sink); | 434 StopDuplicating(&mock_sink); |
| 432 Close(); | 435 Close(); |
| 433 } | 436 } |
| 434 | 437 |
| 435 } // namespace media | 438 } // namespace media |
| OLD | NEW |