diff options
Diffstat (limited to 'media/test/ffmpeg_tests/ffmpeg_tests.cc')
-rw-r--r-- | media/test/ffmpeg_tests/ffmpeg_tests.cc | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/media/test/ffmpeg_tests/ffmpeg_tests.cc b/media/test/ffmpeg_tests/ffmpeg_tests.cc index 47dd1b1..a967bc3 100644 --- a/media/test/ffmpeg_tests/ffmpeg_tests.cc +++ b/media/test/ffmpeg_tests/ffmpeg_tests.cc @@ -70,10 +70,7 @@ int main(int argc, const char** argv) { CommandLine::Init(argc, argv); const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); - // TODO(evanm): GetLooseValues() should return a - // CommandLine::StringType, which can be converted to FilePaths - // directly. - std::vector<std::wstring> filenames(cmd_line->GetLooseValues()); + const std::vector<CommandLine::StringType>& filenames = cmd_line->args(); if (filenames.empty()) { std::cerr << "Usage: " << argv[0] << " MEDIAFILE" << std::endl; @@ -89,12 +86,10 @@ int main(int argc, const char** argv) { } // Retrieve command line options. - std::string in_path(WideToASCII(filenames[0])); + FilePath in_path(filenames[0]); FilePath out_path; - if (filenames.size() > 1) { - // See TODO above the declaration of filenames. - out_path = FilePath::FromWStringHack(filenames[1]); - } + if (filenames.size() > 1) + out_path = FilePath(filenames[1]); // Default flags that match Chrome defaults. int video_threads = 3; @@ -122,17 +117,25 @@ int main(int argc, const char** argv) { av_register_all(); av_register_protocol(&kFFmpegFileProtocol); AVFormatContext* format_context = NULL; - int result = av_open_input_file(&format_context, in_path.c_str(), + // av_open_input_file wants a char*, which can't work with wide paths. + // So we assume ASCII on Windows. On other platforms we can pass the + // path bytes through verbatim. +#if defined(OS_WIN) + std::string string_path = WideToASCII(in_path.value()); +#else + const std::string& string_path = in_path.value(); +#endif + int result = av_open_input_file(&format_context, string_path.c_str(), NULL, 0, NULL); if (result < 0) { switch (result) { case AVERROR_NOFMT: std::cerr << "Error: File format not supported " - << in_path << std::endl; + << in_path.value() << std::endl; break; default: std::cerr << "Error: Could not open input for " - << in_path << std::endl; + << in_path.value() << std::endl; break; } return 1; @@ -152,7 +155,7 @@ int main(int argc, const char** argv) { // Parse a little bit of the stream to fill out the format context. if (av_find_stream_info(format_context) < 0) { std::cerr << "Error: Could not find stream info for " - << in_path << std::endl; + << in_path.value() << std::endl; return 1; } @@ -201,7 +204,7 @@ int main(int argc, const char** argv) { // Only continue if we found our target stream. if (target_stream < 0) { std::cerr << "Error: Could not find target stream " - << target_stream << " for " << in_path << std::endl; + << target_stream << " for " << in_path.value() << std::endl; return 1; } @@ -213,14 +216,14 @@ int main(int argc, const char** argv) { // Only continue if we found our codec. if (!codec) { std::cerr << "Error: Could not find codec for " - << in_path << std::endl; + << in_path.value() << std::endl; return 1; } // TODO(fbarchard): On next ffmpeg roll, retest if this work around is needed. if (codec_context->codec_id == CODEC_ID_THEORA) { std::cerr << "Warning: Disabling threads to avoid Theora bug " - << in_path << std::endl; + << in_path.value() << std::endl; video_threads = 1; } @@ -240,7 +243,7 @@ int main(int argc, const char** argv) { if (avcodec_open(codec_context, codec) < 0) { std::cerr << "Error: Could not open codec " << codec_context->codec->name << " for " - << in_path << std::endl; + << in_path.value() << std::endl; return 1; } @@ -253,7 +256,7 @@ int main(int argc, const char** argv) { avcodec_alloc_frame()); if (!frame.get()) { std::cerr << "Error: avcodec_alloc_frame for " - << in_path << std::endl; + << in_path.value() << std::endl; return 1; } @@ -305,7 +308,8 @@ int main(int argc, const char** argv) { if (fwrite(samples.get(), 1, size_out, output) != static_cast<size_t>(size_out)) { std::cerr << "Error: Could not write " - << size_out << " bytes for " << in_path << std::endl; + << size_out << " bytes for " << in_path.value() + << std::endl; return 1; } } @@ -363,7 +367,7 @@ int main(int argc, const char** argv) { bytes_per_line) { std::cerr << "Error: Could not write data after " << copy_lines << " lines for " - << in_path << std::endl; + << in_path.value() << std::endl; return 1; } source += source_stride; @@ -391,7 +395,7 @@ int main(int argc, const char** argv) { // Make sure our decoding went OK. if (result < 0) { std::cerr << "Error: avcodec_decode returned " - << result << " for " << in_path << std::endl; + << result << " for " << in_path.value() << std::endl; return 1; } } @@ -476,19 +480,19 @@ int main(int argc, const char** argv) { } if (hash_djb2) { *log_out << " DJB2 Hash:" << std::setw(11) << hash_value - << " " << in_path << std::endl; + << " " << in_path.value() << std::endl; } if (hash_md5) { MD5Digest digest; // The result of the computation. MD5Final(&digest, &ctx); *log_out << " MD5 Hash: " << MD5DigestToBase16(digest) - << " " << in_path << std::endl; + << " " << in_path.value() << std::endl; } #endif // SHOW_VERBOSE #if defined(ENABLE_WINDOWS_EXCEPTIONS) } __except(EXCEPTION_EXECUTE_HANDLER) { *log_out << " Exception:" << std::setw(11) << GetExceptionCode() - << " " << in_path << std::endl; + << " " << in_path.value() << std::endl; return 1; } #endif |