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>
19static const int kWebMDefaultTimecodeScale = 1000000;
21WebMInfoParser::WebMInfoParser() : timecode_scale_(-1), duration_(-1) {}
23WebMInfoParser::~WebMInfoParser() {}
25int WebMInfoParser::Parse(
const uint8_t* buf,
int size) {
30 int result = parser.
Parse(buf, size);
43bool WebMInfoParser::OnListEnd(
int id) {
44 if (
id == kWebMIdInfo && timecode_scale_ == -1) {
47 timecode_scale_ = kWebMDefaultTimecodeScale;
52bool WebMInfoParser::OnUInt(
int id, int64_t val) {
53 if (
id != kWebMIdTimecodeScale)
56 if (timecode_scale_ != -1) {
57 DVLOG(1) <<
"Multiple values for id " << std::hex <<
id <<
" specified";
61 timecode_scale_ = val;
65bool WebMInfoParser::OnFloat(
int id,
double val) {
66 if (
id != kWebMIdDuration) {
67 DVLOG(1) <<
"Unexpected float for id" << std::hex << id;
71 if (duration_ != -1) {
72 DVLOG(1) <<
"Multiple values for duration.";
80bool WebMInfoParser::OnBinary(
int id,
const uint8_t* data,
int size) {
81 if (
id == kWebMIdDateUTC) {
85 int64_t date_in_nanoseconds = 0;
86 for (
int i = 0; i < size; ++i)
87 date_in_nanoseconds = (date_in_nanoseconds << 8) | data[i];
89 std::tm exploded_epoch;
90 exploded_epoch.tm_year = 2001;
91 exploded_epoch.tm_mon = 1;
92 exploded_epoch.tm_mday = 1;
93 exploded_epoch.tm_hour = 0;
94 exploded_epoch.tm_min = 0;
95 exploded_epoch.tm_sec = 0;
98 std::chrono::system_clock::from_time_t(std::mktime(&exploded_epoch)) +
99 std::chrono::microseconds(date_in_nanoseconds / 1000);
104bool WebMInfoParser::OnString(
int ,
const std::string& ) {
All the methods that are virtual are virtual for mocking.