• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // xfer-libasound.h - a header for receiver/transmitter of frames by alsa-lib.
4 //
5 // Copyright (c) 2018 Takashi Sakamoto <o-takashi@sakamocchi.jp>
6 //
7 // Licensed under the terms of the GNU General Public License, version 2.
8 
9 #ifndef __ALSA_UTILS_AXFER_XFER_LIBASOUND__H_
10 #define __ALSA_UTILS_AXFER_XFER_LIBASOUND__H_
11 
12 #include "xfer.h"
13 #include "waiter.h"
14 
15 #define logging(state, ...) \
16 	snd_output_printf(state->log, __VA_ARGS__)
17 
18 enum sched_model {
19 	SCHED_MODEL_IRQ = 0,
20 	SCHED_MODEL_TIMER,
21 	SCHED_MODEL_COUNT,
22 };
23 
24 struct xfer_libasound_ops;
25 
26 struct libasound_state {
27 	snd_pcm_t *handle;
28 
29 	snd_output_t *log;
30 	snd_pcm_hw_params_t *hw_params;
31 	snd_pcm_sw_params_t *sw_params;
32 
33 	const struct xfer_libasound_ops *ops;
34 	void *private_data;
35 
36 	bool verbose;
37 
38 	char *node_literal;
39 	char *waiter_type_literal;
40 	char *sched_model_literal;
41 
42 	unsigned int msec_per_period;
43 	unsigned int msec_per_buffer;
44 	unsigned int frames_per_period;
45 	unsigned int frames_per_buffer;
46 
47 	unsigned int msec_for_avail_min;
48 	unsigned int msec_for_start_threshold;
49 	unsigned int msec_for_stop_threshold;
50 
51 	bool finish_at_xrun:1;
52 	bool nonblock:1;
53 	bool mmap:1;
54 	bool test_nowait:1;
55 	bool no_auto_resample:1;
56 	bool no_auto_channels:1;
57 	bool no_auto_format:1;
58 	bool no_softvol:1;
59 
60 	bool use_waiter:1;
61 
62 	enum waiter_type waiter_type;
63 	struct waiter_context *waiter;
64 
65 	// For scheduling type.
66 	enum sched_model sched_model;
67 };
68 
69 // For internal use in 'libasound' module.
70 
71 struct xfer_libasound_ops {
72 	int (*pre_process)(struct libasound_state *state);
73 	int (*process_frames)(struct libasound_state *state,
74 			      unsigned int *frame_count,
75 			      struct mapper_context *mapper,
76 			      struct container_context *cntrs);
77 	void (*post_process)(struct libasound_state *state);
78 	unsigned int private_size;
79 };
80 
81 int xfer_libasound_wait_event(struct libasound_state *state, int timeout_msec,
82 			      unsigned short *revents);
83 
84 extern const struct xfer_libasound_ops xfer_libasound_irq_rw_ops;
85 
86 extern const struct xfer_libasound_ops xfer_libasound_irq_mmap_r_ops;
87 extern const struct xfer_libasound_ops xfer_libasound_irq_mmap_w_ops;
88 
89 extern const struct xfer_libasound_ops xfer_libasound_timer_mmap_w_ops;
90 extern const struct xfer_libasound_ops xfer_libasound_timer_mmap_r_ops;
91 
92 #endif
93