2015-07-07 09:55:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2015 Andrew Kelley
|
|
|
|
*
|
|
|
|
* This file is part of libsoundio, which is MIT licensed.
|
|
|
|
* See http://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
2015-11-01 22:18:37 +00:00
|
|
|
#ifndef SOUNDIO_ALSA_H
|
|
|
|
#define SOUNDIO_ALSA_H
|
2015-07-07 09:55:32 +00:00
|
|
|
|
2015-11-01 22:18:37 +00:00
|
|
|
#include "soundio_internal.h"
|
2015-08-20 21:48:19 +00:00
|
|
|
#include "os.h"
|
2015-11-01 22:18:37 +00:00
|
|
|
#include "list.h"
|
|
|
|
#include "atomics.h"
|
2015-07-27 23:37:45 +00:00
|
|
|
|
2015-07-28 00:06:12 +00:00
|
|
|
#include <alsa/asoundlib.h>
|
|
|
|
|
2015-11-01 22:18:37 +00:00
|
|
|
struct SoundIoPrivate;
|
2015-07-13 16:17:20 +00:00
|
|
|
int soundio_alsa_init(struct SoundIoPrivate *si);
|
2015-07-07 09:55:32 +00:00
|
|
|
|
2015-11-01 22:18:37 +00:00
|
|
|
struct SoundIoDeviceAlsa { int make_the_struct_not_empty; };
|
2015-07-27 23:37:45 +00:00
|
|
|
|
2015-08-28 03:53:28 +00:00
|
|
|
#define SOUNDIO_MAX_ALSA_SND_FILE_LEN 16
|
|
|
|
struct SoundIoAlsaPendingFile {
|
|
|
|
char name[SOUNDIO_MAX_ALSA_SND_FILE_LEN];
|
|
|
|
};
|
|
|
|
|
2015-11-01 22:18:37 +00:00
|
|
|
SOUNDIO_MAKE_LIST_STRUCT(struct SoundIoAlsaPendingFile, SoundIoListAlsaPendingFile, SOUNDIO_LIST_STATIC)
|
|
|
|
|
2015-07-27 23:37:45 +00:00
|
|
|
struct SoundIoAlsa {
|
2015-11-01 22:18:37 +00:00
|
|
|
struct SoundIoOsMutex *mutex;
|
|
|
|
struct SoundIoOsCond *cond;
|
2015-07-07 09:55:32 +00:00
|
|
|
|
2015-07-27 23:37:45 +00:00
|
|
|
struct SoundIoOsThread *thread;
|
2015-12-05 13:25:44 +00:00
|
|
|
struct SoundIoAtomicFlag abort_flag;
|
2015-07-27 23:37:45 +00:00
|
|
|
int notify_fd;
|
|
|
|
int notify_wd;
|
2015-08-28 03:53:28 +00:00
|
|
|
bool have_devices_flag;
|
2015-07-27 23:37:45 +00:00
|
|
|
int notify_pipe_fd[2];
|
2015-11-01 22:18:37 +00:00
|
|
|
struct SoundIoListAlsaPendingFile pending_files;
|
2015-07-27 23:37:45 +00:00
|
|
|
|
|
|
|
// this one is ready to be read with flush_events. protected by mutex
|
|
|
|
struct SoundIoDevicesInfo *ready_devices_info;
|
2015-07-30 07:46:13 +00:00
|
|
|
|
|
|
|
int shutdown_err;
|
|
|
|
bool emitted_shutdown_cb;
|
2015-07-27 23:37:45 +00:00
|
|
|
};
|
|
|
|
|
2015-07-28 00:06:12 +00:00
|
|
|
struct SoundIoOutStreamAlsa {
|
|
|
|
snd_pcm_t *handle;
|
|
|
|
snd_pcm_chmap_t *chmap;
|
|
|
|
int chmap_size;
|
|
|
|
snd_pcm_uframes_t offset;
|
|
|
|
snd_pcm_access_t access;
|
2015-08-26 19:30:46 +00:00
|
|
|
snd_pcm_uframes_t buffer_size_frames;
|
2015-07-28 00:06:12 +00:00
|
|
|
int sample_buffer_size;
|
|
|
|
char *sample_buffer;
|
|
|
|
int poll_fd_count;
|
2015-11-15 05:16:29 +00:00
|
|
|
int poll_fd_count_with_extra;
|
2015-07-28 00:06:12 +00:00
|
|
|
struct pollfd *poll_fds;
|
2015-11-15 05:16:29 +00:00
|
|
|
int poll_exit_pipe_fd[2];
|
2015-11-01 22:18:37 +00:00
|
|
|
struct SoundIoOsThread *thread;
|
2015-12-05 13:25:44 +00:00
|
|
|
struct SoundIoAtomicFlag thread_exit_flag;
|
2015-11-15 04:44:03 +00:00
|
|
|
snd_pcm_uframes_t period_size;
|
2015-08-05 04:57:46 +00:00
|
|
|
int write_frame_count;
|
2015-09-01 21:43:50 +00:00
|
|
|
bool is_paused;
|
2015-12-05 13:25:44 +00:00
|
|
|
struct SoundIoAtomicFlag clear_buffer_flag;
|
2015-11-01 22:18:37 +00:00
|
|
|
struct SoundIoChannelArea areas[SOUNDIO_MAX_CHANNELS];
|
2015-07-28 00:06:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SoundIoInStreamAlsa {
|
|
|
|
snd_pcm_t *handle;
|
|
|
|
snd_pcm_chmap_t *chmap;
|
|
|
|
int chmap_size;
|
|
|
|
snd_pcm_uframes_t offset;
|
|
|
|
snd_pcm_access_t access;
|
|
|
|
int sample_buffer_size;
|
|
|
|
char *sample_buffer;
|
|
|
|
int poll_fd_count;
|
|
|
|
struct pollfd *poll_fds;
|
2015-11-01 22:18:37 +00:00
|
|
|
struct SoundIoOsThread *thread;
|
2015-12-05 13:25:44 +00:00
|
|
|
struct SoundIoAtomicFlag thread_exit_flag;
|
2015-07-28 00:06:12 +00:00
|
|
|
int period_size;
|
|
|
|
int read_frame_count;
|
2015-09-01 21:43:50 +00:00
|
|
|
bool is_paused;
|
2015-11-01 22:18:37 +00:00
|
|
|
struct SoundIoChannelArea areas[SOUNDIO_MAX_CHANNELS];
|
2015-07-28 00:06:12 +00:00
|
|
|
};
|
|
|
|
|
2015-07-27 23:37:45 +00:00
|
|
|
#endif
|