OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/logging.h" | 5 #include "base/logging.h" |
6 #include "content/renderer/media/rtc_media_constraints.h" | 6 #include "content/renderer/media/rtc_media_constraints.h" |
7 #include "content/renderer/media/webrtc_audio_capturer.h" | 7 #include "content/renderer/media/webrtc_audio_capturer.h" |
8 #include "content/renderer/media/webrtc_local_audio_track.h" | 8 #include "content/renderer/media/webrtc_local_audio_track.h" |
9 #include "media/audio/audio_parameters.h" | 9 #include "media/audio/audio_parameters.h" |
10 #include "media/base/audio_bus.h" | 10 #include "media/base/audio_bus.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 int session_id)); | 58 int session_id)); |
59 MOCK_METHOD0(Start, void()); | 59 MOCK_METHOD0(Start, void()); |
60 MOCK_METHOD0(Stop, void()); | 60 MOCK_METHOD0(Stop, void()); |
61 MOCK_METHOD1(SetVolume, void(double volume)); | 61 MOCK_METHOD1(SetVolume, void(double volume)); |
62 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); | 62 MOCK_METHOD1(SetAutomaticGainControl, void(bool enable)); |
63 | 63 |
64 protected: | 64 protected: |
65 virtual ~MockCapturerSource() {} | 65 virtual ~MockCapturerSource() {} |
66 }; | 66 }; |
67 | 67 |
68 class MockWebRtcAudioCapturerSink : public WebRtcAudioCapturerSink { | 68 class MockPeerConnectionAudioSink : public PeerConnectionAudioSink { |
69 public: | 69 public: |
70 MockWebRtcAudioCapturerSink() {} | 70 MockPeerConnectionAudioSink() {} |
71 ~MockWebRtcAudioCapturerSink() {} | 71 ~MockPeerConnectionAudioSink() {} |
72 MOCK_METHOD9(CaptureData, int(const std::vector<int>& channels, | 72 MOCK_METHOD9(OnData, int(const int16* audio_data, |
73 const int16* audio_data, | 73 int sample_rate, |
74 int sample_rate, | 74 int number_of_channels, |
75 int number_of_channels, | 75 int number_of_frames, |
76 int number_of_frames, | 76 const std::vector<int>& channels, |
77 int audio_delay_milliseconds, | 77 int audio_delay_milliseconds, |
78 int current_volume, | 78 int current_volume, |
79 bool need_audio_processing, | 79 bool need_audio_processing, |
80 bool key_pressed)); | 80 bool key_pressed)); |
81 MOCK_METHOD1(SetCaptureFormat, void(const media::AudioParameters& params)); | 81 MOCK_METHOD1(OnSetFormat, void(const media::AudioParameters& params)); |
82 }; | 82 }; |
83 | 83 |
84 } // namespace | 84 } // namespace |
85 | 85 |
86 class WebRtcAudioCapturerTest : public testing::Test { | 86 class WebRtcAudioCapturerTest : public testing::Test { |
87 protected: | 87 protected: |
88 WebRtcAudioCapturerTest() | 88 WebRtcAudioCapturerTest() |
89 #if defined(OS_ANDROID) | 89 #if defined(OS_ANDROID) |
90 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 90 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
91 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 960) { | 91 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 960) { |
(...skipping 26 matching lines...) Expand all Loading... |
118 media::AudioParameters params_; | 118 media::AudioParameters params_; |
119 scoped_refptr<MockCapturerSource> capturer_source_; | 119 scoped_refptr<MockCapturerSource> capturer_source_; |
120 scoped_refptr<WebRtcAudioCapturer> capturer_; | 120 scoped_refptr<WebRtcAudioCapturer> capturer_; |
121 scoped_refptr<WebRtcLocalAudioTrack> track_; | 121 scoped_refptr<WebRtcLocalAudioTrack> track_; |
122 }; | 122 }; |
123 | 123 |
124 // Pass the delay value, vollume and key_pressed info via capture callback, and | 124 // Pass the delay value, vollume and key_pressed info via capture callback, and |
125 // those values should be correctly stored and passed to the track. | 125 // those values should be correctly stored and passed to the track. |
126 TEST_F(WebRtcAudioCapturerTest, VerifyAudioParams) { | 126 TEST_F(WebRtcAudioCapturerTest, VerifyAudioParams) { |
127 // Connect a mock sink to the track. | 127 // Connect a mock sink to the track. |
128 scoped_ptr<MockWebRtcAudioCapturerSink> sink( | 128 scoped_ptr<MockPeerConnectionAudioSink> sink( |
129 new MockWebRtcAudioCapturerSink()); | 129 new MockPeerConnectionAudioSink()); |
130 track_->AddSink(sink.get()); | 130 track_->AddSink(sink.get()); |
131 | 131 |
132 int delay_ms = 65; | 132 int delay_ms = 65; |
133 bool key_pressed = true; | 133 bool key_pressed = true; |
134 double volume = 0.9; | 134 double volume = 0.9; |
135 // MaxVolume() in WebRtcAudioCapturer is hard-coded to return 255, we add 0.5 | 135 // MaxVolume() in WebRtcAudioCapturer is hard-coded to return 255, we add 0.5 |
136 // to do the correct truncation as how the production code does. | 136 // to do the correct truncation as how the production code does. |
137 int expected_volume_value = volume * capturer_->MaxVolume() + 0.5; | 137 int expected_volume_value = volume * capturer_->MaxVolume() + 0.5; |
138 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); | 138 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); |
139 audio_bus->Zero(); | 139 audio_bus->Zero(); |
140 #if defined(OS_ANDROID) | 140 #if defined(OS_ANDROID) |
141 const int expected_buffer_size = params_.sample_rate() / 100; | 141 const int expected_buffer_size = params_.sample_rate() / 100; |
142 #else | 142 #else |
143 const int expected_buffer_size = params_.frames_per_buffer(); | 143 const int expected_buffer_size = params_.frames_per_buffer(); |
144 #endif | 144 #endif |
145 bool expected_need_audio_processing = true; | 145 bool expected_need_audio_processing = true; |
146 media::AudioCapturerSource::CaptureCallback* callback = | 146 media::AudioCapturerSource::CaptureCallback* callback = |
147 static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_); | 147 static_cast<media::AudioCapturerSource::CaptureCallback*>(capturer_); |
148 // Verify the sink is getting the correct values. | 148 // Verify the sink is getting the correct values. |
149 EXPECT_CALL(*sink, SetCaptureFormat(_)); | 149 EXPECT_CALL(*sink, OnSetFormat(_)); |
150 EXPECT_CALL(*sink, | 150 EXPECT_CALL(*sink, |
151 CaptureData(_, _, params_.sample_rate(), params_.channels(), | 151 OnData(_, params_.sample_rate(), params_.channels(), |
152 expected_buffer_size, delay_ms, | 152 expected_buffer_size, _, delay_ms, |
153 expected_volume_value, expected_need_audio_processing, | 153 expected_volume_value, expected_need_audio_processing, |
154 key_pressed)).Times(AtLeast(1)); | 154 key_pressed)).Times(AtLeast(1)); |
155 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); | 155 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); |
156 | 156 |
157 // Verify the cached values in the capturer fits what we expect. | 157 // Verify the cached values in the capturer fits what we expect. |
158 base::TimeDelta cached_delay; | 158 base::TimeDelta cached_delay; |
159 int cached_volume = !expected_volume_value; | 159 int cached_volume = !expected_volume_value; |
160 bool cached_key_pressed = !key_pressed; | 160 bool cached_key_pressed = !key_pressed; |
161 capturer_->GetAudioProcessingParams(&cached_delay, &cached_volume, | 161 capturer_->GetAudioProcessingParams(&cached_delay, &cached_volume, |
162 &cached_key_pressed); | 162 &cached_key_pressed); |
163 EXPECT_EQ(cached_delay.InMilliseconds(), delay_ms); | 163 EXPECT_EQ(cached_delay.InMilliseconds(), delay_ms); |
164 EXPECT_EQ(cached_volume, expected_volume_value); | 164 EXPECT_EQ(cached_volume, expected_volume_value); |
165 EXPECT_EQ(cached_key_pressed, key_pressed); | 165 EXPECT_EQ(cached_key_pressed, key_pressed); |
166 | 166 |
167 track_->RemoveSink(sink.get()); | 167 track_->RemoveSink(sink.get()); |
168 EXPECT_CALL(*capturer_source_.get(), Stop()); | 168 EXPECT_CALL(*capturer_source_.get(), Stop()); |
169 capturer_->Stop(); | 169 capturer_->Stop(); |
170 } | 170 } |
171 | 171 |
172 } // namespace content | 172 } // namespace content |
OLD | NEW |