OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2016 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 #include "webrtc/api/video/i420_buffer.h" |
| 12 #include "webrtc/api/video/video_frame.h" |
11 #include "webrtc/base/gunit.h" | 13 #include "webrtc/base/gunit.h" |
12 #include "webrtc/media/base/fakevideorenderer.h" | 14 #include "webrtc/media/base/fakevideorenderer.h" |
13 #include "webrtc/media/base/videobroadcaster.h" | 15 #include "webrtc/media/base/videobroadcaster.h" |
14 #include "webrtc/video_frame.h" | |
15 | 16 |
16 using rtc::VideoBroadcaster; | 17 using rtc::VideoBroadcaster; |
17 using rtc::VideoSinkWants; | 18 using rtc::VideoSinkWants; |
18 using cricket::FakeVideoRenderer; | 19 using cricket::FakeVideoRenderer; |
19 | 20 |
20 | 21 |
21 TEST(VideoBroadcasterTest, frame_wanted) { | 22 TEST(VideoBroadcasterTest, frame_wanted) { |
22 VideoBroadcaster broadcaster; | 23 VideoBroadcaster broadcaster; |
23 EXPECT_FALSE(broadcaster.frame_wanted()); | 24 EXPECT_FALSE(broadcaster.frame_wanted()); |
24 | 25 |
(...skipping 11 matching lines...) Expand all Loading... |
36 FakeVideoRenderer sink1; | 37 FakeVideoRenderer sink1; |
37 FakeVideoRenderer sink2; | 38 FakeVideoRenderer sink2; |
38 broadcaster.AddOrUpdateSink(&sink1, rtc::VideoSinkWants()); | 39 broadcaster.AddOrUpdateSink(&sink1, rtc::VideoSinkWants()); |
39 broadcaster.AddOrUpdateSink(&sink2, rtc::VideoSinkWants()); | 40 broadcaster.AddOrUpdateSink(&sink2, rtc::VideoSinkWants()); |
40 static int kWidth = 100; | 41 static int kWidth = 100; |
41 static int kHeight = 50; | 42 static int kHeight = 50; |
42 | 43 |
43 rtc::scoped_refptr<webrtc::I420Buffer> buffer( | 44 rtc::scoped_refptr<webrtc::I420Buffer> buffer( |
44 webrtc::I420Buffer::Create(kWidth, kHeight)); | 45 webrtc::I420Buffer::Create(kWidth, kHeight)); |
45 // Initialize, to avoid warnings on use of initialized values. | 46 // Initialize, to avoid warnings on use of initialized values. |
46 buffer->SetToBlack(); | 47 webrtc::I420Buffer::SetBlack(buffer); |
47 | 48 |
48 webrtc::VideoFrame frame(buffer, webrtc::kVideoRotation_0, 0); | 49 webrtc::VideoFrame frame(buffer, webrtc::kVideoRotation_0, 0); |
49 | 50 |
50 broadcaster.OnFrame(frame); | 51 broadcaster.OnFrame(frame); |
51 EXPECT_EQ(1, sink1.num_rendered_frames()); | 52 EXPECT_EQ(1, sink1.num_rendered_frames()); |
52 EXPECT_EQ(1, sink2.num_rendered_frames()); | 53 EXPECT_EQ(1, sink2.num_rendered_frames()); |
53 | 54 |
54 broadcaster.RemoveSink(&sink1); | 55 broadcaster.RemoveSink(&sink1); |
55 broadcaster.OnFrame(frame); | 56 broadcaster.OnFrame(frame); |
56 EXPECT_EQ(1, sink1.num_rendered_frames()); | 57 EXPECT_EQ(1, sink1.num_rendered_frames()); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 VideoSinkWants wants1; | 135 VideoSinkWants wants1; |
135 wants1.black_frames = true; | 136 wants1.black_frames = true; |
136 broadcaster.AddOrUpdateSink(&sink1, wants1); | 137 broadcaster.AddOrUpdateSink(&sink1, wants1); |
137 | 138 |
138 FakeVideoRenderer sink2; | 139 FakeVideoRenderer sink2; |
139 VideoSinkWants wants2; | 140 VideoSinkWants wants2; |
140 wants2.black_frames = false; | 141 wants2.black_frames = false; |
141 broadcaster.AddOrUpdateSink(&sink2, wants2); | 142 broadcaster.AddOrUpdateSink(&sink2, wants2); |
142 | 143 |
143 rtc::scoped_refptr<webrtc::I420Buffer> buffer( | 144 rtc::scoped_refptr<webrtc::I420Buffer> buffer( |
144 new rtc::RefCountedObject<webrtc::I420Buffer>(100, 200)); | 145 webrtc::I420Buffer::Create(100, 200)); |
145 // Makes it not all black. | 146 // Makes it not all black. |
146 buffer->InitializeData(); | 147 buffer->InitializeData(); |
147 | 148 |
148 webrtc::VideoFrame frame1(buffer, webrtc::kVideoRotation_0, | 149 webrtc::VideoFrame frame1(buffer, webrtc::kVideoRotation_0, |
149 10 /* timestamp_us */); | 150 10 /* timestamp_us */); |
150 broadcaster.OnFrame(frame1); | 151 broadcaster.OnFrame(frame1); |
151 EXPECT_TRUE(sink1.black_frame()); | 152 EXPECT_TRUE(sink1.black_frame()); |
152 EXPECT_EQ(10, sink1.timestamp_us()); | 153 EXPECT_EQ(10, sink1.timestamp_us()); |
153 EXPECT_FALSE(sink2.black_frame()); | 154 EXPECT_FALSE(sink2.black_frame()); |
154 EXPECT_EQ(10, sink2.timestamp_us()); | 155 EXPECT_EQ(10, sink2.timestamp_us()); |
155 | 156 |
156 // Switch the sink wants. | 157 // Switch the sink wants. |
157 wants1.black_frames = false; | 158 wants1.black_frames = false; |
158 broadcaster.AddOrUpdateSink(&sink1, wants1); | 159 broadcaster.AddOrUpdateSink(&sink1, wants1); |
159 wants2.black_frames = true; | 160 wants2.black_frames = true; |
160 broadcaster.AddOrUpdateSink(&sink2, wants2); | 161 broadcaster.AddOrUpdateSink(&sink2, wants2); |
161 | 162 |
162 webrtc::VideoFrame frame2(buffer, webrtc::kVideoRotation_0, | 163 webrtc::VideoFrame frame2(buffer, webrtc::kVideoRotation_0, |
163 30 /* timestamp_us */); | 164 30 /* timestamp_us */); |
164 broadcaster.OnFrame(frame2); | 165 broadcaster.OnFrame(frame2); |
165 EXPECT_FALSE(sink1.black_frame()); | 166 EXPECT_FALSE(sink1.black_frame()); |
166 EXPECT_EQ(30, sink1.timestamp_us()); | 167 EXPECT_EQ(30, sink1.timestamp_us()); |
167 EXPECT_TRUE(sink2.black_frame()); | 168 EXPECT_TRUE(sink2.black_frame()); |
168 EXPECT_EQ(30, sink2.timestamp_us()); | 169 EXPECT_EQ(30, sink2.timestamp_us()); |
169 } | 170 } |
OLD | NEW |