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

📄 mpeg_demux.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
}

/**
 * MPEG_PacketDataLengthUpdate Function. Updates the ulPacketDataLength field
 * of the Demux information structure.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @param
 *    ULONG ulDataOffset - amount to update by
 *
 * @param
 *    ULONG ulLine - line number from which this function was called
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
static void MPEG_PacketDataLengthUpdate(DEMUXINFO *pDemuxInfo,
                                        ULONG ulDataOffset,
                                        ULONG ulLine)
{
    pDemuxInfo->ulPacketDataLength -= ulDataOffset;

    if (pDemuxInfo->ulPacketDataLength & 0xf0000000)
    {
        DBGPRINT(DBG_MPEG_DEMUX, ("**** Packet data length is negative - line(%d)! ****\n", (int)ulLine));
        MPEG_DemuxErrorRecovery(pDemuxInfo);
    }
}

/**
 * MPEG2_PesHeaderDataLengthUpdate Function. Updates the ulPesHeaderDataLength
 * field of the Demux information structure.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @param
 *    ULONG ulDataOffset - amount to update by
 *
 * @param
 *    ULONG ulLine - line number from which this function was called
 *
 * @retval
 *    None.
 *
 * @remark
 *    This function is meant for MPEG2 streams only.
 *
 * @verified
 *    Yes.
 */
static void MPEG2_PesHeaderDataLengthUpdate(DEMUXINFO *pDemuxInfo,
                                            ULONG ulDataOffset,
                                            ULONG ulLine)
{
    pDemuxInfo->ulPesHeaderDataLength -= ulDataOffset;

    if (pDemuxInfo->ulPesHeaderDataLength & 0xf0000000)
    {
        DBGPRINT(DBG_MPEG_DEMUX, ("**** PES header data length is negative - line(%d)! ****\n", (int)ulLine));
        MPEG_DemuxErrorRecovery(pDemuxInfo);
    }
}

/**
 * MPEG2_SCRInfoDataLengthUpdate Function. Updates the ulSCRInfoDataLength
 * field of the Demux information structure.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @param
 *    ULONG ulDataOffset - amount to update by
 *
 * @param
 *    ULONG ulLine - line number from which this function was called
 *
 * @retval
 *    None.
 *
 * @remark
 *    This function is meant for MPEG2 streams only.
 *
 * @verified
 *    Yes.
 */
static void MPEG2_SCRInfoDataLengthUpdate(DEMUXINFO *pDemuxInfo,
                                          ULONG ulDataOffset,
                                          ULONG ulLine)
{
    pDemuxInfo->ulSCRInfoDataLength -= ulDataOffset;

    if (pDemuxInfo->ulSCRInfoDataLength & 0xf0000000)
    {
        DBGPRINT(DBG_MPEG_DEMUX, ("**** SCR info data length is negative - line(%d)! ****\n", (int)ulLine));
        MPEG_DemuxErrorRecovery(pDemuxInfo);
    }
}

