diff options
author | James Zern <jzern@google.com> | 2023-07-07 11:34:00 -0700 |
---|---|---|
committer | James Zern <jzern@google.com> | 2023-07-07 18:35:11 -0700 |
commit | d411c8668dc226d9a3c7433c560dedfcc46fc69c (patch) | |
tree | 31183bb7a26d5cc316d6ebb37a9068b69fca8c98 | |
parent | 21f329f09baf689d48c608d51b4e0e7eedbed998 (diff) | |
download | libwebm-d411c8668dc226d9a3c7433c560dedfcc46fc69c.tar.gz |
webm2pes: fix PesOptionalHeader::SetPtsBits w/big-endian
PesOptionalHeader::Write() currently writes the low order bits first, so
they're packed according to its 'big-endian' comment.
Bug: webm:1806
Change-Id: I1f3e2b0916594fc8e83537854d69507692de693f
-rw-r--r-- | m2ts/webm2pes.cc | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/m2ts/webm2pes.cc b/m2ts/webm2pes.cc index afa8a6b..a4169c0 100644 --- a/m2ts/webm2pes.cc +++ b/m2ts/webm2pes.cc @@ -33,9 +33,6 @@ std::string ToString(const char* str) { // void PesOptionalHeader::SetPtsBits(std::int64_t pts_90khz) { - std::uint64_t* pts_bits = &pts.bits; - *pts_bits = 0; - // PTS is broken up and stored in 40 bits as shown: // // PES PTS Only flag @@ -48,32 +45,36 @@ void PesOptionalHeader::SetPtsBits(std::int64_t pts_90khz) { const std::uint32_t pts2 = (pts_90khz >> 15) & 0x7FFF; const std::uint32_t pts3 = pts_90khz & 0x7FFF; - std::uint8_t buffer[5] = {0}; - // PTS only flag. - buffer[0] |= 1 << 5; - // Top 3 bits of PTS and 1 bit marker. - buffer[0] |= pts1 << 1; - // Marker. - buffer[0] |= 1; + pts.bits = 0; - // Next 15 bits of pts and 1 bit marker. - // Top 8 bits of second PTS chunk. - buffer[1] |= (pts2 >> 7) & 0xff; // bottom 7 bits of second PTS chunk. - buffer[2] |= (pts2 << 1); + pts.bits |= (pts3 << 1) & 0xff; // Marker. - buffer[2] |= 1; + pts.bits |= 1; // Last 15 bits of pts and 1 bit marker. // Top 8 bits of second PTS chunk. - buffer[3] |= (pts3 >> 7) & 0xff; + pts.bits <<= 8; + pts.bits |= (pts3 >> 7) & 0xff; + // bottom 7 bits of second PTS chunk. - buffer[4] |= (pts3 << 1) & 0xff; + pts.bits <<= 8; + pts.bits |= (pts2 << 1); // Marker. - buffer[4] |= 1; + pts.bits |= 1; - // Write bits into PesHeaderField. - std::memcpy(reinterpret_cast<std::uint8_t*>(pts_bits), buffer, 5); + // Next 15 bits of pts and 1 bit marker. + // Top 8 bits of second PTS chunk. + pts.bits <<= 8; + pts.bits |= (pts2 >> 7) & 0xff; + + // PTS only flag. + pts.bits <<= 8; + pts.bits |= 1 << 5; + // Top 3 bits of PTS and 1 bit marker. + pts.bits |= pts1 << 1; + // Marker. + pts.bits |= 1; } // Writes fields to |buffer| and returns true. Returns false when write or |