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

📄 bcam.cpp

📁 BCAM 1394 Driver
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//-----------------------------------------------------------------------------
//  Company:  Basler Vision Technologies
//  Section:  Vision Components
//  Project:  1394 Driver
//  <b> Visual SourceSafe Information:</b>
//  $Archive: /Product/CFI/Dev/PC/ReviewSensorSupport/BCAM/Software_VS6/src/bcamapi/Bcam.cpp $
//  $Author: Nebelung, H.$
//  $Revision: 58$
//  $Date: 06.07.2006 10:20:29$
//-----------------------------------------------------------------------------
/**
 * \file     Bcam.cpp
 *
 *
 * \brief   Implementation of the user api
*/
//-----------------------------------------------------------------------------


#include <stdafx.h>
#pragma warning (disable: 4786) // identifier was truncated to '255' characters in the debug information
#pragma warning (disable: 4355) // 'this' used in base member initializer list
#pragma warning (disable: 4100 )
#pragma warning (disable: 4239 )
#pragma warning (disable: 4702) // unreachable code

#include <bcam.h>
#include <atlbase.h>
#include <bcamutility.h>
#include <setupapi.h>
#include <md5.h>

#ifndef BCAM_GUID_INITIALIZED
#include <initguid.h>
#include <bcam_guid.h>
#endif

#include <malloc.h>
#include <bcamerror.h>
#include <bcamversion.h>

#ifndef TRACE
/// In case we are using WTL replace TRACE calls by AtlTrace
#define TRACE AtlTrace
#endif

/******************************************************************************/
using namespace Bcam;

static CThread    s_MessageLoopThread;   ///< thread which runs the message loop for the message-only window

/*
* Synchronization of all camera objects
*/
static CCriticalSection s_TheCriticalSection;

typedef CAutoLock<CCriticalSection> CLock;

///////////////////////////////////////////////////////////////////////////////
//
// struct BcamOL
//
///////////////////////////////////////////////////////////////////////////////
//------------------------------------------------------------------------------
// struct BcamOL 
// Author: Hartmut Nebelung
//------------------------------------------------------------------------------
/**
* \brief   An extended overlapped structure used for kernel-mode calls
*
* This structure is passed to DeviceIoControl-calls to the kernel-mode
* and is collected at the completion port (in case of asynchronous calls).
* 
* \see GetNewBcamOL, Transmit
*/
//------------------------------------------------------------------------------
struct Bcam::BcamOL
{
  OVERLAPPED ol;            ///< Win32-Api defined structure, needed for all calls
  FunctionCode_t function;  ///< Function code to identify the function called
  PVOID pContext;           ///< Pointer to user provided context 
};

//------------------------------------------------------------------------------
// static BcamOL* GetNewBcamOL( FunctionCode_t func, PVOID pContext )
// Author: Hartmut nebelung
//------------------------------------------------------------------------------
/**
* \brief Create a BcamOL structure on the heap and initializes it.
*
* \param     func         The function code to identify the call.
* \param     pContext     The user defined context, may be NULL.
* \return    
*
* Returns an initialized BcamOL structure.
* 
*/
//------------------------------------------------------------------------------
static BcamOL* GetNewBcamOL( FunctionCode_t func, PVOID pContext )
{
  BcamOL* p = new BcamOL;
  if (NULL == p)
    throw BcamException( Bvc::ErrorNumber( E_OUTOFMEMORY ), _T( "GetBcamOL" ));
  
  p->ol.hEvent = NULL;
  p->ol.Internal = 0;
  p->ol.InternalHigh  = 0;
  p->ol.Offset = 0;
  p->ol.OffsetHigh = 0;
  p->pContext = pContext;
  p->function = func;
  
  return p;
}

///////////////////////////////////////////////////////////////////////////////
//
// class CDriverVersionCheck
//
///////////////////////////////////////////////////////////////////////////////
class CDriverVersionCheck
{
public:
  static bool Match();
  static bool s_DriverMatched;
};

bool CDriverVersionCheck::s_DriverMatched;

///////////////////////////////////////////////////////////////////////////////
//
// class BcamUtility
//
///////////////////////////////////////////////////////////////////////////////

//------------------------------------------------------------------------------
// CString BcamUtility::VideoResolutionName(DCSVideoFormat VideoFormat, DCSVideoMode VideoMode)
// Author: A.Happe
//------------------------------------------------------------------------------
/**
* \brief Looks up the video resolution.
* It is restricted to formats 0 to 2.
* If the combination is not supported a BcamException with code 
* BCAM_E_UNSUPPORTED_VIDEO_MODE is thrown.
*
* \param     VideoFormat Code of the video format
* \param     VideoMode Code of the video mode
* \return    
*
* Returns a string representation of the video resolution.
* 
* \todo      
*/
//------------------------------------------------------------------------------
CString BcamUtility::VideoResolutionName(DCSVideoFormat VideoFormat, DCSVideoMode VideoMode)
{
  switch ( VideoFormat )
  {
  case DCS_Format0:
    {
      switch ( VideoMode )
      {
      case DCS_Mode0:
        return _T( "160 x 120, YUV(4:4:4)" );
      case DCS_Mode1:
        return _T( "320 x 240, YUV(4:2:2)" );
      case DCS_Mode2:
        return _T( "640 x 480, YUV(4:1:1)" );
      case DCS_Mode3:
        return _T( "640 x 480, YUV(4:2:2)" );
      case DCS_Mode4:
        return _T( "640 x 480, RGB" );
      case DCS_Mode5:
        return _T( "640 x 480, Mono8" );
      case DCS_Mode6:
        return _T( "640 x 480, Mono16" );
      default:
        throw BcamException(BCAM_E_UNSUPPORTED_VIDEO_MODE, _T( "VideoResolutionName()" ), &VideoMode);
      }
      break;
    }
  case DCS_Format1:
    {
      switch ( VideoMode )
      {
      case DCS_Mode0:
        return _T( "800 x 600, YUV(4:2:2)" );
      case DCS_Mode1:
        return _T( "800 x 600, RGB" );
      case DCS_Mode2:
        return _T( "800 x 600, Mono8" );
      case DCS_Mode3:
        return _T( "1024 x 768, YUV(4:2:2)" );
      case DCS_Mode4:
        return _T( "1024 x 768, RGB" );
      case DCS_Mode5:
        return _T( "1024 x 768, Mono8" );
      case DCS_Mode6:
        return _T( "800 x 600, Mono16" );
      case DCS_Mode7:
        return _T( "1024 x 768, Mono16" );
      default:
        throw BcamException(BCAM_E_UNSUPPORTED_VIDEO_MODE, _T( "VideoResolutionName()" ), &VideoMode);
      }
      break;
    }
  case DCS_Format2:
    {
      switch ( VideoMode )
      {
      case DCS_Mode0:
        return _T( "1280 x 960, YUV(4:2:2)" );
      case DCS_Mode1:
        return _T( "1280 x 960, RGB" );
      case DCS_Mode2:
        return _T( "1280 x 960, Mono8" );
      case DCS_Mode3:
        return _T( "1600 x 1200, YUV(4:2:2)" );
      case DCS_Mode4:
        return _T( "1600 x 1200, RGB" );
      case DCS_Mode5:
        return _T( "1600 x 1200, Mono8" );
      case DCS_Mode6:
        return _T( "1280 x 960, Mono16" );
      case DCS_Mode7:
        return _T( "1600 x 1200, Mono16" );
      default:
        throw BcamException(BCAM_E_UNSUPPORTED_VIDEO_MODE, _T( "VideoResolutionName()" ), &VideoMode);
      }
      break;
    }
  default:
    throw BcamException(BCAM_E_UNSUPPORTED_VIDEO_FORMAT, _T( "VideoResolutionName()" ), &VideoFormat);
  }
}

//------------------------------------------------------------------------------
// CString BcamUtility::VideoFrameRateName(DCSVideoFrameRate VideoFrameRate)
// Author: 
//------------------------------------------------------------------------------
/**
* \brief Get a string representation of the framerate.
*
* \param     VideoFrameRate
* \return    
*
* Returns a string representation of the framerate
* 
*/
//------------------------------------------------------------------------------
CString BcamUtility::VideoFrameRateName(DCSVideoFrameRate VideoFrameRate)
{
  switch ( VideoFrameRate )
  {
  case DCS_1_875fps : return _T( "1.875 fps" );
  case DCS_3_75fps : return _T( "3.75 fps" );
  case DCS_7_5fps : return _T( "7.5 fps" );
  case DCS_15fps : return _T( "15 fps" );
  case DCS_30fps : return _T( "30 fps" );
  case DCS_60fps : return _T( "60 fps" );
  case DCS_120fps : return _T( "120 fps" );
  case DCS_240fps : return _T( "240 fps" );
  default:
    throw BcamException(Bvc::ErrorNumber( E_INVALIDARG ), _T( "VideoFrameRateName" ) );
  }
}

//------------------------------------------------------------------------------
// CString BcamUtility::FeatureName(BcamFeatureID id)
// Author: A.Happe
//------------------------------------------------------------------------------
/**
* \brief Get a string representation of the feature id.
*
* \param     id Identifier of the feature.
* \return    
*
* Returns a string representation of the feature
* 
*/
//------------------------------------------------------------------------------
CString BcamUtility::FeatureName(BcamFeatureID id)
{
  switch ( id )
  {
  case FeatureID_Brightness : 
    return _T( "Brightness" );
  case FeatureID_AutoExposure : 
    return _T( "Auto Exposure" );
  case FeatureID_Sharpness :
    return _T( "Sharpness" );
  case FeatureID_WhiteBalance :
    return _T( "WhiteBalance" );
  case FeatureID_Hue :
    return _T( "Hue" );
  case FeatureID_Saturation :
    return _T( "Saturation" );
  case FeatureID_Gamma :
    return _T( "Gamma" );
  case FeatureID_Shutter :
    return _T( "Shutter" );
  case FeatureID_Gain :
    return _T( "Gain" );
  case FeatureID_Iris :
    return _T( "Iris" );
  case FeatureID_Focus :
    return _T( "Focus" );
  case FeatureID_Temparature :
    return _T( "Temperature" );
  case FeatureID_Trigger :
    return _T( "Trigger" );
  case FeatureID_Zoom  :
    return _T( "Zoom" );
  case FeatureID_Pan :
    return _T( "Pan" );
  case FeatureID_Tilt :
    return _T( "Tilt" );
  case FeatureID_OpticalFilter :
    return _T( "Optical Filter" );
  case FeatureID_CaptureSize :
    return _T( "Capture Size" );
  case FeatureID_CaptureQuality :
    return _T( "Capture Quality" );
  }
  throw BcamException(BCAM_E_INVALID_OR_UNKNOWN_FEATURE_ID, _T( "BcamUtility::FeatureName()" ) );
}

//------------------------------------------------------------------------------
// unsigned long BcamUtility::BytePerPacket(DCSVideoFormat VideoFormat, DCSVideoMode VideoMode, DCSVideoFrameRate VideoFramerate)
// Author: AHappe
//------------------------------------------------------------------------------
/**
* \brief Computes the size of the isocronous packets.
*
* \param     VideoFormat 
* The code of the video format.
* \param     VideoMode
* The code of the video mode.
* \param     VideoFramerate
* The code of the video framerate.
* \return    
*
* Returns the size of the isochronous packet. If the combination of VideoFormat, VideoMode and VideoFramerate is not
* supported a BcamException( BCAM_E_UNSUPPORTED_VIDEO_MODE ) is thrown.
* 
* \see       DCS 2.1.2, AllocateResources
* \todo      
*/
//------------------------------------------------------------------------------
unsigned long BcamUtility::BytePerPacket(DCSVideoFormat VideoFormat, DCSVideoMode VideoMode, DCSVideoFrameRate VideoFramerate)
{
    unsigned long BytePerPacket = 0;
    const unsigned long shiftval = DCS_240fps - VideoFramerate;
    switch ( VideoFormat )
    {
    case 0:
        switch ( VideoMode )
        {
        case 0:
            BytePerPacket =  3*640 >> shiftval;
            break;
        case 1:
            BytePerPacket = 2*2560 >> shiftval;
            break;
        case 2:
            BytePerPacket = 3*10240/2 >> shiftval;
            break;
        case 3:
            BytePerPacket = 2*10240 >> shiftval;
            break;
        case 4:
            BytePerPacket = 3*10240 >> shiftval;
            break;

⌨️ 快捷键说明

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