res_format_attr_*: Parameter Names are Case-Insensitive.

see RFC 4855:
parameter names are case-insensitive both in media type strings and
in the default mapping to the SDP a=fmtp attribute.

This change is required for H.263+ because some implementations are
known to use even mixed-case. This does not fix ASTERISK~29268 because
H.264 was not fixed. This approach here lowers/uppers both parameter
names and parameter values. H.264 needs a different approach because
one of its parameter values is not case-insensitive:
sprop-parameter-sets is Base64.

Change-Id: Idf2a73457be231647aed3c87b1da197afba86892
This commit is contained in:
Alexander Traud 2021-03-05 18:16:56 +01:00 committed by Joshua Colp
parent 8c461845c8
commit 1ae40e502d
8 changed files with 100 additions and 21 deletions

View File

@ -29,8 +29,14 @@
#include "asterisk.h"
#include <ctype.h> /* for tolower */
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/astobj2.h" /* for ao2_ref */
#include "asterisk/logger.h" /* for ast_log, LOG_WARNING */
#include "asterisk/strings.h" /* for ast_str_append */
#include "asterisk/utils.h" /* for MIN */
/*!
* \brief CELT attribute structure.
@ -70,6 +76,7 @@ static int celt_clone(const struct ast_format *src, struct ast_format *dst)
static struct ast_format *celt_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
{
char *attribs = ast_strdupa(attributes), *attrib;
struct ast_format *cloned;
struct celt_attr *attr;
unsigned int val;
@ -80,7 +87,12 @@ static struct ast_format *celt_parse_sdp_fmtp(const struct ast_format *format, c
}
attr = ast_format_get_attribute_data(cloned);
if (sscanf(attributes, "framesize=%30u", &val) == 1) {
/* lower-case everything, so we are case-insensitive */
for (attrib = attribs; *attrib; ++attrib) {
*attrib = tolower(*attrib);
} /* based on channels/chan_sip.c:process_a_sdp_image() */
if (sscanf(attribs, "framesize=%30u", &val) == 1) {
attr->framesize = val;
}

View File

@ -33,8 +33,12 @@
#include "asterisk.h"
#include <ctype.h> /* for toupper */
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/strings.h" /* for ast_str_append */
#include "asterisk/utils.h" /* for ast_strip */
/*! \brief Value that indicates an attribute is actually unset */
#define H263_ATTR_KEY_UNSET UINT8_MAX
@ -174,6 +178,11 @@ static struct ast_format *h263_parse_sdp_fmtp(const struct ast_format *format, c
}
attr = ast_format_get_attribute_data(cloned);
/* upper-case everything, so we are case-insensitive */
for (attrib = attribs; *attrib; ++attrib) {
*attrib = toupper(*attrib);
} /* based on channels/chan_sip.c:process_a_sdp_image() */
attr->BPP = H263_ATTR_KEY_UNSET;
attr->MaxBR = H263_ATTR_KEY_UNSET;
attr->PAR_WIDTH = H263_ATTR_KEY_UNSET;

View File

