[asterisk-commits] dvossel: branch dvossel/fixtheworld_phase2 r307432 - in /team/dvossel/fixthew...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Feb 10 10:47:31 CST 2011
Author: dvossel
Date: Thu Feb 10 10:47:27 2011
New Revision: 307432
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=307432
Log:
Fixes some issues with properly communicating negotiated peer formats with attributes
Modified:
team/dvossel/fixtheworld_phase2/channels/chan_sip.c
team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h
team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h
team/dvossel/fixtheworld_phase2/main/format_cap.c
team/dvossel/fixtheworld_phase2/main/format_pref.c
team/dvossel/fixtheworld_phase2/main/rtp_engine.c
Modified: team/dvossel/fixtheworld_phase2/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/channels/chan_sip.c?view=diff&rev=307432&r1=307431&r2=307432
==============================================================================
--- team/dvossel/fixtheworld_phase2/channels/chan_sip.c (original)
+++ team/dvossel/fixtheworld_phase2/channels/chan_sip.c Thu Feb 10 10:47:27 2011
@@ -8869,20 +8869,20 @@
}
ast_debug(4, "We have an owner, now see if we need to change this call\n");
-
- if (!(ast_format_cap_has_joint(p->owner->nativeformats, p->jointcaps)) && ast_format_cap_has_type(p->jointcaps, AST_FORMAT_TYPE_AUDIO)) {
+ if (ast_format_cap_has_type(p->jointcaps, AST_FORMAT_TYPE_AUDIO)) {
if (debug) {
char s1[SIPBUFSIZE], s2[SIPBUFSIZE];
- ast_debug(1, "Oooh, we need to change our audio formats since our peer supports only %s and not %s\n",
+ ast_debug(1, "Setting native formats after processing SDP. peer joint formats %s, old nativeformats %s\n",
ast_getformatname_multiple(s1, SIPBUFSIZE, p->jointcaps),
ast_getformatname_multiple(s2, SIPBUFSIZE, p->owner->nativeformats));
}
ast_codec_choose(&p->prefs, p->jointcaps, 1, &tmp_fmt);
+ ast_format_cap_remove_all(p->owner->nativeformats);
ast_format_cap_set(p->owner->nativeformats, &tmp_fmt);
- ast_format_cap_joint_copy(p->caps, vpeercapability, p->owner->nativeformats);
- ast_format_cap_joint_copy(p->caps, tpeercapability, p->owner->nativeformats);
+ ast_format_cap_joint_append(p->caps, vpeercapability, p->owner->nativeformats);
+ ast_format_cap_joint_append(p->caps, tpeercapability, p->owner->nativeformats);
ast_set_read_format(p->owner, &p->owner->readformat);
ast_set_write_format(p->owner, &p->owner->writeformat);
@@ -9093,13 +9093,12 @@
ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec);
}
} else if (sscanf(a, "fmtp: %30u %63s", &codec, fmtp_string) == 2) {
- struct ast_rtp_payload_type payload;
-
- payload = ast_rtp_codecs_payload_lookup(newaudiortp, codec);
- if (payload.format.id && payload.asterisk_format) {
+ struct ast_format *format;
+
+ if ((format = ast_rtp_codecs_get_payload_format(newaudiortp, codec))) {
unsigned int bit_rate;
- switch ((int) payload.format.id) {
+ switch ((int) format->id) {
case AST_FORMAT_SIREN7:
if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) {
if (bit_rate != 32000) {
@@ -9134,10 +9133,10 @@
{
int val = 0;
if (sscanf(fmtp_string, "maxaveragebitrate=%30u", &val) == 1) {
- ast_format_append(&payload.format, SILK_ATTR_KEY_MAX_BITRATE, val, AST_FORMAT_ATTR_END);
+ ast_format_append(format, SILK_ATTR_KEY_MAX_BITRATE, val, AST_FORMAT_ATTR_END);
}
if (sscanf(fmtp_string, "usedtx=%30u", &val) == 1) {
- ast_format_append(&payload.format, SILK_ATTR_KEY_DTX, val ? 1 : 0, AST_FORMAT_ATTR_END);
+ ast_format_append(format, SILK_ATTR_KEY_DTX, val ? 1 : 0, AST_FORMAT_ATTR_END);
}
break;
}
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h?view=diff&rev=307432&r1=307431&r2=307432
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/format_cap.h Thu Feb 10 10:47:27 2011
@@ -155,6 +155,15 @@
void ast_format_cap_set(struct ast_format_cap *cap, struct ast_format *format);
/*!
+ * \brief Find if ast_format is within the capabilities of the ast_format_cap object
+ * then return the compatibly format from the capabilities structure in the result.
+ *
+ * retval 1 format is compatible with formats held in ast_format_cap object.
+ * retval 0 format is not compatible with any formats in ast_format_cap object.
+ */
+int ast_format_cap_get_compatible_format(const struct ast_format_cap *cap, const struct ast_format *format, struct ast_format *result);
+
+/*!
* \brief Find if ast_format is within the capabilities of the ast_format_cap object.
*
* retval 1 format is compatible with formats held in ast_format_cap object.
@@ -198,6 +207,14 @@
* \retval 0, joint capabilities do not exist
*/
int ast_format_cap_joint_copy(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result);
+
+/*!
+ * \brief Get joint capability structure, append into result capabilities structure
+ *
+ * \retval 1, joint capabilities exist
+ * \retval 0, joint capabilities do not exist
+ */
+int ast_format_cap_joint_append(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result);
/*!
* \brief Find out if capability structures have any joint capabilities without
Modified: team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h?view=diff&rev=307432&r1=307431&r2=307432
==============================================================================
--- team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h (original)
+++ team/dvossel/fixtheworld_phase2/include/asterisk/rtp_engine.h Thu Feb 10 10:47:27 2011
@@ -1048,6 +1048,19 @@
struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload);
/*!
+ * \brief Retrieve the actual ast_format stored on the codecs structure for a specific payload
+ *
+ * \param codecs Codecs structure to look in
+ * \param payload Numerical payload to look up
+ *
+ * \retval pointer to format structure on success
+ * \retval NULL on failure
+ *
+ * \since 1.10
+ */
+struct ast_format *ast_rtp_codecs_get_payload_format(struct ast_rtp_codecs *codecs, int payload);
+
+/*!
* \brief Get the sample rate associated with known RTP payload types
*
* \param asterisk_format True if the value in format is to be used.
Modified: team/dvossel/fixtheworld_phase2/main/format_cap.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/format_cap.c?view=diff&rev=307432&r1=307431&r2=307432
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/format_cap.c (original)
+++ team/dvossel/fixtheworld_phase2/main/format_cap.c Thu Feb 10 10:47:27 2011
@@ -288,6 +288,21 @@
ast_format_cap_add(cap, format);
}
+int ast_format_cap_get_compatible_format(const struct ast_format_cap *cap, const struct ast_format *format, struct ast_format *result)
+{
+ struct ast_format *f;
+ struct ast_format_cap *tmp_cap = (struct ast_format_cap *) cap;
+ f = ao2_find(tmp_cap->formats, (struct ast_format *) format, OBJ_POINTER | tmp_cap->nolock);
+
+ if (f) {
+ ao2_ref(f, -1);
+ ast_format_copy(result, f);
+ return 1;
+ }
+ ast_format_clear(result);
+ return 0;
+}
+
int ast_format_cap_iscompatible(const struct ast_format_cap *cap, const struct ast_format *format)
{
struct ast_format *f;
@@ -451,6 +466,28 @@
};
ast_format_cap_remove_all(result);
+ it = ao2_iterator_init(cap1->formats, cap2->nolock ? AO2_ITERATOR_DONTLOCK : 0);
+ while ((tmp = ao2_iterator_next(&it))) {
+ data.format = tmp;
+ ao2_callback(cap2->formats,
+ OBJ_MULTIPLE | OBJ_NODATA | cap2->nolock,
+ find_joint_cb,
+ &data);
+ ao2_ref(tmp, -1);
+ }
+ ao2_iterator_destroy(&it);
+
+ return ao2_container_count(result->formats) ? 1 : 0;
+}
+int ast_format_cap_joint_append(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2, struct ast_format_cap *result)
+{
+ struct ao2_iterator it;
+ struct ast_format *tmp;
+ struct find_joint_data data = {
+ .joint_cap = result,
+ .joint_found = 0,
+ };
+
it = ao2_iterator_init(cap1->formats, cap2->nolock ? AO2_ITERATOR_DONTLOCK : 0);
while ((tmp = ao2_iterator_next(&it))) {
data.format = tmp;
Modified: team/dvossel/fixtheworld_phase2/main/format_pref.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/format_pref.c?view=diff&rev=307432&r1=307431&r2=307432
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/format_pref.c (original)
+++ team/dvossel/fixtheworld_phase2/main/format_pref.c Thu Feb 10 10:47:27 2011
@@ -302,27 +302,23 @@
{
int x, slot, found;
size_t f_len = 0;
- struct ast_format tmp_fmt;
- const struct ast_format_list *f_list = ast_format_list_get(&f_len);
-
+ const struct ast_format_list *f_list = ast_format_list_get(&f_len);
+
+ for (x = 0; x < f_len; x++) {
+ slot = pref->order[x];
+
+ if (!slot)
+ break;
+ if (ast_format_cap_get_compatible_format(cap, &f_list[slot-1].format, result)) {
+ found = 1; /*format is found and stored in result */
+ break;
+ }
+ }
+ ast_format_list_destroy(f_list);
+ if (found && (AST_FORMAT_GET_TYPE(result->id) == AST_FORMAT_TYPE_AUDIO)) {
+ return result;
+ }
ast_format_clear(result);
-
- for (x = 0; x < f_len; x++) {
- slot = pref->order[x];
-
- if (!slot)
- break;
- if (ast_format_cap_iscompatible(cap, &f_list[slot-1].format)) {
- found = 1; /*format is found and stored in tmp_fmt */
- break;
- }
- }
- ast_format_list_destroy(f_list);
- if (found && (AST_FORMAT_GET_TYPE(tmp_fmt.id) == AST_FORMAT_TYPE_AUDIO)) {
- ast_format_copy(result, &tmp_fmt);
- return result;
- }
-
ast_debug(4, "Could not find preferred codec - %s\n", find_best ? "Going for the best codec" : "Returning zero codec");
return find_best ? ast_best_codec(cap, result) : NULL;
Modified: team/dvossel/fixtheworld_phase2/main/rtp_engine.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/fixtheworld_phase2/main/rtp_engine.c?view=diff&rev=307432&r1=307431&r2=307432
==============================================================================
--- team/dvossel/fixtheworld_phase2/main/rtp_engine.c (original)
+++ team/dvossel/fixtheworld_phase2/main/rtp_engine.c Thu Feb 10 10:47:27 2011
@@ -567,6 +567,18 @@
}
return result;
+}
+
+
+struct ast_format *ast_rtp_codecs_get_payload_format(struct ast_rtp_codecs *codecs, int payload)
+{
+ if (payload < 0 || payload >= AST_RTP_MAX_PT) {
+ return NULL;
+ }
+ if (!codecs->payloads[payload].asterisk_format) {
+ return NULL;
+ }
+ return &codecs->payloads[payload].format;
}
void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
More information about the asterisk-commits
mailing list