/**
 * MPEG_ResetMiscDataLengths Function. Resets the ulPacketDataLength,
 * ulPesHeaderDataLength, and ulSCRInfoDataLength.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @param
 *    ULONG ulSCRInfoDataLength - SCR information data length (different for
 *                                MPEG1 and MPEG2).
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
static void MPEG_ResetMiscDataLengths(DEMUXINFO *pDemuxInfo, ULONG ulSCRInfoDataLength)
{
    pDemuxInfo->ulPacketDataLength    = 0;
    pDemuxInfo->ulPesHeaderDataLength = 0;
    pDemuxInfo->ulSCRInfoDataLength   = ulSCRInfoDataLength;
}

/**
 * MPEG_DemuxInfoUpdate Function. Updates the demux information structure
 * The pbData and ulDataLength fields are always updated. The
 * ulPacketDataLength, ulPesHeaderDataLength, and ulSCRInfoDataLength fields
 * are only updated if the passed in flag is set appropriately.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @param
 *    LONG lDataOffset - amount to update by
 *
 * @param
 *    BYTE bUpdate - update flag, determines which lengths other than the
 *                   dataLength should be updated, if any.
 *
 * @param
 *    ULONG ulLine - line from which this function was called.
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
static void MPEG_DemuxInfoUpdate(DEMUXINFO *pDemuxInfo, LONG lDataOffset, BYTE bUpdate, ULONG ulLine)
{
    BOOLEAN fError = FALSE;

    if (pDemuxInfo->pDynamicConfigInfo->ulDemuxState != DEMUX_STARTED)
    {
        return;
    }

    /* Always update the data length */
    pDemuxInfo->pbData       += lDataOffset;
    pDemuxInfo->ulDataLength -= lDataOffset;

    /* If data length became zero, get more data. If data length became negative, yield forever. */
    if (pDemuxInfo->ulDataLength == 0)
    {
        MPEG_WaitForMoreData(pDemuxInfo);

        if (pDemuxInfo->pDynamicConfigInfo->ulDemuxState != DEMUX_STARTED)
        {
            return;
        }
    }
    else if (pDemuxInfo->ulDataLength & 0xf0000000)
    {
        DBGPRINT(DBG_MPEG_DEMUX, ("**** Data length is negative - line(%d)! ****\n", (int)ulLine));
        fError = TRUE;
        MPEG_DemuxErrorRecovery(pDemuxInfo);
    }

    /* Update the remaining lengths only if no error was found */
    if (fError == FALSE)
    {
        /* See if the packet data length should be updated */
        if (bUpdate & UPDATE_PDL)
        {
            MPEG_PacketDataLengthUpdate( pDemuxInfo, (ULONG)lDataOffset, ulLine );
        }

        /* See if the PES header data length should be updated */
        if (bUpdate & UPDATE_PHDL)
        {
            MPEG2_PesHeaderDataLengthUpdate( pDemuxInfo, (ULONG)lDataOffset, ulLine );
        }

        /* See if the SCR information data length should be updated */
        if (bUpdate == UPDATE_SCRIDL)
        {
            MPEG2_SCRInfoDataLengthUpdate( pDemuxInfo, (ULONG)lDataOffset, ulLine );
        }
    }
}

/*
 * Updates the output pin info.
 */
static void MPEG_UpdateOutputPins(DEMUXINFO *pDemuxInfo)
{
    OS_SemTake(pDemuxInfo->pDynamicConfigInfo->semPinUpdate, OS_WAIT_FOREVER);

    /* update the pin info and reset the update flag */
    pDemuxInfo->tConfigInfo = *pDemuxInfo->pDynamicConfigInfo;
    pDemuxInfo->pDynamicConfigInfo->fUpdateOutputPins = FALSE;

    /* clear the first payload flags in the dynamic data so we don't get repeats */
    for (int i=0; i<pDemuxInfo->pDynamicConfigInfo->iOutputPinCount; i++)
    {
        pDemuxInfo->pDynamicConfigInfo->tOutputPin[i].fFirstPayload = FALSE;
    }

#if DBG_MPEG_DEMUX >= DBG_TRACE
    MPEG_ConfigurationDataDump(pDemuxInfo->pDynamicConfigInfo);
#endif

    OS_SemGive(pDemuxInfo->pDynamicConfigInfo->semPinUpdate);
}

