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

📄 mpeg_demux.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
                PVOID pEndPtr  = (PVOID)((ULONG)pBasePtr + pOutMessage->payload->get_max_size());

                if ( (pDemuxInfo->pbPacket >= pBasePtr) && (pDemuxInfo->pbPacket <= pEndPtr) )
                {
                    ulPacketHeaderSize = pDemuxInfo->pbData - pDemuxInfo->pbPacket;
                }
                else
                {
                    ulPacketHeaderSize = 0;
                    DBGPRINT(DBG_MPEG_DEMUX, ("ERROR: going to drop packet header because it's not in this payload!\n"));
                }
            }
            else
            {
                ulPacketHeaderSize = 0;
            }

            /* Calculate the amount of data to be sent to the output pin. */
            if (ulPayloadDataLength < (pDemuxInfo->ulPacketDataLength + ulPacketHeaderSize) )
            {
                ulSendDataLength = ulPayloadDataLength;
            }
            else
            {
                /* not adding the packet header size on purpose. The demux doesn't need to know we are sending this data,
                 * we just need to be sure there is enough room in the payload buffer for it */
                ulSendDataLength = pDemuxInfo->ulPacketDataLength;
            }

            /* Set the read pointer of the outgoing payload appropriately */
            pOutMessage->payload->set_rd_ptr((PVOID)(pDemuxInfo->pbData - ulPacketHeaderSize));

            /* Set the write pointer of the outgoing payload appropriately */
            pOutMessage->payload->set_wr_ptr((PVOID)(pDemuxInfo->pbData + ulSendDataLength));
        }

        /* Load the message with encryption information and the pack pointer, if necessary */
        pOutMessage->Encryption = pDemuxInfo->tDataEncryption;

        /* Clear all flags, these are sent from MPEG_WaitForMoreData */
        pOutMessage->EndOfStream              = FALSE;
        pOutMessage->SequenceEnd              = FALSE;
        pOutMessage->DiscontinuityAtBeginning = FALSE;
        pOutMessage->DiscontinuityAtEnd       = FALSE;
        pOutMessage->fInfoPayload             = FALSE;

        /* Time stamp the (first) outgoing message, if appropriate */
        if (iLoopCount == 0)
        {
            switch (tTimeType)
            {
            case DEMUX_DTS:
                if (pDemuxInfo->fDtsExisted == TRUE)
                {
                    pOutMessage->IsTimeStamped = pDemuxInfo->fDtsExisted;
                    pOutMessage->TimeStamp     = (int)pDemuxInfo->ulDTS;
                }
                else
                {
                    pOutMessage->IsTimeStamped = FALSE;
                    pOutMessage->TimeStamp     = 0;
                }
                break;
            case DEMUX_PTS:
            case DEMUX_ANY:
                if (pDemuxInfo->fPtsExisted == TRUE)
                {
                    pOutMessage->IsTimeStamped = pDemuxInfo->fPtsExisted;
                    pOutMessage->TimeStamp     = (int)pDemuxInfo->ulPTS;
                }
                else
                {
                    pOutMessage->IsTimeStamped = FALSE;
                    pOutMessage->TimeStamp     = 0;
                }
                break;
            }
        }
        else
        {
            pOutMessage->IsTimeStamped = FALSE;
            pOutMessage->TimeStamp     = 0;
        }

#if DBG_ON(DBG_VERBOSE)
        DbgPrint(("MPEG_SendData: send the message to the output pin ---\n"));
#endif

        /* To help with DVD navpack syncronization include the navpack tag */
        pOutMessage->ulVobuCC     = pDemuxInfo->tInMessage.ulVobuCC;
        pOutMessage->fIsVobuStill = pDemuxInfo->tInMessage.fIsVobuStill;

#if DEBUG_CSTREAM
        char temp[32];
        sprintf(temp, "0x%x - 0x%x", pDemuxInfo->bPesID, pDemuxInfo->bSubID);
        TCH_PAYLOAD_INFO(pOutMessage->payload, temp);
