mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-22 08:17:01 +00:00
sbc: Update gstreamer plugin to use new sbc API.
This commit is contained in:
parent
ccf5d9ea7e
commit
834a9b193b
5 changed files with 205 additions and 198 deletions
|
@ -96,8 +96,10 @@ sbc_dec_chain (GstPad * pad, GstBuffer * buffer)
|
|||
/* we will reuse the same caps object */
|
||||
if (dec->outcaps == NULL) {
|
||||
caps = gst_caps_new_simple ("audio/x-raw-int",
|
||||
"rate", G_TYPE_INT, dec->sbc.rate,
|
||||
"channels", G_TYPE_INT, dec->sbc.channels, NULL);
|
||||
"rate", G_TYPE_INT,
|
||||
gst_sbc_parse_rate_from_sbc (dec->sbc.frequency),
|
||||
"channels", G_TYPE_INT,
|
||||
gst_sbc_get_channel_number (dec->sbc.mode), NULL);
|
||||
|
||||
template = gst_static_pad_template_get (&sbc_dec_src_factory);
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
#include "sbc.h"
|
||||
#include "gstsbcutil.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
|
@ -27,14 +27,13 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#include "ipc.h"
|
||||
#include "gstsbcenc.h"
|
||||
#include "gstsbcutil.h"
|
||||
|
||||
#define SBC_ENC_DEFAULT_MODE BT_A2DP_CHANNEL_MODE_JOINT_STEREO
|
||||
#define SBC_ENC_DEFAULT_MODE SBC_MODE_AUTO
|
||||
#define SBC_ENC_DEFAULT_BLOCKS 0
|
||||
#define SBC_ENC_DEFAULT_SUB_BANDS 0
|
||||
#define SBC_ENC_DEFAULT_ALLOCATION BT_A2DP_ALLOCATION_LOUDNESS
|
||||
#define SBC_ENC_DEFAULT_ALLOCATION SBC_AM_AUTO
|
||||
#define SBC_ENC_DEFAULT_RATE 0
|
||||
#define SBC_ENC_DEFAULT_CHANNELS 0
|
||||
|
||||
|
@ -54,11 +53,11 @@ gst_sbc_mode_get_type (void)
|
|||
{
|
||||
static GType sbc_mode_type = 0;
|
||||
static GEnumValue sbc_modes[] = {
|
||||
{0, "Auto", "auto"},
|
||||
{1, "Mono", "mono"},
|
||||
{2, "Dual Channel", "dual"},
|
||||
{3, "Stereo", "stereo"},
|
||||
{4, "Joint Stereo", "joint"},
|
||||
{SBC_MODE_MONO, "Mono", "mono"},
|
||||
{SBC_MODE_DUAL_CHANNEL, "Dual Channel", "dual"},
|
||||
{SBC_MODE_STEREO, "Stereo", "stereo"},
|
||||
{SBC_MODE_JOINT_STEREO, "Joint Stereo", "joint"},
|
||||
{SBC_MODE_AUTO, "Auto", "auto"},
|
||||
{-1, NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -75,8 +74,9 @@ gst_sbc_allocation_get_type (void)
|
|||
{
|
||||
static GType sbc_allocation_type = 0;
|
||||
static GEnumValue sbc_allocations[] = {
|
||||
{BT_A2DP_ALLOCATION_LOUDNESS, "Loudness", "loudness"},
|
||||
{BT_A2DP_ALLOCATION_SNR, "SNR", "snr"},
|
||||
{SBC_AM_LOUDNESS, "Loudness", "loudness"},
|
||||
{SBC_AM_SNR, "SNR", "snr"},
|
||||
{SBC_AM_AUTO, "Auto", "auto"},
|
||||
{-1, NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -174,7 +174,6 @@ sbc_enc_generate_srcpad_caps (GstSbcEnc * enc)
|
|||
GstStructure *structure;
|
||||
GEnumValue *enum_value;
|
||||
GEnumClass *enum_class;
|
||||
gchar *temp;
|
||||
GValue *value;
|
||||
|
||||
src_caps = gst_caps_copy (gst_pad_get_pad_template_caps (enc->srcpad));
|
||||
|
@ -209,7 +208,7 @@ sbc_enc_generate_srcpad_caps (GstSbcEnc * enc)
|
|||
g_type_class_unref (enum_class);
|
||||
}
|
||||
|
||||
if (enc->allocation != SBC_ENC_DEFAULT_ALLOCATION) {
|
||||
if (enc->allocation != SBC_AM_AUTO) {
|
||||
enum_class = g_type_class_ref (GST_TYPE_SBC_ALLOCATION);
|
||||
enum_value = g_enum_get_value (enum_class, enc->allocation);
|
||||
gst_sbc_util_set_structure_string_param (structure, "allocation",
|
||||
|
@ -217,9 +216,6 @@ sbc_enc_generate_srcpad_caps (GstSbcEnc * enc)
|
|||
g_type_class_unref (enum_class);
|
||||
}
|
||||
|
||||
temp = gst_caps_to_string (src_caps);
|
||||
GST_DEBUG_OBJECT (enc, "Srcpad caps: %s", temp);
|
||||
g_free (temp);
|
||||
g_free (value);
|
||||
|
||||
return src_caps;
|
||||
|
@ -248,7 +244,6 @@ sbc_enc_src_setcaps (GstPad * pad, GstCaps * caps)
|
|||
static GstCaps *
|
||||
sbc_enc_src_caps_fixate (GstSbcEnc * enc, GstCaps * caps)
|
||||
{
|
||||
|
||||
gchar *error_message = NULL;
|
||||
GstCaps *result;
|
||||
|
||||
|
@ -323,8 +318,6 @@ sbc_enc_sink_setcaps (GstPad * pad, GstCaps * caps)
|
|||
gboolean
|
||||
gst_sbc_enc_fill_sbc_params (GstSbcEnc * enc, GstCaps * caps)
|
||||
{
|
||||
gint mode;
|
||||
|
||||
if (!gst_caps_is_fixed (caps)) {
|
||||
GST_DEBUG_OBJECT (enc, "didn't receive fixed caps, " "returning false");
|
||||
return FALSE;
|
||||
|
@ -333,24 +326,26 @@ gst_sbc_enc_fill_sbc_params (GstSbcEnc * enc, GstCaps * caps)
|
|||
if (!gst_sbc_util_fill_sbc_params (&enc->sbc, caps))
|
||||
return FALSE;
|
||||
|
||||
if (enc->rate != 0 && enc->sbc.rate != enc->rate)
|
||||
if (enc->rate != 0 && gst_sbc_parse_rate_from_sbc (enc->sbc.frequency)
|
||||
!= enc->rate)
|
||||
goto fail;
|
||||
|
||||
if (enc->channels != 0 && enc->sbc.channels != enc->channels)
|
||||
if (enc->channels != 0 && gst_sbc_get_channel_number (enc->sbc.mode)
|
||||
!= enc->channels)
|
||||
goto fail;
|
||||
|
||||
if (enc->blocks != 0 && enc->sbc.blocks != enc->blocks)
|
||||
if (enc->blocks != 0 && gst_sbc_parse_blocks_from_sbc (enc->sbc.blocks)
|
||||
!= enc->blocks)
|
||||
goto fail;
|
||||
|
||||
if (enc->subbands != 0 && enc->sbc.subbands != enc->subbands)
|
||||
if (enc->subbands != 0
|
||||
&& gst_sbc_parse_subbands_from_sbc (enc->sbc.subbands) != enc->subbands)
|
||||
goto fail;
|
||||
|
||||
mode = gst_sbc_get_mode_int_from_sbc_t (&enc->sbc);
|
||||
if (enc->mode != SBC_ENC_DEFAULT_MODE && mode != enc->mode)
|
||||
if (enc->mode != SBC_ENC_DEFAULT_MODE && enc->sbc.mode != enc->mode)
|
||||
goto fail;
|
||||
|
||||
if (enc->allocation != SBC_ENC_DEFAULT_ALLOCATION &&
|
||||
enc->sbc.allocation != enc->allocation)
|
||||
if (enc->allocation != SBC_AM_AUTO && enc->sbc.allocation != enc->allocation)
|
||||
goto fail;
|
||||
|
||||
if (enc->bitpool != SBC_ENC_BITPOOL_AUTO && enc->sbc.bitpool != enc->bitpool)
|
||||
|
@ -360,8 +355,8 @@ gst_sbc_enc_fill_sbc_params (GstSbcEnc * enc, GstCaps * caps)
|
|||
enc->frame_length = sbc_get_frame_length (&enc->sbc);
|
||||
enc->frame_duration = sbc_get_frame_duration (&enc->sbc);
|
||||
|
||||
GST_DEBUG ("codesize: %d, frame_length: %d, frame_duration: %d",
|
||||
enc->codesize, enc->frame_length, enc->frame_duration);
|
||||
GST_DEBUG_OBJECT (enc, "codesize: %d, frame_length: %d, frame_duration:"
|
||||
" %d", enc->codesize, enc->frame_length, enc->frame_duration);
|
||||
|
||||
return TRUE;
|
||||
|
||||
|
@ -383,7 +378,7 @@ sbc_enc_chain (GstPad * pad, GstBuffer * buffer)
|
|||
GstBuffer *output;
|
||||
GstCaps *caps;
|
||||
const guint8 *data;
|
||||
int consumed;
|
||||
gint consumed;
|
||||
|
||||
caps = GST_PAD_CAPS (enc->srcpad);
|
||||
res = gst_pad_alloc_buffer_and_set_caps (enc->srcpad,
|
||||
|
@ -392,11 +387,12 @@ sbc_enc_chain (GstPad * pad, GstBuffer * buffer)
|
|||
goto done;
|
||||
|
||||
data = gst_adapter_peek (adapter, enc->codesize);
|
||||
|
||||
consumed = sbc_encode (&enc->sbc, (gpointer) data,
|
||||
enc->codesize,
|
||||
GST_BUFFER_DATA (output), GST_BUFFER_SIZE (output), NULL);
|
||||
if (consumed <= 0) {
|
||||
GST_ERROR ("comsumed < 0, codesize: %d", enc->codesize);
|
||||
GST_DEBUG_OBJECT (enc, "comsumed < 0, codesize: %d", enc->codesize);
|
||||
break;
|
||||
}
|
||||
gst_adapter_flush (adapter, consumed);
|
||||
|
@ -406,6 +402,7 @@ sbc_enc_chain (GstPad * pad, GstBuffer * buffer)
|
|||
GST_BUFFER_DURATION (output) = enc->frame_duration;
|
||||
|
||||
res = gst_pad_push (enc->srcpad, output);
|
||||
|
||||
if (res != GST_FLOW_OK)
|
||||
goto done;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include "ipc.h"
|
||||
#include <math.h>
|
||||
#include "gstsbcutil.h"
|
||||
|
||||
|
@ -127,131 +126,183 @@ gst_sbc_get_mode_from_list (const GValue * list, gint channels)
|
|||
return "joint";
|
||||
else if (stereo)
|
||||
return "stereo";
|
||||
else if (dual)
|
||||
return "dual";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_get_allocation_mode_int (const gchar * allocation)
|
||||
gst_sbc_parse_rate_from_sbc (gint frequency)
|
||||
{
|
||||
if (g_ascii_strcasecmp (allocation, "loudness") == 0)
|
||||
return BT_A2DP_ALLOCATION_LOUDNESS;
|
||||
else if (g_ascii_strcasecmp (allocation, "snr") == 0)
|
||||
return BT_A2DP_ALLOCATION_SNR;
|
||||
else
|
||||
return -1;
|
||||
switch (frequency) {
|
||||
case SBC_FREQ_16000:
|
||||
return 16000;
|
||||
case SBC_FREQ_32000:
|
||||
return 32000;
|
||||
case SBC_FREQ_44100:
|
||||
return 44100;
|
||||
case SBC_FREQ_48000:
|
||||
return 48000;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_get_mode_int (const gchar * mode)
|
||||
gst_sbc_parse_rate_to_sbc (gint rate)
|
||||
{
|
||||
if (g_ascii_strcasecmp (mode, "joint") == 0)
|
||||
return BT_A2DP_CHANNEL_MODE_JOINT_STEREO;
|
||||
else if (g_ascii_strcasecmp (mode, "stereo") == 0)
|
||||
return BT_A2DP_CHANNEL_MODE_STEREO;
|
||||
else if (g_ascii_strcasecmp (mode, "dual") == 0)
|
||||
return BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL;
|
||||
else if (g_ascii_strcasecmp (mode, "mono") == 0)
|
||||
return BT_A2DP_CHANNEL_MODE_MONO;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* FIXME add dual when sbc_t supports it */
|
||||
gboolean
|
||||
gst_sbc_get_mode_int_for_sbc_t (const gchar * mode)
|
||||
{
|
||||
if (g_ascii_strcasecmp (mode, "joint") == 0)
|
||||
return TRUE;
|
||||
else if (g_ascii_strcasecmp (mode, "stereo") == 0)
|
||||
return FALSE;
|
||||
else if (g_ascii_strcasecmp (mode, "mono") == 0)
|
||||
return FALSE;
|
||||
else
|
||||
return -1;
|
||||
switch (rate) {
|
||||
case 16000:
|
||||
return SBC_FREQ_16000;
|
||||
case 32000:
|
||||
return SBC_FREQ_32000;
|
||||
case 44100:
|
||||
return SBC_FREQ_44100;
|
||||
case 48000:
|
||||
return SBC_FREQ_48000;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_get_mode_int_from_sbc_t (const sbc_t * sbc)
|
||||
gst_sbc_get_channel_number (gint mode)
|
||||
{
|
||||
/* 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;
|
||||
switch (mode) {
|
||||
case SBC_MODE_JOINT_STEREO:
|
||||
case SBC_MODE_STEREO:
|
||||
case SBC_MODE_DUAL_CHANNEL:
|
||||
return 2;
|
||||
case SBC_MODE_MONO:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_parse_subbands_from_sbc (gint subbands)
|
||||
{
|
||||
switch (subbands) {
|
||||
case SBC_SB_4:
|
||||
return 4;
|
||||
case SBC_SB_8:
|
||||
return 8;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_parse_subbands_to_sbc (gint subbands)
|
||||
{
|
||||
switch (subbands) {
|
||||
case 4:
|
||||
return SBC_SB_4;
|
||||
case 8:
|
||||
return SBC_SB_8;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_parse_blocks_from_sbc (gint blocks)
|
||||
{
|
||||
switch (blocks) {
|
||||
case SBC_BLK_4:
|
||||
return 4;
|
||||
case SBC_BLK_8:
|
||||
return 8;
|
||||
case SBC_BLK_12:
|
||||
return 12;
|
||||
case SBC_BLK_16:
|
||||
return 16;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_parse_blocks_to_sbc (gint blocks)
|
||||
{
|
||||
switch (blocks) {
|
||||
case 4:
|
||||
return SBC_BLK_4;
|
||||
case 8:
|
||||
return SBC_BLK_8;
|
||||
case 12:
|
||||
return SBC_BLK_12;
|
||||
case 16:
|
||||
return SBC_BLK_16;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gst_sbc_get_mode_string (gint joint)
|
||||
gst_sbc_parse_mode_from_sbc (gint mode)
|
||||
{
|
||||
switch (joint) {
|
||||
case BT_A2DP_CHANNEL_MODE_MONO:
|
||||
switch (mode) {
|
||||
case SBC_MODE_MONO:
|
||||
return "mono";
|
||||
case BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL:
|
||||
case SBC_MODE_DUAL_CHANNEL:
|
||||
return "dual";
|
||||
case BT_A2DP_CHANNEL_MODE_STEREO:
|
||||
case SBC_MODE_STEREO:
|
||||
return "stereo";
|
||||
case BT_A2DP_CHANNEL_MODE_JOINT_STEREO:
|
||||
case SBC_MODE_JOINT_STEREO:
|
||||
case SBC_MODE_AUTO:
|
||||
return "joint";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gst_sbc_get_allocation_string (gint alloc)
|
||||
gint
|
||||
gst_sbc_parse_mode_to_sbc (const gchar * mode)
|
||||
{
|
||||
switch (alloc) {
|
||||
case BT_A2DP_ALLOCATION_LOUDNESS:
|
||||
return "loudness";
|
||||
case BT_A2DP_ALLOCATION_SNR:
|
||||
return "snr";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* channel mode */
|
||||
#define SBC_CM_MONO 0x00
|
||||
#define SBC_CM_DUAL_CHANNEL 0x01
|
||||
#define SBC_CM_STEREO 0x02
|
||||
#define SBC_CM_JOINT_STEREO 0x03
|
||||
|
||||
/* allocation mode */
|
||||
#define SBC_AM_LOUDNESS 0x00
|
||||
#define SBC_AM_SNR 0x01
|
||||
|
||||
const gchar *
|
||||
gst_sbc_get_mode_string_from_sbc_t (gint channels, gint joint)
|
||||
{
|
||||
if (channels == 2 && joint == 1)
|
||||
return "joint";
|
||||
else if (channels == 2 && joint == 0)
|
||||
return "stereo";
|
||||
else if (channels == 1 && joint == 0)
|
||||
return "mono";
|
||||
if (g_ascii_strcasecmp (mode, "joint") == 0)
|
||||
return SBC_MODE_JOINT_STEREO;
|
||||
else if (g_ascii_strcasecmp (mode, "stereo") == 0)
|
||||
return SBC_MODE_STEREO;
|
||||
else if (g_ascii_strcasecmp (mode, "dual") == 0)
|
||||
return SBC_MODE_DUAL_CHANNEL;
|
||||
else if (g_ascii_strcasecmp (mode, "mono") == 0)
|
||||
return SBC_MODE_MONO;
|
||||
else if (g_ascii_strcasecmp (mode, "auto") == 0)
|
||||
return SBC_MODE_JOINT_STEREO;
|
||||
else
|
||||
return NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gst_sbc_get_allocation_string_from_sbc_t (gint alloc)
|
||||
gst_sbc_parse_allocation_from_sbc (gint alloc)
|
||||
{
|
||||
switch (alloc) {
|
||||
case SBC_AM_LOUDNESS:
|
||||
return "loudness";
|
||||
case SBC_AM_SNR:
|
||||
return "snr";
|
||||
case SBC_AM_AUTO:
|
||||
return "loudness";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_parse_allocation_to_sbc (const gchar * allocation)
|
||||
{
|
||||
if (g_ascii_strcasecmp (allocation, "loudness") == 0)
|
||||
return SBC_AM_LOUDNESS;
|
||||
else if (g_ascii_strcasecmp (allocation, "snr") == 0)
|
||||
return SBC_AM_SNR;
|
||||
else
|
||||
return SBC_AM_LOUDNESS;
|
||||
}
|
||||
|
||||
GstCaps *
|
||||
gst_sbc_parse_caps_from_sbc (sbc_t * sbc)
|
||||
{
|
||||
|
@ -259,42 +310,24 @@ gst_sbc_parse_caps_from_sbc (sbc_t * sbc)
|
|||
const gchar *mode_str;
|
||||
const gchar *allocation_str;
|
||||
|
||||
mode_str = gst_sbc_get_mode_string_from_sbc_t (sbc->channels, sbc->joint);
|
||||
allocation_str = gst_sbc_get_allocation_string_from_sbc_t (sbc->allocation);
|
||||
mode_str = gst_sbc_parse_mode_from_sbc (sbc->mode);
|
||||
allocation_str = gst_sbc_parse_allocation_from_sbc (sbc->allocation);
|
||||
caps = gst_caps_new_simple ("audio/x-sbc",
|
||||
"rate", G_TYPE_INT, sbc->rate,
|
||||
"channels", G_TYPE_INT, sbc->channels,
|
||||
"rate", G_TYPE_INT,
|
||||
gst_sbc_parse_rate_from_sbc (sbc->frequency),
|
||||
"channels", G_TYPE_INT,
|
||||
gst_sbc_get_channel_number (sbc->mode),
|
||||
"mode", G_TYPE_STRING, mode_str,
|
||||
"subbands", G_TYPE_INT, sbc->subbands,
|
||||
"blocks", G_TYPE_INT, sbc->blocks,
|
||||
"subbands", G_TYPE_INT,
|
||||
gst_sbc_parse_subbands_from_sbc (sbc->subbands),
|
||||
"blocks", G_TYPE_INT,
|
||||
gst_sbc_parse_blocks_from_sbc (sbc->blocks),
|
||||
"allocation", G_TYPE_STRING, allocation_str,
|
||||
"bitpool", G_TYPE_INT, sbc->bitpool, NULL);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
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 (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, sbc->frequency,
|
||||
"channels", G_TYPE_INT, channels,
|
||||
"mode", G_TYPE_STRING, mode_str,
|
||||
"subbands", G_TYPE_INT, sbc->subbands,
|
||||
"blocks", G_TYPE_INT, sbc->block_length,
|
||||
"allocation", G_TYPE_STRING, allocation_str,
|
||||
"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
|
||||
|
@ -409,10 +442,9 @@ gst_sbc_util_caps_fixate (GstCaps * caps, gchar ** error_message)
|
|||
|
||||
/* 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 is 2, we can't have channel mode = mono */
|
||||
if ((channels == 1 && (strcmp (mode, "mono") != 0)) ||
|
||||
(channels == 2 && (strcmp (mode, "mono") == 0 ||
|
||||
strcmp (mode, "dual") == 0))) {
|
||||
(channels == 2 && (strcmp (mode, "mono") == 0))) {
|
||||
*error_message = g_strdup_printf ("Invalid combination of "
|
||||
"channels (%d) and channel mode (%s)", channels, mode);
|
||||
error = TRUE;
|
||||
|
@ -492,46 +524,15 @@ gst_sbc_util_fill_sbc_params (sbc_t * sbc, GstCaps * caps)
|
|||
if (!(allocation = gst_structure_get_string (structure, "allocation")))
|
||||
return FALSE;
|
||||
|
||||
sbc->rate = rate;
|
||||
sbc->channels = channels;
|
||||
sbc->blocks = blocks;
|
||||
sbc->subbands = subbands;
|
||||
if (channels == 1 && strcmp (mode, "mono") != 0)
|
||||
return FALSE;
|
||||
|
||||
sbc->frequency = gst_sbc_parse_rate_to_sbc (rate);
|
||||
sbc->blocks = gst_sbc_parse_blocks_to_sbc (blocks);
|
||||
sbc->subbands = gst_sbc_parse_subbands_to_sbc (subbands);
|
||||
sbc->bitpool = bitpool;
|
||||
sbc->joint = gst_sbc_get_mode_int_for_sbc_t (mode);
|
||||
sbc->allocation = gst_sbc_get_allocation_mode_int (allocation);
|
||||
sbc->mode = gst_sbc_parse_mode_to_sbc (mode);
|
||||
sbc->allocation = gst_sbc_parse_allocation_to_sbc (allocation);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_util_calc_frame_len (gint subbands, gint channels,
|
||||
gint blocks, gint bitpool, gint channel_mode)
|
||||
{
|
||||
gint len;
|
||||
gint join;
|
||||
len = 4 + (4 * subbands * channels) / 8;
|
||||
|
||||
if (channel_mode == BT_A2DP_CHANNEL_MODE_MONO ||
|
||||
channel_mode == BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL)
|
||||
len += ((blocks * channels * bitpool) + 7) / 8;
|
||||
else {
|
||||
join = channel_mode == BT_A2DP_CHANNEL_MODE_JOINT_STEREO ? 1 : 0;
|
||||
len += ((join * subbands + blocks * bitpool) + 7) / 8;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
gint
|
||||
gst_sbc_util_calc_bitrate (gint frame_len, gint rate, gint subbands,
|
||||
gint blocks)
|
||||
{
|
||||
return (((frame_len * 8 * rate / subbands) / blocks) / 1000);
|
||||
}
|
||||
|
||||
gint64
|
||||
gst_sbc_util_calc_frame_duration (gint rate, gint blocks, gint subbands)
|
||||
{
|
||||
gint64 res = 1000000;
|
||||
return res * blocks * subbands / rate;
|
||||
}
|
||||
|
|
|
@ -24,7 +24,10 @@
|
|||
#include <gst/gst.h>
|
||||
|
||||
#include "sbc.h"
|
||||
#include "ipc.h"
|
||||
#include <string.h>
|
||||
|
||||
#define SBC_AM_AUTO 0x02
|
||||
#define SBC_MODE_AUTO 0x04
|
||||
|
||||
gint gst_sbc_select_rate_from_list(const GValue *value);
|
||||
|
||||
|
@ -39,15 +42,25 @@ gint gst_sbc_select_bitpool_from_range(const GValue *value);
|
|||
gint gst_sbc_select_bitpool_from_range(const GValue *value);
|
||||
|
||||
const gchar *gst_sbc_get_allocation_from_list(const GValue *value);
|
||||
gint gst_sbc_get_allocation_mode_int(const gchar *allocation);
|
||||
const gchar *gst_sbc_get_allocation_string(int alloc);
|
||||
|
||||
const gchar *gst_sbc_get_mode_from_list(const GValue *value, gint channels);
|
||||
gint gst_sbc_get_mode_int(const gchar *mode);
|
||||
gint gst_sbc_get_mode_int_from_sbc_t(const sbc_t *sbc);
|
||||
const gchar *gst_sbc_get_mode_string(int joint);
|
||||
|
||||
GstCaps* gst_sbc_caps_from_sbc(sbc_capabilities_t *sbc, gint channels);
|
||||
gint gst_sbc_get_channel_number(gint mode);
|
||||
gint gst_sbc_parse_rate_from_sbc(gint frequency);
|
||||
gint gst_sbc_parse_rate_to_sbc(gint rate);
|
||||
|
||||
gint gst_sbc_parse_subbands_from_sbc(gint subbands);
|
||||
gint gst_sbc_parse_subbands_to_sbc(gint subbands);
|
||||
|
||||
gint gst_sbc_parse_blocks_from_sbc(gint blocks);
|
||||
gint gst_sbc_parse_blocks_to_sbc(gint blocks);
|
||||
|
||||
const gchar *gst_sbc_parse_mode_from_sbc(gint mode);
|
||||
gint gst_sbc_parse_mode_to_sbc(const gchar *mode);
|
||||
|
||||
const gchar *gst_sbc_parse_allocation_from_sbc(gint alloc);
|
||||
gint gst_sbc_parse_allocation_to_sbc(const gchar *allocation);
|
||||
|
||||
GstCaps* gst_sbc_parse_caps_from_sbc(sbc_t *sbc);
|
||||
|
||||
GstCaps* gst_sbc_util_caps_fixate(GstCaps *caps, gchar** error_message);
|
||||
|
@ -62,10 +75,3 @@ void gst_sbc_util_set_structure_string_param(GstStructure *structure,
|
|||
|
||||
gboolean gst_sbc_util_fill_sbc_params(sbc_t *sbc, GstCaps *caps);
|
||||
|
||||
gint gst_sbc_util_calc_frame_len(gint subbands, gint channels,
|
||||
gint blocks, gint bitpool, gint channel_mode);
|
||||
|
||||
gint gst_sbc_util_calc_bitrate(gint frame_len, gint rate, gint subbands,
|
||||
gint blocks);
|
||||
|
||||
gint64 gst_sbc_util_calc_frame_duration(gint rate, gint blocks, gint subbands);
|
||||
|
|
Loading…
Reference in a new issue