| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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" | |
| 238 << "Did you build with pthread/w32thread support?" << std::endl; | |
| 239 } | |
| 240 } | 237 } |
| 241 | 238 |
| 242 // Initialize our codec. | 239 // Initialize our codec. |
| 243 if (avcodec_open(codec_context, codec) < 0) { | 240 if (avcodec_open(codec_context, codec) < 0) { |
| 244 std::cerr << "Error: Could not open codec " | 241 std::cerr << "Error: Could not open codec " |
| 245 << codec_context->codec->name << " for " | 242 << codec_context->codec->name << " for " |
| 246 << in_path.value() << std::endl; | 243 << in_path.value() << std::endl; |
| 247 return 1; | 244 return 1; |
| 248 } | 245 } |
| 249 | 246 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 packet.stream_index = target_stream; | 281 packet.stream_index = target_stream; |
| 285 packet.size = 0; | 282 packet.size = 0; |
| 286 } else { | 283 } else { |
| 287 break; | 284 break; |
| 288 } | 285 } |
| 289 } | 286 } |
| 290 | 287 |
| 291 // Only decode packets from our target stream. | 288 // Only decode packets from our target stream. |
| 292 if (packet.stream_index == target_stream) { | 289 if (packet.stream_index == target_stream) { |
| 293 int result = -1; | 290 int result = -1; |
| 294 if (target_codec == CODEC_TYPE_AUDIO) { | 291 if (target_codec == AVMEDIA_TYPE_AUDIO) { |
| 295 int size_out = AVCODEC_MAX_AUDIO_FRAME_SIZE; | 292 int size_out = AVCODEC_MAX_AUDIO_FRAME_SIZE; |
| 296 | 293 |
| 297 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); | 294 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); |
| 298 result = avcodec_decode_audio3(codec_context, samples.get(), &size_out, | 295 result = avcodec_decode_audio3(codec_context, samples.get(), &size_out, |
| 299 &packet); | 296 &packet); |
| 300 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; | 297 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; |
| 301 | 298 |
| 302 if (size_out) { | 299 if (size_out) { |
| 303 decode_times.push_back(delta.InMillisecondsF()); | 300 decode_times.push_back(delta.InMillisecondsF()); |
| 304 ++frames; | 301 ++frames; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 316 | 313 |
| 317 const uint8* u8_samples = | 314 const uint8* u8_samples = |
| 318 reinterpret_cast<const uint8*>(samples.get()); | 315 reinterpret_cast<const uint8*>(samples.get()); |
| 319 if (hash_djb2) { | 316 if (hash_djb2) { |
| 320 hash_value = DJB2Hash(u8_samples, size_out, hash_value); | 317 hash_value = DJB2Hash(u8_samples, size_out, hash_value); |
| 321 } | 318 } |
| 322 if (hash_md5) { | 319 if (hash_md5) { |
| 323 MD5Update(&ctx, u8_samples, size_out); | 320 MD5Update(&ctx, u8_samples, size_out); |
| 324 } | 321 } |
| 325 } | 322 } |
| 326 } else if (target_codec == CODEC_TYPE_VIDEO) { | 323 } else if (target_codec == AVMEDIA_TYPE_VIDEO) { |
| 327 int got_picture = 0; | 324 int got_picture = 0; |
| 328 | 325 |
| 329 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); | 326 base::TimeTicks decode_start = base::TimeTicks::HighResNow(); |
| 330 result = avcodec_decode_video2(codec_context, frame.get(), | 327 result = avcodec_decode_video2(codec_context, frame.get(), |
| 331 &got_picture, &packet); | 328 &got_picture, &packet); |
| 332 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; | 329 base::TimeDelta delta = base::TimeTicks::HighResNow() - decode_start; |
| 333 | 330 |
| 334 if (got_picture) { | 331 if (got_picture) { |
| 335 decode_times.push_back(delta.InMillisecondsF()); | 332 decode_times.push_back(delta.InMillisecondsF()); |
| 336 ++frames; | 333 ++frames; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 if (format_context) | 415 if (format_context) |
| 419 av_close_input_file(format_context); | 416 av_close_input_file(format_context); |
| 420 | 417 |
| 421 // Calculate the sum of times. Note that some of these may be zero. | 418 // Calculate the sum of times. Note that some of these may be zero. |
| 422 double sum = 0; | 419 double sum = 0; |
| 423 for (size_t i = 0; i < decode_times.size(); ++i) { | 420 for (size_t i = 0; i < decode_times.size(); ++i) { |
| 424 sum += decode_times[i]; | 421 sum += decode_times[i]; |
| 425 } | 422 } |
| 426 | 423 |
| 427 if (sum > 0) { | 424 if (sum > 0) { |
| 428 if (target_codec == CODEC_TYPE_AUDIO) { | 425 if (target_codec == AVMEDIA_TYPE_AUDIO) { |
| 429 // Calculate the average milliseconds per frame. | 426 // Calculate the average milliseconds per frame. |
| 430 // Audio decoding is usually in the millisecond or range, and | 427 // Audio decoding is usually in the millisecond or range, and |
| 431 // best expressed in time (ms) rather than FPS, which can approach | 428 // best expressed in time (ms) rather than FPS, which can approach |
| 432 // infinity. | 429 // infinity. |
| 433 double ms = sum / frames; | 430 double ms = sum / frames; |
| 434 // Print our results. | 431 // Print our results. |
| 435 log_out->setf(std::ios::fixed); | 432 log_out->setf(std::ios::fixed); |
| 436 log_out->precision(2); | 433 log_out->precision(2); |
| 437 *log_out << "TIME PER FRAME (MS):" << std::setw(11) << ms << std::endl; | 434 *log_out << "TIME PER FRAME (MS):" << std::setw(11) << ms << std::endl; |
| 438 } else if (target_codec == CODEC_TYPE_VIDEO) { | 435 } else if (target_codec == AVMEDIA_TYPE_VIDEO) { |
| 439 // Calculate the average frames per second. | 436 // Calculate the average frames per second. |
| 440 // Video decoding is expressed in Frames Per Second - a term easily | 437 // Video decoding is expressed in Frames Per Second - a term easily |
| 441 // understood and should exceed a typical target of 30 fps. | 438 // understood and should exceed a typical target of 30 fps. |
| 442 double fps = frames * 1000.0 / sum; | 439 double fps = frames * 1000.0 / sum; |
| 443 // Print our results. | 440 // Print our results. |
| 444 log_out->setf(std::ios::fixed); | 441 log_out->setf(std::ios::fixed); |
| 445 log_out->precision(2); | 442 log_out->precision(2); |
| 446 *log_out << "FPS:" << std::setw(11) << fps << std::endl; | 443 *log_out << "FPS:" << std::setw(11) << fps << std::endl; |
| 447 } | 444 } |
| 448 } | 445 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } __except(EXCEPTION_EXECUTE_HANDLER) { | 492 } __except(EXCEPTION_EXECUTE_HANDLER) { |
| 496 *log_out << " Exception:" << std::setw(11) << GetExceptionCode() | 493 *log_out << " Exception:" << std::setw(11) << GetExceptionCode() |
| 497 << " " << in_path.value() << std::endl; | 494 << " " << in_path.value() << std::endl; |
| 498 return 1; | 495 return 1; |
| 499 } | 496 } |
| 500 #endif | 497 #endif |
| 501 CommandLine::Reset(); | 498 CommandLine::Reset(); |
| 502 return 0; | 499 return 0; |
| 503 } | 500 } |
| 504 | 501 |
| OLD | NEW |