OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2010 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 |
(...skipping 13 matching lines...) Expand all Loading... |
24 namespace cricket { | 24 namespace cricket { |
25 | 25 |
26 class VideoAdapterTest : public testing::Test { | 26 class VideoAdapterTest : public testing::Test { |
27 public: | 27 public: |
28 virtual void SetUp() { | 28 virtual void SetUp() { |
29 capturer_.reset(new FakeVideoCapturer); | 29 capturer_.reset(new FakeVideoCapturer); |
30 capture_format_ = capturer_->GetSupportedFormats()->at(0); | 30 capture_format_ = capturer_->GetSupportedFormats()->at(0); |
31 capture_format_.interval = VideoFormat::FpsToInterval(30); | 31 capture_format_.interval = VideoFormat::FpsToInterval(30); |
32 | 32 |
33 listener_.reset(new VideoCapturerListener(&adapter_)); | 33 listener_.reset(new VideoCapturerListener(&adapter_)); |
34 capturer_->AddOrUpdateSink(listener_.get(), rtc::VideoSinkWants()); | 34 capturer_->SignalFrameCaptured.connect( |
| 35 listener_.get(), &VideoCapturerListener::OnFrameCaptured); |
35 } | 36 } |
36 | 37 |
37 virtual void TearDown() { | 38 virtual void TearDown() { |
38 // Explicitly disconnect the VideoCapturer before to avoid data races | 39 // Explicitly disconnect the VideoCapturer before to avoid data races |
39 // (frames delivered to VideoCapturerListener while it's being destructed). | 40 // (frames delivered to VideoCapturerListener while it's being destructed). |
40 capturer_->RemoveSink(listener_.get()); | 41 capturer_->SignalFrameCaptured.disconnect_all(); |
41 } | 42 } |
42 | 43 |
43 protected: | 44 protected: |
44 class VideoCapturerListener | 45 class VideoCapturerListener: public sigslot::has_slots<> { |
45 : public rtc::VideoSinkInterface<cricket::VideoFrame> { | |
46 public: | 46 public: |
47 struct Stats { | 47 struct Stats { |
48 int captured_frames; | 48 int captured_frames; |
49 int dropped_frames; | 49 int dropped_frames; |
50 bool last_adapt_was_no_op; | 50 bool last_adapt_was_no_op; |
51 | 51 |
52 int cropped_width; | 52 int cropped_width; |
53 int cropped_height; | 53 int cropped_height; |
54 int out_width; | 54 int out_width; |
55 int out_height; | 55 int out_height; |
56 }; | 56 }; |
57 | 57 |
58 explicit VideoCapturerListener(VideoAdapter* adapter) | 58 explicit VideoCapturerListener(VideoAdapter* adapter) |
59 : video_adapter_(adapter), | 59 : video_adapter_(adapter), |
60 captured_frames_(0), | 60 captured_frames_(0), |
61 dropped_frames_(0), | 61 dropped_frames_(0), |
62 last_adapt_was_no_op_(false) { | 62 last_adapt_was_no_op_(false) { |
63 } | 63 } |
64 | 64 |
65 void OnFrame(const cricket::VideoFrame& frame) { | 65 void OnFrameCaptured(VideoCapturer* capturer, |
| 66 const CapturedFrame* captured_frame) { |
66 rtc::CritScope lock(&crit_); | 67 rtc::CritScope lock(&crit_); |
67 const int in_width = frame.width(); | 68 const int in_width = captured_frame->width; |
68 const int in_height = frame.height(); | 69 const int in_height = abs(captured_frame->height); |
69 int cropped_width; | 70 int cropped_width; |
70 int cropped_height; | 71 int cropped_height; |
71 int out_width; | 72 int out_width; |
72 int out_height; | 73 int out_height; |
73 if (video_adapter_->AdaptFrameResolution( | 74 if (video_adapter_->AdaptFrameResolution(in_width, in_height, |
74 in_width, in_height, | 75 captured_frame->time_stamp, |
75 frame.timestamp_us() * rtc::kNumNanosecsPerMicrosec, | 76 &cropped_width, &cropped_height, |
76 &cropped_width, &cropped_height, &out_width, &out_height)) { | 77 &out_width, &out_height)) { |
77 cropped_width_ = cropped_width; | 78 cropped_width_ = cropped_width; |
78 cropped_height_ = cropped_height; | 79 cropped_height_ = cropped_height; |
79 out_width_ = out_width; | 80 out_width_ = out_width; |
80 out_height_ = out_height; | 81 out_height_ = out_height; |
81 last_adapt_was_no_op_ = | 82 last_adapt_was_no_op_ = |
82 (in_width == cropped_width && in_height == cropped_height && | 83 (in_width == cropped_width && in_height == cropped_height && |
83 in_width == out_width && in_height == out_height); | 84 in_width == out_width && in_height == out_height); |
84 } else { | 85 } else { |
85 ++dropped_frames_; | 86 ++dropped_frames_; |
86 } | 87 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); | 176 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
176 | 177 |
177 // Capture 10 frames and verify that every other frame is dropped. The first | 178 // Capture 10 frames and verify that every other frame is dropped. The first |
178 // frame should not be dropped. | 179 // frame should not be dropped. |
179 capturer_->CaptureFrame(); | 180 capturer_->CaptureFrame(); |
180 EXPECT_GE(listener_->GetStats().captured_frames, 1); | 181 EXPECT_GE(listener_->GetStats().captured_frames, 1); |
181 EXPECT_EQ(0, listener_->GetStats().dropped_frames); | 182 EXPECT_EQ(0, listener_->GetStats().dropped_frames); |
182 | 183 |
183 capturer_->CaptureFrame(); | 184 capturer_->CaptureFrame(); |
184 EXPECT_GE(listener_->GetStats().captured_frames, 2); | 185 EXPECT_GE(listener_->GetStats().captured_frames, 2); |
185 EXPECT_EQ(1, listener_->GetStats().dropped_frames); | 186 EXPECT_EQ(0, listener_->GetStats().dropped_frames); |
186 | 187 |
187 capturer_->CaptureFrame(); | 188 capturer_->CaptureFrame(); |
188 EXPECT_GE(listener_->GetStats().captured_frames, 3); | 189 EXPECT_GE(listener_->GetStats().captured_frames, 3); |
189 EXPECT_EQ(1, listener_->GetStats().dropped_frames); | 190 EXPECT_EQ(1, listener_->GetStats().dropped_frames); |
190 | 191 |
191 capturer_->CaptureFrame(); | 192 capturer_->CaptureFrame(); |
192 EXPECT_GE(listener_->GetStats().captured_frames, 4); | 193 EXPECT_GE(listener_->GetStats().captured_frames, 4); |
193 EXPECT_EQ(2, listener_->GetStats().dropped_frames); | 194 EXPECT_EQ(1, listener_->GetStats().dropped_frames); |
194 | 195 |
195 capturer_->CaptureFrame(); | 196 capturer_->CaptureFrame(); |
196 EXPECT_GE(listener_->GetStats().captured_frames, 5); | 197 EXPECT_GE(listener_->GetStats().captured_frames, 5); |
197 EXPECT_EQ(2, listener_->GetStats().dropped_frames); | 198 EXPECT_EQ(2, listener_->GetStats().dropped_frames); |
198 | 199 |
199 capturer_->CaptureFrame(); | 200 capturer_->CaptureFrame(); |
200 EXPECT_GE(listener_->GetStats().captured_frames, 6); | 201 EXPECT_GE(listener_->GetStats().captured_frames, 6); |
201 EXPECT_EQ(3, listener_->GetStats().dropped_frames); | 202 EXPECT_EQ(2, listener_->GetStats().dropped_frames); |
202 | 203 |
203 capturer_->CaptureFrame(); | 204 capturer_->CaptureFrame(); |
204 EXPECT_GE(listener_->GetStats().captured_frames, 7); | 205 EXPECT_GE(listener_->GetStats().captured_frames, 7); |
205 EXPECT_EQ(3, listener_->GetStats().dropped_frames); | 206 EXPECT_EQ(3, listener_->GetStats().dropped_frames); |
206 | 207 |
207 capturer_->CaptureFrame(); | 208 capturer_->CaptureFrame(); |
208 EXPECT_GE(listener_->GetStats().captured_frames, 8); | 209 EXPECT_GE(listener_->GetStats().captured_frames, 8); |
209 EXPECT_EQ(4, listener_->GetStats().dropped_frames); | 210 EXPECT_EQ(3, listener_->GetStats().dropped_frames); |
210 | 211 |
211 capturer_->CaptureFrame(); | 212 capturer_->CaptureFrame(); |
212 EXPECT_GE(listener_->GetStats().captured_frames, 9); | 213 EXPECT_GE(listener_->GetStats().captured_frames, 9); |
213 EXPECT_EQ(4, listener_->GetStats().dropped_frames); | 214 EXPECT_EQ(4, listener_->GetStats().dropped_frames); |
214 | 215 |
215 capturer_->CaptureFrame(); | 216 capturer_->CaptureFrame(); |
216 EXPECT_GE(listener_->GetStats().captured_frames, 10); | 217 EXPECT_GE(listener_->GetStats().captured_frames, 10); |
217 EXPECT_EQ(5, listener_->GetStats().dropped_frames); | 218 EXPECT_EQ(4, listener_->GetStats().dropped_frames); |
218 } | 219 } |
219 | 220 |
220 // Adapt the frame rate to be two thirds of the capture rate at the beginning. | 221 // Adapt the frame rate to be two thirds of the capture rate at the beginning. |
221 // Expect the number of dropped frames to be one thirds of the number the | 222 // Expect the number of dropped frames to be one thirds of the number the |
222 // captured frames. | 223 // captured frames. |
223 TEST_F(VideoAdapterTest, AdaptFramerateToTwoThirds) { | 224 TEST_F(VideoAdapterTest, AdaptFramerateToTwoThirds) { |
224 VideoFormat request_format = capture_format_; | 225 VideoFormat request_format = capture_format_; |
225 request_format.interval = request_format.interval * 3 / 2; | 226 request_format.interval = request_format.interval * 3 / 2; |
226 adapter_.OnOutputFormatRequest(request_format); | 227 adapter_.OnOutputFormatRequest(request_format); |
227 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); | 228 EXPECT_EQ(CS_RUNNING, capturer_->Start(capture_format_)); |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 | 946 |
946 // Instead of getting the exact aspect ratio with cropped resolution 640x360, | 947 // Instead of getting the exact aspect ratio with cropped resolution 640x360, |
947 // the resolution should be adjusted to get a perfect scale factor instead. | 948 // the resolution should be adjusted to get a perfect scale factor instead. |
948 EXPECT_EQ(640, cropped_width_); | 949 EXPECT_EQ(640, cropped_width_); |
949 EXPECT_EQ(368, cropped_height_); | 950 EXPECT_EQ(368, cropped_height_); |
950 EXPECT_EQ(120, out_width_); | 951 EXPECT_EQ(120, out_width_); |
951 EXPECT_EQ(69, out_height_); | 952 EXPECT_EQ(69, out_height_); |
952 } | 953 } |
953 | 954 |
954 } // namespace cricket | 955 } // namespace cricket |
OLD | NEW |