📄 splitter.cpp
字号:
/***********************************************************************/
/* splitter.cpp : Implementation of Memory Manager Splitter
* REALmagic Quasar Hardware Library
* Created by Kevin Vo
* Copyright Sigma Designs Inc
* Sigma Designs Proprietary and confidential
* Created on 4/20/01
* Description: Splitter will receive a loaded buffer. It then processes
* (parses) the buffer and sends the packet to the hardware.
/************************************************************************/
/****h* MMDemux/Splitter
* NAME
* Splitter
* COPYRIGHT
* Copyright 2000 Sigma Designs Inc.
* 355 Fairview Way, Milpitas, CA 95035-3024 USA. All Rights Reserved.
* Sigma Designs Proprietary and Confidential
/*************************************************************************/
#include "pch.h"
#include "manager.h"
#include "splitter.h"
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::Splitter
* USAGE
* Splitter(MemManager *pMemManager)
* DESCRIPTION
* Splitter constructor. It will initialize all the default values and set
* a pointer to the Memory Manager. Default audio type is MPEG1. If it is other
* than this, user needs to call SetAutioType function.
* PARAMETERS
* MemManager *pMemManager - A pointer to the Memory Manager. Splitter uses this
* to get the MediaSample.
* RETURN VALUE
* None.
/**********************************************************************/
Splitter::Splitter(MemManager *pMemManager)
{
m_iFileType = FT_UNKNOWN;
m_bAudioType = MM_AUDIO_FORMAT_MPEG1;
m_bFastForward = FALSE;
m_wTSPlayProgram = 1;
m_wAudioChannelPlay = 1;
m_wVideoChannelPlay = 1;
m_pBitParser = 0;
m_pMemManager = pMemManager;
m_bStop = FALSE;
m_bMMCreated = FALSE;
}
/////////////////////////////////////////////////////////////////////////////
Splitter::Splitter(int freeBufferSize, int mediaSampleSize, unsigned long dwBufferSize)
{
m_iFileType = FT_UNKNOWN;
m_bAudioType = MM_AUDIO_FORMAT_MPEG1;
m_bFastForward = FALSE;
m_wTSPlayProgram = 1;
m_wAudioChannelPlay = 1;
m_wVideoChannelPlay = 1;
m_pBitParser = 0;
m_pMemManager = new MemManager(freeBufferSize, mediaSampleSize, dwBufferSize);
m_bStop = FALSE;
m_bMMCreated = TRUE;
}
/////////////////////////////////////////////////////////////////////////////
Splitter::Splitter(unsigned char* buffer, unsigned long dwBufferSize)
{
m_iFileType = FT_UNKNOWN;
m_bAudioType = MM_AUDIO_FORMAT_MPEG1;
m_bFastForward = FALSE;
m_wTSPlayProgram = 1;
m_wAudioChannelPlay = 1;
m_wVideoChannelPlay = 1;
m_pBitParser = 0;
m_pMemManager = new MemManager(buffer, dwBufferSize);
m_bStop = FALSE;
m_bMMCreated = TRUE;
}
/////////////////////////////////////////////////////////////////////////////
Splitter::~Splitter()
{
if (m_pBitParser)
{
m_pBitParser->StopDemux();
delete m_pBitParser;
}
if (m_bMMCreated)
delete m_pMemManager;
}
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::SetAudioType
* USAGE
* void SetAudioType (MM_AUDIO_FORMAT gAudioType)
* DESCRIPTION
* Sets the audio type.
* PARAMETERS
* MM_AUDIO_FORMAT bAudioType - The audio type can be one of the followings:
* - MM_MEDIASUBTYPE_MPEG1Payload
* - MM_MEDIASUBTYPE_DOLBY_AC3
* - MM_MEDIASUBTYPE_PCM
* - MM_MEDIASUBTYPE_DTS
* RETURN VALUE
* None
* NOTES
* If using with COM Interface, MM_AUDIO_FORMAT has format as GUID.
* Else, MM_AUDIO_FORMAT has format as INT.
/**********************************************************************/
void Splitter::SetAudioType (MM_AUDIO_FORMAT gAudioType)
{
if (gAudioType == MM_MEDIASUBTYPE_MPEG1Payload)
m_bAudioType = MM_AUDIO_FORMAT_MPEG1;
else if (gAudioType == MM_MEDIASUBTYPE_DOLBY_AC3)
m_bAudioType = MM_AUDIO_FORMAT_AC3;
else if (gAudioType == MM_MEDIASUBTYPE_PCM)
m_bAudioType = MM_AUDIO_FORMAT_PCM;
else if (gAudioType == MM_MEDIASUBTYPE_DTS)
m_bAudioType = MM_AUDIO_FORMAT_DTS;
if (m_pBitParser)
m_pBitParser->SetAudioType(m_bAudioType);
}
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::SetFastForward
* USAGE
* void SetFastForward (BOOL bVal)
* DESCRIPTION
* Toggles the Fast Forward mode.
* PARAMETERS
* BOOL bVal - TRUE to enable FF, FALSE to disable FF.
* RETURN VALUE
* None
/**********************************************************************/
void Splitter::SetFastForward(BOOL bVal)
{
m_bFastForward = bVal;
switch (m_iFileType)
{
case FT_MPEG2_SYSTEM:
m_pBitParser->SetFastForward(bVal);
break;
}
}
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::SetFileType
* USAGE
* void SetFileType(int iFileType)
* void SetStreamType(int iStreamType)
* DESCRIPTION
* Sets the stream type. If not called, the splitter is still able to determine
* the stream type by itself.
* PARAMETERS
* One of the followings:
* int iFileType - FT_MPEG_VIDEO
- FT_MPEG_AUDIO
- FT_MPEG_SYSTEM
- FT_MPEG2_SYSTEM
- FT_MPEG2_TRANSPORT
- FT_AC3_AUDIO
- FT_PES
- FT_MPEG4_VIDEO
* RETURN VALUE
* None
/**********************************************************************/
BOOL Splitter::SetFileType(INT iFileType)
{
if (m_pBitParser)
{
m_pBitParser->StopDemux();
delete m_pBitParser;
m_pBitParser = 0;
}
m_bStop = FALSE;
m_iFileType = iFileType;
switch (m_iFileType)
{
case FT_PES:
m_pBitParser = new CMpeg2Pes(m_pMemManager);
break;
case FT_MPEG_SYSTEM:
m_pBitParser = new CMpeg1(m_pMemManager);
break;
case FT_MPEG2_SYSTEM:
m_pBitParser = new CMpeg2(m_pMemManager);
break;
case FT_MPEG2_TRANSPORT:
m_pBitParser = new CMpeg2Transport(m_pMemManager);
m_pBitParser->SetTransport(TRUE);
((CMpeg2Transport*)m_pBitParser)->SetPlayProgram(m_wTSPlayProgram);
break;
case FT_MPEG_AUDIO:
case FT_AC3_AUDIO:
case FT_DTS_AUDIO:
m_pBitParser = new CMpegAudio(m_pMemManager);
break;
case FT_MPEG_VIDEO:
case FT_MPEG4_VIDEO:
m_pBitParser = new CMpegVideo(m_pMemManager);
break;
default:
return FALSE;
}
m_pBitParser->SetAudioType(m_bAudioType);
m_pBitParser->SetPlayAudioChannel(m_wAudioChannelPlay);
m_pBitParser->SetPlayVideoChannel(m_wVideoChannelPlay);
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
void Splitter::SetStreamType(INT iStreamType)
{
SetFileType(iStreamType);
}
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::SetTSPlayProgram
* USAGE
* void SetTSPlayProgram(WORD wProgram)
* DESCRIPTION
* Selects which transport program to play.
* PARAMETERS
* WORD wProgram - Order of program to play. If there are 2 programs then wProgram
* can be 1 or 2.
* RETURN VALUE
* None
/**********************************************************************/
void Splitter::SetTSPlayProgram(WORD wProgram)
{
m_wTSPlayProgram = wProgram;
}
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::SetPlayAudioChannel
* USAGE
* void SetPlayAudioChannel(WORD wAudio)
* DESCRIPTION
* Selects which audio channel to play
* PARAMETERS
* WORD wAudio - Order of audio channel to play. If there are 2 audio channels then
* wAudio can be 1 or 2.
* RETURN VALUE
* None
/**********************************************************************/
void Splitter::SetPlayAudioChannel(WORD wAudio)
{
m_wAudioChannelPlay = wAudio;
}
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::SetPlayVideoChannel
* USAGE
* void SetPlayVideoChannel(WORD wVideo)
* DESCRIPTION
* Selects which video channel to play
* PARAMETERS
* WORD wAudio - Order of video channel to play. If there are 2 video channels then
* wVideo can be 1 or 2.
* RETURN VALUE
* None
/**********************************************************************/
void Splitter::SetPlayVideoChannel(WORD wVideo)
{
m_wVideoChannelPlay = wVideo;
}
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::StopDemux
* USAGE
* StopDemux ()
* DESCRIPTION
* Set the flag to signal the splitter to stop sending data to hardware. The
* SetMediaSampleParameters function will check for the flag before it attempts
* to send data to the hardware. It will reset the stream type.
* PARAMETERS
* None
* RETURN VALUE
* None
/**********************************************************************/
void Splitter::StopDemux (void)
{
if (m_bStop != TRUE)
{
m_bStop = TRUE;
if (m_pBitParser)
m_pBitParser->StopDemux();
}
m_iFileType = FT_UNKNOWN;
}
/////////////////////////////////////////////////////////////////////////////
void Splitter::ResetDemux()
{
if (m_pBitParser)
m_pBitParser->ResetDemux();
m_bStop = FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Identify the file type and initialize the appropriate demux object
BOOL Splitter::Initialize(const BYTE *pBuffer, DWORD dwLength)
{
if (IsPESFile(pBuffer, dwLength))
m_iFileType = FT_PES;
else
m_iFileType = IdentifyHeader(pBuffer, dwLength);
return SetFileType(m_iFileType);
}
/////////////////////////////////////////////////////////////////////////////
/****f* MMDemux/Splitter::Receiver
* USAGE
* int Receiver(CBuffer *pBuffer)
* DESCRIPTION
* Receives a buffer loaded with data read from file or any other sources. It then
* calls the appropriate stream parser to parse the buffer to get audio/video packets.
* PARAMETERS
* CBuffer *pBuffer - A pointer to the CBuffer which contains loaded data from
* from file and its buffer size.
* RETURN VALUE
* SUCCESS_DEMUX if the Splitter successfully demuxed the buffer.
* STOP_DEMUX if StopDemux is called.
/**********************************************************************/
int Splitter::Receiver(CBuffer *pCBuffer)
{
if (pCBuffer != NULL)
{
if (m_bStop)
goto stop_demux;
if (m_iFileType == FT_UNKNOWN)
{
if (!Initialize((BYTE*)pCBuffer->GetBuffer(), pCBuffer->GetActualSize()))
goto stop_demux;
}
return m_pBitParser->Process(pCBuffer);
}
else
{
MmDebugLogfile((MmDebugLevelLog, "Receiver(), buffer is null"));
return STOP_DEMUX;
}
stop_demux:
pCBuffer->Release();
return STOP_DEMUX;
}
////////////////////////////////////////////////////////////////////
CBuffer* Splitter::GetBuffer()
{
return m_pMemManager->GetBuffer();
}
////////////////////////////////////////////////////////////////////
void Splitter::WaitForFilledBufferEmpty()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -