demuxer.h 2.72 KB
/*******************************************************}
{                                                       }
{       File: demuxer.h                                 }
{       Created by Tsviatko Jongov                      }
{       http://tsviatko.jongov.com                      }
{       Date : 25.01.2007                               }
{                                                       }
{       CMpeg2Demux class.                              }
{                                                       }
{*******************************************************/
#include <stdint.h>
#include "buffer.h"

//MPEG-2 start codes
#define SYSTEM_START_CODE_MIN     0x000001B9
#define SYSTEM_START_CODE_MAX     0x000001FF
#define PACK_START_CODE           0x000001BA
#define SYSTEM_START_CODE         0x000001BB

//MPEG-2 stream IDs
#define PROGRAM_STREAM_MAP        0xBC
#define PADDING_STREAM            0xBE
#define PRIVATE_STREAM_2          0xBF
#define ECM_STREAM                0xF0
#define EMM_STREAM                0xF1
#define PROGRAM_STREAM_DIRECTORY  0xFF
#define DSM_CC_STREAM             0xF2
#define ITU_T_STREAM_E            0xF8

#define STREAM_TYPE_VIDEO         1
#define STREAM_TYPE_AUDIO         2


#define	STREAM_TYPE_UNKNOWN			0x00
#define	VIDEO_TYPE_MPEG4			0x01
#define	VIDEO_TYPE_H264				0x1B
#define	VIDEO_TYPE_H265				0x24
#define	VIDEO_TYPE_SVAC				0x80
#define	AUDIO_TYPE_G711				0x90
#define	AUDIO_TYPE_G722_1			0x92
#define	AUDIO_TYPE_G723_1			0x93
#define	AUDIO_TYPE_G729				0x99
#define	AUDIO_TYPE_SVAC				0x9B
//#include <BaseTsd.h>

//typedef long long INT64;
//typedef unsigned long long UINT64;

typedef int ReceiveFunction(unsigned char streamType, void* data, int size, uint64_t pts, uint64_t localPts, bool bKey, void* userData);//es»Øµ÷
typedef int ReceiveFunction2(unsigned int streamtype, void * Data, int Size, uint64_t pts, bool iskeyfram, void* userdata);//ps»Øµ÷

static /*_inline*/ unsigned int asm_swap32(unsigned int x); 
static /*_inline*/ unsigned short asm_swap16(unsigned short x);

class CMpeg2Demux {
private:
	CBuffer * fBuffer; 
	void*     m_userdata;
	void*     m_userdata2;
	ReceiveFunction * fReceiveFunction;
	ReceiveFunction2* fReceiveFunction2;
//	CBuffer* m_frambuf;
	CBuffer* m_psvideo;
	CBuffer* m_esvideo;
	CBuffer* m_psaudio;
	CBuffer* m_esaudio;
	uint64_t m_lastpts;
	bool     m_lastiskeyfram;
	unsigned char	m_streamType;
	int m_pserror = 0;
	int Demultiplex();

	/*DWORD    m_timeStamp;*/
public:
	CMpeg2Demux();
	~CMpeg2Demux();
	int AddData(void * Data, int Size/*, DWORD pts*/);
	void SetReceiveFunction(ReceiveFunction * func, void* userdata);
	void SetReceiveFunction2(ReceiveFunction2 * func2, void* userdata2);
};