alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: alsa@scripple.org
To: alsa-devel@alsa-project.org
Subject: Accessing pending hw_params in SND_PCM_HOOK_TYPE_HW_PARAMS call back
Date: Tue, 13 Oct 2020 13:59:27 -0700	[thread overview]
Message-ID: <162e9d94-86f6-864e-443b-6a2096d1f33d@schells.com> (raw)

Hello,

I'll try again with a more specific question.

Is there a way one can access the hw_params that cause the 
SND_PCM_HOOK_TYPE_HW_PARAMS call back to be called inside the call back 
function?

The hook only provides access to the snd_pcm_t object, but all the 
public calls to get hw_params fail because it's not in a prepared state yet.

If there isn't a way to get them now could we please add the ability 
with a patch like the one below?

With this patch a call to snd_pcm_hook_get_hw_params provides access to 
the pending hw_params structure and the pending parameters can be 
accessed with standard calls like snd_pcm_hw_params_get_channels.

Hopefully I'm just missing how to get them without the patch, but if not 
they really should be made accessible.


diff --git a/alsa-lib-1.1.8/include/pcm.h b/pcm.h
index 5b07823..0cf5dca 100644
--- a/alsa-lib-1.1.8/include/pcm.h
+++ b/pcm.h
@@ -1181,6 +1181,7 @@ typedef struct _snd_pcm_hook snd_pcm_hook_t;
  /** PCM hook callback function */
  typedef int (*snd_pcm_hook_func_t)(snd_pcm_hook_t *hook);
  snd_pcm_t *snd_pcm_hook_get_pcm(snd_pcm_hook_t *hook);
+snd_pcm_hw_params_t *snd_pcm_hook_get_hw_params(snd_pcm_hook_t *hook);
  void *snd_pcm_hook_get_private(snd_pcm_hook_t *hook);
  void snd_pcm_hook_set_private(snd_pcm_hook_t *hook, void *private_data);
  int snd_pcm_hook_add(snd_pcm_hook_t **hookp, snd_pcm_t *pcm,



diff --git a/alsa-lib-1.1.8/src/pcm/pcm_hooks.c b/pcm_hooks.c
index 4416d36..f56c3af 100644
--- a/alsa-lib-1.1.8/src/pcm/pcm_hooks.c
+++ b/pcm_hooks.c
@@ -38,6 +38,7 @@ const char *_snd_module_pcm_hooks = "";
  #ifndef DOC_HIDDEN
  struct _snd_pcm_hook {
         snd_pcm_t *pcm;
+       snd_pcm_hw_params_t *params;
         snd_pcm_hook_func_t func;
         void *private_data;
         struct list_head list;
@@ -117,6 +118,7 @@ static int snd_pcm_hooks_hw_params(snd_pcm_t *pcm, 
snd_pcm_hw_params_t *params)
                 return err;
         list_for_each_safe(pos, next, 
&h->hooks[SND_PCM_HOOK_TYPE_HW_PARAMS]) {
                 snd_pcm_hook_t *hook = list_entry(pos, snd_pcm_hook_t, 
list);
+               hook->params = params;
                 err = hook->func(hook);
                 if (err < 0)
                         return err;
@@ -563,6 +565,17 @@ snd_pcm_t *snd_pcm_hook_get_pcm(snd_pcm_hook_t *hook)
         return hook->pcm;
  }

+/**
+ * \brief Get hw_params handle for a PCM hook
+ * \param hook PCM hook handle
+ * \return hw_params handle
+ */
+snd_pcm_hw_params_t *snd_pcm_hook_get_hw_params(snd_pcm_hook_t *hook)
+{
+       assert(hook);
+       return hook->params;
+}
+
  /**
   * \brief Get callback function private data for a PCM hook
   * \param hook PCM hook handle
@@ -609,6 +622,7 @@ int snd_pcm_hook_add(snd_pcm_hook_t **hookp, 
snd_pcm_t *pcm,
         if (!h)
                 return -ENOMEM;
         h->pcm = pcm;
+       h->params = NULL;
         h->func = func;
         h->private_data = private_data;
         hooks = pcm->private_data;

                 reply	other threads:[~2020-10-13 21:00 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=162e9d94-86f6-864e-443b-6a2096d1f33d@schells.com \
    --to=alsa@scripple.org \
    --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;
as well as URLs for NNTP newsgroup(s).