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

Side by Side Diff: webrtc/modules/video_coding/codecs/test/videoprocessor.cc

Issue 2695653002: Add support for creating HW codecs in VideoProcessor tests. (Closed)
Patch Set: Don't forget the mac! Created 3 years, 10 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 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 // Check if codec size is different from native/original size, and if so, 367 // Check if codec size is different from native/original size, and if so,
368 // upsample back to original size. This is needed for PSNR and SSIM 368 // upsample back to original size. This is needed for PSNR and SSIM
369 // calculations. 369 // calculations.
370 if (image.width() != config_.codec_settings->width || 370 if (image.width() != config_.codec_settings->width ||
371 image.height() != config_.codec_settings->height) { 371 image.height() != config_.codec_settings->height) {
372 rtc::scoped_refptr<I420Buffer> up_image( 372 rtc::scoped_refptr<I420Buffer> up_image(
373 I420Buffer::Create(config_.codec_settings->width, 373 I420Buffer::Create(config_.codec_settings->width,
374 config_.codec_settings->height)); 374 config_.codec_settings->height));
375 375
376 // Should be the same aspect ratio, no cropping needed. 376 // Should be the same aspect ratio, no cropping needed.
377 up_image->ScaleFrom(*image.video_frame_buffer()); 377 if (image.video_frame_buffer()->native_handle()) {
378 up_image->ScaleFrom(*image.video_frame_buffer()->NativeToI420Buffer());
379 } else {
380 up_image->ScaleFrom(*image.video_frame_buffer());
381 }
378 382
379 // TODO(mikhal): Extracting the buffer for now - need to update test. 383 // TODO(mikhal): Extracting the buffer for now - need to update test.
380 size_t length = 384 size_t length =
381 CalcBufferSize(kI420, up_image->width(), up_image->height()); 385 CalcBufferSize(kI420, up_image->width(), up_image->height());
382 std::unique_ptr<uint8_t[]> image_buffer(new uint8_t[length]); 386 std::unique_ptr<uint8_t[]> image_buffer(new uint8_t[length]);
383 int extracted_length = ExtractBuffer(up_image, length, image_buffer.get()); 387 int extracted_length = ExtractBuffer(up_image, length, image_buffer.get());
384 RTC_DCHECK_GT(extracted_length, 0); 388 RTC_DCHECK_GT(extracted_length, 0);
385 // Update our copy of the last successful frame. 389 // Update our copy of the last successful frame.
386 memcpy(last_successful_frame_buffer_.get(), image_buffer.get(), 390 memcpy(last_successful_frame_buffer_.get(), image_buffer.get(),
387 extracted_length); 391 extracted_length);
388 bool write_success = frame_writer_->WriteFrame(image_buffer.get()); 392 bool write_success = frame_writer_->WriteFrame(image_buffer.get());
389 RTC_DCHECK(write_success); 393 RTC_DCHECK(write_success);
390 if (!write_success) { 394 if (!write_success) {
391 fprintf(stderr, "Failed to write frame %d to disk!", frame_number); 395 fprintf(stderr, "Failed to write frame %d to disk!", frame_number);
392 } 396 }
393 } else { // No resize. 397 } else { // No resize.
394 // Update our copy of the last successful frame. 398 // Update our copy of the last successful frame.
395 // TODO(mikhal): Add as a member function, so won't be allocated per frame. 399 // TODO(mikhal): Add as a member function, so won't be allocated per frame.
396 size_t length = CalcBufferSize(kI420, image.width(), image.height()); 400 size_t length = CalcBufferSize(kI420, image.width(), image.height());
397 std::unique_ptr<uint8_t[]> image_buffer(new uint8_t[length]); 401 std::unique_ptr<uint8_t[]> image_buffer(new uint8_t[length]);
398 int extracted_length = ExtractBuffer(image, length, image_buffer.get()); 402 int extracted_length;
403 if (image.video_frame_buffer()->native_handle()) {
404 extracted_length =
405 ExtractBuffer(image.video_frame_buffer()->NativeToI420Buffer(),
406 length, image_buffer.get());
407 } else {
408 extracted_length =
409 ExtractBuffer(image.video_frame_buffer(), length, image_buffer.get());
410 }
399 RTC_DCHECK_GT(extracted_length, 0); 411 RTC_DCHECK_GT(extracted_length, 0);
400 memcpy(last_successful_frame_buffer_.get(), image_buffer.get(), 412 memcpy(last_successful_frame_buffer_.get(), image_buffer.get(),
401 extracted_length); 413 extracted_length);
402 414
403 bool write_success = frame_writer_->WriteFrame(image_buffer.get()); 415 bool write_success = frame_writer_->WriteFrame(image_buffer.get());
404 RTC_DCHECK(write_success); 416 RTC_DCHECK(write_success);
405 if (!write_success) { 417 if (!write_success) {
406 fprintf(stderr, "Failed to write frame %d to disk!", frame_number); 418 fprintf(stderr, "Failed to write frame %d to disk!", frame_number);
407 } 419 }
408 } 420 }
409 } 421 }
410 422
411 int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start, 423 int VideoProcessorImpl::GetElapsedTimeMicroseconds(int64_t start,
412 int64_t stop) { 424 int64_t stop) {
413 int64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec; 425 int64_t encode_time = (stop - start) / rtc::kNumNanosecsPerMicrosec;
414 RTC_DCHECK_GE(encode_time, std::numeric_limits<int>::min()); 426 RTC_DCHECK_GE(encode_time, std::numeric_limits<int>::min());
415 RTC_DCHECK_LE(encode_time, std::numeric_limits<int>::max()); 427 RTC_DCHECK_LE(encode_time, std::numeric_limits<int>::max());
416 return static_cast<int>(encode_time); 428 return static_cast<int>(encode_time);
417 } 429 }
418 430
419 } // namespace test 431 } // namespace test
420 } // namespace webrtc 432 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698