| 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" |
| 11 #include "content/renderer/media/webrtc_audio_device_impl.h" | 11 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 12 #include "content/renderer/media/webrtc_audio_renderer.h" | 12 #include "content/renderer/media/webrtc_audio_renderer.h" |
| 13 #include "media/audio/audio_output_device.h" | 13 #include "media/audio/audio_output_device.h" |
| 14 #include "media/audio/audio_output_ipc.h" | 14 #include "media/audio/audio_output_ipc.h" |
| 15 #include "media/base/audio_bus.h" | 15 #include "media/base/audio_bus.h" |
| 16 #include "media/base/mock_audio_renderer_sink.h" | 16 #include "media/base/mock_audio_renderer_sink.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" | 19 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h" |
| 20 | 20 |
| 21 using testing::Return; | 21 using testing::Return; |
| 22 | 22 |
| 23 namespace content { | 23 namespace content { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const int kHardwareSampleRate = 44100; |
| 28 const int kHardwareBufferSize = 512; |
| 29 |
| 27 class MockAudioOutputIPC : public media::AudioOutputIPC { | 30 class MockAudioOutputIPC : public media::AudioOutputIPC { |
| 28 public: | 31 public: |
| 29 MockAudioOutputIPC() {} | 32 MockAudioOutputIPC() {} |
| 30 virtual ~MockAudioOutputIPC() {} | 33 virtual ~MockAudioOutputIPC() {} |
| 31 | 34 |
| 32 MOCK_METHOD3(CreateStream, void(media::AudioOutputIPCDelegate* delegate, | 35 MOCK_METHOD3(CreateStream, void(media::AudioOutputIPCDelegate* delegate, |
| 33 const media::AudioParameters& params, | 36 const media::AudioParameters& params, |
| 34 int session_id)); | 37 int session_id)); |
| 35 MOCK_METHOD0(PlayStream, void()); | 38 MOCK_METHOD0(PlayStream, void()); |
| 36 MOCK_METHOD0(PauseStream, void()); | 39 MOCK_METHOD0(PauseStream, void()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 protected: | 84 protected: |
| 82 WebRtcAudioRendererTest() | 85 WebRtcAudioRendererTest() |
| 83 : message_loop_(new base::MessageLoopForIO), | 86 : message_loop_(new base::MessageLoopForIO), |
| 84 mock_ipc_(new MockAudioOutputIPC()), | 87 mock_ipc_(new MockAudioOutputIPC()), |
| 85 mock_output_device_(new FakeAudioOutputDevice( | 88 mock_output_device_(new FakeAudioOutputDevice( |
| 86 scoped_ptr<media::AudioOutputIPC>(mock_ipc_), | 89 scoped_ptr<media::AudioOutputIPC>(mock_ipc_), |
| 87 message_loop_->message_loop_proxy())), | 90 message_loop_->message_loop_proxy())), |
| 88 factory_(new MockAudioDeviceFactory()), | 91 factory_(new MockAudioDeviceFactory()), |
| 89 source_(new MockAudioRendererSource()), | 92 source_(new MockAudioRendererSource()), |
| 90 stream_(new rtc::RefCountedObject<MockMediaStream>("label")), | 93 stream_(new rtc::RefCountedObject<MockMediaStream>("label")), |
| 91 renderer_(new WebRtcAudioRenderer(stream_, 1, 1, 1, 44100, 441)) { | 94 renderer_(new WebRtcAudioRenderer(stream_, 1, 1, 1, 44100, |
| 95 kHardwareBufferSize)) { |
| 92 EXPECT_CALL(*factory_.get(), CreateOutputDevice(1)) | 96 EXPECT_CALL(*factory_.get(), CreateOutputDevice(1)) |
| 93 .WillOnce(Return(mock_output_device_.get())); | 97 .WillOnce(Return(mock_output_device_.get())); |
| 94 EXPECT_CALL(*mock_output_device_.get(), Start()); | 98 EXPECT_CALL(*mock_output_device_.get(), Start()); |
| 95 EXPECT_TRUE(renderer_->Initialize(source_.get())); | 99 EXPECT_TRUE(renderer_->Initialize(source_.get())); |
| 96 renderer_proxy_ = renderer_->CreateSharedAudioRendererProxy(stream_); | 100 renderer_proxy_ = renderer_->CreateSharedAudioRendererProxy(stream_); |
| 97 } | 101 } |
| 98 | 102 |
| 99 // Used to construct |mock_output_device_|. | 103 // Used to construct |mock_output_device_|. |
| 100 scoped_ptr<base::MessageLoopForIO> message_loop_; | 104 scoped_ptr<base::MessageLoopForIO> message_loop_; |
| 101 MockAudioOutputIPC* mock_ipc_; // Owned by AudioOuputDevice. | 105 MockAudioOutputIPC* mock_ipc_; // Owned by AudioOuputDevice. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 EXPECT_CALL(*mock_output_device_.get(), Stop()).Times(0); | 148 EXPECT_CALL(*mock_output_device_.get(), Stop()).Times(0); |
| 145 } else { | 149 } else { |
| 146 // When the last proxy is stopped, the sink will stop. | 150 // When the last proxy is stopped, the sink will stop. |
| 147 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get())); | 151 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get())); |
| 148 EXPECT_CALL(*mock_output_device_.get(), Stop()); | 152 EXPECT_CALL(*mock_output_device_.get(), Stop()); |
| 149 } | 153 } |
| 150 renderer_proxies_[i]->Stop(); | 154 renderer_proxies_[i]->Stop(); |
| 151 } | 155 } |
| 152 } | 156 } |
| 153 | 157 |
| 158 // Verify that the sink of the renderer is using the expected sample rate and |
| 159 // buffer size. |
| 160 TEST_F(WebRtcAudioRendererTest, VerifySinkParameters) { |
| 161 renderer_proxy_->Start(); |
| 162 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 163 static const int kExpectedBufferSize = kHardwareSampleRate / 100; |
| 164 #elif defined(OS_ANDROID) |
| 165 static const int kExpectedBufferSize = 2 * kHardwareSampleRate / 100; |
| 166 #else |
| 167 // Windows. |
| 168 static const int kExpectedBufferSize = kHardwareBufferSize; |
| 169 #endif |
| 170 EXPECT_EQ(kExpectedBufferSize, renderer_->frames_per_buffer()); |
| 171 EXPECT_EQ(kHardwareSampleRate, renderer_->sample_rate()); |
| 172 EXPECT_EQ(2, renderer_->channels()); |
| 173 |
| 174 EXPECT_CALL(*mock_output_device_.get(), Stop()); |
| 175 EXPECT_CALL(*source_.get(), RemoveAudioRenderer(renderer_.get())); |
| 176 renderer_proxy_->Stop(); |
| 177 } |
| 178 |
| 154 } // namespace content | 179 } // namespace content |
| OLD | NEW |