![]() |
Axoverlay 2 API
|
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include <sys/time.h>
Go to the source code of this file.
Data Structures | |
| struct | _axo_argb_entry |
Typedefs | |
| typedef struct _axo_settings | axo_settings |
| typedef struct _axo_props | axo_props |
| typedef struct _axo_match | axo_match |
| typedef struct _axo_buffer | axo_buffer |
| typedef struct _axo_request | axo_request |
| typedef struct _axo_submit | axo_submit |
| typedef struct _axo_err | axo_err |
| typedef enum _axo_err_code | axo_err_code |
| typedef enum _axo_format | axo_format |
| typedef enum _axo_format_flags | axo_format_flags |
| typedef struct _axo_detailed_format | axo_detailed_format |
| typedef struct _axo_argb_entry | axo_argb_entry |
Enumerations | |
| enum | _axo_err_code { AXO_ERR_INTERNAL = 0 , AXO_ERR_INVALID = 1 , AXO_ERR_UNSUPPORTED = 2 , AXO_ERR_WAIT = 3 , AXO_ERR_NO_STREAM = 4 , AXO_ERR_NOT_AVAILABLE = 5 } |
| enum | _axo_format { AXO_FORMAT_INVALID = 0 , AXO_FORMAT_ARGB32 = 1 , AXO_FORMAT_4BIT_PALETTE = 2 , AXO_FORMAT_1BIT_PALETTE = 3 , AXO_FORMAT_ARGB16 = 4 , AXO_FORMAT_COUNT } |
| enum | _axo_format_flags { AXO_FORMAT_FLAGS_NONE = 0 , AXO_FORMAT_FLAGS_COMPRESSED = 1 << 1 , AXO_FORMAT_FLAGS_GPU = 1 << 2 } |
Axoverlay 2 API
Copyright (C) 2023, Axis Communications AB
Axoverlay is a library which lets a client application draw custom overlays on video streams. Axoverlay is supported on the Artpec-7 platform and onwards. It's not supported on Ambarella platforms.
| typedef struct _axo_argb_entry axo_argb_entry |
A single entry in a color palette.
The possible values range from 0.0f to 1.0f. For alpha, a value of 1.0f means "fully
visible" and 0.0f means "fully transparent".
| typedef struct _axo_buffer axo_buffer |
Overlay buffer object.
A buffer represents a memory area into which image data can be drawn, to form a single frame of the overlay animation. The buffer is associated with a particular overlay.
| typedef struct _axo_detailed_format axo_detailed_format |
A specific storage format for pixels. Each axo_format, in combination with a compression mode and possibly other settings, determines a specific detailed format.
| typedef struct _axo_err axo_err |
Runtime error.
Many Axoverlay functions have a final parameter axo_err **err which represents the possibility of runtime error. The rules for axo_err are similar to glib's GError, including the possibility to pass err = NULL if client is not interested in handling (or knowing about) an error.
Client cannot create an axo_err object, only receive a pointer to it from Axoverlay. If client does receive an error back, client is responsible for freeing it using axo_err_clear.
Handling errors
Ignoring errors
| typedef enum _axo_err_code axo_err_code |
Error codes describing various classes of error.
| typedef enum _axo_format axo_format |
Colour format, specifying how colours are represented.
Client is able to choose from a set of supported formats. Not all formats may be supported on each hardware platform.
Formats with fewer bits per pixel are always more efficient from a performance point of view, but may be more difficult to work with from a client point of view.
Each axo_format also has a native storage format in memory which is described here. Note that when compression is used, the storage format will be different.
| typedef enum _axo_format_flags axo_format_flags |
Flags used to select a suitable axo_detailed_format. Currently, flags are only used to select a compressed pixel format for GPU rendering.
Flags are combined using bitwise OR to describe requirements.
When the GPU is used to render graphics, the recommended flags are (AXO_FORMAT_FLAGS_COMPRESSED | AXO_FORMAT_FLAGS_GPU).
When the CPU is used for rendering, AXO_FORMAT_FLAGS_NONE shall be selected.
Note that when a compressed format is selected, the rendering backend (e.g. GPU) must be set up to store pixels in that format. It is shown in the example programs how to do this correctly.
| typedef struct _axo_match axo_match |
Description of how to match an overlay against video streams.
| typedef struct _axo_props axo_props |
Overlay properties.
This object type is suitable for passing to axo_create_overlay or axo_adjust_overlay. After a successful call to either of these functions, the props object is reset. Re-using the object will have no effect, until it's modified again by the axo_props-family functions.
The axo_props object tracks modifications to existing properties. That is, the default policy is always to keep any property at its current or default value. If the axo_props object should be passed to axo_adjust_overlay, only those properties that you wish to adjust need to be set on the axo_props object.
| typedef struct _axo_request axo_request |
Overlay buffer request metadata.
Currently, no such metadata is defined and this type is reserved for future use.
| typedef struct _axo_settings axo_settings |
Object representing global settings which need to be set at library startup.
Currently, no such settings are defined and this type is reserved for future use.
| typedef struct _axo_submit axo_submit |
Overlay buffer submit metadata.
Currently, no such metadata is defined and this type is reserved for future use.
| enum _axo_err_code |
Error codes describing various classes of error.
| enum _axo_format |
Colour format, specifying how colours are represented.
Client is able to choose from a set of supported formats. Not all formats may be supported on each hardware platform.
Formats with fewer bits per pixel are always more efficient from a performance point of view, but may be more difficult to work with from a client point of view.
Each axo_format also has a native storage format in memory which is described here. Note that when compression is used, the storage format will be different.
| Enumerator | |
|---|---|
| AXO_FORMAT_ARGB32 | 8 bits unsigned each for alpha, red, green, blue Uncompressed ARGB32 is packed into one uint32 word per pixel. The alpha channel occupies the most significant bits of the word and so on. Example: uint32_t sample = a << 24 | r << 16 | g << 8 | b; |
| AXO_FORMAT_4BIT_PALETTE | 4 bits per pixel palette format. Two pixels are packed into each byte of the framebuffer. The lower-order nibble encodes the first pixel. The colour values for each pixel are looked up from a 16-entry palette. The palette to use should be specified using axo_props_set_palette. The nibble 0x0 refers to the first palette entry (index 0) and the nibble 0xf refers to the last palette entry (index 15). |
| AXO_FORMAT_1BIT_PALETTE | 1 bit per pixel palette format. Eight pixels are packed into each byte of the framebuffer. The least significant bit encodes the first pixel. The colour values for each pixel are looked up from a 2-entry palette. The palette to use should be specified using axo_props_set_palette. An unset bit refers to the first palette entry (index 0) and a set bit refers to the second palette entry (index 1). |
| AXO_FORMAT_ARGB16 | 4 bits unsigned each for alpha, red, green, blue; packed into one uint16 word per pixel. The alpha channel occupies the most significant bits of the word and so on. Example: uint16_t sample = (a & 0xF) << 12 | (r & 0xF) << 8 | (g & 0xF) << 4 | (b & 0xF); |
| AXO_FORMAT_COUNT | The number of possible axo_format values |
| enum _axo_format_flags |
Flags used to select a suitable axo_detailed_format. Currently, flags are only used to select a compressed pixel format for GPU rendering.
Flags are combined using bitwise OR to describe requirements.
When the GPU is used to render graphics, the recommended flags are (AXO_FORMAT_FLAGS_COMPRESSED | AXO_FORMAT_FLAGS_GPU).
When the CPU is used for rendering, AXO_FORMAT_FLAGS_NONE shall be selected.
Note that when a compressed format is selected, the rendering backend (e.g. GPU) must be set up to store pixels in that format. It is shown in the example programs how to do this correctly.
| Enumerator | |
|---|---|
| AXO_FORMAT_FLAGS_NONE | A blank set of flags selects the plain uncompressed format. The pixels will be stored in memory as documented under axo_format. |
| AXO_FORMAT_FLAGS_COMPRESSED | Select a compressed format if available. The compression may be lossless or lossy. If no such format is available, the uncompressed format is returned. |
| AXO_FORMAT_FLAGS_GPU | Select a format which is compatible with using the GPU for rendering |
Ask Axoverlay to adjust the specified overlay's properties.
To "adjust" means to modify overlay properties without re-creating the overlay. After a successful adjustment, the overlay does not need to be re-drawn.
Adjustment is not always possible. In those cases where it's not possible, it is instead necessary to remove the old overlay and create a new one with the desired properties.
| id | The ID number of the overlay that should be adjusted |
| props | The desired new properties for the overlay. After a successful call to this function, the object is reset. |
| err | Error return |
| bool axo_buffer_dma_buf_supported | ( | void | ) |
Check if exporting buffers as DMA buf is supported or not
| size_t axo_buffer_get_byte_size | ( | axo_buffer * | buffer | ) |
Get the size of a buffer, in bytes.
| buffer | The buffer in question |
| char* axo_buffer_get_data | ( | axo_buffer * | buffer, |
| axo_err ** | err | ||
| ) |
Get pointer to buffer data.
The pointer points to the start of the overlay buffer data, where application should draw.
| buffer | The buffer in question |
| err | Error return |
| int axo_buffer_get_dma_buf_fd | ( | axo_buffer * | buffer | ) |
Get DMA buf file descriptor for the buffer
DMA buf file descriptor representing the buffer memory
| buffer | The buffer in question |
| unsigned axo_buffer_get_height | ( | axo_buffer * | buffer | ) |
Get the height of a buffer, in pixels.
| buffer | The buffer in question |
| unsigned long axo_buffer_get_id | ( | axo_buffer * | buffer | ) |
Get the ID number of the buffer.
The combination of (overlay_id, buffer_id) is globally unique. However, ID numbers for deleted overlays and buffers may be recycled. The ID may be used to tell distinct buffers apart. This is useful in case the client needs to cache associated data for a particular buffer.
| buffer | The buffer in question |
| unsigned axo_buffer_get_width | ( | axo_buffer * | buffer | ) |
Get the width of a buffer, in pixels.
| buffer | The buffer in question |
| void axo_buffer_set_timestamp_to_submit | ( | axo_buffer * | buffer, |
| struct timeval | timestamp | ||
| ) |
Set the timestamp to submit the overlay buffer with. NOTE: the timestamp should be set BEFORE submitting the buffer by axo_submit_buffer.
| buffer | The buffer in question |
| timestamp | The timestamp to submit the buffer with |
Create a new overlay with requested properties.
| props | The properties object describing the overlay to be created. After a successful call to this function, the object is reset. |
| match | The match object describing which streams the overlay should be applied to |
| err | Error return |
| void axo_detailed_format_free | ( | axo_detailed_format * | detailed_format | ) |
Free an object of type axo_detailed_format.
| detailed_format | The object to free |
| void axo_detailed_format_get_aligned_size | ( | axo_detailed_format * | detailed_format, |
| unsigned | width, | ||
| unsigned | height, | ||
| unsigned * | aligned_width_out, | ||
| unsigned * | aligned_height_out | ||
| ) |
Return an appropriate overlay size for a given detailed format.
The user shall input their desired overlay size. This function then returns an aligned size which is suitable for passing to axo_props_set_size in combination with that detailed format.
The aligned size is never smaller than the original desired size.
The user is expected to draw a transparent or background colour to the extra padding pixels.
| detailed_format | The detailed overlay format to query alignment for |
| width | Desired overlay width |
| height | Desired overlay height |
| aligned_width_out | Location to store aligned overlay width |
| aligned_height_out | Location to store where aligned overlay height |
| uint32_t axo_detailed_format_get_drm_fourcc | ( | axo_detailed_format * | detailed_format | ) |
Get the Linux DRM "fourcc" code corresponding to this detailed format.
This corresponds to the attribute EGL_LINUX_DRM_FOURCC_EXT in the Khronos EGL extension EGL_EXT_image_dma_buf_import.
Not all Axoverlay formats have a matching fourcc code defined. A code of zero (DRM_FORMAT_INVALID) will be returned for these formats.
| detailed_format | The detailed format to get a fourcc for |
| uint64_t axo_detailed_format_get_drm_modifier | ( | axo_detailed_format * | detailed_format, |
| unsigned | plane | ||
| ) |
Get the Linux DRM "modifier" code corresponding to this detailed format.
This corresponds to the attributes EGL_DMA_BUF_PLANEx_MODIFIER_LO_EXT and EGL_DMA_BUF_PLANEx_MODIFIER_HI_EXT in the Khronos EGL extension EGL_EXT_image_dma_buf_import_modifiers where x is the plane number.
Note that HI refers to the high 32 bits of the modifier code and LO to the low 32 bits.
Multi-plane overlays are not supported at the moment, so the plane number is always zero.
The modifier code zero (DRM_FORMAT_MOD_NONE) is valid and will be returned for detailed formats that do not need a modifier.
| detailed_format | The detailed format to get a modifier code for |
| plane | Shall be set to 0 |
| void axo_err_clear | ( | axo_err ** | err | ) |
Clears the axo_err object.
If err or *err is NULL, does nothing. Otherwise, frees *err and sets *err to NULL.
| err | Error object to clear |
| axo_err_code axo_err_get_code | ( | axo_err * | err | ) |
Get error code from error object.
| err | Error object |
| const char* axo_err_get_message | ( | axo_err * | err | ) |
Get message string from error object.
The string remains valid until axo_err_clear is called.
| err | Error object |
| bool axo_get_aligned_size | ( | axo_format | format, |
| unsigned | width, | ||
| unsigned | height, | ||
| unsigned * | aligned_width_out, | ||
| unsigned * | aligned_height_out, | ||
| axo_err ** | err | ||
| ) |
Return an appropriate overlay size for an uncompressed overlay.
This is a shorthand for axo_detailed_format_get_aligned_size() in the case where the detailed format is just the uncompressed variant of the respective axo_format.
| format | Desired overlay format |
| width | Desired overlay width |
| height | Desired overlay height |
| aligned_width_out | Location to store aligned overlay width |
| aligned_height_out | Location to store where aligned overlay height |
| err | Error return |
| axo_buffer* axo_get_buffer | ( | int | id, |
| axo_request * | request, | ||
| axo_err ** | err | ||
| ) |
Request an overlay buffer for the overlay having ID number id.
The ID number should be one that was previously returned by axo_create_overlay.
This is a blocking and synchronous operation.
The returned buffer object references a memory area suitable for drawing into. Once the application is done drawing, the buffer object should be passed to axo_submit_buffer.
This function does not always complete successfully. Even during normal operation it will return error codes which the client must handle:
AXO_ERR_WAIT : A buffer did not become available within a reasonable amount of time. The timeout can vary between platforms and is selected to avoid blocking the client for too long. This commonly occurs when drawing high-framerate animation on a low framerate video stream.
Recommended action: Try again later, possibly skip a frame of animation.
AXO_ERR_NO_STREAM : The stream on which the overlay is placed has disconnected. No more buffers will ever be availabe. The client should soon receive a VDO stream event indicating that the stream has disconnected. This occurs whenever a stream disconnects and the client happens to call axo_get_buffer before receiving and handling the stream event.
Recommended action: Ignore the error and continue, expect a stream disconnect event soon.
| id | The ID number of the overlay in question |
| request | Unused; should be NULL |
| err | Error return |
| void axo_match_free | ( | axo_match * | match | ) |
Free a match object.
| match | The match object to free |
| axo_match* axo_match_new | ( | void | ) |
Create a new, blank match object.
The object is "blank" in the sense that it does not match any video streams.
The returned object has to be freed by axo_match_free.
| void axo_match_stream_id | ( | axo_match * | match, |
| int | id | ||
| ) |
Set the "stream id" field on a match object.
This makes the match object match a stream having the ID number id. The overlay controlled by this match object will be applied to that stream, if it exists.
Axoverlay does not provide a means to obtain stream numbers for currently active streams. Another API should be used for this purpose.
| match | The match object in question |
| id | The stream ID number that should be matched |
| bool axo_palette_full_load_argb | ( | int | palette_id, |
| const axo_argb_entry * | entries, | ||
| int | count, | ||
| axo_err ** | err | ||
| ) |
Load ARGB data into a palette that was created by axo_palette_new.
The number of entries should match the number required for the selected overlay format.
Any previous contents of the palette are replaced.
The palette will be updated on the next call to axo_submit_buffer.
If the palette was currently in use by one or more overlays, they will be automatically updated to reflect the newly loaded data.
| palette_id | The ID number of the palette to replace |
| entries | The ARGB data that should be loaded into the palette |
| count | The number of axo_argb_entry values to load |
| err | Error return |
| int axo_palette_new | ( | axo_err ** | err | ) |
Allocate a new colour palette that may be used for overlays. The returned ID number is valid to pass to axo_props_set_palette.
The palette is initially empty and data may be loaded into it using axo_palette_full_load_argb.
There may be restrictions on the number of palettes that can be used for overlays at one time, depending on the platform and firmware version. In particular the platform may support only a single global palette that is shared between all applications and overlays.
It is recommended to create only a single palette and use it for all overlays that need palettes. It is not recommended to use the same palette for overlays with different formats.
| err | Error return |
| bool axo_palette_update_color | ( | int | palette_id, |
| const axo_argb_entry | entry, | ||
| int | index, | ||
| axo_err ** | err | ||
| ) |
Update a single ARGB value of a palette that was created by axo_palette_new.
The palette will be updated on the next call to axo_submit_buffer.
If the palette was currently in use by one or more overlays, they will be automatically updated to reflect the newly loaded data.
| palette_id | The ID number of the palette to replace |
| entry | An axo_argb_entry containing the ARGB value that should be loaded into the palette slot specified by index" |
| index | The index of the ARGB value slot to be updated |
| err | Error return |
| void axo_props_free | ( | axo_props * | props | ) |
Free an overlay properties object.
| props | The properties object to free |
| axo_props* axo_props_new | ( | void | ) |
Create a new, blank overlay properties object.
The returned object is "blank" in the sense that it describes a null modification to any existing properties. That is, if the empty object was passed directly to axo_adjust_overlay, it would result in no change to the overlay.
The returned object has to be freed by axo_props_free.
| void axo_props_set_anchor_point | ( | axo_props * | props, |
| double | x, | ||
| double | y | ||
| ) |
Set the "anchor point" field on an overlay properties object.
This field selects the anchor point used for interpreting the "position" field, corresponding to the "AnchorPoint" property documented in the Overlay AFD.
The anchor point is the point inside the overlay buffer which determines the position of the overlay itself. It is the point which is referred to when setting the position of the overlay using axo_props_set_position.
| props | The properties object in question |
| x | arbitrary X position of the point. Normalized value from [0..1] |
| y | arbitrary Y position of the point. Normalized value from [0..1] |
| void axo_props_set_detailed_format | ( | axo_props * | props, |
| axo_detailed_format * | detailed_format | ||
| ) |
Set the detailed format field on an overlay properties object.
This selects the pixel storage format to use for the overlay. It also selects the type of compression to be used, if any.
| props | The properties object in question |
| detailed_format | The new detailed format |
| void axo_props_set_format | ( | axo_props * | props, |
| axo_format | format | ||
| ) |
Shorthand for axo_props_set_detailed_format() to select an uncompressed format.
| props | The properties object in question |
| format | The new format |
| void axo_props_set_manual_dma_sync | ( | axo_props * | props, |
| bool | manual_dma_sync | ||
| ) |
Set dma sync strategy on an overlay properties object.
Setting this field to true makes the application responsible for dma sync operations, this can be useful if for instance the GPU was used to draw the overlay since GPU operations usually flush the framebuffer to memory before finishing.
| props | The properties object in question |
| manual_dma_sync | Manual DMA sync mode enabled/disabled |
| void axo_props_set_nbr_of_buffers | ( | axo_props * | props, |
| unsigned | nbr | ||
| ) |
Set the "nbr_of_buffers" field on an overlay properties object.
Sets the number of buffers used. If not set, the number will default to two. For animation double or triple buffering must be used to prevent flickering. Triple buffering takes up more memory but is more performant than double or single buffering while single buffering takes up the least amount of memory but can only show static overlays.
| props | The properties object in question |
| nbr | The number of buffers to use |
| void axo_props_set_palette | ( | axo_props * | props, |
| int | id | ||
| ) |
Set the "palette" field on an overlay properties object.
This causes the overlay to use the specified palette for colour lookups. The ID number should be one which was previously returned by axo_palette_new.
| props | The properties object in question |
| id | The ID number of the palette to use |
| void axo_props_set_position | ( | axo_props * | props, |
| double | x, | ||
| double | y | ||
| ) |
Set the "position" field on an overlay properties object.
This field describes the position of the overlay within the video frame, corresponding to the "Position" property documented in the Overlay AFD. The interpretation of the X and Y coordinates depends on the fields "position reference" and "anchor point".
| props | The properties object in question |
| x | The new X position |
| y | The new Y position |
| void axo_props_set_position_reference | ( | axo_props * | props, |
| const char * | ref | ||
| ) |
Set the "position reference" field on an overlay properties object.
This function exists for legacy reasons. Axoverlay2 only supports the "channel" reference, which is also the default when no reference is explicitly set. There is no need to call this function.
"channel": (x, y) are fractional numbers giving a position relative to the centre point of the scaled video stream. (x, y) range from -1.0 to +1.0 where -1.0 is left/top and +1.0 is right/bottom. Example: x = -1.0, y = -1.0 is top-left of stream. x = 0.0, y = 0.0 is centre of stream.| props | The properties object in question |
| ref | The new position reference type |
| void axo_props_set_size | ( | axo_props * | props, |
| unsigned | desired_width, | ||
| unsigned | desired_height | ||
| ) |
Set the "size" field on an overlay properties object.
This field corresponds to the "Size" property documented in the Overlay AFD.
Depending on the selected format, there may be alignment restrictions on the size. It may be necessary to pad out the size to meet these requirements. The function axo_get_aligned_size shall always be used to select an appropriate size.
| props | The properties object in question |
| desired_width | The desired new pixel width. The actual overlay width might be different due to alignment requirements from the hardware. axo_buffer_get_width can be used to get the real width. |
| desired_height | The desired new pixel height. The actual overlay height might be different due to alignment requirements from the hardware. axo_buffer_get_height can be used to get the real height. |
| void axo_props_set_upscale_x2 | ( | axo_props * | props, |
| bool | upscale | ||
| ) |
Set 2x upscaling on an overlay properties objects.
True to cause the overlay size to be scaled up by the factor of two.
| props | The properties object in question |
| upscale | True to upscale an overlay |
| void axo_props_set_z_priority | ( | axo_props * | props, |
| int | z_priority | ||
| ) |
Set z priority on an overlay properties object.
An overlay with higher priority will be placed in front of an overlay with lower priority in case they overlay. The default is 0.
| props | The properties object in question |
| z_priority | The intended z-priority for the object |
| bool axo_remove_overlay | ( | int | id, |
| axo_err ** | err | ||
| ) |
Remove the overlay with the specified ID number.
If successful, the overlay will disappear from all streams it was applied to.
| id | The ID number of the overlay, as returned by axo_create_overlay |
| err | Error return |
| bool axo_start | ( | axo_settings * | settings, |
| axo_err ** | err | ||
| ) |
Start up Axoverlay with the given global settings.
Axoverlay must be started before any other functions may be called, except the axo_settings family of functions and other exceptions as noted.
If Axoverlay cannot be started with the given settings, an error is returned.
| settings | Unused; should be NULL |
| err | Error return |
| bool axo_stop | ( | axo_err ** | err | ) |
Stop Axoverlay.
This causes the removal of all overlays, palettes, and other objects managed by Axoverlay. All such objects become invalid.
If there is an error in stopping Axoverlay, it will be returned. This error is purely informational as there is no way for client to handle it, and Axoverlay will still stop working. Client should not call axo_stop again if it fails.
| err | Error return |
| bool axo_submit_buffer | ( | axo_buffer * | buffer, |
| axo_submit * | submit, | ||
| axo_err ** | err | ||
| ) |
Submit an overlay buffer.
Normally, this causes the buffer to be shown in the video frame.
| buffer | The buffer in question |
| submit | Submit metadata object, or NULL to select defaults |
| err | Error return |
| axo_detailed_format* axo_suggest_detailed_format | ( | axo_format | format, |
| axo_format_flags | flags, | ||
| axo_err ** | err | ||
| ) |
Ask axoverlay to select a detailed format to be used for rendering, compatible with the current platform. The selection is valid for multiple overlays.
Example: Client wishes to render ARGB32 graphics using the platform GPU:
The returned object shall be freed using axo_detailed_format_free().
| format | The pixel colour format to use |
| flags | Flags to influence the choice |
| err | Error return |