mac-screen-capture.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. #include "mac-sck-common.h"
  2. static void destroy_screen_stream(struct screen_capture *sc)
  3. {
  4. if (sc->disp) {
  5. [sc->disp stopCaptureWithCompletionHandler:^(NSError *_Nullable error) {
  6. if (error && error.code != 3808) {
  7. MACCAP_ERR("destroy_screen_stream: Failed to stop stream with error %s\n",
  8. [[error localizedFailureReason] cStringUsingEncoding:NSUTF8StringEncoding]);
  9. }
  10. os_event_signal(sc->disp_finished);
  11. }];
  12. os_event_wait(sc->disp_finished);
  13. }
  14. if (sc->stream_properties) {
  15. [sc->stream_properties release];
  16. sc->stream_properties = NULL;
  17. }
  18. if (sc->tex) {
  19. gs_texture_destroy(sc->tex);
  20. sc->tex = NULL;
  21. }
  22. if (sc->current) {
  23. IOSurfaceDecrementUseCount(sc->current);
  24. CFRelease(sc->current);
  25. sc->current = NULL;
  26. }
  27. if (sc->prev) {
  28. IOSurfaceDecrementUseCount(sc->prev);
  29. CFRelease(sc->prev);
  30. sc->prev = NULL;
  31. }
  32. if (sc->disp) {
  33. [sc->disp release];
  34. sc->disp = NULL;
  35. }
  36. os_event_destroy(sc->disp_finished);
  37. os_event_destroy(sc->stream_start_completed);
  38. }
  39. static void sck_video_capture_destroy(void *data)
  40. {
  41. struct screen_capture *sc = data;
  42. if (!sc)
  43. return;
  44. obs_enter_graphics();
  45. destroy_screen_stream(sc);
  46. obs_leave_graphics();
  47. if (sc->shareable_content) {
  48. os_sem_wait(sc->shareable_content_available);
  49. [sc->shareable_content release];
  50. os_sem_destroy(sc->shareable_content_available);
  51. sc->shareable_content_available = NULL;
  52. }
  53. if (sc->capture_delegate) {
  54. [sc->capture_delegate release];
  55. }
  56. [sc->application_id release];
  57. pthread_mutex_destroy(&sc->mutex);
  58. bfree(sc);
  59. }
  60. static bool init_screen_stream(struct screen_capture *sc)
  61. {
  62. SCContentFilter *content_filter;
  63. sc->frame = CGRectZero;
  64. sc->stream_properties = [[SCStreamConfiguration alloc] init];
  65. os_sem_wait(sc->shareable_content_available);
  66. SCDisplay * (^get_target_display)(void) = ^SCDisplay *
  67. {
  68. for (SCDisplay *display in sc->shareable_content.displays) {
  69. if (display.displayID == sc->display) {
  70. return display;
  71. }
  72. }
  73. return nil;
  74. };
  75. void (^set_display_mode)(struct screen_capture *, SCDisplay *) =
  76. ^void(struct screen_capture *capture_data, SCDisplay *target_display) {
  77. CGDisplayModeRef display_mode = CGDisplayCopyDisplayMode(target_display.displayID);
  78. [capture_data->stream_properties setWidth:CGDisplayModeGetPixelWidth(display_mode)];
  79. [capture_data->stream_properties setHeight:CGDisplayModeGetPixelHeight(display_mode)];
  80. CGDisplayModeRelease(display_mode);
  81. };
  82. switch (sc->capture_type) {
  83. case ScreenCaptureDisplayStream: {
  84. SCDisplay *target_display = get_target_display();
  85. if (sc->hide_obs) {
  86. SCRunningApplication *obsApp = nil;
  87. NSString *mainBundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
  88. for (SCRunningApplication *app in sc->shareable_content.applications) {
  89. if ([app.bundleIdentifier isEqualToString:mainBundleIdentifier]) {
  90. obsApp = app;
  91. break;
  92. }
  93. }
  94. NSArray *exclusions = [[NSArray alloc] initWithObjects:obsApp, nil];
  95. NSArray *empty = [[NSArray alloc] init];
  96. content_filter = [[SCContentFilter alloc] initWithDisplay:target_display
  97. excludingApplications:exclusions
  98. exceptingWindows:empty];
  99. [empty release];
  100. [exclusions release];
  101. } else {
  102. NSArray *empty = [[NSArray alloc] init];
  103. content_filter = [[SCContentFilter alloc] initWithDisplay:target_display excludingWindows:empty];
  104. [empty release];
  105. }
  106. set_display_mode(sc, target_display);
  107. } break;
  108. case ScreenCaptureWindowStream: {
  109. SCWindow *target_window = nil;
  110. if (sc->window != 0) {
  111. for (SCWindow *window in sc->shareable_content.windows) {
  112. if (window.windowID == sc->window) {
  113. target_window = window;
  114. break;
  115. }
  116. }
  117. } else {
  118. target_window = [sc->shareable_content.windows objectAtIndex:0];
  119. sc->window = target_window.windowID;
  120. }
  121. content_filter = [[SCContentFilter alloc] initWithDesktopIndependentWindow:target_window];
  122. if (target_window) {
  123. [sc->stream_properties setWidth:(size_t) target_window.frame.size.width];
  124. [sc->stream_properties setHeight:(size_t) target_window.frame.size.height];
  125. }
  126. } break;
  127. case ScreenCaptureApplicationStream: {
  128. SCDisplay *target_display = get_target_display();
  129. SCRunningApplication *target_application = nil;
  130. for (SCRunningApplication *application in sc->shareable_content.applications) {
  131. if ([application.bundleIdentifier isEqualToString:sc->application_id]) {
  132. target_application = application;
  133. break;
  134. }
  135. }
  136. NSArray *target_application_array = [[NSArray alloc] initWithObjects:target_application, nil];
  137. NSArray *empty_array = [[NSArray alloc] init];
  138. content_filter = [[SCContentFilter alloc] initWithDisplay:target_display
  139. includingApplications:target_application_array
  140. exceptingWindows:empty_array];
  141. [target_application_array release];
  142. [empty_array release];
  143. set_display_mode(sc, target_display);
  144. } break;
  145. }
  146. os_sem_post(sc->shareable_content_available);
  147. CGColorRef background = CGColorGetConstantColor(kCGColorClear);
  148. [sc->stream_properties setQueueDepth:8];
  149. [sc->stream_properties setShowsCursor:!sc->hide_cursor];
  150. [sc->stream_properties setColorSpaceName:kCGColorSpaceDisplayP3];
  151. [sc->stream_properties setBackgroundColor:background];
  152. FourCharCode l10r_type = 0;
  153. l10r_type = ('l' << 24) | ('1' << 16) | ('0' << 8) | 'r';
  154. [sc->stream_properties setPixelFormat:l10r_type];
  155. if (@available(macOS 13.0, *)) {
  156. #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130000
  157. [sc->stream_properties setCapturesAudio:YES];
  158. [sc->stream_properties setExcludesCurrentProcessAudio:YES];
  159. [sc->stream_properties setChannelCount:2];
  160. #endif
  161. } else {
  162. if (sc->capture_type != ScreenCaptureWindowStream) {
  163. sc->disp = NULL;
  164. [content_filter release];
  165. os_event_init(&sc->disp_finished, OS_EVENT_TYPE_MANUAL);
  166. os_event_init(&sc->stream_start_completed, OS_EVENT_TYPE_MANUAL);
  167. return true;
  168. }
  169. }
  170. sc->disp = [[SCStream alloc] initWithFilter:content_filter configuration:sc->stream_properties
  171. delegate:sc->capture_delegate];
  172. [content_filter release];
  173. NSError *addStreamOutputError = nil;
  174. BOOL did_add_output = [sc->disp addStreamOutput:sc->capture_delegate type:SCStreamOutputTypeScreen
  175. sampleHandlerQueue:nil
  176. error:&addStreamOutputError];
  177. if (!did_add_output) {
  178. MACCAP_ERR("init_screen_stream: Failed to add stream output with error %s\n",
  179. [[addStreamOutputError localizedFailureReason] cStringUsingEncoding:NSUTF8StringEncoding]);
  180. [addStreamOutputError release];
  181. return !did_add_output;
  182. }
  183. #if __MAC_OS_X_VERSION_MAX_ALLOWED >= 130000
  184. if (@available(macOS 13.0, *)) {
  185. did_add_output = [sc->disp addStreamOutput:sc->capture_delegate type:SCStreamOutputTypeAudio
  186. sampleHandlerQueue:nil
  187. error:&addStreamOutputError];
  188. if (!did_add_output) {
  189. MACCAP_ERR("init_screen_stream: Failed to add audio stream output with error %s\n",
  190. [[addStreamOutputError localizedFailureReason] cStringUsingEncoding:NSUTF8StringEncoding]);
  191. [addStreamOutputError release];
  192. return !did_add_output;
  193. }
  194. }
  195. #endif
  196. os_event_init(&sc->disp_finished, OS_EVENT_TYPE_MANUAL);
  197. os_event_init(&sc->stream_start_completed, OS_EVENT_TYPE_MANUAL);
  198. __block BOOL did_stream_start = NO;
  199. [sc->disp startCaptureWithCompletionHandler:^(NSError *_Nullable error) {
  200. did_stream_start = (BOOL) (error == nil);
  201. if (!did_stream_start) {
  202. MACCAP_ERR("init_screen_stream: Failed to start capture with error %s\n",
  203. [[error localizedFailureReason] cStringUsingEncoding:NSUTF8StringEncoding]);
  204. // Clean up disp so it isn't stopped
  205. [sc->disp release];
  206. sc->disp = NULL;
  207. }
  208. os_event_signal(sc->stream_start_completed);
  209. }];
  210. os_event_wait(sc->stream_start_completed);
  211. return did_stream_start;
  212. }
  213. static void *sck_video_capture_create(obs_data_t *settings, obs_source_t *source)
  214. {
  215. struct screen_capture *sc = bzalloc(sizeof(struct screen_capture));
  216. sc->source = source;
  217. sc->hide_cursor = !obs_data_get_bool(settings, "show_cursor");
  218. sc->hide_obs = obs_data_get_bool(settings, "hide_obs");
  219. sc->show_empty_names = obs_data_get_bool(settings, "show_empty_names");
  220. sc->show_hidden_windows = obs_data_get_bool(settings, "show_hidden_windows");
  221. sc->window = (CGWindowID) obs_data_get_int(settings, "window");
  222. sc->capture_type = (unsigned int) obs_data_get_int(settings, "type");
  223. os_sem_init(&sc->shareable_content_available, 1);
  224. screen_capture_build_content_list(sc, sc->capture_type == ScreenCaptureDisplayStream);
  225. sc->capture_delegate = [[ScreenCaptureDelegate alloc] init];
  226. sc->capture_delegate.sc = sc;
  227. sc->effect = obs_get_base_effect(OBS_EFFECT_DEFAULT_RECT);
  228. if (!sc->effect)
  229. goto fail;
  230. bool legacy_display_id = obs_data_has_user_value(settings, "display");
  231. if (legacy_display_id) {
  232. CGDirectDisplayID display_id = (CGDirectDisplayID) obs_data_get_int(settings, "display");
  233. CFUUIDRef display_uuid = CGDisplayCreateUUIDFromDisplayID(display_id);
  234. CFStringRef uuid_string = CFUUIDCreateString(kCFAllocatorDefault, display_uuid);
  235. obs_data_set_string(settings, "display_uuid", CFStringGetCStringPtr(uuid_string, kCFStringEncodingUTF8));
  236. obs_data_erase(settings, "display");
  237. CFRelease(uuid_string);
  238. CFRelease(display_uuid);
  239. }
  240. const char *display_uuid = obs_data_get_string(settings, "display_uuid");
  241. if (display_uuid) {
  242. CFStringRef uuid_string = CFStringCreateWithCString(kCFAllocatorDefault, display_uuid, kCFStringEncodingUTF8);
  243. CFUUIDRef uuid_ref = CFUUIDCreateFromString(kCFAllocatorDefault, uuid_string);
  244. sc->display = CGDisplayGetDisplayIDFromUUID(uuid_ref);
  245. CFRelease(uuid_string);
  246. CFRelease(uuid_ref);
  247. } else {
  248. sc->display = CGMainDisplayID();
  249. }
  250. sc->application_id = [[NSString alloc] initWithUTF8String:obs_data_get_string(settings, "application")];
  251. pthread_mutex_init(&sc->mutex, NULL);
  252. if (!init_screen_stream(sc))
  253. goto fail;
  254. return sc;
  255. fail:
  256. obs_leave_graphics();
  257. sck_video_capture_destroy(sc);
  258. return NULL;
  259. }
  260. static void sck_video_capture_tick(void *data, float seconds __unused)
  261. {
  262. struct screen_capture *sc = data;
  263. if (!sc->current)
  264. return;
  265. if (!obs_source_showing(sc->source))
  266. return;
  267. IOSurfaceRef prev_prev = sc->prev;
  268. if (pthread_mutex_lock(&sc->mutex))
  269. return;
  270. sc->prev = sc->current;
  271. sc->current = NULL;
  272. pthread_mutex_unlock(&sc->mutex);
  273. if (prev_prev == sc->prev)
  274. return;
  275. obs_enter_graphics();
  276. if (sc->tex)
  277. gs_texture_rebind_iosurface(sc->tex, sc->prev);
  278. else
  279. sc->tex = gs_texture_create_from_iosurface(sc->prev);
  280. obs_leave_graphics();
  281. if (prev_prev) {
  282. IOSurfaceDecrementUseCount(prev_prev);
  283. CFRelease(prev_prev);
  284. }
  285. }
  286. static void sck_video_capture_render(void *data, gs_effect_t *effect __unused)
  287. {
  288. struct screen_capture *sc = data;
  289. if (!sc->tex)
  290. return;
  291. const bool previous = gs_framebuffer_srgb_enabled();
  292. gs_enable_framebuffer_srgb(true);
  293. gs_eparam_t *param = gs_effect_get_param_by_name(sc->effect, "image");
  294. gs_effect_set_texture(param, sc->tex);
  295. while (gs_effect_loop(sc->effect, "DrawD65P3"))
  296. gs_draw_sprite(sc->tex, 0, 0, 0);
  297. gs_enable_framebuffer_srgb(previous);
  298. }
  299. static const char *sck_video_capture_getname(void *unused __unused)
  300. {
  301. if (@available(macOS 13.0, *))
  302. return obs_module_text("SCK.Name");
  303. else
  304. return obs_module_text("SCK.Name.Beta");
  305. }
  306. static uint32_t sck_video_capture_getwidth(void *data)
  307. {
  308. struct screen_capture *sc = data;
  309. return (uint32_t) sc->frame.size.width;
  310. }
  311. static uint32_t sck_video_capture_getheight(void *data)
  312. {
  313. struct screen_capture *sc = data;
  314. return (uint32_t) sc->frame.size.height;
  315. }
  316. static void sck_video_capture_defaults(obs_data_t *settings)
  317. {
  318. CGDirectDisplayID initial_display = 0;
  319. {
  320. NSScreen *mainScreen = [NSScreen mainScreen];
  321. if (mainScreen) {
  322. NSNumber *screen_num = mainScreen.deviceDescription[@"NSScreenNumber"];
  323. if (screen_num) {
  324. initial_display = (CGDirectDisplayID) (uintptr_t) screen_num.pointerValue;
  325. }
  326. }
  327. }
  328. CFUUIDRef display_uuid = CGDisplayCreateUUIDFromDisplayID(initial_display);
  329. CFStringRef uuid_string = CFUUIDCreateString(kCFAllocatorDefault, display_uuid);
  330. obs_data_set_default_string(settings, "display_uuid", CFStringGetCStringPtr(uuid_string, kCFStringEncodingUTF8));
  331. CFRelease(uuid_string);
  332. CFRelease(display_uuid);
  333. obs_data_set_default_obj(settings, "application", NULL);
  334. obs_data_set_default_int(settings, "type", ScreenCaptureDisplayStream);
  335. obs_data_set_default_int(settings, "window", kCGNullWindowID);
  336. obs_data_set_default_bool(settings, "show_cursor", true);
  337. obs_data_set_default_bool(settings, "hide_obs", false);
  338. obs_data_set_default_bool(settings, "show_empty_names", false);
  339. obs_data_set_default_bool(settings, "show_hidden_windows", false);
  340. }
  341. static void sck_video_capture_update(void *data, obs_data_t *settings)
  342. {
  343. struct screen_capture *sc = data;
  344. CGWindowID old_window_id = sc->window;
  345. CGWindowID new_window_id = (CGWindowID) obs_data_get_int(settings, "window");
  346. if (new_window_id > 0 && new_window_id != old_window_id)
  347. sc->window = new_window_id;
  348. ScreenCaptureStreamType capture_type = (ScreenCaptureStreamType) obs_data_get_int(settings, "type");
  349. CFStringRef uuid_string = CFStringCreateWithCString(
  350. kCFAllocatorDefault, obs_data_get_string(settings, "display_uuid"), kCFStringEncodingUTF8);
  351. CFUUIDRef display_uuid = CFUUIDCreateFromString(kCFAllocatorDefault, uuid_string);
  352. CGDirectDisplayID display = CGDisplayGetDisplayIDFromUUID(display_uuid);
  353. CFRelease(uuid_string);
  354. CFRelease(display_uuid);
  355. NSString *application_id = [[NSString alloc] initWithUTF8String:obs_data_get_string(settings, "application")];
  356. bool show_cursor = obs_data_get_bool(settings, "show_cursor");
  357. bool hide_obs = obs_data_get_bool(settings, "hide_obs");
  358. bool show_empty_names = obs_data_get_bool(settings, "show_empty_names");
  359. bool show_hidden_windows = obs_data_get_bool(settings, "show_hidden_windows");
  360. if (capture_type == sc->capture_type) {
  361. switch (sc->capture_type) {
  362. case ScreenCaptureDisplayStream: {
  363. if (sc->display == display && sc->hide_cursor != show_cursor && sc->hide_obs == hide_obs) {
  364. [application_id release];
  365. return;
  366. }
  367. } break;
  368. case ScreenCaptureWindowStream: {
  369. if (old_window_id == sc->window && sc->hide_cursor != show_cursor) {
  370. [application_id release];
  371. return;
  372. }
  373. } break;
  374. case ScreenCaptureApplicationStream: {
  375. if (sc->display == display && [application_id isEqualToString:sc->application_id] &&
  376. sc->hide_cursor != show_cursor) {
  377. [application_id release];
  378. return;
  379. }
  380. } break;
  381. }
  382. }
  383. obs_enter_graphics();
  384. destroy_screen_stream(sc);
  385. sc->capture_type = capture_type;
  386. sc->display = display;
  387. [sc->application_id release];
  388. sc->application_id = application_id;
  389. sc->hide_cursor = !show_cursor;
  390. sc->hide_obs = hide_obs;
  391. sc->show_empty_names = show_empty_names;
  392. sc->show_hidden_windows = show_hidden_windows;
  393. init_screen_stream(sc);
  394. obs_leave_graphics();
  395. }
  396. #pragma mark - obs_properties
  397. static bool content_settings_changed(void *data, obs_properties_t *props, obs_property_t *list __unused,
  398. obs_data_t *settings)
  399. {
  400. struct screen_capture *sc = data;
  401. unsigned int capture_type_id = (unsigned int) obs_data_get_int(settings, "type");
  402. obs_property_t *display_list = obs_properties_get(props, "display_uuid");
  403. obs_property_t *window_list = obs_properties_get(props, "window");
  404. obs_property_t *app_list = obs_properties_get(props, "application");
  405. obs_property_t *empty = obs_properties_get(props, "show_empty_names");
  406. obs_property_t *hidden = obs_properties_get(props, "show_hidden_windows");
  407. obs_property_t *hide_obs = obs_properties_get(props, "hide_obs");
  408. obs_property_t *capture_type_error = obs_properties_get(props, "capture_type_info");
  409. if (sc->capture_type != capture_type_id) {
  410. switch (capture_type_id) {
  411. case 0: {
  412. obs_property_set_visible(display_list, true);
  413. obs_property_set_visible(window_list, false);
  414. obs_property_set_visible(app_list, false);
  415. obs_property_set_visible(empty, false);
  416. obs_property_set_visible(hidden, false);
  417. obs_property_set_visible(hide_obs, true);
  418. if (capture_type_error) {
  419. obs_property_set_visible(capture_type_error, true);
  420. }
  421. break;
  422. }
  423. case 1: {
  424. obs_property_set_visible(display_list, false);
  425. obs_property_set_visible(window_list, true);
  426. obs_property_set_visible(app_list, false);
  427. obs_property_set_visible(empty, true);
  428. obs_property_set_visible(hidden, true);
  429. obs_property_set_visible(hide_obs, false);
  430. if (capture_type_error) {
  431. obs_property_set_visible(capture_type_error, false);
  432. }
  433. break;
  434. }
  435. case 2: {
  436. obs_property_set_visible(display_list, true);
  437. obs_property_set_visible(app_list, true);
  438. obs_property_set_visible(window_list, false);
  439. obs_property_set_visible(empty, false);
  440. obs_property_set_visible(hidden, true);
  441. obs_property_set_visible(hide_obs, false);
  442. if (capture_type_error) {
  443. obs_property_set_visible(capture_type_error, true);
  444. }
  445. break;
  446. }
  447. }
  448. }
  449. sc->show_empty_names = obs_data_get_bool(settings, "show_empty_names");
  450. sc->show_hidden_windows = obs_data_get_bool(settings, "show_hidden_windows");
  451. sc->hide_obs = obs_data_get_bool(settings, "hide_obs");
  452. screen_capture_build_content_list(sc, capture_type_id == ScreenCaptureDisplayStream);
  453. build_display_list(sc, props);
  454. build_window_list(sc, props);
  455. build_application_list(sc, props);
  456. return true;
  457. }
  458. static obs_properties_t *sck_video_capture_properties(void *data)
  459. {
  460. struct screen_capture *sc = data;
  461. obs_properties_t *props = obs_properties_create();
  462. obs_property_t *capture_type = obs_properties_add_list(props, "type", obs_module_text("SCK.Method"),
  463. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  464. obs_property_list_add_int(capture_type, obs_module_text("DisplayCapture"), 0);
  465. obs_property_list_add_int(capture_type, obs_module_text("WindowCapture"), 1);
  466. obs_property_list_add_int(capture_type, obs_module_text("ApplicationCapture"), 2);
  467. obs_property_t *display_list = obs_properties_add_list(
  468. props, "display_uuid", obs_module_text("DisplayCapture.Display"), OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
  469. obs_property_t *app_list = obs_properties_add_list(props, "application", obs_module_text("Application"),
  470. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_STRING);
  471. obs_property_t *window_list = obs_properties_add_list(props, "window", obs_module_text("WindowUtils.Window"),
  472. OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT);
  473. obs_property_t *empty =
  474. obs_properties_add_bool(props, "show_empty_names", obs_module_text("WindowUtils.ShowEmptyNames"));
  475. obs_property_t *hidden =
  476. obs_properties_add_bool(props, "show_hidden_windows", obs_module_text("WindowUtils.ShowHidden"));
  477. obs_properties_add_bool(props, "show_cursor", obs_module_text("DisplayCapture.ShowCursor"));
  478. obs_property_t *hide_obs = obs_properties_add_bool(props, "hide_obs", obs_module_text("DisplayCapture.HideOBS"));
  479. if (sc) {
  480. obs_property_set_modified_callback2(capture_type, content_settings_changed, sc);
  481. obs_property_set_modified_callback2(hidden, content_settings_changed, sc);
  482. switch (sc->capture_type) {
  483. case 0: {
  484. obs_property_set_visible(display_list, true);
  485. obs_property_set_visible(window_list, false);
  486. obs_property_set_visible(app_list, false);
  487. obs_property_set_visible(empty, false);
  488. obs_property_set_visible(hidden, false);
  489. obs_property_set_visible(hide_obs, true);
  490. break;
  491. }
  492. case 1: {
  493. obs_property_set_visible(display_list, false);
  494. obs_property_set_visible(window_list, true);
  495. obs_property_set_visible(app_list, false);
  496. obs_property_set_visible(empty, true);
  497. obs_property_set_visible(hidden, true);
  498. obs_property_set_visible(hide_obs, false);
  499. break;
  500. }
  501. case 2: {
  502. obs_property_set_visible(display_list, true);
  503. obs_property_set_visible(app_list, true);
  504. obs_property_set_visible(window_list, false);
  505. obs_property_set_visible(empty, false);
  506. obs_property_set_visible(hidden, true);
  507. obs_property_set_visible(hide_obs, false);
  508. break;
  509. }
  510. }
  511. obs_property_set_modified_callback2(empty, content_settings_changed, sc);
  512. }
  513. if (@available(macOS 13.0, *))
  514. ;
  515. else {
  516. obs_property_t *audio_warning =
  517. obs_properties_add_text(props, "audio_info", obs_module_text("SCK.AudioUnavailable"), OBS_TEXT_INFO);
  518. obs_property_text_set_info_type(audio_warning, OBS_TEXT_INFO_WARNING);
  519. obs_property_t *capture_type_error = obs_properties_add_text(
  520. props, "capture_type_info", obs_module_text("SCK.CaptureTypeUnavailable"), OBS_TEXT_INFO);
  521. obs_property_text_set_info_type(capture_type_error, OBS_TEXT_INFO_ERROR);
  522. if (sc) {
  523. switch (sc->capture_type) {
  524. case ScreenCaptureDisplayStream: {
  525. obs_property_set_visible(capture_type_error, true);
  526. break;
  527. }
  528. case ScreenCaptureWindowStream: {
  529. obs_property_set_visible(capture_type_error, false);
  530. break;
  531. }
  532. case ScreenCaptureApplicationStream: {
  533. obs_property_set_visible(capture_type_error, true);
  534. break;
  535. }
  536. }
  537. } else {
  538. obs_property_set_visible(capture_type_error, false);
  539. }
  540. }
  541. return props;
  542. }
  543. enum gs_color_space sck_video_capture_get_color_space(void *data, size_t count,
  544. const enum gs_color_space *preferred_spaces)
  545. {
  546. UNUSED_PARAMETER(data);
  547. for (size_t i = 0; i < count; ++i) {
  548. if (preferred_spaces[i] == GS_CS_SRGB_16F)
  549. return GS_CS_SRGB_16F;
  550. }
  551. for (size_t i = 0; i < count; ++i) {
  552. if (preferred_spaces[i] == GS_CS_709_EXTENDED)
  553. return GS_CS_709_EXTENDED;
  554. }
  555. for (size_t i = 0; i < count; ++i) {
  556. if (preferred_spaces[i] == GS_CS_SRGB)
  557. return GS_CS_SRGB;
  558. }
  559. return GS_CS_SRGB_16F;
  560. }
  561. #pragma mark - obs_source_info
  562. struct obs_source_info sck_video_capture_info = {
  563. .id = "screen_capture",
  564. .type = OBS_SOURCE_TYPE_INPUT,
  565. .get_name = sck_video_capture_getname,
  566. .create = sck_video_capture_create,
  567. .destroy = sck_video_capture_destroy,
  568. .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW | OBS_SOURCE_DO_NOT_DUPLICATE | OBS_SOURCE_SRGB |
  569. OBS_SOURCE_AUDIO,
  570. .video_tick = sck_video_capture_tick,
  571. .video_render = sck_video_capture_render,
  572. .get_width = sck_video_capture_getwidth,
  573. .get_height = sck_video_capture_getheight,
  574. .get_defaults = sck_video_capture_defaults,
  575. .get_properties = sck_video_capture_properties,
  576. .update = sck_video_capture_update,
  577. .icon_type = OBS_ICON_TYPE_DESKTOP_CAPTURE,
  578. .video_get_color_space = sck_video_capture_get_color_space,
  579. };