mac-sck-video-capture.m 26 KB

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