| OLD | NEW |
| 1 // Copyright (c) 2012 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 #include "media/base/test_data_util.h" | 5 #include "media/base/test_data_util.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "media/base/buffers.h" | 10 #include "media/base/decoder_buffer.h" |
| 11 #include "media/base/data_buffer.h" | |
| 12 #include "media/ffmpeg/ffmpeg_common.h" | |
| 13 | 11 |
| 14 namespace media { | 12 namespace media { |
| 15 | 13 |
| 16 std::string GetTestDataURL(const std::string& name) { | 14 std::string GetTestDataURL(const std::string& name) { |
| 17 FilePath file_path; | 15 FilePath file_path; |
| 18 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); | 16 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); |
| 19 | 17 |
| 20 file_path = file_path.Append(FILE_PATH_LITERAL("media")) | 18 file_path = file_path.Append(FILE_PATH_LITERAL("media")) |
| 21 .Append(FILE_PATH_LITERAL("test")) | 19 .Append(FILE_PATH_LITERAL("test")) |
| 22 .Append(FILE_PATH_LITERAL("data")) | 20 .Append(FILE_PATH_LITERAL("data")) |
| 23 .AppendASCII(name); | 21 .AppendASCII(name); |
| 24 return file_path.MaybeAsASCII(); | 22 return file_path.MaybeAsASCII(); |
| 25 } | 23 } |
| 26 | 24 |
| 27 void ReadTestDataFile(const std::string& name, scoped_array<uint8>* buffer, | 25 scoped_refptr<DecoderBuffer> ReadTestDataFile(const std::string& name) { |
| 28 int* size) { | |
| 29 FilePath file_path; | 26 FilePath file_path; |
| 30 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); | 27 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &file_path)); |
| 31 | 28 |
| 32 file_path = file_path.Append(FILE_PATH_LITERAL("media")) | 29 file_path = file_path.Append(FILE_PATH_LITERAL("media")) |
| 33 .Append(FILE_PATH_LITERAL("test")) | 30 .Append(FILE_PATH_LITERAL("test")) |
| 34 .Append(FILE_PATH_LITERAL("data")) | 31 .Append(FILE_PATH_LITERAL("data")) |
| 35 .AppendASCII(name); | 32 .AppendASCII(name); |
| 36 | 33 |
| 37 int64 tmp = 0; | 34 int64 tmp = 0; |
| 38 CHECK(file_util::GetFileSize(file_path, &tmp)) | 35 CHECK(file_util::GetFileSize(file_path, &tmp)) |
| 39 << "Failed to get file size for '" << name << "'"; | 36 << "Failed to get file size for '" << name << "'"; |
| 40 | 37 |
| 41 // Why FF_INPUT_BUFFER_PADDING_SIZE? FFmpeg assumes all input buffers are | |
| 42 // padded. Since most of our test data is passed to FFmpeg, it makes sense | |
| 43 // to do the padding here instead of scattering it around test code. | |
| 44 int file_size = static_cast<int>(tmp); | 38 int file_size = static_cast<int>(tmp); |
| 45 int padded_size = file_size + FF_INPUT_BUFFER_PADDING_SIZE; | |
| 46 buffer->reset(reinterpret_cast<uint8_t*>(new uint8[padded_size])); | |
| 47 memset(buffer->get(), 0, padded_size); | |
| 48 | 39 |
| 49 CHECK(file_size == file_util::ReadFile(file_path, | 40 scoped_refptr<DecoderBuffer> buffer(new DecoderBuffer(file_size)); |
| 50 reinterpret_cast<char*>(buffer->get()), | 41 CHECK_EQ(file_size, file_util::ReadFile( |
| 51 file_size)) | 42 file_path, reinterpret_cast<char*>(buffer->GetWritableData()), file_size)) |
| 52 << "Failed to read '" << name << "'"; | 43 << "Failed to read '" << name << "'"; |
| 53 *size = file_size; | |
| 54 } | |
| 55 | 44 |
| 56 void ReadTestDataFile(const std::string& name, | 45 return buffer; |
| 57 scoped_refptr<DataBuffer>* buffer) { | |
| 58 scoped_array<uint8> buf; | |
| 59 int buf_size; | |
| 60 ReadTestDataFile(name, &buf, &buf_size); | |
| 61 *buffer = new DataBuffer(buf.Pass(), buf_size); | |
| 62 } | |
| 63 | |
| 64 void ReadTestDataFile(const std::string& name, | |
| 65 scoped_refptr<Buffer>* buffer) { | |
| 66 scoped_refptr<DataBuffer> data_buffer; | |
| 67 ReadTestDataFile(name, &data_buffer); | |
| 68 *buffer = data_buffer; | |
| 69 } | 46 } |
| 70 | 47 |
| 71 } // namespace media | 48 } // namespace media |
| OLD | NEW |