1 /*
2 * PCM Interface - local header file
3 * Copyright (c) 2000 by Jaroslav Kysela <perex@perex.cz>
4 * Abramo Bagnara <abramo@alsa-project.org>
5 *
6 *
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 *
21 */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <limits.h>
26 #include <sys/uio.h>
27 #include <time.h>
28 #include <sys/time.h>
29
30 #define _snd_mask sndrv_mask
31 #define _snd_pcm_access_mask _snd_mask
32 #define _snd_pcm_format_mask _snd_mask
33 #define _snd_pcm_subformat_mask _snd_mask
34
35 #include "local.h"
36
37 #ifdef THREAD_SAFE_API
38 #define __USE_UNIX98 1 /* for old glibc */
39 #include <pthread.h>
40 #endif
41
42 #define SND_INTERVAL_INLINE
43 #include "interval.h"
44
45 #define SND_MASK_INLINE
46 #include "mask.h"
47
48 #define SND_PCM_HW_PARAM_ACCESS SNDRV_PCM_HW_PARAM_ACCESS
49 #define SND_PCM_HW_PARAM_FIRST_MASK SNDRV_PCM_HW_PARAM_FIRST_MASK
50 #define SND_PCM_HW_PARAM_FORMAT SNDRV_PCM_HW_PARAM_FORMAT
51 #define SND_PCM_HW_PARAM_SUBFORMAT SNDRV_PCM_HW_PARAM_SUBFORMAT
52 #define SND_PCM_HW_PARAM_LAST_MASK SNDRV_PCM_HW_PARAM_LAST_MASK
53 #define SND_PCM_HW_PARAM_SAMPLE_BITS SNDRV_PCM_HW_PARAM_SAMPLE_BITS
54 #define SND_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
55 #define SND_PCM_HW_PARAM_FRAME_BITS SNDRV_PCM_HW_PARAM_FRAME_BITS
56 #define SND_PCM_HW_PARAM_CHANNELS SNDRV_PCM_HW_PARAM_CHANNELS
57 #define SND_PCM_HW_PARAM_RATE SNDRV_PCM_HW_PARAM_RATE
58 #define SND_PCM_HW_PARAM_PERIOD_TIME SNDRV_PCM_HW_PARAM_PERIOD_TIME
59 #define SND_PCM_HW_PARAM_PERIOD_SIZE SNDRV_PCM_HW_PARAM_PERIOD_SIZE
60 #define SND_PCM_HW_PARAM_PERIOD_BYTES SNDRV_PCM_HW_PARAM_PERIOD_BYTES
61 #define SND_PCM_HW_PARAM_PERIODS SNDRV_PCM_HW_PARAM_PERIODS
62 #define SND_PCM_HW_PARAM_BUFFER_TIME SNDRV_PCM_HW_PARAM_BUFFER_TIME
63 #define SND_PCM_HW_PARAM_BUFFER_SIZE SNDRV_PCM_HW_PARAM_BUFFER_SIZE
64 #define SND_PCM_HW_PARAM_BUFFER_BYTES SNDRV_PCM_HW_PARAM_BUFFER_BYTES
65 #define SND_PCM_HW_PARAM_TICK_TIME SNDRV_PCM_HW_PARAM_TICK_TIME
66 #define SND_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_LAST_INTERVAL
67 #define SND_PCM_HW_PARAM_LAST_MASK SNDRV_PCM_HW_PARAM_LAST_MASK
68 #define SND_PCM_HW_PARAM_FIRST_MASK SNDRV_PCM_HW_PARAM_FIRST_MASK
69 #define SND_PCM_HW_PARAM_LAST_INTERVAL SNDRV_PCM_HW_PARAM_LAST_INTERVAL
70 #define SND_PCM_HW_PARAM_FIRST_INTERVAL SNDRV_PCM_HW_PARAM_FIRST_INTERVAL
71
72 /** device accepts mmaped access */
73 #define SND_PCM_INFO_MMAP SNDRV_PCM_INFO_MMAP
74 /** device accepts mmaped access with sample resolution */
75 #define SND_PCM_INFO_MMAP_VALID SNDRV_PCM_INFO_MMAP_VALID
76 /** device is doing double buffering */
77 #define SND_PCM_INFO_DOUBLE SNDRV_PCM_INFO_DOUBLE
78 /** device transfers samples in batch */
79 #define SND_PCM_INFO_BATCH SNDRV_PCM_INFO_BATCH
80 /** device accepts interleaved samples */
81 #define SND_PCM_INFO_INTERLEAVED SNDRV_PCM_INFO_INTERLEAVED
82 /** device accepts non-interleaved samples */
83 #define SND_PCM_INFO_NONINTERLEAVED SNDRV_PCM_INFO_NONINTERLEAVED
84 /** device accepts complex sample organization */
85 #define SND_PCM_INFO_COMPLEX SNDRV_PCM_INFO_COMPLEX
86 /** device is capable block transfers */
87 #define SND_PCM_INFO_BLOCK_TRANSFER SNDRV_PCM_INFO_BLOCK_TRANSFER
88 /** device can detect DAC/ADC overrange */
89 #define SND_PCM_INFO_OVERRANGE SNDRV_PCM_INFO_OVERRANGE
90 /** device supports resume */
91 #define SND_PCM_INFO_RESUME SNDRV_PCM_INFO_RESUME
92 /** device is capable to pause */
93 #define SND_PCM_INFO_PAUSE SNDRV_PCM_INFO_PAUSE
94 /** device can do only half duplex */
95 #define SND_PCM_INFO_HALF_DUPLEX SNDRV_PCM_INFO_HALF_DUPLEX
96 /** device can do only joint duplex (same parameters) */
97 #define SND_PCM_INFO_JOINT_DUPLEX SNDRV_PCM_INFO_JOINT_DUPLEX
98 /** device can do a kind of synchronized start */
99 #define SND_PCM_INFO_SYNC_START SNDRV_PCM_INFO_SYNC_START
100 /** device can disable period wakeups */
101 #define SND_PCM_INFO_NO_PERIOD_WAKEUP SNDRV_PCM_INFO_NO_PERIOD_WAKEUP
102
103 #define SND_PCM_HW_PARAMS_NORESAMPLE SNDRV_PCM_HW_PARAMS_NORESAMPLE
104 #define SND_PCM_HW_PARAMS_EXPORT_BUFFER SNDRV_PCM_HW_PARAMS_EXPORT_BUFFER
105 #define SND_PCM_HW_PARAMS_NO_PERIOD_WAKEUP SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP
106
107 #define SND_PCM_INFO_MONOTONIC 0x80000000
108
109 typedef struct _snd_pcm_rbptr {
110 snd_pcm_t *master;
111 volatile snd_pcm_uframes_t *ptr;
112 int fd;
113 off_t offset;
114 int link_dst_count;
115 snd_pcm_t **link_dst;
116 void *private_data;
117 void (*changed)(snd_pcm_t *pcm, snd_pcm_t *src);
118 } snd_pcm_rbptr_t;
119
120 typedef struct _snd_pcm_channel_info {
121 unsigned int channel;
122 void *addr; /* base address of channel samples */
123 unsigned int first; /* offset to first sample in bits */
124 unsigned int step; /* samples distance in bits */
125 enum { SND_PCM_AREA_SHM, SND_PCM_AREA_MMAP, SND_PCM_AREA_LOCAL } type;
126 union {
127 struct {
128 struct snd_shm_area *area;
129 int shmid;
130 } shm;
131 struct {
132 int fd;
133 off_t offset;
134 } mmap;
135 } u;
136 char reserved[64];
137 } snd_pcm_channel_info_t;
138
139 typedef struct {
140 int (*close)(snd_pcm_t *pcm);
141 int (*nonblock)(snd_pcm_t *pcm, int nonblock); /* always locked */
142 int (*async)(snd_pcm_t *pcm, int sig, pid_t pid);
143 int (*info)(snd_pcm_t *pcm, snd_pcm_info_t *info);
144 int (*hw_refine)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
145 int (*hw_params)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
146 int (*hw_free)(snd_pcm_t *pcm);
147 int (*sw_params)(snd_pcm_t *pcm, snd_pcm_sw_params_t *params); /* always locked */
148 int (*channel_info)(snd_pcm_t *pcm, snd_pcm_channel_info_t *info);
149 void (*dump)(snd_pcm_t *pcm, snd_output_t *out);
150 int (*mmap)(snd_pcm_t *pcm);
151 int (*munmap)(snd_pcm_t *pcm);
152 snd_pcm_chmap_query_t **(*query_chmaps)(snd_pcm_t *pcm);
153 snd_pcm_chmap_t *(*get_chmap)(snd_pcm_t *pcm);
154 int (*set_chmap)(snd_pcm_t *pcm, const snd_pcm_chmap_t *map);
155 } snd_pcm_ops_t;
156
157 typedef struct {
158 int (*status)(snd_pcm_t *pcm, snd_pcm_status_t *status); /* locked */
159 int (*prepare)(snd_pcm_t *pcm); /* locked */
160 int (*reset)(snd_pcm_t *pcm); /* locked */
161 int (*start)(snd_pcm_t *pcm); /* locked */
162 int (*drop)(snd_pcm_t *pcm); /* locked */
163 int (*drain)(snd_pcm_t *pcm); /* need own locking */
164 int (*pause)(snd_pcm_t *pcm, int enable); /* locked */
165 snd_pcm_state_t (*state)(snd_pcm_t *pcm); /* locked */
166 int (*hwsync)(snd_pcm_t *pcm); /* locked */
167 int (*delay)(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp); /* locked */
168 int (*resume)(snd_pcm_t *pcm); /* need own locking */
169 int (*link)(snd_pcm_t *pcm1, snd_pcm_t *pcm2);
170 int (*link_slaves)(snd_pcm_t *pcm, snd_pcm_t *master);
171 int (*unlink)(snd_pcm_t *pcm);
172 snd_pcm_sframes_t (*rewindable)(snd_pcm_t *pcm); /* locked */
173 snd_pcm_sframes_t (*rewind)(snd_pcm_t *pcm, snd_pcm_uframes_t frames); /* locked */
174 snd_pcm_sframes_t (*forwardable)(snd_pcm_t *pcm); /* locked */
175 snd_pcm_sframes_t (*forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames); /* locked */
176 snd_pcm_sframes_t (*writei)(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size); /* need own locking */
177 snd_pcm_sframes_t (*writen)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size); /* need own locking */
178 snd_pcm_sframes_t (*readi)(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size); /* need own locking */
179 snd_pcm_sframes_t (*readn)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size); /* need own locking */
180 snd_pcm_sframes_t (*avail_update)(snd_pcm_t *pcm); /* locked */
181 snd_pcm_sframes_t (*mmap_commit)(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size); /* locked */
182 int (*htimestamp)(snd_pcm_t *pcm, snd_pcm_uframes_t *avail, snd_htimestamp_t *tstamp); /* locked */
183 int (*poll_descriptors_count)(snd_pcm_t *pcm); /* locked */
184 int (*poll_descriptors)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space); /* locked */
185 int (*poll_revents)(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents); /* locked */
186 int (*may_wait_for_avail_min)(snd_pcm_t *pcm, snd_pcm_uframes_t avail);
187 int (*mmap_begin)(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas, snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames); /* locked */
188 } snd_pcm_fast_ops_t;
189
190 struct _snd_pcm {
191 void *open_func;
192 char *name;
193 snd_pcm_type_t type;
194 snd_pcm_stream_t stream;
195 int mode;
196 long minperiodtime; /* in us */
197 int poll_fd_count;
198 int poll_fd;
199 unsigned short poll_events;
200 int setup: 1,
201 compat: 1;
202 snd_pcm_access_t access; /* access mode */
203 snd_pcm_format_t format; /* SND_PCM_FORMAT_* */
204 snd_pcm_subformat_t subformat; /* subformat */
205 unsigned int channels; /* channels */
206 unsigned int rate; /* rate in Hz */
207 snd_pcm_uframes_t period_size;
208 unsigned int period_time; /* period duration */
209 snd_interval_t periods;
210 snd_pcm_tstamp_t tstamp_mode; /* timestamp mode */
211 snd_pcm_tstamp_type_t tstamp_type; /* timestamp type */
212 unsigned int period_step;
213 snd_pcm_uframes_t avail_min; /* min avail frames for wakeup */
214 int period_event;
215 snd_pcm_uframes_t start_threshold;
216 snd_pcm_uframes_t stop_threshold;
217 snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
218 noise is nearest than this */
219 snd_pcm_uframes_t silence_size; /* Silence filling size */
220 snd_pcm_uframes_t boundary; /* pointers wrap point */
221 unsigned int info; /* Info for returned setup */
222 unsigned int msbits; /* used most significant bits */
223 unsigned int rate_num; /* rate numerator */
224 unsigned int rate_den; /* rate denominator */
225 unsigned int hw_flags; /* actual hardware flags */
226 snd_pcm_uframes_t fifo_size; /* chip FIFO size in frames */
227 snd_pcm_uframes_t buffer_size;
228 snd_interval_t buffer_time;
229 unsigned int sample_bits;
230 unsigned int frame_bits;
231 snd_pcm_rbptr_t appl;
232 snd_pcm_rbptr_t hw;
233 snd_pcm_uframes_t min_align;
234 unsigned int mmap_rw: 1; /* use always mmapped buffer */
235 unsigned int mmap_shadow: 1; /* don't call actual mmap,
236 * use the mmaped buffer of the slave
237 */
238 unsigned int donot_close: 1; /* don't close this PCM */
239 unsigned int own_state_check:1; /* plugin has own PCM state check */
240 snd_pcm_channel_info_t *mmap_channels;
241 snd_pcm_channel_area_t *running_areas;
242 snd_pcm_channel_area_t *stopped_areas;
243 const snd_pcm_ops_t *ops;
244 const snd_pcm_fast_ops_t *fast_ops;
245 snd_pcm_t *op_arg;
246 snd_pcm_t *fast_op_arg;
247 void *private_data;
248 struct list_head async_handlers;
249 #ifdef THREAD_SAFE_API
250 int need_lock; /* true = this PCM (plugin) is thread-unsafe,
251 * thus it needs a lock.
252 */
253 int lock_enabled; /* thread-safety lock is enabled on the system;
254 * it's set depending on $LIBASOUND_THREAD_SAFE.
255 */
256 pthread_mutex_t lock;
257 #endif
258 };
259
260 /* make local functions really local */
261 /* Grrr, these cannot be local - a bad aserver uses them!
262 #define snd_pcm_async \
263 snd1_pcm_async
264 #define snd_pcm_mmap \
265 snd1_pcm_mmap
266 #define snd_pcm_munmap \
267 snd1_pcm_munmap
268 #define snd_pcm_hw_refine \
269 snd1_pcm_hw_refine
270 */
271 #define snd_pcm_new \
272 snd1_pcm_new
273 #define snd_pcm_free \
274 snd1_pcm_free
275 #define snd_pcm_areas_from_buf \
276 snd1_pcm_areas_from_buf
277 #define snd_pcm_areas_from_bufs \
278 snd1_pcm_areas_from_bufs
279 #define snd_pcm_open_named_slave \
280 snd1_pcm_open_named_slave
281 #define snd_pcm_hw_open_fd \
282 snd1_pcm_hw_open_fd
283 #define snd_pcm_wait_nocheck \
284 snd1_pcm_wait_nocheck
285 #define snd_pcm_rate_get_default_converter \
286 snd1_pcm_rate_get_default_converter
287 #define snd_pcm_set_hw_ptr \
288 snd1_pcm_set_hw_ptr
289 #define snd_pcm_set_appl_ptr \
290 snd1_pcm_set_appl_ptr
291 #define snd_pcm_link_hw_ptr \
292 snd1_pcm_link_hw_ptr
293 #define snd_pcm_link_appl_ptr \
294 snd1_pcm_link_appl_ptr
295 #define snd_pcm_unlink_hw_ptr \
296 snd1_pcm_unlink_hw_ptr
297 #define snd_pcm_unlink_appl_ptr \
298 snd1_pcm_unlink_appl_ptr
299 #define snd_pcm_mmap_appl_ptr \
300 snd1_pcm_mmap_appl_ptr
301 #define snd_pcm_mmap_appl_backward \
302 snd1_pcm_mmap_appl_backward
303 #define snd_pcm_mmap_appl_forward \
304 snd1_pcm_mmap_appl_forward
305 #define snd_pcm_mmap_hw_backward \
306 snd1_pcm_mmap_hw_backward
307 #define snd_pcm_mmap_hw_forward \
308 snd1_pcm_mmap_hw_forward
309 #define snd_pcm_read_areas \
310 snd1_pcm_read_areas
311 #define snd_pcm_write_areas \
312 snd1_pcm_write_areas
313 #define snd_pcm_read_mmap \
314 snd1_pcm_read_mmap
315 #define snd_pcm_write_mmap \
316 snd1_pcm_write_mmap
317 #define snd_pcm_channel_info_shm \
318 snd1_pcm_channel_info_shm
319 #define snd_pcm_hw_refine_soft \
320 snd1_pcm_hw_refine_soft
321 #define snd_pcm_hw_refine_slave \
322 snd1_pcm_hw_refine_slave
323 #define snd_pcm_hw_params_slave \
324 snd1_pcm_hw_params_slave
325 #define snd_pcm_hw_param_refine_near \
326 snd1_pcm_hw_param_refine_near
327 #define snd_pcm_hw_param_refine_multiple \
328 snd1_pcm_hw_param_refine_multiple
329 #define snd_pcm_hw_param_empty \
330 snd1_pcm_hw_param_empty
331 #define snd_pcm_hw_param_always_eq \
332 snd1_pcm_hw_param_always_eq
333 #define snd_pcm_hw_param_never_eq \
334 snd1_pcm_hw_param_never_eq
335 #define snd_pcm_hw_param_get_mask \
336 snd1_pcm_hw_param_get_mask
337 #define snd_pcm_hw_param_get_interval \
338 snd1_pcm_hw_param_get_interval
339 #define snd_pcm_hw_param_any \
340 snd1_pcm_hw_param_any
341 #define snd_pcm_hw_param_set_integer \
342 snd1_pcm_hw_param_set_integer
343 #define snd_pcm_hw_param_set_first \
344 snd1_pcm_hw_param_set_first
345 #define snd_pcm_hw_param_set_last \
346 snd1_pcm_hw_param_set_last
347 #define snd_pcm_hw_param_set_near \
348 snd1_pcm_hw_param_set_near
349 #define snd_pcm_hw_param_set_min \
350 snd1_pcm_hw_param_set_min
351 #define snd_pcm_hw_param_set_max \
352 snd1_pcm_hw_param_set_max
353 #define snd_pcm_hw_param_set_minmax \
354 snd1_pcm_hw_param_set_minmax
355 #define snd_pcm_hw_param_set \
356 snd1_pcm_hw_param_set
357 #define snd_pcm_hw_param_set_mask \
358 snd1_pcm_hw_param_set_mask
359 #define snd_pcm_hw_param_get \
360 snd1_pcm_hw_param_get
361 #define snd_pcm_hw_param_get_min \
362 snd1_pcm_hw_param_get_min
363 #define snd_pcm_hw_param_get_max \
364 snd1_pcm_hw_param_get_max
365 #define snd_pcm_hw_param_name \
366 snd1_pcm_hw_param_name
367
368 int snd_pcm_new(snd_pcm_t **pcmp, snd_pcm_type_t type, const char *name,
369 snd_pcm_stream_t stream, int mode);
370 int snd_pcm_free(snd_pcm_t *pcm);
371
372 void snd_pcm_areas_from_buf(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas, void *buf);
373 void snd_pcm_areas_from_bufs(snd_pcm_t *pcm, snd_pcm_channel_area_t *areas, void **bufs);
374
375 int snd_pcm_async(snd_pcm_t *pcm, int sig, pid_t pid);
376 int snd_pcm_mmap(snd_pcm_t *pcm);
377 int snd_pcm_munmap(snd_pcm_t *pcm);
378 int snd_pcm_mmap_ready(snd_pcm_t *pcm);
379 void snd_pcm_set_hw_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *hw_ptr, int fd, off_t offset);
380 void snd_pcm_set_appl_ptr(snd_pcm_t *pcm, volatile snd_pcm_uframes_t *appl_ptr, int fd, off_t offset);
381 void snd_pcm_link_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave);
382 void snd_pcm_link_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave);
383 void snd_pcm_unlink_hw_ptr(snd_pcm_t *pcm, snd_pcm_t *slave);
384 void snd_pcm_unlink_appl_ptr(snd_pcm_t *pcm, snd_pcm_t *slave);
385 snd_pcm_sframes_t snd_pcm_mmap_appl_ptr(snd_pcm_t *pcm, off_t offset);
386 void snd_pcm_mmap_appl_backward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
387 void snd_pcm_mmap_appl_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
388 void snd_pcm_mmap_hw_backward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
389 void snd_pcm_mmap_hw_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
390
391 snd_pcm_sframes_t snd_pcm_mmap_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size);
392 snd_pcm_sframes_t snd_pcm_mmap_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
393 snd_pcm_sframes_t snd_pcm_mmap_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
394 snd_pcm_sframes_t snd_pcm_mmap_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
395
396 typedef snd_pcm_sframes_t (*snd_pcm_xfer_areas_func_t)(snd_pcm_t *pcm,
397 const snd_pcm_channel_area_t *areas,
398 snd_pcm_uframes_t offset,
399 snd_pcm_uframes_t size);
400
401 snd_pcm_sframes_t snd_pcm_read_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
402 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
403 snd_pcm_xfer_areas_func_t func);
404 snd_pcm_sframes_t snd_pcm_write_areas(snd_pcm_t *pcm, const snd_pcm_channel_area_t *areas,
405 snd_pcm_uframes_t offset, snd_pcm_uframes_t size,
406 snd_pcm_xfer_areas_func_t func);
407 snd_pcm_sframes_t snd_pcm_read_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t offset,
408 snd_pcm_uframes_t size);
409 snd_pcm_sframes_t snd_pcm_write_mmap(snd_pcm_t *pcm, snd_pcm_uframes_t offset,
410 snd_pcm_uframes_t size);
snd_pcm_channel_info(snd_pcm_t * pcm,snd_pcm_channel_info_t * info)411 static inline int snd_pcm_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t *info)
412 {
413 if (!pcm->ops->channel_info)
414 return -ENOSYS;
415 return pcm->ops->channel_info(pcm, info);
416 }
417 int snd_pcm_channel_info_shm(snd_pcm_t *pcm, snd_pcm_channel_info_t *info, int shmid);
418 int _snd_pcm_poll_descriptor(snd_pcm_t *pcm);
419 #define _snd_pcm_link_descriptor _snd_pcm_poll_descriptor /* FIXME */
420 #define _snd_pcm_async_descriptor _snd_pcm_poll_descriptor /* FIXME */
421
422 /* locked versions */
423 int __snd_pcm_mmap_begin_generic(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
424 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames);
425 int __snd_pcm_mmap_begin(snd_pcm_t *pcm, const snd_pcm_channel_area_t **areas,
426 snd_pcm_uframes_t *offset, snd_pcm_uframes_t *frames);
427 snd_pcm_sframes_t __snd_pcm_mmap_commit(snd_pcm_t *pcm,
428 snd_pcm_uframes_t offset,
429 snd_pcm_uframes_t frames);
430 int __snd_pcm_wait_in_lock(snd_pcm_t *pcm, int timeout);
431
__snd_pcm_avail_update(snd_pcm_t * pcm)432 static inline snd_pcm_sframes_t __snd_pcm_avail_update(snd_pcm_t *pcm)
433 {
434 if (!pcm->fast_ops->avail_update)
435 return -ENOSYS;
436 return pcm->fast_ops->avail_update(pcm->fast_op_arg);
437 }
438
__snd_pcm_start(snd_pcm_t * pcm)439 static inline int __snd_pcm_start(snd_pcm_t *pcm)
440 {
441 if (!pcm->fast_ops->start)
442 return -ENOSYS;
443 return pcm->fast_ops->start(pcm->fast_op_arg);
444 }
445
__snd_pcm_state(snd_pcm_t * pcm)446 static inline snd_pcm_state_t __snd_pcm_state(snd_pcm_t *pcm)
447 {
448 if (!pcm->fast_ops->state)
449 return SND_PCM_STATE_OPEN;
450 return pcm->fast_ops->state(pcm->fast_op_arg);
451 }
452
__snd_pcm_hwsync(snd_pcm_t * pcm)453 static inline int __snd_pcm_hwsync(snd_pcm_t *pcm)
454 {
455 if (!pcm->fast_ops->hwsync)
456 return -ENOSYS;
457 return pcm->fast_ops->hwsync(pcm->fast_op_arg);
458 }
459
__snd_pcm_delay(snd_pcm_t * pcm,snd_pcm_sframes_t * delayp)460 static inline int __snd_pcm_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
461 {
462 if (!pcm->fast_ops->delay)
463 return -ENOSYS;
464 return pcm->fast_ops->delay(pcm->fast_op_arg, delayp);
465 }
466
467 /* handle special error cases */
snd_pcm_check_error(snd_pcm_t * pcm,int err)468 static inline int snd_pcm_check_error(snd_pcm_t *pcm, int err)
469 {
470 if (err == -EINTR) {
471 switch (__snd_pcm_state(pcm)) {
472 case SND_PCM_STATE_XRUN:
473 return -EPIPE;
474 case SND_PCM_STATE_SUSPENDED:
475 return -ESTRPIPE;
476 case SND_PCM_STATE_DISCONNECTED:
477 return -ENODEV;
478 default:
479 break;
480 }
481 }
482 return err;
483 }
484
485 /**
486 * \retval number of frames available to the application for playback
487 *
488 * This is how far ahead the hardware position in the ring buffer is,
489 * compared to the application position. ie. for playback it's the
490 * number of frames in the empty part of the ring buffer.
491 */
__snd_pcm_playback_avail(snd_pcm_t * pcm,const snd_pcm_uframes_t hw_ptr,const snd_pcm_uframes_t appl_ptr)492 static inline snd_pcm_uframes_t __snd_pcm_playback_avail(snd_pcm_t *pcm,
493 const snd_pcm_uframes_t hw_ptr,
494 const snd_pcm_uframes_t appl_ptr)
495 {
496 snd_pcm_sframes_t avail;
497 avail = hw_ptr + pcm->buffer_size - appl_ptr;
498 if (avail < 0)
499 avail += pcm->boundary;
500 else if ((snd_pcm_uframes_t) avail >= pcm->boundary)
501 avail -= pcm->boundary;
502 return avail;
503 }
504
snd_pcm_mmap_playback_avail(snd_pcm_t * pcm)505 static inline snd_pcm_uframes_t snd_pcm_mmap_playback_avail(snd_pcm_t *pcm)
506 {
507 return __snd_pcm_playback_avail(pcm, *pcm->hw.ptr, *pcm->appl.ptr);
508 }
509
510 /*
511 * \retval number of frames available to the application for capture
512 *
513 * This is how far ahead the hardware position in the ring buffer is
514 * compared to the application position. ie. for capture, it's the
515 * number of frames in the filled part of the ring buffer.
516 */
__snd_pcm_capture_avail(snd_pcm_t * pcm,const snd_pcm_uframes_t hw_ptr,const snd_pcm_uframes_t appl_ptr)517 static inline snd_pcm_uframes_t __snd_pcm_capture_avail(snd_pcm_t *pcm,
518 const snd_pcm_uframes_t hw_ptr,
519 const snd_pcm_uframes_t appl_ptr)
520 {
521 snd_pcm_sframes_t avail;
522 avail = hw_ptr - appl_ptr;
523 if (avail < 0)
524 avail += pcm->boundary;
525 return avail;
526 }
527
snd_pcm_mmap_capture_avail(snd_pcm_t * pcm)528 static inline snd_pcm_uframes_t snd_pcm_mmap_capture_avail(snd_pcm_t *pcm)
529 {
530 return __snd_pcm_capture_avail(pcm, *pcm->hw.ptr, *pcm->appl.ptr);
531 }
532
__snd_pcm_avail(snd_pcm_t * pcm,const snd_pcm_uframes_t hw_ptr,const snd_pcm_uframes_t appl_ptr)533 static inline snd_pcm_uframes_t __snd_pcm_avail(snd_pcm_t *pcm,
534 const snd_pcm_uframes_t hw_ptr,
535 const snd_pcm_uframes_t appl_ptr)
536 {
537 if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
538 return __snd_pcm_playback_avail(pcm, hw_ptr, appl_ptr);
539 else
540 return __snd_pcm_capture_avail(pcm, hw_ptr, appl_ptr);
541 }
542
snd_pcm_mmap_avail(snd_pcm_t * pcm)543 static inline snd_pcm_uframes_t snd_pcm_mmap_avail(snd_pcm_t *pcm)
544 {
545 return __snd_pcm_avail(pcm, *pcm->hw.ptr, *pcm->appl.ptr);
546 }
547
548 /*
549 * \retval number of frames available to the hardware for playback
550 *
551 * ie. the filled part of the ring buffer
552 */
snd_pcm_mmap_playback_hw_avail(snd_pcm_t * pcm)553 static inline snd_pcm_sframes_t snd_pcm_mmap_playback_hw_avail(snd_pcm_t *pcm)
554 {
555 return pcm->buffer_size - snd_pcm_mmap_playback_avail(pcm);
556 }
557
558 /*
559 * \retval number of frames available to the hardware for capture
560 *
561 * ie. the empty part of the ring buffer.
562 */
snd_pcm_mmap_capture_hw_avail(snd_pcm_t * pcm)563 static inline snd_pcm_sframes_t snd_pcm_mmap_capture_hw_avail(snd_pcm_t *pcm)
564 {
565 return pcm->buffer_size - snd_pcm_mmap_capture_avail(pcm);
566 }
567
snd_pcm_mmap_hw_avail(snd_pcm_t * pcm)568 static inline snd_pcm_sframes_t snd_pcm_mmap_hw_avail(snd_pcm_t *pcm)
569 {
570 return pcm->buffer_size - snd_pcm_mmap_avail(pcm);
571 }
572
snd_pcm_mmap_playback_hw_rewindable(snd_pcm_t * pcm)573 static inline snd_pcm_sframes_t snd_pcm_mmap_playback_hw_rewindable(snd_pcm_t *pcm)
574 {
575 snd_pcm_sframes_t ret = snd_pcm_mmap_playback_hw_avail(pcm);
576 return (ret >= 0) ? ret : 0;
577 }
578
snd_pcm_mmap_capture_hw_rewindable(snd_pcm_t * pcm)579 static inline snd_pcm_sframes_t snd_pcm_mmap_capture_hw_rewindable(snd_pcm_t *pcm)
580 {
581 snd_pcm_sframes_t ret = snd_pcm_mmap_capture_hw_avail(pcm);
582 return (ret >= 0) ? ret : 0;
583 }
584
snd_pcm_mmap_hw_rewindable(snd_pcm_t * pcm)585 static inline snd_pcm_uframes_t snd_pcm_mmap_hw_rewindable(snd_pcm_t *pcm)
586 {
587 snd_pcm_sframes_t ret = snd_pcm_mmap_hw_avail(pcm);
588 return (ret >= 0) ? ret : 0;
589 }
590
snd_pcm_mmap_areas(snd_pcm_t * pcm)591 static inline const snd_pcm_channel_area_t *snd_pcm_mmap_areas(snd_pcm_t *pcm)
592 {
593 if (pcm->stopped_areas &&
594 __snd_pcm_state(pcm) != SND_PCM_STATE_RUNNING)
595 return pcm->stopped_areas;
596 return pcm->running_areas;
597 }
598
snd_pcm_mmap_offset(snd_pcm_t * pcm)599 static inline snd_pcm_uframes_t snd_pcm_mmap_offset(snd_pcm_t *pcm)
600 {
601 assert(pcm);
602 return *pcm->appl.ptr % pcm->buffer_size;
603 }
604
snd_pcm_mmap_hw_offset(snd_pcm_t * pcm)605 static inline snd_pcm_uframes_t snd_pcm_mmap_hw_offset(snd_pcm_t *pcm)
606 {
607 assert(pcm);
608 return *pcm->hw.ptr % pcm->buffer_size;
609 }
610
611 /*
612 * \retval number of frames pending from application to hardware
613 */
snd_pcm_mmap_playback_delay(snd_pcm_t * pcm)614 static inline snd_pcm_uframes_t snd_pcm_mmap_playback_delay(snd_pcm_t *pcm)
615 {
616 return snd_pcm_mmap_playback_hw_avail(pcm);
617 }
618
619 /*
620 * \retval number of frames pending from hardware to application
621 */
snd_pcm_mmap_capture_delay(snd_pcm_t * pcm)622 static inline snd_pcm_uframes_t snd_pcm_mmap_capture_delay(snd_pcm_t *pcm)
623 {
624 return snd_pcm_mmap_capture_avail(pcm);
625 }
626
snd_pcm_mmap_delay(snd_pcm_t * pcm)627 static inline snd_pcm_sframes_t snd_pcm_mmap_delay(snd_pcm_t *pcm)
628 {
629 if (pcm->stream == SND_PCM_STREAM_PLAYBACK)
630 return snd_pcm_mmap_playback_delay(pcm);
631 else
632 return snd_pcm_mmap_capture_delay(pcm);
633 }
634
_snd_pcm_writei(snd_pcm_t * pcm,const void * buffer,snd_pcm_uframes_t size)635 static inline snd_pcm_sframes_t _snd_pcm_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
636 {
637 /* lock handled in the callback */
638 if (!pcm->fast_ops->writei)
639 return -ENOSYS;
640 return pcm->fast_ops->writei(pcm->fast_op_arg, buffer, size);
641 }
642
_snd_pcm_writen(snd_pcm_t * pcm,void ** bufs,snd_pcm_uframes_t size)643 static inline snd_pcm_sframes_t _snd_pcm_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
644 {
645 /* lock handled in the callback */
646 if (!pcm->fast_ops->writen)
647 return -ENOSYS;
648 return pcm->fast_ops->writen(pcm->fast_op_arg, bufs, size);
649 }
650
_snd_pcm_readi(snd_pcm_t * pcm,void * buffer,snd_pcm_uframes_t size)651 static inline snd_pcm_sframes_t _snd_pcm_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
652 {
653 /* lock handled in the callback */
654 if (!pcm->fast_ops->readi)
655 return -ENOSYS;
656 return pcm->fast_ops->readi(pcm->fast_op_arg, buffer, size);
657 }
658
_snd_pcm_readn(snd_pcm_t * pcm,void ** bufs,snd_pcm_uframes_t size)659 static inline snd_pcm_sframes_t _snd_pcm_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
660 {
661 /* lock handled in the callback */
662 if (!pcm->fast_ops->readn)
663 return -ENOSYS;
664 return pcm->fast_ops->readn(pcm->fast_op_arg, bufs, size);
665 }
666
muldiv(int a,int b,int c,int * r)667 static inline int muldiv(int a, int b, int c, int *r)
668 {
669 int64_t n = (int64_t)a * b;
670 int64_t v = n / c;
671 if (v > INT_MAX) {
672 *r = 0;
673 return INT_MAX;
674 }
675 if (v < INT_MIN) {
676 *r = 0;
677 return INT_MIN;
678 }
679 *r = n % c;
680 return v;
681 }
682
muldiv_down(int a,int b,int c)683 static inline int muldiv_down(int a, int b, int c)
684 {
685 int64_t v = (int64_t)a * b / c;
686 if (v > INT_MAX) {
687 return INT_MAX;
688 }
689 if (v < INT_MIN) {
690 return INT_MIN;
691 }
692 return v;
693 }
694
muldiv_near(int a,int b,int c)695 static inline int muldiv_near(int a, int b, int c)
696 {
697 int r;
698 int n = muldiv(a, b, c, &r);
699 if (r >= (c + 1) / 2)
700 n++;
701 return n;
702 }
703
704 int snd_pcm_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
705 int _snd_pcm_hw_params_internal(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
706 #undef _snd_pcm_hw_params
707 int snd_pcm_hw_refine_soft(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
708 int snd_pcm_hw_refine_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
709 int (*cprepare)(snd_pcm_t *pcm,
710 snd_pcm_hw_params_t *params),
711 int (*cchange)(snd_pcm_t *pcm,
712 snd_pcm_hw_params_t *params,
713 snd_pcm_hw_params_t *sparams),
714 int (*sprepare)(snd_pcm_t *pcm,
715 snd_pcm_hw_params_t *params),
716 int (*schange)(snd_pcm_t *pcm,
717 snd_pcm_hw_params_t *params,
718 snd_pcm_hw_params_t *sparams),
719 int (*srefine)(snd_pcm_t *pcm,
720 snd_pcm_hw_params_t *sparams));
721 int snd_pcm_hw_params_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
722 int (*cchange)(snd_pcm_t *pcm,
723 snd_pcm_hw_params_t *params,
724 snd_pcm_hw_params_t *sparams),
725 int (*sprepare)(snd_pcm_t *pcm,
726 snd_pcm_hw_params_t *params),
727 int (*schange)(snd_pcm_t *pcm,
728 snd_pcm_hw_params_t *params,
729 snd_pcm_hw_params_t *sparams),
730 int (*sparams)(snd_pcm_t *pcm,
731 snd_pcm_hw_params_t *sparams));
732
733
734 void _snd_pcm_hw_params_any(snd_pcm_hw_params_t *params);
735 void _snd_pcm_hw_param_set_empty(snd_pcm_hw_params_t *params,
736 snd_pcm_hw_param_t var);
737 int _snd_pcm_hw_param_set_interval(snd_pcm_hw_params_t *params,
738 snd_pcm_hw_param_t var,
739 const snd_interval_t *val);
740 int _snd_pcm_hw_param_set_mask(snd_pcm_hw_params_t *params,
741 snd_pcm_hw_param_t var, const snd_mask_t *mask);
742 int _snd_pcm_hw_param_first(snd_pcm_hw_params_t *params,
743 snd_pcm_hw_param_t var);
744 int _snd_pcm_hw_param_last(snd_pcm_hw_params_t *params,
745 snd_pcm_hw_param_t var);
746 int _snd_pcm_hw_param_set(snd_pcm_hw_params_t *params,
747 snd_pcm_hw_param_t var, unsigned int val, int dir);
_snd_pcm_hw_params_set_format(snd_pcm_hw_params_t * params,snd_pcm_format_t val)748 static inline int _snd_pcm_hw_params_set_format(snd_pcm_hw_params_t *params,
749 snd_pcm_format_t val)
750 {
751 return _snd_pcm_hw_param_set(params, SND_PCM_HW_PARAM_FORMAT,
752 (unsigned long) val, 0);
753 }
754
_snd_pcm_hw_params_set_subformat(snd_pcm_hw_params_t * params,snd_pcm_subformat_t val)755 static inline int _snd_pcm_hw_params_set_subformat(snd_pcm_hw_params_t *params,
756 snd_pcm_subformat_t val)
757 {
758 return _snd_pcm_hw_param_set(params, SND_PCM_HW_PARAM_SUBFORMAT,
759 (unsigned long) val, 0);
760 }
761
762 int _snd_pcm_hw_param_set_min(snd_pcm_hw_params_t *params,
763 snd_pcm_hw_param_t var, unsigned int val, int dir);
764 int _snd_pcm_hw_param_set_max(snd_pcm_hw_params_t *params,
765 snd_pcm_hw_param_t var, unsigned int val, int dir);
766 int _snd_pcm_hw_param_set_minmax(snd_pcm_hw_params_t *params,
767 snd_pcm_hw_param_t var,
768 unsigned int min, int mindir,
769 unsigned int max, int maxdir);
770 int _snd_pcm_hw_param_refine(snd_pcm_hw_params_t *params,
771 snd_pcm_hw_param_t var,
772 const snd_pcm_hw_params_t *src);
773 int _snd_pcm_hw_params_refine(snd_pcm_hw_params_t *params,
774 unsigned int vars,
775 const snd_pcm_hw_params_t *src);
776 int snd_pcm_hw_param_refine_near(snd_pcm_t *pcm,
777 snd_pcm_hw_params_t *params,
778 snd_pcm_hw_param_t var,
779 const snd_pcm_hw_params_t *src);
780 int snd_pcm_hw_param_refine_multiple(snd_pcm_t *pcm,
781 snd_pcm_hw_params_t *params,
782 snd_pcm_hw_param_t var,
783 const snd_pcm_hw_params_t *src);
784 int snd_pcm_hw_param_empty(const snd_pcm_hw_params_t *params,
785 snd_pcm_hw_param_t var);
786 int snd_pcm_hw_param_always_eq(const snd_pcm_hw_params_t *params,
787 snd_pcm_hw_param_t var,
788 const snd_pcm_hw_params_t *params1);
789 int snd_pcm_hw_param_never_eq(const snd_pcm_hw_params_t *params,
790 snd_pcm_hw_param_t var,
791 const snd_pcm_hw_params_t *params1);
792 const snd_mask_t *snd_pcm_hw_param_get_mask(const snd_pcm_hw_params_t *params,
793 snd_pcm_hw_param_t var);
794 const snd_interval_t *snd_pcm_hw_param_get_interval(const snd_pcm_hw_params_t *params,
795 snd_pcm_hw_param_t var);
796
797 int snd_pcm_hw_param_any(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
798 snd_pcm_hw_param_t var);
799 int snd_pcm_hw_param_set_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
800 snd_set_mode_t mode,
801 snd_pcm_hw_param_t var);
802 int snd_pcm_hw_param_set_first(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
803 snd_pcm_hw_param_t var, unsigned int *rval, int *dir);
804 int snd_pcm_hw_param_set_last(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
805 snd_pcm_hw_param_t var, unsigned int *rval, int *dir);
806 int snd_pcm_hw_param_set_near(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
807 snd_pcm_hw_param_t var, unsigned int *val, int *dir);
808 int snd_pcm_hw_param_set_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
809 snd_set_mode_t mode,
810 snd_pcm_hw_param_t var,
811 unsigned int *val, int *dir);
812 int snd_pcm_hw_param_set_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
813 snd_set_mode_t mode,
814 snd_pcm_hw_param_t var, unsigned int *val, int *dir);
815 int snd_pcm_hw_param_set_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
816 snd_set_mode_t mode,
817 snd_pcm_hw_param_t var,
818 unsigned int *min, int *mindir,
819 unsigned int *max, int *maxdir);
820 int snd_pcm_hw_param_set(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
821 snd_set_mode_t mode,
822 snd_pcm_hw_param_t var, unsigned int val, int dir);
823 int snd_pcm_hw_param_set_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
824 snd_set_mode_t mode,
825 snd_pcm_hw_param_t var, const snd_mask_t *mask);
826 int snd_pcm_hw_param_get(const snd_pcm_hw_params_t *params, snd_pcm_hw_param_t var,
827 unsigned int *val, int *dir);
828 int snd_pcm_hw_param_get_min(const snd_pcm_hw_params_t *params,
829 snd_pcm_hw_param_t var,
830 unsigned int *val, int *dir);
831 int snd_pcm_hw_param_get_max(const snd_pcm_hw_params_t *params,
832 snd_pcm_hw_param_t var,
833 unsigned int *val, int *dir);
834
835 #ifdef INTERNAL
836 snd_pcm_sframes_t INTERNAL(snd_pcm_forward)(snd_pcm_t *pcm, snd_pcm_uframes_t frames);
837
838 int INTERNAL(snd_pcm_hw_params_get_access)(const snd_pcm_hw_params_t *params, snd_pcm_access_t *access);
839 int snd_pcm_hw_params_test_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access);
840 int snd_pcm_hw_params_set_access(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t access);
841 int INTERNAL(snd_pcm_hw_params_set_access_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access);
842 int INTERNAL(snd_pcm_hw_params_set_access_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_t *access);
843 int snd_pcm_hw_params_set_access_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask);
844 int snd_pcm_hw_params_get_access_mask(snd_pcm_hw_params_t *params, snd_pcm_access_mask_t *mask);
845
846 int INTERNAL(snd_pcm_hw_params_get_format)(const snd_pcm_hw_params_t *params, snd_pcm_format_t *val);
847 int snd_pcm_hw_params_test_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val);
848 int snd_pcm_hw_params_set_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t val);
849 int INTERNAL(snd_pcm_hw_params_set_format_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format);
850 int INTERNAL(snd_pcm_hw_params_set_format_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_t *format);
851 int snd_pcm_hw_params_set_format_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask);
852 void snd_pcm_hw_params_get_format_mask(snd_pcm_hw_params_t *params, snd_pcm_format_mask_t *mask);
853
854 int INTERNAL(snd_pcm_hw_params_get_subformat)(const snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat);
855 int snd_pcm_hw_params_test_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat);
856 int snd_pcm_hw_params_set_subformat(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t subformat);
857 int INTERNAL(snd_pcm_hw_params_set_subformat_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat);
858 int INTERNAL(snd_pcm_hw_params_set_subformat_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_t *subformat);
859 int snd_pcm_hw_params_set_subformat_mask(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask);
860 void snd_pcm_hw_params_get_subformat_mask(snd_pcm_hw_params_t *params, snd_pcm_subformat_mask_t *mask);
861
862 int INTERNAL(snd_pcm_hw_params_get_channels)(const snd_pcm_hw_params_t *params, unsigned int *val);
863 int INTERNAL(snd_pcm_hw_params_get_channels_min)(const snd_pcm_hw_params_t *params, unsigned int *val);
864 int INTERNAL(snd_pcm_hw_params_get_channels_max)(const snd_pcm_hw_params_t *params, unsigned int *val);
865 int snd_pcm_hw_params_test_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
866 int snd_pcm_hw_params_set_channels(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val);
867 int snd_pcm_hw_params_set_channels_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
868 int snd_pcm_hw_params_set_channels_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
869 int snd_pcm_hw_params_set_channels_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, unsigned int *max);
870 int INTERNAL(snd_pcm_hw_params_set_channels_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
871 int INTERNAL(snd_pcm_hw_params_set_channels_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
872 int INTERNAL(snd_pcm_hw_params_set_channels_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val);
873
874 int INTERNAL(snd_pcm_hw_params_get_rate)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
875 int INTERNAL(snd_pcm_hw_params_get_rate_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
876 int INTERNAL(snd_pcm_hw_params_get_rate_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
877 int snd_pcm_hw_params_test_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
878 int snd_pcm_hw_params_set_rate(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
879 int snd_pcm_hw_params_set_rate_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
880 int snd_pcm_hw_params_set_rate_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
881 int snd_pcm_hw_params_set_rate_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
882 int INTERNAL(snd_pcm_hw_params_set_rate_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
883 int INTERNAL(snd_pcm_hw_params_set_rate_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
884 int INTERNAL(snd_pcm_hw_params_set_rate_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
885
886 int INTERNAL(snd_pcm_hw_params_get_period_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
887 int INTERNAL(snd_pcm_hw_params_get_period_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
888 int INTERNAL(snd_pcm_hw_params_get_period_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
889 int snd_pcm_hw_params_test_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
890 int snd_pcm_hw_params_set_period_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
891 int snd_pcm_hw_params_set_period_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
892 int snd_pcm_hw_params_set_period_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
893 int snd_pcm_hw_params_set_period_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
894 int INTERNAL(snd_pcm_hw_params_set_period_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
895 int INTERNAL(snd_pcm_hw_params_set_period_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
896 int INTERNAL(snd_pcm_hw_params_set_period_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
897
898 int INTERNAL(snd_pcm_hw_params_get_period_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir);
899 int INTERNAL(snd_pcm_hw_params_get_period_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir);
900 int INTERNAL(snd_pcm_hw_params_get_period_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *frames, int *dir);
901 int snd_pcm_hw_params_test_period_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int dir);
902 int snd_pcm_hw_params_set_period_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val, int dir);
903 int snd_pcm_hw_params_set_period_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
904 int snd_pcm_hw_params_set_period_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
905 int snd_pcm_hw_params_set_period_size_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *min, int *mindir, snd_pcm_uframes_t *max, int *maxdir);
906 int INTERNAL(snd_pcm_hw_params_set_period_size_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
907 int INTERNAL(snd_pcm_hw_params_set_period_size_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
908 int INTERNAL(snd_pcm_hw_params_set_period_size_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val, int *dir);
909 int snd_pcm_hw_params_set_period_size_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
910
911 int INTERNAL(snd_pcm_hw_params_get_periods)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
912 int INTERNAL(snd_pcm_hw_params_get_periods_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
913 int INTERNAL(snd_pcm_hw_params_get_periods_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
914 int snd_pcm_hw_params_test_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
915 int snd_pcm_hw_params_set_periods(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
916 int snd_pcm_hw_params_set_periods_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
917 int snd_pcm_hw_params_set_periods_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
918 int snd_pcm_hw_params_set_periods_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
919 int INTERNAL(snd_pcm_hw_params_set_periods_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
920 int INTERNAL(snd_pcm_hw_params_set_periods_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
921 int INTERNAL(snd_pcm_hw_params_set_periods_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
922 int snd_pcm_hw_params_set_periods_integer(snd_pcm_t *pcm, snd_pcm_hw_params_t *params);
923
924 int INTERNAL(snd_pcm_hw_params_get_buffer_time)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
925 int INTERNAL(snd_pcm_hw_params_get_buffer_time_min)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
926 int INTERNAL(snd_pcm_hw_params_get_buffer_time_max)(const snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
927 int snd_pcm_hw_params_test_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
928 int snd_pcm_hw_params_set_buffer_time(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int val, int dir);
929 int snd_pcm_hw_params_set_buffer_time_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
930 int snd_pcm_hw_params_set_buffer_time_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
931 int snd_pcm_hw_params_set_buffer_time_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *min, int *mindir, unsigned int *max, int *maxdir);
932 int INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
933 int INTERNAL(snd_pcm_hw_params_set_buffer_time_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
934 int INTERNAL(snd_pcm_hw_params_set_buffer_time_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, unsigned int *val, int *dir);
935
936 int INTERNAL(snd_pcm_hw_params_get_buffer_size)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
937 int INTERNAL(snd_pcm_hw_params_get_buffer_size_min)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
938 int INTERNAL(snd_pcm_hw_params_get_buffer_size_max)(const snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
939 int snd_pcm_hw_params_test_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val);
940 int snd_pcm_hw_params_set_buffer_size(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t val);
941 int snd_pcm_hw_params_set_buffer_size_min(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
942 int snd_pcm_hw_params_set_buffer_size_max(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
943 int snd_pcm_hw_params_set_buffer_size_minmax(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *min, snd_pcm_uframes_t *max);
944 int INTERNAL(snd_pcm_hw_params_set_buffer_size_near)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
945 int INTERNAL(snd_pcm_hw_params_set_buffer_size_first)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
946 int INTERNAL(snd_pcm_hw_params_set_buffer_size_last)(snd_pcm_t *pcm, snd_pcm_hw_params_t *params, snd_pcm_uframes_t *val);
947
948 int snd_pcm_sw_params_set_tstamp_mode(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_t val);
949 int INTERNAL(snd_pcm_sw_params_get_tstamp_mode)(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_t *val);
950 int snd_pcm_sw_params_set_tstamp_type(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t val);
951 int snd_pcm_sw_params_get_tstamp_type(const snd_pcm_sw_params_t *params, snd_pcm_tstamp_type_t *val);
952 int snd_pcm_sw_params_set_avail_min(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
953 int INTERNAL(snd_pcm_sw_params_get_avail_min)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
954 int snd_pcm_sw_params_set_start_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
955 int INTERNAL(snd_pcm_sw_params_get_start_threshold)(const snd_pcm_sw_params_t *paramsm, snd_pcm_uframes_t *val);
956 int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
957 int INTERNAL(snd_pcm_sw_params_get_stop_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
958 int snd_pcm_sw_params_set_silence_threshold(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
959 int INTERNAL(snd_pcm_sw_params_get_silence_threshold)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
960 int snd_pcm_sw_params_set_silence_size(snd_pcm_t *pcm, snd_pcm_sw_params_t *params, snd_pcm_uframes_t val);
961 int INTERNAL(snd_pcm_sw_params_get_silence_size)(const snd_pcm_sw_params_t *params, snd_pcm_uframes_t *val);
962 #endif /* INTERNAL */
963
964 const char *snd_pcm_hw_param_name(snd_pcm_hw_param_t param);
965 void snd_pcm_hw_param_dump(const snd_pcm_hw_params_t *params,
966 snd_pcm_hw_param_t var, snd_output_t *out);
967 #if 0
968 int snd_pcm_hw_strategy_simple_near(snd_pcm_hw_strategy_t *strategy, int order,
969 snd_pcm_hw_param_t var,
970 unsigned int best,
971 unsigned int mul);
972 int snd_pcm_hw_strategy_simple_choices(snd_pcm_hw_strategy_t *strategy, int order,
973 snd_pcm_hw_param_t var,
974 unsigned int count,
975 snd_pcm_hw_strategy_simple_choices_list_t *choices);
976 #endif
977
978 #define SCONF_MANDATORY 1
979 #define SCONF_UNCHANGED 2
980
981 int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
982 snd_config_t **pcm_conf, unsigned int count, ...);
983
984 #define SND_PCM_APPEND (1<<8)
985
986 int snd_pcm_open_named_slave(snd_pcm_t **pcmp, const char *name,
987 snd_config_t *root,
988 snd_config_t *conf, snd_pcm_stream_t stream,
989 int mode, snd_config_t *parent_conf);
990 static inline int
snd_pcm_open_slave(snd_pcm_t ** pcmp,snd_config_t * root,snd_config_t * conf,snd_pcm_stream_t stream,int mode,snd_config_t * parent_conf)991 snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *root,
992 snd_config_t *conf, snd_pcm_stream_t stream,
993 int mode, snd_config_t *parent_conf)
994 {
995 return snd_pcm_open_named_slave(pcmp, NULL, root, conf, stream,
996 mode, parent_conf);
997 }
998
999 #define snd_pcm_conf_generic_id(id) _snd_conf_generic_id(id)
1000
1001 int snd_pcm_hw_open_fd(snd_pcm_t **pcmp, const char *name, int fd,
1002 int sync_ptr_ioctl);
1003 int __snd_pcm_mmap_emul_open(snd_pcm_t **pcmp, const char *name,
1004 snd_pcm_t *slave, int close_slave);
1005
1006 int snd_pcm_wait_nocheck(snd_pcm_t *pcm, int timeout);
1007
1008 const snd_config_t *snd_pcm_rate_get_default_converter(snd_config_t *root);
1009
1010 #define SND_PCM_HW_PARBIT_ACCESS (1U << SND_PCM_HW_PARAM_ACCESS)
1011 #define SND_PCM_HW_PARBIT_FORMAT (1U << SND_PCM_HW_PARAM_FORMAT)
1012 #define SND_PCM_HW_PARBIT_SUBFORMAT (1U << SND_PCM_HW_PARAM_SUBFORMAT)
1013 #define SND_PCM_HW_PARBIT_CHANNELS (1U << SND_PCM_HW_PARAM_CHANNELS)
1014 #define SND_PCM_HW_PARBIT_RATE (1U << SND_PCM_HW_PARAM_RATE)
1015 #define SND_PCM_HW_PARBIT_PERIOD_TIME (1U << SND_PCM_HW_PARAM_PERIOD_TIME)
1016 #define SND_PCM_HW_PARBIT_PERIOD_SIZE (1U << SND_PCM_HW_PARAM_PERIOD_SIZE)
1017 #define SND_PCM_HW_PARBIT_PERIODS (1U << SND_PCM_HW_PARAM_PERIODS)
1018 #define SND_PCM_HW_PARBIT_BUFFER_TIME (1U << SND_PCM_HW_PARAM_BUFFER_TIME)
1019 #define SND_PCM_HW_PARBIT_BUFFER_SIZE (1U << SND_PCM_HW_PARAM_BUFFER_SIZE)
1020 #define SND_PCM_HW_PARBIT_SAMPLE_BITS (1U << SND_PCM_HW_PARAM_SAMPLE_BITS)
1021 #define SND_PCM_HW_PARBIT_FRAME_BITS (1U << SND_PCM_HW_PARAM_FRAME_BITS)
1022 #define SND_PCM_HW_PARBIT_PERIOD_BYTES (1U << SND_PCM_HW_PARAM_PERIOD_BYTES)
1023 #define SND_PCM_HW_PARBIT_BUFFER_BYTES (1U << SND_PCM_HW_PARAM_BUFFER_BYTES)
1024 #define SND_PCM_HW_PARBIT_TICK_TIME (1U << SND_PCM_HW_PARAM_TICK_TIME)
1025
1026
1027 #define SND_PCM_ACCBIT_MMAP { ((1U << SND_PCM_ACCESS_MMAP_INTERLEAVED) | \
1028 (1U << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) | \
1029 (1U << SND_PCM_ACCESS_MMAP_COMPLEX)) }
1030 #define SND_PCM_ACCBIT_MMAPI { (1U << SND_PCM_ACCESS_MMAP_INTERLEAVED) }
1031 #define SND_PCM_ACCBIT_MMAPN { (1U << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) }
1032 #define SND_PCM_ACCBIT_MMAPC { (1U << SND_PCM_ACCESS_MMAP_COMPLEX) }
1033
1034 #define SND_PCM_ACCBIT_SHM { ((1U << SND_PCM_ACCESS_MMAP_INTERLEAVED) | \
1035 (1U << SND_PCM_ACCESS_RW_INTERLEAVED) | \
1036 (1U << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) | \
1037 (1U << SND_PCM_ACCESS_RW_NONINTERLEAVED)) }
1038 #define SND_PCM_ACCBIT_SHMI { ((1U << SND_PCM_ACCESS_MMAP_INTERLEAVED) | \
1039 (1U << SND_PCM_ACCESS_RW_INTERLEAVED)) }
1040 #define SND_PCM_ACCBIT_SHMN { ((1U << SND_PCM_ACCESS_MMAP_NONINTERLEAVED) | \
1041 (1U << SND_PCM_ACCESS_RW_NONINTERLEAVED)) }
1042
1043 #define SND_PCM_FMTBIT_LINEAR \
1044 { ((1U << SND_PCM_FORMAT_S8) | \
1045 (1U << SND_PCM_FORMAT_U8) | \
1046 (1U << SND_PCM_FORMAT_S16_LE) | \
1047 (1U << SND_PCM_FORMAT_S16_BE) | \
1048 (1U << SND_PCM_FORMAT_U16_LE) | \
1049 (1U << SND_PCM_FORMAT_U16_BE) | \
1050 (1U << SND_PCM_FORMAT_S20_LE) | \
1051 (1U << SND_PCM_FORMAT_S20_BE) | \
1052 (1U << SND_PCM_FORMAT_U20_LE) | \
1053 (1U << SND_PCM_FORMAT_U20_BE) | \
1054 (1U << SND_PCM_FORMAT_S24_LE) | \
1055 (1U << SND_PCM_FORMAT_S24_BE) | \
1056 (1U << SND_PCM_FORMAT_U24_LE) | \
1057 (1U << SND_PCM_FORMAT_U24_BE) | \
1058 (1U << SND_PCM_FORMAT_S32_LE) | \
1059 (1U << SND_PCM_FORMAT_S32_BE) | \
1060 (1U << SND_PCM_FORMAT_U32_LE) | \
1061 (1U << SND_PCM_FORMAT_U32_BE)), \
1062 ((1U << (SND_PCM_FORMAT_S24_3LE - 32)) | \
1063 (1U << (SND_PCM_FORMAT_U24_3LE - 32)) | \
1064 (1U << (SND_PCM_FORMAT_S24_3BE - 32)) | \
1065 (1U << (SND_PCM_FORMAT_U24_3BE - 32)) | \
1066 (1U << (SND_PCM_FORMAT_S20_3LE - 32)) | \
1067 (1U << (SND_PCM_FORMAT_U20_3LE - 32)) | \
1068 (1U << (SND_PCM_FORMAT_S20_3BE - 32)) | \
1069 (1U << (SND_PCM_FORMAT_U20_3BE - 32)) | \
1070 (1U << (SND_PCM_FORMAT_S18_3LE - 32)) | \
1071 (1U << (SND_PCM_FORMAT_U18_3LE - 32)) | \
1072 (1U << (SND_PCM_FORMAT_S18_3BE - 32)) | \
1073 (1U << (SND_PCM_FORMAT_U18_3BE - 32))) }
1074
1075
1076 #define SND_PCM_FMTBIT_FLOAT \
1077 { ((1U << SND_PCM_FORMAT_FLOAT_LE) | \
1078 (1U << SND_PCM_FORMAT_FLOAT_BE) | \
1079 (1U << SND_PCM_FORMAT_FLOAT64_LE) | \
1080 (1U << SND_PCM_FORMAT_FLOAT64_BE)) }
1081
1082
1083 typedef union snd_tmp_float {
1084 float f;
1085 int32_t i;
1086 } snd_tmp_float_t;
1087
1088 typedef union snd_tmp_double {
1089 double d;
1090 int64_t l;
1091 } snd_tmp_double_t;
1092
1093 /* get the current timestamp */
1094 #ifdef HAVE_CLOCK_GETTIME
gettimestamp(snd_htimestamp_t * tstamp,snd_pcm_tstamp_type_t tstamp_type)1095 static inline void gettimestamp(snd_htimestamp_t *tstamp,
1096 snd_pcm_tstamp_type_t tstamp_type)
1097 {
1098 clockid_t id;
1099
1100 switch (tstamp_type) {
1101 #ifdef CLOCK_MONOTONIC_RAW
1102 case SND_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
1103 id = CLOCK_MONOTONIC_RAW;
1104 break;
1105 #endif
1106 #ifdef CLOCK_MONOTONIC
1107 case SND_PCM_TSTAMP_TYPE_MONOTONIC:
1108 id = CLOCK_MONOTONIC;
1109 break;
1110 #endif
1111 default:
1112 id = CLOCK_REALTIME;
1113 break;
1114 }
1115 clock_gettime(id, tstamp);
1116 }
1117 #else /* HAVE_CLOCK_GETTIME */
gettimestamp(snd_htimestamp_t * tstamp,snd_pcm_tstamp_type_t tstamp_type)1118 static inline void gettimestamp(snd_htimestamp_t *tstamp,
1119 snd_pcm_tstamp_type_t tstamp_type)
1120 {
1121 struct timeval tv;
1122
1123 gettimeofday(&tv, 0);
1124 tstamp->tv_sec = tv.tv_sec;
1125 tstamp->tv_nsec = tv.tv_usec * 1000L;
1126 }
1127 #endif /* HAVE_CLOCK_GETTIME */
1128
1129 snd_pcm_chmap_query_t **
1130 _snd_pcm_make_single_query_chmaps(const snd_pcm_chmap_t *src);
1131 snd_pcm_chmap_t *_snd_pcm_copy_chmap(const snd_pcm_chmap_t *src);
1132 snd_pcm_chmap_query_t **
1133 _snd_pcm_copy_chmap_query(snd_pcm_chmap_query_t * const *src);
1134 snd_pcm_chmap_query_t **
1135 _snd_pcm_parse_config_chmaps(snd_config_t *conf);
1136 snd_pcm_chmap_t *
1137 _snd_pcm_choose_fixed_chmap(snd_pcm_t *pcm, snd_pcm_chmap_query_t * const *maps);
1138
1139 /* return true if the PCM stream may wait to get avail_min space */
snd_pcm_may_wait_for_avail_min(snd_pcm_t * pcm,snd_pcm_uframes_t avail)1140 static inline int snd_pcm_may_wait_for_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail)
1141 {
1142 if (avail >= pcm->avail_min)
1143 return 0;
1144 if (pcm->fast_ops->may_wait_for_avail_min)
1145 return pcm->fast_ops->may_wait_for_avail_min(pcm, avail);
1146 return 1;
1147 }
1148
1149 /* hack to access to internal period_event in snd_pcm_sw_parmams */
sw_get_period_event(const snd_pcm_sw_params_t * params)1150 static inline int sw_get_period_event(const snd_pcm_sw_params_t *params)
1151 {
1152 return params->reserved[sizeof(params->reserved) / sizeof(params->reserved[0])- 1];
1153 }
1154
sw_set_period_event(snd_pcm_sw_params_t * params,int val)1155 static inline void sw_set_period_event(snd_pcm_sw_params_t *params, int val)
1156 {
1157 params->reserved[sizeof(params->reserved) / sizeof(params->reserved[0]) - 1] = val;
1158 }
1159
1160 #define PCMINABORT(pcm) (((pcm)->mode & SND_PCM_ABORT) != 0)
1161
pcm_frame_diff(snd_pcm_uframes_t ptr1,snd_pcm_uframes_t ptr2,snd_pcm_uframes_t boundary)1162 static inline snd_pcm_sframes_t pcm_frame_diff(snd_pcm_uframes_t ptr1,
1163 snd_pcm_uframes_t ptr2,
1164 snd_pcm_uframes_t boundary)
1165 {
1166 if (ptr1 < ptr2)
1167 return ptr1 + (boundary - ptr2);
1168 else
1169 return ptr1 - ptr2;
1170 }
1171
pcm_frame_diff2(snd_pcm_uframes_t ptr1,snd_pcm_uframes_t ptr2,snd_pcm_uframes_t boundary)1172 static inline snd_pcm_sframes_t pcm_frame_diff2(snd_pcm_uframes_t ptr1,
1173 snd_pcm_uframes_t ptr2,
1174 snd_pcm_uframes_t boundary)
1175 {
1176 snd_pcm_sframes_t r = ptr1 - ptr2;
1177 if (r >= (snd_pcm_sframes_t)boundary / 2)
1178 return boundary - r;
1179 return r;
1180 }
1181
1182 #ifdef THREAD_SAFE_API
1183 /*
1184 * __snd_pcm_lock() and __snd_pcm_unlock() are used to lock/unlock the plugin
1185 * forcibly even if it's declared as thread-safe. It's needed only for some
1186 * codes that are thread-unsafe per design (e.g. snd_pcm_nonblock()).
1187 *
1188 * OTOH, snd_pcm_lock() and snd_pcm_unlock() are used to lock/unlock the plugin
1189 * in normal situations. They do lock/unlock only when the plugin is
1190 * thread-unsafe.
1191 *
1192 * Both __snd_pcm_lock() and snd_pcm_lock() (and their unlocks) wouldn't do
1193 * any action when the whole locking is disabled via $LIBASOUND_THREAD_SAFE=0.
1194 */
__snd_pcm_lock(snd_pcm_t * pcm)1195 static inline void __snd_pcm_lock(snd_pcm_t *pcm)
1196 {
1197 if (pcm->lock_enabled)
1198 pthread_mutex_lock(&pcm->lock);
1199 }
__snd_pcm_unlock(snd_pcm_t * pcm)1200 static inline void __snd_pcm_unlock(snd_pcm_t *pcm)
1201 {
1202 if (pcm->lock_enabled)
1203 pthread_mutex_unlock(&pcm->lock);
1204 }
snd_pcm_lock(snd_pcm_t * pcm)1205 static inline void snd_pcm_lock(snd_pcm_t *pcm)
1206 {
1207 if (pcm->lock_enabled && pcm->need_lock)
1208 pthread_mutex_lock(&pcm->lock);
1209 }
snd_pcm_unlock(snd_pcm_t * pcm)1210 static inline void snd_pcm_unlock(snd_pcm_t *pcm)
1211 {
1212 if (pcm->lock_enabled && pcm->need_lock)
1213 pthread_mutex_unlock(&pcm->lock);
1214 }
1215 #else /* THREAD_SAFE_API */
1216 #define __snd_pcm_lock(pcm) do {} while (0)
1217 #define __snd_pcm_unlock(pcm) do {} while (0)
1218 #define snd_pcm_lock(pcm) do {} while (0)
1219 #define snd_pcm_unlock(pcm) do {} while (0)
1220 #endif /* THREAD_SAFE_API */
1221