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

📄 cameradevice.cpp

📁 Microsoft WinCE 6.0 BSP FINAL release source code for use with the i.MX27ADS TO2 WCE600_FINAL_MX27_S
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//
// Releases the handle of the caller process.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::UnBindApplicationProc()
{
    DEBUGMSG(ZONE_FUNCTION, (_T("CAM_Close: Unbind application from camera device\r\n")));

    CameraPowerDown(TRUE);

    m_hCallerProcess = NULL;

    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: IsValidPin
//
// Determine if the pin ID is a valid ID.
//
// Parameters:
//      ulPinId
//          [in] Pin ID to check for validity.
//
// Returns:
//      TRUE if pin is valid
//      FALSE if pin is invalid
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::IsValidPin(ULONG ulPinId)
{
    if ( ulPinId >= m_ulCTypes )
    {
        return FALSE;
    }

    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: IncrCInstances
//
// Increase stream instance number for special pin.
//
// Parameters:
//      ulPinId
//          [in] Pin ID.
//
//      pPinDev
//          [in] Pin Device.
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::IncrCInstances(
    ULONG        ulPinId,
    CPinDevice * pPinDev
    )
{
    if (FALSE == IsValidPin(ulPinId) || 1 == m_StrmInstances[ulPinId].ulCInstances)
    {
        return FALSE;
    }
    else
    {
        m_StrmInstances[ulPinId].ulCInstances++;
        m_StrmInstances[ulPinId].pPinDev = pPinDev;
    }

    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: DecrCInstances
//
// Decrease stream instance number for special pin.
//
// Parameters:
//      ulPinId
//          [in] Pin ID.
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::DecrCInstances(ULONG ulPinId)
{
    if (FALSE == IsValidPin(ulPinId) || 0 == m_StrmInstances[ulPinId].ulCInstances)
    {
        return FALSE;
    }
    else
    {
        m_StrmInstances[ulPinId].ulCInstances--;
        m_StrmInstances[ulPinId].pPinDev = NULL;
    }

    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: PauseCaptureAndPreview
//
// Set capture and preview pins to pause.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::PauseCaptureAndPreview( void )
{
    if ( PREVIEW < m_ulCTypes )
    {
        if (NULL != m_StrmInstances[PREVIEW].pPinDev) 
        {
            m_StrmInstances[PREVIEW].pPinDev->SetState( CSSTATE_PAUSE, &m_StrmInstances[PREVIEW].CsPrevState );
        }
    }

    if (NULL != m_StrmInstances[CAPTURE].pPinDev)
    {
        m_StrmInstances[CAPTURE].pPinDev->SetState( CSSTATE_PAUSE, &m_StrmInstances[CAPTURE].CsPrevState );
    }

    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: RevertCaptureAndPreviewState
//
// Revert capture and preview pins to state before pause.
//
// Parameters:
//      None.
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::RevertCaptureAndPreviewState( void )
{
    if (( PREVIEW < m_ulCTypes ) && (NULL != m_StrmInstances[PREVIEW].pPinDev))
    {
        m_StrmInstances[PREVIEW].pPinDev->SetState(m_StrmInstances[PREVIEW].CsPrevState, NULL);
    }

    if (NULL != m_StrmInstances[CAPTURE].pPinDev)
    {
        m_StrmInstances[CAPTURE].pPinDev->SetState(m_StrmInstances[CAPTURE].CsPrevState, NULL);
    }

    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: GetPinFormat
//
// Get video format for given pin.
//
// Parameters:
//      ulPinId
//          [in] Pin id.
//
//      ulIndex
//          [in] Index for CS_DATARANGE_VIDEO for given pin.
//
//      ppCsDataRangeVid
//          [out] CS_DATARANGE_VIDEO return value.
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::GetPinFormat(
    ULONG                 ulPinId,
    ULONG                 ulIndex,
    PCS_DATARANGE_VIDEO * ppCsDataRangeVid
    )
{
    if ( 0 >= ulIndex || ulIndex > m_PinVideoFormat[ulPinId].ulAvailFormats )
    {
        return FALSE;
    }

    *ppCsDataRangeVid = m_PinVideoFormat[ulPinId].pCsDataRangeVideo[ulIndex-1];

    return TRUE;
}

//-----------------------------------------------------------------------------
//
// Function: AdapterCompareFormat
//
// Compare media format.
//
// Parameters:
//      ulPinId
//          [in] Pin id.
//
//      pCsDataRangeVideoToCompare
//          [in] CS_DATARANGE_VIDEO to compare.
//
//      ppCsDataRangeVideoMatched
//          [out] CS_DATARANGE_VIDEO return value.
//
//      fDetailedComparison
//          [in] If true, a detailed comparison of formats is made.
//
// Returns:
//      TRUE if matched
//      FALSE if not matched
//
//-----------------------------------------------------------------------------
BOOL CCameraDevice::AdapterCompareFormat(
    ULONG                       ulPinId,
    const PCS_DATARANGE_VIDEO   pCsDataRangeVideoToCompare,
    PCS_DATARANGE_VIDEO       * ppCsDataRangeVideoMatched,
    BOOL                        fDetailedComparison
    )
{
    for (ULONG ulCount = 0; ulCount < m_PinVideoFormat[ulPinId].ulAvailFormats; ulCount++)
    {
        PCS_DATARANGE_VIDEO pCsDataRangeVideo = m_PinVideoFormat[ulPinId].pCsDataRangeVideo[ulCount];

        if (FALSE == AdapterCompareGUIDsAndFormatSize(reinterpret_cast<PCSDATARANGE>(pCsDataRangeVideo),
            reinterpret_cast<PCSDATARANGE>(pCsDataRangeVideoToCompare))) 
        {
            continue;
        }

        if (TRUE == fDetailedComparison)
        {
            if ((pCsDataRangeVideoToCompare->bFixedSizeSamples != pCsDataRangeVideo->bFixedSizeSamples)
                  || (pCsDataRangeVideoToCompare->bTemporalCompression   != pCsDataRangeVideo->bTemporalCompression)
                  || (pCsDataRangeVideoToCompare->StreamDescriptionFlags != pCsDataRangeVideo->StreamDescriptionFlags)
                  || (pCsDataRangeVideoToCompare->MemoryAllocationFlags  != pCsDataRangeVideo->MemoryAllocationFlags)) 
            {
                continue;
            }

            if( pCsDataRangeVideoToCompare->VideoInfoHeader.AvgTimePerFrame < pCsDataRangeVideo->ConfigCaps.MinFrameInterval  ||
                pCsDataRangeVideoToCompare->VideoInfoHeader.AvgTimePerFrame > pCsDataRangeVideo->ConfigCaps.MaxFrameInterval  )
            {
                continue;
            }

            // Real Camera drivers can now do ConfigCaps related intersection. Null driver doesn't do such comparison
            if ( 0 != memcmp(&pCsDataRangeVideoToCompare->VideoInfoHeader.bmiHeader, &pCsDataRangeVideo->VideoInfoHeader.bmiHeader, sizeof (pCsDataRangeVideo->VideoInfoHeader.bmiHeader) ) )
            {
                continue;
            }
        }

        // You can now perform more granular comparison involving ConfigCaps and VIDOINFOHEADER etc.

        /////////////////////////////////////////
        if (NULL != ppCsDataRangeVideoMatched)
        {
            *ppCsDataRangeVideoMatched = pCsDataRangeVideo;
        }

        return TRUE;
    }

    return FALSE;
}


//-----------------------------------------------------------------------------
//
//  FUNCTION:        AdapterCompareFormat
//
//  DESCRIPTION:        compare media format
//
//  PARAMETERS:        ULONG ulPinId,
//                    const PCS_DATAFORMAT_VIDEOINFOHEADER   pCsDataVIHToCompare,
//                     PCS_DATARANGE_VIDEO       * ppCsDataRangeVideoMatched,
//                    bool fDetailedComparison
//
//  RETURNS:            TRUE if matched, otherwise return FALSE
//
//-----------------------------------------------------------------------------

BOOL CCameraDevice::AdapterCompareFormat(
    ULONG                                  ulPinId,
    const PCS_DATAFORMAT_VIDEOINFOHEADER   pCsDataVIHToCompare,
    PCS_DATARANGE_VIDEO                  * ppCsDataRangeVideoMatched,
    BOOL                                   fDetailedComparison
    )
{
    for ( ULONG ulCount = 0 ; ulCount < m_PinVideoFormat[ulPinId].ulAvailFormats ; ulCount++ )
    {
        PCS_DATARANGE_VIDEO pCsDataRangeVideo = m_PinVideoFormat[ulPinId].pCsDataRangeVideo[ulCount];

        if ( FALSE == AdapterCompareGUIDsAndFormatSize( reinterpret_cast<PCSDATARANGE>( pCsDataRangeVideo ),
                                                        reinterpret_cast<PCSDATARANGE>( pCsDataVIHToCompare ) ) )
        {
            continue;
        }

        if ( TRUE == fDetailedComparison )
        {

            if( pCsDataVIHToCompare->VideoInfoHeader.AvgTimePerFrame < pCsDataRangeVideo->ConfigCaps.MinFrameInterval  ||
                pCsDataVIHToCompare->VideoInfoHeader.AvgTimePerFrame > pCsDataRangeVideo->ConfigCaps.MaxFrameInterval  )
            {
                continue;
            }

            // Real Camera drivers can now do ConfigCaps related intersection. Null driver doesn't do such comparison
            if ( 0 != memcmp(&pCsDataVIHToCompare->VideoInfoHeader.bmiHeader, &pCsDataRangeVideo->VideoInfoHeader.bmiHeader, sizeof (pCsDataRangeVideo->VideoInfoHeader.bmiHeader) ) )
            {
                continue;
            }
        }

        // You can now perform more granular comparison involving ConfigCaps and VIDOINFOHEADER etc.

        /////////////////////////////////////////
        if ( NULL != ppCsDataRangeVideoMatched )
        {
            *ppCsDataRangeVideoMatched = pCsDataRangeVideo;
        }

        return TRUE;
    }

    return FALSE;
}

//-----------------------------------------------------------------------------
//
// Function: AdapterCompareGUIDsAndFormatSize
//
// Compare media's majorformat and subformat.
//
// Parameters:
//      DataRange1
//          [in] First media format to compare.
//
//      DataRange2
//          [in] Second media format to compare.
//
// Returns:
//      TRUE if matched
//      FALSE if not matched
//
//---------------------------------------

⌨️ 快捷键说明

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