123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //==============================================================================
- //
- // ReplayKit Unity Interface
- #import "UnityReplayKit.h"
- extern "C"
- {
- #if UNITY_REPLAY_KIT_AVAILABLE
- int UnityReplayKitAPIAvailable()
- {
- return [UnityReplayKit sharedInstance].apiAvailable ? 1 : 0;
- }
- int UnityReplayKitRecordingAvailable()
- {
- return [UnityReplayKit sharedInstance].recordingPreviewAvailable ? 1 : 0;
- }
- int UnityReplayKitIsCameraEnabled()
- {
- return [UnityReplayKit sharedInstance].cameraEnabled != NO ? 1 : 0;
- }
- int UnityReplayKitSetCameraEnabled(bool yes)
- {
- BOOL value = yes ? YES : NO;
- [UnityReplayKit sharedInstance].cameraEnabled = value;
- return [UnityReplayKit sharedInstance].cameraEnabled == value;
- }
- int UnityReplayKitIsMicrophoneEnabled()
- {
- return [UnityReplayKit sharedInstance].microphoneEnabled != NO ? 1 : 0;
- }
- int UnityReplayKitSetMicrophoneEnabled(bool yes)
- {
- BOOL value = yes ? YES : NO;
- [UnityReplayKit sharedInstance].microphoneEnabled = value;
- return [UnityReplayKit sharedInstance].microphoneEnabled == value;
- }
- const char* UnityReplayKitLastError()
- {
- NSString* err = [UnityReplayKit sharedInstance].lastError;
- if (err == nil)
- {
- return NULL;
- }
- const char* error = [err cStringUsingEncoding: NSUTF8StringEncoding];
- if (error != NULL)
- {
- error = strdup(error);
- }
- return error;
- }
- int UnityReplayKitStartRecording(int enableMicrophone)
- {
- bool enableMic = enableMicrophone != 0;
- return [[UnityReplayKit sharedInstance] startRecording: enableMic] ? 1 : 0;
- }
- int UnityReplayKitIsRecording()
- {
- return [UnityReplayKit sharedInstance].isRecording ? 1 : 0;
- }
- int UnityReplayKitShowCameraPreviewAt(float x, float y)
- {
- float q = 1.0f / UnityScreenScaleFactor([UIScreen mainScreen]);
- float h = [[UIScreen mainScreen] bounds].size.height;
- return [[UnityReplayKit sharedInstance] showCameraPreviewAt: CGPointMake(x * q, h - y * q)] ? 1 : 0;
- }
- void UnityReplayKitHideCameraPreview()
- {
- [[UnityReplayKit sharedInstance] hideCameraPreview];
- }
- int UnityReplayKitStopRecording()
- {
- #if !PLATFORM_TVOS
- UnityReplayKitHideCameraPreview();
- UnityReplayKitSetCameraEnabled(false);
- #endif
- return [[UnityReplayKit sharedInstance] stopRecording] ? 1 : 0;
- }
- int UnityReplayKitDiscard()
- {
- return [[UnityReplayKit sharedInstance] discardPreview] ? 1 : 0;
- }
- int UnityReplayKitPreview()
- {
- return [[UnityReplayKit sharedInstance] showPreview] ? 1 : 0;
- }
- int UnityReplayKitBroadcastingAPIAvailable()
- {
- return [[UnityReplayKit sharedInstance] broadcastingApiAvailable] ? 1 : 0;
- }
- void UnityReplayKitStartBroadcasting(void* callback)
- {
- [[UnityReplayKit sharedInstance] startBroadcastingWithCallback: callback];
- }
- void UnityReplayKitStopBroadcasting()
- {
- #if !PLATFORM_TVOS
- UnityReplayKitHideCameraPreview();
- #endif
- [[UnityReplayKit sharedInstance] stopBroadcasting];
- }
- int UnityReplayKitIsBroadcasting()
- {
- return [[UnityReplayKit sharedInstance] isBroadcasting] ? 1 : 0;
- }
- const char* UnityReplayKitGetBroadcastURL()
- {
- NSURL *url = [[UnityReplayKit sharedInstance] broadcastURL];
- if (url != nil)
- {
- return [[url absoluteString] UTF8String];
- }
- return nullptr;
- }
- extern "C" float UnityScreenScaleFactor(UIScreen* screen);
- #else
- // Impl when ReplayKit is not available.
- int UnityReplayKitAPIAvailable() { return 0; }
- int UnityReplayKitRecordingAvailable() { return 0; }
- const char* UnityReplayKitLastError() { return NULL; }
- int UnityReplayKitStartRecording(int enableMicrophone) { return 0; }
- int UnityReplayKitIsRecording() { return 0; }
- int UnityReplayKitStopRecording() { return 0; }
- int UnityReplayKitDiscard() { return 0; }
- int UnityReplayKitPreview() { return 0; }
- int UnityReplayKitIsCameraEnabled() { return 0; }
- int UnityReplayKitSetCameraEnabled(bool) { return 0; }
- int UnityReplayKitIsMicrophoneEnabled() { return 0; }
- int UnityReplayKitSetMicrophoneEnabled(bool) { return 0; }
- int UnityReplayKitShowCameraPreviewAt(float x, float y) { return 0; }
- void UnityReplayKitHideCameraPreview() {}
- void UnityReplayKitTriggerBroadcastStatusCallback(void*, bool, const char*);
- int UnityReplayKitBroadcastingAPIAvailable() { return 0; }
- void UnityReplayKitStartBroadcasting(void* callback) { UnityReplayKitTriggerBroadcastStatusCallback(callback, false, "ReplayKit not implemented."); }
- void UnityReplayKitStopBroadcasting() {}
- int UnityReplayKitIsBroadcasting() { return 0; }
- const char* UnityReplayKitGetBroadcastURL() { return nullptr; }
- #endif // UNITY_REPLAY_KIT_AVAILABLE
- } // extern "C"
|