mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-20 06:21:09 +00:00
Use SDL_bool instead an int return code in the SDL API
Most SDL functions used to indicate success or failure using an int return code. These functions have been changed to return SDL_bool. Here is a coccinelle patch to change code that previously compared the return value to 0 and changes it to a boolean test: @ bool_return_type @ identifier func =~ "^(SDL_AddEventWatch|SDL_AddHintCallback|SDL_AddSurfaceAlternateImage|SDL_AddVulkanRenderSemaphores|SDL_BindAudioStream|SDL_BindAudioStreams|SDL_BlitSurface|SDL_BlitSurface9Grid|SDL_BlitSurfaceScaled|SDL_BlitSurfaceTiled|SDL_BlitSurfaceTiledWithScale|SDL_BlitSurfaceUnchecked|SDL_BlitSurfaceUncheckedScaled|SDL_CaptureMouse|SDL_ClearAudioStream|SDL_ClearClipboardData|SDL_ClearComposition|SDL_ClearError|SDL_ClearProperty|SDL_ClearSurface|SDL_CloseIO|SDL_CloseStorage|SDL_ConvertAudioSamples|SDL_ConvertEventToRenderCoordinates|SDL_ConvertPixels|SDL_ConvertPixelsAndColorspace|SDL_CopyFile|SDL_CopyProperties|SDL_CopyStorageFile|SDL_CreateDirectory|SDL_CreateStorageDirectory|SDL_CreateWindowAndRenderer|SDL_DateTimeToTime|SDL_DestroyWindowSurface|SDL_DetachVirtualJoystick|SDL_DisableScreenSaver|SDL_EnableScreenSaver|SDL_EnumerateDirectory|SDL_EnumerateProperties|SDL_EnumerateStorageDirectory|SDL_FillSurfaceRect|SDL_FillSurfaceRects|SDL_FlashWindow|SDL_FlipSurface|SDL_FlushAudioStream|SDL_FlushRenderer|SDL_GL_DestroyContext|SDL_GL_GetAttribute|SDL_GL_GetSwapInterval|SDL_GL_LoadLibrary|SDL_GL_MakeCurrent|SDL_GL_SetAttribute|SDL_GL_SetSwapInterval|SDL_GL_SwapWindow|SDL_GetAudioDeviceFormat|SDL_GetAudioStreamFormat|SDL_GetCameraFormat|SDL_GetClosestFullscreenDisplayMode|SDL_GetCurrentRenderOutputSize|SDL_GetCurrentTime|SDL_GetDXGIOutputInfo|SDL_GetDateTimeLocalePreferences|SDL_GetDisplayBounds|SDL_GetDisplayUsableBounds|SDL_GetGDKDefaultUser|SDL_GetGDKTaskQueue|SDL_GetGamepadSensorData|SDL_GetGamepadTouchpadFinger|SDL_GetHapticEffectStatus|SDL_GetJoystickBall|SDL_GetMasksForPixelFormat|SDL_GetPathInfo|SDL_GetRectUnion|SDL_GetRectUnionFloat|SDL_GetRenderClipRect|SDL_GetRenderColorScale|SDL_GetRenderDrawBlendMode|SDL_GetRenderDrawColor|SDL_GetRenderDrawColorFloat|SDL_GetRenderLogicalPresentation|SDL_GetRenderLogicalPresentationRect|SDL_GetRenderOutputSize|SDL_GetRenderSafeArea|SDL_GetRenderScale|SDL_GetRenderVSync|SDL_GetRenderViewport|SDL_GetSensorData|SDL_GetStorageFileSize|SDL_GetStoragePathInfo|SDL_GetSurfaceAlphaMod|SDL_GetSurfaceBlendMode|SDL_GetSurfaceClipRect|SDL_GetSurfaceColorKey|SDL_GetSurfaceColorMod|SDL_GetTextInputArea|SDL_GetTextureAlphaMod|SDL_GetTextureAlphaModFloat|SDL_GetTextureBlendMode|SDL_GetTextureColorMod|SDL_GetTextureColorModFloat|SDL_GetTextureScaleMode|SDL_GetTextureSize|SDL_GetWindowAspectRatio|SDL_GetWindowBordersSize|SDL_GetWindowMaximumSize|SDL_GetWindowMinimumSize|SDL_GetWindowPosition|SDL_GetWindowRelativeMouseMode|SDL_GetWindowSafeArea|SDL_GetWindowSize|SDL_GetWindowSizeInPixels|SDL_GetWindowSurfaceVSync|SDL_HideCursor|SDL_HideWindow|SDL_Init|SDL_InitHapticRumble|SDL_InitSubSystem|SDL_LoadWAV|SDL_LoadWAV_IO|SDL_LockAudioStream|SDL_LockProperties|SDL_LockSurface|SDL_LockTexture|SDL_LockTextureToSurface|SDL_MaximizeWindow|SDL_MinimizeWindow|SDL_MixAudio|SDL_OpenURL|SDL_OutOfMemory|SDL_PauseAudioDevice|SDL_PauseAudioStreamDevice|SDL_PauseHaptic|SDL_PlayHapticRumble|SDL_PremultiplyAlpha|SDL_PremultiplySurfaceAlpha|SDL_PushEvent|SDL_PutAudioStreamData|SDL_RaiseWindow|SDL_ReadStorageFile|SDL_ReadSurfacePixel|SDL_ReadSurfacePixelFloat|SDL_RegisterApp|SDL_ReloadGamepadMappings|SDL_RemovePath|SDL_RemoveStoragePath|SDL_RemoveTimer|SDL_RenamePath|SDL_RenameStoragePath|SDL_RenderClear|SDL_RenderCoordinatesFromWindow|SDL_RenderCoordinatesToWindow|SDL_RenderFillRect|SDL_RenderFillRects|SDL_RenderGeometry|SDL_RenderGeometryRaw|SDL_RenderLine|SDL_RenderLines|SDL_RenderPoint|SDL_RenderPoints|SDL_RenderPresent|SDL_RenderRect|SDL_RenderRects|SDL_RenderTexture|SDL_RenderTexture9Grid|SDL_RenderTextureRotated|SDL_RenderTextureTiled|SDL_RequestAndroidPermission|SDL_RestoreWindow|SDL_ResumeAudioDevice|SDL_ResumeAudioStreamDevice|SDL_ResumeHaptic|SDL_RumbleGamepad|SDL_RumbleGamepadTriggers|SDL_RumbleJoystick|SDL_RumbleJoystickTriggers|SDL_RunHapticEffect|SDL_SaveBMP|SDL_SaveBMP_IO|SDL_SendAndroidMessage|SDL_SendGamepadEffect|SDL_SendJoystickEffect|SDL_SendJoystickVirtualSensorData|SDL_SetAppMetadata|SDL_SetAppMetadataProperty|SDL_SetAudioDeviceGain|SDL_SetAudioPostmixCallback|SDL_SetAudioStreamFormat|SDL_SetAudioStreamFrequencyRatio|SDL_SetAudioStreamGain|SDL_SetAudioStreamGetCallback|SDL_SetAudioStreamInputChannelMap|SDL_SetAudioStreamOutputChannelMap|SDL_SetAudioStreamPutCallback|SDL_SetBooleanProperty|SDL_SetClipboardData|SDL_SetClipboardText|SDL_SetCursor|SDL_SetFloatProperty|SDL_SetGamepadLED|SDL_SetGamepadMapping|SDL_SetGamepadPlayerIndex|SDL_SetGamepadSensorEnabled|SDL_SetHapticAutocenter|SDL_SetHapticGain|SDL_SetJoystickLED|SDL_SetJoystickPlayerIndex|SDL_SetJoystickVirtualAxis|SDL_SetJoystickVirtualBall|SDL_SetJoystickVirtualButton|SDL_SetJoystickVirtualHat|SDL_SetJoystickVirtualTouchpad|SDL_SetLinuxThreadPriority|SDL_SetLinuxThreadPriorityAndPolicy|SDL_SetLogPriorityPrefix|SDL_SetMemoryFunctions|SDL_SetNumberProperty|SDL_SetPaletteColors|SDL_SetPointerProperty|SDL_SetPointerPropertyWithCleanup|SDL_SetPrimarySelectionText|SDL_SetRenderClipRect|SDL_SetRenderColorScale|SDL_SetRenderDrawBlendMode|SDL_SetRenderDrawColor|SDL_SetRenderDrawColorFloat|SDL_SetRenderLogicalPresentation|SDL_SetRenderScale|SDL_SetRenderTarget|SDL_SetRenderVSync|SDL_SetRenderViewport|SDL_SetScancodeName|SDL_SetStringProperty|SDL_SetSurfaceAlphaMod|SDL_SetSurfaceBlendMode|SDL_SetSurfaceColorKey|SDL_SetSurfaceColorMod|SDL_SetSurfaceColorspace|SDL_SetSurfacePalette|SDL_SetSurfaceRLE|SDL_SetTLS|SDL_SetTextInputArea|SDL_SetTextureAlphaMod|SDL_SetTextureAlphaModFloat|SDL_SetTextureBlendMode|SDL_SetTextureColorMod|SDL_SetTextureColorModFloat|SDL_SetTextureScaleMode|SDL_SetThreadPriority|SDL_SetWindowAlwaysOnTop|SDL_SetWindowAspectRatio|SDL_SetWindowBordered|SDL_SetWindowFocusable|SDL_SetWindowFullscreen|SDL_SetWindowFullscreenMode|SDL_SetWindowHitTest|SDL_SetWindowIcon|SDL_SetWindowKeyboardGrab|SDL_SetWindowMaximumSize|SDL_SetWindowMinimumSize|SDL_SetWindowModalFor|SDL_SetWindowMouseGrab|SDL_SetWindowMouseRect|SDL_SetWindowOpacity|SDL_SetWindowPosition|SDL_SetWindowRelativeMouseMode|SDL_SetWindowResizable|SDL_SetWindowShape|SDL_SetWindowSize|SDL_SetWindowSurfaceVSync|SDL_SetWindowTitle|SDL_SetiOSAnimationCallback|SDL_ShowAndroidToast|SDL_ShowCursor|SDL_ShowMessageBox|SDL_ShowSimpleMessageBox|SDL_ShowWindow|SDL_ShowWindowSystemMenu|SDL_StartTextInput|SDL_StartTextInputWithProperties|SDL_StopHapticEffect|SDL_StopHapticEffects|SDL_StopHapticRumble|SDL_StopTextInput|SDL_SyncWindow|SDL_TimeToDateTime|SDL_TryLockMutex|SDL_TryLockRWLockForReading|SDL_TryLockRWLockForWriting|SDL_TryWaitSemaphore|SDL_UnlockAudioStream|SDL_UpdateHapticEffect|SDL_UpdateNVTexture|SDL_UpdateTexture|SDL_UpdateWindowSurface|SDL_UpdateWindowSurfaceRects|SDL_UpdateYUVTexture|SDL_Vulkan_CreateSurface|SDL_Vulkan_LoadLibrary|SDL_WaitConditionTimeout|SDL_WaitSemaphoreTimeout|SDL_WarpMouseGlobal|SDL_WriteStorageFile|SDL_WriteSurfacePixel|SDL_WriteSurfacePixelFloat)$"; @@ ( func( ... ) - == 0 | - func( + !func( ... ) - < 0 | - func( + !func( ... ) - != 0 | - func( + !func( ... ) - == -1 )
This commit is contained in:
@@ -82,14 +82,14 @@ char *SDL_GetCameraThreadName(SDL_Camera *device, char *buf, size_t buflen)
|
||||
return buf;
|
||||
}
|
||||
|
||||
int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator)
|
||||
bool SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator)
|
||||
{
|
||||
SDL_assert(data != NULL);
|
||||
if (data->allocated_specs <= data->num_specs) {
|
||||
const int newalloc = data->allocated_specs ? (data->allocated_specs * 2) : 16;
|
||||
void *ptr = SDL_realloc(data->specs, sizeof (SDL_CameraSpec) * newalloc);
|
||||
if (!ptr) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
data->specs = (SDL_CameraSpec *) ptr;
|
||||
data->allocated_specs = newalloc;
|
||||
@@ -105,7 +105,7 @@ int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_C
|
||||
|
||||
data->num_specs++;
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -113,14 +113,14 @@ int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_C
|
||||
|
||||
// These get used when a device is disconnected or fails. Apps that ignore the
|
||||
// loss notifications will get black frames but otherwise keep functioning.
|
||||
static int ZombieWaitDevice(SDL_Camera *device)
|
||||
static bool ZombieWaitDevice(SDL_Camera *device)
|
||||
{
|
||||
if (!SDL_AtomicGet(&device->shutdown)) {
|
||||
// !!! FIXME: this is bad for several reasons (uses double, could be precalculated, doesn't track elasped time).
|
||||
const double duration = ((double) device->actual_spec.framerate_denominator / ((double) device->actual_spec.framerate_numerator));
|
||||
SDL_Delay((Uint32) (duration * 1000.0));
|
||||
}
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static size_t GetFrameBufLen(const SDL_CameraSpec *spec)
|
||||
@@ -145,7 +145,7 @@ static size_t GetFrameBufLen(const SDL_CameraSpec *spec)
|
||||
return wxh * SDL_BYTESPERPIXEL(fmt);
|
||||
}
|
||||
|
||||
static int ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
{
|
||||
const SDL_CameraSpec *spec = &device->actual_spec;
|
||||
|
||||
@@ -155,7 +155,7 @@ static int ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *ti
|
||||
device->zombie_pixels = (Uint8 *)SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen);
|
||||
if (!device->zombie_pixels) {
|
||||
*timestampNS = 0;
|
||||
return 0; // oh well, say there isn't a frame yet, so we'll go back to waiting. Maybe allocation will succeed later...?
|
||||
return SDL_CAMERA_FRAME_SKIP; // oh well, say there isn't a frame yet, so we'll go back to waiting. Maybe allocation will succeed later...?
|
||||
}
|
||||
|
||||
Uint8 *dst = device->zombie_pixels;
|
||||
@@ -212,7 +212,7 @@ static int ZombieAcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *ti
|
||||
SDL_Log("CAMERA: dev[%p] Acquired Zombie frame, timestamp %llu", device, (unsigned long long) *timestampNS);
|
||||
#endif
|
||||
|
||||
return 1; // frame is available.
|
||||
return SDL_CAMERA_FRAME_READY; // frame is available.
|
||||
}
|
||||
|
||||
static void ZombieReleaseFrame(SDL_Camera *device, SDL_Surface *frame) // Reclaim frame->pixels and frame->pitch!
|
||||
@@ -650,8 +650,10 @@ void SDL_CloseCamera(SDL_Camera *camera)
|
||||
ClosePhysicalCamera(device);
|
||||
}
|
||||
|
||||
int SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec)
|
||||
SDL_bool SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec)
|
||||
{
|
||||
bool result;
|
||||
|
||||
if (!camera) {
|
||||
return SDL_InvalidParamError("camera");
|
||||
} else if (!spec) {
|
||||
@@ -660,36 +662,38 @@ int SDL_GetCameraFormat(SDL_Camera *camera, SDL_CameraSpec *spec)
|
||||
|
||||
SDL_Camera *device = (SDL_Camera *) camera; // currently there's no separation between physical and logical device.
|
||||
ObtainPhysicalCameraObj(device);
|
||||
const int retval = (device->permission > 0) ? 0 : SDL_SetError("Camera permission has not been granted");
|
||||
if (retval == 0) {
|
||||
if (device->permission > 0) {
|
||||
SDL_copyp(spec, &device->spec);
|
||||
result = true;
|
||||
} else {
|
||||
SDL_zerop(spec);
|
||||
result = SDL_SetError("Camera permission has not been granted");
|
||||
}
|
||||
ReleaseCamera(device);
|
||||
return 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
const char *SDL_GetCameraName(SDL_CameraID instance_id)
|
||||
{
|
||||
const char *retval = NULL;
|
||||
const char *result = NULL;
|
||||
SDL_Camera *device = ObtainPhysicalCamera(instance_id);
|
||||
if (device) {
|
||||
retval = SDL_GetPersistentString(device->name);
|
||||
result = SDL_GetPersistentString(device->name);
|
||||
ReleaseCamera(device);
|
||||
}
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_CameraPosition SDL_GetCameraPosition(SDL_CameraID instance_id)
|
||||
{
|
||||
SDL_CameraPosition retval = SDL_CAMERA_POSITION_UNKNOWN;
|
||||
SDL_CameraPosition result = SDL_CAMERA_POSITION_UNKNOWN;
|
||||
SDL_Camera *device = ObtainPhysicalCamera(instance_id);
|
||||
if (device) {
|
||||
retval = device->position;
|
||||
result = device->position;
|
||||
ReleaseCamera(device);
|
||||
}
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -706,12 +710,12 @@ SDL_CameraID *SDL_GetCameras(int *count)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_CameraID *retval = NULL;
|
||||
SDL_CameraID *result = NULL;
|
||||
|
||||
SDL_LockRWLockForReading(camera_driver.device_hash_lock);
|
||||
int num_devices = SDL_AtomicGet(&camera_driver.device_count);
|
||||
retval = (SDL_CameraID *) SDL_malloc((num_devices + 1) * sizeof (SDL_CameraID));
|
||||
if (!retval) {
|
||||
result = (SDL_CameraID *) SDL_malloc((num_devices + 1) * sizeof (SDL_CameraID));
|
||||
if (!result) {
|
||||
num_devices = 0;
|
||||
} else {
|
||||
int devs_seen = 0;
|
||||
@@ -719,17 +723,17 @@ SDL_CameraID *SDL_GetCameras(int *count)
|
||||
const void *value;
|
||||
void *iter = NULL;
|
||||
while (SDL_IterateHashTable(camera_driver.device_hash, &key, &value, &iter)) {
|
||||
retval[devs_seen++] = (SDL_CameraID) (uintptr_t) key;
|
||||
result[devs_seen++] = (SDL_CameraID) (uintptr_t) key;
|
||||
}
|
||||
|
||||
SDL_assert(devs_seen == num_devices);
|
||||
retval[devs_seen] = 0; // null-terminated.
|
||||
result[devs_seen] = 0; // null-terminated.
|
||||
}
|
||||
SDL_UnlockRWLock(camera_driver.device_hash_lock);
|
||||
|
||||
*count = num_devices;
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_CameraSpec **SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *count)
|
||||
@@ -745,14 +749,14 @@ SDL_CameraSpec **SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *co
|
||||
|
||||
int i;
|
||||
int num_specs = device->num_specs;
|
||||
SDL_CameraSpec **retval = (SDL_CameraSpec **) SDL_malloc(((num_specs + 1) * sizeof(*retval)) + (num_specs * sizeof (**retval)));
|
||||
if (retval) {
|
||||
SDL_CameraSpec *specs = (SDL_CameraSpec *)(retval + (num_specs + 1));
|
||||
SDL_CameraSpec **result = (SDL_CameraSpec **) SDL_malloc(((num_specs + 1) * sizeof(*result)) + (num_specs * sizeof (**result)));
|
||||
if (result) {
|
||||
SDL_CameraSpec *specs = (SDL_CameraSpec *)(result + (num_specs + 1));
|
||||
SDL_memcpy(specs, device->all_specs, num_specs * sizeof(*specs));
|
||||
for (i = 0; i < num_specs; ++i) {
|
||||
retval[i] = specs++;
|
||||
result[i] = specs++;
|
||||
}
|
||||
retval[i] = NULL;
|
||||
result[i] = NULL;
|
||||
|
||||
if (count) {
|
||||
*count = num_specs;
|
||||
@@ -761,7 +765,7 @@ SDL_CameraSpec **SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *co
|
||||
|
||||
ReleaseCamera(device);
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -806,9 +810,9 @@ bool SDL_CameraThreadIterate(SDL_Camera *device)
|
||||
Uint64 timestampNS = 0;
|
||||
|
||||
// AcquireFrame SHOULD NOT BLOCK, as we are holding a lock right now. Block in WaitDevice instead!
|
||||
const int rc = device->AcquireFrame(device, device->acquire_surface, ×tampNS);
|
||||
const SDL_CameraFrameResult rc = device->AcquireFrame(device, device->acquire_surface, ×tampNS);
|
||||
|
||||
if (rc == 1) { // new frame acquired!
|
||||
if (rc == SDL_CAMERA_FRAME_READY) { // new frame acquired!
|
||||
#if DEBUG_CAMERA
|
||||
SDL_Log("CAMERA: New frame available! pixels=%p pitch=%d", device->acquire_surface->pixels, device->acquire_surface->pitch);
|
||||
#endif
|
||||
@@ -842,12 +846,11 @@ bool SDL_CameraThreadIterate(SDL_Camera *device)
|
||||
acquired = device->acquire_surface;
|
||||
slist->timestampNS = timestampNS;
|
||||
}
|
||||
} else if (rc == 0) { // no frame available yet; not an error.
|
||||
} else if (rc == SDL_CAMERA_FRAME_SKIP) { // no frame available yet; not an error.
|
||||
#if 0 //DEBUG_CAMERA
|
||||
SDL_Log("CAMERA: No frame available yet.");
|
||||
#endif
|
||||
} else { // fatal error!
|
||||
SDL_assert(rc == -1);
|
||||
#if DEBUG_CAMERA
|
||||
SDL_Log("CAMERA: dev[%p] error AcquireFrame: %s", device, SDL_GetError());
|
||||
#endif
|
||||
@@ -931,7 +934,7 @@ static int SDLCALL CameraThread(void *devicep)
|
||||
SDL_CameraThreadSetup(device);
|
||||
|
||||
do {
|
||||
if (device->WaitDevice(device) < 0) {
|
||||
if (!device->WaitDevice(device)) {
|
||||
SDL_CameraDisconnected(device); // doh. (but don't break out of the loop, just be a zombie for now!)
|
||||
}
|
||||
} while (SDL_CameraThreadIterate(device));
|
||||
@@ -1091,7 +1094,7 @@ SDL_Camera *SDL_OpenCamera(SDL_CameraID instance_id, const SDL_CameraSpec *spec)
|
||||
closest.width, closest.height, SDL_GetPixelFormatName(closest.format), closest.framerate_numerator, closest.framerate_denominator);
|
||||
#endif
|
||||
|
||||
if (camera_driver.impl.OpenDevice(device, &closest) < 0) {
|
||||
if (!camera_driver.impl.OpenDevice(device, &closest)) {
|
||||
ClosePhysicalCamera(device); // in case anything is half-initialized.
|
||||
ReleaseCamera(device);
|
||||
return NULL;
|
||||
@@ -1219,7 +1222,7 @@ SDL_Surface *SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_Surface *retval = NULL;
|
||||
SDL_Surface *result = NULL;
|
||||
|
||||
// frames are in this list from newest to oldest, so find the end of the list...
|
||||
SurfaceList *slistprev = &device->filled_output_surfaces;
|
||||
@@ -1234,7 +1237,7 @@ SDL_Surface *SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS)
|
||||
if (timestampNS) {
|
||||
*timestampNS = slist->timestampNS;
|
||||
}
|
||||
retval = slist->surface;
|
||||
result = slist->surface;
|
||||
slistprev->next = slist->next; // remove from filled list.
|
||||
slist->next = device->app_held_output_surfaces.next; // add to app_held list.
|
||||
device->app_held_output_surfaces.next = slist;
|
||||
@@ -1242,15 +1245,13 @@ SDL_Surface *SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS)
|
||||
|
||||
ReleaseCamera(device);
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
int SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame)
|
||||
void SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame)
|
||||
{
|
||||
if (!camera) {
|
||||
return SDL_InvalidParamError("camera");
|
||||
} else if (frame == NULL) {
|
||||
return SDL_InvalidParamError("frame");
|
||||
if (!camera || !frame) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_Camera *device = (SDL_Camera *) camera; // currently there's no separation between physical and logical device.
|
||||
@@ -1267,7 +1268,7 @@ int SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame)
|
||||
|
||||
if (!slist) {
|
||||
ReleaseCamera(device);
|
||||
return SDL_SetError("Surface was not acquired from this camera, or was already released");
|
||||
return;
|
||||
}
|
||||
|
||||
// this pointer was owned by the backend (DMA memory or whatever), clear it out.
|
||||
@@ -1287,28 +1288,26 @@ int SDL_ReleaseCameraFrame(SDL_Camera *camera, SDL_Surface *frame)
|
||||
device->empty_output_surfaces.next = slist;
|
||||
|
||||
ReleaseCamera(device);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_CameraID SDL_GetCameraID(SDL_Camera *camera)
|
||||
{
|
||||
SDL_CameraID retval = 0;
|
||||
SDL_CameraID result = 0;
|
||||
if (!camera) {
|
||||
SDL_InvalidParamError("camera");
|
||||
} else {
|
||||
SDL_Camera *device = (SDL_Camera *) camera; // currently there's no separation between physical and logical device.
|
||||
ObtainPhysicalCameraObj(device);
|
||||
retval = device->instance_id;
|
||||
result = device->instance_id;
|
||||
ReleaseCamera(device);
|
||||
}
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
SDL_PropertiesID SDL_GetCameraProperties(SDL_Camera *camera)
|
||||
{
|
||||
SDL_PropertiesID retval = 0;
|
||||
SDL_PropertiesID result = 0;
|
||||
if (!camera) {
|
||||
SDL_InvalidParamError("camera");
|
||||
} else {
|
||||
@@ -1317,26 +1316,26 @@ SDL_PropertiesID SDL_GetCameraProperties(SDL_Camera *camera)
|
||||
if (device->props == 0) {
|
||||
device->props = SDL_CreateProperties();
|
||||
}
|
||||
retval = device->props;
|
||||
result = device->props;
|
||||
ReleaseCamera(device);
|
||||
}
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
int SDL_GetCameraPermissionState(SDL_Camera *camera)
|
||||
{
|
||||
int retval;
|
||||
int result;
|
||||
if (!camera) {
|
||||
retval = SDL_InvalidParamError("camera");
|
||||
SDL_InvalidParamError("camera");
|
||||
result = -1;
|
||||
} else {
|
||||
SDL_Camera *device = (SDL_Camera *) camera; // currently there's no separation between physical and logical device.
|
||||
ObtainPhysicalCameraObj(device);
|
||||
retval = device->permission;
|
||||
result = device->permission;
|
||||
ReleaseCamera(device);
|
||||
}
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -1408,7 +1407,7 @@ static void NukeCameraHashItem(const void *key, const void *value, void *data)
|
||||
// no-op, keys and values in this hashtable are treated as Plain Old Data and don't get freed here.
|
||||
}
|
||||
|
||||
int SDL_CameraInit(const char *driver_name)
|
||||
SDL_bool SDL_CameraInit(const char *driver_name)
|
||||
{
|
||||
if (SDL_GetCurrentCameraDriver()) {
|
||||
SDL_QuitCamera(); // shutdown driver if already running.
|
||||
@@ -1416,13 +1415,13 @@ int SDL_CameraInit(const char *driver_name)
|
||||
|
||||
SDL_RWLock *device_hash_lock = SDL_CreateRWLock(); // create this early, so if it fails we don't have to tear down the whole camera subsystem.
|
||||
if (!device_hash_lock) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
SDL_HashTable *device_hash = SDL_CreateHashTable(NULL, 8, HashCameraID, MatchCameraID, NukeCameraHashItem, false);
|
||||
if (!device_hash) {
|
||||
SDL_DestroyRWLock(device_hash_lock);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Select the proper camera driver
|
||||
@@ -1440,7 +1439,7 @@ int SDL_CameraInit(const char *driver_name)
|
||||
if (!driver_name_copy) {
|
||||
SDL_DestroyRWLock(device_hash_lock);
|
||||
SDL_DestroyHashTable(device_hash);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
while (driver_attempt && (*driver_attempt != 0) && !initialized) {
|
||||
@@ -1501,7 +1500,7 @@ int SDL_CameraInit(const char *driver_name)
|
||||
SDL_zero(camera_driver);
|
||||
SDL_DestroyRWLock(device_hash_lock);
|
||||
SDL_DestroyHashTable(device_hash);
|
||||
return -1; // No driver was available, so fail.
|
||||
return false; // No driver was available, so fail.
|
||||
}
|
||||
|
||||
CompleteCameraEntryPoints();
|
||||
@@ -1509,7 +1508,7 @@ int SDL_CameraInit(const char *driver_name)
|
||||
// Make sure we have a list of devices available at startup...
|
||||
camera_driver.impl.DetectDevices();
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
// This is an internal function, so SDL_PumpEvents() can check for pending camera device events.
|
||||
|
||||
@@ -24,10 +24,10 @@
|
||||
#define SDL_camera_c_h_
|
||||
|
||||
// Initialize the camera subsystem
|
||||
int SDL_CameraInit(const char *driver_name);
|
||||
extern SDL_bool SDL_CameraInit(const char *driver_name);
|
||||
|
||||
// Shutdown the camera subsystem
|
||||
void SDL_QuitCamera(void);
|
||||
extern void SDL_QuitCamera(void);
|
||||
|
||||
// "Pump" the event queue.
|
||||
extern void SDL_UpdateCamera(void);
|
||||
|
||||
@@ -64,7 +64,14 @@ typedef struct CameraFormatAddData
|
||||
int allocated_specs;
|
||||
} CameraFormatAddData;
|
||||
|
||||
int SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator);
|
||||
bool SDL_AddCameraFormat(CameraFormatAddData *data, SDL_PixelFormat format, SDL_Colorspace colorspace, int w, int h, int framerate_numerator, int framerate_denominator);
|
||||
|
||||
typedef enum SDL_CameraFrameResult
|
||||
{
|
||||
SDL_CAMERA_FRAME_ERROR,
|
||||
SDL_CAMERA_FRAME_SKIP,
|
||||
SDL_CAMERA_FRAME_READY
|
||||
} SDL_CameraFrameResult;
|
||||
|
||||
typedef struct SurfaceList
|
||||
{
|
||||
@@ -89,8 +96,8 @@ struct SDL_Camera
|
||||
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_Camera *device);
|
||||
int (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS);
|
||||
bool (*WaitDevice)(SDL_Camera *device);
|
||||
SDL_CameraFrameResult (*AcquireFrame)(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS);
|
||||
void (*ReleaseFrame)(SDL_Camera *device, SDL_Surface *frame);
|
||||
|
||||
// All supported formats/dimensions for this device.
|
||||
@@ -161,10 +168,10 @@ struct SDL_Camera
|
||||
typedef struct SDL_CameraDriverImpl
|
||||
{
|
||||
void (*DetectDevices)(void);
|
||||
int (*OpenDevice)(SDL_Camera *device, const SDL_CameraSpec *spec);
|
||||
bool (*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!
|
||||
bool (*WaitDevice)(SDL_Camera *device);
|
||||
SDL_CameraFrameResult (*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);
|
||||
|
||||
@@ -150,7 +150,7 @@ struct SDL_PrivateCameraData
|
||||
SDL_CameraSpec requested_spec;
|
||||
};
|
||||
|
||||
static int SetErrorStr(const char *what, const char *errstr, const int rc)
|
||||
static bool SetErrorStr(const char *what, const char *errstr, const int rc)
|
||||
{
|
||||
char errbuf[128];
|
||||
if (!errstr) {
|
||||
@@ -185,7 +185,7 @@ static const char *CameraStatusStr(const camera_status_t rc)
|
||||
return NULL; // unknown error
|
||||
}
|
||||
|
||||
static int SetCameraError(const char *what, const camera_status_t rc)
|
||||
static bool SetCameraError(const char *what, const camera_status_t rc)
|
||||
{
|
||||
return SetErrorStr(what, CameraStatusStr(rc), (int) rc);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ static const char *MediaStatusStr(const media_status_t rc)
|
||||
return NULL; // unknown error
|
||||
}
|
||||
|
||||
static int SetMediaError(const char *what, const media_status_t rc)
|
||||
static bool SetMediaError(const char *what, const media_status_t rc)
|
||||
{
|
||||
return SetErrorStr(what, MediaStatusStr(rc), (int) rc);
|
||||
}
|
||||
@@ -233,7 +233,7 @@ static int SetMediaError(const char *what, const media_status_t rc)
|
||||
|
||||
static ACameraManager *cameraMgr = NULL;
|
||||
|
||||
static int CreateCameraManager(void)
|
||||
static bool CreateCameraManager(void)
|
||||
{
|
||||
SDL_assert(cameraMgr == NULL);
|
||||
|
||||
@@ -241,7 +241,7 @@ static int CreateCameraManager(void)
|
||||
if (!cameraMgr) {
|
||||
return SDL_SetError("Error creating ACameraManager");
|
||||
}
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void DestroyCameraManager(void)
|
||||
@@ -289,14 +289,14 @@ static Uint32 format_sdl_to_android(SDL_PixelFormat fmt)
|
||||
}
|
||||
}
|
||||
|
||||
static int ANDROIDCAMERA_WaitDevice(SDL_Camera *device)
|
||||
static bool ANDROIDCAMERA_WaitDevice(SDL_Camera *device)
|
||||
{
|
||||
return 0; // this isn't used atm, since we run our own thread via onImageAvailable callbacks.
|
||||
return true; // this isn't used atm, since we run our own thread via onImageAvailable callbacks.
|
||||
}
|
||||
|
||||
static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
{
|
||||
int retval = 1;
|
||||
SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY;
|
||||
media_status_t res;
|
||||
AImage *image = NULL;
|
||||
|
||||
@@ -307,7 +307,8 @@ static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Ui
|
||||
SDL_assert(res != AMEDIA_IMGREADER_NO_BUFFER_AVAILABLE); // we should only be here if onImageAvailable was called.
|
||||
|
||||
if (res != AMEDIA_OK) {
|
||||
return SetMediaError("Error AImageReader_acquireNextImage", res);
|
||||
SetMediaError("Error AImageReader_acquireNextImage", res);
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
|
||||
int64_t atimestamp = 0;
|
||||
@@ -336,7 +337,7 @@ static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Ui
|
||||
|
||||
frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen);
|
||||
if (frame->pixels == NULL) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
int32_t row_stride = 0;
|
||||
Uint8 *dst = frame->pixels;
|
||||
@@ -355,7 +356,7 @@ static int ANDROIDCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Ui
|
||||
|
||||
pAImage_delete(image);
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void ANDROIDCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
@@ -458,7 +459,7 @@ static void ANDROIDCAMERA_CloseDevice(SDL_Camera *device)
|
||||
}
|
||||
|
||||
// this is where the "opening" of the camera happens, after permission is granted.
|
||||
static int PrepareCamera(SDL_Camera *device)
|
||||
static bool PrepareCamera(SDL_Camera *device)
|
||||
{
|
||||
SDL_assert(device->hidden != NULL);
|
||||
|
||||
@@ -512,7 +513,7 @@ static int PrepareCamera(SDL_Camera *device)
|
||||
return SetMediaError("Error AImageReader_setImageListener", res2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void SDLCALL CameraPermissionCallback(void *userdata, const char *permission, SDL_bool granted)
|
||||
@@ -521,7 +522,7 @@ static void SDLCALL CameraPermissionCallback(void *userdata, const char *permiss
|
||||
if (device->hidden != NULL) { // if device was already closed, don't send an event.
|
||||
if (!granted) {
|
||||
SDL_CameraPermissionOutcome(device, false); // sorry, permission denied.
|
||||
} else if (PrepareCamera(device) < 0) { // permission given? Actually open the camera now.
|
||||
} else if (!PrepareCamera(device)) { // 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_CameraDisconnected(device);
|
||||
} else {
|
||||
@@ -534,7 +535,7 @@ static void SDLCALL CameraPermissionCallback(void *userdata, const char *permiss
|
||||
}
|
||||
|
||||
|
||||
static int ANDROIDCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
static bool 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.
|
||||
@@ -552,19 +553,19 @@ static int ANDROIDCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *sp
|
||||
|
||||
device->hidden = (struct SDL_PrivateCameraData *) SDL_calloc(1, sizeof (struct SDL_PrivateCameraData));
|
||||
if (device->hidden == NULL) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPhysicalCamera(device); // ref'd until permission callback fires.
|
||||
|
||||
// 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_RequestAndroidPermission("android.permission.CAMERA", CameraPermissionCallback, device) < 0) {
|
||||
if (!SDL_RequestAndroidPermission("android.permission.CAMERA", CameraPermissionCallback, device)) {
|
||||
UnrefPhysicalCamera(device);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 0; // we don't open the camera until permission is granted, so always succeed for now.
|
||||
return true; // we don't open the camera until permission is granted, so always succeed for now.
|
||||
}
|
||||
|
||||
static void ANDROIDCAMERA_FreeDeviceHandle(SDL_Camera *device)
|
||||
@@ -864,7 +865,7 @@ static bool ANDROIDCAMERA_Init(SDL_CameraDriverImpl *impl)
|
||||
dlclose(libcamera2);
|
||||
}
|
||||
|
||||
if (CreateCameraManager() < 0) {
|
||||
if (!CreateCameraManager()) {
|
||||
dlclose(libmedia);
|
||||
dlclose(libcamera2);
|
||||
return false;
|
||||
|
||||
@@ -141,14 +141,14 @@ static bool CheckCameraPermissions(SDL_Camera *device)
|
||||
}
|
||||
@end
|
||||
|
||||
static int COREMEDIA_WaitDevice(SDL_Camera *device)
|
||||
static bool COREMEDIA_WaitDevice(SDL_Camera *device)
|
||||
{
|
||||
return 0; // this isn't used atm, since we run our own thread out of Grand Central Dispatch.
|
||||
return true; // this isn't used atm, since we run our own thread out of Grand Central Dispatch.
|
||||
}
|
||||
|
||||
static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
{
|
||||
int retval = 1;
|
||||
SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY;
|
||||
SDLPrivateCameraData *hidden = (__bridge SDLPrivateCameraData *) device->hidden;
|
||||
CMSampleBufferRef sample_buffer = hidden.current_sample;
|
||||
hidden.current_sample = NULL;
|
||||
@@ -185,7 +185,7 @@ static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64
|
||||
const size_t buflen = pitch * frame->h;
|
||||
frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen);
|
||||
if (frame->pixels == NULL) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
frame->pitch = pitch;
|
||||
SDL_memcpy(frame->pixels, CVPixelBufferGetBaseAddress(image), buflen);
|
||||
@@ -203,7 +203,7 @@ static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64
|
||||
frame->pitch = (int)CVPixelBufferGetBytesPerRowOfPlane(image, 0); // this is what SDL3 currently expects
|
||||
frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen);
|
||||
if (frame->pixels == NULL) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
Uint8 *dst = frame->pixels;
|
||||
for (int i = 0; i < numPlanes; i++) {
|
||||
@@ -219,7 +219,7 @@ static int COREMEDIA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64
|
||||
|
||||
CVPixelBufferUnlockBaseAddress(image, 0);
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void COREMEDIA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
@@ -248,7 +248,7 @@ static void COREMEDIA_CloseDevice(SDL_Camera *device)
|
||||
}
|
||||
}
|
||||
|
||||
static int COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
static bool COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
{
|
||||
AVCaptureDevice *avdevice = (__bridge AVCaptureDevice *) device->handle;
|
||||
|
||||
@@ -364,7 +364,7 @@ static int COREMEDIA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
|
||||
CheckCameraPermissions(device); // check right away, in case the process is already granted permission.
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void COREMEDIA_FreeDeviceHandle(SDL_Camera *device)
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
#include "../SDL_syscamera.h"
|
||||
|
||||
static int DUMMYCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
static bool DUMMYCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
@@ -33,14 +33,15 @@ static void DUMMYCAMERA_CloseDevice(SDL_Camera *device)
|
||||
{
|
||||
}
|
||||
|
||||
static int DUMMYCAMERA_WaitDevice(SDL_Camera *device)
|
||||
static bool DUMMYCAMERA_WaitDevice(SDL_Camera *device)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int DUMMYCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult DUMMYCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
SDL_Unsupported();
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
|
||||
static void DUMMYCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
|
||||
@@ -34,17 +34,17 @@
|
||||
|
||||
EM_JS_DEPS(sdlcamera, "$dynCall");
|
||||
|
||||
static int EMSCRIPTENCAMERA_WaitDevice(SDL_Camera *device)
|
||||
static bool EMSCRIPTENCAMERA_WaitDevice(SDL_Camera *device)
|
||||
{
|
||||
SDL_assert(!"This shouldn't be called"); // we aren't using SDL's internal thread.
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int EMSCRIPTENCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult 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) {
|
||||
return -1;
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
|
||||
*timestampNS = SDL_GetTicksNS(); // best we can do here.
|
||||
@@ -67,13 +67,13 @@ static int EMSCRIPTENCAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
|
||||
if (!rc) {
|
||||
SDL_free(rgba);
|
||||
return 0; // something went wrong, maybe shutting down; just don't return a frame.
|
||||
return SDL_CAMERA_FRAME_ERROR; // something went wrong, maybe shutting down; just don't return a frame.
|
||||
}
|
||||
|
||||
frame->pixels = rgba;
|
||||
frame->pitch = device->actual_spec.width * 4;
|
||||
|
||||
return 1;
|
||||
return SDL_CAMERA_FRAME_READY;
|
||||
}
|
||||
|
||||
static void EMSCRIPTENCAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
@@ -110,7 +110,7 @@ static void SDLEmscriptenCameraPermissionOutcome(SDL_Camera *device, int approve
|
||||
SDL_CameraPermissionOutcome(device, approved ? true : false);
|
||||
}
|
||||
|
||||
static int EMSCRIPTENCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
static bool 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
|
||||
@@ -203,7 +203,7 @@ static int EMSCRIPTENCAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec
|
||||
});
|
||||
}, 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.
|
||||
return true; // the real work waits until the user approves a camera.
|
||||
}
|
||||
|
||||
static void EMSCRIPTENCAMERA_FreeDeviceHandle(SDL_Camera *device)
|
||||
|
||||
@@ -347,7 +347,7 @@ typedef struct SDL_PrivateCameraData
|
||||
int pitch;
|
||||
} SDL_PrivateCameraData;
|
||||
|
||||
static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device)
|
||||
static bool MEDIAFOUNDATION_WaitDevice(SDL_Camera *device)
|
||||
{
|
||||
SDL_assert(device->hidden->current_sample == NULL);
|
||||
|
||||
@@ -358,7 +358,7 @@ static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device)
|
||||
DWORD stream_flags = 0;
|
||||
const HRESULT ret = IMFSourceReader_ReadSample(srcreader, (DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, NULL, &stream_flags, NULL, &sample);
|
||||
if (FAILED(ret)) {
|
||||
return -1; // ruh roh.
|
||||
return false; // ruh roh.
|
||||
}
|
||||
|
||||
// we currently ignore stream_flags format changes, but my _hope_ is that IMFSourceReader is handling this and
|
||||
@@ -368,7 +368,7 @@ static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device)
|
||||
if (sample != NULL) {
|
||||
break;
|
||||
} else if (stream_flags & (MF_SOURCE_READERF_ERROR | MF_SOURCE_READERF_ENDOFSTREAM)) {
|
||||
return -1; // apparently this camera has gone down. :/
|
||||
return false; // apparently this camera has gone down. :/
|
||||
}
|
||||
|
||||
// otherwise, there was some minor burp, probably; just try again.
|
||||
@@ -376,7 +376,7 @@ static int MEDIAFOUNDATION_WaitDevice(SDL_Camera *device)
|
||||
|
||||
device->hidden->current_sample = sample;
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -421,17 +421,17 @@ static void SDLCALL CleanupIMFMediaBuffer(void *userdata, void *value)
|
||||
SDL_free(objs);
|
||||
}
|
||||
|
||||
static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
{
|
||||
SDL_assert(device->hidden->current_sample != NULL);
|
||||
|
||||
int retval = 1;
|
||||
|
||||
SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY;
|
||||
HRESULT ret;
|
||||
LONGLONG timestamp100NS = 0;
|
||||
SDL_IMFObjects *objs = (SDL_IMFObjects *) SDL_calloc(1, sizeof (SDL_IMFObjects));
|
||||
|
||||
if (objs == NULL) {
|
||||
return -1;
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
|
||||
objs->sample = device->hidden->current_sample;
|
||||
@@ -439,21 +439,21 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
|
||||
const SDL_PropertiesID surfprops = SDL_GetSurfaceProperties(frame);
|
||||
if (!surfprops) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
ret = IMFSample_GetSampleTime(objs->sample, ×tamp100NS);
|
||||
if (FAILED(ret)) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
|
||||
*timestampNS = timestamp100NS * 100; // the timestamps are in 100-nanosecond increments; move to full nanoseconds.
|
||||
}
|
||||
|
||||
ret = (retval < 0) ? E_FAIL : IMFSample_ConvertToContiguousBuffer(objs->sample, &objs->buffer); // IMFSample_GetBufferByIndex(objs->sample, 0, &objs->buffer);
|
||||
ret = (result == SDL_CAMERA_FRAME_ERROR) ? E_FAIL : IMFSample_ConvertToContiguousBuffer(objs->sample, &objs->buffer); // IMFSample_GetBufferByIndex(objs->sample, 0, &objs->buffer);
|
||||
|
||||
if (FAILED(ret)) {
|
||||
SDL_free(objs);
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
BYTE *pixels = NULL;
|
||||
LONG pitch = 0;
|
||||
@@ -463,25 +463,25 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
DWORD buflen = 0;
|
||||
ret = IMF2DBuffer2_Lock2DSize(objs->buffer2d2, MF2DBuffer_LockFlags_Read, &pixels, &pitch, &bufstart, &buflen);
|
||||
if (FAILED(ret)) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
CleanupIMF2DBuffer2(NULL, objs);
|
||||
} else {
|
||||
frame->pixels = pixels;
|
||||
frame->pitch = (int) pitch;
|
||||
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer2, NULL) < 0) {
|
||||
retval = -1;
|
||||
if (!SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer2, NULL)) {
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
}
|
||||
} else if (SUCCEEDED(IMFMediaBuffer_QueryInterface(objs->buffer, &SDL_IID_IMF2DBuffer, (void **)&objs->buffer2d))) {
|
||||
ret = IMF2DBuffer_Lock2D(objs->buffer2d, &pixels, &pitch);
|
||||
if (FAILED(ret)) {
|
||||
CleanupIMF2DBuffer(NULL, objs);
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
frame->pixels = pixels;
|
||||
frame->pitch = (int) pitch;
|
||||
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer, NULL) < 0) {
|
||||
retval = -1;
|
||||
if (!SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMF2DBuffer, NULL)) {
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -489,7 +489,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
ret = IMFMediaBuffer_Lock(objs->buffer, &pixels, &maxlen, ¤tlen);
|
||||
if (FAILED(ret)) {
|
||||
CleanupIMFMediaBuffer(NULL, objs);
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
pitch = (LONG) device->hidden->pitch;
|
||||
if (pitch < 0) { // image rows are reversed.
|
||||
@@ -497,18 +497,18 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
}
|
||||
frame->pixels = pixels;
|
||||
frame->pitch = (int) pitch;
|
||||
if (SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMFMediaBuffer, NULL) < 0) {
|
||||
retval = -1;
|
||||
if (!SDL_SetPointerPropertyWithCleanup(surfprops, PROP_SURFACE_IMFOBJS_POINTER, objs, CleanupIMFMediaBuffer, NULL)) {
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (retval < 0) {
|
||||
if (result != SDL_CAMERA_FRAME_READY) {
|
||||
*timestampNS = 0;
|
||||
}
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void MEDIAFOUNDATION_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
@@ -522,11 +522,11 @@ static void MEDIAFOUNDATION_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
|
||||
#else
|
||||
|
||||
static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
{
|
||||
SDL_assert(device->hidden->current_sample != NULL);
|
||||
|
||||
int retval = 1;
|
||||
SDL_CameraFrameResult result = SDL_CAMERA_FRAME_READY;
|
||||
HRESULT ret;
|
||||
LONGLONG timestamp100NS = 0;
|
||||
|
||||
@@ -535,21 +535,21 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
|
||||
const SDL_PropertiesID surfprops = SDL_GetSurfaceProperties(frame);
|
||||
if (!surfprops) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
ret = IMFSample_GetSampleTime(sample, ×tamp100NS);
|
||||
if (FAILED(ret)) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
|
||||
*timestampNS = timestamp100NS * 100; // the timestamps are in 100-nanosecond increments; move to full nanoseconds.
|
||||
}
|
||||
|
||||
IMFMediaBuffer *buffer = NULL;
|
||||
ret = (retval < 0) ? E_FAIL : IMFSample_ConvertToContiguousBuffer(sample, &buffer); // IMFSample_GetBufferByIndex(sample, 0, &buffer);
|
||||
ret = (result < 0) ? E_FAIL : IMFSample_ConvertToContiguousBuffer(sample, &buffer); // IMFSample_GetBufferByIndex(sample, 0, &buffer);
|
||||
|
||||
if (FAILED(ret)) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
IMF2DBuffer *buffer2d = NULL;
|
||||
IMF2DBuffer2 *buffer2d2 = NULL;
|
||||
@@ -561,11 +561,11 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
DWORD buflen = 0;
|
||||
ret = IMF2DBuffer2_Lock2DSize(buffer2d2, MF2DBuffer_LockFlags_Read, &pixels, &pitch, &bufstart, &buflen);
|
||||
if (FAILED(ret)) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen);
|
||||
if (frame->pixels == NULL) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
SDL_memcpy(frame->pixels, pixels, buflen);
|
||||
frame->pitch = (int)pitch;
|
||||
@@ -576,7 +576,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
} else if (SUCCEEDED(IMFMediaBuffer_QueryInterface(buffer, &SDL_IID_IMF2DBuffer, (void **)&buffer2d))) {
|
||||
ret = IMF2DBuffer_Lock2D(buffer2d, &pixels, &pitch);
|
||||
if (FAILED(ret)) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
BYTE *bufstart = pixels;
|
||||
const DWORD buflen = (SDL_abs((int)pitch) * frame->w) * frame->h;
|
||||
@@ -585,7 +585,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
}
|
||||
frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen);
|
||||
if (frame->pixels == NULL) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
SDL_memcpy(frame->pixels, bufstart, buflen);
|
||||
frame->pitch = (int)pitch;
|
||||
@@ -597,7 +597,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
DWORD maxlen = 0, currentlen = 0;
|
||||
ret = IMFMediaBuffer_Lock(buffer, &pixels, &maxlen, ¤tlen);
|
||||
if (FAILED(ret)) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
BYTE *bufstart = pixels;
|
||||
pitch = (LONG)device->hidden->pitch;
|
||||
@@ -607,7 +607,7 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
}
|
||||
frame->pixels = SDL_aligned_alloc(SDL_GetSIMDAlignment(), buflen);
|
||||
if (frame->pixels == NULL) {
|
||||
retval = -1;
|
||||
result = SDL_CAMERA_FRAME_ERROR;
|
||||
} else {
|
||||
SDL_memcpy(frame->pixels, bufstart, buflen);
|
||||
frame->pitch = (int)pitch;
|
||||
@@ -620,11 +620,11 @@ static int MEDIAFOUNDATION_AcquireFrame(SDL_Camera *device, SDL_Surface *frame,
|
||||
|
||||
IMFSample_Release(sample);
|
||||
|
||||
if (retval < 0) {
|
||||
if (result != SDL_CAMERA_FRAME_READY) {
|
||||
*timestampNS = 0;
|
||||
}
|
||||
|
||||
return retval;
|
||||
return result;
|
||||
}
|
||||
|
||||
static void MEDIAFOUNDATION_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
@@ -695,7 +695,7 @@ done:
|
||||
}
|
||||
|
||||
|
||||
static int MEDIAFOUNDATION_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
static bool MEDIAFOUNDATION_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
{
|
||||
const char *utf8symlink = (const char *) device->handle;
|
||||
IMFAttributes *attrs = NULL;
|
||||
@@ -825,7 +825,7 @@ static int MEDIAFOUNDATION_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *
|
||||
|
||||
#undef CHECK_HRESULT
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
|
||||
failed:
|
||||
|
||||
@@ -861,7 +861,7 @@ failed:
|
||||
}
|
||||
SDL_free(wstrsymlink);
|
||||
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void MEDIAFOUNDATION_FreeDeviceHandle(SDL_Camera *device)
|
||||
|
||||
@@ -86,8 +86,7 @@ static int (*PIPEWIRE_pw_core_disconnect)(struct pw_core *);
|
||||
static struct pw_node_info * (*PIPEWIRE_pw_node_info_merge)(struct pw_node_info *info, const struct pw_node_info *update, bool reset);
|
||||
static void (*PIPEWIRE_pw_node_info_free)(struct pw_node_info *info);
|
||||
static struct pw_stream *(*PIPEWIRE_pw_stream_new)(struct pw_core *, const char *, struct pw_properties *);
|
||||
static void (*PIPEWIRE_pw_stream_add_listener)(struct pw_stream *stream, struct spa_hook *listener,
|
||||
const struct pw_stream_events *events, void *data);
|
||||
static void (*PIPEWIRE_pw_stream_add_listener)(struct pw_stream *stream, struct spa_hook *listener, const struct pw_stream_events *events, void *data);
|
||||
static void (*PIPEWIRE_pw_stream_destroy)(struct pw_stream *);
|
||||
static int (*PIPEWIRE_pw_stream_connect)(struct pw_stream *, enum pw_direction, uint32_t, enum pw_stream_flags,
|
||||
const struct spa_pod **, uint32_t);
|
||||
@@ -104,26 +103,25 @@ static int (*PIPEWIRE_pw_properties_setf)(struct pw_properties *, const char *,
|
||||
static const char *pipewire_library = SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC;
|
||||
static void *pipewire_handle = NULL;
|
||||
|
||||
static int pipewire_dlsym(const char *fn, void **addr)
|
||||
static bool pipewire_dlsym(const char *fn, void **addr)
|
||||
{
|
||||
*addr = SDL_LoadFunction(pipewire_handle, fn);
|
||||
if (!*addr) {
|
||||
// Don't call SDL_SetError(): SDL_LoadFunction already did.
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
#define SDL_PIPEWIRE_SYM(x) \
|
||||
if (!pipewire_dlsym(#x, (void **)(char *)&PIPEWIRE_##x)) { \
|
||||
return -1; \
|
||||
}
|
||||
#define SDL_PIPEWIRE_SYM(x) \
|
||||
if (!pipewire_dlsym(#x, (void **)(char *)&PIPEWIRE_##x)) \
|
||||
return false
|
||||
|
||||
static int load_pipewire_library(void)
|
||||
static bool load_pipewire_library(void)
|
||||
{
|
||||
pipewire_handle = SDL_LoadObject(pipewire_library);
|
||||
return pipewire_handle ? 0 : -1;
|
||||
return pipewire_handle ? true : false;
|
||||
}
|
||||
|
||||
static void unload_pipewire_library(void)
|
||||
@@ -138,9 +136,9 @@ static void unload_pipewire_library(void)
|
||||
|
||||
#define SDL_PIPEWIRE_SYM(x) PIPEWIRE_##x = x
|
||||
|
||||
static int load_pipewire_library(void)
|
||||
static bool load_pipewire_library(void)
|
||||
{
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void unload_pipewire_library(void)
|
||||
@@ -150,7 +148,7 @@ static void unload_pipewire_library(void)
|
||||
|
||||
#endif // SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC
|
||||
|
||||
static int load_pipewire_syms(void)
|
||||
static bool load_pipewire_syms(void)
|
||||
{
|
||||
SDL_PIPEWIRE_SYM(pw_get_library_version);
|
||||
SDL_PIPEWIRE_SYM(pw_check_library_version);
|
||||
@@ -192,18 +190,18 @@ static int load_pipewire_syms(void)
|
||||
SDL_PIPEWIRE_SYM(pw_properties_set);
|
||||
SDL_PIPEWIRE_SYM(pw_properties_setf);
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int init_pipewire_library(void)
|
||||
static bool init_pipewire_library(void)
|
||||
{
|
||||
if (!load_pipewire_library()) {
|
||||
if (!load_pipewire_syms()) {
|
||||
if (load_pipewire_library()) {
|
||||
if (load_pipewire_syms()) {
|
||||
PIPEWIRE_pw_init(NULL, NULL);
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void deinit_pipewire_library(void)
|
||||
@@ -293,9 +291,9 @@ static uint32_t param_clear(struct spa_list *param_list, uint32_t id)
|
||||
}
|
||||
|
||||
#if PW_CHECK_VERSION(0,3,60)
|
||||
#define SPA_PARAMS_INFO_SEQ(p) ((p).seq)
|
||||
#define SPA_PARAMS_INFO_SEQ(p) ((p).seq)
|
||||
#else
|
||||
#define SPA_PARAMS_INFO_SEQ(p) ((p).padding[0])
|
||||
#define SPA_PARAMS_INFO_SEQ(p) ((p).padding[0])
|
||||
#endif
|
||||
|
||||
static struct param *param_add(struct spa_list *params,
|
||||
@@ -472,7 +470,7 @@ static const struct pw_stream_events stream_events = {
|
||||
.process = on_process,
|
||||
};
|
||||
|
||||
static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
static bool PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
{
|
||||
struct pw_properties *props;
|
||||
const struct spa_pod *params[3];
|
||||
@@ -481,11 +479,11 @@ static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *s
|
||||
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));
|
||||
|
||||
if (!device) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
device->hidden = (struct SDL_PrivateCameraData *) SDL_calloc(1, sizeof (struct SDL_PrivateCameraData));
|
||||
if (device->hidden == NULL) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
pw_array_init(&device->hidden->buffers, 64);
|
||||
|
||||
@@ -497,13 +495,12 @@ static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *s
|
||||
PW_KEY_TARGET_OBJECT, device->name,
|
||||
NULL);
|
||||
if (props == NULL) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
device->hidden->stream = PIPEWIRE_pw_stream_new(hotplug.core,
|
||||
"SDL PipeWire Camera", props);
|
||||
device->hidden->stream = PIPEWIRE_pw_stream_new(hotplug.core, "SDL PipeWire Camera", props);
|
||||
if (device->hidden->stream == NULL) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
PIPEWIRE_pw_stream_add_listener(device->hidden->stream,
|
||||
@@ -525,12 +522,12 @@ static int PIPEWIRECAMERA_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *s
|
||||
PW_STREAM_FLAG_AUTOCONNECT |
|
||||
PW_STREAM_FLAG_MAP_BUFFERS,
|
||||
params, n_params)) < 0) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void PIPEWIRECAMERA_CloseDevice(SDL_Camera *device)
|
||||
@@ -550,15 +547,15 @@ static void PIPEWIRECAMERA_CloseDevice(SDL_Camera *device)
|
||||
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
|
||||
}
|
||||
|
||||
static int PIPEWIRECAMERA_WaitDevice(SDL_Camera *device)
|
||||
static bool PIPEWIRECAMERA_WaitDevice(SDL_Camera *device)
|
||||
{
|
||||
PIPEWIRE_pw_thread_loop_lock(hotplug.loop);
|
||||
PIPEWIRE_pw_thread_loop_wait(hotplug.loop);
|
||||
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
{
|
||||
struct pw_buffer *b;
|
||||
|
||||
@@ -574,7 +571,7 @@ static int PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, U
|
||||
}
|
||||
if (b == NULL) {
|
||||
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
|
||||
return 0;
|
||||
return SDL_CAMERA_FRAME_SKIP;
|
||||
}
|
||||
|
||||
#if PW_CHECK_VERSION(1,0,5)
|
||||
@@ -587,7 +584,7 @@ static int PIPEWIRECAMERA_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, U
|
||||
|
||||
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
|
||||
|
||||
return 1;
|
||||
return SDL_CAMERA_FRAME_READY;
|
||||
}
|
||||
|
||||
static void PIPEWIRECAMERA_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
@@ -625,7 +622,7 @@ static void collect_rates(CameraFormatAddData *data, struct param *p, SDL_PixelF
|
||||
SPA_FALLTHROUGH;
|
||||
case SPA_CHOICE_Enum:
|
||||
for (i = 0; i < n_vals; i++) {
|
||||
if (SDL_AddCameraFormat(data, sdlfmt, colorspace, size->width, size->height, rates[i].num, rates[i].denom) < 0) {
|
||||
if (!SDL_AddCameraFormat(data, sdlfmt, colorspace, size->width, size->height, rates[i].num, rates[i].denom)) {
|
||||
return; // Probably out of memory; we'll go with what we have, if anything.
|
||||
}
|
||||
}
|
||||
@@ -976,7 +973,7 @@ static bool pipewire_server_version_at_least(int major, int minor, int patch)
|
||||
}
|
||||
|
||||
// The hotplug thread
|
||||
static int hotplug_loop_init(void)
|
||||
static bool hotplug_loop_init(void)
|
||||
{
|
||||
int res;
|
||||
|
||||
@@ -1028,7 +1025,7 @@ static int hotplug_loop_init(void)
|
||||
PW_REQUIRED_MAJOR, PW_REQUIRED_MINOR, PW_REQUIRED_PATCH);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1037,24 +1034,24 @@ static void PIPEWIRECAMERA_Deinitialize(void)
|
||||
if (pipewire_initialized) {
|
||||
if (hotplug.loop) {
|
||||
PIPEWIRE_pw_thread_loop_lock(hotplug.loop);
|
||||
}
|
||||
}
|
||||
if (hotplug.registry) {
|
||||
spa_hook_remove(&hotplug.registry_listener);
|
||||
PIPEWIRE_pw_proxy_destroy((struct pw_proxy*)hotplug.registry);
|
||||
}
|
||||
spa_hook_remove(&hotplug.registry_listener);
|
||||
PIPEWIRE_pw_proxy_destroy((struct pw_proxy *)hotplug.registry);
|
||||
}
|
||||
if (hotplug.core) {
|
||||
spa_hook_remove(&hotplug.core_listener);
|
||||
PIPEWIRE_pw_core_disconnect(hotplug.core);
|
||||
}
|
||||
spa_hook_remove(&hotplug.core_listener);
|
||||
PIPEWIRE_pw_core_disconnect(hotplug.core);
|
||||
}
|
||||
if (hotplug.context) {
|
||||
PIPEWIRE_pw_context_destroy(hotplug.context);
|
||||
}
|
||||
}
|
||||
if (hotplug.loop) {
|
||||
PIPEWIRE_pw_thread_loop_unlock(hotplug.loop);
|
||||
PIPEWIRE_pw_thread_loop_destroy(hotplug.loop);
|
||||
}
|
||||
}
|
||||
deinit_pipewire_library();
|
||||
spa_zero(hotplug);
|
||||
spa_zero(hotplug);
|
||||
pipewire_initialized = false;
|
||||
}
|
||||
}
|
||||
@@ -1063,13 +1060,13 @@ static bool PIPEWIRECAMERA_Init(SDL_CameraDriverImpl *impl)
|
||||
{
|
||||
if (!pipewire_initialized) {
|
||||
|
||||
if (init_pipewire_library() < 0) {
|
||||
if (!init_pipewire_library()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
pipewire_initialized = true;
|
||||
|
||||
if (hotplug_loop_init() < 0) {
|
||||
if (!hotplug_loop_init()) {
|
||||
PIPEWIRECAMERA_Deinitialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -22,13 +22,14 @@
|
||||
|
||||
#ifdef SDL_CAMERA_DRIVER_V4L2
|
||||
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h> // low-level i/o
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h> // low-level i/o
|
||||
#include <stddef.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#ifndef V4L2_CAP_DEVICE_CAPS
|
||||
@@ -88,11 +89,11 @@ static int xioctl(int fh, int request, void *arg)
|
||||
return r;
|
||||
}
|
||||
|
||||
static int V4L2_WaitDevice(SDL_Camera *device)
|
||||
static bool V4L2_WaitDevice(SDL_Camera *device)
|
||||
{
|
||||
const int fd = device->hidden->fd;
|
||||
|
||||
int retval;
|
||||
int rc;
|
||||
|
||||
do {
|
||||
fd_set fds;
|
||||
@@ -103,22 +104,22 @@ static int V4L2_WaitDevice(SDL_Camera *device)
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100 * 1000;
|
||||
|
||||
retval = select(fd + 1, &fds, NULL, NULL, &tv);
|
||||
if ((retval == -1) && (errno == EINTR)) {
|
||||
retval = 0; // pretend it was a timeout, keep looping.
|
||||
rc = select(fd + 1, &fds, NULL, NULL, &tv);
|
||||
if ((rc == -1) && (errno == EINTR)) {
|
||||
rc = 0; // pretend it was a timeout, keep looping.
|
||||
}
|
||||
|
||||
// Thread is requested to shut down
|
||||
if (SDL_AtomicGet(&device->shutdown)) {
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
} while (retval == 0);
|
||||
} while (rc == 0);
|
||||
|
||||
return retval;
|
||||
return false;
|
||||
}
|
||||
|
||||
static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
static SDL_CameraFrameResult V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *timestampNS)
|
||||
{
|
||||
const int fd = device->hidden->fd;
|
||||
const io_method io = device->hidden->io;
|
||||
@@ -129,15 +130,16 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim
|
||||
case IO_METHOD_READ:
|
||||
if (read(fd, device->hidden->buffers[0].start, size) == -1) {
|
||||
switch (errno) {
|
||||
case EAGAIN:
|
||||
return 0;
|
||||
case EAGAIN:
|
||||
return SDL_CAMERA_FRAME_SKIP;
|
||||
|
||||
case EIO:
|
||||
// Could ignore EIO, see spec.
|
||||
// fall through
|
||||
case EIO:
|
||||
// Could ignore EIO, see spec.
|
||||
// fall through
|
||||
|
||||
default:
|
||||
return SDL_SetError("read");
|
||||
default:
|
||||
SDL_SetError("read");
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,20 +156,22 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim
|
||||
|
||||
if (xioctl(fd, VIDIOC_DQBUF, &buf) == -1) {
|
||||
switch (errno) {
|
||||
case EAGAIN:
|
||||
return 0;
|
||||
case EAGAIN:
|
||||
return SDL_CAMERA_FRAME_SKIP;
|
||||
|
||||
case EIO:
|
||||
// Could ignore EIO, see spec.
|
||||
// fall through
|
||||
case EIO:
|
||||
// Could ignore EIO, see spec.
|
||||
// fall through
|
||||
|
||||
default:
|
||||
return SDL_SetError("VIDIOC_DQBUF: %d", errno);
|
||||
default:
|
||||
SDL_SetError("VIDIOC_DQBUF: %d", errno);
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if ((int)buf.index < 0 || (int)buf.index >= device->hidden->nb_buffers) {
|
||||
return SDL_SetError("invalid buffer index");
|
||||
SDL_SetError("invalid buffer index");
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
|
||||
frame->pixels = device->hidden->buffers[buf.index].start;
|
||||
@@ -189,16 +193,16 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim
|
||||
|
||||
if (xioctl(fd, VIDIOC_DQBUF, &buf) == -1) {
|
||||
switch (errno) {
|
||||
case EAGAIN:
|
||||
return 0;
|
||||
case EAGAIN:
|
||||
return SDL_CAMERA_FRAME_SKIP;
|
||||
|
||||
case EIO:
|
||||
// Could ignore EIO, see spec.
|
||||
case EIO:
|
||||
// Could ignore EIO, see spec.
|
||||
// fall through
|
||||
|
||||
// fall through
|
||||
|
||||
default:
|
||||
return SDL_SetError("VIDIOC_DQBUF");
|
||||
default:
|
||||
SDL_SetError("VIDIOC_DQBUF");
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,7 +214,8 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim
|
||||
}
|
||||
|
||||
if (i >= device->hidden->nb_buffers) {
|
||||
return SDL_SetError("invalid buffer index");
|
||||
SDL_SetError("invalid buffer index");
|
||||
return SDL_CAMERA_FRAME_ERROR;
|
||||
}
|
||||
|
||||
frame->pixels = (void*)buf.m.userptr;
|
||||
@@ -229,7 +234,7 @@ static int V4L2_AcquireFrame(SDL_Camera *device, SDL_Surface *frame, Uint64 *tim
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
return SDL_CAMERA_FRAME_READY;
|
||||
}
|
||||
|
||||
static void V4L2_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
@@ -289,7 +294,7 @@ static void V4L2_ReleaseFrame(SDL_Camera *device, SDL_Surface *frame)
|
||||
}
|
||||
}
|
||||
|
||||
static int EnqueueBuffers(SDL_Camera *device)
|
||||
static bool EnqueueBuffers(SDL_Camera *device)
|
||||
{
|
||||
const int fd = device->hidden->fd;
|
||||
const io_method io = device->hidden->io;
|
||||
@@ -335,17 +340,17 @@ static int EnqueueBuffers(SDL_Camera *device)
|
||||
|
||||
case IO_METHOD_INVALID: SDL_assert(!"Shouldn't have hit this"); break;
|
||||
}
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int AllocBufferRead(SDL_Camera *device, size_t buffer_size)
|
||||
static bool 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;
|
||||
return (device->hidden->buffers[0].start != NULL);
|
||||
}
|
||||
|
||||
static int AllocBufferMmap(SDL_Camera *device)
|
||||
static bool AllocBufferMmap(SDL_Camera *device)
|
||||
{
|
||||
const int fd = device->hidden->fd;
|
||||
int i;
|
||||
@@ -374,10 +379,10 @@ static int AllocBufferMmap(SDL_Camera *device)
|
||||
return SDL_SetError("mmap");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static int AllocBufferUserPtr(SDL_Camera *device, size_t buffer_size)
|
||||
static bool AllocBufferUserPtr(SDL_Camera *device, size_t buffer_size)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < device->hidden->nb_buffers; ++i) {
|
||||
@@ -385,10 +390,10 @@ static int AllocBufferUserPtr(SDL_Camera *device, size_t buffer_size)
|
||||
device->hidden->buffers[i].start = SDL_calloc(1, buffer_size);
|
||||
|
||||
if (!device->hidden->buffers[i].start) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void format_v4l2_to_sdl(Uint32 fmt, SDL_PixelFormat *format, SDL_Colorspace *colorspace)
|
||||
@@ -415,7 +420,7 @@ static Uint32 format_sdl_to_v4l2(SDL_PixelFormat fmt)
|
||||
CASE(V4L2_PIX_FMT_MJPEG, SDL_PIXELFORMAT_UNKNOWN);
|
||||
#undef CASE
|
||||
default:
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -470,7 +475,7 @@ static void V4L2_CloseDevice(SDL_Camera *device)
|
||||
}
|
||||
}
|
||||
|
||||
static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
static bool V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
{
|
||||
const V4L2DeviceHandle *handle = (const V4L2DeviceHandle *) device->handle;
|
||||
struct stat st;
|
||||
@@ -501,7 +506,7 @@ static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
device->hidden = (struct SDL_PrivateCameraData *) SDL_calloc(1, sizeof (struct SDL_PrivateCameraData));
|
||||
if (device->hidden == NULL) {
|
||||
close(fd);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
device->hidden->fd = fd;
|
||||
@@ -597,13 +602,15 @@ static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
|
||||
device->hidden->buffers = SDL_calloc(device->hidden->nb_buffers, sizeof(*device->hidden->buffers));
|
||||
if (!device->hidden->buffers) {
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t size, pitch;
|
||||
SDL_CalculateSurfaceSize(device->spec.format, device->spec.width, device->spec.height, &size, &pitch, false);
|
||||
if (!SDL_CalculateSurfaceSize(device->spec.format, device->spec.width, device->spec.height, &size, &pitch, false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int rc = 0;
|
||||
bool rc = true;
|
||||
switch (io) {
|
||||
case IO_METHOD_READ:
|
||||
rc = AllocBufferRead(device, size);
|
||||
@@ -622,10 +629,10 @@ static int V4L2_OpenDevice(SDL_Camera *device, const SDL_CameraSpec *spec)
|
||||
break;
|
||||
}
|
||||
|
||||
if (rc < 0) {
|
||||
return -1;
|
||||
} else if (EnqueueBuffers(device) < 0) {
|
||||
return -1;
|
||||
if (!rc) {
|
||||
return false;
|
||||
} else if (!EnqueueBuffers(device)) {
|
||||
return false;
|
||||
} else if (io != IO_METHOD_READ) {
|
||||
enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
if (xioctl(fd, VIDIOC_STREAMON, &type) == -1) {
|
||||
@@ -636,7 +643,7 @@ static int V4L2_OpenDevice(SDL_Camera *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_CameraPermissionOutcome(device, true);
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool FindV4L2CameraByBusInfoCallback(SDL_Camera *device, void *userdata)
|
||||
@@ -645,7 +652,7 @@ static bool FindV4L2CameraByBusInfoCallback(SDL_Camera *device, void *userdata)
|
||||
return (SDL_strcmp(handle->bus_info, (const char *) userdata) == 0);
|
||||
}
|
||||
|
||||
static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace, Uint32 v4l2fmt, int w, int h)
|
||||
static bool AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFormat sdlfmt, SDL_Colorspace colorspace, Uint32 v4l2fmt, int w, int h)
|
||||
{
|
||||
struct v4l2_frmivalenum frmivalenum;
|
||||
SDL_zero(frmivalenum);
|
||||
@@ -661,8 +668,8 @@ static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFor
|
||||
const float fps = (float) denominator / (float) numerator;
|
||||
SDL_Log("CAMERA: * Has discrete frame interval (%d / %d), fps=%f", numerator, denominator, fps);
|
||||
#endif
|
||||
if (SDL_AddCameraFormat(data, sdlfmt, colorspace, w, h, denominator, numerator) == -1) {
|
||||
return -1; // Probably out of memory; we'll go with what we have, if anything.
|
||||
if (!SDL_AddCameraFormat(data, sdlfmt, colorspace, w, h, denominator, numerator)) {
|
||||
return false; // Probably out of memory; we'll go with what we have, if anything.
|
||||
}
|
||||
frmivalenum.index++; // set up for the next one.
|
||||
} else if ((frmivalenum.type == V4L2_FRMIVAL_TYPE_STEPWISE) || (frmivalenum.type == V4L2_FRMIVAL_TYPE_CONTINUOUS)) {
|
||||
@@ -674,8 +681,8 @@ static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFor
|
||||
SDL_Log("CAMERA: * Has %s frame interval (%d / %d), fps=%f", (frmivalenum.type == V4L2_FRMIVAL_TYPE_STEPWISE) ? "stepwise" : "continuous", n, d, fps);
|
||||
#endif
|
||||
// SDL expects framerate, V4L2 provides interval
|
||||
if (SDL_AddCameraFormat(data, sdlfmt, colorspace, w, h, d, n) == -1) {
|
||||
return -1; // Probably out of memory; we'll go with what we have, if anything.
|
||||
if (!SDL_AddCameraFormat(data, sdlfmt, colorspace, w, h, d, n)) {
|
||||
return false; // Probably out of memory; we'll go with what we have, if anything.
|
||||
}
|
||||
d += (int) frmivalenum.stepwise.step.denominator;
|
||||
}
|
||||
@@ -683,7 +690,7 @@ static int AddCameraFormat(const int fd, CameraFormatAddData *data, SDL_PixelFor
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -756,7 +763,7 @@ static void MaybeAddDevice(const char *path)
|
||||
#if DEBUG_CAMERA
|
||||
SDL_Log("CAMERA: * Has discrete size %dx%d", w, h);
|
||||
#endif
|
||||
if (AddCameraFormat(fd, &add_data, sdlfmt, colorspace, fmtdesc.pixelformat, w, h) == -1) {
|
||||
if (!AddCameraFormat(fd, &add_data, sdlfmt, colorspace, fmtdesc.pixelformat, w, h)) {
|
||||
break; // Probably out of memory; we'll go with what we have, if anything.
|
||||
}
|
||||
frmsizeenum.index++; // set up for the next one.
|
||||
@@ -772,7 +779,7 @@ static void MaybeAddDevice(const char *path)
|
||||
#if DEBUG_CAMERA
|
||||
SDL_Log("CAMERA: * Has %s size %dx%d", (frmsizeenum.type == V4L2_FRMSIZE_TYPE_STEPWISE) ? "stepwise" : "continuous", w, h);
|
||||
#endif
|
||||
if (AddCameraFormat(fd, &add_data, sdlfmt, colorspace, fmtdesc.pixelformat, w, h) == -1) {
|
||||
if (!AddCameraFormat(fd, &add_data, sdlfmt, colorspace, fmtdesc.pixelformat, w, h)) {
|
||||
break; // Probably out of memory; we'll go with what we have, if anything.
|
||||
}
|
||||
}
|
||||
@@ -856,12 +863,14 @@ static void V4L2_Deinitialize(void)
|
||||
static void V4L2_DetectDevices(void)
|
||||
{
|
||||
#ifdef SDL_USE_LIBUDEV
|
||||
if (SDL_UDEV_Init() == 0) {
|
||||
if (SDL_UDEV_AddCallback(CameraUdevCallback) == 0) {
|
||||
if (SDL_UDEV_Init()) {
|
||||
if (SDL_UDEV_AddCallback(CameraUdevCallback)) {
|
||||
SDL_UDEV_Scan(); // Force a scan to build the initial device list
|
||||
}
|
||||
return;
|
||||
}
|
||||
#else
|
||||
#endif // SDL_USE_LIBUDEV
|
||||
|
||||
DIR *dirp = opendir("/dev");
|
||||
if (dirp) {
|
||||
struct dirent *dent;
|
||||
@@ -875,7 +884,6 @@ static void V4L2_DetectDevices(void)
|
||||
}
|
||||
closedir(dirp);
|
||||
}
|
||||
#endif // SDL_USE_LIBUDEV
|
||||
}
|
||||
|
||||
static bool V4L2_Init(SDL_CameraDriverImpl *impl)
|
||||
|
||||
Reference in New Issue
Block a user