Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: webrtc/media/engine/webrtcvideocapturer_unittest.cc

Issue 2258933003: Refactor WebRtcVideoCapturer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #ifdef HAVE_WEBRTC_VIDEO 11 // TODO(nisse): For some reason rtc_media_unittests is built (gyp)
12 // without -DHAVE_WEBRTC_VIDEO. How to fix?
nisse-webrtc 2016/08/19 12:01:16 Should this be set explicitly in media.gyp? Or sho
perkj_webrtc 2016/08/19 13:08:59 just see what happens if you drop if HAVE_WEBRTC_V
nisse-webrtc 2016/08/19 13:30:02 Let's see if kjellander has any comments on the ot
nisse-webrtc 2016/08/23 08:36:26 That cl was landed, so reverted this change.
12 13
14 // #ifdef HAVE_WEBRTC_VIDEO
15 #if 1
13 #include <stdio.h> 16 #include <stdio.h>
14 17
15 #include <memory> 18 #include <memory>
16 #include <vector> 19 #include <vector>
17 20
18 #include "webrtc/base/gunit.h" 21 #include "webrtc/base/gunit.h"
19 #include "webrtc/base/logging.h" 22 #include "webrtc/base/logging.h"
20 #include "webrtc/base/stringutils.h" 23 #include "webrtc/base/stringutils.h"
21 #include "webrtc/base/thread.h" 24 #include "webrtc/base/thread.h"
22 #include "webrtc/media/base/testutils.h" 25 #include "webrtc/media/base/testutils.h"
23 #include "webrtc/media/base/videocommon.h" 26 #include "webrtc/media/base/videocommon.h"
24 #include "webrtc/media/engine/fakewebrtcvcmfactory.h" 27 #include "webrtc/media/engine/fakewebrtcvcmfactory.h"
25 #include "webrtc/media/engine/webrtcvideocapturer.h" 28 #include "webrtc/media/engine/webrtcvideocapturer.h"
26 29
27 using cricket::VideoFormat; 30 using cricket::VideoFormat;
28 31
29 static const std::string kTestDeviceName = "JuberTech FakeCam Q123"; 32 static const std::string kTestDeviceName = "JuberTech FakeCam Q123";
30 static const std::string kTestDeviceId = "foo://bar/baz"; 33 static const std::string kTestDeviceId = "foo://bar/baz";
31 const VideoFormat kDefaultVideoFormat = 34 const VideoFormat kDefaultVideoFormat =
32 VideoFormat(640, 400, VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY); 35 VideoFormat(640, 400, VideoFormat::FpsToInterval(30), cricket::FOURCC_ANY);
33 36
34 class WebRtcVideoCapturerTest : public testing::Test { 37 class WebRtcVideoCapturerTest : public testing::Test {
35 public: 38 public:
36 WebRtcVideoCapturerTest() 39 WebRtcVideoCapturerTest()
37 : factory_(new FakeWebRtcVcmFactory), 40 : factory_(new FakeWebRtcVcmFactory),
38 capturer_(new cricket::WebRtcVideoCapturer(factory_)), 41 capturer_(new cricket::WebRtcVideoCapturer(factory_)) {
39 listener_(capturer_.get()) {
40 factory_->device_info.AddDevice(kTestDeviceName, kTestDeviceId); 42 factory_->device_info.AddDevice(kTestDeviceName, kTestDeviceId);
41 // add a VGA/I420 capability 43 // add a VGA/I420 capability
42 webrtc::VideoCaptureCapability vga; 44 webrtc::VideoCaptureCapability vga;
43 vga.width = 640; 45 vga.width = 640;
44 vga.height = 480; 46 vga.height = 480;
45 vga.maxFPS = 30; 47 vga.maxFPS = 30;
46 vga.rawType = webrtc::kVideoI420; 48 vga.rawType = webrtc::kVideoI420;
47 factory_->device_info.AddCapability(kTestDeviceId, vga); 49 factory_->device_info.AddCapability(kTestDeviceId, vga);
48 } 50 }
49 51
50 protected: 52 protected:
51 FakeWebRtcVcmFactory* factory_; // owned by capturer_ 53 FakeWebRtcVcmFactory* factory_; // owned by capturer_
52 std::unique_ptr<cricket::WebRtcVideoCapturer> capturer_; 54 std::unique_ptr<cricket::WebRtcVideoCapturer> capturer_;
53 cricket::VideoCapturerListener listener_;
54 }; 55 };
55 56
56 TEST_F(WebRtcVideoCapturerTest, TestNotOpened) { 57 TEST_F(WebRtcVideoCapturerTest, TestNotOpened) {
57 EXPECT_EQ("", capturer_->GetId()); 58 EXPECT_EQ("", capturer_->GetId());
58 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty()); 59 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty());
59 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); 60 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL);
60 EXPECT_FALSE(capturer_->IsRunning()); 61 EXPECT_FALSE(capturer_->IsRunning());
61 } 62 }
62 63
63 TEST_F(WebRtcVideoCapturerTest, TestBadInit) { 64 TEST_F(WebRtcVideoCapturerTest, TestBadInit) {
(...skipping 12 matching lines...) Expand all
76 EXPECT_FALSE(capturer_->IsRunning()); 77 EXPECT_FALSE(capturer_->IsRunning());
77 } 78 }
78 79
79 TEST_F(WebRtcVideoCapturerTest, TestInitVcm) { 80 TEST_F(WebRtcVideoCapturerTest, TestInitVcm) {
80 EXPECT_TRUE(capturer_->Init(factory_->Create(0, 81 EXPECT_TRUE(capturer_->Init(factory_->Create(0,
81 reinterpret_cast<const char*>(kTestDeviceId.c_str())))); 82 reinterpret_cast<const char*>(kTestDeviceId.c_str()))));
82 } 83 }
83 84
84 TEST_F(WebRtcVideoCapturerTest, TestCapture) { 85 TEST_F(WebRtcVideoCapturerTest, TestCapture) {
85 EXPECT_TRUE(capturer_->Init(cricket::Device(kTestDeviceName, kTestDeviceId))); 86 EXPECT_TRUE(capturer_->Init(cricket::Device(kTestDeviceName, kTestDeviceId)));
87 cricket::VideoCapturerListener listener(capturer_.get());
86 cricket::VideoFormat format( 88 cricket::VideoFormat format(
87 capturer_->GetSupportedFormats()->at(0)); 89 capturer_->GetSupportedFormats()->at(0));
88 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format)); 90 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format));
89 EXPECT_TRUE(capturer_->IsRunning()); 91 EXPECT_TRUE(capturer_->IsRunning());
90 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL); 92 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL);
91 EXPECT_EQ(format, *capturer_->GetCaptureFormat()); 93 EXPECT_EQ(format, *capturer_->GetCaptureFormat());
92 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener_.last_capture_state(), 1000); 94 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener.last_capture_state(), 1000);
93 factory_->modules[0]->SendFrame(640, 480); 95 factory_->modules[0]->SendFrame(640, 480);
94 EXPECT_TRUE_WAIT(listener_.frame_count() > 0, 5000); 96 EXPECT_TRUE_WAIT(listener.frame_count() > 0, 5000);
95 EXPECT_EQ(capturer_->GetCaptureFormat()->fourcc, listener_.frame_fourcc()); 97 EXPECT_EQ(640, listener.frame_width());
96 EXPECT_EQ(640, listener_.frame_width()); 98 EXPECT_EQ(480, listener.frame_height());
97 EXPECT_EQ(480, listener_.frame_height());
98 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); 99 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format));
99 capturer_->Stop(); 100 capturer_->Stop();
100 EXPECT_FALSE(capturer_->IsRunning()); 101 EXPECT_FALSE(capturer_->IsRunning());
101 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); 102 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL);
102 EXPECT_EQ_WAIT(cricket::CS_STOPPED, listener_.last_capture_state(), 1000); 103 EXPECT_EQ_WAIT(cricket::CS_STOPPED, listener.last_capture_state(), 1000);
103 } 104 }
104 105
105 TEST_F(WebRtcVideoCapturerTest, TestCaptureVcm) { 106 TEST_F(WebRtcVideoCapturerTest, TestCaptureVcm) {
106 EXPECT_TRUE(capturer_->Init(factory_->Create(0, 107 EXPECT_TRUE(capturer_->Init(factory_->Create(0,
107 reinterpret_cast<const char*>(kTestDeviceId.c_str())))); 108 reinterpret_cast<const char*>(kTestDeviceId.c_str()))));
109 cricket::VideoCapturerListener listener(capturer_.get());
108 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty()); 110 EXPECT_TRUE(capturer_->GetSupportedFormats()->empty());
109 VideoFormat format; 111 VideoFormat format;
110 EXPECT_TRUE(capturer_->GetBestCaptureFormat(kDefaultVideoFormat, &format)); 112 EXPECT_TRUE(capturer_->GetBestCaptureFormat(kDefaultVideoFormat, &format));
111 EXPECT_EQ(kDefaultVideoFormat.width, format.width); 113 EXPECT_EQ(kDefaultVideoFormat.width, format.width);
112 EXPECT_EQ(kDefaultVideoFormat.height, format.height); 114 EXPECT_EQ(kDefaultVideoFormat.height, format.height);
113 EXPECT_EQ(kDefaultVideoFormat.interval, format.interval); 115 EXPECT_EQ(kDefaultVideoFormat.interval, format.interval);
114 EXPECT_EQ(cricket::FOURCC_I420, format.fourcc); 116 EXPECT_EQ(cricket::FOURCC_I420, format.fourcc);
115 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format)); 117 EXPECT_EQ(cricket::CS_STARTING, capturer_->Start(format));
116 EXPECT_TRUE(capturer_->IsRunning()); 118 EXPECT_TRUE(capturer_->IsRunning());
117 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL); 119 ASSERT_TRUE(capturer_->GetCaptureFormat() != NULL);
118 EXPECT_EQ(format, *capturer_->GetCaptureFormat()); 120 EXPECT_EQ(format, *capturer_->GetCaptureFormat());
119 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener_.last_capture_state(), 1000); 121 EXPECT_EQ_WAIT(cricket::CS_RUNNING, listener.last_capture_state(), 1000);
120 factory_->modules[0]->SendFrame(640, 480); 122 factory_->modules[0]->SendFrame(640, 480);
121 EXPECT_TRUE_WAIT(listener_.frame_count() > 0, 5000); 123 EXPECT_TRUE_WAIT(listener.frame_count() > 0, 5000);
122 EXPECT_EQ(capturer_->GetCaptureFormat()->fourcc, listener_.frame_fourcc()); 124 EXPECT_EQ(640, listener.frame_width());
123 EXPECT_EQ(640, listener_.frame_width()); 125 EXPECT_EQ(480, listener.frame_height());
124 EXPECT_EQ(480, listener_.frame_height());
125 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); 126 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format));
126 capturer_->Stop(); 127 capturer_->Stop();
127 EXPECT_FALSE(capturer_->IsRunning()); 128 EXPECT_FALSE(capturer_->IsRunning());
128 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); 129 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL);
129 } 130 }
130 131
131 TEST_F(WebRtcVideoCapturerTest, TestCaptureWithoutInit) { 132 TEST_F(WebRtcVideoCapturerTest, TestCaptureWithoutInit) {
132 cricket::VideoFormat format; 133 cricket::VideoFormat format;
133 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format)); 134 EXPECT_EQ(cricket::CS_FAILED, capturer_->Start(format));
134 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL); 135 EXPECT_TRUE(capturer_->GetCaptureFormat() == NULL);
135 EXPECT_FALSE(capturer_->IsRunning()); 136 EXPECT_FALSE(capturer_->IsRunning());
136 } 137 }
137 138
138 #endif // HAVE_WEBRTC_VIDEO 139 #endif // HAVE_WEBRTC_VIDEO
OLDNEW
« webrtc/media/engine/webrtcvideocapturer.cc ('K') | « webrtc/media/engine/webrtcvideocapturer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698