diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 15:57:23 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-21 15:57:23 +0000 |
commit | 2e4c50cd49a81bef973b934c236b110e660f3746 (patch) | |
tree | ae4a3d58d0a8efc60d47494305b59c57980eac78 /media | |
parent | 445a971d141c3b745a84f8fed3a2d627789ebf22 (diff) | |
download | chromium_src-2e4c50cd49a81bef973b934c236b110e660f3746.zip chromium_src-2e4c50cd49a81bef973b934c236b110e660f3746.tar.gz chromium_src-2e4c50cd49a81bef973b934c236b110e660f3746.tar.bz2 |
Remove deprecated CommandLine::GetLooseValues(), rename to args().
It returned a wstring, when really we wanted the native encoded
strings. Fixing the majority of callers actually simplified them
in many cases because the callers wanted native strings too.
Since I'm touching every caller, I gave it a more useful name.
I'm not sure where "loose" came from but it never made sense to me.
BUG=24672
Review URL: http://codereview.chromium.org/3028010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53193 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/test/ffmpeg_tests/ffmpeg_tests.cc | 52 | ||||
-rw-r--r-- | media/tools/media_bench/media_bench.cc | 50 | ||||
-rw-r--r-- | media/tools/player_wtl/player_wtl.cc | 2 | ||||
-rw-r--r-- | media/tools/scaler_bench/scaler_bench.cc | 2 | ||||
-rw-r--r-- | media/tools/wav_ola_test/wav_ola_test.cc | 13 |
5 files changed, 66 insertions, 53 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 diff --git a/media/tools/media_bench/media_bench.cc b/media/tools/media_bench/media_bench.cc index ad6a7c2..cdc2560 100644 --- a/media/tools/media_bench/media_bench.cc +++ b/media/tools/media_bench/media_bench.cc @@ -89,10 +89,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] << " [OPTIONS] FILE [DUMPFILE]\n" << " --stream=[audio|video] " @@ -129,12 +126,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]); CodecType target_codec = CODEC_TYPE_UNKNOWN; // Determine whether to benchmark audio or video decoding. @@ -230,17 +225,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; @@ -270,7 +273,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; } @@ -300,7 +303,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; } @@ -312,7 +315,7 @@ 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; } @@ -344,7 +347,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; } @@ -357,7 +360,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; } @@ -409,7 +412,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; } } @@ -467,7 +471,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; @@ -495,7 +499,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; } } @@ -556,18 +560,18 @@ 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; } #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 diff --git a/media/tools/player_wtl/player_wtl.cc b/media/tools/player_wtl/player_wtl.cc index 5df87a7..3bb8f9e 100644 --- a/media/tools/player_wtl/player_wtl.cc +++ b/media/tools/player_wtl/player_wtl.cc @@ -31,7 +31,7 @@ int Run(wchar_t* win_cmd_line, int cmd_show) { CommandLine::Init(0, NULL); const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); - std::vector<std::wstring> filenames(cmd_line->GetLooseValues()); + const std::vector<std::wstring>& filenames = cmd_line->args(); CMessageLoop the_loop; g_module.AddMessageLoop(&the_loop); diff --git a/media/tools/scaler_bench/scaler_bench.cc b/media/tools/scaler_bench/scaler_bench.cc index 749e1a6..b5d2ae1 100644 --- a/media/tools/scaler_bench/scaler_bench.cc +++ b/media/tools/scaler_bench/scaler_bench.cc @@ -135,7 +135,7 @@ int main(int argc, const char** argv) { CommandLine::Init(argc, argv); const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); - if (!cmd_line->GetLooseValues().empty()) { + if (!cmd_line->args().empty()) { std::cerr << "Usage: " << argv[0] << " [OPTIONS]\n" << " --frames=N " << "Number of frames\n" diff --git a/media/tools/wav_ola_test/wav_ola_test.cc b/media/tools/wav_ola_test/wav_ola_test.cc index 0aec9fd..4c006c3 100644 --- a/media/tools/wav_ola_test/wav_ola_test.cc +++ b/media/tools/wav_ola_test/wav_ola_test.cc @@ -71,7 +71,7 @@ int main(int argc, const char** argv) { CommandLine::Init(argc, argv); const CommandLine* cmd_line = CommandLine::ForCurrentProcess(); - 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] << " RATE INFILE OUTFILE\n" << std::endl; @@ -79,12 +79,17 @@ int main(int argc, const char** argv) { } // Retrieve command line options. - FilePath in_path(FilePath::FromWStringHack(filenames[1])); - FilePath out_path(FilePath::FromWStringHack(filenames[2])); + FilePath in_path(filenames[1]); + FilePath out_path(filenames[2]); double playback_rate = 0.0; // Determine speed of rerecord. - if (!StringToDouble(WideToUTF8(filenames[0]), &playback_rate)) +#if defined(OS_WIN) + std::string filename_str = WideToASCII(filenames[0]); +#else + const std::string& filename_str = filenames[0]; +#endif + if (!StringToDouble(filename_str, &playback_rate)) playback_rate = 0.0; // Open input file. |