int snd_pcm_resume(snd_pcm_t *pcm);
int snd_pcm_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail, snd_htimestamp_t *tstamp);
snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t *pcm);
+snd_pcm_sframes_t snd_pcm_rewindable(snd_pcm_t *pcm);
snd_pcm_sframes_t snd_pcm_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
+snd_pcm_sframes_t snd_pcm_forwardable(snd_pcm_t *pcm);
snd_pcm_sframes_t snd_pcm_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
return pcm->fast_ops->pause(pcm->fast_op_arg, enable);
}
+/**
+ * \brief Get safe count of frames which can be rewinded
+ * \param pcm PCM handle
+ * \return a positive number of frames or negative error code
+ *
+ * Note: The snd_pcm_rewind() can accept bigger value than returned
+ * by this function. But it is not guaranteed that output stream
+ * will be consistent with bigger value.
+ */
+snd_pcm_sframes_t snd_pcm_rewindable(snd_pcm_t *pcm)
+{
+ assert(pcm);
+ if (CHECK_SANITY(! pcm->setup)) {
+ SNDMSG("PCM not set up");
+ return -EIO;
+ }
+ return pcm->fast_ops->rewindable(pcm->fast_op_arg);
+}
+
/**
* \brief Move application frame position backward
* \param pcm PCM handle
return pcm->fast_ops->rewind(pcm->fast_op_arg, frames);
}
+/**
+ * \brief Get safe count of frames which can be forwarded
+ * \param pcm PCM handle
+ * \return a positive number of frames or negative error code
+ *
+ * Note: The snd_pcm_forward() can accept bigger value than returned
+ * by this function. But it is not guaranteed that output stream
+ * will be consistent with bigger value.
+ */
+snd_pcm_sframes_t snd_pcm_forwardable(snd_pcm_t *pcm)
+{
+ assert(pcm);
+ if (CHECK_SANITY(! pcm->setup)) {
+ SNDMSG("PCM not set up");
+ return -EIO;
+ }
+ return pcm->fast_ops->forwardable(pcm->fast_op_arg);
+}
+
/**
* \brief Move application frame position forward
* \param pcm PCM handle
return !!(params->info & SNDRV_PCM_INFO_OVERRANGE);
}
-/**
- * \brief Check, if device supports forward
- * \param params Configuration space
- * \return Boolean value
- * \retval 0 Device doesn't support forward
- * \retval 1 Device supports forward
- *
- * It is not allowed to call this function when given configuration is not exactly one.
- * Usually, #snd_pcm_hw_params() function chooses one configuration
- * from the configuration space.
- */
-int snd_pcm_hw_params_can_forward(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 & SND_PCM_INFO_FORWARD);
-}
-
-/**
- * \brief Check, if device supports rewind
- * \param params Configuration space
- * \return Boolean value
- * \retval 0 Device doesn't support rewind
- * \retval 1 Device supports rewind
- *
- * It is not allowed to call this function when given configuration is not exactly one.
- * Usually, #snd_pcm_hw_params() function chooses one configuration
- * from the configuration space.
- */
-int snd_pcm_hw_params_can_rewind(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 & SND_PCM_INFO_REWIND);
-}
-
/**
* \brief Check, if hardware supports pause
* \param params Configuration space
return -EIO;
}
+static snd_pcm_sframes_t snd_pcm_dmix_rewindable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_hw_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_dmix_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_direct_t *dmix = pcm->private_data;
return result + frames;
}
+static snd_pcm_sframes_t snd_pcm_dmix_forwardable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_dmix_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_sframes_t avail;
.drop = snd_pcm_dmix_drop,
.drain = snd_pcm_dmix_drain,
.pause = snd_pcm_dmix_pause,
+ .rewindable = snd_pcm_dmix_rewindable,
.rewind = snd_pcm_dmix_rewind,
+ .forwardable = snd_pcm_dmix_forwardable,
.forward = snd_pcm_dmix_forward,
.resume = snd_pcm_direct_resume,
.link = NULL,
return -EIO;
}
-static snd_pcm_sframes_t snd_pcm_dshare_rewind(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_uframes_t frames ATTRIBUTE_UNUSED)
+static snd_pcm_sframes_t snd_pcm_dshare_rewindable(snd_pcm_t *pcm)
{
-#if 0
- /* FIXME: substract samples from the mix ring buffer, too? */
+ return snd_pcm_mmap_playback_hw_avail(pcm);
+}
+
+static snd_pcm_sframes_t snd_pcm_dshare_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
+{
+ snd_pcm_sframes_t avail;
+
+ avail = snd_pcm_mmap_playback_hw_avail(pcm);
+ if (avail < 0)
+ return 0;
+ if (frames > (snd_pcm_uframes_t)avail)
+ frames = avail;
snd_pcm_mmap_appl_backward(pcm, frames);
return frames;
-#else
- return -EIO;
-#endif
+}
+
+static snd_pcm_sframes_t snd_pcm_dshare_forwardable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_playback_avail(pcm);
}
static snd_pcm_sframes_t snd_pcm_dshare_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
.drop = snd_pcm_dshare_drop,
.drain = snd_pcm_dshare_drain,
.pause = snd_pcm_dshare_pause,
+ .rewindable = snd_pcm_dshare_rewindable,
.rewind = snd_pcm_dshare_rewind,
+ .forwardable = snd_pcm_dshare_forwardable,
.forward = snd_pcm_dshare_forward,
.resume = snd_pcm_direct_resume,
.link = NULL,
return -EIO;
}
+static snd_pcm_sframes_t snd_pcm_dsnoop_rewindable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_capture_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_dsnoop_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
+ snd_pcm_sframes_t avail;
+
+ avail = snd_pcm_mmap_capture_avail(pcm);
+ if (avail < 0)
+ return 0;
+ if (frames > (snd_pcm_uframes_t)avail)
+ frames = avail;
snd_pcm_mmap_appl_backward(pcm, frames);
return frames;
}
+static snd_pcm_sframes_t snd_pcm_dsnoop_forwardable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_capture_hw_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_dsnoop_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_sframes_t avail;
.drop = snd_pcm_dsnoop_drop,
.drain = snd_pcm_dsnoop_drain,
.pause = snd_pcm_dsnoop_pause,
+ .rewindable = snd_pcm_dsnoop_rewindable,
.rewind = snd_pcm_dsnoop_rewind,
+ .forwardable = snd_pcm_dsnoop_forwardable,
.forward = snd_pcm_dsnoop_forward,
.resume = snd_pcm_direct_resume,
.link = NULL,
return err;
}
+static snd_pcm_sframes_t snd_pcm_file_rewindable(snd_pcm_t *pcm)
+{
+ snd_pcm_file_t *file = pcm->private_data;
+ snd_pcm_sframes_t res = snd_pcm_rewindable(pcm);
+ snd_pcm_sframes_t n = snd_pcm_bytes_to_frames(pcm, file->wbuf_used_bytes);
+ if (res > n)
+ res = n;
+ return res;
+}
+
static snd_pcm_sframes_t snd_pcm_file_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_file_t *file = pcm->private_data;
return err;
}
+static snd_pcm_sframes_t snd_pcm_file_forwardable(snd_pcm_t *pcm)
+{
+ snd_pcm_file_t *file = pcm->private_data;
+ snd_pcm_sframes_t res = snd_pcm_forwardable(pcm);
+ snd_pcm_sframes_t n = snd_pcm_bytes_to_frames(pcm, file->wbuf_size_bytes - file->wbuf_used_bytes);
+ if (res > n)
+ res = n;
+ return res;
+}
+
static snd_pcm_sframes_t snd_pcm_file_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_file_t *file = pcm->private_data;
.drop = snd_pcm_file_drop,
.drain = snd_pcm_file_drain,
.pause = snd_pcm_generic_pause,
+ .rewindable = snd_pcm_file_rewindable,
.rewind = snd_pcm_file_rewind,
+ .forwardable = snd_pcm_file_forwardable,
.forward = snd_pcm_file_forward,
.resume = snd_pcm_generic_resume,
.link = snd_pcm_generic_link,
return snd_pcm_delay(generic->slave, delayp);
}
+snd_pcm_sframes_t snd_pcm_generic_forwardable(snd_pcm_t *pcm)
+{
+ snd_pcm_generic_t *generic = pcm->private_data;
+ return snd_pcm_forwardable(generic->slave);
+}
+
snd_pcm_sframes_t snd_pcm_generic_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_generic_t *generic = pcm->private_data;
return INTERNAL(snd_pcm_forward)(generic->slave, frames);
}
+snd_pcm_sframes_t snd_pcm_generic_rewindable(snd_pcm_t *pcm)
+{
+ snd_pcm_generic_t *generic = pcm->private_data;
+ return snd_pcm_rewindable(generic->slave);
+}
+
snd_pcm_sframes_t snd_pcm_generic_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_generic_t *generic = pcm->private_data;
snd1_pcm_generic_resume
#define snd_pcm_generic_delay \
snd1_pcm_generic_delay
+#define snd_pcm_generic_forwardable \
+ snd1_pcm_generic_forwardable
#define snd_pcm_generic_forward \
snd1_pcm_generic_forward
+#define snd_pcm_generic_rewindable \
+ snd1_pcm_generic_rewindable
#define snd_pcm_generic_rewind \
snd1_pcm_generic_rewind
#define snd_pcm_generic_link \
int snd_pcm_generic_pause(snd_pcm_t *pcm, int enable);
int snd_pcm_generic_resume(snd_pcm_t *pcm);
int snd_pcm_generic_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp);
+snd_pcm_sframes_t snd_pcm_generic_forwardable(snd_pcm_t *pcm);
snd_pcm_sframes_t snd_pcm_generic_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
+snd_pcm_sframes_t snd_pcm_generic_rewindable(snd_pcm_t *pcm);
snd_pcm_sframes_t snd_pcm_generic_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
int snd_pcm_generic_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2);
int snd_pcm_generic_link_slaves(snd_pcm_t *pcm, snd_pcm_t *master);
.drop = snd_pcm_generic_drop,
.drain = snd_pcm_generic_drain,
.pause = snd_pcm_generic_pause,
+ .rewindable = snd_pcm_generic_rewindable,
.rewind = snd_pcm_generic_rewind,
+ .forwardable = snd_pcm_generic_forwardable,
.forward = snd_pcm_generic_forward,
.resume = snd_pcm_generic_resume,
.link = snd_pcm_generic_link,
if (params->info != ~0UL) {
params->info &= ~0xf0000000;
- params->info |= (pcm->monotonic ? SND_PCM_INFO_MONOTONIC : 0) |
- SND_PCM_INFO_REWIND |
- SND_PCM_INFO_FORWARD;
+ params->info |= (pcm->monotonic ? SND_PCM_INFO_MONOTONIC : 0);
}
return 0;
return 0;
}
+static snd_pcm_sframes_t snd_pcm_hw_rewindable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_hw_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_hw_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_hw_t *hw = pcm->private_data;
return frames;
}
+static snd_pcm_sframes_t snd_pcm_hw_forwardable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_hw_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_hw_t *hw = pcm->private_data;
.drop = snd_pcm_hw_drop,
.drain = snd_pcm_hw_drain,
.pause = snd_pcm_hw_pause,
+ .rewindable = snd_pcm_hw_rewindable,
.rewind = snd_pcm_hw_rewind,
+ .forwardable = snd_pcm_hw_forwardable,
.forward = snd_pcm_hw_forward,
.resume = snd_pcm_hw_resume,
.link = snd_pcm_hw_link,
return 0;
}
+static snd_pcm_sframes_t snd_pcm_ioplug_rewindable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_hw_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_ioplug_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_mmap_appl_backward(pcm, frames);
return frames;
}
+static snd_pcm_sframes_t snd_pcm_ioplug_forwardable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_ioplug_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_mmap_appl_forward(pcm, frames);
.link = NULL,
.link_slaves = NULL,
.unlink = NULL,
+ .rewindable = snd_pcm_ioplug_rewindable,
.rewind = snd_pcm_ioplug_rewind,
+ .forwardable = snd_pcm_ioplug_forwardable,
.forward = snd_pcm_ioplug_forward,
.writei = snd_pcm_ioplug_writei,
.writen = snd_pcm_ioplug_writen,
#define SND_PCM_HW_PARAMS_NORESAMPLE SNDRV_PCM_HW_PARAMS_NORESAMPLE
#define SND_PCM_HW_PARAMS_EXPORT_BUFFER SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER
-#define SND_PCM_INFO_FORWARD 0x10000000
-#define SND_PCM_INFO_REWIND 0x20000000
#define SND_PCM_INFO_MONOTONIC 0x80000000
typedef struct _snd_pcm_rbptr {
int (*link)(snd_pcm_t *pcm1, snd_pcm_t *pcm2);
int (*link_slaves)(snd_pcm_t *pcm, snd_pcm_t *master);
int (*unlink)(snd_pcm_t *pcm);
+ snd_pcm_sframes_t (*rewindable)(snd_pcm_t *pcm);
snd_pcm_sframes_t (*rewind)(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
+ snd_pcm_sframes_t (*forwardable)(snd_pcm_t *pcm);
snd_pcm_sframes_t (*forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
snd_pcm_sframes_t (*writei)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
snd_pcm_sframes_t (*writen)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
.drop = snd_pcm_generic_drop,
.drain = snd_pcm_generic_drain,
.pause = snd_pcm_generic_pause,
+ .rewindable = snd_pcm_generic_rewindable,
.rewind = snd_pcm_meter_rewind,
+ .forwardable = snd_pcm_generic_forwardable,
.forward = snd_pcm_meter_forward,
.resume = snd_pcm_generic_resume,
.writei = snd_pcm_mmap_writei,
.drop = snd_pcm_generic_drop,
.drain = snd_pcm_generic_drain,
.pause = snd_pcm_generic_pause,
+ .rewindable = snd_pcm_generic_rewindable,
.rewind = snd_pcm_mmap_emul_rewind,
+ .forwardable = snd_pcm_generic_forwardable,
.forward = snd_pcm_mmap_emul_forward,
.resume = snd_pcm_generic_resume,
.link = snd_pcm_generic_link,
return 0;
}
+static snd_pcm_sframes_t snd_pcm_plugin_rewindable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_hw_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_plugin_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_plugin_t *plugin = pcm->private_data;
if (frames == 0)
return 0;
- /* FIXME: rate plugin */
if (plugin->slave_frames)
sframes = plugin->slave_frames(pcm, (snd_pcm_sframes_t) frames);
else
return n;
}
+static snd_pcm_sframes_t snd_pcm_plugin_forwardable(snd_pcm_t *pcm)
+{
+ return snd_pcm_mmap_avail(pcm);
+}
+
static snd_pcm_sframes_t snd_pcm_plugin_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_plugin_t *plugin = pcm->private_data;
if (frames == 0)
return 0;
- /* FIXME: rate plugin */
if (plugin->slave_frames)
sframes = plugin->slave_frames(pcm, (snd_pcm_sframes_t) frames);
else
.drop = snd_pcm_generic_drop,
.drain = snd_pcm_generic_drain,
.pause = snd_pcm_generic_pause,
+ .rewindable = snd_pcm_plugin_rewindable,
.rewind = snd_pcm_plugin_rewind,
+ .forwardable = snd_pcm_plugin_forwardable,
.forward = snd_pcm_plugin_forward,
.resume = snd_pcm_generic_resume,
.link = snd_pcm_generic_link,
return n;
}
+static snd_pcm_sframes_t snd_pcm_share_rewindable(snd_pcm_t *pcm)
+{
+ snd_pcm_share_t *share = pcm->private_data;
+ snd_pcm_share_slave_t *slave = share->slave;
+ snd_pcm_sframes_t ret;
+ Pthread_mutex_lock(&slave->mutex);
+ ret = snd_pcm_rewindable(slave->pcm);
+ Pthread_mutex_unlock(&slave->mutex);
+ return ret;
+}
+
static snd_pcm_sframes_t snd_pcm_share_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_share_t *share = pcm->private_data;
return n;
}
+static snd_pcm_sframes_t snd_pcm_share_forwardable(snd_pcm_t *pcm)
+{
+ snd_pcm_share_t *share = pcm->private_data;
+ snd_pcm_share_slave_t *slave = share->slave;
+ snd_pcm_sframes_t ret;
+ Pthread_mutex_lock(&slave->mutex);
+ ret = snd_pcm_forwardable(slave->pcm);
+ Pthread_mutex_unlock(&slave->mutex);
+ return ret;
+}
+
static snd_pcm_sframes_t snd_pcm_share_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_share_t *share = pcm->private_data;
.writen = snd_pcm_mmap_writen,
.readi = snd_pcm_mmap_readi,
.readn = snd_pcm_mmap_readn,
+ .rewindable = snd_pcm_share_rewindable,
.rewind = snd_pcm_share_rewind,
+ .forwardable = snd_pcm_share_forwardable,
.forward = snd_pcm_share_forward,
.resume = snd_pcm_share_resume,
.avail_update = snd_pcm_share_avail_update,
return snd_pcm_shm_action(pcm);
}
+static snd_pcm_sframes_t snd_pcm_shm_rewindable(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
+{
+ return 0; /* FIX ME */
+}
+
static snd_pcm_sframes_t snd_pcm_shm_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_shm_t *shm = pcm->private_data;
return snd_pcm_shm_action(pcm);
}
+static snd_pcm_sframes_t snd_pcm_shm_forwardable(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
+{
+ return 0; /* FIX ME */
+}
+
static snd_pcm_sframes_t snd_pcm_shm_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
snd_pcm_shm_t *shm = pcm->private_data;
.drop = snd_pcm_shm_drop,
.drain = snd_pcm_shm_drain,
.pause = snd_pcm_shm_pause,
+ .rewindable = snd_pcm_shm_rewindable,
.rewind = snd_pcm_shm_rewind,
+ .forwardable = snd_pcm_shm_forwardable,
.forward = snd_pcm_shm_forward,
.resume = snd_pcm_shm_resume,
.writei = snd_pcm_mmap_writei,