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

📄 descriptors.h

📁 mpeg4 demux 代码
💻 H
字号:
/* <LIC_AMD_STD>
 * Copyright (C) 2003-2005 Advanced Micro Devices, Inc.  All Rights Reserved.
 *
 * Unless otherwise designated in writing, this software and any related
 * documentation are the confidential proprietary information of AMD.
 * THESE MATERIALS ARE PROVIDED "AS IS" WITHOUT ANY
 * UNLESS OTHERWISE NOTED IN WRITING, EXPRESS OR IMPLIED WARRANTY OF ANY
 * KIND, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY,
 * NONINFRINGEMENT, TITLE, FITNESS FOR ANY PARTICULAR PURPOSE AND IN NO
 * EVENT SHALL AMD OR ITS LICENSORS BE LIABLE FOR ANY DAMAGES WHATSOEVER.
 *
 * AMD does not assume any responsibility for any errors which may appear
 * in the Materials nor any responsibility to support or update the
 * Materials.  AMD retains the right to modify the Materials at any time,
 * without notice, and is not obligated to provide such modified
 * Materials to you. AMD is not obligated to furnish, support, or make
 * any further information available to you.
 * </LIC_AMD_STD>  */
/* <CTL_AMD_STD>
 * </CTL_AMD_STD>  */
/* <DOC_AMD_STD>
 * </DOC_AMD_STD>  */

#ifndef __PARSE_MP4_H_
#define __PARSE_MP4_H_

#include "mai_types.h"
#include "bytestrm.h"
#include <iostream>

using namespace std;

#define FOURCC(c1,c2,c3,c4) (c1 << 24 | c2 << 16 | c3 << 8 | c4)

/* Tabel 1. MPEG4 systems, tag identifiers */
#define ObjectDescrTag					0x01
#define InitialObjectDescrTag			0x02
#define ES_DescrTag						0x03
#define DecoderConfigDescrTag			0x04
#define DecSpecificInfoTag				0x05
#define SLConfigDescrTag				0x06
#define ContentIdentDescrTag			0x07
#define SupplContentIdentDescrTag		0x08
#define IPI_DescrPointerTag				0x09
#define IPMP_DescrPointerTag			0x0A
#define IPMP_DescrTag					0x0B
#define QoS_DescrTag					0x0C
#define RegistrationDescrTag			0x0D

#define ContentClassificationDescrTag	0x40
#define KeyWordDescrTag					0x41
#define RatingDescrTag					0x42
#define LanguageDescrTag				0x43
#define ShortTextualDescrTag			0x44
#define ExpandedTextualDescrTag			0x45
#define ContentCreatorNameDescrTag		0x46
#define ContentCreationDateDescrTag		0x47
#define OCICreatorNameDescrTag			0x48
#define OCICreationDateDescrTag			0x49

#define ExtDescrTagStartRange			0x80
#define ExtDescrTagEndRange				0xFE
#define OCIDescrTagStartRange			0x40
#define OCIDescrTagEndRange				0x5F

const long sizeOfInstance=100;

/******** abstract classes ***********************/

class CBaseDescriptor {
public:
	CBaseDescriptor()
	{
		tag = 0;
	};
	CBaseDescriptor(m_u8 tag_par)
	{
		tag = tag_par;
	};

	void GetDescriptorLength(Byte_Stream &input_stream)
	{
		m_u8 byte_count = 0;
		m_u8 tbyte;
		DescriptorSize = input_stream.GetByte() & 0x7f;
		do
		{
			DescriptorSize <<= 7;
			tbyte = input_stream.GetByte();
			DescriptorSize |= (tbyte &0x7f);
			byte_count++;
		}while( (tbyte & 0x80) && byte_count < 3);
	};

	m_u8 tag;
	m_u32 DescriptorSize;

};
class CDecoderSpecificInfo : public CBaseDescriptor
{
public:
	CDecoderSpecificInfo()
		:CBaseDescriptor(DecSpecificInfoTag)
	{
	};


};
/*
abstract class QoS_Qualifier extends ExpandableBaseClass : bit(8) tag=0x01..0xff {
// empty. To be filled by classes extending this class.
}
*/
class QoS_Qualifier : public CBaseDescriptor{
public:
	QoS_Qualifier(){};
	QoS_Qualifier(m_u8 tag_par)
	{
		if(tag_par >= 0x01 && tag_par <= 0xff)
			CBaseDescriptor::tag = tag_par;
	};

};

class ExtensionDescriptor : public CBaseDescriptor
{
public:
	ExtensionDescriptor(){};
	ExtensionDescriptor(m_u8 tag_par)
	{
		if(tag_par >= ExtDescrTagStartRange && tag_par <= ExtDescrTagEndRange)

			CBaseDescriptor::tag = tag_par;
	};


};

class OCI_Descriptor : public CBaseDescriptor {
public:
	OCI_Descriptor();
	OCI_Descriptor(m_u8 tag_par)
	{
		if(tag_par >= OCIDescrTagStartRange && tag_par <= OCIDescrTagEndRange)

			CBaseDescriptor::tag = tag_par;
	};


};

/**********************************************************/

class IPI_DescrPointer : public CBaseDescriptor {
public:
	 IPI_DescrPointer()
		 :CBaseDescriptor(IPI_DescrPointerTag)
	 {
	 };
protected:
	m_u16	IPI_ES_Id;
};
/*
class IPMP_Descriptor() extends BaseDescriptor : m_u8 IPMP_DescrTag {
m_u8 IPMP_DescriptorID;
unsigned int(16) IPMPS_Type;
if (IPMPS_Type == 0) {
m_u8 URLString[sizeOfInstance-3];
} else {
m_u8 IPMP_data[sizeOfInstance-3];
}
}
*/

class IPMP_Descriptor : public CBaseDescriptor{
public:
	 IPMP_Descriptor()
		 :CBaseDescriptor(IPMP_DescrTag)
	 {
	 };
protected:
	m_u8	IPMP_DescriptorID;
	m_u16	IPMPS_Type;
	m_u8	URLString ;
	m_u8	IPMP_data[sizeOfInstance-3];

};

class IPMP_DescriptorPointer :public CBaseDescriptor
{
public:
	IPMP_DescriptorPointer()
		:CBaseDescriptor(IPMP_DescrPointerTag)
	{
	};
	m_u8 IPMP_DescriptorID;
};

class RegistrationDescriptor : public CBaseDescriptor {
public:
	RegistrationDescriptor()
		 :CBaseDescriptor(RegistrationDescrTag)
	 {
	 };
protected:
	m_u32 formatIdentifier;
	m_u8 additionalIdentificationInfo[sizeOfInstance-4];
};


class CSLConfigDescriptor : public CBaseDescriptor {
public:
	CSLConfigDescriptor()
		:CBaseDescriptor(SLConfigDescrTag)
	{
	};
	void ReadData(Byte_Stream &input_stream);

	~CSLConfigDescriptor();

protected:
	m_u8	predefined;
	m_bool	useAccessUnitStartFlag;
	m_bool	useAccessUnitEndFlag;
	m_bool	useRandomAccessPointFlag;
	m_bool	hasRandomAccessUnitsOnlyFlag;
	m_bool	usePaddingFlag;
	m_bool	useTimeStampsFlag;
	m_bool	useIdleFlag;
	m_bool	durationFlag;
	m_u32	timeStampResolution;
	m_u32	OCRResolution;
	m_u8	timeStampLength; // must be . 64
	m_u8	OCRLength; // must be . 64
	m_u8	AU_Length; // must be . 32
	m_u8	instantBitrateLength;
	m_u8	degradationPriorityLength;
	m_u8	AU_seqNumLength; // must be . 16
	m_u8	packetSeqNumLength; // must be . 16
	m_u8	 reserved ;

	m_u32 timeScale;
	m_u16 accessUnitDuration;
	m_u16 compositionUnitDuration;

	m_u32 startDecodingTimeStamp;
	m_u32 startCompositionTimeStamp;

	m_bool OCRstreamFlag;
	m_u16 OCR_ES_Id;
};

class QoS_Descriptor: public CBaseDescriptor
{
public:
	QoS_Descriptor()
		:CBaseDescriptor(QoS_DescrTag)
	{
		predefined =1;
	};
	void ReadData(Byte_Stream &input_stream)
	{
		predefined = input_stream.GetByte();
		if(predefined == 0)
		{
			//
		}
	};
protected:
	m_u8 predefined;
	QoS_Qualifier qualifiers[6];
};

