From e714ab9dba55967102a75869fd48b0d391f489b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Tue, 13 Aug 2013 12:10:42 -0400 Subject: [PATCH] pulse: Make gst_pulse_format_info_to_caps() shared https://bugzilla.gnome.org/show_bug.cgi?id=678402 --- ext/pulse/pulsesink.c | 110 ------------------------------------------ ext/pulse/pulseutil.c | 110 ++++++++++++++++++++++++++++++++++++++++++ ext/pulse/pulseutil.h | 2 + 3 files changed, 112 insertions(+), 110 deletions(-) diff --git a/ext/pulse/pulsesink.c b/ext/pulse/pulsesink.c index ec7d4eff01..e580afce2d 100644 --- a/ext/pulse/pulsesink.c +++ b/ext/pulse/pulsesink.c @@ -2024,116 +2024,6 @@ done: pa_threaded_mainloop_signal (mainloop, 0); } -static gboolean -gst_pulse_format_info_int_prop_to_value (pa_format_info * format, - const char *key, GValue * value) -{ - GValue v = { 0, }; - int i; - int *a, n; - int min, max; - - if (pa_format_info_get_prop_int (format, key, &i) == 0) { - g_value_init (value, G_TYPE_INT); - g_value_set_int (value, i); - - } else if (pa_format_info_get_prop_int_array (format, key, &a, &n) == 0) { - g_value_init (value, GST_TYPE_LIST); - g_value_init (&v, G_TYPE_INT); - - for (i = 0; i < n; i++) { - g_value_set_int (&v, a[i]); - gst_value_list_append_value (value, &v); - } - - pa_xfree (a); - - } else if (pa_format_info_get_prop_int_range (format, key, &min, &max) == 0) { - g_value_init (value, GST_TYPE_INT_RANGE); - gst_value_set_int_range (value, min, max); - - } else { - /* Property not available or is not an int type */ - return FALSE; - } - - return TRUE; -} - -static GstCaps * -gst_pulse_format_info_to_caps (pa_format_info * format) -{ - GstCaps *ret = NULL; - GValue v = { 0, }; - pa_sample_spec ss; - - switch (format->encoding) { - case PA_ENCODING_PCM:{ - char *tmp = NULL; - - pa_format_info_to_sample_spec (format, &ss, NULL); - - if (pa_format_info_get_prop_string (format, - PA_PROP_FORMAT_SAMPLE_FORMAT, &tmp)) { - /* No specific sample format means any sample format */ - ret = gst_caps_from_string (_PULSE_CAPS_PCM); - goto out; - - } else if (ss.format == PA_SAMPLE_ALAW) { - ret = gst_caps_from_string (_PULSE_CAPS_ALAW); - - } else if (ss.format == PA_SAMPLE_ULAW) { - ret = gst_caps_from_string (_PULSE_CAPS_MP3); - - } else { - /* Linear PCM format */ - const char *sformat = - gst_pulse_sample_format_to_caps_format (ss.format); - - ret = gst_caps_from_string (_PULSE_CAPS_LINEAR); - - if (sformat) - gst_caps_set_simple (ret, "format", G_TYPE_STRING, NULL); - } - - pa_xfree (tmp); - break; - } - - case PA_ENCODING_AC3_IEC61937: - ret = gst_caps_from_string (_PULSE_CAPS_AC3); - break; - - case PA_ENCODING_EAC3_IEC61937: - ret = gst_caps_from_string (_PULSE_CAPS_EAC3); - break; - - case PA_ENCODING_DTS_IEC61937: - ret = gst_caps_from_string (_PULSE_CAPS_DTS); - break; - - case PA_ENCODING_MPEG_IEC61937: - ret = gst_caps_from_string (_PULSE_CAPS_MP3); - break; - - default: - GST_WARNING ("Found a PA format that we don't support yet"); - goto out; - } - - if (gst_pulse_format_info_int_prop_to_value (format, PA_PROP_FORMAT_RATE, &v)) - gst_caps_set_value (ret, "rate", &v); - - g_value_unset (&v); - - if (gst_pulse_format_info_int_prop_to_value (format, PA_PROP_FORMAT_CHANNELS, - &v)) - gst_caps_set_value (ret, "channels", &v); - -out: - return ret; -} - /* Call with mainloop lock held */ static pa_stream * gst_pulsesink_create_probe_stream (GstPulseSink * psink, diff --git a/ext/pulse/pulseutil.c b/ext/pulse/pulseutil.c index 89ed1068f3..b0f4a0aab7 100644 --- a/ext/pulse/pulseutil.c +++ b/ext/pulse/pulseutil.c @@ -375,3 +375,113 @@ gst_pulse_make_proplist (const GstStructure * properties) gst_structure_foreach (properties, make_proplist_item, proplist); return proplist; } + +static gboolean +gst_pulse_format_info_int_prop_to_value (pa_format_info * format, + const char *key, GValue * value) +{ + GValue v = { 0, }; + int i; + int *a, n; + int min, max; + + if (pa_format_info_get_prop_int (format, key, &i) == 0) { + g_value_init (value, G_TYPE_INT); + g_value_set_int (value, i); + + } else if (pa_format_info_get_prop_int_array (format, key, &a, &n) == 0) { + g_value_init (value, GST_TYPE_LIST); + g_value_init (&v, G_TYPE_INT); + + for (i = 0; i < n; i++) { + g_value_set_int (&v, a[i]); + gst_value_list_append_value (value, &v); + } + + pa_xfree (a); + + } else if (pa_format_info_get_prop_int_range (format, key, &min, &max) == 0) { + g_value_init (value, GST_TYPE_INT_RANGE); + gst_value_set_int_range (value, min, max); + + } else { + /* Property not available or is not an int type */ + return FALSE; + } + + return TRUE; +} + +GstCaps * +gst_pulse_format_info_to_caps (pa_format_info * format) +{ + GstCaps *ret = NULL; + GValue v = { 0, }; + pa_sample_spec ss; + + switch (format->encoding) { + case PA_ENCODING_PCM:{ + char *tmp = NULL; + + pa_format_info_to_sample_spec (format, &ss, NULL); + + if (pa_format_info_get_prop_string (format, + PA_PROP_FORMAT_SAMPLE_FORMAT, &tmp)) { + /* No specific sample format means any sample format */ + ret = gst_caps_from_string (_PULSE_CAPS_PCM); + goto out; + + } else if (ss.format == PA_SAMPLE_ALAW) { + ret = gst_caps_from_string (_PULSE_CAPS_ALAW); + + } else if (ss.format == PA_SAMPLE_ULAW) { + ret = gst_caps_from_string (_PULSE_CAPS_MP3); + + } else { + /* Linear PCM format */ + const char *sformat = + gst_pulse_sample_format_to_caps_format (ss.format); + + ret = gst_caps_from_string (_PULSE_CAPS_LINEAR); + + if (sformat) + gst_caps_set_simple (ret, "format", G_TYPE_STRING, NULL); + } + + pa_xfree (tmp); + break; + } + + case PA_ENCODING_AC3_IEC61937: + ret = gst_caps_from_string (_PULSE_CAPS_AC3); + break; + + case PA_ENCODING_EAC3_IEC61937: + ret = gst_caps_from_string (_PULSE_CAPS_EAC3); + break; + + case PA_ENCODING_DTS_IEC61937: + ret = gst_caps_from_string (_PULSE_CAPS_DTS); + break; + + case PA_ENCODING_MPEG_IEC61937: + ret = gst_caps_from_string (_PULSE_CAPS_MP3); + break; + + default: + GST_WARNING ("Found a PA format that we don't support yet"); + goto out; + } + + if (gst_pulse_format_info_int_prop_to_value (format, PA_PROP_FORMAT_RATE, &v)) + gst_caps_set_value (ret, "rate", &v); + + g_value_unset (&v); + + if (gst_pulse_format_info_int_prop_to_value (format, PA_PROP_FORMAT_CHANNELS, + &v)) + gst_caps_set_value (ret, "channels", &v); + +out: + return ret; +} diff --git a/ext/pulse/pulseutil.h b/ext/pulse/pulseutil.h index d558afac20..3b7293f0ee 100644 --- a/ext/pulse/pulseutil.h +++ b/ext/pulse/pulseutil.h @@ -88,4 +88,6 @@ void gst_pulse_cvolume_from_linear (pa_cvolume *v, unsigned channels, gdouble vo pa_proplist *gst_pulse_make_proplist (const GstStructure *properties); +GstCaps * gst_pulse_format_info_to_caps (pa_format_info * format); + #endif