OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "webrtc/api/remotevideocapturer.h" | 14 #include "webrtc/api/remotevideocapturer.h" |
15 #include "webrtc/api/test/fakeconstraints.h" | 15 #include "webrtc/api/test/fakeconstraints.h" |
16 #include "webrtc/api/videosource.h" | 16 #include "webrtc/api/videosource.h" |
17 #include "webrtc/base/gunit.h" | 17 #include "webrtc/base/gunit.h" |
18 #include "webrtc/media/base/fakemediaengine.h" | 18 #include "webrtc/media/base/fakemediaengine.h" |
19 #include "webrtc/media/base/fakevideocapturer.h" | 19 #include "webrtc/media/base/fakevideocapturer.h" |
20 #include "webrtc/media/base/fakevideorenderer.h" | 20 #include "webrtc/media/base/fakevideorenderer.h" |
21 #include "webrtc/media/engine/webrtcvideoframe.h" | 21 #include "webrtc/media/engine/webrtcvideoframe.h" |
22 #include "webrtc/pc/channelmanager.h" | |
23 | 22 |
24 using webrtc::FakeConstraints; | 23 using webrtc::FakeConstraints; |
25 using webrtc::VideoSource; | 24 using webrtc::VideoSource; |
26 using webrtc::MediaConstraintsInterface; | 25 using webrtc::MediaConstraintsInterface; |
27 using webrtc::MediaSourceInterface; | 26 using webrtc::MediaSourceInterface; |
28 using webrtc::ObserverInterface; | 27 using webrtc::ObserverInterface; |
29 using webrtc::VideoSourceInterface; | 28 using webrtc::VideoSourceInterface; |
30 | 29 |
31 namespace { | 30 namespace { |
32 | 31 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } | 103 } |
105 MediaSourceInterface::SourceState state() const { return state_; } | 104 MediaSourceInterface::SourceState state() const { return state_; } |
106 | 105 |
107 private: | 106 private: |
108 MediaSourceInterface::SourceState state_; | 107 MediaSourceInterface::SourceState state_; |
109 rtc::scoped_refptr<VideoSourceInterface> source_; | 108 rtc::scoped_refptr<VideoSourceInterface> source_; |
110 }; | 109 }; |
111 | 110 |
112 class VideoSourceTest : public testing::Test { | 111 class VideoSourceTest : public testing::Test { |
113 protected: | 112 protected: |
114 VideoSourceTest() | 113 VideoSourceTest() { |
115 : channel_manager_(new cricket::ChannelManager( | |
116 new cricket::FakeMediaEngine(), rtc::Thread::Current())) { | |
117 InitCapturer(false); | 114 InitCapturer(false); |
118 } | 115 } |
119 void InitCapturer(bool is_screencast) { | 116 void InitCapturer(bool is_screencast) { |
120 capturer_cleanup_ = rtc::scoped_ptr<TestVideoCapturer>( | 117 capturer_cleanup_ = rtc::scoped_ptr<TestVideoCapturer>( |
121 new TestVideoCapturer(is_screencast)); | 118 new TestVideoCapturer(is_screencast)); |
122 capturer_ = capturer_cleanup_.get(); | 119 capturer_ = capturer_cleanup_.get(); |
123 } | 120 } |
124 | 121 |
125 void InitScreencast() { InitCapturer(true); } | 122 void InitScreencast() { InitCapturer(true); } |
126 | 123 |
127 void SetUp() { | |
128 ASSERT_TRUE(channel_manager_->Init()); | |
129 } | |
130 | |
131 void CreateVideoSource() { | 124 void CreateVideoSource() { |
132 CreateVideoSource(NULL); | 125 CreateVideoSource(NULL); |
133 } | 126 } |
134 | 127 |
135 void CreateVideoSource( | 128 void CreateVideoSource( |
136 const webrtc::MediaConstraintsInterface* constraints) { | 129 const webrtc::MediaConstraintsInterface* constraints) { |
137 // VideoSource take ownership of |capturer_| | 130 // VideoSource take ownership of |capturer_| |
138 source_ = | 131 source_ = |
139 VideoSource::Create(channel_manager_.get(), capturer_cleanup_.release(), | 132 VideoSource::Create(rtc::Thread::Current(), capturer_cleanup_.release(), |
140 constraints, false); | 133 constraints, false); |
141 | 134 |
142 ASSERT_TRUE(source_.get() != NULL); | 135 ASSERT_TRUE(source_.get() != NULL); |
143 EXPECT_EQ(capturer_, source_->GetVideoCapturer()); | 136 EXPECT_EQ(capturer_, source_->GetVideoCapturer()); |
144 | 137 |
145 state_observer_.reset(new StateObserver(source_)); | 138 state_observer_.reset(new StateObserver(source_)); |
146 source_->RegisterObserver(state_observer_.get()); | 139 source_->RegisterObserver(state_observer_.get()); |
147 source_->AddSink(&renderer_); | 140 source_->AddSink(&renderer_); |
148 } | 141 } |
149 | 142 |
150 rtc::scoped_ptr<TestVideoCapturer> capturer_cleanup_; | 143 rtc::scoped_ptr<TestVideoCapturer> capturer_cleanup_; |
151 TestVideoCapturer* capturer_; | 144 TestVideoCapturer* capturer_; |
152 cricket::FakeVideoRenderer renderer_; | 145 cricket::FakeVideoRenderer renderer_; |
153 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_; | |
154 rtc::scoped_ptr<StateObserver> state_observer_; | 146 rtc::scoped_ptr<StateObserver> state_observer_; |
155 rtc::scoped_refptr<VideoSource> source_; | 147 rtc::scoped_refptr<VideoSource> source_; |
156 }; | 148 }; |
157 | 149 |
158 | 150 |
159 // Test that a VideoSource transition to kLive state when the capture | 151 // Test that a VideoSource transition to kLive state when the capture |
160 // device have started and kEnded if it is stopped. | 152 // device have started and kEnded if it is stopped. |
161 // It also test that an output can receive video frames. | 153 // It also test that an output can receive video frames. |
162 TEST_F(VideoSourceTest, CapturerStartStop) { | 154 TEST_F(VideoSourceTest, CapturerStartStop) { |
163 // Initialize without constraints. | 155 // Initialize without constraints. |
(...skipping 29 matching lines...) Expand all Loading... |
193 | 185 |
194 ASSERT_TRUE(capturer_->CaptureFrame()); | 186 ASSERT_TRUE(capturer_->CaptureFrame()); |
195 EXPECT_EQ(2, renderer_.num_rendered_frames()); | 187 EXPECT_EQ(2, renderer_.num_rendered_frames()); |
196 | 188 |
197 source_->Stop(); | 189 source_->Stop(); |
198 } | 190 } |
199 | 191 |
200 // Test start stop with a remote VideoSource - the video source that has a | 192 // Test start stop with a remote VideoSource - the video source that has a |
201 // RemoteVideoCapturer and takes video frames from FrameInput. | 193 // RemoteVideoCapturer and takes video frames from FrameInput. |
202 TEST_F(VideoSourceTest, StartStopRemote) { | 194 TEST_F(VideoSourceTest, StartStopRemote) { |
203 source_ = VideoSource::Create(channel_manager_.get(), | 195 source_ = VideoSource::Create(rtc::Thread::Current(), |
204 new webrtc::RemoteVideoCapturer(), NULL, true); | 196 new webrtc::RemoteVideoCapturer(), NULL, true); |
205 | 197 |
206 ASSERT_TRUE(source_.get() != NULL); | 198 ASSERT_TRUE(source_.get() != NULL); |
207 EXPECT_TRUE(NULL != source_->GetVideoCapturer()); | 199 EXPECT_TRUE(NULL != source_->GetVideoCapturer()); |
208 | 200 |
209 state_observer_.reset(new StateObserver(source_)); | 201 state_observer_.reset(new StateObserver(source_)); |
210 source_->RegisterObserver(state_observer_.get()); | 202 source_->RegisterObserver(state_observer_.get()); |
211 source_->AddSink(&renderer_); | 203 source_->AddSink(&renderer_); |
212 | 204 |
213 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 205 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 FakeConstraints constraints; | 520 FakeConstraints constraints; |
529 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5); | 521 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5); |
530 | 522 |
531 CreateVideoSource(&constraints); | 523 CreateVideoSource(&constraints); |
532 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 524 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
533 kMaxWaitMs); | 525 kMaxWaitMs); |
534 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 526 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
535 ASSERT_TRUE(format != NULL); | 527 ASSERT_TRUE(format != NULL); |
536 EXPECT_EQ(30, format->framerate()); | 528 EXPECT_EQ(30, format->framerate()); |
537 } | 529 } |
OLD | NEW |