5 #include <packager/media/formats/webm/webm_info_parser.h>
9 #include <absl/log/log.h>
11 #include <packager/macros/logging.h>
12 #include <packager/media/formats/webm/webm_constants.h>
19 static const int kWebMDefaultTimecodeScale = 1000000;
21 WebMInfoParser::WebMInfoParser()
22 : timecode_scale_(-1),
26 WebMInfoParser::~WebMInfoParser() {}
28 int WebMInfoParser::Parse(
const uint8_t* buf,
int size) {
33 int result = parser.
Parse(buf, size);
46 bool WebMInfoParser::OnListEnd(
int id) {
47 if (
id == kWebMIdInfo && timecode_scale_ == -1) {
50 timecode_scale_ = kWebMDefaultTimecodeScale;
55 bool WebMInfoParser::OnUInt(
int id, int64_t val) {
56 if (
id != kWebMIdTimecodeScale)
59 if (timecode_scale_ != -1) {
60 DVLOG(1) <<
"Multiple values for id " << std::hex <<
id <<
" specified";
64 timecode_scale_ = val;
68 bool WebMInfoParser::OnFloat(
int id,
double val) {
69 if (
id != kWebMIdDuration) {
70 DVLOG(1) <<
"Unexpected float for id" << std::hex << id;
74 if (duration_ != -1) {
75 DVLOG(1) <<
"Multiple values for duration.";
83 bool WebMInfoParser::OnBinary(
int id,
const uint8_t* data,
int size) {
84 if (
id == kWebMIdDateUTC) {
88 int64_t date_in_nanoseconds = 0;
89 for (
int i = 0; i < size; ++i)
90 date_in_nanoseconds = (date_in_nanoseconds << 8) | data[i];
92 std::tm exploded_epoch;
93 exploded_epoch.tm_year = 2001;
94 exploded_epoch.tm_mon = 1;
95 exploded_epoch.tm_mday = 1;
96 exploded_epoch.tm_hour = 0;
97 exploded_epoch.tm_min = 0;
98 exploded_epoch.tm_sec = 0;
101 std::chrono::system_clock::from_time_t(std::mktime(&exploded_epoch)) +
102 std::chrono::microseconds(date_in_nanoseconds / 1000);
107 bool WebMInfoParser::OnString(
int ,
const std::string& ) {
All the methods that are virtual are virtual for mocking.