OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 static const std::string kTestDeviceName = "JuberTech FakeCam Q123"; | 29 static const std::string kTestDeviceName = "JuberTech FakeCam Q123"; |
30 static const std::string kTestDeviceId = "foo://bar/baz"; | 30 static const std::string kTestDeviceId = "foo://bar/baz"; |
31 const VideoFormat kDefaultVideoFormat = | 31 const VideoFormat kDefaultVideoFormat = |
32 VideoFormat(640, 400, VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY); | 32 VideoFormat(640, 400, VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY); |
33 | 33 |
34 class WebRtcVideoCapturerTest : public testing::Test { | 34 class WebRtcVideoCapturerTest : public testing::Test { |
35 public: | 35 public: |
36 WebRtcVideoCapturerTest() | 36 WebRtcVideoCapturerTest() |
37 : factory_(new FakeWebRtcVcmFactory), | 37 : factory_(new FakeWebRtcVcmFactory), |
38 capturer_(new cricket::WebRtcVideoCapturer(factory_)), | 38 capturer_(new cricket::WebRtcVideoCapturer(factory_)) { |
39 listener_(capturer_.get()) { | |
40 factory_->device_info.AddDevice(kTestDeviceName, kTestDeviceId); | 39 factory_->device_info.AddDevice(kTestDeviceName, kTestDeviceId); |
41 // add a VGA/I420 capability | 40 // add a VGA/I420 capability |
42 webrtc::VideoCaptureCapability vga; | 41 webrtc::VideoCaptureCapability vga; |
43 vga.width = 640; | 42 vga.width = 640; |
44 vga.height = 480; | 43 vga.height = 480; |
45 vga.maxFPS = 30; | 44 vga.maxFPS = 30; |
46 vga.rawType = webrtc::kVideoI420; | 45 vga.rawType = webrtc::kVideoI420; |
47 factory_->device_info.AddCapability(kTestDeviceId, vga); | 46 factory_->device_info.AddCapability(kTestDeviceId, vga); |
48 } | 47 } |
49 | 48 |
50 protected: | 49 protected: |
51 FakeWebRtcVcmFactory* factory_; // owned by capturer_ | 50 FakeWebRtcVcmFactory* factory_; // owned by capturer_ |
52 std::unique_ptr<cricket::WebRtcVideoCapturer> capturer_; | 51 std::unique_ptr<cricket::WebRtcVideoCapturer> capturer_; |
53 cricket::VideoCapturerListener listener_; | |
54 }; | 52 }; |
55 | 53 |
56 TEST_F(WebRtcVideoCapturerTest, TestNotOpened) { | 54 TEST_F(WebRtcVideoCapturerTest, TestNotOpened) { |
57 EXPECT_EQ("", capturer_->GetId()); | 55 EXPECT_EQ("", capturer_->GetId()); |
58 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty()); | 56 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty()); |
59 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); | 57 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); |
60 EXPECT_FALSE(capturer_->IsRunning()); | 58 EXPECT_FALSE(capturer_->IsRunning()); |
61 } | 59 } |
62 | 60 |
63 TEST_F(WebRtcVideoCapturerTest, TestBadInit) { | 61 TEST_F(WebRtcVideoCapturerTest, TestBadInit) { |
(...skipping 12 matching lines...) Expand all Loading... |
76 EXPECT_FALSE(capturer_->IsRunning()); | 74 EXPECT_FALSE(capturer_->IsRunning()); |
77 } | 75 } |
78 | 76 |
79 TEST_F(WebRtcVideoCapturerTest, TestInitVcm) { | 77 TEST_F(WebRtcVideoCapturerTest, TestInitVcm) { |
80 EXPECT_TRUE(capturer_->Init(factory_->Create(0, | 78 EXPECT_TRUE(capturer_->Init(factory_->Create(0, |
81 reinterpret_cast<const char*>(kTestDeviceId.c_str())))); | 79 reinterpret_cast<const char*>(kTestDeviceId.c_str())))); |
82 } | 80 } |
83 | 81 |
84 TEST_F(WebRtcVideoCapturerTest, TestCapture) { | 82 TEST_F(WebRtcVideoCapturerTest, TestCapture) { |
85 EXPECT_TRUE(capturer_->Init(cricket::Device(kTestDeviceName, kTestDeviceId))); | 83 EXPECT_TRUE(capturer_->Init(cricket::Device(kTestDeviceName, kTestDeviceId))); |
| 84 cricket::VideoCapturerListener listener(capturer_.get()); |
86 cricket::VideoFormat format( | 85 cricket::VideoFormat format( |
87 capturer_->GetSupportedFormats()->at(0)); | 86 capturer_->GetSupportedFormats()->at(0)); |
88 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format)); | 87 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format)); |
89 EXPECT_TRUE(capturer_->IsRunning()); | 88 EXPECT_TRUE(capturer_->IsRunning()); |
90 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL); | 89 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL); |
91 EXPECT_EQ(format, *capturer_->GetCaptureFormat()); | 90 EXPECT_EQ(format, *capturer_->GetCaptureFormat()); |
92 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener_.last_capture_state(), 1000); | 91 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener.last_capture_state(), 1000); |
93 factory_->modules[0]->SendFrame(640, 480); | 92 factory_->modules[0]->SendFrame(640, 480); |
94 EXPECT_TRUE_WAIT(listener_.frame_count() > 0, 5000); | 93 EXPECT_TRUE_WAIT(listener.frame_count() > 0, 5000); |
95 EXPECT_EQ(capturer_->GetCaptureFormat()->fourcc, listener_.frame_fourcc()); | 94 EXPECT_EQ(640, listener.frame_width()); |
96 EXPECT_EQ(640, listener_.frame_width()); | 95 EXPECT_EQ(480, listener.frame_height()); |
97 EXPECT_EQ(480, listener_.frame_height()); | |
98 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); | 96 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); |
99 capturer_->Stop(); | 97 capturer_->Stop(); |
100 EXPECT_FALSE(capturer_->IsRunning()); | 98 EXPECT_FALSE(capturer_->IsRunning()); |
101 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); | 99 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); |
102 EXPECT_EQ_WAIT(cricket::CS_STOPPED, listener_.last_capture_state(), 1000); | 100 EXPECT_EQ_WAIT(cricket::CS_STOPPED, listener.last_capture_state(), 1000); |
103 } | 101 } |
104 | 102 |
105 TEST_F(WebRtcVideoCapturerTest, TestCaptureVcm) { | 103 TEST_F(WebRtcVideoCapturerTest, TestCaptureVcm) { |
106 EXPECT_TRUE(capturer_->Init(factory_->Create(0, | 104 EXPECT_TRUE(capturer_->Init(factory_->Create(0, |
107 reinterpret_cast<const char*>(kTestDeviceId.c_str())))); | 105 reinterpret_cast<const char*>(kTestDeviceId.c_str())))); |
| 106 cricket::VideoCapturerListener listener(capturer_.get()); |
108 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty()); | 107 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty()); |
109 VideoFormat format; | 108 VideoFormat format; |
110 EXPECT_TRUE(capturer_->GetBestCaptureFormat(kDefaultVideoFormat, &format)); | 109 EXPECT_TRUE(capturer_->GetBestCaptureFormat(kDefaultVideoFormat, &format)); |
111 EXPECT_EQ(kDefaultVideoFormat.width, format.width); | 110 EXPECT_EQ(kDefaultVideoFormat.width, format.width); |
112 EXPECT_EQ(kDefaultVideoFormat.height, format.height); | 111 EXPECT_EQ(kDefaultVideoFormat.height, format.height); |
113 EXPECT_EQ(kDefaultVideoFormat.interval, format.interval); | 112 EXPECT_EQ(kDefaultVideoFormat.interval, format.interval); |
114 EXPECT_EQ(cricket::FOURCC_I420, format.fourcc); | 113 EXPECT_EQ(cricket::FOURCC_I420, format.fourcc); |
115 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format)); | 114 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format)); |
116 EXPECT_TRUE(capturer_->IsRunning()); | 115 EXPECT_TRUE(capturer_->IsRunning()); |
117 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL); | 116 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL); |
118 EXPECT_EQ(format, *capturer_->GetCaptureFormat()); | 117 EXPECT_EQ(format, *capturer_->GetCaptureFormat()); |
119 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener_.last_capture_state(), 1000); | 118 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener.last_capture_state(), 1000); |
120 factory_->modules[0]->SendFrame(640, 480); | 119 factory_->modules[0]->SendFrame(640, 480); |
121 EXPECT_TRUE_WAIT(listener_.frame_count() > 0, 5000); | 120 EXPECT_TRUE_WAIT(listener.frame_count() > 0, 5000); |
122 EXPECT_EQ(capturer_->GetCaptureFormat()->fourcc, listener_.frame_fourcc()); | 121 EXPECT_EQ(640, listener.frame_width()); |
123 EXPECT_EQ(640, listener_.frame_width()); | 122 EXPECT_EQ(480, listener.frame_height()); |
124 EXPECT_EQ(480, listener_.frame_height()); | |
125 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); | 123 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); |
126 capturer_->Stop(); | 124 capturer_->Stop(); |
127 EXPECT_FALSE(capturer_->IsRunning()); | 125 EXPECT_FALSE(capturer_->IsRunning()); |
128 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); | 126 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); |
129 } | 127 } |
130 | 128 |
131 TEST_F(WebRtcVideoCapturerTest, TestCaptureWithoutInit) { | 129 TEST_F(WebRtcVideoCapturerTest, TestCaptureWithoutInit) { |
132 cricket::VideoFormat format; | 130 cricket::VideoFormat format; |
133 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); | 131 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); |
134 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); | 132 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); |
135 EXPECT_FALSE(capturer_->IsRunning()); | 133 EXPECT_FALSE(capturer_->IsRunning()); |
136 } | 134 } |
137 | 135 |
138 #endif // HAVE_WEBRTC_VIDEO | 136 #endif // HAVE_WEBRTC_VIDEO |
OLD | NEW |