Exemple #1
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);
}
void RemoteControl::startServer()
{
    if ( (display=XOpenDisplay(NULL)) == NULL )
    {
            fprintf( stderr, "Cannot connect to X server\n");
            exit( -1 );
    }
    winRoot = DefaultRootWindow(display);
    int display_width = DisplayWidth(display, DefaultScreen(display));
    int display_height = DisplayHeight(display, DefaultScreen(display));
    maxx = display_width*3/4;
    maxy = display_height*3/4;
    rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
    if(!rfbScreen)
       return;
    rfbScreen->desktopName = "LibVNCServer Example";
    rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
    rfbScreen->alwaysShared = TRUE;
    rfbScreen->ptrAddEvent = doptr;
    rfbScreen->kbdAddEvent = dokey;
    rfbScreen->newClientHook = newclient;


    initBuffer((unsigned char*)rfbScreen->frameBuffer);
    //rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff);
    MakeRichCursor(rfbScreen);
    rfbInitServer(rfbScreen);
    rfbRunEventLoop(rfbScreen,-1,TRUE);
    return;
}
Exemple #3
0
int main(int argc,char** argv)
{
	td = new MyDrawable(0,0,100,100);
  server = rfbGetScreen(&argc,argv,400,300,8,3,4);
  server->frameBuffer = (char*)malloc(400*300*4);
	server->kbdAddEvent = keyevent;
	server->serverFormat.redShift   = 16;
	server->serverFormat.greenShift = 8;
	server->serverFormat.blueShift  = 0;
  rfbInitServer(server);
  rfbRunEventLoop(server,-1,TRUE);
	
	td->setBG(0xFFFF00);
	
	UGui::instance()->addRoot(*td);
	
	while( 1 ) {
		bool updated = UGui::instance()->eventLoop();
		if (updated) {
			printf(".");
			fflush(0);
			rfbMarkRectAsModified(server, 0, 0, 400, 300);
		}
		usleep(10000);
	}
	
  return(0);
}
Exemple #4
0
int main(int argc,char** argv)
{
  int i;
  uint8_t bytes[256*3];

  rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,256,256,8,1,1);
  if(!server)
    return 0;
  server->serverFormat.trueColour=FALSE;
  server->colourMap.count=256;
  server->colourMap.is16=FALSE;
  for(i=0;i<256;i++) {
    bytes[i*3+0]=255-i; /* red */
    bytes[i*3+1]=0; /* green */
    bytes[i*3+2]=i; /* blue */
  }
  bytes[128*3+0]=0xff;
  bytes[128*3+1]=0;
  bytes[128*3+2]=0;
  server->colourMap.data.bytes=bytes;

  server->frameBuffer=(char*)malloc(256*256);
  for(i=0;i<256*256;i++)
     server->frameBuffer[i]=(i/256);

  rfbInitServer(server);
  rfbRunEventLoop(server,-1,FALSE);

  return(0);
}
/* Initialization */
int main(int argc,char** argv)
{
  rfbScreenInfoPtr rfbScreen = rfbGetScreen(NULL,NULL,maxx,maxy,8,3,bpp);
  if(!rfbScreen)
    return 0;
  rfbScreen->desktopName = "MIR Screen";
  rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
  rfbScreen->alwaysShared = TRUE;
  rfbScreen->kbdAddEvent = dokey;
  initBuffer((unsigned char*)rfbScreen->frameBuffer, 0);
  /* initialize the server */
  rfbInitServer(rfbScreen);

  /* this is the non-blocking event loop; a background thread is started */
  rfbRunEventLoop(rfbScreen,-1,TRUE);
  fprintf(stderr, "Running background loop...\n");
  unsigned char i = 0;
  while(! vnc_to_exit) {
	printf("render() %i\n", i);
	render(rfbScreen, i);
	i += 32;
	sleep(1);
  }

  free(rfbScreen->frameBuffer);
  rfbScreenCleanup(rfbScreen);
  return(0);
}
int main(int argc,char** argv)
{                                                                
  rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,8,3,4);
  server->frameBuffer=(char*)malloc(400*300*4);
  rfbInitServer(server);           
  rfbRunEventLoop(server,-1,FALSE);
  return(0);
}
Exemple #7
0
int main(int argc,char** argv)
{                                       
  int i,j;
  uint16_t* f;
                         
  rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2);
  if(!server)
    return 0;
  server->frameBuffer=(char*)malloc(400*300*2);
  f=(uint16_t*)server->frameBuffer;
  for(j=0;j<300;j++)
    for(i=0;i<400;i++)
      f[j*400+i]=/* red */ ((j*32/300) << 10) |
		 /* green */ (((j+400-i)*32/700) << 5) |
		 /* blue */ ((i*32/400));

  rfbInitServer(server);           
  rfbRunEventLoop(server,-1,FALSE);
  return(0);
}
Exemple #8
0
int main(int argc,char** argv)
{
  char *repeaterHost;
  int repeaterPort, sock;
  char id[250];
  int idlen;
  rfbClientPtr cl;

  int i,j;
  uint16_t* f;

  /* Parse command-line arguments */
  if (argc < 3) {
    fprintf(stderr,
      "Usage: %s <id> <repeater-host> [<repeater-port>]\n", argv[0]);
    exit(1);
  }
  idlen = snprintf(id, sizeof(id) - 1, "ID:%s", argv[1]);
  if(idlen < 0 || idlen >= (int)sizeof(id)) {
      fprintf(stderr, "Error, given ID is probably too long.\n");
      return 1;
  }

  repeaterHost = argv[2];
  repeaterPort = argc < 4 ? 5500 : atoi(argv[3]);

  /* The initialization is identical to simple15.c */
  rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2);
  if(!server)
    return 0;
  server->frameBuffer=(char*)malloc(400*300*2);
  f=(uint16_t*)server->frameBuffer;
  for(j=0;j<300;j++)
    for(i=0;i<400;i++)
      f[j*400+i]=/* red */ ((j*32/300) << 10) |
		 /* green */ (((j+400-i)*32/700) << 5) |
		 /* blue */ ((i*32/400));

  /* Now for the repeater-specific part: */
  server->port = -1; /* do not listen on any port */
  server->ipv6port = -1; /* do not listen on any port */

  sock = rfbConnectToTcpAddr(repeaterHost, repeaterPort);
  if (sock < 0) {
    perror("connect to repeater");
    return 1;
  }
  if (write(sock, id, idlen+1) != idlen+1) {
    perror("writing id");
    return 1;
  }
  cl = rfbNewClient(server, sock);
  if (!cl) {
    perror("new client");
    return 1;
  }
  cl->reverseConnection = 0;
  cl->clientGoneHook = clientGone;

  /* Run the server */
  rfbInitServer(server);
  rfbRunEventLoop(server,-1,FALSE);

  return 0;
}
Exemple #9
0
int main(int argc,char** argv)
{
  if (argc>1) openSerialPort(argv[1]);

  bzero(last_raster_crc,sizeof(unsigned int)*1200);

  rfbScreenInfoPtr rfbScreen = rfbGetScreen(&argc,argv,maxx,maxy,8,3,bpp);
  if(!rfbScreen)
    return 0;
  rfbScreen->desktopName = "C65GS Remote Display";
  rfbScreen->frameBuffer = (char*)malloc(maxx*maxy*bpp);
  rfbScreen->alwaysShared = TRUE;
  rfbScreen->kbdAddEvent = dokey;
  rfbScreen->newClientHook = newclient;
  rfbScreen->httpDir = "../webclients";
  rfbScreen->httpEnableProxyConnect = TRUE;

  initBuffer((unsigned char*)rfbScreen->frameBuffer);

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

  /* this is the non-blocking event loop; a background thread is started */
  rfbRunEventLoop(rfbScreen,-1,TRUE);
  fprintf(stderr, "Running background loop...\n");

  int sock = connect_to_port(6565);
  if (sock==-1) {
    fprintf(stderr,"Could not connect to video proxy on port 6565.\n");
    exit(-1);
  }

  raster_cache=calloc(sizeof(struct raster_cache),65536);
  {
    int j;
    for(j=0;j<1200;j++) raster_crc[j]=0;
  }

  printf("Allocated raster cache.\n");

  printf("Started.\n"); fflush(stdout);

    int last_colour=0x00;
    int in_vblank=0;
    int firstraster=1;
    int bytes=0;

    int rasternumber;
    int last_raster=0;
    int next_rasternumber=0;

    int raster_low=0;
    int raster_high=1200;

    while(1) {
      int i;
      unsigned char packet[8192];
      int len=read(sock,packet,2132);
      if (len<1) usleep(10000);

      if (1) {
	if (len > 2100) {
	  // probably a C65GS compressed video frame.
	  // printf("."); fflush(stdout);

	  unsigned char *raster_data=NULL;
    
	  // Each should consist of 13 blocks of
	  //   raster_number (16 bits)
	  //   audio left (8 bits)
	  //   audio right (8 bits)
	  //   CRC32 of raster (32 bits)
	  //   dummy byte (8 bits)

	  // One of these should have the MSB set in the raster number 
	  // to indicate that a raw raster follows.

	  unsigned int crc;
	  int offset=0x56;

	  for(i=0;i<13;i++) {
	    rasternumber = packet[offset+0]<<8;
	    rasternumber |= packet[offset+1];
	    rasternumber &= 0xfff;

	    next_rasternumber = packet[offset+9+0]<<8;
	    next_rasternumber |= packet[offset+9+1];
	    next_rasternumber &= 0xfff;

	    if (rasternumber==1199) {
	      updateFrameBuffer(rfbScreen);
	    }

	    crc=packet[offset+4]<<0;
	    crc|=packet[offset+5]<<8;
	    crc|=packet[offset+6]<<16;
	    crc|=packet[offset+7]<<24;
	   
	    // printf("i=% 2d@$%03x: Saw raster $%04x, crc=$%08x\n",i,offset,rasternumber,crc);
	    
	    // check validity of raster number
	    if (rasternumber>=0&&rasternumber<1200) {
	      if (((!i)&&next_rasternumber-1==rasternumber)||(last_raster+1==rasternumber)) { // rasternumber>=raster_low&&rasternumber<=raster_high) {
		// remember CRC for this raster
		raster_crc[rasternumber]=crc;
		if (raster_data) {
		  // we have raster data, so update the cache
		  bcopy(raster_data,raster_cache[crc&0xffff].data,1920);
		  raster_cache[crc&0xffff].crc=crc;
		}
		
		// describe acceptable raster range for next for supressing glitches
		raster_low=rasternumber+1; if (raster_low>=1200) raster_low=0;
		raster_high=rasternumber+50; if (raster_high>=1200) raster_high=1200;
	      } else {
		// printf("  rejected (acceptable range is %d -- %d)\n",raster_low,raster_high);
		break;
	      }
	    }
	    
	    last_raster=rasternumber;

	    // keep pointer to and skip raster data if it follows this line
	    if (packet[offset+0]&0x80) {
	      raster_data=&packet[offset+9];
	      offset+=1920+9;
	    } else {
	      offset+=9;
	      raster_data=NULL;
	    }
	  }
	}
      }      
    }

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

  return(0);
}
Exemple #10
0
int main(int argc,char** argv)
{
  FILE* in=stdin;
  int i,j,k,l,width,height,paddedWidth;
  char buffer[1024];
  rfbScreenInfoPtr rfbScreen;
  enum { BW, GRAY, TRUECOLOUR } picType=TRUECOLOUR;
  int bytesPerPixel,bitsPerPixelInFile;

  if(argc>1) {
    in=fopen(argv[1],"rb");
    if(!in) {
      printf("Couldn't find file %s.\n",argv[1]);
      exit(1);
    }
  }

  fgets(buffer,1024,in);
  if(!strncmp(buffer,"P6",2)) {
	  picType=TRUECOLOUR;
	  bytesPerPixel=4; bitsPerPixelInFile=3*8;
  } else if(!strncmp(buffer,"P5",2)) {
	  picType=GRAY;
	  bytesPerPixel=1; bitsPerPixelInFile=1*8;
  } else if(!strncmp(buffer,"P4",2)) {
	  picType=BW;
	  bytesPerPixel=1; bitsPerPixelInFile=1;
  } else {
    printf("Not a ppm.\n");
    exit(2);
  }

  /* skip comments */
  do {
    fgets(buffer,1024,in);
  } while(buffer[0]=='#');

  /* get width & height */
  sscanf(buffer,"%d %d",&width,&height);
  rfbLog("Got width %d and height %d.\n",width,height);
  if(picType!=BW)
	fgets(buffer,1024,in);
  else
	  width=1+((width-1)|7);

  /* vncviewers have problems with widths which are no multiple of 4. */
  paddedWidth = width;
  if(width&3)
    paddedWidth+=4-(width&3);

  /* initialize data for vnc server */
  rfbScreen = rfbGetScreen(&argc,argv,paddedWidth,height,8,(bitsPerPixelInFile+7)/8,bytesPerPixel);
  if(argc>1)
    rfbScreen->desktopName = argv[1];
  else
    rfbScreen->desktopName = "Picture";
  rfbScreen->alwaysShared = TRUE;
  rfbScreen->kbdAddEvent = HandleKey;

  /* enable http */
  rfbScreen->httpDir = "../classes";

  /* allocate picture and read it */
  rfbScreen->frameBuffer = (char*)malloc(paddedWidth*bytesPerPixel*height);
  fread(rfbScreen->frameBuffer,width*bitsPerPixelInFile/8,height,in);
  fclose(in);

  if(picType!=TRUECOLOUR) {
	  rfbScreen->serverFormat.trueColour=FALSE;
	  rfbScreen->colourMap.count=256;
	  rfbScreen->colourMap.is16=FALSE;
	  rfbScreen->colourMap.data.bytes=malloc(256*3);
	  for(i=0;i<256;i++)
		  memset(rfbScreen->colourMap.data.bytes+3*i,i,3);
  }

  switch(picType) {
	case TRUECOLOUR:
		  /* correct the format to 4 bytes instead of 3 (and pad to paddedWidth) */
		  for(j=height-1;j>=0;j--) {
		    for(i=width-1;i>=0;i--)
		      for(k=2;k>=0;k--)
			rfbScreen->frameBuffer[(j*paddedWidth+i)*4+k]=
			  rfbScreen->frameBuffer[(j*width+i)*3+k];
		    for(i=width*4;i<paddedWidth*4;i++)
		      rfbScreen->frameBuffer[j*paddedWidth*4+i]=0;
		  }
		  break;
	case GRAY:
		  break;
	case BW:
		  /* correct the format from 1 bit to 8 bits */
		  for(j=height-1;j>=0;j--)
			  for(i=width-1;i>=0;i-=8) {
				  l=(unsigned char)rfbScreen->frameBuffer[(j*width+i)/8];
				  for(k=7;k>=0;k--)
					  rfbScreen->frameBuffer[j*paddedWidth+i+7-k]=(l&(1<<k))?0:255;
			  }
		  break;
  }

  /* initialize server */
  rfbInitServer(rfbScreen);

  /* run event loop */
  rfbRunEventLoop(rfbScreen,40000,FALSE);

  return(0);
}