| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "content/renderer/media/audio_device_factory.h" | 7 #include "content/renderer/media/audio_device_factory.h" |
| 8 #include "content/renderer/media/audio_message_filter.h" | 8 #include "content/renderer/media/audio_message_filter.h" |
| 9 #include "content/renderer/media/media_stream_audio_renderer.h" | 9 #include "content/renderer/media/media_stream_audio_renderer.h" |
| 10 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" | 10 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 mock_ipc_(new MockAudioOutputIPC()), | 84 mock_ipc_(new MockAudioOutputIPC()), |
| 85 mock_output_device_(new FakeAudioOutputDevice( | 85 mock_output_device_(new FakeAudioOutputDevice( |
| 86 scoped_ptr<media::AudioOutputIPC>(mock_ipc_), | 86 scoped_ptr<media::AudioOutputIPC>(mock_ipc_), |
| 87 message_loop_->message_loop_proxy())), | 87 message_loop_->message_loop_proxy())), |
| 88 factory_(new MockAudioDeviceFactory()), | 88 factory_(new MockAudioDeviceFactory()), |
| 89 source_(new MockAudioRendererSource()), | 89 source_(new MockAudioRendererSource()), |
| 90 stream_(new rtc::RefCountedObject<MockMediaStream>("label")), | 90 stream_(new rtc::RefCountedObject<MockMediaStream>("label")), |
| 91 renderer_(new WebRtcAudioRenderer(stream_, 1, 1, 1, 44100, 441)) { | 91 renderer_(new WebRtcAudioRenderer(stream_, 1, 1, 1, 44100, 441)) { |
| 92 EXPECT_CALL(*factory_.get(), CreateOutputDevice(1)) | 92 EXPECT_CALL(*factory_.get(), CreateOutputDevice(1)) |
| 93 .WillOnce(Return(mock_output_device_)); | 93 .WillOnce(Return(mock_output_device_)); |
| 94 EXPECT_CALL(*mock_output_device_, Start()); | 94 EXPECT_CALL(*mock_output_device_.get(), Start()); |
| 95 EXPECT_TRUE(renderer_->Initialize(source_.get())); | 95 EXPECT_TRUE(renderer_->Initialize(source_.get())); |
| 96 renderer_proxy_ = renderer_->CreateSharedAudioRendererProxy(stream_); | 96 renderer_proxy_ = renderer_->CreateSharedAudioRendererProxy(stream_); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Used to construct |mock_output_device_|. | 99 // Used to construct |mock_output_device_|. |
| 100 scoped_ptr<base::MessageLoopForIO> message_loop_; | 100 scoped_ptr<base::MessageLoopForIO> message_loop_; |
| 101 MockAudioOutputIPC* mock_ipc_; // Owned by AudioOuputDevice. | 101 MockAudioOutputIPC* mock_ipc_; // Owned by AudioOuputDevice. |
| 102 | 102 |
| 103 scoped_refptr<FakeAudioOutputDevice> mock_output_device_; | 103 scoped_refptr<FakeAudioOutputDevice> mock_output_device_; |
| 104 scoped_ptr<MockAudioDeviceFactory> factory_; | 104 scoped_ptr<MockAudioDeviceFactory> factory_; |
| 105 scoped_ptr<MockAudioRendererSource> source_; | 105 scoped_ptr<MockAudioRendererSource> source_; |
| 106 scoped_refptr<webrtc::MediaStreamInterface> stream_; | 106 scoped_refptr<webrtc::MediaStreamInterface> stream_; |
| 107 scoped_refptr<WebRtcAudioRenderer> renderer_; | 107 scoped_refptr<WebRtcAudioRenderer> renderer_; |
| 108 scoped_refptr<MediaStreamAudioRenderer> renderer_proxy_; | 108 scoped_refptr<MediaStreamAudioRenderer> renderer_proxy_; |
| 109 }; | 109 }; |
| 110 | 110 |
| 111 // Verify that the renderer will be stopped if the only proxy is stopped. | 111 // Verify that the renderer will be stopped if the only proxy is stopped. |
| 112 TEST_F(WebRtcAudioRendererTest, StopRenderer) { | 112 TEST_F(WebRtcAudioRendererTest, StopRenderer) { |
| 113 renderer_proxy_->Start(); | 113 renderer_proxy_->Start(); |
| 114 | 114 |
| 115 // |renderer_| has only one proxy, stopping the proxy should stop the sink of | 115 // |renderer_| has only one proxy, stopping the proxy should stop the sink of |
| 116 // |renderer_|. | 116 // |renderer_|. |
| 117 EXPECT_CALL(*mock_output_device_, Stop()); | 117 EXPECT_CALL(*mock_output_device_.get(), Stop()); |
| 118 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get())); | 118 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get())); |
| 119 renderer_proxy_->Stop(); | 119 renderer_proxy_->Stop(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Verify that the renderer will not be stopped unless the last proxy is | 122 // Verify that the renderer will not be stopped unless the last proxy is |
| 123 // stopped. | 123 // stopped. |
| 124 TEST_F(WebRtcAudioRendererTest, MultipleRenderers) { | 124 TEST_F(WebRtcAudioRendererTest, MultipleRenderers) { |
| 125 renderer_proxy_->Start(); | 125 renderer_proxy_->Start(); |
| 126 | 126 |
| 127 // Create a vector of renderer proxies from the |renderer_|. | 127 // Create a vector of renderer proxies from the |renderer_|. |
| 128 std::vector<scoped_refptr<MediaStreamAudioRenderer> > renderer_proxies_; | 128 std::vector<scoped_refptr<MediaStreamAudioRenderer> > renderer_proxies_; |
| 129 static const int kNumberOfRendererProxy = 5; | 129 static const int kNumberOfRendererProxy = 5; |
| 130 for (int i = 0; i < kNumberOfRendererProxy; ++i) { | 130 for (int i = 0; i < kNumberOfRendererProxy; ++i) { |
| 131 scoped_refptr<MediaStreamAudioRenderer> renderer_proxy( | 131 scoped_refptr<MediaStreamAudioRenderer> renderer_proxy( |
| 132 renderer_->CreateSharedAudioRendererProxy(stream_)); | 132 renderer_->CreateSharedAudioRendererProxy(stream_)); |
| 133 renderer_proxy->Start(); | 133 renderer_proxy->Start(); |
| 134 renderer_proxies_.push_back(renderer_proxy); | 134 renderer_proxies_.push_back(renderer_proxy); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // Stop the |renderer_proxy_| should not stop the sink since it is used by | 137 // Stop the |renderer_proxy_| should not stop the sink since it is used by |
| 138 // other proxies. | 138 // other proxies. |
| 139 EXPECT_CALL(*mock_output_device_, Stop()).Times(0); | 139 EXPECT_CALL(*mock_output_device_.get(), Stop()).Times(0); |
| 140 renderer_proxy_->Stop(); | 140 renderer_proxy_->Stop(); |
| 141 | 141 |
| 142 for (int i = 0; i < kNumberOfRendererProxy; ++i) { | 142 for (int i = 0; i < kNumberOfRendererProxy; ++i) { |
| 143 if (i != kNumberOfRendererProxy -1) { | 143 if (i != kNumberOfRendererProxy -1) { |
| 144 EXPECT_CALL(*mock_output_device_, Stop()).Times(0); | 144 EXPECT_CALL(*mock_output_device_.get(), Stop()).Times(0); |
| 145 } else { | 145 } else { |
| 146 // When the last proxy is stopped, the sink will stop. | 146 // When the last proxy is stopped, the sink will stop. |
| 147 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get())); | 147 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get())); |
| 148 EXPECT_CALL(*mock_output_device_, Stop()); | 148 EXPECT_CALL(*mock_output_device_.get(), Stop()); |
| 149 } | 149 } |
| 150 renderer_proxies_[i]->Stop(); | 150 renderer_proxies_[i]->Stop(); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace content | 154 } // namespace content |
| OLD | NEW |