Fix use of deprecated glib on audio plugin
diff --git a/audio/avdtp.c b/audio/avdtp.c
index fdac1e3..88e3e8a 100644
--- a/audio/avdtp.c
+++ b/audio/avdtp.c
@@ -2091,7 +2091,8 @@
 {
 	struct avdtp *session = data;
 	struct avdtp_common_header *header;
-	gsize size;
+	ssize_t size;
+	int fd;
 
 	DBG("");
 
@@ -2103,13 +2104,14 @@
 	if (cond & (G_IO_HUP | G_IO_ERR))
 		goto failed;
 
-	if (g_io_channel_read(chan, session->buf, session->imtu, &size)
-							!= G_IO_ERROR_NONE) {
+	fd = g_io_channel_unix_get_fd(chan);
+	size = read(fd, session->buf, session->imtu);
+	if (size < 0) {
 		error("IO Channel read error");
 		goto failed;
 	}
 
-	if (size < sizeof(struct avdtp_common_header)) {
+	if ((size_t) size < sizeof(struct avdtp_common_header)) {
 		error("Received too small packet (%zu bytes)", size);
 		goto failed;
 	}
diff --git a/audio/gstavdtpsink.c b/audio/gstavdtpsink.c
index 95c4811..48fa24d 100644
--- a/audio/gstavdtpsink.c
+++ b/audio/gstavdtpsink.c
@@ -122,12 +122,11 @@
 				"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);
-static GIOError gst_avdtp_sink_audioservice_expect(
-				GstAvdtpSink *self,
-				bt_audio_msg_header_t *outmsg,
-				guint8 expected_name);
+static int gst_avdtp_sink_audioservice_expect(GstAvdtpSink *self,
+					bt_audio_msg_header_t *outmsg,
+					guint8 expected_name);
 
 
 static void gst_avdtp_sink_base_init(gpointer g_class)
@@ -287,6 +286,7 @@
 	}
 
 	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);
 
 	return 0;
@@ -413,11 +413,10 @@
 {
 	struct bluetooth_data *data = self->data;
 	gint ret;
-	GIOError err;
 	GError *gerr = NULL;
 	GIOStatus status;
 	GIOFlags flags;
-	gsize read;
+	int fd;
 
 	/* Proceed if stream was already acquired */
 	if (self->stream != NULL)
@@ -450,14 +449,14 @@
 					"socket to nonblock");
 	}
 
+	fd = g_io_channel_unix_get_fd(self->stream);
+
 	/* It is possible there is some outstanding
 	data in the pipe - we have to empty it */
 	GST_LOG_OBJECT(self, "emptying stream pipe");
 	while (1) {
-		err = g_io_channel_read(self->stream, data->buffer,
-					(gsize) data->link_mtu,
-					&read);
-		if (err != G_IO_ERROR_NONE || read <= 0)
+		ssize_t bread = read(fd, data->buffer, data->link_mtu);
+		if (bread <= 0)
 			break;
 	}
 
@@ -1143,7 +1142,7 @@
 	gchar *buf[BT_SUGGESTED_BUFFER_SIZE];
 	struct bt_get_capabilities_req *req = (void *) buf;
 	struct bt_get_capabilities_rsp *rsp = (void *) buf;
-	GIOError io_error;
+	int err;
 
 	memset(req, 0, BT_SUGGESTED_BUFFER_SIZE);
 
@@ -1157,16 +1156,16 @@
 	if (self->autoconnect)
 		req->flags |= BT_FLAG_AUTOCONNECT;
 
-	io_error = gst_avdtp_sink_audioservice_send(self, &req->h);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_send(self, &req->h);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error while asking device caps");
 		return FALSE;
 	}
 
 	rsp->h.length = 0;
-	io_error = gst_avdtp_sink_audioservice_expect(self,
-			&rsp->h, BT_GET_CAPABILITIES);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_expect(self,
+					&rsp->h, BT_GET_CAPABILITIES);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error while getting device caps");
 		return FALSE;
 	}
@@ -1355,6 +1354,7 @@
 	dbus_message_unref(reply);
 
 	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);
 	GST_DEBUG_OBJECT(self, "stream_fd=%d", fd);
 
@@ -1461,6 +1461,7 @@
 	}
 
 	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 |
 					G_IO_NVAL, server_callback, self);
 
@@ -1483,7 +1484,7 @@
 	struct bt_start_stream_req *req = (void *) buf;
 	struct bt_start_stream_rsp *rsp = (void *) buf;
 	struct bt_new_stream_ind *ind = (void *) buf;
-	GIOError io_error;
+	int err;
 
 	if (self->transport != NULL)
 		return gst_avdtp_sink_conf_recv_stream_fd(self);
@@ -1493,26 +1494,26 @@
 	req->h.name = BT_START_STREAM;
 	req->h.length = sizeof(*req);
 
