summaryrefslogtreecommitdiff
path: root/m2ts/webm2pes.cc
diff options
context:
space:
mode:
Diffstat (limited to 'm2ts/webm2pes.cc')
-rw-r--r--m2ts/webm2pes.cc41
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