7 #include "packager/media/formats/webm/segmenter_test_base.h"
9 #include "packager/media/base/muxer_util.h"
10 #include "packager/media/file/memory_file.h"
11 #include "packager/media/formats/webm/webm_constants.h"
13 namespace edash_packager {
18 const uint8_t kTestMediaSampleData[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x00};
19 const size_t kTestMediaSampleDataSize =
sizeof(kTestMediaSampleData);
21 const int kTrackId = 1;
22 const uint32_t kTimeScale = 1000;
23 const uint64_t kDuration = 8000;
24 const VideoCodec kVideoCodec = kCodecVP8;
25 const std::string kCodecString =
"vp8";
26 const std::string kLanguage =
"en";
27 const uint16_t kWidth = 100;
28 const uint16_t kHeight = 100;
29 const uint16_t kPixelWidth = 100;
30 const uint16_t kPixelHeight = 100;
31 const int16_t kTrickPlayRate = 1;
32 const uint8_t kNaluLengthSize = 0;
36 SegmentTestBase::SegmentTestBase() {}
38 void SegmentTestBase::SetUp() {
39 output_file_name_ =
"memory://output-file.webm";
40 segment_template_ =
"memory://output-template-$Number$.webm";
41 cur_time_timescale_ = 0;
42 single_segment_ =
true;
45 void SegmentTestBase::TearDown() {
52 kTestMediaSampleData, kTestMediaSampleDataSize, is_key_frame);
53 sample->set_dts(cur_time_timescale_);
54 sample->set_pts(cur_time_timescale_);
55 sample->set_duration(duration);
57 cur_time_timescale_ += duration;
78 return new VideoStreamInfo(kTrackId, kTimeScale, kDuration, kVideoCodec,
79 kCodecString, kLanguage, kWidth, kHeight,
80 kPixelWidth, kPixelHeight, kTrickPlayRate,
81 kNaluLengthSize, NULL, 0,
false);
85 return output_file_name_;
89 return GetSegmentName(segment_template_, 0, number, 0);
92 SegmentTestBase::ClusterParser::ClusterParser() : in_cluster_(false) {}
94 SegmentTestBase::ClusterParser::~ClusterParser() {}
96 void SegmentTestBase::ClusterParser::PopulateFromCluster(
97 const std::string& file_name) {
98 cluster_sizes_.clear();
99 std::string file_contents;
102 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
103 const size_t size = file_contents.size();
104 WebMListParser cluster_parser(kWebMIdCluster,
this);
106 while (position < size) {
107 int read = cluster_parser.Parse(data + position, size - position);
110 cluster_parser.Reset();
115 void SegmentTestBase::ClusterParser::PopulateFromSegment(
116 const std::string& file_name) {
117 cluster_sizes_.clear();
118 std::string file_contents;
121 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
122 const size_t size = file_contents.size();
123 WebMListParser header_parser(kWebMIdEBMLHeader,
this);
124 int offset = header_parser.Parse(data, size);
125 ASSERT_LT(0, offset);
127 WebMListParser segment_parser(kWebMIdSegment,
this);
128 ASSERT_LT(0, segment_parser.Parse(data + offset, size - offset));
131 int SegmentTestBase::ClusterParser::GetFrameCountForCluster(
size_t i)
const {
132 DCHECK(i < cluster_sizes_.size());
133 return cluster_sizes_[i];
136 int SegmentTestBase::ClusterParser::cluster_count()
const {
137 return cluster_sizes_.size();
140 WebMParserClient* SegmentTestBase::ClusterParser::OnListStart(
int id) {
141 if (
id == kWebMIdCluster) {
145 cluster_sizes_.push_back(0);
152 bool SegmentTestBase::ClusterParser::OnListEnd(
int id) {
153 if (
id == kWebMIdCluster) {
162 bool SegmentTestBase::ClusterParser::OnUInt(
int id, int64_t val) {
166 bool SegmentTestBase::ClusterParser::OnFloat(
int id,
double val) {
170 bool SegmentTestBase::ClusterParser::OnBinary(
int id,
173 if (in_cluster_ &&
id == kWebMIdSimpleBlock) {
174 cluster_sizes_[cluster_sizes_.size() - 1]++;
180 bool SegmentTestBase::ClusterParser::OnString(
int id,
const std::string& str) {