/* Resets camera device after capturing.
 * Since new capture request may require different frame dimensions we must
 * reset frame info cached in the capture window. The only way to do that would
 * be closing, and reopening it again. */
static void
_camera_device_reset(WndCameraDevice* cd)
{
    if (cd != NULL && cd->cap_window != NULL) {
        capDriverDisconnect(cd->cap_window);
        if (cd->dc != NULL) {
            ReleaseDC(cd->cap_window, cd->dc);
            cd->dc = NULL;
        }
        if (cd->gdi_bitmap != NULL) {
            free(cd->gdi_bitmap);
            cd->gdi_bitmap = NULL;
        }
        if (cd->frame_bitmap != NULL) {
            free(cd->frame_bitmap);
            cd->frame_bitmap = NULL;
        }
        if (cd->framebuffer != NULL) {
            free(cd->framebuffer);
            cd->framebuffer = NULL;
        }

        /* Recreate the capturing window. */
        DestroyWindow(cd->cap_window);
        cd->cap_window = capCreateCaptureWindow(cd->window_name, WS_CHILD, 0, 0,
                                                0, 0, HWND_MESSAGE, 1);
    }
}
Exemple #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);
}
Exemple #3
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();
}
/* Uninitializes and frees WndCameraDevice descriptor.
 * Note that upon return from this routine memory allocated for the descriptor
 * will be freed.
 */
static void
_camera_device_free(WndCameraDevice* cd)
{
    if (cd != NULL) {
        if (cd->cap_window != NULL) {
            /* Disconnect from the driver. */
            capDriverDisconnect(cd->cap_window);

            if (cd->dc != NULL) {
                W("%s: Frames should not be capturing at this point",
                  __FUNCTION__);
                ReleaseDC(cd->cap_window, cd->dc);
                cd->dc = NULL;
            }
            /* Destroy the capturing window. */
            DestroyWindow(cd->cap_window);
            cd->cap_window = NULL;
        }
        if (cd->gdi_bitmap != NULL) {
            free(cd->gdi_bitmap);
        }
        if (cd->frame_bitmap != NULL) {
            free(cd->frame_bitmap);
        }
        if (cd->window_name != NULL) {
            free(cd->window_name);
        }
        if (cd->framebuffer != NULL) {
            free(cd->framebuffer);
        }
        AFREE(cd);
    } else {
        W("%s: No descriptor", __FUNCTION__);
    }
}
CWinVideoGrabber::~CWinVideoGrabber()
{
	if (!inited) return;
	StopRecording();
	StopPreviewing();
	capDriverDisconnect(videowindow); 
	DestroyWindow(videowindow);
}
Exemple #6
0
/**
 * Destroy camera window
 */
static void camera_destroy_window(camera_handle* pHandle)
{
    if (pHandle->hCapWnd) {
        capSetCallbackOnFrame(pHandle->hCapWnd, NULL);
        capDriverDisconnect(pHandle->hCapWnd);
        DestroyWindow(pHandle->hCapWnd);
        pHandle->hCapWnd = NULL;
    }
}
Exemple #7
0
void cap_close(cap_cx *cx)
{
	if(cx->opened)
	{
		cap_stop(cx);
		capDriverDisconnect(cx->hwnd);
		cx->opened = 0;
	}
}
Exemple #8
0
void CvCaptureCAM_VFW::close()
{
    if( capWnd )
    {
        capSetCallbackOnFrame( capWnd, NULL );
        capDriverDisconnect( capWnd );
        DestroyWindow( capWnd );
        closeHIC();
    }
    cvReleaseImage( &frame );
    init();
}
Exemple #9
0
//Description: sets up an imaging device for capture operations
//Input: digitizer ID number and a dummy string
//Output: returns success (non-negative) or failure
EXPORT long SetUp(long driver, long width, long height){

	//reset the image and size variables
	pImage = NULL;
	dwSize = 0;

	//make sure we don't already have a window
	if(hWndC == NULL) {
		//create the capture window, the window is currently being draw in the top left corner
		//because the buffer is filled with nothing if it is not being drawn on the screen;
		//only a window size of 1x1 is needed to get this to work
		hWndC = capCreateCaptureWindow(TEXT("Webcam Capture Window"), WS_CHILD | WS_VISIBLE, 0, 0,
			1, 1, GetDesktopWindow(), 0); 
	}

	//connect the selected driver to the window
	if(!capDriverConnect(hWndC, driver)) {
		DestroyWindow(hWndC);
		return -1;
	}

	//create a frame capture callback function
	if(!capSetCallbackOnFrame(hWndC, capFrame)) {
		capDriverDisconnect(hWndC);
		DestroyWindow(hWndC);
		return -1;
	}


	//begin previewing
	capPreviewRate(hWndC, 66);
	if(!capPreview(hWndC, TRUE)) {
		capDriverDisconnect(hWndC);
		DestroyWindow(hWndC);
		return -1;
	}

	return 0;
}
Exemple #10
0
/**
 * Close camera native handle (and destroy preview window)
 */
