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

📄 mpeg2.cpp

📁 神龙卡 SDK_84xx_DShow_145_02.zip 这个是 windows 上二个是linux
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				case 0:	m_llPts = (LONGLONG(GetByte() & 0x0E) << 29); break;
				case 1:	m_llPts += (LONGLONG(GetByte()) << 22); break;
				case 2:	m_llPts += (LONGLONG(GetByte() & 0xFE) << 14); break;
				case 3:	m_llPts += (LONGLONG(GetByte()) << 7); break;
				case 4:	m_llPts += (LONGLONG(GetByte() >> 1)); break;

				case 5:	m_llDts = (LONGLONG(GetByte() & 0x0E) << 29); break;
				case 6:	m_llDts += (LONGLONG(GetByte()) << 22); break;
				case 7:	m_llDts += (LONGLONG(GetByte() & 0xFE) << 14); break;
				case 8:	m_llDts += (LONGLONG(GetByte()) << 7); break;
				case 9:	m_llDts += (LONGLONG(GetByte() >> 1)); break;
			}
			curByte++;
		}
		bCurHeaderDataLength += 10;
		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, 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 iStuffingByte = bHeaderDataLength - bCurHeaderDataLength;
	INT i;
	for (i = 0; i < iStuffingByte; i++)
	{
		GetByte();
		if (m_bEndOfBuffer)
			return;
	}

	wPacketHeaderLength += bHeaderDataLength ;

	// Pointer to the beginning of the payload
	m_bPayloadPtr = m_pBuffer + m_dwBufferIndex;
	// Actual payload data size
	m_dwPayloadLength = wPacketLength - wPacketHeaderLength;
	if (wPacketLength < wPacketHeaderLength) // Wrong packet header
		m_dwPayloadLength = 0;

}

////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2::GetAc3DtsPacket
 * USAGE
 *  void GetAc3DtsPacket()
 * DESCRIPTION
 *  Parses the audio packet of dolby AC3, DTS or PCM packet header.
 * PARAMETERS
 *  None.
 * RETURN VALUE
 *  None.
/**********************************************************************/
void CMpeg2::GetAc3DtsPacket()
{
	INT wPacketHeaderLength = 0;
	INT wPacketLength = 0;
	INT i = 0;
	BYTE byte = 0;

	m_bPtsDtsFlag = FALSE;
	m_llPts = 0;

	wPacketLength = (WORD)GetWord();

	// 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 (i = 0; i < wStuffingByte; i++)
	{
		byte = (BYTE)GetByte();
		if (m_bEndOfBuffer)
			return;
	}				

	wPacketHeaderLength += bHeaderDataLength ;

	// Sub stream id: AC3 (10000***b), DTS (10001***b), PCM (10100***b), SUB (001*****b)
	m_bSubstreamId = (BYTE)GetByte();
	if ((m_bSubstreamId >> 5) != SUB_SUBSTREAM_ID)
	{
		m_bNFrameHeaders = (BYTE)GetByte();     // Number of frame headers
		m_iFirstAccessUnit = (WORD)GetWord();         // Frst access unit pointer
		wPacketHeaderLength += 4;

		// Determine the correct audio channel to play
		if (m_AVId.dwAudioStreamId == 0)
		{
			DWORD shiftCount = m_bSubstreamId & 0x7;
			DWORD newMask = 1 << shiftCount;
			if (!((m_dwAudioMask >> shiftCount) & 0x1))
			{
				m_dwAudioMask = m_dwAudioMask | newMask;
				m_wAudioChannelCount++;
				if (m_wAudioChannelCount == m_wAudioChannelPlay) 
					m_AVId.dwAudioStreamId = m_bSubstreamId;
				switch(m_bSubstreamId >> 3)
				{
					case AC3_SUBSTREAM_ID:
						MmDebugLogfile((MmDebugLevelTrace, "ac3 audio channel %d", m_wAudioChannelCount));
						break;
					case DTS_SUBSTREAM_ID:
						MmDebugLogfile((MmDebugLevelTrace, "dts audio channel %d", m_wAudioChannelCount));
						break;
					case PCM_SUBSTREAM_ID:
						MmDebugLogfile((MmDebugLevelTrace, "pcm audio channel %d", m_wAudioChannelCount));
						break;
				}
			}
		}
		if ((m_bSubstreamId >> 3) == PCM_SUBSTREAM_ID)
		{
			GetByte();
			GetWord();
			wPacketHeaderLength += 3;
		}
	}
	// Pointer to the beginning of the payload
	m_bPayloadPtr = m_pBuffer + m_dwBufferIndex;
	// Actual payload data size
	m_dwPayloadLength = wPacketLength - wPacketHeaderLength;
	if (wPacketLength < wPacketHeaderLength) // Wrong packet header ??
		m_dwPayloadLength = 0;
}

/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/CMpeg2::SkipSystemHeader
 * USAGE
 *  void SkipSystemHeader
 * DESCRIPTION
 *  Parses the mpeg2 system header
 * PARAMETERS
 *  None.
 * RETURN VALUE
 *  None.
/**********************************************************************/
void CMpeg2::SkipSystemHeader()
{
	BYTE byte = 0;
	WORD wHeaderLength = 0;
	INT curByte = 1;

	while (!m_bEndOfBuffer)
	{
		switch(curByte)
		{
			case 1:
				wHeaderLength = (WORD)GetByte();
				break;
			case 2:
				wHeaderLength = (wHeaderLength << 8) | (WORD)GetByte();
				break;
			// Rate bound and marker bits (3 bytes).
			case 3:
			case 4:
			case 5:
				GetByte();
				break;
			// Audio bound, fixed flag, CSPS flag.
			case 6:
				GetByte();
				break;
			// System audio clock flag, system video clock flag, marker bit, video bound bits.
			case 7:
				GetByte();
				break;
			// Reserved byte
			case 8:
				GetByte();
				break;
			// Std_buffer_bound_scale and Std_buffer_size_bound
			case 9:
			default:
				byte = (BYTE)ShowByte();
				if ((byte >> 7) == 1)	// first bit is 1, skip 3 bytes
				{		
					GetByte();	 // Stream Id
					GetWord();   // buffer bound scale and buffer size bound
				}
				else
					return;
		}
		curByte++;
	}
/*
	wHeaderLength = (WORD)GetWord();

	// Rate bound and marker bits (3 bytes).
	GetWord();
	GetByte();
	// Audio bound, fixed flag, CSPS flag.
	GetByte();
	// System audio clock flag, system video clock flag, marker bit, video bound bits.
	GetByte();
	// Reserved byte
	GetByte();

	// Skip Std_buffer_bound_scale and Std_buffer_size_bound
	while (!m_bEndOfBuffer)
	{
		byte = (BYTE)ShowByte();
		if ((byte >> 7) == 1)	// first bit is 1, skip 3 bytes
		{		
			GetByte();	 // Stream Id
			GetWord();   // buffer bound scale and buffer size bound
		}
		else
			break;
	}
*/
}

////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

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