All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Wischer, Timo (ADITG/ESB)" <twischer@de.adit-jv.com>
To: "patch@alsa-project.org" <patch@alsa-project.org>
Cc: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>
Subject: Re: [PATCH - JACK PCM plugin] jack: Use boundary as hw_ptr wrap around
Date: Fri, 9 Feb 2018 13:11:40 +0000	[thread overview]
Message-ID: <B0FB33DC1499054591F62C0EF1E013D7684F8022@HI2EXCH01.adit-jv.com> (raw)
In-Reply-To: <1516794545-9868-1-git-send-email-twischer@de.adit-jv.com>

Hello all,

[1] was merged as it is (see [2])
Therefore this commit can be merged without conflicts, now.

Please have a look.

[1] http://mailman.alsa-project.org/pipermail/alsa-devel/2018-January/130942.html
[2] http://git.alsa-project.org/?p=alsa-plugins.git;a=commit;h=21839e981a4b7c7178c1a473f20460c003e13db4

Best regards

Timo Wischer

Advanced Driver Information Technology GmbH
Engineering Software Base (ADITG/ESB)
Robert-Bosch-Str. 200
31139 Hildesheim
Germany

Tel. +49 5121 49 6938
Fax +49 5121 49 6999
twischer@de.adit-jv.com

ADIT is a joint venture company of Robert Bosch GmbH/Robert Bosch Car Multimedia GmbH and DENSO Corporation
Sitz: Hildesheim, Registergericht: Amtsgericht Hildesheim HRB 3438
Geschäftsführung: Wilhelm Grabow, Ken Yaguchi

________________________________________
From: Wischer, Timo (ADITG/ESB)
Sent: Wednesday, January 24, 2018 12:49 PM
To: patch@alsa-project.org
Cc: alsa-devel@alsa-project.org; Wischer, Timo (ADITG/ESB)
Subject: [PATCH - JACK PCM plugin] jack: Use boundary as hw_ptr wrap around

From: Timo Wischer <twischer@de.adit-jv.com>

instead of using buffer_size as wrap around.

This is required to detect Xruns.

It is also required to allow the JACK thread
to processes the whole ALSA audio buffer at once
without calling snd_pcm_avail_update() in between.

For example when the hw_ptr will be updated with
hw_ptr += buffer_size
and it is using the buffer_size as wrap around
hw_ptr %= buffer_size
would result in the same value as before the add operation.

Due to that the user application would not recognize
that the complete audio buffer was copied.

Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
---

This patch is depending on
http://mailman.alsa-project.org/pipermail/alsa-devel/2018-January/130942.html

diff --git a/jack/pcm_jack.c b/jack/pcm_jack.c
index 3aed332..c22a5d0 100644
--- a/jack/pcm_jack.c
+++ b/jack/pcm_jack.c
@@ -40,6 +40,7 @@ typedef struct {

        char **port_names;
        unsigned int num_ports;
+       snd_pcm_uframes_t boundary;
        unsigned int hw_ptr;
        unsigned int sample_bits;
        snd_pcm_uframes_t min_avail;
@@ -130,6 +131,21 @@ static int snd_pcm_jack_poll_revents(snd_pcm_ioplug_t *io,
 static snd_pcm_sframes_t snd_pcm_jack_pointer(snd_pcm_ioplug_t *io)
 {
        snd_pcm_jack_t *jack = io->private_data;
+
+       /* ALSA library is calulating the delta between the last pointer and
+        * the current one.
+        * Normally it is expecting a value between 0 and buffer_size.
+        * The following example would result in an negative delta
+        * which would result in a hw_ptr which will be reduced.
+        *  last_hw = jack->boundary - io->buffer_size
+        *  hw = 0
+        * But we cannot use
+        * return jack->hw_ptr % io->buffer_size;
+        * because in this case an update of
+        * hw_ptr += io->buffer_size
+        * would not be recognized by the ALSA library.
+        * Therefore we are using jack->boundary as the wrap around.
+        */
        return jack->hw_ptr;
 }

@@ -162,7 +178,7 @@ snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io)

        while (xfer < nframes) {
                snd_pcm_uframes_t frames = nframes - xfer;
-               snd_pcm_uframes_t offset = hw_ptr;
+               snd_pcm_uframes_t offset = hw_ptr % io->buffer_size;
                snd_pcm_uframes_t cont = io->buffer_size - offset;

                if (cont < frames)
@@ -176,7 +192,8 @@ snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io)
                }

                hw_ptr += frames;
-               hw_ptr %= io->buffer_size;
+               if (hw_ptr >= jack->boundary)
+                       hw_ptr -= jack->boundary;
                xfer += frames;
        }
        jack->hw_ptr = hw_ptr;
@@ -200,6 +217,8 @@ static int snd_pcm_jack_prepare(snd_pcm_ioplug_t *io)
        err = snd_pcm_sw_params_current(io->pcm, swparams);
        if (err == 0) {
                snd_pcm_sw_params_get_avail_min(swparams, &jack->min_avail);
+               /* get boundary for available calulation */
+               snd_pcm_sw_params_get_boundary(swparams, &jack->boundary);
        }

        /* deactivate jack connections if this is XRUN recovery */
--
2.7.4

  reply	other threads:[~2018-02-09 13:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-24 11:49 [PATCH - JACK PCM plugin] jack: Use boundary as hw_ptr wrap around twischer
2018-02-09 13:11 ` Wischer, Timo (ADITG/ESB) [this message]
2018-02-13  5:40 ` Takashi Iwai
2018-02-13 14:56   ` Wischer, Timo (ADITG/ESB)
2018-02-13 17:03     ` Takashi Iwai
2018-02-15 10:36       ` Wischer, Timo (ADITG/ESB)
2018-02-15 11:32         ` Takashi Iwai
2018-02-23  9:28           ` [PATCH IO plug API 1/1] ioplug: Use boundary for " twischer
2018-02-23 10:40             ` Takashi Iwai
2018-02-23 13:52               ` Takashi Iwai
2018-02-23 14:18                 ` [PATCH - JACK PCM plugin] jack: Use boundary as hw_ptr " twischer
2018-02-24 10:43                   ` Takashi Iwai

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=B0FB33DC1499054591F62C0EF1E013D7684F8022@HI2EXCH01.adit-jv.com \
    --to=twischer@de.adit-jv.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=patch@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.