Home | History | Annotate | Download | only in audio
      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 typedef void (*a2dp_config_cb_t) (struct avdtp *session, struct a2dp_sep *sep,
    125 					struct avdtp_stream *stream,
    126 					struct avdtp_error *err,
    127 					void *user_data);
    128 typedef void (*a2dp_stream_cb_t) (struct avdtp *session,
    129 					struct avdtp_error *err,
    130 					void *user_data);
    131 
    132 int a2dp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config);
    133 void a2dp_unregister(const bdaddr_t *src);
    134 
    135 struct a2dp_sep *a2dp_get(struct avdtp *session, struct avdtp_remote_sep *sep);
    136 unsigned int a2dp_config(struct avdtp *session, struct a2dp_sep *sep,
    137 				a2dp_config_cb_t cb, GSList *caps,
    138 				void *user_data);
    139 unsigned int a2dp_resume(struct avdtp *session, struct a2dp_sep *sep,
    140 				a2dp_stream_cb_t cb, void *user_data);
    141 unsigned int a2dp_suspend(struct avdtp *session, struct a2dp_sep *sep,
    142 				a2dp_stream_cb_t cb, void *user_data);
    143 gboolean a2dp_cancel(struct audio_device *dev, unsigned int id);
    144 
    145 gboolean a2dp_sep_lock(struct a2dp_sep *sep, struct avdtp *session);
    146 gboolean a2dp_sep_unlock(struct a2dp_sep *sep, struct avdtp *session);
    147 gboolean a2dp_sep_get_lock(struct a2dp_sep *sep);
    148 struct a2dp_sep *a2dp_get_sep(struct avdtp *session,
    149 				struct avdtp_stream *stream);
    150