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

Side by Side Diff: media/test/ffmpeg_tests/ffmpeg_tests.cc

Issue 6993042: ffmpeg chromium glue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Software qualification test for FFmpeg. This test is used to certify that 5 // Software qualification test for FFmpeg. This test is used to certify that
6 // software decoding quality and performance of FFmpeg meets a mimimum 6 // software decoding quality and performance of FFmpeg meets a mimimum
7 // standard. 7 // standard.
8 8
9 #include <iomanip> 9 #include <iomanip>
10 #include <iostream> 10 #include <iostream>
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // path bytes through verbatim. 123 // path bytes through verbatim.
124 #if defined(OS_WIN) 124 #if defined(OS_WIN)
125 std::string string_path = WideToASCII(in_path.value()); 125 std::string string_path = WideToASCII(in_path.value());
126 #else 126 #else
127 const std::string& string_path = in_path.value(); 127 const std::string& string_path = in_path.value();
128 #endif 128 #endif
129 int result = av_open_input_file(&format_context, string_path.c_str(), 129 int result = av_open_input_file(&format_context, string_path.c_str(),
130 NULL, 0, NULL); 130 NULL, 0, NULL);
131 if (result < 0) { 131 if (result < 0) {
132 switch (result) { 132 switch (result) {
133 case AVERROR_NOFMT: 133 case AVERROR(EINVAL):
134 std::cerr << "Error: File format not supported " 134 std::cerr << "Error: File format not supported "
135 << in_path.value() << std::endl; 135 << in_path.value() << std::endl;
136 break; 136 break;
137 default: 137 default:
138 std::cerr << "Error: Could not open input for " 138 std::cerr << "Error: Could not open input for "
139 << in_path.value() << std::endl; 139 << in_path.value() << std::endl;
140 break; 140 break;
141 } 141 }
142 return 1; 142 return 1;
143 } 143 }
(...skipping 15 matching lines...) Expand all
159 << in_path.value() << std::endl; 159 << in_path.value() << std::endl;
160 return 1; 160 return 1;
161 } 161 }
162 162
163 // Find our target stream(s) 163 // Find our target stream(s)
164 int video_stream = -1; 164 int video_stream = -1;
165 int audio_stream = -1; 165 int audio_stream = -1;
166 for (size_t i = 0; i < format_context->nb_streams; ++i) { 166 for (size_t i = 0; i < format_context->nb_streams; ++i) {
167 AVCodecContext* codec_context = format_context->streams[i]->codec; 167 AVCodecContext* codec_context = format_context->streams[i]->codec;
168 168
169 if (codec_context->codec_type == CODEC_TYPE_VIDEO && video_stream < 0) { 169 if (codec_context->codec_type == AVMEDIA_TYPE_VIDEO && video_stream < 0) {
170 #if SHOW_VERBOSE 170 #if SHOW_VERBOSE
171 *log_out << "V "; 171 *log_out << "V ";
172 #endif 172 #endif
173 video_stream = i; 173 video_stream = i;
174 } else { 174 } else {
175 if (codec_context->codec_type == CODEC_TYPE_AUDIO && audio_stream < 0) { 175 if (codec_context->codec_type == AVMEDIA_TYPE_AUDIO && audio_stream < 0) {
176 #if SHOW_VERBOSE 176 #if SHOW_VERBOSE
177 *log_out << "A "; 177 *log_out << "A ";
178 #endif 178 #endif
179 audio_stream = i; 179 audio_stream = i;
180 } else { 180 } else {
181 #if SHOW_VERBOSE 181 #if SHOW_VERBOSE
182 *log_out << " "; 182 *log_out << " ";
183 #endif 183 #endif
184 } 184 }
185 } 185 }
186 186
187 #if SHOW_VERBOSE 187 #if SHOW_VERBOSE
188 AVCodec* codec = avcodec_find_decoder(codec_context->codec_id); 188 AVCodec* codec = avcodec_find_decoder(codec_context->codec_id);
189 if (!codec || (codec_context->codec_type == CODEC_TYPE_UNKNOWN)) { 189 if (!codec || (codec_context->codec_type == AVMEDIA_TYPE_UNKNOWN)) {
190 *log_out << "Stream #" << i << ": Unknown" << std::endl; 190 *log_out << "Stream #" << i << ": Unknown" << std::endl;
191 } else { 191 } else {
192 // Print out stream information 192 // Print out stream information
193 *log_out << "Stream #" << i << ": " << codec->name << " (" 193 *log_out << "Stream #" << i << ": " << codec->name << " ("
194 << codec->long_name << ")" << std::endl; 194 << codec->long_name << ")" << std::endl;
195 } 195 }
196 #endif 196 #endif
197 } 197 }
198 int target_stream = video_stream; 198 int target_stream = video_stream;
199 CodecType target_codec = CODEC_TYPE_VIDEO; 199 AVMediaType target_codec = AVMEDIA_TYPE_VIDEO;
200 if (target_stream < 0) { 200 if (target_stream < 0) {
201 target_stream = audio_stream; 201 target_stream = audio_stream;
202 target_codec = CODEC_TYPE_AUDIO; 202 target_codec = AVMEDIA_TYPE_AUDIO;
203 } 203 }
204 204
205 // Only continue if we found our target stream. 205 // Only continue if we found our target stream.
206 if (target_stream < 0) { 206 if (target_stream < 0) {
207 std::cerr << "Error: Could not find target stream " 207 std::cerr << "Error: Could not find target stream "
208 << target_stream << " for " << in_path.value() << std::endl; 208 << target_stream << " for " << in_path.value() << std::endl;
209 return 1; 209 return 1;
210 } 210 }
211 211
212 // Prepare FFmpeg structures. 212 // Prepare FFmpeg structures.
(...skipping 12 matching lines...) Expand all
225 if (codec_context->codec_id == CODEC_ID_THEORA) { 225 if (codec_context->codec_id == CODEC_ID_THEORA) {
226 std::cerr << "Warning: Disabling threads to avoid Theora bug " 226 std::cerr << "Warning: Disabling threads to avoid Theora bug "
227 << in_path.value() << std::endl; 227 << in_path.value() << std::endl;
228 video_threads = 1; 228 video_threads = 1;
229 } 229 }
230 230
231 codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; 231 codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK;
232 codec_context->error_recognition = FF_ER_CAREFUL; 232 codec_context->error_recognition = FF_ER_CAREFUL;
233 233
234 // Initialize threaded decode. 234 // Initialize threaded decode.
235 if (target_codec == CODEC_TYPE_VIDEO && video_threads > 0) { 235 if (target_codec == AVMEDIA_TYPE_VIDEO && video_threads > 0) {
236 if (avcodec_thread_init(codec_context, video_threads) < 0) { 236 codec_context->thread_count = video_threads;
237 std::cerr << "Warning: Could not initialize threading!\n" 237 // avcodec_thread_init deprecated
scherkus (not reviewing) 2011/06/29 17:00:36 you can remove this comment
ilja 2011/06/29 21:40:05 Done.
238 << "Did you build with pthread/w32thread support?" << std::endl;
239 }
240 } 238 }
241 239
242 // Initialize our codec. 240 // Initialize our codec.
243 if (avcodec_open(codec_context, codec) < 0) { 241 if (avcodec_open(codec_context, codec) < 0) {
244 std::cerr << "Error: Could not open codec " 242 std::cerr << "Error: Could not open codec "
245 << codec_context->codec->name << " for " 243 << codec_context->codec->name << " for "
246 << in_path.value() << std::endl; 244 << in_path.value() << std::endl;
247 return 1; 245 return 1;
248 } 246 }
249 247
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 packet.stream_index = target_stream; 282 packet.stream_index = target_stream;
285 packet.size = 0; 283 packet.size = 0;
286 } else { 284 } else {
287 break; 285 break;
288 } 286 }
289 } 287 }
290 288
291 // Only decode packets from our target stream. 289 // Only decode packets from our target stream.
292 if (packet.stream_index == target_stream) { 290 if (packet.stream_index == target_stream) {
293 int result = -1; 291 int result = -1;
294 if (target_codec == CODEC_TYPE_AUDIO) { 292 if (target_codec == AVMEDIA_TYPE_AUDIO) {
295 int size_out = AVCODEC_MAX_AUDIO_FRAME_SIZE; 293 int size_out = AVCODEC_MAX_AUDIO_FRAME_SIZE;
296 294
297 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); 295 base::TimeTicks decode_start = base::TimeTicks::HighResNow();
298 result = avcodec_decode_audio3(codec_context, samples.get(), &size_out, 296 result = avcodec_decode_audio3(codec_context, samples.get(), &size_out,
299 &packet); 297 &packet);
300 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; 298 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start;
301 299
302 if (size_out) { 300 if (size_out) {
303 decode_times.push_back(delta.InMillisecondsF()); 301 decode_times.push_back(delta.InMillisecondsF());
304 ++frames; 302 ++frames;
(...skipping 11 matching lines...) Expand all
316 314
317 const uint8* u8_samples = 315 const uint8* u8_samples =
318 reinterpret_cast<const uint8*>(samples.get()); 316 reinterpret_cast<const uint8*>(samples.get());
319 if (hash_djb2) { 317 if (hash_djb2) {
320 hash_value = DJB2Hash(u8_samples, size_out, hash_value); 318 hash_value = DJB2Hash(u8_samples, size_out, hash_value);
321 } 319 }
322 if (hash_md5) { 320 if (hash_md5) {
323 MD5Update(&ctx, u8_samples, size_out); 321 MD5Update(&ctx, u8_samples, size_out);
324 } 322 }
325 } 323 }
326 } else if (target_codec == CODEC_TYPE_VIDEO) { 324 } else if (target_codec == AVMEDIA_TYPE_VIDEO) {
327 int got_picture = 0; 325 int got_picture = 0;
328 326
329 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); 327 base::TimeTicks decode_start = base::TimeTicks::HighResNow();
330 result = avcodec_decode_video2(codec_context, frame.get(), 328 result = avcodec_decode_video2(codec_context, frame.get(),
331 &got_picture, &packet); 329 &got_picture, &packet);
332 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; 330 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start;
333 331
334 if (got_picture) { 332 if (got_picture) {
335 decode_times.push_back(delta.InMillisecondsF()); 333 decode_times.push_back(delta.InMillisecondsF());
336 ++frames; 334 ++frames;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 if (format_context) 416 if (format_context)
419 av_close_input_file(format_context); 417 av_close_input_file(format_context);
420 418
421 // Calculate the sum of times. Note that some of these may be zero. 419 // Calculate the sum of times. Note that some of these may be zero.
422 double sum = 0; 420 double sum = 0;
423 for (size_t i = 0; i < decode_times.size(); ++i) { 421 for (size_t i = 0; i < decode_times.size(); ++i) {
424 sum += decode_times[i]; 422 sum += decode_times[i];
425 } 423 }
426 424
427 if (sum > 0) { 425 if (sum > 0) {
428 if (target_codec == CODEC_TYPE_AUDIO) { 426 if (target_codec == AVMEDIA_TYPE_AUDIO) {
429 // Calculate the average milliseconds per frame. 427 // Calculate the average milliseconds per frame.
430 // Audio decoding is usually in the millisecond or range, and 428 // Audio decoding is usually in the millisecond or range, and
431 // best expressed in time (ms) rather than FPS, which can approach 429 // best expressed in time (ms) rather than FPS, which can approach
432 // infinity. 430 // infinity.
433 double ms = sum / frames; 431 double ms = sum / frames;
434 // Print our results. 432 // Print our results.
435 log_out->setf(std::ios::fixed); 433 log_out->setf(std::ios::fixed);
436 log_out->precision(2); 434 log_out->precision(2);
437 *log_out << "TIME PER FRAME (MS):" << std::setw(11) << ms << std::endl; 435 *log_out << "TIME PER FRAME (MS):" << std::setw(11) << ms << std::endl;
438 } else if (target_codec == CODEC_TYPE_VIDEO) { 436 } else if (target_codec == AVMEDIA_TYPE_VIDEO) {
439 // Calculate the average frames per second. 437 // Calculate the average frames per second.
440 // Video decoding is expressed in Frames Per Second - a term easily 438 // Video decoding is expressed in Frames Per Second - a term easily
441 // understood and should exceed a typical target of 30 fps. 439 // understood and should exceed a typical target of 30 fps.
442 double fps = frames * 1000.0 / sum; 440 double fps = frames * 1000.0 / sum;
443 // Print our results. 441 // Print our results.
444 log_out->setf(std::ios::fixed); 442 log_out->setf(std::ios::fixed);
445 log_out->precision(2); 443 log_out->precision(2);
446 *log_out << "FPS:" << std::setw(11) << fps << std::endl; 444 *log_out << "FPS:" << std::setw(11) << fps << std::endl;
447 } 445 }
448 } 446 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 } __except(EXCEPTION_EXECUTE_HANDLER) { 493 } __except(EXCEPTION_EXECUTE_HANDLER) {
496 *log_out << " Exception:" << std::setw(11) << GetExceptionCode() 494 *log_out << " Exception:" << std::setw(11) << GetExceptionCode()
497 << " " << in_path.value() << std::endl; 495 << " " << in_path.value() << std::endl;
498 return 1; 496 return 1;
499 } 497 }
500 #endif 498 #endif
501 CommandLine::Reset(); 499 CommandLine::Reset();
502 return 0; 500 return 0;
503 } 501 }
504 502
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698