]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: hw: introduce SNDRV_PCM_INFO_PERFECT_DRAIN
authorJaroslav Kysela <perex@perex.cz>
Tue, 25 Apr 2023 12:36:19 +0000 (14:36 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 3 May 2023 12:00:57 +0000 (14:00 +0200)
Handle the driver informing us that it is not necessary to set up
silencing upon playback draining. This will be the case for drivers
which are guaranteed to not read any samples beyond the application
pointer.

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/pcm.h
include/sound/uapi/asound.h
src/pcm/pcm.c
src/pcm/pcm_hw.c
src/pcm/pcm_local.h

index b5a514fa6cbee11a4b0bed4eb55e8e6dc9558504..dd031b6cc8cf1d3ef75747598c2f2f8941844b7c 100644 (file)
@@ -722,6 +722,7 @@ int snd_pcm_hw_params_is_half_duplex(const snd_pcm_hw_params_t *params);
 int snd_pcm_hw_params_is_joint_duplex(const snd_pcm_hw_params_t *params);
 int snd_pcm_hw_params_can_sync_start(const snd_pcm_hw_params_t *params);
 int snd_pcm_hw_params_can_disable_period_wakeup(const snd_pcm_hw_params_t *params);
+int snd_pcm_hw_params_is_perfect_drain(const snd_pcm_hw_params_t *params);
 int snd_pcm_hw_params_supports_audio_wallclock_ts(const snd_pcm_hw_params_t *params); /* deprecated, use audio_ts_type */
 int snd_pcm_hw_params_supports_audio_ts_type(const snd_pcm_hw_params_t *params, int type);
 int snd_pcm_hw_params_get_rate_numden(const snd_pcm_hw_params_t *params,
index fc18c024fc629dcaa5d3557828e5ce8395c9a633..0b8834f24dba7d4d4c76f98b5638d146bb858cc0 100644 (file)
@@ -281,6 +281,7 @@ typedef int __bitwise snd_pcm_subformat_t;
 #define SNDRV_PCM_INFO_DOUBLE          0x00000004      /* Double buffering needed for PCM start/stop */
 #define SNDRV_PCM_INFO_BATCH           0x00000010      /* double buffering */
 #define SNDRV_PCM_INFO_SYNC_APPLPTR    0x00000020      /* need the explicit sync of appl_ptr update */
+#define SNDRV_PCM_INFO_PERFECT_DRAIN   0x00000040      /* silencing at the end of stream is not required */
 #define SNDRV_PCM_INFO_INTERLEAVED     0x00000100      /* channels are interleaved */
 #define SNDRV_PCM_INFO_NONINTERLEAVED  0x00000200      /* channels are not interleaved */
 #define SNDRV_PCM_INFO_COMPLEX         0x00000400      /* complex frame organization (mmap only) */
index 88b13ed43141cffa72e3173e8ea7cf6386208330..d387da3d83a5767c3f9137d704bc09c049aa225b 100644 (file)
@@ -3707,6 +3707,29 @@ int snd_pcm_hw_params_can_disable_period_wakeup(const snd_pcm_hw_params_t *param
        return !!(params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP);
 }
 
+/**
+ * \brief Check if hardware is capable of perfect drain
+ * \param params Configuration space
+ * \retval 0 Hardware doesn't do perfect drain
+ * \retval 1 Hardware does perfect drain
+ *
+ * This function should only be called when the configuration space
+ * contains a single configuration. Call #snd_pcm_hw_params to choose
+ * a single configuration from the configuration space.
+ *
+ * Perfect drain means that the hardware does not use samples
+ * beyond the stream application pointer.
+ */
+int snd_pcm_hw_params_is_perfect_drain(const snd_pcm_hw_params_t *params)
+{
+       assert(params);
+       if (CHECK_SANITY(params->info == ~0U)) {
+               SNDMSG("invalid PCM info field");
+               return 0; /* FIXME: should be a negative error? */
+       }
+       return !!(params->info & SNDRV_PCM_INFO_PERFECT_DRAIN);
+}
+
 /**
  * \brief Check if hardware supports audio wallclock timestamps
  * \param params Configuration space
index 6d7b2d48df98eb6403792d9ccf0d1074f74f8cda..37a18b863dee4940e72cef9026bffa3a90bc67cf 100644 (file)
@@ -99,6 +99,7 @@ typedef struct {
        struct snd_pcm_sync_ptr *sync_ptr;
 
        bool prepare_reset_sw_params;
+       bool perfect_drain;
 
        int period_event;
        snd_timer_t *period_timer;
@@ -398,6 +399,7 @@ static int snd_pcm_hw_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
        params->info &= ~0xf0000000;
        if (pcm->tstamp_type != SND_PCM_TSTAMP_TYPE_GETTIMEOFDAY)
                params->info |= SND_PCM_INFO_MONOTONIC;
+       hw->perfect_drain = !!(params->info & SND_PCM_INFO_PERFECT_DRAIN);
        return query_status_data(hw);
 }
 
@@ -739,7 +741,7 @@ static int snd_pcm_hw_drain(snd_pcm_t *pcm)
 
        if (pcm->stream != SND_PCM_STREAM_PLAYBACK)
                goto __skip_silence;
-       if (hw->drain_silence == 0)
+       if (hw->drain_silence == 0 || hw->perfect_drain)
                goto __skip_silence;
        snd_pcm_sw_params_current_no_lock(pcm, &sw_params);
        if (hw->drain_silence > 0) {
index 4a859cd12ec00f220accc70a59cfbd954b6a216c..b039dda00717f409ba4d5c54c913683b3302421b 100644 (file)
@@ -79,6 +79,8 @@
 #define SND_PCM_INFO_DOUBLE SNDRV_PCM_INFO_DOUBLE
 /** device transfers samples in batch */
 #define SND_PCM_INFO_BATCH SNDRV_PCM_INFO_BATCH
+/** device does perfect drain (silencing not required) */
+#define SND_PCM_INFO_PERFECT_DRAIN SNDRV_PCM_INFO_PERFECT_DRAIN
 /** device accepts interleaved samples */
 #define SND_PCM_INFO_INTERLEAVED SNDRV_PCM_INFO_INTERLEAVED
 /** device accepts non-interleaved samples */