OSDN Git Service

implement PcrPacket class in Utils
authorcocot <cocot@users.sourceforge.jp>
Wed, 25 Feb 2009 12:37:04 +0000 (21:37 +0900)
committercocot <cocot@users.sourceforge.jp>
Wed, 25 Feb 2009 12:37:04 +0000 (21:37 +0900)
src/Utils.cc

index c16a3a9..46bcc52 100644 (file)
@@ -616,6 +616,29 @@ byte* Descriptor::GetData(void)
     return mData;
 }
 
+PcrPacket::PcrPacket(Int64 pcr, byte counter, ushort pid)
+{
+    SetPID(pid);
+    SetContinuityCounter(counter);
+    mData[3] &= 0x0f; // adaptation field only, no payload
+    mData[3] |= 0x20; // adaptation field only, no payload
+    mData[4] = 183; // length
+    mData[5] = 0x10; // only PCR present
+    Int64 tsClockValue = pcr / 300;
+    Int64 tsOffsetValue = pcr % 300;
+    mData[6] = (byte)((tsClockValue & 0x1fe000000LL) >> 25);
+    mData[7] = (byte)((tsClockValue & 0x1fe0000) >> 17);
+    mData[8] = (byte)((tsClockValue & 0x1fe00) >> 9);
+    mData[9] = (byte)((tsClockValue & 0x1fe) >> 1);
+    if ((tsClockValue & 0x1) == 0)
+        mData[10] &= 0x7f;
+    if ((tsOffsetValue & 0x100) == 0)
+        mData[10] &= 0xfe;
+    mData[11] = (byte)(tsOffsetValue & 0xff);
+    for (int i = 12; i < Constants::TS_SIZE; i++)
+        mData[i] = 0xff;
+}
+
 
 } // namespace