/#include <windows.h>
#include <ceddk.h>
#include <bsp.h>
#include <camera.h>
#include <camerapddprops.h>
#include <dstruct.h>
#include <cameradriver.h>
#include <pindriver.h>
#include <display_vf.h>
#include <IpuModuleInterfaceClass.h>
#include <IpuBufferManager.h>
#include <prpclass.h>
#include <Sensorformats.h>
void VfStartWindowTest(void)
{ static char times=0;
BOOL bYC ;
MSGQUEUEOPTIONS msgOptions;
CSPROPERTY_STREAMEX_S CsPropStreamEx;
BOOL bResult = FALSE;
BOOL bMode = TRUE;
HANDLE hCameraDll = INVALID_HANDLE_VALUE;
HANDLE hPreviewPinDll = INVALID_HANDLE_VALUE;
DWORD dwBytesTransferred;
HANDLE hPreviewMsgQ = NULL;
CSPROPERTY IOCTLInput;
PCS_DATARANGE_VIDEO pPreviewDataRange = &DCAM_StreamMode_RGB565_WVGA;
DWORD dwStructSize;
PCSP_PIN pCsPin = NULL;
PCSMULTIPLE_ITEM pCSDataRangeItems;
PCS_DATARANGE_VIDEO pCSDataRangeVideo;
CS_DATAFORMAT_VIDEOINFOHEADER PreviewDataFormat = {0};
CSSTATE state;
prpVfWindowOffset prpWindow;
hCameraDll = CreateFile(TEXT("CAM1:"), // "special" file name
GENERIC_READ|GENERIC_WRITE, // desired access
FILE_SHARE_READ|FILE_SHARE_WRITE, // sharing mode
NULL, // security attributes (=NULL)
OPEN_EXISTING, // creation disposition
FILE_ATTRIBUTE_NORMAL, // flags and attributes
NULL); // template file (ignored)
if(INVALID_HANDLE_VALUE == hCameraDll)
{
ERRORMSG(1, (TEXT("LoadCamDriver: CreateFile CAM1 failed!Last error code is %d \r\n"), GetLastError()));
goto CLEANUP;
}
RETAILMSG(1, (TEXT("Create CAM1 OK!\r\n")));
// open a preview pin
hPreviewPinDll= CreateFile(TEXT("PIN1:"), // "special" file name
GENERIC_READ|GENERIC_WRITE, // desired access
0, // sharing mode
NULL, // security attributes (=NULL)
OPEN_ALWAYS, // creation disposition
FILE_ATTRIBUTE_NORMAL, // flags and attributes
NULL); // template file (ignored)
if(INVALID_HANDLE_VALUE == hPreviewPinDll)
{
ERRORMSG(1, (TEXT("LoadCamDriver: Open a pin for preview failed!Last error code is %d \r\n"), GetLastError()));
goto CLEANUP;
}
RETAILMSG(1, (TEXT("Create PIN1 OK!\r\n")));
// Open msg queue for Preview Pin
msgOptions.dwSize = sizeof(MSGQUEUEOPTIONS);
msgOptions.dwFlags = MSGQUEUE_ALLOW_BROKEN;
msgOptions.dwMaxMessages = 0;
msgOptions.cbMaxMessage = sizeof(CS_MSGQUEUE_BUFFER);
msgOptions.bReadAccess = TRUE;
hPreviewMsgQ = CreateMsgQueue(NULL, &msgOptions);
if(!hPreviewMsgQ)
{
RETAILMSG(1, (TEXT("LoadCamDriver: CreateMsgQueue for Preview pin failed!\r\n")));
goto CLEANUP;
}
RETAILMSG(1, (TEXT("Create MsgQ OK!\r\n")));
// create preview pin instance
CsPropStreamEx.hMsgQueue = hPreviewMsgQ;
CsPropStreamEx.CsPin.PinId = PREVIEW;
CsPropStreamEx.CsPin.Property.Set = CSPROPSETID_StreamEx;
CsPropStreamEx.CsPin.Property.Id = CSPROPERTY_STREAMEX_INIT;
CsPropStreamEx.CsPin.Property.Flags = CSPROPERTY_TYPE_SET;
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_STREAM_INSTANTIATE, // I/O control code
&CsPropStreamEx, // in buffer
sizeof(CSPROPERTY_STREAMEX_S), // in buffer size
NULL, // out buffer
0, // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored (=NULL)
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: create preview pin instance failed!\r\n")));
goto CLEANUP;
}
RETAILMSG(1, (TEXT("Create preview pin instance OK!\r\n")));
// Set DirectDisplay Mode
bMode = TRUE;
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_SET_DIRECT_DISPLAY_MODE, // I/O control code
NULL, // in buffer
bMode, // in buffer size
NULL, // out buffer
0, // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored =NULL
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: set DirectDisplay Mode failed!\r\n")));
goto CLEANUP;
}
RETAILMSG(1, (TEXT("set DIRECT mode OK!\r\n")));
// Set Preview Window
prpWindow.ptStart.x = 0;
prpWindow.ptStart.y = 0;
prpWindow.iHeight = 480;
prpWindow.iWidth = 800;
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_SET_PREVIEW_WINDOW, // I/O control code
&prpWindow, // in buffer
sizeof(prpVfWindowOffset), // in buffer size
NULL, // out buffer
0, // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored =NULL
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: set Preview Window failed!\r\n")));
goto CLEANUP;
}
RETAILMSG(1, (TEXT("set preview window OK!\r\n")));
IOCTLInput.Set = CSPROPSETID_Pin;
IOCTLInput.Id = CSPROPERTY_PIN_DATAINTERSECTION;
IOCTLInput.Flags = CSPROPERTY_TYPE_GET;
dwStructSize = sizeof(CSP_PIN) + sizeof(CSMULTIPLE_ITEM) + sizeof(CS_DATARANGE_VIDEO);
pCsPin = (PCSP_PIN)malloc(dwStructSize);
if (NULL == pCsPin)
{
RETAILMSG(1, (TEXT("LoadCamDriver: Malloc memory failed!\r\n")));
goto CLEANUP;
}
pCsPin->Property = IOCTLInput;
pCsPin->PinId = PREVIEW;
pCSDataRangeItems = (PCSMULTIPLE_ITEM)(pCsPin + 1);
pCSDataRangeItems->Count = 1;
pCSDataRangeItems->Size = sizeof(CSMULTIPLE_ITEM) + sizeof(CS_DATARANGE_VIDEO);
pCSDataRangeVideo = (PCS_DATARANGE_VIDEO)(pCSDataRangeItems + 1);
memcpy(pCSDataRangeVideo, pPreviewDataRange, sizeof(CS_DATARANGE_VIDEO));
// Get Preview format
bResult = DeviceIoControl(hCameraDll, // file handle to the driver
IOCTL_CS_PROPERTY, // I/O control code
pCsPin, // in buffer
dwStructSize, // in buffer size
&PreviewDataFormat, // out buffer
sizeof(CS_DATAFORMAT_VIDEOINFOHEADER), // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored (=NULL)
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: Could not perform DATAINTERSECTION GET!\r\n")));
goto CLEANUP;
}
// Set Preview format
IOCTLInput.Set = CSPROPSETID_Connection;
IOCTLInput.Id = CSPROPERTY_CONNECTION_DATAFORMAT;
IOCTLInput.Flags = CSPROPERTY_TYPE_SET;
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_CS_PROPERTY, // I/O control code
&IOCTLInput, // in buffer
sizeof(CSPROPERTY), // in buffer size
&PreviewDataFormat, // out buffer
sizeof(CS_DATAFORMAT_VIDEOINFOHEADER), // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored (=NULL)
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: set BitCount for preview pin failed!\r\n")));
goto CLEANUP;
}
bYC = 0 /**/
//IOCTL_SET_VIDEO_IN_CHANNEL
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_SET_VIDEO_IN_YC, // I/O control code
NULL, // in buffer
bYC, // in buffer size
NULL, // out buffer
0, // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored =NULL
// Pause Preview
IOCTLInput.Set = CSPROPSETID_Connection;
IOCTLInput.Id = CSPROPERTY_CONNECTION_STATE;
IOCTLInput.Flags = CSPROPERTY_TYPE_SET;
state = CSSTATE_PAUSE;
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_CS_PROPERTY, // I/O control code
&IOCTLInput, // in buffer
sizeof(CSPROPERTY), // in buffer size
&state, // out buffer
sizeof(CSSTATE), // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored (=NULL)
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: set pause for preview pin failed!\r\n")));
goto CLEANUP;
}
RETAILMSG(1, (TEXT("Pause preview OK!\r\n")));
// Start Preview
IOCTLInput.Set = CSPROPSETID_Connection;
IOCTLInput.Id = CSPROPERTY_CONNECTION_STATE;
IOCTLInput.Flags = CSPROPERTY_TYPE_SET;
state = CSSTATE_RUN;
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_CS_PROPERTY, // I/O control code
&IOCTLInput, // in buffer
sizeof(CSPROPERTY), // in buffer size
&state, // out buffer
sizeof(CSSTATE), // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored (=NULL)
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: set run for preview pin failed!\r\n")));
goto CLEANUP;
}
RETAILMSG(1, (TEXT("Start preview OK!\r\n")));
Sleep(60*1000);
// Stop Preview
IOCTLInput.Set = CSPROPSETID_Connection;
IOCTLInput.Id = CSPROPERTY_CONNECTION_STATE;
IOCTLInput.Flags = CSPROPERTY_TYPE_SET;
state = CSSTATE_STOP;
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_CS_PROPERTY, // I/O control code
&IOCTLInput, // in buffer
sizeof(CSPROPERTY), // in buffer size
&state, // out buffer
sizeof(CSSTATE), // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored (=NULL)
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: set stop for preview pin failed!\r\n")));
goto CLEANUP;
}
// Disable DirectDisplay Mode
bMode = FALSE;
bResult = DeviceIoControl(hPreviewPinDll, // file handle to the driver
IOCTL_SET_DIRECT_DISPLAY_MODE, // I/O control code
NULL, // in buffer
bMode, // in buffer size
NULL, // out buffer
0, // out buffer size
&dwBytesTransferred, // number of bytes returned
NULL); // ignored =NULL
if (!bResult)
{
RETAILMSG(1, (TEXT("LoadCamDriver: set DirectDisplay Mode failed!\r\n")));
goto CLEANUP;
}
CLEANUP:
if(pCsPin != NULL)
{
free(pCsPin);
pCsPin = NULL;
}
if(hPreviewMsgQ != NULL)
{
CloseMsgQueue(hPreviewMsgQ);
hPreviewMsgQ = NULL;
}
if(hPreviewPinDll != INVALID_HANDLE_VALUE)
{
CloseHandle(hPreviewPinDll);
hPreviewPinDll = INVALID_HANDLE_VALUE;
}
if(hCameraDll != INVALID_HANDLE_VALUE)
{
CloseHandle(hCameraDll);
hCameraDll = INVALID_HANDLE_VALUE;
}
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR pCmdLine, int nCmdShow)
{
MessageBox(NULL, TEXT("Test Start ."), L"Test", MB_OK);
VfStartWindowTest();
return 0;
}
注意:
1 pause preview不是必须的
2 IOCTL_SET_VIDEO_IN_CHANNEL 和 IOCTL_SET_VIDEO_IN_YC是用来切换通道的
3. 切换通道尽量放在pause preview和start preview之前,因为某些AD芯片有某种怪癖,如果preview通道已经建立好了,那么再切换通道,会导致切换不成功