⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 transport.cpp

📁 神龙卡 SDK_84xx_DShow_145_02.zip 这个是 windows 上二个是linux
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				m_dwBufferIndex -= (bPointerField + 2);
				m_dwPayloadLength = 187 - wBytesAdvanced;
				return 1;
			}
		}
		// bPayloadStart = 0, No PES packet or PSI data. PES payload.
		// Is this a valid TS packet when no adaptation field exists???
		else if ((m_wPid == m_ProgDef.iVideoElemStreamId) || (m_wPid == m_ProgDef.iAudioElemStreamId))
		{
			(m_wPid == m_ProgDef.iVideoElemStreamId) ? (m_bStreamType = MM_VIDEO) : (m_bStreamType = MM_AUDIO);
			m_dwPayloadLength = 187 - wBytesAdvanced;
			m_bPayloadPtr = m_pBuffer + m_dwBufferIndex;
			m_bPesPayload = TRUE;
			return 1;
		}
		m_dwPayloadLength = 187 - wBytesAdvanced;
		return 1;
	}
	return 0;
}

////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2Transport::GetPASection
 * USAGE
 *  int GetPASection()
 * DESCRIPTION
 *  Parses the program association section of transport stream packet.
 * PARAMETERS
 *  None.
 * RETURN VALUE
 *  Returns the length of this entire section. Returns -1 if it is an
 *  invalid TS packet.
/**********************************************************************/
int CMpeg2Transport::GetPASection()
{
	BYTE bCode = 0;
	WORD wLength = 0;

	bCode = (BYTE)GetByte();
	INT bSecSyntaxIndicator = bCode >> 7;	// Bit 7
	if ((bSecSyntaxIndicator != 1) || ((bCode & 0x40) != 0))
		return -1;
//	INT bReserved = (bCode & 0x30) >> 4;	// Bits 5, 4	
	INT wSectionLength = (bCode & 0xF);	// Bits 3-0
	wSectionLength = (wSectionLength << 8) | (BYTE)GetByte();
	if (((wSectionLength & 0xC00) != 0) || (wSectionLength > 1021))
		return -1;

	WORD wTransportStreamId = (WORD)GetWord();
	bCode = (BYTE)GetByte();
//	INT bVersionNum = (bCode & 0x3E) >> 1;	// Bits 5-1
//	INT bCurNextIndicator = bCode & 0x1;	// Bit 0
	BYTE bSectionNum = (BYTE)GetByte();
	BYTE bLastSectionNum = (BYTE)GetByte();
	wLength += 5;

	while (TRUE)
	{
		WORD wProgramNum = (WORD)GetWord();
		if (wProgramNum == 0)
		{
			INT wNetworkPid = (WORD)GetWord() & 0x1FFF;	// Left 13 bits
			if ((wNetworkPid < 0x00010) || (wNetworkPid > 0x1FFE))
				return -1;
		}
		else
		{
			INT wProgramMapPid = (WORD)GetWord() & 0x1FFF;
			if ((wProgramMapPid < 0x00010) || (wProgramMapPid > 0x1FFE))
				return -1;
		}
		wLength += 4;
		if ((wLength + 4) == wSectionLength)
			break;
		if (m_bEndOfBuffer || m_bStopDemux)
			break;
	}
	DWORD dwCRC = GetDWord();
	return wSectionLength + 2;
}

////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2Transport::GetPMSection
 * USAGE
 *  int GetPMSection()
 * DESCRIPTION
 *  Parses the program map section of transport stream packet.
 * PARAMETERS
 *  None.
 * RETURN VALUE
 *  Returns the length of this entire section. Returns -1 if it is an
 *  invalid TS packet.
