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

Side by Side Diff: webrtc/media/base/capturemanager_unittest.cc

Issue 1757843003: Remove CaptureManager and related calls in ChannelManager. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 9 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
« no previous file with comments | « webrtc/media/base/capturemanager.cc ('k') | webrtc/media/base/fakecapturemanager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2012 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 "webrtc/media/base/capturemanager.h"
12
13 #include "webrtc/base/arraysize.h"
14 #include "webrtc/base/gunit.h"
15 #include "webrtc/base/sigslot.h"
16 #include "webrtc/media/base/fakevideocapturer.h"
17 #include "webrtc/media/base/fakevideorenderer.h"
18
19 const int kMsCallbackWait = 50;
20
21 const int kFps = 30;
22 const cricket::VideoFormatPod kCameraFormats[] = {
23 {640, 480, cricket::VideoFormat::FpsToInterval(kFps), cricket::FOURCC_I420},
24 {320, 240, cricket::VideoFormat::FpsToInterval(kFps), cricket::FOURCC_I420}
25 };
26
27 class CaptureManagerTest : public ::testing::Test, public sigslot::has_slots<> {
28 public:
29 CaptureManagerTest()
30 : capture_manager_(),
31 callback_count_(0),
32 format_vga_(kCameraFormats[0]),
33 format_qvga_(kCameraFormats[1]) {
34 }
35 virtual void SetUp() {
36 PopulateSupportedFormats();
37 capture_state_ = cricket::CS_STOPPED;
38 capture_manager_.SignalCapturerStateChange.connect(
39 this,
40 &CaptureManagerTest::OnCapturerStateChange);
41 }
42 void PopulateSupportedFormats() {
43 std::vector<cricket::VideoFormat> formats;
44 for (uint32_t i = 0; i < arraysize(kCameraFormats); ++i) {
45 formats.push_back(cricket::VideoFormat(kCameraFormats[i]));
46 }
47 video_capturer_.ResetSupportedFormats(formats);
48 }
49 int NumFramesRendered() { return video_renderer_.num_rendered_frames(); }
50 bool WasRenderedResolution(cricket::VideoFormat format) {
51 return format.width == video_renderer_.width() &&
52 format.height == video_renderer_.height();
53 }
54 cricket::CaptureState capture_state() { return capture_state_; }
55 int callback_count() { return callback_count_; }
56 void OnCapturerStateChange(cricket::VideoCapturer* capturer,
57 cricket::CaptureState capture_state) {
58 capture_state_ = capture_state;
59 ++callback_count_;
60 }
61
62 protected:
63 cricket::FakeVideoCapturer video_capturer_;
64 cricket::FakeVideoRenderer video_renderer_;
65
66 cricket::CaptureManager capture_manager_;
67
68 cricket::CaptureState capture_state_;
69 int callback_count_;
70 cricket::VideoFormat format_vga_;
71 cricket::VideoFormat format_qvga_;
72 };
73
74 // Incorrect use cases.
75 TEST_F(CaptureManagerTest, InvalidAddingRemoving) {
76 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
77 cricket::VideoFormat()));
78 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
79 format_vga_));
80 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
81 EXPECT_EQ(1, callback_count());
82 // NULL argument currently allowed, and does nothing.
83 capture_manager_.AddVideoSink(&video_capturer_, NULL);
84 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
85 }
86
87 // Valid use cases
88 TEST_F(CaptureManagerTest, KeepFirstResolutionHigh) {
89 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
90 format_vga_));
91 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
92 EXPECT_EQ(1, callback_count());
93 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_);
94 EXPECT_TRUE(video_capturer_.CaptureFrame());
95 EXPECT_EQ(1, NumFramesRendered());
96 // Renderer should be fed frames with the resolution of format_vga_.
97 EXPECT_TRUE(WasRenderedResolution(format_vga_));
98
99 // Start again with one more format.
100 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
101 format_qvga_));
102 // Existing renderers should be fed frames with the resolution of format_vga_.
103 EXPECT_TRUE(video_capturer_.CaptureFrame());
104 EXPECT_TRUE(WasRenderedResolution(format_vga_));
105 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
106 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
107 format_qvga_));
108 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
109 format_vga_));
110 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
111 format_qvga_));
112 }
113
114 // Should pick the lowest resolution as the highest resolution is not chosen
115 // until after capturing has started. This ensures that no particular resolution
116 // is favored over others.
117 TEST_F(CaptureManagerTest, KeepFirstResolutionLow) {
118 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
119 format_qvga_));
120 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
121 format_vga_));
122 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_);
123 EXPECT_EQ_WAIT(1, callback_count(), kMsCallbackWait);
124 EXPECT_TRUE(video_capturer_.CaptureFrame());
125 EXPECT_EQ(1, NumFramesRendered());
126 EXPECT_TRUE(WasRenderedResolution(format_qvga_));
127 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
128 format_qvga_));
129 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
130 format_vga_));
131 }
132
133 // Ensure that the reference counting is working when multiple start and
134 // multiple stop calls are made.
135 TEST_F(CaptureManagerTest, MultipleStartStops) {
136 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
137 format_vga_));
138 // Add video capturer but with different format.
139 EXPECT_TRUE(capture_manager_.StartVideoCapture(&video_capturer_,
140 format_qvga_));
141 EXPECT_EQ_WAIT(cricket::CS_RUNNING, capture_state(), kMsCallbackWait);
142 EXPECT_EQ(1, callback_count());
143 capture_manager_.AddVideoSink(&video_capturer_, &video_renderer_);
144 // Ensure that a frame can be captured when two start calls have been made.
145 EXPECT_TRUE(video_capturer_.CaptureFrame());
146 EXPECT_EQ(1, NumFramesRendered());
147
148 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_, format_vga_));
149 // Video should still render since there has been two start calls but only
150 // one stop call.
151 EXPECT_TRUE(video_capturer_.CaptureFrame());
152 EXPECT_EQ(2, NumFramesRendered());
153
154 EXPECT_TRUE(capture_manager_.StopVideoCapture(&video_capturer_,
155 format_qvga_));
156 EXPECT_EQ_WAIT(cricket::CS_STOPPED, capture_state(), kMsCallbackWait);
157 EXPECT_EQ(2, callback_count());
158 // Last stop call should fail as it is one more than the number of start
159 // calls.
160 EXPECT_FALSE(capture_manager_.StopVideoCapture(&video_capturer_,
161 format_vga_));
162 }
OLDNEW
« no previous file with comments | « webrtc/media/base/capturemanager.cc ('k') | webrtc/media/base/fakecapturemanager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698