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

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

Issue 1647773002: MediaStream audio sourcing: Bypass audio processing for non-WebRTC cases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NOT FOR REVIEW -- This will be broken-up across multiple CLs. Created 4 years, 10 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/location.h" 10 #include "base/location.h"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/run_loop.h" 12 #include "base/run_loop.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/thread_task_runner_handle.h" 15 #include "base/thread_task_runner_handle.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "content/child/child_process.h" 17 #include "content/child/child_process.h"
18 #include "content/renderer/media/media_stream.h" 18 #include "content/renderer/media/media_stream.h"
19 #include "content/renderer/media/media_stream_audio_source.h"
20 #include "content/renderer/media/media_stream_source.h" 19 #include "content/renderer/media/media_stream_source.h"
21 #include "content/renderer/media/media_stream_video_track.h" 20 #include "content/renderer/media/media_stream_video_track.h"
22 #include "content/renderer/media/mock_data_channel_impl.h" 21 #include "content/renderer/media/mock_data_channel_impl.h"
23 #include "content/renderer/media/mock_media_constraint_factory.h" 22 #include "content/renderer/media/mock_media_constraint_factory.h"
24 #include "content/renderer/media/mock_media_stream_video_source.h" 23 #include "content/renderer/media/mock_media_stream_video_source.h"
25 #include "content/renderer/media/mock_peer_connection_impl.h" 24 #include "content/renderer/media/mock_peer_connection_impl.h"
26 #include "content/renderer/media/mock_web_rtc_peer_connection_handler_client.h" 25 #include "content/renderer/media/mock_web_rtc_peer_connection_handler_client.h"
27 #include "content/renderer/media/peer_connection_tracker.h" 26 #include "content/renderer/media/peer_connection_tracker.h"
28 #include "content/renderer/media/rtc_media_constraints.h" 27 #include "content/renderer/media/rtc_media_constraints.h"
29 #include "content/renderer/media/rtc_peer_connection_handler.h" 28 #include "content/renderer/media/rtc_peer_connection_handler.h"
30 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h" 29 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory. h"
30 #include "content/renderer/media/webrtc/processed_local_audio_source.h"
31 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" 31 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h"
32 #include "content/renderer/media/webrtc_local_audio_track.h"
33 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
35 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 34 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
36 #include "third_party/WebKit/public/platform/WebMediaStream.h" 35 #include "third_party/WebKit/public/platform/WebMediaStream.h"
37 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 36 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
38 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" 37 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
39 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" 38 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h"
40 #include "third_party/WebKit/public/platform/WebRTCDTMFSenderHandler.h" 39 #include "third_party/WebKit/public/platform/WebRTCDTMFSenderHandler.h"
41 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h" 40 #include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h"
42 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" 41 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 mock_dependency_factory_.reset(); 242 mock_dependency_factory_.reset();
244 mock_client_.reset(); 243 mock_client_.reset();
245 blink::WebHeap::collectAllGarbageForTesting(); 244 blink::WebHeap::collectAllGarbageForTesting();
246 } 245 }
247 246
248 // Creates a WebKit local MediaStream. 247 // Creates a WebKit local MediaStream.
249 blink::WebMediaStream CreateLocalMediaStream( 248 blink::WebMediaStream CreateLocalMediaStream(
250 const std::string& stream_label) { 249 const std::string& stream_label) {
251 std::string video_track_label("video-label"); 250 std::string video_track_label("video-label");
252 std::string audio_track_label("audio-label"); 251 std::string audio_track_label("audio-label");
253 blink::WebMediaStreamSource audio_source; 252
254 audio_source.initialize(blink::WebString::fromUTF8(audio_track_label), 253 blink::WebMediaStreamSource blink_audio_source;
255 blink::WebMediaStreamSource::TypeAudio, 254 blink_audio_source.initialize(blink::WebString::fromUTF8(audio_track_label),
256 blink::WebString::fromUTF8("audio_track"), 255 blink::WebMediaStreamSource::TypeAudio,
257 false /* remote */, true /* readonly */); 256 blink::WebString::fromUTF8("audio_track"),
258 audio_source.setExtraData(new MediaStreamAudioSource()); 257 false /* remote */, true /* readonly */);
258 ProcessedLocalAudioSource* const audio_source =
259 new ProcessedLocalAudioSource(
260 -1 /* consumer_render_frame_id is N/A for non-browser tests */,
261 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock device",
262 "mock_device_id"),
263 mock_dependency_factory_.get());
264 audio_source->SetAllowInvalidRenderFrameIdForTesting(true);
265 audio_source->SetSourceConstraints(
266 MockMediaConstraintFactory().CreateWebMediaConstraints());
267 blink_audio_source.setExtraData(audio_source); // Takes ownership.
268
269 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks(
270 static_cast<size_t>(1));
271 audio_tracks[0].initialize(blink_audio_source.id(), blink_audio_source);
272 CHECK(audio_source->ConnectToTrack(audio_tracks[0]));
273
259 blink::WebMediaStreamSource video_source; 274 blink::WebMediaStreamSource video_source;
260 video_source.initialize(blink::WebString::fromUTF8(video_track_label), 275 video_source.initialize(blink::WebString::fromUTF8(video_track_label),
261 blink::WebMediaStreamSource::TypeVideo, 276 blink::WebMediaStreamSource::TypeVideo,
262 blink::WebString::fromUTF8("video_track"), 277 blink::WebString::fromUTF8("video_track"),
263 false /* remote */, true /* readonly */); 278 false /* remote */, true /* readonly */);
264 MockMediaStreamVideoSource* native_video_source = 279 MockMediaStreamVideoSource* native_video_source =
265 new MockMediaStreamVideoSource(false); 280 new MockMediaStreamVideoSource(false);
266 video_source.setExtraData(native_video_source); 281 video_source.setExtraData(native_video_source);
267 282
268 blink::WebVector<blink::WebMediaStreamTrack> audio_tracks(
269 static_cast<size_t>(1));
270 audio_tracks[0].initialize(audio_source.id(), audio_source);
271 StreamDeviceInfo device_info(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock device",
272 "mock_device_id");
273 MockMediaConstraintFactory constraint_factory;
274 const blink::WebMediaConstraints constraints =
275 constraint_factory.CreateWebMediaConstraints();
276 scoped_refptr<WebRtcAudioCapturer> capturer(
277 WebRtcAudioCapturer::CreateCapturer(-1, device_info, constraints,
278 nullptr, nullptr));
279 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter(
280 WebRtcLocalAudioTrackAdapter::Create(audio_track_label, nullptr));
281 scoped_ptr<WebRtcLocalAudioTrack> native_track(
282 new WebRtcLocalAudioTrack(adapter.get(), capturer, nullptr));
283 audio_tracks[0].setExtraData(native_track.release());
284 blink::WebVector<blink::WebMediaStreamTrack> video_tracks( 283 blink::WebVector<blink::WebMediaStreamTrack> video_tracks(
285 static_cast<size_t>(1)); 284 static_cast<size_t>(1));
286 blink::WebMediaConstraints video_constraints; 285 blink::WebMediaConstraints video_constraints;
287 video_constraints.initialize(); 286 video_constraints.initialize();
288 video_tracks[0] = MediaStreamVideoTrack::CreateVideoTrack( 287 video_tracks[0] = MediaStreamVideoTrack::CreateVideoTrack(
289 native_video_source, video_constraints, 288 native_video_source, video_constraints,
290 MediaStreamVideoSource::ConstraintsCallback(), true); 289 MediaStreamVideoSource::ConstraintsCallback(), true);
291 290
292 blink::WebMediaStream local_stream; 291 blink::WebMediaStream local_stream;
293 local_stream.initialize(base::UTF8ToUTF16(stream_label), audio_tracks, 292 local_stream.initialize(base::UTF8ToUTF16(stream_label), audio_tracks,
(...skipping 12 matching lines...) Expand all
306 mock_dependency_factory_->CreateLocalMediaStream(stream_label)); 305 mock_dependency_factory_->CreateLocalMediaStream(stream_label));
307 if (!video_track_label.empty()) { 306 if (!video_track_label.empty()) {
308 webrtc::VideoSourceInterface* source = NULL; 307 webrtc::VideoSourceInterface* source = NULL;
309 scoped_refptr<webrtc::VideoTrackInterface> video_track( 308 scoped_refptr<webrtc::VideoTrackInterface> video_track(
310 mock_dependency_factory_->CreateLocalVideoTrack( 309 mock_dependency_factory_->CreateLocalVideoTrack(
311 video_track_label, source)); 310 video_track_label, source));
312 stream->AddTrack(video_track.get()); 311 stream->AddTrack(video_track.get());
313 } 312 }
314 if (!audio_track_label.empty()) { 313 if (!audio_track_label.empty()) {
315 scoped_refptr<webrtc::AudioTrackInterface> audio_track( 314 scoped_refptr<webrtc::AudioTrackInterface> audio_track(
316 WebRtcLocalAudioTrackAdapter::Create(audio_track_label, NULL)); 315 WebRtcLocalAudioTrackAdapter::Create(
316 audio_track_label, nullptr, pc_handler_->signaling_thread()));
317 stream->AddTrack(audio_track.get()); 317 stream->AddTrack(audio_track.get());
318 } 318 }
319 mock_peer_connection_->AddRemoteStream(stream.get()); 319 mock_peer_connection_->AddRemoteStream(stream.get());
320 return stream; 320 return stream;
321 } 321 }
322 322
323 base::MessageLoop message_loop_; 323 base::MessageLoop message_loop_;
324 scoped_ptr<ChildProcess> child_process_; 324 scoped_ptr<ChildProcess> child_process_;
325 scoped_ptr<MockWebRTCPeerConnectionHandlerClient> mock_client_; 325 scoped_ptr<MockWebRTCPeerConnectionHandlerClient> mock_client_;
326 scoped_ptr<MockPeerConnectionDependencyFactory> mock_dependency_factory_; 326 scoped_ptr<MockPeerConnectionDependencyFactory> mock_dependency_factory_;
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 EXPECT_CALL(*mock_tracker_.get(), 1038 EXPECT_CALL(*mock_tracker_.get(),
1039 TrackCreateDTMFSender(pc_handler_.get(), 1039 TrackCreateDTMFSender(pc_handler_.get(),
1040 testing::Ref(tracks[0]))); 1040 testing::Ref(tracks[0])));
1041 1041
1042 scoped_ptr<blink::WebRTCDTMFSenderHandler> sender( 1042 scoped_ptr<blink::WebRTCDTMFSenderHandler> sender(
1043 pc_handler_->createDTMFSender(tracks[0])); 1043 pc_handler_->createDTMFSender(tracks[0]));
1044 EXPECT_TRUE(sender.get()); 1044 EXPECT_TRUE(sender.get());
1045 } 1045 }
1046 1046
1047 } // namespace content 1047 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698