File: pcm_generic.c

package info (click to toggle)
alsa-lib 1.1.3-5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,656 kB
  • sloc: ansic: 84,132; sh: 11,192; makefile: 711
file content (349 lines) | stat: -rw-r--r-- 9,847 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/**
 * \file pcm/pcm_generic.c
 * \ingroup PCM
 * \brief PCM Interface
 * \author Jaroslav Kysela <perex@perex.cz>
 * \date 2004
 */
/*
 *  PCM - Common generic plugin code
 *  Copyright (c) 2004 by Jaroslav Kysela <perex@perex.cz> 
 *
 *
 *   This library is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as
 *   published by the Free Software Foundation; either version 2.1 of
 *   the License, or (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU Lesser General Public License for more details.
 *
 *   You should have received a copy of the GNU Lesser General Public
 *   License along with this library; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

#include <sys/ioctl.h>
#include <limits.h>
#include "pcm_local.h"
#include "pcm_generic.h"

#ifndef DOC_HIDDEN

int snd_pcm_generic_close(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	int err = 0;
	if (generic->close_slave)
		err = snd_pcm_close(generic->slave);
	free(generic);
	return err;
}

int snd_pcm_generic_nonblock(snd_pcm_t *pcm, int nonblock)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_nonblock(generic->slave, nonblock);
}

int snd_pcm_generic_async(snd_pcm_t *pcm, int sig, pid_t pid)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_async(generic->slave, sig, pid);
}

int snd_pcm_generic_poll_descriptors_count(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_poll_descriptors_count(generic->slave);
}

int snd_pcm_generic_poll_descriptors(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int space)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_poll_descriptors(generic->slave, pfds, space);
}

int snd_pcm_generic_poll_revents(snd_pcm_t *pcm, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_poll_descriptors_revents(generic->slave, pfds, nfds, revents);
}

int snd_pcm_generic_info(snd_pcm_t *pcm, snd_pcm_info_t * info)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_info(generic->slave, info);
}

int snd_pcm_generic_hw_free(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_hw_free(generic->slave);
}

int snd_pcm_generic_sw_params(snd_pcm_t *pcm, snd_pcm_sw_params_t *params)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_sw_params(generic->slave, params);
}

int snd_pcm_generic_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_hw_refine(generic->slave, params);
}

int snd_pcm_generic_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return _snd_pcm_hw_params_internal(generic->slave, params);
}

int snd_pcm_generic_prepare(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_prepare(generic->slave);
}

int snd_pcm_generic_channel_info(snd_pcm_t *pcm, snd_pcm_channel_info_t *info)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	if (pcm->mmap_shadow) {
		/* No own buffer is required - the plugin won't change
		 * the data on the buffer, or do safely on-the-place
		 * conversion
		 */
		return snd_pcm_channel_info(generic->slave, info);
	} else {
		/* Allocate own buffer */
		return snd_pcm_channel_info_shm(pcm, info, -1);
	}
}

int snd_pcm_generic_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
{ 
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_status(generic->slave, status);
}

snd_pcm_state_t snd_pcm_generic_state(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_state(generic->slave);
}

int snd_pcm_generic_hwsync(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_hwsync(generic->slave);
}

int snd_pcm_generic_reset(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_reset(generic->slave);
}

int snd_pcm_generic_start(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_start(generic->slave);
}

int snd_pcm_generic_drop(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_drop(generic->slave);
}

int snd_pcm_generic_drain(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_drain(generic->slave);
}

int snd_pcm_generic_pause(snd_pcm_t *pcm, int enable)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_pause(generic->slave, enable);
}

int snd_pcm_generic_resume(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_resume(generic->slave);
}

int snd_pcm_generic_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_delay(generic->slave, delayp);
}

snd_pcm_sframes_t snd_pcm_generic_forwardable(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_forwardable(generic->slave);
}

snd_pcm_sframes_t snd_pcm_generic_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return INTERNAL(snd_pcm_forward)(generic->slave, frames);
}

snd_pcm_sframes_t snd_pcm_generic_rewindable(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_rewindable(generic->slave);
}

snd_pcm_sframes_t snd_pcm_generic_rewind(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_rewind(generic->slave, frames);
}

