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"
12 #include "packager/version/version.h"
19 const uint8_t kTestMediaSampleData[] = {0xde, 0xad, 0xbe, 0xef, 0x00};
20 const uint8_t kTestMediaSampleSideData[] = {
22 0x12, 0x34, 0x56, 0x78, 0x9a, 0x00, 0x00, 0x00,
23 0x73, 0x69, 0x64, 0x65, 0x00};
25 const int kTrackId = 1;
26 const uint32_t kTimeScale = 1000;
27 const uint64_t kDuration = 8000;
28 const Codec kCodec = kCodecVP8;
29 const std::string kCodecString =
"vp8";
30 const std::string kLanguage =
"en";
31 const uint16_t kWidth = 100;
32 const uint16_t kHeight = 100;
33 const uint16_t kPixelWidth = 100;
34 const uint16_t kPixelHeight = 100;
35 const int16_t kTrickPlayRate = 1;
36 const uint8_t kNaluLengthSize = 0;
40 SegmentTestBase::SegmentTestBase() {}
42 void SegmentTestBase::SetUp() {
43 SetPackagerVersionForTesting(
"test");
45 output_file_name_ = std::string(kMemoryFilePrefix) +
"output-file.webm";
47 std::string(kMemoryFilePrefix) +
"output-template-$Number$.webm";
48 cur_time_timescale_ = 0;
49 single_segment_ =
true;
52 void SegmentTestBase::TearDown() {
57 KeyFrameFlag key_frame_flag,
59 SideDataFlag side_data_flag) {
60 scoped_refptr<MediaSample> sample;
61 const bool is_key_frame = key_frame_flag == kKeyFrame;
62 if (side_data_flag == kGenerateSideData) {
64 kTestMediaSampleData,
sizeof(kTestMediaSampleData),
65 kTestMediaSampleSideData,
sizeof(kTestMediaSampleSideData),
69 sizeof(kTestMediaSampleData), is_key_frame);
71 sample->set_dts(cur_time_timescale_);
72 sample->set_pts(cur_time_timescale_);
73 sample->set_duration(duration);
75 cur_time_timescale_ += duration;
90 ret.
temp_dir = std::string(kMemoryFilePrefix) +
"temp/";
96 kCodecString, NULL, 0, kWidth, kHeight,
97 kPixelWidth, kPixelHeight, kTrickPlayRate,
98 kNaluLengthSize, kLanguage,
false);
102 return output_file_name_;
106 return GetSegmentName(segment_template_, 0, number, 0);
109 SegmentTestBase::ClusterParser::ClusterParser() : in_cluster_(false) {}
111 SegmentTestBase::ClusterParser::~ClusterParser() {}
113 void SegmentTestBase::ClusterParser::PopulateFromCluster(
114 const std::string& file_name) {
115 cluster_sizes_.clear();
116 std::string file_contents;
119 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
120 const size_t size = file_contents.size();
121 WebMListParser cluster_parser(kWebMIdCluster,
this);
123 while (position < size) {
124 int read = cluster_parser.Parse(data + position, size - position);
127 cluster_parser.Reset();
132 void SegmentTestBase::ClusterParser::PopulateFromSegment(
133 const std::string& file_name) {
134 cluster_sizes_.clear();
135 std::string file_contents;
138 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
139 const size_t size = file_contents.size();
140 WebMListParser header_parser(kWebMIdEBMLHeader,
this);
141 int offset = header_parser.Parse(data, size);
142 ASSERT_LT(0, offset);
144 WebMListParser segment_parser(kWebMIdSegment,
this);
145 ASSERT_LT(0, segment_parser.Parse(data + offset, size - offset));
148 int SegmentTestBase::ClusterParser::GetFrameCountForCluster(
size_t i)
const {
149 DCHECK(i < cluster_sizes_.size());
150 return cluster_sizes_[i];
153 int SegmentTestBase::ClusterParser::cluster_count()
const {
154 return cluster_sizes_.size();
157 WebMParserClient* SegmentTestBase::ClusterParser::OnListStart(
int id) {
158 if (
id == kWebMIdCluster) {
162 cluster_sizes_.push_back(0);
169 bool SegmentTestBase::ClusterParser::OnListEnd(
int id) {
170 if (
id == kWebMIdCluster) {
179 bool SegmentTestBase::ClusterParser::OnUInt(
int id, int64_t val) {
183 bool SegmentTestBase::ClusterParser::OnFloat(
int id,
double val) {
187 bool SegmentTestBase::ClusterParser::OnBinary(
int id,
190 if (in_cluster_ && (
id == kWebMIdSimpleBlock ||
id == kWebMIdBlock)) {
191 cluster_sizes_.back()++;
197 bool SegmentTestBase::ClusterParser::OnString(
int id,
const std::string& str) {