示例#1
0
文件: capture.c 项目: ofilin/remcam2
int cap_configure(cap_cx *cx, char *err)
{
	CAPTUREPARMS params;

	if(capCaptureGetSetup(cx->hwnd, &params, sizeof(params)))
	{
		params.fYield = TRUE;
		params.fCaptureAudio = FALSE;
		params.wPercentDropForError = 100;

		params.fMakeUserHitOKToCapture = FALSE;
		params.fAbortLeftMouse = FALSE;
		params.fAbortRightMouse = FALSE;
		params.vKeyAbort = 0;

		if(capCaptureSetSetup(cx->hwnd, &params, sizeof(params)))
		{
			if(capSetCallbackOnVideoStream(cx->hwnd, cap_stream_cb))
			{
				return 1;
			}
		}
	}

	set_err("Can't set capture settings");
	return 0;
}
示例#2
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();
}
示例#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);
}
示例#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);
}
示例#5
0
static void _vfw_engine_configure(VfwEngine *obj){
	if (_vfw_engine_setup(obj)==-1){
		return;
	}
	if (_vfw_engine_select_format(obj)==-1){
		return ;
	}
	capSetCallbackOnVideoStream(obj->capvideo, vfw_engine_stream_callback);
	if (!capCaptureSequenceNoFile(obj->capvideo)){
		ms_error("vfw: fail to start capture !");
	}
	ms_thread_create(&obj->thread,NULL,vfw_engine_thread,obj);
	obj->configured=TRUE;
}
示例#6
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;
  }
}
// Disconnection
// No comments
BOOL	CAviCap::Disconnect()
{	

	CHECKWIN();
	CHECKCNCT();
	
	capSetCallbackOnFrame(GetSafeHwnd(), NULL);
	capSetCallbackOnVideoStream(GetSafeHwnd(), NULL);
	StartSeq(FALSE);
	
	if(_curDriver!=-1&&GetSafeHwnd())
		if(capDriverDisconnect(GetSafeHwnd()))
			 _curDriver=-1;

	if(_bmpInfo)	{delete _bmpInfo;
			_bmpInfo=NULL;}

	if(_curDriver==-1)
		return TRUE;
	else	return FALSE;
}
示例#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: capSetCallbackOnVideoStream
BOOL	CAviCap::SetStreamCallBack(LPVOID cb)
{
	CHECKWIN();
	CHECKCNCT();
	return capSetCallbackOnVideoStream(GetSafeHwnd(), cb);
}
示例#10
0
	void CSoCProjectView::OnInitialUpdate()
	{
		CScrollView::OnInitialUpdate();

		CSize sizeTotal;
		// TODO: 이 뷰의 전체 크기를 계산합니다.
		sizeTotal.cx = 640;
		sizeTotal.cy = 480;
		SetScrollSizes(MM_TEXT, sizeTotal);

		CSoCProjectDoc*pDoc = GetDocument();
		// TODO: 여기에 생성 코드를 추가합니다.
		RECT r;
		GetClientRect(&r);
		pDoc->m_hCamWnd = capCreateCaptureWindow(
			_T("Capture Window"), WS_CHILD | WS_VISIBLE, 5, 5, r.right-5, r.bottom-5, this->m_hWnd, NULL);

		// 설치된 디바이스를 순서로 0 ~ 9까지의 카메라를 지정 할 수 있다.
		if(!capDriverConnect(pDoc->m_hCamWnd, 0)) AfxMessageBox(_T("웹캠 인식 실패 ㅠㅠ"));

		// 현재 드라이버 정보에 관한 내용 얻어오기
		capDriverGetCaps(pDoc->m_hCamWnd, &pDoc->m_psCapsInfo, sizeof(pDoc->m_psCapsInfo));

		//비디오 포맷 변환을 지원하는지 확인한다.
		if(pDoc->m_psCapsInfo.fHasDlgVideoFormat) {
			// 비디오 포맷 변환을 지원하면 아래 함수를 호출한다.
			// 호출되는 함수는 새로운 다이얼로그를 호출하고 해상도와 포맷형식, 프레임 버퍼크기등을 지정할 수 있다.
			// 이때, 지원되지 않는 비디오포멧을 설정하면 검정 화면을 보게될 것이야...
			capDlgVideoFormat(pDoc->m_hCamWnd);
		}

		// m_psCapsInfo.fHasOverlay에서 overlay가 지원이 되지 않으면(=0) 사용 할 수 없다.
		if(pDoc->m_psCapsInfo.fHasOverlay) {
			// 하드웨어 오버레이는 시스템 부하를 줄여준다.(optioinal)
			capOverlay(pDoc->m_hCamWnd, FALSE);
		}

		// BITMAPINFO 설정
		capGetVideoFormat(pDoc->m_hCamWnd, &pDoc->m_BTMInfo, sizeof(pDoc->m_BTMInfo));

		// 1/1000 단위로 영상이 출력된다.
		capPreviewRate(pDoc->m_hCamWnd, 1);

		// 프리뷰 영상을 재생한다.
		capPreview(pDoc->m_hCamWnd, TRUE);

		CAPTUREPARMS cp;     
	
		capCaptureGetSetup(pDoc->m_hCamWnd, &cp, sizeof(cp) );	// get the current defaults      
	
		cp.dwRequestMicroSecPerFrame = 1;					// Set desired frame rate     
		cp.fMakeUserHitOKToCapture   = FALSE;
		cp.fYield                    = TRUE;                // we want capture on a background thread.
		cp.wNumVideoRequested        = (WORD) 1;			// we may get less than this - no problem
		cp.fCaptureAudio             = FALSE;     
		cp.vKeyAbort                 = 0;                   // If no key is provided, it won't stop...
		cp.fAbortLeftMouse           = FALSE;
		cp.fAbortRightMouse          = FALSE;
		cp.fLimitEnabled             = FALSE;				// we want to stop     
		cp.fMCIControl               = FALSE;
	
		capCaptureSetSetup(pDoc->m_hCamWnd, &cp, sizeof(cp) ); 
		
		capSetCallbackOnVideoStream(pDoc->m_hCamWnd, VideoCallbackProc);
		capSetCallbackOnFrame(pDoc->m_hCamWnd, VideoCallbackProc);
	}