summaryrefslogtreecommitdiffstats
path: root/audio/gstsbcutil.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-11-21 20:24:11 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-11-21 20:24:11 +0000
commitd4e24bf6a3d8af6479abce92fbbf1869a59669aa (patch)
tree8ba8c084bb1eb1a3e1dd598127ca33553dbc6d23 /audio/gstsbcutil.c
parent47e2c26cc95d761099c367593bbbd4bc581bf0ac (diff)
Integrate new ipc API implementation.
Diffstat (limited to 'audio/gstsbcutil.c')
-rw-r--r--audio/gstsbcutil.c174
1 files changed, 151 insertions, 23 deletions
diff --git a/audio/gstsbcutil.c b/audio/gstsbcutil.c
index 1d7a1227..f2351e6b 100644
--- a/audio/gstsbcutil.c
+++ b/audio/gstsbcutil.c
@@ -99,11 +99,11 @@ const gchar *gst_sbc_get_mode_from_list(const GValue *value)
gint gst_sbc_get_allocation_mode_int(const gchar *allocation)
{
if (g_ascii_strcasecmp(allocation, "loudness") == 0)
- return CFG_ALLOCATION_LOUDNESS;
+ return BT_A2DP_ALLOCATION_LOUDNESS;
else if (g_ascii_strcasecmp(allocation, "snr") == 0)
- return CFG_ALLOCATION_SNR;
+ return BT_A2DP_ALLOCATION_SNR;
else if (g_ascii_strcasecmp(allocation, "auto") == 0)
- return CFG_ALLOCATION_AUTO;
+ return BT_A2DP_ALLOCATION_AUTO;
else
return -1;
}
@@ -111,15 +111,15 @@ gint gst_sbc_get_allocation_mode_int(const gchar *allocation)
gint gst_sbc_get_mode_int(const gchar *mode)
{
if (g_ascii_strcasecmp(mode, "joint") == 0)
- return CFG_MODE_JOINT_STEREO;
+ return BT_A2DP_CHANNEL_MODE_JOINT_STEREO;
else if (g_ascii_strcasecmp(mode, "stereo") == 0)
- return CFG_MODE_STEREO;
+ return BT_A2DP_CHANNEL_MODE_STEREO;
else if (g_ascii_strcasecmp(mode, "dual") == 0)
- return CFG_MODE_DUAL_CHANNEL;
+ return BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL;
else if (g_ascii_strcasecmp(mode, "mono") == 0)
- return CFG_MODE_MONO;
+ return BT_A2DP_CHANNEL_MODE_MONO;
else if (g_ascii_strcasecmp(mode, "auto") == 0)
- return CFG_MODE_AUTO;
+ return BT_A2DP_CHANNEL_MODE_AUTO;
else
return -1;
}
@@ -127,15 +127,15 @@ gint gst_sbc_get_mode_int(const gchar *mode)
const gchar *gst_sbc_get_mode_string(int joint)
{
switch (joint) {
- case CFG_MODE_MONO:
+ case BT_A2DP_CHANNEL_MODE_MONO:
return "mono";
- case CFG_MODE_DUAL_CHANNEL:
+ case BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL:
return "dual";
- case CFG_MODE_STEREO:
+ case BT_A2DP_CHANNEL_MODE_STEREO:
return "stereo";
- case CFG_MODE_JOINT_STEREO:
+ case BT_A2DP_CHANNEL_MODE_JOINT_STEREO:
return "joint";
- case CFG_MODE_AUTO:
+ case BT_A2DP_CHANNEL_MODE_AUTO:
return NULL; /* TODO what should be selected here? */
default:
return NULL;
@@ -145,37 +145,165 @@ const gchar *gst_sbc_get_mode_string(int joint)
const gchar *gst_sbc_get_allocation_string(int alloc)
{
switch (alloc) {
- case CFG_ALLOCATION_LOUDNESS:
+ case BT_A2DP_ALLOCATION_LOUDNESS:
return "loudness";
- case CFG_ALLOCATION_SNR:
+ case BT_A2DP_ALLOCATION_SNR:
return "snr";
- case CFG_ALLOCATION_AUTO:
+ case BT_A2DP_ALLOCATION_AUTO:
return "loudness"; /* TODO what should be selected here? */
default:
return NULL;
}
}
-GstCaps* gst_sbc_caps_from_sbc(struct ipc_data_cfg *cfg,
- struct ipc_codec_sbc *sbc, gint channels)
+GstCaps* gst_sbc_caps_from_sbc(sbc_capabilities_t *sbc, gint channels)
{
GstCaps *caps;
const gchar *mode_str;
const gchar *allocation_str;
- mode_str = gst_sbc_get_mode_string(cfg->mode);
- allocation_str = gst_sbc_get_allocation_string(sbc->allocation);
+ mode_str = gst_sbc_get_mode_string(sbc->channel_mode);
+ allocation_str = gst_sbc_get_allocation_string(sbc->allocation_method);
caps = gst_caps_new_simple("audio/x-sbc",
- "rate", G_TYPE_INT, cfg->rate,
+ "rate", G_TYPE_INT, sbc->frequency,
"channels", G_TYPE_INT, channels,
"mode", G_TYPE_STRING, mode_str,
"subbands", G_TYPE_INT, sbc->subbands,
- "blocks", G_TYPE_INT, sbc->blocks,
+ "blocks", G_TYPE_INT, sbc->block_length,
"allocation", G_TYPE_STRING, allocation_str,
- "bitpool", G_TYPE_INT, sbc->bitpool,
+ "bitpool", G_TYPE_INT, sbc->max_bitpool,
NULL);
return caps;
}
+/*
+ * Given a GstCaps, this will return a fixed GstCaps on sucessfull conversion.
+ * If an error occurs, it will return NULL and error_message will contain the
+ * error message.
+ *
+ * error_message must be passed NULL, if an error occurs, the caller has the
+ * ownership of the error_message, it must be freed after use.
+ */
+GstCaps* gst_sbc_util_caps_fixate(GstCaps *caps, gchar** error_message)
+{
+ GstCaps *result;
+ GstStructure *structure;
+ const GValue *value;
+ gboolean error = FALSE;
+ gint temp, rate, channels, blocks, subbands, bitpool;
+ const gchar* allocation = NULL;
+ const gchar* mode = NULL;
+
+ g_assert(*error_message == NULL);
+
+ structure = gst_caps_get_structure(caps, 0);
+
+ if (!gst_structure_has_field(structure, "rate")) {
+ error = TRUE;
+ *error_message = g_strdup("no rate");
+ goto error;
+ } else {
+ value = gst_structure_get_value(structure, "rate");
+ if (GST_VALUE_HOLDS_LIST(value))
+ temp = gst_sbc_select_rate_from_list(value);
+ else
+ temp = g_value_get_int(value);
+ rate = temp;
+ }
+
+ if (!gst_structure_has_field(structure, "channels")) {
+ error = TRUE;
+ *error_message = g_strdup("no channels");
+ goto error;
+ } else {
+ value = gst_structure_get_value(structure, "channels");
+ if (GST_VALUE_HOLDS_INT_RANGE(value))
+ temp = gst_sbc_select_channels_from_range(value);
+ else
+ temp = g_value_get_int(value);
+ channels = temp;
+ }
+
+ if (!gst_structure_has_field(structure, "blocks")) {
+ error = TRUE;
+ *error_message = g_strdup("no blocks.");
+ goto error;
+ } else {
+ value = gst_structure_get_value(structure, "blocks");
+ if (GST_VALUE_HOLDS_LIST(value))
+ temp = gst_sbc_select_blocks_from_list(value);
+ else
+ temp = g_value_get_int(value);
+ blocks = temp;
+ }
+
+ if (!gst_structure_has_field(structure, "subbands")) {
+ error = TRUE;
+ *error_message = g_strdup("no subbands");
+ goto error;
+ } else {
+ value = gst_structure_get_value(structure, "subbands");
+ if (GST_VALUE_HOLDS_LIST(value))
+ temp = gst_sbc_select_subbands_from_list(value);
+ else
+ temp = g_value_get_int(value);
+ subbands = temp;
+ }
+
+ if (!gst_structure_has_field(structure, "bitpool")) {
+ error = TRUE;
+ *error_message = g_strdup("no bitpool");
+ goto error;
+ } else {
+ value = gst_structure_get_value(structure, "bitpool");
+ if (GST_VALUE_HOLDS_INT_RANGE(value))
+ temp = gst_sbc_select_bitpool_from_range(value);
+ else
+ temp = g_value_get_int(value);
+ bitpool = temp;
+ }
+
+ if (!gst_structure_has_field(structure, "allocation")) {
+ error = TRUE;
+ *error_message = g_strdup("no allocation");
+ goto error;
+ } else {
+ value = gst_structure_get_value(structure, "allocation");
+ if (GST_VALUE_HOLDS_LIST(value))
+ allocation = gst_sbc_get_allocation_from_list(value);
+ else
+ allocation = g_value_get_string(value);
+ }
+
+ if (!gst_structure_has_field(structure, "mode")) {
+ error = TRUE;
+ *error_message = g_strdup("no mode");
+ goto error;
+ } else {
+ value = gst_structure_get_value(structure, "mode");
+ if (GST_VALUE_HOLDS_LIST(value))
+ mode = gst_sbc_get_mode_from_list(value);
+ else
+ mode = g_value_get_string(value);
+ }
+
+error:
+ if (error)
+ return NULL;
+
+ result = gst_caps_new_simple("audio/x-sbc",
+ "rate", G_TYPE_INT, rate,
+ "channels", G_TYPE_INT, channels,
+ "mode", G_TYPE_STRING, mode,
+ "blocks", G_TYPE_INT, blocks,
+ "subbands", G_TYPE_INT, subbands,
+ "allocation", G_TYPE_STRING, allocation,
+ "bitpool", G_TYPE_INT, bitpool,
+ NULL);
+
+ return result;
+}
+
+