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

📄 cmpegcontroller.cpp

📁 DIRECTSHOW 开发指南电子书
💻 CPP
字号:
//
// CMpegController.cpp
//

#define GLOBAL
extern "C"
{
#include "global.h"
#include "getbit.h"
#include "smartcache.h"
}

extern "C" void InitSystem(void);
extern "C" void UninitSystem(void);
extern "C" void ResetSystem(void);
extern "C" void CheckSequenceHeader(void);

#include "CMpegController.h"

////////////////////////////////////////////////////////////////////////////
CMpegController::CMpegController()
{
}

CMpegController::~CMpegController()
{
}

bool CMpegController::Initialize(void)
{
	InitSmartCache();   // Initialize smart cache
	InitSystem();       // Init decoder system
	return true;
}

void CMpegController::Uninitialize(void)
{
	UninitSystem();      // Release decoder buffer	
	ReleaseSmartCache(); // Release smart cache
}

// RGB24: 1
// YUY2:  2
void CMpegController::SetOutputType(int inType)
{
	Store_Flag = inType;
}

void CMpegController::SetOutputImageSize(long inImageSize)
{
	mOutputImageSize = inImageSize;
}

void CMpegController::BeginFlush(void)
{
	Fault_Flag = ERROR_FLUSH;   // Give a chance to exit decoding cycle
	BeginFlushSmartCache();
	Sleep(10);
}

void CMpegController::EndFlush(void)
{
	// Confirm currently NOT in decoding cycle
/*	int waitingCounter = 0;
	while (gIsPictureDecoding && waitingCounter < 10) 
	{
		waitingCounter++;
		Sleep(1);
	}*/
	Fault_Flag = 0;
	EndFlushSmartCache();
//	ResetSystem();
}

void CMpegController::BeginEndOfStream(void)
{
	gIsEOS = TRUE;
	if (CheckOutputWaiting())
	{
		Fault_Flag = ERROR_FLUSH;
		BeginFlushSmartCache();
		// Confirm currently NOT in decoding cycle
/*		int waitingCounter = 0;
		while (gIsPictureDecoding && waitingCounter < 20) 
		{
			waitingCounter++;
			Sleep(1);
		}*/
		Sleep(10);
		EndFlushSmartCache();
	}
}

void CMpegController::EndEndOfStream(void)
{
//	Fault_Flag = ERROR_FLUSH;
//	BeginFlushSmartCache();
//	while (gIsPictureDecoding); // Confirm currently NOT in decoding cycle
//	EndFlushSmartCache();
	gIsEOS = FALSE;
}

// Just make sure that filter's receiving NOT block
void CMpegController::FlushAllPending(void)
{
	Fault_Flag = ERROR_FLUSH;
	BeginFlushSmartCache();
	Sleep(10);
	EndFlushSmartCache();
	Fault_Flag = 0;
}

bool CMpegController::ReceiveMpeg(unsigned char * inData, long inLength)
{
	long pass = ReceiveToSmartCache(inData, inLength);
	return pass > 0 ? true : false;
}

void CMpegController::GetDecoded(unsigned char * outPicture)
{
//	FinalDecodedOut(outPicture);
	if (Store_Flag == STORE_YUY2)
	{
		memcpy(outPicture, yuy2, mOutputImageSize);
	}
	else
	{
		memcpy(outPicture, rgb24, mOutputImageSize);
	}
}

BOOL CMpegController::IsCacheInputWaiting(void)
{
	return CheckInputWaiting();
}

BOOL CMpegController::IsCacheOutputWaiting(void)
{
	return CheckOutputWaiting();
}

BOOL CMpegController::IsCacheEmpty(void)
{
	return GetAvailableInSmartCache() > 0 ? FALSE : TRUE;
}

void CMpegController::SequenceHeaderChecking(void)
{
	CheckSequenceHeader();
}

BOOL CMpegController::LocatePictureHeader(void)
{
	if (Frame_Number == 0)
	{
		while (Get_Hdr() && picture_coding_type!=I_TYPE);
		if (picture_coding_type == I_TYPE)
		{
			return TRUE;
		}
	}
	else if (Frame_Number == 1)
	{
		while (Get_Hdr() && picture_coding_type==B_TYPE);
		if (picture_coding_type != B_TYPE)
		{
			return TRUE;
		}
	}
	else
	{
		if (Get_Hdr())
		{
			return TRUE;
		}
	}
	return FALSE;
}

BOOL CMpegController::DecodeOnePicture(void)
{
	if (Decode_Picture())
	{
		return TRUE;
	}
	return FALSE;
}

⌨️ 快捷键说明

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