OLD | NEW |
| (Empty) |
1 /* | |
2 * libjingle | |
3 * Copyright 2004 Google Inc. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions are met: | |
7 * | |
8 * 1. Redistributions of source code must retain the above copyright notice, | |
9 * this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | |
11 * this list of conditions and the following disclaimer in the documentation | |
12 * and/or other materials provided with the distribution. | |
13 * 3. The name of the author may not be used to endorse or promote products | |
14 * derived from this software without specific prior written permission. | |
15 * | |
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
26 */ | |
27 | |
28 #ifdef HAVE_WEBRTC_VIDEO | |
29 | |
30 #include <stdio.h> | |
31 #include <vector> | |
32 #include "talk/media/base/testutils.h" | |
33 #include "talk/media/base/videocommon.h" | |
34 #include "talk/media/webrtc/fakewebrtcvcmfactory.h" | |
35 #include "talk/media/webrtc/webrtcvideocapturer.h" | |
36 #include "webrtc/base/gunit.h" | |
37 #include "webrtc/base/logging.h" | |
38 #include "webrtc/base/stringutils.h" | |
39 #include "webrtc/base/thread.h" | |
40 | |
41 using cricket::VideoFormat; | |
42 | |
43 static const std::string kTestDeviceName = "JuberTech FakeCam Q123"; | |
44 static const std::string kTestDeviceId = "foo://bar/baz"; | |
45 const VideoFormat kDefaultVideoFormat = | |
46 VideoFormat(640, 400, VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY); | |
47 | |
48 class WebRtcVideoCapturerTest : public testing::Test { | |
49 public: | |
50 WebRtcVideoCapturerTest() | |
51 : factory_(new FakeWebRtcVcmFactory), | |
52 capturer_(new cricket::WebRtcVideoCapturer(factory_)), | |
53 listener_(capturer_.get()) { | |
54 factory_->device_info.AddDevice(kTestDeviceName, kTestDeviceId); | |
55 // add a VGA/I420 capability | |
56 webrtc::VideoCaptureCapability vga; | |
57 vga.width = 640; | |
58 vga.height = 480; | |
59 vga.maxFPS = 30; | |
60 vga.rawType = webrtc::kVideoI420; | |
61 factory_->device_info.AddCapability(kTestDeviceId, vga); | |
62 } | |
63 | |
64 protected: | |
65 FakeWebRtcVcmFactory* factory_; // owned by capturer_ | |
66 rtc::scoped_ptr<cricket::WebRtcVideoCapturer> capturer_; | |
67 cricket::VideoCapturerListener listener_; | |
68 }; | |
69 | |
70 TEST_F(WebRtcVideoCapturerTest, TestNotOpened) { | |
71 EXPECT_EQ("", capturer_->GetId()); | |
72 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty()); | |
73 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); | |
74 EXPECT_FALSE(capturer_->IsRunning()); | |
75 } | |
76 | |
77 TEST_F(WebRtcVideoCapturerTest, TestBadInit) { | |
78 EXPECT_FALSE(capturer_->Init(cricket::Device("bad-name", "bad-id"))); | |
79 EXPECT_FALSE(capturer_->IsRunning()); | |
80 } | |
81 | |
82 TEST_F(WebRtcVideoCapturerTest, TestInit) { | |
83 EXPECT_TRUE(capturer_->Init(cricket::Device(kTestDeviceName, kTestDeviceId))); | |
84 EXPECT_EQ(kTestDeviceId, capturer_->GetId()); | |
85 EXPECT_TRUE(NULL != capturer_->GetSupportedFormats()); | |
86 ASSERT_EQ(1U, capturer_->GetSupportedFormats()->size()); | |
87 EXPECT_EQ(640, (*capturer_->GetSupportedFormats())[0].width); | |
88 EXPECT_EQ(480, (*capturer_->GetSupportedFormats())[0].height); | |
89 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); // not started yet | |
90 EXPECT_FALSE(capturer_->IsRunning()); | |
91 } | |
92 | |
93 TEST_F(WebRtcVideoCapturerTest, TestInitVcm) { | |
94 EXPECT_TRUE(capturer_->Init(factory_->Create(0, | |
95 reinterpret_cast<const char*>(kTestDeviceId.c_str())))); | |
96 } | |
97 | |
98 TEST_F(WebRtcVideoCapturerTest, TestCapture) { | |
99 EXPECT_TRUE(capturer_->Init(cricket::Device(kTestDeviceName, kTestDeviceId))); | |
100 cricket::VideoFormat format( | |
101 capturer_->GetSupportedFormats()->at(0)); | |
102 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format)); | |
103 EXPECT_TRUE(capturer_->IsRunning()); | |
104 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL); | |
105 EXPECT_EQ(format, *capturer_->GetCaptureFormat()); | |
106 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener_.last_capture_state(), 1000); | |
107 EXPECT_TRUE(factory_->modules[0]->SendFrame(640, 480)); | |
108 EXPECT_TRUE_WAIT(listener_.frame_count() > 0, 5000); | |
109 EXPECT_EQ(capturer_->GetCaptureFormat()->fourcc, listener_.frame_fourcc()); | |
110 EXPECT_EQ(640, listener_.frame_width()); | |
111 EXPECT_EQ(480, listener_.frame_height()); | |
112 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); | |
113 capturer_->Stop(); | |
114 EXPECT_FALSE(capturer_->IsRunning()); | |
115 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); | |
116 EXPECT_EQ_WAIT(cricket::CS_STOPPED, listener_.last_capture_state(), 1000); | |
117 } | |
118 | |
119 TEST_F(WebRtcVideoCapturerTest, TestCaptureVcm) { | |
120 EXPECT_TRUE(capturer_->Init(factory_->Create(0, | |
121 reinterpret_cast<const char*>(kTestDeviceId.c_str())))); | |
122 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty()); | |
123 VideoFormat format; | |
124 EXPECT_TRUE(capturer_->GetBestCaptureFormat(kDefaultVideoFormat, &format)); | |
125 EXPECT_EQ(kDefaultVideoFormat.width, format.width); | |
126 EXPECT_EQ(kDefaultVideoFormat.height, format.height); | |
127 EXPECT_EQ(kDefaultVideoFormat.interval, format.interval); | |
128 EXPECT_EQ(cricket::FOURCC_I420, format.fourcc); | |
129 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format)); | |
130 EXPECT_TRUE(capturer_->IsRunning()); | |
131 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL); | |
132 EXPECT_EQ(format, *capturer_->GetCaptureFormat()); | |
133 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener_.last_capture_state(), 1000); | |
134 EXPECT_TRUE(factory_->modules[0]->SendFrame(640, 480)); | |
135 EXPECT_TRUE_WAIT(listener_.frame_count() > 0, 5000); | |
136 EXPECT_EQ(capturer_->GetCaptureFormat()->fourcc, listener_.frame_fourcc()); | |
137 EXPECT_EQ(640, listener_.frame_width()); | |
138 EXPECT_EQ(480, listener_.frame_height()); | |
139 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); | |
140 capturer_->Stop(); | |
141 EXPECT_FALSE(capturer_->IsRunning()); | |
142 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); | |
143 } | |
144 | |
145 TEST_F(WebRtcVideoCapturerTest, TestCaptureWithoutInit) { | |
146 cricket::VideoFormat format; | |
147 EXPECT_EQ(cricket::CS_NO_DEVICE, capturer_->Start(format)); | |
148 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); | |
149 EXPECT_FALSE(capturer_->IsRunning()); | |
150 } | |
151 | |
152 #endif // HAVE_WEBRTC_VIDEO | |
OLD | NEW |