📄 mpeg_tsdemux.cpp
字号:
/*****************************************************************************
******************************************************************************
** **
** Copyright (c) 2002 Videon Central, Inc. **
** All rights reserved. **
** **
** The computer program contained herein contains proprietary information **
** which is the property of Videon Central, Inc. The program may be used **
** and/or copied only with the written permission of Videon Central, Inc. **
** or in accordance with the terms and conditions stipulated in the **
** agreement/contract under which the programs have been supplied. **
** **
******************************************************************************
*****************************************************************************/
/**
* @file mpeg_tsdemux.cpp
*
* MPEG Transport Demux source file.
*
*/
#include <string.h>
#include "vdvd_types.h"
#include "osapi.h"
#include "msg_app.h"
#include "cDemux.h"
#include "mpeg_tsdemux.h"
#include "utility.h"
#include "mpgstruct.h"
#include "mpginfo.h"
#include "dbgprint.h"
#ifdef DMALLOC
#include "dmalloc.h"
#endif
/******************************************************************************
*******************************************************************************
** **
** MPEG Demux Debug Defines **
** **
*******************************************************************************
******************************************************************************/
#define MPEG_DEMUX_DEBUG_ON 0
/******************************************************************************
*******************************************************************************
** **
** MPEG Demux Private Variables **
** **
*******************************************************************************
******************************************************************************/
static TSDEMUXINFO tDemuxInfo;
static ULONG ulTSDemuxErrorCnt = 0;
/******************************************************************************
*******************************************************************************
** **
** MPEG Demux Forward Function Declarations **
** **
*******************************************************************************
******************************************************************************/
/******************************************************************************
*******************************************************************************
** **
** MPEG Demux Input Function **
** **
*******************************************************************************
******************************************************************************/
/******************************************************************************
*******************************************************************************
** **
** MPEG Demux Output Function **
** **
*******************************************************************************
******************************************************************************/
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
static void MPEG2TS_Send_PID( TSDEMUXINFO *configInfo )
{
BYTE *pbData;
ULONG ulSize;
pbData = (BYTE *)configInfo->pbPayload;
ulSize = configInfo->ulPayloadSize;
if( ulSize > 0 )
{
//Double check for the start condition
configInfo->tConfigInfo.tOutputPin[configInfo->wPIDIndex].fSendPayload |= configInfo->fPayloadUnitStart;
//Make sure that we start on a payload boundry
if( configInfo->tConfigInfo.tOutputPin[configInfo->wPIDIndex].fSendPayload == TRUE )
{
//Check for valid time stamps
switch( configInfo->tConfigInfo.tOutputPin[configInfo->wPIDIndex].tTimeType )
{
case DEMUX_DTS:
if( configInfo->fDtsExisted == TRUE )
{
configInfo->tConfigInfo.tOutputPin[configInfo->wPIDIndex].pDestStream->WritePTSDirect(configInfo->ulDTS);
configInfo->fDtsExisted = FALSE;
}
break;
case DEMUX_PTS:
case DEMUX_ANY:
if( configInfo->fPtsExisted == TRUE )
{
configInfo->tConfigInfo.tOutputPin[configInfo->wPIDIndex].pDestStream->WritePTSDirect(configInfo->ulPTS);
configInfo->fPtsExisted = FALSE;
}
break;
default:
break;
}
// Send the message to the output pin
configInfo->tConfigInfo.tOutputPin[configInfo->wPIDIndex].pDestStream->WriteDirect(pbData, ulSize);
}
}
}
/******************************************************************************
*******************************************************************************
** **
** MPEG Demux Debug Functions **
** **
*******************************************************************************
******************************************************************************/
/******************************************************************************
*******************************************************************************
** **
** MPEG Demux Information Functions **
** **
*******************************************************************************
******************************************************************************/
/**
* MPEG_DemuxInit Function. Initializes the Demux information structure. This
* function fully initializes the private data of the Demux class.
*
* @param
* TSDEMUXINFO *pDemuxInfo - Demux information
*
* @retval
* None.
*
* @remark
* None.
*
* @verified
* No.
*/
static void MPEG2TS_DemuxInit( TSDEMUXINFO *pDemuxInfo )
{
/*
* Demux State
*/
pDemuxInfo->ulDemuxState = NO_SYNC;
/*
* Data pointers
*/
pDemuxInfo->wPID = (SHORT)(INVALID_PID);
pDemuxInfo->wPIDIndex = INVALID_STREAM;
pDemuxInfo->pbData = NULL;
pDemuxInfo->pbPesHeader = NULL;
pDemuxInfo->pbPayload = NULL;
pDemuxInfo->ulPayloadSize = 0;
/*
* Data lengths
*/
pDemuxInfo->fBufferBeingUsed = FALSE;
pDemuxInfo->wSIPID = (SHORT)(INVALID_PID);
pDemuxInfo->wBufferSize = 0;
pDemuxInfo->wPacketSize = 0;
/*
* Encryption data
*/
pDemuxInfo->tDataEncryption = NONE;
/*
* Synchronization data
*/
pDemuxInfo->ulPCRBase = 0;
pDemuxInfo->ulPCRExt = 0;
pDemuxInfo->fPtsExisted = FALSE;
pDemuxInfo->ulPTS = 0x00000000;
pDemuxInfo->fDtsExisted = FALSE;
pDemuxInfo->ulDTS = 0x00000000;
/*
* Local configuration information
*/
pDemuxInfo->messInput = NULL;
pDemuxInfo->pbInputData = NULL;
pDemuxInfo->ulInputSize = 0;
pDemuxInfo->tConfigInfo.tInputPin = NULL;
pDemuxInfo->tConfigInfo.iOutputPinCount = 0;
for( int i = 0; i < OUTPUT_STREAM_MAX_COUNT; i++ )
{
pDemuxInfo->tConfigInfo.tOutputPin[i].wPID = (SHORT)(INVALID_PID);
pDemuxInfo->tConfigInfo.tOutputPin[i].pDestStream = NULL;
pDemuxInfo->tConfigInfo.tOutputPin[i].fSendPayload = FALSE;
}
} /* end MPEG2TS_DemuxInit() */
/************************************************************************/
/************************************************************************/
/** **/
/************************************************************************/
/************************************************************************/
static void MPEG2TS_DemuxUpdate( TSDEMUXINFO *pDemuxInfo )
{
pDemuxInfo->tConfigInfo.iOutputPinCount = pDemuxInfo->pDynamicConfigInfo->iOutputPinCount;
pDemuxInfo->tConfigInfo.tInputPin = pDemuxInfo->pDynamicConfigInfo->tInputPin;
for (int i = 0; i < OUTPUT_STREAM_MAX_COUNT; i++)
{
if (pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].wPID != pDemuxInfo->tConfigInfo.tOutputPin[i].wPID)
{
DbgPrint(("Updateing %08x\n", pDemuxInfo->tConfigInfo.tOutputPin[i].wPID));
DbgPrint(("Updateing %08x %08x\n", (int)pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].wPID,
(int)pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].pDestStream));
pDemuxInfo->tConfigInfo.tOutputPin[i].wPID = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].wPID;
pDemuxInfo->tConfigInfo.tOutputPin[i].pDestStream = pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].pDestStream;
pDemuxInfo->tConfigInfo.tOutputPin[i].fSendPayload = FALSE;
}
}
} /* end MPEG2TS_DemuxUpdate() */
/************************************************************************/
/************************************************************************/
/** **/
/** procedure MPE2TS_IsBeingWatched() **/
/** **/
/** PURPOSE: To check to see if the current PID is desired. **/
/** **/
/************************************************************************/
/************************************************************************/
BOOLEAN MPEG2TS_IsBeingWatched( TSDEMUXINFO *configInfo )
{
#if 1
BYTE *pbHeader;
BOOLEAN fRet;
SHORT sPID;
fRet = FALSE;
pbHeader = configInfo->pbData;
sPID = ((PMPG_TRANSPORT_HDR)( (BYTE *)configInfo->pbData ))->wPID;
configInfo->wPID = sPID;
for( int i = 0; i < OUTPUT_STREAM_MAX_COUNT; i++ )
{
if( configInfo->tConfigInfo.tOutputPin[i].wPID == sPID )
{
if ( configInfo->tConfigInfo.tOutputPin[i].pDestStream != NULL )
{
configInfo->wPIDIndex = i;
fRet = TRUE;
break;
}
}
}
return( fRet );
#else
configInfo->wPIDIndex = INVALID_STREAM;
for( int i = 0; i < OUTPUT_STREAM_MAX_COUNT; i++ )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -