OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #include <string> | |
12 | |
13 #include "webrtc/api/remotevideocapturer.h" | |
14 #include "webrtc/base/gunit.h" | |
15 #include "webrtc/media/engine/webrtcvideoframe.h" | |
16 | |
17 using cricket::CaptureState; | |
18 using cricket::VideoCapturer; | |
19 using cricket::VideoFormat; | |
20 using cricket::VideoFormatPod; | |
21 using cricket::VideoFrame; | |
22 | |
23 static const int kMaxWaitMs = 1000; | |
24 static const VideoFormatPod kTestFormat = | |
25 {640, 480, FPS_TO_INTERVAL(30), cricket::FOURCC_ANY}; | |
26 | |
27 class RemoteVideoCapturerTest : public testing::Test, | |
28 public sigslot::has_slots<> { | |
29 protected: | |
30 RemoteVideoCapturerTest() | |
31 : captured_frame_num_(0), | |
32 capture_state_(cricket::CS_STOPPED) {} | |
33 | |
34 virtual void SetUp() { | |
35 capturer_.SignalStateChange.connect( | |
36 this, &RemoteVideoCapturerTest::OnStateChange); | |
37 } | |
38 | |
39 ~RemoteVideoCapturerTest() { | |
40 capturer_.SignalStateChange.disconnect(this); | |
41 } | |
42 | |
43 int captured_frame_num() const { | |
44 return captured_frame_num_; | |
45 } | |
46 | |
47 CaptureState capture_state() const { | |
48 return capture_state_; | |
49 } | |
50 | |
51 webrtc::RemoteVideoCapturer capturer_; | |
52 | |
53 private: | |
54 void OnStateChange(VideoCapturer* capturer, | |
55 CaptureState capture_state) { | |
56 EXPECT_EQ(&capturer_, capturer); | |
57 capture_state_ = capture_state; | |
58 } | |
59 | |
60 int captured_frame_num_; | |
61 CaptureState capture_state_; | |
62 }; | |
63 | |
64 TEST_F(RemoteVideoCapturerTest, StartStop) { | |
65 // Start | |
66 EXPECT_TRUE( | |
67 capturer_.StartCapturing(VideoFormat(kTestFormat))); | |
68 EXPECT_TRUE_WAIT((cricket::CS_RUNNING == capture_state()), kMaxWaitMs); | |
69 EXPECT_EQ(VideoFormat(kTestFormat), | |
70 *capturer_.GetCaptureFormat()); | |
71 EXPECT_TRUE(capturer_.IsRunning()); | |
72 | |
73 // Stop | |
74 capturer_.Stop(); | |
75 EXPECT_TRUE_WAIT((cricket::CS_STOPPED == capture_state()), kMaxWaitMs); | |
76 EXPECT_TRUE(NULL == capturer_.GetCaptureFormat()); | |
77 } | |
78 | |
79 TEST_F(RemoteVideoCapturerTest, GetPreferredFourccs) { | |
80 EXPECT_FALSE(capturer_.GetPreferredFourccs(NULL)); | |
81 | |
82 std::vector<uint32_t> fourccs; | |
83 EXPECT_TRUE(capturer_.GetPreferredFourccs(&fourccs)); | |
84 EXPECT_EQ(1u, fourccs.size()); | |
85 EXPECT_EQ(cricket::FOURCC_I420, fourccs.at(0)); | |
86 } | |
87 | |
88 TEST_F(RemoteVideoCapturerTest, GetBestCaptureFormat) { | |
89 VideoFormat desired = VideoFormat(kTestFormat); | |
90 EXPECT_FALSE(capturer_.GetBestCaptureFormat(desired, NULL)); | |
91 | |
92 VideoFormat expected_format = VideoFormat(kTestFormat); | |
93 expected_format.fourcc = cricket::FOURCC_I420; | |
94 VideoFormat best_format; | |
95 EXPECT_TRUE(capturer_.GetBestCaptureFormat(desired, &best_format)); | |
96 EXPECT_EQ(expected_format, best_format); | |
97 } | |
OLD | NEW |