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"
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 uint32_t kTimeScale = 1000;
26 const uint64_t kDuration = 8000;
27 const VideoCodec kVideoCodec = kCodecVP8;
28 const std::string kCodecString =
"vp8";
29 const std::string kLanguage =
"en";
30 const uint16_t kWidth = 100;
31 const uint16_t kHeight = 100;
32 const uint16_t kPixelWidth = 100;
33 const uint16_t kPixelHeight = 100;
34 const int16_t kTrickPlayRate = 1;
35 const uint8_t kNaluLengthSize = 0;
39 SegmentTestBase::SegmentTestBase() {}
41 void SegmentTestBase::SetUp() {
42 output_file_name_ = std::string(kMemoryFilePrefix) +
"output-file.webm";
44 std::string(kMemoryFilePrefix) +
"output-template-$Number$.webm";
45 cur_time_timescale_ = 0;
46 single_segment_ =
true;
49 void SegmentTestBase::TearDown() {
54 KeyFrameFlag key_frame_flag,
56 SideDataFlag side_data_flag) {
57 scoped_refptr<MediaSample> sample;
58 const bool is_key_frame = key_frame_flag == kKeyFrame;
59 if (side_data_flag == kGenerateSideData) {
61 kTestMediaSampleData,
sizeof(kTestMediaSampleData),
62 kTestMediaSampleSideData,
sizeof(kTestMediaSampleSideData),
66 sizeof(kTestMediaSampleData), is_key_frame);
68 sample->set_dts(cur_time_timescale_);
69 sample->set_pts(cur_time_timescale_);
70 sample->set_duration(duration);
72 cur_time_timescale_ += duration;
88 ret.
temp_dir = std::string(kMemoryFilePrefix) +
"temp/";
93 return new VideoStreamInfo(kTrackId, kTimeScale, kDuration, kVideoCodec,
94 kCodecString, kLanguage, kWidth, kHeight,
95 kPixelWidth, kPixelHeight, kTrickPlayRate,
96 kNaluLengthSize, NULL, 0,
false);
100 return output_file_name_;
104 return GetSegmentName(segment_template_, 0, number, 0);
107 SegmentTestBase::ClusterParser::ClusterParser() : in_cluster_(false) {}
109 SegmentTestBase::ClusterParser::~ClusterParser() {}
111 void SegmentTestBase::ClusterParser::PopulateFromCluster(
112 const std::string& file_name) {
113 cluster_sizes_.clear();
114 std::string file_contents;
117 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
118 const size_t size = file_contents.size();
119 WebMListParser cluster_parser(kWebMIdCluster,
this);
121 while (position < size) {
122 int read = cluster_parser.Parse(data + position, size - position);
125 cluster_parser.Reset();
130 void SegmentTestBase::ClusterParser::PopulateFromSegment(
131 const std::string& file_name) {
132 cluster_sizes_.clear();
133 std::string file_contents;
136 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
137 const size_t size = file_contents.size();
138 WebMListParser header_parser(kWebMIdEBMLHeader,
this);
139 int offset = header_parser.Parse(data, size);
140 ASSERT_LT(0, offset);
142 WebMListParser segment_parser(kWebMIdSegment,
this);
143 ASSERT_LT(0, segment_parser.Parse(data + offset, size - offset));
146 int SegmentTestBase::ClusterParser::GetFrameCountForCluster(
size_t i)
const {
147 DCHECK(i < cluster_sizes_.size());
148 return cluster_sizes_[i];
151 int SegmentTestBase::ClusterParser::cluster_count()
const {
152 return cluster_sizes_.size();
155 WebMParserClient* SegmentTestBase::ClusterParser::OnListStart(
int id) {
156 if (
id == kWebMIdCluster) {
160 cluster_sizes_.push_back(0);
167 bool SegmentTestBase::ClusterParser::OnListEnd(
int id) {
168 if (
id == kWebMIdCluster) {
177 bool SegmentTestBase::ClusterParser::OnUInt(
int id, int64_t val) {
181 bool SegmentTestBase::ClusterParser::OnFloat(
int id,
double val) {
185 bool SegmentTestBase::ClusterParser::OnBinary(
int id,
188 if (in_cluster_ && (
id == kWebMIdSimpleBlock ||
id == kWebMIdBlock)) {
189 cluster_sizes_.back()++;
195 bool SegmentTestBase::ClusterParser::OnString(
int id,
const std::string& str) {