Using callback mode
Callbacks are used to asynchronously access camera image data and status information.
You can use callbacks to provide custom code to execute when performing camera operations such as accessing encoded video or viewfinder frames. Using callbacks provides a lot of flexibility to control what occurs in your application when a function executes. For example, you can use callbacks to perform image processing or to save data to disk. Callback functions execute in a separate thread, so you need to be sure that your code is thread-safe through the use of appropriate thread synchronization primitives (mutexes, semaphores, condvars, etc.).
Callbacks are deregistered when the operation started by one of the above functions completes. For example, when the camera_stop_viewfinder() function is invoked, any callbacks registered during the camera_start_viewfinder() function call are deregistered.
These are the callback signatures for various Camera library functions:
- status_callback:
- This callback is invoked when non-image data relevant to the state of the camera is being reported.
For example, a change in autofocus state, or a disk space warning. The callback has the following signature:
void function_name( camera_handle_t, camera_devstatus_t, uint16_t, void* );where:-
camera_handle_t — The handle of the camera invoking the callback.
-
camera_devstatus_t — The status event that occurred.
-
uint16_t — Any extra data associated with the status event that occurred.
-
void* — The user-specified arg argument.
-
- video_callback:
- This callback is invoked when an uncompressed video frame becomes available.
The callback has the following signature:
void function_name( camera_handle_t, camera_buffer_t*, void* );-
camera_handle_t — The handle of the camera invoking the callback.
-
camera_buffer_t* — A pointer to a camera_buffer_t structure which describes the video frame. This data is only guaranteed to be valid while your callback function is executing.
-
void* — The user-specified arg argument.
Note:On platforms that advertise the CAMERA_FEATURE_PREVIEWISVIDEO feature, video frames are not explicitly available. Instead, use the frames returned by the viewfinder_callback. -
- viewfinder_callback:
- This callback is invoked when a viewfinder
buffer becomes available. The viewfinder is rendered to a Screen
window by the operating system. You are not required to add display
code, unless you need to perform custom output using some other
mechanism. The callback has the following signature:
void function_name( camera_handle_t, camera_buffer_t*, void* );-
camera_handle_t — The handle of the camera invoking the callback.
-
camera_buffer_t* — A pointer to a camera_buffer_t structure which describes the viewfinder frame. This data is only guaranteed to be valid while your callback function is executing.
-
void* — The user-specified arg argument.
-
- enc_video_callback:
- This callback is invoked when an encoded video frame becomes available. The callback has the following signature:
void function_name( camera_handle_t, camera_buffer_t*, void* );-
camera_handle_t: The handle of the camera invoking the callback.
-
camera_buffer_t*: A pointer to a camera_buffer_t structure which describes the encoded frame. This data is only guaranteed to be valid while your callback function is executing.
-
void*: The user-specified arg argument.
-
