pipewire/spa/plugins/alsa/alsa-utils.h

167 lines
3.9 KiB
C
Raw Normal View History

2016-09-20 11:20:43 +02:00
/* Spa ALSA Sink
*
* Copyright © 2018 Wim Taymans
2016-09-20 11:20:43 +02:00
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
2016-09-20 11:20:43 +02:00
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
2016-09-20 11:20:43 +02:00
*/
#ifndef SPA_ALSA_UTILS_H
#define SPA_ALSA_UTILS_H
2016-09-20 11:20:43 +02:00
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
#include <math.h>
2016-09-20 11:20:43 +02:00
#include <asoundlib.h>
#include <spa/support/loop.h>
#include <spa/support/log.h>
#include <spa/utils/list.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/param.h>
#include <spa/param/audio/format-utils.h>
2016-09-20 11:20:43 +02:00
2019-01-07 15:52:42 +01:00
#define DEFAULT_RATE 48000u
#define DEFAULT_CHANNELS 2u
2017-05-26 17:25:58 +02:00
struct props {
char device[64];
char device_name[128];
char card_name[128];
uint32_t min_latency;
uint32_t max_latency;
};
2016-09-20 11:20:43 +02:00
#define MAX_BUFFERS 32
2017-05-26 17:25:58 +02:00
struct buffer {
uint32_t id;
#define BUFFER_FLAG_OUT (1<<0)
uint32_t flags;
struct spa_buffer *buf;
2017-05-26 17:25:58 +02:00
struct spa_meta_header *h;
struct spa_list link;
2016-09-20 11:20:43 +02:00
};
#define BW_MAX 0.256
#define BW_MED 0.064
#define BW_MIN 0.016
2019-04-25 12:53:23 +02:00
#define BW_PERIOD (3 * SPA_NSEC_PER_SEC)
2017-05-26 17:25:58 +02:00
struct state {
struct spa_handle handle;
struct spa_node node;
struct spa_log *log;
struct spa_loop *main_loop;
struct spa_loop *data_loop;
snd_pcm_stream_t stream;
snd_output_t *output;
struct spa_hook_list hooks;
const struct spa_node_callbacks *callbacks;
void *callbacks_data;
2017-05-26 17:25:58 +02:00
uint64_t info_all;
struct spa_node_info info;
struct spa_param_info params[8];
2017-05-26 17:25:58 +02:00
struct props props;
bool opened;
snd_pcm_t *hndl;
bool have_format;
struct spa_audio_info current_format;
snd_pcm_uframes_t buffer_frames;
snd_pcm_uframes_t period_frames;
snd_pcm_format_t format;
int rate;
int channels;
size_t frame_size;
uint64_t port_info_all;
struct spa_port_info port_info;
struct spa_param_info port_params[8];
struct spa_io_buffers *io;
struct spa_io_range *range;
struct spa_io_clock *clock;
struct spa_io_position *position;
struct spa_io_sequence *notify;
2017-05-26 17:25:58 +02:00
struct buffer buffers[MAX_BUFFERS];
unsigned int n_buffers;
struct spa_list free;
struct spa_list ready;
size_t ready_offset;
2017-05-26 17:25:58 +02:00
bool started;
struct spa_source source;
int timerfd;
2019-01-07 15:52:42 +01:00
uint32_t threshold;
2019-04-25 16:15:52 +02:00
uint32_t last_threshold;
unsigned int alsa_started:1;
unsigned int alsa_sync:1;
unsigned int slaved:1;
2017-05-26 17:25:58 +02:00
snd_htimestamp_t now;
2017-05-26 17:25:58 +02:00
int64_t sample_count;
int64_t sample_time;
uint64_t next_time;
uint64_t base_time;
2017-10-24 18:04:03 +02:00
uint64_t underrun;
double safety;
double bw;
double z1, z2, z3;
double w0, w1, w2;
2016-09-20 11:20:43 +02:00
};
int
spa_alsa_enum_format(struct state *state, int seq,
uint32_t start, uint32_t num,
const struct spa_pod *filter);
2017-04-04 19:44:00 +02:00
2017-05-26 17:25:58 +02:00
int spa_alsa_set_format(struct state *state, struct spa_audio_info *info, uint32_t flags);
2016-09-20 11:20:43 +02:00
int spa_alsa_start(struct state *state);
2019-04-24 15:38:06 +02:00
int spa_alsa_reslave(struct state *state);
int spa_alsa_pause(struct state *state);
2017-05-26 17:25:58 +02:00
int spa_alsa_close(struct state *state);
2016-09-20 11:20:43 +02:00
int spa_alsa_write(struct state *state, snd_pcm_uframes_t silence);
int spa_alsa_read(struct state *state, snd_pcm_uframes_t silence);
2016-09-20 11:20:43 +02:00
#ifdef __cplusplus
2017-05-26 08:05:01 +02:00
} /* extern "C" */
2016-09-20 11:20:43 +02:00
#endif
#endif /* SPA_ALSA_UTILS_H */