/**********************************************************************/
int CMpeg2Transport::GetPMSection()
{	
	BYTE bCode = 0;
	INT wLength = 0;

	bCode = (BYTE)GetByte();
	INT bSecSyntaxIndicator = bCode >> 7;	// Bit 7
	if ((bSecSyntaxIndicator != 1) || ((bCode & 0x40) != 0))
		return -1;
//	INT bReserved = (bCode & 0x30) >> 4;	// Bits 5, 4	
	INT wSectionLength = (bCode & 0xF);	// Bits 3-0
	wSectionLength = (wSectionLength << 8) | (BYTE)GetByte();
	if (((wSectionLength & 0xC00) != 0) || (wSectionLength > 1021))
		return -1;

	m_wProgramNumber = (WORD)GetWord();
	bCode = (BYTE)GetByte();
//	INT bVersionNum = (bCode & 0x3E) >> 1;	// Bits 5-1
//	INT bCurNextIndicator = bCode & 0x1;	// Bit 0
	BYTE bSectionNum = (BYTE)GetByte();
	BYTE bLastSectionNum = (BYTE)GetByte();
	if ((bSectionNum != 0) || (bLastSectionNum != 0))
		return -1;
	INT wPcrPid = (WORD)GetWord() & 0x1FFF;	// Bits 12-0

	INT wProgramInfoLength = (WORD)GetWord() & 0xFFF;	// Bits 11-0
	if ((wProgramInfoLength & 0xC00) != 0)				// First 2 bits should be 00
		return -1;
	wLength += 9;
	// Ignore descriptor fields for now, move the pointer to the end of descriptor.
	m_dwBufferIndex += wProgramInfoLength;
	wLength = wLength + wProgramInfoLength;

	if (m_ProgDef.iProgramNum == -1)
	{
		m_wProgramCounter++;
		if (m_wProgramCounter == m_wProgramPlay)
			m_ProgDef.iProgramNum = m_wProgramNumber;
	}

	while (TRUE)
	{
		BYTE bPmtStreamType = (BYTE)GetByte();		
		INT wElementaryPid = (WORD)GetWord() & 0x1FFF;	// Bits 12-0
		INT wESInfoLength = (WORD)GetWord() & 0xFFF;	// Bits 11-0
		wLength = wLength + 5 + wESInfoLength;

		if ((wESInfoLength & 0xC00) != 0)				// First 2 bits should be 00
			return -1;
		if (bPmtStreamType == 0x01 || bPmtStreamType == 0x02)
		{
			if (m_ProgDef.iProgramNum == m_wProgramNumber)
				m_ProgDef.iVideoElemStreamId = wElementaryPid;
		}
		else if (bPmtStreamType == 0x03 || bPmtStreamType == 0x04 || bPmtStreamType == 0x81)
		{
			if (m_ProgDef.iProgramNum == m_wProgramNumber)
				m_ProgDef.iAudioElemStreamId = wElementaryPid;
		}
		else if (bPmtStreamType == 0x05 || bPmtStreamType == 0x06)
			m_wPrivateStreamPid = wElementaryPid;
		else	// Unknown stream?
			MmDebugLogfile((MmDebugLevelTrace|MmDebugLevelLog, "TS unknown stream type: 0x%X ", bPmtStreamType));

		// Ignore descriptor fields for now, move the pointer to the end of descriptor.
		// Add 4 for the CRC.
		m_dwBufferIndex += wESInfoLength;
		if ((wLength + 4) == wSectionLength)
			break;
		if (m_bEndOfBuffer || m_bStopDemux)
			break;
	}
	DWORD dwCRC = GetDWord();
	return wSectionLength + 2;
}

////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2Transport::GetCASection
 * USAGE
 *  int GetCASection()
 * DESCRIPTION
 *  Parses the conditional access section of transport stream packet.
 * PARAMETERS
 *  None.
 * RETURN VALUE
 *  Returns the length of this entire section. Returns -1 if it is an
 *  invalid TS packet.
/**********************************************************************/
// Need to implement correctly!!
int CMpeg2Transport::GetCASection()
{
	BYTE bCode = 0;
	WORD wLength = 0;

	bCode = (BYTE)GetByte();
	INT bSecSyntaxIndicator = bCode >> 7;	// Bit 7
	if ((bSecSyntaxIndicator != 1) || ((bCode & 0x40) != 0))
		return -1;
//	INT bReserved = (bCode & 0x30) >> 4;	// Bits 5, 4	
	INT wSectionLength = (bCode & 0xF);	// Bits 3-0
	wSectionLength = (wSectionLength << 8) | (BYTE)GetByte();
	if ((wSectionLength & 0xC00) != 0)
		return -1;
	wLength += 2;

	GetWord();									// Reserved, first 2 bytes
	bCode = (BYTE)GetByte();
//	INT bVersionNum = (bCode & 0x3E) >> 1;	// Bits 5-1
//	INT bCurNextIndicator = bCode & 0x1;	// Bit 0
	BYTE bSectionNum = (BYTE)GetByte();
	BYTE bLastSectionNum = (BYTE)GetByte();
	wLength += 5;

	// Ignore descriptor fields for now, move the pointer to the end of descriptor.
	m_dwBufferIndex += (wSectionLength - wLength);	// BAD!!!

	DWORD dwCRC = GetDWord();
	return wSectionLength + 2;
}

