13 #include <OpenGL/OpenGL.h>
20 "title" :
"VuoSyphonListener",
22 "VuoSyphonServerNotifier",
35 static void __attribute__((constructor)) VuoSyphonListener_init()
37 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
39 dispatch_sync(dispatch_get_main_queue(), ^{
60 SyphonImage *frame = (SyphonImage *)image->freeCallbackContext;
73 if (
self = [super
init])
77 dispatch_sync(dispatch_get_main_queue(), ^{
85 refreshQueue = dispatch_queue_create(
"vuo.syphon.VuoSyphonListener", 0);
105 [
self refreshSyphonClientThreadUnsafe:allServerDescriptions];
129 __block NSDictionary *currentDict;
131 currentDict = [[
syphonClient serverDescription] retain];
135 dispatch_sync(dispatch_get_main_queue(), ^{
137 currentDict = [[syphonClient serverDescription] retain];
141 bool isCurrentStillDesired;
143 VuoText currentName =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
144 VuoText currentAppName =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
152 bool isCurrentStillAvailable;
154 VuoText currentUUID =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
159 [currentDict release];
161 if (isCurrentStillDesired && isCurrentStillAvailable)
172 dispatch_sync(dispatch_get_main_queue(), ^{
177 self.syphonClient = nil;
194 dispatch_sync(dispatch_get_main_queue(), ^{
199 self.syphonClient = nil;
208 NSDictionary *chosenServerDict = nil;
209 NSString *chosenUUID = [NSString stringWithUTF8String:chosenServer.serverUUID];
210 NSArray *allServerDicts = [[SyphonServerDirectory sharedDirectory] servers];
211 for (NSDictionary *serverDict in allServerDicts)
213 if ([chosenUUID isEqualToString:[serverDict objectForKey:SyphonServerDescriptionUUIDKey]])
215 chosenServerDict = serverDict;
221 void (^connect)(void) = ^{
222 SyphonClient *s = [[SyphonClient alloc] initWithServerDescription:chosenServerDict options:nil newFrameHandler:^(SyphonClient *client) {
223 VuoGlContext_perform(^(CGLContextObj cgl_ctx){
224 SyphonImage *frame = [client newFrameImageForContext:cgl_ctx];
226 if (frame.textureSize.width < 1 || frame.textureSize.height < 1)
232 VuoImage image = VuoImage_makeClientOwnedGlTextureRectangle(frame.textureName, GL_RGBA, frame.textureSize.width, frame.textureSize.height, VuoSyphonListener_freeSyphonImageCallback, frame);
234 callback(VuoImage_makeCopy(image, false, 0, 0, false));
239 self.syphonClient = s;
247 dispatch_sync(dispatch_get_main_queue(), ^{
260 [
self refreshSyphonClientThreadUnsafe:serverDescriptions];
276 dispatch_sync(dispatch_get_main_queue(), ^{
280 self.syphonClient = nil;