Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: content/renderer/media/webrtc_audio_capturer_unittest.cc

Issue 1721273002: MediaStream audio object graph untangling and clean-ups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed mcasas's 1st round comments, plus REBASE. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_constraint_factory.h" 8 #include "content/renderer/media/mock_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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 960) { 69 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 960) {
70 // Android works with a buffer size bigger than 20ms. 70 // Android works with a buffer size bigger than 20ms.
71 #else 71 #else
72 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, 72 : params_(media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
73 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128) { 73 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 128) {
74 #endif 74 #endif
75 } 75 }
76 76
77 void VerifyAudioParams(const blink::WebMediaConstraints& constraints, 77 void VerifyAudioParams(const blink::WebMediaConstraints& constraints,
78 bool need_audio_processing) { 78 bool need_audio_processing) {
79 capturer_ = WebRtcAudioCapturer::CreateCapturer( 79 const scoped_ptr<WebRtcAudioCapturer> capturer =
80 -1, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "", 80 WebRtcAudioCapturer::CreateCapturer(
81 params_.sample_rate(), params_.channel_layout(), 81 -1, StreamDeviceInfo(
82 params_.frames_per_buffer()), 82 MEDIA_DEVICE_AUDIO_CAPTURE, "", "", params_.sample_rate(),
83 constraints, NULL, NULL); 83 params_.channel_layout(), params_.frames_per_buffer()),
84 capturer_source_ = new MockCapturerSource(); 84 constraints, nullptr, nullptr);
85 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), -1)); 85 const scoped_refptr<MockCapturerSource> capturer_source(
86 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true)); 86 new MockCapturerSource());
87 EXPECT_CALL(*capturer_source_.get(), Start()); 87 EXPECT_CALL(*capturer_source.get(), Initialize(_, capturer.get(), -1));
88 capturer_->SetCapturerSource(capturer_source_, params_); 88 EXPECT_CALL(*capturer_source.get(), SetAutomaticGainControl(true));
89 EXPECT_CALL(*capturer_source.get(), Start());
90 capturer->SetCapturerSource(capturer_source, params_);
89 91
90 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 92 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
91 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 93 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
92 track_.reset(new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL)); 94 const scoped_ptr<WebRtcLocalAudioTrack> track(
93 track_->Start(); 95 new WebRtcLocalAudioTrack(adapter.get()));
96 capturer->AddTrack(track.get());
94 97
95 // Connect a mock sink to the track. 98 // Connect a mock sink to the track.
96 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); 99 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
97 track_->AddSink(sink.get()); 100 track->AddSink(sink.get());
98 101
99 int delay_ms = 65; 102 int delay_ms = 65;
100 bool key_pressed = true; 103 bool key_pressed = true;
101 double volume = 0.9; 104 double volume = 0.9;
102 105
103 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); 106 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_);
104 audio_bus->Zero(); 107 audio_bus->Zero();
105 108
106 media::AudioCapturerSource::CaptureCallback* callback = 109 media::AudioCapturerSource::CaptureCallback* callback =
107 static_cast<media::AudioCapturerSource::CaptureCallback*>( 110 static_cast<media::AudioCapturerSource::CaptureCallback*>(
108 capturer_.get()); 111 capturer.get());
109 112
110 // Verify the sink is getting the correct values. 113 // Verify the sink is getting the correct values.
111 EXPECT_CALL(*sink, FormatIsSet()); 114 EXPECT_CALL(*sink, FormatIsSet());
112 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); 115 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1));
113 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); 116 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed);
114 117
115 track_->RemoveSink(sink.get()); 118 track->RemoveSink(sink.get());
116 EXPECT_CALL(*capturer_source_.get(), Stop()); 119 EXPECT_CALL(*capturer_source.get(), Stop());
117 capturer_->Stop(); 120 capturer->Stop();
118 } 121 }
119 122
120 media::AudioParameters params_; 123 media::AudioParameters params_;
121 scoped_refptr<MockCapturerSource> capturer_source_;
122 scoped_refptr<WebRtcAudioCapturer> capturer_;
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 MockConstraintFactory constraint_factory; 129 MockConstraintFactory 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 MockConstraintFactory constraint_factory; 135 MockConstraintFactory constraint_factory;
136 const std::string dummy_constraint = "dummy"; 136 const std::string dummy_constraint = "dummy";
137 // Set a non-audio constraint. 137 // Set a non-audio constraint.
138 constraint_factory.basic().width.setExact(240); 138 constraint_factory.basic().width.setExact(240);
139 139
140 scoped_refptr<WebRtcAudioCapturer> capturer( 140 scoped_ptr<WebRtcAudioCapturer> capturer(WebRtcAudioCapturer::CreateCapturer(
141 WebRtcAudioCapturer::CreateCapturer( 141 0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "",
142 0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "", 142 params_.sample_rate(), params_.channel_layout(),
143 params_.sample_rate(), params_.channel_layout(), 143 params_.frames_per_buffer()),
144 params_.frames_per_buffer()), 144 constraint_factory.CreateWebMediaConstraints(), NULL, NULL));
145 constraint_factory.CreateWebMediaConstraints(), NULL, NULL));
146 EXPECT_TRUE(capturer.get() == NULL); 145 EXPECT_TRUE(capturer.get() == NULL);
147 } 146 }
148 147
149 148
150 } // namespace content 149 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698