📄 cdemux.cpp
字号:
*
* @verified
* Yes.
*/
BOOLEAN cDemux::AttachInputStream( DEMUXIOSTREAM *pInputStream )
{
/* Verify the given cStream object pointer */
if (pInputStream == NULL )
{
DbgPrint(("DEMUX: Input stream pointer is NULL!\n"));
return DEMUX_FAIL;
}
/* Assign the given cStream object pointer as the input pin of the demux */
tDemuxConfigInfo.tInputPin = pInputStream;
DBGPRINT(DBG_ON(DBG_TRACE), ("cDemux::AttachInputStream() -- 0x%08x\n", (int)tDemuxConfigInfo.tInputPin));
/* Return successfully */
return (DEMUX_PASS);
}
/**
* Detach Input Stream function. Detaches the previously attached cStream
* object from the demux.
*
* @param
* None.
*
* @retval
* DEMUX_PASS - if successful
* DEMUX_FAIL - if not successful
*
* @remark
* This function still needs some clean up work.
*
* @verified
* No.
*/
BOOLEAN cDemux::DetachInputStream( void )
{
DBGPRINT(DBG_ON(DBG_TRACE), ("cDemux::DetachInputStream() -- 0x%08x\n", (int)tDemuxConfigInfo.tInputPin));
/* cannot detach the input stream while the demux is running */
DbgAssert(tDemuxConfigInfo.ulDemuxState != DEMUX_STARTED);
/* if the demux is stopping wait for it to complete */
while (tDemuxConfigInfo.ulDemuxState == DEMUX_STOPPING)
{
OS_TaskDelay(OS_WAIT_1S/10);
}
/* Set the input pin pointer to NULL */
tDemuxConfigInfo.tInputPin = NULL;
/* Return successfully */
return (DEMUX_PASS);
}
/**
* Attach Output Stream function. Configures the demux to send the payload data
* of an input stream with the given PES_ID and SUB_ID combination to the
* given cStream object.
*
* @param
* BYTE bPesID - Stream ID to associate with the given destination
* stream object.
*
* @param
* BYTE bSubID - Sub-Stream ID to associate with the given destination
* stream object.
*
* @param
* DEMUXIOSTREAM *pOutputStream - Stream object to send payload data to when
* a stream is found with the given PES_ID and
* SUB_ID combination.
*
* @retval
* DEMUX_PASS - if successful
* DEMUX_FAIL - if not successful
*
* @remark
* None.
*
* @verified
* Yes.
*/
BOOLEAN cDemux::AttachOutputStream(BYTE bPesID,
BYTE bSubID,
DEMUX_TIMESTAMP_TYPE tTimeType,
OUTPUT_STREAM_TYPE tStreamType,
DEMUXIOSTREAM *pOutputStream
)
{
int iOutputPinCount;
/* Initialization */
iOutputPinCount = tDemuxConfigInfo.iOutputPinCount;
/* Make sure the maximum number of output pins have not already been assigned */
if (iOutputPinCount == OUTPUT_STREAM_MAX_COUNT)
{
DbgPrint(("DEMUX: Maximum number of output pins have been assigned!\n"));
return DEMUX_FAIL;
}
/* Verify the given cStream object pointer */
if (pOutputStream == NULL)
{
DbgPrint(("DEMUX: Output stream pointer is NULL!\n"));
return DEMUX_FAIL;
}
/* take sem to make sure pin info doesn't change in the middle
* of an update in the worker thread */
OS_SemTake(tDemuxConfigInfo.semPinUpdate, OS_WAIT_FOREVER);
/* Assign the given output pin */
tDemuxConfigInfo.tOutputPin[iOutputPinCount].bPesID = bPesID;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].bSubID = bSubID;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].fFirstPayload = TRUE;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].tTimeType = tTimeType;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].tStreamType = tStreamType;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].pDestStream = pOutputStream;
#ifdef __DEMUX_TS_SUPPORT__
tDemuxConfigInfo.tOutputPin[iOutputPinCount].wPID = (SHORT)(INVALID_PID);
#endif
DBGPRINT(DBG_ON(DBG_TRACE), ("cDemux::AttachOutputStream(): bPesID=%x, bSubID=%x\n",
tDemuxConfigInfo.tOutputPin[iOutputPinCount].bPesID, tDemuxConfigInfo.tOutputPin[iOutputPinCount].bSubID));
/* Increment the number of demux output pins */
tDemuxConfigInfo.iOutputPinCount++;
/* Inform other tasks via this variable that the output pins changed */
tDemuxConfigInfo.fUpdateOutputPins = TRUE;
OS_SemGive(tDemuxConfigInfo.semPinUpdate);
/* Return successfully */
return DEMUX_PASS;
}
#ifdef __DEMUX_TS_SUPPORT__
/**
* Attach Output PID Stream function. Configures the Demux to send the payload
* data of an input stream with the given PID
*
* @param
* WORD wPID - PID to associate with the given destination
* stream object.
*
* @param
* DEMUXIOSTREAM *pOutputStream - Stream object to send payload data to
* when a stream is found with the given
* PES_ID and SUB_ID combination.
*
* @retval
* DEMUX_PASS - if successful
* DEMUX_FAIL - if not successful
*/
BOOLEAN cDemux::AttachOutputPIDStream(SHORT wPID,
DEMUX_TIMESTAMP_TYPE tTimeType,
OUTPUT_STREAM_TYPE tStreamType,
DEMUXIOSTREAM *pOutputStream
)
{
int iOutputPinCount;
/* Initialization */
iOutputPinCount = tDemuxConfigInfo.iOutputPinCount;
/* Make sure the maximum number of output pins have not already been assigned */
if (iOutputPinCount == OUTPUT_STREAM_MAX_COUNT)
{
DbgPrint(("DEMUX: Maximum number of output pins have been assigned!\n"));
return DEMUX_FAIL;
}
/* Verify the given cStream object pointer */
if (pOutputStream == NULL)
{
DbgPrint(("DEMUX: Output stream pointer is NULL!\n"));
return DEMUX_FAIL;
}
/* take sem to make sure pin info doesn't change in the middle
* of an update in the worker thread */
OS_SemTake(tDemuxConfigInfo.semPinUpdate, OS_WAIT_FOREVER);
/* Assign the given output pin */
tDemuxConfigInfo.tOutputPin[iOutputPinCount].bPesID = 0x00;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].bSubID = NO_SUB_ID;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].fFirstPayload = TRUE;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].wPID = wPID;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].tTimeType = tTimeType;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].tStreamType = tStreamType;
tDemuxConfigInfo.tOutputPin[iOutputPinCount].pDestStream = pOutputStream;
DBGPRINT(DBG_ON(DBG_TRACE), ("cDemux::AttachOutputPIDStream:%d 0x%08x\n", tDemuxConfigInfo.iOutputPinCount, (int)pOutputStream));
/* Increment the number of demux output pins */
tDemuxConfigInfo.iOutputPinCount++;
/* Inform other tasks via this variable that the output pins changed */
tDemuxConfigInfo.fUpdateOutputPins = TRUE;
OS_SemGive(tDemuxConfigInfo.semPinUpdate);
/* Return successfully */
return DEMUX_PASS;
}
#endif
/**
* Detach Output Stream function. Detaches the given output stream from the Demux.
*
* @param
* DEMUXIOSTREAM *pOutputStream - Stream object to detach from the Demux
*
* @retval
* DEMUX_PASS - if successful
* DEMUX_FAIL - if not successful
*
* @remark
* None.
*
* @verified
* No.
*/
BOOLEAN cDemux::DetachOutputStream( DEMUXIOSTREAM *pOutputStream )
{
BOOLEAN fRetVal = DEMUX_FAIL;
/* take sem to make sure pin info doesn't change in the middle
* of an update in the worker thread */
OS_SemTake(tDemuxConfigInfo.semPinUpdate, OS_WAIT_FOREVER);
/* Locate the output stream to be detached and detach it */
for (int i = 0; i < tDemuxConfigInfo.iOutputPinCount; i++)
{
if (fRetVal == DEMUX_FAIL)
{
/* find the stream we want to remove */
if (tDemuxConfigInfo.tOutputPin[i].pDestStream == pOutputStream)
{
DBGPRINT(DBG_ON(DBG_TRACE), ("cDemux::DetachOutputStream(): bPesID=%x, bSubID=%x\n",
tDemuxConfigInfo.tOutputPin[i].bPesID, tDemuxConfigInfo.tOutputPin[i].bSubID));
tDemuxConfigInfo.tOutputPin[i].bPesID = 0x00;
tDemuxConfigInfo.tOutputPin[i].bSubID = NO_SUB_ID;
tDemuxConfigInfo.tOutputPin[i].tTimeType = DEMUX_ANY;
tDemuxConfigInfo.tOutputPin[i].tStreamType = UNDEFINED;
tDemuxConfigInfo.tOutputPin[i].pDestStream = NULL;
#ifdef __DEMUX_TS_SUPPORT__
tDemuxConfigInfo.tOutputPin[i].wPID = (SHORT)(INVALID_PID);
#endif
fRetVal = DEMUX_PASS;
}
}
else
{
/* We've removed a demux. If it was not at the end of the list we need to shift the
* remaining streams down one */
tDemuxConfigInfo.tOutputPin[i-1].bPesID = tDemuxConfigInfo.tOutputPin[i].bPesID;
tDemuxConfigInfo.tOutputPin[i-1].bSubID = tDemuxConfigInfo.tOutputPin[i].bSubID;
tDemuxConfigInfo.tOutputPin[i-1].fFirstPayload = tDemuxConfigInfo.tOutputPin[i].fFirstPayload;;
tDemuxConfigInfo.tOutputPin[i-1].tTimeType = tDemuxConfigInfo.tOutputPin[i].tTimeType;
tDemuxConfigInfo.tOutputPin[i-1].tStreamType = tDemuxConfigInfo.tOutputPin[i].tStreamType;
tDemuxConfigInfo.tOutputPin[i-1].pDestStream = tDemuxConfigInfo.tOutputPin[i].pDestStream;
#ifdef __DEMUX_TS_SUPPORT__
tDemuxConfigInfo.tOutputPin[i-1].wPID = tDemuxConfigInfo.tOutputPin[i].wPID;
#endif
/* invalidate the old entry */
tDemuxConfigInfo.tOutputPin[i].bPesID = 0x00;
tDemuxConfigInfo.tOutputPin[i].bSubID = NO_SUB_ID;
tDemuxConfigInfo.tOutputPin[i].tTimeType = DEMUX_ANY;
tDemuxConfigInfo.tOutputPin[i].tStreamType = UNDEFINED;
tDemuxConfigInfo.tOutputPin[i].pDestStream = NULL;
#ifdef __DEMUX_TS_SUPPORT__
tDemuxConfigInfo.tOutputPin[i].wPID = (SHORT)(INVALID_PID);
#endif
}
}
/* If the output stream was located, decrement the number of output pins */
if (fRetVal == DEMUX_PASS)
{
tDemuxConfigInfo.iOutputPinCount--;
// Inform other tasks via this variable that the output pins changed
tDemuxConfigInfo.fUpdateOutputPins = TRUE;
}
OS_SemGive(tDemuxConfigInfo.semPinUpdate);
/* Return status */
return (fRetVal);
}
/**
* Get Status function. Returns the number of Demux errors.
*
* @param
* None.
*
* @retval
* ULONG ulRet - Number of demux errors
*
* @verified
* Yes.
*/
ULONG cDemux::DemuxGetStatus( void )
{
ULONG ulRet = 0;
if (0 != iDemuxThreadID)
{
switch (tCurrentType)
{
case DEMUX_MPEG1:
case DEMUX_MPEG2:
ulRet = MPEGDemuxGetErrorCnt();
break;
#ifdef __DEMUX_TS_SUPPORT__
case DEMUX_TRANSPORT:
ulRet = MPEG2TSDemuxGetErrorCnt();
break;
#endif
#ifdef __DEMUX_MP3_SUPPORT__
case DEMUX_MP3:
ulRet = MP3DemuxGetErrorCnt();
break;
#endif
default:
ulRet = 0;
break;
}
}
return (ulRet);
}
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
DEMUX_STREAM_TYPE cDemux::DemuxGetType( void )
{
return (tCurrentType);
}
#if ENABLE_DEMUX_REMAP_FEATURE
/**
* Remap Stream function. Remaps the specified stream/substream pair as per the
* following guidelines:
*
* 1.) If the stream ID is not tagged for remap, the corresponding
* sub-stream ID will not be remapped.
* 2.) If bInStreamSubID = bOutStreamSubID = NO_SUB_ID, then only the
* stream ID is remapped.
* 3.) If bInStreamSubID = NO_SUB_ID, then all sub-stream IDs are
* remapped regardless of what they are.
*
* @param
* BYTE bInStreamID - Input stream ID to be remapped.
*
* @param
* BYTE bInStreamSubID - Input sub-stream ID to be remapped.
*
* @param
* BYTE bOutStreamID - Value to be used when remapping the specified
* input stream ID.
*
* @param
* BYTE bOutStreamSubID - Value to be used when remapping the specified
* input sub-stream ID.
*
* @retval
* DEMUX_PASS - if successful
* DEMUX_FAIL - if not successful
*
* @verified
* No.
*/
BOOLEAN cDemux::RemapStream(BYTE bInStreamID,
BYTE bInStreamSubID,
BYTE bOutStreamID,
BYTE bOutStreamSubID
)
{
tDemuxConfigInfo.bRemapStreamID = bInStreamID;
tDemuxConfigInfo.bRemapSubStreamID = bInStreamSubID;
tDemuxConfigInfo.bRemapStreamIDValue = bOutStreamID;
tDemuxConfigInfo.bRemapSubStreamIDValue = bOutStreamSubID;
tDemuxConfigInfo.fUpdateRemap = TRUE;
return (DEMUX_PASS);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -