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

📄 clpinfodb.cpp

📁 这是DVD中伺服部分的核心代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        if (spnMid > spnIN)
        {
            fiRight = fiMid;
        }
        else
        {
            fiLeft = fiMid;
        }
    }

    *fiFound = fiLeft;

#if DBG_ON(DBG_VERBOSE)
    ULONG      spnFound;
    spnFound =  ( ( (pClpInfoEpMapCoarse[ciStart].SPN_EP_coarse & 0xfffe0000)) | (pClpInfoEpMapFine[*fiFound].SPN_EP_fine) );
    DBGPRINT(DBG_ON(DBG_VERBOSE), (" FOUND pClpInfoEpMapFine[%i].SPN_EP: 0x%x\n", *fiFound, spnFound));
#endif

    return(CLPINFO_SUCCESS);
}

/*

    returns the first index that is marked as an angle change point

    THIS ONE'S LOGIC CAN BE A LITTLE DIFFERENT
*/
CLPINFO_STATUS  ClpInfo::ClpInfoSearch_FineForAngle(BOOLEAN fReverse, ULONG fiStart, ULONG fiEnd, ULONG *fiFound)
{
    ULONG       i;
    FINEINFO    *pClpInfoEpMapFine;
    ULONG       fiFirst                 = (!fReverse) ? fiStart : fiEnd;
    ULONG       fiLast                  = (!fReverse) ? fiEnd   : fiStart;
    SHORT       increment               = (!fReverse) ? 1       : -1;

    if (hClpInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("ClpInfoSearch_FineForAngle: Database not created!\n"));
        return (CLPINFO_FAILURE);
    }

    if (m_tClpInfoData == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("ClpInfoSearch_FineForAngle: Clip not loaded!\n"));
        return(CLPINFO_FAILURE);
    }

    pClpInfoEpMapFine = m_tClpInfoData->CPI.EP_map.stream_pid_entry[EPMAP_STREAMINDEX].EP_map_for_one_stream_PID.fine;

    /* Search the EP Coarse - must use linear search! */
    for(i=fiFirst; i!=fiLast+increment; i+=increment)
    {
        DBGPRINT(DBG_ON(DBG_VERBOSE), (" pClpInfoEpMapFine[%i].is_angle_change_point: %u\n", i, pClpInfoEpMapFine[i].is_angle_change_point));

        if (pClpInfoEpMapFine[i].is_angle_change_point)
        {
            *fiFound = i;
            return(CLPINFO_SUCCESS);
        }
    }
    return(CLPINFO_FAILURE);
}

/*
 * returns the largest index that has a ref_to_EP_fine <= the fiNewPosition
 *
 * KEEP LOGIC OF ALL CLIPINFO SEARCHING FUNCTIONS EQUAL
 *
 * @param
 *      ciStart       -- the first index ciFound could be  (cannot be > ciEnd  )
 *      ciEnd         -- the last  index ciFound could be  (cannot be < ciStart  )
 *      fiNewPosition -- the fine we're looking for
 *      ciFound       -- the first index that's equal   or   the largest index that is < fiNewPosition
 *      spnFound      -- the spn at that course and fine.
 *
 * @retval
 *      CLPINFO_STATUS
 */
CLPINFO_STATUS  ClpInfo::ClpInfoSearch_CoarseForFine(ULONG ciStart, ULONG ciEnd, ULONG fiNewPosition, ULONG *ciFound, ULONG *spnFound)
{
    ULONG      ciLeft  = ciStart;
    ULONG      ciRight = ciEnd + 1;
    ULONG      ciMid;

    COARSEINFO *pClpInfoEpMapCoarse;
    FINEINFO   *pClpInfoEpMapFine;
    ULONG      ref_to_EP_fine = fiNewPosition;

    DBGPRINT(DBG_ON(DBG_TRACE), ("\nClpInfoSearch_CoarseForFine:\n"));


    if (hClpInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("ClpInfoSearch_CoarseForFine: Database not created!\n"));
        return (CLPINFO_FAILURE);
    }

    if (m_tClpInfoData == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("ClpInfoSearch_CoarseForFine: Clip not loaded!\n"));
        return(CLPINFO_FAILURE);
    }

    pClpInfoEpMapCoarse = m_tClpInfoData->CPI.EP_map.stream_pid_entry[EPMAP_STREAMINDEX].EP_map_for_one_stream_PID.coarse;
    pClpInfoEpMapFine   = m_tClpInfoData->CPI.EP_map.stream_pid_entry[EPMAP_STREAMINDEX].EP_map_for_one_stream_PID.fine;

    DBGPRINT(DBG_ON(DBG_VERBOSE), (" fiNewPosition: %u\n", fiNewPosition));

    /* binary search */
    while (ciLeft < ciRight - 1)
    {
        ciMid = (ciLeft + ciRight) / 2;

        ref_to_EP_fine = pClpInfoEpMapCoarse[ciMid].ref_to_EP_fine_id;

        DBGPRINT(DBG_ON(DBG_VERBOSE), (" pClpInfoEpMapCoarse[%i].ref_to_EP_fine: %u\n", ciMid, ref_to_EP_fine));
        if (ref_to_EP_fine > fiNewPosition)
        {
            ciRight = ciMid;
        }
        else
        {
            ciLeft = ciMid;
        }
    }

    *ciFound  = ciLeft;

    /* spn using the found ci and the specified fi */
    *spnFound = ( (pClpInfoEpMapCoarse[*ciFound].SPN_EP_coarse & 0xfffe0000) | (pClpInfoEpMapFine[fiNewPosition].SPN_EP_fine) );

