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
3 // found in the LICENSE file.
5 #include "media/base/test_data_util.h"
7 #include "base/file_util.h"
8 #include "base/logging.h"
9 #include "base/path_service.h"
10 #include "media/base/buffers.h"
11 #include "media/base/data_buffer.h"
12 #include "media/ffmpeg/ffmpeg_common.h"
16 std::string
GetTestDataURL(const std::string
& name
) {
18 CHECK(PathService::Get(base::DIR_SOURCE_ROOT
, &file_path
));
20 file_path
= file_path
.Append(FILE_PATH_LITERAL("media"))
21 .Append(FILE_PATH_LITERAL("test"))
22 .Append(FILE_PATH_LITERAL("data"))
24 return file_path
.MaybeAsASCII();
27 void ReadTestDataFile(const std::string
& name
, scoped_array
<uint8
>* buffer
,
30 CHECK(PathService::Get(base::DIR_SOURCE_ROOT
, &file_path
));
32 file_path
= file_path
.Append(FILE_PATH_LITERAL("media"))
33 .Append(FILE_PATH_LITERAL("test"))
34 .Append(FILE_PATH_LITERAL("data"))
38 CHECK(file_util::GetFileSize(file_path
, &tmp
))
39 << "Failed to get file size for '" << name
<< "'";
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
);
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
);
49 CHECK(file_size
== file_util::ReadFile(file_path
,
50 reinterpret_cast<char*>(buffer
->get()),
52 << "Failed to read '" << name
<< "'";
56 void ReadTestDataFile(const std::string
& name
,
57 scoped_refptr
<DataBuffer
>* buffer
) {
58 scoped_array
<uint8
> buf
;
60 ReadTestDataFile(name
, &buf
, &buf_size
);
61 *buffer
= new DataBuffer(buf
.Pass(), buf_size
);
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
;