public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/1] AVDTP SRC stream send buffer size verification
@ 2010-12-15  9:48 Dmitriy Paliy
  2010-12-15  9:48 ` [PATCH] Add " Dmitriy Paliy
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitriy Paliy @ 2010-12-15  9:48 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

In this patch, send buffer size for L2CAP socket is verified against
outgoing L2CAP MTU size and increased to be twice of it if it is less
than that. Such verification is done for AVDTP source transport channel
only.

Reason to do this check is that system default socket buffer size was
reduced in Meego and it affected IOP with some car-kits that use large
MTUs.

Worth to mention that send buffer size is never decreased, and can be
increased only.

BR,
Dmitriy


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

* [PATCH] Add AVDTP SRC stream send buffer size verification
  2010-12-15  9:48 [PATCH 0/1] AVDTP SRC stream send buffer size verification Dmitriy Paliy
@ 2010-12-15  9:48 ` Dmitriy Paliy
  2010-12-16 19:47   ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: Dmitriy Paliy @ 2010-12-15  9:48 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dmitriy Paliy

Functions get_send_buffer_size and set_send_buffer_size are added to
avdpt.c.

get_send_buffer_size returns size of send buffer for a given socket
on success or error code on failure. set_send_buffer_size sets size
of send buffer for a given socket, and returns 0 on success or error
code on failure.

Size of send buffer for L2CAP socket for SRC AVDTP stream is verified
during establishment of a new transport channel. If the size is less
than twice of outgoing L2CAP MTU, then it is considered as being
insufficient to handle streaming data reliably.

In this case buffer size is increased to be twice of MTU size. Such
fixes some IOP problems with car-kits that use large MTU for music
playback.
---
 audio/avdtp.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/audio/avdtp.c b/audio/avdtp.c
index 1683e7c..34b95fd 100644
--- a/audio/avdtp.c
+++ b/audio/avdtp.c
@@ -838,6 +838,40 @@ static gboolean transport_cb(GIOChannel *chan, GIOCondition cond,
 	return FALSE;
 }
 
+static int get_send_buffer_size(int sk)
+{
+	int size;
+	socklen_t optlen = sizeof(size);
+
+	if (getsockopt(sk, SOL_SOCKET, SO_SNDBUF, &size, &optlen) < 0) {
+		int err = -errno;
+		error("getsockopt(SO_SNDBUF) failed: %s (%d)", strerror(-err),
+									-err);
+		return err;
+	}
+
+	/*
+	 * Doubled value is returned by getsockopt since kernel uses that
+	 * space for its own purposes (see man 7 socket, bookkeeping overhead
+	 * for SO_SNDBUF).
+	 */
+	return size / 2;
+}
+
+static int set_send_buffer_size(int sk, int size)
+{
+	socklen_t optlen = sizeof(size);
+
+	if (setsockopt(sk, SOL_SOCKET, SO_SNDBUF, &size, optlen) < 0) {
+		int err = -errno;
+		error("setsockopt(SO_SNDBUF) failed: %s (%d)", strerror(-err),
+									-err);
+		return err;
+	}
+
+	return 0;
+}
+
 static void handle_transport_connect(struct avdtp *session, GIOChannel *io,
 					uint16_t imtu, uint16_t omtu)
 {
@@ -865,6 +899,25 @@ static void handle_transport_connect(struct avdtp *session, GIOChannel *io,
 	stream->omtu = omtu;
 	stream->imtu = imtu;
 
+	/* only if local SEP is of type SRC */
+	if (sep->info.type == AVDTP_SEP_TYPE_SOURCE) {
+		int sk, buf_size, min_buf_size;
+
+		sk = g_io_channel_unix_get_fd(stream->io);
+		buf_size = get_send_buffer_size(sk);
+		if (buf_size < 0)
+			goto proceed;
+
+		DBG("sk %d, omtu %d, send buffer size %d", sk, omtu, buf_size);
+		min_buf_size = omtu * 2;
+		if (buf_size < min_buf_size) {
+			DBG("send buffer size to be increassed to %d",
+								min_buf_size);
+			set_send_buffer_size(sk, min_buf_size);
+		}
+	}
+
+proceed:
 	if (!stream->open_acp && sep->cfm && sep->cfm->open)
 		sep->cfm->open(session, sep, stream, NULL, sep->user_data);
 
-- 
1.7.0.4


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

* Re: [PATCH] Add AVDTP SRC stream send buffer size verification
  2010-12-15  9:48 ` [PATCH] Add " Dmitriy Paliy
@ 2010-12-16 19:47   ` Johan Hedberg
  0 siblings, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2010-12-16 19:47 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth

Hi Dmitriy,

On Wed, Dec 15, 2010, Dmitriy Paliy wrote:
> Functions get_send_buffer_size and set_send_buffer_size are added to
> avdpt.c.
> 
> get_send_buffer_size returns size of send buffer for a given socket
> on success or error code on failure. set_send_buffer_size sets size
> of send buffer for a given socket, and returns 0 on success or error
> code on failure.
> 
> Size of send buffer for L2CAP socket for SRC AVDTP stream is verified
> during establishment of a new transport channel. If the size is less
> than twice of outgoing L2CAP MTU, then it is considered as being
> insufficient to handle streaming data reliably.
> 
> In this case buffer size is increased to be twice of MTU size. Such
> fixes some IOP problems with car-kits that use large MTU for music
> playback.
> ---
>  audio/avdtp.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 53 insertions(+), 0 deletions(-)

Thanks. The patch has been pushed upstream.

Johan

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

end of thread, other threads:[~2010-12-16 19:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-15  9:48 [PATCH 0/1] AVDTP SRC stream send buffer size verification Dmitriy Paliy
2010-12-15  9:48 ` [PATCH] Add " Dmitriy Paliy
2010-12-16 19:47   ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox