uint64_t timer_period;
uint64_t timer_expirations;
- snd_pcm_channel_area_t *audiobuf_areas;
+ const snd_pcm_channel_area_t *audiobuf_areas;
snd_pcm_channel_area_t *payload_areas;
snd_pcm_uframes_t hw_ptr;
return res;
}
-static int aaf_init_audiobuf_areas(snd_pcm_aaf_t *aaf)
-{
- int res;
- char *buf;
- ssize_t frame_size;
- snd_pcm_channel_area_t *areas;
- snd_pcm_ioplug_t *io = &aaf->io;
-
- frame_size = snd_pcm_format_size(io->format, io->channels);
- if (frame_size < 0)
- return frame_size;
-
- buf = calloc(io->buffer_size, frame_size);
- if (!buf)
- return -ENOMEM;
-
- areas = calloc(io->channels, sizeof(snd_pcm_channel_area_t));
- if (!areas) {
- res = -ENOMEM;
- goto err_free_buf;
- }
-
- res = aaf_init_areas(aaf, areas, buf);
- if (res < 0)
- goto err_free_areas;
-
- aaf->audiobuf_areas = areas;
- return 0;
-
-err_free_areas:
- free(areas);
-err_free_buf:
- free(buf);
- return res;
-}
-
static void aaf_inc_ptr(snd_pcm_uframes_t *ptr, snd_pcm_uframes_t val,
snd_pcm_uframes_t boundary)
{
snd_pcm_ioplug_t *io = &aaf->io;
static const unsigned int accesses[] = {
SND_PCM_ACCESS_RW_INTERLEAVED,
+ SND_PCM_ACCESS_MMAP_INTERLEAVED,
};
static const unsigned int formats[] = {
SND_PCM_FORMAT_S16_BE,
if (res < 0)
goto err_free_pdu;
- res = aaf_init_audiobuf_areas(aaf);
- if (res < 0)
- goto err_free_payload_areas;
-
return 0;
-err_free_payload_areas:
- free(aaf->payload_areas);
err_free_pdu:
free(aaf->pdu);
err_close_timer:
close(aaf->timer_fd);
free(aaf->pdu);
free(aaf->payload_areas);
- free(aaf->audiobuf_areas->addr);
- free(aaf->audiobuf_areas);
return 0;
}
int res;
snd_pcm_aaf_t *aaf = io->private_data;
+ aaf->audiobuf_areas = snd_pcm_ioplug_mmap_areas(io);
aaf->pdu_seq = 0;
aaf->hw_ptr = 0;
aaf->hw_virt_ptr = 0;
return 0;
}
-static snd_pcm_sframes_t aaf_transfer(snd_pcm_ioplug_t *io,
- const snd_pcm_channel_area_t *areas,
- snd_pcm_uframes_t offset,
- snd_pcm_uframes_t size)
-{
- int res;
- snd_pcm_aaf_t *aaf = io->private_data;
-
- if (io->stream == SND_PCM_STREAM_PLAYBACK) {
- res = snd_pcm_areas_copy_wrap(aaf->audiobuf_areas,
- (io->appl_ptr % io->buffer_size),
- io->buffer_size, areas, offset,
- size, io->channels, size,
- io->format);
- } else {
- res = snd_pcm_areas_copy_wrap(areas, offset, (offset + size),
- aaf->audiobuf_areas,
- (io->appl_ptr % io->buffer_size),
- io->buffer_size, io->channels,
- size, io->format);
- }
-
- if (res < 0)
- return res;
-
- return size;
-}
-
static const snd_pcm_ioplug_callback_t aaf_callback = {
.close = aaf_close,
.dump = aaf_dump,
.prepare = aaf_prepare,
.start = aaf_start,
.stop = aaf_stop,
- .transfer = aaf_transfer,
};
SND_PCM_PLUGIN_DEFINE_FUNC(aaf)
aaf->io.callback = &aaf_callback;
aaf->io.private_data = aaf;
aaf->io.flags = SND_PCM_IOPLUG_FLAG_BOUNDARY_WA;
+ aaf->io.mmap_rw = 1;
res = snd_pcm_ioplug_create(&aaf->io, name, stream, mode);
if (res < 0) {
SNDERR("Failed to create ioplug instance");