2023-02-08 18:12:00 +01:00
|
|
|
/* Spa ALSA Sink */
|
|
|
|
|
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
|
|
|
|
|
/* SPDX-License-Identifier: MIT */
|
2016-09-20 11:20:43 +02:00
|
|
|
|
2019-01-14 12:58:23 +01: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>
|
2018-11-09 15:24:24 +01:00
|
|
|
#include <math.h>
|
2016-09-20 11:20:43 +02:00
|
|
|
|
2019-05-23 09:25:51 +02:00
|
|
|
#include <alsa/asoundlib.h>
|
2023-04-14 19:49:44 +02:00
|
|
|
#include <alsa/version.h>
|
2021-06-02 13:23:08 +02:00
|
|
|
#include <alsa/use-case.h>
|
2016-09-20 11:20:43 +02:00
|
|
|
|
2019-10-25 15:01:02 +02:00
|
|
|
#include <spa/support/plugin.h>
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/support/loop.h>
|
|
|
|
|
#include <spa/utils/list.h>
|
2021-03-18 18:40:56 +01:00
|
|
|
#include <spa/utils/json.h>
|
2022-03-30 17:22:26 +02:00
|
|
|
#include <spa/utils/dll.h>
|
2023-07-11 19:25:13 +02:00
|
|
|
#include <spa/utils/ratelimit.h>
|
2017-11-10 13:36:14 +01:00
|
|
|
|
|
|
|
|
#include <spa/node/node.h>
|
2019-05-20 10:14:00 +02:00
|
|
|
#include <spa/node/utils.h>
|
2017-11-21 19:34:37 +01:00
|
|
|
#include <spa/node/io.h>
|
2020-12-09 20:33:57 +01:00
|
|
|
#include <spa/debug/types.h>
|
2018-08-25 12:08:29 +02:00
|
|
|
#include <spa/param/param.h>
|
2021-05-24 18:01:19 +02:00
|
|
|
#include <spa/param/latency-utils.h>
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/param/audio/format-utils.h>
|
2024-09-18 09:54:34 +02:00
|
|
|
#include <spa/param/audio/raw-json.h>
|
2023-10-11 15:56:52 +02:00
|
|
|
#include <spa/param/tag-utils.h>
|
2016-09-20 11:20:43 +02:00
|
|
|
|
2021-09-23 14:25:32 +10:00
|
|
|
#include "alsa.h"
|
|
|
|
|
|
2020-12-09 12:09:40 +01:00
|
|
|
|
2022-01-03 16:03:23 +01:00
|
|
|
#define MAX_RATES 16
|
|
|
|
|
|
2021-12-17 16:08:08 +01:00
|
|
|
#define DEFAULT_PERIOD 1024u
|
2019-01-07 15:52:42 +01:00
|
|
|
#define DEFAULT_RATE 48000u
|
|
|
|
|
#define DEFAULT_CHANNELS 2u
|
2024-01-25 10:26:11 +01:00
|
|
|
/* CHMAP defaults to true when using UCM */
|
2020-09-14 20:15:48 +02:00
|
|
|
#define DEFAULT_USE_CHMAP false
|
2018-06-15 11:26:03 +02:00
|
|
|
|
2023-06-29 16:40:21 +02:00
|
|
|
#define MAX_HTIMESTAMP_ERROR 64
|
|
|
|
|
|
2017-05-26 17:25:58 +02:00
|
|
|
struct props {
|
|
|
|
|
char device[64];
|
|
|
|
|
char device_name[128];
|
|
|
|
|
char card_name[128];
|
2020-09-14 20:15:48 +02:00
|
|
|
bool use_chmap;
|
2017-05-25 13:28:15 +02:00
|
|
|
};
|
2016-09-20 11:20:43 +02:00
|
|
|
|
2017-10-31 15:59:08 +01:00
|
|
|
#define MAX_BUFFERS 32
|
2023-02-28 13:55:04 -05:00
|
|
|
#define MAX_POLL 16
|
2016-09-29 18:18:59 +02:00
|
|
|
|
2017-05-26 17:25:58 +02:00
|
|
|
struct buffer {
|
2019-01-07 17:57:03 +01:00
|
|
|
uint32_t id;
|
2019-02-27 16:43:01 +01:00
|
|
|
#define BUFFER_FLAG_OUT (1<<0)
|
2019-01-07 17:57:03 +01:00
|
|
|
uint32_t flags;
|
2018-05-11 09:56:46 +02:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
2019-04-29 10:00:42 +02:00
|
|
|
#define BW_MAX 0.128
|
2019-04-23 17:31:29 +02:00
|
|
|
#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)
|
2018-11-09 15:24:24 +01:00
|
|
|
|
2020-12-28 14:24:59 +01:00
|
|
|
struct channel_map {
|
|
|
|
|
uint32_t channels;
|
|
|
|
|
uint32_t pos[SPA_AUDIO_MAX_CHANNELS];
|
|
|
|
|
};
|
2021-11-23 11:28:41 +01:00
|
|
|
|
|
|
|
|
struct card {
|
|
|
|
|
struct spa_list link;
|
|
|
|
|
int ref;
|
|
|
|
|
uint32_t index;
|
|
|
|
|
snd_use_case_mgr_t *ucm;
|
|
|
|
|
char *ucm_prefix;
|
|
|
|
|
int format_ref;
|
|
|
|
|
uint32_t rate;
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-18 14:53:15 +02:00
|
|
|
struct rt_state {
|
|
|
|
|
struct spa_list followers;
|
|
|
|
|
struct state *driver;
|
|
|
|
|
struct spa_list driver_link;
|
|
|
|
|
|
|
|
|
|
unsigned int sources_added:1;
|
|
|
|
|
unsigned int following:1;
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-07 14:02:26 -05:00
|
|
|
struct bound_ctl {
|
|
|
|
|
char name[256];
|
|
|
|
|
snd_ctl_elem_info_t *info;
|
|
|
|
|
snd_ctl_elem_value_t *value;
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-26 17:25:58 +02:00
|
|
|
struct state {
|
|
|
|
|
struct spa_handle handle;
|
|
|
|
|
struct spa_node node;
|
|
|
|
|
|
|
|
|
|
struct spa_log *log;
|
2019-06-06 15:20:43 +02:00
|
|
|
struct spa_system *data_system;
|
2017-05-26 17:25:58 +02:00
|
|
|
struct spa_loop *data_loop;
|
2023-11-21 17:05:24 -05:00
|
|
|
struct spa_loop *main_loop;
|
2017-05-26 17:25:58 +02:00
|
|
|
|
2022-08-05 14:01:37 +02:00
|
|
|
FILE *log_file;
|
2023-07-11 19:25:13 +02:00
|
|
|
struct spa_ratelimit rate_limit;
|
2022-08-05 14:01:37 +02:00
|
|
|
|
2021-12-20 19:20:38 +01:00
|
|
|
uint32_t card_index;
|
2021-11-23 11:28:41 +01:00
|
|
|
struct card *card;
|
2017-05-26 17:25:58 +02:00
|
|
|
snd_pcm_stream_t stream;
|
|
|
|
|
snd_output_t *output;
|
2023-09-15 09:09:04 +02:00
|
|
|
char name[64];
|
2017-05-26 17:25:58 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook_list hooks;
|
2019-05-15 12:17:52 +02:00
|
|
|
struct spa_callbacks callbacks;
|
2017-05-26 17:25:58 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
uint64_t info_all;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_node_info info;
|
2021-08-17 09:14:40 +02:00
|
|
|
#define NODE_PropInfo 0
|
|
|
|
|
#define NODE_Props 1
|
|
|
|
|
#define NODE_IO 2
|
|
|
|
|
#define NODE_ProcessLatency 3
|
|
|
|
|
#define N_NODE_PARAMS 4
|
2021-05-21 11:08:52 +02:00
|
|
|
struct spa_param_info params[N_NODE_PARAMS];
|
2017-05-26 17:25:58 +02:00
|
|
|
struct props props;
|
|
|
|
|
|
2023-09-15 11:15:26 +02:00
|
|
|
unsigned int opened:1;
|
|
|
|
|
unsigned int prepared:1;
|
|
|
|
|
unsigned int started:1;
|
2017-05-26 17:25:58 +02:00
|
|
|
snd_pcm_t *hndl;
|
|
|
|
|
|
|
|
|
|
bool have_format;
|
|
|
|
|
struct spa_audio_info current_format;
|
|
|
|
|
|
2021-01-05 12:44:10 +01:00
|
|
|
uint32_t default_period_size;
|
2021-12-17 16:09:52 +01:00
|
|
|
uint32_t default_period_num;
|
2021-01-14 17:10:05 +01:00
|
|
|
uint32_t default_headroom;
|
2021-03-29 13:20:14 +02:00
|
|
|
uint32_t default_start_delay;
|
2020-12-09 20:33:57 +01:00
|
|
|
uint32_t default_format;
|
2020-07-01 12:54:27 +02:00
|
|
|
unsigned int default_channels;
|
2020-09-16 15:14:26 +02:00
|
|
|
unsigned int default_rate;
|
2022-01-03 16:03:23 +01:00
|
|
|
uint32_t allowed_rates[MAX_RATES];
|
|
|
|
|
uint32_t n_allowed_rates;
|
2020-12-28 14:24:59 +01:00
|
|
|
struct channel_map default_pos;
|
2023-09-18 14:53:15 +02:00
|
|
|
unsigned int disable_mmap:1;
|
|
|
|
|
unsigned int disable_batch:1;
|
|
|
|
|
unsigned int disable_tsched:1;
|
2021-12-10 11:04:38 +01:00
|
|
|
char clock_name[64];
|
2022-01-12 17:50:12 +01:00
|
|
|
uint32_t quantum_limit;
|
2020-07-01 12:54:27 +02:00
|
|
|
|
2017-05-26 17:25:58 +02:00
|
|
|
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;
|
2022-04-28 12:32:08 +02:00
|
|
|
size_t frame_scale;
|
2020-07-01 11:42:10 +02:00
|
|
|
int blocks;
|
2019-09-05 13:41:59 +02:00
|
|
|
uint32_t delay;
|
|
|
|
|
uint32_t read_size;
|
2023-09-15 12:21:18 +02:00
|
|
|
uint32_t max_read;
|
2017-05-26 17:25:58 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
uint64_t port_info_all;
|
2019-02-27 16:43:01 +01:00
|
|
|
struct spa_port_info port_info;
|
2021-08-17 09:14:40 +02:00
|
|
|
#define PORT_EnumFormat 0
|
|
|
|
|
#define PORT_Meta 1
|
|
|
|
|
#define PORT_IO 2
|
|
|
|
|
#define PORT_Format 3
|
|
|
|
|
#define PORT_Buffers 4
|
|
|
|
|
#define PORT_Latency 5
|
2023-10-11 15:56:52 +02:00
|
|
|
#define PORT_Tag 6
|
|
|
|
|
#define N_PORT_PARAMS 7
|
2021-05-21 11:08:52 +02:00
|
|
|
struct spa_param_info port_params[N_PORT_PARAMS];
|
2021-06-24 09:43:58 +02:00
|
|
|
enum spa_direction port_direction;
|
2017-11-21 19:34:37 +01:00
|
|
|
struct spa_io_buffers *io;
|
2018-07-17 09:50:51 +02:00
|
|
|
struct spa_io_clock *clock;
|
2018-10-24 10:27:57 +02:00
|
|
|
struct spa_io_position *position;
|
2019-07-09 16:56:05 +02:00
|
|
|
struct spa_io_rate_match *rate_match;
|
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;
|
2017-10-31 15:59:08 +01:00
|
|
|
|
2017-11-21 12:30:15 +01:00
|
|
|
size_t ready_offset;
|
|
|
|
|
|
2023-02-28 13:55:04 -05:00
|
|
|
/* Either a single source for tsched, or a set of pollfds from ALSA */
|
|
|
|
|
struct spa_source source[MAX_POLL];
|
2017-05-26 17:25:58 +02:00
|
|
|
int timerfd;
|
2023-02-28 13:55:04 -05:00
|
|
|
struct pollfd pfds[MAX_POLL];
|
|
|
|
|
int n_fds;
|
2019-01-07 15:52:42 +01:00
|
|
|
uint32_t threshold;
|
2019-04-25 16:15:52 +02:00
|
|
|
uint32_t last_threshold;
|
2020-12-11 17:38:27 +01:00
|
|
|
uint32_t headroom;
|
2021-03-29 13:20:14 +02:00
|
|
|
uint32_t start_delay;
|
2022-12-14 12:27:33 +01:00
|
|
|
uint32_t min_delay;
|
2023-03-03 14:10:33 +01:00
|
|
|
uint32_t max_delay;
|
2023-06-29 16:40:21 +02:00
|
|
|
uint32_t htimestamp_error;
|
2024-02-20 08:47:03 +01:00
|
|
|
uint32_t htimestamp_max_errors;
|
2019-07-09 16:56:05 +02:00
|
|
|
|
2023-09-20 11:32:34 +02:00
|
|
|
struct spa_fraction driver_rate;
|
|
|
|
|
uint32_t driver_duration;
|
|
|
|
|
|
2019-04-23 17:31:29 +02:00
|
|
|
unsigned int alsa_started:1;
|
|
|
|
|
unsigned int alsa_sync:1;
|
2022-05-11 17:41:56 +02:00
|
|
|
unsigned int alsa_sync_warning:1;
|
2020-02-21 10:47:32 +01:00
|
|
|
unsigned int following:1;
|
2019-10-23 16:04:03 +02:00
|
|
|
unsigned int matching:1;
|
2020-07-27 15:56:20 +02:00
|
|
|
unsigned int resample:1;
|
2021-01-05 17:48:09 +01:00
|
|
|
unsigned int use_mmap:1;
|
|
|
|
|
unsigned int planar:1;
|
2021-05-07 11:51:22 +02:00
|
|
|
unsigned int freewheel:1;
|
2021-06-02 17:25:21 +02:00
|
|
|
unsigned int open_ucm:1;
|
2021-08-12 14:08:20 +02:00
|
|
|
unsigned int is_iec958:1;
|
|
|
|
|
unsigned int is_hdmi:1;
|
2021-11-23 11:28:41 +01:00
|
|
|
unsigned int multi_rate:1;
|
2023-06-29 16:23:39 +02:00
|
|
|
unsigned int htimestamp:1;
|
2023-08-28 10:06:29 +02:00
|
|
|
unsigned int is_pro:1;
|
2023-09-18 14:46:56 +02:00
|
|
|
unsigned int sources_added:1;
|
2023-10-09 10:10:46 +02:00
|
|
|
unsigned int auto_link:1;
|
2023-09-11 11:04:49 +02:00
|
|
|
unsigned int linked:1;
|
2023-10-18 14:45:47 +02:00
|
|
|
unsigned int is_batch:1;
|
2024-04-27 13:28:51 -07:00
|
|
|
unsigned int force_rate:1;
|
2021-08-12 14:08:20 +02:00
|
|
|
|
|
|
|
|
uint64_t iec958_codecs;
|
2017-05-26 17:25:58 +02:00
|
|
|
|
|
|
|
|
int64_t sample_count;
|
2018-11-16 17:00:40 +01:00
|
|
|
|
|
|
|
|
int64_t sample_time;
|
|
|
|
|
uint64_t next_time;
|
2019-04-23 17:31:29 +02:00
|
|
|
uint64_t base_time;
|
2017-10-24 18:04:03 +02:00
|
|
|
|
|
|
|
|
uint64_t underrun;
|
2019-04-23 17:31:29 +02:00
|
|
|
|
2020-12-09 12:09:40 +01:00
|
|
|
struct spa_dll dll;
|
2021-03-03 15:40:10 +01:00
|
|
|
double max_error;
|
2023-04-10 16:28:55 +02:00
|
|
|
double max_resync;
|
2024-10-04 10:47:47 +02:00
|
|
|
double err_avg, err_var, err_wdw;
|
2021-05-21 10:01:37 +02:00
|
|
|
|
2021-06-24 09:43:58 +02:00
|
|
|
struct spa_latency_info latency[2];
|
2021-08-17 09:14:40 +02:00
|
|
|
struct spa_process_latency_info process_latency;
|
2023-06-08 17:37:04 -04:00
|
|
|
|
2023-10-11 15:56:52 +02:00
|
|
|
struct spa_pod *tag[2];
|
|
|
|
|
|
2023-11-07 14:02:26 -05:00
|
|
|
/* for rate match and bind ctls */
|
2023-06-08 17:37:04 -04:00
|
|
|
snd_ctl_t *ctl;
|
2023-11-07 14:02:26 -05:00
|
|
|
|
|
|
|
|
/* Rate match via an ALSA ctl */
|
2023-06-08 17:37:04 -04:00
|
|
|
snd_ctl_elem_value_t *pitch_elem;
|
|
|
|
|
double last_rate;
|
2023-09-18 09:40:52 +02:00
|
|
|
|
2023-11-07 14:02:26 -05:00
|
|
|
/* ALSA ctls exposed as params */
|
|
|
|
|
unsigned int num_bind_ctls;
|
|
|
|
|
struct bound_ctl bound_ctls[16];
|
2024-03-14 10:13:41 -04:00
|
|
|
struct pollfd ctl_pfds[MAX_POLL];
|
2023-11-07 14:02:26 -05:00
|
|
|
struct spa_source ctl_sources[MAX_POLL];
|
|
|
|
|
int ctl_n_fds;
|
|
|
|
|
|
2023-09-18 09:40:52 +02:00
|
|
|
struct spa_list link;
|
2023-09-18 14:53:15 +02:00
|
|
|
|
|
|
|
|
struct spa_list followers;
|
|
|
|
|
struct state *driver;
|
|
|
|
|
struct spa_list driver_link;
|
|
|
|
|
|
|
|
|
|
struct rt_state rt;
|
2016-09-20 11:20:43 +02:00
|
|
|
};
|
|
|
|
|
|
2021-11-30 17:43:07 +01:00
|
|
|
struct spa_pod *spa_alsa_enum_propinfo(struct state *state,
|
2021-12-01 11:39:30 +01:00
|
|
|
uint32_t idx, struct spa_pod_builder *b);
|
2021-11-30 17:43:07 +01:00
|
|
|
int spa_alsa_add_prop_params(struct state *state, struct spa_pod_builder *b);
|
|
|
|
|
int spa_alsa_parse_prop_params(struct state *state, struct spa_pod *params);
|
|
|
|
|
|
|
|
|
|
int spa_alsa_enum_format(struct state *state, int seq,
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t start, uint32_t num,
|
2019-02-25 12:29:57 +01:00
|
|
|
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);
|
2023-06-08 17:37:04 -04:00
|
|
|
int spa_alsa_update_rate_match(struct state *state);
|
2016-09-20 11:20:43 +02:00
|
|
|
|
2021-11-23 12:27:36 +01:00
|
|
|
int spa_alsa_init(struct state *state, const struct spa_dict *info);
|
2021-06-02 13:23:08 +02:00
|
|
|
int spa_alsa_clear(struct state *state);
|
|
|
|
|
|
2021-09-14 12:42:03 +02:00
|
|
|
int spa_alsa_open(struct state *state, const char *params);
|
2023-09-15 11:15:26 +02:00
|
|
|
int spa_alsa_prepare(struct state *state);
|
2018-11-16 17:00:40 +01:00
|
|
|
int spa_alsa_start(struct state *state);
|
2020-02-21 10:47:32 +01:00
|
|
|
int spa_alsa_reassign_follower(struct state *state);
|
2018-11-16 17:00:40 +01:00
|
|
|
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
|
|
|
|
2021-01-05 17:48:09 +01:00
|
|
|
int spa_alsa_write(struct state *state);
|
2021-05-07 11:51:22 +02:00
|
|
|
int spa_alsa_read(struct state *state);
|
|
|
|
|
int spa_alsa_skip(struct state *state);
|
2018-11-09 15:24:24 +01:00
|
|
|
|
2020-03-19 13:12:49 +01:00
|
|
|
void spa_alsa_recycle_buffer(struct state *state, uint32_t buffer_id);
|
|
|
|
|
|
2023-11-07 13:01:52 -05:00
|
|
|
void spa_alsa_emit_node_info(struct state *state, bool full);
|
|
|
|
|
void spa_alsa_emit_port_info(struct state *state, bool full);
|
|
|
|
|
|
2021-03-18 18:40:56 +01:00
|
|
|
static inline void spa_alsa_parse_position(struct channel_map *map, const char *val, size_t len)
|
|
|
|
|
{
|
2024-09-18 09:54:34 +02:00
|
|
|
spa_audio_parse_position(val, len, map->pos, &map->channels);
|
2021-03-18 18:40:56 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-03 16:03:23 +01:00
|
|
|
static inline uint32_t spa_alsa_parse_rates(uint32_t *rates, uint32_t max, const char *val, size_t len)
|
|
|
|
|
{
|
2024-09-18 09:54:34 +02:00
|
|
|
return spa_json_str_array_uint32(val, len, rates, max);
|
2022-01-03 16:03:23 +01:00
|
|
|
}
|
|
|
|
|
|
2021-08-12 14:08:20 +02:00
|
|
|
static inline uint32_t spa_alsa_iec958_codec_from_name(const char *name)
|
|
|
|
|
{
|
2024-09-18 09:54:34 +02:00
|
|
|
return spa_type_audio_iec958_codec_from_short_name(name);
|
2021-08-12 14:08:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void spa_alsa_parse_iec958_codecs(uint64_t *codecs, const char *val, size_t len)
|
|
|
|
|
{
|
2024-09-13 13:09:54 +02:00
|
|
|
struct spa_json it[1];
|
2021-08-12 14:08:20 +02:00
|
|
|
char v[256];
|
|
|
|
|
|
2024-09-13 13:09:54 +02:00
|
|
|
if (spa_json_begin_array_relax(&it[0], val, len) <= 0)
|
|
|
|
|
return;
|
2021-08-12 14:08:20 +02:00
|
|
|
|
|
|
|
|
*codecs = 0;
|
2024-09-13 13:09:54 +02:00
|
|
|
while (spa_json_get_string(&it[0], v, sizeof(v)) > 0)
|
2021-08-12 14:08:20 +02:00
|
|
|
*codecs |= 1ULL << spa_alsa_iec958_codec_from_name(v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint32_t spa_alsa_get_iec958_codecs(struct state *state, uint32_t *codecs,
|
|
|
|
|
uint32_t max_codecs)
|
|
|
|
|
{
|
|
|
|
|
uint64_t mask = state->iec958_codecs;
|
|
|
|
|
uint32_t i = 0, j = 0;
|
2021-08-18 10:52:04 +02:00
|
|
|
if (!(state->is_iec958 || state->is_hdmi))
|
|
|
|
|
return 0;
|
2021-08-12 14:08:20 +02:00
|
|
|
while (mask && i < max_codecs) {
|
|
|
|
|
if (mask & 1)
|
|
|
|
|
codecs[i++] = j;
|
|
|
|
|
mask >>= 1;
|
|
|
|
|
j++;
|
|
|
|
|
}
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-17 10:05:54 +02:00
|
|
|
/* This function is also as snd_pcm_channel_area_addr() since 1.2.6 which is not yet
|
|
|
|
|
* in ubuntu and I can't figure out how to do the ALSA version check. */
|
2023-04-14 19:25:51 +02:00
|
|
|
static inline void *channel_area_addr(const snd_pcm_channel_area_t *area, snd_pcm_uframes_t offset)
|
|
|
|
|
{
|
|
|
|
|
return (char *)area->addr + (area->first + area->step * offset) / 8;
|
|
|
|
|
}
|
2022-09-21 15:52:24 +02:00
|
|
|
|
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
|
|
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#endif /* SPA_ALSA_UTILS_H */
|