Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Functions | Variables
stream.c File Reference

Media Stream API. More...

#include "asterisk.h"
#include "asterisk/logger.h"
#include "asterisk/stream.h"
#include "asterisk/strings.h"
#include "asterisk/format.h"
#include "asterisk/format_cap.h"
#include "asterisk/vector.h"
#include "asterisk/config.h"
#include "asterisk/rtp_engine.h"
Include dependency graph for stream.c:

Go to the source code of this file.

Data Structures

struct  ast_stream
 
struct  ast_stream_metadata_entry
 
struct  ast_stream_topology
 

Macros

#define MIN_STREAM_NAME_LEN   16
 
#define set_pref_value(_name, _value, _prefs, _UC, _lc, _error_message)
 
#define TOPOLOGY_INITIAL_STREAM_COUNT   2
 

Functions

struct ast_streamast_stream_alloc (const char *name, enum ast_media_type type)
 Create a new media stream representation. More...
 
struct ast_streamast_stream_clone (const struct ast_stream *stream, const char *name)
 Create a deep clone of an existing stream. More...
 
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. More...
 
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. More...
 
struct ast_streamast_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. More...
 
void ast_stream_free (struct ast_stream *stream)
 Destroy a media stream representation. More...
 
int ast_stream_get_format_count (const struct ast_stream *stream)
 Get the count of the current negotiated formats of a stream. More...
 
const struct ast_format_capast_stream_get_formats (const struct ast_stream *stream)
 Get the current negotiated formats of a stream. More...
 
int ast_stream_get_group (const struct ast_stream *stream)
 Get the stream group that a stream is part of. More...
 
const char * ast_stream_get_metadata (const struct ast_stream *stream, const char *m_key)
 Get a stream metadata value. More...
 
struct ast_variableast_stream_get_metadata_list (const struct ast_stream *stream)
 Get all stream metadata keys. More...
 
const char * ast_stream_get_name (const struct ast_stream *stream)
 Get the name of a stream. More...
 
int ast_stream_get_position (const struct ast_stream *stream)
 Get the position of the stream in the topology. More...
 
struct ast_rtp_codecsast_stream_get_rtp_codecs (const struct ast_stream *stream)
 Get rtp_codecs associated with the stream. More...
 
enum ast_stream_state ast_stream_get_state (const struct ast_stream *stream)
 Get the current state of a stream. More...
 
enum ast_media_type ast_stream_get_type (const struct ast_stream *stream)
 Get the media type of a stream. More...
 
void ast_stream_set_formats (struct ast_stream *stream, struct ast_format_cap *caps)
 Set the current negotiated formats of a stream. More...
 
void ast_stream_set_group (struct ast_stream *stream, int group)
 Set the stream group for a stream. More...
 
int ast_stream_set_metadata (struct ast_stream *stream, const char *m_key, const char *value)
 Set a stream metadata value. More...
 
void ast_stream_set_rtp_codecs (struct ast_stream *stream, struct ast_rtp_codecs *rtp_codecs)
 Set rtp_codecs associated with the stream. More...
 
void ast_stream_set_state (struct ast_stream *stream, enum ast_stream_state state)
 Set the state of a stream. More...
 
void ast_stream_set_type (struct ast_stream *stream, enum ast_media_type type)
 Change the media type of a stream. More...
 
const char * ast_stream_state2str (enum ast_stream_state state)
 Convert the state of a stream into a string. More...
 
enum ast_stream_state ast_stream_str2state (const char *str)
 Convert a string to a stream state. More...
 
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. More...
 
struct ast_stream_topologyast_stream_topology_alloc (void)
 Create a stream topology. More...
 
int ast_stream_topology_append_stream (struct ast_stream_topology *topology, struct ast_stream *stream)
 Append a stream to the topology. More...
 
struct ast_stream_topologyast_stream_topology_clone (const struct ast_stream_topology *topology)
 Create a deep clone of an existing stream topology. More...
 
struct ast_stream_topologyast_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 media types in format_cap into separate streams. More...
 
struct ast_stream_topologyast_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. More...
 
int ast_stream_topology_del_stream (struct ast_stream_topology *topology, unsigned int position)
 Delete a specified stream from the given topology. More...
 
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. More...
 
void ast_stream_topology_free (struct ast_stream_topology *topology)
 Unreference and destroy a stream topology. More...
 
int ast_stream_topology_get_active_count (const struct ast_stream_topology *topology)
 Get the number of active (non-REMOVED) streams in a topology. More...
 
int ast_stream_topology_get_count (const struct ast_stream_topology *topology)
 Get the number of streams in a topology. More...
 
struct ast_streamast_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. More...
 
struct ast_format_capast_stream_topology_get_formats (struct ast_stream_topology *topology)
 Create a format capabilities structure representing the topology. More...
 
struct ast_format_capast_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 particular type in the topology. More...
 
struct ast_streamast_stream_topology_get_stream (const struct ast_stream_topology *topology, unsigned int stream_num)
 Get a specific stream from the topology. More...
 
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. More...
 
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. More...
 
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. More...
 
static void stream_topology_destroy (void *data)
 

Variables

const char * ast_stream_codec_negotiation_keep_map []
 "keep" enum to string map More...
 
const char * ast_stream_codec_negotiation_operation_map []
 "operation" enum to string map More...
 
const char * ast_stream_codec_negotiation_params_map []
 Preference enum to string map. More...
 
const char * ast_stream_codec_negotiation_prefer_map []
 "prefer" enum to string map More...
 
const char * ast_stream_codec_negotiation_transcode_map []
 "transcode" state enum to string map More...
 
const char * ast_stream_state_map []
 Stream state enum to string map. More...
 

Detailed Description

Media Stream API.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file stream.c.

Macro Definition Documentation

◆ MIN_STREAM_NAME_LEN

#define MIN_STREAM_NAME_LEN   16

◆ set_pref_value

#define set_pref_value (   _name,
  _value,
  _prefs,
  _UC,
  _lc,
  _error_message 
)

Definition at line 159 of file stream.c.

Referenced by ast_stream_codec_prefs_parse().

◆ TOPOLOGY_INITIAL_STREAM_COUNT

#define TOPOLOGY_INITIAL_STREAM_COUNT   2

Definition at line 649 of file stream.c.

Referenced by ast_stream_topology_alloc().

Function Documentation

◆ ast_stream_alloc()

struct ast_stream* ast_stream_alloc ( const char *  name,
enum ast_media_type  type 
)

Create a new media stream representation.

Parameters
nameA name for the stream
typeThe media type the stream is handling
Return values
non-NULLsuccess
NULLfailure
Note
This is NOT an AO2 object and has no locking. It is expected that a higher level object provides protection.
The stream will default to an inactive state until changed.
Since
15

Definition at line 233 of file stream.c.

References ast_calloc, ast_format_cap_alloc, AST_FORMAT_CAP_FLAG_DEFAULT, ast_free, AST_STREAM_STATE_INACTIVE, ast_stream::formats, ast_stream::group, MAX, MIN_STREAM_NAME_LEN, ast_stream::name, NULL, S_OR, ast_stream::state, ast_stream::type, and type.

Referenced by ast_stream_topology_create_from_format_cap(), AST_TEST_DEFINE(), ast_unreal_indicate(), build_topology(), handle_incoming_sdp(), make_channel(), sdp_requires_deferral(), t38_create_media_state(), and test_stream_alloc().

234 {
235  struct ast_stream *stream;
236  size_t name_len = MAX(strlen(S_OR(name, "")), MIN_STREAM_NAME_LEN); /* Ensure there is enough room for 'removed' or a type-position */
237 
238  stream = ast_calloc(1, sizeof(*stream) + name_len + 1);
239  if (!stream) {
240  return NULL;
241  }
242 
243  stream->type = type;
245  stream->group = -1;
246  strcpy(stream->name, S_OR(name, "")); /* Safe */
247 
249  if (!stream->formats) {
250  ast_free(stream);
251  return NULL;
252  }
253 
254  return stream;
255 }
static const char type[]
Definition: chan_ooh323.c:109
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
#define MIN_STREAM_NAME_LEN
Definition: stream.c:231
Set when the stream is not sending OR receiving media.
Definition: stream.h:94
#define NULL
Definition: resample.c:96
enum ast_stream_state state
The current state of the stream.
Definition: stream.c:100
char name[0]
Name for the stream within the context of the channel it is on.
Definition: stream.c:120
int group
The group that the stream is part of.
Definition: stream.c:110
#define MAX(a, b)
Definition: utils.h:228
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79

◆ ast_stream_clone()

struct ast_stream* ast_stream_clone ( const struct ast_stream stream,
const char *  name 
)

Create a deep clone of an existing stream.

Parameters
streamThe existing stream
Optionalname for cloned stream. If NULL, then existing stream's name is copied.
Return values
non-NULLsuccess
NULLfailure
Note
Opaque data pointers set with ast_stream_set_data() are not part of the deep clone. We have no way to clone the data.
Since
15

Definition at line 257 of file stream.c.

References ast_calloc, ast_format_cap_alloc, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_free, AST_MEDIA_TYPE_UNKNOWN, ast_stream_get_metadata_list(), ast_stream::formats, ast_stream::group, MAX, ast_stream::metadata, MIN_STREAM_NAME_LEN, ast_stream::name, NULL, and S_OR.

Referenced by append_all_streams(), append_source_stream(), ast_sip_session_create_joint_call_stream(), ast_stream_create_resolved(), ast_stream_topology_clone(), ast_stream_topology_create_resolved(), remove_all_original_streams(), resolve_refresh_media_states(), sip_session_refresh(), and stream_echo_topology_alloc().

