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

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);
}
}