OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/base/test_data_util.h" |
| 6 |
| 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" |
| 9 |
| 10 namespace media { |
| 11 |
| 12 bool ReadTestDataFile(const std::string& name, scoped_array<uint8>* buffer, |
| 13 int* size) { |
| 14 FilePath file_path; |
| 15 if (!PathService::Get(base::DIR_SOURCE_ROOT, &file_path)) |
| 16 return false; |
| 17 |
| 18 file_path = file_path.Append(FILE_PATH_LITERAL("media")) |
| 19 .Append(FILE_PATH_LITERAL("test")) |
| 20 .Append(FILE_PATH_LITERAL("data")) |
| 21 .AppendASCII(name); |
| 22 |
| 23 int64 tmp = 0; |
| 24 if (!file_util::GetFileSize(file_path, &tmp)) |
| 25 return false; |
| 26 |
| 27 int file_size = static_cast<int>(tmp); |
| 28 buffer->reset(new uint8[file_size]); |
| 29 |
| 30 if (file_size != file_util::ReadFile(file_path, |
| 31 reinterpret_cast<char*>(buffer->get()), |
| 32 file_size)) { |
| 33 buffer->reset(); |
| 34 return false; |
| 35 } |
| 36 |
| 37 *size = file_size; |
| 38 return true; |
| 39 } |
| 40 |
| 41 bool ReadTestDataFile(const std::string& name, scoped_refptr<Buffer>* buffer) { |
| 42 scoped_array<uint8> buf; |
| 43 int buf_size; |
| 44 if (!ReadTestDataFile(name, &buf, &buf_size)) |
| 45 return false; |
| 46 *buffer = new DataBuffer(buf.release(), buf_size); |
| 47 return true; |
| 48 } |
| 49 |
| 50 } // namespace media |
OLD | NEW |