Asterisk - The Open Source Telephony Project
18.5.0
|
Data Buffer API. More...
Go to the source code of this file.
Typedefs | |
typedef void(* | ast_data_buffer_free_callback) (void *data) |
A callback function to free a data payload in a data buffer. More... | |
Functions | |
struct ast_data_buffer * | ast_data_buffer_alloc (ast_data_buffer_free_callback free_fn, size_t size) |
Allocate a data buffer. More... | |
size_t | ast_data_buffer_count (const struct ast_data_buffer *buffer) |
Return the number of payloads in a data buffer. More... | |
void | ast_data_buffer_free (struct ast_data_buffer *buffer) |
Free a data buffer (and all held data payloads) More... | |
void * | ast_data_buffer_get (const struct ast_data_buffer *buffer, size_t pos) |
Retrieve a data payload from the data buffer. More... | |
size_t | ast_data_buffer_max (const struct ast_data_buffer *buffer) |
Return the maximum number of payloads a data buffer can hold. More... | |
int | ast_data_buffer_put (struct ast_data_buffer *buffer, size_t pos, void *payload) |
Place a data payload at a position in the data buffer. More... | |
void * | ast_data_buffer_remove (struct ast_data_buffer *buffer, size_t pos) |
Remove a data payload from the data buffer. More... | |
void * | ast_data_buffer_remove_head (struct ast_data_buffer *buffer) |
Remove the first payload from the data buffer. More... | |
void | ast_data_buffer_resize (struct ast_data_buffer *buffer, size_t size) |
Resize a data buffer. More... | |
Data Buffer API.
A data buffer acts as a ring buffer of data. It is given a fixed number of data packets to store (which may be dynamically changed). Given a number it will store a data packet at that position relative to the others. Given a number it will retrieve the given data packet if it is present. This is purposely a storage of arbitrary things so that it can be used for multiple things.
Definition in file data_buffer.h.
typedef void(* ast_data_buffer_free_callback) (void *data) |
A callback function to free a data payload in a data buffer.
The | data payload |
Definition at line 48 of file data_buffer.h.
struct ast_data_buffer* ast_data_buffer_alloc | ( | ast_data_buffer_free_callback | free_fn, |
size_t | size | ||
) |
Allocate a data buffer.
free_fn | Callback function to free a data payload |
size | The maximum number of data payloads to contain in the data buffer |
non-NULL | success |
NULL | failure |
Definition at line 145 of file data_buffer.c.
References ast_assert, ast_calloc, ast_data_buffer_cache_adjust(), AST_LIST_HEAD_INIT_NOLOCK, ast_data_buffer::cached_payloads, ast_data_buffer::free_fn, free_fn_do_nothing(), ast_data_buffer::max, NULL, and ast_data_buffer::payloads.
Referenced by ast_rtp_prop_set(), and AST_TEST_DEFINE().
size_t ast_data_buffer_count | ( | const struct ast_data_buffer * | buffer | ) |
Return the number of payloads in a data buffer.
buffer | The data buffer |
the | number of data payloads |
Definition at line 356 of file data_buffer.c.
References ast_assert, ast_data_buffer::count, and NULL.
Referenced by ast_rtp_read(), AST_TEST_DEFINE(), get_recv_buffer_count(), and get_send_buffer_count().
void ast_data_buffer_free | ( | struct ast_data_buffer * | buffer | ) |
Free a data buffer (and all held data payloads)
buffer | The data buffer |
Definition at line 338 of file data_buffer.c.
References ast_assert, ast_free, AST_LIST_REMOVE_HEAD, ast_data_buffer::cached_payloads, ast_data_buffer::free_fn, data_buffer_payload_entry::list, NULL, data_buffer_payload_entry::payload, and ast_data_buffer::payloads.
Referenced by ast_data_buffer_free_wrapper(), ast_rtp_destroy(), and ast_rtp_prop_set().
void* ast_data_buffer_get | ( | const struct ast_data_buffer * | buffer, |
size_t | pos | ||
) |
Retrieve a data payload from the data buffer.
buffer | The data buffer |
pos | The position of the data payload |
non-NULL | success |
NULL | failure |
Definition at line 269 of file data_buffer.c.
References ast_assert, AST_LIST_TRAVERSE, data_buffer_payload_entry::list, NULL, data_buffer_payload_entry::payload, ast_data_buffer::payloads, and data_buffer_payload_entry::pos.
Referenced by ast_rtp_read(), ast_rtp_rtcp_handle_nack(), and AST_TEST_DEFINE().
size_t ast_data_buffer_max | ( | const struct ast_data_buffer * | buffer | ) |
Return the maximum number of payloads a data buffer can hold.
buffer | The data buffer |
the | maximum number of data payloads |
Definition at line 363 of file data_buffer.c.
References ast_assert, ast_data_buffer::max, and NULL.
Referenced by ast_rtp_read(), ast_rtp_rtcp_handle_nack(), AST_TEST_DEFINE(), and get_recv_buffer_max().
int ast_data_buffer_put | ( | struct ast_data_buffer * | buffer, |
size_t | pos, | ||
void * | payload | ||
) |
Place a data payload at a position in the data buffer.
buffer | The data buffer |
pos | The position of the data payload |
payload | The data payload |
0 | success |
-1 | failure |
Definition at line 203 of file data_buffer.c.
References ast_assert, ast_data_buffer_cache_adjust(), ast_debug, AST_LIST_INSERT_BEFORE_CURRENT, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_data_buffer::cache_count, ast_data_buffer::cached_payloads, ast_data_buffer::count, ast_data_buffer::free_fn, data_buffer_payload_entry::list, ast_data_buffer::max, NULL, data_buffer_payload_entry::payload, ast_data_buffer::payloads, and data_buffer_payload_entry::pos.
Referenced by ast_rtp_read(), AST_TEST_DEFINE(), and rtp_raw_write().
void* ast_data_buffer_remove | ( | struct ast_data_buffer * | buffer, |
size_t | pos | ||
) |
Remove a data payload from the data buffer.
buffer | The data buffer |
pos | The position of the data payload |
non-NULL | success |
NULL | failure |
Definition at line 299 of file data_buffer.c.
References ast_assert, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, data_buffer_free_buffer_payload(), data_buffer_payload_entry::list, NULL, data_buffer_payload_entry::payload, ast_data_buffer::payloads, and data_buffer_payload_entry::pos.
Referenced by ast_rtp_read(), and AST_TEST_DEFINE().
void* ast_data_buffer_remove_head | ( | struct ast_data_buffer * | buffer | ) |
Remove the first payload from the data buffer.
buffer | The data buffer |
non-NULL | success |
NULL | failure |
Definition at line 320 of file data_buffer.c.
References ast_assert, AST_LIST_REMOVE_HEAD, ast_data_buffer::count, data_buffer_free_buffer_payload(), data_buffer_payload_entry::list, NULL, data_buffer_payload_entry::payload, and ast_data_buffer::payloads.
Referenced by AST_TEST_DEFINE().
void ast_data_buffer_resize | ( | struct ast_data_buffer * | buffer, |
size_t | size | ||
) |
Resize a data buffer.
buffer | The data buffer |
size | The new maximum size of the data buffer |
Definition at line 168 of file data_buffer.c.
References ast_assert, ast_data_buffer_cache_adjust(), ast_free, AST_LIST_REMOVE_HEAD, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_data_buffer::count, ast_data_buffer::free_fn, data_buffer_payload_entry::list, ast_data_buffer::max, NULL, data_buffer_payload_entry::payload, and ast_data_buffer::payloads.
Referenced by ast_rtp_read(), ast_rtp_rtcp_handle_nack(), and AST_TEST_DEFINE().