#define READ_FRAME_DEFAULT 1920
#define PERIOD_SIZE_DEFAULT (READ_FRAME_DEFAULT)
#define PERIOD_COUNTS_DEFAULT (8*2)
#define BUFFER_SIZE_DEFAULT (PERIOD_SIZE_DEFAULT * PERIOD_COUNTS_DEFAULT)
#define MUTE_TIME_DEFAULT (3)
err = snd_pcm_readi(capture_handle, buffer, g_read_frame);
alsa_fake_device_write_open()
if (device_flag == DEVICE_FLAG_BLUETOOTH) {
sprintf(bluealsa_device, "%s%s", "bluealsa:HCI=hci0,PROFILE=a2dp,DEV=",
g_bt_mac_addr);
eq_debug("[EQ_WRITE_OPEN] Open PCM: %s\n", bluealsa_device);
write_err = snd_pcm_open(write_handle, bluealsa_device,
SND_PCM_STREAM_PLAYBACK, 0);
}
snd_pcm_hw_params_set_access()
snd_pcm_hw_params_set_format()
snd_pcm_hw_params_set_channels()
snd_pcm_hw_params_set_buffer_size_near()
snd_pcm_hw_params_set_period_size_near()
err = snd_pcm_writei(write_handle, buffer, g_read_frame);
static const snd_pcm_ioplug_callback_t bluealsa_callback = {
.start = bluealsa_start,
.stop = bluealsa_stop,
.pointer = bluealsa_pointer,
.close = bluealsa_close,
.hw_params = bluealsa_hw_params,
.hw_free = bluealsa_hw_free,
.sw_params = bluealsa_sw_params,
.prepare = bluealsa_prepare,
.drain = bluealsa_drain,
.pause = bluealsa_pause,
.dump = bluealsa_dump,
.delay = bluealsa_delay,
.poll_descriptors_count = bluealsa_poll_descriptors_count,
.poll_descriptors = bluealsa_poll_descriptors,
.poll_revents = bluealsa_poll_revents,
};
bluealsa_hw_params()
pcm->pcm_fd = bluealsa_open_transport(pcm->fd, &pcm->transport)
if (pcm->io.stream == SND_PCM_STREAM_PLAYBACK) {
pcm->pcm_buffer_size = fcntl(pcm->pcm_fd, F_SETPIPE_SZ, 2048);
debug("FIFO buffer 2048 size: %zd", pcm->pcm_buffer_size);
}
debug("Selected HW buffer: %zd periods x %zd bytes %c= %zd bytes",
io->buffer_size / io->period_size, pcm->frame_size * io->period_size,
io->period_size * (io->buffer_size / io->period_size) == io->buffer_size ? '=' : '<',
io->buffer_size * pcm->frame_size);
static int bluealsa_start(snd_pcm_ioplug_t *io)
pthread_create(&pcm->io_thread, NULL, io_thread, io)
io_thread()
debug("Starting IO loop xy");
for (;;) {
snd_pcm_uframes_t io_ptr = pcm->io_ptr;
snd_pcm_uframes_t io_buffer_size = io->buffer_size;
snd_pcm_uframes_t io_hw_ptr = pcm->io_hw_ptr;
snd_pcm_uframes_t io_hw_boundary = pcm->io_hw_boundary;
snd_pcm_uframes_t frames = io->period_size;
... ...
do {
if ((ret = write(pcm->pcm_fd, head, len)) == -1) {
debug("pcm write ret: %d, len: %d", ret, len);
if (errno == EINTR)
continue;
SNDERR("PCM FIFO write error: %s", strerror(errno));
goto final;
}
debug("pcm write ret: %d, len: %d", ret, len);
head += ret;
len -= ret;
} while (len != 0);
}
void *io_thread_a2dp_source_sbc(void *arg) {
for (;;) {
io_thread_read_pcm(&t->a2dp.pcm, pcm.tail, ffb_len_in(&pcm))
sbc_encode()
io_thread_write_bt()
}
}