#endif

        /* Send the message to the output pin */
        if (pOutputPin->Write( (PVOID)pOutMessage ) != OS_OK)
        {
            if (pOutMessage->payload != NULL)
            {
                delete (pOutMessage->payload);
                pOutMessage->payload = NULL;
            }
            pOutputPin->ReleaseMsg(pOutMessage);
            pOutMessage = NULL;
            return;
        }

        /* Update the packet data length by the amount of data just sent */
        MPEG_DemuxInfoUpdate(pDemuxInfo, ulSendDataLength, UPDATE_PDL, __LINE__);

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

        /* Update the payload data length */
        ulPayloadDataLength = pDemuxInfo->tInMessage.payload->get_size();

        /* Update the loop counter */
        iLoopCount++;
    }
}


/******************************************************************************
*******************************************************************************
**                                                                           **
**  MPEG Demux Debug Functions                                               **
**                                                                           **
*******************************************************************************
******************************************************************************/

/**
 * MPEG_StreamDump Function. Dumps stream data.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
static void MPEG_StreamDump( DEMUXINFO *pDemuxInfo )
{
#if 1
    ulDemuxErrorCnt++;
#else
    int   i,j;
    BYTE *pbTmp;

    ulDemuxErrorCnt++;

    printf("Base data ptr = 0x%08x\n", (ULONG)pDemuxInfo->tInMessage.payload->get_base_ptr());
    printf("Current data ptr = 0x%08x\n", (ULONG)pDemuxInfo->pbData);
    printf("Data length = %d\n", pDemuxInfo->ulDataLength);
    printf("Packet data length = %d\n", pDemuxInfo->ulPacketDataLength);
    printf("Start code = 0x%08x\n", pDemuxInfo->ulStartCode);

    pbTmp = pDemuxInfo->pbData - 16;
    for (i=0; i<128; i++)
    {
        if ( (i & 0x0f) == 0x00 )
        {
            printf( "0x%08x |", (ULONG)&pbTmp[i] );
        }
        printf( " %02x", pbTmp[i] );
        if ( (i & 0x0f) == 0x0f )
        {
            printf( " | " );
            for (j=(i-15); j<=i; j++)
            {
                if ( (pbTmp[j]>=0x30)  && (pbTmp[j]<=0x70) )
                {
                    printf( "%c", pbTmp[j] );
                }
                else
                {
                    printf( "." );
                }
            }
            printf( "\n" );
        }
    }
#endif
}

/**
 * MPEG_ConfigurationDataDump Function. Dumps the Demux configuration data.
 *
 * @param
 *    DEMUXCONFIGINFO *pDemuxInfo - Demux configuration information
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
#if DBG_MPEG_DEMUX >= DBG_TRACE
static void MPEG_ConfigurationDataDump( DEMUXCONFIGINFO *pDemuxConfigInfo )
{
    printf("\n***********************************\n");
    printf(" DEMUX CONFIGURATION DATA DUMP\n");
    printf("***********************************\n");
    printf("Number of Output Pins = %d\n", pDemuxConfigInfo->iOutputPinCount);
    printf("Input pin = 0x%08x\n", (int)pDemuxConfigInfo->tInputPin);
    for (int i = 0; i < pDemuxConfigInfo->iOutputPinCount; i++)
    {
        printf("Output pin(%d) = 0x%08x\n", i, (int)pDemuxConfigInfo->tOutputPin[i].pDestStream);
        printf("PES_ID = 0x%02x\n", pDemuxConfigInfo->tOutputPin[i].bPesID);
        printf("SUB_ID = 0x%02x\n", pDemuxConfigInfo->tOutputPin[i].bSubID);
    }
    printf("\n");
}
#endif

/******************************************************************************
*******************************************************************************
**                                                                           **
**  MPEG Demux Information Functions                                         **
**                                                                           **
*******************************************************************************
******************************************************************************/

