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,
125 static_cast<int>(size - position));
128 cluster_parser.Reset();
133 void SegmentTestBase::ClusterParser::PopulateFromSegment(
134 const std::string& file_name) {
135 cluster_sizes_.clear();
136 std::string file_contents;
139 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(file_contents.c_str());
140 const size_t size = file_contents.size();
141 WebMListParser header_parser(kWebMIdEBMLHeader,
this);
142 int offset = header_parser.Parse(data, static_cast<int>(size));
143 ASSERT_LT(0, offset);
145 WebMListParser segment_parser(kWebMIdSegment,
this);
147 0, segment_parser.Parse(data + offset, static_cast<int>(size) - offset));
150 int SegmentTestBase::ClusterParser::GetFrameCountForCluster(
size_t i)
const {
151 DCHECK(i < cluster_sizes_.size());
152 return cluster_sizes_[i];
155 size_t SegmentTestBase::ClusterParser::cluster_count()
const {
156 return cluster_sizes_.size();
159 WebMParserClient* SegmentTestBase::ClusterParser::OnListStart(
int id) {
160 if (
id == kWebMIdCluster) {
164 cluster_sizes_.push_back(0);
171 bool SegmentTestBase::ClusterParser::OnListEnd(
int id) {
172 if (
id == kWebMIdCluster) {
181 bool SegmentTestBase::ClusterParser::OnUInt(
int id, int64_t val) {
185 bool SegmentTestBase::ClusterParser::OnFloat(
int id,
double val) {
189 bool SegmentTestBase::ClusterParser::OnBinary(
int id,
192 if (in_cluster_ && (
id == kWebMIdSimpleBlock ||
id == kWebMIdBlock)) {
193 cluster_sizes_.back()++;
199 bool SegmentTestBase::ClusterParser::OnString(
int id,
const std::string& str) {