mac-sck-common.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. @interface ScreenCaptureDelegate : NSObject <SCStreamOutput, SCStreamDelegate>
  25. @property struct screen_capture *sc;
  26. @end
  27. struct screen_capture {
  28. obs_source_t *source;
  29. gs_effect_t *effect;
  30. gs_texture_t *tex;
  31. NSRect frame;
  32. bool hide_cursor;
  33. bool hide_obs;
  34. bool show_hidden_windows;
  35. bool show_empty_names;
  36. bool audio_only;
  37. SCStream *disp;
  38. SCStreamConfiguration *stream_properties;
  39. SCShareableContent *shareable_content;
  40. ScreenCaptureDelegate *capture_delegate;
  41. os_event_t *disp_finished;
  42. os_event_t *stream_start_completed;
  43. os_sem_t *shareable_content_available;
  44. IOSurfaceRef current, prev;
  45. bool capture_failed;
  46. pthread_mutex_t mutex;
  47. ScreenCaptureStreamType capture_type;
  48. ScreenCaptureAudioStreamType audio_capture_type;
  49. CGDirectDisplayID display;
  50. CGWindowID window;
  51. NSString *application_id;
  52. };
  53. bool is_screen_capture_available(void);
  54. void screen_capture_build_content_list(struct screen_capture *sc, bool display_capture);
  55. bool build_display_list(struct screen_capture *sc, obs_properties_t *props);
  56. bool build_window_list(struct screen_capture *sc, obs_properties_t *props);
  57. bool build_application_list(struct screen_capture *sc, obs_properties_t *props);
  58. static const char *screen_capture_getname(void *unused __unused);
  59. void screen_stream_video_update(struct screen_capture *sc, CMSampleBufferRef sample_buffer);
  60. void screen_stream_audio_update(struct screen_capture *sc, CMSampleBufferRef sample_buffer);
  61. #pragma clang diagnostic pop