@ -31,10 +31,12 @@
#include "asterisk.h"
#include <ctype.h> /* for tolower */
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/strings.h" /* for ast_str_append */
#include "asterisk/utils.h" /* for ast_calloc, ast_free */
#include "asterisk/utils.h" /* for ast_free */
#include "asterisk/ilbc.h"
@ -71,6 +73,7 @@ static int ilbc_clone(const struct ast_format *src, struct ast_format *dst)
static struct ast_format *ilbc_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
{
char *attribs = ast_strdupa(attributes), *attrib;
struct ast_format *cloned;
struct ilbc_attr *attr;
const char *kvp;
@ -82,7 +85,12 @@ static struct ast_format *ilbc_parse_sdp_fmtp(const struct ast_format *format, c
}
attr = ast_format_get_attribute_data(cloned);
if ((kvp = strstr(attributes, "mode")) && sscanf(kvp, "mode=%30u", &val) == 1) {
/* lower-case everything, so we are case-insensitive */
for (attrib = attribs; *attrib; ++attrib) {
*attrib = tolower(*attrib);
} /* based on channels/chan_sip.c:process_a_sdp_image() */
if ((kvp = strstr(attribs, "mode")) && sscanf(kvp, "mode=%30u", &val) == 1) {
attr->mode = val;
} else {
attr->mode = 30; /* optional attribute; 30 is default value */

View File

@ -29,8 +29,11 @@
#include "asterisk.h"
#include <ctype.h>
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/astobj2.h"
#include "asterisk/logger.h"
#include "asterisk/strings.h"
#include "asterisk/utils.h"
@ -135,6 +138,7 @@ static void sdp_fmtp_get(const char *attributes, const char *name, int *attr)
static struct ast_format *opus_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
{
char *attribs = ast_strdupa(attributes), *attrib;
struct ast_format *cloned;
struct opus_attr *attr;
@ -145,22 +149,27 @@ static struct ast_format *opus_parse_sdp_fmtp(const struct ast_format *format, c
attr = ast_format_get_attribute_data(cloned);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_MAX_PLAYBACK_RATE, &attr->maxplayrate);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_MAX_CODED_AUDIO_BANDWIDTH,
/* lower-case everything, so we are case-insensitive */
for (attrib = attribs; *attrib; ++attrib) {
*attrib = tolower(*attrib);
} /* based on channels/chan_sip.c:process_a_sdp_image() */
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_MAX_PLAYBACK_RATE, &attr->maxplayrate);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_MAX_CODED_AUDIO_BANDWIDTH,
&attr->maxplayrate);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_SPROP_MAX_CAPTURE_RATE,
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_SPROP_MAX_CAPTURE_RATE,
&attr->spropmaxcapturerate);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_MAX_PTIME, &attr->maxptime);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_PTIME, &attr->ptime);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_MAX_AVERAGE_BITRATE, &attr->maxbitrate);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_STEREO, &attr->stereo);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_MAX_PTIME, &attr->maxptime);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_PTIME, &attr->ptime);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_MAX_AVERAGE_BITRATE, &attr->maxbitrate);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_STEREO, &attr->stereo);
if (attr->stereo) {
ast_format_set_channel_count(cloned, 2);
}
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_SPROP_STEREO, &attr->spropstereo);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_CBR, &attr->cbr);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_FEC, &attr->fec);
sdp_fmtp_get(attributes, CODEC_OPUS_ATTR_DTX, &attr->dtx);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_SPROP_STEREO, &attr->spropstereo);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_CBR, &attr->cbr);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_FEC, &attr->fec);
sdp_fmtp_get(attribs, CODEC_OPUS_ATTR_DTX, &attr->dtx);
return cloned;
}

View File

