mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Changed result of mmap_commit callback
(follows description of snd_pcm_mmap_commit function).
This commit is contained in:
parent
8ca451f0e1
commit
0917ba63b0
11 changed files with 57 additions and 53 deletions
|
|
@ -279,9 +279,9 @@ static snd_pcm_sframes_t snd_pcm_file_readn(snd_pcm_t *pcm, void **bufs, snd_pcm
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
|
static int snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset,
|
snd_pcm_uframes_t offset,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_file_t *file = pcm->private_data;
|
snd_pcm_file_t *file = pcm->private_data;
|
||||||
snd_pcm_uframes_t ofs;
|
snd_pcm_uframes_t ofs;
|
||||||
|
|
|
||||||
|
|
@ -185,9 +185,9 @@ static snd_pcm_sframes_t snd_pcm_hooks_readn(snd_pcm_t *pcm, void **bufs, snd_pc
|
||||||
return snd_pcm_readn(h->slave, bufs, size);
|
return snd_pcm_readn(h->slave, bufs, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_hooks_mmap_commit(snd_pcm_t *pcm,
|
static int snd_pcm_hooks_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset,
|
snd_pcm_uframes_t offset,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_hooks_t *h = pcm->private_data;
|
snd_pcm_hooks_t *h = pcm->private_data;
|
||||||
return snd_pcm_mmap_commit(h->slave, offset, size);
|
return snd_pcm_mmap_commit(h->slave, offset, size);
|
||||||
|
|
|
||||||
|
|
@ -142,7 +142,7 @@ typedef struct {
|
||||||
snd_pcm_sframes_t (*readi)(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
|
snd_pcm_sframes_t (*readi)(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
|
||||||
snd_pcm_sframes_t (*readn)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
|
snd_pcm_sframes_t (*readn)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
|
||||||
snd_pcm_sframes_t (*avail_update)(snd_pcm_t *pcm);
|
snd_pcm_sframes_t (*avail_update)(snd_pcm_t *pcm);
|
||||||
snd_pcm_sframes_t (*mmap_commit)(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
|
int (*mmap_commit)(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
|
||||||
} snd_pcm_fast_ops_t;
|
} snd_pcm_fast_ops_t;
|
||||||
|
|
||||||
struct _snd_pcm {
|
struct _snd_pcm {
|
||||||
|
|
|
||||||
|
|
@ -396,9 +396,9 @@ static int snd_pcm_meter_resume(snd_pcm_t *pcm)
|
||||||
return snd_pcm_resume(meter->slave);
|
return snd_pcm_resume(meter->slave);
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_meter_mmap_commit(snd_pcm_t *pcm,
|
static int snd_pcm_meter_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset,
|
snd_pcm_uframes_t offset,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_meter_t *meter = pcm->private_data;
|
snd_pcm_meter_t *meter = pcm->private_data;
|
||||||
snd_pcm_uframes_t old_rptr = *pcm->appl_ptr;
|
snd_pcm_uframes_t old_rptr = *pcm->appl_ptr;
|
||||||
|
|
@ -406,11 +406,10 @@ static snd_pcm_sframes_t snd_pcm_meter_mmap_commit(snd_pcm_t *pcm,
|
||||||
if (result <= 0)
|
if (result <= 0)
|
||||||
return result;
|
return result;
|
||||||
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
|
if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
|
||||||
snd_pcm_meter_add_frames(pcm, snd_pcm_mmap_areas(pcm), old_rptr,
|
snd_pcm_meter_add_frames(pcm, snd_pcm_mmap_areas(pcm), old_rptr, size);
|
||||||
(snd_pcm_uframes_t) result);
|
|
||||||
meter->rptr = *pcm->appl_ptr;
|
meter->rptr = *pcm->appl_ptr;
|
||||||
}
|
}
|
||||||
return result;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_meter_avail_update(snd_pcm_t *pcm)
|
static snd_pcm_sframes_t snd_pcm_meter_avail_update(snd_pcm_t *pcm)
|
||||||
|
|
|
||||||
|
|
@ -506,26 +506,22 @@ static int snd_pcm_multi_resume(snd_pcm_t *pcm)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_multi_mmap_commit(snd_pcm_t *pcm,
|
static int snd_pcm_multi_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset,
|
snd_pcm_uframes_t offset,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_multi_t *multi = pcm->private_data;
|
snd_pcm_multi_t *multi = pcm->private_data;
|
||||||
|
snd_pcm_t *slave;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
int err;
|
||||||
|
|
||||||
for (i = 0; i < multi->slaves_count; ++i) {
|
for (i = 0; i < multi->slaves_count; ++i) {
|
||||||
snd_pcm_t *slave = multi->slaves[i].pcm;
|
slave = multi->slaves[i].pcm;
|
||||||
snd_pcm_sframes_t frames = snd_pcm_mmap_commit(slave, offset, size);
|
err = snd_pcm_mmap_commit(slave, offset, size);
|
||||||
if (frames < 0)
|
if (err < 0)
|
||||||
return frames;
|
return err;
|
||||||
if (i == 0) {
|
|
||||||
size = frames;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ((snd_pcm_uframes_t) frames != size)
|
|
||||||
return -EBADFD;
|
|
||||||
}
|
}
|
||||||
return size;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int snd_pcm_multi_mmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
|
static int snd_pcm_multi_mmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
|
||||||
|
|
|
||||||
|
|
@ -221,11 +221,17 @@ static snd_pcm_sframes_t snd_pcm_null_readn(snd_pcm_t *pcm, void **bufs ATTRIBUT
|
||||||
return snd_pcm_read_areas(pcm, NULL, 0, size, snd_pcm_null_xfer_areas);
|
return snd_pcm_read_areas(pcm, NULL, 0, size, snd_pcm_null_xfer_areas);
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_null_mmap_commit(snd_pcm_t *pcm,
|
static int snd_pcm_null_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
return snd_pcm_null_fwd(pcm, size);
|
snd_pcm_sframes_t res;
|
||||||
|
|
||||||
|
res = snd_pcm_null_fwd(pcm, size);
|
||||||
|
if (res < 0)
|
||||||
|
return res;
|
||||||
|
assert((snd_pcm_uframes_t)res == size);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_null_avail_update(snd_pcm_t *pcm)
|
static snd_pcm_sframes_t snd_pcm_null_avail_update(snd_pcm_t *pcm)
|
||||||
|
|
|
||||||
|
|
@ -1821,7 +1821,7 @@ static snd_interval_t refine_intervals[SND_PCM_HW_PARAM_LAST_INTERVAL - SND_PCM_
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef RULES_DEBUG
|
#define RULES_DEBUG
|
||||||
|
|
||||||
int snd_pcm_hw_refine_soft(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
|
int snd_pcm_hw_refine_soft(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
|
||||||
{
|
{
|
||||||
|
|
@ -1995,7 +1995,7 @@ int snd_pcm_hw_refine_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
|
||||||
}
|
}
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
#ifdef RULES_DEBUG
|
#ifdef RULES_DEBUG
|
||||||
snd_output_printf(log, "cchange '%s', schange < 0\n", pcm->name);
|
snd_output_printf(log, "cchange '%s', (schange || srefine) < 0\n", pcm->name);
|
||||||
snd_pcm_hw_params_dump(params, log);
|
snd_pcm_hw_params_dump(params, log);
|
||||||
#endif
|
#endif
|
||||||
cchange(pcm, params, &sparams);
|
cchange(pcm, params, &sparams);
|
||||||
|
|
|
||||||
|
|
@ -286,28 +286,30 @@ snd_pcm_sframes_t snd_pcm_plugin_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_ufra
|
||||||
snd_pcm_plugin_read_areas);
|
snd_pcm_plugin_read_areas);
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_pcm_sframes_t snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
|
int snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_plugin_t *plugin = pcm->private_data;
|
snd_pcm_plugin_t *plugin = pcm->private_data;
|
||||||
snd_pcm_t *slave = plugin->slave;
|
snd_pcm_t *slave = plugin->slave;
|
||||||
const snd_pcm_channel_area_t *areas;
|
const snd_pcm_channel_area_t *areas;
|
||||||
snd_pcm_uframes_t xfer, hw_offset;
|
snd_pcm_uframes_t xfer, hw_offset;
|
||||||
snd_pcm_uframes_t slave_size;
|
snd_pcm_sframes_t slave_size;
|
||||||
if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
|
if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
|
||||||
snd_atomic_write_begin(&plugin->watom);
|
snd_atomic_write_begin(&plugin->watom);
|
||||||
snd_pcm_mmap_appl_forward(pcm, size);
|
snd_pcm_mmap_appl_forward(pcm, size);
|
||||||
snd_atomic_write_end(&plugin->watom);
|
snd_atomic_write_end(&plugin->watom);
|
||||||
return size;
|
return 0;
|
||||||
}
|
}
|
||||||
slave_size = snd_pcm_avail_update(slave);
|
slave_size = snd_pcm_avail_update(slave);
|
||||||
if (slave_size <= 0)
|
if (slave_size < 0)
|
||||||
return slave_size;
|
return slave_size;
|
||||||
|
if (slave_size == 0)
|
||||||
|
return -EIO;
|
||||||
areas = snd_pcm_mmap_areas(pcm);
|
areas = snd_pcm_mmap_areas(pcm);
|
||||||
hw_offset = snd_pcm_mmap_hw_offset(pcm);
|
hw_offset = snd_pcm_mmap_hw_offset(pcm);
|
||||||
xfer = 0;
|
xfer = 0;
|
||||||
while (size && slave_size) {
|
while (size > 0 && slave_size > 0) {
|
||||||
snd_pcm_uframes_t frames = size;
|
snd_pcm_uframes_t frames = size;
|
||||||
snd_pcm_uframes_t cont = pcm->buffer_size - hw_offset;
|
snd_pcm_uframes_t cont = pcm->buffer_size - hw_offset;
|
||||||
const snd_pcm_channel_area_t *slave_areas;
|
const snd_pcm_channel_area_t *slave_areas;
|
||||||
|
|
@ -331,7 +333,8 @@ snd_pcm_sframes_t snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
|
||||||
size -= frames;
|
size -= frames;
|
||||||
slave_size -= slave_frames;
|
slave_size -= slave_frames;
|
||||||
}
|
}
|
||||||
return xfer;
|
assert(size == 0);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
|
snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ snd_pcm_sframes_t snd_pcm_plugin_writei(snd_pcm_t *pcm, const void *buffer, snd_
|
||||||
snd_pcm_sframes_t snd_pcm_plugin_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
|
snd_pcm_sframes_t snd_pcm_plugin_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
|
||||||
snd_pcm_sframes_t snd_pcm_plugin_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
|
snd_pcm_sframes_t snd_pcm_plugin_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
|
||||||
snd_pcm_sframes_t snd_pcm_plugin_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
|
snd_pcm_sframes_t snd_pcm_plugin_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
|
||||||
snd_pcm_sframes_t snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
|
int snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
|
||||||
snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm);
|
snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm);
|
||||||
int snd_pcm_plugin_mmap_status(snd_pcm_t *pcm);
|
int snd_pcm_plugin_mmap_status(snd_pcm_t *pcm);
|
||||||
int snd_pcm_plugin_mmap_control(snd_pcm_t *pcm);
|
int snd_pcm_plugin_mmap_control(snd_pcm_t *pcm);
|
||||||
|
|
|
||||||
|
|
@ -759,14 +759,14 @@ static snd_pcm_sframes_t snd_pcm_share_avail_update(snd_pcm_t *pcm)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Call it with mutex held */
|
/* Call it with mutex held */
|
||||||
static snd_pcm_sframes_t _snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
|
static int _snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_share_t *share = pcm->private_data;
|
snd_pcm_share_t *share = pcm->private_data;
|
||||||
snd_pcm_share_slave_t *slave = share->slave;
|
snd_pcm_share_slave_t *slave = share->slave;
|
||||||
snd_pcm_t *spcm = slave->pcm;
|
snd_pcm_t *spcm = slave->pcm;
|
||||||
snd_pcm_sframes_t ret = 0;
|
snd_pcm_sframes_t ret;
|
||||||
snd_pcm_sframes_t frames;
|
snd_pcm_sframes_t frames;
|
||||||
if (pcm->stream == SND_PCM_STREAM_PLAYBACK &&
|
if (pcm->stream == SND_PCM_STREAM_PLAYBACK &&
|
||||||
share->state == SND_PCM_STATE_RUNNING) {
|
share->state == SND_PCM_STATE_RUNNING) {
|
||||||
|
|
@ -792,12 +792,12 @@ static snd_pcm_sframes_t _snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
|
||||||
}
|
}
|
||||||
_snd_pcm_share_update(pcm);
|
_snd_pcm_share_update(pcm);
|
||||||
}
|
}
|
||||||
return size;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
|
static int snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset,
|
snd_pcm_uframes_t offset,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_share_t *share = pcm->private_data;
|
snd_pcm_share_t *share = pcm->private_data;
|
||||||
snd_pcm_share_slave_t *slave = share->slave;
|
snd_pcm_share_slave_t *slave = share->slave;
|
||||||
|
|
|
||||||
|
|
@ -446,9 +446,9 @@ static int snd_pcm_shm_resume(snd_pcm_t *pcm)
|
||||||
return snd_pcm_shm_action(pcm);
|
return snd_pcm_shm_action(pcm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static snd_pcm_sframes_t snd_pcm_shm_mmap_commit(snd_pcm_t *pcm,
|
static int snd_pcm_shm_mmap_commit(snd_pcm_t *pcm,
|
||||||
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
|
||||||
snd_pcm_uframes_t size)
|
snd_pcm_uframes_t size)
|
||||||
{
|
{
|
||||||
snd_pcm_shm_t *shm = pcm->private_data;
|
snd_pcm_shm_t *shm = pcm->private_data;
|
||||||
volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl;
|
volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue