📄 cmpeg2controller.cpp
字号:
//
// CMpegController.cpp
//
//#define GLOBAL // modified by djhuang
extern "C"
{
#include "C\getbit.h"
#include "C\smartcache.h"
#include "C\config.h"
//#include "C\inttypes.h"
#include "C\mpeg2.h"
//#include "C\mpeg2_internal.h"
}
extern "C" void InitSystem(void);
extern "C" void UninitSystem(void);
extern "C" void ResetSystem(void);
extern "C" void CheckSequenceHeader(void);
#include "CMpeg2Controller.h"
////////////////////////////////////////////////////////////////////////////
CMpeg2Controller::CMpeg2Controller()
{
}
CMpeg2Controller::~CMpeg2Controller()
{
}
bool CMpeg2Controller::Initialize(void)
{
InitSmartCache(); // Initialize smart cache
// InitSystem(); // Init decoder system
mpeg2dec=mpeg2_init();
return true;
}
void CMpeg2Controller::Uninitialize(void)
{
// UninitSystem(); // Release decoder buffer
// mpeg2_close (mpeg2dec);
ReleaseSmartCache(); // Release smart cache
}
// RGB24: 1
// YUY2: 2
void CMpeg2Controller::SetOutputType(int inType)
{
Store_Flag = inType;
}
void CMpeg2Controller::SetOutputImageSize(long inImageSize)
{
mOutputImageSize = inImageSize;
}
void CMpeg2Controller::BeginFlush(void)
{
Fault_Flag = ERROR_FLUSH; // Give a chance to exit decoding cycle
BeginFlushSmartCache();
Sleep(10);
}
void CMpeg2Controller::EndFlush(void)
{
// Confirm currently NOT in decoding cycle
/* int waitingCounter = 0;
while (gIsPictureDecoding && waitingCounter < 10)
{
waitingCounter++;
Sleep(1);
}*/
Fault_Flag = 0;
EndFlushSmartCache();
// ResetSystem();
}
void CMpeg2Controller::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 CMpeg2Controller::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 CMpeg2Controller::FlushAllPending(void)
{
Fault_Flag = ERROR_FLUSH;
BeginFlushSmartCache();
Sleep(10);
EndFlushSmartCache();
Fault_Flag = 0;
}
bool CMpeg2Controller::ReceiveMpeg(unsigned char * inData, long inLength)
{
long pass = ReceiveToSmartCache(inData, inLength);
return pass > 0 ? true : false;
}
void CMpeg2Controller::GetDecoded(unsigned char * outPicture)
{
// FinalDecodedOut(outPicture);
if (Store_Flag == STORE_YUY2)
{
if(framenum==0)
memcpy(outPicture, 0, mOutputImageSize);
else
memcpy(outPicture, info->current_fbuf->buf[1],
/*info->current_fbuf->id */ mOutputImageSize);
framenum ++;
}
else
{
// memcpy(outPicture, rgb24, mOutputImageSize);
}
}
BOOL CMpeg2Controller::IsCacheInputWaiting(void)
{
return CheckInputWaiting();
}
BOOL CMpeg2Controller::IsCacheOutputWaiting(void)
{
return CheckOutputWaiting();
}
BOOL CMpeg2Controller::IsCacheEmpty(void)
{
return GetAvailableInSmartCache() > 0 ? FALSE : TRUE;
}
void CMpeg2Controller::SequenceHeaderChecking(void)
{
// CheckSequenceHeader();
}
BOOL CMpeg2Controller::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 CMpeg2Controller::DecodeOnePicture(void)
{
/* if (Decode_Picture())
//if (Decode_Bitstream())
//if(1)
{
return TRUE;
}
*/ return FALSE;
}
void CMpeg2Controller::GetBytes(void)
{
int readsize = BUFFER_SIZE;
{
if (gIsEOS)
{
int available = GetAvailableInSmartCache();
if (available == 0)
{
// Force to exit from decoding cycle
Fault_Flag = ERROR_FLUSH;
}
if (available < BUFFER_SIZE)
{
readsize = available;
}
}
Read = FetchDataFromSmartCache(Rdbfr, BUFFER_SIZE);
Rdptr = Rdbfr;
Rdmax = Rdbfr + Read;
}
}
BOOL CMpeg2Controller::Decode_Mpeg2(void)
{
BOOL pass= My_decode_mpeg2(Rdptr,Rdmax);
return pass;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -