Make signalling channel priority 6 (2024)

Discussion:

[PATCH BlueZ v2 1/4] android/AVDTP: Make signalling channel priority 6

Luiz Augusto von Dentz

2014-01-28 06:16:57 UTC

Permalink

From: Luiz Augusto von Dentz <luiz.von.dentz-***@public.gmane.org>

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.

android/avdtp.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/android/avdtp.c b/android/avdtp.c
index 4abcd75..4cfffc8 100644
--- a/android/avdtp.c
+++ b/android/avdtp.c
@@ -2057,6 +2057,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 priority;

new_fd = dup(fd);
if (new_fd < 0) {
@@ -2064,6 +2065,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,
+(const void *) &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

Luiz Augusto von Dentz

2014-01-28 06:16:58 UTC

Permalink

From: Luiz Augusto von Dentz <luiz.von.dentz-***@public.gmane.org>

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 4cfffc8..23fe519 100644
--- a/android/avdtp.c
+++ b/android/avdtp.c
@@ -2833,10 +2833,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

Luiz Augusto von Dentz

2014-01-28 06:16:59 UTC

Permalink

From: Luiz Augusto von Dentz <luiz.von.dentz-***@public.gmane.org>

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

Luiz Augusto von Dentz

2014-01-28 06:17:00 UTC

Permalink

From: Luiz Augusto von Dentz <luiz.von.dentz-***@public.gmane.org>

This makes the stream to block on io operation so it does not return
EAGAIN on syscall such as write.
---
android/hal-audio.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/android/hal-audio.c b/android/hal-audio.c
index 2ca6289..21c1d94 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>
@@ -1121,7 +1122,7 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
struct audio_preset *preset;
const struct audio_codec *codec;
uint16_t mtu;
-int fd;
+int fd, flags;

out = calloc(1, sizeof(struct a2dp_stream_out));
if (!out)
@@ -1156,8 +1157,18 @@ static int audio_open_output_stream(struct audio_hw_device *dev,
if (!preset || fd < 0)
goto fail;

-out->ep->fd = fd;
+flags = fcntl(fd, F_GETFL, 0);
+if (flags < 0) {
+error("fcntl(F_GETFL): %s (%d)", strerror(errno), errno);
+goto fail;
+}

+if (fcntl(fd, F_SETFL, flags & ~O_NONBLOCK) < 0) {
+error("fcntl(F_SETFL): %s (%d)", strerror(errno), errno);
+goto fail;
+}
+
+out->ep->fd = fd;
codec = out->ep->codec;

codec->init(preset, mtu, &out->ep->codec_data);

--
1.8.4.2

Marcel Holtmann

2014-01-28 12:05:04 UTC

Permalink

Hi Luiz,

Post by Luiz Augusto von Dentz
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 sl=

ot.

Post by Luiz Augusto von Dentz
---
v2: Return error if writes fails since that probably means the socket=

has been

Post by Luiz Augusto von Dentz
disconnected, also makes code setting socket to blocking a bit cleane=

r.

Post by Luiz Augusto von Dentz
=20
android/avdtp.c | 9 +++++++++
1 file changed, 9 insertions(+)
=20
diff --git a/android/avdtp.c b/android/avdtp.c
index 4abcd75..4cfffc8 100644
--- a/android/avdtp.c
+++ b/android/avdtp.c
@@ -2057,6 +2057,7 @@ struct avdtp *avdtp_new(int fd, size_t imtu, si=

ze_t omtu, uint16_t version)

Post by Luiz Augusto von Dentz
struct avdtp *session;
GIOCondition cond =3D G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
int new_fd;
+int priority;

make it =93int new_fd, priority;=94.

Post by Luiz Augusto von Dentz
=20
new_fd =3D dup(fd);
if (new_fd < 0) {
@@ -2064,6 +2065,14 @@ struct avdtp *avdtp_new(int fd, size_t imtu, s=

ize_t omtu, uint16_t version)

Post by Luiz Augusto von Dentz
return NULL;
}
=20
+priority =3D 6;
+if (setsockopt(new_fd, SOL_SOCKET, SO_PRIORITY,
+(const void *) &priority, sizeof(priority)) < 0) {

What is this (const void *) cast for. That should not be needed.

Post by Luiz Augusto von Dentz
+error("setsockopt(SO_PRIORITY): %s (%d)", strerror(errno),
+errno);
+return NULL;
+}
+
session =3D g_new0(struct avdtp, 1);
session->io =3D g_io_channel_unix_new(new_fd);
session->version =3D version;

Regards

Marcel

4 Replies
10 Views
Permalink to this page
Disable enhanced parsing

Thread Navigation

Luiz Augusto von Dentz2014-01-28 06:16:57 UTC
Luiz Augusto von Dentz2014-01-28 06:16:58 UTC
Luiz Augusto von Dentz2014-01-28 06:16:59 UTC
Luiz Augusto von Dentz2014-01-28 06:17:00 UTC
Marcel Holtmann2014-01-28 12:05:04 UTC
Make signalling channel priority 6 (2024)
Top Articles
Latest Posts
Recommended Articles
Article information

Author: Reed Wilderman

Last Updated:

Views: 6391

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Reed Wilderman

Birthday: 1992-06-14

Address: 998 Estell Village, Lake Oscarberg, SD 48713-6877

Phone: +21813267449721

Job: Technology Engineer

Hobby: Swimming, Do it yourself, Beekeeping, Lapidary, Cosplaying, Hiking, Graffiti

Introduction: My name is Reed Wilderman, I am a faithful, bright, lucky, adventurous, lively, rich, vast person who loves writing and wants to share my knowledge and understanding with you.