Chromium Code Reviews| 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 |
| 20 namespace media { | 21 namespace media { |
| 21 | 22 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 37 kBitsPerChannel, kBufferSize); | 38 kBitsPerChannel, kBufferSize); |
| 38 | 39 |
| 39 CreateMixerInput(kDefaultDeviceId); | 40 CreateMixerInput(kDefaultDeviceId); |
| 40 fake_callback_.reset(new FakeAudioRenderCallback(0)); | 41 fake_callback_.reset(new FakeAudioRenderCallback(0)); |
| 41 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); | 42 mixer_input_->Initialize(audio_parameters_, fake_callback_.get()); |
| 42 audio_bus_ = AudioBus::Create(audio_parameters_); | 43 audio_bus_ = AudioBus::Create(audio_parameters_); |
| 43 } | 44 } |
| 44 | 45 |
| 45 void CreateMixerInput(const std::string& device_id) { | 46 void CreateMixerInput(const std::string& device_id) { |
| 46 mixer_input_ = new AudioRendererMixerInput(this, kRenderFrameId, device_id, | 47 mixer_input_ = new AudioRendererMixerInput(this, kRenderFrameId, device_id, |
| 47 url::Origin()); | 48 url::Origin(), |
| 49 AudioLatency::LATENCY_PLAYBACK); | |
| 48 } | 50 } |
| 49 | 51 |
| 50 AudioRendererMixer* GetMixer(int owner_id, | 52 AudioRendererMixer* GetMixer(int owner_id, |
| 51 const AudioParameters& params, | 53 const AudioParameters& params, |
| 54 AudioLatency::LatencyType latency, | |
| 52 const std::string& device_id, | 55 const std::string& device_id, |
| 53 const url::Origin& security_origin, | 56 const url::Origin& security_origin, |
| 54 OutputDeviceStatus* device_status) { | 57 OutputDeviceStatus* device_status) { |
| 55 if (device_id == kNonexistentDeviceId) { | 58 if (device_id == kNonexistentDeviceId) { |
| 56 if (device_status) | 59 if (device_status) |
| 57 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; | 60 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_FOUND; |
| 58 return nullptr; | 61 return nullptr; |
| 59 } | 62 } |
| 60 | 63 |
| 61 if (device_id == kUnauthorizedDeviceId) { | 64 if (device_id == kUnauthorizedDeviceId) { |
| 62 if (device_status) | 65 if (device_status) |
| 63 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED; | 66 *device_status = OUTPUT_DEVICE_STATUS_ERROR_NOT_AUTHORIZED; |
| 64 return nullptr; | 67 return nullptr; |
| 65 } | 68 } |
| 66 | 69 |
| 67 size_t idx = (device_id == kDefaultDeviceId) ? 0 : 1; | 70 size_t idx = (device_id == kDefaultDeviceId) ? 0 : 1; |
| 68 if (!mixers_[idx]) { | 71 if (!mixers_[idx]) { |
| 69 sinks_[idx] = | 72 sinks_[idx] = |
| 70 new MockAudioRendererSink(device_id, OUTPUT_DEVICE_STATUS_OK); | 73 new MockAudioRendererSink(device_id, OUTPUT_DEVICE_STATUS_OK); |
| 71 EXPECT_CALL(*(sinks_[idx].get()), Start()); | 74 EXPECT_CALL(*(sinks_[idx].get()), Start()); |
| 72 EXPECT_CALL(*(sinks_[idx].get()), Stop()); | 75 EXPECT_CALL(*(sinks_[idx].get()), Stop()); |
| 73 | 76 |
| 74 mixers_[idx].reset( | 77 mixers_[idx].reset( |
| 75 new AudioRendererMixer(audio_parameters_, sinks_[idx].get())); | 78 new AudioRendererMixer(audio_parameters_, sinks_[idx].get())); |
| 76 } | 79 } |
| 77 EXPECT_CALL(*this, | 80 EXPECT_CALL(*this, ReturnMixer(mixers_[idx].get())); |
|
chcunningham
2016/06/22 02:13:56
Can we rename this to ReleaseMixer? Return is a li
o1ka
2016/06/23 16:36:16
I remember renaming it once, it used to be RemoveM
chcunningham
2016/06/27 23:12:25
Understood. I just kept reading ReturnMixer as som
o1ka
2016/06/28 13:04:58
Acknowledged.
| |
| 78 ReturnMixer(kRenderFrameId, testing::_, device_id, testing::_)); | |
| 79 | 81 |
| 80 if (device_status) | 82 if (device_status) |
| 81 *device_status = OUTPUT_DEVICE_STATUS_OK; | 83 *device_status = OUTPUT_DEVICE_STATUS_OK; |
| 82 return mixers_[idx].get(); | 84 return mixers_[idx].get(); |
| 83 } | 85 } |
| 84 | 86 |
| 85 double ProvideInput() { | 87 double ProvideInput() { |
| 86 return mixer_input_->ProvideInput(audio_bus_.get(), 0); | 88 return mixer_input_->ProvideInput(audio_bus_.get(), 0); |
| 87 } | 89 } |
| 88 | 90 |
| 89 MOCK_METHOD4(ReturnMixer, | 91 MOCK_METHOD1(ReturnMixer, void(const AudioRendererMixer*)); |
| 90 void(int, | |
| 91 const AudioParameters&, | |
| 92 const std::string&, | |
| 93 const url::Origin&)); | |
| 94 | 92 |
| 95 MOCK_METHOD4( | 93 MOCK_METHOD4( |
| 96 GetOutputDeviceInfo, | 94 GetOutputDeviceInfo, |
| 97 OutputDeviceInfo(int, int, const std::string&, const url::Origin&)); | 95 OutputDeviceInfo(int, int, const std::string&, const url::Origin&)); |
| 98 | 96 |
| 99 MOCK_METHOD1(SwitchCallbackCalled, void(OutputDeviceStatus)); | 97 MOCK_METHOD1(SwitchCallbackCalled, void(OutputDeviceStatus)); |
| 100 | 98 |
| 101 void SwitchCallback(base::RunLoop* loop, OutputDeviceStatus result) { | 99 void SwitchCallback(base::RunLoop* loop, OutputDeviceStatus result) { |
| 102 SwitchCallbackCalled(result); | 100 SwitchCallbackCalled(result); |
| 103 loop->Quit(); | 101 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)); | 300 EXPECT_CALL(*this, SwitchCallbackCalled(OUTPUT_DEVICE_STATUS_ERROR_INTERNAL)); |
| 303 mixer_input_->SwitchOutputDevice( | 301 mixer_input_->SwitchOutputDevice( |
| 304 kDefaultDeviceId, url::Origin(), | 302 kDefaultDeviceId, url::Origin(), |
| 305 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, | 303 base::Bind(&AudioRendererMixerInputTest::SwitchCallback, |
| 306 base::Unretained(this), &run_loop)); | 304 base::Unretained(this), &run_loop)); |
| 307 mixer_input_->Stop(); | 305 mixer_input_->Stop(); |
| 308 run_loop.Run(); | 306 run_loop.Run(); |
| 309 } | 307 } |
| 310 | 308 |
| 311 } // namespace media | 309 } // namespace media |
| OLD | NEW |