Reply To: Virtual Screen Device

Home Forums Syphon Syphon Development – Developer Virtual Screen Device Reply To: Virtual Screen Device

#5771
vade
Keymaster

Im confused. What exactly are you trying to do? QLab allows you to use QC, so use a Syphon Server QC plugin and everything stays on the GPU? You should never have to read back to the CPU, that defeats the entire purpose of Syphon.

For AVFoundation, you can use:

AVCaptureVideoPreviewLayer, coupled with AVCaptureDeviceInput, AVCaptureDevice, and of course AVCaptureSession. You use a CARenderer to render your AVCaptureVideoPreviewLayer directly on the GPU. You would bind a Syphon Servers FBO, and render directly into the shared IOSurface backed texture.

Code from a test QC Plugin:

Make session and what not

self.captureSession = [[AVCaptureSession alloc] init];

self.captureSession.sessionPreset = AVCaptureSessionPresetHigh;

self.captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

self.captureDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:self.captureDevice error:NULL];

[self.captureSession addInput:self.captureDeviceInput];

self.capturePreviewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];

self.capturePreviewLayer.bounds = CGRectMake(0, 0, 640, 480);
self.capturePreviewLayer.videoGravity = AVLayerVideoGravityResizeAspect;
[self.captureSession startRunning];

Assuming a CALayer and CARenderer, when you bind the SyphonServers FBO, do:


glViewport (0, 0, imageBounds.size.width, imageBounds.size.height);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho (0, imageBounds.size.width, 0, imageBounds.size.height, -1, 1);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

// Do we need this? I suspect not but...
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);

if(!self.renderer)
self.renderer = [CARenderer rendererWithCGLContext:cgl_ctx options:nil];

renderer.bounds = imageBounds;
renderer.layer = renderLayer;
renderer.layer.position = NSMakePoint(imageBounds.size.width/2.0, imageBounds.size.height/2.0);
renderer.layer.bounds = imageBounds;
renderer.layer.autoresizingMask = kCALayerWidthSizable | kCALayerHeightSizable;

[renderer beginFrameAtTime:CACurrentMediaTime() timeStamp:NULL];
[renderer addUpdateRect:imageBounds];
[renderer render];
[renderer endFrame];

glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();

You can probably optimize this more by disabling blending and removing the clear, etc.