258 {
259  struct ast_stream *new_stream;
260  const char *stream_name;
261  size_t name_len;
262 
263  if (!stream) {
264  return NULL;
265  }
266 
267  stream_name = name ?: stream->name;
268  name_len = MAX(strlen(S_OR(stream_name, "")), MIN_STREAM_NAME_LEN); /* Ensure there is enough room for 'removed' or a type-position */
269  new_stream = ast_calloc(1, sizeof(*stream) + name_len + 1);
270  if (!new_stream) {
271  return NULL;
272  }
273 
274  memcpy(new_stream, stream, sizeof(*new_stream));
275  strcpy(new_stream->name, stream_name); /* Safe */
276  new_stream->group = -1;
277 
279  if (!new_stream->formats) {
280  ast_free(new_stream);
281  return NULL;
282  }
284 
285  new_stream->metadata = ast_stream_get_metadata_list(stream);
286 
287  /* rtp_codecs aren't cloned */
288 
289  return new_stream;
290 }
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
#define MIN_STREAM_NAME_LEN
Definition: stream.c:231
#define NULL
Definition: resample.c:96
char name[0]
Name for the stream within the context of the channel it is on.
Definition: stream.c:120
int group
The group that the stream is part of.
Definition: stream.c:110
#define MAX(a, b)
Definition: utils.h:228
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
struct ast_variable * ast_stream_get_metadata_list(const struct ast_stream *stream)
Get all stream metadata keys.
Definition: stream.c:439
static const char name[]
Definition: cdr_mysql.c:74
#define ast_free(a)
Definition: astmm.h:182
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:204
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
struct ast_variable * metadata
Stream metadata vector.
Definition: stream.c:105

◆ ast_stream_codec_prefs_parse()

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.

Since
18

This function is mainly used by pjsip_configuration as a sorcery parameter handler.

Parameters
pref_stringA string in the format described by ast_stream_codec_prefs_to_str().
prefsPointer to a ast_stream_codec_negotiation_prefs structure to receive the parsed values.
error_messageAn optional ast_str** into which parsing errors will be placed.
Return values
0if success
-1if failed

Whitespace around the ':' and ',' separators is ignored and the parameters can be specified in any order. Parameters missing in the input string will have their values set to the appropriate *_UNSPECIFIED value and will not be considered an error. It's up to the caller to decide whether set a default value, return an error, etc.

Sample input: "prefer : configured , operation: union,keep:all, transcode:prevent"

Definition at line 181 of file stream.c.

References ast_str_append(), ast_strdupa, CODEC_NEGOTIATION_KEEP_UNSPECIFIED, CODEC_NEGOTIATION_OPERATION_UNSPECIFIED, CODEC_NEGOTIATION_PREFER_UNSPECIFIED, CODEC_NEGOTIATION_TRANSCODE_UNSPECIFIED, ast_stream_codec_negotiation_prefs::keep, name, NULL, ast_stream_codec_negotiation_prefs::operation, ast_stream_codec_negotiation_prefs::prefer, set_pref_value, ast_stream_codec_negotiation_prefs::transcode, and value.

Referenced by codec_prefs_handler().

183 {
184  char *initial_value = ast_strdupa(pref_string);
185  char *current_value;
186  char *pref;
187  char *saveptr1;
188  char *saveptr2;
189  char *name;
190  char *value;
191 
192  if (!prefs) {
193  return -1;
194  }
195 
200 
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);
204 
205  if (!name || !value) {
206  if (error_message) {
207  ast_str_append(error_message, 0, "Codec preference '%s' is invalid", pref);
208  }
209  return -1;
210  }
211 
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);
216 
217  current_value = NULL;
218  }
219 
220  return 0;
221 }
enum ast_stream_codec_negotiation_prefs_operation_values operation
Definition: stream.h:296
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
enum ast_stream_codec_negotiation_prefs_prefer_values prefer
Definition: stream.h:294
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
enum ast_stream_codec_negotiation_prefs_keep_values keep
Definition: stream.h:298
static const char name[]
Definition: cdr_mysql.c:74
enum ast_stream_codec_negotiation_prefs_transcode_values transcode
Definition: stream.h:300
#define set_pref_value(_name, _value, _prefs, _UC, _lc, _error_message)
Definition: stream.c:159

◆ ast_stream_codec_prefs_to_str()

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.

Since
18

This function can be used for debugging purposes but is also used in pjsip_configuration as a sorcery parameter handler

Parameters
prefsA pointer to a ast_stream_codec_negotiation_prefs structure
bufA pointer to an ast_str* used for the output. See note below.
Returns
the contents of the ast_str as a const char *.
Warning
No attempt should ever be made to free the returned char * and it should be dup'd if needed after the ast_str is freed.
Note
buf can't be NULL but it CAN contain a NULL value. If so, a new ast_str will be allocated and the value of buf updated with a pointer to it. Whether the caller supplies the ast_str or it's allocated by this function, it's the caller's responsibility to free it.

Sample output: "prefer: configured, operation: union, keep:all, transcode:prevent"

Definition at line 132 of file stream.c.

References ast_str_append(), ast_str_buffer(), ast_stream_codec_keep_to_str, ast_stream_codec_operation_to_str, ast_stream_codec_param_to_str, ast_stream_codec_prefer_to_str, ast_stream_codec_transcode_to_str, CODEC_NEGOTIATION_PARAM_KEEP, CODEC_NEGOTIATION_PARAM_OPERATION, CODEC_NEGOTIATION_PARAM_PREFER, CODEC_NEGOTIATION_PARAM_TRANSCODE, ast_stream_codec_negotiation_prefs::keep, ast_stream_codec_negotiation_prefs::operation, ast_stream_codec_negotiation_prefs::prefer, and ast_stream_codec_negotiation_prefs::transcode.

Referenced by ast_stream_create_resolved(), and codec_prefs_to_str().

