OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "content/renderer/media/webrtc/webrtc_media_stream_adapter.h" | 5 #include "content/renderer/media/webrtc/webrtc_media_stream_adapter.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "content/child/child_process.h" | 12 #include "content/child/child_process.h" |
13 #include "content/renderer/media/media_stream.h" | 13 #include "content/renderer/media/media_stream.h" |
14 #include "content/renderer/media/media_stream_audio_source.h" | |
15 #include "content/renderer/media/media_stream_video_source.h" | 14 #include "content/renderer/media/media_stream_video_source.h" |
16 #include "content/renderer/media/media_stream_video_track.h" | 15 #include "content/renderer/media/media_stream_video_track.h" |
| 16 #include "content/renderer/media/mock_audio_device_factory.h" |
| 17 #include "content/renderer/media/mock_constraint_factory.h" |
17 #include "content/renderer/media/mock_media_stream_video_source.h" | 18 #include "content/renderer/media/mock_media_stream_video_source.h" |
18 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" | 19 #include "content/renderer/media/webrtc/mock_peer_connection_dependency_factory.
h" |
19 #include "content/renderer/media/webrtc/webrtc_local_audio_track_adapter.h" | 20 #include "content/renderer/media/webrtc/processed_local_audio_source.h" |
20 #include "content/renderer/media/webrtc_local_audio_track.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 23 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
23 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 24 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 25 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
25 #include "third_party/WebKit/public/platform/WebVector.h" | 26 #include "third_party/WebKit/public/platform/WebVector.h" |
26 #include "third_party/WebKit/public/web/WebHeap.h" | 27 #include "third_party/WebKit/public/web/WebHeap.h" |
27 | 28 |
| 29 using ::testing::_; |
| 30 |
28 namespace content { | 31 namespace content { |
29 | 32 |
30 class WebRtcMediaStreamAdapterTest : public ::testing::Test { | 33 class WebRtcMediaStreamAdapterTest : public ::testing::Test { |
31 public: | 34 public: |
32 void SetUp() override { | 35 void SetUp() override { |
33 child_process_.reset(new ChildProcess()); | 36 child_process_.reset(new ChildProcess()); |
34 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); | 37 dependency_factory_.reset(new MockPeerConnectionDependencyFactory()); |
35 } | 38 } |
36 | 39 |
37 void TearDown() override { | 40 void TearDown() override { |
38 adapter_.reset(); | 41 adapter_.reset(); |
39 blink::WebHeap::collectAllGarbageForTesting(); | 42 blink::WebHeap::collectAllGarbageForTesting(); |
40 } | 43 } |
41 | 44 |
42 blink::WebMediaStream CreateBlinkMediaStream(bool audio, bool video) { | 45 blink::WebMediaStream CreateBlinkMediaStream(bool audio, bool video) { |
43 blink::WebVector<blink::WebMediaStreamTrack> audio_track_vector( | 46 blink::WebVector<blink::WebMediaStreamTrack> audio_track_vector( |
44 audio ? static_cast<size_t>(1) : 0); | 47 audio ? static_cast<size_t>(1) : 0); |
45 if (audio) { | 48 if (audio) { |
46 blink::WebMediaStreamSource audio_source; | 49 blink::WebMediaStreamSource audio_source; |
47 audio_source.initialize("audio", | 50 audio_source.initialize("audio", |
48 blink::WebMediaStreamSource::TypeAudio, | 51 blink::WebMediaStreamSource::TypeAudio, |
49 "audio", | 52 "audio", |
50 false /* remote */); | 53 false /* remote */); |
51 audio_source.setExtraData(new MediaStreamAudioSource()); | 54 ProcessedLocalAudioSource* const source = |
52 | 55 new ProcessedLocalAudioSource( |
| 56 -1 /* consumer_render_frame_id is N/A for non-browser tests */, |
| 57 StreamDeviceInfo(MEDIA_DEVICE_AUDIO_CAPTURE, "Mock audio device", |
| 58 "mock_audio_device_id", |
| 59 media::AudioParameters::kAudioCDSampleRate, |
| 60 media::CHANNEL_LAYOUT_STEREO, |
| 61 media::AudioParameters::kAudioCDSampleRate / 50), |
| 62 dependency_factory_.get()); |
| 63 source->SetAllowInvalidRenderFrameIdForTesting(true); |
| 64 source->SetSourceConstraints( |
| 65 MockConstraintFactory().CreateWebMediaConstraints()); |
| 66 audio_source.setExtraData(source); // Takes ownership. |
53 audio_track_vector[0].initialize(audio_source); | 67 audio_track_vector[0].initialize(audio_source); |
54 scoped_refptr<WebRtcLocalAudioTrackAdapter> adapter( | 68 EXPECT_CALL(*mock_audio_device_factory_.mock_capturer_source(), |
55 WebRtcLocalAudioTrackAdapter::Create( | 69 Initialize(_, _, -1)); |
56 audio_track_vector[0].id().utf8(), nullptr)); | 70 EXPECT_CALL(*mock_audio_device_factory_.mock_capturer_source(), |
57 std::unique_ptr<WebRtcLocalAudioTrack> native_track( | 71 SetAutomaticGainControl(true)); |
58 new WebRtcLocalAudioTrack(adapter.get())); | 72 EXPECT_CALL(*mock_audio_device_factory_.mock_capturer_source(), Start()); |
59 audio_track_vector[0].setExtraData(native_track.release()); | 73 EXPECT_CALL(*mock_audio_device_factory_.mock_capturer_source(), Stop()); |
| 74 CHECK(source->ConnectToTrack(audio_track_vector[0])); |
60 } | 75 } |
61 | 76 |
62 blink::WebVector<blink::WebMediaStreamTrack> video_track_vector( | 77 blink::WebVector<blink::WebMediaStreamTrack> video_track_vector( |
63 video ? static_cast<size_t>(1) : 0); | 78 video ? static_cast<size_t>(1) : 0); |
64 MediaStreamSource::SourceStoppedCallback dummy_callback; | 79 MediaStreamSource::SourceStoppedCallback dummy_callback; |
65 if (video) { | 80 if (video) { |
66 blink::WebMediaStreamSource video_source; | 81 blink::WebMediaStreamSource video_source; |
67 video_source.initialize("video", | 82 video_source.initialize("video", |
68 blink::WebMediaStreamSource::TypeVideo, | 83 blink::WebMediaStreamSource::TypeVideo, |
69 "video", | 84 "video", |
(...skipping 27 matching lines...) Expand all Loading... |
97 EXPECT_EQ(expected_number_of_video_tracks, | 112 EXPECT_EQ(expected_number_of_video_tracks, |
98 adapter_->webrtc_media_stream()->GetVideoTracks().size()); | 113 adapter_->webrtc_media_stream()->GetVideoTracks().size()); |
99 EXPECT_EQ(blink_stream.id().utf8(), | 114 EXPECT_EQ(blink_stream.id().utf8(), |
100 adapter_->webrtc_media_stream()->label()); | 115 adapter_->webrtc_media_stream()->label()); |
101 } | 116 } |
102 | 117 |
103 webrtc::MediaStreamInterface* webrtc_stream() { | 118 webrtc::MediaStreamInterface* webrtc_stream() { |
104 return adapter_->webrtc_media_stream(); | 119 return adapter_->webrtc_media_stream(); |
105 } | 120 } |
106 | 121 |
107 protected: | 122 private: |
108 base::MessageLoop message_loop_; | 123 base::MessageLoop message_loop_; |
109 std::unique_ptr<ChildProcess> child_process_; | 124 std::unique_ptr<ChildProcess> child_process_; |
110 std::unique_ptr<MockPeerConnectionDependencyFactory> dependency_factory_; | 125 std::unique_ptr<MockPeerConnectionDependencyFactory> dependency_factory_; |
111 std::unique_ptr<WebRtcMediaStreamAdapter> adapter_; | 126 std::unique_ptr<WebRtcMediaStreamAdapter> adapter_; |
| 127 MockAudioDeviceFactory mock_audio_device_factory_; |
112 }; | 128 }; |
113 | 129 |
114 TEST_F(WebRtcMediaStreamAdapterTest, CreateWebRtcMediaStream) { | 130 TEST_F(WebRtcMediaStreamAdapterTest, CreateWebRtcMediaStream) { |
115 blink::WebMediaStream blink_stream = CreateBlinkMediaStream(true, true); | 131 blink::WebMediaStream blink_stream = CreateBlinkMediaStream(true, true); |
116 CreateWebRtcMediaStream(blink_stream, 1, 1); | 132 CreateWebRtcMediaStream(blink_stream, 1, 1); |
117 } | 133 } |
118 | 134 |
119 // Test that we don't crash if a MediaStream is created in Blink with an unknown | 135 // Test that we don't crash if a MediaStream is created in Blink with an unknown |
120 // audio sources. This can happen if a MediaStream is created with | 136 // audio sources. This can happen if a MediaStream is created with |
121 // remote audio track. | 137 // remote audio track. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 EXPECT_TRUE(webrtc_stream()->GetVideoTracks().empty()); | 175 EXPECT_TRUE(webrtc_stream()->GetVideoTracks().empty()); |
160 | 176 |
161 native_stream->AddTrack(audio_tracks[0]); | 177 native_stream->AddTrack(audio_tracks[0]); |
162 EXPECT_EQ(1u, webrtc_stream()->GetAudioTracks().size()); | 178 EXPECT_EQ(1u, webrtc_stream()->GetAudioTracks().size()); |
163 | 179 |
164 native_stream->AddTrack(video_tracks[0]); | 180 native_stream->AddTrack(video_tracks[0]); |
165 EXPECT_EQ(1u, webrtc_stream()->GetVideoTracks().size()); | 181 EXPECT_EQ(1u, webrtc_stream()->GetVideoTracks().size()); |
166 } | 182 } |
167 | 183 |
168 } // namespace content | 184 } // namespace content |
OLD | NEW |