5#include <packager/media/formats/webm/webm_info_parser.h>
13#include <absl/log/log.h>
15#include <packager/media/formats/webm/webm_constants.h>
16#include <packager/media/formats/webm/webm_parser.h>
23static const int kWebMDefaultTimecodeScale = 1000000;
25WebMInfoParser::WebMInfoParser() : timecode_scale_(-1), duration_(-1) {}
27WebMInfoParser::~WebMInfoParser() {}
29int WebMInfoParser::Parse(
const uint8_t* buf,
int size) {
34 int result = parser.
Parse(buf, size);
47bool WebMInfoParser::OnListEnd(
int id) {
48 if (
id == kWebMIdInfo && timecode_scale_ == -1) {
51 timecode_scale_ = kWebMDefaultTimecodeScale;
56bool WebMInfoParser::OnUInt(
int id, int64_t val) {
57 if (
id != kWebMIdTimecodeScale)
60 if (timecode_scale_ != -1) {
61 DVLOG(1) <<
"Multiple values for id " << std::hex <<
id <<
" specified";
65 timecode_scale_ = val;
69bool WebMInfoParser::OnFloat(
int id,
double val) {
70 if (
id != kWebMIdDuration) {
71 DVLOG(1) <<
"Unexpected float for id" << std::hex << id;
75 if (duration_ != -1) {
76 DVLOG(1) <<
"Multiple values for duration.";
84bool WebMInfoParser::OnBinary(
int id,
const uint8_t* data,
int size) {
85 if (
id == kWebMIdDateUTC) {
89 int64_t date_in_nanoseconds = 0;
90 for (
int i = 0; i < size; ++i)
91 date_in_nanoseconds = (date_in_nanoseconds << 8) | data[i];
93 std::tm exploded_epoch;
94 exploded_epoch.tm_year = 2001;
95 exploded_epoch.tm_mon = 1;
96 exploded_epoch.tm_mday = 1;
97 exploded_epoch.tm_hour = 0;
98 exploded_epoch.tm_min = 0;
99 exploded_epoch.tm_sec = 0;
102 std::chrono::system_clock::from_time_t(std::mktime(&exploded_epoch)) +
103 std::chrono::microseconds(date_in_nanoseconds / 1000);
108bool WebMInfoParser::OnString(
int ,
const std::string& ) {
All the methods that are virtual are virtual for mocking.