Index: webrtc/test/testsupport/metrics/video_metrics.cc |
diff --git a/webrtc/test/testsupport/metrics/video_metrics.cc b/webrtc/test/testsupport/metrics/video_metrics.cc |
index 75bbc61fce0e55309175b93a9a1c2195001663e9..3013b6135593995b37ecb41ccfb2f8547c85ba8c 100644 |
--- a/webrtc/test/testsupport/metrics/video_metrics.cc |
+++ b/webrtc/test/testsupport/metrics/video_metrics.cc |
@@ -17,6 +17,7 @@ |
#include <memory> |
#include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
+#include "webrtc/test/frame_utils.h" |
#include "webrtc/video_frame.h" |
#include "libyuv/convert.h" |
@@ -110,44 +111,17 @@ int CalculateMetrics(VideoMetricsType video_metrics_type, |
int frame_number = 0; |
// Read reference and test frames. |
- const size_t frame_length = 3 * width * height >> 1; |
- rtc::scoped_refptr<I420Buffer> ref_i420_buffer; |
- rtc::scoped_refptr<I420Buffer> test_i420_buffer; |
- std::unique_ptr<uint8_t[]> ref_buffer(new uint8_t[frame_length]); |
- std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[frame_length]); |
- |
- // Set decoded image parameters. |
- int half_width = (width + 1) / 2; |
- ref_i420_buffer = |
- I420Buffer::Create(width, height, width, half_width, half_width); |
- test_i420_buffer = |
- I420Buffer::Create(width, height, width, half_width, half_width); |
- |
- // TODO(nisse): Have a frame reader in one place. And read directly |
- // into the planes of an I420Buffer, the extra copying below is silly. |
- size_t ref_bytes = fread(ref_buffer.get(), 1, frame_length, ref_fp); |
- size_t test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp); |
- while (ref_bytes == frame_length && test_bytes == frame_length) { |
- // Converting from buffer to plane representation. |
- size_t size_y = width * height; |
- size_t size_uv = half_width * ((height + 1) / 2); |
- libyuv::I420Copy( |
- ref_buffer.get(), width, |
- ref_buffer.get() + size_y, half_width, |
- ref_buffer.get() + size_y + size_uv, half_width, |
- ref_i420_buffer->MutableDataY(), ref_i420_buffer->StrideY(), |
- ref_i420_buffer->MutableDataU(), ref_i420_buffer->StrideU(), |
- ref_i420_buffer->MutableDataV(), ref_i420_buffer->StrideV(), |
- width, height); |
- |
- libyuv::I420Copy( |
- test_buffer.get(), width, |
- test_buffer.get() + size_y, half_width, |
- test_buffer.get() + size_y + size_uv, half_width, |
- test_i420_buffer->MutableDataY(), test_i420_buffer->StrideY(), |
- test_i420_buffer->MutableDataU(), test_i420_buffer->StrideU(), |
- test_i420_buffer->MutableDataV(), test_i420_buffer->StrideV(), |
- width, height); |
+ for (;;) { |
+ rtc::scoped_refptr<I420Buffer> ref_i420_buffer( |
+ test::ReadI420Buffer(width, height, ref_fp)); |
+ if (!ref_i420_buffer) |
+ break; |
+ |
+ rtc::scoped_refptr<I420Buffer> test_i420_buffer( |
+ test::ReadI420Buffer(width, height, test_fp)); |
+ |
+ if (!test_i420_buffer) |
+ break; |
switch (video_metrics_type) { |
case kPSNR: |
@@ -166,8 +140,6 @@ int CalculateMetrics(VideoMetricsType video_metrics_type, |
break; |
} |
frame_number++; |
- ref_bytes = fread(ref_buffer.get(), 1, frame_length, ref_fp); |
- test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp); |
} |
int return_code = 0; |
if (frame_number == 0) { |