1 /* 2 * 3 * BlueZ - Bluetooth protocol stack for Linux 4 * 5 * Copyright (C) 2006-2010 Nokia Corporation 6 * Copyright (C) 2004-2010 Marcel Holtmann <marcel (at) holtmann.org> 7 * 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 * 23 */ 24 25 #define A2DP_CODEC_SBC 0x00 26 #define A2DP_CODEC_MPEG12 0x01 27 #define A2DP_CODEC_MPEG24 0x02 28 #define A2DP_CODEC_ATRAC 0x03 29 30 #define SBC_SAMPLING_FREQ_16000 (1 << 3) 31 #define SBC_SAMPLING_FREQ_32000 (1 << 2) 32 #define SBC_SAMPLING_FREQ_44100 (1 << 1) 33 #define SBC_SAMPLING_FREQ_48000 1 34 35 #define SBC_CHANNEL_MODE_MONO (1 << 3) 36 #define SBC_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) 37 #define SBC_CHANNEL_MODE_STEREO (1 << 1) 38 #define SBC_CHANNEL_MODE_JOINT_STEREO 1 39 40 #define SBC_BLOCK_LENGTH_4 (1 << 3) 41 #define SBC_BLOCK_LENGTH_8 (1 << 2) 42 #define SBC_BLOCK_LENGTH_12 (1 << 1) 43 #define SBC_BLOCK_LENGTH_16 1 44 45 #define SBC_SUBBANDS_4 (1 << 1) 46 #define SBC_SUBBANDS_8 1 47 48 #define SBC_ALLOCATION_SNR (1 << 1) 49 #define SBC_ALLOCATION_LOUDNESS 1 50 51 #define MPEG_CHANNEL_MODE_MONO (1 << 3) 52 #define MPEG_CHANNEL_MODE_DUAL_CHANNEL (1 << 2) 53 #define MPEG_CHANNEL_MODE_STEREO (1 << 1) 54 #define MPEG_CHANNEL_MODE_JOINT_STEREO 1 55 56 #define MPEG_LAYER_MP1 (1 << 2) 57 #define MPEG_LAYER_MP2 (1 << 1) 58 #define MPEG_LAYER_MP3 1 59 60 #define MPEG_SAMPLING_FREQ_16000 (1 << 5) 61 #define MPEG_SAMPLING_FREQ_22050 (1 << 4) 62 #define MPEG_SAMPLING_FREQ_24000 (1 << 3) 63 #define MPEG_SAMPLING_FREQ_32000 (1 << 2) 64 #define MPEG_SAMPLING_FREQ_44100 (1 << 1) 65 #define MPEG_SAMPLING_FREQ_48000 1 66 67 #define MAX_BITPOOL 64 68 #define MIN_BITPOOL 2 69 70 #if __BYTE_ORDER == __LITTLE_ENDIAN 71 72 struct sbc_codec_cap { 73 struct avdtp_media_codec_capability cap; 74 uint8_t channel_mode:4; 75 uint8_t frequency:4; 76 uint8_t allocation_method:2; 77 uint8_t subbands:2; 78 uint8_t block_length:4; 79 uint8_t min_bitpool; 80 uint8_t max_bitpool; 81 } __attribute__ ((packed)); 82 83 struct mpeg_codec_cap { 84 struct avdtp_media_codec_capability cap; 85 uint8_t channel_mode:4; 86 uint8_t crc:1; 87 uint8_t layer:3; 88 uint8_t frequency:6; 89 uint8_t mpf:1; 90 uint8_t rfa:1; 91 uint16_t bitrate; 92 } __attribute__ ((packed)); 93 94 #elif __BYTE_ORDER == __BIG_ENDIAN 95 96 struct sbc_codec_cap { 97 struct avdtp_media_codec_capability cap; 98 uint8_t frequency:4; 99 uint8_t channel_mode:4; 100 uint8_t block_length:4; 101 uint8_t subbands:2; 102 uint8_t allocation_method:2; 103 uint8_t min_bitpool; 104 uint8_t max_bitpool; 105 } __attribute__ ((packed)); 106 107 struct mpeg_codec_cap { 108 struct avdtp_media_codec_capability cap; 109 uint8_t layer:3; 110 uint8_t crc:1; 111 uint8_t channel_mode:4; 112 uint8_t rfa:1; 113 uint8_t mpf:1; 114 uint8_t frequency:6; 115 uint16_t bitrate; 116 } __attribute__ ((packed)); 117 118 #else 119 #error "Unknown byte order" 120 #endif 121 122 struct a2dp_sep; 123 124 125 typedef void (*a2dp_select_cb_t) (struct avdtp *session, 126 struct a2dp_sep *sep, GSList *caps, 127 void *user_data); 128 typedef void (*a2dp_config_cb_t) (struct avdtp *session, struct a2dp_sep *sep, 129 struct avdtp_stream *stream, 130 struct avdtp_error *err, 131 void *user_data); 132 typedef void (*a2dp_stream_cb_t) (struct avdtp *session, 133 struct avdtp_error *err, 134 void *user_data); 135 136 int a2dp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config); 137 void a2dp_unregister(const bdaddr_t *src); 138 139 struct a2dp_sep *a2dp_add_sep(const bdaddr_t *src, uint8_t type, 140 uint8_t codec, gboolean delay_reporting, 141 struct media_endpoint *endpoint, int *err); 142 void a2dp_remove_sep(struct a2dp_sep *sep); 143 144 struct a2dp_sep *a2dp_get(struct avdtp *session, struct avdtp_remote_sep *sep); 145 146 unsigned int a2dp_select_capabilities(struct avdtp *session, 147 uint8_t type, const char *sender, 148 a2dp_select_cb_t cb, 149 void *user_data); 150 unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep, 151 a2dp_config_cb_t cb, GSList *caps, 152 void *user_data); 153 unsigned int a2dp_resume(struct avdtp *session, struct a2dp_sep *sep, 154 a2dp_stream_cb_t cb, void *user_data); 155 unsigned int a2dp_suspend(struct avdtp *session, struct a2dp_sep *sep, 156 a2dp_stream_cb_t cb, void *user_data); 157 gboolean a2dp_cancel(struct audio_device *dev, unsigned int id); 158 159 gboolean a2dp_sep_lock(struct a2dp_sep *sep, struct avdtp *session); 160 gboolean a2dp_sep_unlock(struct a2dp_sep *sep, struct avdtp *session); 161 gboolean a2dp_sep_get_lock(struct a2dp_sep *sep); 162 struct avdtp_stream *a2dp_sep_get_stream(struct a2dp_sep *sep); 163 struct a2dp_sep *a2dp_get_sep(struct avdtp *session, 164 struct avdtp_stream *stream); 165