OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 221 } |
222 } | 222 } |
223 | 223 |
224 std::ostream* log_out = &std::cout; | 224 std::ostream* log_out = &std::cout; |
225 #if defined(ENABLE_WINDOWS_EXCEPTIONS) | 225 #if defined(ENABLE_WINDOWS_EXCEPTIONS) |
226 // Catch exceptions so this tool can be used in automated testing. | 226 // Catch exceptions so this tool can be used in automated testing. |
227 __try { | 227 __try { |
228 #endif | 228 #endif |
229 | 229 |
230 // Register FFmpeg and attempt to open file. | 230 // Register FFmpeg and attempt to open file. |
231 avcodec_init(); | |
232 av_log_set_level(verbose_level); | 231 av_log_set_level(verbose_level); |
233 av_register_all(); | 232 av_register_all(); |
234 av_register_protocol2(&kFFmpegFileProtocol, sizeof(kFFmpegFileProtocol)); | 233 av_register_protocol2(&kFFmpegFileProtocol, sizeof(kFFmpegFileProtocol)); |
235 AVFormatContext* format_context = NULL; | 234 AVFormatContext* format_context = NULL; |
236 // av_open_input_file wants a char*, which can't work with wide paths. | 235 // avformat_open_input() wants a char*, which can't work with wide paths. |
237 // So we assume ASCII on Windows. On other platforms we can pass the | 236 // So we assume ASCII on Windows. On other platforms we can pass the |
238 // path bytes through verbatim. | 237 // path bytes through verbatim. |
239 #if defined(OS_WIN) | 238 #if defined(OS_WIN) |
240 std::string string_path = WideToASCII(in_path.value()); | 239 std::string string_path = WideToASCII(in_path.value()); |
241 #else | 240 #else |
242 const std::string& string_path = in_path.value(); | 241 const std::string& string_path = in_path.value(); |
243 #endif | 242 #endif |
244 int result = av_open_input_file(&format_context, string_path.c_str(), | 243 int result = avformat_open_input(&format_context, string_path.c_str(), |
245 NULL, 0, NULL); | 244 NULL, NULL); |
246 if (result < 0) { | 245 if (result < 0) { |
247 switch (result) { | 246 switch (result) { |
248 case AVERROR(EINVAL): | 247 case AVERROR(EINVAL): |
249 std::cerr << "Error: File format not supported " | 248 std::cerr << "Error: File format not supported " |
250 << in_path.value() << std::endl; | 249 << in_path.value() << std::endl; |
251 break; | 250 break; |
252 default: | 251 default: |
253 std::cerr << "Error: Could not open input for " | 252 std::cerr << "Error: Could not open input for " |
254 << in_path.value() << std::endl; | 253 << in_path.value() << std::endl; |
255 break; | 254 break; |
(...skipping 16 matching lines...) Expand all Loading... |
272 output = file_util::OpenFile(out_path, "wb"); | 271 output = file_util::OpenFile(out_path, "wb"); |
273 } | 272 } |
274 if (!output) { | 273 if (!output) { |
275 std::cerr << "Error: Could not open output " | 274 std::cerr << "Error: Could not open output " |
276 << out_path.value() << std::endl; | 275 << out_path.value() << std::endl; |
277 return 1; | 276 return 1; |
278 } | 277 } |
279 } | 278 } |
280 | 279 |
281 // Parse a little bit of the stream to fill out the format context. | 280 // Parse a little bit of the stream to fill out the format context. |
282 if (av_find_stream_info(format_context) < 0) { | 281 if (avformat_find_stream_info(format_context, NULL) < 0) { |
283 std::cerr << "Error: Could not find stream info for " | 282 std::cerr << "Error: Could not find stream info for " |
284 << in_path.value() << std::endl; | 283 << in_path.value() << std::endl; |
285 return 1; | 284 return 1; |
286 } | 285 } |
287 | 286 |
288 // Find our target stream. | 287 // Find our target stream. |
289 int target_stream = -1; | 288 int target_stream = -1; |
290 for (size_t i = 0; i < format_context->nb_streams; ++i) { | 289 for (size_t i = 0; i < format_context->nb_streams; ++i) { |
291 AVCodecContext* codec_context = format_context->streams[i]->codec; | 290 AVCodecContext* codec_context = format_context->streams[i]->codec; |
292 AVCodec* codec = avcodec_find_decoder(codec_context->codec_id); | 291 AVCodec* codec = avcodec_find_decoder(codec_context->codec_id); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 } else if (skip == 3) { | 333 } else if (skip == 3) { |
335 codec_context->skip_loop_filter = AVDISCARD_ALL; | 334 codec_context->skip_loop_filter = AVDISCARD_ALL; |
336 codec_context->skip_frame = AVDISCARD_NONREF; | 335 codec_context->skip_frame = AVDISCARD_NONREF; |
337 } | 336 } |
338 if (fast2) { | 337 if (fast2) { |
339 // Note this flag is no longer necessary for H264 multithreading. | 338 // Note this flag is no longer necessary for H264 multithreading. |
340 codec_context->flags2 |= CODEC_FLAG2_FAST; | 339 codec_context->flags2 |= CODEC_FLAG2_FAST; |
341 } | 340 } |
342 if (error_correction) { | 341 if (error_correction) { |
343 codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; | 342 codec_context->error_concealment = FF_EC_GUESS_MVS | FF_EC_DEBLOCK; |
344 codec_context->error_recognition = FF_ER_CAREFUL; | 343 codec_context->err_recognition = AV_EF_CAREFUL; |
345 } | 344 } |
346 | 345 |
347 // Initialize threaded decode. | 346 // Initialize threaded decode. |
348 if (target_codec == AVMEDIA_TYPE_VIDEO && video_threads > 0) { | 347 if (target_codec == AVMEDIA_TYPE_VIDEO && video_threads > 0) { |
349 codec_context->thread_count = video_threads; | 348 codec_context->thread_count = video_threads; |
350 } | 349 } |
351 | 350 |
352 // Initialize our codec. | 351 // Initialize our codec. |
353 if (avcodec_open(codec_context, codec) < 0) { | 352 if (avcodec_open2(codec_context, codec, NULL) < 0) { |
354 std::cerr << "Error: Could not open codec " | 353 std::cerr << "Error: Could not open codec " |
355 << (codec_context->codec ? codec_context->codec->name : "(NULL)") | 354 << (codec_context->codec ? codec_context->codec->name : "(NULL)") |
356 << " for " << in_path.value() << std::endl; | 355 << " for " << in_path.value() << std::endl; |
357 return 1; | 356 return 1; |
358 } | 357 } |
359 | 358 |
360 // Buffer used for audio decoding. | 359 // Buffer used for audio decoding. |
361 scoped_ptr_malloc<int16, media::ScopedPtrAVFree> samples( | 360 scoped_ptr_malloc<int16, media::ScopedPtrAVFree> samples( |
362 reinterpret_cast<int16*>(av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE))); | 361 reinterpret_cast<int16*>(av_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE))); |
363 | 362 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 } while (read_result >= 0); | 525 } while (read_result >= 0); |
527 base::TimeDelta total = base::TimeTicks::HighResNow() - start; | 526 base::TimeDelta total = base::TimeTicks::HighResNow() - start; |
528 LeaveTimingSection(); | 527 LeaveTimingSection(); |
529 | 528 |
530 // Clean up. | 529 // Clean up. |
531 if (output) | 530 if (output) |
532 file_util::CloseFile(output); | 531 file_util::CloseFile(output); |
533 if (codec_context) | 532 if (codec_context) |
534 avcodec_close(codec_context); | 533 avcodec_close(codec_context); |
535 if (format_context) | 534 if (format_context) |
536 av_close_input_file(format_context); | 535 avformat_close_input(&format_context); |
537 | 536 |
538 // Calculate the sum of times. Note that some of these may be zero. | 537 // Calculate the sum of times. Note that some of these may be zero. |
539 double sum = 0; | 538 double sum = 0; |
540 for (size_t i = 0; i < decode_times.size(); ++i) { | 539 for (size_t i = 0; i < decode_times.size(); ++i) { |
541 sum += decode_times[i]; | 540 sum += decode_times[i]; |
542 } | 541 } |
543 | 542 |
544 double average = 0; | 543 double average = 0; |
545 double stddev = 0; | 544 double stddev = 0; |
546 double fps = 0; | 545 double fps = 0; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 #if defined(ENABLE_WINDOWS_EXCEPTIONS) | 593 #if defined(ENABLE_WINDOWS_EXCEPTIONS) |
595 } __except(EXCEPTION_EXECUTE_HANDLER) { | 594 } __except(EXCEPTION_EXECUTE_HANDLER) { |
596 *log_out << " Exception:" << std::setw(11) << GetExceptionCode() | 595 *log_out << " Exception:" << std::setw(11) << GetExceptionCode() |
597 << " " << in_path.value() << std::endl; | 596 << " " << in_path.value() << std::endl; |
598 return 1; | 597 return 1; |
599 } | 598 } |
600 #endif | 599 #endif |
601 CommandLine::Reset(); | 600 CommandLine::Reset(); |
602 return 0; | 601 return 0; |
603 } | 602 } |
OLD | NEW |