-	io_error = gst_avdtp_sink_audioservice_send(self, &req->h);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_send(self, &req->h);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error ocurred while sending "
 					"start packet");
 		return FALSE;
 	}
 
 	rsp->h.length = sizeof(*rsp);
-	io_error = gst_avdtp_sink_audioservice_expect(self,
-			&rsp->h, BT_START_STREAM);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_expect(self, &rsp->h,
+							BT_START_STREAM);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error while stream "
 			"start confirmation");
 		return FALSE;
 	}
 
 	ind->h.length = sizeof(*ind);
-	io_error = gst_avdtp_sink_audioservice_expect(self, &ind->h,
-			BT_NEW_STREAM);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_expect(self, &ind->h,
+							BT_NEW_STREAM);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error while receiving "
 			"stream filedescriptor");
 		return FALSE;
@@ -1610,10 +1611,10 @@
 	struct bt_set_configuration_req *req = (void *) buf;
 	struct bt_set_configuration_rsp *rsp = (void *) buf;
 	gboolean ret;
-	GIOError io_error;
 	gchar *temp;
 	GstStructure *structure;
 	codec_capabilities_t *codec = NULL;
+	int err;
 
 	temp = gst_caps_to_string(caps);
 	GST_DEBUG_OBJECT(self, "configuring device with caps: %s", temp);
@@ -1645,17 +1646,17 @@
 	open_req->seid = codec->seid;
 	open_req->lock = BT_WRITE_LOCK;
 
-	io_error = gst_avdtp_sink_audioservice_send(self, &open_req->h);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_send(self, &open_req->h);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error ocurred while sending "
 					"open packet");
 		return FALSE;
 	}
 
 	open_rsp->h.length = sizeof(*open_rsp);
-	io_error = gst_avdtp_sink_audioservice_expect(self,
-			&open_rsp->h, BT_OPEN);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_expect(self, &open_rsp->h,
+								BT_OPEN);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error while receiving device "
 					"confirmation");
 		return FALSE;
@@ -1681,17 +1682,17 @@
 	}
 
 	req->h.length += req->codec.length - sizeof(req->codec);
-	io_error = gst_avdtp_sink_audioservice_send(self, &req->h);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_send(self, &req->h);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error ocurred while sending "
 					"configurarion packet");
 		return FALSE;
 	}
 
 	rsp->h.length = sizeof(*rsp);
