andreacremaschi / Syphon-virtual-screen

Emulate a fake monitor to hijack full-screen video output and pipe the video stream to a Syphon server
http://andreacremaschi.github.io/Syphon-virtual-screen/
154 stars 22 forks source link

Crash on CGDisplayCreateImage() #1

Closed andreacremaschi closed 11 years ago

andreacremaschi commented 11 years ago

Re: @andreacremaschi @micrem73 Thanx man. The CGDisplayCreateImage() method crash when using it with EWProxyFramebuffer id.

Yes, actually I think it happens because I can't figure out how to get the CGDirectDisplayID associated with the frame buffer. Actually, I just call CGGetActiveDisplayList and get the last one (ugly, I know, but it just work with a single-GPU configuration). Any better ideas?

anome commented 11 years ago

Hello Andrea,

This code works too (it's coming from Enno's code) :

-- - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - -

// Getting the data from framebuffer EWProxyFramebufferDriverUpdateMemory(connect); EWProxyFramebufferModeInfo *info = [self getCurrentModeInfo];

// Creating a texture with data GLuint _texture; glGenTextures( 1, &_texture ); glBindTexture( GL_TEXTURE_RECTANGLE_ARB, _texture ); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB8, info->width, info->height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, driverbuf);

// Publishing this texture [syphonServer publishFrameTexture:_texturetextureTarget: GL_TEXTURE_RECTANGLE_ARB imageRegion: NSMakeRect(0,0, info->width, info->height) textureDimensions: NSMakeSize(info->width, info->height) flipped: YES];

-- - - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - -

But the Syphon image appears badly, like if there is a color space problem. What do you think ?

Best, Philippe

anome commented 11 years ago

Hello Andrea,

Ok the glTexImage2D line should be replaced with :

-- - - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - -

glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB, info->width, info->height, 0, GL_RGB, GL_UNSIGNED_BYTE, driverbuf);

-- - - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - - - - 8< - - - - -

Now it works great, despite it's eating some CPU. As Syphon and EWProxyFramebuffer both use IOKit, I'm sure there could be some optimization. What do you think ?

Best, Philippe

andreacremaschi commented 11 years ago

Yes, silly me, I didn't think about looking in Enno's code to see how to get direct access to the memory buffer. Thanks for the fix! Some optimization can surely be done (i.e. creating texture once, using apple client storage), but keep in mind that Syphon Virtual Screen will never be the 'right' way to go to have the best performance: it sits on EWProxyFrameBuffer that is a CPU virtual memory buffer, so the slow copy from CPU to GPU is unavoidable. I'll update the code as soon as I find the time to do it (feel free to fork and please make a pull request if you wish to). Thanks and keep on your great job with Millumin, I'm looking at your work with great interest since months!

Ciao, Andrea

anome commented 11 years ago

Hi,

Thanx for the explanations. So the best thing is probably to wait QLab 3 with native Syphon support. And anyway, I can now prepare a nice tutorial QLab+Millumin as things works well (despite some CPU usage). Thanx again for your time.

Have a nice day Andrea, Philippe