 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
cheriff Regular
Joined: 23 Jun 2004 Posts: 262 Location: Sydney.au
|
Posted: Tue Sep 02, 2008 10:50 pm Post subject: PS3 export fb0 to VNC |
|
|
UPDATE: from IRC: | Quote: | <jadamcze> cheriff: ps3 fb is ARGB8888, libvncserver doesn't seem to support converting from that format
<jadamcze> There appears to be no magic option to get the colours right. afaict.
<malc> just add one to fb_ea if you're not using the alpha... | Malc's idea seems to work so take that for what it's worth :)
Hi, I find this useful, so thought I might share. It takes whatever format /dev/fb0 is set to, and uses it as input for a simple VNC server.
Caveats: resends entire buffer each frame
probably not secure much
colours seem mixed up, either an endian or pixel format issue
That last one could be easily fixed with the right parameter in the setup code, I just cant be bothered huntin through headers for it.
Try using ps3-video-mode to change the size of the framebuffer, and hence the performance.. 720p seems to work nicely for me on a 100MB network.
You need to have libvncserver properly installed. Gentoo just emerged it properly for me.
Credits: mostly ripped from the provided sample applications
Building: | Code: | make main.o
gcc -o main main.o -lvncserver
./main |
Code: (ugly and hackish, but mostly works)
| Code: | #include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <rfb/rfb.h>
#include <rfb/keysym.h>
#include <linux/fb.h>
#include <linux/kd.h>
#include <asm/ps3fb.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/mman.h>
typedef struct ClientData {
rfbBool oldButton;
int oldx,oldy;
} ClientData;
rfbClientPtr gcl = NULL;
static void doptr(int buttonMask,int x,int y,rfbClientPtr cl){
}
static void dokey(rfbBool down,rfbKeySym key,rfbClientPtr cl)
{
}
static void clientgone(rfbClientPtr cl)
{
free(cl->clientData);
gcl = NULL;
}
static enum rfbNewClientAction newclient(rfbClientPtr cl)
{
cl->clientData = (void*)calloc(sizeof(ClientData),1);
cl->clientGoneHook = clientgone;
gcl = cl;
return RFB_CLIENT_ACCEPT;
}
int main(int argc, char *argv[]){
int fd = open("/dev/fb0", O_RDWR);
struct ps3fb_ioctl_res res;
ioctl(fd, PS3FB_IOCTL_SCREENINFO, (unsigned long)&res);
printf("xres: %d, yres: %d, xoff: %d, yoff: %d, num_frames: %d\n",
res.xres, res.yres, res.xoff, res.yoff, res.num_frames);
unsigned int length = res.xres * res.yres * 4 * res.num_frames;
int bpp = 4;
void * buffer = mmap(NULL, length, PROT_WRITE, MAP_SHARED, fd, 0);
rfbScreenInfoPtr rfbScreen =
rfbGetScreen(&argc,argv, res.xres, res.yres,8,3,bpp);
rfbScreen->desktopName = "PS3 VNC";
rfbScreen->frameBuffer = buffer;
rfbScreen->alwaysShared = TRUE;
rfbScreen->ptrAddEvent = doptr;
rfbScreen->kbdAddEvent = dokey;
rfbScreen->newClientHook = newclient;
rfbScreen->httpDir = "../classes";
rfbScreen->httpEnableProxyConnect = TRUE;
rfbInitServer(rfbScreen);
while(1){
rfbMarkRectAsModified(rfbScreen, 0,0,res.xres, res.yres);
rfbProcessEvents(rfbScreen,1);
if (gcl){
rfbSendUpdateBuf(gcl);
}
}
} |
ENJOY![/quote] _________________ Damn, I need a decent signature!
Last edited by cheriff on Wed Sep 03, 2008 8:30 am; edited 1 time in total |
|
| Back to top |
|
 |
ps2devman
Joined: 09 Oct 2006 Posts: 271
|
Posted: Wed Sep 03, 2008 1:42 am Post subject: |
|
|
| thanks for sharing |
|
| Back to top |
|
 |
cheriff Regular
Joined: 23 Jun 2004 Posts: 262 Location: Sydney.au
|
Posted: Wed Sep 03, 2008 8:27 am Post subject: |
|
|
no problem.
One thing I should point out its that the '1' in 'rfbProcessEvents(rfbScreen,1);' refers to how long we should sleep in the select(). Making this larger will cause the server to sleep longer and perhaps not burn so much CPU in the busy loop. I guess each to his own for the CPU/responsiveness tradeoff.
I did try getting it to vsync, hoping that would cause it also sync to the app, thereby refresh at 60Hz and avoid tearing - no such luck. Maybe someone else will have better luck.
I actually optionally incorporate this into my app, so instead of actually rendering to fb0, just to a malloc'd region that is passed to the library and then update the screen in the call to flip(). No tearing that way, and can use arbitrary screen sizes like 800x600, which is a nice size to dev in on a busy screen.
So guess this is more of a proof of concept and starting point, rather than a finished thing anyone would be expected to use as-is :) _________________ Damn, I need a decent signature! |
|
| Back to top |
|
 |
ZeZu
Joined: 06 Jan 2005 Posts: 2
|
Posted: Mon Jan 05, 2009 6:49 am Post subject: |
|
|
Here is a quick fix for color correction:
rfbScreen->serverFormat.redShift = 16;
rfbScreen->serverFormat.greenShift = 8;
rfbScreen->serverFormat.blueShift = 0;
Will have more fixes later,
code is very usefull for me, thanks for posting |
|
| Back to top |
|
 |
pettersson
Joined: 26 Aug 2009 Posts: 2
|
Posted: Thu Aug 27, 2009 1:55 am Post subject: |
|
|
Hi,
"InStream max string length exceeded" is the error I get when using the code above and trying to connect to my PS3.
Any help or insights are appreciated :)
.pettersson |
|
| Back to top |
|
 |
cheriff Regular
Joined: 23 Jun 2004 Posts: 262 Location: Sydney.au
|
Posted: Wed Sep 02, 2009 9:46 am Post subject: |
|
|
Hi pettersson,
Are you per chance using libvncserver as distributed by debian? (perhaps also including Ubuntu)
I've heard one report that the binary in apt appears to be buggy, but building from source seems to work fine.
Does that help any?
| pettersson wrote: | Hi,
"InStream max string length exceeded" is the error I get when using the code above and trying to connect to my PS3.
Any help or insights are appreciated :)
.pettersson |
_________________ Damn, I need a decent signature! |
|
| Back to top |
|
 |
pettersson
Joined: 26 Aug 2009 Posts: 2
|
Posted: Sat Sep 05, 2009 10:57 pm Post subject: |
|
|
Hi,
thanks for your answer. I compiled libvncserver from the sources.
But i found another solution for my problem: I bought a second PS3, so I have one in my living room and one on my desk, so no need for vnc for now :)
regards,
pettersson |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|