133 {
134  if (!prefs || !buf || !*buf) {
135  return "";
136  }
137 
138  ast_str_append(buf, 0, "%s:%s, %s:%s, %s:%s, %s:%s",
147  );
148 
149  return ast_str_buffer(*buf);
150 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
enum ast_stream_codec_negotiation_prefs_operation_values operation
Definition: stream.h:296
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
enum ast_stream_codec_negotiation_prefs_prefer_values prefer
Definition: stream.h:294
#define ast_stream_codec_operation_to_str(value)
Safely get the name of an "operation" parameter value.
Definition: stream.h:264
enum ast_stream_codec_negotiation_prefs_keep_values keep
Definition: stream.h:298
#define ast_stream_codec_keep_to_str(value)
Safely get the name of a "keep" parameter value.
Definition: stream.h:274
#define ast_stream_codec_transcode_to_str(value)
Safely get the name of a "transcode" parameter value.
Definition: stream.h:284
enum ast_stream_codec_negotiation_prefs_transcode_values transcode
Definition: stream.h:300
#define ast_stream_codec_prefer_to_str(value)
Safely get the name of a "prefer" parameter value.
Definition: stream.h:254
#define ast_stream_codec_param_to_str(value)
Safely get the name of a preference parameter.
Definition: stream.h:244

◆ ast_stream_create_resolved()

struct ast_stream* ast_stream_create_resolved ( struct ast_stream pending_stream,
struct ast_stream configured_stream,
struct ast_stream_codec_negotiation_prefs prefs,
struct ast_str **  error_message 
)

Create a resolved stream from 2 streams.

Since
18
Parameters
pending_streamThe "live" stream created from an SDP, passed through the core, or used to create an SDP.
configured_streamThe static stream used to validate the pending stream.
prefsA pointer to an ast_stream_codec_negotiation_prefs structure.
error_messageIf supplied, error messages will be appended.

The resulting stream will contain all of the attributes and metadata of the pending stream but will contain only the formats that passed the validation specified by the ast_stream_codec_negotiation_prefs structure. This may mean that the stream's format_caps will be empty. It's up to the caller to determine what to do with the stream in that case. I.E. Free it, set it to the REMOVED state, etc. A stream will always be returned unless there was some catastrophic allocation failure.

Return values
NULLif there was some allocation failure.
Anew, resolved stream.

Definition at line 525 of file stream.c.

References ao2_cleanup, ao2_ref, ast_codec_media_type2str(), ast_format_cap_alloc, ast_format_cap_append, ast_format_cap_append_from_cap(), ast_format_cap_append_names(), ast_format_cap_empty(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_compatible(), ast_format_cap_get_format(), ast_format_cap_get_framing(), AST_FORMAT_CAP_NAMES_LEN, ast_format_cap_remove_by_type(), ast_format_cap_set_framing(), ast_free, AST_MEDIA_TYPE_UNKNOWN, ast_str_append(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_str_tmp, ast_stream_clone(), ast_stream_codec_prefs_to_str(), AST_STREAM_MAX_CODEC_PREFS_LENGTH, ast_stream_set_formats(), ast_stream_to_str(), ast_trace, buf, CODEC_NEGOTIATION_KEEP_FIRST, CODEC_NEGOTIATION_OPERATION_INTERSECT, CODEC_NEGOTIATION_OPERATION_ONLY_NONPREFERRED, CODEC_NEGOTIATION_OPERATION_ONLY_PREFERRED, CODEC_NEGOTIATION_OPERATION_UNION, CODEC_NEGOTIATION_PREFER_PENDING, ast_stream::formats, ast_stream_codec_negotiation_prefs::keep, NULL, ast_stream_codec_negotiation_prefs::operation, ast_stream_codec_negotiation_prefs::prefer, SCOPE_ENTER, SCOPE_EXIT_RTN_VALUE, TRACE_ATLEAST, and ast_stream::type.

Referenced by ast_stream_topology_create_resolved().

528 {
529  struct ast_format_cap *preferred_caps = NULL;
530  struct ast_format_cap *nonpreferred_caps = NULL;
532  struct ast_stream *joint_stream;
533  enum ast_media_type media_type = pending_stream ? pending_stream->type : AST_MEDIA_TYPE_UNKNOWN;
534  int res = 0;
535  SCOPE_ENTER(4, "Pending: %s Validation: %s Prefs: %s\n",
536  ast_str_tmp(128, ast_stream_to_str(pending_stream, &STR_TMP)),
537  ast_str_tmp(128, ast_stream_to_str(validation_stream, &STR_TMP)),
538  ast_str_tmp(128, ast_stream_codec_prefs_to_str(prefs, &STR_TMP)));
539 
540  if (!pending_stream || !validation_stream || !prefs || !joint_caps
541  || media_type == AST_MEDIA_TYPE_UNKNOWN) {
542  if (error_message) {
543  ast_str_append(error_message, 0, "Invalid arguments");
544  }
545  ao2_cleanup(joint_caps);
546  SCOPE_EXIT_RTN_VALUE(NULL, "Invalid arguments\n");
547  }
548 
550  preferred_caps = pending_stream->formats;
551  nonpreferred_caps = validation_stream->formats;
552  } else {
553  preferred_caps = validation_stream->formats;
554  nonpreferred_caps = pending_stream->formats;
555  }
556  ast_format_cap_set_framing(joint_caps, ast_format_cap_get_framing(pending_stream->formats));
557 
558  switch(prefs->operation) {
560  res = ast_format_cap_append_from_cap(joint_caps, preferred_caps, media_type);
561  break;
563  res = ast_format_cap_append_from_cap(joint_caps, nonpreferred_caps, media_type);
564  break;
566  res = ast_format_cap_get_compatible(preferred_caps, nonpreferred_caps, joint_caps);
567  break;
569  res = ast_format_cap_append_from_cap(joint_caps, preferred_caps, media_type);
570  if (res == 0) {
571  res = ast_format_cap_append_from_cap(joint_caps, nonpreferred_caps, media_type);
572  }
573  break;
574  default:
575  break;
576  }
577 
578  if (res) {
579  if (error_message) {
580  ast_str_append(error_message, 0, "No common formats available for media type '%s' ",
581  ast_codec_media_type2str(pending_stream->type));
582  ast_format_cap_append_names(preferred_caps, error_message);
583  ast_str_append(error_message, 0, "<>");
584  ast_format_cap_append_names(nonpreferred_caps, error_message);
585  ast_str_append(error_message, 0, " with prefs: ");
586  ast_stream_codec_prefs_to_str(prefs, error_message);
587  }
588 
589  ao2_cleanup(joint_caps);
590  SCOPE_EXIT_RTN_VALUE(NULL, "No common formats available\n");
591  }
592 
593  if (!ast_format_cap_empty(joint_caps)) {
594  if (prefs->keep == CODEC_NEGOTIATION_KEEP_FIRST) {
595  struct ast_format *single = ast_format_cap_get_format(joint_caps, 0);
597  ast_format_cap_append(joint_caps, single, 0);
598  ao2_ref(single, -1);
599  }
600  } else {
601  if (error_message) {
602  ast_str_append(error_message, 0, "No common formats available for media type '%s' ",
603  ast_codec_media_type2str(pending_stream->type));
604  ast_format_cap_append_names(preferred_caps, error_message);
605  ast_str_append(error_message, 0, "<>");
606  ast_format_cap_append_names(nonpreferred_caps, error_message);
607  ast_str_append(error_message, 0, " with prefs: ");
608  ast_stream_codec_prefs_to_str(prefs, error_message);
609  }
610  }
611 
612  joint_stream = ast_stream_clone(pending_stream, NULL);
613  if (!joint_stream) {
614  ao2_cleanup(joint_caps);
615  return NULL;
616  }
617 
618  /* ref to joint_caps will be transferred to the stream */
619  ast_stream_set_formats(joint_stream, joint_caps);
620 
621  if (TRACE_ATLEAST(3)) {
623  if (buf) {
624  ast_str_set(&buf, 0, "Resolved '%s' stream ", ast_codec_media_type2str(pending_stream->type));
625  ast_format_cap_append_names(preferred_caps, &buf);
626  ast_str_append(&buf, 0, "<>");
627  ast_format_cap_append_names(nonpreferred_caps, &buf);
628  ast_str_append(&buf, 0, " to ");
629  ast_format_cap_append_names(joint_caps, &buf);
630  ast_str_append(&buf, 0, " with prefs: ");
631  ast_stream_codec_prefs_to_str(prefs, &buf);
632  ast_trace(1, "%s\n", ast_str_buffer(buf));
633  ast_free(buf);
634  }
635  }
636 
637  ao2_cleanup(joint_caps);
638  SCOPE_EXIT_RTN_VALUE(joint_stream, "Joint stream: %s\n", ast_str_tmp(128, ast_stream_to_str(joint_stream, &STR_TMP)));
639 }
unsigned int ast_format_cap_get_framing(const struct ast_format_cap *cap)
Get the global framing.
Definition: format_cap.c:438
media_type
Media types generate different "dummy answers" for not accepting the offer of a media stream...
Definition: sip.h:489
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define AST_STREAM_MAX_CODEC_PREFS_LENGTH
Define for allocating buffer space for to_str() functions.
Definition: stream.h:307
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
#define AST_FORMAT_CAP_NAMES_LEN
Definition: format_cap.h:326
enum ast_stream_codec_negotiation_prefs_operation_values operation
Definition: stream.h:296
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:347
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
#define ast_trace(level,...)
Print a basic trace message.
Definition: logger.h:692
Definition of a media format.
Definition: format.c:43
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
enum ast_stream_codec_negotiation_prefs_prefer_values prefer
Definition: stream.h:294
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.
Definition: stream.c:132
void ast_format_cap_set_framing(struct ast_format_cap *cap, unsigned int framing)
Set the global framing.
Definition: format_cap.c:136
#define NULL
Definition: resample.c:96
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_str_tmp(init_len, __expr)
Definition: strings.h:1136
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
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.
Definition: stream.c:337
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_format_cap_append(cap, format, framing)
Definition: format_cap.h:103
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
enum ast_stream_codec_negotiation_prefs_keep_values keep
Definition: stream.h:298
void ast_format_cap_remove_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Remove all formats matching a specific format type.
Definition: format_cap.c:525
void ast_stream_set_formats(struct ast_stream *stream, struct ast_format_cap *caps)
Set the current negotiated formats of a stream.
Definition: stream.c:365
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define ast_free(a)
Definition: astmm.h:182
#define SCOPE_ENTER(level,...)
Non RAII_VAR Scope Trace macros The advantage of these macros is that the EXITs will have the actual ...
Definition: logger.h:780
#define TRACE_ATLEAST(level)
Definition: logger.h:637
#define SCOPE_EXIT_RTN_VALUE(__return_value,...)
Scope Exit with return value.
Definition: logger.h:875
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_stream * ast_stream_clone(const struct ast_stream *stream, const char *name)
Create a deep clone of an existing stream.
Definition: stream.c:257
ast_media_type
Types of media.
Definition: codec.h:30
int ast_format_cap_empty(const struct ast_format_cap *cap)
Determine if a format cap has no formats in it.
Definition: format_cap.c:746
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
int ast_format_cap_get_compatible(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result)
Find the compatible formats between two capabilities structures.
Definition: format_cap.c:630
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
const char * ast_format_cap_append_names(const struct ast_format_cap *cap, struct ast_str **buf)
Append the names of codecs of a set of formats to an ast_str buffer.
Definition: format_cap.c:741

◆ ast_stream_free()

void ast_stream_free ( struct ast_stream stream)

Destroy a media stream representation.

Parameters
streamThe media stream
Since
15

Definition at line 292 of file stream.c.

References ao2_cleanup, ast_free, ast_rtp_codecs_payloads_destroy(), ast_variables_destroy(), ast_stream::formats, ast_stream::metadata, and ast_stream::rtp_codecs.

Referenced by append_all_streams(), append_source_stream(), ast_sip_session_create_outgoing(), ast_stream_topology_clone(), ast_stream_topology_create_from_format_cap(), ast_stream_topology_create_resolved(), ast_stream_topology_del_stream(), ast_stream_topology_set_stream(), AST_TEST_DEFINE(), build_topology(), handle_incoming_sdp(), remove_all_original_streams(), sdp_requires_deferral(), sip_session_refresh(), stream_echo_topology_alloc(), stream_topology_destroy(), and t38_create_media_state().

293 {
294  if (!stream) {
295  return;
296  }
297 
299 
300  if (stream->rtp_codecs) {
302  }
303 
304  ao2_cleanup(stream->formats);
305 
306  ast_free(stream);
307 }
struct ast_rtp_codecs * rtp_codecs
The rtp_codecs used by the stream.
Definition: stream.c:115
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
#define ast_free(a)
Definition: astmm.h:182
void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs)
Destroy the contents of an RTP codecs structure (but not the structure itself)
Definition: rtp_engine.c:974
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_variable * metadata
Stream metadata vector.
Definition: stream.c:105

◆ ast_stream_get_format_count()

int ast_stream_get_format_count ( const struct ast_stream stream)

Get the count of the current negotiated formats of a stream.

Parameters
streamThe media stream
Returns
The count of negotiated formats
Since
18

Definition at line 358 of file stream.c.

References ast_assert, ast_format_cap_count(), ast_stream::formats, and NULL.

Referenced by ast_sip_session_create_outgoing(), and ast_stream_topology_create_resolved().

359 {
360  ast_assert(stream != NULL);
361 
362  return stream->formats ? ast_format_cap_count(stream->formats) : 0;
363 }
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96

◆ ast_stream_get_formats()

const struct ast_format_cap* ast_stream_get_formats ( const struct ast_stream stream)

Get the current negotiated formats of a stream.

Parameters
streamThe media stream
Return values
non-NULLsuccess
NULLfailure
Note
The reference count is not increased
Since
15

Definition at line 330 of file stream.c.

References ast_assert, ast_stream::formats, and NULL.

Referenced by ast_sip_session_create_joint_call_stream(), ast_stream_topology_equal(), AST_TEST_DEFINE(), create_outgoing_sdp_stream(), handle_showchan(), is_compatible_format(), local_request_with_stream_topology(), media_offer_read_av(), media_offer_write_av(), native_rtp_request_stream_topology_update(), simple_bridge_request_stream_topology_update(), sip_session_refresh(), and validate_stream().

331 {
332  ast_assert(stream != NULL);
333 
334  return stream->formats;
335 }
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96

◆ ast_stream_get_group()

int ast_stream_get_group ( const struct ast_stream stream)

Get the stream group that a stream is part of.

Parameters
streamThe stream
Returns
the numerical stream group (-1 if not in a group)
Since
15.2.0

Definition at line 1077 of file stream.c.

References ast_assert, ast_stream::group, and NULL.

Referenced by add_msid_to_stream(), ast_stream_topology_clone(), and handle_showchan().

1078 {
1079  ast_assert(stream != NULL);
1080 
1081  return stream->group;
1082 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
int group
The group that the stream is part of.
Definition: stream.c:110

◆ ast_stream_get_metadata()

const char* ast_stream_get_metadata ( const struct ast_stream stream,
const char *  m_key 
)

Get a stream metadata value.

Parameters
streamThe media stream
m_keyAn arbitrary metadata key
Return values
non-NULLmetadata value
NULLfailure or not found
Since
15.5

Definition at line 423 of file stream.c.

References ast_assert_return, ast_stream::metadata, ast_variable::name, ast_variable::next, NULL, and ast_variable::value.

Referenced by add_msid_to_stream(), AST_TEST_DEFINE(), handle_incoming_sdp(), sdp_requires_deferral(), and sip_session_refresh().

424 {
425  struct ast_variable *v;
426 
427  ast_assert_return(stream != NULL, NULL);
428  ast_assert_return(m_key != NULL, NULL);
429 
430  for (v = stream->metadata; v; v = v->next) {
431  if (strcmp(v->name, m_key) == 0) {
432  return v->value;
433  }
434  }
435 
436  return NULL;
437 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
#define ast_assert_return(a,...)
Definition: utils.h:696
struct ast_variable * metadata
Stream metadata vector.
Definition: stream.c:105

◆ ast_stream_get_metadata_list()

struct ast_variable* ast_stream_get_metadata_list ( const struct ast_stream stream)

Get all stream metadata keys.

Parameters
streamThe media stream
Return values
Anast_variable list of the metadata key/value pairs.
NULLif error or no variables are set.

When you're finished with the list, you must call ast_variables_destroy(list);

Since
15.5

Definition at line 439 of file stream.c.

References ast_assert_return, ast_variable_list_append, ast_variable_new, ast_variables_destroy(), ast_stream::metadata, ast_variable::name, ast_variable::next, NULL, and ast_variable::value.

Referenced by ast_stream_clone(), and handle_showchan().

440 {
441  struct ast_variable *v;
442  struct ast_variable *vout = NULL;
443 
444  ast_assert_return(stream != NULL, NULL);
445 
446  for (v = stream->metadata; v; v = v->next) {
447  struct ast_variable *vt = ast_variable_new(v->name, v->value, "");
448 
449  if (!vt) {
450  ast_variables_destroy(vout);
451  return NULL;
452  }
453 
454  ast_variable_list_append(&vout, vt);
455  }
456 
457  return vout;
458 }
struct ast_variable * next
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
#define ast_variable_new(name, value, filename)
#define ast_assert_return(a,...)
Definition: utils.h:696
struct ast_variable * metadata
Stream metadata vector.
Definition: stream.c:105
#define ast_variable_list_append(head, new_var)

◆ ast_stream_get_name()

const char* ast_stream_get_name ( const struct ast_stream stream)

Get the name of a stream.

Parameters
streamThe media stream
Return values
non-NULLsuccess
NULLfailure
Since
15

Definition at line 309 of file stream.c.

References ast_assert, ast_stream::name, and NULL.

Referenced by ast_sip_session_media_state_add(), ast_stream_topology_equal(), AST_TEST_DEFINE(), handle_incoming_sdp(), handle_showchan(), is_media_state_valid(), is_video_dest(), is_video_source(), remove_all_original_streams(), resolve_refresh_media_states(), sdp_requires_deferral(), sip_session_refresh(), softmix_bridge_stream_sources_update(), and validate_stream().

310 {
311  ast_assert(stream != NULL);
312 
313  return stream->name;
314 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
char name[0]
Name for the stream within the context of the channel it is on.
Definition: stream.c:120

◆ ast_stream_get_position()

int ast_stream_get_position ( const struct ast_stream stream)

Get the position of the stream in the topology.

Parameters
streamThe media stream
Returns
The position of the stream (-1 on error)
Since
15

Definition at line 500 of file stream.c.

References ast_assert, NULL, and ast_stream::position.

Referenced by __ast_read(), apply_negotiated_sdp_stream(), AST_TEST_DEFINE(), ast_write_stream(), check_stream_positions(), create_outgoing_sdp_stream(), stream_echo_write_error(), and tech_write().

501 {
502  ast_assert(stream != NULL);
503 
504  return stream->position;
505 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
unsigned int position
The position of the stream in the topology.
Definition: stream.c:90

◆ ast_stream_get_rtp_codecs()

struct ast_rtp_codecs* ast_stream_get_rtp_codecs ( const struct ast_stream stream)

Get rtp_codecs associated with the stream.

Parameters
streamThe media stream
Returns
The rtp_codecs
Since
15.5

Definition at line 507 of file stream.c.

References ast_assert, NULL, and ast_stream::rtp_codecs.

508 {
509  ast_assert(stream != NULL);
510 
511  return stream->rtp_codecs;
512 }
struct ast_rtp_codecs * rtp_codecs
The rtp_codecs used by the stream.
Definition: stream.c:115
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96

◆ ast_stream_get_state()

enum ast_stream_state ast_stream_get_state ( const struct ast_stream stream)

◆ ast_stream_get_type()

enum ast_media_type ast_stream_get_type ( const struct ast_stream stream)

◆ ast_stream_set_formats()

void ast_stream_set_formats ( struct ast_stream stream,
struct ast_format_cap caps 
)

Set the current negotiated formats of a stream.

Parameters
streamThe media stream
capsThe current negotiated formats
Note
The new format capabilities structure has its refcount bumped and any existing format capabilities structure has its refcount decremented.
Since
15

Definition at line 365 of file stream.c.

References ao2_bump, ao2_cleanup, ast_assert, ast_stream::formats, and NULL.

Referenced by apply_cap_to_bundled(), ast_sip_session_create_joint_call_stream(), ast_stream_create_resolved(), ast_stream_topology_create_from_format_cap(), AST_TEST_DEFINE(), build_topology(), local_request_with_stream_topology(), media_offer_write_av(), native_rtp_request_stream_topology_update(), simple_bridge_request_stream_topology_update(), sip_session_refresh(), and t38_create_media_state().

366 {
367  ast_assert(stream != NULL);
368 
369  ao2_cleanup(stream->formats);
370  stream->formats = ao2_bump(caps);
371 }
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define ao2_bump(obj)
Definition: astobj2.h:491
#define ao2_cleanup(obj)
Definition: astobj2.h:1958

◆ ast_stream_set_group()

void ast_stream_set_group ( struct ast_stream stream,
int  group 
)

Set the stream group for a stream.

Parameters
streamThe stream
groupThe group the stream is part of
Since
15.2.0

Definition at line 1084 of file stream.c.

References ast_assert, ast_stream::group, and NULL.

Referenced by ast_stream_topology_clone(), and set_remote_mslabel_and_stream_group().

1085 {
1086  ast_assert(stream != NULL);
1087 
1088  stream->group = group;
1089 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
int group
The group that the stream is part of.
Definition: stream.c:110

◆ ast_stream_set_metadata()

int ast_stream_set_metadata ( struct ast_stream stream,
const char *  m_key,
const char *  value 
)

Set a stream metadata value.

Parameters
streamThe media stream
m_keyAn arbitrary metadata key
valueString metadata value or NULL to remove existing value
Return values
-1failure
0success
Since
15.5

Definition at line 460 of file stream.c.

References ast_assert_return, ast_free, ast_variable_list_append, ast_variable_new, ast_stream::metadata, ast_variable::name, ast_variable::next, and NULL.

Referenced by add_msid_to_stream(), append_source_stream(), AST_TEST_DEFINE(), handle_incoming_sdp(), media_offer_write_av(), and sdp_requires_deferral().

461 {
462  struct ast_variable *v;
463  struct ast_variable *prev;
464 
465  ast_assert_return(stream != NULL, -1);
466  ast_assert_return(m_key != NULL, -1);
467 
468  prev = NULL;
469  v = stream->metadata;
470  while(v) {
471  struct ast_variable *next = v->next;
472  if (strcmp(v->name, m_key) == 0) {
473  if (prev) {
474  prev->next = next;
475  } else {
476  stream->metadata = next;
477  }
478  ast_free(v);
479  break;
480  } else {
481  prev = v;
482  }
483  v = next;
484  }
485 
486  if (!value) {
487  return 0;
488  }
489 
490  v = ast_variable_new(m_key, value, "");
491  if (!v) {
492  return -1;
493  }
494 
495  ast_variable_list_append(&stream->metadata, v);
496 
497  return 0;
498 }
struct ast_variable * next
Structure for variables, used for configurations and for channel variables.
#define NULL
Definition: resample.c:96
int value
Definition: syslog.c:37
#define ast_variable_new(name, value, filename)
#define ast_free(a)
Definition: astmm.h:182
#define ast_assert_return(a,...)
Definition: utils.h:696
struct ast_variable * metadata
Stream metadata vector.
Definition: stream.c:105
#define ast_variable_list_append(head, new_var)

◆ ast_stream_set_rtp_codecs()

void ast_stream_set_rtp_codecs ( struct ast_stream stream,
struct ast_rtp_codecs rtp_codecs 
)

Set rtp_codecs associated with the stream.

Parameters
streamThe media stream
rtp_codecsThe rtp_codecs
Since
15.5

Definition at line 514 of file stream.c.

References ast_assert, ast_rtp_codecs_payloads_destroy(), NULL, and ast_stream::rtp_codecs.

515 {
516  ast_assert(stream != NULL);
517 
518  if (stream->rtp_codecs) {
520  }
521 
522  stream->rtp_codecs = rtp_codecs;
523 }
struct ast_rtp_codecs * rtp_codecs
The rtp_codecs used by the stream.
Definition: stream.c:115
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs)
Destroy the contents of an RTP codecs structure (but not the structure itself)
Definition: rtp_engine.c:974

◆ ast_stream_set_state()

void ast_stream_set_state ( struct ast_stream stream,
enum ast_stream_state  state 
)

Set the state of a stream.

Parameters
streamThe media stream
stateThe new state that the stream is in
Note
Used by stream creator to update internal state
Since
15

Definition at line 380 of file stream.c.

References ast_assert, NULL, ast_stream::state, and state.

Referenced by append_source_stream(), ast_stream_topology_create_resolved(), AST_TEST_DEFINE(), create_outgoing_sdp_stream(), handle_incoming_sdp(), handle_negotiated_sdp(), handle_negotiated_sdp_session_media(), native_rtp_request_stream_topology_update(), remove_all_original_streams(), remove_destination_streams(), remove_stream_from_bundle(), resolve_refresh_media_states(), sdp_requires_deferral(), simple_bridge_request_stream_topology_update(), sip_session_refresh(), softmix_bridge_stream_sources_update(), stream_echo_topology_alloc(), t38_create_media_state(), test_stream_alloc(), and unreal_colp_stream_topology_request_change().

381 {
382  ast_assert(stream != NULL);
383 
384  stream->state = state;
385 
386 }
enum sip_cc_notify_state state
Definition: chan_sip.c:959
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
enum ast_stream_state state
The current state of the stream.
Definition: stream.c:100

◆ ast_stream_set_type()

void ast_stream_set_type ( struct ast_stream stream,
enum ast_media_type  type 
)

Change the media type of a stream.

Parameters
streamThe media stream
typeThe new media type
Since
15

Definition at line 323 of file stream.c.

References ast_assert, NULL, ast_stream::type, and type.

Referenced by AST_TEST_DEFINE().

324 {
325  ast_assert(stream != NULL);
326 
327  stream->type = type;
328 }
static const char type[]
Definition: chan_ooh323.c:109
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85

◆ ast_stream_state2str()

const char* ast_stream_state2str ( enum ast_stream_state  state)

Convert the state of a stream into a string.

Parameters
stateThe stream state
Returns
The state of the stream in string format
Since
15

Definition at line 388 of file stream.c.

References AST_STREAM_STATE_INACTIVE, AST_STREAM_STATE_RECVONLY, AST_STREAM_STATE_REMOVED, AST_STREAM_STATE_SENDONLY, and AST_STREAM_STATE_SENDRECV.

Referenced by handle_showchan(), resolve_refresh_media_states(), and softmix_bridge_stream_sources_update().

389 {
390  switch (state) {
392  return "removed";
394  return "sendrecv";
396  return "sendonly";
398  return "recvonly";
400  return "inactive";
401  default:
402  return "<unknown>";
403  }
404 }
Set when the stream has been removed/declined.
Definition: stream.h:78
Set when the stream is not sending OR receiving media.
Definition: stream.h:94
Set when the stream is sending and receiving media.
Definition: stream.h:82
Set when the stream is sending media only.
Definition: stream.h:86
Set when the stream is receiving media only.
Definition: stream.h:90

◆ ast_stream_str2state()

enum ast_stream_state ast_stream_str2state ( const char *  str)

Convert a string to a stream state.

Parameters
strThe string to convert
Returns
The stream state
Since
15.0.0

Definition at line 406 of file stream.c.

References AST_STREAM_STATE_INACTIVE, AST_STREAM_STATE_RECVONLY, AST_STREAM_STATE_REMOVED, AST_STREAM_STATE_SENDONLY, and AST_STREAM_STATE_SENDRECV.

407 {
408  if (!strcmp("sendrecv", str)) {
410  }
411  if (!strcmp("sendonly", str)) {
413  }
414  if (!strcmp("recvonly", str)) {
416  }
417  if (!strcmp("inactive", str)) {
419  }
421 }
Set when the stream has been removed/declined.
Definition: stream.h:78
Set when the stream is not sending OR receiving media.
Definition: stream.h:94
const char * str
Definition: app_jack.c:147
Set when the stream is sending and receiving media.
Definition: stream.h:82
Set when the stream is sending media only.
Definition: stream.h:86
Set when the stream is receiving media only.
Definition: stream.h:90

◆ ast_stream_to_str()

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.

Since
18
Parameters
streamA stream
bufA pointer to an ast_str* used for the output.
Return values
""(empty string) if either buf or *buf are NULL
(null stream)if *stream was NULL
<stream_representation>otherwise
Warning
No attempt should ever be made to free the returned char * and it should be dup'd if needed after the ast_str is freed.

Return format: <name>:<media_type>:<stream_state> (formats)

Sample return: "audio:audio:sendrecv (ulaw,g722)"

Definition at line 337 of file stream.c.

References ast_codec_media_type2str(), ast_format_cap_append_names(), ast_str_append(), ast_str_buffer(), ast_stream_state_map, ast_stream::formats, ast_stream::name, ast_stream::position, S_OR, ast_stream::state, and ast_stream::type.

Referenced by add_sdp_streams(), apply_negotiated_sdp_stream(), ast_stream_create_resolved(), ast_stream_topology_to_str(), create_local_sdp(), create_outgoing_sdp_stream(), handle_incoming_sdp(), is_media_state_valid(), resolve_refresh_media_states(), and softmix_bridge_stream_sources_update().

338 {
339  if (!buf || !*buf) {
340  return "";
341  }
342 
343  if (!stream) {
344  ast_str_append(buf, 0, "(null stream)");
345  return ast_str_buffer(*buf);
346  }
347 
348  ast_str_append(buf, 0, "%d:%s:%s:%s ",
349  stream->position,
350  S_OR(stream->name, "noname"),
352  ast_stream_state_map[stream->state]);
353  ast_format_cap_append_names(stream->formats, buf);
354 
355  return ast_str_buffer(*buf);
356 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
const char * ast_stream_state_map[]
Stream state enum to string map.
Definition: stream.c:223
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:347
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
enum ast_stream_state state
The current state of the stream.
Definition: stream.c:100
char name[0]
Name for the stream within the context of the channel it is on.
Definition: stream.c:120
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
unsigned int position
The position of the stream in the topology.
Definition: stream.c:90
const char * ast_format_cap_append_names(const struct ast_format_cap *cap, struct ast_str **buf)
Append the names of codecs of a set of formats to an ast_str buffer.
Definition: format_cap.c:741

◆ ast_stream_topology_alloc()

struct ast_stream_topology* ast_stream_topology_alloc ( void  )

Create a stream topology.

Return values
non-NULLsuccess
NULLfailure
Since
15
Note
This returns an ao2 refcounted object

Definition at line 650 of file stream.c.

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_ref, AST_VECTOR_INIT, NULL, stream_topology_destroy(), and TOPOLOGY_INITIAL_STREAM_COUNT.

Referenced by __ast_channel_alloc_ap(), ast_channel_set_stream_topology(), ast_sip_session_create_outgoing(), ast_stream_topology_clone(), ast_stream_topology_create_from_format_cap(), ast_stream_topology_create_resolved(), AST_TEST_DEFINE(), ast_unreal_indicate(), build_topology(), handle_incoming_sdp(), make_channel(), sdp_requires_deferral(), sfu_topologies_on_join(), sfu_topologies_on_source_change(), softmix_bridge_stream_sources_update(), stream_echo_topology_alloc(), and t38_create_media_state().

651 {
652  struct ast_stream_topology *topology;
653 
655  if (!topology) {
656  return NULL;
657  }
658 
659  if (AST_VECTOR_INIT(&topology->streams, TOPOLOGY_INITIAL_STREAM_COUNT)) {
660  ao2_ref(topology, -1);
661  topology = NULL;
662  }
663 
664  return topology;
665 }
static void stream_topology_destroy(void *data)
Definition: stream.c:641
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define TOPOLOGY_INITIAL_STREAM_COUNT
Definition: stream.c:649

◆ ast_stream_topology_append_stream()

int ast_stream_topology_append_stream ( struct ast_stream_topology topology,
struct ast_stream stream 
)

Append a stream to the topology.

Parameters
topologyThe topology of streams
streamThe stream to append
Returns
the position of the stream in the topology (-1 on error)
Since
15
Note
If the stream's name is empty, it'll be set to <stream_type>-<position>

Definition at line 748 of file stream.c.

References ast_assert, ast_codec_media_type2str(), ast_strlen_zero, AST_VECTOR_APPEND, AST_VECTOR_SIZE, MIN_STREAM_NAME_LEN, ast_stream::name, ast_stream::position, and ast_stream::type.

Referenced by append_all_streams(), append_source_stream(), ast_sip_session_create_outgoing(), ast_stream_topology_create_from_format_cap(), ast_stream_topology_create_resolved(), AST_TEST_DEFINE(), ast_unreal_indicate(), build_topology(), make_channel(), resolve_refresh_media_states(), sip_session_refresh(), stream_echo_topology_alloc(), and test_media_add().

749 {
750  ast_assert(topology && stream);
751 
752  if (AST_VECTOR_APPEND(&topology->streams, stream)) {
753  return -1;
754  }
755 
756  stream->position = AST_VECTOR_SIZE(&topology->streams) - 1;
757 
758  if (ast_strlen_zero(stream->name)) {
759  snprintf(stream->name, MIN_STREAM_NAME_LEN, "%s-%d", ast_codec_media_type2str(stream->type), stream->position);
760  }
761 
762  return AST_VECTOR_SIZE(&topology->streams) - 1;
763 }
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:347
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define MIN_STREAM_NAME_LEN
Definition: stream.c:231
#define ast_assert(a)
Definition: utils.h:695
#define ast_strlen_zero(foo)
Definition: strings.h:52
char name[0]
Name for the stream within the context of the channel it is on.
Definition: stream.c:120
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611
unsigned int position
The position of the stream in the topology.
Definition: stream.c:90

◆ ast_stream_topology_clone()

struct ast_stream_topology* ast_stream_topology_clone ( const struct ast_stream_topology topology)

Create a deep clone of an existing stream topology.

Parameters
topologyThe existing topology of streams
Return values
non-NULLsuccess
NULLfailure
Since
15
Note
This returns an ao2 refcounted object

Definition at line 667 of file stream.c.

References ast_assert, ast_stream_clone(), ast_stream_free(), ast_stream_get_group(), ast_stream_set_group(), ast_stream_topology_alloc(), ast_stream_topology_free(), AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_SIZE, and NULL.

Referenced by ast_sip_session_create_outgoing(), ast_sip_session_media_state_clone(), AST_TEST_DEFINE(), ast_unreal_alloc_stream_topology(), ast_unreal_new_channels(), chan_pjsip_new(), create_local_sdp(), dial_exec_full(), do_forward(), handle_negotiated_sdp(), local_request_with_stream_topology(), media_offer_read_av(), media_offer_write_av(), native_rtp_request_stream_topology_update(), session_refresh_state_get_or_alloc(), sfu_topologies_on_join(), sfu_topologies_on_source_change(), simple_bridge_request_stream_topology_update(), softmix_bridge_stream_sources_update(), topology_change_refresh_data_alloc(), and unreal_colp_stream_topology_request_change().

669 {
670  struct ast_stream_topology *new_topology;
671  int i;
672 
673  ast_assert(topology != NULL);
674 
675  new_topology = ast_stream_topology_alloc();
676  if (!new_topology) {
677  return NULL;
678  }
679 
680  for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
681  struct ast_stream *existing = AST_VECTOR_GET(&topology->streams, i);
682  struct ast_stream *stream = ast_stream_clone(existing, NULL);
683 
684  if (!stream || AST_VECTOR_APPEND(&new_topology->streams, stream)) {
685  ast_stream_free(stream);
686  ast_stream_topology_free(new_topology);
687  return NULL;
688  }
689 
690  ast_stream_set_group(stream, ast_stream_get_group(existing));
691  }
692 
693  return new_topology;
694 }
struct ast_stream_topology * ast_stream_topology_alloc(void)
Create a stream topology.
Definition: stream.c:650
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:743
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
void ast_stream_free(struct ast_stream *stream)
Destroy a media stream representation.
Definition: stream.c:292
void ast_stream_set_group(struct ast_stream *stream, int group)
Set the stream group for a stream.
Definition: stream.c:1084
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
struct ast_stream * ast_stream_clone(const struct ast_stream *stream, const char *name)
Create a deep clone of an existing stream.
Definition: stream.c:257
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611
int ast_stream_get_group(const struct ast_stream *stream)
Get the stream group that a stream is part of.
Definition: stream.c:1077

◆ ast_stream_topology_create_from_format_cap()

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 media types in format_cap into separate streams.

Parameters
capsThe format capabilities structure (NULL creates an empty topology)
Return values
non-NULLsuccess
NULLfailure
Note
The format capabilities reference is NOT altered by this function since a new format capabilities structure is created for each media type.
Each stream will have its name set to the corresponding media type. For example: "audio".
Each stream will be set to the sendrecv state.
Since
15

Definition at line 848 of file stream.c.

References ao2_cleanup, ao2_ref, ast_codec_media_type2str(), ast_format_cap_alloc, ast_format_cap_append_from_cap(), ast_format_cap_count(), AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_get_framing(), ast_format_cap_has_type(), ast_format_cap_set_framing(), AST_MEDIA_TYPE_END, AST_MEDIA_TYPE_UNKNOWN, ast_stream_alloc(), ast_stream_free(), ast_stream_set_formats(), AST_STREAM_STATE_SENDRECV, ast_stream_topology_alloc(), ast_stream_topology_append_stream(), ast_stream_topology_free(), MIN_STREAM_NAME_LEN, ast_stream::name, NULL, ast_stream::position, ast_stream::state, ast_stream::type, and type.

Referenced by ast_channel_nativeformats_set(), AST_TEST_DEFINE(), ast_unreal_alloc(), chan_pjsip_request(), local_request(), request_channel(), and sip_endpoint_apply_handler().

850 {
851  struct ast_stream_topology *topology;
852  enum ast_media_type type;
853 
854  topology = ast_stream_topology_alloc();
855  if (!topology || !cap || !ast_format_cap_count(cap)) {
856  return topology;
857  }
858 
859  for (type = AST_MEDIA_TYPE_UNKNOWN + 1; type < AST_MEDIA_TYPE_END; type++) {
860  struct ast_format_cap *new_cap;
861  struct ast_stream *stream;
862 
863  if (!ast_format_cap_has_type(cap, type)) {
864  continue;
865  }
866 
868  if (!new_cap) {
869  ast_stream_topology_free(topology);
870  return NULL;
871  }
872 
874  if (ast_format_cap_append_from_cap(new_cap, cap, type)) {
875  ao2_cleanup(new_cap);
876  ast_stream_topology_free(topology);
877  return NULL;
878  }
879 
880  stream = ast_stream_alloc(NULL, type);
881  if (!stream) {
882  ao2_cleanup(new_cap);
883  ast_stream_topology_free(topology);
884  return NULL;
885  }
886 
887  ast_stream_set_formats(stream, new_cap);
888  ao2_ref(new_cap, -1);
890  if (ast_stream_topology_append_stream(topology, stream) == -1) {
891  ast_stream_free(stream);
892  ast_stream_topology_free(topology);
893  return NULL;
894  }
895 
896  snprintf(stream->name, MIN_STREAM_NAME_LEN, "%s-%d", ast_codec_media_type2str(stream->type), stream->position);
897  }
898 
899  return topology;
900 }
struct ast_stream_topology * ast_stream_topology_alloc(void)
Create a stream topology.
Definition: stream.c:650
static const char type[]
Definition: chan_ooh323.c:109
unsigned int ast_format_cap_get_framing(const struct ast_format_cap *cap)
Get the global framing.
Definition: format_cap.c:438
void ast_stream_topology_free(struct ast_stream_topology *topology)
Unreference and destroy a stream topology.
Definition: stream.c:743
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:347
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
#define MIN_STREAM_NAME_LEN
Definition: stream.c:231
void ast_format_cap_set_framing(struct ast_format_cap *cap, unsigned int framing)
Set the global framing.
Definition: format_cap.c:136
#define NULL
Definition: resample.c:96
enum ast_stream_state state
The current state of the stream.
Definition: stream.c:100
void ast_stream_free(struct ast_stream *stream)
Destroy a media stream representation.
Definition: stream.c:292
char name[0]
Name for the stream within the context of the channel it is on.
Definition: stream.c:120
struct ast_stream * ast_stream_alloc(const char *name, enum ast_media_type type)
Create a new media stream representation.
Definition: stream.c:233
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
#define ao2_ref(o, delta)
Definition: astobj2.h:464
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
int ast_stream_topology_append_stream(struct ast_stream_topology *topology, struct ast_stream *stream)
Append a stream to the topology.
Definition: stream.c:748
void ast_stream_set_formats(struct ast_stream *stream, struct ast_format_cap *caps)
Set the current negotiated formats of a stream.
Definition: stream.c:365
Set when the stream is sending and receiving media.
Definition: stream.h:82
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
ast_media_type
Types of media.
Definition: codec.h:30
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
unsigned int position
The position of the stream in the topology.
Definition: stream.c:90
int ast_format_cap_has_type(const struct ast_format_cap *cap, enum ast_media_type type)
Find out if the capabilities structure has any formats of a specific type.
Definition: format_cap.c:615

◆ ast_stream_topology_create_resolved()

struct ast_stream_topology* ast_stream_topology_create_resolved ( struct ast_stream_topology pending_topology,
struct ast_stream_topology validation_topology,
struct ast_stream_codec_negotiation_prefs prefs,
struct ast_str **  error_message 
)

Create a resolved stream topology from 2 topologies.

Since
18
Parameters
pending_topologyThe "live" topology created from an SDP, passed through the core, or used to create an SDP.
configured_topologyThe static topology used to validate the pending topology. It MUST have only 1 stream per media type.
prefsA pointer to an ast_stream_codec_negotiation_prefs structure.
error_messageIf supplied, error messages will be appended.

The streams in the resolved topology will contain all of the attributes of the corresponding stream from the pending topology. It's format_caps however will contain only the formats that passed the validation specified by the ast_stream_codec_negotiation_prefs structure. This may mean that some of the streams format_caps will be empty. If that's the case, the stream will be in a REMOVED state. With those rules in mind, a resolved topology will always be returned (unless there's some catastrophic allocation failure) and the resolved topology is guaranteed to have the same number of streams, in the same order, as the pending topology.

Return values
NULLif there was some allocation failure.
Thejoint topology.

Definition at line 1030 of file stream.c.

References ao2_cleanup, ast_stream_clone(), ast_stream_create_resolved(), ast_stream_free(), ast_stream_get_format_count(), ast_stream_set_state(), AST_STREAM_STATE_REMOVED, ast_stream_topology_alloc(), ast_stream_topology_append_stream(), ast_stream_topology_get_first_stream_by_type(), AST_VECTOR_GET, AST_VECTOR_SIZE, NULL, and ast_stream::type.

1033 {
1034  struct ast_stream_topology *joint_topology = ast_stream_topology_alloc();
1035  int res = 0;
1036  int i;
1037 
1038  if (!pending_topology || !configured_topology || !joint_topology) {
1039  ao2_cleanup(joint_topology);
1040  return NULL;
1041  }
1042 
1043  for (i = 0; i < AST_VECTOR_SIZE(&pending_topology->streams); i++) {
1044  struct ast_stream *pending_stream = AST_VECTOR_GET(&pending_topology->streams, i);
1045  struct ast_stream *configured_stream =
1046  ast_stream_topology_get_first_stream_by_type(configured_topology, pending_stream->type);
1047  struct ast_stream *joint_stream;
1048 
1049  if (!configured_stream) {
1050  joint_stream = ast_stream_clone(pending_stream, NULL);
1051  if (!joint_stream) {
1052  ao2_cleanup(joint_topology);
1053  return NULL;
1054  }
1056  } else {
1057  joint_stream = ast_stream_create_resolved(pending_stream, configured_stream, prefs, error_message);
1058  if (!joint_stream) {
1059  ao2_cleanup(joint_topology);
1060  return NULL;
1061  } else if (ast_stream_get_format_count(joint_stream) == 0) {
1063  }
1064  }
1065 
1066  res = ast_stream_topology_append_stream(joint_topology, joint_stream);
1067  if (res < 0) {
1068  ast_stream_free(joint_stream);
1069  ao2_cleanup(joint_topology);
1070  return NULL;
1071  }
1072  }
1073 
1074  return joint_topology;
1075 }
struct ast_stream_topology * ast_stream_topology_alloc(void)
Create a stream topology.
Definition: stream.c:650
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.
Definition: stream.c:525
Set when the stream has been removed/declined.
Definition: stream.h:78
int ast_stream_get_format_count(const struct ast_stream *stream)
Get the count of the current negotiated formats of a stream.
Definition: stream.c:358
#define NULL
Definition: resample.c:96
void ast_stream_free(struct ast_stream *stream)
Destroy a media stream representation.
Definition: stream.c:292
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.
Definition: stream.c:964
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
int ast_stream_topology_append_stream(struct ast_stream_topology *topology, struct ast_stream *stream)
Append a stream to the topology.
Definition: stream.c:748
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_stream * ast_stream_clone(const struct ast_stream *stream, const char *name)
Create a deep clone of an existing stream.
Definition: stream.c:257
void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state)
Set the state of a stream.
Definition: stream.c:380
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_stream_topology_del_stream()

int ast_stream_topology_del_stream ( struct ast_stream_topology topology,
unsigned int  position 
)

Delete a specified stream from the given topology.

Since
15.0.0
Parameters
topologyThe topology of streams.
positionThe topology position to delete.
Note
Deleting a stream will completely remove it from the topology as if it never existed in it. i.e., Any following stream positions will shift down so there is no gap.
Return values
0on success.
-1on failure.
Returns
Nothing

Definition at line 825 of file stream.c.

References ast_assert, ast_stream_free(), AST_VECTOR_GET, AST_VECTOR_REMOVE_ORDERED, AST_VECTOR_SIZE, NULL, and ast_stream::position.

Referenced by AST_TEST_DEFINE(), and sip_session_refresh().

827 {
828  struct ast_stream *stream;
829 
830  ast_assert(topology != NULL);
831 
832  if (AST_VECTOR_SIZE(&topology->streams) <= position) {
833  return -1;
834  }
835 
836  stream = AST_VECTOR_REMOVE_ORDERED(&topology->streams, position);
837  ast_stream_free(stream);
838 
839  /* Fix up higher stream position indices */
840  for (; position < AST_VECTOR_SIZE(&topology->streams); ++position) {
841  stream = AST_VECTOR_GET(&topology->streams, position);
842  stream->position = position;
843  }
844 
845  return 0;
846 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
void ast_stream_free(struct ast_stream *stream)
Destroy a media stream representation.
Definition: stream.c:292
#define AST_VECTOR_REMOVE_ORDERED(vec, idx)
Remove an element from a vector by index while maintaining order.
Definition: vector.h:448
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611
unsigned int position
The position of the stream in the topology.
Definition: stream.c:90

◆ ast_stream_topology_equal()

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.

Parameters
leftThe left topology
rightThe right topology
Return values
1topologies are equivalent
0topologies differ
Since
15

Definition at line 696 of file stream.c.

References ast_assert, ast_format_cap_count(), ast_format_cap_identical(), ast_stream_get_formats(), ast_stream_get_name(), ast_stream_get_state(), ast_stream_get_type(), ast_stream_topology_get_count(), ast_stream_topology_get_stream(), and NULL.

Referenced by ast_channel_request_stream_topology_change(), handle_negotiated_sdp(), reschedule_reinvite(), sip_session_refresh(), and test_is_media_state_equal().

698 {
699  int index;
700 
701  ast_assert(left != NULL);
702  ast_assert(right != NULL);
703 
705  return 0;
706  }
707 
708  for (index = 0; index < ast_stream_topology_get_count(left); ++index) {
709  const struct ast_stream *left_stream = ast_stream_topology_get_stream(left, index);
710  const struct ast_stream *right_stream = ast_stream_topology_get_stream(right, index);
711 
712  if (ast_stream_get_type(left_stream) != ast_stream_get_type(right_stream)) {
713  return 0;
714  }
715 
716  if (ast_stream_get_state(left_stream) != ast_stream_get_state(right_stream)) {
717  return 0;
718  }
719 
720  if (!ast_stream_get_formats(left_stream) && ast_stream_get_formats(right_stream) &&
722  /* A NULL format capabilities and an empty format capabilities are the same, as they have
723  * no formats inside. If one does though... they are not equal.
724  */
725  return 0;
726  } else if (!ast_stream_get_formats(right_stream) && ast_stream_get_formats(left_stream) &&
728  return 0;
729  } else if (ast_stream_get_formats(left_stream) && ast_stream_get_formats(right_stream) &&
731  /* But if both are actually present we need to do an actual identical check. */
732  return 0;
733  }
734 
735  if (strcmp(ast_stream_get_name(left_stream), ast_stream_get_name(right_stream))) {
736  return 0;
737  }
738  }
739 
740  return 1;
741 }
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
#define ast_assert(a)
Definition: utils.h:695
const struct ast_format_cap * ast_stream_get_formats(const struct ast_stream *stream)
Get the current negotiated formats of a stream.
Definition: stream.c:330
#define NULL
Definition: resample.c:96
enum ast_stream_state ast_stream_get_state(const struct ast_stream *stream)
Get the current state of a stream.
Definition: stream.c:373
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
Definition: stream.c:765
int ast_format_cap_identical(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
Determine if two capabilities structures are identical.
Definition: format_cap.c:689
enum ast_media_type ast_stream_get_type(const struct ast_stream *stream)
Get the media type of a stream.
Definition: stream.c:316
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.
Definition: stream.c:788
const char * ast_stream_get_name(const struct ast_stream *stream)
Get the name of a stream.
Definition: stream.c:309

◆ ast_stream_topology_free()

void ast_stream_topology_free ( struct ast_stream_topology topology)

◆ ast_stream_topology_get_active_count()

int ast_stream_topology_get_active_count ( const struct ast_stream_topology topology)

Get the number of active (non-REMOVED) streams in a topology.

Parameters
topologyThe topology of streams
Returns
the number of active streams
Since
18

Definition at line 772 of file stream.c.

References ast_assert, AST_STREAM_STATE_REMOVED, AST_VECTOR_GET, AST_VECTOR_SIZE, NULL, and ast_stream::state.

773 {
774  int i;
775  int count = 0;
776  ast_assert(topology != NULL);
777 
778  for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
779  struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);
780  if (stream->state != AST_STREAM_STATE_REMOVED) {
781  count++;
782  }
783  }
784 
785  return count;
786 }
Set when the stream has been removed/declined.
Definition: stream.h:78
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
enum ast_stream_state state
The current state of the stream.
Definition: stream.c:100
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_stream_topology_get_count()

int ast_stream_topology_get_count ( const struct ast_stream_topology topology)

Get the number of streams in a topology.

Parameters
topologyThe topology of streams
Returns
the number of streams (-1 on error)
Since
15

Definition at line 765 of file stream.c.

References ast_assert, AST_VECTOR_SIZE, and NULL.

Referenced by append_all_streams(), append_source_streams(), ast_sip_session_create_outgoing(), ast_sip_session_is_pending_stream_default(), ast_stream_topology_equal(), ast_stream_topology_map(), AST_TEST_DEFINE(), ast_write_stream(), chan_pjsip_new(), check_stream_positions(), create_local_sdp(), handle_incoming_sdp(), handle_negotiated_sdp(), handle_showchan(), is_media_state_valid(), local_request_with_stream_topology(), make_channel(), map_source_to_destinations(), media_offer_read_av(), native_rtp_bridge_join(), native_rtp_request_stream_topology_update(), remove_all_original_streams(), remove_destination_streams(), resolve_refresh_media_states(), sdp_requires_deferral(), simple_bridge_join(), simple_bridge_request_stream_topology_update(), sip_session_refresh(), softmix_bridge_stream_sources_update(), softmix_bridge_stream_topology_changed(), stream_echo_topology_alloc(), stream_echo_write(), test_media_add(), unreal_colp_stream_topology_request_change(), and validate_original_streams().

766 {
767  ast_assert(topology != NULL);
768 
769  return AST_VECTOR_SIZE(&topology->streams);
770 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_stream_topology_get_first_stream_by_type()

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.

Parameters
topologyThe topology of streams
typeThe media type
Return values
non-NULLsuccess
NULLfailure
Since
15

Definition at line 964 of file stream.c.

References ast_assert, AST_STREAM_STATE_REMOVED, AST_VECTOR_GET, AST_VECTOR_SIZE, NULL, ast_stream::state, and ast_stream::type.

Referenced by ast_stream_topology_create_resolved(), AST_TEST_DEFINE(), channel_set_default_streams(), and media_offer_write_av().

967 {
968  int i;
969 
970  ast_assert(topology != NULL);
971 
972  for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
973  struct ast_stream *stream;
974 
975  stream = AST_VECTOR_GET(&topology->streams, i);
976  if (stream->type == type
977  && stream->state != AST_STREAM_STATE_REMOVED) {
978  return stream;
979  }
980  }
981 
982  return NULL;
983 }
static const char type[]
Definition: chan_ooh323.c:109
Set when the stream has been removed/declined.
Definition: stream.h:78
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
enum ast_stream_state state
The current state of the stream.
Definition: stream.c:100
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_stream_topology_get_formats()

struct ast_format_cap* ast_stream_topology_get_formats ( struct ast_stream_topology topology)

Create a format capabilities structure representing the topology.

A helper function that, given a stream topology, creates a format capabilities structure containing all formats from all active streams.

Parameters
topologyThe topology of streams
Return values
non-NULLsuccess (the resulting format caps must be unreffed by the caller)
NULLfailure
Note
The stream topology is NOT altered by this function.
Since
15

Definition at line 930 of file stream.c.

References AST_MEDIA_TYPE_UNKNOWN, and ast_stream_topology_get_formats_by_type().

Referenced by AST_TEST_DEFINE(), ast_unreal_alloc_stream_topology(), chan_pjsip_new(), compatible_formats_exist(), and request_channel().

932 {
934 }
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...
Definition: stream.c:902

◆ ast_stream_topology_get_formats_by_type()

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 particular type in the topology.

Since
18

A helper function that, given a stream topology and a media type, creates a format capabilities structure containing all formats from all active streams with the particular type.

Parameters
topologyThe topology of streams
typeThe media type
Return values
non-NULLsuccess (the resulting format caps must be unreffed by the caller)
NULLfailure
Note
The stream topology is NOT altered by this function.

Definition at line 902 of file stream.c.

References ast_assert, ast_format_cap_alloc, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, AST_MEDIA_TYPE_UNKNOWN, AST_STREAM_STATE_REMOVED, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_stream::formats, NULL, ast_stream::state, and ast_stream::type.

Referenced by ast_stream_topology_get_formats().

904 {
905  struct ast_format_cap *caps;
906  int i;
907 
908  ast_assert(topology != NULL);
909 
911  if (!caps) {
912  return NULL;
913  }
914 
915  for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
916  struct ast_stream *stream;
917 
918  stream = AST_VECTOR_GET(&topology->streams, i);
919  if (!stream->formats || stream->state == AST_STREAM_STATE_REMOVED) {
920  continue;
921  }
922  if (type == AST_MEDIA_TYPE_UNKNOWN || type == stream->type) {
924  }
925  }
926 
927  return caps;
928 }
static const char type[]
Definition: chan_ooh323.c:109
struct ast_format_cap * formats
Current formats negotiated on the stream.
Definition: stream.c:95
Set when the stream has been removed/declined.
Definition: stream.h:78
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
enum ast_stream_state state
The current state of the stream.
Definition: stream.c:100
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_stream_topology_get_stream()

struct ast_stream* ast_stream_topology_get_stream ( const struct ast_stream_topology topology,
unsigned int  position 
)

Get a specific stream from the topology.

Parameters
topologyThe topology of streams
positionThe topology position to get
Return values
non-NULLsuccess
NULLfailure
Since
15

Definition at line 788 of file stream.c.

References ast_assert, AST_VECTOR_GET, and NULL.

Referenced by __ast_read(), append_all_streams(), append_source_streams(), ast_sip_session_create_outgoing(), ast_sip_session_is_pending_stream_default(), ast_sip_session_media_state_add(), ast_sip_session_media_state_clone(), ast_stream_topology_equal(), ast_stream_topology_map(), AST_TEST_DEFINE(), ast_write_stream(), check_stream_positions(), create_local_sdp(), handle_incoming_sdp(), handle_negotiated_sdp(), handle_showchan(), is_compatible_format(), is_media_state_valid(), local_request_with_stream_topology(), map_source_to_destinations(), media_offer_read_av(), native_rtp_request_stream_topology_update(), remove_all_original_streams(), remove_destination_streams(), resolve_refresh_media_states(), sdp_requires_deferral(), simple_bridge_request_stream_topology_update(), sip_session_refresh(), softmix_bridge_stream_sources_update(), softmix_bridge_stream_topology_changed(), stream_echo_topology_alloc(), stream_echo_write(), stream_echo_write_error(), test_media_add(), unreal_colp_stream_topology_request_change(), and validate_original_streams().

790 {
791  ast_assert(topology != NULL);
792 
793  return AST_VECTOR_GET(&topology->streams, stream_num);
794 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682

◆ ast_stream_topology_map()

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.

Note
The given vectors in which mapping values are placed are reset by this function. This means if those vectors already contain mapping values they will be lost.
Parameters
topologyThe topology to map
typesThe media types to be mapped
v0Index mapping of topology to types
v1Index mapping of types to topology
Since
15

Definition at line 985 of file stream.c.

References AST_MEDIA_TYPE_END, ast_stream_get_type(), ast_stream_topology_get_count(), ast_stream_topology_get_stream(), AST_VECTOR_APPEND, AST_VECTOR_ELEM_DEFAULT_CMP, AST_VECTOR_FREE, AST_VECTOR_GET_INDEX_NTH, AST_VECTOR_INIT, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, and type.

Referenced by ast_bridge_channel_stream_map(), and AST_TEST_DEFINE().

987 {
988  int i;
989  int nths[AST_MEDIA_TYPE_END] = {0};
990  int size = ast_stream_topology_get_count(topology);
991 
992  /*
993  * Clear out any old mappings and initialize the new ones
994  */
995  AST_VECTOR_FREE(v0);
996  AST_VECTOR_FREE(v1);
997 
998  /*
999  * Both vectors are sized to the topology. The media types vector is always
1000  * guaranteed to be the size of the given topology or greater.
1001  */
1002  AST_VECTOR_INIT(v0, size);
1003  AST_VECTOR_INIT(v1, size);
1004 
1005  for (i = 0; i < size; ++i) {
1006  struct ast_stream *stream = ast_stream_topology_get_stream(topology, i);
1007  enum ast_media_type type = ast_stream_get_type(stream);
1008  int index = AST_VECTOR_GET_INDEX_NTH(types, ++nths[type],
1010 
1011  if (index == -1) {
1012  /*
1013  * If a given type is not found for an index level then update the
1014  * media types vector with that type. This keeps the media types
1015  * vector always at the max topology size.
1016  */
1017  AST_VECTOR_APPEND(types, type);
1018  index = AST_VECTOR_SIZE(types) - 1;
1019  }
1020 
1021  /*
1022  * The mapping is reflexive in the sense that if it maps in one direction
1023  * then the reverse direction maps back to the other's index.
1024  */
1025  AST_VECTOR_REPLACE(v0, i, index);
1026  AST_VECTOR_REPLACE(v1, index, i);
1027  }
1028 }
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
static const char type[]
Definition: chan_ooh323.c:109
#define AST_VECTOR_GET_INDEX_NTH(vec, nth, value, cmp)
Get the nth index from a vector that matches the given comparison.
Definition: vector.h:698
#define AST_VECTOR_ELEM_DEFAULT_CMP(elem, value)
Default comparator for AST_VECTOR_REMOVE_ELEM_UNORDERED()
Definition: vector.h:564
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
int ast_stream_topology_get_count(const struct ast_stream_topology *topology)
Get the number of streams in a topology.
Definition: stream.c:765
enum ast_media_type ast_stream_get_type(const struct ast_stream *stream)
Get the media type of a stream.
Definition: stream.c:316
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.
Definition: stream.c:788
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
ast_media_type
Types of media.
Definition: codec.h:30
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ ast_stream_topology_set_stream()

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.

Parameters
topologyThe topology of streams
positionThe topology position to set
streamThe stream to put in its place
Return values
0success
-1failure
Note
If an existing stream exists it will be destroyed
You can overwrite an existing position in the topology or set the first unused position. You can't set positions beyond that.
Since
15
Note
If the stream's name is empty, it'll be set to <stream_type>-<position>

Definition at line 796 of file stream.c.

References ast_assert, ast_codec_media_type2str(), ast_stream_free(), ast_strlen_zero, AST_VECTOR_APPEND, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, MIN_STREAM_NAME_LEN, ast_stream::name, ast_stream::position, and ast_stream::type.

Referenced by append_all_streams(), AST_TEST_DEFINE(), handle_incoming_sdp(), remove_all_original_streams(), resolve_refresh_media_states(), sdp_requires_deferral(), t38_create_media_state(), and test_media_add().

798 {
799  struct ast_stream *existing_stream;
800 
801  ast_assert(topology && stream);
802 
803  if (position > AST_VECTOR_SIZE(&topology->streams)) {
804  return -1;
805  }
806 
807  if (position < AST_VECTOR_SIZE(&topology->streams)) {
808  existing_stream = AST_VECTOR_GET(&topology->streams, position);
809  ast_stream_free(existing_stream);
810  }
811 
812  stream->position = position;
813 
814  if (position == AST_VECTOR_SIZE(&topology->streams)) {
815  return AST_VECTOR_APPEND(&topology->streams, stream);
816  }
817 
818  if (ast_strlen_zero(stream->name)) {
819  snprintf(stream->name, MIN_STREAM_NAME_LEN, "%s-%d", ast_codec_media_type2str(stream->type), stream->position);
820  }
821 
822  return AST_VECTOR_REPLACE(&topology->streams, position, stream);
823 }
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:347
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define MIN_STREAM_NAME_LEN
Definition: stream.c:231
#define ast_assert(a)
Definition: utils.h:695
void ast_stream_free(struct ast_stream *stream)
Destroy a media stream representation.
Definition: stream.c:292
#define ast_strlen_zero(foo)
Definition: strings.h:52
char name[0]
Name for the stream within the context of the channel it is on.
Definition: stream.c:120
enum ast_media_type type
The type of media the stream is handling.
Definition: stream.c:85
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611
unsigned int position
The position of the stream in the topology.
Definition: stream.c:90

◆ ast_stream_topology_to_str()

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.

Since
18
Parameters
topologyA stream topology
bufA pointer to an ast_str* used for the output.
Return values
""(empty string) if either buf or *buf are NULL
(null topology)if *topology was NULL
<topology_representation>otherwise
Warning
No attempt should ever be made to free the returned char * and it should be dup'd if needed after the ast_str is freed.

Return format: <final>? <stream> ...

Sample return: "final <audio:audio:sendrecv (ulaw,g722)> <video:video:sendonly (h264)>"

Definition at line 936 of file stream.c.

References ast_str_append(), ast_str_buffer(), ast_stream_to_str(), AST_VECTOR_GET, AST_VECTOR_SIZE, and S_COR.

Referenced by ast_channel_request_stream_topology_change(), ast_channel_set_stream_topology(), ast_sip_session_create_outgoing(), call(), chan_pjsip_call(), chan_pjsip_indicate(), chan_pjsip_request_with_stream_topology(), compatible_formats_exist(), dial_exec_full(), is_media_state_valid(), on_topology_change_response(), resolve_refresh_media_states(), send_topology_change_refresh(), session_on_tsx_state(), sip_session_refresh(), softmix_bridge_stream_sources_update(), and wait_for_answer().

938 {
939  int i;
940 
941  if (!buf ||!*buf) {
942  return "";
943  }
944 
945  if (!topology) {
946  ast_str_append(buf, 0, "(null topology)");
947  return ast_str_buffer(*buf);
948  }
949 
950  ast_str_append(buf, 0, "%s", S_COR(topology->final, "final", ""));
951 
952  for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
953  struct ast_stream *stream;
954 
955  stream = AST_VECTOR_GET(&topology->streams, i);
956  ast_str_append(buf, 0, " <");
957  ast_stream_to_str(stream, buf);
958  ast_str_append(buf, 0, ">");
959  }
960 
961  return ast_str_buffer(*buf);
962 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1091
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.
Definition: stream.c:337
#define S_COR(a, b, c)
returns the equivalent of logic or for strings, with an additional boolean check: second one if not e...
Definition: strings.h:85
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:682
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:611

◆ stream_topology_destroy()

static void stream_topology_destroy ( void *  data)
static

Definition at line 641 of file stream.c.

References ast_stream_free(), AST_VECTOR_CALLBACK_VOID, and AST_VECTOR_FREE.

Referenced by ast_stream_topology_alloc().

642 {
643  struct ast_stream_topology *topology = data;
644 
645  AST_VECTOR_CALLBACK_VOID(&topology->streams, ast_stream_free);
646  AST_VECTOR_FREE(&topology->streams);
647 }
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
void ast_stream_free(struct ast_stream *stream)
Destroy a media stream representation.
Definition: stream.c:292
#define AST_VECTOR_CALLBACK_VOID(vec, callback,...)
Execute a callback on every element in a vector disregarding callback return.
Definition: vector.h:865

Variable Documentation

◆ ast_stream_codec_negotiation_keep_map

const char* ast_stream_codec_negotiation_keep_map[]
Initial value:

"keep" enum to string map

Definition at line 69 of file stream.c.

◆ ast_stream_codec_negotiation_operation_map

const char* ast_stream_codec_negotiation_operation_map[]

"operation" enum to string map

Definition at line 61 of file stream.c.

◆ ast_stream_codec_negotiation_params_map

const char* ast_stream_codec_negotiation_params_map[]

Preference enum to string map.

Definition at line 47 of file stream.c.

◆ ast_stream_codec_negotiation_prefer_map

const char* ast_stream_codec_negotiation_prefer_map[]
Initial value:

"prefer" enum to string map

Definition at line 55 of file stream.c.

◆ ast_stream_codec_negotiation_transcode_map

const char* ast_stream_codec_negotiation_transcode_map[]
Initial value:

"transcode" state enum to string map

Definition at line 75 of file stream.c.

◆ ast_stream_state_map

const char* ast_stream_state_map[]

Stream state enum to string map.

Definition at line 223 of file stream.c.

Referenced by ast_stream_to_str().