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 "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "content/renderer/media/mock_media_constraint_factory.h" | 7 #include "content/renderer/media/mock_media_constraint_factory.h" |
8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 8 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
9 #include "content/renderer/media/webrtc_audio_capturer.h" | 9 #include "content/renderer/media/webrtc_audio_capturer.h" |
10 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | 10 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
11 #include "content/renderer/media/webrtc_local_audio_track.h" | 11 #include "content/renderer/media/webrtc_local_audio_track.h" |
12 #include "media/audio/audio_parameters.h" | 12 #include "media/audio/audio_parameters.h" |
13 #include "media/base/audio_bus.h" | 13 #include "media/base/audio_bus.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 15 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
16 #include "third_party/WebKit/public/web/WebHeap.h" | 16 #include "third_party/WebKit/public/web/WebHeap.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 class WebRtcLocalAudioSourceProviderTest : public testing::Test { | 20 class WebRtcLocalAudioSourceProviderTest : public testing::Test { |
21 protected: | 21 protected: |
22 void SetUp() override { | 22 void SetUp() override { |
23 source_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 23 source_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
24 media::CHANNEL_LAYOUT_MONO, 1, 48000, 16, 480); | 24 media::CHANNEL_LAYOUT_MONO, 48000, 16, 480); |
25 sink_params_.Reset( | 25 sink_params_.Reset( |
26 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | 26 media::AudioParameters::AUDIO_PCM_LOW_LATENCY, |
27 media::CHANNEL_LAYOUT_STEREO, 2, 44100, 16, | 27 media::CHANNEL_LAYOUT_STEREO, 44100, 16, |
28 WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize); | 28 WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize); |
29 sink_bus_ = media::AudioBus::Create(sink_params_); | 29 sink_bus_ = media::AudioBus::Create(sink_params_); |
30 MockMediaConstraintFactory constraint_factory; | 30 MockMediaConstraintFactory constraint_factory; |
31 scoped_refptr<WebRtcAudioCapturer> capturer( | 31 scoped_refptr<WebRtcAudioCapturer> capturer( |
32 WebRtcAudioCapturer::CreateCapturer( | 32 WebRtcAudioCapturer::CreateCapturer( |
33 -1, StreamDeviceInfo(), | 33 -1, StreamDeviceInfo(), |
34 constraint_factory.CreateWebMediaConstraints(), NULL, NULL)); | 34 constraint_factory.CreateWebMediaConstraints(), NULL, NULL)); |
35 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 35 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
36 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 36 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); |
37 scoped_ptr<WebRtcLocalAudioTrack> native_track( | 37 scoped_ptr<WebRtcLocalAudioTrack> native_track( |
(...skipping 28 matching lines...) Expand all Loading... |
66 // Point the WebVector into memory owned by |sink_bus_|. | 66 // Point the WebVector into memory owned by |sink_bus_|. |
67 blink::WebVector<float*> audio_data( | 67 blink::WebVector<float*> audio_data( |
68 static_cast<size_t>(sink_bus_->channels())); | 68 static_cast<size_t>(sink_bus_->channels())); |
69 for (size_t i = 0; i < audio_data.size(); ++i) | 69 for (size_t i = 0; i < audio_data.size(); ++i) |
70 audio_data[i] = sink_bus_->channel(i); | 70 audio_data[i] = sink_bus_->channel(i); |
71 | 71 |
72 // Enable the |source_provider_| by asking for data. This will inject | 72 // Enable the |source_provider_| by asking for data. This will inject |
73 // source_params_.frames_per_buffer() of zero into the resampler since there | 73 // source_params_.frames_per_buffer() of zero into the resampler since there |
74 // no available data in the FIFO. | 74 // no available data in the FIFO. |
75 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); | 75 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); |
76 EXPECT_TRUE(sink_bus_->channel(0)[0] == 0); | 76 EXPECT_EQ(0, sink_bus_->channel(0)[0]); |
77 | 77 |
78 // Create a source AudioBus with channel data filled with non-zero values. | 78 // Create a source AudioBus with channel data filled with non-zero values. |
79 const scoped_ptr<media::AudioBus> source_bus = | 79 const scoped_ptr<media::AudioBus> source_bus = |
80 media::AudioBus::Create(source_params_); | 80 media::AudioBus::Create(source_params_); |
81 std::fill(source_bus->channel(0), | 81 std::fill(source_bus->channel(0), |
82 source_bus->channel(0) + source_bus->frames(), | 82 source_bus->channel(0) + source_bus->frames(), |
83 0.5f); | 83 0.5f); |
84 | 84 |
85 // Deliver data to |source_provider_|. | 85 // Deliver data to |source_provider_|. |
86 base::TimeTicks estimated_capture_time = base::TimeTicks::Now(); | 86 base::TimeTicks estimated_capture_time = base::TimeTicks::Now(); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 // Stop the audio track. | 134 // Stop the audio track. |
135 WebRtcLocalAudioTrack* native_track = static_cast<WebRtcLocalAudioTrack*>( | 135 WebRtcLocalAudioTrack* native_track = static_cast<WebRtcLocalAudioTrack*>( |
136 MediaStreamTrack::GetTrack(blink_track_)); | 136 MediaStreamTrack::GetTrack(blink_track_)); |
137 native_track->Stop(); | 137 native_track->Stop(); |
138 | 138 |
139 // Delete the source provider. | 139 // Delete the source provider. |
140 source_provider_.reset(); | 140 source_provider_.reset(); |
141 } | 141 } |
142 | 142 |
143 } // namespace content | 143 } // namespace content |
OLD | NEW |