static javacall_result camera_close(javacall_handle handle)
{
    camera_handle* pHandle = (camera_handle*)handle;

    if (pHandle->hCapWnd) {
        capSetCallbackOnFrame(pHandle->hCapWnd, NULL);
        capDriverDisconnect(pHandle->hCapWnd);
        DestroyWindow(pHandle->hCapWnd);
        pHandle->hCapWnd = NULL;
    }

    FREE(pHandle);

    return JAVACALL_OK;
}
Exemple #11
0
static int vfw_cleanup (zbar_video_t *vdo)
{
    /* close open device */
    video_state_t *state = vdo->state;
    /* NB this has to go here so the thread can pump messages during cleanup */
    capDriverDisconnect(state->hwnd);
    DestroyWindow(state->hwnd);
    state->hwnd = NULL;
    _zbar_thread_stop(&state->thread, &vdo->qlock);

    if(state->captured) {
        CloseHandle(state->captured);
        state->captured = NULL;
    }
    return(0);
}
void MMCapture::captureCleanup() {
  if(m_audioThread != NULL) {
    m_audioQueue.put(AudioQueueElement());
    while(m_audioThread->stillActive()) {
      Sleep(100);
    }
    SAFEDELETE(m_audioThread);
  }
  if(m_webCamConnected) {
    CHECKRESULT(capDriverDisconnect(m_captureWindow));
    m_webCamConnected = false;
  }
  if(m_captureWindow != NULL) {
    CHECKRESULT(DestroyWindow(m_captureWindow));
    m_captureWindow = NULL;
  }
}
// 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;
}
Exemple #14
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);
}
/* Resets camera device after capturing.
 * Since new capture request may require different frame dimensions we must
 * reset frame info cached in the capture window. The only way to do that would
 * be closing, and reopening it again. */
