diff --git a/common/libwebm_util.cc b/common/libwebm_util.cc index 82b1934..7520bb7 100644 --- a/common/libwebm_util.cc +++ b/common/libwebm_util.cc @@ -83,4 +83,10 @@ bool WriteUint8(std::uint8_t val, std::FILE* fileptr) { return (std::fputc(val, fileptr) == val); } +std::uint16_t ReadUint16(const std::uint8_t* buf) { + if (buf == nullptr) + return 0; + return ((buf[0] << 8) | buf[1]); +} + } // namespace libwebm diff --git a/common/libwebm_util.h b/common/libwebm_util.h index 14df585..233c482 100644 --- a/common/libwebm_util.h +++ b/common/libwebm_util.h @@ -54,6 +54,10 @@ bool ParseVP9SuperFrameIndex(const std::uint8_t* frame, // Writes |val| to |fileptr| and returns true upon success. bool WriteUint8(std::uint8_t val, std::FILE* fileptr); +// Reads 2 bytes from |buf| and returns them as a uint16_t. Returns 0 when |buf| +// is a nullptr. +std::uint16_t ReadUint16(const std::uint8_t* buf); + } // namespace libwebm #endif // LIBWEBM_COMMON_LIBWEBM_UTIL_H_ diff --git a/m2ts/vpxpes_parser.cc b/m2ts/vpxpes_parser.cc index cbc0ee7..d4d2fbd 100644 --- a/m2ts/vpxpes_parser.cc +++ b/m2ts/vpxpes_parser.cc @@ -189,6 +189,9 @@ bool VpxPesParser::ParsePesOptionalHeader(PesOptionalHeader* header) { return false; } + header->pts = (pes_file_data_[offset] & 0xe) << 29 | + ((ReadUint16(&pes_file_data_[offset + 1]) & ~1) << 14) | + (ReadUint16(&pes_file_data_[offset + 3]) >> 1); offset += 5; bytes_left -= 5; }