bluetooth: Pull a2dp-codecs.h from BlueZ
authorArun Raghavan <arun.raghavan@collabora.co.uk>
Wed, 30 Mar 2011 19:26:20 +0000 (00:56 +0530)
committerColin Guthrie <colin@mageia.org>
Thu, 31 Mar 2011 10:04:39 +0000 (11:04 +0100)
This pulls a2dp-codecs.h from BlueZ which contains the capabilities
structures for SBC and MPEG. We currently have these manually added to
ipc.h, so pulling this header makes our files identical to upstream.

src/Makefile.am
src/modules/bluetooth/a2dp-codecs.h [new file with mode: 0644]
src/modules/bluetooth/bluetooth-util.c
src/modules/bluetooth/ipc.h
src/modules/bluetooth/module-bluetooth-device.c

index f3717ce..3bec5e8 100644 (file)
@@ -1847,7 +1847,9 @@ libbluetooth_sbc_la_LIBADD = $(MODULE_LIBADD)
 libbluetooth_sbc_la_CFLAGS = $(AM_CFLAGS) -I$(top_srcdir)/src/modules/bluetooth/sbc
 BLUETOOTH_SBC_FILES = $(subst modules/bluetooth/,,$(libbluetooth_sbc_la_SOURCES))
 
-libbluetooth_ipc_la_SOURCES = modules/bluetooth/ipc.c modules/bluetooth/ipc.h
+libbluetooth_ipc_la_SOURCES = \
+               modules/bluetooth/a2dp-codecs.h \
+               modules/bluetooth/ipc.c modules/bluetooth/ipc.h
 libbluetooth_ipc_la_LDFLAGS = -avoid-version
 libbluetooth_ipc_la_LIBADD = $(AM_LIBADD) libpulsecore-@PA_MAJORMINOR@.la libpulsecommon-@PA_MAJORMINOR@.la libpulse.la
 libbluetooth_ipc_la_CFLAGS = $(AM_CFLAGS)
diff --git a/src/modules/bluetooth/a2dp-codecs.h b/src/modules/bluetooth/a2dp-codecs.h
new file mode 100644 (file)
index 0000000..e44634e
--- /dev/null
@@ -0,0 +1,116 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2006-2010  Nokia Corporation
+ *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#define A2DP_CODEC_SBC                 0x00
+#define A2DP_CODEC_MPEG12              0x01
+#define A2DP_CODEC_MPEG24              0x02
+#define A2DP_CODEC_ATRAC               0x03
+
+#define SBC_SAMPLING_FREQ_16000                (1 << 3)
+#define SBC_SAMPLING_FREQ_32000                (1 << 2)
+#define SBC_SAMPLING_FREQ_44100                (1 << 1)
+#define SBC_SAMPLING_FREQ_48000                1
+
+#define SBC_CHANNEL_MODE_MONO          (1 << 3)
+#define SBC_CHANNEL_MODE_DUAL_CHANNEL  (1 << 2)
+#define SBC_CHANNEL_MODE_STEREO                (1 << 1)
+#define SBC_CHANNEL_MODE_JOINT_STEREO  1
+
+#define SBC_BLOCK_LENGTH_4             (1 << 3)
+#define SBC_BLOCK_LENGTH_8             (1 << 2)
+#define SBC_BLOCK_LENGTH_12            (1 << 1)
+#define SBC_BLOCK_LENGTH_16            1
+
+#define SBC_SUBBANDS_4                 (1 << 1)
+#define SBC_SUBBANDS_8                 1
+
+#define SBC_ALLOCATION_SNR             (1 << 1)
+#define SBC_ALLOCATION_LOUDNESS                1
+
+#define MPEG_CHANNEL_MODE_MONO         (1 << 3)
+#define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2)
+#define MPEG_CHANNEL_MODE_STEREO       (1 << 1)
+#define MPEG_CHANNEL_MODE_JOINT_STEREO 1
+
+#define MPEG_LAYER_MP1                 (1 << 2)
+#define MPEG_LAYER_MP2                 (1 << 1)
+#define MPEG_LAYER_MP3                 1
+
+#define MPEG_SAMPLING_FREQ_16000       (1 << 5)
+#define MPEG_SAMPLING_FREQ_22050       (1 << 4)
+#define MPEG_SAMPLING_FREQ_24000       (1 << 3)
+#define MPEG_SAMPLING_FREQ_32000       (1 << 2)
+#define MPEG_SAMPLING_FREQ_44100       (1 << 1)
+#define MPEG_SAMPLING_FREQ_48000       1
+
+#define MAX_BITPOOL 64
+#define MIN_BITPOOL 2
+
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+
+typedef struct {
+       uint8_t channel_mode:4;
+       uint8_t frequency:4;
+       uint8_t allocation_method:2;
+       uint8_t subbands:2;
+       uint8_t block_length:4;
+       uint8_t min_bitpool;
+       uint8_t max_bitpool;
+} __attribute__ ((packed)) a2dp_sbc_t;
+
+typedef struct {
+       uint8_t channel_mode:4;
+       uint8_t crc:1;
+       uint8_t layer:3;
+       uint8_t frequency:6;
+       uint8_t mpf:1;
+       uint8_t rfa:1;
+       uint16_t bitrate;
+} __attribute__ ((packed)) a2dp_mpeg_t;
+
+#elif __BYTE_ORDER == __BIG_ENDIAN
+
+typedef struct {
+       uint8_t frequency:4;
+       uint8_t channel_mode:4;
+       uint8_t block_length:4;
+       uint8_t subbands:2;
+       uint8_t allocation_method:2;
+       uint8_t min_bitpool;
+       uint8_t max_bitpool;
+} __attribute__ ((packed)) a2dp_sbc_t;
+
+typedef struct {
+       uint8_t layer:3;
+       uint8_t crc:1;
+       uint8_t channel_mode:4;
+       uint8_t rfa:1;
+       uint8_t mpf:1;
+       uint8_t frequency:6;
+       uint16_t bitrate;
+} __attribute__ ((packed)) a2dp_mpeg_t;
+
+#else
+#error "Unknown byte order"
+#endif
index 5d388ce..740b317 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "bluetooth-util.h"
 #include "ipc.h"