/**
 * MPEG_ResetDataInfo Function. Resets the Demux data information.
 *
 * @param
 *    DEMUXCONFIGINFO *pDemuxInfo - Demux configuration information
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
static void MPEG_ResetDataInfo( DEMUXINFO *pDemuxInfo )
{
    /* Data pointers */
    pDemuxInfo->pbData                  = NULL;
    pDemuxInfo->pbPack                  = NULL;
    pDemuxInfo->pbPacket                = NULL;
    pDemuxInfo->pbBypassData            = NULL;

    /* Data lengths */
    pDemuxInfo->ulDataLength            = 0;
    pDemuxInfo->ulPacketDataLength      = 0;
    pDemuxInfo->ulPesHeaderDataLength   = 0;
    pDemuxInfo->ulSCRInfoDataLength     = 0;

    /* Start code and stream IDs */
    pDemuxInfo->ulStartCode             = 0x00000000;
    pDemuxInfo->bPesID                  = 0x00;
    pDemuxInfo->bSubID                  = NO_SUB_ID;

    /* Start of stream variable */
    pDemuxInfo->fSystemHeaderFound      = FALSE;

    /* Encryption data */
    pDemuxInfo->tDataEncryption         = NONE;

    /* Synchronization data */
    pDemuxInfo->ulSCRBase               = 0;
    pDemuxInfo->ulSCRExt                = 0;
    pDemuxInfo->fPtsExisted             = FALSE;
    pDemuxInfo->ulPTS                   = 0x00000000;
    pDemuxInfo->fDtsExisted             = FALSE;
    pDemuxInfo->ulDTS                   = 0x00000000;
}

/**
 * MPEG_DemuxInit Function. Initializes the Demux information structure. This
 * function fully initializes the private data of the Demux class.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
static void MPEG_DemuxInit(DEMUXINFO *pDemuxInfo)
{
    /* Demux State */
    pDemuxInfo->ulDemuxState = FIND_START_CODE;

    /* Reset the Demux data information */
    MPEG_ResetDataInfo(pDemuxInfo);

    /* Current payload pointer */
    if (pDemuxInfo->tInMessage.payload != NULL)
    {
        TCH_PAYLOAD(pDemuxInfo->tInMessage.payload);
        delete (pDemuxInfo->tInMessage.payload);
        pDemuxInfo->tInMessage.payload = NULL;
    }

    /* Local configuration information */
    pDemuxInfo->tConfigInfo = *pDemuxInfo->pDynamicConfigInfo;
    pDemuxInfo->pDynamicConfigInfo->fUpdateOutputPins = FALSE;
}


/**
 * MPEG_DemuxErrorRecovery Function. Reset the Demux information, gets more data
 * and attempts to find a new start code as the result of a Demux error.
 *
 * @param
 *    DEMUXINFO *pDemuxInfo - Demux information
 *
 * @retval
 *    None.
 *
 * @verified
 *    Yes.
 */
static void MPEG_DemuxErrorRecovery( DEMUXINFO *pDemuxInfo )
{
  /*
   *  Print error message
   */
  DBGPRINT(DBG_MPEG_DEMUX, ("**** MPEG_DemuxErrorRecovery: Begin ****\n"));
  MPEG_StreamDump(pDemuxInfo);

  /*
   *  Reset the Demux data information
   */
  MPEG_ResetDataInfo(pDemuxInfo);

  /*
   *  Wait for more data
   */
  MPEG_WaitForMoreData(pDemuxInfo);

  /*
   *  Look for the next start code
   */
  pDemuxInfo->ulDemuxState = FIND_START_CODE;

  /*
   *  Print error message
   */
  DBGPRINT(DBG_MPEG_DEMUX, ("**** MPEG_DemuxErrorRecovery: End ****\n"));

⌨️ 快捷键说明

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