예제 #1
0
/* 
 * 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);
}
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);
}