From: Stefan Schoenleitner <dev.c0debabe@gmail.com>
To: alsa-devel@alsa-project.org
Subject: io plugin: polling on unix socket, socket buffer sizes ?
Date: Tue, 22 Dec 2009 13:02:26 +0100 [thread overview]
Message-ID: <4B30B552.8030903@gmail.com> (raw)
Hi,
I'm currently writing an alsa io plugin that should exchange PCM samples
with another piece of software over a unix socket.
More precisely exactly 160 PCM samples with 16bit each should be
exchanged at a time.
AFAIK the alsa plugin framework works by utilizing poll().
Thus if the plugin is used for playback it would use POLLOUT on the
socket to see if the next chunk of data can be written to the socket
without blocking.
By reading quite a lot of alsa code (including pcm_bluetooth.c from
bluez) it seems that I need to set the socket buffer size to a value
small enough, right ?
Thus if I would like to send one period consisting of 160 samples (with
16bits each) at a time, I would need to set the unix send buffer size to
320 bytes.
This way some kind of handshaking between my application and the alsa
plugin would be established:
Each time the application reads a full period of data from the socket,
the alsa plugin will start to send the next period as poll() will return
the POLLOUT event.
(Thus the transfer callback function would be called in the plugin code.)
Is this correct so far ?
To test the behavior I wrote two small code snippets:
One is unix socket reader that reads a chunk of 10 bytes at a time and
then sleeps for 10 seconds.
The socket recv buffer size SO_RCVBUF has been set to 10 bytes with
setsockopt().
The other snippet is the unix socket writer:
It sets the socket send buffer size SO_SNDBUF to 10 bytes so that after
writing 10 bytes to the socket, poll with POLLOUT would block until the
other end (the reader) reads some bytes and the send buffer is drained.
The reader polls on the socket with a timeout of 1 sec and in case poll
returns the POLLOUT event, it writes a chunk of 10 bytes to the socket.
With these small code snippets I would expect the following behavior:
reply other threads:[~2009-12-22 12:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4B30B552.8030903@gmail.com \
--to=dev.c0debabe@gmail.com \
--cc=alsa-devel@alsa-project.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox