// DLL export declaration
DllExport	void videoDecoderDllExportOpen();

DllExport	void videoDecoderStart(char *chrBitsFile, int &iDisplayWidth, int &iDisplayHeight, char *pBitstream, long lBitstreamLength);
DllExport	void videoDecoder(char *pBitstream, long lBitstreamLength);
DllExport	void videoDecoderEnd();

DllExport	int getDecConfigInfoBitstreams (char *pInBitstream, long lInBitsLength, char *&pOutBitstream, long &lOutBitsOffset, long &lOutBitsLength);
DllExport	int getVOLheaderBitstreams (char *pInBitstream, long lInBitsLength, char *&pOutBitstream, long &lOutBitsOffset, long &lOutBitsLength);
DllExport	int getOneVopBitstreams (char *pInBitstream, long lInBitsLength, char *&pOutBitstream, long &lOutBitsOffset, long &lOutBitsLength);

DllExport	unsigned char *getYframe();
DllExport	unsigned char *getUframe();
DllExport	unsigned char *getVframe();
DllExport	unsigned char *getBYframe();

DllExport	int getDecodingTime(int layer);
DllExport	int getVopType (int layer);
DllExport	int getDisplayWidth(int layer);
DllExport	int getDisplayHeight(int layer);

DllExport	bool isShapeUsed(int layer);	
DllExport	bool isVideoDecoderEnd();

DllExport	void videoDecoderDllExportClose();

//
void SeqPlayer(char *chrFileName, int width, int height)
{
	bool bVideoDecoderEnd = false;
	int iWidth=width;
	int iHeight=height;
	int iWidthUV=width/2;
	int iHeightUV=height/2;

	videoDecoderDllExportOpen(); // (1)

	FILE *fp=fopen(m_chrFileName,"rb");
	if(fp==NULL) {
		char temp[100];
		sprintf(temp, "File open error: %s", m_chrFileName);
		AfxMessageBox(temp);
		exit(1);
	}
	long lBitstreamOffset = 0;
	fseek (fp,0L,SEEK_END);
	long lBitstreamLength = ftell(fp);
	fseek (fp,0L,SEEK_SET);
	char *pBitstream=NULL;
	pBitstream = new char [lBitstreamLength+1];
	fread((char *)pBitstream, sizeof(char), lBitstreamLength, fp);
	fclose(fp);

	char *pDecConfigBitstream=NULL;
	long lDecConfigBitsOffset=0;
	long lDecConfigBitsLength=0;

	int check = getDecConfigInfoBitstreams (pBitstream, lBitstreamLength, pDecConfigBitstream, lDecConfigBitsOffset, lDecConfigBitsLength); // (2)
	if (check==EOF)
			AfxMessageBox("Error: getDecConfigInfoBitstreams()");
	videoDecoderStart(m_chrFileName, iWidth, iHeight, pDecConfigBitstream, lDecConfigBitsLength); // (3)
	assert(iWidth>=width && iHeight>=height);

	lBitstreamOffset = lDecConfigBitsOffset + lDecConfigBitsLength;

	char *pStartBitstream = pBitstream+lBitstreamOffset;
	long lStartLength = lBitstreamLength - lDecConfigBitsLength;
	while (!bVideoDecoderEnd) {
		char *pVopBitstream=NULL;
		long lVopBitsOffset=0;
		long lVopBitsLength=0;
		int check = getOneVopBitstreams (pStartBitstream, lStartLength, pVopBitstream, lVopBitsOffset, lVopBitsLength); // (4)
		if (check==EOF) {			
			break;
		}
		lBitstreamOffset += lVopBitsOffset + lVopBitsLength;
		videoDecoder(pVopBitstream, lVopBitsLength); // (5)
		unsigned char *pxlYframe = getYframe(); // (6)
		unsigned char *pxlUframe = getUframe(); // (7)
		unsigned char *pxlVframe = getVframe(); // (8)
		unsigned char *pxlBYframe = getBYframe(); // (9)
		bool bShapeUsage = isShapeUsed(0); // (10)

		/////////////////////
		// Display Routine //
		/////////////////////
		//bVideoDecoderEnd = m_pVideoDecoder->isVideoDecoderEnd();	
		pStartBitstream = pBitstream+lBitstreamOffset;
		lStartLength = lStartLength - lVopBitsLength;

		if(lStartLength==0) bVideoDecoderEnd=true;
	}

	videoDecoderEnd(); // (11)
	videoDecoderDllExportClose(); // (12)

	return;
}