@ -29,8 +29,13 @@
#include "asterisk.h"
#include <ctype.h> /* for tolower */
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/logger.h" /* for ast_log, LOG_WARNING */
#include "asterisk/strings.h" /* for ast_str_append */
#include "asterisk/utils.h" /* for MAX, MIN */
/*!
* \brief SILK attribute structure.
@ -78,6 +83,7 @@ static int silk_clone(const struct ast_format *src, struct ast_format *dst)
static struct ast_format *silk_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
{
char *attribs = ast_strdupa(attributes), *attrib;
struct ast_format *cloned;
struct silk_attr *attr;
unsigned int val;
@ -88,13 +94,18 @@ static struct ast_format *silk_parse_sdp_fmtp(const struct ast_format *format, c
}
attr = ast_format_get_attribute_data(cloned);
if (sscanf(attributes, "maxaveragebitrate=%30u", &val) == 1) {
/* lower-case everything, so we are case-insensitive */
for (attrib = attribs; *attrib; ++attrib) {
*attrib = tolower(*attrib);
} /* based on channels/chan_sip.c:process_a_sdp_image() */
if (sscanf(attribs, "maxaveragebitrate=%30u", &val) == 1) {
attr->maxbitrate = val;
}
if (sscanf(attributes, "usedtx=%30u", &val) == 1) {
if (sscanf(attribs, "usedtx=%30u", &val) == 1) {
attr->dtx = val;
}
if (sscanf(attributes, "useinbandfec=%30u", &val) == 1) {
if (sscanf(attribs, "useinbandfec=%30u", &val) == 1) {
attr->fec = val;
}

View File

@ -29,8 +29,13 @@
#include "asterisk.h"
#include <ctype.h> /* for tolower */
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/astobj2.h" /* for ao2_bump */
#include "asterisk/logger.h" /* for ast_log, LOG_WARNING */
#include "asterisk/strings.h" /* for ast_str_append */
/* Destroy is a required callback and must exist */
static void siren14_destroy(struct ast_format *format)
@ -45,9 +50,15 @@ static int siren14_clone(const struct ast_format *src, struct ast_format *dst)
static struct ast_format *siren14_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
{
char *attribs = ast_strdupa(attributes), *attrib;
unsigned int val;
if (sscanf(attributes, "bitrate=%30u", &val) == 1) {
/* lower-case everything, so we are case-insensitive */
for (attrib = attribs; *attrib; ++attrib) {
*attrib = tolower(*attrib);
} /* based on channels/chan_sip.c:process_a_sdp_image() */
if (sscanf(attribs, "bitrate=%30u", &val) == 1) {
if (val != 48000) {
ast_log(LOG_WARNING, "Got siren14 offer at %u bps, but only 48000 bps supported; ignoring.\n", val);
return NULL;

View File

@ -29,8 +29,13 @@
#include "asterisk.h"
#include <ctype.h> /* for tolower */
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/astobj2.h" /* for ao2_bump */
#include "asterisk/logger.h" /* for ast_log, LOG_WARNING */
#include "asterisk/strings.h" /* for ast_str_append */
/* Destroy is a required callback and must exist */
static void siren7_destroy(struct ast_format *format)
@ -45,9 +50,15 @@ static int siren7_clone(const struct ast_format *src, struct ast_format *dst)
static struct ast_format *siren7_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
{
char *attribs = ast_strdupa(attributes), *attrib;
unsigned int val;
if (sscanf(attributes, "bitrate=%30u", &val) == 1) {
/* lower-case everything, so we are case-insensitive */
for (attrib = attribs; *attrib; ++attrib) {
*attrib = tolower(*attrib);
} /* based on channels/chan_sip.c:process_a_sdp_image() */
if (sscanf(attribs, "bitrate=%30u", &val) == 1) {
if (val != 32000) {
ast_log(LOG_WARNING, "Got Siren7 offer at %u bps, but only 32000 bps supported; ignoring.\n", val);
return NULL;

View File

@ -31,6 +31,8 @@
#include "asterisk.h"
#include <ctype.h> /* for tolower */
#include "asterisk/module.h"
#include "asterisk/format.h"
#include "asterisk/logger.h" /* for ast_log, LOG_WARNING */
@ -76,6 +78,7 @@ static int vp8_clone(const struct ast_format *src, struct ast_format *dst)
static struct ast_format *vp8_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
{
char *attribs = ast_strdupa(attributes), *attrib;
struct ast_format *cloned;
struct vp8_attr *attr;
const char *kvp;
@ -87,13 +90,18 @@ static struct ast_format *vp8_parse_sdp_fmtp(const struct ast_format *format, co
}
attr = ast_format_get_attribute_data(cloned);
if ((kvp = strstr(attributes, "max-fr")) && sscanf(kvp, "max-fr=%30u", &val) == 1) {
/* lower-case everything, so we are case-insensitive */
for (attrib = attribs; *attrib; ++attrib) {
*attrib = tolower(*attrib);
} /* based on channels/chan_sip.c:process_a_sdp_image() */
if ((kvp = strstr(attribs, "max-fr")) && sscanf(kvp, "max-fr=%30u", &val) == 1) {
attr->maximum_frame_rate = val;
} else {
attr->maximum_frame_rate = UINT_MAX;
}
if ((kvp = strstr(attributes, "max-fs")) && sscanf(kvp, "max-fs=%30u", &val) == 1) {
if ((kvp = strstr(attribs, "max-fs")) && sscanf(kvp, "max-fs=%30u", &val) == 1) {
attr->maximum_frame_size = val;
} else {
attr->maximum_frame_size = UINT_MAX;