48 [CODEC_NEGOTIATION_PARAM_UNSPECIFIED] =
"unspecified",
56 [CODEC_NEGOTIATION_PREFER_UNSPECIFIED] =
"unspecified",
62 [CODEC_NEGOTIATION_OPERATION_UNSPECIFIED] =
"unspecified",
70 [CODEC_NEGOTIATION_KEEP_UNSPECIFIED] =
"unspecified",
76 [CODEC_NEGOTIATION_TRANSCODE_UNSPECIFIED] =
"unspecified",
134 if (!prefs || !buf || !*buf) {
159 #define set_pref_value(_name, _value, _prefs, _UC, _lc, _error_message) \
162 if (strcmp(_name, ast_stream_codec_negotiation_params_map[CODEC_NEGOTIATION_PARAM_ ## _UC]) == 0) { \
164 for (i = CODEC_NEGOTIATION_ ## _UC ## _UNSPECIFIED + 1; i < CODEC_NEGOTIATION_ ## _UC ## _END; i++) { \
165 if (strcmp(value, ast_stream_codec_negotiation_ ## _lc ## _map[i]) == 0) { \
169 if ( prefs->_lc == CODEC_NEGOTIATION_ ## _UC ## _UNSPECIFIED) { \
171 if (_error_message) { \
172 ast_str_append(_error_message, 0, "Codec preference '%s' has invalid value '%s'", name, value); \
182 struct ast_str **error_message)
196 prefs->
prefer = CODEC_NEGOTIATION_PREFER_UNSPECIFIED;
197 prefs->
operation = CODEC_NEGOTIATION_OPERATION_UNSPECIFIED;
198 prefs->
keep = CODEC_NEGOTIATION_KEEP_UNSPECIFIED;
199 prefs->
transcode = CODEC_NEGOTIATION_TRANSCODE_UNSPECIFIED;
201 for (current_value = initial_value; (pref = strtok_r(current_value,
",", &saveptr1)) != NULL; ) {
202 name = strtok_r(pref,
": ", &saveptr2);
203 value = strtok_r(NULL,
": ", &saveptr2);
205 if (!name || !value) {
207 ast_str_append(error_message, 0,
"Codec preference '%s' is invalid", pref);
212 set_pref_value(name, value, prefs, OPERATION, operation, error_message);
213 set_pref_value(name, value, prefs, PREFER, prefer, error_message);
214 set_pref_value(name, value, prefs, KEEP, keep, error_message);
215 set_pref_value(name, value, prefs, TRANSCODE, transcode, error_message);
217 current_value = NULL;
231 #define MIN_STREAM_NAME_LEN 16
236 size_t name_len = MAX(strlen(
S_OR(name,
"")), MIN_STREAM_NAME_LEN);
238 stream =
ast_calloc(1,
sizeof(*stream) + name_len + 1);
246 strcpy(stream->
name,
S_OR(name,
""));
260 const char *stream_name;
267 stream_name = name ?: stream->
name;
268 name_len = MAX(strlen(
S_OR(stream_name,
"")), MIN_STREAM_NAME_LEN);
269 new_stream =
ast_calloc(1,
sizeof(*stream) + name_len + 1);
274 memcpy(new_stream, stream,
sizeof(*new_stream));
275 strcpy(new_stream->
name, stream_name);
276 new_stream->
group = -1;
280 ast_free(new_stream);
311 ast_assert(stream != NULL);
318 ast_assert(stream != NULL);
325 ast_assert(stream != NULL);
332 ast_assert(stream != NULL);
360 ast_assert(stream != NULL);
367 ast_assert(stream != NULL);
375 ast_assert(stream != NULL);
377 return stream->
state;
382 ast_assert(stream != NULL);
384 stream->
state = state;
408 if (!strcmp(
"sendrecv", str)) {
411 if (!strcmp(
"sendonly", str)) {
414 if (!strcmp(
"recvonly", str)) {
417 if (!strcmp(
"inactive", str)) {
427 ast_assert_return(stream != NULL, NULL);
428 ast_assert_return(m_key != NULL, NULL);
431 if (strcmp(v->
name, m_key) == 0) {
444 ast_assert_return(stream != NULL, NULL);
454 ast_variable_list_append(&vout, vt);
465 ast_assert_return(stream != NULL, -1);
466 ast_assert_return(m_key != NULL, -1);
472 if (strcmp(v->
name, m_key) == 0) {
490 v = ast_variable_new(m_key, value,
"");
495 ast_variable_list_append(&stream->
metadata, v);
502 ast_assert(stream != NULL);
509 ast_assert(stream != NULL);
516 ast_assert(stream != NULL);
527 struct ast_str **error_message)
533 enum ast_media_type media_type = pending_stream ? pending_stream->
type : AST_MEDIA_TYPE_UNKNOWN;
535 SCOPE_ENTER(4,
"Pending: %s Validation: %s Prefs: %s\n",
540 if (!pending_stream || !validation_stream || !prefs || !joint_caps
541 || media_type == AST_MEDIA_TYPE_UNKNOWN) {
545 ao2_cleanup(joint_caps);
546 SCOPE_EXIT_RTN_VALUE(NULL,
"Invalid arguments\n");
550 preferred_caps = pending_stream->
formats;
551 nonpreferred_caps = validation_stream->
formats;
553 preferred_caps = validation_stream->
formats;
554 nonpreferred_caps = pending_stream->
formats;
580 ast_str_append(error_message, 0,
"No common formats available for media type '%s' ",
589 ao2_cleanup(joint_caps);
590 SCOPE_EXIT_RTN_VALUE(NULL,
"No common formats available\n");
602 ast_str_append(error_message, 0,
"No common formats available for media type '%s' ",
614 ao2_cleanup(joint_caps);
621 if (TRACE_ATLEAST(3)) {
637 ao2_cleanup(joint_caps);
641 static void stream_topology_destroy(
void *data)
649 #define TOPOLOGY_INITIAL_STREAM_COUNT 2
673 ast_assert(topology != NULL);
701 ast_assert(left != NULL);
702 ast_assert(right != NULL);
745 ao2_cleanup(topology);
750 ast_assert(topology && stream);
758 if (ast_strlen_zero(stream->
name)) {
767 ast_assert(topology != NULL);
776 ast_assert(topology != NULL);
791 ast_assert(topology != NULL);
801 ast_assert(topology && stream);
818 if (ast_strlen_zero(stream->
name)) {
830 ast_assert(topology != NULL);
859 for (type = AST_MEDIA_TYPE_UNKNOWN + 1; type < AST_MEDIA_TYPE_END; type++) {
875 ao2_cleanup(new_cap);
882 ao2_cleanup(new_cap);
908 ast_assert(topology != NULL);
922 if (type == AST_MEDIA_TYPE_UNKNOWN || type == stream->
type) {
970 ast_assert(topology != NULL);
976 if (stream->
type == type
989 int nths[AST_MEDIA_TYPE_END] = {0};
1005 for (i = 0; i < size; ++i) {
1038 if (!pending_topology || !configured_topology || !joint_topology) {
1039 ao2_cleanup(joint_topology);
1049 if (!configured_stream) {
1051 if (!joint_stream) {
1052 ao2_cleanup(joint_topology);
1058 if (!joint_stream) {
1059 ao2_cleanup(joint_topology);
1069 ao2_cleanup(joint_topology);
1074 return joint_topology;
1079 ast_assert(stream != NULL);
1081 return stream->
group;
1086 ast_assert(stream != NULL);
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
struct ast_variable * next
struct ast_stream_topology * ast_stream_topology_alloc(void)
Create a stream topology.
struct ast_rtp_codecs * rtp_codecs
The rtp_codecs used by the stream.
const char * ast_stream_codec_negotiation_prefer_map[]
"prefer" enum to string map
struct ast_stream_topology * ast_stream_topology_create_resolved(struct ast_stream_topology *pending_topology, struct ast_stream_topology *configured_topology, struct ast_stream_codec_negotiation_prefs *prefs, struct ast_str **error_message)
Create a resolved stream topology from 2 topologies.
#define AST_VECTOR_GET_INDEX_NTH(vec, nth, value, cmp)
Get the nth index from a vector that matches the given comparison.
Asterisk main include file. File version handling, generic pbx functions.
struct ast_format_cap * ast_stream_topology_get_formats(struct ast_stream_topology *topology)
Create a format capabilities structure representing the topology.
enum ast_stream_state ast_stream_str2state(const char *str)
Convert a string to a stream state.
String manipulation functions.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
struct ast_stream * ast_stream_create_resolved(struct ast_stream *pending_stream, struct ast_stream *validation_stream, struct ast_stream_codec_negotiation_prefs *prefs, struct ast_str **error_message)
Create a resolved stream from 2 streams.
const char * ast_stream_codec_negotiation_keep_map[]
"keep" enum to string map
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
#define AST_VECTOR_ELEM_DEFAULT_CMP(elem, value)
Default comparator for AST_VECTOR_REMOVE_ELEM_UNORDERED()
#define AST_STREAM_MAX_CODEC_PREFS_LENGTH
Define for allocating buffer space for to_str() functions.
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
const char * ast_stream_state_map[]
Stream state enum to string map.
enum ast_stream_codec_negotiation_prefs_operation_values operation
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
struct ast_format_cap * formats
Current formats negotiated on the stream.
Structure for variables, used for configurations and for channel variables.
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Set when the stream has been removed/declined.
int ast_stream_get_format_count(const struct ast_stream *stream)
Get the count of the current negotiated formats of a stream.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
enum ast_stream_codec_negotiation_prefs_prefer_values prefer
Set when the stream is not sending OR receiving media.
void ast_stream_topology_map(const struct ast_stream_topology *topology, struct ast_vector_int *types, struct ast_vector_int *v0, struct ast_vector_int *v1)
Map a given topology's streams to the given types.
const struct ast_format_cap * ast_stream_get_formats(const struct ast_stream *stream)
Get the current negotiated formats of a stream.
ast_stream_state
States that a stream may be in.
const char * ast_stream_codec_prefs_to_str(const struct ast_stream_codec_negotiation_prefs *prefs, struct ast_str **buf)
Return a string representing the codec preferences.
const char * ast_stream_codec_negotiation_params_map[]
Preference enum to string map.
enum ast_stream_state state
The current state of the stream.
void ast_stream_set_type(struct ast_stream *stream, enum ast_media_type type)
Change the media type of a stream.
void ast_stream_free(struct ast_stream *stream)
Destroy a media stream representation.
enum ast_stream_state ast_stream_get_state(const struct ast_stream *stream)
Get the current state of a stream.
char name[0]
Name for the stream within the context of the channel it is on.
struct ast_stream * ast_stream_alloc(const char *name, enum ast_media_type type)
Create a new media stream representation.
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
struct ast_stream * ast_stream_topology_get_first_stream_by_type(const struct ast_stream_topology *topology, enum ast_media_type type)
Gets the first active stream of a specific type from the topology.
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Configuration File Parser.
int group
The group that the stream is part of.
#define ast_str_tmp(init_len, __expr)
Provides a temporary ast_str and returns a copy of its buffer.
struct ast_stream_topology * ast_stream_topology_create_from_format_cap(struct ast_format_cap *cap)
A helper function that, given a format capabilities structure, creates a topology and separates the m...
#define ast_stream_codec_operation_to_str(value)
Safely get the name of an "operation" parameter value.
struct ast_format_cap * ast_stream_topology_get_formats_by_type(struct ast_stream_topology *topology, enum ast_media_type type)
Create a format capabilities structure containing all the formats from all the streams of a particula...
void ast_stream_set_group(struct ast_stream *stream, int group)
Set the stream group for a stream.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
enum ast_media_type type
The type of media the stream is handling.
const char * ast_stream_to_str(const struct ast_stream *stream, struct ast_str **buf)
Get a string representing the stream for debugging/display purposes.
struct ast_stream_topology::@408 streams
A vector of all the streams in this topology.
#define ast_strdupa(s)
duplicate a string in memory from the stack
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
const char * ast_stream_topology_to_str(const struct ast_stream_topology *topology, struct ast_str **buf)
Get a string representing the topology for debugging/display purposes.
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
const char * ast_stream_codec_negotiation_operation_map[]
"operation" enum to string map
#define AST_VECTOR_REMOVE_ORDERED(vec, idx)
Remove an element from a vector by index while maintaining order.
#define AST_VECTOR(name, type)
Define a vector structure.
int ast_stream_topology_append_stream(struct ast_stream_topology *topology, struct ast_stream *stream)
Append a stream to the topology.
struct ast_stream_topology * ast_stream_topology_clone(const struct ast_stream_topology *topology)
Create a deep clone of an existing stream topology.
enum ast_stream_codec_negotiation_prefs_keep_values keep
void ast_stream_set_formats(struct ast_stream *stream, struct ast_format_cap *caps)
Set the current negotiated formats of a stream.
int ast_stream_topology_equal(const struct ast_stream_topology *left, const struct ast_stream_topology *right)
Compare two stream topologies to see if they are equal.
const char * ast_stream_codec_negotiation_transcode_map[]
"transcode" state enum to string map
Set when the stream is sending and receiving media.
Support for dynamic strings.
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
struct ast_variable * ast_stream_get_metadata_list(const struct ast_stream *stream)
Get all stream metadata keys.
int ast_stream_codec_prefs_parse(const char *pref_string, struct ast_stream_codec_negotiation_prefs *prefs, struct ast_str **error_message)
Parses a string representing the codec prefs into a ast_stream_codec_negotiation_pref structure...
#define ast_stream_codec_keep_to_str(value)
Safely get the name of a "keep" parameter value.
#define ast_stream_codec_transcode_to_str(value)
Safely get the name of a "transcode" parameter value.
Set when the stream is sending media only.
#define ast_calloc(num, len)
A wrapper for calloc()
int ast_stream_set_metadata(struct ast_stream *stream, const char *m_key, const char *value)
Set a stream metadata value.
Support for logging to various files, console and syslog Configuration in file logger.conf.
Vector container support.
int ast_stream_topology_del_stream(struct ast_stream_topology *topology, unsigned int position)
Delete a specified stream from the given topology.
void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs)
Destroy the contents of an RTP codecs structure (but not the structure itself)
enum ast_media_type ast_stream_get_type(const struct ast_stream *stream)
Get the media type of a stream.
int ast_stream_get_position(const struct ast_stream *stream)
Get the position of the stream in the topology.
const char * ast_stream_state2str(enum ast_stream_state state)
Convert the state of a stream into a string.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
struct ast_rtp_codecs * ast_stream_get_rtp_codecs(const struct ast_stream *stream)
Get rtp_codecs associated with the stream.
struct ast_stream * ast_stream_topology_get_stream(const struct ast_stream_topology *topology, unsigned int stream_num)
Get a specific stream from the topology.
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
enum ast_stream_codec_negotiation_prefs_transcode_values transcode
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
struct ast_stream * ast_stream_clone(const struct ast_stream *stream, const char *name)
Create a deep clone of an existing stream.
#define ast_stream_codec_prefer_to_str(value)
Safely get the name of a "prefer" parameter value.
#define ast_stream_codec_param_to_str(value)
Safely get the name of a preference parameter.
const char * ast_stream_get_name(const struct ast_stream *stream)
Get the name of a stream.
ast_media_type
Types of media.
int ast_stream_topology_get_active_count(const struct ast_stream_topology *topology)
Get the number of active (non-REMOVED) streams in a topology.
Pluggable RTP Architecture.
int ast_stream_topology_set_stream(struct ast_stream_topology *topology, unsigned int position, struct ast_stream *stream)
Set a specific position in a topology.
void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state)
Set the state of a stream.
void ast_stream_set_rtp_codecs(struct ast_stream *stream, struct ast_rtp_codecs *rtp_codecs)
Set rtp_codecs associated with the stream.
Integer vector definition.
Set when the stream is receiving media only.
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
struct ast_variable * metadata
Stream metadata vector.
unsigned int position
The position of the stream in the topology.
const char * ast_stream_get_metadata(const struct ast_stream *stream, const char *m_key)
Get a stream metadata value.
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
int ast_stream_get_group(const struct ast_stream *stream)
Get the stream group that a stream is part of.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.