New upstream version 24.0.1+dfsg1

This commit is contained in:
Sebastian Ramacher 2019-09-22 23:19:10 +02:00
parent b14f9eae6d
commit 5a730d6ec3
842 changed files with 42245 additions and 33385 deletions

View file

@ -1,9 +1,9 @@
Syphon="Syphon-Client"
Syphon="SyphonClient"
Source="Quelle"
LaunchSyphonInject="SyphonInject starten"
Inject="Injizieren"
Application="Anwendung"
SyphonLicense="Syphon-Lizenz"
SyphonLicense="SyphonLizenz"
Crop="Zuschneiden"
Crop.origin.x="Links abschneiden"
Crop.origin.y="Oben abschneiden"

View file

@ -1,12 +1,13 @@
Syphon="Cliente Syphon"
Source="Fonte"
LaunchSyphonInject="Lanzar SyphonInject"
LaunchSyphonInject="Iniciar SyphonInject"
Inject="Inxectar"
Application="Aplicación"
Application="Aplicativo"
SyphonLicense="Licenza Syphon"
Crop="Recortar"
Crop.origin.x="Recortar á esquerda"
Crop.origin.y="Recortar arriba"
Crop.size.width="Recortar á dereita"
Crop.size.height="Recortar abaixo"
Crop.origin.x="Recortar pola esquerda"
Crop.origin.y="Recortar por riba"
Crop.size.width="Recortar pola dereita"
Crop.size.height="Recortar por baixo"
AllowTransparency="Permitir transparencia"

View file

@ -2,7 +2,7 @@ Source="Vir"
LaunchSyphonInject="Zaženi SyphonInject"
Inject="Vstavi"
Application="Aplikacija"
SyphonLicense="Syphon Licenca"
SyphonLicense="Licenca za Syphon"
Crop="Obreži"
Crop.origin.x="Obreži levo"
Crop.origin.y="Obreži vrh"

View file

@ -3,40 +3,41 @@
#import "syphon-framework/Syphon.h"
#include <obs-module.h>
#define LOG(level, message, ...) \
blog(level, "%s: " message, obs_source_get_name(s->source), ##__VA_ARGS__)
#define LOG(level, message, ...) \
blog(level, "%s: " message, obs_source_get_name(s->source), \
##__VA_ARGS__)
struct syphon {
SYPHON_CLIENT_UNIQUE_CLASS_NAME *client;
IOSurfaceRef ref;
gs_samplerstate_t *sampler;
gs_effect_t *effect;
gs_vertbuffer_t *vertbuffer;
gs_texture_t *tex;
uint32_t width, height;
bool crop;
CGRect crop_rect;
bool allow_transparency;
gs_effect_t *effect;
gs_vertbuffer_t *vertbuffer;
gs_texture_t *tex;
uint32_t width, height;
bool crop;
CGRect crop_rect;
bool allow_transparency;
obs_source_t *source;
bool active;
bool uuid_changed;
id new_server_listener;
id retire_listener;
id new_server_listener;
id retire_listener;
NSString *app_name;
NSString *name;
NSString *uuid;
obs_data_t *inject_info;
NSString *inject_app;
NSString *inject_uuid;
bool inject_active;
id launch_listener;
bool inject_server_found;
float inject_wait_time;
NSString *inject_app;
NSString *inject_uuid;
bool inject_active;
id launch_listener;
bool inject_server_found;
float inject_wait_time;
};
typedef struct syphon *syphon_t;
@ -55,9 +56,9 @@ static inline void find_and_inject_target(syphon_t s, NSArray *arr, bool retry);
@interface OBSSyphonKVObserver : NSObject
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context;
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context;
@end
static inline void handle_application_launch(syphon_t s, NSArray *new)
@ -73,9 +74,9 @@ static inline void handle_application_launch(syphon_t s, NSArray *new)
@implementation OBSSyphonKVObserver
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
UNUSED_PARAMETER(keyPath);
UNUSED_PARAMETER(object);
@ -117,7 +118,7 @@ static void stop_client(syphon_t s)
s->ref = NULL;
}
s->width = 0;
s->width = 0;
s->height = 0;
obs_leave_graphics();
@ -143,8 +144,10 @@ static inline void check_version(syphon_t s, NSDictionary *desc)
"VersionKey");
if (version.unsignedIntValue > 0)
LOG(LOG_WARNING, "Got server description version %d, "
"expected 0", version.unsignedIntValue);
LOG(LOG_WARNING,
"Got server description version %d, "
"expected 0",
version.unsignedIntValue);
}
static inline void check_description(syphon_t s, NSDictionary *desc)
@ -169,9 +172,10 @@ static inline void check_description(syphon_t s, NSDictionary *desc)
}
NSString *surfaces_string = [NSString stringWithFormat:@"%@", surfaces];
LOG(LOG_WARNING, "SyphonSurfaces does not contain"
"'SyphonSurfaceTypeIOSurface': %s",
surfaces_string.UTF8String);
LOG(LOG_WARNING,
"SyphonSurfaces does not contain"
"'SyphonSurfaceTypeIOSurface': %s",
surfaces_string.UTF8String);
}
static inline bool update_string(NSString **str, NSString *new)
@ -185,7 +189,7 @@ static inline bool update_string(NSString **str, NSString *new)
}
static inline void handle_new_frame(syphon_t s,
SYPHON_CLIENT_UNIQUE_CLASS_NAME *client)
SYPHON_CLIENT_UNIQUE_CLASS_NAME *client)
{
IOSurfaceRef ref = [client IOSurface];
@ -206,9 +210,9 @@ static inline void handle_new_frame(syphon_t s,
CFRelease(s->ref);
}
s->ref = ref;
s->tex = gs_texture_create_from_iosurface(s->ref);
s->width = gs_texture_get_width(s->tex);
s->ref = ref;
s->tex = gs_texture_create_from_iosurface(s->ref);
s->width = gs_texture_get_width(s->tex);
s->height = gs_texture_get_height(s->tex);
obs_leave_graphics();
}
@ -230,7 +234,7 @@ static void create_client(syphon_t s)
if (!desc) {
desc = servers[0];
if (update_string(&s->uuid,
desc[SyphonServerDescriptionUUIDKey]))
desc[SyphonServerDescriptionUUIDKey]))
s->uuid_changed = true;
}
@ -241,11 +245,11 @@ static void create_client(syphon_t s)
s->client = [[SYPHON_CLIENT_UNIQUE_CLASS_NAME alloc]
initWithServerDescription:desc
options:nil
newFrameHandler:^
(SYPHON_CLIENT_UNIQUE_CLASS_NAME *client)
{
handle_new_frame(s, client);
}];
newFrameHandler:^(
SYPHON_CLIENT_UNIQUE_CLASS_NAME
*client) {
handle_new_frame(s, client);
}];
}
s->active = true;
@ -254,27 +258,27 @@ static void create_client(syphon_t s)
static inline void release_settings(syphon_t s)
{
[s->app_name release];
[s->name release];
[s->uuid release];
[s->name release];
[s->uuid release];
}
static inline bool load_syphon_settings(syphon_t s, obs_data_t *settings)
{
NSString *app_name = @(obs_data_get_string(settings, "app_name"));
NSString *name = @(obs_data_get_string(settings, "name"));
bool equal_names = [app_name isEqual:s->app_name] &&
[name isEqual:s->name];
NSString *name = @(obs_data_get_string(settings, "name"));
bool equal_names = [app_name isEqual:s->app_name] &&
[name isEqual:s->name];
if (s->uuid_changed && equal_names)
return false;
NSString *uuid = @(obs_data_get_string(settings, "uuid"));
NSString *uuid = @(obs_data_get_string(settings, "uuid"));
if ([uuid isEqual:s->uuid] && equal_names)
return false;
release_settings(s);
s->app_name = [app_name retain];
s->name = [name retain];
s->uuid = [uuid retain];
s->app_name = [app_name retain];
s->name = [name retain];
s->uuid = [uuid retain];
s->uuid_changed = false;
return true;
}
@ -288,15 +292,15 @@ static inline void update_from_announce(syphon_t s, NSDictionary *info)
return;
NSString *app_name = info[SyphonServerDescriptionAppNameKey];
NSString *name = info[SyphonServerDescriptionNameKey];
NSString *uuid = info[SyphonServerDescriptionUUIDKey];
NSString *name = info[SyphonServerDescriptionNameKey];
NSString *uuid = info[SyphonServerDescriptionUUIDKey];
if (![uuid isEqual:s->uuid] &&
!([app_name isEqual:s->app_name] && [name isEqual:s->name]))
!([app_name isEqual:s->app_name] && [name isEqual:s->name]))
return;
update_string(&s->app_name, app_name);
update_string(&s->name, name);
update_string(&s->name, name);
if (update_string(&s->uuid, uuid))
s->uuid_changed = true;
@ -304,27 +308,28 @@ static inline void update_from_announce(syphon_t s, NSDictionary *info)
}
static inline void update_inject_state(syphon_t s, NSDictionary *info,
bool announce)
bool announce)
{
if (!info)
return;
NSString *app_name = info[SyphonServerDescriptionAppNameKey];
NSString *name = info[SyphonServerDescriptionNameKey];
NSString *uuid = info[SyphonServerDescriptionUUIDKey];
NSString *name = info[SyphonServerDescriptionNameKey];
NSString *uuid = info[SyphonServerDescriptionUUIDKey];
if (![uuid isEqual:s->inject_uuid] &&
(![app_name isEqual:s->inject_app]
|| ![name isEqual:@"InjectedSyphon"]))
(![app_name isEqual:s->inject_app] ||
![name isEqual:@"InjectedSyphon"]))
return;
if (!(s->inject_server_found = announce)) {
s->inject_wait_time = 0.f;
objc_release(&s->inject_uuid);
LOG(LOG_INFO, "Injected server retired: "
"[%s] InjectedSyphon (%s)",
s->inject_app.UTF8String, uuid.UTF8String);
LOG(LOG_INFO,
"Injected server retired: "
"[%s] InjectedSyphon (%s)",
s->inject_app.UTF8String, uuid.UTF8String);
return;
}
@ -333,8 +338,7 @@ static inline void update_inject_state(syphon_t s, NSDictionary *info,
s->inject_uuid = [uuid retain];
LOG(LOG_INFO, "Injected server found: [%s] %s (%s)",
app_name.UTF8String, name.UTF8String,
uuid.UTF8String);
app_name.UTF8String, name.UTF8String, uuid.UTF8String);
}
static inline void handle_announce(syphon_t s, NSNotification *note)
@ -406,15 +410,15 @@ fail_tvarray:
static inline bool init_obs_graphics_objects(syphon_t s)
{
struct gs_sampler_info info = {
.filter = GS_FILTER_LINEAR,
.address_u = GS_ADDRESS_CLAMP,
.address_v = GS_ADDRESS_CLAMP,
.address_w = GS_ADDRESS_CLAMP,
.filter = GS_FILTER_LINEAR,
.address_u = GS_ADDRESS_CLAMP,
.address_v = GS_ADDRESS_CLAMP,
.address_w = GS_ADDRESS_CLAMP,
.max_anisotropy = 1,
};
obs_enter_graphics();
s->sampler = gs_samplerstate_create(&info);
s->sampler = gs_samplerstate_create(&info);
s->vertbuffer = create_vertbuffer();
obs_leave_graphics();
@ -426,25 +430,21 @@ static inline bool init_obs_graphics_objects(syphon_t s)
static inline bool create_syphon_listeners(syphon_t s)
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
s->new_server_listener = [nc
s->new_server_listener = [nc
addObserverForName:SyphonServerAnnounceNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note)
{
handle_announce(s, note);
}
];
usingBlock:^(NSNotification *note) {
handle_announce(s, note);
}];
s->retire_listener = [nc
s->retire_listener = [nc
addObserverForName:SyphonServerRetireNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note)
{
handle_retire(s, note);
}
];
usingBlock:^(NSNotification *note) {
handle_retire(s, note);
}];
return s->new_server_listener != nil && s->retire_listener != nil;
}
@ -456,9 +456,9 @@ static inline bool create_applications_observer(syphon_t s, NSWorkspace *ws)
return false;
[ws addObserver:s->launch_listener
forKeyPath:NSStringFromSelector(@selector(runningApplications))
options:NSKeyValueObservingOptionNew
context:s];
forKeyPath:NSStringFromSelector(@selector(runningApplications))
options:NSKeyValueObservingOptionNew
context:s];
return true;
}
@ -467,8 +467,7 @@ static inline void load_crop(syphon_t s, obs_data_t *settings)
{
s->crop = obs_data_get_bool(settings, "crop");
#define LOAD_CROP(x) \
s->crop_rect.x = obs_data_get_double(settings, "crop." #x)
#define LOAD_CROP(x) s->crop_rect.x = obs_data_get_double(settings, "crop." #x)
LOAD_CROP(origin.x);
LOAD_CROP(origin.y);
LOAD_CROP(size.width);
@ -486,7 +485,7 @@ static void *syphon_create_internal(obs_data_t *settings, obs_source_t *source)
if (!s)
return s;
s->source = source;
s->source = source;
if (!init_obs_graphics_objects(s))
goto fail;
@ -495,9 +494,9 @@ static void *syphon_create_internal(obs_data_t *settings, obs_source_t *source)
goto fail;
const char *inject_info = obs_data_get_string(settings, "application");
s->inject_info = obs_data_create_from_json(inject_info);
s->inject_active = obs_data_get_bool(settings, "inject");
s->inject_app = @(obs_data_get_string(s->inject_info, "name"));
s->inject_info = obs_data_create_from_json(inject_info);
s->inject_active = obs_data_get_bool(settings, "inject");
s->inject_app = @(obs_data_get_string(s->inject_info, "name"));
if (s->inject_app)
[s->inject_app retain];
@ -516,8 +515,8 @@ static void *syphon_create_internal(obs_data_t *settings, obs_source_t *source)
load_crop(s, settings);
s->allow_transparency = obs_data_get_bool(settings,
"allow_transparency");
s->allow_transparency =
obs_data_get_bool(settings, "allow_transparency");
return s;
@ -549,7 +548,8 @@ static inline void syphon_destroy_internal(syphon_t s)
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
[ws removeObserver:s->launch_listener
forKeyPath:NSStringFromSelector(@selector(runningApplications))];
forKeyPath:NSStringFromSelector(@selector
(runningApplications))];
objc_release(&s->launch_listener);
objc_release(&s->inject_app);
@ -561,7 +561,7 @@ static inline void syphon_destroy_internal(syphon_t s)
obs_enter_graphics();
stop_client(s);
if (s->sampler)
gs_samplerstate_destroy(s->sampler);
if (s->vertbuffer)
@ -587,44 +587,45 @@ static inline NSString *get_string(obs_data_t *settings, const char *name)
}
static inline void update_strings_from_context(syphon_t s, obs_data_t *settings,
NSString **app, NSString **name, NSString **uuid)
NSString **app, NSString **name,
NSString **uuid)
{
if (!s || !s->uuid_changed)
return;
s->uuid_changed = false;
*app = s->app_name;
*app = s->app_name;
*name = s->name;
*uuid = s->uuid;
obs_data_set_string(settings, "app_name", s->app_name.UTF8String);
obs_data_set_string(settings, "name", s->name.UTF8String);
obs_data_set_string(settings, "uuid", s->uuid.UTF8String);
obs_data_set_string(settings, "name", s->name.UTF8String);
obs_data_set_string(settings, "uuid", s->uuid.UTF8String);
}
static inline void add_servers(syphon_t s, obs_property_t *list,
obs_data_t *settings)
obs_data_t *settings)
{
bool found_current = settings == NULL;
NSString *set_app = get_string(settings, "app_name");
NSString *set_app = get_string(settings, "app_name");
NSString *set_name = get_string(settings, "name");
NSString *set_uuid = get_string(settings, "uuid");
update_strings_from_context(s, settings,
&set_app, &set_name, &set_uuid);
update_strings_from_context(s, settings, &set_app, &set_name,
&set_uuid);
obs_property_list_add_string(list, "", "");
NSArray *arr = [[SyphonServerDirectory sharedDirectory] servers];
for (NSDictionary *server in arr) {
NSString *app = server[SyphonServerDescriptionAppNameKey];
NSString *app = server[SyphonServerDescriptionAppNameKey];
NSString *name = server[SyphonServerDescriptionNameKey];
NSString *uuid = server[SyphonServerDescriptionUUIDKey];
NSString *serv = [NSString stringWithFormat:@"[%@] %@",
app, name];
NSString *serv =
[NSString stringWithFormat:@"[%@] %@", app, name];
obs_property_list_add_string(list,
serv.UTF8String, uuid.UTF8String);
obs_property_list_add_string(list, serv.UTF8String,
uuid.UTF8String);
if (!found_current)
found_current = [uuid isEqual:set_uuid];
@ -633,15 +634,15 @@ static inline void add_servers(syphon_t s, obs_property_t *list,
if (found_current || !set_uuid.length || !set_app.length)
return;
NSString *serv = [NSString stringWithFormat:@"[%@] %@",
set_app, set_name];
size_t idx = obs_property_list_add_string(list,
serv.UTF8String, set_uuid.UTF8String);
NSString *serv =
[NSString stringWithFormat:@"[%@] %@", set_app, set_name];
size_t idx = obs_property_list_add_string(list, serv.UTF8String,
set_uuid.UTF8String);
obs_property_list_item_disable(list, idx, true);
}
static bool servers_changed(obs_properties_t *props, obs_property_t *list,
obs_data_t *settings)
obs_data_t *settings)
{
@autoreleasepool {
obs_property_list_clear(list);
@ -662,16 +663,15 @@ static inline bool is_inject_available_in_lib_dir(NSFileManager *fm, NSURL *url)
if (!url.isFileURL)
return false;
for (NSString *path in [fm
contentsOfDirectoryAtPath:url.path
error:nil]) {
for (NSString *path in [fm contentsOfDirectoryAtPath:url.path
error:nil]) {
NSURL *bundle_url = [url URLByAppendingPathComponent:path];
NSBundle *bundle = [NSBundle bundleWithURL:bundle_url];
NSBundle *bundle = [NSBundle bundleWithURL:bundle_url];
if (!bundle)
continue;
if ([bundle.bundleIdentifier
isEqual:@"zakk.lol.SASyphonInjector"])
isEqual:@"zakk.lol.SASyphonInjector"])
return true;
}
@ -705,7 +705,7 @@ static inline void launch_syphon_inject_internal()
}
static bool launch_syphon_inject(obs_properties_t *props, obs_property_t *prop,
void *data)
void *data)
{
UNUSED_PARAMETER(props);
UNUSED_PARAMETER(prop);
@ -720,13 +720,13 @@ static bool launch_syphon_inject(obs_properties_t *props, obs_property_t *prop,
static int describes_app(obs_data_t *info, NSRunningApplication *app)
{
int score = 0;
if ([app.localizedName isEqual:get_string(info, "name")])
if ([app.localizedName isEqual:get_string(info, "name")])
score += 2;
if ([app.bundleIdentifier isEqual:get_string(info, "bundle")])
score += 2;
if ([app.executableURL isEqual:get_string(info, "executable")])
if ([app.executableURL isEqual:get_string(info, "executable")])
score += 2;
if (score && app.processIdentifier == obs_data_get_int(info, "pid"))
@ -739,10 +739,10 @@ static inline void app_to_data(NSRunningApplication *app, obs_data_t *app_data)
{
obs_data_set_string(app_data, "name", app.localizedName.UTF8String);
obs_data_set_string(app_data, "bundle",
app.bundleIdentifier.UTF8String);
app.bundleIdentifier.UTF8String);
// Until we drop 10.8, use path.fileSystemRepsentation
obs_data_set_string(app_data, "executable",
app.executableURL.path.fileSystemRepresentation);
app.executableURL.path.fileSystemRepresentation);
obs_data_set_int(app_data, "pid", app.processIdentifier);
}
@ -760,8 +760,9 @@ static inline NSDictionary *get_duplicate_names(NSArray *apps)
}
static inline size_t add_app(obs_property_t *prop, NSDictionary *duplicates,
NSString *name, const char *bundle, const char *json_data,
bool is_duplicate, pid_t pid)
NSString *name, const char *bundle,
const char *json_data, bool is_duplicate,
pid_t pid)
{
if (!is_duplicate) {
NSNumber *val = duplicates[name];
@ -769,20 +770,21 @@ static inline size_t add_app(obs_property_t *prop, NSDictionary *duplicates,
}
if (is_duplicate)
name = [NSString stringWithFormat:@"%@ (%s: %d)",
name, bundle, pid];
name = [NSString
stringWithFormat:@"%@ (%s: %d)", name, bundle, pid];
return obs_property_list_add_string(prop, name.UTF8String, json_data);
}
static void update_inject_list_internal(obs_properties_t *props,
obs_property_t *prop, obs_data_t *settings)
obs_property_t *prop,
obs_data_t *settings)
{
UNUSED_PARAMETER(props);
const char *current_str = obs_data_get_string(settings, "application");
obs_data_t *current = obs_data_create_from_json(current_str);
NSString *current_name = @(obs_data_get_string(current, "name"));
const char *current_str = obs_data_get_string(settings, "application");
obs_data_t *current = obs_data_create_from_json(current_str);
NSString *current_name = @(obs_data_get_string(current, "name"));
bool current_found = !obs_data_has_user_value(current, "name");
@ -790,10 +792,10 @@ static void update_inject_list_internal(obs_properties_t *props,
obs_property_list_add_string(prop, "", "");
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
NSArray *apps = ws.runningApplications;
NSArray *apps = ws.runningApplications;
NSDictionary *duplicates = get_duplicate_names(apps);
NSMapTable *candidates = [NSMapTable weakToStrongObjectsMapTable];
NSMapTable *candidates = [NSMapTable weakToStrongObjectsMapTable];
obs_data_t *app_data = obs_data_create();
for (NSRunningApplication *app in apps) {
@ -801,11 +803,10 @@ static void update_inject_list_internal(obs_properties_t *props,
int score = describes_app(current, app);
NSString *name = app.localizedName;
add_app(prop, duplicates, name,
app.bundleIdentifier.UTF8String,
obs_data_get_json(app_data),
[name isEqual:current_name] && score < 4,
app.processIdentifier);
add_app(prop, duplicates, name, app.bundleIdentifier.UTF8String,
obs_data_get_json(app_data),
[name isEqual:current_name] && score < 4,
app.processIdentifier);
if (score >= 4) {
[candidates setObject:@(score) forKey:app];
@ -816,10 +817,10 @@ static void update_inject_list_internal(obs_properties_t *props,
if (!current_found) {
size_t idx = add_app(prop, duplicates, current_name,
obs_data_get_string(current, "bundle"),
current_str,
duplicates[current_name] != nil,
obs_data_get_int(current, "pid"));
obs_data_get_string(current, "bundle"),
current_str,
duplicates[current_name] != nil,
obs_data_get_int(current, "pid"));
obs_property_list_item_disable(prop, idx, true);
} else if (candidates.count > 0) {
@ -829,7 +830,7 @@ static void update_inject_list_internal(obs_properties_t *props,
for (NSRunningApplication *app in candidates.keyEnumerator) {
NSNumber *score = [candidates objectForKey:app];
if ([score compare:best_match_score] ==
NSOrderedDescending) {
NSOrderedDescending) {
best_match = app;
best_match_score = score;
}
@ -839,7 +840,7 @@ static void update_inject_list_internal(obs_properties_t *props,
if (best_match_score.intValue >= 4) {
app_to_data(best_match, current);
obs_data_set_string(settings, "application",
obs_data_get_json(current));
obs_data_get_json(current));
}
}
@ -847,7 +848,7 @@ static void update_inject_list_internal(obs_properties_t *props,
}
static void toggle_inject_internal(obs_properties_t *props,
obs_property_t *prop, obs_data_t *settings)
obs_property_t *prop, obs_data_t *settings)
{
bool enabled = obs_data_get_bool(settings, "inject");
obs_property_t *inject_list = obs_properties_get(props, "application");
@ -857,7 +858,7 @@ static void toggle_inject_internal(obs_properties_t *props,
}
static bool toggle_inject(obs_properties_t *props, obs_property_t *prop,
obs_data_t *settings)
obs_data_t *settings)
{
@autoreleasepool {
toggle_inject_internal(props, prop, settings);
@ -866,7 +867,7 @@ static bool toggle_inject(obs_properties_t *props, obs_property_t *prop,
}
static bool update_inject_list(obs_properties_t *props, obs_property_t *prop,
obs_data_t *settings)
obs_data_t *settings)
{
@autoreleasepool {
update_inject_list_internal(props, prop, settings);
@ -875,11 +876,11 @@ static bool update_inject_list(obs_properties_t *props, obs_property_t *prop,
}
static bool update_crop(obs_properties_t *props, obs_property_t *prop,
obs_data_t *settings)
obs_data_t *settings)
{
bool enabled = obs_data_get_bool(settings, "crop");
#define LOAD_CROP(x) \
#define LOAD_CROP(x) \
prop = obs_properties_get(props, "crop." #x); \
obs_property_set_enabled(prop, enabled);
LOAD_CROP(origin.x);
@ -903,7 +904,7 @@ static void show_syphon_license_internal(void)
}
static bool show_syphon_license(obs_properties_t *props, obs_property_t *prop,
void *data)
void *data)
{
UNUSED_PARAMETER(props);
UNUSED_PARAMETER(prop);
@ -928,28 +929,28 @@ static inline obs_properties_t *syphon_properties_internal(syphon_t s)
if (s)
obs_source_addref(s->source);
obs_properties_t *props = obs_properties_create_param(s,
syphon_release);
obs_properties_t *props =
obs_properties_create_param(s, syphon_release);
obs_property_t *list = obs_properties_add_list(props,
"uuid", obs_module_text("Source"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
obs_property_t *list = obs_properties_add_list(
props, "uuid", obs_module_text("Source"), OBS_COMBO_TYPE_LIST,
OBS_COMBO_FORMAT_STRING);
obs_property_set_modified_callback(list, servers_changed);
obs_properties_add_bool(props, "allow_transparency",
obs_module_text("AllowTransparency"));
obs_module_text("AllowTransparency"));
obs_property_t *launch = obs_properties_add_button(props,
"launch inject", obs_module_text("LaunchSyphonInject"),
launch_syphon_inject);
obs_property_t *launch = obs_properties_add_button(
props, "launch inject", obs_module_text("LaunchSyphonInject"),
launch_syphon_inject);
obs_property_t *inject = obs_properties_add_bool(props,
"inject", obs_module_text("Inject"));
obs_property_t *inject = obs_properties_add_bool(
props, "inject", obs_module_text("Inject"));
obs_property_set_modified_callback(inject, toggle_inject);
obs_property_t *inject_list = obs_properties_add_list(props,
"application", obs_module_text("Application"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
obs_property_t *inject_list = obs_properties_add_list(
props, "application", obs_module_text("Application"),
OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
obs_property_set_modified_callback(inject_list, update_inject_list);
if (!get_inject_application_path())
@ -960,13 +961,14 @@ static inline obs_properties_t *syphon_properties_internal(syphon_t s)
obs_property_set_enabled(inject_list, false);
}
obs_property_t *crop = obs_properties_add_bool(props, "crop",
obs_module_text("Crop"));
obs_property_t *crop =
obs_properties_add_bool(props, "crop", obs_module_text("Crop"));
obs_property_set_modified_callback(crop, update_crop);
#define LOAD_CROP(x) \
obs_properties_add_float(props, "crop." #x, \
obs_module_text("Crop." #x), 0., 4096.f, .5f);
#define LOAD_CROP(x) \
obs_properties_add_float(props, "crop." #x, \
obs_module_text("Crop." #x), 0., 4096.f, \
.5f);
LOAD_CROP(origin.x);
LOAD_CROP(origin.y);
LOAD_CROP(size.width);
@ -974,8 +976,8 @@ static inline obs_properties_t *syphon_properties_internal(syphon_t s)
#undef LOAD_CROP
obs_properties_add_button(props, "syphon license",
obs_module_text("SyphonLicense"),
show_syphon_license);
obs_module_text("SyphonLicense"),
show_syphon_license);
return props;
}
@ -993,8 +995,8 @@ static inline void syphon_save_internal(syphon_t s, obs_data_t *settings)
return;
obs_data_set_string(settings, "app_name", s->app_name.UTF8String);
obs_data_set_string(settings, "name", s->name.UTF8String);
obs_data_set_string(settings, "uuid", s->uuid.UTF8String);
obs_data_set_string(settings, "name", s->name.UTF8String);
obs_data_set_string(settings, "uuid", s->uuid.UTF8String);
}
static void syphon_save(void *data, obs_data_t *settings)
@ -1005,25 +1007,25 @@ static void syphon_save(void *data, obs_data_t *settings)
}
static inline void build_sprite(struct gs_vb_data *data, float fcx, float fcy,
float start_u, float end_u, float start_v, float end_v)
float start_u, float end_u, float start_v,
float end_v)
{
struct vec2 *tvarray = data->tvarray[0].array;
vec3_set(data->points+1, fcx, 0.0f, 0.0f);
vec3_set(data->points+2, 0.0f, fcy, 0.0f);
vec3_set(data->points+3, fcx, fcy, 0.0f);
vec2_set(tvarray, start_u, start_v);
vec2_set(tvarray+1, end_u, start_v);
vec2_set(tvarray+2, start_u, end_v);
vec2_set(tvarray+3, end_u, end_v);
vec3_set(data->points + 1, fcx, 0.0f, 0.0f);
vec3_set(data->points + 2, 0.0f, fcy, 0.0f);
vec3_set(data->points + 3, fcx, fcy, 0.0f);
vec2_set(tvarray, start_u, start_v);
vec2_set(tvarray + 1, end_u, start_v);
vec2_set(tvarray + 2, start_u, end_v);
vec2_set(tvarray + 3, end_u, end_v);
}
static inline void build_sprite_rect(struct gs_vb_data *data,
float origin_x, float origin_y, float end_x, float end_y)
static inline void build_sprite_rect(struct gs_vb_data *data, float origin_x,
float origin_y, float end_x, float end_y)
{
build_sprite(data, fabs(end_x - origin_x), fabs(end_y - origin_y),
origin_x, end_x,
origin_y, end_y);
origin_x, end_x, origin_y, end_y);
}
static inline void tick_inject_state(syphon_t s, float seconds)
@ -1050,17 +1052,15 @@ static void syphon_video_tick(void *data, float seconds)
if (!s->tex)
return;
static const CGRect null_crop = { { 0.f } };
static const CGRect null_crop = {{0.f}};
const CGRect *crop = &null_crop;
if (s->crop)
crop = &s->crop_rect;
obs_enter_graphics();
build_sprite_rect(gs_vertexbuffer_get_data(s->vertbuffer),
crop->origin.x,
s->height - crop->origin.y,
s->width - crop->size.width,
crop->size.height);
crop->origin.x, s->height - crop->origin.y,
s->width - crop->size.width, crop->size.height);
obs_leave_graphics();
}
@ -1085,7 +1085,7 @@ static void syphon_video_render(void *data, gs_effect_t *effect)
gs_load_samplerstate(s->sampler, 0);
gs_technique_t *tech = gs_effect_get_technique(s->effect, "Draw");
gs_effect_set_texture(gs_effect_get_param_by_name(s->effect, "image"),
s->tex);
s->tex);
gs_technique_begin(tech);
gs_technique_begin_pass(tech, 0);
@ -1105,9 +1105,8 @@ static uint32_t syphon_get_width(void *data)
syphon_t s = (syphon_t)data;
if (!s->crop)
return s->width;
int32_t width = s->width
- s->crop_rect.origin.x
- s->crop_rect.size.width;
int32_t width =
s->width - s->crop_rect.origin.x - s->crop_rect.size.width;
return MAX(0, width);
}
@ -1116,9 +1115,8 @@ static uint32_t syphon_get_height(void *data)
syphon_t s = (syphon_t)data;
if (!s->crop)
return s->height;
int32_t height = s->height
- s->crop_rect.origin.y
- s->crop_rect.size.height;
int32_t height =
s->height - s->crop_rect.origin.y - s->crop_rect.size.height;
return MAX(0, height);
}
@ -1134,9 +1132,9 @@ static inline void inject_app(syphon_t s, NSRunningApplication *app, bool retry)
if (!sbapp)
return LOG(LOG_ERROR, "Could not inject %s",
app.localizedName.UTF8String);
app.localizedName.UTF8String);
sbapp.timeout = 10*60;
sbapp.timeout = 10 * 60;
sbapp.sendMode = kAEWaitReply;
[sbapp sendEvent:'ascr' id:'gdut' parameters:0];
sbapp.sendMode = kAENoReply;
@ -1145,9 +1143,8 @@ static inline void inject_app(syphon_t s, NSRunningApplication *app, bool retry)
if (retry)
return;
LOG(LOG_INFO, "Injected '%s' (%d, '%s')",
app.localizedName.UTF8String,
app.processIdentifier, app.bundleIdentifier.UTF8String);
LOG(LOG_INFO, "Injected '%s' (%d, '%s')", app.localizedName.UTF8String,
app.processIdentifier, app.bundleIdentifier.UTF8String);
}
static inline void find_and_inject_target(syphon_t s, NSArray *arr, bool retry)
@ -1174,20 +1171,17 @@ static inline void find_and_inject_target(syphon_t s, NSArray *arr, bool retry)
static inline bool inject_info_equal(obs_data_t *prev, obs_data_t *new)
{
if (![get_string(prev, "name")
isEqual:get_string(new, "name")])
if (![get_string(prev, "name") isEqual:get_string(new, "name")])
return false;
if (![get_string(prev, "bundle")
isEqual:get_string(new, "bundle")])
if (![get_string(prev, "bundle") isEqual:get_string(new, "bundle")])
return false;
if (![get_string(prev, "executable")
isEqual:get_string(new, "executable")])
isEqual:get_string(new, "executable")])
return false;
if (![get_string(prev, "pid")
isEqual:get_string(new, "pid")])
if (![get_string(prev, "pid") isEqual:get_string(new, "pid")])
return false;
return true;
@ -1195,15 +1189,15 @@ static inline bool inject_info_equal(obs_data_t *prev, obs_data_t *new)
static inline void update_inject(syphon_t s, obs_data_t *settings)
{
bool try_injecting = s->inject_active;
s->inject_active = obs_data_get_bool(settings, "inject");
bool try_injecting = s->inject_active;
s->inject_active = obs_data_get_bool(settings, "inject");
const char *inject_str = obs_data_get_string(settings, "application");
try_injecting = !try_injecting && s->inject_active;
obs_data_t *prev = s->inject_info;
s->inject_info = obs_data_create_from_json(inject_str);
NSString *prev_app = s->inject_app;
s->inject_app = [@(obs_data_get_string(s->inject_info, "name")) retain];
[prev_app release];
@ -1216,10 +1210,10 @@ static inline void update_inject(syphon_t s, obs_data_t *settings)
s->inject_server_found = false;
for (NSDictionary *server in servers)
update_inject_state(s, server, true);
if (!try_injecting)
try_injecting = s->inject_active &&
!inject_info_equal(prev, s->inject_info);
!inject_info_equal(prev, s->inject_info);
obs_data_release(prev);
@ -1239,15 +1233,15 @@ static inline bool update_syphon(syphon_t s, obs_data_t *settings)
NSDictionary *dict = find_by_uuid(arr, s->uuid);
if (dict) {
NSString *app = dict[SyphonServerDescriptionAppNameKey];
NSString *app = dict[SyphonServerDescriptionAppNameKey];
NSString *name = dict[SyphonServerDescriptionNameKey];
obs_data_set_string(settings, "app_name", app.UTF8String);
obs_data_set_string(settings, "name", name.UTF8String);
obs_data_set_string(settings, "name", name.UTF8String);
load_syphon_settings(s, settings);
} else if (!dict && !s->uuid.length) {
obs_data_set_string(settings, "app_name", "");
obs_data_set_string(settings, "name", "");
obs_data_set_string(settings, "name", "");
load_syphon_settings(s, settings);
}
@ -1256,8 +1250,8 @@ static inline bool update_syphon(syphon_t s, obs_data_t *settings)
static void syphon_update_internal(syphon_t s, obs_data_t *settings)
{
s->allow_transparency = obs_data_get_bool(settings,
"allow_transparency");
s->allow_transparency =
obs_data_get_bool(settings, "allow_transparency");
load_crop(s, settings);
update_inject(s, settings);
@ -1273,19 +1267,18 @@ static void syphon_update(void *data, obs_data_t *settings)
}
struct obs_source_info syphon_info = {
.id = "syphon-input",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW |
OBS_SOURCE_DO_NOT_DUPLICATE,
.get_name = syphon_get_name,
.create = syphon_create,
.destroy = syphon_destroy,
.video_render = syphon_video_render,
.video_tick = syphon_video_tick,
.id = "syphon-input",
.type = OBS_SOURCE_TYPE_INPUT,
.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW |
OBS_SOURCE_DO_NOT_DUPLICATE,
.get_name = syphon_get_name,
.create = syphon_create,
.destroy = syphon_destroy,
.video_render = syphon_video_render,
.video_tick = syphon_video_tick,
.get_properties = syphon_properties,
.get_width = syphon_get_width,
.get_height = syphon_get_height,
.update = syphon_update,
.save = syphon_save,
.get_width = syphon_get_width,
.get_height = syphon_get_height,
.update = syphon_update,
.save = syphon_save,
};