#if DBG_ON(DBG_VERBOSE)
    ref_to_EP_fine  = pClpInfoEpMapCoarse[*ciFound].ref_to_EP_fine_id;
    DBGPRINT(DBG_ON(DBG_VERBOSE), (" FOUND pClpInfoEpMapCoarse[%i].ref_to_EP_fine: %u - spn: %u\n", *ciFound, ref_to_EP_fine, *spnFound));
#endif

    return(CLPINFO_SUCCESS);
}




CLPINFO_STATUS  ClpInfo::ClpInfoSearch_CoarseAndFineForSPN(ULONG spnCurrentPosition, ULONG *ciFound, ULONG *fiFound)
{
    COARSEINFO  *pClpInfoEpMapCoarse  = NULL;
    ULONG       ulNumCoarseEntries    = 0;
    ULONG       ulCoarseStartIndex;
    ULONG       ulCoarseEndIndex;

    FINEINFO    *pClpInfoEpMapFine    = NULL;
    ULONG       ulNumFineEntries      = 0;

    ULONG       i_coarse, i_fine;

    DBGPRINT(DBG_ON(DBG_VERBOSE), ("\nClpInfoSearch_CoarseAndFineForSPN\n"));
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("spnCurrentPosition: 0x%x\n", spnCurrentPosition));

    if (hClpInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("ClpInfoSearch_ChangePoint: Database not created!\n"));
        return (CLPINFO_FAILURE);
    }

    if (m_tClpInfoData == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("ClpInfoSearch_ChangePoint: Clip not loaded!\n"));
        return(CLPINFO_FAILURE);
    }

    /* Get the EP Coarse */
    if ( CLPINFO_SUCCESS != ClpInfoGet_EPMapCoarse(EPMAP_STREAMINDEX,  &pClpInfoEpMapCoarse, &ulNumCoarseEntries) )
    {
        DBGPRINT(DBG_ON(DBG_ERROR), (" ClpInfoGet_EPMapCoarse Failed"));
        goto errout;
    }

    /* Get the EP Fine */
    if ( CLPINFO_SUCCESS != ClpInfoGet_EPMapFine(EPMAP_STREAMINDEX, &pClpInfoEpMapFine, &ulNumFineEntries) )
    {
        DBGPRINT(DBG_ON(DBG_ERROR), (" ClpInfoGet_EPMapFine Failed"));
        goto errout;
    }

    ulCoarseStartIndex = m_ciStart;
    ulCoarseEndIndex   = m_ciEnd;

    DBGPRINT(DBG_ON(DBG_VERBOSE), ("ulCoarseStartIndex: %u\n", ulCoarseStartIndex));
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("ulCoarseEndIndex: %u\n\n", ulCoarseEndIndex));
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("ulNumFineEntries: %u\n\n", ulNumFineEntries));


    DBGPRINT(DBG_ON(DBG_TRACE), ("current position:\n"));
    if ( CLPINFO_SUCCESS != ClpInfoSearch_CoarseForSPN(ulCoarseStartIndex, ulCoarseEndIndex, spnCurrentPosition, &i_coarse))
    {
        DBGPRINT(DBG_ON(DBG_ERROR), (" ClpInfoSearch_CoarseForSPN Failed"));
        goto errout;
    }
    DBGPRINT(DBG_ON(DBG_TRACE), ("i_coarse: %u\n", i_coarse));

    /* search the fines of the related coarse for the current position */
    if ( CLPINFO_SUCCESS != ClpInfoSearch_FineForSPN(i_coarse, spnCurrentPosition, &i_fine))
    {
        DBGPRINT(DBG_ON(DBG_ERROR), (" ClpInfoSearch_FineForSPN Failed"));
        goto errout;
    }
    DBGPRINT(DBG_ON(DBG_TRACE), ("i_fine: %u\n\n", i_fine));

    *ciFound = i_coarse;
    *fiFound = i_fine;

    return(CLPINFO_SUCCESS);
