7 #include "packager/media/formats/webvtt/webvtt_timestamp.h"
11 #include "packager/base/logging.h"
12 #include "packager/base/strings/string_number_conversions.h"
18 bool GetTotalMilliseconds(uint64_t hours,
24 if (minutes > 59 || seconds > 59 || ms > 999) {
25 VLOG(1) <<
"Hours:" << hours
26 <<
" Minutes:" << minutes
27 <<
" Seconds:" << seconds
29 <<
" shoud have never made it to GetTotalMilliseconds";
32 *out = 60 * 60 * 1000 * hours +
40 bool WebVttTimestampParse(
const base::StringPiece& source, uint64_t* out) {
43 if (source.length() < 9) {
44 LOG(WARNING) <<
"Timestamp '" << source <<
"' is mal-formed";
48 const size_t minutes_begin = source.length() - 9;
49 const size_t seconds_begin = source.length() - 6;
50 const size_t milliseconds_begin = source.length() - 3;
57 const bool has_hours = minutes_begin >= 3 &&
58 source[minutes_begin-1] ==
':' &&
59 base::StringToUint64(source.substr(0, minutes_begin-1), &hours);
61 if ((minutes_begin == 0 || has_hours) &&
62 source[seconds_begin-1] ==
':' &&
63 source[milliseconds_begin-1] ==
'.' &&
64 base::StringToUint64(source.substr(minutes_begin, 2), &minutes) &&
65 base::StringToUint64(source.substr(seconds_begin, 2), &seconds) &&
66 base::StringToUint64(source.substr(milliseconds_begin, 3), &ms)) {
67 return GetTotalMilliseconds(hours, minutes, seconds, ms, out);
70 LOG(WARNING) <<
"Timestamp '" << source <<
"' is mal-formed";