-	io_error = gst_avdtp_sink_audioservice_expect(self,
-			&rsp->h, BT_SET_CONFIGURATION);
-	if (io_error != G_IO_ERROR_NONE) {
+	err = gst_avdtp_sink_audioservice_expect(self, &rsp->h,
+							BT_SET_CONFIGURATION);
+	if (err < 0) {
 		GST_ERROR_OBJECT(self, "Error while receiving device "
 					"confirmation");
 		return FALSE;
@@ -1724,16 +1725,15 @@
 					GstBuffer *buffer)
 {
 	GstAvdtpSink *self = GST_AVDTP_SINK(basesink);
-	gsize ret;
-	GIOError err;
+	ssize_t ret;
+	int fd;
 
-	err = g_io_channel_write(self->stream,
-				(gchar *) GST_BUFFER_DATA(buffer),
-				(gsize) (GST_BUFFER_SIZE(buffer)), &ret);
+	fd = g_io_channel_unix_get_fd(self->stream);
 
-	if (err != G_IO_ERROR_NONE) {
-		GST_ERROR_OBJECT(self, "Error while writting to socket: %d %s",
-				errno, strerror(errno));
+	ret = write(fd, GST_BUFFER_DATA(buffer), GST_BUFFER_SIZE(buffer));
+	if (ret < 0) {
+		GST_ERROR_OBJECT(self, "Error while writting to socket: %s",
+							strerror(errno));
 		return GST_FLOW_ERROR;
 	}
 
@@ -1840,53 +1840,55 @@
 	*/
 }
 
-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)
 {
-	GIOError error;
-	gsize written;
+	ssize_t written;
 	const char *type, *name;
 	uint16_t length;
+	int fd;
 
 	length = msg->length ? msg->length : BT_SUGGESTED_BUFFER_SIZE;
 
-	error = g_io_channel_write(self->server, (const gchar *) msg, length,
-								&written);
-	if (error != G_IO_ERROR_NONE)
+	fd = g_io_channel_unix_get_fd(self->server);
+
+	written = write(fd, msg, length);
+	if (written < 0) {
 		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);
 	name = bt_audio_strname(msg->name);
 
 	GST_DEBUG_OBJECT(self, "sent: %s -> %s", type, name);
 
-	return error;
+	return 0;
 }
 
-static GIOError gst_avdtp_sink_audioservice_recv(
-					GstAvdtpSink *self,
-					bt_audio_msg_header_t *inmsg)
+static int gst_avdtp_sink_audioservice_recv(GstAvdtpSink *self,
+						bt_audio_msg_header_t *inmsg)
 {
-	GIOError status;
-	gsize bytes_read;
+	ssize_t bytes_read;
 	const char *type, *name;
 	uint16_t length;
+	int fd, err;
 
 	length = inmsg->length ? inmsg->length : BT_SUGGESTED_BUFFER_SIZE;
 
-	status = g_io_channel_read(self->server, (gchar *) inmsg, length,
-								&bytes_read);
-	if (status != G_IO_ERROR_NONE) {
+	fd = g_io_channel_unix_get_fd(self->server);
+
+	bytes_read = read(fd, inmsg, length);
+	if (bytes_read < 0) {
 		GST_ERROR_OBJECT(self, "Error receiving data from "
-				"audio service");
-		return status;
+				"audio service: %s", strerror(errno));
+		return -errno;
 	}
 
 	type = bt_audio_strtype(inmsg->type);
 	if (!type) {
-		status = G_IO_ERROR_INVAL;
+		err = -EINVAL;
 		GST_ERROR_OBJECT(self, "Bogus message type %d "
 				"received from audio service",
 				inmsg->type);
@@ -1894,41 +1896,41 @@
 
 	name = bt_audio_strname(inmsg->name);
 	if (!name) {
-		status = G_IO_ERROR_INVAL;
+		err = -EINVAL;
 		GST_ERROR_OBJECT(self, "Bogus message name %d "
 				"received from audio service",
 				inmsg->name);
 	}
 
 	if (inmsg->type == BT_ERROR) {
-		bt_audio_error_t *err = (void *) inmsg;
-		status = G_IO_ERROR_INVAL;
+		bt_audio_error_t *msg = (void *) inmsg;
+		err = -EINVAL;
 		GST_ERROR_OBJECT(self, "%s failed : "
 					"%s(%d)",
 					name,
-					strerror(err->posix_errno),
-					err->posix_errno);
+					strerror(msg->posix_errno),
+					msg->posix_errno);
 	}
 
 	GST_DEBUG_OBJECT(self, "received: %s <- %s", type, name);
 
-	return status;
+	return err;
 }
 
-static GIOError gst_avdtp_sink_audioservice_expect(
-			GstAvdtpSink *self, bt_audio_msg_header_t *outmsg,
-			guint8 expected_name)
+static int gst_avdtp_sink_audioservice_expect(GstAvdtpSink *self,
+						bt_audio_msg_header_t *outmsg,
+						guint8 expected_name)
 {
-	GIOError status;
+	int err;
 
-	status = gst_avdtp_sink_audioservice_recv(self, outmsg);
-	if (status != G_IO_ERROR_NONE)
-		return status;
+	err = gst_avdtp_sink_audioservice_recv(self, outmsg);
+	if (err < 0)
+		return err;
 
 	if (outmsg->name != expected_name)
-		status = G_IO_ERROR_INVAL;
+		return -EINVAL;
 
-	return status;
+	return 0;
 }
 
 gboolean gst_avdtp_sink_plugin_init(GstPlugin *plugin)
diff --git a/audio/headset.c b/audio/headset.c
index 53a594d..120ab23 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -1235,8 +1235,9 @@
 	struct headset *hs;
 	struct headset_slc *slc;
 	unsigned char buf[BUF_SIZE];
-	gsize bytes_read = 0;
-	gsize free_space;
+	ssize_t bytes_read;
+	size_t free_space;
+	int fd;
 
 	if (cond & G_IO_NVAL)
 		return FALSE;
@@ -1249,14 +1250,16 @@
 		goto failed;
 	}
 
-	if (g_io_channel_read(chan, (gchar *) buf, sizeof(buf) - 1,
-				&bytes_read) != G_IO_ERROR_NONE)
+	fd = g_io_channel_unix_get_fd(chan);
+
+	bytes_read = read(fd, buf, sizeof(buf) - 1);
+	if (bytes_read < 0)
 		return TRUE;
 
 	free_space = sizeof(slc->buf) - slc->data_start -
 			slc->data_length - 1;
 
-	if (free_space < bytes_read) {
+	if (free_space < (size_t) bytes_read) {
 		/* Very likely that the HS is sending us garbage so
 		 * just ignore the data and disconnect */
 		error("Too much data to fit incomming buffer");
diff --git a/audio/unix.c b/audio/unix.c
index 76c68a8..a4b92f4 100644
--- a/audio/unix.c
+++ b/audio/unix.c
@@ -1791,7 +1791,7 @@
 		return FALSE;
 
 	if (cond & (G_IO_HUP | G_IO_ERR)) {
-		g_io_channel_close(chan);
+		g_io_channel_shutdown(chan, TRUE, NULL);
 		return FALSE;
 	}