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

Side by Side Diff: webrtc/test/testsupport/metrics/video_metrics.cc

Issue 2278883002: Move MutableDataY{,U,V} methods to I420Buffer only. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. 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 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 17 matching lines...) Expand all
28 // Used for calculating min and max values. 28 // Used for calculating min and max values.
29 static bool LessForFrameResultValue(const FrameResult& s1, 29 static bool LessForFrameResultValue(const FrameResult& s1,
30 const FrameResult& s2) { 30 const FrameResult& s2) {
31 return s1.value < s2.value; 31 return s1.value < s2.value;
32 } 32 }
33 33
34 enum VideoMetricsType { kPSNR, kSSIM, kBoth }; 34 enum VideoMetricsType { kPSNR, kSSIM, kBoth };
35 35
36 // Calculates metrics for a frame and adds statistics to the result for it. 36 // Calculates metrics for a frame and adds statistics to the result for it.
37 void CalculateFrame(VideoMetricsType video_metrics_type, 37 void CalculateFrame(VideoMetricsType video_metrics_type,
38 const VideoFrame* ref, 38 const VideoFrameBuffer& ref,
39 const VideoFrame* test, 39 const VideoFrameBuffer& test,
40 int frame_number, 40 int frame_number,
41 QualityMetricsResult* result) { 41 QualityMetricsResult* result) {
42 FrameResult frame_result = {0, 0}; 42 FrameResult frame_result = {0, 0};
43 frame_result.frame_number = frame_number; 43 frame_result.frame_number = frame_number;
44 switch (video_metrics_type) { 44 switch (video_metrics_type) {
45 case kPSNR: 45 case kPSNR:
46 frame_result.value = I420PSNR(ref, test); 46 frame_result.value = I420PSNR(ref, test);
47 break; 47 break;
48 case kSSIM: 48 case kSSIM:
49 frame_result.value = I420SSIM(ref, test); 49 frame_result.value = I420SSIM(ref, test);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 if (test_fp == NULL) { 103 if (test_fp == NULL) {
104 // Cannot open test file. 104 // Cannot open test file.
105 fprintf(stderr, "Cannot open file %s\n", test_filename); 105 fprintf(stderr, "Cannot open file %s\n", test_filename);
106 fclose(ref_fp); 106 fclose(ref_fp);
107 return -2; 107 return -2;
108 } 108 }
109 int frame_number = 0; 109 int frame_number = 0;
110 110
111 // Read reference and test frames. 111 // Read reference and test frames.
112 const size_t frame_length = 3 * width * height >> 1; 112 const size_t frame_length = 3 * width * height >> 1;
113 VideoFrame ref_frame; 113 rtc::scoped_refptr<I420Buffer> ref_i420_buffer;
114 VideoFrame test_frame; 114 rtc::scoped_refptr<I420Buffer> test_i420_buffer;
115 std::unique_ptr<uint8_t[]> ref_buffer(new uint8_t[frame_length]); 115 std::unique_ptr<uint8_t[]> ref_buffer(new uint8_t[frame_length]);
116 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[frame_length]); 116 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[frame_length]);
117 117
118 // Set decoded image parameters. 118 // Set decoded image parameters.
119 int half_width = (width + 1) / 2; 119 int half_width = (width + 1) / 2;
120 ref_frame.CreateEmptyFrame(width, height, width, half_width, half_width); 120 ref_i420_buffer =
121 test_frame.CreateEmptyFrame(width, height, width, half_width, half_width); 121 I420Buffer::Create(width, height, width, half_width, half_width);
122 test_i420_buffer =
123 I420Buffer::Create(width, height, width, half_width, half_width);
122 124
123 size_t ref_bytes = fread(ref_buffer.get(), 1, frame_length, ref_fp); 125 size_t ref_bytes = fread(ref_buffer.get(), 1, frame_length, ref_fp);
124 size_t test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp); 126 size_t test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp);
125 while (ref_bytes == frame_length && test_bytes == frame_length) { 127 while (ref_bytes == frame_length && test_bytes == frame_length) {
126 // Converting from buffer to plane representation. 128 // Converting from buffer to plane representation.
127 ConvertToI420(kI420, ref_buffer.get(), 0, 0, width, height, 0, 129 ConvertToI420(kI420, ref_buffer.get(), 0, 0, width, height, 0,
128 kVideoRotation_0, &ref_frame); 130 kVideoRotation_0, ref_i420_buffer.get());
129 ConvertToI420(kI420, test_buffer.get(), 0, 0, width, height, 0, 131 ConvertToI420(kI420, test_buffer.get(), 0, 0, width, height, 0,
130 kVideoRotation_0, &test_frame); 132 kVideoRotation_0, test_i420_buffer.get());
133
131 switch (video_metrics_type) { 134 switch (video_metrics_type) {
132 case kPSNR: 135 case kPSNR:
133 CalculateFrame(kPSNR, &ref_frame, &test_frame, frame_number, 136 CalculateFrame(kPSNR, *ref_i420_buffer, *test_i420_buffer, frame_number,
134 psnr_result); 137 psnr_result);
135 break; 138 break;
136 case kSSIM: 139 case kSSIM:
137 CalculateFrame(kSSIM, &ref_frame, &test_frame, frame_number, 140 CalculateFrame(kSSIM, *ref_i420_buffer, *test_i420_buffer, frame_number,
138 ssim_result); 141 ssim_result);
139 break; 142 break;
140 case kBoth: 143 case kBoth:
141 CalculateFrame(kPSNR, &ref_frame, &test_frame, frame_number, 144 CalculateFrame(kPSNR, *ref_i420_buffer, *test_i420_buffer, frame_number,
142 psnr_result); 145 psnr_result);
143 CalculateFrame(kSSIM, &ref_frame, &test_frame, frame_number, 146 CalculateFrame(kSSIM, *ref_i420_buffer, *test_i420_buffer, frame_number,
144 ssim_result); 147 ssim_result);
145 break; 148 break;
146 } 149 }
147 frame_number++; 150 frame_number++;
148 ref_bytes = fread(ref_buffer.get(), 1, frame_length, ref_fp); 151 ref_bytes = fread(ref_buffer.get(), 1, frame_length, ref_fp);
149 test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp); 152 test_bytes = fread(test_buffer.get(), 1, frame_length, test_fp);
150 } 153 }
151 int return_code = 0; 154 int return_code = 0;
152 if (frame_number == 0) { 155 if (frame_number == 0) {
153 fprintf(stderr, "Tried to measure video metrics from empty files " 156 fprintf(stderr, "Tried to measure video metrics from empty files "
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 int width, 193 int width,
191 int height, 194 int height,
192 QualityMetricsResult* result) { 195 QualityMetricsResult* result) {
193 assert(result != NULL); 196 assert(result != NULL);
194 return CalculateMetrics(kSSIM, ref_filename, test_filename, width, height, 197 return CalculateMetrics(kSSIM, ref_filename, test_filename, width, height,
195 NULL, result); 198 NULL, result);
196 } 199 }
197 200
198 } // namespace test 201 } // namespace test
199 } // namespace webrtc 202 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698