OSDN Git Service

Replaced snd_pcm_avail() with snd_pcm_hwsync()
[android-x86/external-alsa-lib.git] / src / pcm / pcm_hw.c
index 3a87349..c1e9a34 100644 (file)
@@ -77,9 +77,11 @@ struct sndrv_pcm_hw_params_old {
 #define SND_PCM_IOCTL_HW_REFINE_OLD _IOWR('A', 0x10, struct sndrv_pcm_hw_params_old)
 #define SND_PCM_IOCTL_HW_PARAMS_OLD _IOWR('A', 0x11, struct sndrv_pcm_hw_params_old)
 
-#define SND_PCM_IOCTL_XRUN _IO('A', 0x48)
+#define SND_PCM_IOCTL_HWSYNC _IO ('A', 0x22)
+#define SND_PCM_IOCTL_XRUN   _IO ('A', 0x48)
 
 static int use_old_hw_params_ioctl(int fd, unsigned int cmd, snd_pcm_hw_params_t *params);
+static snd_pcm_sframes_t snd_pcm_hw_avail_update(snd_pcm_t *pcm);
 
 /*
  *
@@ -101,7 +103,7 @@ typedef struct {
 
 #define SNDRV_FILE_PCM_STREAM_PLAYBACK         "/dev/snd/pcmC%iD%ip"
 #define SNDRV_FILE_PCM_STREAM_CAPTURE          "/dev/snd/pcmC%iD%ic"
-#define SNDRV_PCM_VERSION_MAX                  SNDRV_PROTOCOL_VERSION(2, 0, 2)
+#define SNDRV_PCM_VERSION_MAX                  SNDRV_PROTOCOL_VERSION(2, 0, 3)
 
 /* update appl_ptr with driver */
 #define UPDATE_SHADOW_PTR(hw) \
@@ -270,7 +272,7 @@ static int snd_pcm_hw_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t * params)
                        *params = old;
                        pmask = snd_pcm_hw_param_get_mask(params, SND_PCM_HW_PARAM_ACCESS);
                        oldmask = *(snd_pcm_access_mask_t *)pmask;
-                       if (snd_pcm_hw_params_get_access(params, &access) < 0)
+                       if (INTERNAL(snd_pcm_hw_params_get_access)(params, &access) < 0)
                                goto _err;
                        switch (access) {
                        case SND_PCM_ACCESS_MMAP_INTERLEAVED:
@@ -393,6 +395,31 @@ static int snd_pcm_hw_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
        return 0;
 }
 
+static int snd_pcm_hw_hwsync(snd_pcm_t *pcm)
+{
+       snd_pcm_hw_t *hw = pcm->private_data;
+       int fd = hw->fd;
+       if (SNDRV_PROTOCOL_VERSION(2, 0, 3) <= hw->version) {
+               if (ioctl(fd, SND_PCM_IOCTL_HWSYNC) < 0) {
+                       // SYSERR("SND_PCM_IOCTL_HWSYNC failed");
+                       return -errno;
+               }
+       } else {
+               snd_pcm_sframes_t delay;
+               int err = snd_pcm_hw_delay(pcm, &delay);
+               if (err < 0) {
+                       switch (snd_pcm_state(pcm)) {
+                       case SND_PCM_STATE_PREPARED:
+                       case SND_PCM_STATE_SUSPENDED:
+                               return 0;
+                       default:
+                               return err;
+                       }
+               }
+       }
+       return 0;
+}
+
 static int snd_pcm_hw_prepare(snd_pcm_t *pcm)
 {
        snd_pcm_hw_t *hw = pcm->private_data;
@@ -757,6 +784,7 @@ static snd_pcm_ops_t snd_pcm_hw_ops = {
 static snd_pcm_fast_ops_t snd_pcm_hw_fast_ops = {
        status: snd_pcm_hw_status,
        state: snd_pcm_hw_state,
+       hwsync: snd_pcm_hw_hwsync,
        delay: snd_pcm_hw_delay,
        prepare: snd_pcm_hw_prepare,
        reset: snd_pcm_hw_reset,
@@ -1016,8 +1044,10 @@ SND_DLSYM_BUILD_VERSION(_snd_pcm_hw_open, SND_PCM_DLSYM_VERSION);
  *  To be removed helpers, but keep binary compatibility at the time
  */
 
+#ifndef DOC_HIDDEN
 #define __OLD_TO_NEW_MASK(x) ((x&7)|((x&0x07fffff8)<<5))
 #define __NEW_TO_OLD_MASK(x) ((x&7)|((x&0xffffff00)>>5))
+#endif
 
 static void snd_pcm_hw_convert_from_old_params(snd_pcm_hw_params_t *params,
                                               struct sndrv_pcm_hw_params_old *oparams)