From: Andrei Emeltchenko <Andrei.Emeltchenko.news@gmail.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCHv4 12/12] android/audio: Add write to SCO
Date: Fri, 9 May 2014 11:14:10 +0300 [thread overview]
Message-ID: <20140509081408.GD23010@aemeltch-MOBL1> (raw)
In-Reply-To: <CABBYNZ+QNsM9aQ_5gM_dYYtSp9PP0YsSE+=4yHrvJbm1HBe06A@mail.gmail.com>
Hi Luiz,
On Thu, May 08, 2014 at 04:51:48PM +0300, Luiz Augusto von Dentz wrote:
> Hi Andrei,
>
> On Thu, May 8, 2014 at 3:25 PM, Andrei Emeltchenko
> <Andrei.Emeltchenko.news@gmail.com> wrote:
> > From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
> >
> > For synchronization interleave read() and write().
> > ---
> > android/hal-sco.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > 1 file changed, 73 insertions(+)
> >
> > diff --git a/android/hal-sco.c b/android/hal-sco.c
> > index 7b6608b..5ec56ce 100644
> > --- a/android/hal-sco.c
> > +++ b/android/hal-sco.c
> > @@ -41,6 +41,8 @@
> > #define OUT_BUFFER_SIZE 2560
> > #define OUT_STREAM_FRAMES 2560
> >
> > +#define SOCKET_POLL_TIMEOUT_MS 500
> > +
> > static int listen_sk = -1;
> > static int audio_sk = -1;
> >
> > @@ -275,6 +277,74 @@ static void downmix_to_mono(struct sco_stream_out *out, const uint8_t *buffer,
> > }
> > }
> >
> > +static bool write_data(struct sco_stream_out *out, const uint8_t *buffer,
> > + size_t bytes)
> > +{
> > + struct pollfd pfd;
> > + size_t len, written = 0;
> > + int ret;
> > + uint16_t mtu = /* out->cfg.mtu */ 48;
> > + uint8_t read_buf[mtu];
> > + bool do_write = false;
> > +
> > + pfd.fd = out->fd;
> > + pfd.events = POLLOUT | POLLIN | POLLHUP | POLLNVAL;
> > +
> > + while (bytes > written) {
> > +
> > + /* poll for sending */
> > + if (poll(&pfd, 1, SOCKET_POLL_TIMEOUT_MS) == 0) {
> > + DBG("timeout fd %d", out->fd);
> > + return false;
> > + }
> > +
> > + if (pfd.revents & (POLLHUP | POLLNVAL)) {
> > + error("error fd %d, events 0x%x", out->fd, pfd.revents);
> > + return false;
> > + }
> > +
> > + if (pfd.revents & POLLIN) {
> > + ret = read(out->fd, read_buf, mtu);
> > + if (ret < 0) {
> > + error("Error reading fd %d (%s)", out->fd,
> > + strerror(errno));
> > + return false;
> > + }
> > +
> > + do_write = true;
>
> You probably gonna have store the read data in a buffer to be read by
> upper layer after remixed to 44.1 KHz, to safe space you can probably
> leave the remixing to be done on the read callback. Im fine to do this
> in a separate patch but we should at least add a comment about it.
I think we need to have special thread which does read-write since Android
might call read() without write().
Best regards
Andrei Emeltchenko
next prev parent reply other threads:[~2014-05-09 8:14 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-08 12:25 [PATCHv4 01/12] android/hal-sco: Add audio HAL for SCO handling Andrei Emeltchenko
2014-05-08 12:25 ` [PATCHv4 02/12] android/hal-audio-hsp: Add open_output_stream() Andrei Emeltchenko
2014-05-08 12:25 ` [PATCHv4 03/12] android/audio: Add Audio SCO message API Andrei Emeltchenko
2014-05-08 12:25 ` [PATCHv4 04/12] android/handsfree: Add SCO Audio IPC Andrei Emeltchenko
2014-05-08 13:22 ` Luiz Augusto von Dentz
2014-05-09 7:32 ` Andrei Emeltchenko
2014-05-09 7:37 ` Andrei Emeltchenko
2014-05-09 8:02 ` Szymon Janc
2014-05-09 8:06 ` Luiz Augusto von Dentz
2014-05-09 8:07 ` Andrei Emeltchenko
2014-05-09 8:11 ` Luiz Augusto von Dentz
2014-05-09 8:13 ` Szymon Janc
2014-05-08 12:25 ` [PATCHv4 05/12] android/hal-sco: Implement Audio IPC on Audio HAL Andrei Emeltchenko
2014-05-08 13:24 ` Luiz Augusto von Dentz
2014-05-08 12:25 ` [PATCHv4 06/12] android/ipc: Use error printing error messages Andrei Emeltchenko
2014-05-08 13:27 ` Luiz Augusto von Dentz
2014-05-08 12:25 ` [PATCHv4 07/12] android/haltest: Add testinng for audio SCO HAL Andrei Emeltchenko
2014-05-08 13:31 ` Luiz Augusto von Dentz
2014-05-08 12:25 ` [PATCHv4 08/12] android/audio: Add resampler support Andrei Emeltchenko
2014-05-08 12:25 ` [PATCHv4 09/12] audio/haltest: Make audio_stream static Andrei Emeltchenko
2014-05-08 12:25 ` [PATCHv4 10/12] android/audio: Add downmix support to audio SCO HAL Andrei Emeltchenko
2014-05-08 12:25 ` [PATCHv4 11/12] android/audio: Use resampler interface to resample SCO Andrei Emeltchenko
2014-05-08 12:25 ` [PATCHv4 12/12] android/audio: Add write to SCO Andrei Emeltchenko
2014-05-08 13:51 ` Luiz Augusto von Dentz
2014-05-09 8:14 ` Andrei Emeltchenko [this message]
2014-05-09 8:16 ` Luiz Augusto von Dentz
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=20140509081408.GD23010@aemeltch-MOBL1 \
--to=andrei.emeltchenko.news@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
/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