expand dshare to allow audio clock when not streaming data
cover expand dshare to allow audio clock when not streaming data
The general idea of these changes is to be able to open the device without defined bindings. This would start the audio clock without blocking a channel.
This might be useful for hardware that requires running clock early at system start and to be available even without application streaming audio data.
Andreas Pape (2):
alsa: pcm: add unsupported OPS
alsa: dshare: allow missing bindings
src/pcm/Makefile.am | 4 +- src/pcm/pcm_dshare.c | 72 +++++++++++-- src/pcm/pcm_unsupported.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++ src/pcm/pcm_unsupported.h | 167 +++++++++++++++++++++++++++++ 4 files changed, 495 insertions(+), 13 deletions(-) create mode 100644 src/pcm/pcm_unsupported.c create mode 100644 src/pcm/pcm_unsupported.h
Signature · 1 line
2.7.4
PATCH 1/2 alsa: pcm: add unsupported OPS
From: Andreas Pape <[email protected]>
--- src/pcm/Makefile.am | 4 +- src/pcm/pcm_unsupported.c | 265 ++++++++++++++++++++++++++++++++++++++++++++++ src/pcm/pcm_unsupported.h | 166 +++++++++++++++++++++++++++++ 3 files changed, 433 insertions(+), 2 deletions(-) create mode 100644 src/pcm/pcm_unsupported.c create mode 100644 src/pcm/pcm_unsupported.h
src/pcm/Makefile.am +2 -2
@@ -8,7 +8,7 @@ libpcm_la_SOURCES = mask.c interval.c \ pcm_hw.c pcm_misc.c pcm_mmap.c pcm_symbols.c if BUILD_PCM_PLUGIN -libpcm_la_SOURCES += pcm_generic.c pcm_plugin.c +libpcm_la_SOURCES += pcm_generic.c pcm_plugin.c pcm_unsupported.c endif if BUILD_PCM_PLUGIN_COPY libpcm_la_SOURCES += pcm_copy.c
@@ -108,7 +108,7 @@ EXTRA_DIST = pcm_dmix_i386.c pcm_dmix_x86_64.c pcm_dmix_generic.c noinst_HEADERS = pcm_local.h pcm_plugin.h mask.h mask_inline.h \ interval.h interval_inline.h plugin_ops.h ladspa.h \ pcm_direct.h pcm_dmix_i386.h pcm_dmix_x86_64.h \ - pcm_generic.h pcm_ext_parm.h + pcm_generic.h pcm_ext_parm.h pcm_unsupported.h alsadir = $(datadir)/alsa
src/pcm/pcm_unsupported.c new file +265 -0
265 lines not on this page · raw message
src/pcm/pcm_unsupported.h new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPS
Quoted 5 lines · Adam Miartus
From: Andreas Pape <[email protected]>
Signed-off-by Andreas Pape <[email protected]>Signed-off-by Adam Miartus <[email protected]>
No description isn't good at all. There must be something you can explain in details here.
About the changes:
src/pcm/pcm_unsupported.c line 38
Quoted 5 lines
src/pcm/pcm_unsupported.c new file +5
-0+#define PCM_UNSUPPORTED_ERR (-ENOSYS) +void snd_pcm_unsupported_dump (snd_pcm_t *pcm,snd_output_t *out) +{ +snd_output_printf (out,"unsupported\n" ); +}
IMO, we don't need to show anything if it's dummy.
And, maybe it's more straightforward to let the PCM core allow NULL ops?
thanks,
Takashi
Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPS
Quoted 12 lines
-----Original Message-----
From: Takashi Iwai <[email protected]>
Sent: Dienstag, 9. Juli 2019 14:25
To: Miartus, Adam (Arion Recruitment; ADITG/ESM) <[email protected] jv.com>
Cc: [email protected]; Pape, Andreas (ADITG/ESS1) <[email protected]>
Subject: Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPSQuoted 1 line · Adam Miartus
Quoted 7 lines
Quoted 4 lines
From: Andreas Pape <[email protected]>
Signed-off-by Andreas Pape <[email protected]>Signed-off-by Adam Miartus <[email protected]>No description isn't good at all. There must be something you can explain in details here.
Certainly, I will add explanation in patch v2.
Quoted 6 lines
About the changes:
Review
Quoted 2 lines
(quoted diff) +2
-0+#define PCM_UNSUPPORTED_ERR (-ENOSYS) +void snd_pcm_unsupported_dump(snd_pcm_t *pcm, snd_output_t*out)
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+{ + snd_output_printf(out, "unsupported\n"); +}IMO, we don't need to show anything if it's dummy.
And, maybe it's more straightforward to let the PCM core allow NULL ops?
If you agree I could add following in patch v2, then we could drop snd_pcm_unsupported_dump function altogether
src/pcm/pcm.c +2 -1
@@ -2277,7 +2277,8 @@ int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out) {assert (pcm);assert (out); - pcm->ops->dump (pcm->op_arg, out); +if (pcm->ops->dump) + pcm->ops->dump (pcm->op_arg, out);return 0 ; }
Please let me know if you agree with proposed changes and I will prepare patch v2.
Adam
Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPS
Quoted 45 lines · Adam (Arion Recruitment; ADITG/ESM)
Quoted 13 lines
-----Original Message-----
From: Takashi Iwai <[email protected]>
Sent: Dienstag, 9. Juli 2019 14:25
To: Miartus, Adam (Arion Recruitment; ADITG/ESM) <[email protected] jv.com>
Cc: [email protected]; Pape, Andreas (ADITG/ESS1) <[email protected]>
Subject: Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPSQuoted 1 line · Adam Miartus
Quoted 7 lines
Quoted 4 lines
From: Andreas Pape <[email protected]>
Signed-off-by Andreas Pape <[email protected]>Signed-off-by Adam Miartus <[email protected]>No description isn't good at all. There must be something you can explain in details here.
Certainly, I will add explanation in patch v2.
Quoted 6 lines
About the changes:
Review
Quoted 2 lines
(quoted diff) +2
-0+#define PCM_UNSUPPORTED_ERR (-ENOSYS) +void snd_pcm_unsupported_dump(snd_pcm_t *pcm, snd_output_t*out)
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+{ + snd_output_printf(out, "unsupported\n"); +}IMO, we don't need to show anything if it's dummy.
And, maybe it's more straightforward to let the PCM core allow NULL ops?If you agree I could add following in patch v2, then we could drop
snd_pcm_unsupported_dumpfunction altogethersrc/pcm/pcm.c +0
-0
src/pcm/pcm.c int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out) · line 2283
Quoted 8 lines
src/pcm/pcm.c +2
-1@@ -2277,7 +2277,8 @@ int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out) {assert (pcm);assert (out); - pcm->ops->dump (pcm->op_arg, out); +if (pcm->ops->dump) + pcm->ops->dump (pcm->op_arg, out);return 0 ; }
I *guess* this would be simpler in the end, although I'm fine with your original idea, too. Let's see and compare the both results.
thanks,
Takashi
Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPS
Quoted 67 lines
-----Original Message-----
From: Takashi Iwai <[email protected]>
Sent: Mittwoch, 10. Juli 2019 17:00
To: Miartus, Adam (Arion Recruitment; ADITG/ESM) <[email protected] jv.com>
Cc: [email protected]; Pape, Andreas (ADITG/ESS1) <[email protected]>
Subject: Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPSQuoted 38 lines · Adam (Arion Recruitment; ADITG/ESM)
Quoted 13 lines
-----Original Message-----
From: Takashi Iwai <[email protected]>
Sent: Dienstag, 9. Juli 2019 14:25
To: Miartus, Adam (Arion Recruitment; ADITG/ESM) <[email protected] jv.com>
Cc: [email protected]; Pape, Andreas (ADITG/ESS1) <[email protected]>
Subject: Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPSQuoted 1 line · Adam Miartus
Quoted 7 lines
Quoted 4 lines
From: Andreas Pape <[email protected]>
Signed-off-by Andreas Pape <[email protected]>Signed-off-by Adam Miartus <[email protected]>No description isn't good at all. There must be something you can explain in details here.
Certainly, I will add explanation in patch v2.
Quoted 6 lines
About the changes:
Review
Quoted 2 lines
(quoted diff) +2
-0+#define PCM_UNSUPPORTED_ERR (-ENOSYS) +void snd_pcm_unsupported_dump(snd_pcm_t *pcm, snd_output_t*out)
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+{ + snd_output_printf(out, "unsupported\n"); +}IMO, we don't need to show anything if it's dummy.
And, maybe it's more straightforward to let the PCM core allow NULL ops?Quoted 1 line
If you agree I could add following in patch v2, then we could drop
snd_pcm_unsupported_dumpfunction altogethersrc/pcm/pcm.c int snd_pcm_dump(snd_pcm_t *pcm,
Quoted 6 lines
src/pcm/pcm.c +0
-0@@ -2277,7 +2277,8 @@ int snd_pcm_dump(snd_pcm_t *pcm,
snd_output_t*out)src/pcm/pcm.c int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out) · line 2283
Quoted 8 lines
src/pcm/pcm.c +2
-1{assert (pcm);assert (out); - pcm->ops->dump (pcm->op_arg, out); +if (pcm->ops->dump) + pcm->ops->dump (pcm->op_arg, out);return 0 ; }
Quoted 2 lines
I *guess* this would be simpler in the end, although I'm fine with your original idea, too. Let's see and compare the both results.
Yes I agree, it would even be better to remove the pcm_unsupported.c altogether. I had a look at how snd_pcm_ops_t and snd_pcm_fast_ops_t callbacks are used in alsa-lib and in most cases (90% or more) it is assumed that the function pointer is valid without checking for NULL.
Unfortunately, not all functions in ops and fast_ops share the same return type, so checking for null pointer in a macro is not straightforward. One way I see is to add:
if (ops->callback == NULL)
return -ENOSYS;
check in every occurrence of ops callback call in source code, then we could drop pcm_unsupported.c file completely.
Optionally we could add a set of macros such as (it compiled both in gcc and in clang)
#define snd_callback_int(fpointer, ...) ({ \
int result; \
if (fpointer == NULL) \
result = -ENOSYS; \
else \
result = fpointer(__VA_ARGS__); \
result; \
})For each ops function return types, currently these are:
int, void, snd_pcm_chmap_query_t**, snd_pcm_chmap_t *, snd_pcm_state_t, snd_pcm_sframes_t
So, the variants for macros would be:snd_callback_voidsnd_callback_intsnd_callback_ptrsnd_callback_sframes
This might seem like cumbersome approach but it would save lines of code and provide a way to check for null callback pointer, which is currently not done in most cases.
What do you think about these two approaches, what could you consider correct and able to be merged?
Adam
Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPS
Quoted 87 lines · Adam (Arion Recruitment; ADITG/ESM)
Quoted 68 lines
-----Original Message-----
From: Takashi Iwai <[email protected]>
Sent: Mittwoch, 10. Juli 2019 17:00
To: Miartus, Adam (Arion Recruitment; ADITG/ESM) <[email protected] jv.com>
Cc: [email protected]; Pape, Andreas (ADITG/ESS1) <[email protected]>
Subject: Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPSQuoted 38 lines · Adam (Arion Recruitment; ADITG/ESM)
Quoted 13 lines
-----Original Message-----
From: Takashi Iwai <[email protected]>
Sent: Dienstag, 9. Juli 2019 14:25
To: Miartus, Adam (Arion Recruitment; ADITG/ESM) <[email protected] jv.com>
Cc: [email protected]; Pape, Andreas (ADITG/ESS1) <[email protected]>
Subject: Re: [ALSA patch] [PATCH 1/2] alsa: pcm: add unsupported OPSQuoted 1 line · Adam Miartus
Quoted 7 lines
Quoted 4 lines
From: Andreas Pape <[email protected]>
Signed-off-by Andreas Pape <[email protected]>Signed-off-by Adam Miartus <[email protected]>No description isn't good at all. There must be something you can explain in details here.
Certainly, I will add explanation in patch v2.
Quoted 6 lines
About the changes:
Review
Quoted 2 lines
(quoted diff) +2
-0+#define PCM_UNSUPPORTED_ERR (-ENOSYS) +void snd_pcm_unsupported_dump(snd_pcm_t *pcm, snd_output_t*out)
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+{ + snd_output_printf(out, "unsupported\n"); +}IMO, we don't need to show anything if it's dummy.
And, maybe it's more straightforward to let the PCM core allow NULL ops?Quoted 1 line
If you agree I could add following in patch v2, then we could drop
snd_pcm_unsupported_dumpfunction altogethersrc/pcm/pcm.c int snd_pcm_dump(snd_pcm_t *pcm,
Quoted 6 lines
src/pcm/pcm.c +0
-0@@ -2277,7 +2277,8 @@ int snd_pcm_dump(snd_pcm_t *pcm,
snd_output_t*out)src/pcm/pcm.c int snd_pcm_dump(snd_pcm_t *pcm, snd_output_t *out) · line 2283
Quoted 8 lines
src/pcm/pcm.c +2
-1{assert (pcm);assert (out); - pcm->ops->dump (pcm->op_arg, out); +if (pcm->ops->dump) + pcm->ops->dump (pcm->op_arg, out);return 0 ; }Quoted 2 lines
I *guess* this would be simpler in the end, although I'm fine with your original idea, too. Let's see and compare the both results.
Yes I agree, it would even be better to remove the
pcm_unsupported.caltogether. I had a look at howsnd_pcm_ops_tandsnd_pcm_fast_ops_tcallbacks are used in alsa-lib and in most cases (90% or more) it is assumed that the function pointer is valid without checking for NULL.Unfortunately, not all functions in ops and
fast_opsshare the same return type, so checking for null pointer in a macro is not straightforward. One way I see is to add:if (
ops->callback== NULL)return -ENOSYS;check in every occurrence of ops callback call in source code, then we could drop
pcm_unsupported.cfile completely.Optionally we could add a set of macros such as (it compiled both in gcc and in clang)
Quoted 8 lines
#define snd_callback_int(fpointer, ...) ({ \
int result; \
if (fpointer == NULL) \
result = -ENOSYS; \
else \
result = fpointer(__VA_ARGS__); \
result; \
})I don't think we need to put too tricky code there. Even if it's a bit longer, the simple open code should be more understandable. So just add simply the NULL check at each place instead of macro including the control flow inside.
thanks,
Takashi
PATCH 2/2 alsa: dshare: allow missing bindings
In reply to Adam MiartusFrom: Andreas Pape <[email protected]>
The general idea of this patch is to be able to open the device without defined bindings. This would start the audio clock without blocking any channel.
This might be useful for hardware that requires running clock early at system start and to be available even without application streaming audio data.
--- src/pcm/pcm_dshare.c | 72 +++++++++++++++++++++++++++++++++++++++-------- src/pcm/pcm_unsupported.h | 1 + 2 files changed, 62 insertions(+), 11 deletions(-)
src/pcm/pcm_dshare.c +61 -11
@@ -44,6 +44,7 @@#include <sys/un.h> #include <sys/mman.h> #include "pcm_direct.h" +#include "pcm_unsupported.h" #ifndef PIC /* entry for static linking */
@@ -508,7 +509,8 @@ static int snd_pcm_dshare_close(snd_pcm_t *pcm)if (dshare->timer)snd_timer_close (dshare->timer); -do_silenca (pcm); +if (dshare->bindings) +do_silence (pcm);snd_pcm_direct_semaphore_down (dshare,DIRECT_IPC_SEM_CLIENT ); dshare->shmptr->u.dshare.chn_mask &= ~dshare->u.dshare.chn_mask;snd_pcm_close (dshare->spcm);
@@ -621,6 +623,54 @@ static void snd_pcm_dshare_dump(snd_pcm_t *pcm, snd_output_t *out)snd_pcm_dump (dshare->spcm, out); } +static const snd_pcm_ops_t snd_pcm_dshare_dummy_ops = { + .close = snd_pcm_dshare_close, + .info = snd_pcm_unsupported_info, + .hw_refine = snd_pcm_unsupported_hw_refine, + .hw_params = snd_pcm_unsupported_hw_params, + .hw_free = snd_pcm_unsupported_hw_free, + .sw_params = snd_pcm_unsupported_sw_params, + .channel_info = snd_pcm_unsupported_channel_info, + .dump = snd_pcm_unsupported_dump, + .nonblock = snd_pcm_unsupported_nonblock, + .async = snd_pcm_unsupported_async, + .mmap = snd_pcm_unsupported_mmap, + .munmap = snd_pcm_unsupported_munmap, + .get_chmap = snd_pcm_unsupported_get_chmap, + .set_chmap = snd_pcm_unsupported_set_chmap, +}; + +static const snd_pcm_fast_ops_t snd_pcm_dshare_fast_dummy_ops = { + .status = snd_pcm_unsupported_status, + .state = snd_pcm_unsupported_state, + .hwsync = snd_pcm_unsupported_hwsync, + .delay = snd_pcm_unsupported_delay, + .prepare = snd_pcm_unsupported_prepare, + .reset = snd_pcm_unsupported_reset, + .start = snd_pcm_unsupported_start, + .drop = snd_pcm_unsupported_drop, + .drain = snd_pcm_unsupported_drain, + .pause = snd_pcm_unsupported_pause, + .rewindable = snd_pcm_unsupported_rewindable, + .rewind = snd_pcm_unsupported_rewind, + .forwardable = snd_pcm_unsupported_forwardable, + .forward = snd_pcm_unsupported_forward, + .resume = snd_pcm_unsupported_resume, + .link =NULL , + .link_slaves =NULL , + .unlink =NULL , + .writei = snd_pcm_unsupported_writei, + .writen = snd_pcm_unsupported_writen, + .readi = snd_pcm_unsupported_readi, + .readn = snd_pcm_unsupported_readn, + .avail_update = snd_pcm_unsupported_avail_update, + .mmap_commit = snd_pcm_unsupported_mmap_commit, + .htimestamp = snd_pcm_unsupported_htimestamp, + .poll_descriptors = snd_pcm_unsupported_poll_descriptors, + .poll_descriptors_count =NULL , + .poll_revents = snd_pcm_unsupported_poll_revents, +}; +static const snd_pcm_ops_t snd_pcm_dshare_ops = { .close = snd_pcm_dshare_close, .info = snd_pcm_direct_info,
@@ -713,12 +763,7 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,if (ret <0 ) goto _err_nosem; -if (!dshare->bindings) { -SNDERR ("dshare: specify bindings!!!" ); - ret = -EINVAL ; - goto _err_nosem; - } - + dshare->ipc_key = opts->ipc_key; dshare->ipc_perm = opts->ipc_perm; dshare->ipc_gid = opts->ipc_gid;
@@ -751,9 +796,14 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name,SNDERR ("unable to create IPC shm instance" ); goto _err; } - - pcm->ops = &snd_pcm_dshare_ops; - pcm->fast_ops = &snd_pcm_dshare_fast_ops; + +if (!dshare->bindings) { + pcm->ops = &snd_pcm_dshare_dummy_ops; + pcm->fast_ops = &snd_pcm_dshare_fast_dummy_ops; + }else { + pcm->ops = &snd_pcm_dshare_ops; + pcm->fast_ops = &snd_pcm_dshare_fast_ops; + } pcm->private_data = dshare; dshare->state =SND_PCM_STATE_OPEN ; dshare->slowptr = opts->slowptr;
@@ -843,7 +893,7 @@ int snd_pcm_dshare_open(snd_pcm_t **pcmp, const char *name, dshare->spcm = spcm; } -for (chn =0 ; chn < dshare->channels; chn++) { +for (chn =0 ; dshare->bindings && (chn < dshare->channels); chn++) {unsigned int dchn = dshare->bindings ? dshare->bindings[chn] : chn;if (dchn !=UINT_MAX ) dshare->u.dshare.chn_mask |= (1ULL << dchn);
src/pcm/pcm_unsupported.h +1 -0
@@ -114,6 +114,7 @@#define snd_pcm_unsupported_may_wait_for_avail_min \ snd1_pcm_unsupported_may_wait_for_avail_min +void snd_pcm_unsupported_dump (snd_pcm_t *pcm,snd_output_t *out);int snd_pcm_unsupported_close (snd_pcm_t *pcm);int snd_pcm_unsupported_nonblock (snd_pcm_t *pcm,int nonblock);int snd_pcm_unsupported_async (snd_pcm_t *pcm,int sig,pid_t pid);
Signature · 1 line
2.7.4