Merge commit 'vudentz/master'

This commit is contained in:
Lennart Poettering 2008-12-23 18:31:12 +01:00
commit f24e4c19c3
4 changed files with 219 additions and 174 deletions

View file

@ -1381,12 +1381,12 @@ libbluetooth_sbc_la_CFLAGS = $(AM_CFLAGS)
libbluetooth_ipc_la_SOURCES = modules/bluetooth/ipc.c modules/bluetooth/ipc.h libbluetooth_ipc_la_SOURCES = modules/bluetooth/ipc.c modules/bluetooth/ipc.h
libbluetooth_ipc_la_LDFLAGS = -avoid-version libbluetooth_ipc_la_LDFLAGS = -avoid-version
libbluetooth_ipc_la_LIBADD = $(AM_LIBADD)libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la libbluetooth_ipc_la_LIBADD = $(AM_LIBADD)libpulsecore-@PA_MAJORMINORMICRO@.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
libbluetooth_ipc_la_CFLAGS = $(AM_CFLAGS) libbluetooth_ipc_la_CFLAGS = $(AM_CFLAGS) -w
module_bluetooth_device_la_SOURCES = modules/bluetooth/module-bluetooth-device.c modules/bluetooth/rtp.h module_bluetooth_device_la_SOURCES = modules/bluetooth/module-bluetooth-device.c modules/bluetooth/rtp.h
module_bluetooth_device_la_LDFLAGS = -module -avoid-version module_bluetooth_device_la_LDFLAGS = -module -avoid-version
module_bluetooth_device_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libdbus-util.la libbluetooth-ipc.la libbluetooth-sbc.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la module_bluetooth_device_la_LIBADD = $(AM_LIBADD) $(DBUS_LIBS) libpulsecore-@PA_MAJORMINORMICRO@.la libdbus-util.la libbluetooth-ipc.la libbluetooth-sbc.la libpulsecommon-@PA_MAJORMINORMICRO@.la libpulse.la
module_bluetooth_device_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) module_bluetooth_device_la_CFLAGS = $(AM_CFLAGS) $(DBUS_CFLAGS) -w
# Apple Airtunes/RAOP # Apple Airtunes/RAOP
module_raop_sink_la_SOURCES = modules/module-raop-sink.c module_raop_sink_la_SOURCES = modules/module-raop-sink.c

View file

