]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: implement snd_pcm_hw_params_get_sync() and obsolete snd_pcm_info_get_sync()
authorJaroslav Kysela <perex@perex.cz>
Tue, 20 Aug 2024 13:33:45 +0000 (15:33 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 20 Aug 2024 13:43:30 +0000 (15:43 +0200)
Use the new clock source mechanism to get information about
similar PCM clock sources for PCM streams.

Link: https://lore.kernel.org/linux-sound/20240625172836.589380-1-perex@perex.cz/
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
include/pcm.h
include/sound/uapi/asound.h
src/pcm/pcm.c

index 102ff8127d052a46eea737e2f779dc9b6ca0dd3d..b5c6788985be410ee25690db60ad5dee66c1bf96 100644 (file)
@@ -508,6 +508,9 @@ typedef union _snd_pcm_sync_id {
        unsigned int id32[4];
 } snd_pcm_sync_id_t;
 
+/** synchronization ID size (see snd_pcm_hw_params_get_sync) */
+#define SND_PCM_HW_PARAMS_SYNC_SIZE    16
+
 /** Infinite wait for snd_pcm_wait() */
 #define SND_PCM_WAIT_INFINITE          (-1)
 /** Wait for next i/o in snd_pcm_wait() */
@@ -747,6 +750,7 @@ int snd_pcm_hw_params_get_rate_numden(const snd_pcm_hw_params_t *params,
                                      unsigned int *rate_den);
 int snd_pcm_hw_params_get_sbits(const snd_pcm_hw_params_t *params);
 int snd_pcm_hw_params_get_fifo_size(const snd_pcm_hw_params_t *params);
+const unsigned char * snd_pcm_hw_params_get_sync(const snd_pcm_hw_params_t *params);
 
 #if 0
 typedef struct _snd_pcm_hw_strategy snd_pcm_hw_strategy_t;
index f3b2b94ddfd6dd176b76fc10d1f9cc6b01a217bf..012fd890b2c9cbbf9797bd8b5cf5006cc3151664 100644 (file)
@@ -426,7 +426,8 @@ struct snd_pcm_hw_params {
        unsigned int rate_num;          /* R: rate numerator */
        unsigned int rate_den;          /* R: rate denominator */
        snd_pcm_uframes_t fifo_size;    /* R: chip FIFO size in frames */
-       unsigned char reserved[64];     /* reserved for future */
+       unsigned char sync[16];         /* R: synchronization ID (perfect sync - one clock source) */
+       unsigned char reserved[48];     /* reserved for future */
 };
 
 enum {
index 62e76e7e04c313f83d548ddbcc8c49d219f7fe6e..f8581191964b49929417a9b1be612d013c9fe9ef 100644 (file)
@@ -494,8 +494,8 @@ software parameter.
 There are two functions allowing link multiple streams together. In the
 case, the linking means that all operations are synchronized. Because the
 drivers cannot guarantee the synchronization (sample resolution) on hardware
-lacking this feature, the #snd_pcm_info_get_sync() function
-returns synchronization ID - #snd_pcm_sync_id_t, which is equal
+lacking this feature, the #snd_pcm_hw_params_get_sync() function
+returns 16-byte synchronization ID, which is equal
 for hardware synchronized streams. When the #snd_pcm_link()
 function is called, all operations managing the stream state for these two
 streams are joined. The opposite function is #snd_pcm_unlink().
@@ -3948,6 +3948,25 @@ int snd_pcm_hw_params_get_fifo_size(const snd_pcm_hw_params_t *params)
        return params->fifo_size;
 }
 
+/**
+ * \brief Get hardware synchronization ID from a PCM info container
+ * \param params Configuration space
+ * \return 16-byte synchronization ID (use #SND_PCM_HW_PARAMS_SYNC_SIZE)
+ *
+ * This synchronization ID determines the similar clocks for the
+ * PCM stream between multiple devices (including different cards).
+ * "All zeros" means "not set". The contents of the ID can be used
+ * only for a comparison with the contents of another ID returned
+ * from this function. Applications should not do a comparison with
+ * hard-coded values, because the implementation generating such
+ * synchronization IDs may be changed in future.
+ */
+const unsigned char *snd_pcm_hw_params_get_sync(const snd_pcm_hw_params_t *params)
+{
+       assert(params);
+       return params->sync;
+}
+
 /**
  * \brief Fill params with a full configuration space for a PCM
  * \param pcm PCM handle
@@ -7332,7 +7351,7 @@ unsigned int snd_pcm_info_get_subdevices_avail(const snd_pcm_info_t *obj)
 }
 
 /**
- * \brief Get hardware synchronization ID from a PCM info container
+ * \brief (DEPRECATED) Get hardware synchronization ID from a PCM info container
  * \param obj PCM info container
  * \return hardware synchronization ID
  */
@@ -7340,9 +7359,12 @@ snd_pcm_sync_id_t snd_pcm_info_get_sync(const snd_pcm_info_t *obj)
 {
        snd_pcm_sync_id_t res;
        assert(obj);
-       memcpy(&res, &obj->sync, sizeof(res));
+       bzero(&res, sizeof(res));
        return res;
 }
+#ifndef DOC_HIDDEN
+link_warning(snd_pcm_info_get_sync, "Warning: snd_pcm_info_get_sync is deprecated, consider to use snd_pcm_hw_params_get_sync");
+#endif
 
 /**
  * \brief Set wanted device inside a PCM info container (see #snd_ctl_pcm_info)