7 #include "packager/media/formats/webm/segmenter_test_base.h" 9 #include "packager/file/memory_file.h" 10 #include "packager/media/formats/webm/webm_constants.h" 11 #include "packager/version/version.h" 18 const uint8_t kTestMediaSampleData[] = {0xde, 0xad, 0xbe, 0xef, 0x00};
19 const uint8_t kTestMediaSampleSideData[] = {
21 0x12, 0x34, 0x56, 0x78, 0x9a, 0x00, 0x00, 0x00,
22 0x73, 0x69, 0x64, 0x65, 0x00};
24 const int kTrackId = 1;
25 const uint64_t kDurationInSeconds = 8;
26 const Codec kCodec = kCodecVP8;
27 const std::string kCodecString =
"vp8";
28 const std::string kLanguage =
"en";
29 const uint16_t kWidth = 100;
30 const uint16_t kHeight = 100;
31 const uint16_t kPixelWidth = 100;
32 const uint16_t kPixelHeight = 100;
33 const int16_t kTrickPlayFactor = 1;
34 const uint8_t kNaluLengthSize = 0;
38 SegmentTestBase::SegmentTestBase() {}
40 void SegmentTestBase::SetUp() {
41 SetPackagerVersionForTesting(
"test");
43 output_file_name_ = std::string(kMemoryFilePrefix) +
"output-file.webm";
47 void SegmentTestBase::TearDown() {
52 KeyFrameFlag key_frame_flag,
54 SideDataFlag side_data_flag) {
55 std::shared_ptr<MediaSample> sample;
56 const bool is_key_frame = key_frame_flag == kKeyFrame;
57 if (side_data_flag == kGenerateSideData) {
59 kTestMediaSampleData,
sizeof(kTestMediaSampleData),
60 kTestMediaSampleSideData,
sizeof(kTestMediaSampleSideData),
64 sizeof(kTestMediaSampleData), is_key_frame);
66 sample->set_dts(cur_timestamp_);
67 sample->set_pts(cur_timestamp_);
68 sample->set_duration(duration);
70 cur_timestamp_ += duration;
79 ret.
temp_dir = std::string(kMemoryFilePrefix) +
"temp/";
84 uint32_t time_scale)
const {
86 kTrackId, time_scale, kDurationInSeconds * time_scale, kCodec,
87 H26xStreamFormat::kUnSpecified, kCodecString, NULL, 0, kWidth, kHeight,
88 kPixelWidth, kPixelHeight, kTrickPlayFactor, kNaluLengthSize, kLanguage,
93 return output_file_name_;
96 SegmentTestBase::ClusterParser::ClusterParser() {}
98 SegmentTestBase::ClusterParser::~ClusterParser() {}
100 void SegmentTestBase::ClusterParser::PopulateFromCluster(
101 const std::string& file_name) {
102 frame_timecodes_.clear();
103 std::string file_contents;
106 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
107 const size_t size = file_contents.size();
110 while (position < size) {
111 int read = cluster_parser.
Parse(data + position,
112 static_cast<int>(size - position));
115 cluster_parser.
Reset();
120 void SegmentTestBase::ClusterParser::PopulateFromSegment(
121 const std::string& file_name) {
122 frame_timecodes_.clear();
123 std::string file_contents;
126 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
127 const size_t size = file_contents.size();
129 int offset = header_parser.
Parse(data, static_cast<int>(size));
130 ASSERT_LT(0, offset);
134 0, segment_parser.
Parse(data + offset, static_cast<int>(size) - offset));
137 size_t SegmentTestBase::ClusterParser::GetFrameCountForCluster(
138 size_t cluster_index)
const {
139 DCHECK_LT(cluster_index, frame_timecodes_.size());
140 return frame_timecodes_[cluster_index].size();
143 int64_t SegmentTestBase::ClusterParser::GetFrameTimecode(
144 size_t cluster_index,
145 size_t frame_index)
const {
146 DCHECK_LT(cluster_index, frame_timecodes_.size());
147 DCHECK_LT(frame_index, frame_timecodes_[cluster_index].size());
148 return frame_timecodes_[cluster_index][frame_index];
151 size_t SegmentTestBase::ClusterParser::cluster_count()
const {
152 return frame_timecodes_.size();
156 if (
id == kWebMIdCluster) {
160 frame_timecodes_.emplace_back();
161 cluster_timecode_ = -1;
168 bool SegmentTestBase::ClusterParser::OnListEnd(
int id) {
169 if (
id == kWebMIdCluster) {
178 bool SegmentTestBase::ClusterParser::OnUInt(
int id, int64_t val) {
179 if (
id == kWebMIdTimecode)
180 cluster_timecode_ = val;
184 bool SegmentTestBase::ClusterParser::OnFloat(
int id,
double val) {
188 bool SegmentTestBase::ClusterParser::OnBinary(
int id,
191 if (in_cluster_ && (
id == kWebMIdSimpleBlock ||
id == kWebMIdBlock)) {
192 if (cluster_timecode_ == -1) {
193 LOG(WARNING) <<
"Cluster timecode not yet available";
196 int timecode = data[1] << 8 | data[2];
197 frame_timecodes_.back().push_back(cluster_timecode_ + timecode);
203 bool SegmentTestBase::ClusterParser::OnString(
int id,
const std::string& str) {
static bool ReadFileToString(const char *file_name, std::string *contents)
All the methods that are virtual are virtual for mocking.