mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-20 15:51:07 +01:00
Introduce enum for SDL_GetCameraPermissionState result
This commit is contained in:
committed by
Ryan C. Gordon
parent
5be08481e1
commit
385715c0dd
@@ -136,6 +136,20 @@ typedef enum SDL_CameraPosition
|
||||
SDL_CAMERA_POSITION_BACK_FACING
|
||||
} SDL_CameraPosition;
|
||||
|
||||
/**
|
||||
* The current state of a request for camera access.
|
||||
*
|
||||
* \since This enum is available since SDL 3.4.0.
|
||||
*
|
||||
* \sa SDL_GetCameraPermissionState
|
||||
*/
|
||||
typedef enum SDL_CameraPermissionState
|
||||
{
|
||||
SDL_CAMERA_PERMISSION_STATE_DENIED = -1,
|
||||
SDL_CAMERA_PERMISSION_STATE_PENDING,
|
||||
SDL_CAMERA_PERMISSION_STATE_APPROVED,
|
||||
} SDL_CameraPermissionState;
|
||||
|
||||
|
||||
/**
|
||||
* Use this function to get the number of built-in camera drivers.
|
||||
@@ -368,7 +382,7 @@ extern SDL_DECLSPEC SDL_Camera * SDLCALL SDL_OpenCamera(SDL_CameraID instance_id
|
||||
* \sa SDL_OpenCamera
|
||||
* \sa SDL_CloseCamera
|
||||
*/
|
||||
extern SDL_DECLSPEC int SDLCALL SDL_GetCameraPermissionState(SDL_Camera *camera);
|
||||
extern SDL_DECLSPEC SDL_CameraPermissionState SDLCALL SDL_GetCameraPermissionState(SDL_Camera *camera);
|
||||
|
||||
/**
|
||||
* Get the instance ID of an opened camera.
|
||||
|
||||
@@ -270,7 +270,7 @@ static void ClosePhysicalCamera(SDL_Camera *device)
|
||||
|
||||
SDL_aligned_free(device->zombie_pixels);
|
||||
|
||||
device->permission = 0;
|
||||
device->permission = SDL_CAMERA_PERMISSION_STATE_PENDING;
|
||||
device->zombie_pixels = NULL;
|
||||
device->filled_output_surfaces.next = NULL;
|
||||
device->empty_output_surfaces.next = NULL;
|
||||
@@ -581,7 +581,7 @@ void SDL_CameraPermissionOutcome(SDL_Camera *device, bool approved)
|
||||
pending.next = NULL;
|
||||
SDL_PendingCameraEvent *pending_tail = &pending;
|
||||
|
||||
const int permission = approved ? 1 : -1;
|
||||
const SDL_CameraPermissionState permission = approved ? SDL_CAMERA_PERMISSION_STATE_APPROVED : SDL_CAMERA_PERMISSION_STATE_DENIED;
|
||||
|
||||
ObtainPhysicalCameraObj(device);
|
||||
if (device->permission != permission) {
|
||||
@@ -665,7 +665,7 @@ bool SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec)
|
||||
|
||||
SDL_Camera *device = camera; // currently there's no separation between physical and logical device.
|
||||
ObtainPhysicalCameraObj(device);
|
||||
if (device->permission > 0) {
|
||||
if (device->permission > SDL_CAMERA_PERMISSION_STATE_PENDING) {
|
||||
SDL_copyp(spec, &device->spec);
|
||||
result = true;
|
||||
} else {
|
||||
@@ -808,9 +808,9 @@ bool SDL_CameraThreadIterate(SDL_Camera *device)
|
||||
}
|
||||
|
||||
const int permission = device->permission;
|
||||
if (permission <= 0) {
|
||||
if (permission <= SDL_CAMERA_PERMISSION_STATE_PENDING) {
|
||||
SDL_UnlockMutex(device->lock);
|
||||
return (permission < 0) ? false : true; // if permission was denied, shut it down. if undecided, we're done for now.
|
||||
return (permission < SDL_CAMERA_PERMISSION_STATE_PENDING) ? false : true; // if permission was denied, shut it down. if undecided, we're done for now.
|
||||
}
|
||||
|
||||
bool failed = false; // set to true if disaster worthy of treating the device as lost has happened.
|
||||
@@ -1264,7 +1264,7 @@ SDL_Surface *SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS)
|
||||
|
||||
ObtainPhysicalCameraObj(device);
|
||||
|
||||
if (device->permission <= 0) {
|
||||
if (device->permission <= SDL_CAMERA_PERMISSION_STATE_PENDING) {
|
||||
ReleaseCamera(device);
|
||||
SDL_SetError("Camera permission has not been granted");
|
||||
return NULL;
|
||||
@@ -1371,12 +1371,12 @@ SDL_PropertiesID SDL_GetCameraProperties(SDL_Camera *camera)
|
||||
return result;
|
||||
}
|
||||
|
||||
int SDL_GetCameraPermissionState(SDL_Camera *camera)
|
||||
SDL_CameraPermissionState SDL_GetCameraPermissionState(SDL_Camera *camera)
|
||||
{
|
||||
int result;
|
||||
SDL_CameraPermissionState result;
|
||||
if (!camera) {
|
||||
SDL_InvalidParamError("camera");
|
||||
result = -1;
|
||||
result = SDL_CAMERA_PERMISSION_STATE_DENIED;
|
||||
} else {
|
||||
SDL_Camera *device = camera; // currently there's no separation between physical and logical device.
|
||||
ObtainPhysicalCameraObj(device);
|
||||
|
||||
@@ -160,8 +160,8 @@ struct SDL_Camera
|
||||
// Optional properties.
|
||||
SDL_PropertiesID props;
|
||||
|
||||
// -1: user denied permission, 0: waiting for user response, 1: user approved permission.
|
||||
int permission;
|
||||
// Current state of user permission check.
|
||||
SDL_CameraPermissionState permission;
|
||||
|
||||
// Data private to this driver, used when device is opened and running.
|
||||
struct SDL_PrivateCameraData *hidden;
|
||||
|
||||
@@ -85,7 +85,7 @@ static void CoreMediaFormatToSDL(FourCharCode fmt, SDL_PixelFormat *pixel_format
|
||||
|
||||
static bool CheckCameraPermissions(SDL_Camera *device)
|
||||
{
|
||||
if (device->permission == 0) { // still expecting a permission result.
|
||||
if (device->permission == SDL_CAMERA_PERMISSION_STATE_PENDING) { // still expecting a permission result.
|
||||
if (@available(macOS 14, *)) {
|
||||
const AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
||||
if (status != AVAuthorizationStatusNotDetermined) { // NotDetermined == still waiting for an answer from the user.
|
||||
@@ -96,7 +96,7 @@ static bool CheckCameraPermissions(SDL_Camera *device)
|
||||
}
|
||||
}
|
||||
|
||||
return (device->permission > 0);
|
||||
return (device->permission > SDL_CAMERA_PERMISSION_STATE_PENDING);
|
||||
}
|
||||
|
||||
// this delegate just receives new video frames on a Grand Central Dispatch queue, and fires off the
|
||||
|
||||
@@ -288,7 +288,7 @@ SDL_DYNAPI_PROC(const char*,SDL_GetCameraDriver,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_GetCameraFormat,(SDL_Camera *a, SDL_CameraSpec *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(SDL_CameraID,SDL_GetCameraID,(SDL_Camera *a),(a),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetCameraName,(SDL_CameraID a),(a),return)
|
||||
SDL_DYNAPI_PROC(int,SDL_GetCameraPermissionState,(SDL_Camera *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_CameraPermissionState,SDL_GetCameraPermissionState,(SDL_Camera *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_CameraPosition,SDL_GetCameraPosition,(SDL_CameraID a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetCameraProperties,(SDL_Camera *a),(a),return)
|
||||
SDL_DYNAPI_PROC(SDL_CameraSpec**,SDL_GetCameraSupportedFormats,(SDL_CameraID a, int *b),(a,b),return)
|
||||
|
||||
Reference in New Issue
Block a user