[Asterisk-code-review] ast format: Adds an identifier for interleaved audio formats... (asterisk[master])

Frank Haase asteriskteam at digium.com
Sun Nov 6 05:42:50 CST 2016


Frank Haase has uploaded a new change for review. ( https://gerrit.asterisk.org/4322 )

Change subject: ast_format: Adds an identifier for interleaved audio formats to the ast_format
......................................................................

ast_format: Adds an identifier for interleaved audio formats to the ast_format

Adds an identifier (with a getter and setter) to detect channels with
interleaved audio.
This is needed by the binaural bridge_softmix patch (ASTERISK-26292) and
was already discussed here:
http://lists.digium.com/pipermail/asterisk-dev/2016-October/075900.html
The identifier can be set during fmtp parsing (to be seen in the
res_format_attr_opus.c change).

ASTERISK-26292

Change-Id: I359801cc5f98c35671c48dabc81a7f4ee1183d63
---
M include/asterisk/format.h
M main/format.c
M main/format_cap.c
M res/res_format_attr_opus.c
M res/res_pjsip_sdp_rtp.c
5 files changed, 38 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/22/4322/1

diff --git a/include/asterisk/format.h b/include/asterisk/format.h
index a5ca038..b01592d 100644
--- a/include/asterisk/format.h
+++ b/include/asterisk/format.h
@@ -299,6 +299,24 @@
 const char *ast_format_get_name(const struct ast_format *format);
 
 /*!
+ * \brief Get the channel count on a format
+ *
+ * \param The media format
+ *
+ * \return Currently set channel count
+ */
+unsigned int ast_format_get_channel_count(const struct ast_format *format);
+
+/*!
+ * \brief Set the channel count on a format
+ *
+ * \param format The media format
+ * \param channel_count The number of audio channels used
+ *
+ */
+void ast_format_set_channel_count(struct ast_format *format, unsigned int channel_count);
+
+/*!
  * \brief Get the codec associated with a format
  *
  * \param format The media format
diff --git a/main/format.c b/main/format.c
index b5e5779..5ae5ad9 100644
--- a/main/format.c
+++ b/main/format.c
@@ -49,6 +49,8 @@
 	void *attribute_data;
 	/*! \brief Pointer to the optional format interface */
 	const struct ast_format_interface *interface;
+	/*! \brief The number if audio channels used, if more than one an interleaved format is required */
+	unsigned int channel_count;
 };
 
 /*! \brief Structure used when registering a format interface */
@@ -175,6 +177,16 @@
 	format->attribute_data = attribute_data;
 }
 
+unsigned int ast_format_get_channel_count(const struct ast_format *format)
+{
+	return format->channel_count;
+}
+
+void ast_format_set_channel_count(struct ast_format *format, unsigned int channel_count)
+{
+	format->channel_count = channel_count;
+}
+
 /*! \brief Destructor for media formats */
 static void format_destroy(void *obj)
 {
@@ -199,6 +211,7 @@
 	}
 	format->name = format_name;
 	format->codec = ao2_bump(codec);
+	format->channel_count = 1;
 
 	format_interface = ao2_find(interfaces, codec->name, OBJ_SEARCH_KEY);
 	if (format_interface) {
diff --git a/main/format_cap.c b/main/format_cap.c
index 1fe342b..9614575 100644
--- a/main/format_cap.c
+++ b/main/format_cap.c
@@ -637,6 +637,10 @@
 			continue;
 		}
 
+		if (ast_format_get_channel_count(framed->format) > 1) {
+			ast_format_set_channel_count(format, ast_format_get_channel_count(framed->format));
+		}
+
 		res = ast_format_cap_append(result, format, framed->framing);
 		ao2_ref(format, -1);
 
diff --git a/res/res_format_attr_opus.c b/res/res_format_attr_opus.c
index a3e48e3..3e18dd5 100644
--- a/res/res_format_attr_opus.c
+++ b/res/res_format_attr_opus.c
@@ -145,6 +145,8 @@
 	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);
+	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);
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index 3df9df0..6446ca9 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -269,6 +269,7 @@
 
 				format_parsed = ast_format_parse_sdp_fmtp(format, fmt_param);
 				if (format_parsed) {
+					ast_format_set_channel_count(format, ast_format_get_channel_count(format_parsed));
 					ast_rtp_codecs_payload_replace_format(codecs, num, format_parsed);
 					ao2_ref(format_parsed, -1);
 				}

-- 
To view, visit https://gerrit.asterisk.org/4322
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I359801cc5f98c35671c48dabc81a7f4ee1183d63
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Frank Haase <fra.haase at googlemail.com>



More information about the asterisk-code-review mailing list