13 #include <OpenGL/OpenGL.h>
14 #include <OpenGL/CGLMacro.h>
21 "title" :
"VuoSyphonListener",
23 "VuoSyphonServerNotifier",
36 static void __attribute__((constructor)) VuoSyphonListener_init()
38 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
40 dispatch_sync(dispatch_get_main_queue(), ^{
61 SyphonImage *frame = (SyphonImage *)image->freeCallbackContext;
74 if (
self = [super
init])
78 dispatch_sync(dispatch_get_main_queue(), ^{
86 refreshQueue = dispatch_queue_create(
"vuo.syphon.VuoSyphonListener", 0);
106 [
self refreshSyphonClientThreadUnsafe:allServerDescriptions];
130 __block NSDictionary *currentDict;
132 currentDict = [[
syphonClient serverDescription] retain];
136 dispatch_sync(dispatch_get_main_queue(), ^{
138 currentDict = [[syphonClient serverDescription] retain];
142 bool isCurrentStillDesired;
144 VuoText currentName =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
145 VuoText currentAppName =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
153 bool isCurrentStillAvailable;
155 VuoText currentUUID =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
160 [currentDict release];
162 if (isCurrentStillDesired && isCurrentStillAvailable)
173 dispatch_sync(dispatch_get_main_queue(), ^{
178 self.syphonClient = nil;
195 dispatch_sync(dispatch_get_main_queue(), ^{
200 self.syphonClient = nil;
209 NSDictionary *chosenServerDict = nil;
210 NSString *chosenUUID = [NSString stringWithUTF8String:chosenServer.serverUUID];
211 NSArray *allServerDicts = [[SyphonServerDirectory sharedDirectory] servers];
212 for (NSDictionary *serverDict in allServerDicts)
214 if ([chosenUUID isEqualToString:[serverDict objectForKey:SyphonServerDescriptionUUIDKey]])
216 chosenServerDict = serverDict;
222 void (^connect)(void) = ^{
223 __block SyphonClient *s;
225 s = [[SyphonClient alloc] initWithServerDescription:chosenServerDict context:cgl_ctx options:nil newFrameHandler:^(SyphonClient *client) {
226 SyphonImage *frame = [client newFrameImage];
228 if (frame.textureSize.width < 1 || frame.textureSize.height < 1)
234 VuoImage image = VuoImage_makeClientOwnedGlTextureRectangle(frame.textureName, GL_RGBA, frame.textureSize.width, frame.textureSize.height, VuoSyphonListener_freeSyphonImageCallback, frame);
236 callback(VuoImage_makeCopy(image, false, 0, 0, false));
241 self.syphonClient = s;
249 dispatch_sync(dispatch_get_main_queue(), ^{
262 [
self refreshSyphonClientThreadUnsafe:serverDescriptions];
278 dispatch_sync(dispatch_get_main_queue(), ^{
282 self.syphonClient = nil;