opus: Handle sprop-stereo and sprop-maxcapturerate RTP caps fields

https://bugzilla.gnome.org/show_bug.cgi?id=746617
This commit is contained in:
Sebastian Dröge 2015-03-23 12:24:55 +01:00 committed by Tim-Philipp Müller
parent 4b5ad70924
commit bbb1143ca3
2 changed files with 67 additions and 1 deletions

View file

@ -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,

View file

@ -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;
}