#if ENABLE_DEMUX_REMAP_FEATURE
/**
 * MPEG_UpdateRemap Function. Updates the remap parameters in the static
 * demux configuration information.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
static void MPEG_UpdateRemap(DEMUXINFO *pDemuxInfo)
{
    DBGPRINT(DBG_ON(DBG_TRACE), ("MPEG_UpdateRemap: BEGIN\n"));

    if (pDemuxInfo != NULL)
    {
        OS_SemTake(pDemuxInfo->pDynamicConfigInfo->semRemapUpdate, OS_WAIT_FOREVER);

        pDemuxInfo->pDynamicConfigInfo->fUpdateRemap = FALSE;

        pDemuxInfo->tConfigInfo.bRemapStreamID =
            pDemuxInfo->pDynamicConfigInfo->bRemapStreamID;

        pDemuxInfo->tConfigInfo.bRemapSubStreamID =
            pDemuxInfo->pDynamicConfigInfo->bRemapSubStreamID;

        pDemuxInfo->tConfigInfo.bRemapStreamIDValue =
            pDemuxInfo->pDynamicConfigInfo->bRemapStreamIDValue;

        pDemuxInfo->tConfigInfo.bRemapSubStreamIDValue =
            pDemuxInfo->pDynamicConfigInfo->bRemapSubStreamIDValue;

        DBGPRINT(DBG_ON(DBG_TRACE), ("MPEG_UpdateRemap: 0x%02x 0x%02x 0x%02x 0x%02x\n",
        pDemuxInfo->pDynamicConfigInfo->bRemapStreamID,
        pDemuxInfo->pDynamicConfigInfo->bRemapSubStreamID,
        pDemuxInfo->pDynamicConfigInfo->bRemapStreamIDValue,
        pDemuxInfo->pDynamicConfigInfo->bRemapSubStreamIDValue));

        OS_SemGive(pDemuxInfo->pDynamicConfigInfo->semRemapUpdate);
    }

    DBGPRINT(DBG_ON(DBG_TRACE), ("MPEG_UpdateRemap: END\n"));
}
#endif

/******************************************************************************
*******************************************************************************
**                                                                           **
**  MPEG Start Code Functions                                                **
**                                                                           **
*******************************************************************************
******************************************************************************/

/**
 * MPEG_IsStartCodeValid Function. Examines the given start code to see if it
 * is valid.
 *
 * @param
 *    ULONG ulStartCode - start code to be examined
 *
 * @retval
 *    TRUE if the start code is valid
 *    FALSE if the start code is not valid
 *
 * @verified
 *    No.
 */
static inline BOOLEAN MPEG_IsStartCodeValid( ULONG ulStartCode )
{
    BOOLEAN fRetVal;

    /*
     *  Look for a valid start code
     */
    switch (ulStartCode)
    {
    case MPEG_PACK_HEADER_START_CODE:
    case MPEG_SYSTEM_HEADER_START_CODE:
    case MPEG_PRIVATE_STREAM_1_START_CODE:
    case MPEG_PRIVATE_STREAM_2_START_CODE:
    case MPEG_PADDING_STREAM_START_CODE:
    case MPEG_PROGRAM_STREAM_MAP_START_CODE:
        fRetVal = TRUE;
        break;

    default:
        if( (ulStartCode >= MPEG_AUDIO1_PACKET_START_CODE_BEGIN) &&
            (ulStartCode <= MPEG_AUDIO1_PACKET_START_CODE_END) )
        {
            fRetVal = TRUE;
        }
        else if( (ulStartCode >= MPEG_AUDIO2_PACKET_START_CODE_BEGIN) &&
            (ulStartCode <= MPEG_AUDIO2_PACKET_START_CODE_END) )
        {
            fRetVal = TRUE;
        }
        else if( (ulStartCode >= MPEG_VIDEO_PACKET_START_CODE_BEGIN) &&
            (ulStartCode <= MPEG_VIDEO_PACKET_START_CODE_END) )
        {
            fRetVal = TRUE;
        }
        else if(ulStartCode == MPEG_VIDEO_VC1_PACKET_START_CODE)
        {
            fRetVal = TRUE;
        }
        else
        {
            fRetVal = FALSE;
            DBGPRINT(DBG_MPEG_DEMUX, ("**** MPEG_IsStartCodeValid: Invalid (0x%08x)! ****\n", ulStartCode));
        }
        break;
    }

    /*
     *  Return whether or not the start code is valid
     */
    return fRetVal;

⌨️ 快捷键说明

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