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

Unified Diff: webrtc/test/testsupport/metrics/video_metrics.cc

Issue 2362683002: New helper function test::ReadI420Buffer, refactor FrameReader to use it. (Closed)
Patch Set: Another try to fix the 64-bit windows build. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/test/testsupport/frame_reader_unittest.cc ('k') | webrtc/test/testsupport/mock/mock_frame_reader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
« no previous file with comments | « webrtc/test/testsupport/frame_reader_unittest.cc ('k') | webrtc/test/testsupport/mock/mock_frame_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698