| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <memory> | 6 #include <memory> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
| 12 #include "media/base/audio_latency.h" |
| 12 #include "media/base/audio_renderer_mixer.h" | 13 #include "media/base/audio_renderer_mixer.h" |
| 13 #include "media/base/audio_renderer_mixer_input.h" | 14 #include "media/base/audio_renderer_mixer_input.h" |
| 14 #include "media/base/audio_renderer_mixer_pool.h" | 15 #include "media/base/audio_renderer_mixer_pool.h" |
| 15 #include "media/base/fake_audio_render_callback.h" | 16 #include "media/base/fake_audio_render_callback.h" |
| 16 #include "media/base/mock_audio_renderer_sink.h" | 17 #include "media/base/mock_audio_renderer_sink.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 21 namespace { |
| 22 void LogUma(int value) {} |
| 23 } |
| 24 |
| 20 namespace media { | 25 namespace media { |
| 21 | 26 |
| 22 static const int kBitsPerChannel = 16; | 27 static const int kBitsPerChannel = 16; |
| 23 static const int kSampleRate = 48000; | 28 static const int kSampleRate = 48000; |
| 24 static const int kBufferSize = 8192; | 29 static const int kBufferSize = 8192; |
| 25 static const int kRenderFrameId = 42; | 30 static const int kRenderFrameId = 42; |
| 26 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 31 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
| 27 static const char kDefaultDeviceId[] = "default"; | 32 static const char kDefaultDeviceId[] = "default"; |
| 28 static const char kUnauthorizedDeviceId[] = "unauthorized"; | 33 static const char kUnauthorizedDeviceId[] = "unauthorized"; |
| 29 static const char kNonexistentDeviceId[] = "nonexistent"; | 34 static const char kNonexistentDeviceId[] = "nonexistent"; |
| 30 | 35 |
| 31 class AudioRendererMixerInputTest : public testing::Test, | 36 class AudioRendererMixerInputTest : public testing::Test, |
| 32 AudioRendererMixerPool { | 37 AudioRendererMixerPool { |
| 33 public: | 38 public: |
| 34 AudioRendererMixerInputTest() { | 39 AudioRendererMixerInputTest() { |
| 35 audio_parameters_ = AudioParameters( | 40 audio_parameters_ = AudioParameters( |
| 36 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, | 41 AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, |
| 37 kBitsPerChannel, kBufferSize); | 42 kBitsPerChannel, kBufferSize); |
| 38 | 43 |
| 39 CreateMixerInput(kDefaultDeviceId); | 44 CreateMixerInput(kDefaultDeviceId); |
| 40 fake_callback_.reset(new FakeAudioRenderCallback(0)); | 45 fake_callback_.reset(new FakeAudioRenderCallback(0)); |
| 41 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | 46 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
| 42 audio_bus_ = AudioBus::Create(audio_parameters_); | 47 audio_bus_ = AudioBus::Create(audio_parameters_); |
| 43 } | 48 } |
| 44 | 49 |
| 45 void CreateMixerInput(const std::string& device_id) { | 50 void CreateMixerInput(const std::string& device_id) { |
| 46 mixer_input_ = new AudioRendererMixerInput(this, kRenderFrameId, device_id, | 51 mixer_input_ = new AudioRendererMixerInput(this, kRenderFrameId, device_id, |
| 47 url::Origin()); | 52 url::Origin(), |
| 53 AudioLatency::LATENCY_PLAYBACK); |
| 48 } | 54 } |
| 49 | 55 |
| 50 AudioRendererMixer* GetMixer(int owner_id, | 56 AudioRendererMixer* GetMixer(int owner_id, |
| 51 const AudioParameters& params, | 57 const AudioParameters& params, |
| 58 AudioLatency::LatencyType latency, |
| 52 const std::string& device_id, | 59 const std::string& device_id, |
| 53 const url::Origin& security_origin, | 60 const url::Origin& security_origin, |
| 54 OutputDeviceStatus* device_status) { | 61 OutputDeviceStatus* device_status) { |
| 55 if (device_id == kNonexistentDeviceId) { | 62 if (device_id == kNonexistentDeviceId) { |
| 56 if (device_status) | 63 if (device_status) |
| 57 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; | 64 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; |
| 58 return nullptr; | 65 return nullptr; |
| 59 } | 66 } |
| 60 | 67 |
| 61 if (device_id == kUnauthorizedDeviceId) { | 68 if (device_id == kUnauthorizedDeviceId) { |
| 62 if (device_status) | 69 if (device_status) |
| 63 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED; | 70 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED; |
| 64 return nullptr; | 71 return nullptr; |
| 65 } | 72 } |
| 66 | 73 |
| 67 size_t idx = (device_id == kDefaultDeviceId) ? 0 : 1; | 74 size_t idx = (device_id == kDefaultDeviceId) ? 0 : 1; |
| 68 if (!mixers_[idx]) { | 75 if (!mixers_[idx]) { |
| 69 sinks_[idx] = | 76 sinks_[idx] = |
| 70 new MockAudioRendererSink(device_id, OUTPUT_DEVICE_STATUS_OK); | 77 new MockAudioRendererSink(device_id, OUTPUT_DEVICE_STATUS_OK); |
| 71 EXPECT_CALL(*(sinks_[idx].get()), Start()); | 78 EXPECT_CALL(*(sinks_[idx].get()), Start()); |
| 72 EXPECT_CALL(*(sinks_[idx].get()), Stop()); | 79 EXPECT_CALL(*(sinks_[idx].get()), Stop()); |
| 73 | 80 |
| 74 mixers_[idx].reset( | 81 mixers_[idx].reset(new AudioRendererMixer( |
| 75 new AudioRendererMixer(audio_parameters_, sinks_[idx].get())); | 82 audio_parameters_, sinks_[idx].get(), base::Bind(&LogUma))); |
| 76 } | 83 } |
| 77 EXPECT_CALL(*this, | 84 EXPECT_CALL(*this, ReturnMixer(mixers_[idx].get())); |
| 78 ReturnMixer(kRenderFrameId, testing::_, device_id, testing::_)); | |
| 79 | 85 |
| 80 if (device_status) | 86 if (device_status) |
| 81 *device_status = OUTPUT_DEVICE_STATUS_OK; | 87 *device_status = OUTPUT_DEVICE_STATUS_OK; |
| 82 return mixers_[idx].get(); | 88 return mixers_[idx].get(); |
| 83 } | 89 } |
| 84 | 90 |
| 85 double ProvideInput() { | 91 double ProvideInput() { |
| 86 return mixer_input_->ProvideInput(audio_bus_.get(), 0); | 92 return mixer_input_->ProvideInput(audio_bus_.get(), 0); |
| 87 } | 93 } |
| 88 | 94 |
| 89 MOCK_METHOD4(ReturnMixer, | 95 MOCK_METHOD1(ReturnMixer, void(AudioRendererMixer*)); |
| 90 void(int, | |
| 91 const AudioParameters&, | |
| 92 const std::string&, | |
| 93 const url::Origin&)); | |
| 94 | 96 |
| 95 MOCK_METHOD4( | 97 MOCK_METHOD4( |
| 96 GetOutputDeviceInfo, | 98 GetOutputDeviceInfo, |
| 97 OutputDeviceInfo(int, int, const std::string&, const url::Origin&)); | 99 OutputDeviceInfo(int, int, const std::string&, const url::Origin&)); |
| 98 | 100 |
| 99 MOCK_METHOD1(SwitchCallbackCalled, void(OutputDeviceStatus)); | 101 MOCK_METHOD1(SwitchCallbackCalled, void(OutputDeviceStatus)); |
| 100 | 102 |
| 101 void SwitchCallback(base::RunLoop* loop, OutputDeviceStatus result) { | 103 void SwitchCallback(base::RunLoop* loop, OutputDeviceStatus result) { |
| 102 SwitchCallbackCalled(result); | 104 SwitchCallbackCalled(result); |
| 103 loop->Quit(); | 105 loop->Quit(); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL)); | 304 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL)); |
| 303 mixer_input_->SwitchOutputDevice( | 305 mixer_input_->SwitchOutputDevice( |
| 304 kDefaultDeviceId, url::Origin(), | 306 kDefaultDeviceId, url::Origin(), |
| 305 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 307 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 306 base::Unretained(this), &run_loop)); | 308 base::Unretained(this), &run_loop)); |
| 307 mixer_input_->Stop(); | 309 mixer_input_->Stop(); |
| 308 run_loop.Run(); | 310 run_loop.Run(); |
| 309 } | 311 } |
| 310 | 312 |
| 311 } // namespace media | 313 } // namespace media |
| OLD | NEW |