OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/renderer/media/audio_track_recorder.h" | 5 #include "content/renderer/media/audio_track_recorder.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
9 #include "base/macros.h" | 11 #include "base/macros.h" |
10 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
11 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
12 #include "base/strings/utf_string_conversions.h" | |
13 #include "content/renderer/media/media_stream_audio_source.h" | 14 #include "content/renderer/media/media_stream_audio_source.h" |
14 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | |
15 #include "content/renderer/media/webrtc_local_audio_track.h" | |
16 #include "media/audio/simple_sources.h" | 15 #include "media/audio/simple_sources.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" |
19 #include "third_party/WebKit/public/web/WebHeap.h" | 19 #include "third_party/WebKit/public/web/WebHeap.h" |
20 #include "third_party/opus/src/include/opus.h" | 20 #include "third_party/opus/src/include/opus.h" |
21 | 21 |
22 using ::testing::_; | 22 using ::testing::_; |
23 using ::testing::DoAll; | 23 using ::testing::DoAll; |
24 using ::testing::InSequence; | 24 using ::testing::InSequence; |
25 using ::testing::Mock; | 25 using ::testing::Mock; |
26 using ::testing::Return; | 26 using ::testing::Return; |
27 using ::testing::SaveArg; | 27 using ::testing::SaveArg; |
28 using ::testing::TestWithParam; | 28 using ::testing::TestWithParam; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 202 |
203 // Decoder for verifying data was properly encoded. | 203 // Decoder for verifying data was properly encoded. |
204 OpusDecoder* opus_decoder_; | 204 OpusDecoder* opus_decoder_; |
205 std::unique_ptr<float[]> buffer_; | 205 std::unique_ptr<float[]> buffer_; |
206 | 206 |
207 private: | 207 private: |
208 // Prepares a blink track of a given MediaStreamType and attaches the native | 208 // Prepares a blink track of a given MediaStreamType and attaches the native |
209 // track, which can be used to capture audio data and pass it to the producer. | 209 // track, which can be used to capture audio data and pass it to the producer. |
210 // Adapted from media::WebRTCLocalAudioSourceProviderTest. | 210 // Adapted from media::WebRTCLocalAudioSourceProviderTest. |
211 void PrepareBlinkTrack() { | 211 void PrepareBlinkTrack() { |
212 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | |
213 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | |
214 std::unique_ptr<WebRtcLocalAudioTrack> native_track( | |
215 new WebRtcLocalAudioTrack(adapter.get())); | |
216 blink::WebMediaStreamSource audio_source; | 212 blink::WebMediaStreamSource audio_source; |
217 audio_source.initialize(base::UTF8ToUTF16("dummy_source_id"), | 213 audio_source.initialize(blink::WebString::fromUTF8("dummy_source_id"), |
218 blink::WebMediaStreamSource::TypeAudio, | 214 blink::WebMediaStreamSource::TypeAudio, |
219 base::UTF8ToUTF16("dummy_source_name"), | 215 blink::WebString::fromUTF8("dummy_source_name"), |
220 false /* remote */); | 216 false /* remote */); |
| 217 audio_source.setExtraData(new MediaStreamAudioSource(true)); |
221 blink_track_.initialize(blink::WebString::fromUTF8("audio_track"), | 218 blink_track_.initialize(blink::WebString::fromUTF8("audio_track"), |
222 audio_source); | 219 audio_source); |
223 blink_track_.setExtraData(native_track.release()); | 220 CHECK(MediaStreamAudioSource::From(audio_source) |
| 221 ->ConnectToTrack(blink_track_)); |
224 } | 222 } |
225 | 223 |
226 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorderTest); | 224 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorderTest); |
227 }; | 225 }; |
228 | 226 |
229 TEST_P(AudioTrackRecorderTest, OnData) { | 227 TEST_P(AudioTrackRecorderTest, OnData) { |
230 InSequence s; | 228 InSequence s; |
231 base::RunLoop run_loop; | 229 base::RunLoop run_loop; |
232 base::Closure quit_closure = run_loop.QuitClosure(); | 230 base::Closure quit_closure = run_loop.QuitClosure(); |
233 | 231 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 292 |
295 if (GetParam().sample_rate % 100) | 293 if (GetParam().sample_rate % 100) |
296 audio_track_recorder_->OnData(*GetFirstSourceAudioBus(), TimeTicks::Now()); | 294 audio_track_recorder_->OnData(*GetFirstSourceAudioBus(), TimeTicks::Now()); |
297 | 295 |
298 run_loop.Run(); | 296 run_loop.Run(); |
299 Mock::VerifyAndClearExpectations(this); | 297 Mock::VerifyAndClearExpectations(this); |
300 } | 298 } |
301 | 299 |
302 INSTANTIATE_TEST_CASE_P(, AudioTrackRecorderTest, ValuesIn(kATRTestParams)); | 300 INSTANTIATE_TEST_CASE_P(, AudioTrackRecorderTest, ValuesIn(kATRTestParams)); |
303 } // namespace content | 301 } // namespace content |
OLD | NEW |