errout:
    return(CLPINFO_FAILURE);
}



CLPINFO_STATUS  ClpInfo::ClpInfoSearch_ChangePoint(BOOLEAN fAngle, BOOLEAN fReverse, ULONG spnCurrentPosition, ULONG *ulAngleChangePointSPN, ULONG *ulAngleChangePointPTS, ULONG *ciAnglePoint, ULONG *fiAnglePoint)
{
    COARSEINFO  *pClpInfoEpMapCoarse  = NULL;
    ULONG       ulNumCoarseEntries    = 0;
    ULONG       ulCoarseStartIndex;
    ULONG       ulCoarseEndIndex;

    FINEINFO    *pClpInfoEpMapFine    = NULL;
    ULONG       ulNumFineEntries      = 0;

    ULONG       ref_to_EP_fine;
    ULONG       next_ref_to_EP_fine;
    ULONG       SPN_EP_coarse;
    ULONG       PTS_EP_coarse;

    ULONG       i_coarse, i_fine;
    ULONG       i_coarse_endpoint;
    SHORT       increment;


    DBGPRINT(DBG_ON(DBG_VERBOSE), ("spnCurrentPosition: %u\n\n", spnCurrentPosition));

    if (hClpInfo == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("ClpInfoSearch_ChangePoint: Database not created!\n"));
        return (CLPINFO_FAILURE);
    }

    if (m_tClpInfoData == NULL)
    {
        DBGPRINT(DBG_ON(DBG_ERROR), ("ClpInfoSearch_ChangePoint: Clip not loaded!\n"));
        return(CLPINFO_FAILURE);
    }

    /* Get the EP Coarse */
    if ( CLPINFO_SUCCESS != ClpInfoGet_EPMapCoarse(EPMAP_STREAMINDEX,  &pClpInfoEpMapCoarse, &ulNumCoarseEntries) )
    {
        DBGPRINT(DBG_ON(DBG_ERROR), (" ClpInfoGet_EPMapCoarse Failed"));
        goto errout;
    }


    ulCoarseStartIndex = m_ciStart;
    ulCoarseEndIndex   = m_ciEnd;

    DBGPRINT(DBG_ON(DBG_VERBOSE), ("ulCoarseStartIndex: %u\n\n", ulCoarseStartIndex));
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("ulCoarseEndIndex: %u\n\n", ulCoarseEndIndex));


    /* Get the EP Fine */
    if ( CLPINFO_SUCCESS != ClpInfoGet_EPMapFine(EPMAP_STREAMINDEX, &pClpInfoEpMapFine, &ulNumFineEntries) )
    {
	    DBGPRINT(DBG_ON(DBG_ERROR), (" ClpInfoGet_EPMapFine Failed"));
	    goto errout;
    }
    DBGPRINT(DBG_ON(DBG_VERBOSE), ("ulNumFineEntries: %u\n\n", ulNumFineEntries));

    /* search the coarse for the current position */

    DBGPRINT(DBG_ON(DBG_TRACE), ("current position:\n"));
    if ( CLPINFO_SUCCESS != ClpInfoSearch_CoarseForSPN(ulCoarseStartIndex, ulCoarseEndIndex, spnCurrentPosition, &i_coarse))
    {
        DBGPRINT(DBG_ON(DBG_ERROR), (" ClpInfoSearch_CoarseForSPN Failed"));
        goto errout;
    }
    DBGPRINT(DBG_ON(DBG_TRACE), ("i_coarse: %u\n\n", i_coarse));

    /* Get information from that coarse */
    ref_to_EP_fine      = pClpInfoEpMapCoarse[i_coarse].ref_to_EP_fine_id;
    next_ref_to_EP_fine = (i_coarse+1 < ulNumCoarseEntries) ? pClpInfoEpMapCoarse[i_coarse+1].ref_to_EP_fine_id : ulNumFineEntries;
    SPN_EP_coarse       = pClpInfoEpMapCoarse[i_coarse].SPN_EP_coarse;
    PTS_EP_coarse       = pClpInfoEpMapCoarse[i_coarse].PTS_EP_coarse >> 1;

    DBGPRINT(DBG_ON(DBG_VERBOSE), (" ref to ep fine = %u\n", ref_to_EP_fine));
    DBGPRINT(DBG_ON(DBG_VERBOSE), (" ref to next ep fine = %u\n", next_ref_to_EP_fine));
    DBGPRINT(DBG_ON(DBG_VERBOSE), (" SPN_EP_coarse = 0x%x\n\n", SPN_EP_coarse));

    /* search the fines of the related coarse for the current position */
    if ( CLPINFO_SUCCESS != ClpInfoSearch_FineForSPN(i_coarse, spnCurrentPosition, &i_fine))
    {
        DBGPRINT(DBG_ON(DBG_ERROR), (" ClpInfoSearch_FineForSPN Failed"));
        goto errout;
    }
    DBGPRINT(DBG_ON(DBG_TRACE), ("i_fine: %u\n\n", i_fine));



    increment         =  (!fReverse) ? 1 : -1;
    i_coarse_endpoint =  (!fReverse) ? ulCoarseEndIndex    : ulCoarseStartIndex;


    if (fAngle == FALSE)  /* just get the first I-frame */
    {
        const ULONG I_tp_size[8]          = {0, 683, 1366, 2048, 3072, 4779, 6827, 0};         /* rounded up to a full source packet */

        ULONG spnIstart;
        ULONG spnIend;

        /* FOUND point */
        *ulAngleChangePointPTS = (PTS_EP_coarse << 19) | (pClpInfoEpMapFine[i_fine].PTS_EP_fine << 8);
        *ciAnglePoint          = i_coarse;
        *fiAnglePoint          = i_fine;

        /* Find the SPN of the end of the I-frame (or, if we're not in an I-frame, return the current SPN) */
        {
            spnIstart = (SPN_EP_coarse & 0xfffe0000) | pClpInfoEpMapFine[i_fine].SPN_EP_fine;
            spnIend   = spnIstart + I_tp_size[pClpInfoEpMapFine[i_fine].I_end_position_offset];

            /* if the index into the I_tp_size array is 7, we need to play up to the next I-frame */
            if (spnIstart == spnIend)
            {
                i_fine++;

                /* if the next I-frame is after the next coarse, get the next coarse */
                if (i_fine >= next_ref_to_EP_fine)
                {
                    i_coarse++;

                    /* If the next coarse is after the end, we're done looking - return failure */
                    if (i_coarse >= i_coarse_endpoint)
                    {
                        goto errout;
                    }
                    SPN_EP_coarse = pClpInfoEpMapCoarse[i_coarse].SPN_EP_coarse;
                }

                /* Get the SPN of the start of the next I-frame */
                spnIend = (SPN_EP_coarse & 0xfffe0000) | pClpInfoEpMapFine[i_fine].SPN_EP_fine;
            }
        }

        /*
         * determine if we're within an I-frame (and need to play through the rest of it)
         *    or if we're outside of an I-frame (and can stop playing right here)
         */
        *ulAngleChangePointSPN = (spnCurrentPosition < spnIend) ? spnIend : spnCurrentPosition;

        return(CLPINFO_SUCCESS);           /* if the point found is valid, return success here */
    }
    else   /* get the first I-frame that is an angle change point */
    {
        /* search the rest of the fines in this coarse for an angle change point */
        if ( CLPINFO_SUCCESS == ClpInfoSearch_FineForAngle(fReverse, i_fine+increment, next_ref_to_EP_fine-1, &i_fine))
        {
            /* FOUND angle change point */
            *ulAngleChangePointSPN = (SPN_EP_coarse & 0xfffe0000) | pClpInfoEpMapFine[i_fine].SPN_EP_fine;
            *ulAngleChangePointPTS = (PTS_EP_coarse << 19) | (pClpInfoEpMapFine[i_fine].PTS_EP_fine << 8);
            *ciAnglePoint          = i_coarse;
            *fiAnglePoint          = i_fine;
            if (*ulAngleChangePointSPN >= spnCurrentPosition)
            {
                return(CLPINFO_SUCCESS);           /* if the point found is valid, return success here */
            }                                 /* otherwise, keep looking - starting at the next coarse */
        }

        /* angle change point not  yet found.  we need to go to the next coarse and then search its associated fines */
        while (i_coarse != i_coarse_endpoint)
        {
            /* next coarse */
            i_coarse += increment;

            /* get info from that coarse */
            ref_to_EP_fine      = pClpInfoEpMapCoarse[i_coarse].ref_to_EP_fine_id;
            next_ref_to_EP_fine = (i_coarse+1 < ulNumCoarseEntries) ? pClpInfoEpMapCoarse[i_coarse+1].ref_to_EP_fine_id : ulNumFineEntries;
            SPN_EP_coarse       = pClpInfoEpMapCoarse[i_coarse].SPN_EP_coarse;
            PTS_EP_coarse       = pClpInfoEpMapCoarse[i_coarse].PTS_EP_coarse >> 1;

⌨️ 快捷键说明

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