diff options
Diffstat (limited to 'audio/gstsbcutil.c')
| -rw-r--r-- | audio/gstsbcutil.c | 64 | 
1 files changed, 52 insertions, 12 deletions
diff --git a/audio/gstsbcutil.c b/audio/gstsbcutil.c index e5d21af0..7c47dbca 100644 --- a/audio/gstsbcutil.c +++ b/audio/gstsbcutil.c @@ -90,21 +90,39 @@ const gchar *gst_sbc_get_allocation_from_list(const GValue *value)  /*   * Selects one mode from the ones on the list   */ -const gchar *gst_sbc_get_mode_from_list(const GValue *list) +const gchar *gst_sbc_get_mode_from_list(const GValue *list, gint channels)  {  	int i;  	const GValue *value;  	const gchar *aux; +	gboolean joint, stereo, dual, mono; +	joint = stereo = dual = mono = FALSE;  	guint size = gst_value_list_get_size(list); +  	for (i = 0; i < size; i++) {  		value = gst_value_list_get_value(list, i);  		aux = g_value_get_string(value); -		if (strcmp("joint", aux) == 0) { +		if (strcmp("joint", aux) == 0) +			joint = TRUE; +		else if (strcmp("stereo", aux) == 0) +			stereo = TRUE; +		else if (strcmp("dual", aux) == 0) +			dual = TRUE; +		else if (strcmp("mono", aux) == 0) +			mono = TRUE; +	} + +	if (channels == 1 && mono) +		return "mono"; +	else if (channels == 2) { +		if (joint)  			return "joint"; -		} +		else if (stereo) +			return "stereo";  	} -	return g_value_get_string(gst_value_list_get_value(list, size-1)); + +	return NULL;  }  gint gst_sbc_get_allocation_mode_int(const gchar *allocation) @@ -148,7 +166,20 @@ gboolean gst_sbc_get_mode_int_for_sbc_t(const gchar *mode)  		return -1;  } -const gchar *gst_sbc_get_mode_string(int joint) +gint gst_sbc_get_mode_int_from_sbc_t(const sbc_t *sbc) +{ +	/* TODO define constants */ +	if (sbc->channels == 2 && sbc->joint == 1) +		return 4; +	else if (sbc->channels == 2 && sbc->joint == 0) +		return 3; +	else if (sbc->channels == 1) +		return 1; +	else +		return -1; +} + +const gchar *gst_sbc_get_mode_string(gint joint)  {  	switch (joint) {  	case BT_A2DP_CHANNEL_MODE_MONO: @@ -166,7 +197,7 @@ const gchar *gst_sbc_get_mode_string(int joint)  	}  } -const gchar *gst_sbc_get_allocation_string(int alloc) +const gchar *gst_sbc_get_allocation_string(gint alloc)  {  	switch (alloc) {  	case BT_A2DP_ALLOCATION_LOUDNESS: @@ -190,7 +221,7 @@ const gchar *gst_sbc_get_allocation_string(int alloc)  #define SBC_AM_LOUDNESS         0x00  #define SBC_AM_SNR              0x01 -const gchar *gst_sbc_get_mode_string_from_sbc_t(int channels, int joint) +const gchar *gst_sbc_get_mode_string_from_sbc_t(gint channels, gint joint)  {  	if (channels == 2 && joint == 1)  		return "joint"; @@ -202,7 +233,7 @@ const gchar *gst_sbc_get_mode_string_from_sbc_t(int channels, int joint)  		return NULL;  } -const gchar *gst_sbc_get_allocation_string_from_sbc_t(int alloc) +const gchar *gst_sbc_get_allocation_string_from_sbc_t(gint alloc)  {  	switch (alloc) {  	case SBC_AM_LOUDNESS: @@ -365,14 +396,23 @@ GstCaps* gst_sbc_util_caps_fixate(GstCaps *caps, gchar** error_message)  	} else {  		value = gst_structure_get_value(structure, "mode");  		if (GST_VALUE_HOLDS_LIST(value)) { -			if (channels == 1) -				mode = "mono"; -			else -				mode = gst_sbc_get_mode_from_list(value); +			mode = gst_sbc_get_mode_from_list(value, channels);  		} else  			mode = g_value_get_string(value);  	} +	/* perform validation  +	 * if channels is 1, we must have channel mode = mono +	 * if channels is 2, we can't have channel mode = mono, dual */ +	if ( (channels == 1 && (strcmp(mode, "mono") != 0) ) || +			( channels == 2 && ( strcmp(mode, "mono") == 0 || +			strcmp(mode, "dual") == 0 ) )) { +		*error_message = g_strdup_printf("Invalid combination of " +					"channels (%d) and channel mode (%s)", +					channels, mode); +		error = TRUE; +	} +  error:  	if (error)  		return NULL;  | 
