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

Side by Side Diff: webrtc/tools/frame_analyzer/video_quality_analysis.cc

Issue 2535783002: Revert of Bug in ExtractFrame API (extracts frames incorrectly) (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « webrtc/tools/BUILD.gn ('k') | webrtc/tools/frame_analyzer/video_quality_analysis_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "webrtc/tools/frame_analyzer/video_quality_analysis.h" 11 #include "webrtc/tools/frame_analyzer/video_quality_analysis.h"
12 12
13 #include <assert.h> 13 #include <assert.h>
14 #include <stdio.h> 14 #include <stdio.h>
15 #include <stdlib.h> 15 #include <stdlib.h>
16
16 #include <string> 17 #include <string>
17 18
18 #define STATS_LINE_LENGTH 32 19 #define STATS_LINE_LENGTH 32
19 #define Y4M_FILE_HEADER_MAX_SIZE 200 20 #define Y4M_FILE_HEADER_MAX_SIZE 200
20 #define Y4M_FRAME_DELIMITER "FRAME" 21 #define Y4M_FRAME_DELIMITER "FRAME"
21 #define Y4M_FRAME_HEADER_SIZE 6 22 #define Y4M_FRAME_HEADER_SIZE 6
22 23
23 namespace webrtc { 24 namespace webrtc {
24 namespace test { 25 namespace test {
25 26
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 fclose(input_file); 119 fclose(input_file);
119 return !errors; 120 return !errors;
120 } 121 }
121 122
122 bool ExtractFrameFromY4mFile(const char* y4m_file_name, 123 bool ExtractFrameFromY4mFile(const char* y4m_file_name,
123 int width, 124 int width,
124 int height, 125 int height,
125 int frame_number, 126 int frame_number,
126 uint8_t* result_frame) { 127 uint8_t* result_frame) {
127 int frame_size = GetI420FrameSize(width, height); 128 int frame_size = GetI420FrameSize(width, height);
128 int inital_offset = frame_number * (frame_size + Y4M_FRAME_HEADER_SIZE); 129 int frame_offset = frame_number * frame_size;
129 int frame_offset = 0; 130 bool errors = false;
130 131
131 FILE* input_file = fopen(y4m_file_name, "rb"); 132 FILE* input_file = fopen(y4m_file_name, "rb");
132 if (input_file == NULL) { 133 if (input_file == NULL) {
133 fprintf(stderr, "Couldn't open input file for reading: %s\n", 134 fprintf(stderr, "Couldn't open input file for reading: %s\n",
134 y4m_file_name); 135 y4m_file_name);
135 return false; 136 return false;
136 } 137 }
137 138
138 // YUV4MPEG2, a.k.a. Y4M File format has a file header and a frame header. The 139 // YUV4MPEG2, a.k.a. Y4M File format has a file header and a frame header. The
139 // file header has the aspect: "YUV4MPEG2 C420 W640 H360 Ip F30:1 A1:1". 140 // file header has the aspect: "YUV4MPEG2 C420 W640 H360 Ip F30:1 A1:1".
140 char frame_header[Y4M_FILE_HEADER_MAX_SIZE]; 141 // Skip the header if this is the first frame of the file.
141 size_t bytes_read = 142 if (frame_number == 0) {
142 fread(frame_header, 1, Y4M_FILE_HEADER_MAX_SIZE, input_file); 143 char frame_header[Y4M_FILE_HEADER_MAX_SIZE];
143 if (bytes_read != static_cast<size_t>(frame_size) && ferror(input_file)) { 144 size_t bytes_read =
144 fprintf(stdout, "Error while reading frame from file %s\n", 145 fread(frame_header, 1, Y4M_FILE_HEADER_MAX_SIZE, input_file);
145 y4m_file_name); 146 if (bytes_read != static_cast<size_t>(frame_size) && ferror(input_file)) {
146 fclose(input_file); 147 fprintf(stdout, "Error while reading first frame from file %s\n",
147 return false; 148 y4m_file_name);
149 fclose(input_file);
150 return false;
151 }
152 std::string header_contents(frame_header);
153 std::size_t found = header_contents.find(Y4M_FRAME_DELIMITER);
154 if (found == std::string::npos) {
155 fprintf(stdout, "Corrupted Y4M header, could not find \"FRAME\" in %s\n",
156 header_contents.c_str());
157 fclose(input_file);
158 return false;
159 }
160 frame_offset = static_cast<int>(found);
148 } 161 }
149 std::string header_contents(frame_header);
150 std::size_t found = header_contents.find(Y4M_FRAME_DELIMITER);
151 if (found == std::string::npos) {
152 fprintf(stdout, "Corrupted Y4M header, could not find \"FRAME\" in %s\n",
153 header_contents.c_str());
154 fclose(input_file);
155 return false;
156 }
157 frame_offset = static_cast<int>(found);
158 162
159 // Change stream pointer to new offset, skipping the frame header as well. 163 // Change stream pointer to new offset, skipping the frame header as well.
160 fseek(input_file, inital_offset + frame_offset + Y4M_FRAME_HEADER_SIZE, 164 fseek(input_file, frame_offset + Y4M_FRAME_HEADER_SIZE, SEEK_SET);
161 SEEK_SET);
162 165
163 bytes_read = fread(result_frame, 1, frame_size, input_file); 166 size_t bytes_read = fread(result_frame, 1, frame_size, input_file);
164 if (feof(input_file)) { 167 if (bytes_read != static_cast<size_t>(frame_size) &&
165 fclose(input_file); 168 ferror(input_file)) {
166 return false;
167 }
168 if (bytes_read != static_cast<size_t>(frame_size) && ferror(input_file)) {
169 fprintf(stdout, "Error while reading frame no %d from file %s\n", 169 fprintf(stdout, "Error while reading frame no %d from file %s\n",
170 frame_number, y4m_file_name); 170 frame_number, y4m_file_name);
171 fclose(input_file); 171 errors = true;
172 return false;
173 } 172 }
174 173
175 fclose(input_file); 174 fclose(input_file);
176 return true; 175 return !errors;
177 } 176 }
178 177
179 double CalculateMetrics(VideoAnalysisMetricsType video_metrics_type, 178 double CalculateMetrics(VideoAnalysisMetricsType video_metrics_type,
180 const uint8_t* ref_frame, 179 const uint8_t* ref_frame,
181 const uint8_t* test_frame, 180 const uint8_t* test_frame,
182 int width, 181 int width,
183 int height) { 182 int height) {
184 if (!ref_frame || !test_frame) 183 if (!ref_frame || !test_frame)
185 return -1; 184 return -1;
186 else if (height < 0 || width < 0) 185 else if (height < 0 || width < 0)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 for (iter = results->frames.begin(); iter != results->frames.end() - 1; 366 for (iter = results->frames.begin(); iter != results->frames.end() - 1;
368 ++iter) { 367 ++iter) {
369 fprintf(output, "%f,", iter->ssim_value); 368 fprintf(output, "%f,", iter->ssim_value);
370 } 369 }
371 fprintf(output, "%f] score\n", iter->ssim_value); 370 fprintf(output, "%f] score\n", iter->ssim_value);
372 } 371 }
373 } 372 }
374 373
375 } // namespace test 374 } // namespace test
376 } // namespace webrtc 375 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/tools/BUILD.gn ('k') | webrtc/tools/frame_analyzer/video_quality_analysis_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698