From 18e975fc5ef68a89875c77974570884b9214a009 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 20 Jul 2009 17:34:17 +0200 Subject: merged --- src/modules/bluetooth/sbc.c | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) (limited to 'src/modules/bluetooth/sbc.c') diff --git a/src/modules/bluetooth/sbc.c b/src/modules/bluetooth/sbc.c index 6fa54796..779be4bd 100644 --- a/src/modules/bluetooth/sbc.c +++ b/src/modules/bluetooth/sbc.c @@ -973,13 +973,13 @@ int sbc_init(sbc_t *sbc, unsigned long flags) return 0; } -int sbc_parse(sbc_t *sbc, void *input, int input_len) +ssize_t sbc_parse(sbc_t *sbc, const void *input, size_t input_len) { return sbc_decode(sbc, input, input_len, NULL, 0, NULL); } -int sbc_decode(sbc_t *sbc, void *input, int input_len, void *output, - int output_len, int *written) +ssize_t sbc_decode(sbc_t *sbc, const void *input, size_t input_len, + void *output, size_t output_len, size_t *written) { struct sbc_priv *priv; char *ptr; @@ -1004,7 +1004,7 @@ int sbc_decode(sbc_t *sbc, void *input, int input_len, void *output, sbc->bitpool = priv->frame.bitpool; priv->frame.codesize = sbc_get_codesize(sbc); - priv->frame.length = sbc_get_frame_length(sbc); + priv->frame.length = framelen; } if (!output) @@ -1020,7 +1020,7 @@ int sbc_decode(sbc_t *sbc, void *input, int input_len, void *output, ptr = output; - if (output_len < samples * priv->frame.channels * 2) + if (output_len < (size_t) (samples * priv->frame.channels * 2)) samples = output_len / (priv->frame.channels * 2); for (i = 0; i < samples; i++) { @@ -1044,10 +1044,8 @@ int sbc_decode(sbc_t *sbc, void *input, int input_len, void *output, return framelen; } -ssize_t sbc_encode(sbc_t *sbc, - const void *input, size_t input_len, - void *output, size_t output_len, - size_t *written) +ssize_t sbc_encode(sbc_t *sbc, const void *input, size_t input_len, + void *output, size_t output_len, size_t *written) { struct sbc_priv *priv; int framelen, samples; @@ -1138,30 +1136,25 @@ void sbc_finish(sbc_t *sbc) size_t sbc_get_frame_length(sbc_t *sbc) { size_t ret; - uint8_t subbands, channels, blocks, joint; + uint8_t subbands, channels, blocks, joint, bitpool; struct sbc_priv *priv; priv = sbc->priv; - if (!priv->init) { - subbands = sbc->subbands ? 8 : 4; - blocks = 4 + (sbc->blocks * 4); - channels = sbc->mode == SBC_MODE_MONO ? 1 : 2; - joint = sbc->mode == SBC_MODE_JOINT_STEREO ? 1 : 0; - } else { - subbands = priv->frame.subbands; - blocks = priv->frame.blocks; - channels = priv->frame.channels; - joint = priv->frame.joint; - } + if (priv->init) + return priv->frame.length; - ret = 4 + (4 * subbands * channels) / 8; + subbands = sbc->subbands ? 8 : 4; + blocks = 4 + (sbc->blocks * 4); + channels = sbc->mode == SBC_MODE_MONO ? 1 : 2; + joint = sbc->mode == SBC_MODE_JOINT_STEREO ? 1 : 0; + bitpool = sbc->bitpool; + ret = 4 + (4 * subbands * channels) / 8; /* This term is not always evenly divide so we round it up */ if (channels == 1) - ret += ((blocks * channels * sbc->bitpool) + 7) / 8; + ret += ((blocks * channels * bitpool) + 7) / 8; else - ret += (((joint ? subbands : 0) + blocks * sbc->bitpool) + 7) - / 8; + ret += (((joint ? subbands : 0) + blocks * bitpool) + 7) / 8; return ret; } -- cgit