Skip to contentSkip to conversation

android/AVDTP: Make signalling channel priority 6

PATCH In review Luiz Augusto von Dentz 2 participants 5 messages Jan 28, 2014 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v3 1/4 android/AVDTP: Make signalling channel priority 6

From: Luiz Augusto von Dentz <[email protected]>

This makes signalling priority 6 so it can push commands before the stream channel, without this the stream channel may be schedule first and cause the signalling commands to timeout while waiting a slot.
---
v2: Return error if writes fails since that probably means the socket has been disconnected, also makes code setting socket to blocking a bit cleaner.
v3: Remove cast as suggested by Marcel, make code setting stream fd to block a separate function.

 android/avdtp.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
android/avdtp.c +9 -1
index 4abcd75..e93ff70 100644
@@ -2056,7 +2056,7 @@ struct avdtp *avdtp_new(int fd, size_t imtu, size_t omtu, uint16_t version)
 {
 	struct avdtp *session;
 	GIOCondition cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
-	int new_fd;
+	int new_fd, priority;
 
 	new_fd = dup(fd);
 	if (new_fd < 0) {
@@ -2064,6 +2064,14 @@ struct avdtp *avdtp_new(int fd, size_t imtu, size_t omtu, uint16_t version)
 		return NULL;
 	}
 
+	priority = 6;
+	if (setsockopt(new_fd, SOL_SOCKET, SO_PRIORITY, &priority,
+						sizeof(priority)) < 0) {
+		error("setsockopt(SO_PRIORITY): %s (%d)", strerror(errno),
+									errno);
+		return NULL;
+	}
+
 	session = g_new0(struct avdtp, 1);
 	session->io = g_io_channel_unix_new(new_fd);
 	session->version = version;
Signature · 1 line
1.8.4.2
author maintainer
#1 lore raw

PATCH v3 2/4 android/AVDTP: Make stream channel priority 5

From: Luiz Augusto von Dentz <[email protected]>

This makes channel priority 5 so it has higher priority than regular traffic but less than signalling channel.

---
 android/avdtp.c | 9 +++++++++
 1 file changed, 9 insertions(+)
android/avdtp.c +9 -0
index e93ff70..1783555 100644
@@ -2832,10 +2832,19 @@ gboolean avdtp_stream_set_transport(struct avdtp_stream *stream, int fd,
 						size_t imtu, size_t omtu)
 {
 	GIOChannel *io;
+	int priority;
 
 	if (stream != stream->session->pending_open)
 		return FALSE;
 
+	priority = 5;
+	if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, &priority,
+						sizeof(priority)) < 0) {
+		error("setsockopt(SO_PRIORITY): %s (%d)", strerror(errno),
+									errno);
+		return FALSE;
+	}
+
 	io = g_io_channel_unix_new(fd);
 
 	handle_transport_connect(stream->session, io, imtu, omtu);
Signature · 1 line
1.8.4.2
author maintainer
#2 lore raw

PATCH v3 3/4 android/hal-audio: Fix not handling EINTR errors

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

If the kernel interrupts us while writting just try again.

---
 android/hal-audio.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
android/hal-audio.c +13 -6
index 8d737ad..2ca6289 100644
@@ -399,7 +399,7 @@ static void sbc_resume(void *codec_data)
 	sbc_data->frames_sent = 0;
 }
 
