linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6
@ 2014-01-28 17:14 Luiz Augusto von Dentz
  2014-01-28 17:14 ` [PATCH BlueZ v3 2/4] android/AVDTP: Make stream channel priority 5 Luiz Augusto von Dentz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2014-01-28 17:14 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(-)

diff --git a/android/avdtp.c b/android/avdtp.c
index 4abcd75..e93ff70 100644
--- a/android/avdtp.c
+++ b/android/avdtp.c
@@ -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;
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH BlueZ v3 2/4] android/AVDTP: Make stream channel priority 5
  2014-01-28 17:14 [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6 Luiz Augusto von Dentz
@ 2014-01-28 17:14 ` Luiz Augusto von Dentz
  2014-01-28 17:14 ` [PATCH BlueZ v3 3/4] android/hal-audio: Fix not handling EINTR errors Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2014-01-28 17:14 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(+)

diff --git a/android/avdtp.c b/android/avdtp.c
index e93ff70..1783555 100644
--- a/android/avdtp.c
+++ b/android/avdtp.c
@@ -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);
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH BlueZ v3 3/4] android/hal-audio: Fix not handling EINTR errors
  2014-01-28 17:14 [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6 Luiz Augusto von Dentz
  2014-01-28 17:14 ` [PATCH BlueZ v3 2/4] android/AVDTP: Make stream channel priority 5 Luiz Augusto von Dentz
@ 2014-01-28 17:14 ` Luiz Augusto von Dentz
  2014-01-28 17:14 ` [PATCH BlueZ v3 4/4] android/hal-audio: Set stream fd to blocking Luiz Augusto von Dentz
  2014-01-28 23:33 ` [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6 Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2014-01-28 17:14 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If the kernel interrupts us while writting just try again.
---
 android/hal-audio.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 8d737ad..2ca6289 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -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);
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH BlueZ v3 4/4] android/hal-audio: Set stream fd to blocking
  2014-01-28 17:14 [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6 Luiz Augusto von Dentz
  2014-01-28 17:14 ` [PATCH BlueZ v3 2/4] android/AVDTP: Make stream channel priority 5 Luiz Augusto von Dentz
  2014-01-28 17:14 ` [PATCH BlueZ v3 3/4] android/hal-audio: Fix not handling EINTR errors Luiz Augusto von Dentz
@ 2014-01-28 17:14 ` Luiz Augusto von Dentz
  2014-01-28 23:33 ` [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6 Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2014-01-28 17:14 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(-)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 2ca6289..b1323b0 100644
--- a/android/hal-audio.c
+++ b/android/hal-audio.c
@@ -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);
-- 
1.8.4.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6
  2014-01-28 17:14 [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6 Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2014-01-28 17:14 ` [PATCH BlueZ v3 4/4] android/hal-audio: Set stream fd to blocking Luiz Augusto von Dentz
@ 2014-01-28 23:33 ` Szymon Janc
  3 siblings, 0 replies; 5+ messages in thread
From: Szymon Janc @ 2014-01-28 23:33 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

On Tuesday 28 of January 2014 09:14:43 Luiz Augusto von Dentz wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> 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(-)
> 
> diff --git a/android/avdtp.c b/android/avdtp.c
> index 4abcd75..e93ff70 100644
> --- a/android/avdtp.c
> +++ b/android/avdtp.c
> @@ -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;

All four patches applied, thanks.

-- 
BR
Szymon Janc

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-01-28 23:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-28 17:14 [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6 Luiz Augusto von Dentz
2014-01-28 17:14 ` [PATCH BlueZ v3 2/4] android/AVDTP: Make stream channel priority 5 Luiz Augusto von Dentz
2014-01-28 17:14 ` [PATCH BlueZ v3 3/4] android/hal-audio: Fix not handling EINTR errors Luiz Augusto von Dentz
2014-01-28 17:14 ` [PATCH BlueZ v3 4/4] android/hal-audio: Set stream fd to blocking Luiz Augusto von Dentz
2014-01-28 23:33 ` [PATCH BlueZ v3 1/4] android/AVDTP: Make signalling channel priority 6 Szymon Janc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).