| 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/mock_media_constraint_factory.h" | |
| 15 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | |
| 16 #include "content/renderer/media/webrtc_local_audio_track.h" | |
| 17 #include "media/audio/simple_sources.h" | 15 #include "media/audio/simple_sources.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/web/WebHeap.h" | 19 #include "third_party/WebKit/public/web/WebHeap.h" |
| 21 #include "third_party/opus/src/include/opus.h" | 20 #include "third_party/opus/src/include/opus.h" |
| 22 | 21 |
| 23 using ::testing::_; | 22 using ::testing::_; |
| 24 using ::testing::DoAll; | 23 using ::testing::DoAll; |
| 25 using ::testing::InSequence; | 24 using ::testing::InSequence; |
| 26 using ::testing::Mock; | 25 using ::testing::Mock; |
| 27 using ::testing::Return; | 26 using ::testing::Return; |
| 28 using ::testing::SaveArg; | 27 using ::testing::SaveArg; |
| 29 using ::testing::TestWithParam; | 28 using ::testing::TestWithParam; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 media::SineWaveAudioSource first_source_; | 199 media::SineWaveAudioSource first_source_; |
| 201 media::SineWaveAudioSource second_source_; | 200 media::SineWaveAudioSource second_source_; |
| 202 | 201 |
| 203 // Decoder for verifying data was properly encoded. | 202 // Decoder for verifying data was properly encoded. |
| 204 OpusDecoder* opus_decoder_; | 203 OpusDecoder* opus_decoder_; |
| 205 scoped_ptr<float[]> buffer_; | 204 scoped_ptr<float[]> buffer_; |
| 206 | 205 |
| 207 private: | 206 private: |
| 208 // Prepares a blink track of a given MediaStreamType and attaches the native | 207 // 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. | 208 // track, which can be used to capture audio data and pass it to the producer. |
| 210 // Adapted from media::WebRTCLocalAudioSourceProviderTest. | |
| 211 void PrepareBlinkTrack() { | 209 void PrepareBlinkTrack() { |
| 212 MockMediaConstraintFactory constraint_factory; | |
| 213 scoped_refptr<WebRtcAudioCapturer> capturer( | |
| 214 WebRtcAudioCapturer::CreateCapturer( | |
| 215 -1, StreamDeviceInfo(), | |
| 216 constraint_factory.CreateWebMediaConstraints(), NULL, NULL)); | |
| 217 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | |
| 218 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | |
| 219 scoped_ptr<WebRtcLocalAudioTrack> native_track( | |
| 220 new WebRtcLocalAudioTrack(adapter.get(), capturer, NULL)); | |
| 221 blink::WebMediaStreamSource audio_source; | 210 blink::WebMediaStreamSource audio_source; |
| 222 audio_source.initialize(base::UTF8ToUTF16("dummy_source_id"), | 211 audio_source.initialize(blink::WebString::fromUTF8("dummy_source_id"), |
| 223 blink::WebMediaStreamSource::TypeAudio, | 212 blink::WebMediaStreamSource::TypeAudio, |
| 224 base::UTF8ToUTF16("dummy_source_name"), | 213 blink::WebString::fromUTF8("dummy_source_name"), |
| 225 false /* remote */, true /* readonly */); | 214 false /* remote */, true /* readonly */); |
| 215 audio_source.setExtraData( |
| 216 new MediaStreamAudioSource(false /* is_remote */)); |
| 226 blink_track_.initialize(blink::WebString::fromUTF8("audio_track"), | 217 blink_track_.initialize(blink::WebString::fromUTF8("audio_track"), |
| 227 audio_source); | 218 audio_source); |
| 228 blink_track_.setExtraData(native_track.release()); | 219 ASSERT_TRUE(MediaStreamAudioSource::Get(audio_source) |
| 220 ->ConnectToTrack(blink_track_)); |
| 229 } | 221 } |
| 230 | 222 |
| 231 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorderTest); | 223 DISALLOW_COPY_AND_ASSIGN(AudioTrackRecorderTest); |
| 232 }; | 224 }; |
| 233 | 225 |
| 234 TEST_P(AudioTrackRecorderTest, OnData) { | 226 TEST_P(AudioTrackRecorderTest, OnData) { |
| 235 InSequence s; | 227 InSequence s; |
| 236 base::RunLoop run_loop; | 228 base::RunLoop run_loop; |
| 237 base::Closure quit_closure = run_loop.QuitClosure(); | 229 base::Closure quit_closure = run_loop.QuitClosure(); |
| 238 | 230 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 base::TimeTicks::Now()); | 274 base::TimeTicks::Now()); |
| 283 } | 275 } |
| 284 | 276 |
| 285 run_loop.Run(); | 277 run_loop.Run(); |
| 286 Mock::VerifyAndClearExpectations(this); | 278 Mock::VerifyAndClearExpectations(this); |
| 287 } | 279 } |
| 288 | 280 |
| 289 INSTANTIATE_TEST_CASE_P(, AudioTrackRecorderTest, ValuesIn(kATRTestParams)); | 281 INSTANTIATE_TEST_CASE_P(, AudioTrackRecorderTest, ValuesIn(kATRTestParams)); |
| 290 | 282 |
| 291 } // namespace content | 283 } // namespace content |
| OLD | NEW |