////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2Transport::GetPrivateSection
 * USAGE
 *  int GetPrivateSection()
 * DESCRIPTION
 *  Parses the private section of transport stream packet.
 * PARAMETERS
 *  None.
 * RETURN VALUE
 *  Returns the length of this entire section. Returns -1 if it is an
 *  invalid TS packet.
/**********************************************************************/
// Need to implement correctly!
int CMpeg2Transport::GetPrivateSection()
{
	BYTE bCode = 0;
	WORD wLength = 0;

	bCode = (BYTE)GetByte();
	INT bSecSyntaxIndicator = bCode >> 7;			// Bit 7
//	INT bPrivateIndicator = (bCode & 0x40) >> 6;	// Bit 6 = 0
//	INT bReserved = (bCode & 0x30) >> 4;			// Bits 5, 4	
	INT wPriSectionLength = (bCode & 0xF);			// Bits 3-0
	wPriSectionLength = (wPriSectionLength << 8) | (BYTE)GetByte();
	wLength = 2;

	if (bSecSyntaxIndicator == 0)
	{
		// Private data bytes
	}
	else
	{
		WORD wTableIdExt = (WORD)GetWord();
		bCode = (BYTE)GetByte();
//		INT bVersionNum = (bCode & 0x3E) >> 1;	// Bits 5-1
//		INT bCurNextIndicator = bCode & 0x1;	// Bit 0
		BYTE m_bSectionNum = (BYTE)GetByte();
		BYTE m_bLastSectionNum = (BYTE)GetByte();
		wLength += 5;
		
		// Private data bytes

		DWORD dwCRC = GetDWord();
		wLength += 4;
	}

	return wPriSectionLength + 2;
}

////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2Transport::StripPESPacketHeader
 * USAGE
 *  int StripPESPacketHeader()
 * DESCRIPTION
 *  Parses the packet header.
 * PARAMETERS
 *  None.
 * RETURN VALUE
 *  Returns the packet header length.
/**********************************************************************/
int CMpeg2Transport::StripPESPacketHeader()
{
	int wPacketHeaderLength = 0;
	int wPacketLength = 0;
	BYTE byte = 0;
	m_bPtsDtsFlag = FALSE;
	m_llPts = 0;

	wPacketLength = (WORD)GetWord();
	wPacketHeaderLength += 2;

	// Skip byte containing scrambling control, priority, alignment, copyright 
	// and original bits.
	byte = (BYTE)GetByte();
	wPacketHeaderLength++;	

	// Get PTS, DTS, ESCR, ESRate, DSM trick mode, additional copy info, CRC and
	// extension flags.
	byte = (BYTE)GetByte();
	wPacketHeaderLength++;
	INT bPtsDtsFlag = byte >> 6;				// Bits 7 & 6
	INT bESCRFlag = (byte & 0x20) >> 5;		// Bit 5, must be 0
	INT bESRateFlag = (byte & 0x10) >> 4;		// Bit 4, must be 0
	INT bDSMTrickModeFlag = (byte & 0x8) >> 3;	// Bit 3, must be 0
	INT bAddCopyInfoFlag = (byte & 0x4) >> 2;	// Bit 2, must be 0
	INT bCRCFlag = (byte & 0x2) >> 1;			// Bit 1, must be 0
	INT bExtFlag = byte & 0x1;					// Bit 0, 0 or 1

	// Get Header Data Length
	BYTE bHeaderDataLength = (BYTE)GetByte();
	wPacketHeaderLength++;

	// Keep current # of advanced bytes after the PES_header_data_length field.
	// Use this to calculate the stuffing bytes.
	BYTE bCurHeaderDataLength = 0;

	// Get PTS
	if (bPtsDtsFlag == 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;
	}
	else if(bPtsDtsFlag == 0x3)	// '11' PTS and DTS present
	{
		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));

		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));
		bCurHeaderDataLength += 10;
		m_bPtsDtsFlag = TRUE;
	}

	// Check if ESCRFlag is set to 1 to skip 6 bytes
	if (bESCRFlag == 1)
	{
		for (int i = 0; i < 6; i++)
			GetByte();
		bCurHeaderDataLength += 6;
	}
	if (bESRateFlag == 1)
	{
		for (int i = 0; i < 3; i++)
			GetByte();
		bCurHeaderDataLength += 3;
	}
	if (bDSMTrickModeFlag == 1)
	{
		GetByte();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -