📄 cameradevice.cpp
字号:
BSPGetSensorFormat(&sensorFormat);
sensorOutputFormat = (csiSensorOutputFormat) sensorFormat;
sensorOutputResolution = csiSensorOutputResolution_VGA;
// sensorOutputResolution = csiSensorOutputResolution_QVGA;
if (!m_pCsi->CsiConfigureSensor(sensorOutputFormat, sensorOutputResolution))
{
DEBUGMSG(ZONE_ERROR,
(TEXT("%s: Sensor configuration failed. Aborting remaining configuration steps.\r\n"), __WFUNCTION__));
return FALSE;
}
//----------------------------------------------------
// Set up preprocessor input parameters common
// to both encoding and viewfinding tasks
//----------------------------------------------------
if (sensorOutputFormat == csiSensorOutputFormat_RGB)
{
inFormat = prpInputFormat_RGB; // Interlaced RGB888
}
else if ((sensorOutputFormat == csiSensorOutputFormat_YUV422) ||
(sensorOutputFormat == csiSensorOutputFormat_YUV422))
{
inFormat = prpInputFormat_YUV444IL; // Interlaced YUV444 }
}
else
{
inFormat = prpInputFormat_Generic; // Bayer data
}
// inFormat = prpInputFormat_RGB; // Use this if we are
// are using CSI test pattern.
// Set up Preproc input width and height configuration
// parameters from the output resolution.
switch (sensorOutputResolution)
{
case csiSensorOutputResolution_SXGA:
inFrameSize.width = 1280;
inFrameSize.height = 960;
break;
case csiSensorOutputResolution_VGA:
inFrameSize.width = 640;
inFrameSize.height = 480;
break;
case csiSensorOutputResolution_QVGA:
inFrameSize.width = 320;
inFrameSize.height = 240;
break;
case csiSensorOutputResolution_CIF:
inFrameSize.width = 352;
inFrameSize.height = 288;
break;
case csiSensorOutputResolution_QCIF:
inFrameSize.width = 176;
inFrameSize.height = 144;
break;
case csiSensorOutputResolution_QQVGA:
inFrameSize.width = 160;
inFrameSize.height = 120;
break;
default:
break;
}
//----------------------------------------------------
// Configure viewfinding path if Preview pin is used
// and configuration is needed.
//----------------------------------------------------
if (!m_bCameraVfConfig && (m_StrmInstances[PREVIEW].pPinDev != NULL))
{
// Set input format and frame size config params
prpVfConfig.inputFormat = inFormat;
prpVfConfig.inputSize = inFrameSize;
Format = m_StrmInstances[PREVIEW].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biCompression;
switch (Format)
{
// Used by GSG in MX21 driver for RGB565
case CS_BI_BITFIELDS:
prpVfConfig.vfFormat = prpVfOutputFormat_RGB;
break;
case CS_BI_RGB:
prpVfConfig.vfFormat = prpVfOutputFormat_RGB;
break;
default:
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Invalid data format for preview.\r\n"), __WFUNCTION__));
return FALSE;
}
// Set up viewfinding channel CSC parameters
// based on input. We know output is RGB.
if (prpVfConfig.inputFormat == prpInputFormat_YUV444IL)
{
prpVfConfig.vfCSCEquation = prpCSCY2R_A1;
}
else
{
prpVfConfig.vfCSCEquation = prpCSCNoOp;
}
// TODO: Support Rotation
prpVfConfig.vfFlipRot.verticalFlip = m_bFlipVertical;
prpVfConfig.vfFlipRot.horizontalFlip = m_bFlipHorizontal;
prpVfConfig.vfFlipRot.rotate90 = m_bRotate;
// Set up viewfinding image output dimensions
prpVfConfig.vfSize.width = (UINT16)m_StrmInstances[PREVIEW].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biWidth;
prpVfConfig.vfSize.height = (UINT16)m_StrmInstances[PREVIEW].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biHeight;
// Set direct display variable
prpVfConfig.directDisplay = m_bDirectDisplay;
// Set up viewfinding window offset
prpVfConfig.vfOffset.x = (UINT16)m_StrmInstances[PREVIEW].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.rcTarget.left;
prpVfConfig.vfOffset.y = (UINT16)m_StrmInstances[PREVIEW].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.rcTarget.top;
//----------------------------------------------------
// Configure Preprocessor
//----------------------------------------------------
if (m_pPrp->PrpConfigureViewfinding(&prpVfConfig))
{
// Camera has been configured for viewfinding.
m_bCameraVfConfig = TRUE;
}
else
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Preprocessor viewfinding configure failed.\r\n"), __WFUNCTION__));
return FALSE;
}
}
//----------------------------------------------------
// Configure encoding path if Capture pin is used
// and configuration is needed.
//----------------------------------------------------
if (!m_bCameraEncConfig && (m_StrmInstances[CAPTURE].pPinDev != NULL))
{
// Set input format and frame size config params
prpEncConfig.inputFormat = inFormat;
prpEncConfig.inputSize = inFrameSize;
Format = m_StrmInstances[CAPTURE].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biCompression;
switch (Format)
{
case FOURCC_YUYV:
prpEncConfig.encFormat = prpEncOutputFormat_YUYV422;
break;
case FOURCC_UYVY:
prpEncConfig.encFormat = prpEncOutputFormat_UYVY422;
break;
case CS_BI_BITFIELDS:
prpEncConfig.encFormat = prpEncOutputFormat_RGB;
break;
case CS_BI_RGB:
prpEncConfig.encFormat = prpEncOutputFormat_RGB;
break;
default:
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Invalid data format for Capture.\r\n"), __WFUNCTION__));
return FALSE;
}
// Set up encoding channel CSC parameters
// based on input and output
switch(prpEncConfig.encFormat)
{
case prpEncOutputFormat_YUV444:
case prpEncOutputFormat_YUV422:
case prpEncOutputFormat_YUV420:
case prpEncOutputFormat_YUV444IL:
case prpEncOutputFormat_YUYV422:
case prpEncOutputFormat_YVYU422:
case prpEncOutputFormat_UYVY422:
case prpEncOutputFormat_VYUY422:
if (prpEncConfig.inputFormat == prpInputFormat_RGB)
prpEncConfig.encCSCEquation = prpCSCR2Y_A1;
else
prpEncConfig.encCSCEquation = prpCSCNoOp;
break;
case prpEncOutputFormat_RGB:
case prpEncOutputFormat_RGBA:
if (prpEncConfig.inputFormat == prpInputFormat_YUV444IL)
prpEncConfig.encCSCEquation = prpCSCY2R_A1;
else
prpEncConfig.encCSCEquation = prpCSCNoOp;
break;
}
// Set up encoding data width if format is RGB
// If format is not RGB, width and offsets can be inferred
if (prpEncConfig.encFormat == prpEncOutputFormat_RGB)
{
bitDepth = m_StrmInstances[CAPTURE].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biBitCount;
switch (bitDepth)
{
case 32:
// R = 10, G = 12, B = 10 ????
prpEncConfig.encDataWidth = prpDataWidth_32BPP;
prpEncConfig.encRGBPixelFormat.component0_offset = 0;
prpEncConfig.encRGBPixelFormat.component1_offset = 10;
prpEncConfig.encRGBPixelFormat.component2_offset = 22;
prpEncConfig.encRGBPixelFormat.component0_width = 10;
prpEncConfig.encRGBPixelFormat.component1_width = 12;
prpEncConfig.encRGBPixelFormat.component2_width = 10;
break;
case 24:
prpEncConfig.encDataWidth = prpDataWidth_24BPP;
prpEncConfig.encRGBPixelFormat.component0_offset = 0;
prpEncConfig.encRGBPixelFormat.component1_offset = 8;
prpEncConfig.encRGBPixelFormat.component2_offset = 16;
prpEncConfig.encRGBPixelFormat.component0_width = 8;
prpEncConfig.encRGBPixelFormat.component1_width = 8;
prpEncConfig.encRGBPixelFormat.component2_width = 8;
break;
case 16:
prpEncConfig.encDataWidth = prpDataWidth_16BPP;
prpEncConfig.encRGBPixelFormat.component0_offset = 0;
prpEncConfig.encRGBPixelFormat.component1_offset = 5;
prpEncConfig.encRGBPixelFormat.component2_offset = 11;
prpEncConfig.encRGBPixelFormat.component0_width = 5;
prpEncConfig.encRGBPixelFormat.component1_width = 6;
prpEncConfig.encRGBPixelFormat.component2_width = 5;
break;
default:
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Invalid bit depth 0x%x for Capture image.\r\n"),
__WFUNCTION__, bitDepth));
return FALSE;
}
}
// TODO: Support Rotation
prpEncConfig.encFlipRot.verticalFlip = m_bFlipVertical;
prpEncConfig.encFlipRot.horizontalFlip = m_bFlipHorizontal;
prpEncConfig.encFlipRot.rotate90 = m_bRotate;
// Set up encoding image output dimensions
prpEncConfig.encSize.width = (UINT16)m_StrmInstances[CAPTURE].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biWidth;
prpEncConfig.encSize.height = (UINT16)m_StrmInstances[CAPTURE].pPinDev->m_CsDataRangeVideo.VideoInfoHeader.bmiHeader.biHeight;
DEBUGMSG(ZONE_DEVICE, (TEXT("%s: Encoding output width: %x, height: %x\r\n"),
__WFUNCTION__, prpEncConfig.encSize.width, prpEncConfig.encSize.height));
//----------------------------------------------------
// Configure Preprocessor for encoding
//----------------------------------------------------
if (m_pPrp->PrpConfigureEncoding(&prpEncConfig))
{
// Camera has been configured.
m_bCameraEncConfig = TRUE;
}
else
{
DEBUGMSG(ZONE_ERROR, (TEXT("%s: Preprocessor encoding configure failed.\r\n"), __WFUNCTION__));
return FALSE;
}
}
CAM_FUNCTION_EXIT();
return TRUE;
}
//-----------------------------------------------------------------------------
//
// Function: CameraSensorZoom
//
// This function sets the camera zoom value.
//
// Parameters:
// zoomVal
// [in] zoom value.
// If 2, zoom by 2x. If 1, zoom by 1x.
// All other values are invalid.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void CCameraDevice::CameraSensorZoom(DWORD zoomVal)
{
CAM_FUNCTION_ENTRY();
m_pCsi->CsiZoom(zoomVal);
CAM_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: CameraSetDirectDisplay
//
// This function turns Direct Display mode on or off.
//
// Parameters:
// bDirectDisplay
// [in] If TRUE, turn Direct Display mode on.
// If FALSE, turn Direct Display mode off.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void CCameraDevice::CameraSetDirectDisplay(BOOL bDirectDisplay)
{
CAM_FUNCTION_ENTRY();
// Set Direct Display variable
m_bDirectDisplay = bDirectDisplay;
// Assure that we will reconfigure IPU before starting.
m_bCameraVfConfig = FALSE;
CAM_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: CameraSetDirectCapture
//
// This function turns Direct Capture mode on or off.
//
// Parameters:
// bDirectDisplay
// [in] If TRUE, turn Direct Capture mode on.
// If FALSE, turn Direct Capture mode off.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void CCameraDevice::CameraSetDirectCapture(BOOL bDirectCapture)
{
CAM_FUNCTION_ENTRY();
// Set Direct Capture variable
m_bDirectCapture = bDirectCapture;
// Assure that we will reconfigure IPU before starting.
m_bCameraEncConfig = FALSE;
CAM_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
//
// Function: CameraMarkAsModified
//
// This function informs the camera driver that important
// configuration paramaters have been modified. This ensures
// that the camera will reconfigure the preprocessing before
// starting again.
//
// Parameters:
// None.
//
// Returns:
// None.
//
//-----------------------------------------------------------------------------
void CCameraDevice::CameraMarkAsModified(ULONG ulPinId)
{
CAM_FUNCTION_ENTRY();
if (ulPinId == PREVIEW)
{
// Assure that we will reconfigure IPU before starting.
m_bCameraVfConfig = FALSE;
}
else if (ulPinId == CAPTURE)
{
// Assure that we will reconfigure IPU before starting.
m_bCameraEncConfig = FALSE;
}
CAM_FUNCTION_EXIT();
}
//-----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -