OLD | NEW |
1 // Copyright (c) 2010 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 // Standalone benchmarking application based on FFmpeg. This tool is used to | 5 // Standalone benchmarking application based on FFmpeg. This tool is used to |
6 // measure decoding performance between different FFmpeg compile and run-time | 6 // measure decoding performance between different FFmpeg compile and run-time |
7 // options. We also use this tool to measure performance regressions when | 7 // options. We also use this tool to measure performance regressions when |
8 // testing newer builds of FFmpeg from trunk. | 8 // testing newer builds of FFmpeg from trunk. |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 | 11 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 if (media::InitializeMediaLibrary(FilePath()) == false) { | 125 if (media::InitializeMediaLibrary(FilePath()) == false) { |
126 std::cerr << "Unable to initialize the media library."; | 126 std::cerr << "Unable to initialize the media library."; |
127 return 1; | 127 return 1; |
128 } | 128 } |
129 | 129 |
130 // Retrieve command line options. | 130 // Retrieve command line options. |
131 FilePath in_path(filenames[0]); | 131 FilePath in_path(filenames[0]); |
132 FilePath out_path; | 132 FilePath out_path; |
133 if (filenames.size() > 1) | 133 if (filenames.size() > 1) |
134 out_path = FilePath(filenames[1]); | 134 out_path = FilePath(filenames[1]); |
135 CodecType target_codec = CODEC_TYPE_UNKNOWN; | 135 AVMediaType target_codec = AVMEDIA_TYPE_UNKNOWN; |
136 | 136 |
137 // Determine whether to benchmark audio or video decoding. | 137 // Determine whether to benchmark audio or video decoding. |
138 std::string stream(cmd_line->GetSwitchValueASCII(switches::kStream)); | 138 std::string stream(cmd_line->GetSwitchValueASCII(switches::kStream)); |
139 if (!stream.empty()) { | 139 if (!stream.empty()) { |
140 if (stream.compare("audio") == 0) { | 140 if (stream.compare("audio") == 0) { |
141 target_codec = CODEC_TYPE_AUDIO; | 141 target_codec = AVMEDIA_TYPE_AUDIO; |
142 } else if (stream.compare("video") == 0) { | 142 } else if (stream.compare("video") == 0) { |
143 target_codec = CODEC_TYPE_VIDEO; | 143 target_codec = AVMEDIA_TYPE_VIDEO; |
144 } else { | 144 } else { |
145 std::cerr << "Unknown --stream option " << stream << std::endl; | 145 std::cerr << "Unknown --stream option " << stream << std::endl; |
146 return 1; | 146 return 1; |
147 } | 147 } |
148 } | 148 } |
149 | 149 |
150 // Determine number of threads to use for video decoding (optional). | 150 // Determine number of threads to use for video decoding (optional). |
151 int video_threads = 0; | 151 int video_threads = 0; |
152 std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads)); | 152 std::string threads(cmd_line->GetSwitchValueASCII(switches::kVideoThreads)); |
153 if (!threads.empty() && | 153 if (!threads.empty() && |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // path bytes through verbatim. | 232 // path bytes through verbatim. |
233 #if defined(OS_WIN) | 233 #if defined(OS_WIN) |
234 std::string string_path = WideToASCII(in_path.value()); | 234 std::string string_path = WideToASCII(in_path.value()); |
235 #else | 235 #else |
236 const std::string& string_path = in_path.value(); | 236 const std::string& string_path = in_path.value(); |
237 #endif | 237 #endif |
238 int result = av_open_input_file(&format_context, string_path.c_str(), | 238 int result = av_open_input_file(&format_context, string_path.c_str(), |
239 NULL, 0, NULL); | 239 NULL, 0, NULL); |
240 if (result < 0) { | 240 if (result < 0) { |
241 switch (result) { | 241 switch (result) { |
242 case AVERROR_NOFMT: | 242 case AVERROR(EINVAL): |
243 std::cerr << "Error: File format not supported " | 243 std::cerr << "Error: File format not supported " |
244 << in_path.value() << std::endl; | 244 << in_path.value() << std::endl; |
245 break; | 245 break; |
246 default: | 246 default: |
247 std::cerr << "Error: Could not open input for " | 247 std::cerr << "Error: Could not open input for " |
248 << in_path.value() << std::endl; | 248 << in_path.value() << std::endl; |
249 break; | 249 break; |
250 } | 250 } |
251 return 1; | 251 return 1; |
252 } | 252 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 AVCodec* codec = avcodec_find_decoder(codec_context->codec_id); | 286 AVCodec* codec = avcodec_find_decoder(codec_context->codec_id); |
287 | 287 |
288 // See if we found our target codec. | 288 // See if we found our target codec. |
289 if (codec_context->codec_type == target_codec && target_stream < 0) { | 289 if (codec_context->codec_type == target_codec && target_stream < 0) { |
290 *log_out << "* "; | 290 *log_out << "* "; |
291 target_stream = i; | 291 target_stream = i; |
292 } else { | 292 } else { |
293 *log_out << " "; | 293 *log_out << " "; |
294 } | 294 } |
295 | 295 |
296 if (!codec || (codec_context->codec_type == CODEC_TYPE_UNKNOWN)) { | 296 if (!codec || (codec_context->codec_type == AVMEDIA_TYPE_UNKNOWN)) { |
297 *log_out << "Stream #" << i << ": Unknown" << std::endl; | 297 *log_out << "Stream #" << i << ": Unknown" << std::endl; |
298 } else { | 298 } else { |
299 // Print out stream information | 299 // Print out stream information |
300 *log_out << "Stream #" << i << ": " << codec->name << " (" | 300 *log_out << "Stream #" << i << ": " << codec->name << " (" |
301 << codec->long_name << ")" << std::endl; | 301 << codec->long_name << ")" << std::endl; |
302 } | 302 } |
303 } | 303 } |
304 | 304 |
305 // Only continue if we found our target stream. | 305 // Only continue if we found our target stream. |
306 if (target_stream < 0) { | 306 if (target_stream < 0) { |
(...skipping 25 matching lines...) Expand all Loading... |
332 if (fast2) { | 332 if (fast2) { |
333 // Note this flag is no longer necessary for H264 multithreading. | 333 // Note this flag is no longer necessary for H264 multithreading. |
334 codec_context->flags2 |= CODEC_FLAG2_FAST; | 334 codec_context->flags2 |= CODEC_FLAG2_FAST; |
335 } | 335 } |
336 if (error_correction) { | 336 if (error_correction) { |
337 codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; | 337 codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; |
338 codec_context->error_recognition = FF_ER_CAREFUL; | 338 codec_context->error_recognition = FF_ER_CAREFUL; |
339 } | 339 } |
340 | 340 |
341 // Initialize threaded decode. | 341 // Initialize threaded decode. |
342 if (target_codec == CODEC_TYPE_VIDEO && video_threads > 0) { | 342 if (target_codec == AVMEDIA_TYPE_VIDEO && video_threads > 0) { |
343 if (avcodec_thread_init(codec_context, video_threads) < 0) { | 343 codec_context->thread_count = video_threads; |
344 std::cerr << "Warning: Could not initialize threading!\n" | |
345 << "Did you build with pthread/w32thread support?" << std::endl; | |
346 } | |
347 } | 344 } |
348 | 345 |
349 // Initialize our codec. | 346 // Initialize our codec. |
350 if (avcodec_open(codec_context, codec) < 0) { | 347 if (avcodec_open(codec_context, codec) < 0) { |
351 std::cerr << "Error: Could not open codec " | 348 std::cerr << "Error: Could not open codec " |
352 << (codec_context->codec ? codec_context->codec->name : "(NULL)") | 349 << (codec_context->codec ? codec_context->codec->name : "(NULL)") |
353 << " for " << in_path.value() << std::endl; | 350 << " for " << in_path.value() << std::endl; |
354 return 1; | 351 return 1; |
355 } | 352 } |
356 | 353 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 packet.stream_index = target_stream; | 392 packet.stream_index = target_stream; |
396 packet.size = 0; | 393 packet.size = 0; |
397 } else { | 394 } else { |
398 break; | 395 break; |
399 } | 396 } |
400 } | 397 } |
401 | 398 |
402 // Only decode packets from our target stream. | 399 // Only decode packets from our target stream. |
403 if (packet.stream_index == target_stream) { | 400 if (packet.stream_index == target_stream) { |
404 int result = -1; | 401 int result = -1; |
405 if (target_codec == CODEC_TYPE_AUDIO) { | 402 if (target_codec == AVMEDIA_TYPE_AUDIO) { |
406 int size_out = AVCODEC_MAX_AUDIO_FRAME_SIZE; | 403 int size_out = AVCODEC_MAX_AUDIO_FRAME_SIZE; |
407 | 404 |
408 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); | 405 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); |
409 result = avcodec_decode_audio3(codec_context, samples.get(), &size_out, | 406 result = avcodec_decode_audio3(codec_context, samples.get(), &size_out, |
410 &packet); | 407 &packet); |
411 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; | 408 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; |
412 | 409 |
413 if (size_out) { | 410 if (size_out) { |
414 decode_times.push_back(delta.InMillisecondsF()); | 411 decode_times.push_back(delta.InMillisecondsF()); |
415 ++frames; | 412 ++frames; |
(...skipping 11 matching lines...) Expand all Loading... |
427 | 424 |
428 const uint8* u8_samples = | 425 const uint8* u8_samples = |
429 reinterpret_cast<const uint8*>(samples.get()); | 426 reinterpret_cast<const uint8*>(samples.get()); |
430 if (hash_djb2) { | 427 if (hash_djb2) { |
431 hash_value = DJB2Hash(u8_samples, size_out, hash_value); | 428 hash_value = DJB2Hash(u8_samples, size_out, hash_value); |
432 } | 429 } |
433 if (hash_md5) { | 430 if (hash_md5) { |
434 MD5Update(&ctx, u8_samples, size_out); | 431 MD5Update(&ctx, u8_samples, size_out); |
435 } | 432 } |
436 } | 433 } |
437 } else if (target_codec == CODEC_TYPE_VIDEO) { | 434 } else if (target_codec == AVMEDIA_TYPE_VIDEO) { |
438 int got_picture = 0; | 435 int got_picture = 0; |
439 | 436 |
440 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); | 437 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); |
441 result = avcodec_decode_video2(codec_context, frame.get(), | 438 result = avcodec_decode_video2(codec_context, frame.get(), |
442 &got_picture, &packet); | 439 &got_picture, &packet); |
443 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; | 440 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; |
444 | 441 |
445 if (got_picture) { | 442 if (got_picture) { |
446 decode_times.push_back(delta.InMillisecondsF()); | 443 decode_times.push_back(delta.InMillisecondsF()); |
447 ++frames; | 444 ++frames; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 #if defined(ENABLE_WINDOWS_EXCEPTIONS) | 583 #if defined(ENABLE_WINDOWS_EXCEPTIONS) |
587 } __except(EXCEPTION_EXECUTE_HANDLER) { | 584 } __except(EXCEPTION_EXECUTE_HANDLER) { |
588 *log_out << " Exception:" << std::setw(11) << GetExceptionCode() | 585 *log_out << " Exception:" << std::setw(11) << GetExceptionCode() |
589 << " " << in_path.value() << std::endl; | 586 << " " << in_path.value() << std::endl; |
590 return 1; | 587 return 1; |
591 } | 588 } |
592 #endif | 589 #endif |
593 CommandLine::Reset(); | 590 CommandLine::Reset(); |
594 return 0; | 591 return 0; |
595 } | 592 } |
OLD | NEW |