static void
_camera_device_reset(WndCameraDevice* cd)
{
    if (cd != NULL && cd->cap_window != NULL) {
        capDriverDisconnect(cd->cap_window);
        if (cd->dc != NULL) {
            ReleaseDC(cd->cap_window, cd->dc);
            cd->dc = NULL;
        }
        if (cd->gdi_bitmap != NULL) {
            free(cd->gdi_bitmap);
            cd->gdi_bitmap = NULL;
        }
        if (cd->frame_bitmap != NULL) {
            free(cd->frame_bitmap);
            cd->frame_bitmap = NULL;
        }
        if (cd->framebuffer != NULL) {
            free(cd->framebuffer);
            cd->framebuffer = NULL;
        }
        if (cd->last_frame != NULL) {
            free(cd->last_frame);
            cd->last_frame = NULL;
        }
        cd->last_frame_size = 0;

        /* Recreate the capturing window. */
        DestroyWindow(cd->cap_window);
        cd->cap_window = capCreateCaptureWindow(cd->window_name, WS_CHILD, 0, 0,
                                                0, 0, HWND_MESSAGE, 1);
        if (cd->cap_window != NULL) {
            /* Save capture window descriptor as window's user data. */
            capSetUserData(cd->cap_window, cd);
        }
    }
}
Exemple #16
0
long __stdcall DlgProc ( HWND hWnd , unsigned msg , unsigned wParam , long lParam )
{ 
   switch(msg)
   {
      case WM_INITDIALOG: 
			//hEdit = GetDlgItem( hWnd , I_EDIT );  
			//GetClientRect( hEdit , &rect );
			hWndCap = capCreateCaptureWindow ( NULL, WS_CHILD | WS_VISIBLE , 0, 0, 320, 240, hWnd, 1235 );
			//hWndCap = capCreateCaptureWindow ( NULL, WS_CHILD | WS_VISIBLE , 0, 0, (rect.right-rect.left ), (rect.bottom-rect.top), hEdit, 1235);
						
			// вручную заполняем структуру CapVar
			ZeroMemory( &CapVar, sizeof(COMPVARS) );   
			CapVar.cbSize = sizeof(COMPVARS);
			CapVar.dwFlags = ICMF_COMPVARS_VALID;   
			CapVar.cbState = 0;   
			CapVar.fccHandler = mmioFOURCC( 'x', '2', '6', '4' );   
			CapVar.fccType = ICTYPE_VIDEO;

			// открываем декомпрессор (долго)
			CapVar.hic = ICOpen( ICTYPE_VIDEO, CapVar.fccHandler, ICMODE_COMPRESS ); 

			hThread = CreateThread( NULL, 0, (LPTHREAD_START_ROUTINE)SendThread, NULL, 0, 0 );
						
			return -1 ;

      case WM_COMMAND:
			switch(LOWORD(wParam))			
			{
				case I_BUTTON_CONN :

					if( !capDriverConnect( hWndCap, 0 ) )
               {
                  EndDialog ( hWnd, 0 );
                  return -1;
               }
									
					capCaptureGetSetup( hWndCap, &CapParms, sizeof(CAPTUREPARMS) );        
   
					CapParms.dwRequestMicroSecPerFrame = 66000;    
					CapParms.fLimitEnabled = FALSE;     
					CapParms.fCaptureAudio = FALSE;    
					CapParms.fMCIControl = FALSE;     
					CapParms.fYield = TRUE;      
					CapParms.vKeyAbort = VK_ESCAPE;    
					CapParms.fAbortLeftMouse = FALSE;    
					CapParms.fAbortRightMouse = FALSE;    
					capCaptureSetSetup( hWndCap, &CapParms, sizeof(CAPTUREPARMS) );    
     
					capPreviewScale( hWndCap, 1 );     
					capPreviewRate( hWndCap, 66 );     
					capPreviewScale( hWndCap, FALSE );    
					capPreview( hWndCap, 1 );    
									
					//added by jimmy 

					// OPTIONAL STEP: Setup resolution
					capGetVideoFormat( hWndCap, &InputBmpInfo ,sizeof(InputBmpInfo) );
					//InputBmpInfo.bmiHeader.biWidth = 320; //(rect.right-rect.left );
					//InputBmpInfo.bmiHeader.biHeight = 240; //(rect.bottom-rect.top);
					//InputBmpInfo.bmiHeader.biBitCount = 24;
					capSetVideoFormat( hWndCap, &InputBmpInfo, sizeof(InputBmpInfo) );
					//capDriverDisconnect (hWndCap, 0);//Can we do better?
					//capDriverConnect (hWndCap, 0);

					capSetCallbackOnFrame( hWndCap, FrameCallBack ); 									

					if(CapVar.hic > 0 )   
					{  
						OutFormatSize = ICCompressGetFormatSize( CapVar.hic, &InputBmpInfo.bmiHeader );   // BITMAPINFO возвращает размер структуры исходных данных InputBmpInfo
						ICCompressGetFormat( CapVar.hic, &InputBmpInfo.bmiHeader, &OutputBmpInfo.bmiHeader );   //  заполняет структуру получаемых данных OutputBmpInfo
						OutBufferSize = ICCompressGetSize( CapVar.hic, &InputBmpInfo.bmiHeader, &OutputBmpInfo.bmiHeader );   // максимальный размер одного сжатого кадра (полученного)
						ICSeqCompressFrameStart( &CapVar, &InputBmpInfo );  // начало сжатия 
					}

					break;

				case I_BUTTON_EXIT :

					ICSeqCompressFrameEnd(&CapVar);   // конец сжатия
					ICCompressorFree(&CapVar);   
					ICClose(CapVar.hic);  

					capPreview( hWndCap , false );		
					capDriverDisconnect( hWndCap );

					EndDialog ( hWnd , 0 ) ;									
					break;

			}
		   return -1 ;	

      case WM_CLOSE :

			ICSeqCompressFrameEnd(&CapVar);   // конец сжатия
			ICCompressorFree(&CapVar);   
			ICClose(CapVar.hic);  

			capPreview( hWndCap , false );		
			capDriverDisconnect( hWndCap );
				
			EndDialog ( hWnd , 0 ) ;
         return -1 ;

   }

   return 0 ;
}
//----------------------------------------------------------------------------------------------------------------------------------------------------------------
//카메라를 종료하는 함수.
void CWebCam::StopCam() 
{
	capCaptureAbort(m_hCam);  //캡처동작 중지.
	capDriverDisconnect(m_hCam);  //카메라와 캡처윈도우 사이의 연결을 끊는 메시지를 발생시킨다.
	m_hCam = NULL;
}
Exemple #18
0
static void _vfw_engine_disconnect(VfwEngine *obj){
	capDriverDisconnect(obj->capvideo);
	DestroyWindow(obj->capvideo);
	obj->capvideo=NULL;
}
Exemple #19
0
//-----------------------------------------------------------------------------
void ShutdownCamera (const char sCameraImg[])
{
capDriverDisconnect(hgCapWnd);
lprintf("\nDelete temporary file %s\n", sCameraImg);
unlink(sCameraImg);
}
Exemple #20
0
//Description: disconnects a capture window from a capture device
//	must be called before a process is dettached from the DLL
//Input: none
//Output: none
EXPORT void Close(void) {
	capDriverDisconnect(hWndC);
}