📄 transport.cpp
字号:
bCurHeaderDataLength++;
}
if (bAddCopyInfoFlag == 1)
{
GetByte();
bCurHeaderDataLength++;
}
if (bCRCFlag == 1)
{
GetWord();
bCurHeaderDataLength += 2;
}
// Check if Extension flag is set to 1 to skip bytes
if (bExtFlag == 1)
{
// Get private data flag, pack header field flag, program packet sequence
// counter flag, P-STD buffer flag, reserved and PES extention flag2 bits.
byte = (BYTE)GetByte();
bCurHeaderDataLength++;
INT bPrivateDataFlag = byte >> 7; // Bit 7, must be 0
INT bPackHeaderFieldFlag = (byte & 0x40) >> 6; // Bit 6, must be 0
INT bSeqCounterFlag = (byte & 0x20) >> 5; // Bit 5, must be 0
INT bSTDBufferFlag = (byte & 0x10) >> 4; // Bit 4, must be 1
// INT bReserved = (byte & 0xE) >> 1; // Bits 3-1, must be 7
INT bExtFlag2 = byte & 0x1; // Bit 0, must be 0
if (bPrivateDataFlag == 1)
{
for (byte = 0; byte < 4; byte++)
GetDWord();
bCurHeaderDataLength += 16;
}
if (bPackHeaderFieldFlag == 1)
{
GetByte();
bCurHeaderDataLength++;
}
if (bSeqCounterFlag == 1)
{
GetWord();
bCurHeaderDataLength += 2;
}
// Check if STD Buffer flag is set to skip STD buffer scale and size (2 bytes).
if (bSTDBufferFlag == 1)
{
GetWord();
bCurHeaderDataLength += 2;
}
if (bExtFlag2 == 1)
{
BYTE bPESExtFieldLength = (BYTE)(GetByte() & 0x7F);
for (byte = 0; byte < bPESExtFieldLength; byte++)
GetByte();
bCurHeaderDataLength += (1 + bPESExtFieldLength);
}
}
// Skip stuffing bytes
INT wStuffingByte = bHeaderDataLength - bCurHeaderDataLength;
for (int i = 0; i < wStuffingByte; i++)
{
byte = (BYTE)GetByte();
if (m_bEndOfBuffer || m_bStopDemux)
return 0;
}
wPacketHeaderLength += bHeaderDataLength;
return wPacketHeaderLength;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2Transport::StripAc3PacketHeader
* USAGE
* int StripAc3PacketHeader()
* DESCRIPTION
* Parses the packet header with StreamId of AC3/DTS/PCM/SUB.
* PARAMETERS
* None.
* RETURN VALUE
* Returns the packet header length.
/**********************************************************************/
int CMpeg2Transport::StripAc3PESPacketHeader()
{
INT wPacketHeaderLength = 0;
INT wPacketLength = 0;
BYTE byte = 0;
m_bPtsDtsFlag = FALSE;
m_llDts = 0;
wPacketLength = (WORD)GetWord();
wPacketHeaderLength += 2;
// Skip byte containing scrambling control, priority, alignment, copyright
// and original or copy bits.
GetByte();
wPacketHeaderLength++;
// Get PTS, DTS, ESCR, ESRate, DSM trick mode, additional copy info, CRC and
// extension flags.
byte = (BYTE)GetByte();
wPacketHeaderLength++;
INT bPtsFlag = byte >> 6; // Bits 7 & 6, PTS or no
INT bESCRFlag = byte & 0x20; // Bit 5, should be 0
INT bESRateFlag = byte & 0x10; // Bit 4, should be 0
INT bDSMTrickModeFlag = byte & 0x8; // Bit 3, should be 0
INT bAddCopyInfoFlag = byte & 0x4; // Bit 2, should be 0
INT bCRCFlag = byte & 0x2; // Bit 1, should be 0
INT bExtFlag = byte & 0x1; // Bit 0, 0 or 1
// Get Header Data Length
INT bHeaderDataLength = (BYTE)GetByte();
wPacketHeaderLength++;
// Keep current # of advanced bytes after the PES_header_data_length field.
// Use this to calculate the stuffing bytes.
INT bCurHeaderDataLength = 0;
// Get PTS
if (bPtsFlag == 0x2) // '10'
{
m_llPts = (LONGLONG(GetByte() & 0x0E) << 29);
m_llPts += (LONGLONG(GetByte()) << 22);
m_llPts += (LONGLONG(GetByte() & 0xFE) << 14);
m_llPts += (LONGLONG(GetByte()) << 7);
m_llPts += (LONGLONG(GetByte() >> 1));
bCurHeaderDataLength += 5;
m_bPtsDtsFlag = TRUE;
}
if (bESCRFlag == 1)
{
GetDWord();
GetWord();
bCurHeaderDataLength += 6;
}
if (bESRateFlag == 1)
{
GetWord();
GetByte();
bCurHeaderDataLength += 3;
}
if (bDSMTrickModeFlag == 1)
{
GetByte();
bCurHeaderDataLength++;
}
if (bAddCopyInfoFlag == 1)
{
GetByte();
bCurHeaderDataLength++;
}
if (bCRCFlag == 1)
{
GetWord();
bCurHeaderDataLength += 2;
}
// Check if Extension flag is set to 1 to skip bytes
if (bExtFlag == 1)
{
// Get private data flag, pack header field flag, program packet sequence
// counter flag, P-STD buffer flag, reserved and PES extention flag2 bits.
byte = (BYTE)GetByte();
bCurHeaderDataLength++;
INT bPrivateDataFlag = byte >> 7; // Bit 7, should be 0
INT bPackHeaderFieldFlag = byte & 0x40; // Bit 6, should be 0
INT bSeqCounterFlag = byte & 0x20; // Bit 5, should be 0
INT bSTDBufferFlag = byte & 0x10; // Bit 4, should be 1
// INT bReserved = byte & 0xE; // Bits 3-1, should be 111b
INT bExtFlag2 = byte & 0x1; // Bit 0, should be 0
if (bPrivateDataFlag == 1)
{
for (byte = 0; byte < 4; byte++)
GetDWord();
bCurHeaderDataLength += 16;
}
if (bPackHeaderFieldFlag == 1)
{
GetByte();
bCurHeaderDataLength++;
}
if (bSeqCounterFlag == 1)
{
GetWord();
bCurHeaderDataLength += 2;
}
// Check if STD Buffer flag is set to 1 to skip STD buffer scale and
// buffer size (2 bytes).
if (bSTDBufferFlag == 0x10) // 10000b or bit 4 is 1
{
GetWord();
bCurHeaderDataLength += 2;
}
if (bExtFlag2 == 1)
{
BYTE bPESExtFieldLength = (BYTE)(GetByte() & 0x7F);
for (byte = 0; byte < bPESExtFieldLength; byte++)
GetByte();
bCurHeaderDataLength += (1 + bPESExtFieldLength);
}
}
// Skip stuffing bytes
INT wStuffingByte = bHeaderDataLength - bCurHeaderDataLength;
for (int i = 0; i < wStuffingByte; i++)
{
byte = (BYTE)GetByte();
if (m_bEndOfBuffer || m_bStopDemux)
return 0;
}
wPacketHeaderLength += bHeaderDataLength;
return wPacketHeaderLength;
}
////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2Transport::GetAdaptationField
* USAGE
* int GetAdaptationField (BYTE bAdaptFieldCtrl)
* DESCRIPTION
* Get the transport stream adapation field section.
* PARAMETERS
* BYTE bAdaptFieldCtrl - Adaptation field control which is from the transport
* stream header.
* RETURN VALUE
* Returns the length of this entire field, including the Adaptation
* Field Length byte. Returns -1 if error occurs (not a valid TS packet).
/**********************************************************************/
int CMpeg2Transport::GetAdaptationField(INT bAdaptFieldCtrl)
{
INT bAdaptFieldLength = 0;
INT bCurrentLength = 0;
bAdaptFieldLength = (BYTE)GetByte();
if (bAdaptFieldCtrl == 0x2 && bAdaptFieldLength != 183)
return -1;
else if (bAdaptFieldCtrl == 0x3 && bAdaptFieldLength > 182)
return -1;
if (bAdaptFieldLength > 0)
{
BYTE bCode = (BYTE)GetByte();
bCurrentLength++;
m_bDiscIndicator = (bCode & 0x80) >> 7; // Bit 7
// BOOL bRandomIndicator = (bCode & 0x40) >> 6; // Bit 6
// BOOL bPriorityIndicator = (bCode & 0x20) >> 5; // Bit 5
m_bPcrFlag = (bCode & 0x10) >> 4; // Bit 4
BOOL bOPCRFlag = (bCode & 0x8) >> 3; // Bit 3
BOOL bSplicingFlag = (bCode & 0x4) >> 2; // Bit 2
BOOL bTransportFlag = (bCode & 0x2) >> 1; // Bit 1
BOOL bAdapFieldExtFlag = bCode & 0x1; // Bit 0
// Skip program clock reference base (33 bits), reserved (6 bits)
// and program clock reference extension (9 bits), 6 bytes total
if (m_bPcrFlag == 1)
{
m_llPcr = GetDWord();
BYTE byte = (BYTE)GetByte();
m_llPcr = (m_llPcr << 1) | (byte & 0x1);
GetByte();
bCurrentLength += 6;
}
// Skip original program clock reference base (33 bits), reserved (6 bits)
// and original program clock reference extension (9 bits), 6 bytes total.
if (bOPCRFlag == 1)
{
for (int i = 0; i < 6; i++)
GetByte();
bCurrentLength += 6;
}
// Skip splice countdown, 1 byte
if (bSplicingFlag == 1)
{
GetByte();
bCurrentLength++;
}
// Skip transport private data length (1 byte) and private data length
if (bTransportFlag == 1)
{
BYTE bTransportLength = (BYTE)GetByte();
for (int i = 0; i < bTransportLength; i++) // Private data
GetByte();
bCurrentLength += (bTransportLength + 1);
}
if (bAdapFieldExtFlag == 1)
{
BYTE bAdaptFieldExtLength = (BYTE)GetByte();
bCode = (BYTE)GetByte();
bCurrentLength += 2;
BOOL bLtwFlag = (bCode & 0x80) >> 7; // Bit 7
BOOL bPiecewiseRateFlag = (bCode & 0x40) >> 6; // Bit 6
BOOL bSeamlessSpliceFlag = (bCode & 0x20) >> 5; // Bit 5
// INT bReserved = bCode & 0x1F; // Bits 4-0
if (bLtwFlag == 1)
{
GetWord();
bCurrentLength += 2;
}
if (bPiecewiseRateFlag == 1)
{
GetByte();
GetWord();
bCurrentLength += 3;
}
if (bSeamlessSpliceFlag == 1)
{
m_llDts = (LONGLONG(GetByte() & 0x0E) << 29);
m_llDts += (LONGLONG(GetByte()) << 22);
m_llDts += (LONGLONG(GetByte() & 0xFE) << 14);
m_llDts += (LONGLONG(GetByte()) << 7);
m_llDts += (LONGLONG(GetByte() >> 1));
m_bPtsDtsFlag = FALSE;
bCurrentLength += 5;
}
// Reserved bytes ???
while (TRUE)
{
BYTE reserved = (BYTE)GetByte();
// Reaches stuffing byte or end of Adaptation Field
if (reserved == 0xFF || bCurrentLength == bAdaptFieldLength)
break;
if (m_bEndOfBuffer || m_bStopDemux)
break;
bCurrentLength++;
}
}
// Skip stuffing bytes
INT wStuffingBytes = bAdaptFieldLength - bCurrentLength;
for (int i = 0; i < wStuffingBytes; i++)
{
BYTE byte = (BYTE)GetByte();
// Note: If to check with FF, SM encoded stream won't work. The last byte
// of stuffing byte is 0 instead of FF.
// if (byte != 0xFF) // Invalid TS packet -> invalid Adaptation Field.
// return -1;
}
/*
BYTE b;
for (int i = 0; i < bAdaptFieldLength; i++)
b = GetByte();
if (bAdaptFieldLength == 0x5E)
{
// m_dwBufferIndex--;
// bAdaptFieldLength--;
// MmDebugLogfile((MmDebugLevelTrace, "%X %d", b, bAdaptFieldLength));
}
*/
return bAdaptFieldLength + 1;
}
else // Value 0 is for inserting a single stuffing byte
return 1;
}
/////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -