mac-sck-common.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include <AvailabilityMacros.h>
  2. #include <Cocoa/Cocoa.h>
  3. #pragma clang diagnostic push
  4. #pragma clang diagnostic ignored "-Wunguarded-availability-new"
  5. #include <stdlib.h>
  6. #include <obs-module.h>
  7. #include <util/threading.h>
  8. #include <pthread.h>
  9. #include <IOSurface/IOSurface.h>
  10. #include <ScreenCaptureKit/ScreenCaptureKit.h>
  11. #include <CoreMedia/CMSampleBuffer.h>
  12. #include <CoreVideo/CVPixelBuffer.h>
  13. #define MACCAP_LOG(level, msg, ...) blog(level, "[ mac-screencapture ]: " msg, ##__VA_ARGS__)
  14. #define MACCAP_ERR(msg, ...) MACCAP_LOG(LOG_ERROR, msg, ##__VA_ARGS__)
  15. typedef enum {
  16. ScreenCaptureDisplayStream = 0,
  17. ScreenCaptureWindowStream = 1,
  18. ScreenCaptureApplicationStream = 2,
  19. } ScreenCaptureStreamType;
  20. typedef enum {
  21. ScreenCaptureAudioDesktopStream = 0,
  22. ScreenCaptureAudioApplicationStream = 1,
  23. } ScreenCaptureAudioStreamType;
  24. typedef SCDisplay *SCDisplayRef;
  25. @interface ScreenCaptureDelegate : NSObject <SCStreamOutput, SCStreamDelegate>
  26. @property struct screen_capture *sc;
  27. @end
  28. struct screen_capture {
  29. obs_source_t *source;
  30. gs_effect_t *effect;
  31. gs_texture_t *tex;
  32. NSRect frame;
  33. bool hide_cursor;
  34. bool hide_obs;
  35. bool show_hidden_windows;
  36. bool show_empty_names;
  37. bool audio_only;
  38. SCStream *disp;
  39. SCStreamConfiguration *stream_properties;
  40. SCShareableContent *shareable_content;
  41. ScreenCaptureDelegate *capture_delegate;
  42. os_event_t *disp_finished;
  43. os_event_t *stream_start_completed;
  44. os_sem_t *shareable_content_available;
  45. IOSurfaceRef current, prev;
  46. bool capture_failed;
  47. pthread_mutex_t mutex;
  48. ScreenCaptureStreamType capture_type;
  49. ScreenCaptureAudioStreamType audio_capture_type;
  50. CGDirectDisplayID display;
  51. CGWindowID window;
  52. NSString *application_id;
  53. };
  54. bool is_screen_capture_available(void);
  55. void screen_capture_build_content_list(struct screen_capture *sc, bool display_capture);
  56. bool build_display_list(struct screen_capture *sc, obs_properties_t *props);
  57. bool build_window_list(struct screen_capture *sc, obs_properties_t *props);
  58. bool build_application_list(struct screen_capture *sc, obs_properties_t *props);
  59. static const char *screen_capture_getname(void *unused __unused);
  60. void screen_stream_video_update(struct screen_capture *sc, CMSampleBufferRef sample_buffer);
  61. void screen_stream_audio_update(struct screen_capture *sc, CMSampleBufferRef sample_buffer);
  62. #pragma clang diagnostic pop