13#include <OpenGL/OpenGL.h>
14#include <OpenGL/CGLMacro.h>
19 "title" :
"VuoSyphonListener",
21 "VuoSyphonServerNotifier",
34static void __attribute__((constructor)) VuoSyphonListener_init()
36 dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
38 dispatch_sync(dispatch_get_main_queue(), ^{
59 SyphonImage *frame = (SyphonImage *)image->freeCallbackContext;
72 if (
self = [super
init])
76 dispatch_sync(dispatch_get_main_queue(), ^{
84 refreshQueue = dispatch_queue_create(
"vuo.syphon.VuoSyphonListener", 0);
104 [
self refreshSyphonClientThreadUnsafe:allServerDescriptions];
128 __block NSDictionary *currentDict;
130 currentDict = [[
syphonClient serverDescription] retain];
134 dispatch_sync(dispatch_get_main_queue(), ^{
136 currentDict = [[syphonClient serverDescription] retain];
140 bool isCurrentStillDesired;
142 VuoText currentName =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
143 VuoText currentAppName =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
151 bool isCurrentStillAvailable;
153 VuoText currentUUID =
VuoText_make([[currentDict objectForKey:SyphonServerDescriptionUUIDKey] UTF8String]);
158 [currentDict release];
160 if (isCurrentStillDesired && isCurrentStillAvailable)
171 dispatch_sync(dispatch_get_main_queue(), ^{
176 self.syphonClient = nil;
193 dispatch_sync(dispatch_get_main_queue(), ^{
198 self.syphonClient = nil;
207 NSDictionary *chosenServerDict = nil;
208 NSString *chosenUUID = [NSString stringWithUTF8String:chosenServer.serverUUID];
209 NSArray *allServerDicts = [[SyphonServerDirectory sharedDirectory] servers];
210 for (NSDictionary *serverDict in allServerDicts)
212 if ([chosenUUID isEqualToString:[serverDict objectForKey:SyphonServerDescriptionUUIDKey]])
214 chosenServerDict = serverDict;
220 void (^connect)(void) = ^{
221 __block SyphonClient *s;
223 s = [[SyphonClient alloc] initWithServerDescription:chosenServerDict context:cgl_ctx options:nil newFrameHandler:^(SyphonClient *client) {
224 SyphonImage *frame = [client newFrameImage];
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;