@ -22,22 +22,26 @@
#include "ipc.h" #include "ipc.h"
/* This table contains the string representation for messages */ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
static const char *strmsg[] = {
"BT_GETCAPABILITIES_REQ", /* This table contains the string representation for messages types */
"BT_GETCAPABILITIES_RSP", static const char *strtypes[] = {
"BT_SETCONFIGURATION_REQ", "BT_REQUEST",
"BT_SETCONFIGURATION_RSP", "BT_RESPONSE",
"BT_STREAMSTART_REQ", "BT_INDICATION",
"BT_STREAMSTART_RSP", "BT_ERROR",
"BT_STREAMSTOP_REQ", };
"BT_STREAMSTOP_RSP",
"BT_STREAMSUSPEND_IND", /* This table contains the string representation for messages names */
"BT_STREAMRESUME_IND", static const char *strnames[] = {
"BT_CONTROL_REQ", "BT_GET_CAPABILITIES",
"BT_CONTROL_RSP", "BT_SET_CONFIGURATION",
"BT_CONTROL_IND", "BT_NEW_STREAM",
"BT_STREAMFD_IND", "BT_START_STREAM",
"BT_STOP_STREAM",
"BT_SUSPEND_STREAM",
"BT_RESUME_STREAM",
"BT_CONTROL",
}; };
int bt_audio_service_open(void) int bt_audio_service_open(void)
@ -88,7 +92,7 @@ int bt_audio_service_get_data_fd(int sk)
msgh.msg_control = &cmsg_b; msgh.msg_control = &cmsg_b;
msgh.msg_controllen = CMSG_LEN(sizeof(int)); msgh.msg_controllen = CMSG_LEN(sizeof(int));
ret = (int) recvmsg(sk, &msgh, 0); ret = recvmsg(sk, &msgh, 0);
if (ret < 0) { if (ret < 0) {
err = errno; err = errno;
fprintf(stderr, "%s: Unable to receive fd: %s (%d)\n", fprintf(stderr, "%s: Unable to receive fd: %s (%d)\n",
@ -109,10 +113,18 @@ int bt_audio_service_get_data_fd(int sk)
return -1; return -1;
} }
const char *bt_audio_strmsg(int type) const char *bt_audio_strtype(uint8_t type)
{ {
if (type < 0 || (size_t) type > (sizeof(strmsg) / sizeof(strmsg[0]))) if (type >= ARRAY_SIZE(strtypes))
return NULL; return NULL;
return strmsg[type]; return strtypes[type];
}
const char *bt_audio_strname(uint8_t name)
{
if (name >= ARRAY_SIZE(strnames))
return NULL;
return strnames[name];
} }

View file

@ -25,32 +25,32 @@
Audio daemon User Audio daemon User
on snd_pcm_open on snd_pcm_open
<--BT_GETCAPABILITIES_REQ <--BT_GET_CAPABILITIES_REQ
BT_GETCAPABILITIES_RSP--> BT_GET_CAPABILITIES_RSP-->
on snd_pcm_hw_params on snd_pcm_hw_params
<--BT_SETCONFIGURATION_REQ <--BT_SETCONFIGURATION_REQ
BT_SETCONFIGURATION_RSP--> BT_SET_CONFIGURATION_RSP-->
on snd_pcm_prepare on snd_pcm_prepare
<--BT_STREAMSTART_REQ <--BT_START_STREAM_REQ
<Moves to streaming state> <Moves to streaming state>
BT_STREAMSTART_RSP--> BT_START_STREAM_RSP-->
BT_STREAMFD_IND --> BT_NEW_STREAM_IND -->
< streams data > < streams data >
.......... ..........
on snd_pcm_drop/snd_pcm_drain on snd_pcm_drop/snd_pcm_drain
<--BT_STREAMSTOP_REQ <--BT_STOP_STREAM_REQ
<Moves to open state> <Moves to open state>
BT_STREAMSTOP_RSP--> BT_STOP_STREAM_RSP-->
on IPC close or appl crash on IPC close or appl crash
<Moves to idle> <Moves to idle>
@ -71,43 +71,36 @@ extern "C" {
#include <sys/un.h> #include <sys/un.h>
#include <errno.h> #include <errno.h>
#define BT_AUDIO_IPC_PACKET_SIZE 128 #define BT_SUGGESTED_BUFFER_SIZE 128
#define BT_IPC_SOCKET_NAME "\0/org/bluez/audio" #define BT_IPC_SOCKET_NAME "\0/org/bluez/audio"
/* Generic message header definition, except for RSP messages */ /* Generic message header definition, except for RESPONSE messages */
typedef struct { typedef struct {
uint8_t msg_type; uint8_t type;
uint8_t name;
uint16_t length;
} __attribute__ ((packed)) bt_audio_msg_header_t; } __attribute__ ((packed)) bt_audio_msg_header_t;
/* Generic message header definition, for all RSP messages */
typedef struct { typedef struct {
bt_audio_msg_header_t msg_h; bt_audio_msg_header_t h;
uint8_t posix_errno; uint8_t posix_errno;
} __attribute__ ((packed)) bt_audio_rsp_msg_header_t; } __attribute__ ((packed)) bt_audio_error_t;
/* Messages list */ /* Message types */
#define BT_GETCAPABILITIES_REQ 0 #define BT_REQUEST 0
#define BT_GETCAPABILITIES_RSP 1 #define BT_RESPONSE 1
#define BT_INDICATION 2
#define BT_ERROR 3
#define BT_SETCONFIGURATION_REQ 2 /* Messages names */
#define BT_SETCONFIGURATION_RSP 3 #define BT_GET_CAPABILITIES 0
#define BT_SET_CONFIGURATION 1
#define BT_STREAMSTART_REQ 4 #define BT_NEW_STREAM 2
#define BT_STREAMSTART_RSP 5 #define BT_START_STREAM 3
#define BT_STOP_STREAM 4
#define BT_STREAMSTOP_REQ 6 #define BT_SUSPEND_STREAM 5
#define BT_STREAMSTOP_RSP 7 #define BT_RESUME_STREAM 6
#define BT_CONTROL 7
#define BT_STREAMSUSPEND_IND 8
#define BT_STREAMRESUME_IND 9
#define BT_CONTROL_REQ 10
#define BT_CONTROL_RSP 11
#define BT_CONTROL_IND 12
#define BT_STREAMFD_IND 13
/* BT_GETCAPABILITIES_REQ */
#define BT_CAPABILITIES_TRANSPORT_A2DP 0 #define BT_CAPABILITIES_TRANSPORT_A2DP 0
#define BT_CAPABILITIES_TRANSPORT_SCO 1 #define BT_CAPABILITIES_TRANSPORT_SCO 1
@ -119,19 +112,22 @@ typedef struct {
#define BT_FLAG_AUTOCONNECT 1 #define BT_FLAG_AUTOCONNECT 1
struct bt_getcapabilities_req { struct bt_get_capabilities_req {
bt_audio_msg_header_t h; bt_audio_msg_header_t h;
char device[18]; /* Address of the remote Device */ char device[18]; /* Address of the remote Device */
uint8_t transport; /* Requested transport */ uint8_t transport; /* Requested transport */
uint8_t flags; /* Requested flags */ uint8_t flags; /* Requested flags */
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_GETCAPABILITIES_RSP */
/** /**
* SBC Codec parameters as per A2DP profile 1.0 § 4.3 * SBC Codec parameters as per A2DP profile 1.0 § 4.3
*/ */
#define BT_A2DP_CODEC_SBC 0x00
#define BT_A2DP_CODEC_MPEG12 0x01
#define BT_A2DP_CODEC_MPEG24 0x02
#define BT_A2DP_CODEC_ATRAC 0x03
#define BT_SBC_SAMPLING_FREQ_16000 (1 << 3) #define BT_SBC_SAMPLING_FREQ_16000 (1 << 3)
#define BT_SBC_SAMPLING_FREQ_32000 (1 << 2) #define BT_SBC_SAMPLING_FREQ_32000 (1 << 2)
#define BT_SBC_SAMPLING_FREQ_44100 (1 << 1) #define BT_SBC_SAMPLING_FREQ_44100 (1 << 1)
@ -164,7 +160,19 @@ struct bt_getcapabilities_req {
#define BT_MPEG_LAYER_2 (1 << 1) #define BT_MPEG_LAYER_2 (1 << 1)
#define BT_MPEG_LAYER_3 1 #define BT_MPEG_LAYER_3 1
#define BT_HFP_CODEC_PCM 0x00
#define BT_PCM_FLAG_NREC 1
typedef struct { typedef struct {
uint8_t transport;
uint8_t type;
uint8_t length;
uint8_t data[0];
} __attribute__ ((packed)) codec_capabilities_t;
typedef struct {
codec_capabilities_t capability;
uint8_t channel_mode; uint8_t channel_mode;
uint8_t frequency; uint8_t frequency;
uint8_t allocation_method; uint8_t allocation_method;
@ -175,6 +183,7 @@ typedef struct {
} __attribute__ ((packed)) sbc_capabilities_t; } __attribute__ ((packed)) sbc_capabilities_t;
typedef struct { typedef struct {
codec_capabilities_t capability;
uint8_t channel_mode; uint8_t channel_mode;
uint8_t crc; uint8_t crc;
uint8_t layer; uint8_t layer;
@ -183,74 +192,64 @@ typedef struct {
uint16_t bitrate; uint16_t bitrate;
} __attribute__ ((packed)) mpeg_capabilities_t; } __attribute__ ((packed)) mpeg_capabilities_t;
struct bt_getcapabilities_rsp { typedef struct {
bt_audio_rsp_msg_header_t rsp_h; codec_capabilities_t capability;
uint8_t transport; /* Granted transport */ uint8_t flags;
sbc_capabilities_t sbc_capabilities; /* A2DP only */ uint16_t sampling_rate;
mpeg_capabilities_t mpeg_capabilities; /* A2DP only */ } __attribute__ ((packed)) pcm_capabilities_t;
uint16_t sampling_rate; /* SCO only */
struct bt_get_capabilities_rsp {
bt_audio_msg_header_t h;
uint8_t data[0]; /* First codec_capabilities_t */
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_SETCONFIGURATION_REQ */ struct bt_set_configuration_req {
struct bt_setconfiguration_req {
bt_audio_msg_header_t h; bt_audio_msg_header_t h;
char device[18]; /* Address of the remote Device */ char device[18]; /* Address of the remote Device */
uint8_t transport; /* Requested transport */
uint8_t access_mode; /* Requested access mode */ uint8_t access_mode; /* Requested access mode */
sbc_capabilities_t sbc_capabilities; /* A2DP only - only one of this field codec_capabilities_t codec; /* Requested codec */
and next one must be filled */
mpeg_capabilities_t mpeg_capabilities; /* A2DP only */
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_SETCONFIGURATION_RSP */ struct bt_set_configuration_rsp {
struct bt_setconfiguration_rsp { bt_audio_msg_header_t h;
bt_audio_rsp_msg_header_t rsp_h;
uint8_t transport; /* Granted transport */ uint8_t transport; /* Granted transport */
uint8_t access_mode; /* Granted access mode */ uint8_t access_mode; /* Granted access mode */
uint16_t link_mtu; /* Max length that transport supports */ uint16_t link_mtu; /* Max length that transport supports */
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_STREAMSTART_REQ */
#define BT_STREAM_ACCESS_READ 0 #define BT_STREAM_ACCESS_READ 0
#define BT_STREAM_ACCESS_WRITE 1 #define BT_STREAM_ACCESS_WRITE 1
#define BT_STREAM_ACCESS_READWRITE 2 #define BT_STREAM_ACCESS_READWRITE 2
struct bt_streamstart_req { struct bt_start_stream_req {
bt_audio_msg_header_t h; bt_audio_msg_header_t h;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_STREAMSTART_RSP */ struct bt_start_stream_rsp {
struct bt_streamstart_rsp { bt_audio_msg_header_t h;
bt_audio_rsp_msg_header_t rsp_h;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_STREAMFD_IND */
/* This message is followed by one byte of data containing the stream data fd /* This message is followed by one byte of data containing the stream data fd
as ancilliary data */ as ancilliary data */
struct bt_streamfd_ind { struct bt_new_stream_ind {
bt_audio_msg_header_t h; bt_audio_msg_header_t h;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_STREAMSTOP_REQ */ struct bt_stop_stream_req {
struct bt_streamstop_req {
bt_audio_msg_header_t h; bt_audio_msg_header_t h;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_STREAMSTOP_RSP */ struct bt_stop_stream_rsp {
struct bt_streamstop_rsp {
bt_audio_rsp_msg_header_t rsp_h;
} __attribute__ ((packed));
/* BT_STREAMSUSPEND_IND */
struct bt_streamsuspend_ind {
bt_audio_msg_header_t h; bt_audio_msg_header_t h;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_STREAMRESUME_IND */ struct bt_suspend_stream_ind {
struct bt_streamresume_ind {
bt_audio_msg_header_t h; bt_audio_msg_header_t h;
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_CONTROL_REQ */ struct bt_resume_stream_ind {
bt_audio_msg_header_t h;
} __attribute__ ((packed));
#define BT_CONTROL_KEY_POWER 0x40 #define BT_CONTROL_KEY_POWER 0x40
#define BT_CONTROL_KEY_VOL_UP 0x41 #define BT_CONTROL_KEY_VOL_UP 0x41
@ -272,14 +271,12 @@ struct bt_control_req {
uint8_t key; /* Control Key */ uint8_t key; /* Control Key */
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_CONTROL_RSP */
struct bt_control_rsp { struct bt_control_rsp {
bt_audio_rsp_msg_header_t rsp_h; bt_audio_msg_header_t h;
uint8_t mode; /* Control Mode */ uint8_t mode; /* Control Mode */
uint8_t key; /* Control Key */ uint8_t key; /* Control Key */
} __attribute__ ((packed)); } __attribute__ ((packed));
/* BT_CONTROL_IND */
struct bt_control_ind { struct bt_control_ind {
bt_audio_msg_header_t h; bt_audio_msg_header_t h;
uint8_t mode; /* Control Mode */ uint8_t mode; /* Control Mode */
@ -299,7 +296,10 @@ BT_STREAMFD_IND message is returned */
int bt_audio_service_get_data_fd(int sk); int bt_audio_service_get_data_fd(int sk);
/* Human readable message type string */ /* Human readable message type string */
const char *bt_audio_strmsg(int type); const char *bt_audio_strtype(uint8_t type);
/* Human readable message name string */
const char *bt_audio_strname(uint8_t name);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -122,8 +122,12 @@ static const char* const valid_modargs[] = {
static int bt_audioservice_send(int sk, const bt_audio_msg_header_t *msg) { static int bt_audioservice_send(int sk, const bt_audio_msg_header_t *msg) {
int e; int e;
pa_log_debug("sending %s", bt_audio_strmsg(msg->msg_type)); const char *type, *name;
if (send(sk, msg, BT_AUDIO_IPC_PACKET_SIZE, 0) > 0)
type = bt_audio_strtype(msg->type);
name = bt_audio_strname(msg->name);
pa_log_debug("sending: %s -> %s", type, name);
if (send(sk, msg, BT_SUGGESTED_BUFFER_SIZE, 0) > 0)
e = 0; e = 0;
else { else {
e = -errno; e = -errno;
@ -132,20 +136,22 @@ static int bt_audioservice_send(int sk, const bt_audio_msg_header_t *msg) {
return e; return e;
} }
static int bt_audioservice_recv(int sk, bt_audio_msg_header_t *inmsg) { static int bt_audioservice_recv(int sk, bt_audio_msg_header_t *inmsg, uint16_t expected_length) {
int e; int e;
const char *type; const char *type, *name;
pa_log_debug("trying to receive msg from audio service..."); pa_log_debug("trying to receive msg from audio service...");
if (recv(sk, inmsg, BT_AUDIO_IPC_PACKET_SIZE, 0) > 0) { if (recv(sk, inmsg, expected_length ? : BT_SUGGESTED_BUFFER_SIZE, 0) > 0) {
type = bt_audio_strmsg(inmsg->msg_type); type = bt_audio_strtype(inmsg->type);
if (type) { name = bt_audio_strname(inmsg->name);
pa_log_debug("Received %s", type); if (type && name) {
pa_log_debug("Received: %s <- %s", type, name);
e = 0; e = 0;
} }
else { else {
e = -EINVAL; e = -EINVAL;
pa_log_error("Bogus message type %d received from audio service", inmsg->msg_type); pa_log_error("Bogus message type %d name %d received from audio service",
inmsg->type, inmsg->name);
} }
} }
else { else {
@ -156,29 +162,66 @@ static int bt_audioservice_recv(int sk, bt_audio_msg_header_t *inmsg) {
return e; return e;
} }
static int bt_audioservice_expect(int sk, bt_audio_msg_header_t *rsp_hdr, int expected_type) { static int bt_audioservice_expect(int sk, bt_audio_msg_header_t *rsp, uint8_t expected_name, uint16_t expected_length) {
int e = bt_audioservice_recv(sk, rsp_hdr); int e = bt_audioservice_recv(sk, rsp, expected_length);
if (e == 0) {
if (rsp_hdr->msg_type != expected_type) { if (e < 0) {
if (rsp->name != expected_name) {
e = -EINVAL; e = -EINVAL;
pa_log_error("Bogus message %s received while %s was expected", bt_audio_strmsg(rsp_hdr->msg_type), pa_log_error("Bogus message %s received while %s was expected",
bt_audio_strmsg(expected_type)); bt_audio_strname(rsp->name),
bt_audio_strname(expected_name));
} }
} }
if (rsp->type == BT_ERROR) {
bt_audio_error_t *error = (void *) rsp;
pa_log_error("%s failed : %s(%d)", bt_audio_strname(rsp->name), pa_cstrerror(error->posix_errno), error->posix_errno);
return -error->posix_errno;
}
return e; return e;
} }
static int bt_parsecaps(struct userdata *u, struct bt_get_capabilities_rsp *rsp) {
uint16_t bytes_left = rsp->h.length - sizeof(*rsp);
codec_capabilities_t *codec = (void *) rsp->data;
u->transport = codec->transport;
if (codec->transport != BT_CAPABILITIES_TRANSPORT_A2DP)
return 0;
while (bytes_left > 0) {
if (codec->type == BT_A2DP_CODEC_SBC)
break;
bytes_left -= codec->length;
codec = (void *) (codec + codec->length);
}
if (bytes_left <= 0 || codec->length != sizeof(u->a2dp.sbc_capabilities))
return -EINVAL;
memcpy(&u->a2dp.sbc_capabilities, codec, codec->length);
return 0;
}
static int bt_getcaps(struct userdata *u) { static int bt_getcaps(struct userdata *u) {
int e; int e;
union { union {
bt_audio_rsp_msg_header_t rsp_hdr; bt_audio_msg_header_t rsp;
struct bt_getcapabilities_req getcaps_req; struct bt_get_capabilities_req getcaps_req;
struct bt_getcapabilities_rsp getcaps_rsp; struct bt_get_capabilities_rsp getcaps_rsp;
uint8_t buf[BT_AUDIO_IPC_PACKET_SIZE]; uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
} msg; } msg;
memset(msg.buf, 0, BT_AUDIO_IPC_PACKET_SIZE); memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
msg.getcaps_req.h.msg_type = BT_GETCAPABILITIES_REQ; msg.getcaps_req.h.type = BT_REQUEST;
msg.getcaps_req.h.name = BT_GET_CAPABILITIES;
msg.getcaps_req.h.length = sizeof(msg.getcaps_req);
strncpy(msg.getcaps_req.device, u->addr, 18); strncpy(msg.getcaps_req.device, u->addr, 18);
if (strcasecmp(u->profile, "a2dp") == 0) if (strcasecmp(u->profile, "a2dp") == 0)
msg.getcaps_req.transport = BT_CAPABILITIES_TRANSPORT_A2DP; msg.getcaps_req.transport = BT_CAPABILITIES_TRANSPORT_A2DP;
@ -196,20 +239,13 @@ static int bt_getcaps(struct userdata *u) {
return e; return e;
} }
e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp_hdr.msg_h, BT_GETCAPABILITIES_RSP); e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp, BT_GET_CAPABILITIES, 0);
if (e < 0) { if (e < 0) {
pa_log_error("Failed to expect for GETCAPABILITIES_RSP"); pa_log_error("Failed to expect for GETCAPABILITIES_RSP");
return e; return e;
} }
if (msg.rsp_hdr.posix_errno != 0) {
pa_log_error("BT_GETCAPABILITIES failed : %s (%d)", pa_cstrerror(msg.rsp_hdr.posix_errno), msg.rsp_hdr.posix_errno);
return -msg.rsp_hdr.posix_errno;
}
if ((u->transport = msg.getcaps_rsp.transport) == BT_CAPABILITIES_TRANSPORT_A2DP) return bt_parsecaps(u, &msg.getcaps_rsp);
u->a2dp.sbc_capabilities = msg.getcaps_rsp.sbc_capabilities;
return 0;
} }
static uint8_t default_bitpool(uint8_t freq, uint8_t mode) { static uint8_t default_bitpool(uint8_t freq, uint8_t mode) {
@ -393,10 +429,10 @@ static void bt_a2dp_setup(struct bt_a2dp *a2dp) {
static int bt_setconf(struct userdata *u) { static int bt_setconf(struct userdata *u) {
int e; int e;
union { union {
bt_audio_rsp_msg_header_t rsp_hdr; bt_audio_msg_header_t rsp;
struct bt_setconfiguration_req setconf_req; struct bt_set_configuration_req setconf_req;
struct bt_setconfiguration_rsp setconf_rsp; struct bt_set_configuration_rsp setconf_rsp;
uint8_t buf[BT_AUDIO_IPC_PACKET_SIZE]; uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
} msg; } msg;
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP) { if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP) {
@ -410,12 +446,16 @@ static int bt_setconf(struct userdata *u) {
else else
u->ss.format = PA_SAMPLE_U8; u->ss.format = PA_SAMPLE_U8;
memset(msg.buf, 0, BT_AUDIO_IPC_PACKET_SIZE); memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
msg.setconf_req.h.msg_type = BT_SETCONFIGURATION_REQ; msg.setconf_req.h.type = BT_REQUEST;
msg.setconf_req.h.name = BT_SET_CONFIGURATION;
msg.setconf_req.h.length = sizeof(msg.setconf_req);
strncpy(msg.setconf_req.device, u->addr, 18); strncpy(msg.setconf_req.device, u->addr, 18);
msg.setconf_req.transport = u->transport; msg.setconf_req.codec.transport = u->transport;
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP) if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP)
msg.setconf_req.sbc_capabilities = u->a2dp.sbc_capabilities; memcpy(&msg.setconf_req.codec, &u->a2dp.sbc_capabilities,
sizeof(u->a2dp.sbc_capabilities));
msg.setconf_req.access_mode = BT_CAPABILITIES_ACCESS_MODE_WRITE; msg.setconf_req.access_mode = BT_CAPABILITIES_ACCESS_MODE_WRITE;
e = bt_audioservice_send(u->audioservice_fd, &msg.setconf_req.h); e = bt_audioservice_send(u->audioservice_fd, &msg.setconf_req.h);
@ -424,17 +464,12 @@ static int bt_setconf(struct userdata *u) {
return e; return e;
} }
e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp_hdr.msg_h, BT_SETCONFIGURATION_RSP); e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp, BT_SET_CONFIGURATION, sizeof(msg.setconf_rsp));
if (e < 0) { if (e < 0) {
pa_log_error("Failed to expect BT_SETCONFIGURATION_RSP"); pa_log_error("Failed to expect BT_SETCONFIGURATION_RSP");
return e; return e;
} }
if (msg.rsp_hdr.posix_errno != 0) {
pa_log_error("BT_SETCONFIGURATION failed : %s(%d)", pa_cstrerror(msg.rsp_hdr.posix_errno), msg.rsp_hdr.posix_errno);
return -msg.rsp_hdr.posix_errno;
}
u->transport = msg.setconf_rsp.transport; u->transport = msg.setconf_rsp.transport;
u->strtransport = (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP ? pa_xstrdup("A2DP") : pa_xstrdup("SCO")); u->strtransport = (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP ? pa_xstrdup("A2DP") : pa_xstrdup("SCO"));
u->link_mtu = msg.setconf_rsp.link_mtu; u->link_mtu = msg.setconf_rsp.link_mtu;
@ -456,14 +491,17 @@ static int bt_getstreamfd(struct userdata *u) {
int e; int e;
// uint32_t period_count = io->buffer_size / io->period_size; // uint32_t period_count = io->buffer_size / io->period_size;
union { union {
bt_audio_rsp_msg_header_t rsp_hdr; bt_audio_msg_header_t rsp;
struct bt_streamstart_req start_req; struct bt_start_stream_req start_req;
struct bt_streamfd_ind streamfd_ind; struct bt_start_stream_rsp start_rsp;
uint8_t buf[BT_AUDIO_IPC_PACKET_SIZE]; struct bt_new_stream_ind streamfd_ind;
uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
} msg; } msg;
memset(msg.buf, 0, BT_AUDIO_IPC_PACKET_SIZE); memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
msg.start_req.h.msg_type = BT_STREAMSTART_REQ; msg.start_req.h.type = BT_REQUEST;
msg.start_req.h.name = BT_START_STREAM;
msg.start_req.h.length = sizeof(msg.start_req);
e = bt_audioservice_send(u->audioservice_fd, &msg.start_req.h); e = bt_audioservice_send(u->audioservice_fd, &msg.start_req.h);
if (e < 0) { if (e < 0) {
@ -471,18 +509,13 @@ static int bt_getstreamfd(struct userdata *u) {
return e; return e;
} }
e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp_hdr.msg_h, BT_STREAMSTART_RSP); e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp, BT_START_STREAM, sizeof(msg.start_rsp));
if (e < 0) { if (e < 0) {
pa_log_error("Failed to expect BT_STREAMSTART_RSP"); pa_log_error("Failed to expect BT_STREAMSTART_RSP");
return e; return e;
} }
if (msg.rsp_hdr.posix_errno != 0) { e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp, BT_NEW_STREAM, sizeof(msg.streamfd_ind));
pa_log_error("BT_START failed : %s(%d)", pa_cstrerror(msg.rsp_hdr.posix_errno), msg.rsp_hdr.posix_errno);
return -msg.rsp_hdr.posix_errno;
}
e = bt_audioservice_expect(u->audioservice_fd, &msg.streamfd_ind.h, BT_STREAMFD_IND);
if (e < 0) { if (e < 0) {
pa_log_error("Failed to expect BT_STREAMFD_IND"); pa_log_error("Failed to expect BT_STREAMFD_IND");
return e; return e;