5 #include "packager/media/formats/webm/webm_info_parser.h"
7 #include "packager/base/logging.h"
8 #include "packager/media/formats/webm/webm_constants.h"
15 static const int kWebMDefaultTimecodeScale = 1000000;
17 WebMInfoParser::WebMInfoParser()
18 : timecode_scale_(-1),
22 WebMInfoParser::~WebMInfoParser() {}
29 int result = parser.
Parse(buf, size);
40 bool WebMInfoParser::OnListEnd(
int id) {
41 if (
id == kWebMIdInfo && timecode_scale_ == -1) {
44 timecode_scale_ = kWebMDefaultTimecodeScale;
49 bool WebMInfoParser::OnUInt(
int id, int64_t val) {
50 if (
id != kWebMIdTimecodeScale)
53 if (timecode_scale_ != -1) {
54 DVLOG(1) <<
"Multiple values for id " << std::hex <<
id <<
" specified";
58 timecode_scale_ = val;
62 bool WebMInfoParser::OnFloat(
int id,
double val) {
63 if (
id != kWebMIdDuration) {
64 DVLOG(1) <<
"Unexpected float for id" << std::hex << id;
68 if (duration_ != -1) {
69 DVLOG(1) <<
"Multiple values for duration.";
77 bool WebMInfoParser::OnBinary(
int id,
const uint8_t* data,
int size) {
78 if (
id == kWebMIdDateUTC) {
82 int64_t date_in_nanoseconds = 0;
83 for (
int i = 0; i < size; ++i)
84 date_in_nanoseconds = (date_in_nanoseconds << 8) | data[i];
86 base::Time::Exploded exploded_epoch;
87 exploded_epoch.year = 2001;
88 exploded_epoch.month = 1;
89 exploded_epoch.day_of_month = 1;
90 exploded_epoch.hour = 0;
91 exploded_epoch.minute = 0;
92 exploded_epoch.second = 0;
93 exploded_epoch.millisecond = 0;
94 date_utc_ = base::Time::FromUTCExploded(exploded_epoch) +
95 base::TimeDelta::FromMicroseconds(date_in_nanoseconds / 1000);
100 bool WebMInfoParser::OnString(
int id,
const std::string& str) {