-static void write_media_packet(int fd, struct sbc_data *sbc_data,
+static int write_media_packet(int fd, struct sbc_data *sbc_data,
 				struct media_packet *mp, size_t data_len)
 {
 	struct timespec cur;
@@ -407,10 +407,13 @@ static void write_media_packet(int fd, struct sbc_data *sbc_data,
 	unsigned expected_frames;
 	int ret;
 
-	ret = write(fd, mp, sizeof(*mp) + data_len);
-	if (ret < 0) {
-		int err = errno;
-		error("SBC: failed to write data: %d (%s)", err, strerror(err));
+	while (true) {
+		ret = write(fd, mp, sizeof(*mp) + data_len);
+		if (ret >= 0)
+			break;
+
+		if (errno != EINTR)
+			return -errno;
 	}
 
 	sbc_data->frames_sent += mp->payload.frame_count;
@@ -432,6 +435,8 @@ static void write_media_packet(int fd, struct sbc_data *sbc_data,
 	if (sbc_data->frames_sent >= expected_frames)
 		usleep(sbc_data->frame_duration *
 				mp->payload.frame_count);
+
+	return ret;
 }
 
 static ssize_t sbc_write_data(void *codec_data, const void *buffer,
@@ -474,7 +479,9 @@ static ssize_t sbc_write_data(void *codec_data, const void *buffer,
 		 */
 		if (mp->payload.frame_count == sbc_data->frames_per_packet ||
 				bytes == consumed) {
-			write_media_packet(fd, sbc_data, mp, encoded);
+			ret = write_media_packet(fd, sbc_data, mp, encoded);
+			if (ret < 0)
+				return ret;
 
 			encoded = 0;
 			free_space = sbc_data->out_buf_size - sizeof(*mp);
Signature · 1 line
1.8.4.2
author maintainer
#3 lore raw

PATCH v3 4/4 android/hal-audio: Set stream fd to blocking

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This makes the stream to block on io operation so it does not return EAGAIN on syscall such as write.

---
 android/hal-audio.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
android/hal-audio.c +22 -1
index 2ca6289..b1323b0 100644
@@ -25,6 +25,7 @@
 #include <sys/un.h>
 #include <unistd.h>
 #include <arpa/inet.h>
+#include <fcntl.h>
 
 #include <hardware/audio.h>
 #include <hardware/hardware.h>
@@ -1108,6 +1109,24 @@ static int in_remove_audio_effect(const struct audio_stream *stream,
 	return -ENOSYS;
 }
 
+static int set_blocking(int fd)
+{
+	int flags;
+
+	flags = fcntl(fd, F_GETFL, 0);
+	if (flags < 0) {
+		error("fcntl(F_GETFL): %s (%d)", strerror(errno), errno);
+		return -errno;
+	}
+
+	if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) < 0) {
+		error("fcntl(F_SETFL): %s (%d)", strerror(errno), errno);
+		return -errno;
+	}
+
+	return 0;
+}
+
 static int audio_open_output_stream(struct audio_hw_device *dev,
 					audio_io_handle_t handle,
 					audio_devices_t devices,
@@ -1156,8 +1175,10 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
 	if (!preset || fd < 0)
 		goto fail;
 
-	out->ep->fd = fd;
+	if (set_blocking(fd) < 0)
+		goto fail;
 
+	out->ep->fd = fd;
 	codec = out->ep->codec;
 
 	codec->init(preset, mtu, &out->ep->codec_data);
Signature · 1 line
1.8.4.2
#4 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 32 lines · On Tuesday 28 of January 2014 09:14:43 Luiz Augusto von Dentz wrote:

From: Luiz Augusto von Dentz <[email protected]>

This makes signalling priority 6 so it can push commands before the stream channel, without this the stream channel may be schedule first and cause the signalling commands to timeout while waiting a slot.
---
v2: Return error if writes fails since that probably means the socket has been disconnected, also makes code setting socket to blocking a bit cleaner. v3: Remove cast as suggested by Marcel, make code setting stream fd to block a separate function.

 android/avdtp.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
android/avdtp.c +2 -1
index 4abcd75..e93ff70 100644
@@ -2056,7 +2056,7 @@ struct avdtp *avdtp_new(int fd, size_t imtu, size_t
 omtu, uint16_t version) {
 	struct avdtp *session;
 	GIOCondition cond = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
-	int new_fd;
+	int new_fd, priority;
 
 	new_fd = dup(fd);
 	if (new_fd < 0) {
@@ -2064,6 +2064,14 @@ struct avdtp *avdtp_new(int fd, size_t imtu, size_t
 omtu, uint16_t version) return NULL;
 	}
 
+	priority = 6;

android/avdtp.c struct avdtp *avdtp_new(int fd, size_t imtu, size_t · line 2077

Quoted 10 lines
android/avdtp.c +7 -0
+	if (setsockopt(new_fd, SOL_SOCKET, SO_PRIORITY, &priority,
+						sizeof(priority)) < 0) {
+		error("setsockopt(SO_PRIORITY): %s (%d)", strerror(errno),
+									errno);
+		return NULL;
+	}
+
 	session = g_new0(struct avdtp, 1);
 	session->io = g_io_channel_unix_new(new_fd);
 	session->version = version;

All four patches applied, thanks.

Signature · 2 lines
BR
Szymon Janc