libvdo
vdo-buffer.h File Reference

A memory buffer. More...

#include "vdo-frame.h"
Include dependency graph for vdo-buffer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

VdoBuffer * vdo_buffer_new (gint fd, gsize capacity, guint64 offset, gpointer opaque)
 Create a buffer which is owned by an external framework. More...
 
VdoBuffer * vdo_buffer_new_full (gint fd, gsize capacity, guint64 offset, gpointer opaque, VdoMap *settings)
 Create a buffer with custom buffer properties. More...
 
guint32 vdo_buffer_get_id (VdoBuffer *self)
 Return an id representing the VdoBuffer. More...
 
gint vdo_buffer_get_fd (VdoBuffer *self)
 Return a file descriptor representing the VdoBuffer. More...
 
gint64 vdo_buffer_get_offset (VdoBuffer *self)
 Return file offset to the VdoBuffer. More...
 
gsize vdo_buffer_get_capacity (VdoBuffer *self)
 Returns the entire buffer capacity of the VdoBuffer. More...
 
gboolean vdo_buffer_is_complete (VdoBuffer *self)
 Indicates whether the TemporalUnit is complete after this frame. More...
 
gboolean vdo_buffer_is_contiguous (VdoBuffer *self)
 Indicates whether the buffer is contiguous or sparse. More...
 
gpointer vdo_buffer_get_opaque (VdoBuffer *self)
 Get a pointer to an opaque, containing user provided custom information. More...
 
gpointer vdo_buffer_get_data (VdoBuffer *self)
 Return a pointer to the underlying buffer. More...
 
VdoFrame * vdo_buffer_get_frame (VdoBuffer *self)
 Return a pointer to the underlying frame. More...
 

Detailed Description

A memory buffer.

Copyright (C) 2018-2025, Axis Communications AB, Lund

Function Documentation

◆ vdo_buffer_get_capacity()

gsize vdo_buffer_get_capacity ( VdoBuffer *  self)

Returns the entire buffer capacity of the VdoBuffer.

For alignment purposes the buffer may be larger than requested.

Parameters
selfA VdoBuffer.
Returns
Capacity of the buffer in bytes.

◆ vdo_buffer_get_data()

gpointer vdo_buffer_get_data ( VdoBuffer *  self)

Return a pointer to the underlying buffer.

Beware this pointer is only valid for as long as the VdoBuffer itself is valid.

The layout of the data depends on the VdoFormat and VdoFrameType. For H.26x this is always Annex B with long start-code 0x00000001.

For example a single VdoBuffer with format VDO_FRAME_TYPE_H265_IDR might contain [NAL_VPS][NAL_SPS][NAL_PPS][IDR-Slice].

In the above example vdo_frame_get_header_size is the byte offset to the IDR-Slice.

Parameters
selfA VdoBuffer.
Returns
A pointer to the buffer data or NULL if allocation failed.

◆ vdo_buffer_get_fd()

gint vdo_buffer_get_fd ( VdoBuffer *  self)

Return a file descriptor representing the VdoBuffer.

Parameters
selfA VdoBuffer.
Returns
A file descriptor or -1 on error.

◆ vdo_buffer_get_frame()

VdoFrame* vdo_buffer_get_frame ( VdoBuffer *  self)

Return a pointer to the underlying frame.

Beware this pointer is only valid for as long as the VdoBuffer itself is valid.

while (1) {
VdoBuffer *buffer = vdo_stream_get_buffer(stream, &error);
VdoFrame *frame = vdo_buffer_get_frame(buffer);
if (!frame) { // An error occurred
// Only log unexpected errors (ignore server maintenance etc.)
if (!vdo_error_is_expected(&error))
fprintf(stderr, "%s\n", err->message);
// Exit and try to create a new stream
break;
}
// Extract the timestamp from the frame
uint64_t timestamp = vdo_frame_get_timestamp(frame);
g_object_unref(buffer); // Both 'buffer' and 'frame' are now invalid
}
A video frame.
VdoFrame * vdo_buffer_get_frame(VdoBuffer *self)
Return a pointer to the underlying frame.
gboolean vdo_error_is_expected(GError **error)
Check if error is expected.
guint64 vdo_frame_get_timestamp(VdoFrame *self)
Return the capture timestamp of this frame.
VdoBuffer * vdo_stream_get_buffer(VdoStream *self, GError **error)
Fetch a VdoBuffer containing a frame.
Parameters
selfA VdoBuffer, or NULL.
Returns
A pointer to the frame, or NULL if self was NULL.
Examples
vdo-example-blocking.cc, vdo-example-nv12.cc, vdo-example-rgb.cc, and vdo-example.cc.

◆ vdo_buffer_get_id()

guint32 vdo_buffer_get_id ( VdoBuffer *  self)

Return an id representing the VdoBuffer.

The id is not guaranteed to be globally unique.

Parameters
selfA VdoBuffer.
Returns
The id.