class CAudioDecoderSpecificInfo
{
public:
	CAudioDecoderSpecificInfo() {};
	void ReadData(Byte_Stream &input_stream)
	{
		m_u32 temp =0;
		// Table 1.6.2 ISO/IEC 14496-3
		const m_u32 sample_rates[] =
		{
			96000, 88200, 64000, 48000, 44100, 32000,
			24000, 22050, 16000, 12000, 11025, 8000,7350
		};

		temp = input_stream.GetUINT();
		AudioObjectType = BitField(temp,27,5);
		samplingFrequencyIndex = BitField(temp,23,4);

		if(samplingFrequencyIndex == 0xf)
		{
			samplingFrequency =BitField(temp,0,23);
			temp = input_stream.GetByte();
			samplingFrequency <<= 1;
			samplingFrequency |= BitField(temp,7,1);
			channelConfiguration = BitField(temp,3,4);
		}
		else
		{
			channelConfiguration = BitField(temp,19,4);
			if(samplingFrequencyIndex <= 0xC)
				samplingFrequency = sample_rates[samplingFrequencyIndex];
		}
	}

	m_u8 AudioObjectType;
	m_u8 samplingFrequencyIndex;
	m_u32 samplingFrequency;
	m_u8 channelConfiguration;
};
class CDecoderConfigDescriptor : public CBaseDescriptor {
public:
	CDecoderConfigDescriptor()
		:CBaseDescriptor(DecoderConfigDescrTag)
	{
	};
	void ReadData(Byte_Stream &input_stream);

	~CDecoderConfigDescriptor();

protected:
	m_u8	objectTypeIndication;
	m_u8	streamType;
	m_bool	upStream;
	m_bool reserved;
	m_u32	bufferSizeDB;
	m_u32	maxBitrate;
	m_u32	avgBitrate;
	CDecoderSpecificInfo VideoSpecificInfo;
	CAudioDecoderSpecificInfo AudioSpecificInfo;
};


class CES_Descriptor : public CBaseDescriptor {
public:
	CES_Descriptor()
		:CBaseDescriptor(ES_DescrTag)
	{
	};
	void ReadData(Byte_Stream &input_stream);

	~CES_Descriptor()
	{
		if(decConfigDescr)
			delete decConfigDescr;
		if(slConfigDescr)
			delete slConfigDescr;
	};

protected:
	m_u16	ES_ID;
	m_bool	streamDependenceFlag;
	m_bool URL_Flag;
	m_bool reserved;
	m_u8	URLlength;
	m_u8	*URLstring;
	m_u8	streamPriority;
	m_u16	dependsOn_ES_ID;


	CDecoderConfigDescriptor	*decConfigDescr;
	CSLConfigDescriptor			*slConfigDescr;
	IPI_DescrPointer			ipiPtr[1] ;
//	IP_IdentificationDataSet	ipIDS[255] ;
	IPMP_DescriptorPointer		ipmpDescrPtr[255];
//	LanguageDescriptor			langDescr[255] ;
	QoS_Descriptor				qosDescr[1] ;
	RegistrationDescriptor		regDescr[1] ;
	ExtensionDescriptor			ExtDescrList[255];


};


class CObjectDescriptor : public CBaseDescriptor
{
public:
	CObjectDescriptor()
		:CBaseDescriptor(ObjectDescrTag)
	{
	};
	void ReadData(Byte_Stream &input_stream);
	~CObjectDescriptor()
	{
		while(esd_cnt > 0)
			delete CESDescriptorList[esd_cnt--];
	};

protected:
	m_u16	ObjectDescriptorID;
	m_bool	URL_Flag;
	m_u8	reserved;
	m_u8	URLlength;
	m_u8	*URLstring;
	int		esd_cnt;

	CES_Descriptor				*CESDescriptorList[30] ;
	OCI_Descriptor				OCIDescrList[255] ;
	IPMP_DescriptorPointer		IPMPDescrPtrList[255] ;
	ExtensionDescriptor			ExtDescrList[255];
};

class CInitialObjectDescriptor : public CBaseDescriptor {
public:
	CInitialObjectDescriptor()
		:CBaseDescriptor(InitialObjectDescrTag)
	{
	};
	void ReadData(Byte_Stream &input_stream);


private:
	m_u16	ObjectDescriptorID;
	m_bool	URL_Flag;
	m_u8	reserved;
	m_u8	URLlength;
	m_u8	*URLstring;
	int		esd_cnt;

	CES_Descriptor				*CESDescriptorList[30] ;
	OCI_Descriptor				OCIDescrList[255] ;
	IPMP_DescriptorPointer		IPMPDescrPtrList[255] ;
	ExtensionDescriptor			ExtDescrList[255];

	m_bool	includeInlineProfileLevelFlag;
	m_u8	ODProfileLevelIndication;
	m_u8	sceneProfileLevelIndication;
	m_u8	audioProfileLevelIndication;
	m_u8	visualProfileLevelIndication;
	m_u8	graphicsProfileLevelIndication;


};



#endif /* !__PARSE_MP4_H */

⌨️ 快捷键说明

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