bluez: Fix use of deprecated glib on audio plugin

This commit is contained in:
Luiz Augusto von Dentz 2011-01-19 10:04:49 +02:00 committed by Tim-Philipp Müller
parent c3afd98226
commit 1396082264

View file

@ -121,9 +121,9 @@ static GstStaticPadTemplate avdtp_sink_factory =
GST_RTP_PAYLOAD_DYNAMIC_STRING ", " GST_RTP_PAYLOAD_DYNAMIC_STRING ", "
"clock-rate = (int) 90000, " "encoding-name = (string) \"MPA\"")); "clock-rate = (int) 90000, " "encoding-name = (string) \"MPA\""));
static GIOError gst_avdtp_sink_audioservice_send (GstAvdtpSink * self, static int gst_avdtp_sink_audioservice_send (GstAvdtpSink * self,
const bt_audio_msg_header_t * msg); const bt_audio_msg_header_t * msg);
static GIOError gst_avdtp_sink_audioservice_expect (GstAvdtpSink * self, static int gst_avdtp_sink_audioservice_expect (GstAvdtpSink * self,
bt_audio_msg_header_t * outmsg, guint8 expected_name); bt_audio_msg_header_t * outmsg, guint8 expected_name);
@ -289,6 +289,7 @@ gst_avdtp_sink_bluetooth_recvmsg_fd (GstAvdtpSink * sink)
} }
sink->stream = g_io_channel_unix_new (ret); sink->stream = g_io_channel_unix_new (ret);
g_io_channel_set_encoding (sink->stream, NULL, NULL);
GST_DEBUG_OBJECT (sink, "stream_fd=%d", ret); GST_DEBUG_OBJECT (sink, "stream_fd=%d", ret);
return 0; return 0;
@ -413,11 +414,10 @@ gst_avdtp_sink_conf_recv_stream_fd (GstAvdtpSink * self)
{ {
struct bluetooth_data *data = self->data; struct bluetooth_data *data = self->data;
gint ret; gint ret;
GIOError err;
GError *gerr = NULL; GError *gerr = NULL;
GIOStatus status; GIOStatus status;
GIOFlags flags; GIOFlags flags;
gsize read; int fd;
/* Proceed if stream was already acquired */ /* Proceed if stream was already acquired */
if (self->stream != NULL) if (self->stream != NULL)
@ -448,13 +448,14 @@ proceed:
"setting server " "socket to nonblock"); "setting server " "socket to nonblock");
} }
fd = g_io_channel_unix_get_fd (self->stream);
/* It is possible there is some outstanding /* It is possible there is some outstanding
data in the pipe - we have to empty it */ data in the pipe - we have to empty it */
GST_LOG_OBJECT (self, "emptying stream pipe"); GST_LOG_OBJECT (self, "emptying stream pipe");
while (1) { while (1) {
err = g_io_channel_read (self->stream, data->buffer, ssize_t bread = read (fd, data->buffer, data->link_mtu);
(gsize) data->link_mtu, &read); if (bread <= 0)
if (err != G_IO_ERROR_NONE || read <= 0)
break; break;
} }
@ -1134,7 +1135,7 @@ gst_avdtp_sink_get_capabilities (GstAvdtpSink * self)
gchar *buf[BT_SUGGESTED_BUFFER_SIZE]; gchar *buf[BT_SUGGESTED_BUFFER_SIZE];
struct bt_get_capabilities_req *req = (void *) buf; struct bt_get_capabilities_req *req = (void *) buf;
struct bt_get_capabilities_rsp *rsp = (void *) buf; struct bt_get_capabilities_rsp *rsp = (void *) buf;
GIOError io_error; int err;
memset (req, 0, BT_SUGGESTED_BUFFER_SIZE); memset (req, 0, BT_SUGGESTED_BUFFER_SIZE);
@ -1148,16 +1149,15 @@ gst_avdtp_sink_get_capabilities (GstAvdtpSink * self)
if (self->autoconnect) if (self->autoconnect)
req->flags |= BT_FLAG_AUTOCONNECT; req->flags |= BT_FLAG_AUTOCONNECT;
io_error = gst_avdtp_sink_audioservice_send (self, &req->h); err = gst_avdtp_sink_audioservice_send (self, &req->h);
if (io_error != G_IO_ERROR_NONE) { if (err < 0) {
GST_ERROR_OBJECT (self, "Error while asking device caps"); GST_ERROR_OBJECT (self, "Error while asking device caps");
return FALSE; return FALSE;
} }
rsp->h.length = 0; rsp->h.length = 0;
io_error = gst_avdtp_sink_audioservice_expect (self, err = gst_avdtp_sink_audioservice_expect (self, &rsp->h, BT_GET_CAPABILITIES);
&rsp->h, BT_GET_CAPABILITIES); if (err < 0) {
if (io_error != G_IO_ERROR_NONE) {
GST_ERROR_OBJECT (self, "Error while getting device caps"); GST_ERROR_OBJECT (self, "Error while getting device caps");
return FALSE; return FALSE;
} }
@ -1347,6 +1347,7 @@ gst_avdtp_sink_transport_acquire (GstAvdtpSink * self)
dbus_message_unref (reply); dbus_message_unref (reply);
self->stream = g_io_channel_unix_new (fd); self->stream = g_io_channel_unix_new (fd);
g_io_channel_set_encoding (self->stream, NULL, NULL);
g_io_channel_set_close_on_unref (self->stream, TRUE); g_io_channel_set_close_on_unref (self->stream, TRUE);
GST_DEBUG_OBJECT (self, "stream_fd=%d", fd); GST_DEBUG_OBJECT (self, "stream_fd=%d", fd);
@ -1453,6 +1454,7 @@ gst_avdtp_sink_start (GstBaseSink * basesink)
} }
self->server = g_io_channel_unix_new (sk); self->server = g_io_channel_unix_new (sk);
g_io_channel_set_encoding (self->server, NULL, NULL);
self->watch_id = g_io_add_watch (self->server, G_IO_HUP | G_IO_ERR | self->watch_id = g_io_add_watch (self->server, G_IO_HUP | G_IO_ERR |
G_IO_NVAL, server_callback, self); G_IO_NVAL, server_callback, self);
@ -1475,7 +1477,7 @@ gst_avdtp_sink_stream_start (GstAvdtpSink * self)
struct bt_start_stream_req *req = (void *) buf; struct bt_start_stream_req *req = (void *) buf;
struct bt_start_stream_rsp *rsp = (void *) buf; struct bt_start_stream_rsp *rsp = (void *) buf;
struct bt_new_stream_ind *ind = (void *) buf; struct bt_new_stream_ind *ind = (void *) buf;
GIOError io_error; int err;
if (self->transport != NULL) if (self->transport != NULL)
return gst_avdtp_sink_conf_recv_stream_fd (self); return gst_avdtp_sink_conf_recv_stream_fd (self);
@ -1485,23 +1487,22 @@ gst_avdtp_sink_stream_start (GstAvdtpSink * self)
req->h.name = BT_START_STREAM; req->h.name = BT_START_STREAM;
req->h.length = sizeof (*req); req->h.length = sizeof (*req);
io_error = gst_avdtp_sink_audioservice_send (self, &req->h); err = gst_avdtp_sink_audioservice_send (self, &req->h);
if (io_error != G_IO_ERROR_NONE) { if (err < 0) {
GST_ERROR_OBJECT (self, "Error ocurred while sending " "start packet"); GST_ERROR_OBJECT (self, "Error ocurred while sending " "start packet");
return FALSE; return FALSE;
} }
rsp->h.length = sizeof (*rsp); rsp->h.length = sizeof (*rsp);
io_error = gst_avdtp_sink_audioservice_expect (self, err = gst_avdtp_sink_audioservice_expect (self, &rsp->h, BT_START_STREAM);
&rsp->h, BT_START_STREAM); if (err < 0) {
if (io_error != G_IO_ERROR_NONE) {
GST_ERROR_OBJECT (self, "Error while stream " "start confirmation"); GST_ERROR_OBJECT (self, "Error while stream " "start confirmation");
return FALSE; return FALSE;
} }
ind->h.length = sizeof (*ind); ind->h.length = sizeof (*ind);
io_error = gst_avdtp_sink_audioservice_expect (self, &ind->h, BT_NEW_STREAM); err = gst_avdtp_sink_audioservice_expect (self, &ind->h, BT_NEW_STREAM);
if (io_error != G_IO_ERROR_NONE) { if (err < 0) {
GST_ERROR_OBJECT (self, "Error while receiving " "stream filedescriptor"); GST_ERROR_OBJECT (self, "Error while receiving " "stream filedescriptor");
return FALSE; return FALSE;
} }
@ -1597,10 +1598,10 @@ gst_avdtp_sink_configure (GstAvdtpSink * self, GstCaps * caps)
struct bt_set_configuration_req *req = (void *) buf; struct bt_set_configuration_req *req = (void *) buf;
struct bt_set_configuration_rsp *rsp = (void *) buf; struct bt_set_configuration_rsp *rsp = (void *) buf;
gboolean ret; gboolean ret;
GIOError io_error;
gchar *temp; gchar *temp;
GstStructure *structure; GstStructure *structure;
codec_capabilities_t *codec = NULL; codec_capabilities_t *codec = NULL;
int err;
temp = gst_caps_to_string (caps); temp = gst_caps_to_string (caps);
GST_DEBUG_OBJECT (self, "configuring device with caps: %s", temp); GST_DEBUG_OBJECT (self, "configuring device with caps: %s", temp);
@ -1631,15 +1632,15 @@ gst_avdtp_sink_configure (GstAvdtpSink * self, GstCaps * caps)
open_req->seid = codec->seid; open_req->seid = codec->seid;
open_req->lock = BT_WRITE_LOCK; open_req->lock = BT_WRITE_LOCK;
io_error = gst_avdtp_sink_audioservice_send (self, &open_req->h); err = gst_avdtp_sink_audioservice_send (self, &open_req->h);
if (io_error != G_IO_ERROR_NONE) { if (err < 0) {
GST_ERROR_OBJECT (self, "Error ocurred while sending " "open packet"); GST_ERROR_OBJECT (self, "Error ocurred while sending " "open packet");
return FALSE; return FALSE;
} }
open_rsp->h.length = sizeof (*open_rsp); open_rsp->h.length = sizeof (*open_rsp);
io_error = gst_avdtp_sink_audioservice_expect (self, &open_rsp->h, BT_OPEN); err = gst_avdtp_sink_audioservice_expect (self, &open_rsp->h, BT_OPEN);
if (io_error != G_IO_ERROR_NONE) { if (err < 0) {
GST_ERROR_OBJECT (self, "Error while receiving device " "confirmation"); GST_ERROR_OBJECT (self, "Error while receiving device " "confirmation");
return FALSE; return FALSE;
} }
@ -1661,17 +1662,17 @@ gst_avdtp_sink_configure (GstAvdtpSink * self, GstCaps * caps)
} }
req->h.length += req->codec.length - sizeof (req->codec); req->h.length += req->codec.length - sizeof (req->codec);
io_error = gst_avdtp_sink_audioservice_send (self, &req->h); err = gst_avdtp_sink_audioservice_send (self, &req->h);
if (io_error != G_IO_ERROR_NONE) { if (err < 0) {
GST_ERROR_OBJECT (self, "Error ocurred while sending " GST_ERROR_OBJECT (self, "Error ocurred while sending "
"configurarion packet"); "configurarion packet");
return FALSE; return FALSE;
} }
rsp->h.length = sizeof (*rsp); rsp->h.length = sizeof (*rsp);
io_error = gst_avdtp_sink_audioservice_expect (self, err = gst_avdtp_sink_audioservice_expect (self, &rsp->h,
&rsp->h, BT_SET_CONFIGURATION); BT_SET_CONFIGURATION);
if (io_error != G_IO_ERROR_NONE) { if (err < 0) {
GST_ERROR_OBJECT (self, "Error while receiving device " "confirmation"); GST_ERROR_OBJECT (self, "Error while receiving device " "confirmation");
return FALSE; return FALSE;
} }
@ -1703,16 +1704,15 @@ static GstFlowReturn
gst_avdtp_sink_render (GstBaseSink * basesink, GstBuffer * buffer) gst_avdtp_sink_render (GstBaseSink * basesink, GstBuffer * buffer)
{ {
GstAvdtpSink *self = GST_AVDTP_SINK (basesink); GstAvdtpSink *self = GST_AVDTP_SINK (basesink);
gsize ret; ssize_t ret;
GIOError err; int fd;
err = g_io_channel_write (self->stream, fd = g_io_channel_unix_get_fd (self->stream);
(gchar *) GST_BUFFER_DATA (buffer),
(gsize) (GST_BUFFER_SIZE (buffer)), &ret);
if (err != G_IO_ERROR_NONE) { ret = write (fd, GST_BUFFER_DATA (buffer), GST_BUFFER_SIZE (buffer));
GST_ERROR_OBJECT (self, "Error while writting to socket: %d %s", if (ret < 0) {
errno, strerror (errno)); GST_ERROR_OBJECT (self, "Error while writting to socket: %s",
strerror (errno));
return GST_FLOW_ERROR; return GST_FLOW_ERROR;
} }
@ -1810,89 +1810,94 @@ gst_avdtp_sink_init (GstAvdtpSink * self, GstAvdtpSinkClass * klass)
*/ */
} }
static GIOError static int
gst_avdtp_sink_audioservice_send (GstAvdtpSink * self, gst_avdtp_sink_audioservice_send (GstAvdtpSink * self,
const bt_audio_msg_header_t * msg) const bt_audio_msg_header_t * msg)
{ {
GIOError error; ssize_t written;
gsize written;
const char *type, *name; const char *type, *name;
uint16_t length; uint16_t length;
int fd;
length = msg->length ? msg->length : BT_SUGGESTED_BUFFER_SIZE; length = msg->length ? msg->length : BT_SUGGESTED_BUFFER_SIZE;
error = g_io_channel_write (self->server, (const gchar *) msg, length, fd = g_io_channel_unix_get_fd (self->server);
&written);
if (error != G_IO_ERROR_NONE) written = write (fd, msg, length);
if (written < 0) {
GST_ERROR_OBJECT (self, "Error sending data to audio service:" GST_ERROR_OBJECT (self, "Error sending data to audio service:"
" %s(%d)", strerror (errno), errno); " %s", strerror (errno));
return -errno;
}
type = bt_audio_strtype (msg->type); type = bt_audio_strtype (msg->type);
name = bt_audio_strname (msg->name); name = bt_audio_strname (msg->name);
GST_DEBUG_OBJECT (self, "sent: %s -> %s", type, name); GST_DEBUG_OBJECT (self, "sent: %s -> %s", type, name);
return error; return 0;
} }
static GIOError static int
gst_avdtp_sink_audioservice_recv (GstAvdtpSink * self, gst_avdtp_sink_audioservice_recv (GstAvdtpSink * self,
bt_audio_msg_header_t * inmsg) bt_audio_msg_header_t * inmsg)
{ {
GIOError status; ssize_t bytes_read;
gsize bytes_read;
const char *type, *name; const char *type, *name;
uint16_t length; uint16_t length;
int fd, err;
length = inmsg->length ? inmsg->length : BT_SUGGESTED_BUFFER_SIZE; length = inmsg->length ? inmsg->length : BT_SUGGESTED_BUFFER_SIZE;
status = g_io_channel_read (self->server, (gchar *) inmsg, length, fd = g_io_channel_unix_get_fd (self->server);
&bytes_read);
if (status != G_IO_ERROR_NONE) { bytes_read = read (fd, inmsg, length);
GST_ERROR_OBJECT (self, "Error receiving data from " "audio service"); if (bytes_read < 0) {
return status; GST_ERROR_OBJECT (self, "Error receiving data from "
"audio service: %s", strerror (errno));
return -errno;
} }
type = bt_audio_strtype (inmsg->type); type = bt_audio_strtype (inmsg->type);
if (!type) { if (!type) {
status = G_IO_ERROR_INVAL; err = -EINVAL;
GST_ERROR_OBJECT (self, "Bogus message type %d " GST_ERROR_OBJECT (self, "Bogus message type %d "
"received from audio service", inmsg->type); "received from audio service", inmsg->type);
} }
name = bt_audio_strname (inmsg->name); name = bt_audio_strname (inmsg->name);
if (!name) { if (!name) {
status = G_IO_ERROR_INVAL; err = -EINVAL;
GST_ERROR_OBJECT (self, "Bogus message name %d " GST_ERROR_OBJECT (self, "Bogus message name %d "
"received from audio service", inmsg->name); "received from audio service", inmsg->name);
} }
if (inmsg->type == BT_ERROR) { if (inmsg->type == BT_ERROR) {
bt_audio_error_t *err = (void *) inmsg; bt_audio_error_t *msg = (void *) inmsg;
status = G_IO_ERROR_INVAL; err = -EINVAL;
GST_ERROR_OBJECT (self, "%s failed : " GST_ERROR_OBJECT (self, "%s failed : "
"%s(%d)", name, strerror (err->posix_errno), err->posix_errno); "%s(%d)", name, strerror (msg->posix_errno), msg->posix_errno);
} }
GST_DEBUG_OBJECT (self, "received: %s <- %s", type, name); GST_DEBUG_OBJECT (self, "received: %s <- %s", type, name);
return status; return err;
} }
static GIOError static int
gst_avdtp_sink_audioservice_expect (GstAvdtpSink * self, gst_avdtp_sink_audioservice_expect (GstAvdtpSink * self,
bt_audio_msg_header_t * outmsg, guint8 expected_name) bt_audio_msg_header_t * outmsg, guint8 expected_name)
{ {
GIOError status; int err;
status = gst_avdtp_sink_audioservice_recv (self, outmsg); err = gst_avdtp_sink_audioservice_recv (self, outmsg);
if (status != G_IO_ERROR_NONE) if (err < 0)
return status; return err;
if (outmsg->name != expected_name) if (outmsg->name != expected_name)
status = G_IO_ERROR_INVAL; return -EINVAL;
return status; return 0;
} }
gboolean gboolean