mData[3] |= value;
}
+TsTable::TsTable(void)
+{
+ // error = 0, payload = 1, priority = 0
+ mData[1] = 0x40;
+ // scrambling = 0, adaptation = 01, continuity = 0
+ mData[3] = 0x10;
+ // pointer = 00
+ mData[4] = 0x0;
+ // reserved, version, current/next
+ mData[10] = 0xc1;
+ // section
+ mData[11] = 0x0;
+ // last section
+ mData[12] = 0x0;
+}
+
+TsTable::TsTable(byte* data)
+{
+ SetData(data, 0);
+}
+
+void TsTable::AddData(byte* data, int offset, int len)
+{
+ byte* newData = NULL;
+ newData = new byte[std::strlen(mData)+(len-offset)+1];
+ std::strncpy(&newData[0], &mData[0], std::strlen(mData));
+ std::strncat(&newData[0], &data[0], (len-offset));
+ mData = &newData[0];
+}
+
+bool TsTable::Complete(void)
+{
+ int currentLen = strlen(mData) - (GetPointerSize() + 8);
+ if (GetLength() > currentLen)
+ return false;
+ return true;
+}
+
+byte TsTable::GetTableId(void)
+{
+ return mData[5 + GetPointerSize()];
+}
+
+void TsTable::SetTableId(byte value)
+{
+ mData[5 + GetPointerSize()] = value;
+}
+ushort TsTable::GetNumberId(void)
+{
+ return (ushort)((mData[8 + GetPointerSize()] << 8)
+ + mData[9 + GetPointerSize()]);
+}
+void TsTable::SetNumberId(ushort value)
+{
+ mData[8 + GetPointerSize()] = (byte)((value >> 8) & 0xff);
+ mData[9 + GetPointerSize()] = (byte)(value & 0xff);
+}
+ushort TsTable::GetLength(void)
+{
+ return (ushort)(((mData[6 + GetPointerSize()] & 0x0f) << 8)
+ + mData[7 + GetPointerSize()]);
+}
+
+void TsTable::SetLength(ushort value)
+{
+ // syntax, reserved, length
+ mData[6 + GetPointerSize()]
+ = (byte)(0xb0 | (byte)((value >> 8) & 0x0f));
+ mData[7 + GetPointerSize()] = (byte)(value & 0xff);
+}
+void TsTable::RefreshCrc(void)
+{
+ uint crc = Constants::ComputeCrc(
+ mData, GetLength() - 1, 5 + GetPointerSize());
+ mData[GetLength() + 4 + GetPointerSize()]
+ = (byte)((crc >> 24) & 0xff);
+ mData[GetLength() + 5 + GetPointerSize()]
+ = (byte)((crc >> 16) & 0xff);
+ mData[GetLength() + 6 + GetPointerSize()]
+ = (byte)((crc >> 8) & 0xff);
+ mData[GetLength() + 7 + GetPointerSize()]
+ = (byte)(crc & 0xff);
+ for (int i = GetLength() + 8 + GetPointerSize();
+ i < Constants::TS_SIZE; i++) {
+ mData[i] = 0xff;
+ }
}
+
+
+
+
+} // namespace
+
+
};
class Constants {
- static const int TS_PAYLOAD_SIZE;
- static const int TS_SIZE;
- static const int STRIDE_SIZE;
- static const int DISK_BUFFER;
- static const byte SYNC_BYTE;
- static const byte PAT_PID;
- static const byte SIT_PID;
- static const byte PAT_TABLE_ID;
- static const byte PMT_TABLE_ID;
- static const byte DTCP_DESCRIPTOR_TAG;
- static const byte PACK_ID;
- static const byte SYS_ID;
- static const byte MAP_ID;
- static const byte DIR_ID;
- static const byte PAD_ID;
-
- // defaults
- static const ushort DEFAULT_PMT_PID;
- static const ushort DEFAULT_VIDEO_PID;
- static const ushort MAX_VIDEO_PID;
- static const ushort DEFAULT_AUDIO_PID;
- static const ushort MAX_AUDIO_PID;
- static const ushort DEFAULT_PCR_PID;
- static const ushort DEFAULT_SUBTITLE_PID;
- static const ushort DEFAULT_PRESENTATION_GRAPHICS_PID;
- static const ushort DEFAULT_INTERACTIVE_GRAPHICS_PID;
- static const ushort DEFAULT_PROGRAM_NUMBER;
- static const int MAX_BUFFER_COUNT;
- static const int MIN_BUFFER_COUNT;
- static const Int64 AUDIO_DELAY;
- static const UInt32 MKVCLUSTER_START;
- static const UInt32 MKVFILE_START;
- static const UInt32 MKVSEGMENT_START;
- static const UInt32 MKVTRACKINFO_START;
- static const byte MKVTIMECODE_START;
-
- // stream types
- static const byte PES_VIDEO;
- static const byte PES_AUDIO_MPEG;
- static const byte PES_PRIVATE1;
- static const byte PES_PADDING;
- static const byte PES_PRIVATE2;
- static const byte PES_VIDEO_VC1;
- static const byte PES_PRIVATE_AC3;
- static const byte PES_PRIVATE_AC3_PLUS;
- static const byte PES_PRIVATE_DTS_HD;
- static const byte PES_PRIVATE_LPCM;
- static const byte PES_PRIVATE_AC3_TRUE_HD;
- static const UInt32 VC1_SEQ_SC;
- static const UInt32 VC1_END_OF_STREAM;
- static const ushort AC3_SYNC;
- static const UInt32 H264_PREFIX;
- static const UInt32 H264_END_OF_STREAM;
- static const UInt32 DTS_SYNC;
- static const UInt32 DTS_EXT_SYNC;
- static const UInt32 MLP_SYNC;
- static const UInt32 MPEG2_SEQ_CODE;
- static const UInt32 MPEG2_SEQ_EXT;
- static const UInt32 MPEG2_SEQ_END;
-
- // clocks
- static const Int64 MPEG2TS_CLOCK_RATE;
- static const Int64 MAX_MPEG2TS_CLOCK;
- static const Int64 MAX_BLURAY_CLOCK;
- static const Int64 MAX_FIREWIRE_CLOCK;
- static const Int64 MAX_PTS_CLOCK;
- static const Int64 PTS_CLOCK_RATE;
- static const int MAX_OFFSET;
- static const int MAX_COUNT;
-
- // descriptors
- static readonly byte hdmv_registration_descriptor[];
- static readonly byte copy_control_descriptor[];
- static readonly byte vc1_descriptor[];
- static readonly byte ac3_registration_descriptor[];
-
- static readonly byte DefaultSitTableOne[];
- static readonly uint crc_table[];
- static uint ComputeCrc(byte* data);
- static uint ComputeCrc(byte* data, int length);
- static uint ComputeCrc(byte* data, int length, int startIndex);
+ public:
+ static const int TS_PAYLOAD_SIZE;
+ static const int TS_SIZE;
+ static const int STRIDE_SIZE;
+ static const int DISK_BUFFER;
+ static const byte SYNC_BYTE;
+ static const byte PAT_PID;
+ static const byte SIT_PID;
+ static const byte PAT_TABLE_ID;
+ static const byte PMT_TABLE_ID;
+ static const byte DTCP_DESCRIPTOR_TAG;
+ static const byte PACK_ID;
+ static const byte SYS_ID;
+ static const byte MAP_ID;
+ static const byte DIR_ID;
+ static const byte PAD_ID;
+
+ // defaults
+ static const ushort DEFAULT_PMT_PID;
+ static const ushort DEFAULT_VIDEO_PID;
+ static const ushort MAX_VIDEO_PID;
+ static const ushort DEFAULT_AUDIO_PID;
+ static const ushort MAX_AUDIO_PID;
+ static const ushort DEFAULT_PCR_PID;
+ static const ushort DEFAULT_SUBTITLE_PID;
+ static const ushort DEFAULT_PRESENTATION_GRAPHICS_PID;
+ static const ushort DEFAULT_INTERACTIVE_GRAPHICS_PID;
+ static const ushort DEFAULT_PROGRAM_NUMBER;
+ static const int MAX_BUFFER_COUNT;
+ static const int MIN_BUFFER_COUNT;
+ static const Int64 AUDIO_DELAY;
+ static const UInt32 MKVCLUSTER_START;
+ static const UInt32 MKVFILE_START;
+ static const UInt32 MKVSEGMENT_START;
+ static const UInt32 MKVTRACKINFO_START;
+ static const byte MKVTIMECODE_START;
+
+ // stream types
+ static const byte PES_VIDEO;
+ static const byte PES_AUDIO_MPEG;
+ static const byte PES_PRIVATE1;
+ static const byte PES_PADDING;
+ static const byte PES_PRIVATE2;
+ static const byte PES_VIDEO_VC1;
+ static const byte PES_PRIVATE_AC3;
+ static const byte PES_PRIVATE_AC3_PLUS;
+ static const byte PES_PRIVATE_DTS_HD;
+ static const byte PES_PRIVATE_LPCM;
+ static const byte PES_PRIVATE_AC3_TRUE_HD;
+ static const UInt32 VC1_SEQ_SC;
+ static const UInt32 VC1_END_OF_STREAM;
+ static const ushort AC3_SYNC;
+ static const UInt32 H264_PREFIX;
+ static const UInt32 H264_END_OF_STREAM;
+ static const UInt32 DTS_SYNC;
+ static const UInt32 DTS_EXT_SYNC;
+ static const UInt32 MLP_SYNC;
+ static const UInt32 MPEG2_SEQ_CODE;
+ static const UInt32 MPEG2_SEQ_EXT;
+ static const UInt32 MPEG2_SEQ_END;
+
+ // clocks
+ static const Int64 MPEG2TS_CLOCK_RATE;
+ static const Int64 MAX_MPEG2TS_CLOCK;
+ static const Int64 MAX_BLURAY_CLOCK;
+ static const Int64 MAX_FIREWIRE_CLOCK;
+ static const Int64 MAX_PTS_CLOCK;
+ static const Int64 PTS_CLOCK_RATE;
+ static const int MAX_OFFSET;
+ static const int MAX_COUNT;
+
+ // descriptors
+ static readonly byte hdmv_registration_descriptor[];
+ static readonly byte copy_control_descriptor[];
+ static readonly byte vc1_descriptor[];
+ static readonly byte ac3_registration_descriptor[];
+ static readonly byte DefaultSitTableOne[];
+ static readonly uint crc_table[];
+ static uint ComputeCrc(byte* data);
+ static uint ComputeCrc(byte* data, int length);
+ static uint ComputeCrc(byte* data, int length, int startIndex);
};
class ProgramInfo {
TsTable();
TsTable(byte* data);
void AddData(byte* data, int offset, int len);
- bool Complete;
- byte TableId;
+ bool Complete(void);
+ byte GetTableId(void);
+ void SetTableId(byte value);
+ ushort GetNumberId(void);
+ void SetNumberId(ushort value);
+ ushort GetLength(void);
+ void SetLength(ushort value);
protected:
- ushort NumberId;
- ushort Length;
void RefreshCrc(void);
};