sdlAcquireCameraFrame function

Pointer<SdlSurface> sdlAcquireCameraFrame(
  1. Pointer<SdlCamera> camera,
  2. Pointer<Uint64> timestampNs
)

Acquire a frame.

The frame is a memory pointer to the image data, whose size and format are given by the spec requested when opening the device.

This is a non blocking API. If there is a frame available, a non-NULL surface is returned, and timestampNS will be filled with a non-zero value.

Note that an error case can also return NULL, but a NULL by itself is normal and just signifies that a new frame is not yet available. Note that even if a camera device fails outright (a USB camera is unplugged while in use, etc), SDL will send an event separately to notify the app, but continue to provide blank frames at ongoing intervals until SDL_CloseCamera() is called, so real failure here is almost always an out of memory condition.

After use, the frame should be released with SDL_ReleaseCameraFrame(). If you don't do this, the system may stop providing more video!

Do not call SDL_DestroySurface() on the returned surface! It must be given back to the camera subsystem with SDL_ReleaseCameraFrame!

If the system is waiting for the user to approve access to the camera, as some platforms require, this will return NULL (no frames available); you should either wait for an SDL_EVENT_CAMERA_DEVICE_APPROVED (or SDL_EVENT_CAMERA_DEVICE_DENIED) event, or poll SDL_GetCameraPermissionState() occasionally until it returns non-zero.

\param camera opened camera device. \param timestampNS a pointer filled in with the frame's timestamp, or 0 on error. Can be NULL. \returns a new frame of video on success, NULL if none is currently available.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.1.3.

\sa SDL_ReleaseCameraFrame

extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_AcquireCameraFrame(SDL_Camera *camera, Uint64 *timestampNS)

Implementation

Pointer<SdlSurface> sdlAcquireCameraFrame(
    Pointer<SdlCamera> camera, Pointer<Uint64> timestampNs) {
  final sdlAcquireCameraFrameLookupFunction = libSdl3.lookupFunction<
      Pointer<SdlSurface> Function(
          Pointer<SdlCamera> camera, Pointer<Uint64> timestampNs),
      Pointer<SdlSurface> Function(Pointer<SdlCamera> camera,
          Pointer<Uint64> timestampNs)>('SDL_AcquireCameraFrame');
  return sdlAcquireCameraFrameLookupFunction(camera, timestampNs);
}