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

📄 cameradevice.cpp

📁 freescale i.mx31 BSP CE5.0全部源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//
// Function: BindApplicationProc
//
// Saves the handle of the caller process.
//
// Parameters:
//      hCurrentProc
//          [in] Handle to caller process to save.
//
// Returns:
//      TRUE if success
//      FALSE if failure
//
//-----------------------------------------------------------------------------
bool CCameraDevice::BindApplicationProc(HANDLE hCurrentProc)
{
    if ( NULL != m_hCallerProcess )
    {
        return false;
    }

    m_hCallerProcess = hCurrentProc;

    return true;
}


//-----------------------------------------------------------------------------
//
// Function: UnBindApplicationProc
//
// 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")));

    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)
{
#ifdef SUPPORT_3_PINS
    if (PREVIEW > ulPinId || STILL < ulPinId)
    {
        return false;
    }
#else
    if (CAPTURE > ulPinId || STILL < ulPinId)
    {
        return false;
    }
#endif

    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 )
{
#ifdef SUPPORT_3_PINS
    if (NULL != m_StrmInstances[PREVIEW].pPinDev) 
    {
        m_StrmInstances[PREVIEW].pPinDev->SetState(CSSTATE_PAUSE, 
            &m_StrmInstances[PREVIEW].CsPrevState);
    }
#endif

    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 )
{
#ifdef SUPPORT_3_PINS
    if (NULL != m_StrmInstances[PREVIEW].pPinDev) 
    {
        m_StrmInstances[PREVIEW].pPinDev->SetState(m_StrmInstances[PREVIEW].CsPrevState, NULL);
    }
#endif
    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 (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
//
//-----------------------------------------------------------------------------
bool CCameraDevice::AdapterCompareGUIDsAndFormatSize(
    const PCSDATARANGE DataRange1,
    const PCSDATARANGE DataRange2
    )
{
    return (IsEqualGUID(DataRange1->MajorFormat, DataRange2->MajorFormat)
        && IsEqualGUID(DataRange1->SubFormat, DataRange2->SubFormat)
        && IsEqualGUID(DataRange1->Specifier, DataRange2->Specifier));
}


//-----------------------------------------------------------------------------
//
// Function: ValidateBuffer
//
// Check if the data buffer is valid.
//
// Parameters:
//      lpBuff
//          [in] Buffer to validate.
//
//      ulActualBufLen
//          [in] Length of buffer to validate.
//
//      ulExpectedBuffLen
//          [in] Buffer length expected.
//
//      dwError
//          [in] Return error code.
//
// Returns:
//      The buffer pointer if successful.
//      NULL if invalid.
//
//-----------------------------------------------------------------------------
LPVOID CCameraDevice::ValidateBuffer(
    LPVOID   lpBuff,
    ULONG    ulActualBufLen,
    ULONG    ulExpectedBuffLen,
    DWORD  * dwError
    )
{
    LPVOID lpMapped = NULL;

    if (NULL == lpBuff)
    {
        DEBUGMSG(ZONE_IOCTL | ZONE_ERROR, (_T("IOControl(%08x): buffer is NULL\r\n"), this));
        *dwError = ERROR_INSUFFICIENT_BUFFER;

        return NULL;
    }

    if (ulActualBufLen < ulExpectedBuffLen)
    {
        DEBUGMSG(ZONE_IOCTL|ZONE_ERROR, (_T("IOControl(%08x): buffer is not large enough\r\n"), this));
        *dwError = ERROR_INSUFFICIENT_BUFFER;

        return NULL;
    }

⌨️ 快捷键说明

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