source: mainline/uspace/lib/drv/generic/remote_audio_pcm.c@ ad1aedc

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ad1aedc was ad1aedc, checked in by Jan Vesely <jano.vesely@…>, 13 years ago

libdrv: Document client side audio pcm API.

  • Property mode set to 100644
File size: 22.6 KB
Line 
1/*
2 * Copyright (c) 2012 Jan Vesely
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28/** @addtogroup libdrv
29 * @{
30 */
31/** @file
32 */
33
34#include <async.h>
35#include <devman.h>
36#include <ddf/log.h>
37#include <errno.h>
38#include <str.h>
39#include <as.h>
40#include <sys/mman.h>
41
42#include "audio_pcm_iface.h"
43#include "ddf/driver.h"
44
45typedef enum {
46 IPC_M_AUDIO_PCM_GET_INFO_STR,
47 IPC_M_AUDIO_PCM_QUERY_CAPS,
48 IPC_M_AUDIO_PCM_TEST_FORMAT,
49 IPC_M_AUDIO_PCM_GET_BUFFER,
50 IPC_M_AUDIO_PCM_RELEASE_BUFFER,
51 IPC_M_AUDIO_PCM_GET_BUFFER_POS,
52 IPC_M_AUDIO_PCM_START_PLAYBACK,
53 IPC_M_AUDIO_PCM_STOP_PLAYBACK,
54 IPC_M_AUDIO_PCM_START_CAPTURE,
55 IPC_M_AUDIO_PCM_STOP_CAPTURE,
56} audio_pcm_iface_funcs_t;
57
58/*
59 * CLIENT SIDE
60 */
61
62/**
63 * Open audio session with device identified by location service string.
64 *
65 * @param name Location service string.
66 * @return Pointer to a new audio device session, NULL on failure.
67 */
68audio_pcm_sess_t *audio_pcm_open(const char *name)
69{
70 devman_handle_t device_handle = 0;
71 const int ret = devman_fun_get_handle(name, &device_handle, 0);
72 if (ret != EOK)
73 return NULL;
74 return devman_device_connect(EXCHANGE_SERIALIZE, device_handle,
75 IPC_FLAG_BLOCKING);
76}
77
78/**
79 * Open audio session with device identified by location service id
80 *
81 * @param name Location service id.
82 * @return Pointer to a new audio device session, NULL on failure.
83 */
84audio_pcm_sess_t *audio_pcm_open_service(service_id_t id)
85{
86 return loc_service_connect(EXCHANGE_SERIALIZE, id, IPC_FLAG_BLOCKING);
87}
88
89/**
90 * Close open audio device session.
91 *
92 * @param name Open audio device session.
93 *
94 * @note Calling this function on already closed or invalid session results
95 * in undefined behavior.
96 */
97void audio_pcm_close(audio_pcm_sess_t *sess)
98{
99 if (sess)
100 async_hangup(sess);
101}
102
103/**
104 * Get a short description string.
105 *
106 * @param sess Audio device session.
107 * @param name Place to store newly allocated string.
108 *
109 * @return Error code.
110 *
111 * @note Caller is responsible for freeing newly allocated memory.
112 */
113int audio_pcm_get_info_str(audio_pcm_sess_t *sess, const char **name)
114{
115 async_exch_t *exch = async_exchange_begin(sess);
116 sysarg_t name_size;
117 const int ret = async_req_1_1(exch,
118 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
119 IPC_M_AUDIO_PCM_GET_INFO_STR, &name_size);
120 if (ret == EOK && name) {
121 char *name_place = calloc(1, name_size);
122 if (!name_place) {
123 /* Make the other side fail
124 * as it waits for read request */
125 async_data_read_start(exch, (void*)-1, 0);
126 async_exchange_end(exch);
127 return ENOMEM;
128 }
129 const int ret =
130 async_data_read_start(exch, name_place, name_size);
131 if (ret != EOK) {
132 free(name_place);
133 async_exchange_end(exch);
134 return ret;
135 }
136 *name = name_place;
137 }
138 async_exchange_end(exch);
139 return ret;
140}
141
142
143/**
144 * Query value of specified capability.
145 *
146 * @param sess Audio device session.
147 * @param cap Audio device capability.
148 * @param val Place to store queried value.
149 *
150 * @return Error code.
151 */
152int audio_pcm_query_cap(audio_pcm_sess_t *sess, audio_cap_t cap, unsigned *val)
153{
154 if (!val)
155 return EINVAL;
156 async_exch_t *exch = async_exchange_begin(sess);
157 sysarg_t value = 0;
158 const int ret = async_req_2_1(exch,
159 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_QUERY_CAPS,
160 cap, &value);
161 if (ret == EOK)
162 *val = value;
163 async_exchange_end(exch);
164 return ret;
165}
166
167/**
168 * Query current position in device buffer.
169 *
170 * @param sess Audio device session.
171 * @param pos Place to store the result.
172 *
173 * @return Error code.
174 *
175 * Works for both playback and capture.
176 */
177int audio_pcm_get_buffer_pos(audio_pcm_sess_t *sess, size_t *pos)
178{
179 if (!pos)
180 return EINVAL;
181 async_exch_t *exch = async_exchange_begin(sess);
182 sysarg_t value = 0;;
183 const int ret = async_req_1_1(exch,
184 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
185 IPC_M_AUDIO_PCM_GET_BUFFER_POS, &value);
186 if (ret == EOK)
187 *pos = value;
188 async_exchange_end(exch);
189 return ret;
190}
191
192/**
193 * Test format parameters for device support.
194 *
195 * @param sess Audio device session.
196 * @param channels Number of channels
197 * @param rate Sampling rate.
198 * @format Sample format.
199 *
200 * @return Error code.
201 *
202 * Works for both playback and capture. This function modifies provided
203 * parameters to the nearest values supported by the device.
204 */
205int audio_pcm_test_format(audio_pcm_sess_t *sess, unsigned *channels,
206 unsigned *rate, pcm_sample_format_t *format)
207{
208 async_exch_t *exch = async_exchange_begin(sess);
209 sysarg_t channels_arg = channels ? *channels : 0;
210 sysarg_t rate_arg = rate ? *rate : 0;
211 sysarg_t format_arg = format ? *format : 0;
212 const int ret = async_req_4_3(exch,
213 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
214 IPC_M_AUDIO_PCM_TEST_FORMAT, channels_arg, rate_arg, format_arg,
215 &channels_arg, &rate_arg, &format_arg);
216 async_exchange_end(exch);
217
218 /* All OK or something has changed. Verify that it was not one of the
219 * params we care about */
220 if ((ret == EOK || ret == ELIMIT)
221 && (!channels || *channels == channels_arg)
222 && (!rate || *rate == rate_arg)
223 && (!format || *format == format_arg))
224 return EOK;
225 if (channels)
226 *channels = channels_arg;
227 if (rate)
228 *rate = rate_arg;
229 if (format)
230 *format = format_arg;
231 return ret;
232}
233
234/**
235 * Get device accessible playback/capture buffer.
236 *
237 * @param sess Audio device session.
238 * @param buffer Place to store pointer to the buffer.
239 * @param size Place to store buffer size (bytes).
240 * @param event_rec Event callback function.
241 * @param arg Event callback custom parameter.
242 *
243 * @return Error code.
244 */
245int audio_pcm_get_buffer(audio_pcm_sess_t *sess, void **buffer, size_t *size,
246 async_client_conn_t event_rec, void* arg)
247{
248 if (!buffer || !size)
249 return EINVAL;
250
251 async_exch_t *exch = async_exchange_begin(sess);
252
253 sysarg_t buffer_size = *size;
254 const int ret = async_req_2_1(exch,
255 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_GET_BUFFER,
256 (sysarg_t)buffer_size, &buffer_size);
257 if (ret == EOK) {
258 void *dst = NULL;
259 int ret = async_share_in_start_0_0(exch, buffer_size, &dst);
260 if (ret != EOK) {
261 async_exchange_end(exch);
262 return ret;
263 }
264 ret = async_connect_to_me(exch, 0, 0, 0, event_rec, arg);
265 if (ret != EOK) {
266 async_exchange_end(exch);
267 return ret;
268 }
269
270 *buffer = dst;
271 *size = buffer_size;
272 }
273 async_exchange_end(exch);
274 return ret;
275}
276
277/**
278 * Release device accessible playback/capture buffer.
279 *
280 * @param sess Audio device session.
281 *
282 * @return Error code.
283 */
284int audio_pcm_release_buffer(audio_pcm_sess_t *sess)
285{
286 async_exch_t *exch = async_exchange_begin(sess);
287 const int ret = async_req_1_0(exch,
288 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
289 IPC_M_AUDIO_PCM_RELEASE_BUFFER);
290 async_exchange_end(exch);
291 return ret;
292}
293
294/**
295 * Start playback on buffer from position 0.
296 *
297 * @param sess Audio device session.
298 * @param frames Size of fragment (in frames).
299 * @param channels Number of channels.
300 * @param sample_rate Sampling rate (for one channel).
301 * @param format Sample format.
302 *
303 * @return Error code.
304 *
305 * Event will be generated after every fragment. Set fragment size to
306 * 0 to turn off event generation.
307 */
308int audio_pcm_start_playback(audio_pcm_sess_t *sess, unsigned frames,
309 unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
310{
311 if (channels > UINT16_MAX)
312 return EINVAL;
313 assert((format & UINT16_MAX) == format);
314 const sysarg_t packed = (channels << 16) | (format & UINT16_MAX);
315 async_exch_t *exch = async_exchange_begin(sess);
316 const int ret = async_req_4_0(exch,
317 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
318 IPC_M_AUDIO_PCM_START_PLAYBACK,
319 frames, sample_rate, packed);
320 async_exchange_end(exch);
321 return ret;
322}
323
324/**
325 * Stop current playback.
326 *
327 * @param sess Audio device session.
328 *
329 * @return Error code.
330 */
331int audio_pcm_stop_playback(audio_pcm_sess_t *sess)
332{
333 async_exch_t *exch = async_exchange_begin(sess);
334 const int ret = async_req_1_0(exch,
335 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
336 IPC_M_AUDIO_PCM_STOP_PLAYBACK);
337 async_exchange_end(exch);
338 return ret;
339}
340
341/**
342 * Start capture on buffer from position 0.
343 *
344 * @param sess Audio device session.
345 * @param frames Size of fragment (in frames).
346 * @param channels Number of channels.
347 * @param sample_rate Sampling rate (for one channel).
348 * @param format Sample format.
349 *
350 * @return Error code.
351 *
352 * Event will be generated after every fragment. Set fragment size to
353 * 0 to turn off event generation.
354 */
355int audio_pcm_start_capture(audio_pcm_sess_t *sess, unsigned frames,
356 unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
357{
358 if (channels > UINT16_MAX)
359 return EINVAL;
360 assert((format & UINT16_MAX) == format);
361 const sysarg_t packed = (channels << 16) | (format & UINT16_MAX);
362 async_exch_t *exch = async_exchange_begin(sess);
363 const int ret = async_req_4_0(exch,
364 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_START_CAPTURE,
365 frames, sample_rate, packed);
366 async_exchange_end(exch);
367 return ret;
368}
369
370/**
371 * Stop current playback.
372 *
373 * @param sess Audio device session.
374 *
375 * @return Error code.
376 */
377int audio_pcm_stop_capture(audio_pcm_sess_t *sess)
378{
379 async_exch_t *exch = async_exchange_begin(sess);
380 const int ret = async_req_1_0(exch,
381 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_STOP_CAPTURE);
382 async_exchange_end(exch);
383 return ret;
384}
385
386/*
387 * SERVER SIDE
388 */
389static void remote_audio_pcm_get_info_str(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
390static void remote_audio_pcm_query_caps(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
391static void remote_audio_pcm_get_buffer_pos(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
392static void remote_audio_pcm_test_format(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
393static void remote_audio_pcm_get_buffer(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
394static void remote_audio_pcm_release_buffer(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
395static void remote_audio_pcm_start_playback(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
396static void remote_audio_pcm_stop_playback(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
397static void remote_audio_pcm_start_capture(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
398static void remote_audio_pcm_stop_capture(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
399
400/** Remote audio pcm buffer interface operations. */
401static remote_iface_func_ptr_t remote_audio_pcm_iface_ops[] = {
402 [IPC_M_AUDIO_PCM_GET_INFO_STR] = remote_audio_pcm_get_info_str,
403 [IPC_M_AUDIO_PCM_QUERY_CAPS] = remote_audio_pcm_query_caps,
404 [IPC_M_AUDIO_PCM_GET_BUFFER_POS] = remote_audio_pcm_get_buffer_pos,
405 [IPC_M_AUDIO_PCM_TEST_FORMAT] = remote_audio_pcm_test_format,
406 [IPC_M_AUDIO_PCM_GET_BUFFER] = remote_audio_pcm_get_buffer,
407 [IPC_M_AUDIO_PCM_RELEASE_BUFFER] = remote_audio_pcm_release_buffer,
408 [IPC_M_AUDIO_PCM_START_PLAYBACK] = remote_audio_pcm_start_playback,
409 [IPC_M_AUDIO_PCM_STOP_PLAYBACK] = remote_audio_pcm_stop_playback,
410 [IPC_M_AUDIO_PCM_START_CAPTURE] = remote_audio_pcm_start_capture,
411 [IPC_M_AUDIO_PCM_STOP_CAPTURE] = remote_audio_pcm_stop_capture,
412};
413
414/** Remote audio mixer interface structure. */
415remote_iface_t remote_audio_pcm_iface = {
416 .method_count = sizeof(remote_audio_pcm_iface_ops) /
417 sizeof(remote_audio_pcm_iface_ops[0]),
418 .methods = remote_audio_pcm_iface_ops
419};
420
421void remote_audio_pcm_get_info_str(ddf_fun_t *fun, void *iface,
422 ipc_callid_t callid, ipc_call_t *call)
423{
424 const audio_pcm_iface_t *pcm_iface = iface;
425
426 if (!pcm_iface->get_info_str) {
427 async_answer_0(callid, ENOTSUP);
428 return;
429 }
430 const char *name = NULL;
431 const int ret = pcm_iface->get_info_str(fun, &name);
432 const size_t name_size = name ? str_size(name) + 1 : 0;
433 async_answer_1(callid, ret, name_size);
434 /* Send the string. */
435 if (ret == EOK && name_size > 0) {
436 size_t size;
437 ipc_callid_t name_id;
438 if (!async_data_read_receive(&name_id, &size)) {
439 async_answer_0(name_id, EPARTY);
440 return;
441 }
442 if (size != name_size) {
443 async_answer_0(name_id, ELIMIT);
444 return;
445 }
446 async_data_read_finalize(name_id, name, name_size);
447 }
448}
449
450void remote_audio_pcm_query_caps(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
451{
452 const audio_pcm_iface_t *pcm_iface = iface;
453 const audio_cap_t cap = DEV_IPC_GET_ARG1(*call);
454 if (pcm_iface->query_cap) {
455 const unsigned value = pcm_iface->query_cap(fun, cap);
456 async_answer_1(callid, EOK, value);
457 } else {
458 async_answer_0(callid, ENOTSUP);
459 }
460}
461void remote_audio_pcm_get_buffer_pos(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
462{
463 const audio_pcm_iface_t *pcm_iface = iface;
464 size_t pos = 0;
465 const int ret = pcm_iface->get_buffer_pos ?
466 pcm_iface->get_buffer_pos(fun, &pos) : ENOTSUP;
467 async_answer_1(callid, ret, pos);
468}
469
470void remote_audio_pcm_test_format(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
471{
472 const audio_pcm_iface_t *pcm_iface = iface;
473 unsigned channels = DEV_IPC_GET_ARG1(*call);
474 unsigned rate = DEV_IPC_GET_ARG2(*call);
475 pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call);
476 const int ret = pcm_iface->test_format ?
477 pcm_iface->test_format(fun, &channels, &rate, &format) : ENOTSUP;
478 async_answer_3(callid, ret, channels, rate, format);
479}
480
481void remote_audio_pcm_get_buffer(ddf_fun_t *fun, void *iface,
482 ipc_callid_t callid, ipc_call_t *call)
483{
484 const audio_pcm_iface_t *pcm_iface = iface;
485
486 if (!pcm_iface->get_buffer ||
487 !pcm_iface->release_buffer ||
488 !pcm_iface->set_event_session) {
489 async_answer_0(callid, ENOTSUP);
490 return;
491 }
492 void *buffer = NULL;
493 size_t size = DEV_IPC_GET_ARG1(*call);
494 int ret = pcm_iface->get_buffer(fun, &buffer, &size);
495 async_answer_1(callid, ret, size);
496 if (ret != EOK || size == 0)
497 return;
498
499 /* Share the buffer. */
500 size_t share_size = 0;
501 ipc_callid_t share_id = 0;
502
503 ddf_msg(LVL_DEBUG2, "Receiving share request.");
504 if (!async_share_in_receive(&share_id, &share_size)) {
505 ddf_msg(LVL_DEBUG, "Failed to share pcm buffer.");
506 pcm_iface->release_buffer(fun);
507 async_answer_0(share_id, EPARTY);
508 return;
509 }
510
511 ddf_msg(LVL_DEBUG2, "Checking requested share size.");
512 if (share_size != size) {
513 ddf_msg(LVL_DEBUG, "Incorrect pcm buffer size requested.");
514 pcm_iface->release_buffer(fun);
515 async_answer_0(share_id, ELIMIT);
516 return;
517 }
518
519 ddf_msg(LVL_DEBUG2, "Calling share finalize.");
520 ret = async_share_in_finalize(share_id, buffer, AS_AREA_WRITE
521 | AS_AREA_READ);
522 if (ret != EOK) {
523 ddf_msg(LVL_DEBUG, "Failed to share buffer.");
524 pcm_iface->release_buffer(fun);
525 return;
526 }
527
528 ddf_msg(LVL_DEBUG2, "Buffer shared with size %zu, creating callback.",
529 share_size);
530 {
531 ipc_call_t call;
532 ipc_callid_t callid = async_get_call(&call);
533 async_sess_t *sess =
534 async_callback_receive_start(EXCHANGE_ATOMIC, &call);
535 if (sess == NULL) {
536 ddf_msg(LVL_DEBUG, "Failed to create event callback");
537 pcm_iface->release_buffer(fun);
538 async_answer_0(callid, EAGAIN);
539 return;
540 }
541 ret = pcm_iface->set_event_session(fun, sess);
542 if (ret != EOK) {
543 ddf_msg(LVL_DEBUG, "Failed to set event callback.");
544 pcm_iface->release_buffer(fun);
545 async_answer_0(callid, ret);
546 return;
547 }
548 ddf_msg(LVL_DEBUG2, "Buffer and event session setup OK.");
549 async_answer_0(callid, EOK);
550 }
551}
552
553void remote_audio_pcm_release_buffer(ddf_fun_t *fun, void *iface,
554 ipc_callid_t callid, ipc_call_t *call)
555{
556 const audio_pcm_iface_t *pcm_iface = iface;
557
558 const int ret = pcm_iface->release_buffer ?
559 pcm_iface->release_buffer(fun) : ENOTSUP;
560 async_answer_0(callid, ret);
561}
562
563void remote_audio_pcm_start_playback(ddf_fun_t *fun, void *iface,
564 ipc_callid_t callid, ipc_call_t *call)
565{
566 const audio_pcm_iface_t *pcm_iface = iface;
567
568 const unsigned frames = DEV_IPC_GET_ARG1(*call);
569 const unsigned rate = DEV_IPC_GET_ARG2(*call);
570 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT8_MAX;
571 const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX;
572
573 const int ret = pcm_iface->start_playback
574 ? pcm_iface->start_playback(fun, frames, channels, rate, format)
575 : ENOTSUP;
576 async_answer_0(callid, ret);
577}
578
579void remote_audio_pcm_stop_playback(ddf_fun_t *fun, void *iface,
580 ipc_callid_t callid, ipc_call_t *call)
581{
582 const audio_pcm_iface_t *pcm_iface = iface;
583
584 const int ret = pcm_iface->stop_playback ?
585 pcm_iface->stop_playback(fun) : ENOTSUP;
586 async_answer_0(callid, ret);
587}
588
589void remote_audio_pcm_start_capture(ddf_fun_t *fun, void *iface,
590 ipc_callid_t callid, ipc_call_t *call)
591{
592 const audio_pcm_iface_t *pcm_iface = iface;
593
594 const unsigned frames = DEV_IPC_GET_ARG1(*call);
595 const unsigned rate = DEV_IPC_GET_ARG2(*call);
596 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT16_MAX;
597 const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX;
598
599 const int ret = pcm_iface->start_capture
600 ? pcm_iface->start_capture(fun, frames, channels, rate, format)
601 : ENOTSUP;
602 async_answer_0(callid, ret);
603}
604
605void remote_audio_pcm_stop_capture(ddf_fun_t *fun, void *iface,
606 ipc_callid_t callid, ipc_call_t *call)
607{
608 const audio_pcm_iface_t *pcm_iface = iface;
609
610 const int ret = pcm_iface->stop_capture ?
611 pcm_iface->stop_capture(fun) : ENOTSUP;
612 async_answer_0(callid, ret);
613}
614
615#if 0
616
617void remote_audio_mixer_get_info(
618 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
619{
620 audio_mixer_iface_t *mixer_iface = iface;
621
622 if (!mixer_iface->get_info) {
623 async_answer_0(callid, ENOTSUP);
624 return;
625 }
626 const char *name = NULL;
627 unsigned items = 0;
628 const int ret = mixer_iface->get_info(fun, &name, &items);
629 const size_t name_size = name ? str_size(name) + 1 : 0;
630 async_answer_2(callid, ret, name_size, items);
631 /* Send the name. */
632 if (ret == EOK && name_size > 0) {
633 size_t size;
634 ipc_callid_t name_id;
635 if (!async_data_read_receive(&name_id, &size)) {
636 async_answer_0(name_id, EPARTY);
637 return;
638 }
639 if (size != name_size) {
640 async_answer_0(name_id, ELIMIT);
641 return;
642 }
643 async_data_read_finalize(name_id, name, name_size);
644 }
645}
646
647void remote_audio_mixer_get_item_info(
648 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
649{
650 audio_mixer_iface_t *mixer_iface = iface;
651
652 if (!mixer_iface->get_item_info) {
653 async_answer_0(callid, ENOTSUP);
654 return;
655 }
656
657 const unsigned item = DEV_IPC_GET_ARG1(*call);
658 const char *name = NULL;
659 unsigned channels = 0;
660 const int ret = mixer_iface->get_item_info(fun, item, &name, &channels);
661 const size_t name_size = name ? str_size(name) + 1 : 0;
662 async_answer_2(callid, ret, name_size, channels);
663 /* Send the name. */
664 if (ret == EOK && name_size > 0) {
665 size_t size;
666 ipc_callid_t name_id;
667 if (!async_data_read_receive(&name_id, &size)) {
668 async_answer_0(name_id, EPARTY);
669 return;
670 }
671 if (size != name_size) {
672 async_answer_0(name_id, ELIMIT);
673 return;
674 }
675 async_data_read_finalize(name_id, name, name_size);
676 }
677}
678
679void remote_audio_mixer_get_channel_info(
680 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
681{
682 audio_mixer_iface_t *mixer_iface = iface;
683
684 if (!mixer_iface->get_channel_info) {
685 async_answer_0(callid, ENOTSUP);
686 return;
687 }
688
689 const unsigned item = DEV_IPC_GET_ARG1(*call);
690 const unsigned channel = DEV_IPC_GET_ARG2(*call);
691 const char *name = NULL;
692 unsigned levels = 0;
693 const int ret =
694 mixer_iface->get_channel_info(fun, item, channel, &name, &levels);
695 const size_t name_size = name ? str_size(name) + 1 : 0;
696 async_answer_2(callid, ret, name_size, levels);
697 /* Send the name. */
698 if (ret == EOK && name_size > 0) {
699 size_t size;
700 ipc_callid_t name_id;
701 if (!async_data_read_receive(&name_id, &size)) {
702 async_answer_0(name_id, EPARTY);
703 return;
704 }
705 if (size != name_size) {
706 async_answer_0(name_id, ELIMIT);
707 return;
708 }
709 async_data_read_finalize(name_id, name, name_size);
710 }
711}
712
713void remote_audio_mixer_channel_mute_set(
714 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
715{
716 audio_mixer_iface_t *mixer_iface = iface;
717
718 if (!mixer_iface->channel_mute_set) {
719 async_answer_0(callid, ENOTSUP);
720 return;
721 }
722 const unsigned item = DEV_IPC_GET_ARG1(*call);
723 const unsigned channel = DEV_IPC_GET_ARG2(*call);
724 const bool mute = DEV_IPC_GET_ARG3(*call);
725 const int ret = mixer_iface->channel_mute_set(fun, item, channel, mute);
726 async_answer_0(callid, ret);
727}
728
729void remote_audio_mixer_channel_mute_get(
730 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
731{
732 audio_mixer_iface_t *mixer_iface = iface;
733
734 if (!mixer_iface->channel_mute_get) {
735 async_answer_0(callid, ENOTSUP);
736 return;
737 }
738 const unsigned item = DEV_IPC_GET_ARG1(*call);
739 const unsigned channel = DEV_IPC_GET_ARG2(*call);
740 bool mute = false;
741 const int ret =
742 mixer_iface->channel_mute_get(fun, item, channel, &mute);
743 async_answer_1(callid, ret, mute);
744}
745
746void remote_audio_mixer_channel_volume_set(
747 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
748{
749 audio_mixer_iface_t *mixer_iface = iface;
750
751 if (!mixer_iface->channel_volume_set) {
752 async_answer_0(callid, ENOTSUP);
753 return;
754 }
755 const unsigned item = DEV_IPC_GET_ARG1(*call);
756 const unsigned channel = DEV_IPC_GET_ARG2(*call);
757 const unsigned level = DEV_IPC_GET_ARG3(*call);
758 const int ret =
759 mixer_iface->channel_volume_set(fun, item, channel, level);
760 async_answer_0(callid, ret);
761}
762
763void remote_audio_mixer_channel_volume_get(
764 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
765{
766 audio_mixer_iface_t *mixer_iface = iface;
767
768 if (!mixer_iface->channel_volume_get) {
769 async_answer_0(callid, ENOTSUP);
770 return;
771 }
772 const unsigned item = DEV_IPC_GET_ARG1(*call);
773 const unsigned channel = DEV_IPC_GET_ARG2(*call);
774 unsigned current = 0, max = 0;
775 const int ret =
776 mixer_iface->channel_volume_get(fun, item, channel, &current, &max);
777 async_answer_2(callid, ret, current, max);
778}
779#endif
780
781/**
782 * @}
783 */
784
Note: See TracBrowser for help on using the repository browser.