From 2ad44bd1621a3e037ef8c524e169d54370ffdece Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Tue, 28 Nov 2023 23:03:19 -0500
Subject: [PATCH] camera: Made a pass over all the sources, cleaning up for
SDL3 style, etc.
---
src/camera/SDL_camera.c | 423 +++++++++---------------
src/camera/SDL_camera_c.h | 6 +-
src/camera/SDL_syscamera.h | 30 +-
src/camera/android/SDL_camera_android.c | 264 +++++++--------
src/camera/apple/SDL_camera_apple.m | 243 ++++++--------
src/camera/v4l2/SDL_camera_v4l2.c | 332 ++++++++-----------
6 files changed, 537 insertions(+), 761 deletions(-)
diff --git a/src/camera/SDL_camera.c b/src/camera/SDL_camera.c
index f10fc755fe7c..d62854c9c352 100644
--- a/src/camera/SDL_camera.c
+++ b/src/camera/SDL_camera.c
@@ -20,8 +20,6 @@
*/
#include "SDL_internal.h"
-#include "SDL3/SDL.h"
-#include "SDL3/SDL_camera.h"
#include "SDL_syscamera.h"
#include "SDL_camera_c.h"
#include "../video/SDL_pixels_c.h"
@@ -29,16 +27,16 @@
#define DEBUG_CAMERA 1
-/* list node entries to share frames between SDL and user app */
+// list node entries to share frames between SDL and user app
+// !!! FIXME: do we need this struct?
typedef struct entry_t
{
SDL_CameraFrame frame;
} entry_t;
-static SDL_CameraDevice *open_devices[16];
+static SDL_CameraDevice *open_devices[16]; // !!! FIXME: remove limit
-static void
-close_device(SDL_CameraDevice *device)
+static void CloseCameraDevice(SDL_CameraDevice *device)
{
if (!device) {
return;
@@ -57,27 +55,23 @@ close_device(SDL_CameraDevice *device)
SDL_DestroyMutex(device->acquiring_lock);
}
- {
- int i, n = SDL_arraysize(open_devices);
- for (i = 0; i < n; i++) {
- if (open_devices[i] == device) {
- open_devices[i] = NULL;
- }
+ const int n = SDL_arraysize(open_devices);
+ for (int i = 0; i < n; i++) {
+ if (open_devices[i] == device) {
+ open_devices[i] = NULL;
}
}
- {
- entry_t *entry = NULL;
- while (device->buffer_queue != NULL) {
- SDL_ListPop(&device->buffer_queue, (void**)&entry);
- if (entry) {
- SDL_CameraFrame f = entry->frame;
- /* Release frames not acquired, if any */
- if (f.timestampNS) {
- ReleaseFrame(device, &f);
- }
- SDL_free(entry);
+ entry_t *entry = NULL;
+ while (device->buffer_queue != NULL) {
+ SDL_ListPop(&device->buffer_queue, (void**)&entry);
+ if (entry) {
+ SDL_CameraFrame f = entry->frame;
+ // Release frames not acquired, if any
+ if (f.timestampNS) {
+ ReleaseFrame(device, &f);
}
+ SDL_free(entry);
}
}
@@ -87,12 +81,12 @@ close_device(SDL_CameraDevice *device)
SDL_free(device);
}
-/* Tell if all device are closed */
-SDL_bool check_all_device_closed(void)
+// Tell if all devices are closed
+SDL_bool CheckAllDeviceClosed(void)
{
- int i, n = SDL_arraysize(open_devices);
+ const int n = SDL_arraysize(open_devices);
int all_closed = SDL_TRUE;
- for (i = 0; i < n; i++) {
+ for (int i = 0; i < n; i++) {
if (open_devices[i]) {
all_closed = SDL_FALSE;
break;
@@ -101,11 +95,11 @@ SDL_bool check_all_device_closed(void)
return all_closed;
}
-/* Tell if at least one device is in playing state */
-SDL_bool check_device_playing(void)
+// Tell if at least one device is in playing state
+SDL_bool CheckDevicePlaying(void)
{
- int i, n = SDL_arraysize(open_devices);
- for (i = 0; i < n; i++) {
+ const int n = SDL_arraysize(open_devices);
+ for (int i = 0; i < n; i++) {
if (open_devices[i]) {
if (SDL_GetCameraStatus(open_devices[i]) == SDL_CAMERA_PLAYING) {
return SDL_TRUE;
@@ -115,35 +109,26 @@ SDL_bool check_device_playing(void)
return SDL_FALSE;
}
-void
-SDL_CloseCamera(SDL_CameraDevice *device)
+void SDL_CloseCamera(SDL_CameraDevice *device)
{
if (!device) {
SDL_InvalidParamError("device");
- return;
+ } else {
+ CloseCameraDevice(device);
}
- close_device(device);
}
-int
-SDL_StartCamera(SDL_CameraDevice *device)
+int SDL_StartCamera(SDL_CameraDevice *device)
{
- SDL_CameraStatus status;
- int result;
if (!device) {
return SDL_InvalidParamError("device");
- }
-
- if (device->is_spec_set == SDL_FALSE) {
+ } else if (device->is_spec_set == SDL_FALSE) {
return SDL_SetError("no spec set");
- }
-
- status = SDL_GetCameraStatus(device);
- if (status != SDL_CAMERA_INIT) {
+ } else if (SDL_GetCameraStatus(device) != SDL_CAMERA_INIT) {
return SDL_SetError("invalid state");
}
- result = StartCamera(device);
+ const int result = StartCamera(device);
if (result < 0) {
return result;
}
@@ -153,34 +138,23 @@ SDL_StartCamera(SDL_CameraDevice *device)
return 0;
}
-int
-SDL_GetCameraSpec(SDL_CameraDevice *device, SDL_CameraSpec *spec)
+int SDL_GetCameraSpec(SDL_CameraDevice *device, SDL_CameraSpec *spec)
{
if (!device) {
return SDL_InvalidParamError("device");
- }
-
- if (!spec) {
+ } else if (!spec) {
return SDL_InvalidParamError("spec");
}
SDL_zerop(spec);
-
return GetDeviceSpec(device, spec);
}
-int
-SDL_StopCamera(SDL_CameraDevice *device)
+int SDL_StopCamera(SDL_CameraDevice *device)
{
- SDL_CameraStatus status;
- int ret;
if (!device) {
return SDL_InvalidParamError("device");
- }
-
- status = SDL_GetCameraStatus(device);
-
- if (status != SDL_CAMERA_PLAYING) {
+ } else if (SDL_GetCameraStatus(device) != SDL_CAMERA_PLAYING) {
return SDL_SetError("invalid state");
}
@@ -188,104 +162,88 @@ SDL_StopCamera(SDL_CameraDevice *device)
SDL_AtomicSet(&device->shutdown, 1);
SDL_LockMutex(device->acquiring_lock);
- ret = StopCamera(device);
+ const int retval = StopCamera(device);
SDL_UnlockMutex(device->acquiring_lock);
- if (ret < 0) {
- return -1;
- }
-
- return 0;
+ return (retval < 0) ? -1 : 0;
}
-/* Check spec has valid format and frame size */
-static int
-prepare_cameraspec(SDL_CameraDevice *device, const SDL_CameraSpec *desired, SDL_CameraSpec *obtained, int allowed_changes)
+// Check spec has valid format and frame size
+static int prepare_cameraspec(SDL_CameraDevice *device, const SDL_CameraSpec *desired, SDL_CameraSpec *obtained, int allowed_changes)
{
- /* Check format */
- {
- int i, num = SDL_GetNumCameraFormats(device);
- int is_format_valid = 0;
-
- for (i = 0; i < num; i++) {
- Uint32 format;
- if (SDL_GetCameraFormat(device, i, &format) == 0) {
- if (format == desired->format && format != SDL_PIXELFORMAT_UNKNOWN) {
- is_format_valid = 1;
- obtained->format = format;
- break;
- }
+ // Check format
+ const int numfmts = SDL_GetNumCameraFormats(device);
+ SDL_bool is_format_valid = SDL_FALSE;
+
+ for (int i = 0; i < numfmts; i++) {
+ Uint32 format;
+ if (SDL_GetCameraFormat(device, i, &format) == 0) {
+ if (format == desired->format && format != SDL_PIXELFORMAT_UNKNOWN) {
+ is_format_valid = SDL_TRUE;
+ obtained->format = format;
+ break;
}
}
+ }
- if (!is_format_valid) {
- if (allowed_changes) {
- for (i = 0; i < num; i++) {
- Uint32 format;
- if (SDL_GetCameraFormat(device, i, &format) == 0) {
- if (format != SDL_PIXELFORMAT_UNKNOWN) {
- obtained->format = format;
- is_format_valid = 1;
- break;
- }
+ if (!is_format_valid) {
+ if (allowed_changes) {
+ for (int i = 0; i < numfmts; i++) {
+ Uint32 format;
+ if (SDL_GetCameraFormat(device, i, &format) == 0) {
+ if (format != SDL_PIXELFORMAT_UNKNOWN) {
+ obtained->format = format;
+ is_format_valid = SDL_TRUE;
+ break;
}
}
-
- } else {
- SDL_SetError("Not allowed to change the format");
- return -1;
}
+ } else {
+ return SDL_SetError("Not allowed to change the format");
}
+ }
- if (!is_format_valid) {
- SDL_SetError("Invalid format");
- return -1;
- }
+ if (!is_format_valid) {
+ return SDL_SetError("Invalid format");
}
- /* Check frame size */
- {
- int i, num = SDL_GetNumCameraFrameSizes(device, obtained->format);
- int is_framesize_valid = 0;
+ // Check frame size
+ const int numsizes = SDL_GetNumCameraFrameSizes(device, obtained->format);
+ SDL_bool is_framesize_valid = SDL_FALSE;
- for (i = 0; i < num; i++) {
- int w, h;
- if (SDL_GetCameraFrameSize(device, obtained->format, i, &w, &h) == 0) {
- if (desired->width == w && desired->height == h) {
- is_framesize_valid = 1;
- obtained->width = w;
- obtained->height = h;
- break;
- }
+ for (int i = 0; i < numsizes; i++) {
+ int w, h;
+ if (SDL_GetCameraFrameSize(device, obtained->format, i, &w, &h) == 0) {
+ if (desired->width == w && desired->height == h) {
+ is_framesize_valid = SDL_TRUE;
+ obtained->width = w;
+ obtained->height = h;
+ break;
}
}
+ }
- if (!is_framesize_valid) {
- if (allowed_changes) {
- int w, h;
- if (SDL_GetCameraFrameSize(device, obtained->format, 0, &w, &h) == 0) {
- is_framesize_valid = 1;
- obtained->width = w;
- obtained->height = h;
- }
- } else {
- SDL_SetError("Not allowed to change the frame size");
- return -1;
+ if (!is_framesize_valid) {
+ if (allowed_changes) {
+ int w, h;
+ if (SDL_GetCameraFrameSize(device, obtained->format, 0, &w, &h) == 0) {
+ is_framesize_valid = SDL_TRUE;
+ obtained->width = w;
+ obtained->height = h;
}
+ } else {
+ return SDL_SetError("Not allowed to change the frame size");
}
+ }
- if (!is_framesize_valid) {
- SDL_SetError("Invalid frame size");
- return -1;
- }
-
+ if (!is_framesize_valid) {
+ return SDL_SetError("Invalid frame size");
}
return 0;
}
-const char *
-SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id)
+const char *SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id)
{
static char buf[256];
buf[0] = 0;
@@ -299,47 +257,41 @@ SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id)
if (GetCameraDeviceName(instance_id, buf, sizeof (buf)) < 0) {
buf[0] = 0;
}
+
return buf;
}
-SDL_CameraDeviceID *
-SDL_GetCameraDevices(int *count)
+SDL_CameraDeviceID *SDL_GetCameraDevices(int *count)
{
+ int dummycount = 0;
+ if (!count) {
+ count = &dummycount;
+ }
int num = 0;
- SDL_CameraDeviceID *ret = GetCameraDevices(&num);
-
- if (ret) {
- if (count) {
- *count = num;
- }
- return ret;
+ SDL_CameraDeviceID *retval = GetCameraDevices(&num);
+ if (retval) {
+ *count = num;
+ return retval;
}
- /* return list of 0 ID, null terminated */
- num = 0;
- ret = (SDL_CameraDeviceID *)SDL_malloc((num + 1) * sizeof(*ret));
-
- if (ret == NULL) {
+ // return list of 0 ID, null terminated
+ retval = (SDL_CameraDeviceID *)SDL_calloc(1, sizeof(*retval));
+ if (retval == NULL) {
SDL_OutOfMemory();
- if (count) {
- *count = 0;
- }
+ *count = 0;
return NULL;
}
- ret[num] = 0;
- if (count) {
- *count = num;
- }
+ retval[0] = 0;
+ *count = 0;
- return ret;
+ return retval;
}
-/* Camera thread function */
-static int SDLCALL
-SDL_CameraThread(void *devicep)
+// Camera thread function
+static int SDLCALL SDL_CameraThread(void *devicep)
{
const int delay = 20;
SDL_CameraDevice *device = (SDL_CameraDevice *) devicep;
@@ -358,23 +310,23 @@ SDL_CameraThread(void *devicep)
Android_JNI_CameraSetThreadPriority(device->iscapture, device);
}*/
#else
- /* The camera capture is always a high priority thread */
+ // The camera capture is always a high priority thread
SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH);
#endif
- /* Perform any thread setup */
+ // Perform any thread setup
device->threadid = SDL_GetCurrentThreadID();
- /* Init state */
+ // Init state
+ // !!! FIXME: use a semaphore or something
while (!SDL_AtomicGet(&device->enabled)) {
SDL_Delay(delay);
}
- /* Loop, filling the camera buffers */
+ // Loop, filling the camera buffers
while (!SDL_AtomicGet(&device->shutdown)) {
SDL_CameraFrame f;
int ret;
- entry_t *entry;
SDL_zero(f);
@@ -389,7 +341,7 @@ SDL_CameraThread(void *devicep)
}
if (ret < 0) {
- /* Flag it as an error */
+ // Flag it as an error
#if DEBUG_CAMERA
SDL_Log("dev[%p] error AcquireFrame: %d %s", (void *)device, ret, SDL_GetError());
#endif
@@ -397,7 +349,7 @@ SDL_CameraThread(void *devicep)
}
- entry = SDL_malloc(sizeof (entry_t));
+ entry_t *entry = SDL_malloc(sizeof (entry_t));
if (entry == NULL) {
goto error_mem;
}
@@ -424,26 +376,25 @@ SDL_CameraThread(void *devicep)
SDL_Log("dev[%p] End thread 'SDL_CameraThread' with error: %s", (void *)device, SDL_GetError());
#endif
SDL_AtomicSet(&device->shutdown, 1);
- SDL_OutOfMemory();
+ SDL_OutOfMemory(); // !!! FIXME: this error isn't accessible since the thread is about to terminate
return 0;
}
-SDL_CameraDevice *
-SDL_OpenCamera(SDL_CameraDeviceID instance_id)
+SDL_CameraDevice *SDL_OpenCamera(SDL_CameraDeviceID instance_id)
{
- int i, n = SDL_arraysize(open_devices);
- int id = -1;
+ const int n = SDL_arraysize(open_devices);
SDL_CameraDevice *device = NULL;
const char *device_name = NULL;
+ int id = -1;
if (!SDL_WasInit(SDL_INIT_VIDEO)) {
SDL_SetError("Video subsystem is not initialized");
goto error;
}
- /* !!! FIXME: there is a race condition here if two devices open from two threads at once. */
- /* Find an available device ID... */
- for (i = 0; i < n; i++) {
+ // !!! FIXME: there is a race condition here if two devices open from two threads at once.
+ // Find an available device ID...
+ for (int i = 0; i < n; i++) {
if (open_devices[i] == NULL) {
id = i;
break;
@@ -470,7 +421,7 @@ SDL_OpenCamera(SDL_CameraDeviceID instance_id)
#if 0
// FIXME do we need this ?
- /* Let the user override. */
+ // Let the user override.
{
const char *dev = SDL_getenv("SDL_CAMERA_DEVICE_NAME");
if (dev && dev[0]) {
@@ -490,7 +441,6 @@ SDL_OpenCamera(SDL_CameraDeviceID instance_id)
}
device->dev_name = SDL_strdup(device_name);
-
SDL_AtomicSet(&device->shutdown, 0);
SDL_AtomicSet(&device->enabled, 0);
@@ -510,37 +460,28 @@ SDL_OpenCamera(SDL_CameraDeviceID instance_id)
goto error;
}
- /* empty */
+ // empty
device->buffer_queue = NULL;
- open_devices[id] = device; /* add it to our list of open devices. */
-
-
- /* Start the camera thread */
- {
- const size_t stacksize = 64 * 1024;
- char threadname[64];
+ open_devices[id] = device; // add it to our list of open devices.
- SDL_snprintf(threadname, sizeof (threadname), "SDLCamera%d", id);
- device->thread = SDL_CreateThreadInternal(SDL_CameraThread, threadname, stacksize, device);
- if (device->thread == NULL) {
- SDL_SetError("Couldn't create camera thread");
- goto error;
- }
+ // Start the camera thread
+ char threadname[64];
+ SDL_snprintf(threadname, sizeof (threadname), "SDLCamera%d", id);
+ device->thread = SDL_CreateThreadInternal(SDL_CameraThread, threadname, 0, device);
+ if (device->thread == NULL) {
+ SDL_SetError("Couldn't create camera thread");
+ goto error;
}
return device;
error:
- close_device(device);
+ CloseCameraDevice(device);
return NULL;
}
-int
-SDL_SetCameraSpec(SDL_CameraDevice *device,
- const SDL_CameraSpec *desired,
- SDL_CameraSpec *obtained,
- int allowed_changes)
+int SDL_SetCameraSpec(SDL_CameraDevice *device, const SDL_CameraSpec *desired, SDL_CameraSpec *obtained, int allowed_changes)
{
SDL_CameraSpec _obtained;
SDL_CameraSpec _desired;
@@ -548,9 +489,7 @@ SDL_SetCameraSpec(SDL_CameraDevice *device,
if (!device) {
return SDL_InvalidParamError("device");
- }
-
- if (device->is_spec_set == SDL_TRUE) {
+ } else if (device->is_spec_set == SDL_TRUE) {
return SDL_SetError("already configured");
}
@@ -559,7 +498,7 @@ SDL_SetCameraSpec(SDL_CameraDevice *device,
desired = &_desired;
allowed_changes = SDL_CAMERA_ALLOW_ANY_CHANGE;
} else {
- /* in case desired == obtained */
+ // in case desired == obtained
_desired = *desired;
desired = &_desired;
}
@@ -588,14 +527,11 @@ SDL_SetCameraSpec(SDL_CameraDevice *device,
return 0;
}
-int
-SDL_AcquireCameraFrame(SDL_CameraDevice *device, SDL_CameraFrame *frame)
+int SDL_AcquireCameraFrame(SDL_CameraDevice *device, SDL_CameraFrame *frame)
{
if (!device) {
return SDL_InvalidParamError("device");
- }
-
- if (!frame) {
+ } else if (!frame) {
return SDL_InvalidParamError("frame");
}
@@ -604,7 +540,7 @@ SDL_AcquireCameraFrame(SDL_CameraDevice *device, SDL_CameraFrame *frame)
if (device->thread == NULL) {
int ret;
- /* Wait for a frame */
+ // Wait for a frame
while ((ret = AcquireFrame(device, frame)) == 0) {
if (frame->num_planes) {
return 0;
@@ -622,42 +558,33 @@ SDL_AcquireCameraFrame(SDL_CameraDevice *device, SDL_CameraFrame *frame)
*frame = entry->frame;
SDL_free(entry);
- /* Error from thread */
+ // Error from thread
if (frame->num_planes == 0 && frame->timestampNS == 0) {
return SDL_SetError("error from acquisition thread");
}
-
-
} else {
- /* Queue is empty. Not an error. */
+ // Queue is empty. Not an error.
}
}
return 0;
}
-int
-SDL_ReleaseCameraFrame(SDL_CameraDevice *device, SDL_CameraFrame *frame)
+int SDL_ReleaseCameraFrame(SDL_CameraDevice *device, SDL_CameraFrame *frame)
{
if (!device) {
return SDL_InvalidParamError("device");
- }
-
- if (frame == NULL) {
+ } else if (frame == NULL) {
return SDL_InvalidParamError("frame");
- }
-
- if (ReleaseFrame(device, frame) < 0) {
+ } else if (ReleaseFrame(device, frame) < 0) {
return -1;
}
SDL_zerop(frame);
-
return 0;
}
-int
-SDL_GetNumCameraFormats(SDL_CameraDevice *device)
+int SDL_GetNumCameraFormats(SDL_CameraDevice *device)
{
if (!device) {
return SDL_InvalidParamError("device");
@@ -665,21 +592,18 @@ SDL_GetNumCameraFormats(SDL_CameraDevice *device)
return GetNumFormats(device);
}
-int
-SDL_GetCameraFormat(SDL_CameraDevice *device, int index, Uint32 *format)
+int SDL_GetCameraFormat(SDL_CameraDevice *device, int index, Uint32 *format)
{
if (!device) {
return SDL_InvalidParamError("device");
- }
- if (!format) {
+ } else if (!format) {
return SDL_InvalidParamError("format");
}
*format = 0;
return GetFormat(device, index, format);
}
-int
-SDL_GetNumCameraFrameSizes(SDL_CameraDevice *device, Uint32 format)
+int SDL_GetNumCameraFrameSizes(SDL_CameraDevice *device, Uint32 format)
{
if (!device) {
return SDL_InvalidParamError("device");
@@ -687,29 +611,20 @@ SDL_GetNumCameraFrameSizes(SDL_CameraDevice *device, Uint32 format)
return GetNumFrameSizes(device, format);
}
-int
-SDL_GetCameraFrameSize(SDL_CameraDevice *device, Uint32 format, int index, int *width, int *height)
+int SDL_GetCameraFrameSize(SDL_CameraDevice *device, Uint32 format, int index, int *width, int *height)
{
if (!device) {
return SDL_InvalidParamError("device");
- }
- if (!width) {
+ } else if (!width) {
return SDL_InvalidParamError("width");
- }
- if (!height) {
+ } else if (!height) {
return SDL_InvalidParamError("height");
}
- *width = 0;
- *height = 0;
+ *width = *height = 0;
return GetFrameSize(device, format, index, width, height);
}
-SDL_CameraDevice *
-SDL_OpenCameraWithSpec(
- SDL_CameraDeviceID instance_id,
- const SDL_CameraSpec *desired,
- SDL_CameraSpec *obtained,
- int allowed_changes)
+SDL_CameraDevice *SDL_OpenCameraWithSpec(SDL_CameraDeviceID instance_id, const SDL_CameraSpec *desired, SDL_CameraSpec *obtained, int allowed_changes)
{
SDL_CameraDevice *device;
@@ -724,42 +639,32 @@ SDL_OpenCameraWithSpec(
return device;
}
-SDL_CameraStatus
-SDL_GetCameraStatus(SDL_CameraDevice *device)
+SDL_CameraStatus SDL_GetCameraStatus(SDL_CameraDevice *device)
{
if (device == NULL) {
return SDL_CAMERA_INIT;
- }
-
- if (device->is_spec_set == SDL_FALSE) {
+ } else if (device->is_spec_set == SDL_FALSE) {
return SDL_CAMERA_INIT;
- }
-
- if (SDL_AtomicGet(&device->shutdown)) {
+ } else if (SDL_AtomicGet(&device->shutdown)) {
return SDL_CAMERA_STOPPED;
- }
-
- if (SDL_AtomicGet(&device->enabled)) {
+ } else if (SDL_AtomicGet(&device->enabled)) {
return SDL_CAMERA_PLAYING;
}
return SDL_CAMERA_INIT;
}
-int
-SDL_CameraInit(void)
+int SDL_CameraInit(void)
{
SDL_zeroa(open_devices);
-
SDL_SYS_CameraInit();
return 0;
}
-void
-SDL_QuitCamera(void)
+void SDL_QuitCamera(void)
{
- int i, n = SDL_arraysize(open_devices);
- for (i = 0; i < n; i++) {
- close_device(open_devices[i]);
+ const int n = SDL_arraysize(open_devices);
+ for (int i = 0; i < n; i++) {
+ CloseCameraDevice(open_devices[i]);
}
SDL_zeroa(open_devices);
diff --git a/src/camera/SDL_camera_c.h b/src/camera/SDL_camera_c.h
index 1b3ea36e85de..787b5f2db5fc 100644
--- a/src/camera/SDL_camera_c.h
+++ b/src/camera/SDL_camera_c.h
@@ -23,10 +23,10 @@
#ifndef SDL_camera_c_h_
#define SDL_camera_c_h_
-/* Initialize the camera subsystem */
+// Initialize the camera subsystem
int SDL_CameraInit(void);
-/* Shutdown the camera subsystem */
+// Shutdown the camera subsystem
void SDL_QuitCamera(void);
-#endif /* SDL_camera_c_h_ */
+#endif // SDL_camera_c_h_
diff --git a/src/camera/SDL_syscamera.h b/src/camera/SDL_syscamera.h
index cb0ce2c6f2a5..990272f8d0a8 100644
--- a/src/camera/SDL_syscamera.h
+++ b/src/camera/SDL_syscamera.h
@@ -25,45 +25,43 @@
#include "../SDL_list.h"
-/* The SDL camera driver */
+// The SDL camera driver
typedef struct SDL_CameraDevice SDL_CameraDevice;
-/* Define the SDL camera driver structure */
+// Define the SDL camera driver structure
struct SDL_CameraDevice
{
- /* * * */
- /* Data common to all devices */
-
- /* The device's current camera specification */
+ // The device's current camera specification
SDL_CameraSpec spec;
- /* Device name */
+ // Device name
char *dev_name;
- /* Current state flags */
+ // Current state flags
SDL_AtomicInt shutdown;
SDL_AtomicInt enabled;
SDL_bool is_spec_set;
- /* A mutex for locking the queue buffers */
+ // A mutex for locking the queue buffers
SDL_Mutex *device_lock;
SDL_Mutex *acquiring_lock;
- /* A thread to feed the camera device */
+ // A thread to feed the camera device
SDL_Thread *thread;
SDL_ThreadID threadid;
- /* Queued buffers (if app not using callback). */
+ // Queued buffers (if app not using callback).
SDL_ListNode *buffer_queue;
- /* * * */
- /* Data private to this driver */
+ // Data private to this driver
struct SDL_PrivateCameraData *hidden;
};
extern int SDL_SYS_CameraInit(void);
extern int SDL_SYS_CameraQuit(void);
+// !!! FIXME: These names need to be made camera-specific.
+
extern int OpenDevice(SDL_CameraDevice *_this);
extern void CloseDevice(SDL_CameraDevice *_this);
@@ -86,7 +84,7 @@ extern int GetFrameSize(SDL_CameraDevice *_this, Uint32 format, int index, int *
extern int GetCameraDeviceName(SDL_CameraDeviceID instance_id, char *buf, int size);
extern SDL_CameraDeviceID *GetCameraDevices(int *count);
-extern SDL_bool check_all_device_closed(void);
-extern SDL_bool check_device_playing(void);
+extern SDL_bool CheckAllDeviceClosed(void);
+extern SDL_bool CheckDevicePlaying(void);
-#endif /* SDL_syscamera_h_ */
+#endif // SDL_syscamera_h_
diff --git a/src/camera/android/SDL_camera_android.c b/src/camera/android/SDL_camera_android.c
index b00e18334502..51d2446b6709 100644
--- a/src/camera/android/SDL_camera_android.c
+++ b/src/camera/android/SDL_camera_android.c
@@ -62,8 +62,7 @@
static ACameraManager *cameraMgr = NULL;
static ACameraIdList *cameraIdList = NULL;
-static void
-create_cameraMgr(void)
+static void create_cameraMgr(void)
{
if (cameraMgr == NULL) {
#if 0 // !!! FIXME: this is getting replaced in a different branch.
@@ -81,8 +80,7 @@ create_cameraMgr(void)
}
}
-static void
-delete_cameraMgr(void)
+static void delete_cameraMgr(void)
{
if (cameraIdList) {
ACameraManager_deleteCameraIdList(cameraIdList);
@@ -104,50 +102,46 @@ struct SDL_PrivateCameraData
ACaptureSessionOutputContainer *sessionOutputContainer;
AImageReader *reader;
int num_formats;
- int count_formats[6]; // see format_2_id
+ int count_formats[6]; // see format_to_id
};
-/**/
#define FORMAT_SDL SDL_PIXELFORMAT_NV12
-static int
-format_2_id(int fmt) {
+static int format_to_id(int fmt) {
switch (fmt) {
-#define CASE(x, y) case x: return y
+ #define CASE(x, y) case x: return y
CASE(FORMAT_SDL, 0);
CASE(SDL_PIXELFORMAT_RGB565, 1);
CASE(SDL_PIXELFORMAT_XRGB8888, 2);
CASE(SDL_PIXELFORMAT_RGBA8888, 3);
CASE(SDL_PIXELFORMAT_RGBX8888, 4);
CASE(SDL_PIXELFORMAT_UNKNOWN, 5);
-#undef CASE
+ #undef CASE
default:
- return 5;
+ return 5;
}
}
-static int
-id_2_format(int fmt) {
+static int id_to_format(int fmt) {
switch (fmt) {
-#define CASE(x, y) case y: return x
+ #define CASE(x, y) case y: return x
CASE(FORMAT_SDL, 0);
CASE(SDL_PIXELFORMAT_RGB565, 1);
CASE(SDL_PIXELFORMAT_XRGB8888, 2);
CASE(SDL_PIXELFORMAT_RGBA8888, 3);
CASE(SDL_PIXELFORMAT_RGBX8888, 4);
CASE(SDL_PIXELFORMAT_UNKNOWN, 5);
-#undef CASE
+ #undef CASE
default:
return SDL_PIXELFORMAT_UNKNOWN;
}
}
-static Uint32
-format_android_2_sdl(Uint32 fmt)
+static Uint32 format_android_to_sdl(Uint32 fmt)
{
switch (fmt) {
-#define CASE(x, y) case x: return y
+ #define CASE(x, y) case x: return y
CASE(AIMAGE_FORMAT_YUV_420_888, FORMAT_SDL);
CASE(AIMAGE_FORMAT_RGB_565, SDL_PIXELFORMAT_RGB565);
CASE(AIMAGE_FORMAT_RGB_888, SDL_PIXELFORMAT_XRGB8888);
@@ -157,71 +151,72 @@ format_android_2_sdl(Uint32 fmt)
CASE(AIMAGE_FORMAT_RGBA_FP16, SDL_PIXELFORMAT_UNKNOWN); // 64bits
CASE(AIMAGE_FORMAT_RAW_PRIVATE, SDL_PIXELFORMAT_UNKNOWN);
CASE(AIMAGE_FORMAT_JPEG, SDL_PIXELFORMAT_UNKNOWN);
-#undef CASE
+ #undef CASE
default:
SDL_Log("Unknown format AIMAGE_FORMAT '%d'", fmt);
return SDL_PIXELFORMAT_UNKNOWN;
}
}
-static Uint32
-format_sdl_2_android(Uint32 fmt)
+static Uint32 format_sdl_to_android(Uint32 fmt)
{
switch (fmt) {
-#define CASE(x, y) case y: return x
+ #define CASE(x, y) case y: return x
CASE(AIMAGE_FORMAT_YUV_420_888, FORMAT_SDL);
CASE(AIMAGE_FORMAT_RGB_565, SDL_PIXELFORMAT_RGB565);
CASE(AIMAGE_FORMAT_RGB_888, SDL_PIXELFORMAT_XRGB8888);
CASE(AIMAGE_FORMAT_RGBA_8888, SDL_PIXELFORMAT_RGBA8888);
CASE(AIMAGE_FORMAT_RGBX_8888, SDL_PIXELFORMAT_RGBX8888);
-#undef CASE
+ #undef CASE
default:
return 0;
}
}
-static void
-onDisconnected(void *context, ACameraDevice *device)
+static void onDisconnected(void *context, ACameraDevice *device)
{
// SDL_CameraDevice *_this = (SDL_CameraDevice *) context;
+ #if DEBUG_CAMERA
SDL_Log("CB onDisconnected");
+ #endif
}
-static void
-onError(void *context, ACameraDevice *device, int error)
+static void onError(void *context, ACameraDevice *device, int error)
{
// SDL_CameraDevice *_this = (SDL_CameraDevice *) context;
+ #if DEBUG_CAMERA
SDL_Log("CB onError");
+ #endif
}
-static void
-onClosed(void* context, ACameraCaptureSession *session)
+static void onClosed(void* context, ACameraCaptureSession *session)
{
// SDL_CameraDevice *_this = (SDL_CameraDevice *) context;
+ #if DEBUG_CAMERA
SDL_Log("CB onClosed");
+ #endif
}
-static void
-onReady(void* context, ACameraCaptureSession *session)
+static void onReady(void* context, ACameraCaptureSession *session)
{
// SDL_CameraDevice *_this = (SDL_CameraDevice *) context;
+ #if DEBUG_CAMERA
SDL_Log("CB onReady");
+ #endif
}
-static void
-onActive(void* context, ACameraCaptureSession *session)
+static void onActive(void* context, ACameraCaptureSession *session)
{
// SDL_CameraDevice *_this = (SDL_CameraDevice *) context;
+ #if DEBUG_CAMERA
SDL_Log("CB onActive");
+ #endif
}
-int
-OpenDevice(SDL_CameraDevice *_this)
+int OpenDevice(SDL_CameraDevice *_this)
{
- camera_status_t res;
-
/* Cannot open a second camera, while the first one is opened.
* If you want to play several camera, they must all be opened first, then played.
*
@@ -230,7 +225,7 @@ OpenDevice(SDL_CameraDevice *_this)
* before configuring sessions on any of the camera devices. * "
*
*/
- if (check_device_playing()) {
+ if (CheckDevicePlaying()) {
return SDL_SetError("A camera is already playing");
}
@@ -245,7 +240,7 @@ OpenDevice(SDL_CameraDevice *_this)
_this->hidden->dev_callbacks.onDisconnected = onDisconnected;
_this->hidden->dev_callbacks.onError = onError;
- res = ACameraManager_openCamera(cameraMgr, _this->dev_name, &_this->hidden->dev_cal
(Patch may be truncated, please check the link at the top of this post.)