+#include "a2dp-codecs.h"
 
 #define HFP_AG_ENDPOINT "/MediaEndpoint/HFPAG"
 #define A2DP_SOURCE_ENDPOINT "/MediaEndpoint/A2DPSource"
@@ -58,9 +59,6 @@
     " </interface>"                                                     \
     "</node>"
 
-#define MAX_BITPOOL 64
-#define MIN_BITPOOL 2U
-
 struct pa_bluetooth_discovery {
     PA_REFCNT_DECLARE;
 
@@ -636,7 +634,7 @@ static void register_endpoint(pa_bluetooth_discovery *y, const char *path, const
         uint8_t *caps = &capability;
         pa_dbus_append_basic_array_variant_dict_entry(&d, "Capabilities", DBUS_TYPE_BYTE, &caps, 1);
     } else {
-        sbc_capabilities_raw_t capabilities;
+        a2dp_sbc_t capabilities;
         uint8_t *caps = (uint8_t *) &capabilities;
 
         capabilities.channel_mode = BT_A2DP_CHANNEL_MODE_MONO | BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL |
@@ -1277,7 +1275,7 @@ static uint8_t a2dp_default_bitpool(uint8_t freq, uint8_t mode) {
 
 static DBusMessage *endpoint_select_configuration(DBusConnection *c, DBusMessage *m, void *userdata) {
     pa_bluetooth_discovery *y = userdata;
-    sbc_capabilities_raw_t *cap, config;
+    a2dp_sbc_t *cap, config;
     uint8_t *pconf = (uint8_t *) &config;
     int i, size;
     DBusMessage *r;
index 4547168..d69b97e 100644 (file)
@@ -202,34 +202,6 @@ typedef struct {
        uint8_t max_bitpool;
 } __attribute__ ((packed)) sbc_capabilities_t;
 
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-
-typedef struct {
-       uint8_t channel_mode:4;
-       uint8_t frequency:4;
-       uint8_t allocation_method:2;
-       uint8_t subbands:2;
-       uint8_t block_length:4;
-       uint8_t min_bitpool;
-       uint8_t max_bitpool;
-} __attribute__ ((packed)) sbc_capabilities_raw_t;
-
-#elif __BYTE_ORDER == __BIG_ENDIAN
-
-typedef struct {
-       uint8_t frequency:4;
-       uint8_t channel_mode:4;
-       uint8_t block_length:4;
-       uint8_t subbands:2;
-       uint8_t allocation_method:2;
-       uint8_t min_bitpool;
-       uint8_t max_bitpool;
-} __attribute__ ((packed)) sbc_capabilities_raw_t;
-
-#else
-#error "Unknown byte order"
-#endif
-
 typedef struct {
        codec_capabilities_t capability;
        uint8_t channel_mode;
index ac0f16f..b132d42 100644 (file)
 #include "module-bluetooth-device-symdef.h"
 #include "ipc.h"
 #include "sbc.h"
+#include "a2dp-codecs.h"
 #include "rtp.h"
 #include "bluetooth-util.h"
 
-#define MAX_BITPOOL 64
-#define MIN_BITPOOL 2U
-
 #define BITPOOL_DEC_LIMIT 32
 #define BITPOOL_DEC_STEP 5
 
@@ -2112,12 +2110,12 @@ static void shutdown_bt(struct userdata *u) {
 static int bt_transport_config_a2dp(struct userdata *u) {
     const pa_bluetooth_transport *t;
     struct a2dp_info *a2dp = &u->a2dp;
-    sbc_capabilities_raw_t *config;
+    a2dp_sbc_t *config;
 
     t = pa_bluetooth_discovery_get_transport(u->discovery, u->transport);
     pa_assert(t);
 
-    config = (sbc_capabilities_raw_t *) t->config;
+    config = (a2dp_sbc_t *) t->config;
 
     if (a2dp->sbc_initialized)
         sbc_reinit(&a2dp->sbc, 0);