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

Side by Side Diff: remoting/codec/codec_test.cc

Issue 1150163002: Update VideoFramePump to pass un-changed frames to encoders. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add basic tests for unchanged frames Created 5 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <deque> 5 #include <deque>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 int memory_size = size.width() * size.height() * kBytesPerPixel; 240 int memory_size = size.width() * size.height() * kBytesPerPixel;
241 for (int i = 0; i < memory_size; ++i) { 241 for (int i = 0; i < memory_size; ++i) {
242 frame->data()[i] = rand() % 256; 242 frame->data()[i] = rand() % 256;
243 } 243 }
244 244
245 return frame.Pass(); 245 return frame.Pass();
246 } 246 }
247 247
248 static void TestEncodingRects(VideoEncoder* encoder, 248 static void TestEncodingRects(VideoEncoder* encoder,
249 VideoEncoderTester* tester, 249 VideoEncoderTester* tester,
250 webrtc::DesktopFrame* frame, 250 DesktopFrame* frame,
251 const DesktopRect* rects, 251 const DesktopRect* rects,
252 int count) { 252 int count) {
253 frame->mutable_updated_region()->Clear(); 253 frame->mutable_updated_region()->Clear();
254 for (int i = 0; i < count; ++i) { 254 for (int i = 0; i < count; ++i) {
255 frame->mutable_updated_region()->AddRect(rects[i]); 255 frame->mutable_updated_region()->AddRect(rects[i]);
256 } 256 }
257 257
258 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); 258 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame);
259 tester->DataAvailable(packet.Pass()); 259 tester->DataAvailable(packet.Pass());
260 } 260 }
261 261
262 void TestVideoEncoder(VideoEncoder* encoder, bool strict) { 262 void TestVideoEncoder(VideoEncoder* encoder, bool strict) {
263 const int kSizes[] = {320, 319, 317, 150}; 263 const int kSizes[] = {320, 319, 317, 150};
264 264
265 VideoEncoderTester tester; 265 VideoEncoderTester tester;
266 266
267 for (size_t xi = 0; xi < arraysize(kSizes); ++xi) { 267 for (size_t xi = 0; xi < arraysize(kSizes); ++xi) {
268 for (size_t yi = 0; yi < arraysize(kSizes); ++yi) { 268 for (size_t yi = 0; yi < arraysize(kSizes); ++yi) {
269 DesktopSize size = DesktopSize(kSizes[xi], kSizes[yi]); 269 DesktopSize size = DesktopSize(kSizes[xi], kSizes[yi]);
270 scoped_ptr<webrtc::DesktopFrame> frame = PrepareFrame(size); 270 scoped_ptr<DesktopFrame> frame = PrepareFrame(size);
271 std::vector<std::vector<DesktopRect> > test_rect_lists = 271 std::vector<std::vector<DesktopRect> > test_rect_lists =
272 MakeTestRectLists(size); 272 MakeTestRectLists(size);
273 for (size_t i = 0; i < test_rect_lists.size(); ++i) { 273 for (size_t i = 0; i < test_rect_lists.size(); ++i) {
274 const std::vector<DesktopRect>& test_rects = test_rect_lists[i]; 274 const std::vector<DesktopRect>& test_rects = test_rect_lists[i];
275 TestEncodingRects(encoder, &tester, frame.get(), 275 TestEncodingRects(encoder, &tester, frame.get(),
276 &test_rects[0], test_rects.size()); 276 &test_rects[0], test_rects.size());
277 } 277 }
278
279 // Pass some empty frames through the encoder.
280 for (int i = 0; i < 10; ++i) {
281 TestEncodingRects(encoder, &tester, frame.get(), nullptr, 0);
282 }
278 } 283 }
279 } 284 }
280 } 285 }
281 286
287 void TestVideoEncoderEmptyFrames(VideoEncoder* encoder, int max_topoff_frames) {
288 const DesktopSize kSize(640, 480);
289 scoped_ptr<DesktopFrame> frame(PrepareFrame(kSize));
290 frame->mutable_updated_region()->SetRect(
291 webrtc::DesktopRect::MakeSize(kSize));
292 EXPECT_TRUE(encoder->Encode(*frame));
293
294 frame->mutable_updated_region()->Clear();
295 int topoff_frame_count = 0;
296 do {
Sergey Ulanov 2015/06/09 05:32:43 nit: this can be a simpler for loop: for (int i
Wez 2015/06/09 22:00:37 That implementation would enforce that there are e
297 bool topped_off = encoder->Encode(*frame) != nullptr;
298 if (!topped_off)
299 break;
300 topoff_frame_count++;
301 } while (topoff_frame_count <= max_topoff_frames);
302 EXPECT_LE(topoff_frame_count, max_topoff_frames);
303 }
304
282 static void TestEncodeDecodeRects(VideoEncoder* encoder, 305 static void TestEncodeDecodeRects(VideoEncoder* encoder,
283 VideoEncoderTester* encoder_tester, 306 VideoEncoderTester* encoder_tester,
284 VideoDecoderTester* decoder_tester, 307 VideoDecoderTester* decoder_tester,
285 DesktopFrame* frame, 308 DesktopFrame* frame,
286 const DesktopRect* rects, int count) { 309 const DesktopRect* rects, int count) {
287 frame->mutable_updated_region()->Clear(); 310 frame->mutable_updated_region()->Clear();
288 for (int i = 0; i < count; ++i) { 311 for (int i = 0; i < count; ++i) {
289 frame->mutable_updated_region()->AddRect(rects[i]); 312 frame->mutable_updated_region()->AddRect(rects[i]);
290 } 313 }
291 decoder_tester->AddRects(rects, count); 314 decoder_tester->AddRects(rects, count);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 444
422 if (frame_count >= kWarmUpFrameCount) { 445 if (frame_count >= kWarmUpFrameCount) {
423 elapsed = base::TimeTicks::Now() - start_time; 446 elapsed = base::TimeTicks::Now() - start_time;
424 } 447 }
425 } 448 }
426 449
427 return (frame_count * base::TimeDelta::FromSeconds(1)) / elapsed; 450 return (frame_count * base::TimeDelta::FromSeconds(1)) / elapsed;
428 } 451 }
429 452
430 } // namespace remoting 453 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698