diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 21:50:13 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-16 21:50:13 +0000 |
commit | e83eedcd41bdebf055f130051d2c84d39f27a466 (patch) | |
tree | 2108eb93717e3629397246e25b98afe3798525c9 /media | |
parent | e62dbbfc6f722159733239d396098e2e0407f56f (diff) | |
download | chromium_src-e83eedcd41bdebf055f130051d2c84d39f27a466.zip chromium_src-e83eedcd41bdebf055f130051d2c84d39f27a466.tar.gz chromium_src-e83eedcd41bdebf055f130051d2c84d39f27a466.tar.bz2 |
file_util: deprecate remaining wstring functions
This removes the last wstring-accepting functions from file_util
on non-Windows platforms.
BUG=24672
Review URL: http://codereview.chromium.org/3005005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52755 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/test/ffmpeg_tests/ffmpeg_tests.cc | 14 | ||||
-rw-r--r-- | media/tools/media_bench/media_bench.cc | 18 | ||||
-rw-r--r-- | media/tools/omx_test/file_reader_util.cc | 38 | ||||
-rw-r--r-- | media/tools/omx_test/file_reader_util.h | 15 | ||||
-rw-r--r-- | media/tools/omx_test/file_sink.cc | 6 | ||||
-rw-r--r-- | media/tools/omx_test/file_sink.h | 7 | ||||
-rw-r--r-- | media/tools/omx_test/omx_test.cc | 17 | ||||
-rw-r--r-- | media/tools/wav_ola_test/wav_ola_test.cc | 10 |
8 files changed, 72 insertions, 53 deletions
diff --git a/media/test/ffmpeg_tests/ffmpeg_tests.cc b/media/test/ffmpeg_tests/ffmpeg_tests.cc index 0b95b00..47dd1b1 100644 --- a/media/test/ffmpeg_tests/ffmpeg_tests.cc +++ b/media/test/ffmpeg_tests/ffmpeg_tests.cc @@ -70,6 +70,9 @@ 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()); if (filenames.empty()) { @@ -86,10 +89,11 @@ int main(int argc, const char** argv) { } // Retrieve command line options. - std::string in_path(WideToUTF8(filenames[0])); - std::string out_path; + std::string in_path(WideToASCII(filenames[0])); + FilePath out_path; if (filenames.size() > 1) { - out_path = WideToUTF8(filenames[1]); + // See TODO above the declaration of filenames. + out_path = FilePath::FromWStringHack(filenames[1]); } // Default flags that match Chrome defaults. @@ -137,10 +141,10 @@ int main(int argc, const char** argv) { // Open output file. FILE *output = NULL; if (!out_path.empty()) { - output = file_util::OpenFile(out_path.c_str(), "wb"); + output = file_util::OpenFile(out_path, "wb"); if (!output) { std::cerr << "Error: Could not open output " - << out_path << std::endl; + << out_path.value() << std::endl; return 1; } } diff --git a/media/tools/media_bench/media_bench.cc b/media/tools/media_bench/media_bench.cc index 926d283..ad6a7c2 100644 --- a/media/tools/media_bench/media_bench.cc +++ b/media/tools/media_bench/media_bench.cc @@ -89,6 +89,9 @@ 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()); if (filenames.empty()) { std::cerr << "Usage: " << argv[0] << " [OPTIONS] FILE [DUMPFILE]\n" @@ -126,10 +129,11 @@ int main(int argc, const char** argv) { } // Retrieve command line options. - std::string in_path(WideToUTF8(filenames[0])); - std::string out_path; + std::string in_path(WideToASCII(filenames[0])); + FilePath out_path; if (filenames.size() > 1) { - out_path = WideToUTF8(filenames[1]); + // See TODO above the declaration of filenames. + out_path = FilePath::FromWStringHack(filenames[1]); } CodecType target_codec = CODEC_TYPE_UNKNOWN; @@ -246,19 +250,19 @@ int main(int argc, const char** argv) { FILE *output = NULL; if (!out_path.empty()) { // TODO(fbarchard): Add pipe:1 for piping to stderr. - if (!strncmp(out_path.c_str(), "pipe:", 5) || - !strcmp(out_path.c_str(), "-")) { + if (out_path.value().substr(0, 5) == FILE_PATH_LITERAL("pipe:") || + out_path.value() == FILE_PATH_LITERAL("-")) { output = stdout; log_out = &std::cerr; #if defined(OS_WIN) _setmode(_fileno(stdout), _O_BINARY); #endif } else { - output = file_util::OpenFile(out_path.c_str(), "wb"); + output = file_util::OpenFile(out_path, "wb"); } if (!output) { std::cerr << "Error: Could not open output " - << out_path << std::endl; + << out_path.value() << std::endl; return 1; } } diff --git a/media/tools/omx_test/file_reader_util.cc b/media/tools/omx_test/file_reader_util.cc index f397bb6..1ba7cea 100644 --- a/media/tools/omx_test/file_reader_util.cc +++ b/media/tools/omx_test/file_reader_util.cc @@ -19,27 +19,27 @@ namespace media { ////////////////////////////////////////////////////////////////////////////// // BasicFileReader -BasicFileReader::BasicFileReader(const std::string& filename) - : filename_(filename), +BasicFileReader::BasicFileReader(const FilePath& path) + : path_(path), file_(NULL) { } bool BasicFileReader::Initialize() { - file_.Set(file_util::OpenFile(filename_, "rb")); + file_.Set(file_util::OpenFile(path_, "rb")); if (!file_.get()) { - LOG(ERROR) << "unable to open " << filename_; + LOG(ERROR) << "unable to open " << path_.value(); } return file_.get() != NULL; } ////////////////////////////////////////////////////////////////////////////// // YuvFileReader -YuvFileReader::YuvFileReader(const std::string& filename, +YuvFileReader::YuvFileReader(const FilePath& path, int width, int height, int loop_count, bool enable_csc) - : BasicFileReader(filename), + : BasicFileReader(path), width_(width), height_(height), loop_count_(loop_count), @@ -96,9 +96,9 @@ void YuvFileReader::Read(uint8** output, int* size) { ////////////////////////////////////////////////////////////////////////////// // BlockFileReader -BlockFileReader::BlockFileReader(const std::string& filename, +BlockFileReader::BlockFileReader(const FilePath& path, int block_size) - : BasicFileReader(filename), + : BasicFileReader(path), block_size_(block_size) { } @@ -110,8 +110,8 @@ void BlockFileReader::Read(uint8** output, int* size) { ////////////////////////////////////////////////////////////////////////////// // FFmpegFileReader -FFmpegFileReader::FFmpegFileReader(const std::string& filename) - : filename_(filename), +FFmpegFileReader::FFmpegFileReader(const FilePath& path) + : path_(path), format_context_(NULL), codec_context_(NULL), target_stream_(-1), @@ -124,17 +124,25 @@ FFmpegFileReader::~FFmpegFileReader() { } bool FFmpegFileReader::Initialize() { - int result = av_open_input_file(&format_context_, filename_.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(path_.value()); +#else + const std::string& string_path = 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: LOG(ERROR) << "Error: File format not supported " - << filename_ << std::endl; + << path_.value() << std::endl; break; default: LOG(ERROR) << "Error: Could not open input for " - << filename_ << std::endl; + << path_.value() << std::endl; break; } return false; @@ -215,8 +223,8 @@ void FFmpegFileReader::Read(uint8** output, int* size) { // H264FileReader const int kH264ReadSize = 1024 * 1024; -H264FileReader::H264FileReader(const std::string& filename) - : BasicFileReader(filename), +H264FileReader::H264FileReader(const FilePath& path) + : BasicFileReader(path), read_buf_(new uint8[kH264ReadSize]), current_(0), used_(0) { diff --git a/media/tools/omx_test/file_reader_util.h b/media/tools/omx_test/file_reader_util.h index bed5dcb..4bd028f 100644 --- a/media/tools/omx_test/file_reader_util.h +++ b/media/tools/omx_test/file_reader_util.h @@ -8,6 +8,7 @@ #include <string> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/scoped_handle.h" #include "base/scoped_ptr.h" @@ -33,7 +34,7 @@ class FileReader { class BasicFileReader : public FileReader { public: - explicit BasicFileReader(const std::string& filename); + explicit BasicFileReader(const FilePath& path); virtual bool Initialize(); virtual void Read(uint8** output, int* size) = 0; @@ -41,7 +42,7 @@ class BasicFileReader : public FileReader { FILE* file() const { return file_.get(); } private: - std::string filename_; + FilePath path_; ScopedStdioHandle file_; DISALLOW_COPY_AND_ASSIGN(BasicFileReader); @@ -55,7 +56,7 @@ class YuvFileReader : public BasicFileReader { // NV21. // TODO(jiesun): Make color space more generic not a hard coded color // space conversion. - YuvFileReader(const std::string& filename, + YuvFileReader(const FilePath& path, int width, int height, int loop_count, @@ -74,7 +75,7 @@ class YuvFileReader : public BasicFileReader { class BlockFileReader : public BasicFileReader { public: - BlockFileReader(const std::string& filename, + BlockFileReader(const FilePath& path, int block_size); virtual void Read(uint8** output, int* size); @@ -86,13 +87,13 @@ class BlockFileReader : public BasicFileReader { class FFmpegFileReader : public FileReader { public: - explicit FFmpegFileReader(const std::string& filename); + explicit FFmpegFileReader(const FilePath& path); virtual ~FFmpegFileReader(); virtual bool Initialize(); virtual void Read(uint8** output, int* size); private: - std::string filename_; + FilePath path_; AVFormatContext* format_context_; AVCodecContext* codec_context_; int target_stream_; @@ -103,7 +104,7 @@ class FFmpegFileReader : public FileReader { class H264FileReader : public BasicFileReader { public: - explicit H264FileReader(const std::string& filename); + explicit H264FileReader(const FilePath& path); virtual void Read(uint8** output, int* size); private: diff --git a/media/tools/omx_test/file_sink.cc b/media/tools/omx_test/file_sink.cc index 2191980..98766ab 100644 --- a/media/tools/omx_test/file_sink.cc +++ b/media/tools/omx_test/file_sink.cc @@ -38,10 +38,10 @@ void FileSink::BufferReady(int size, uint8* buffer) { bool FileSink::Initialize() { // Opens the output file for writing. - if (!output_filename_.empty()) { - output_file_.Set(file_util::OpenFile(output_filename_, "wb")); + if (!output_path_.empty()) { + output_file_.Set(file_util::OpenFile(output_path_, "wb")); if (!output_file_.get()) { - LOG(ERROR) << "can't open dump file %s" << output_filename_; + LOG(ERROR) << "can't open dump file %s" << output_path_.value(); return false; } } diff --git a/media/tools/omx_test/file_sink.h b/media/tools/omx_test/file_sink.h index a20bca1..fb7b732 100644 --- a/media/tools/omx_test/file_sink.h +++ b/media/tools/omx_test/file_sink.h @@ -9,6 +9,7 @@ #include <string> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/scoped_handle.h" #include "base/scoped_ptr.h" @@ -18,10 +19,10 @@ namespace media { // a file. class FileSink { public: - FileSink(std::string output_filename, + FileSink(const FilePath& output_path, bool simulate_copy, bool enable_csc) - : output_filename_(output_filename), + : output_path_(output_path), simulate_copy_(simulate_copy), enable_csc_(enable_csc), width_(0), @@ -42,7 +43,7 @@ class FileSink { void Write(uint8* buffer, int size); private: - std::string output_filename_; + FilePath output_path_; bool simulate_copy_; bool enable_csc_; ScopedStdioHandle output_file_; diff --git a/media/tools/omx_test/omx_test.cc b/media/tools/omx_test/omx_test.cc index 9a185e6..5203eb0 100644 --- a/media/tools/omx_test/omx_test.cc +++ b/media/tools/omx_test/omx_test.cc @@ -317,9 +317,10 @@ int main(int argc, char** argv) { return -1; } + const CommandLine& cmd_line = *CommandLine::ForCurrentProcess(); // Read a bunch of parameters. - std::string input_filename = GetStringSwitch("input-file"); - std::string output_filename = GetStringSwitch("output-file"); + FilePath input_path = cmd_line.GetSwitchValuePath("input-file"); + FilePath output_path = cmd_line.GetSwitchValuePath("output-file"); bool encoder = HasSwitch("encoder"); bool copy = HasSwitch("copy"); bool enable_csc = HasSwitch("enable-csc"); @@ -360,21 +361,21 @@ int main(int argc, char** argv) { FileReader* file_reader; if (encoder) { file_reader = new YuvFileReader( - input_filename.c_str(), av_stream->codec->width, + input_path, av_stream->codec->width, av_stream->codec->height, loop_count, enable_csc); } else if (use_ffmpeg) { // Use ffmepg for reading. - file_reader = new FFmpegFileReader(input_filename.c_str()); - } else if (EndsWith(input_filename, ".264", false)) { - file_reader = new H264FileReader(input_filename.c_str()); + file_reader = new FFmpegFileReader(input_path); + } else if (input_path.Extension() == FILE_PATH_LITERAL(".264")) { + file_reader = new H264FileReader(input_path); } else { // Creates a reader that reads in blocks of 32KB. const int kReadSize = 32768; - file_reader = new BlockFileReader(input_filename.c_str(), kReadSize); + file_reader = new BlockFileReader(input_path, kReadSize); } // Create a file sink. - FileSink* file_sink = new FileSink(output_filename, copy, enable_csc); + FileSink* file_sink = new FileSink(output_path, copy, enable_csc); // Create a test app object and initialize it. scoped_refptr<TestApp> test = new TestApp(av_stream, file_sink, file_reader); diff --git a/media/tools/wav_ola_test/wav_ola_test.cc b/media/tools/wav_ola_test/wav_ola_test.cc index 1737b36..0aec9fd 100644 --- a/media/tools/wav_ola_test/wav_ola_test.cc +++ b/media/tools/wav_ola_test/wav_ola_test.cc @@ -79,8 +79,8 @@ int main(int argc, const char** argv) { } // Retrieve command line options. - std::string in_path(WideToUTF8(filenames[1])); - std::string out_path(WideToUTF8(filenames[2])); + FilePath in_path(FilePath::FromWStringHack(filenames[1])); + FilePath out_path(FilePath::FromWStringHack(filenames[2])); double playback_rate = 0.0; // Determine speed of rerecord. @@ -88,14 +88,14 @@ int main(int argc, const char** argv) { playback_rate = 0.0; // Open input file. - ScopedFILE input(file_util::OpenFile(in_path.c_str(), "rb")); + ScopedFILE input(file_util::OpenFile(in_path, "rb")); if (!(input.get())) { LOG(ERROR) << "could not open input"; return 1; } // Open output file. - ScopedFILE output(file_util::OpenFile(out_path.c_str(), "wb")); + ScopedFILE output(file_util::OpenFile(out_path, "wb")); if (!(output.get())) { LOG(ERROR) << "could not open output"; return 1; @@ -125,7 +125,7 @@ int main(int argc, const char** argv) { ola.FlushBuffers(); // Print out input format. - std::cout << in_path << "\n" + std::cout << in_path.value() << "\n" << "Channels: " << wav.channels << "\n" << "Sample Rate: " << wav.sample_rate << "\n" << "Bit Rate: " << wav.bit_rate << "\n" |