summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2015-03-23 12:24:55 +0100
committerTim-Philipp Müller <tim@centricular.com>2016-02-17 14:58:01 +0000
commitbbb1143ca36f9e201a6236dcfed384d44b26b4e4 (patch)
treebfdfd257ab42a3c3ddb2523d224898b89916f890
parent4b5ad70924f3c86b6cdeff2d75068daad80a584b (diff)
downloadgstreamer-plugins-good-bbb1143ca36f9e201a6236dcfed384d44b26b4e4.tar.gz
opus: Handle sprop-stereo and sprop-maxcapturerate RTP caps fields
https://bugzilla.gnome.org/show_bug.cgi?id=746617
-rw-r--r--gst/rtp/gstrtpopusdepay.c29
-rw-r--r--gst/rtp/gstrtpopuspay.c39
2 files changed, 67 insertions, 1 deletions
diff --git a/gst/rtp/gstrtpopusdepay.c b/gst/rtp/gstrtpopusdepay.c
index 6bcdd1262..f58259ff8 100644
--- a/gst/rtp/gstrtpopusdepay.c
+++ b/gst/rtp/gstrtpopusdepay.c
@@ -92,9 +92,38 @@ static gboolean
gst_rtp_opus_depay_setcaps (GstRTPBaseDepayload * depayload, GstCaps * caps)
{
GstCaps *srccaps;
+ GstStructure *s;
gboolean ret;
+ const gchar *sprop_stereo, *sprop_maxcapturerate;
srccaps = gst_caps_new_empty_simple ("audio/x-opus");
+
+ s = gst_caps_get_structure (caps, 0);
+ if ((sprop_stereo = gst_structure_get_string (s, "sprop-stereo"))) {
+ if (strcmp (sprop_stereo, "0") == 0)
+ gst_caps_set_simple (srccaps, "channels", G_TYPE_INT, 1, NULL);
+ else if (strcmp (sprop_stereo, "1") == 0)
+ gst_caps_set_simple (srccaps, "channels", G_TYPE_INT, 2, NULL);
+ else
+ GST_WARNING_OBJECT (depayload, "Unknown sprop-stereo value '%s'",
+ sprop_stereo);
+ }
+
+ if ((sprop_maxcapturerate =
+ gst_structure_get_string (s, "sprop-maxcapturerate"))) {
+ gulong rate;
+ gchar *tailptr;
+
+ rate = strtoul (sprop_maxcapturerate, &tailptr, 10);
+ if (rate > INT_MAX || *tailptr != '\0') {
+ GST_WARNING_OBJECT (depayload,
+ "Failed to parse sprop-maxcapturerate value '%s'",
+ sprop_maxcapturerate);
+ } else {
+ gst_caps_set_simple (srccaps, "rate", G_TYPE_INT, rate, NULL);
+ }
+ }
+
ret = gst_pad_set_caps (GST_RTP_BASE_DEPAYLOAD_SRCPAD (depayload), srccaps);
GST_DEBUG_OBJECT (depayload,
diff --git a/gst/rtp/gstrtpopuspay.c b/gst/rtp/gstrtpopuspay.c
index d0f7b10c5..a5a69569e 100644
--- a/gst/rtp/gstrtpopuspay.c
+++ b/gst/rtp/gstrtpopuspay.c
@@ -97,6 +97,9 @@ gst_rtp_opus_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
GstCaps *src_caps;
GstStructure *s;
char *encoding_name;
+ gint channels, rate;
+ const char *sprop_stereo = NULL;
+ char *sprop_maxcapturerate = NULL;
src_caps = gst_pad_get_allowed_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload));
if (src_caps) {
@@ -110,10 +113,44 @@ gst_rtp_opus_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
encoding_name = g_strdup ("X-GST-OPUS-DRAFT-SPITTKA-00");
}
+ s = gst_caps_get_structure (caps, 0);
+ if (gst_structure_get_int (s, "channels", &channels)) {
+ if (channels > 2) {
+ GST_ERROR_OBJECT (payload, "More than 2 channels are not supported yet");
+ return FALSE;
+ } else if (channels == 2) {
+ sprop_stereo = "1";
+ } else {
+ sprop_stereo = "0";
+ }
+ }
+
+ if (gst_structure_get_int (s, "rate", &rate)) {
+ sprop_maxcapturerate = g_strdup_printf ("%d", rate);
+ }
+
gst_rtp_base_payload_set_options (payload, "audio", FALSE,
encoding_name, 48000);
g_free (encoding_name);
- res = gst_rtp_base_payload_set_outcaps (payload, NULL);
+
+ if (sprop_maxcapturerate && sprop_stereo) {
+ res =
+ gst_rtp_base_payload_set_outcaps (payload, "sprop-maxcapturerate",
+ G_TYPE_STRING, sprop_maxcapturerate, "sprop-stereo", G_TYPE_STRING,
+ sprop_stereo, NULL);
+ } else if (sprop_maxcapturerate) {
+ res =
+ gst_rtp_base_payload_set_outcaps (payload, "sprop-maxcapturerate",
+ G_TYPE_STRING, sprop_maxcapturerate, NULL);
+ } else if (sprop_stereo) {
+ res =
+ gst_rtp_base_payload_set_outcaps (payload, "sprop-stereo",
+ G_TYPE_STRING, sprop_stereo, NULL);
+ } else {
+ res = gst_rtp_base_payload_set_outcaps (payload, NULL);
+ }
+
+ g_free (sprop_maxcapturerate);
return res;
}