Renamed CameraDevice to Camera

This is consistent with the rest of the SDL API
This commit is contained in:
Sam Lantinga
2024-07-14 12:22:42 -07:00
parent 9358333286
commit 9797c5d0c0
15 changed files with 284 additions and 284 deletions
+20 -20
View File
@@ -53,9 +53,9 @@ extern "C" {
*
* \since This datatype is available since SDL 3.0.0.
*
* \sa SDL_GetCameraDevices
* \sa SDL_GetCameras
*/
typedef Uint32 SDL_CameraDeviceID;
typedef Uint32 SDL_CameraID;
/**
* The opaque structure used to identify an opened SDL camera.
@@ -72,7 +72,7 @@ typedef struct SDL_Camera SDL_Camera;
*
* \since This struct is available since SDL 3.0.0.
*
* \sa SDL_GetCameraDeviceSupportedFormats
* \sa SDL_GetCameraSupportedFormats
* \sa SDL_GetCameraFormat
*/
typedef struct SDL_CameraSpec
@@ -90,7 +90,7 @@ typedef struct SDL_CameraSpec
*
* \since This enum is available since SDL 3.0.0.
*
* \sa SDL_GetCameraDevicePosition
* \sa SDL_GetCameraPosition
*/
typedef enum SDL_CameraPosition
{
@@ -182,7 +182,7 @@ extern SDL_DECLSPEC const char *SDLCALL SDL_GetCurrentCameraDriver(void);
*
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC SDL_CameraDeviceID *SDLCALL SDL_GetCameraDevices(int *count);
extern SDL_DECLSPEC SDL_CameraID *SDLCALL SDL_GetCameras(int *count);
/**
* Get the list of native formats/sizes a camera supports.
@@ -192,7 +192,7 @@ extern SDL_DECLSPEC SDL_CameraDeviceID *SDLCALL SDL_GetCameraDevices(int *count)
* and sizes and so want to find the optimal spec that doesn't require
* conversion.
*
* This function isn't strictly required; if you call SDL_OpenCameraDevice
* This function isn't strictly required; if you call SDL_OpenCamera
* with a NULL spec, SDL will choose a native format for you, and if you
* instead specify a desired format, it will transparently convert to the
* requested format on your behalf.
@@ -222,10 +222,10 @@ extern SDL_DECLSPEC SDL_CameraDeviceID *SDLCALL SDL_GetCameraDevices(int *count)
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetCameraDevices
* \sa SDL_OpenCameraDevice
* \sa SDL_GetCameras
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC SDL_CameraSpec *SDLCALL SDL_GetCameraDeviceSupportedFormats(SDL_CameraDeviceID devid, int *count);
extern SDL_DECLSPEC SDL_CameraSpec *SDLCALL SDL_GetCameraSupportedFormats(SDL_CameraID devid, int *count);
/**
* Get the human-readable device name for a camera.
@@ -240,9 +240,9 @@ extern SDL_DECLSPEC SDL_CameraSpec *SDLCALL SDL_GetCameraDeviceSupportedFormats(
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetCameraDevices
* \sa SDL_GetCameras
*/
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraName(SDL_CameraID instance_id);
/**
* Get the position of the camera in relation to the system.
@@ -259,9 +259,9 @@ extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraDeviceName(SDL_CameraDevic
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetCameraDevices
* \sa SDL_GetCameras
*/
extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraDevicePosition(SDL_CameraDeviceID instance_id);
extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraPosition(SDL_CameraID instance_id);
/**
* Open a video recording device (a "camera").
@@ -304,10 +304,10 @@ extern SDL_DECLSPEC SDL_CameraPosition SDLCALL SDL_GetCameraDevicePosition(SDL_C
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetCameraDevices
* \sa SDL_GetCameras
* \sa SDL_GetCameraFormat
*/
extern SDL_DECLSPEC SDL_Camera *SDLCALL SDL_OpenCameraDevice(SDL_CameraDeviceID instance_id, const SDL_CameraSpec *spec);
extern SDL_DECLSPEC SDL_Camera *SDLCALL SDL_OpenCamera(SDL_CameraID instance_id, const SDL_CameraSpec *spec);
/**
* Query if camera access has been approved by the user.
@@ -337,7 +337,7 @@ extern SDL_DECLSPEC SDL_Camera *SDLCALL SDL_OpenCameraDevice(SDL_CameraDeviceID
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_OpenCameraDevice
* \sa SDL_OpenCamera
* \sa SDL_CloseCamera
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetCameraPermissionState(SDL_Camera *camera);
@@ -353,14 +353,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetCameraPermissionState(SDL_Camera *camera)
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_OpenCameraDevice
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC SDL_CameraDeviceID SDLCALL SDL_GetCameraInstanceID(SDL_Camera *camera);
extern SDL_DECLSPEC SDL_CameraID SDLCALL SDL_GetCameraID(SDL_Camera *camera);
/**
* Get the properties associated with an opened camera.
*
* \param camera the SDL_Camera obtained from SDL_OpenCameraDevice().
* \param camera the SDL_Camera obtained from SDL_OpenCamera().
* \returns a valid property ID on success or 0 on failure; call
* SDL_GetError() for more information.
*
@@ -391,7 +391,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetCameraProperties(SDL_Camera
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_OpenCameraDevice
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC int SDLCALL SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec);
+1 -1
View File
@@ -695,7 +695,7 @@ typedef struct SDL_CameraDeviceEvent
SDL_EventType type; /**< SDL_EVENT_CAMERA_DEVICE_ADDED, SDL_EVENT_CAMERA_DEVICE_REMOVED, SDL_EVENT_CAMERA_DEVICE_APPROVED, SDL_EVENT_CAMERA_DEVICE_DENIED */
Uint32 reserved;
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
SDL_CameraDeviceID which; /**< SDL_CameraDeviceID for the device being added or removed or changing */
SDL_CameraID which; /**< SDL_CameraID for the device being added or removed or changing */
} SDL_CameraDeviceEvent;
/**
+105 -105
View File
File diff suppressed because it is too large Load Diff
+29 -29
View File
@@ -27,34 +27,34 @@
#define DEBUG_CAMERA 0
typedef struct SDL_CameraDevice SDL_CameraDevice;
typedef struct SDL_Camera SDL_Camera;
/* Backends should call this as devices are added to the system (such as
a USB camera being plugged in), and should also be called for
for every device found during DetectDevices(). */
extern SDL_CameraDevice *SDL_AddCameraDevice(const char *name, SDL_CameraPosition position, int num_specs, const SDL_CameraSpec *specs, void *handle);
extern SDL_Camera *SDL_AddCamera(const char *name, SDL_CameraPosition position, int num_specs, const SDL_CameraSpec *specs, void *handle);
/* Backends should call this if an opened camera device is lost.
This can happen due to i/o errors, or a device being unplugged, etc. */
extern void SDL_CameraDeviceDisconnected(SDL_CameraDevice *device);
extern void SDL_CameraDisconnected(SDL_Camera *device);
// Find an SDL_CameraDevice, selected by a callback. NULL if not found. DOES NOT LOCK THE DEVICE.
extern SDL_CameraDevice *SDL_FindPhysicalCameraDeviceByCallback(SDL_bool (*callback)(SDL_CameraDevice *device, void *userdata), void *userdata);
// Find an SDL_Camera, selected by a callback. NULL if not found. DOES NOT LOCK THE DEVICE.
extern SDL_Camera *SDL_FindPhysicalCameraByCallback(SDL_bool (*callback)(SDL_Camera *device, void *userdata), void *userdata);
// Backends should call this when the user has approved/denied access to a camera.
extern void SDL_CameraDevicePermissionOutcome(SDL_CameraDevice *device, SDL_bool approved);
extern void SDL_CameraPermissionOutcome(SDL_Camera *device, SDL_bool approved);
// Backends can call this to get a standardized name for a thread to power a specific camera device.
extern char *SDL_GetCameraThreadName(SDL_CameraDevice *device, char *buf, size_t buflen);
extern char *SDL_GetCameraThreadName(SDL_Camera *device, char *buf, size_t buflen);
// Backends can call these to change a device's refcount.
extern void RefPhysicalCameraDevice(SDL_CameraDevice *device);
extern void UnrefPhysicalCameraDevice(SDL_CameraDevice *device);
extern void RefPhysicalCamera(SDL_Camera *device);
extern void UnrefPhysicalCamera(SDL_Camera *device);
// These functions are the heart of the camera threads. Backends can call them directly if they aren't using the SDL-provided thread.
extern void SDL_CameraThreadSetup(SDL_CameraDevice *device);
extern SDL_bool SDL_CameraThreadIterate(SDL_CameraDevice *device);
extern void SDL_CameraThreadShutdown(SDL_CameraDevice *device);
extern void SDL_CameraThreadSetup(SDL_Camera *device);
extern SDL_bool SDL_CameraThreadIterate(SDL_Camera *device);
extern void SDL_CameraThreadShutdown(SDL_Camera *device);
// common utility functionality to gather up camera specs. Not required!
typedef struct CameraFormatAddData
@@ -74,7 +74,7 @@ typedef struct SurfaceList
} SurfaceList;
// Define the SDL camera driver structure
struct SDL_CameraDevice
struct SDL_Camera
{
// A mutex for locking
SDL_Mutex *lock;
@@ -89,9 +89,9 @@ struct SDL_CameraDevice
SDL_AtomicInt refcount;
// These are, initially, set from camera_driver, but we might swap them out with Zombie versions on disconnect/failure.
int (*WaitDevice)(SDL_CameraDevice *device);
int (*AcquireFrame)(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS);
void (*ReleaseFrame)(SDL_CameraDevice *device, SDL_Surface *frame);
int (*WaitDevice)(SDL_Camera *device);
int (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS);
void (*ReleaseFrame)(SDL_Camera *device, SDL_Surface *frame);
// All supported formats/dimensions for this device.
SDL_CameraSpec *all_specs;
@@ -106,7 +106,7 @@ struct SDL_CameraDevice
SDL_CameraSpec spec;
// Unique value assigned at creation time.
SDL_CameraDeviceID instance_id;
SDL_CameraID instance_id;
// Driver-specific hardware data on how to open device (`hidden` is driver-specific data _when opened_).
void *handle;
@@ -161,23 +161,23 @@ struct SDL_CameraDevice
typedef struct SDL_CameraDriverImpl
{
void (*DetectDevices)(void);
int (*OpenDevice)(SDL_CameraDevice *device, const SDL_CameraSpec *spec);
void (*CloseDevice)(SDL_CameraDevice *device);
int (*WaitDevice)(SDL_CameraDevice *device);
int (*AcquireFrame)(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS); // set frame->pixels, frame->pitch, and *timestampNS!
void (*ReleaseFrame)(SDL_CameraDevice *device, SDL_Surface *frame); // Reclaim frame->pixels and frame->pitch!
void (*FreeDeviceHandle)(SDL_CameraDevice *device); // SDL is done with this device; free the handle from SDL_AddCameraDevice()
int (*OpenDevice)(SDL_Camera *device, const SDL_CameraSpec *spec);
void (*CloseDevice)(SDL_Camera *device);
int (*WaitDevice)(SDL_Camera *device);
int (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS); // set frame->pixels, frame->pitch, and *timestampNS!
void (*ReleaseFrame)(SDL_Camera *device, SDL_Surface *frame); // Reclaim frame->pixels and frame->pitch!
void (*FreeDeviceHandle)(SDL_Camera *device); // SDL is done with this device; free the handle from SDL_AddCamera()
void (*Deinitialize)(void);
SDL_bool ProvidesOwnCallbackThread;
} SDL_CameraDriverImpl;
typedef struct SDL_PendingCameraDeviceEvent
typedef struct SDL_PendingCameraEvent
{
Uint32 type;
SDL_CameraDeviceID devid;
struct SDL_PendingCameraDeviceEvent *next;
} SDL_PendingCameraDeviceEvent;
SDL_CameraID devid;
struct SDL_PendingCameraEvent *next;
} SDL_PendingCameraEvent;
typedef struct SDL_CameraDriver
{
@@ -187,8 +187,8 @@ typedef struct SDL_CameraDriver
SDL_RWLock *device_hash_lock; // A rwlock that protects `device_hash`
SDL_HashTable *device_hash; // the collection of currently-available camera devices
SDL_PendingCameraDeviceEvent pending_events;
SDL_PendingCameraDeviceEvent *pending_events_tail;
SDL_PendingCameraEvent pending_events;
SDL_PendingCameraEvent *pending_events_tail;
SDL_AtomicInt device_count;
SDL_AtomicInt shutting_down; // non-zero during SDL_Quit, so we known not to accept any last-minute device hotplugs.
+27 -27
View File
@@ -289,12 +289,12 @@ static Uint32 format_sdl_to_android(SDL_PixelFormat fmt)
}
}
static int ANDROIDCAMERA_WaitDevice(SDL_CameraDevice *device)
static int ANDROIDCAMERA_WaitDevice(SDL_Camera *device)
{
return 0; // this isn't used atm, since we run our own thread via onImageAvailable callbacks.
}
static int ANDROIDCAMERA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS)
static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
{
int retval = 1;
media_status_t res;
@@ -358,7 +358,7 @@ static int ANDROIDCAMERA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *fra
return retval;
}
static void ANDROIDCAMERA_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
static void ANDROIDCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
{
// !!! FIXME: this currently copies the data to the surface, but in theory we could just keep the AImage until ReleaseFrame...
SDL_aligned_free(frame->pixels);
@@ -369,7 +369,7 @@ static void onImageAvailable(void *context, AImageReader *reader)
#if DEBUG_CAMERA
SDL_Log("CAMERA: CB onImageAvailable");
#endif
SDL_CameraDevice *device = (SDL_CameraDevice *) context;
SDL_Camera *device = (SDL_Camera *) context;
SDL_CameraThreadIterate(device);
}
@@ -378,7 +378,7 @@ static void onDisconnected(void *context, ACameraDevice *device)
#if DEBUG_CAMERA
SDL_Log("CAMERA: CB onDisconnected");
#endif
SDL_CameraDeviceDisconnected((SDL_CameraDevice *) context);
SDL_CameraDisconnected((SDL_Camera *) context);
}
static void onError(void *context, ACameraDevice *device, int error)
@@ -386,12 +386,12 @@ static void onError(void *context, ACameraDevice *device, int error)
#if DEBUG_CAMERA
SDL_Log("CAMERA: CB onError");
#endif
SDL_CameraDeviceDisconnected((SDL_CameraDevice *) context);
SDL_CameraDisconnected((SDL_Camera *) context);
}
static void onClosed(void* context, ACameraCaptureSession *session)
{
// SDL_CameraDevice *_this = (SDL_CameraDevice *) context;
// SDL_Camera *_this = (SDL_Camera *) context;
#if DEBUG_CAMERA
SDL_Log("CAMERA: CB onClosed");
#endif
@@ -399,7 +399,7 @@ static void onClosed(void* context, ACameraCaptureSession *session)
static void onReady(void* context, ACameraCaptureSession *session)
{
// SDL_CameraDevice *_this = (SDL_CameraDevice *) context;
// SDL_Camera *_this = (SDL_Camera *) context;
#if DEBUG_CAMERA
SDL_Log("CAMERA: CB onReady");
#endif
@@ -407,13 +407,13 @@ static void onReady(void* context, ACameraCaptureSession *session)
static void onActive(void* context, ACameraCaptureSession *session)
{
// SDL_CameraDevice *_this = (SDL_CameraDevice *) context;
// SDL_Camera *_this = (SDL_Camera *) context;
#if DEBUG_CAMERA
SDL_Log("CAMERA: CB onActive");
#endif
}
static void ANDROIDCAMERA_CloseDevice(SDL_CameraDevice *device)
static void ANDROIDCAMERA_CloseDevice(SDL_Camera *device)
{
if (device && device->hidden) {
struct SDL_PrivateCameraData *hidden = device->hidden;
@@ -458,7 +458,7 @@ static void ANDROIDCAMERA_CloseDevice(SDL_CameraDevice *device)
}
// this is where the "opening" of the camera happens, after permission is granted.
static int PrepareCamera(SDL_CameraDevice *device)
static int PrepareCamera(SDL_Camera *device)
{
SDL_assert(device->hidden != NULL);
@@ -483,7 +483,7 @@ static int PrepareCamera(SDL_CameraDevice *device)
imglistener.context = device;
imglistener.onImageAvailable = onImageAvailable;
// just in case SDL_OpenCameraDevice is overwriting device->spec as CameraPermissionCallback runs, we work from a different copy.
// just in case SDL_OpenCamera is overwriting device->spec as CameraPermissionCallback runs, we work from a different copy.
const SDL_CameraSpec *spec = &device->hidden->requested_spec;
if ((res = pACameraManager_openCamera(cameraMgr, (const char *) device->handle, &dev_callbacks, &device->hidden->device)) != ACAMERA_OK) {
@@ -517,24 +517,24 @@ static int PrepareCamera(SDL_CameraDevice *device)
static void SDLCALL CameraPermissionCallback(void *userdata, const char *permission, SDL_bool granted)
{
SDL_CameraDevice *device = (SDL_CameraDevice *) userdata;
SDL_Camera *device = (SDL_Camera *) userdata;
if (device->hidden != NULL) { // if device was already closed, don't send an event.
if (!granted) {
SDL_CameraDevicePermissionOutcome(device, SDL_FALSE); // sorry, permission denied.
SDL_CameraPermissionOutcome(device, SDL_FALSE); // sorry, permission denied.
} else if (PrepareCamera(device) < 0) { // permission given? Actually open the camera now.
// uhoh, setup failed; since the app thinks we already "opened" the device, mark it as disconnected and don't report the permission.
SDL_CameraDeviceDisconnected(device);
SDL_CameraDisconnected(device);
} else {
// okay! We have permission to use the camera _and_ opening the hardware worked out, report that the camera is usable!
SDL_CameraDevicePermissionOutcome(device, SDL_TRUE); // go go go!
SDL_CameraPermissionOutcome(device, SDL_TRUE); // go go go!
}
}
UnrefPhysicalCameraDevice(device); // we ref'd this in OpenDevice, release the extra reference.
UnrefPhysicalCamera(device); // we ref'd this in OpenDevice, release the extra reference.
}
static int ANDROIDCAMERA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *spec)
static int ANDROIDCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
{
#if 0 // !!! FIXME: for now, we'll just let this fail if it is going to fail, without checking for this
/* Cannot open a second camera, while the first one is opened.
@@ -555,19 +555,19 @@ static int ANDROIDCAMERA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSp
return -1;
}
RefPhysicalCameraDevice(device); // ref'd until permission callback fires.
RefPhysicalCamera(device); // ref'd until permission callback fires.
// just in case SDL_OpenCameraDevice is overwriting device->spec as CameraPermissionCallback runs, we work from a different copy.
// just in case SDL_OpenCamera is overwriting device->spec as CameraPermissionCallback runs, we work from a different copy.
SDL_copyp(&device->hidden->requested_spec, spec);
if (SDL_AndroidRequestPermission("android.permission.CAMERA", CameraPermissionCallback, device) < 0) {
UnrefPhysicalCameraDevice(device);
UnrefPhysicalCamera(device);
return -1;
}
return 0; // we don't open the camera until permission is granted, so always succeed for now.
}
static void ANDROIDCAMERA_FreeDeviceHandle(SDL_CameraDevice *device)
static void ANDROIDCAMERA_FreeDeviceHandle(SDL_Camera *device)
{
if (device) {
SDL_free(device->handle);
@@ -666,7 +666,7 @@ static void GatherCameraSpecs(const char *devid, CameraFormatAddData *add_data,
pACameraMetadata_free(metadata);
}
static SDL_bool FindAndroidCameraDeviceByID(SDL_CameraDevice *device, void *userdata)
static SDL_bool FindAndroidCameraByID(SDL_Camera *device, void *userdata)
{
const char *devid = (const char *) userdata;
return (SDL_strcmp(devid, (const char *) device->handle) == 0);
@@ -678,7 +678,7 @@ static void MaybeAddDevice(const char *devid)
SDL_Log("CAMERA: MaybeAddDevice('%s')", devid);
#endif
if (SDL_FindPhysicalCameraDeviceByCallback(FindAndroidCameraDeviceByID, (void *) devid)) {
if (SDL_FindPhysicalCameraByCallback(FindAndroidCameraByID, (void *) devid)) {
return; // already have this one.
}
@@ -689,7 +689,7 @@ static void MaybeAddDevice(const char *devid)
if (add_data.num_specs > 0) {
char *namecpy = SDL_strdup(devid);
if (namecpy) {
SDL_CameraDevice *device = SDL_AddCameraDevice(fullname, position, add_data.num_specs, add_data.specs, namecpy);
SDL_Camera *device = SDL_AddCamera(fullname, position, add_data.num_specs, add_data.specs, namecpy);
if (!device) {
SDL_free(namecpy);
}
@@ -725,9 +725,9 @@ static void onCameraUnavailable(void *context, const char *cameraId)
// THIS CALLBACK FIRES WHEN YOU OPEN THE DEVICE YOURSELF. :(
// Make sure we don't have the device opened, in which case onDisconnected will fire instead if actually lost.
SDL_CameraDevice *device = SDL_FindPhysicalCameraDeviceByCallback(FindAndroidCameraDeviceByID, (void *) cameraId);
SDL_Camera *device = SDL_FindPhysicalCameraByCallback(FindAndroidCameraByID, (void *) cameraId);
if (device && !device->hidden) {
SDL_CameraDeviceDisconnected(device);
SDL_CameraDisconnected(device);
}
}
+16 -16
View File
@@ -83,16 +83,16 @@ static void CoreMediaFormatToSDL(FourCharCode fmt, SDL_PixelFormat *pixel_format
@end
static SDL_bool CheckCameraPermissions(SDL_CameraDevice *device)
static SDL_bool CheckCameraPermissions(SDL_Camera *device)
{
if (device->permission == 0) { // 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.
SDL_CameraDevicePermissionOutcome(device, (status == AVAuthorizationStatusAuthorized) ? SDL_TRUE : SDL_FALSE);
SDL_CameraPermissionOutcome(device, (status == AVAuthorizationStatusAuthorized) ? SDL_TRUE : SDL_FALSE);
}
} else {
SDL_CameraDevicePermissionOutcome(device, SDL_TRUE); // always allowed (or just unqueryable...?) on older macOS.
SDL_CameraPermissionOutcome(device, SDL_TRUE); // always allowed (or just unqueryable...?) on older macOS.
}
}
@@ -102,14 +102,14 @@ static SDL_bool CheckCameraPermissions(SDL_CameraDevice *device)
// this delegate just receives new video frames on a Grand Central Dispatch queue, and fires off the
// main device thread iterate function directly to consume it.
@interface SDLCaptureVideoDataOutputSampleBufferDelegate : NSObject<AVCaptureVideoDataOutputSampleBufferDelegate>
@property SDL_CameraDevice *device;
-(id) init:(SDL_CameraDevice *) dev;
@property SDL_Camera *device;
-(id) init:(SDL_Camera *) dev;
-(void) captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection;
@end
@implementation SDLCaptureVideoDataOutputSampleBufferDelegate
-(id) init:(SDL_CameraDevice *) dev {
-(id) init:(SDL_Camera *) dev {
if ( self = [super init] ) {
_device = dev;
}
@@ -118,7 +118,7 @@ static SDL_bool CheckCameraPermissions(SDL_CameraDevice *device)
- (void) captureOutput:(AVCaptureOutput *)output didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection
{
SDL_CameraDevice *device = self.device;
SDL_Camera *device = self.device;
if (!device || !device->hidden) {
return; // oh well.
}
@@ -141,12 +141,12 @@ static SDL_bool CheckCameraPermissions(SDL_CameraDevice *device)
}
@end
static int COREMEDIA_WaitDevice(SDL_CameraDevice *device)
static int COREMEDIA_WaitDevice(SDL_Camera *device)
{
return 0; // this isn't used atm, since we run our own thread out of Grand Central Dispatch.
}
static int COREMEDIA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS)
static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
{
int retval = 1;
SDLPrivateCameraData *hidden = (__bridge SDLPrivateCameraData *) device->hidden;
@@ -222,13 +222,13 @@ static int COREMEDIA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame,
return retval;
}
static void COREMEDIA_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
static void COREMEDIA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
{
// !!! FIXME: this currently copies the data to the surface, but in theory we could just keep this locked until ReleaseFrame...
SDL_aligned_free(frame->pixels);
}
static void COREMEDIA_CloseDevice(SDL_CameraDevice *device)
static void COREMEDIA_CloseDevice(SDL_Camera *device)
{
if (device && device->hidden) {
SDLPrivateCameraData *hidden = (SDLPrivateCameraData *) CFBridgingRelease(device->hidden);
@@ -248,7 +248,7 @@ static void COREMEDIA_CloseDevice(SDL_CameraDevice *device)
}
}
static int COREMEDIA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *spec)
static int COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
{
AVCaptureDevice *avdevice = (__bridge AVCaptureDevice *) device->handle;
@@ -367,7 +367,7 @@ static int COREMEDIA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *
return 0;
}
static void COREMEDIA_FreeDeviceHandle(SDL_CameraDevice *device)
static void COREMEDIA_FreeDeviceHandle(SDL_Camera *device)
{
if (device && device->handle) {
CFBridgingRelease(device->handle);
@@ -408,7 +408,7 @@ static void GatherCameraSpecs(AVCaptureDevice *device, CameraFormatAddData *add_
}
}
static SDL_bool FindCoreMediaCameraDeviceByUniqueID(SDL_CameraDevice *device, void *userdata)
static SDL_bool FindCoreMediaCameraByUniqueID(SDL_Camera *device, void *userdata)
{
NSString *uniqueid = (__bridge NSString *) userdata;
AVCaptureDevice *avdev = (__bridge AVCaptureDevice *) device->handle;
@@ -421,7 +421,7 @@ static void MaybeAddDevice(AVCaptureDevice *avdevice)
return; // not connected.
} else if (![avdevice hasMediaType:AVMediaTypeVideo]) {
return; // not a camera.
} else if (SDL_FindPhysicalCameraDeviceByCallback(FindCoreMediaCameraDeviceByUniqueID, (__bridge void *) avdevice.uniqueID)) {
} else if (SDL_FindPhysicalCameraByCallback(FindCoreMediaCameraByUniqueID, (__bridge void *) avdevice.uniqueID)) {
return; // already have this one.
}
@@ -434,7 +434,7 @@ static void MaybeAddDevice(AVCaptureDevice *avdevice)
} else if (avdevice.position == AVCaptureDevicePositionBack) {
position = SDL_CAMERA_POSITION_BACK_FACING;
}
SDL_AddCameraDevice(avdevice.localizedName.UTF8String, position, add_data.num_specs, add_data.specs, (void *) CFBridgingRetain(avdevice));
SDL_AddCamera(avdevice.localizedName.UTF8String, position, add_data.num_specs, add_data.specs, (void *) CFBridgingRetain(avdevice));
}
SDL_free(add_data.specs);
+6 -6
View File
@@ -24,26 +24,26 @@
#include "../SDL_syscamera.h"
static int DUMMYCAMERA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *spec)
static int DUMMYCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
{
return SDL_Unsupported();
}
static void DUMMYCAMERA_CloseDevice(SDL_CameraDevice *device)
static void DUMMYCAMERA_CloseDevice(SDL_Camera *device)
{
}
static int DUMMYCAMERA_WaitDevice(SDL_CameraDevice *device)
static int DUMMYCAMERA_WaitDevice(SDL_Camera *device)
{
return SDL_Unsupported();
}
static int DUMMYCAMERA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS)
static int DUMMYCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
{
return SDL_Unsupported();
}
static void DUMMYCAMERA_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
static void DUMMYCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
{
}
@@ -51,7 +51,7 @@ static void DUMMYCAMERA_DetectDevices(void)
{
}
static void DUMMYCAMERA_FreeDeviceHandle(SDL_CameraDevice *device)
static void DUMMYCAMERA_FreeDeviceHandle(SDL_Camera *device)
{
}
+10 -10
View File
@@ -34,13 +34,13 @@
EM_JS_DEPS(sdlcamera, "$dynCall");
static int EMSCRIPTENCAMERA_WaitDevice(SDL_CameraDevice *device)
static int EMSCRIPTENCAMERA_WaitDevice(SDL_Camera *device)
{
SDL_assert(!"This shouldn't be called"); // we aren't using SDL's internal thread.
return -1;
}
static int EMSCRIPTENCAMERA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS)
static int EMSCRIPTENCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
{
void *rgba = SDL_malloc(device->actual_spec.width * device->actual_spec.height * 4);
if (!rgba) {
@@ -76,12 +76,12 @@ static int EMSCRIPTENCAMERA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *
return 1;
}
static void EMSCRIPTENCAMERA_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
static void EMSCRIPTENCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
{
SDL_free(frame->pixels);
}
static void EMSCRIPTENCAMERA_CloseDevice(SDL_CameraDevice *device)
static void EMSCRIPTENCAMERA_CloseDevice(SDL_Camera *device)
{
if (device) {
MAIN_THREAD_EM_ASM({
@@ -98,16 +98,16 @@ static void EMSCRIPTENCAMERA_CloseDevice(SDL_CameraDevice *device)
}
}
static void SDLEmscriptenCameraDevicePermissionOutcome(SDL_CameraDevice *device, int approved, int w, int h, int fps)
static void SDLEmscriptenCameraPermissionOutcome(SDL_Camera *device, int approved, int w, int h, int fps)
{
device->spec.width = device->actual_spec.width = w;
device->spec.height = device->actual_spec.height = h;
device->spec.framerate_numerator = device->actual_spec.framerate_numerator = fps;
device->spec.framerate_denominator = device->actual_spec.framerate_denominator = 1;
SDL_CameraDevicePermissionOutcome(device, approved ? SDL_TRUE : SDL_FALSE);
SDL_CameraPermissionOutcome(device, approved ? SDL_TRUE : SDL_FALSE);
}
static int EMSCRIPTENCAMERA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *spec)
static int EMSCRIPTENCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
{
MAIN_THREAD_EM_ASM({
// Since we can't get actual specs until we make a move that prompts the user for
@@ -199,12 +199,12 @@ static int EMSCRIPTENCAMERA_OpenDevice(SDL_CameraDevice *device, const SDL_Camer
console.error("Tried to open camera but it threw an error! " + err.name + ": " + err.message);
dynCall('viiiii', outcome, [device, 0, 0, 0, 0]); // we call this a permission error, because it probably is.
});
}, device, spec->width, spec->height, spec->framerate_numerator, spec->framerate_denominator, SDLEmscriptenCameraDevicePermissionOutcome, SDL_CameraThreadIterate);
}, device, spec->width, spec->height, spec->framerate_numerator, spec->framerate_denominator, SDLEmscriptenCameraPermissionOutcome, SDL_CameraThreadIterate);
return 0; // the real work waits until the user approves a camera.
}
static void EMSCRIPTENCAMERA_FreeDeviceHandle(SDL_CameraDevice *device)
static void EMSCRIPTENCAMERA_FreeDeviceHandle(SDL_Camera *device)
{
// no-op.
}
@@ -228,7 +228,7 @@ static void EMSCRIPTENCAMERA_DetectDevices(void)
// will pop up a user permission dialog warning them we're trying to access the camera, and we generally
// don't want that during SDL_Init().
if (supported) {
SDL_AddCameraDevice("Web browser's camera", SDL_CAMERA_POSITION_UNKNOWN, 0, NULL, (void *) (size_t) 0x1);
SDL_AddCamera("Web browser's camera", SDL_CAMERA_POSITION_UNKNOWN, 0, NULL, (void *) (size_t) 0x1);
}
}
@@ -347,7 +347,7 @@ typedef struct SDL_PrivateCameraData
int pitch;
} SDL_PrivateCameraData;
static int MEDIAFOUNDATION_WaitDevice(SDL_CameraDevice *device)
static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device)
{
SDL_assert(device->hidden->current_sample == NULL);
@@ -421,7 +421,7 @@ static void SDLCALL CleanupIMFMediaBuffer(void *userdata, void *value)
SDL_free(objs);
}
static int MEDIAFOUNDATION_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS)
static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
{
SDL_assert(device->hidden->current_sample != NULL);
@@ -511,7 +511,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *f
return retval;
}
static void MEDIAFOUNDATION_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
static void MEDIAFOUNDATION_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
{
const SDL_PropertiesID surfprops = SDL_GetSurfaceProperties(frame);
if (surfprops) {
@@ -522,7 +522,7 @@ static void MEDIAFOUNDATION_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *
#else
static int MEDIAFOUNDATION_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS)
static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
{
SDL_assert(device->hidden->current_sample != NULL);
@@ -627,14 +627,14 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *f
return retval;
}
static void MEDIAFOUNDATION_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
static void MEDIAFOUNDATION_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
{
SDL_aligned_free(frame->pixels);
}
#endif
static void MEDIAFOUNDATION_CloseDevice(SDL_CameraDevice *device)
static void MEDIAFOUNDATION_CloseDevice(SDL_Camera *device)
{
if (device && device->hidden) {
if (device->hidden->srcreader) {
@@ -695,7 +695,7 @@ done:
}
static int MEDIAFOUNDATION_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *spec)
static int MEDIAFOUNDATION_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
{
const char *utf8symlink = (const char *) device->handle;
IMFAttributes *attrs = NULL;
@@ -821,7 +821,7 @@ static int MEDIAFOUNDATION_OpenDevice(SDL_CameraDevice *device, const SDL_Camera
IMFMediaSource_Release(source); // srcreader is holding a reference to this.
// There is no user permission prompt for camera access (I think?)
SDL_CameraDevicePermissionOutcome(device, SDL_TRUE);
SDL_CameraPermissionOutcome(device, SDL_TRUE);
#undef CHECK_HRESULT
@@ -864,7 +864,7 @@ failed:
return -1;
}
static void MEDIAFOUNDATION_FreeDeviceHandle(SDL_CameraDevice *device)
static void MEDIAFOUNDATION_FreeDeviceHandle(SDL_Camera *device)
{
if (device) {
SDL_free(device->handle); // the device's symlink string.
@@ -962,7 +962,7 @@ static void GatherCameraSpecs(IMFMediaSource *source, CameraFormatAddData *add_d
IMFPresentationDescriptor_Release(presentdesc);
}
static SDL_bool FindMediaFoundationCameraDeviceBySymlink(SDL_CameraDevice *device, void *userdata)
static SDL_bool FindMediaFoundationCameraBySymlink(SDL_Camera *device, void *userdata)
{
return (SDL_strcmp((const char *) device->handle, (const char *) userdata) == 0);
}
@@ -971,7 +971,7 @@ static void MaybeAddDevice(IMFActivate *activation)
{
char *symlink = QueryActivationObjectString(activation, &SDL_MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK);
if (SDL_FindPhysicalCameraDeviceByCallback(FindMediaFoundationCameraDeviceBySymlink, symlink)) {
if (SDL_FindPhysicalCameraByCallback(FindMediaFoundationCameraBySymlink, symlink)) {
SDL_free(symlink);
return; // already have this one.
}
@@ -985,7 +985,7 @@ static void MaybeAddDevice(IMFActivate *activation)
CameraFormatAddData add_data;
GatherCameraSpecs(source, &add_data);
if (add_data.num_specs > 0) {
SDL_AddCameraDevice(name, SDL_CAMERA_POSITION_UNKNOWN, add_data.num_specs, add_data.specs, symlink);
SDL_AddCamera(name, SDL_CAMERA_POSITION_UNKNOWN, add_data.num_specs, add_data.specs, symlink);
}
SDL_free(add_data.specs);
IMFActivate_ShutdownObject(activation);
+11 -11
View File
@@ -429,12 +429,12 @@ static void on_process(void *data)
static void on_stream_state_changed(void *data, enum pw_stream_state old,
enum pw_stream_state state, const char *error)
{
SDL_CameraDevice *device = data;
SDL_Camera *device = data;
switch (state) {
case PW_STREAM_STATE_UNCONNECTED:
break;
case PW_STREAM_STATE_STREAMING:
SDL_CameraDevicePermissionOutcome(device, SDL_TRUE);
SDL_CameraPermissionOutcome(device, SDL_TRUE);
break;
default:
break;
@@ -447,13 +447,13 @@ static void on_stream_param_changed(void *data, uint32_t id, const struct spa_po
static void on_add_buffer(void *data, struct pw_buffer *buffer)
{
SDL_CameraDevice *device = data;
SDL_Camera *device = data;
pw_array_add_ptr(&device->hidden->buffers, buffer);
}
static void on_remove_buffer(void *data, struct pw_buffer *buffer)
{
SDL_CameraDevice *device = data;
SDL_Camera *device = data;
struct pw_buffer **p;
pw_array_for_each(p, &device->hidden->buffers) {
if (*p == buffer) {
@@ -472,7 +472,7 @@ static const struct pw_stream_events stream_events = {
.process = on_process,
};
static int PIPEWIRECAMERA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *spec)
static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
{
struct pw_properties *props;
const struct spa_pod *params[3];
@@ -533,7 +533,7 @@ static int PIPEWIRECAMERA_OpenDevice(SDL_CameraDevice *device, const SDL_CameraS
return 0;
}
static void PIPEWIRECAMERA_CloseDevice(SDL_CameraDevice *device)
static void PIPEWIRECAMERA_CloseDevice(SDL_Camera *device)
{
if (!device) {
return;
@@ -550,7 +550,7 @@ static void PIPEWIRECAMERA_CloseDevice(SDL_CameraDevice *device)
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
}
static int PIPEWIRECAMERA_WaitDevice(SDL_CameraDevice *device)
static int PIPEWIRECAMERA_WaitDevice(SDL_Camera *device)
{
PIPEWIRE_pw_thread_loop_lock(hotplug.loop);
PIPEWIRE_pw_thread_loop_wait(hotplug.loop);
@@ -558,7 +558,7 @@ static int PIPEWIRECAMERA_WaitDevice(SDL_CameraDevice *device)
return 0;
}
static int PIPEWIRECAMERA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS)
static int PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
{
struct pw_buffer *b;
@@ -590,7 +590,7 @@ static int PIPEWIRECAMERA_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *fr
return 1;
}
static void PIPEWIRECAMERA_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
static void PIPEWIRECAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
{
struct pw_buffer **p;
PIPEWIRE_pw_thread_loop_lock(hotplug.loop);
@@ -717,7 +717,7 @@ static void add_device(struct global *g)
collect_format(&data, p);
}
if (data.num_specs > 0) {
SDL_AddCameraDevice(g->name, SDL_CAMERA_POSITION_UNKNOWN,
SDL_AddCamera(g->name, SDL_CAMERA_POSITION_UNKNOWN,
data.num_specs, data.specs, g);
}
SDL_free(data.specs);
@@ -747,7 +747,7 @@ static void PIPEWIRECAMERA_DetectDevices(void)
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
}
static void PIPEWIRECAMERA_FreeDeviceHandle(SDL_CameraDevice *device)
static void PIPEWIRECAMERA_FreeDeviceHandle(SDL_Camera *device)
{
}
+16 -16
View File
@@ -88,7 +88,7 @@ static int xioctl(int fh, int request, void *arg)
return r;
}
static int V4L2_WaitDevice(SDL_CameraDevice *device)
static int V4L2_WaitDevice(SDL_Camera *device)
{
const int fd = device->hidden->fd;
@@ -118,7 +118,7 @@ static int V4L2_WaitDevice(SDL_CameraDevice *device)
return retval;
}
static int V4L2_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint64 *timestampNS)
static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
{
const int fd = device->hidden->fd;
const io_method io = device->hidden->io;
@@ -232,7 +232,7 @@ static int V4L2_AcquireFrame(SDL_CameraDevice *device, SDL_Surface *frame, Uint6
return 1;
}
static void V4L2_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
static void V4L2_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
{
struct v4l2_buffer buf;
const int fd = device->hidden->fd;
@@ -289,7 +289,7 @@ static void V4L2_ReleaseFrame(SDL_CameraDevice *device, SDL_Surface *frame)
}
}
static int EnqueueBuffers(SDL_CameraDevice *device)
static int EnqueueBuffers(SDL_Camera *device)
{
const int fd = device->hidden->fd;
const io_method io = device->hidden->io;
@@ -338,14 +338,14 @@ static int EnqueueBuffers(SDL_CameraDevice *device)
return 0;
}
static int AllocBufferRead(SDL_CameraDevice *device, size_t buffer_size)
static int AllocBufferRead(SDL_Camera *device, size_t buffer_size)
{
device->hidden->buffers[0].length = buffer_size;
device->hidden->buffers[0].start = SDL_calloc(1, buffer_size);
return device->hidden->buffers[0].start ? 0 : -1;
}
static int AllocBufferMmap(SDL_CameraDevice *device)
static int AllocBufferMmap(SDL_Camera *device)
{
const int fd = device->hidden->fd;
int i;
@@ -377,7 +377,7 @@ static int AllocBufferMmap(SDL_CameraDevice *device)
return 0;
}
static int AllocBufferUserPtr(SDL_CameraDevice *device, size_t buffer_size)
static int AllocBufferUserPtr(SDL_Camera *device, size_t buffer_size)
{
int i;
for (i = 0; i < device->hidden->nb_buffers; ++i) {
@@ -419,7 +419,7 @@ static Uint32 format_sdl_to_v4l2(SDL_PixelFormat fmt)
}
}
static void V4L2_CloseDevice(SDL_CameraDevice *device)
static void V4L2_CloseDevice(SDL_Camera *device)
{
if (!device) {
return;
@@ -470,7 +470,7 @@ static void V4L2_CloseDevice(SDL_CameraDevice *device)
}
}
static int V4L2_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *spec)
static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
{
const V4L2DeviceHandle *handle = (const V4L2DeviceHandle *) device->handle;
struct stat st;
@@ -634,12 +634,12 @@ static int V4L2_OpenDevice(SDL_CameraDevice *device, const SDL_CameraSpec *spec)
}
// Currently there is no user permission prompt for camera access, but maybe there will be a D-Bus portal interface at some point.
SDL_CameraDevicePermissionOutcome(device, SDL_TRUE);
SDL_CameraPermissionOutcome(device, SDL_TRUE);
return 0;
}
static SDL_bool FindV4L2CameraDeviceByBusInfoCallback(SDL_CameraDevice *device, void *userdata)
static SDL_bool FindV4L2CameraByBusInfoCallback(SDL_Camera *device, void *userdata)
{
const V4L2DeviceHandle *handle = (const V4L2DeviceHandle *) device->handle;
return (SDL_strcmp(handle->bus_info, (const char *) userdata) == 0);
@@ -713,7 +713,7 @@ static void MaybeAddDevice(const char *path)
} else if ((vcap.device_caps & V4L2_CAP_VIDEO_CAPTURE) == 0) {
close(fd);
return; // not a video capture device.
} else if (SDL_FindPhysicalCameraDeviceByCallback(FindV4L2CameraDeviceByBusInfoCallback, vcap.bus_info)) {
} else if (SDL_FindPhysicalCameraByCallback(FindV4L2CameraByBusInfoCallback, vcap.bus_info)) {
close(fd);
return; // already have it.
}
@@ -795,7 +795,7 @@ static void MaybeAddDevice(const char *path)
if (handle->path) {
handle->bus_info = SDL_strdup((char *)vcap.bus_info);
if (handle->bus_info) {
if (SDL_AddCameraDevice((const char *) vcap.card, SDL_CAMERA_POSITION_UNKNOWN, add_data.num_specs, add_data.specs, handle)) {
if (SDL_AddCamera((const char *) vcap.card, SDL_CAMERA_POSITION_UNKNOWN, add_data.num_specs, add_data.specs, handle)) {
SDL_free(add_data.specs);
return; // good to go.
}
@@ -809,7 +809,7 @@ static void MaybeAddDevice(const char *path)
SDL_free(add_data.specs);
}
static void V4L2_FreeDeviceHandle(SDL_CameraDevice *device)
static void V4L2_FreeDeviceHandle(SDL_Camera *device)
{
if (device) {
V4L2DeviceHandle *handle = (V4L2DeviceHandle *) device->handle;
@@ -820,7 +820,7 @@ static void V4L2_FreeDeviceHandle(SDL_CameraDevice *device)
}
#ifdef SDL_USE_LIBUDEV
static SDL_bool FindV4L2CameraDeviceByPathCallback(SDL_CameraDevice *device, void *userdata)
static SDL_bool FindV4L2CameraByPathCallback(SDL_Camera *device, void *userdata)
{
const V4L2DeviceHandle *handle = (const V4L2DeviceHandle *) device->handle;
return (SDL_strcmp(handle->path, (const char *) userdata) == 0);
@@ -829,7 +829,7 @@ static SDL_bool FindV4L2CameraDeviceByPathCallback(SDL_CameraDevice *device, voi
static void MaybeRemoveDevice(const char *path)
{
if (path) {
SDL_CameraDeviceDisconnected(SDL_FindPhysicalCameraDeviceByCallback(FindV4L2CameraDeviceByPathCallback, (void *) path));
SDL_CameraDisconnected(SDL_FindPhysicalCameraByCallback(FindV4L2CameraByPathCallback, (void *) path));
}
}
+6 -6
View File
@@ -186,13 +186,13 @@ SDL3_0.0.0 {
SDL_GetBooleanProperty;
SDL_GetCPUCacheLineSize;
SDL_GetCPUCount;
SDL_GetCameraDeviceName;
SDL_GetCameraDevicePosition;
SDL_GetCameraDeviceSupportedFormats;
SDL_GetCameraDevices;
SDL_GetCameraName;
SDL_GetCameraPosition;
SDL_GetCameraSupportedFormats;
SDL_GetCameras;
SDL_GetCameraDriver;
SDL_GetCameraFormat;
SDL_GetCameraInstanceID;
SDL_GetCameraID;
SDL_GetCameraPermissionState;
SDL_GetCameraProperties;
SDL_GetClipboardData;
@@ -591,7 +591,7 @@ SDL3_0.0.0 {
SDL_OnApplicationWillTerminate;
SDL_OpenAudioDevice;
SDL_OpenAudioDeviceStream;
SDL_OpenCameraDevice;
SDL_OpenCamera;
SDL_OpenFileStorage;
SDL_OpenGamepad;
SDL_OpenHaptic;
+6 -6
View File
@@ -211,13 +211,13 @@
#define SDL_GetBooleanProperty SDL_GetBooleanProperty_REAL
#define SDL_GetCPUCacheLineSize SDL_GetCPUCacheLineSize_REAL
#define SDL_GetCPUCount SDL_GetCPUCount_REAL
#define SDL_GetCameraDeviceName SDL_GetCameraDeviceName_REAL
#define SDL_GetCameraDevicePosition SDL_GetCameraDevicePosition_REAL
#define SDL_GetCameraDeviceSupportedFormats SDL_GetCameraDeviceSupportedFormats_REAL
#define SDL_GetCameraDevices SDL_GetCameraDevices_REAL
#define SDL_GetCameraName SDL_GetCameraName_REAL
#define SDL_GetCameraPosition SDL_GetCameraPosition_REAL
#define SDL_GetCameraSupportedFormats SDL_GetCameraSupportedFormats_REAL
#define SDL_GetCameras SDL_GetCameras_REAL
#define SDL_GetCameraDriver SDL_GetCameraDriver_REAL
#define SDL_GetCameraFormat SDL_GetCameraFormat_REAL
#define SDL_GetCameraInstanceID SDL_GetCameraInstanceID_REAL
#define SDL_GetCameraID SDL_GetCameraID_REAL
#define SDL_GetCameraPermissionState SDL_GetCameraPermissionState_REAL
#define SDL_GetCameraProperties SDL_GetCameraProperties_REAL
#define SDL_GetClipboardData SDL_GetClipboardData_REAL
@@ -616,7 +616,7 @@
#define SDL_OnApplicationWillTerminate SDL_OnApplicationWillTerminate_REAL
#define SDL_OpenAudioDevice SDL_OpenAudioDevice_REAL
#define SDL_OpenAudioDeviceStream SDL_OpenAudioDeviceStream_REAL
#define SDL_OpenCameraDevice SDL_OpenCameraDevice_REAL
#define SDL_OpenCamera SDL_OpenCamera_REAL
#define SDL_OpenFileStorage SDL_OpenFileStorage_REAL
#define SDL_OpenGamepad SDL_OpenGamepad_REAL
#define SDL_OpenHaptic SDL_OpenHaptic_REAL
+6 -6
View File
@@ -231,13 +231,13 @@ SDL_DYNAPI_PROC(char*,SDL_GetBasePath,(void),(),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetBooleanProperty,(SDL_PropertiesID a, const char *b, SDL_bool c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetCPUCacheLineSize,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_GetCPUCount,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetCameraDeviceName,(SDL_CameraDeviceID a),(a),return)
SDL_DYNAPI_PROC(SDL_CameraPosition,SDL_GetCameraDevicePosition,(SDL_CameraDeviceID a),(a),return)
SDL_DYNAPI_PROC(SDL_CameraSpec*,SDL_GetCameraDeviceSupportedFormats,(SDL_CameraDeviceID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_CameraDeviceID*,SDL_GetCameraDevices,(int *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetCameraName,(SDL_CameraID a),(a),return)
SDL_DYNAPI_PROC(SDL_CameraPosition,SDL_GetCameraPosition,(SDL_CameraID a),(a),return)
SDL_DYNAPI_PROC(SDL_CameraSpec*,SDL_GetCameraSupportedFormats,(SDL_CameraID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_CameraID*,SDL_GetCameras,(int *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetCameraDriver,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetCameraFormat,(SDL_Camera *a, SDL_CameraSpec *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_CameraDeviceID,SDL_GetCameraInstanceID,(SDL_Camera *a),(a),return)
SDL_DYNAPI_PROC(SDL_CameraID,SDL_GetCameraID,(SDL_Camera *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetCameraPermissionState,(SDL_Camera *a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetCameraProperties,(SDL_Camera *a),(a),return)
SDL_DYNAPI_PROC(void*,SDL_GetClipboardData,(const char *a, size_t *b),(a,b),return)
@@ -627,7 +627,7 @@ SDL_DYNAPI_PROC(void,SDL_OnApplicationWillResignActive,(void),(),)
SDL_DYNAPI_PROC(void,SDL_OnApplicationWillTerminate,(void),(),)
SDL_DYNAPI_PROC(SDL_AudioDeviceID,SDL_OpenAudioDevice,(SDL_AudioDeviceID a, const SDL_AudioSpec *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_AudioStream*,SDL_OpenAudioDeviceStream,(SDL_AudioDeviceID a, const SDL_AudioSpec *b, SDL_AudioStreamCallback c, void *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(SDL_Camera*,SDL_OpenCameraDevice,(SDL_CameraDeviceID a, const SDL_CameraSpec *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Camera*,SDL_OpenCamera,(SDL_CameraID a, const SDL_CameraSpec *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Storage*,SDL_OpenFileStorage,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_Gamepad*,SDL_OpenGamepad,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_Haptic*,SDL_OpenHaptic,(SDL_HapticID a),(a),return)
+13 -13
View File
@@ -23,8 +23,8 @@ static SDL_CameraSpec spec;
static SDL_Texture *texture = NULL;
static SDL_bool texture_updated = SDL_FALSE;
static SDL_Surface *frame_current = NULL;
static SDL_CameraDeviceID front_camera = 0;
static SDL_CameraDeviceID back_camera = 0;
static SDL_CameraID front_camera = 0;
static SDL_CameraID back_camera = 0;
int SDL_AppInit(void **appstate, int argc, char *argv[])
{
@@ -87,19 +87,19 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
return SDL_APP_FAILURE;
}
SDL_CameraDeviceID *devices = SDL_GetCameraDevices(&devcount);
SDL_CameraID *devices = SDL_GetCameras(&devcount);
if (!devices) {
SDL_Log("SDL_GetCameraDevices failed: %s", SDL_GetError());
SDL_Log("SDL_GetCameras failed: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
SDL_CameraDeviceID camera_id = 0;
SDL_CameraID camera_id = 0;
SDL_Log("Saw %d camera devices.", devcount);
for (i = 0; i < devcount; i++) {
const SDL_CameraDeviceID device = devices[i];
const char *name = SDL_GetCameraDeviceName(device);
const SDL_CameraPosition position = SDL_GetCameraDevicePosition(device);
const SDL_CameraID device = devices[i];
const char *name = SDL_GetCameraName(device);
const SDL_CameraPosition position = SDL_GetCameraPosition(device);
const char *posstr = "";
if (position == SDL_CAMERA_POSITION_FRONT_FACING) {
front_camera = device;
@@ -137,13 +137,13 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
spec.framerate_numerator = 1000;
spec.framerate_denominator = 1;
camera = SDL_OpenCameraDevice(camera_id, pspec);
camera = SDL_OpenCamera(camera_id, pspec);
if (!camera) {
SDL_Log("Failed to open camera device: %s", SDL_GetError());
return SDL_APP_FAILURE;
}
SDL_snprintf(window_title, sizeof (window_title), "testcamera: %s (%s)", SDL_GetCameraDeviceName(camera_id), SDL_GetCurrentCameraDriver());
SDL_snprintf(window_title, sizeof (window_title), "testcamera: %s (%s)", SDL_GetCameraName(camera_id), SDL_GetCurrentCameraDriver());
SDL_SetWindowTitle(window, window_title);
return SDL_APP_CONTINUE;
@@ -158,8 +158,8 @@ static int FlipCamera(void)
}
if (camera) {
const SDL_CameraDeviceID current = SDL_GetCameraInstanceID(camera);
SDL_CameraDeviceID nextcam = 0;
const SDL_CameraID current = SDL_GetCameraID(camera);
SDL_CameraID nextcam = 0;
if (current == front_camera) {
nextcam = back_camera;
} else if (current == back_camera) {
@@ -181,7 +181,7 @@ static int FlipCamera(void)
texture = NULL; /* will rebuild when new camera is approved. */
}
camera = SDL_OpenCameraDevice(nextcam, NULL);
camera = SDL_OpenCamera(nextcam, NULL);
if (!camera) {
SDL_Log("Failed to open camera device: %s", SDL_GetError());
return SDL_APP_FAILURE;