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;
77 return new VideoStreamInfo(kTrackId, kTimeScale, kDuration, kVideoCodec,
78 kCodecString, kLanguage, kWidth, kHeight,
79 kPixelWidth, kPixelHeight, kTrickPlayRate,
80 kNaluLengthSize, NULL, 0,
false);
84 return output_file_name_;
88 return GetSegmentName(segment_template_, 0, number, 0);
91 SegmentTestBase::ClusterParser::ClusterParser() : in_cluster_(false) {}
93 SegmentTestBase::ClusterParser::~ClusterParser() {}
95 void SegmentTestBase::ClusterParser::PopulateFromCluster(
96 const std::string& file_name) {
97 cluster_sizes_.clear();
98 std::string file_contents;
101 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
102 const size_t size = file_contents.size();
103 WebMListParser cluster_parser(kWebMIdCluster,
this);
105 while (position < size) {
106 int read = cluster_parser.Parse(data + position, size - position);
109 cluster_parser.Reset();
114 void SegmentTestBase::ClusterParser::PopulateFromSegment(
115 const std::string& file_name) {
116 cluster_sizes_.clear();
117 std::string file_contents;
120 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
121 const size_t size = file_contents.size();
122 WebMListParser header_parser(kWebMIdEBMLHeader,
this);
123 int offset = header_parser.Parse(data, size);
124 ASSERT_LT(0, offset);
126 WebMListParser segment_parser(kWebMIdSegment,
this);
127 ASSERT_LT(0, segment_parser.Parse(data + offset, size - offset));
130 int SegmentTestBase::ClusterParser::GetFrameCountForCluster(
size_t i)
const {
131 DCHECK(i < cluster_sizes_.size());
132 return cluster_sizes_[i];
135 int SegmentTestBase::ClusterParser::cluster_count()
const {
136 return cluster_sizes_.size();
139 WebMParserClient* SegmentTestBase::ClusterParser::OnListStart(
int id) {
140 if (
id == kWebMIdCluster) {
144 cluster_sizes_.push_back(0);
151 bool SegmentTestBase::ClusterParser::OnListEnd(
int id) {
152 if (
id == kWebMIdCluster) {
161 bool SegmentTestBase::ClusterParser::OnUInt(
int id, int64_t val) {
165 bool SegmentTestBase::ClusterParser::OnFloat(
int id,
double val) {
169 bool SegmentTestBase::ClusterParser::OnBinary(
int id,
172 if (in_cluster_ &&
id == kWebMIdSimpleBlock) {
173 cluster_sizes_[cluster_sizes_.size() - 1]++;
179 bool SegmentTestBase::ClusterParser::OnString(
int id,
const std::string& str) {