mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-29 14:38:29 +00:00
camera: SDL_GetCameraDevices should not report "no devices" like an error.
This commit is contained in:
@@ -539,7 +539,13 @@ char *SDL_GetCameraDeviceName(SDL_CameraDeviceID instance_id)
|
|||||||
|
|
||||||
SDL_CameraDeviceID *SDL_GetCameraDevices(int *count)
|
SDL_CameraDeviceID *SDL_GetCameraDevices(int *count)
|
||||||
{
|
{
|
||||||
|
int dummy_count;
|
||||||
|
if (!count) {
|
||||||
|
count = &dummy_count;
|
||||||
|
}
|
||||||
|
|
||||||
if (!SDL_GetCurrentCameraDriver()) {
|
if (!SDL_GetCurrentCameraDriver()) {
|
||||||
|
*count = 0;
|
||||||
SDL_SetError("Camera subsystem is not initialized");
|
SDL_SetError("Camera subsystem is not initialized");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -548,7 +554,6 @@ SDL_CameraDeviceID *SDL_GetCameraDevices(int *count)
|
|||||||
|
|
||||||
SDL_LockRWLockForReading(camera_driver.device_hash_lock);
|
SDL_LockRWLockForReading(camera_driver.device_hash_lock);
|
||||||
int num_devices = SDL_AtomicGet(&camera_driver.device_count);
|
int num_devices = SDL_AtomicGet(&camera_driver.device_count);
|
||||||
if (num_devices > 0) {
|
|
||||||
retval = (SDL_CameraDeviceID *) SDL_malloc((num_devices + 1) * sizeof (SDL_CameraDeviceID));
|
retval = (SDL_CameraDeviceID *) SDL_malloc((num_devices + 1) * sizeof (SDL_CameraDeviceID));
|
||||||
if (!retval) {
|
if (!retval) {
|
||||||
num_devices = 0;
|
num_devices = 0;
|
||||||
@@ -564,15 +569,11 @@ SDL_CameraDeviceID *SDL_GetCameraDevices(int *count)
|
|||||||
SDL_assert(devs_seen == num_devices);
|
SDL_assert(devs_seen == num_devices);
|
||||||
retval[devs_seen] = 0; // null-terminated.
|
retval[devs_seen] = 0; // null-terminated.
|
||||||
}
|
}
|
||||||
}
|
|
||||||
SDL_UnlockRWLock(camera_driver.device_hash_lock);
|
SDL_UnlockRWLock(camera_driver.device_hash_lock);
|
||||||
|
|
||||||
if (count) {
|
|
||||||
*count = num_devices;
|
*count = num_devices;
|
||||||
}
|
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_CameraSpec *SDL_GetCameraDeviceSupportedFormats(SDL_CameraDeviceID instance_id, int *count)
|
SDL_CameraSpec *SDL_GetCameraDeviceSupportedFormats(SDL_CameraDeviceID instance_id, int *count)
|
||||||
|
@@ -26,6 +26,9 @@ static SDL_Surface *frame_current = NULL;
|
|||||||
|
|
||||||
int SDL_AppInit(int argc, char *argv[])
|
int SDL_AppInit(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
int devcount = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
/* Initialize test framework */
|
/* Initialize test framework */
|
||||||
state = SDLTest_CommonCreateState(argv, 0);
|
state = SDLTest_CommonCreateState(argv, 0);
|
||||||
if (state == NULL) {
|
if (state == NULL) {
|
||||||
@@ -55,17 +58,24 @@ int SDL_AppInit(int argc, char *argv[])
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_CameraDeviceID *devices = SDL_GetCameraDevices(NULL);
|
SDL_CameraDeviceID *devices = SDL_GetCameraDevices(&devcount);
|
||||||
if (!devices) {
|
if (!devices) {
|
||||||
SDL_Log("SDL_GetCameraDevices failed: %s", SDL_GetError());
|
SDL_Log("SDL_GetCameraDevices failed: %s", SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SDL_Log("Saw %d camera devices.", devcount);
|
||||||
|
for (i = 0; i < devcount; i++) {
|
||||||
|
char *name = SDL_GetCameraDeviceName(devices[i]);
|
||||||
|
SDL_Log(" - Camera #%d: %s", i, name);
|
||||||
|
SDL_free(name);
|
||||||
|
}
|
||||||
|
|
||||||
const SDL_CameraDeviceID devid = devices[0]; /* just take the first one. */
|
const SDL_CameraDeviceID devid = devices[0]; /* just take the first one. */
|
||||||
SDL_free(devices);
|
SDL_free(devices);
|
||||||
|
|
||||||
if (!devid) {
|
if (!devid) {
|
||||||
SDL_Log("No cameras available? %s", SDL_GetError());
|
SDL_Log("No cameras available?");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user