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 <memory> |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "webrtc/api/test/fakeconstraints.h" | 15 #include "webrtc/api/test/fakeconstraints.h" |
15 #include "webrtc/api/videocapturertracksource.h" | 16 #include "webrtc/api/videocapturertracksource.h" |
16 #include "webrtc/base/gunit.h" | 17 #include "webrtc/base/gunit.h" |
17 #include "webrtc/media/base/fakemediaengine.h" | 18 #include "webrtc/media/base/fakemediaengine.h" |
18 #include "webrtc/media/base/fakevideocapturer.h" | 19 #include "webrtc/media/base/fakevideocapturer.h" |
19 #include "webrtc/media/base/fakevideorenderer.h" | 20 #include "webrtc/media/base/fakevideorenderer.h" |
20 #include "webrtc/media/engine/webrtcvideoframe.h" | 21 #include "webrtc/media/engine/webrtcvideoframe.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 | 103 |
103 private: | 104 private: |
104 MediaSourceInterface::SourceState state_; | 105 MediaSourceInterface::SourceState state_; |
105 rtc::scoped_refptr<VideoTrackSourceInterface> source_; | 106 rtc::scoped_refptr<VideoTrackSourceInterface> source_; |
106 }; | 107 }; |
107 | 108 |
108 class VideoCapturerTrackSourceTest : public testing::Test { | 109 class VideoCapturerTrackSourceTest : public testing::Test { |
109 protected: | 110 protected: |
110 VideoCapturerTrackSourceTest() { InitCapturer(false); } | 111 VideoCapturerTrackSourceTest() { InitCapturer(false); } |
111 void InitCapturer(bool is_screencast) { | 112 void InitCapturer(bool is_screencast) { |
112 capturer_cleanup_ = rtc::scoped_ptr<TestVideoCapturer>( | 113 capturer_cleanup_ = std::unique_ptr<TestVideoCapturer>( |
113 new TestVideoCapturer(is_screencast)); | 114 new TestVideoCapturer(is_screencast)); |
114 capturer_ = capturer_cleanup_.get(); | 115 capturer_ = capturer_cleanup_.get(); |
115 } | 116 } |
116 | 117 |
117 void InitScreencast() { InitCapturer(true); } | 118 void InitScreencast() { InitCapturer(true); } |
118 | 119 |
119 void CreateVideoCapturerSource() { CreateVideoCapturerSource(NULL); } | 120 void CreateVideoCapturerSource() { CreateVideoCapturerSource(NULL); } |
120 | 121 |
121 void CreateVideoCapturerSource( | 122 void CreateVideoCapturerSource( |
122 const webrtc::MediaConstraintsInterface* constraints) { | 123 const webrtc::MediaConstraintsInterface* constraints) { |
123 // VideoSource take ownership of |capturer_| | 124 // VideoSource take ownership of |capturer_| |
124 source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(), | 125 source_ = VideoCapturerTrackSource::Create(rtc::Thread::Current(), |
125 capturer_cleanup_.release(), | 126 capturer_cleanup_.release(), |
126 constraints, false); | 127 constraints, false); |
127 | 128 |
128 ASSERT_TRUE(source_.get() != NULL); | 129 ASSERT_TRUE(source_.get() != NULL); |
129 | 130 |
130 state_observer_.reset(new StateObserver(source_)); | 131 state_observer_.reset(new StateObserver(source_)); |
131 source_->RegisterObserver(state_observer_.get()); | 132 source_->RegisterObserver(state_observer_.get()); |
132 source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); | 133 source_->AddOrUpdateSink(&renderer_, rtc::VideoSinkWants()); |
133 } | 134 } |
134 | 135 |
135 rtc::scoped_ptr<TestVideoCapturer> capturer_cleanup_; | 136 std::unique_ptr<TestVideoCapturer> capturer_cleanup_; |
136 TestVideoCapturer* capturer_; | 137 TestVideoCapturer* capturer_; |
137 cricket::FakeVideoRenderer renderer_; | 138 cricket::FakeVideoRenderer renderer_; |
138 rtc::scoped_ptr<StateObserver> state_observer_; | 139 std::unique_ptr<StateObserver> state_observer_; |
139 rtc::scoped_refptr<VideoTrackSourceInterface> source_; | 140 rtc::scoped_refptr<VideoTrackSourceInterface> source_; |
140 }; | 141 }; |
141 | 142 |
142 // Test that a VideoSource transition to kLive state when the capture | 143 // Test that a VideoSource transition to kLive state when the capture |
143 // device have started and kEnded if it is stopped. | 144 // device have started and kEnded if it is stopped. |
144 // It also test that an output can receive video frames. | 145 // It also test that an output can receive video frames. |
145 TEST_F(VideoCapturerTrackSourceTest, CapturerStartStop) { | 146 TEST_F(VideoCapturerTrackSourceTest, CapturerStartStop) { |
146 // Initialize without constraints. | 147 // Initialize without constraints. |
147 CreateVideoCapturerSource(); | 148 CreateVideoCapturerSource(); |
148 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 149 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 FakeConstraints constraints; | 482 FakeConstraints constraints; |
482 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5); | 483 constraints.AddOptional(MediaConstraintsInterface::kMaxFrameRate, 0.5); |
483 | 484 |
484 CreateVideoCapturerSource(&constraints); | 485 CreateVideoCapturerSource(&constraints); |
485 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), | 486 EXPECT_EQ_WAIT(MediaSourceInterface::kLive, state_observer_->state(), |
486 kMaxWaitMs); | 487 kMaxWaitMs); |
487 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); | 488 const cricket::VideoFormat* format = capturer_->GetCaptureFormat(); |
488 ASSERT_TRUE(format != NULL); | 489 ASSERT_TRUE(format != NULL); |
489 EXPECT_EQ(30, format->framerate()); | 490 EXPECT_EQ(30, format->framerate()); |
490 } | 491 } |
OLD | NEW |