OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 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/base/gunit.h" | |
12 #include "webrtc/media/base/videobroadcaster.h" | |
13 #include "webrtc/media/engine/webrtcvideoframe.h" | |
14 | |
15 using rtc::VideoBroadcaster; | |
16 using rtc::VideoSinkWants; | |
17 using cricket::WebRtcVideoFrame; | |
18 | |
19 namespace { | |
20 | |
21 class TestSink : public rtc::VideoSinkInterface<cricket::VideoFrame> { | |
22 public: | |
23 void OnFrame(const cricket::VideoFrame& frame) override { | |
24 ++number_of_rendered_frames_; | |
25 } | |
26 | |
27 size_t number_of_rendered_frames_ = 0; | |
pbos-webrtc
2016/02/26 14:26:18
I think this should be an int.
perkj_webrtc
2016/02/26 15:22:34
Done.
| |
28 }; | |
29 | |
30 } // namespace | |
31 | |
32 TEST(VideoBroadcasterTest, frame_wanted) { | |
33 VideoBroadcaster broadcaster; | |
34 EXPECT_FALSE(broadcaster.frame_wanted()); | |
35 | |
36 TestSink sink; | |
37 broadcaster.AddOrUpdateSink(&sink, rtc::VideoSinkWants()); | |
38 EXPECT_TRUE(broadcaster.frame_wanted()); | |
39 | |
40 broadcaster.RemoveSink(&sink); | |
41 EXPECT_FALSE(broadcaster.frame_wanted()); | |
42 } | |
43 | |
44 TEST(VideoBroadcasterTest, OnFrame) { | |
45 VideoBroadcaster broadcaster; | |
46 | |
47 TestSink sink1; | |
48 TestSink sink2; | |
49 broadcaster.AddOrUpdateSink(&sink1, rtc::VideoSinkWants()); | |
50 broadcaster.AddOrUpdateSink(&sink2, rtc::VideoSinkWants()); | |
51 | |
52 WebRtcVideoFrame frame; | |
53 | |
54 broadcaster.OnFrame(frame); | |
55 EXPECT_EQ(1u, sink1.number_of_rendered_frames_); | |
56 EXPECT_EQ(1u, sink2.number_of_rendered_frames_); | |
57 | |
58 broadcaster.RemoveSink(&sink1); | |
59 broadcaster.OnFrame(frame); | |
60 EXPECT_EQ(1u, sink1.number_of_rendered_frames_); | |
61 EXPECT_EQ(2u, sink2.number_of_rendered_frames_); | |
62 | |
63 broadcaster.AddOrUpdateSink(&sink1, rtc::VideoSinkWants()); | |
64 broadcaster.OnFrame(frame); | |
65 EXPECT_EQ(2u, sink1.number_of_rendered_frames_); | |
66 EXPECT_EQ(3u, sink2.number_of_rendered_frames_); | |
67 } | |
68 | |
69 TEST(VideoBroadcasterTest, wants_rotation_applied) { | |
pbos-webrtc
2016/02/26 14:26:18
AppliesRotationIfAnySinkWantsRotationApplied or so
| |
70 VideoBroadcaster broadcaster; | |
71 EXPECT_TRUE(broadcaster.wants().rotation_applied); | |
72 | |
73 TestSink sink1; | |
74 VideoSinkWants wants1; | |
75 wants1.rotation_applied = false; | |
76 | |
77 broadcaster.AddOrUpdateSink(&sink1, wants1); | |
78 EXPECT_FALSE(broadcaster.wants().rotation_applied); | |
79 | |
80 TestSink sink2; | |
81 VideoSinkWants wants2; | |
82 wants2.rotation_applied = true; | |
83 | |
84 broadcaster.AddOrUpdateSink(&sink2, wants2); | |
85 EXPECT_TRUE(broadcaster.wants().rotation_applied); | |
86 | |
87 broadcaster.RemoveSink(&sink2); | |
88 EXPECT_FALSE(broadcaster.wants().rotation_applied); | |
89 } | |
90 | |
91 TEST(VideoBroadcasterTest, wants_max_pixel_count) { | |
perkj_webrtc
2016/02/26 15:22:34
AppliesMinOfSinkWantsMaxPixelCount
| |
92 VideoBroadcaster broadcaster; | |
93 EXPECT_TRUE(!broadcaster.wants().max_pixel_count); | |
94 | |
95 TestSink sink1; | |
96 VideoSinkWants wants1; | |
97 wants1.max_pixel_count = rtc::Optional<int>(1280 * 720); | |
98 | |
99 broadcaster.AddOrUpdateSink(&sink1, wants1); | |
100 EXPECT_EQ(1280 * 720, *broadcaster.wants().max_pixel_count); | |
101 | |
102 TestSink sink2; | |
103 VideoSinkWants wants2; | |
104 wants2.max_pixel_count = rtc::Optional<int>(640 * 360); | |
105 broadcaster.AddOrUpdateSink(&sink2, wants2); | |
106 EXPECT_EQ(640 * 360, *broadcaster.wants().max_pixel_count); | |
107 | |
108 broadcaster.RemoveSink(&sink2); | |
109 EXPECT_EQ(1280 * 720, *broadcaster.wants().max_pixel_count); | |
110 } | |
111 | |
112 TEST(VideoBroadcasterTest, wants_max_pixel_count_step_up) { | |
pbos-webrtc
2016/02/26 14:26:18
AppliesAMaxAboveMaxPixelCountStepUp
perkj_webrtc
2016/02/26 15:22:34
AppliesMinOfSinkWantsMaxPixelCountStepUP
| |
113 VideoBroadcaster broadcaster; | |
114 EXPECT_TRUE(!broadcaster.wants().max_pixel_count_step_up); | |
115 | |
116 TestSink sink1; | |
117 VideoSinkWants wants1; | |
118 wants1.max_pixel_count_step_up = rtc::Optional<int>(1280 * 720); | |
119 | |
120 broadcaster.AddOrUpdateSink(&sink1, wants1); | |
121 EXPECT_EQ(1280 * 720, *broadcaster.wants().max_pixel_count_step_up); | |
122 | |
123 TestSink sink2; | |
124 VideoSinkWants wants2; | |
125 wants2.max_pixel_count_step_up = rtc::Optional<int>(640 * 360); | |
126 broadcaster.AddOrUpdateSink(&sink2, wants2); | |
127 EXPECT_EQ(640 * 360, *broadcaster.wants().max_pixel_count_step_up); | |
128 | |
129 broadcaster.RemoveSink(&sink2); | |
130 EXPECT_EQ(1280 * 720, *broadcaster.wants().max_pixel_count_step_up); | |
131 } | |
OLD | NEW |