stream: Enforce formats immutability and ensure formats exist.

Some places in Asterisk did not treat the formats on a stream
as immutable when they are.

The ast_stream_get_formats function is now const to enforce this
and parts of Asterisk have been updated to take this into account.
Some violations of this were also fixed along the way.

An additional minor tweak is that streams are now allocated with
an empty format capabilities structure removing the need in various
places to check that one is present on the stream.

ASTERISK-28846

Change-Id: I32f29715330db4ff48edd6f1f359090458a9bfbe
This commit is contained in:
Joshua C. Colp
2020-04-21 06:52:24 -03:00
committed by Kevin Harwell
parent 9ad3d2829c
commit 1c5e68580a
10 changed files with 59 additions and 13 deletions

View File

@@ -1235,7 +1235,7 @@ static int media_offer_read_av(struct ast_sip_session *session, char *buf,
struct ast_stream_topology *topology;
int idx;
struct ast_stream *stream = NULL;
struct ast_format_cap *caps;
const struct ast_format_cap *caps;
size_t accum = 0;
if (session->inv_session->dlg->state == PJSIP_DIALOG_STATE_ESTABLISHED) {
@@ -1352,9 +1352,18 @@ static int media_offer_write_av(void *obj)
if (!stream) {
return 0;
}
caps = ast_stream_get_formats(stream);
caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
if (!caps) {
return -1;
}
ast_format_cap_append_from_cap(caps, ast_stream_get_formats(stream),
AST_MEDIA_TYPE_UNKNOWN);
ast_format_cap_remove_by_type(caps, data->media_type);
ast_format_cap_update_by_allow_disallow(caps, data->value, 1);
ast_stream_set_formats(stream, caps);
ao2_ref(caps, -1);
return 0;
}