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 "build/build_config.h" | 6 #include "build/build_config.h" |
7 #include "content/public/renderer/media_stream_audio_sink.h" | 7 #include "content/public/renderer/media_stream_audio_sink.h" |
8 #include "content/renderer/media/mock_media_constraint_factory.h" | 8 #include "content/renderer/media/mock_media_constraint_factory.h" |
9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 9 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" |
10 #include "content/renderer/media/webrtc_audio_capturer.h" | 10 #include "content/renderer/media/webrtc_audio_capturer.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 params_.sample_rate(), params_.channel_layout(), | 81 params_.sample_rate(), params_.channel_layout(), |
82 params_.frames_per_buffer()), | 82 params_.frames_per_buffer()), |
83 constraints, NULL, NULL); | 83 constraints, NULL, NULL); |
84 capturer_source_ = new MockCapturerSource(); | 84 capturer_source_ = new MockCapturerSource(); |
85 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), -1)); | 85 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), -1)); |
86 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); | 86 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); |
87 EXPECT_CALL(*capturer_source_.get(), Start()); | 87 EXPECT_CALL(*capturer_source_.get(), Start()); |
88 capturer_->SetCapturerSource(capturer_source_, params_); | 88 capturer_->SetCapturerSource(capturer_source_, params_); |
89 | 89 |
90 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 90 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( |
91 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); | 91 WebRtcLocalAudioTrackAdapter::Create(std::string(), nullptr, nullptr)); |
92 track_.reset(new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); | 92 track_.reset(new WebRtcLocalAudioTrack(adapter.get())); |
93 track_->Start(); | 93 capturer_->AddTrack(track_.get()); |
94 | 94 |
95 // Connect a mock sink to the track. | 95 // Connect a mock sink to the track. |
96 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); | 96 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); |
97 track_->AddSink(sink.get()); | 97 track_->AddSink(sink.get()); |
98 | 98 |
99 int delay_ms = 65; | 99 int delay_ms = 65; |
100 bool key_pressed = true; | 100 bool key_pressed = true; |
101 double volume = 0.9; | 101 double volume = 0.9; |
102 | 102 |
103 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); | 103 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); |
104 audio_bus->Zero(); | 104 audio_bus->Zero(); |
105 | 105 |
106 media::AudioCapturerSource::CaptureCallback* callback = | 106 media::AudioCapturerSource::CaptureCallback* callback = |
107 static_cast<media::AudioCapturerSource::CaptureCallback*>( | 107 static_cast<media::AudioCapturerSource::CaptureCallback*>( |
108 capturer_.get()); | 108 capturer_.get()); |
109 | 109 |
110 // Verify the sink is getting the correct values. | 110 // Verify the sink is getting the correct values. |
111 EXPECT_CALL(*sink, FormatIsSet()); | 111 EXPECT_CALL(*sink, FormatIsSet()); |
112 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); | 112 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); |
113 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); | 113 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); |
114 | 114 |
115 track_->RemoveSink(sink.get()); | 115 track_->RemoveSink(sink.get()); |
116 EXPECT_CALL(*capturer_source_.get(), Stop()); | 116 EXPECT_CALL(*capturer_source_.get(), Stop()); |
117 capturer_->Stop(); | 117 capturer_->Stop(); |
118 } | 118 } |
119 | 119 |
120 media::AudioParameters params_; | 120 media::AudioParameters params_; |
121 scoped_refptr<MockCapturerSource> capturer_source_; | 121 scoped_refptr<MockCapturerSource> capturer_source_; |
122 scoped_refptr<WebRtcAudioCapturer> capturer_; | 122 scoped_ptr<WebRtcAudioCapturer> capturer_; |
123 scoped_ptr<WebRtcLocalAudioTrack> track_; | 123 scoped_ptr<WebRtcLocalAudioTrack> track_; |
124 }; | 124 }; |
125 | 125 |
126 TEST_F(WebRtcAudioCapturerTest, VerifyAudioParamsWithAudioProcessing) { | 126 TEST_F(WebRtcAudioCapturerTest, VerifyAudioParamsWithAudioProcessing) { |
127 // Turn off the default constraints to verify that the sink will get packets | 127 // Turn off the default constraints to verify that the sink will get packets |
128 // with a buffer size smaller than 10ms. | 128 // with a buffer size smaller than 10ms. |
129 MockMediaConstraintFactory constraint_factory; | 129 MockMediaConstraintFactory constraint_factory; |
130 constraint_factory.DisableDefaultAudioConstraints(); | 130 constraint_factory.DisableDefaultAudioConstraints(); |
131 VerifyAudioParams(constraint_factory.CreateWebMediaConstraints(), false); | 131 VerifyAudioParams(constraint_factory.CreateWebMediaConstraints(), false); |
132 } | 132 } |
133 | 133 |
134 TEST_F(WebRtcAudioCapturerTest, FailToCreateCapturerWithWrongConstraints) { | 134 TEST_F(WebRtcAudioCapturerTest, FailToCreateCapturerWithWrongConstraints) { |
135 MockMediaConstraintFactory constraint_factory; | 135 MockMediaConstraintFactory constraint_factory; |
136 const std::string dummy_constraint = "dummy"; | 136 const std::string dummy_constraint = "dummy"; |
137 constraint_factory.AddMandatory(dummy_constraint, true); | 137 constraint_factory.AddMandatory(dummy_constraint, true); |
138 | 138 |
139 scoped_refptr<WebRtcAudioCapturer> capturer( | 139 scoped_ptr<WebRtcAudioCapturer> capturer( |
140 WebRtcAudioCapturer::CreateCapturer( | 140 WebRtcAudioCapturer::CreateCapturer( |
141 0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "", | 141 0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "", |
142 params_.sample_rate(), params_.channel_layout(), | 142 params_.sample_rate(), params_.channel_layout(), |
143 params_.frames_per_buffer()), | 143 params_.frames_per_buffer()), |
144 constraint_factory.CreateWebMediaConstraints(), NULL, NULL)); | 144 constraint_factory.CreateWebMediaConstraints(), NULL, NULL)); |
145 EXPECT_TRUE(capturer.get() == NULL); | 145 EXPECT_TRUE(capturer.get() == NULL); |
146 } | 146 } |
147 | 147 |
148 | 148 |
149 } // namespace content | 149 } // namespace content |
OLD | NEW |