2008-07-31 20:16:43 -03:00
|
|
|
/***
|
2009-01-29 16:27:27 +01:00
|
|
|
This file is part of PulseAudio.
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
Copyright 2008 Joao Paulo Rechi Vita
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
PulseAudio is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
PulseAudio 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.
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
License along with PulseAudio; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
|
USA.
|
2008-07-31 20:16:43 -03:00
|
|
|
***/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include <config.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
#include <string.h>
|
2008-08-11 18:10:14 -03:00
|
|
|
#include <errno.h>
|
|
|
|
|
#include <poll.h>
|
2008-08-25 22:15:25 -03:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <linux/sockios.h>
|
2008-08-29 11:46:02 -03:00
|
|
|
#include <arpa/inet.h>
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-07-31 20:16:43 -03:00
|
|
|
#include <pulse/xmalloc.h>
|
2008-08-11 13:52:59 -03:00
|
|
|
#include <pulse/timeval.h>
|
2008-08-13 16:52:28 -03:00
|
|
|
#include <pulse/sample.h>
|
2008-07-31 20:16:43 -03:00
|
|
|
#include <pulsecore/module.h>
|
|
|
|
|
#include <pulsecore/modargs.h>
|
2008-08-19 16:06:21 -03:00
|
|
|
#include <pulsecore/core-util.h>
|
|
|
|
|
#include <pulsecore/core-error.h>
|
|
|
|
|
#include <pulsecore/socket-util.h>
|
2008-08-11 13:27:13 -03:00
|
|
|
#include <pulsecore/thread.h>
|
|
|
|
|
#include <pulsecore/thread-mq.h>
|
|
|
|
|
#include <pulsecore/rtpoll.h>
|
|
|
|
|
#include <pulsecore/time-smoother.h>
|
|
|
|
|
#include <pulsecore/rtclock.h>
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
#include <modules/dbus-util.h>
|
|
|
|
|
|
2008-08-29 20:22:14 -03:00
|
|
|
#include "module-bluetooth-device-symdef.h"
|
|
|
|
|
#include "ipc.h"
|
|
|
|
|
#include "sbc.h"
|
|
|
|
|
#include "rtp.h"
|
2009-01-29 16:27:27 +01:00
|
|
|
#include "bluetooth-util.h"
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
#define BUFFER_SIZE 2048
|
|
|
|
|
#define MAX_BITPOOL 64
|
2008-09-29 21:43:28 +02:00
|
|
|
#define MIN_BITPOOL 2U
|
2008-08-16 16:03:20 -03:00
|
|
|
#define SOL_SCO 17
|
|
|
|
|
#define SCO_TXBUFS 0x03
|
|
|
|
|
#define SCO_RXBUFS 0x04
|
2008-07-31 20:16:43 -03:00
|
|
|
|
|
|
|
|
PA_MODULE_AUTHOR("Joao Paulo Rechi Vita");
|
|
|
|
|
PA_MODULE_DESCRIPTION("Bluetooth audio sink and source");
|
|
|
|
|
PA_MODULE_VERSION(PACKAGE_VERSION);
|
|
|
|
|
PA_MODULE_LOAD_ONCE(FALSE);
|
|
|
|
|
PA_MODULE_USAGE(
|
2009-01-29 16:27:27 +01:00
|
|
|
"name=<name for the card/sink/source, to be prefixed> "
|
|
|
|
|
"card_name=<name for the card> "
|
|
|
|
|
"sink_name=<name for the sink> "
|
|
|
|
|
"source_name=<name for the source> "
|
2008-09-29 21:40:52 +02:00
|
|
|
"address=<address of the device> "
|
2009-01-19 14:53:35 +02:00
|
|
|
"profile=<a2dp|hsp> "
|
|
|
|
|
"rate=<sample rate> "
|
|
|
|
|
"channels=<number of channels> "
|
|
|
|
|
"path=<device object path>");
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
static const char* const valid_modargs[] = {
|
|
|
|
|
"name",
|
|
|
|
|
"card_name",
|
|
|
|
|
"sink_name",
|
|
|
|
|
"source_name",
|
|
|
|
|
"address",
|
|
|
|
|
"profile",
|
|
|
|
|
"rate",
|
|
|
|
|
"channels",
|
|
|
|
|
"path",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
|
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
struct bt_a2dp {
|
|
|
|
|
sbc_capabilities_t sbc_capabilities;
|
|
|
|
|
sbc_t sbc; /* Codec data */
|
2008-08-21 15:12:03 -03:00
|
|
|
pa_bool_t sbc_initialized; /* Keep track if the encoder is initialized */
|
2008-09-29 21:43:28 +02:00
|
|
|
size_t codesize; /* SBC codesize */
|
|
|
|
|
unsigned samples; /* Number of encoded samples */
|
2008-08-11 13:27:13 -03:00
|
|
|
uint8_t buffer[BUFFER_SIZE]; /* Codec transfer buffer */
|
2008-09-29 21:43:28 +02:00
|
|
|
size_t count; /* Codec transfer buffer counter */
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
unsigned total_samples; /* Cumulative number of codec samples */
|
2008-08-11 13:27:13 -03:00
|
|
|
uint16_t seq_num; /* Cumulative packet sequence */
|
2008-09-29 21:43:28 +02:00
|
|
|
unsigned frame_count; /* Current frames in buffer*/
|
2008-08-11 13:27:13 -03:00
|
|
|
};
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
enum profile {
|
|
|
|
|
PROFILE_A2DP,
|
|
|
|
|
PROFILE_SCO,
|
|
|
|
|
PROFILE_OFF
|
|
|
|
|
};
|
|
|
|
|
|
2008-07-31 20:16:43 -03:00
|
|
|
struct userdata {
|
|
|
|
|
pa_core *core;
|
|
|
|
|
pa_module *module;
|
|
|
|
|
pa_sink *sink;
|
2009-01-19 14:53:35 +02:00
|
|
|
pa_source *source;
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
pa_thread_mq thread_mq;
|
|
|
|
|
pa_rtpoll *rtpoll;
|
|
|
|
|
pa_rtpoll_item *rtpoll_item;
|
|
|
|
|
pa_thread *thread;
|
|
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
uint64_t offset;
|
2008-08-11 13:27:13 -03:00
|
|
|
pa_smoother *smoother;
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
char *address;
|
|
|
|
|
pa_sample_spec sample_spec;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
int service_fd;
|
2008-09-29 21:43:28 +02:00
|
|
|
int stream_fd;
|
2008-08-11 18:10:14 -03:00
|
|
|
|
2008-08-30 17:41:00 -03:00
|
|
|
uint8_t transport;
|
2008-09-29 21:43:28 +02:00
|
|
|
size_t link_mtu;
|
2008-08-11 18:10:14 -03:00
|
|
|
size_t block_size;
|
|
|
|
|
pa_usec_t latency;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
struct bt_a2dp a2dp;
|
2009-01-19 14:53:35 +02:00
|
|
|
char *path;
|
2009-01-29 16:27:27 +01:00
|
|
|
pa_dbus_connection *connection;
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
enum profile profile;
|
|
|
|
|
|
|
|
|
|
pa_bluetooth_device *device;
|
2008-07-31 20:16:43 -03:00
|
|
|
};
|
|
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
static int bt_audioservice_send(int sk, const bt_audio_msg_header_t *msg) {
|
2008-07-31 20:16:43 -03:00
|
|
|
int e;
|
2008-12-17 17:19:22 -03:00
|
|
|
const char *type, *name;
|
2009-01-06 11:00:44 -03:00
|
|
|
uint16_t length;
|
2008-12-17 17:19:22 -03:00
|
|
|
|
2009-01-06 11:00:44 -03:00
|
|
|
length = msg->length ? msg->length : BT_SUGGESTED_BUFFER_SIZE;
|
2008-12-17 17:19:22 -03:00
|
|
|
type = bt_audio_strtype(msg->type);
|
|
|
|
|
name = bt_audio_strname(msg->name);
|
|
|
|
|
pa_log_debug("sending: %s -> %s", type, name);
|
2009-01-06 11:00:44 -03:00
|
|
|
if (send(sk, msg, length, 0) > 0)
|
2008-07-31 20:16:43 -03:00
|
|
|
e = 0;
|
|
|
|
|
else {
|
|
|
|
|
e = -errno;
|
2008-08-13 16:07:19 -03:00
|
|
|
pa_log_error("Error sending data to audio service: %s(%d)", pa_cstrerror(errno), errno);
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
|
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
static int bt_audioservice_recv(int sk, bt_audio_msg_header_t *inmsg, uint16_t expected_length) {
|
2008-08-11 13:27:13 -03:00
|
|
|
int e;
|
2008-12-17 17:19:22 -03:00
|
|
|
const char *type, *name;
|
2009-01-06 11:00:44 -03:00
|
|
|
uint16_t length;
|
|
|
|
|
|
|
|
|
|
length = expected_length ? expected_length : BT_SUGGESTED_BUFFER_SIZE;
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2008-08-19 17:35:43 -03:00
|
|
|
pa_log_debug("trying to receive msg from audio service...");
|
2009-01-06 11:00:44 -03:00
|
|
|
if (recv(sk, inmsg, length, 0) > 0) {
|
2008-12-17 17:19:22 -03:00
|
|
|
type = bt_audio_strtype(inmsg->type);
|
|
|
|
|
name = bt_audio_strname(inmsg->name);
|
|
|
|
|
if (type && name) {
|
|
|
|
|
pa_log_debug("Received: %s <- %s", type, name);
|
2008-08-11 13:27:13 -03:00
|
|
|
e = 0;
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
|
|
|
|
else {
|
2008-08-11 13:27:13 -03:00
|
|
|
e = -EINVAL;
|
2008-12-17 17:19:22 -03:00
|
|
|
pa_log_error("Bogus message type %d name %d received from audio service",
|
|
|
|
|
inmsg->type, inmsg->name);
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2008-08-11 13:27:13 -03:00
|
|
|
e = -errno;
|
2008-08-13 16:07:19 -03:00
|
|
|
pa_log_error("Error receiving data from audio service: %s(%d)", pa_cstrerror(errno), errno);
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
|
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
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, expected_length);
|
|
|
|
|
|
|
|
|
|
if (e < 0) {
|
|
|
|
|
if (rsp->name != expected_name) {
|
2008-08-11 13:27:13 -03:00
|
|
|
e = -EINVAL;
|
2008-12-17 17:19:22 -03:00
|
|
|
pa_log_error("Bogus message %s received while %s was expected",
|
|
|
|
|
bt_audio_strname(rsp->name),
|
|
|
|
|
bt_audio_strname(expected_name));
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
|
|
|
|
}
|
2008-12-17 17:19:22 -03:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
static int bt_getcaps(struct userdata *u) {
|
|
|
|
|
int e;
|
2008-08-25 21:56:31 -03:00
|
|
|
union {
|
2008-12-17 17:19:22 -03:00
|
|
|
bt_audio_msg_header_t rsp;
|
|
|
|
|
struct bt_get_capabilities_req getcaps_req;
|
|
|
|
|
struct bt_get_capabilities_rsp getcaps_rsp;
|
|
|
|
|
uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
|
2008-08-25 21:56:31 -03:00
|
|
|
} msg;
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
|
|
|
|
|
msg.getcaps_req.h.type = BT_REQUEST;
|
|
|
|
|
msg.getcaps_req.h.name = BT_GET_CAPABILITIES;
|
|
|
|
|
msg.getcaps_req.h.length = sizeof(msg.getcaps_req);
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
strncpy(msg.getcaps_req.device, u->address, 18);
|
2009-01-19 14:53:35 +02:00
|
|
|
if (pa_streq(u->profile, "a2dp"))
|
2008-08-25 21:56:31 -03:00
|
|
|
msg.getcaps_req.transport = BT_CAPABILITIES_TRANSPORT_A2DP;
|
2009-01-19 14:53:35 +02:00
|
|
|
else if (pa_streq(u->profile, "hsp"))
|
2008-08-25 21:56:31 -03:00
|
|
|
msg.getcaps_req.transport = BT_CAPABILITIES_TRANSPORT_SCO;
|
2008-08-11 13:27:13 -03:00
|
|
|
else {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Invalid profile argument: %s", u->profile);
|
2008-08-11 13:27:13 -03:00
|
|
|
return -1;
|
|
|
|
|
}
|
2008-08-25 21:56:31 -03:00
|
|
|
msg.getcaps_req.flags = BT_FLAG_AUTOCONNECT;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-08-25 21:56:31 -03:00
|
|
|
e = bt_audioservice_send(u->audioservice_fd, &msg.getcaps_req.h);
|
2008-08-11 13:27:13 -03:00
|
|
|
if (e < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to send GETCAPABILITIES_REQ");
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp, BT_GET_CAPABILITIES, 0);
|
2008-08-11 13:27:13 -03:00
|
|
|
if (e < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to expect for GETCAPABILITIES_RSP");
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
return bt_parsecaps(u, &msg.getcaps_rsp);
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static uint8_t default_bitpool(uint8_t freq, uint8_t mode) {
|
|
|
|
|
switch (freq) {
|
|
|
|
|
case BT_SBC_SAMPLING_FREQ_16000:
|
|
|
|
|
case BT_SBC_SAMPLING_FREQ_32000:
|
|
|
|
|
return 53;
|
|
|
|
|
case BT_SBC_SAMPLING_FREQ_44100:
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case BT_A2DP_CHANNEL_MODE_MONO:
|
|
|
|
|
case BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL:
|
|
|
|
|
return 31;
|
|
|
|
|
case BT_A2DP_CHANNEL_MODE_STEREO:
|
|
|
|
|
case BT_A2DP_CHANNEL_MODE_JOINT_STEREO:
|
|
|
|
|
return 53;
|
|
|
|
|
default:
|
|
|
|
|
pa_log_warn("Invalid channel mode %u", mode);
|
|
|
|
|
return 53;
|
|
|
|
|
}
|
|
|
|
|
case BT_SBC_SAMPLING_FREQ_48000:
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case BT_A2DP_CHANNEL_MODE_MONO:
|
|
|
|
|
case BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL:
|
|
|
|
|
return 29;
|
|
|
|
|
case BT_A2DP_CHANNEL_MODE_STEREO:
|
|
|
|
|
case BT_A2DP_CHANNEL_MODE_JOINT_STEREO:
|
|
|
|
|
return 51;
|
|
|
|
|
default:
|
|
|
|
|
pa_log_warn("Invalid channel mode %u", mode);
|
|
|
|
|
return 51;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
pa_log_warn("Invalid sampling freq %u", freq);
|
|
|
|
|
return 53;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int bt_a2dp_init(struct userdata *u) {
|
|
|
|
|
sbc_capabilities_t *cap = &u->a2dp.sbc_capabilities;
|
2008-09-29 21:42:29 +02:00
|
|
|
uint8_t max_bitpool, min_bitpool;
|
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
|
uint32_t rate;
|
|
|
|
|
uint8_t cap;
|
|
|
|
|
} freq_table[] = {
|
|
|
|
|
{ 16000U, BT_SBC_SAMPLING_FREQ_16000 },
|
|
|
|
|
{ 32000U, BT_SBC_SAMPLING_FREQ_32000 },
|
|
|
|
|
{ 44100U, BT_SBC_SAMPLING_FREQ_44100 },
|
|
|
|
|
{ 48000U, BT_SBC_SAMPLING_FREQ_48000 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Find the lowest freq that is at least as high as the requested
|
|
|
|
|
* sampling rate */
|
|
|
|
|
for (i = 0; i < PA_ELEMENTSOF(freq_table); i++)
|
|
|
|
|
if (freq_table[i].rate >= u->ss.rate || i == PA_ELEMENTSOF(freq_table)-1 ) {
|
|
|
|
|
u->ss.rate = freq_table[i].rate;
|
|
|
|
|
cap->frequency = freq_table[i].cap;
|
2008-08-11 13:27:13 -03:00
|
|
|
break;
|
2008-09-29 21:42:29 +02:00
|
|
|
}
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-09-29 21:42:29 +02:00
|
|
|
if (u->ss.channels >= 2) {
|
2008-08-11 13:27:13 -03:00
|
|
|
if (cap->channel_mode & BT_A2DP_CHANNEL_MODE_JOINT_STEREO)
|
|
|
|
|
cap->channel_mode = BT_A2DP_CHANNEL_MODE_JOINT_STEREO;
|
|
|
|
|
else if (cap->channel_mode & BT_A2DP_CHANNEL_MODE_STEREO)
|
|
|
|
|
cap->channel_mode = BT_A2DP_CHANNEL_MODE_STEREO;
|
|
|
|
|
else if (cap->channel_mode & BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL)
|
|
|
|
|
cap->channel_mode = BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL;
|
2008-09-29 21:42:29 +02:00
|
|
|
|
|
|
|
|
u->ss.channels = 2;
|
2008-08-11 13:27:13 -03:00
|
|
|
} else {
|
|
|
|
|
if (cap->channel_mode & BT_A2DP_CHANNEL_MODE_MONO)
|
|
|
|
|
cap->channel_mode = BT_A2DP_CHANNEL_MODE_MONO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!cap->channel_mode) {
|
|
|
|
|
pa_log_error("No supported channel modes");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cap->block_length & BT_A2DP_BLOCK_LENGTH_16)
|
|
|
|
|
cap->block_length = BT_A2DP_BLOCK_LENGTH_16;
|
|
|
|
|
else if (cap->block_length & BT_A2DP_BLOCK_LENGTH_12)
|
|
|
|
|
cap->block_length = BT_A2DP_BLOCK_LENGTH_12;
|
|
|
|
|
else if (cap->block_length & BT_A2DP_BLOCK_LENGTH_8)
|
|
|
|
|
cap->block_length = BT_A2DP_BLOCK_LENGTH_8;
|
|
|
|
|
else if (cap->block_length & BT_A2DP_BLOCK_LENGTH_4)
|
|
|
|
|
cap->block_length = BT_A2DP_BLOCK_LENGTH_4;
|
|
|
|
|
else {
|
|
|
|
|
pa_log_error("No supported block lengths");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cap->subbands & BT_A2DP_SUBBANDS_8)
|
|
|
|
|
cap->subbands = BT_A2DP_SUBBANDS_8;
|
|
|
|
|
else if (cap->subbands & BT_A2DP_SUBBANDS_4)
|
|
|
|
|
cap->subbands = BT_A2DP_SUBBANDS_4;
|
|
|
|
|
else {
|
|
|
|
|
pa_log_error("No supported subbands");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cap->allocation_method & BT_A2DP_ALLOCATION_LOUDNESS)
|
|
|
|
|
cap->allocation_method = BT_A2DP_ALLOCATION_LOUDNESS;
|
|
|
|
|
else if (cap->allocation_method & BT_A2DP_ALLOCATION_SNR)
|
|
|
|
|
cap->allocation_method = BT_A2DP_ALLOCATION_SNR;
|
|
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
min_bitpool = (uint8_t) PA_MAX(MIN_BITPOOL, cap->min_bitpool);
|
|
|
|
|
max_bitpool = (uint8_t) PA_MIN(default_bitpool(cap->frequency, cap->channel_mode), cap->max_bitpool);
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
cap->min_bitpool = (uint8_t) min_bitpool;
|
|
|
|
|
cap->max_bitpool = (uint8_t) max_bitpool;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void bt_a2dp_setup(struct bt_a2dp *a2dp) {
|
|
|
|
|
sbc_capabilities_t active_capabilities = a2dp->sbc_capabilities;
|
|
|
|
|
|
|
|
|
|
if (a2dp->sbc_initialized)
|
|
|
|
|
sbc_reinit(&a2dp->sbc, 0);
|
|
|
|
|
else
|
|
|
|
|
sbc_init(&a2dp->sbc, 0);
|
2008-08-21 15:12:03 -03:00
|
|
|
a2dp->sbc_initialized = TRUE;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
if (active_capabilities.frequency & BT_SBC_SAMPLING_FREQ_16000)
|
|
|
|
|
a2dp->sbc.frequency = SBC_FREQ_16000;
|
|
|
|
|
|
|
|
|
|
if (active_capabilities.frequency & BT_SBC_SAMPLING_FREQ_32000)
|
|
|
|
|
a2dp->sbc.frequency = SBC_FREQ_32000;
|
|
|
|
|
|
|
|
|
|
if (active_capabilities.frequency & BT_SBC_SAMPLING_FREQ_44100)
|
|
|
|
|
a2dp->sbc.frequency = SBC_FREQ_44100;
|
|
|
|
|
|
|
|
|
|
if (active_capabilities.frequency & BT_SBC_SAMPLING_FREQ_48000)
|
|
|
|
|
a2dp->sbc.frequency = SBC_FREQ_48000;
|
|
|
|
|
|
|
|
|
|
if (active_capabilities.channel_mode & BT_A2DP_CHANNEL_MODE_MONO)
|
|
|
|
|
a2dp->sbc.mode = SBC_MODE_MONO;
|
|
|
|
|
|
|
|
|
|
if (active_capabilities.channel_mode & BT_A2DP_CHANNEL_MODE_DUAL_CHANNEL)
|
|
|
|
|
a2dp->sbc.mode = SBC_MODE_DUAL_CHANNEL;
|
|
|
|
|
|
|
|
|
|
if (active_capabilities.channel_mode & BT_A2DP_CHANNEL_MODE_STEREO)
|
|
|
|
|
a2dp->sbc.mode = SBC_MODE_STEREO;
|
|
|
|
|
|
|
|
|
|
if (active_capabilities.channel_mode & BT_A2DP_CHANNEL_MODE_JOINT_STEREO)
|
|
|
|
|
a2dp->sbc.mode = SBC_MODE_JOINT_STEREO;
|
|
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
a2dp->sbc.allocation = (uint8_t) (active_capabilities.allocation_method == BT_A2DP_ALLOCATION_SNR ? SBC_AM_SNR : SBC_AM_LOUDNESS);
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
switch (active_capabilities.subbands) {
|
|
|
|
|
case BT_A2DP_SUBBANDS_4:
|
|
|
|
|
a2dp->sbc.subbands = SBC_SB_4;
|
|
|
|
|
break;
|
|
|
|
|
case BT_A2DP_SUBBANDS_8:
|
|
|
|
|
a2dp->sbc.subbands = SBC_SB_8;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (active_capabilities.block_length) {
|
|
|
|
|
case BT_A2DP_BLOCK_LENGTH_4:
|
|
|
|
|
a2dp->sbc.blocks = SBC_BLK_4;
|
|
|
|
|
break;
|
|
|
|
|
case BT_A2DP_BLOCK_LENGTH_8:
|
|
|
|
|
a2dp->sbc.blocks = SBC_BLK_8;
|
|
|
|
|
break;
|
|
|
|
|
case BT_A2DP_BLOCK_LENGTH_12:
|
|
|
|
|
a2dp->sbc.blocks = SBC_BLK_12;
|
|
|
|
|
break;
|
|
|
|
|
case BT_A2DP_BLOCK_LENGTH_16:
|
|
|
|
|
a2dp->sbc.blocks = SBC_BLK_16;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a2dp->sbc.bitpool = active_capabilities.max_bitpool;
|
2008-09-29 21:43:28 +02:00
|
|
|
a2dp->codesize = (uint16_t) sbc_get_codesize(&a2dp->sbc);
|
2008-08-16 16:03:20 -03:00
|
|
|
a2dp->count = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int bt_setconf(struct userdata *u) {
|
|
|
|
|
int e;
|
2008-08-25 21:56:31 -03:00
|
|
|
union {
|
2008-12-17 17:19:22 -03:00
|
|
|
bt_audio_msg_header_t rsp;
|
|
|
|
|
struct bt_set_configuration_req setconf_req;
|
|
|
|
|
struct bt_set_configuration_rsp setconf_rsp;
|
|
|
|
|
uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
|
2008-08-25 21:56:31 -03:00
|
|
|
} msg;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP) {
|
|
|
|
|
e = bt_a2dp_init(u);
|
|
|
|
|
if (e < 0) {
|
|
|
|
|
pa_log_error("a2dp_init error");
|
|
|
|
|
return e;
|
|
|
|
|
}
|
2008-08-17 20:35:56 -03:00
|
|
|
u->ss.format = PA_SAMPLE_S16LE;
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
2009-01-19 10:19:53 -03:00
|
|
|
else {
|
|
|
|
|
u->ss.format = PA_SAMPLE_S16LE;
|
|
|
|
|
u->ss.channels = 1;
|
|
|
|
|
u->ss.rate = 8000;
|
|
|
|
|
}
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
|
|
|
|
|
msg.setconf_req.h.type = BT_REQUEST;
|
|
|
|
|
msg.setconf_req.h.name = BT_SET_CONFIGURATION;
|
|
|
|
|
msg.setconf_req.h.length = sizeof(msg.setconf_req);
|
|
|
|
|
|
2008-08-25 21:56:31 -03:00
|
|
|
strncpy(msg.setconf_req.device, u->addr, 18);
|
2008-12-17 17:19:22 -03:00
|
|
|
msg.setconf_req.codec.transport = u->transport;
|
2009-01-06 11:02:16 -03:00
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP) {
|
2008-12-17 17:19:22 -03:00
|
|
|
memcpy(&msg.setconf_req.codec, &u->a2dp.sbc_capabilities,
|
|
|
|
|
sizeof(u->a2dp.sbc_capabilities));
|
2009-01-06 11:02:16 -03:00
|
|
|
msg.setconf_req.h.length += msg.setconf_req.codec.length
|
|
|
|
|
- sizeof(msg.setconf_req.codec);
|
|
|
|
|
}
|
2008-08-25 21:56:31 -03:00
|
|
|
msg.setconf_req.access_mode = BT_CAPABILITIES_ACCESS_MODE_WRITE;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-08-25 21:56:31 -03:00
|
|
|
e = bt_audioservice_send(u->audioservice_fd, &msg.setconf_req.h);
|
2008-08-11 13:27:13 -03:00
|
|
|
if (e < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to send BT_SETCONFIGURATION_REQ");
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp, BT_SET_CONFIGURATION, sizeof(msg.setconf_rsp));
|
2008-08-11 13:27:13 -03:00
|
|
|
if (e < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to expect BT_SETCONFIGURATION_RSP");
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-25 21:56:31 -03:00
|
|
|
u->transport = msg.setconf_rsp.transport;
|
|
|
|
|
u->link_mtu = msg.setconf_rsp.link_mtu;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
/* setup SBC encoder now we agree on parameters */
|
|
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP) {
|
|
|
|
|
bt_a2dp_setup(&u->a2dp);
|
2008-08-17 01:54:12 -03:00
|
|
|
u->block_size = u->a2dp.codesize;
|
2008-08-19 17:35:43 -03:00
|
|
|
pa_log_info("sbc parameters:\n\tallocation=%u\n\tsubbands=%u\n\tblocks=%u\n\tbitpool=%u\n",
|
2008-08-11 13:27:13 -03:00
|
|
|
u->a2dp.sbc.allocation, u->a2dp.sbc.subbands, u->a2dp.sbc.blocks, u->a2dp.sbc.bitpool);
|
|
|
|
|
}
|
2008-08-17 01:54:12 -03:00
|
|
|
else
|
|
|
|
|
u->block_size = u->link_mtu;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int bt_getstreamfd(struct userdata *u) {
|
2008-08-16 16:03:20 -03:00
|
|
|
int e;
|
|
|
|
|
// uint32_t period_count = io->buffer_size / io->period_size;
|
2008-08-25 21:56:31 -03:00
|
|
|
union {
|
2008-12-17 17:19:22 -03:00
|
|
|
bt_audio_msg_header_t rsp;
|
|
|
|
|
struct bt_start_stream_req start_req;
|
|
|
|
|
struct bt_start_stream_rsp start_rsp;
|
|
|
|
|
struct bt_new_stream_ind streamfd_ind;
|
|
|
|
|
uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
|
2008-08-25 21:56:31 -03:00
|
|
|
} msg;
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
memset(msg.buf, 0, BT_SUGGESTED_BUFFER_SIZE);
|
|
|
|
|
msg.start_req.h.type = BT_REQUEST;
|
|
|
|
|
msg.start_req.h.name = BT_START_STREAM;
|
|
|
|
|
msg.start_req.h.length = sizeof(msg.start_req);
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2008-08-25 21:56:31 -03:00
|
|
|
e = bt_audioservice_send(u->audioservice_fd, &msg.start_req.h);
|
2008-08-11 13:27:13 -03:00
|
|
|
if (e < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to send BT_STREAMSTART_REQ");
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp, BT_START_STREAM, sizeof(msg.start_rsp));
|
2008-08-11 13:27:13 -03:00
|
|
|
if (e < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to expect BT_STREAMSTART_RSP");
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-17 17:19:22 -03:00
|
|
|
e = bt_audioservice_expect(u->audioservice_fd, &msg.rsp, BT_NEW_STREAM, sizeof(msg.streamfd_ind));
|
2008-08-11 13:27:13 -03:00
|
|
|
if (e < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to expect BT_STREAMFD_IND");
|
2008-08-11 13:27:13 -03:00
|
|
|
return e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->stream_fd >= 0)
|
2008-08-13 16:08:20 -03:00
|
|
|
pa_close(u->stream_fd);
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
u->stream_fd = bt_audio_service_get_data_fd(u->audioservice_fd);
|
|
|
|
|
if (u->stream_fd < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to get data fd: %s (%d)",pa_cstrerror(errno), errno);
|
2008-08-11 13:27:13 -03:00
|
|
|
return -errno;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-19 16:06:21 -03:00
|
|
|
// if (setsockopt(u->stream_fd, SOL_SCO, SCO_TXBUFS, &period_count, sizeof(period_count)) == 0)
|
|
|
|
|
// return 0;
|
|
|
|
|
// if (setsockopt(u->stream_fd, SOL_SCO, SO_SNDBUF, &period_count, sizeof(period_count)) == 0)
|
|
|
|
|
// return 0;
|
|
|
|
|
// /* FIXME : handle error codes */
|
2008-08-14 20:57:32 -03:00
|
|
|
pa_make_fd_nonblock(u->stream_fd);
|
2008-08-19 16:06:21 -03:00
|
|
|
// pa_make_socket_low_delay(u->stream_fd);
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int sink_process_msg(pa_msgobject *o, int code, void *data, int64_t offset, pa_memchunk *chunk) {
|
|
|
|
|
struct userdata *u = PA_SINK(o)->userdata;
|
|
|
|
|
|
2008-08-19 17:35:43 -03:00
|
|
|
pa_log_debug("got message: %d", code);
|
2008-08-11 13:27:13 -03:00
|
|
|
switch (code) {
|
|
|
|
|
|
|
|
|
|
case PA_SINK_MESSAGE_SET_STATE:
|
|
|
|
|
switch ((pa_sink_state_t) PA_PTR_TO_UINT(data)) {
|
|
|
|
|
case PA_SINK_SUSPENDED:
|
|
|
|
|
pa_assert(PA_SINK_IS_OPENED(u->sink->thread_info.state));
|
|
|
|
|
pa_smoother_pause(u->smoother, pa_rtclock_usec());
|
|
|
|
|
break;
|
|
|
|
|
case PA_SINK_IDLE:
|
|
|
|
|
case PA_SINK_RUNNING:
|
|
|
|
|
if (u->sink->thread_info.state == PA_SINK_SUSPENDED)
|
|
|
|
|
pa_smoother_resume(u->smoother, pa_rtclock_usec());
|
|
|
|
|
break;
|
|
|
|
|
case PA_SINK_UNLINKED:
|
|
|
|
|
case PA_SINK_INIT:
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PA_SINK_MESSAGE_GET_LATENCY: {
|
2008-08-11 18:10:14 -03:00
|
|
|
pa_usec_t w, r;
|
2008-09-29 21:43:28 +02:00
|
|
|
/* r = pa_smoother_get(u->smoother, pa_rtclock_usec()); */
|
|
|
|
|
/* /\* w = pa_bytes_to_usec(u->offset + (uint64_t) u->memchunk.length, &u->sink->sample_spec); *\/ */
|
|
|
|
|
*((pa_usec_t*) data) = /*w > r ? w - r :*/ 0;
|
2008-08-15 16:56:26 -03:00
|
|
|
return 0;
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pa_sink_process_msg(o, code, data, offset, chunk);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-26 09:43:48 -03:00
|
|
|
static int sco_process_render(struct userdata *u) {
|
|
|
|
|
void *p;
|
2008-09-29 21:43:28 +02:00
|
|
|
int ret = 0;
|
|
|
|
|
pa_memchunk memchunk;
|
2008-08-11 18:10:14 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_sink_render_full(u->sink, u->block_size, &memchunk);
|
2008-08-11 18:10:14 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
p = pa_memblock_acquire(memchunk.memblock);
|
2008-08-11 18:10:14 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
for (;;) {
|
|
|
|
|
ssize_t l;
|
2008-08-11 18:10:14 -03:00
|
|
|
|
2009-01-27 00:53:31 +01:00
|
|
|
l = pa_loop_write(u->stream_fd, p, memchunk.length, NULL);
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_debug("Memblock written to socket: %li bytes", (long) l);
|
2008-08-11 18:10:14 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_assert(l != 0);
|
2008-08-11 18:10:14 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
if (l > 0) {
|
|
|
|
|
u->offset += (uint64_t) l;
|
|
|
|
|
break;
|
2008-08-14 20:59:28 -03:00
|
|
|
}
|
2008-09-29 21:43:28 +02:00
|
|
|
|
|
|
|
|
if (errno == EINTR)
|
|
|
|
|
pa_log_debug("EINTR");
|
|
|
|
|
else if (errno == EAGAIN)
|
2008-08-26 09:43:48 -03:00
|
|
|
pa_log_debug("EAGAIN");
|
|
|
|
|
else {
|
|
|
|
|
pa_log_error("Failed to write data to FIFO: %s", pa_cstrerror(errno));
|
2008-09-29 21:43:28 +02:00
|
|
|
ret = -1;
|
|
|
|
|
break;
|
2008-08-11 18:10:14 -03:00
|
|
|
}
|
|
|
|
|
}
|
2008-09-29 21:43:28 +02:00
|
|
|
|
|
|
|
|
pa_memblock_release(memchunk.memblock);
|
|
|
|
|
pa_memblock_unref(memchunk.memblock);
|
|
|
|
|
|
|
|
|
|
return ret;
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
|
|
|
|
|
2008-08-21 21:31:43 -03:00
|
|
|
static int a2dp_process_render(struct userdata *u) {
|
2008-09-29 21:43:28 +02:00
|
|
|
int written;
|
|
|
|
|
|
2008-08-21 21:31:43 -03:00
|
|
|
struct bt_a2dp *a2dp = &u->a2dp;
|
|
|
|
|
struct rtp_header *header = (void *) a2dp->buffer;
|
|
|
|
|
struct rtp_payload *payload = (void *) (a2dp->buffer + sizeof(*header));
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
/* Render some data */
|
2008-09-29 21:43:28 +02:00
|
|
|
int frame_size, encoded;
|
2008-08-21 21:31:43 -03:00
|
|
|
void *p;
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_memchunk memchunk;
|
2008-08-21 21:31:43 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_sink_render_full(u->sink, u->block_size, &memchunk);
|
2008-08-21 21:31:43 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
p = pa_memblock_acquire(memchunk.memblock);
|
2008-08-21 21:31:43 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
frame_size = (uint16_t) sbc_get_frame_length(&a2dp->sbc);
|
2008-08-21 21:31:43 -03:00
|
|
|
pa_log_debug("SBC frame_size: %d", frame_size);
|
|
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
encoded = sbc_encode(&a2dp->sbc, p, (int) a2dp->codesize, a2dp->buffer + a2dp->count,
|
|
|
|
|
(int) (sizeof(a2dp->buffer) - a2dp->count), &written);
|
2008-08-21 21:31:43 -03:00
|
|
|
pa_log_debug("SBC: encoded: %d; written: %d", encoded, written);
|
2008-09-29 21:43:28 +02:00
|
|
|
|
|
|
|
|
pa_memblock_release(memchunk.memblock);
|
|
|
|
|
pa_memblock_unref(memchunk.memblock);
|
|
|
|
|
|
2008-08-21 21:31:43 -03:00
|
|
|
if (encoded <= 0) {
|
|
|
|
|
pa_log_error("SBC encoding error (%d)", encoded);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
a2dp->count += (size_t) written;
|
2008-08-21 21:31:43 -03:00
|
|
|
a2dp->frame_count++;
|
2008-09-29 21:43:28 +02:00
|
|
|
a2dp->samples += (unsigned) encoded / frame_size;
|
|
|
|
|
a2dp->total_samples += (unsigned) encoded / frame_size;
|
|
|
|
|
|
|
|
|
|
} while (a2dp->count + (size_t) written <= u->link_mtu);
|
2008-08-21 21:31:43 -03:00
|
|
|
|
|
|
|
|
/* write it to the fifo */
|
|
|
|
|
memset(a2dp->buffer, 0, sizeof(*header) + sizeof(*payload));
|
|
|
|
|
payload->frame_count = a2dp->frame_count;
|
|
|
|
|
header->v = 2;
|
|
|
|
|
header->pt = 1;
|
|
|
|
|
header->sequence_number = htons(a2dp->seq_num);
|
2008-09-29 21:43:28 +02:00
|
|
|
header->timestamp = htonl(a2dp->total_samples);
|
2008-08-21 21:31:43 -03:00
|
|
|
header->ssrc = htonl(1);
|
|
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
for (;;) {
|
|
|
|
|
ssize_t l;
|
2008-08-21 21:31:43 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
l = pa_loop_write(u->stream_fd, a2dp->buffer, a2dp->count, NULL);
|
|
|
|
|
pa_log_debug("avdtp_write: requested %lu bytes; written %li bytes", (unsigned long) a2dp->count, (long) l);
|
2008-08-21 21:31:43 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_assert(l != 0);
|
|
|
|
|
|
|
|
|
|
if (l > 0)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (errno == EINTR)
|
2008-08-21 21:31:43 -03:00
|
|
|
pa_log_debug("EINTR");
|
2008-09-29 21:43:28 +02:00
|
|
|
else if (errno == EAGAIN)
|
2008-08-21 21:31:43 -03:00
|
|
|
pa_log_debug("EAGAIN");
|
|
|
|
|
else {
|
|
|
|
|
pa_log_error("Failed to write data to FIFO: %s", pa_cstrerror(errno));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u->offset += a2dp->codesize*a2dp->frame_count;
|
|
|
|
|
|
|
|
|
|
/* Reset buffer of data to send */
|
|
|
|
|
a2dp->count = sizeof(struct rtp_header) + sizeof(struct rtp_payload);
|
|
|
|
|
a2dp->frame_count = 0;
|
|
|
|
|
a2dp->samples = 0;
|
|
|
|
|
a2dp->seq_num++;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-26 09:43:48 -03:00
|
|
|
static void thread_func(void *userdata) {
|
2008-08-17 20:36:33 -03:00
|
|
|
struct userdata *u = userdata;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
2008-08-26 09:43:48 -03:00
|
|
|
pa_log_debug("IO Thread starting up");
|
2008-08-17 20:36:33 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
if (u->core->realtime_scheduling)
|
|
|
|
|
pa_make_realtime(u->core->realtime_priority);
|
|
|
|
|
|
2008-08-17 20:36:33 -03:00
|
|
|
pa_thread_mq_install(&u->thread_mq);
|
|
|
|
|
pa_rtpoll_install(u->rtpoll);
|
|
|
|
|
|
|
|
|
|
pa_smoother_set_time_offset(u->smoother, pa_rtclock_usec());
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
2008-08-25 22:15:25 -03:00
|
|
|
int ret, l;
|
2008-08-17 20:36:33 -03:00
|
|
|
struct pollfd *pollfd;
|
2008-08-29 11:46:02 -03:00
|
|
|
uint64_t n;
|
2008-08-21 21:31:43 -03:00
|
|
|
pa_usec_t usec;
|
2008-08-17 20:36:33 -03:00
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
if (PA_SINK_IS_OPENED(u->sink->thread_info.state))
|
|
|
|
|
if (u->sink->thread_info.rewind_requested)
|
2008-08-17 20:36:33 -03:00
|
|
|
pa_sink_process_rewind(u->sink, 0);
|
|
|
|
|
|
|
|
|
|
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
|
|
|
|
|
|
|
|
|
if (PA_SINK_IS_OPENED(u->sink->thread_info.state) && pollfd->revents) {
|
2008-08-26 09:43:48 -03:00
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP) {
|
2008-08-29 11:46:02 -03:00
|
|
|
if ((l = a2dp_process_render(u)) < 0)
|
2008-08-26 09:43:48 -03:00
|
|
|
goto fail;
|
2008-09-29 21:43:28 +02:00
|
|
|
} else {
|
2008-08-26 09:43:48 -03:00
|
|
|
if ((l = sco_process_render(u)) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
2008-08-19 16:06:21 -03:00
|
|
|
pollfd->revents = 0;
|
2008-08-17 20:36:33 -03:00
|
|
|
|
2008-08-19 16:06:21 -03:00
|
|
|
/* feed the time smoother */
|
|
|
|
|
n = u->offset;
|
2008-08-25 22:15:25 -03:00
|
|
|
if (ioctl(u->stream_fd, SIOCOUTQ, &l) >= 0 && l > 0)
|
2008-09-29 21:43:28 +02:00
|
|
|
n -= (uint64_t) l;
|
2008-08-17 20:36:33 -03:00
|
|
|
usec = pa_bytes_to_usec(n, &u->sink->sample_spec);
|
|
|
|
|
if (usec > u->latency)
|
|
|
|
|
usec -= u->latency;
|
|
|
|
|
else
|
|
|
|
|
usec = 0;
|
|
|
|
|
pa_smoother_put(u->smoother, pa_rtclock_usec(), usec);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Hmm, nothing to do. Let's sleep */
|
2008-08-26 09:43:48 -03:00
|
|
|
pa_log_debug("IO thread going to sleep");
|
2008-09-29 21:43:28 +02:00
|
|
|
pollfd->events = (short) (PA_SINK_IS_OPENED(u->sink->thread_info.state) ? POLLOUT : 0);
|
2008-08-17 20:36:33 -03:00
|
|
|
if ((ret = pa_rtpoll_run(u->rtpoll, TRUE)) < 0) {
|
2008-08-19 17:35:43 -03:00
|
|
|
pa_log_error("rtpoll_run < 0");
|
2008-08-17 20:36:33 -03:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2008-08-26 09:43:48 -03:00
|
|
|
pa_log_debug("IO thread waking up");
|
2008-08-17 20:36:33 -03:00
|
|
|
|
|
|
|
|
if (ret == 0) {
|
2008-08-20 10:52:25 -03:00
|
|
|
pa_log_debug("rtpoll_run == 0");
|
2008-08-17 20:36:33 -03:00
|
|
|
goto finish;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
|
|
|
|
if (pollfd->revents & ~POLLOUT) {
|
2008-08-19 16:06:21 -03:00
|
|
|
pa_log_error("FIFO shutdown.");
|
2008-08-17 20:36:33 -03:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fail:
|
|
|
|
|
/* If this was no regular exit from the loop we have to continue processing messages until we receive PA_MESSAGE_SHUTDOWN */
|
2008-08-26 09:43:48 -03:00
|
|
|
pa_log_debug("IO thread failed");
|
2008-08-17 20:36:33 -03:00
|
|
|
pa_asyncmsgq_post(u->thread_mq.outq, PA_MSGOBJECT(u->core), PA_CORE_MESSAGE_UNLOAD_MODULE, u->module, 0, NULL, NULL);
|
|
|
|
|
pa_asyncmsgq_wait_for(u->thread_mq.inq, PA_MESSAGE_SHUTDOWN);
|
|
|
|
|
|
|
|
|
|
finish:
|
2008-08-26 09:43:48 -03:00
|
|
|
pa_log_debug("IO thread shutting down");
|
2008-08-17 20:36:33 -03:00
|
|
|
}
|
|
|
|
|
|
2009-01-19 14:53:35 +02:00
|
|
|
static DBusHandlerResult filter_cb(DBusConnection *bus, DBusMessage *msg, void *userdata) {
|
|
|
|
|
DBusMessageIter arg_i;
|
|
|
|
|
DBusError err;
|
|
|
|
|
const char *value;
|
|
|
|
|
struct userdata *u;
|
|
|
|
|
|
|
|
|
|
pa_assert(bus);
|
|
|
|
|
pa_assert(msg);
|
|
|
|
|
pa_assert(userdata);
|
|
|
|
|
u = userdata;
|
|
|
|
|
|
|
|
|
|
pa_log_debug("dbus: interface=%s, path=%s, member=%s\n",
|
|
|
|
|
dbus_message_get_interface(msg),
|
|
|
|
|
dbus_message_get_path(msg),
|
|
|
|
|
dbus_message_get_member(msg));
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&err);
|
|
|
|
|
|
|
|
|
|
if (dbus_message_is_signal(msg, "org.bluez.Headset", "PropertyChanged") ||
|
|
|
|
|
dbus_message_is_signal(msg, "org.bluez.AudioSink", "PropertyChanged")) {
|
|
|
|
|
|
|
|
|
|
struct device *d;
|
|
|
|
|
const char *profile;
|
|
|
|
|
DBusMessageIter variant_i;
|
|
|
|
|
dbus_uint16_t gain;
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_iter_init(msg, &arg_i)) {
|
|
|
|
|
pa_log("dbus: message has no parameters");
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_STRING) {
|
|
|
|
|
pa_log("Property name not a string.");
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_get_basic(&arg_i, &value);
|
|
|
|
|
|
|
|
|
|
if (!dbus_message_iter_next(&arg_i)) {
|
|
|
|
|
pa_log("Property value missing");
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&arg_i) != DBUS_TYPE_VARIANT) {
|
|
|
|
|
pa_log("Property value not a variant.");
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_message_iter_recurse(&arg_i, &variant_i);
|
|
|
|
|
|
|
|
|
|
if (dbus_message_iter_get_arg_type(&variant_i) != DBUS_TYPE_UINT16) {
|
|
|
|
|
dbus_message_iter_get_basic(&variant_i, &gain);
|
|
|
|
|
|
|
|
|
|
if (pa_streq(value, "SpeakerGain")) {
|
|
|
|
|
pa_log("spk gain: %d", gain);
|
2009-01-28 04:49:07 +01:00
|
|
|
pa_cvolume_set(&u->sink->virtual_volume, 1, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
|
2009-01-19 14:53:35 +02:00
|
|
|
pa_subscription_post(u->sink->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, u->sink->index);
|
|
|
|
|
} else {
|
|
|
|
|
pa_log("mic gain: %d", gain);
|
|
|
|
|
if (!u->source)
|
|
|
|
|
goto done;
|
|
|
|
|
|
2009-01-28 04:49:07 +01:00
|
|
|
pa_cvolume_set(&u->source->virtual_volume, 1, (pa_volume_t) (gain * PA_VOLUME_NORM / 15));
|
2009-01-19 14:53:35 +02:00
|
|
|
pa_subscription_post(u->source->core, PA_SUBSCRIPTION_EVENT_SOURCE|PA_SUBSCRIPTION_EVENT_CHANGE, u->source->index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
dbus_error_free(&err);
|
|
|
|
|
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int sink_get_volume_cb(pa_sink *s) {
|
|
|
|
|
struct userdata *u = s->userdata;
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
/* refresh? */
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int source_get_volume_cb(pa_source *s) {
|
|
|
|
|
struct userdata *u = s->userdata;
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
/* refresh? */
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int sink_set_volume_cb(pa_sink *s) {
|
|
|
|
|
DBusError e;
|
|
|
|
|
DBusMessage *m, *r;
|
|
|
|
|
DBusMessageIter it, itvar;
|
|
|
|
|
dbus_uint16_t vol;
|
|
|
|
|
const char *spkgain = "SpeakerGain";
|
|
|
|
|
struct userdata *u = s->userdata;
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
dbus_error_init(&e);
|
|
|
|
|
|
2009-01-28 04:49:07 +01:00
|
|
|
vol = ((float) pa_cvolume_max(&s->virtual_volume) / PA_VOLUME_NORM) * 15;
|
2009-01-19 14:53:35 +02:00
|
|
|
pa_log_debug("set headset volume: %d", vol);
|
|
|
|
|
|
|
|
|
|
pa_assert_se(m = dbus_message_new_method_call("org.bluez", u->path, "org.bluez.Headset", "SetProperty"));
|
|
|
|
|
dbus_message_iter_init_append(m, &it);
|
|
|
|
|
dbus_message_iter_append_basic(&it, DBUS_TYPE_STRING, &spkgain);
|
|
|
|
|
dbus_message_iter_open_container(&it, DBUS_TYPE_VARIANT, DBUS_TYPE_UINT16_AS_STRING, &itvar);
|
|
|
|
|
dbus_message_iter_append_basic(&itvar, DBUS_TYPE_UINT16, &vol);
|
|
|
|
|
dbus_message_iter_close_container(&it, &itvar);
|
|
|
|
|
|
|
|
|
|
r = dbus_connection_send_with_reply_and_block(pa_dbus_connection_get(u->conn), m, -1, &e);
|
|
|
|
|
|
|
|
|
|
finish:
|
|
|
|
|
if (m)
|
|
|
|
|
dbus_message_unref(m);
|
|
|
|
|
if (r)
|
|
|
|
|
dbus_message_unref(r);
|
|
|
|
|
|
|
|
|
|
dbus_error_free(&e);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int source_set_volume_cb(pa_source *s) {
|
|
|
|
|
dbus_uint16_t vol;
|
|
|
|
|
struct userdata *u = s->userdata;
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
2009-01-28 04:49:07 +01:00
|
|
|
vol = ((float)pa_cvolume_max(&s->virtual_volume) / PA_VOLUME_NORM) * 15;
|
2009-01-19 14:53:35 +02:00
|
|
|
|
|
|
|
|
pa_log_debug("set headset mic volume: %d (not implemented yet)", vol);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
static char *get_name(const char *type, pa_modargs *ma, const char *device_id, pa_bool_t *namereg_fail) {
|
|
|
|
|
char *t;
|
|
|
|
|
const char *n;
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
pa_assert(type);
|
|
|
|
|
pa_assert(ma);
|
|
|
|
|
pa_assert(device_id);
|
|
|
|
|
pa_assert(namereg_fail);
|
2009-01-19 14:53:35 +02:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
t = pa_sprintf_malloc("%s_name", type);
|
|
|
|
|
n = pa_modargs_get_value(ma, t, NULL);
|
|
|
|
|
pa_xfree(t);
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
if (n) {
|
|
|
|
|
*namereg_fail = TRUE;
|
|
|
|
|
return pa_xstrdup(n);
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
2009-01-29 16:27:27 +01:00
|
|
|
|
|
|
|
|
if ((n = pa_modargs_get_value(ma, "name", NULL)))
|
|
|
|
|
*namereg_fail = TRUE;
|
|
|
|
|
else {
|
|
|
|
|
n = device_id;
|
|
|
|
|
*namereg_fail = FALSE;
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
2009-01-29 16:27:27 +01:00
|
|
|
|
|
|
|
|
return pa_sprintf_malloc("bluez_%s.%s", type, n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int add_sink(struct userdata *u) {
|
|
|
|
|
pa_sink_new_data data;
|
|
|
|
|
pa_bool_t b;
|
|
|
|
|
|
|
|
|
|
pa_sink_new_data_init(&data);
|
|
|
|
|
data.driver = __FILE__;
|
|
|
|
|
data.module = m;
|
|
|
|
|
pa_sink_new_data_set_sample_spec(&data, &u->ss);
|
|
|
|
|
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Bluetooth %s on %s", u->profile == PROFILE_A2DP ? "A2DP" : "HSP/HFP", u->addr);
|
|
|
|
|
pa_proplist_sets(data.proplist, "bluetooth.protocol", u->profile == PROFILE_A2DP ? "a2dp" : "sco");
|
|
|
|
|
data.card = u->card;
|
|
|
|
|
data.name = get_name("sink", ma, u->addr, &b);
|
|
|
|
|
data.namereg_fail = b;
|
|
|
|
|
|
|
|
|
|
u->sink = pa_sink_new(u->core, &data, PA_SINK_HARDWARE|PA_SINK_LATENCY);
|
|
|
|
|
pa_sink_new_data_done(&data);
|
|
|
|
|
|
|
|
|
|
if (!u->sink) {
|
|
|
|
|
pa_log_error("Failed to create sink");
|
|
|
|
|
return -1;
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
2008-09-29 21:40:52 +02:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
u->sink->userdata = u;
|
|
|
|
|
u->sink->parent.process_msg = sink_process_msg;
|
|
|
|
|
u->sink->get_volume = sink_get_volume_cb;
|
|
|
|
|
u->sink->set_volume = sink_set_volume_cb;
|
|
|
|
|
|
|
|
|
|
pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq);
|
|
|
|
|
pa_sink_set_rtpoll(u->sink, u->rtpoll);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int add_source(struct userdata *u) {
|
|
|
|
|
pa_source_new_data data;
|
|
|
|
|
pa_bool_t b;
|
|
|
|
|
|
|
|
|
|
pa_source_new_data_init(&data);
|
|
|
|
|
data.driver = __FILE__;
|
|
|
|
|
data.module = m;
|
|
|
|
|
pa_source_new_data_set_sample_spec(&data, &u->ss);
|
|
|
|
|
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Bluetooth %s on %s", u->profile == PROFILE_A2DP ? "A2DP" : "HSP/HFP", u->addr);
|
|
|
|
|
pa_proplist_sets(data.proplist, "bluetooth.protocol", u->profile == PROFILE_A2DP ? "a2dp" : "sco");
|
|
|
|
|
data.card = u->card;
|
|
|
|
|
data.name = get_name("source", ma, u->addr, &b);
|
|
|
|
|
data.namereg_fail = b;
|
|
|
|
|
|
|
|
|
|
u->source = pa_source_new(u->core, &data, PA_SOURCE_HARDWARE|PA_SOURCE_LATENCY);
|
|
|
|
|
pa_source_new_data_done(&data);
|
|
|
|
|
|
|
|
|
|
if (!u->source) {
|
|
|
|
|
pa_log_error("Failed to create source");
|
|
|
|
|
return -1;
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
2009-01-29 16:27:27 +01:00
|
|
|
|
|
|
|
|
u->source->userdata = u;
|
|
|
|
|
u->source->parent.process_msg = source_process_msg;
|
|
|
|
|
u->source->get_volume = source_get_volume_cb;
|
|
|
|
|
u->source->set_volume = source_set_volume_cb;
|
|
|
|
|
|
|
|
|
|
pa_source_set_asyncmsgq(u->source, u->thread_mq.inq);
|
|
|
|
|
pa_source_set_rtpoll(u->source, u->rtpoll);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void init_profile(struct userdata *u) {
|
|
|
|
|
enum profile *d;
|
|
|
|
|
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
|
|
|
|
if (u->profile == PROFILE_A2DP ||
|
|
|
|
|
u->profile == PROFILE_SCO)
|
|
|
|
|
add_sink(u);
|
|
|
|
|
|
|
|
|
|
if (u->profile == PROFILE_SCO)
|
|
|
|
|
add_source(u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int init_bt(struct userdata *u) {
|
|
|
|
|
pa_assert(u);
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
/* connect to the bluez audio service */
|
2009-01-29 16:27:27 +01:00
|
|
|
if ((u->audioservice_fd = bt_audio_service_open()) < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Couldn't connect to bluetooth audio service");
|
2009-01-29 16:27:27 +01:00
|
|
|
return -1;
|
2008-07-31 20:16:43 -03:00
|
|
|
}
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_debug("Connected to the bluetooth audio service");
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
/* queries device capabilities */
|
2009-01-29 16:27:27 +01:00
|
|
|
if (bt_getcaps(u) < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to get device capabilities");
|
2009-01-29 16:27:27 +01:00
|
|
|
return -1;
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_debug("Got device capabilities");
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static setup_bt(struct userdata *u) {
|
|
|
|
|
pa_assert(u);
|
|
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
/* configures the connection */
|
2009-01-29 16:27:27 +01:00
|
|
|
if (bt_setconf(u) < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to set config");
|
2009-01-29 16:27:27 +01:00
|
|
|
return -1;
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_debug("Connection to the device configured");
|
2008-08-11 13:27:13 -03:00
|
|
|
|
|
|
|
|
/* gets the device socket */
|
2009-01-29 16:27:27 +01:00
|
|
|
if (bt_getstreamfd(u) < 0) {
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_error("Failed to get stream fd (%d)", e);
|
2009-01-29 16:27:27 +01:00
|
|
|
return -1;
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_log_debug("Got the device socket");
|
2009-01-29 16:27:27 +01:00
|
|
|
}
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
static int card_set_profile(pa_card *c, pa_card_profile *new_profile) {
|
|
|
|
|
struct userdata *u;
|
|
|
|
|
enum profile *d;
|
|
|
|
|
pa_queue *inputs = NULL, *outputs = NULL;
|
|
|
|
|
|
|
|
|
|
pa_assert(c);
|
|
|
|
|
pa_assert(new_profile);
|
|
|
|
|
pa_assert_se(u = c->userdata);
|
|
|
|
|
|
|
|
|
|
d = PA_CARD_PROFILE_DATA(new_profile);
|
|
|
|
|
|
|
|
|
|
if (u->sink) {
|
|
|
|
|
inputs = pa_sink_move_all_start(u->sink);
|
|
|
|
|
|
|
|
|
|
pa_sink_unlink(u->sink);
|
|
|
|
|
pa_sink_unref(u->sink);
|
|
|
|
|
u->sink = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->source) {
|
|
|
|
|
outputs = pa_source_move_all_start(u->source);
|
|
|
|
|
|
|
|
|
|
pa_source_unlink(u->source);
|
|
|
|
|
pa_source_unref(u->source);
|
|
|
|
|
u->source = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u->profile = *d;
|
|
|
|
|
|
|
|
|
|
init_profile(u);
|
|
|
|
|
|
|
|
|
|
if (inputs) {
|
|
|
|
|
if (u->sink)
|
|
|
|
|
pa_sink_move_all_finish(u->sink, inputs, FALSE);
|
|
|
|
|
else
|
|
|
|
|
pa_sink_move_all_fail(inputs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (outputs) {
|
|
|
|
|
if (u->source)
|
|
|
|
|
pa_source_move_all_finish(u->source, outputs, FALSE);
|
|
|
|
|
else
|
|
|
|
|
pa_source_move_all_fail(outputs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int add_card(struct userdata *u) {
|
|
|
|
|
pa_card_new_data data;
|
|
|
|
|
pa_bool_t b;
|
|
|
|
|
pa_card_profile *p;
|
|
|
|
|
enum profile *d;
|
|
|
|
|
|
|
|
|
|
pa_card_new_data_init(&data);
|
2008-08-11 13:27:13 -03:00
|
|
|
data.driver = __FILE__;
|
2009-01-29 16:27:27 +01:00
|
|
|
data.module = u->module;
|
|
|
|
|
pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, u->addr);
|
2008-08-25 22:48:27 -03:00
|
|
|
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_API, "bluez");
|
|
|
|
|
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_CLASS, "sound");
|
|
|
|
|
pa_proplist_setf(data.proplist, PA_PROP_DEVICE_CONNECTOR, "bluetooth");
|
2008-09-29 21:43:28 +02:00
|
|
|
/* pa_proplist_setf(data.proplist, PA_PROP_DEVICE_FORM_FACTOR, "headset"); /\*FIXME*\/ */
|
|
|
|
|
/* pa_proplist_setf(data.proplist, PA_PROP_DEVICE_VENDOR_PRODUCT_ID, "product_id"); /\*FIXME*\/ */
|
|
|
|
|
/* pa_proplist_setf(data.proplist, PA_PROP_DEVICE_SERIAL, "serial"); /\*FIXME*\/ */
|
2009-01-29 16:27:27 +01:00
|
|
|
data.name = get_name("card", ma, u->addr, &b);
|
|
|
|
|
data.namereg_fail = b;
|
|
|
|
|
|
|
|
|
|
data.profiles = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
|
|
|
|
|
|
|
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP ||
|
|
|
|
|
u->transport == BT_CAPABILITIES_TRANSPORT_ANY) {
|
|
|
|
|
|
|
|
|
|
p = pa_card_profile_new("a2dp", "A2DP Advanced Audio Distribution Profile", sizeof(enum profile));
|
|
|
|
|
p->priority = 10;
|
|
|
|
|
p->n_sinks = 1;
|
|
|
|
|
p->n_sources = 0;
|
|
|
|
|
p->max_sink_channels = 2;
|
|
|
|
|
p->max_source_channels = 0;
|
|
|
|
|
|
|
|
|
|
d = PA_CARD_PROFILE_DATA(p);
|
|
|
|
|
*d = PROFILE_A2DP;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_SCO ||
|
|
|
|
|
u->transport == BT_CAPABILITIES_TRANSPORT_ANY) {
|
|
|
|
|
|
|
|
|
|
p = pa_card_profile_new("hsp", "HSP/HFP Headset/Hands-Free Profile", sizeof(enum profile));
|
|
|
|
|
p->priority = 20;
|
|
|
|
|
p->n_sinks = 1;
|
|
|
|
|
p->n_sources = 1;
|
|
|
|
|
p->max_sink_channels = 1;
|
|
|
|
|
p->max_source_channels = 1;
|
|
|
|
|
|
|
|
|
|
d = PA_CARD_PROFILE_DATA(p);
|
|
|
|
|
*d = PROFILE_SCO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pa_assert(!pa_hashmap_isempty(data.profiles));
|
|
|
|
|
|
|
|
|
|
p = pa_card_profile_new("off", "Off", sizeof(enum profile));
|
|
|
|
|
d = PA_CARD_PROFILE_DATA(p);
|
|
|
|
|
*d = PROFILE_OFF;
|
|
|
|
|
|
|
|
|
|
u->card = pa_card_new(m->core, &data);
|
|
|
|
|
pa_card_new_data_done(&data);
|
|
|
|
|
|
|
|
|
|
if (!u->card) {
|
|
|
|
|
pa_log("Failed to allocate card.");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
card->userdata = u;
|
|
|
|
|
card->set_profile = card_set_profile;
|
|
|
|
|
|
|
|
|
|
d = PA_CARD_PROFILE_DATA(u->card->active_profile);
|
|
|
|
|
u->profile = *d;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pa__init(pa_module* m) {
|
|
|
|
|
pa_modargs *ma;
|
|
|
|
|
uint32_t channels;
|
|
|
|
|
pa_sink_new_data sink_data;
|
|
|
|
|
pa_source_new_data source_data;
|
|
|
|
|
pa_card card_data;
|
|
|
|
|
struct pollfd *pollfd;
|
|
|
|
|
struct userdata *u;
|
|
|
|
|
pa_bool_t b;
|
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
if (!(ma = pa_modargs_new(m->argument, valid_modargs))) {
|
|
|
|
|
pa_log_error("Failed to parse module arguments");
|
2008-08-11 13:27:13 -03:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
m->userdata = u = pa_xnew0(struct userdata, 1);
|
|
|
|
|
u->module = m;
|
|
|
|
|
u->core = m->core;
|
|
|
|
|
u->audioservice_fd = -1;
|
|
|
|
|
u->stream_fd = -1;
|
|
|
|
|
u->transport = (uint8_t) -1;
|
|
|
|
|
u->smoother = pa_smoother_new(PA_USEC_PER_SEC, PA_USEC_PER_SEC*2, TRUE, 10);
|
|
|
|
|
u->rtpoll = pa_rtpoll_new();
|
|
|
|
|
pa_thread_mq_init(&u->thread_mq, u->core->mainloop, u->rtpoll);
|
|
|
|
|
u->add_source = m->core->default_sample_spec;
|
2008-08-15 16:23:54 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
if (!(u->address = pa_xstrdup(pa_modargs_get_value(ma, "address", NULL)))) {
|
|
|
|
|
pa_log_error("Failed to get device address from module arguments");
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u->path = pa_xstrdup(pa_modargs_get_value(ma, "path", NULL));
|
|
|
|
|
|
|
|
|
|
p = pa_modargs_get_value(ma, "profile", NULL);
|
|
|
|
|
if (p && !pa_streq(p, "hsp") && !pa_streq(p, "a2dp")) {
|
|
|
|
|
pa_log_error("Failed to get profile from module arguments");
|
2008-08-26 09:43:48 -03:00
|
|
|
goto fail;
|
2008-08-11 13:27:13 -03:00
|
|
|
}
|
2009-01-29 16:27:27 +01:00
|
|
|
|
|
|
|
|
if (pa_modargs_get_value_u32(ma, "rate", &u->ss.rate) < 0 ||
|
|
|
|
|
u->ss.rate <= 0 || u->ss.rate > PA_RATE_MAX) {
|
|
|
|
|
pa_log_error("Failed to get rate from module arguments");
|
2009-01-19 14:53:35 +02:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2008-08-11 13:27:13 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
channels = u->ss.channels;
|
|
|
|
|
if (pa_modargs_get_value_u32(ma, "channels", &channels) < 0 ||
|
|
|
|
|
channels <= 0 || channels > PA_CHANNELS_MAX) {
|
|
|
|
|
pa_log_error("Failed to get channels from module arguments");
|
2009-01-19 14:53:35 +02:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2009-01-29 16:27:27 +01:00
|
|
|
u->ss.channels = (uint8_t) channels;
|
|
|
|
|
|
|
|
|
|
/* Connect to the BT service and query capabilities */
|
|
|
|
|
if (init_bt(u) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
/* Add the card structure. This will also initialize the default profile */
|
|
|
|
|
if (add_card(u) < 0)
|
|
|
|
|
goto fail;
|
2009-01-19 14:53:35 +02:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
/* Now configure the the right profile */
|
|
|
|
|
if (setup_bt(u) < 0)
|
2009-01-19 14:53:35 +02:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
if (init_profile(u) < 0)
|
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
|
|
if (u->path) {
|
|
|
|
|
DBusError err;
|
|
|
|
|
dbus_error_init(&err);
|
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
|
|
u->conn = pa_dbus_bus_get(m->core, DBUS_BUS_SYSTEM, &err);
|
|
|
|
|
if (dbus_error_is_set(&err) || (!u->conn)) {
|
|
|
|
|
pa_log("Failed to get D-Bus connection: %s", err.message);
|
2009-01-19 14:53:35 +02:00
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
if (!dbus_connection_add_filter(pa_dbus_connection_get(u->conn), filter_cb, u, NULL)) {
|
|
|
|
|
pa_log_error("Failed to add filter function");
|
2009-01-19 14:53:35 +02:00
|
|
|
goto fail;
|
|
|
|
|
}
|
2009-01-29 16:27:27 +01:00
|
|
|
|
|
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_SCO ||
|
|
|
|
|
u->transport == BT_CAPABILITIES_TRANSPORT_ANY) {
|
|
|
|
|
t = pa_sprintf_malloc("type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged',path='%s'", u->path);
|
|
|
|
|
dbus_bus_add_match(pa_dbus_connection_get(u->conn), t, &err);
|
|
|
|
|
pa_xfree(t);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&err)) {
|
|
|
|
|
pa_log_error("Unable to subscribe to org.bluez.Headset signals: %s: %s", err.name, err.message);
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP ||
|
|
|
|
|
u->transport == BT_CAPABILITIES_TRANSPORT_ANY) {
|
|
|
|
|
t = pa_sprintf_malloc("type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged',path='%s'", u->path);
|
|
|
|
|
dbus_bus_add_match(pa_dbus_connection_get(u->conn), t, &err);
|
|
|
|
|
pa_xfree(t);
|
|
|
|
|
|
|
|
|
|
if (dbus_error_is_set(&err)) {
|
|
|
|
|
pa_log_error("Unable to subscribe to org.bluez.AudioSink signals: %s: %s", err.name, err.message);
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-19 14:53:35 +02:00
|
|
|
}
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1);
|
|
|
|
|
pollfd = pa_rtpoll_item_get_pollfd(u->rtpoll_item, NULL);
|
|
|
|
|
pollfd->fd = u->stream_fd;
|
|
|
|
|
pollfd->events = pollfd->revents = 0;
|
|
|
|
|
|
|
|
|
|
if (!(u->thread = pa_thread_new(thread_func, u))) {
|
|
|
|
|
pa_log_error("Failed to create IO thread");
|
|
|
|
|
goto fail;
|
2009-01-19 14:53:35 +02:00
|
|
|
}
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
if (u->sink)
|
|
|
|
|
pa_sink_put(u->sink);
|
|
|
|
|
|
|
|
|
|
if (u->source)
|
|
|
|
|
pa_sink_put(u->source);
|
|
|
|
|
|
2008-08-11 13:27:13 -03:00
|
|
|
pa_modargs_free(ma);
|
2008-07-31 20:16:43 -03:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
fail:
|
2008-08-11 13:27:13 -03:00
|
|
|
if (ma)
|
|
|
|
|
pa_modargs_free(ma);
|
2008-09-29 21:43:28 +02:00
|
|
|
|
2008-07-31 20:16:43 -03:00
|
|
|
pa__done(m);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
int pa__get_n_used(pa_module *m) {
|
|
|
|
|
struct userdata *u;
|
|
|
|
|
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
pa_assert_se(u = m->userdata);
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
(u->sink ? pa_sink_linked_by(u->sink) : 0) +
|
|
|
|
|
(u->source ? pa_source_linked_by(u->source) : 0);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-31 20:16:43 -03:00
|
|
|
void pa__done(pa_module *m) {
|
2008-08-20 10:52:25 -03:00
|
|
|
struct userdata *u;
|
|
|
|
|
pa_assert(m);
|
|
|
|
|
|
|
|
|
|
if (!(u = m->userdata))
|
|
|
|
|
return;
|
|
|
|
|
|
2009-01-19 14:53:35 +02:00
|
|
|
if (u->conn) {
|
|
|
|
|
DBusError error;
|
2009-01-29 16:27:27 +01:00
|
|
|
char *t;
|
2009-01-19 14:53:35 +02:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_SCO ||
|
|
|
|
|
u->transport == BT_CAPABILITIES_TRANSPORT_ANY) {
|
|
|
|
|
|
|
|
|
|
t = pa_sprintf_malloc("type='signal',sender='org.bluez',interface='org.bluez.Headset',member='PropertyChanged',path='%s'", u->path);
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
dbus_bus_remove_match(pa_dbus_connection_get(u->conn), t, &error);
|
2009-01-19 14:53:35 +02:00
|
|
|
dbus_error_free(&error);
|
2009-01-29 16:27:27 +01:00
|
|
|
pa_xfree(t);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->transport == BT_CAPABILITIES_TRANSPORT_A2DP ||
|
|
|
|
|
u->transport == BT_CAPABILITIES_TRANSPORT_ANY) {
|
|
|
|
|
|
|
|
|
|
t = pa_sprintf_malloc("type='signal',sender='org.bluez',interface='org.bluez.AudioSink',member='PropertyChanged',path='%s'", u->path);
|
|
|
|
|
dbus_error_init(&error);
|
|
|
|
|
dbus_bus_remove_match(pa_dbus_connection_get(u->conn), t, &error);
|
2009-01-19 14:53:35 +02:00
|
|
|
dbus_error_free(&error);
|
2009-01-29 16:27:27 +01:00
|
|
|
pa_xfree(t);
|
2009-01-19 14:53:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dbus_connection_remove_filter(pa_dbus_connection_get(u->conn), filter_cb, u);
|
|
|
|
|
pa_dbus_connection_unref(u->conn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->path)
|
|
|
|
|
pa_xfree(u->path);
|
|
|
|
|
|
2008-08-20 10:52:25 -03:00
|
|
|
if (u->sink)
|
|
|
|
|
pa_sink_unlink(u->sink);
|
|
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
if (u->source)
|
|
|
|
|
pa_source_unlink(u->source);
|
|
|
|
|
|
2008-08-20 10:52:25 -03:00
|
|
|
if (u->thread) {
|
|
|
|
|
pa_asyncmsgq_send(u->thread_mq.inq, NULL, PA_MESSAGE_SHUTDOWN, NULL, 0, NULL);
|
|
|
|
|
pa_thread_free(u->thread);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->sink)
|
|
|
|
|
pa_sink_unref(u->sink);
|
2008-07-31 20:16:43 -03:00
|
|
|
|
2009-01-29 16:27:27 +01:00
|
|
|
if (u->source)
|
|
|
|
|
pa_source_unref(u->source);
|
|
|
|
|
|
|
|
|
|
if (u->card)
|
|
|
|
|
pa_card_unref(u->card);
|
|
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_thread_mq_done(&u->thread_mq);
|
|
|
|
|
|
2008-08-20 10:52:25 -03:00
|
|
|
if (u->rtpoll_item)
|
|
|
|
|
pa_rtpoll_item_free(u->rtpoll_item);
|
|
|
|
|
|
|
|
|
|
if (u->rtpoll)
|
|
|
|
|
pa_rtpoll_free(u->rtpoll);
|
|
|
|
|
|
|
|
|
|
if (u->smoother)
|
|
|
|
|
pa_smoother_free(u->smoother);
|
|
|
|
|
|
2008-09-29 21:43:28 +02:00
|
|
|
pa_xfree(u->name);
|
|
|
|
|
pa_xfree(u->addr);
|
|
|
|
|
pa_xfree(u->profile);
|
|
|
|
|
pa_xfree(u->strtransport);
|
2008-08-21 17:06:41 -03:00
|
|
|
|
2008-08-20 10:52:25 -03:00
|
|
|
if (u->stream_fd >= 0)
|
|
|
|
|
pa_close(u->stream_fd);
|
|
|
|
|
|
|
|
|
|
if (u->audioservice_fd >= 0)
|
2009-01-29 16:27:27 +01:00
|
|
|
pa_close(u->service_fd);
|
2008-08-20 10:52:25 -03:00
|
|
|
|
|
|
|
|
pa_xfree(u);
|
|
|
|
|
}
|