◆ vdo_buffer_get_offset()

gint64 vdo_buffer_get_offset ( VdoBuffer *  self)

Return file offset to the VdoBuffer.

Parameters
selfA VdoBuffer.
Returns
The file offset.

◆ vdo_buffer_get_opaque()

gpointer vdo_buffer_get_opaque ( VdoBuffer *  self)

Get a pointer to an opaque, containing user provided custom information.

The opaque pointer has no predefined meaning inside the vdo framework itself, it is meant to facilitate interoperability with other existing frameworks as well as caching the buffer data pointer(see vdo_buffer_get_data).

typedef struct {
gpointer buffer_data;
size_t framework_data;
} external_framework_t;
// Allocate and Enqueue a Buffer
external_framework_t *opaque_in = g_new0(external_framework_t, 1);
VdoBuffer *buffer_in = vdo_stream_buffer_alloc(stream, opaque_in, NULL);
opaque_in->buffer_data = vdo_buffer_get_data(buffer_in);
opaque_in->framework_data = 0x12345678;
vdo_stream_buffer_enqueue(stream, buffer_in);
// Retrieve filled Buffer
VdoBuffer *buffer_out = vdo_stream_get_buffer(stream, NULL);
external_framework_t *opaque_out = vdo_frame_get_opaque(buffer_out);
assert(opaque_in == opaque_out);
gpointer vdo_buffer_get_data(VdoBuffer *self)
Return a pointer to the underlying buffer.
VdoBuffer * vdo_stream_buffer_alloc(VdoStream *self, gpointer opaque, GError **error)
Allocate a new buffer for this stream.
gboolean vdo_stream_buffer_enqueue(VdoStream *self, VdoBuffer *buffer, GError **error)
Enqueue a buffer for this video stream.
Parameters
selfA VdoBuffer.
Returns
A pointer to the opaque user provided information.

◆ vdo_buffer_is_complete()

gboolean vdo_buffer_is_complete ( VdoBuffer *  self)

Indicates whether the TemporalUnit is complete after this frame.

This is only relevant for AV1 as other formats are complete.

Parameters
selfA VdoBuffer.
Returns
TRUE means complete, FALSE means incomplete.

◆ vdo_buffer_is_contiguous()

gboolean vdo_buffer_is_contiguous ( VdoBuffer *  self)

Indicates whether the buffer is contiguous or sparse.

By default all buffers are contiguous unless the stream option "frame.chunks" is true, enabling chunks is necessary for zero-copy on some platforms.

Contiguous buffers have trivial layout (■■■). They can be accessed with vdo_buffer_get_data().

Sparse buffers are spread over multiple chunks with gaps in between (■□■□■). They must be accessed with vdo_frame_take_chunk() or vdo_frame_take_chunk_ex().

Parameters
selfA VdoBuffer.
Returns
TRUE means contiguous, FALSE means sparse.

◆ vdo_buffer_new()

VdoBuffer* vdo_buffer_new ( gint  fd,
gsize  capacity,
guint64  offset,
gpointer  opaque 
)

Create a buffer which is owned by an external framework.

Default: VDO_BUFFER_ACCESS_CPU_RD (suitable for normal consumers) The fd will not be closed by g_object_unref.

Parameters
fdA mmap compatible file descriptor
capacityThe buffer capacity
offsetThe offset to the start of the buffer
opaqueThe opaque custom information associated with the buffer
Returns
A VdoBuffer. Free with g_object_unref().

◆ vdo_buffer_new_full()

VdoBuffer* vdo_buffer_new_full ( gint  fd,
gsize  capacity,
guint64  offset,
gpointer  opaque,
VdoMap *  settings 
)

Create a buffer with custom buffer properties.

Default: VDO_BUFFER_ACCESS_ANY_RW (suitable for producers) The fd will not be closed by g_object_unref.

VdoMap *settings = vdo_map_new();
vdo_map_set_uint32(settings, "buffer.access", VDO_BUFFER_ACCESS_ANY_RW);
VdoBuffer *buffer = vdo_buffer_new_full(fd, capacity, 0, NULL, settings);
A class representing a dictionary mapping keys to values.
VdoBuffer * vdo_buffer_new_full(gint fd, gsize capacity, guint64 offset, gpointer opaque, VdoMap *settings)
Create a buffer with custom buffer properties.
VdoMap * vdo_map_new(void)
Constructs a new empty VdoMap.
void vdo_map_set_uint32(VdoMap *self, const gchar *name, guint32 value)
Sets the value associated with the specified key.
@ VDO_BUFFER_ACCESS_ANY_RW
Definition: vdo-types.h:379
Parameters
fdA mmap compatible file descriptor
capacityThe buffer capacity
offsetThe offset to the start of the buffer
opaqueThe opaque custom information associated with the buffer
settingsOverride default buffer properties such as VdoBufferAccess
Returns
A VdoBuffer. Free with g_object_unref().