cameradriver.h

来自「该BSP是基于PXA270+WINCE的BSP」· C头文件 代码 · 共 441 行

H
441
字号
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
//
/**************************************************************************
** Copyright 2000-2004 Intel Corporation. All Rights Reserved.
**
** Portions of the source code contained or described herein and all documents
** related to such source code (Material) are owned by Intel Corporation
** or its suppliers or licensors and is licensed by Microsoft Corporation for distribution.  
** Title to the Material remains with Intel Corporation or its suppliers and licensors. 
** Use of the Materials is subject to the terms of the Microsoft license agreement which accompanied the Materials.  
** No other license under any patent, copyright, trade secret or other intellectual
** property right is granted to or conferred upon you by disclosure or
** delivery of the Materials, either expressly, by implication, inducement,
** estoppel or otherwise 
** Some portion of the Materials may be copyrighted by Microsoft Corporation.
********************************************************************************/


#ifndef __CAMERADRIVER_H__
#define __CAMERADRIVER_H__

#include <windows.h>
#include <ceddk.h>
#include <linklist.h>
#include "Cs.h"
#include "Csmedia.h"

extern "C" {
    #include <bulverde.h>
}


#ifndef DEBUG

#undef  DEBUGMSG
#define DEBUGMSG RETAILMSG

#define ZONE_ERROR           (1)
#define ZONE_WARN            (1)
#define ZONE_INIT            (1)
#define ZONE_FUNCTION        (0)
#define ZONE_IOCTL           (0)
#define ZONE_DEVICE          (0)

#endif // DEBUG

#ifdef DEBUG

#define DEBUGMASK(bit)       (1 << (bit))

#define MASK_ERROR           DEBUGMASK(0)
#define MASK_WARN            DEBUGMASK(1)
#define MASK_INIT            DEBUGMASK(2)
#define MASK_FUNCTION        DEBUGMASK(3)
#define MASK_IOCTL           DEBUGMASK(4)
#define MASK_DEVICE          DEBUGMASK(5)

#ifdef CAMINTERFACE
DBGPARAM dpCurSettings = {
    _T("Camera"), 
    {
        _T("Errors"), _T("Warnings"), _T("Init"), _T("Function"), 
        _T("Ioctl"), _T("Device"), _T("Activity"), _T(""),
        _T(""),_T(""),_T(""),_T(""),
        _T(""),_T(""),_T(""),_T("") 
    },
    MASK_ERROR | MASK_WARN | MASK_INIT
}; 
#else
extern DBGPARAM dpCurSettings;
#endif

#define ZONE_ERROR           DEBUGZONE(0)
#define ZONE_WARN            DEBUGZONE(1)
#define ZONE_INIT            DEBUGZONE(2)
#define ZONE_FUNCTION        DEBUGZONE(3)
#define ZONE_IOCTL           DEBUGZONE(4)
#define ZONE_DEVICE          DEBUGZONE(5)

#endif


#define PIN_REG_PATH         TEXT("Software\\Microsoft\\DirectX\\DirectShow\\Capture")

#define dim(x)               (sizeof(x) / sizeof(x[0]))

#define SAFEDELETE( pointer ) \
    if ( NULL != pointer )    \
    {                         \
        delete pointer;       \
        pointer = NULL;       \
    }

#define MAX_SUPPORTED_PINS        2
#define MAX_PINNAME_LENGTH       10
#define MAX_VIDEO_FORMAT         10
#define NUM_VIDEOPROCAMP_ITEMS   10
#define NUM_CAMERACONTROL_ITEMS   8
#define NUM_PROPERTY_ITEMS       NUM_VIDEOPROCAMP_ITEMS + NUM_CAMERACONTROL_ITEMS

#define MAX_HW_FRAMES             3  


// CAPTURE and STILL are required pin types. PREVIEW (or VIDEOPORT) is optional, so list it last.
enum
{
    CAPTURE = 0,
    STILL,
    PREVIEW
};

static const WCHAR g_wszPinNames[MAX_SUPPORTED_PINS][MAX_PINNAME_LENGTH] = { L"Capture"
                                                                            ,L"Still"
                                                                            //,L"Preview"
                                                                            };

static const WCHAR g_wszPinDeviceNames[MAX_SUPPORTED_PINS][MAX_PINNAME_LENGTH] = {L"PIN1:"
                                                                                  ,L"PIN1:"
                                                                                  //,L"PIN1:"
                                                                                  };

typedef struct _Supported_Video_Formats
{
    GUID                categoryGUID;
    ULONG               ulAvailFormats;
    PCS_DATARANGE_VIDEO pCsDataRangeVideo[ MAX_VIDEO_FORMAT ];
} PINVIDEOFORMAT, * PPINVIDEOFORMAT;

typedef struct _Dev_Property 
{
    ULONG                     ulDefaultValue;
    ULONG                     ulCurrentValue;
    ULONG                     ulFlags;
    ULONG                     ulCapabilities;
    PCSPROPERTY_VALUES        pCsPropValues;
    PCSPROPERTY_STEPPING_LONG pRangeNStep;
    BOOL                      fGetSupported;
    BOOL                      fSetSupported;
} DEV_PROPERTY, * PDEV_PROPERTY;

typedef struct _Video_Control_Caps
{
    ULONG ulVideoControlCaps;
} VIDCONTROLCAPS, *PVIDCONTROLCAPS;

class CPinDevice;

typedef struct _StreamInstances
{
    ULONG        ulCInstances;
    CSSTATE      CsPrevState;
    CPinDevice * pPinDev;
} STREAM_INSTANCES, * PSTREAM_INSTANCES;


typedef struct CCameraOpenHandle CAMERAOPENHANDLE, *PCAMERAOPENHANDLE;

typedef class CCameraDevice 
{
public:
    CCameraDevice( );

    ~CCameraDevice( );
    
    bool
    Initialize(
        PVOID context
        );

    PCAMERAOPENHANDLE
    BindApplicationProc( );

    void
    UnBindApplicationProc( PCAMERAOPENHANDLE );
    
    DWORD
    AdapterHandlePowerRequests(
        DWORD dwCode,
        __in_bcount(InBufLen) PUCHAR pInBuf,
        DWORD  InBufLen,
        __out_bcount(OutBufLen) PUCHAR pOutBuf,
        DWORD  OutBufLen,
        PDWORD pdwBytesTransferred
        );
    
    DWORD
    AdapterHandlePinRequests(
        __in_bcount(InBufLen) PUCHAR pInBuf,
        DWORD  InBufLen,
        __out_bcount(OutBufLen) PUCHAR pOutBuf,
        DWORD  OutBufLen,
        PDWORD pdwBytesTransferred
        );

    DWORD
    AdapterHandleVersion(
        __out_bcount(OutBufLen) PUCHAR pOutBuf,
        DWORD  OutBufLen,
        PDWORD pdwBytesTransferred
        );        

    DWORD
    AdapterHandleVidProcAmpRequests(
        __in_bcount(InBufLen) PUCHAR pInBuf,
        DWORD  InBufLen,
        __out_bcount(OutBufLen) PUCHAR pOutBuf,
        DWORD  OutBufLen,
        PDWORD pdwBytesTransferred 
        );

    DWORD
    AdapterHandleCamControlRequests(
        __in_bcount(InBufLen) PUCHAR pInBuf,
        DWORD  InBufLen,
        __out_bcount(OutBufLen) PUCHAR pOutBuf,
        DWORD  OutBufLen,
        PDWORD pdwBytesTransferred
        );

    DWORD
    AdapterHandleCompressionRequests(
        __in_bcount(InBufLen) PUCHAR pInBuf,
        DWORD  InBufLen,
        __out_bcount(OutBufLen) PUCHAR pOutBuf,
        DWORD  OutBufLen,
        PDWORD pdwBytesTransferred
        );

    DWORD
    AdapterHandleVideoControlRequests(
        __in_bcount(InBufLen) PUCHAR pInBuf,
        DWORD  InBufLen,
        __out_bcount(OutBufLen) PUCHAR pOutBuf,
        DWORD  OutBufLen,
        PDWORD pdwBytesTransferred
        );
    
    DWORD
    AdapterHandleDroppedFramesRequests(
        __in_bcount(InBufLen) PUCHAR pInBuf,
        DWORD  InBufLen,
        __out_bcount(OutBufLen) PUCHAR pOutBuf,
        DWORD  OutBufLen,
        PDWORD pdwBytesTransferred
        );
    
    LPVOID
    ValidateBuffer(
        __in_bcount(ulActualBufLen) LPVOID  lpBuff,
        ULONG   ulActualBufLen,
        ULONG   ulExpectedBuffLen,
        DWORD * dwError
        );
    
    bool
    AdapterCompareFormat(
        const ULONG                 ulPinId,
        const PCS_DATARANGE_VIDEO   pCsDataRangeVideoToCompare,
        PCS_DATARANGE_VIDEO       * ppCsDataRangeVideoMatched,
        bool                        fDetailedComparison
        );

    bool
    AdapterCompareFormat(
        const ULONG                            ulPinId,
        const PCS_DATAFORMAT_VIDEOINFOHEADER   pCsDataRangeVideoToCompare,
        PCS_DATARANGE_VIDEO                  * ppCsDataRangeVideoMatched,
        bool                                   fDetailedComparison
        );

    bool
    IsValidPin(
        ULONG ulPinId
        );

    bool
    GetPinFormat(
        ULONG                 ulPinId,
        ULONG                 ulIndex,
        PCS_DATARANGE_VIDEO * ppCsDataRangeVid
        );

    bool
    GetZoom(
        PULONG pulZoom 
        );

    bool
    GetBrightness(
        PULONG pulBrightness
        );

    bool
    IncrCInstances(
        ULONG        ulPinId,
        CPinDevice * pPinDev
        );

    bool
    DecrCInstances(
        ULONG ulPinId
        );

    bool
    PauseCaptureAndPreview( );

    bool
    RevertCaptureAndPreviewState( );

    bool
    StartHWCapture( );

    bool
    StopHWCapture( );
    
    bool
    CaptureHWStillImage( );

    bool
    GetCurrentHWBuffer (
        ULONG ulPinId,
        P_CAMERA_DMA_BUFFER_INFO pCamDmaBuffer
        );

    void
    CameraHandleVideoFrame ( );

    void
    CameraHandleStillFrame ( );

private:

    bool
    AllocateHWBuffers (
        ULONG ucBufferType
        );

    bool
    DeAllocateHWBuffers (
        ULONG ucBufferType
        );

    void
    GetBasicSupportInfo(
        __out_bcount(OutBufLen) PUCHAR        pOutBuf,
        DWORD         OutBufLen,
        PDWORD        pdwBytesTransferred,
        PDEV_PROPERTY pDevProp,
        PDWORD        pdwError
        );

    void
    GetDefaultValues(
        __out_bcount(OutBufLen) PUCHAR        pOutBuf,
        DWORD         OutBufLen,
        PDWORD        pdwBytesTransferred,
        PDEV_PROPERTY pDevProp,
        PDWORD        pdwError
        );

    bool
    AdapterCompareGUIDsAndFormatSize(
        const PCSDATARANGE DataRange1,
        const PCSDATARANGE DataRange2
        );

    void
    SuspendCamera( );
    
    void
    ResumeCamera( );



    CRITICAL_SECTION m_csDevice;        
    HANDLE           m_hStream;                        // Handle to the corresponding stream sub-device
    
    PINVIDEOFORMAT   m_PinVideoFormat[MAX_SUPPORTED_PINS];
    VIDCONTROLCAPS   m_PinVideoCaps[MAX_SUPPORTED_PINS];
    ULONG            m_ulCTypes;
    STREAM_INSTANCES m_StrmInstances[MAX_SUPPORTED_PINS];

    ULONG            m_ulPropSetSupported;             // Number of property item supported.
    CSPROPERTY_SET   m_VideoProcAmpSet;                // This is also the beginning of the property set table.
    CSPROPERTY_SET   m_CameraControlSet;

    //
    // Property items of what device supports 
    //
    CSPROPERTY_ITEM  m_VideoProcAmpItems[NUM_VIDEOPROCAMP_ITEMS];
    CSPROPERTY_ITEM  m_CameraControlItems[NUM_CAMERACONTROL_ITEMS];

    DEV_PROPERTY     m_DevProps[NUM_PROPERTY_ITEMS];

    bool             m_bCameraHWRunning;
    bool             m_bNewFrameReady;

    CAMERA_DMA_BUFFER_INFO m_CameraHWVideoBuffers[MAX_HW_FRAMES];
    CAMERA_DMA_BUFFER_INFO m_CameraHWStillBuffer;
    ULONG                  m_ulCurrentFrame;

    HANDLE m_hCameraShutdownComplete;

    // Camera context
    P_XLLP_Camera_Context_T  m_pXllpCAMERA;

    // device power state
    CEDEVICE_POWER_STATE m_PowerState;
    BOOL                 m_bCameraWasRunning;           // video capture was running before sleep

    LIST_ENTRY           m_hCameraOpenHandles;          // list of opened handles

    friend int CameraInitPdd(void * pContext);

} CAMERADEVICE, * PCAMERADEVICE;


typedef struct CCameraOpenHandle
{
    LIST_ENTRY    lList;
    HANDLE        hCallerProcess;
    int           cRef;
    PCAMERADEVICE pCamDevice;

} CAMERAOPENHANDLE, * PCAMERAOPENHANDLE;


void CameraVideoFrameCallback ( DWORD dwContext );
void CameraStillFrameCallback ( DWORD dwContext );

#endif // __CAMERADRIVER_H__

⌨️ 快捷键说明

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