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

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

Issue 1780653002: Revert of MediaStream audio object graph untangling and clean-ups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 const scoped_ptr<WebRtcAudioCapturer> capturer = 79 capturer_ = WebRtcAudioCapturer::CreateCapturer(
80 WebRtcAudioCapturer::CreateCapturer( 80 -1, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "",
81 -1, StreamDeviceInfo( 81 params_.sample_rate(), params_.channel_layout(),
82 MEDIA_DEVICE_AUDIO_CAPTURE, "", "", params_.sample_rate(), 82 params_.frames_per_buffer()),
83 params_.channel_layout(), params_.frames_per_buffer()), 83 constraints, NULL, NULL);
84 constraints, nullptr, nullptr); 84 capturer_source_ = new MockCapturerSource();
85 const scoped_refptr<MockCapturerSource> capturer_source( 85 EXPECT_CALL(*capturer_source_.get(), Initialize(_, capturer_.get(), -1));
86 new MockCapturerSource()); 86 EXPECT_CALL(*capturer_source_.get(), SetAutomaticGainControl(true));
87 EXPECT_CALL(*capturer_source.get(), Initialize(_, capturer.get(), -1)); 87 EXPECT_CALL(*capturer_source_.get(), Start());
88 EXPECT_CALL(*capturer_source.get(), SetAutomaticGainControl(true)); 88 capturer_->SetCapturerSource(capturer_source_, params_);
89 EXPECT_CALL(*capturer_source.get(), Start());
90 capturer->SetCapturerSource(capturer_source, params_);
91 89
92 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( 90 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
93 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL)); 91 WebRtcLocalAudioTrackAdapter::Create(std::string(), NULL));
94 const scoped_ptr<WebRtcLocalAudioTrack> track( 92 track_.reset(new WebRtcLocalAudioTrack(adapter.get(), capturer_, NULL));
95 new WebRtcLocalAudioTrack(adapter.get())); 93 track_->Start();
96 capturer->AddTrack(track.get());
97 94
98 // Connect a mock sink to the track. 95 // Connect a mock sink to the track.
99 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink()); 96 scoped_ptr<MockMediaStreamAudioSink> sink(new MockMediaStreamAudioSink());
100 track->AddSink(sink.get()); 97 track_->AddSink(sink.get());
101 98
102 int delay_ms = 65; 99 int delay_ms = 65;
103 bool key_pressed = true; 100 bool key_pressed = true;
104 double volume = 0.9; 101 double volume = 0.9;
105 102
106 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_); 103 scoped_ptr<media::AudioBus> audio_bus = media::AudioBus::Create(params_);
107 audio_bus->Zero(); 104 audio_bus->Zero();
108 105
109 media::AudioCapturerSource::CaptureCallback* callback = 106 media::AudioCapturerSource::CaptureCallback* callback =
110 static_cast<media::AudioCapturerSource::CaptureCallback*>( 107 static_cast<media::AudioCapturerSource::CaptureCallback*>(
111 capturer.get()); 108 capturer_.get());
112 109
113 // Verify the sink is getting the correct values. 110 // Verify the sink is getting the correct values.
114 EXPECT_CALL(*sink, FormatIsSet()); 111 EXPECT_CALL(*sink, FormatIsSet());
115 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1)); 112 EXPECT_CALL(*sink, OnDataCallback()).Times(AtLeast(1));
116 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed); 113 callback->Capture(audio_bus.get(), delay_ms, volume, key_pressed);
117 114
118 track->RemoveSink(sink.get()); 115 track_->RemoveSink(sink.get());
119 EXPECT_CALL(*capturer_source.get(), Stop()); 116 EXPECT_CALL(*capturer_source_.get(), Stop());
120 capturer->Stop(); 117 capturer_->Stop();
121 } 118 }
122 119
123 media::AudioParameters params_; 120 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_ptr<WebRtcAudioCapturer> capturer(WebRtcAudioCapturer::CreateCapturer( 140 scoped_refptr<WebRtcAudioCapturer> capturer(
141 0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "", 141 WebRtcAudioCapturer::CreateCapturer(
142 params_.sample_rate(), params_.channel_layout(), 142 0, StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "", "",
143 params_.frames_per_buffer()), 143 params_.sample_rate(), params_.channel_layout(),
144 constraint_factory.CreateWebMediaConstraints(), NULL, NULL)); 144 params_.frames_per_buffer()),
145 constraint_factory.CreateWebMediaConstraints(), NULL, NULL));
145 EXPECT_TRUE(capturer.get() == NULL); 146 EXPECT_TRUE(capturer.get() == NULL);
146 } 147 }
147 148
148 149
149 } // namespace content 150 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_audio_capturer.cc ('k') | content/renderer/media/webrtc_audio_device_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698