int snd_pcm_generic_link(snd_pcm_t *pcm1, snd_pcm_t *pcm2)
{
	snd_pcm_generic_t *generic = pcm1->private_data;
	if (generic->slave->fast_ops->link)
		return generic->slave->fast_ops->link(generic->slave->fast_op_arg, pcm2);
	return -ENOSYS;
}

int snd_pcm_generic_link_slaves(snd_pcm_t *pcm, snd_pcm_t *master)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	if (generic->slave->fast_ops->link_slaves)
		return generic->slave->fast_ops->link_slaves(generic->slave->fast_op_arg, master);
	return -ENOSYS;
}

int snd_pcm_generic_unlink(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	if (generic->slave->fast_ops->unlink)
		return generic->slave->fast_ops->unlink(generic->slave->fast_op_arg);
	return -ENOSYS;
}

snd_pcm_sframes_t snd_pcm_generic_writei(snd_pcm_t *pcm, const void *buffer, snd_pcm_uframes_t size)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return _snd_pcm_writei(generic->slave, buffer, size);
}

snd_pcm_sframes_t snd_pcm_generic_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return _snd_pcm_writen(generic->slave, bufs, size);
}

snd_pcm_sframes_t snd_pcm_generic_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return _snd_pcm_readi(generic->slave, buffer, size);
}

snd_pcm_sframes_t snd_pcm_generic_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return _snd_pcm_readn(generic->slave, bufs, size);
}

snd_pcm_sframes_t snd_pcm_generic_mmap_commit(snd_pcm_t *pcm, 
					      snd_pcm_uframes_t offset,
					      snd_pcm_uframes_t size)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_mmap_commit(generic->slave, offset, size);
}

snd_pcm_sframes_t snd_pcm_generic_avail_update(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_avail_update(generic->slave);
}

int snd_pcm_generic_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
			       snd_htimestamp_t *tstamp)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_htimestamp(generic->slave, avail, tstamp);
}

/* stand-alone version - similar like snd_pcm_hw_htimestamp but
 * taking the tstamp via gettimestamp().
 */
int snd_pcm_generic_real_htimestamp(snd_pcm_t *pcm, snd_pcm_uframes_t *avail,
				    snd_htimestamp_t *tstamp)
{
	snd_pcm_sframes_t avail1;
	int ok = 0;

	while (1) {
		avail1 = __snd_pcm_avail_update(pcm);
		if (avail1 < 0)
			return avail1;
		if (ok && (snd_pcm_uframes_t)avail1 == *avail)
			break;
		*avail = avail1;
		gettimestamp(tstamp, pcm->tstamp_type);
		ok = 1;
	}
	return 0;
}

int snd_pcm_generic_mmap(snd_pcm_t *pcm)
{
	if (pcm->mmap_shadow) {
		/* Copy the slave mmapped buffer data */
		snd_pcm_generic_t *generic = pcm->private_data;
		pcm->mmap_channels = generic->slave->mmap_channels;
		pcm->running_areas = generic->slave->running_areas;
		pcm->stopped_areas = generic->slave->stopped_areas;
	}
	return 0;
}

int snd_pcm_generic_munmap(snd_pcm_t *pcm)
{
	if (pcm->mmap_shadow) {
		/* Clean up */
		pcm->mmap_channels = NULL;
		pcm->running_areas = NULL;
		pcm->stopped_areas = NULL;
	}
	return 0;
}

snd_pcm_chmap_query_t **snd_pcm_generic_query_chmaps(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_query_chmaps(generic->slave);
}

snd_pcm_chmap_t *snd_pcm_generic_get_chmap(snd_pcm_t *pcm)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_get_chmap(generic->slave);
}

int snd_pcm_generic_set_chmap(snd_pcm_t *pcm, const snd_pcm_chmap_t *map)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_set_chmap(generic->slave, map);
}

int snd_pcm_generic_may_wait_for_avail_min(snd_pcm_t *pcm, snd_pcm_uframes_t avail ATTRIBUTE_UNUSED)
{
	snd_pcm_generic_t *generic = pcm->private_data;
	return snd_pcm_may_wait_for_avail_min(generic->slave, snd_pcm_mmap_avail(generic->slave));
}

#endif /* DOC_HIDDEN */