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

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

audio, sb16: Add and implement API for playback/capture with or without fragments.

  • Property mode set to 100644
File size: 21.9 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_REGISTER_EVENTS,
49 IPC_M_AUDIO_PCM_UNREGISTER_EVENTS,
50 IPC_M_AUDIO_PCM_TEST_FORMAT,
51 IPC_M_AUDIO_PCM_GET_BUFFER,
52 IPC_M_AUDIO_PCM_RELEASE_BUFFER,
53 IPC_M_AUDIO_PCM_GET_BUFFER_POS,
54 IPC_M_AUDIO_PCM_START_PLAYBACK,
55 IPC_M_AUDIO_PCM_STOP_PLAYBACK,
56 IPC_M_AUDIO_PCM_START_CAPTURE,
57 IPC_M_AUDIO_PCM_STOP_CAPTURE,
58} audio_pcm_iface_funcs_t;
59
60/*
61 * CLIENT SIDE
62 */
63
64/**
65 * Open audio session with device identified by location service string.
66 *
67 * @param name Location service string.
68 * @return Pointer to a new audio device session, NULL on failure.
69 */
70audio_pcm_sess_t *audio_pcm_open(const char *name)
71{
72 devman_handle_t device_handle = 0;
73 const int ret = devman_fun_get_handle(name, &device_handle, 0);
74 if (ret != EOK)
75 return NULL;
76 return devman_device_connect(EXCHANGE_SERIALIZE, device_handle,
77 IPC_FLAG_BLOCKING);
78}
79
80/**
81 * Open audio session with device identified by location service id
82 *
83 * @param name Location service id.
84 * @return Pointer to a new audio device session, NULL on failure.
85 */
86audio_pcm_sess_t *audio_pcm_open_service(service_id_t id)
87{
88 return loc_service_connect(EXCHANGE_SERIALIZE, id, IPC_FLAG_BLOCKING);
89}
90
91/**
92 * Close open audio device session.
93 *
94 * @param name Open audio device session.
95 *
96 * @note Calling this function on already closed or invalid session results
97 * in undefined behavior.
98 */
99void audio_pcm_close(audio_pcm_sess_t *sess)
100{
101 if (sess)
102 async_hangup(sess);
103}
104
105/**
106 * Get a short description string.
107 *
108 * @param sess Audio device session.
109 * @param name Place to store newly allocated string.
110 *
111 * @return Error code.
112 *
113 * @note Caller is responsible for freeing newly allocated memory.
114 */
115int audio_pcm_get_info_str(audio_pcm_sess_t *sess, const char **name)
116{
117 if (!name)
118 return EINVAL;
119 async_exch_t *exch = async_exchange_begin(sess);
120 sysarg_t name_size;
121 const int ret = async_req_1_1(exch,
122 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
123 IPC_M_AUDIO_PCM_GET_INFO_STR, &name_size);
124 if (ret == EOK) {
125 char *name_place = calloc(1, name_size);
126 if (!name_place) {
127 /* Make the other side fail
128 * as it waits for read request */
129 async_data_read_start(exch, (void*)-1, 0);
130 async_exchange_end(exch);
131 return ENOMEM;
132 }
133 const int ret =
134 async_data_read_start(exch, name_place, name_size);
135 if (ret != EOK) {
136 free(name_place);
137 async_exchange_end(exch);
138 return ret;
139 }
140 *name = name_place;
141 }
142 async_exchange_end(exch);
143 return ret;
144}
145
146
147/**
148 * Query value of specified capability.
149 *
150 * @param sess Audio device session.
151 * @param cap Audio device capability.
152 * @param val Place to store queried value.
153 *
154 * @return Error code.
155 */
156int audio_pcm_query_cap(audio_pcm_sess_t *sess, audio_cap_t cap, unsigned *val)
157{
158 if (!val)
159 return EINVAL;
160 async_exch_t *exch = async_exchange_begin(sess);
161 sysarg_t value = 0;
162 const int ret = async_req_2_1(exch,
163 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_QUERY_CAPS,
164 cap, &value);
165 if (ret == EOK)
166 *val = value;
167 async_exchange_end(exch);
168 return ret;
169}
170
171/**
172 * Query current position in device buffer.
173 *
174 * @param sess Audio device session.
175 * @param pos Place to store the result.
176 *
177 * @return Error code.
178 *
179 * Works for both playback and capture.
180 */
181int audio_pcm_get_buffer_pos(audio_pcm_sess_t *sess, size_t *pos)
182{
183 if (!pos)
184 return EINVAL;
185 async_exch_t *exch = async_exchange_begin(sess);
186 sysarg_t value = 0;;
187 const int ret = async_req_1_1(exch,
188 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
189 IPC_M_AUDIO_PCM_GET_BUFFER_POS, &value);
190 if (ret == EOK)
191 *pos = value;
192 async_exchange_end(exch);
193 return ret;
194}
195
196/**
197 * Test format parameters for device support.
198 *
199 * @param sess Audio device session.
200 * @param channels Number of channels
201 * @param rate Sampling rate.
202 * @format Sample format.
203 *
204 * @return Error code.
205 *
206 * Works for both playback and capture. This function modifies provided
207 * parameters to the nearest values supported by the device.
208 */
209int audio_pcm_test_format(audio_pcm_sess_t *sess, unsigned *channels,
210 unsigned *rate, pcm_sample_format_t *format)
211{
212 async_exch_t *exch = async_exchange_begin(sess);
213 sysarg_t channels_arg = channels ? *channels : 0;
214 sysarg_t rate_arg = rate ? *rate : 0;
215 sysarg_t format_arg = format ? *format : 0;
216 const int ret = async_req_4_3(exch,
217 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
218 IPC_M_AUDIO_PCM_TEST_FORMAT, channels_arg, rate_arg, format_arg,
219 &channels_arg, &rate_arg, &format_arg);
220 async_exchange_end(exch);
221
222 /* All OK or something has changed. Verify that it was not one of the
223 * params we care about */
224 if ((ret == EOK || ret == ELIMIT)
225 && (!channels || *channels == channels_arg)
226 && (!rate || *rate == rate_arg)
227 && (!format || *format == format_arg))
228 return EOK;
229 if (channels)
230 *channels = channels_arg;
231 if (rate)
232 *rate = rate_arg;
233 if (format)
234 *format = format_arg;
235 return ret;
236}
237
238/**
239 * Register callback for device generated events.
240 *
241 * @param sess Audio device session.
242 * @param event_rec Event callback function.
243 * @param arg Event callback custom parameter.
244 *
245 * @return Error code.
246 */
247int audio_pcm_register_event_callback(audio_pcm_sess_t *sess,
248 async_client_conn_t event_callback, void *arg)
249{
250 if (!event_callback)
251 return EINVAL;
252
253 async_exch_t *exch = async_exchange_begin(sess);
254 int ret = async_req_1_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
255 IPC_M_AUDIO_PCM_REGISTER_EVENTS);
256 if (ret == EOK) {
257 ret = async_connect_to_me(exch, 0, 0, 0, event_callback, arg);
258 }
259 async_exchange_end(exch);
260 return ret;
261}
262
263/**
264 * Unregister callback for device generated events.
265 *
266 * @param sess Audio device session.
267 *
268 * @return Error code.
269 */
270int audio_pcm_unregister_event_callback(audio_pcm_sess_t *sess)
271{
272 async_exch_t *exch = async_exchange_begin(sess);
273 const int ret = async_req_1_0(exch,
274 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
275 IPC_M_AUDIO_PCM_UNREGISTER_EVENTS);
276 async_exchange_end(exch);
277 return ret;
278}
279
280/**
281 * Get device accessible playback/capture buffer.
282 *
283 * @param sess Audio device session.
284 * @param buffer Place to store pointer to the buffer.
285 * @param size Place to store buffer size (bytes).
286 *
287 * @return Error code.
288 */
289int audio_pcm_get_buffer(audio_pcm_sess_t *sess, void **buffer, size_t *size)
290{
291 if (!buffer || !size)
292 return EINVAL;
293
294 async_exch_t *exch = async_exchange_begin(sess);
295
296 sysarg_t buffer_size = *size;
297 int ret = async_req_2_1(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
298 IPC_M_AUDIO_PCM_GET_BUFFER, (sysarg_t)buffer_size, &buffer_size);
299 if (ret == EOK) {
300 void *dst = NULL;
301 ret = async_share_in_start_0_0(exch, buffer_size, &dst);
302 if (ret != EOK) {
303 async_exchange_end(exch);
304 return ret;
305 }
306 *buffer = dst;
307 *size = buffer_size;
308 }
309 async_exchange_end(exch);
310 return ret;
311}
312
313/**
314 * Release device accessible playback/capture buffer.
315 *
316 * @param sess Audio device session.
317 *
318 * @return Error code.
319 */
320int audio_pcm_release_buffer(audio_pcm_sess_t *sess)
321{
322 async_exch_t *exch = async_exchange_begin(sess);
323 const int ret = async_req_1_0(exch,
324 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
325 IPC_M_AUDIO_PCM_RELEASE_BUFFER);
326 async_exchange_end(exch);
327 return ret;
328}
329
330/**
331 * Start playback on buffer from position 0.
332 *
333 * @param sess Audio device session.
334 * @param frames Size of fragment (in frames).
335 * @param channels Number of channels.
336 * @param sample_rate Sampling rate (for one channel).
337 * @param format Sample format.
338 *
339 * @return Error code.
340 *
341 * Event will be generated after every fragment. Set fragment size to
342 * 0 to turn off event generation.
343 */
344int audio_pcm_start_playback_fragment(audio_pcm_sess_t *sess, unsigned frames,
345 unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
346{
347 if (channels > UINT16_MAX)
348 return EINVAL;
349 assert((format & UINT16_MAX) == format);
350 const sysarg_t packed = (channels << 16) | (format & UINT16_MAX);
351 async_exch_t *exch = async_exchange_begin(sess);
352 const int ret = async_req_4_0(exch,
353 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
354 IPC_M_AUDIO_PCM_START_PLAYBACK,
355 frames, sample_rate, packed);
356 async_exchange_end(exch);
357 return ret;
358}
359/**
360 * Stops playback after current fragment.
361 *
362 * @param sess Audio device session.
363 *
364 * @return Error code.
365 */
366int audio_pcm_last_playback_fragment(audio_pcm_sess_t *sess)
367{
368 async_exch_t *exch = async_exchange_begin(sess);
369 const int ret = async_req_2_0(exch,
370 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
371 IPC_M_AUDIO_PCM_STOP_PLAYBACK, false);
372 async_exchange_end(exch);
373 return ret;
374}
375
376/**
377 * Start playback on buffer from the current position.
378 *
379 * @param sess Audio device session.
380 * @param channels Number of channels.
381 * @param sample_rate Sampling rate (for one channel).
382 * @param format Sample format.
383 *
384 * @return Error code.
385 */
386int audio_pcm_start_playback(audio_pcm_sess_t *sess,
387 unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
388{
389 return audio_pcm_start_playback_fragment(
390 sess, 0, channels, sample_rate, format);
391}
392
393/**
394 * Immediately stops current playback.
395 *
396 * @param sess Audio device session.
397 *
398 * @return Error code.
399 */
400int audio_pcm_stop_playback(audio_pcm_sess_t *sess)
401{
402 async_exch_t *exch = async_exchange_begin(sess);
403 const int ret = async_req_2_0(exch,
404 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
405 IPC_M_AUDIO_PCM_STOP_PLAYBACK, true);
406 async_exchange_end(exch);
407 return ret;
408}
409
410/**
411 * Start capture on buffer from the current position.
412 *
413 * @param sess Audio device session.
414 * @param frames Size of fragment (in frames).
415 * @param channels Number of channels.
416 * @param sample_rate Sampling rate (for one channel).
417 * @param format Sample format.
418 *
419 * @return Error code.
420 *
421 * Event will be generated after every fragment. Set fragment size to
422 * 0 to turn off event generation.
423 */
424int audio_pcm_start_capture_fragment(audio_pcm_sess_t *sess, unsigned frames,
425 unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
426{
427 if (channels > UINT16_MAX)
428 return EINVAL;
429 assert((format & UINT16_MAX) == format);
430 const sysarg_t packed = (channels << 16) | (format & UINT16_MAX);
431 async_exch_t *exch = async_exchange_begin(sess);
432 const int ret = async_req_4_0(exch,
433 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_START_CAPTURE,
434 frames, sample_rate, packed);
435 async_exchange_end(exch);
436 return ret;
437}
438
439/**
440 * Start capture on buffer from the current position.
441 *
442 * @param sess Audio device session.
443 * @param channels Number of channels.
444 * @param sample_rate Sampling rate (for one channel).
445 * @param format Sample format.
446 *
447 * @return Error code.
448 */
449int audio_pcm_start_capture(audio_pcm_sess_t *sess,
450 unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
451{
452 return audio_pcm_start_capture_fragment(
453 sess, 0, channels, sample_rate, format);
454}
455
456/**
457 * Stops capture at the end of current fragment.
458 *
459 * Won't work if capture was started with fragment size 0.
460 * @param sess Audio device session.
461 *
462 * @return Error code.
463 */
464int audio_pcm_last_capture_fragment(audio_pcm_sess_t *sess)
465{
466 async_exch_t *exch = async_exchange_begin(sess);
467 const int ret = async_req_2_0(exch,
468 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
469 IPC_M_AUDIO_PCM_STOP_CAPTURE, false);
470 async_exchange_end(exch);
471 return ret;
472}
473
474/**
475 * Immediately stops current capture.
476 *
477 * @param sess Audio device session.
478 *
479 * @return Error code.
480 */
481int audio_pcm_stop_capture(audio_pcm_sess_t *sess)
482{
483 async_exch_t *exch = async_exchange_begin(sess);
484 const int ret = async_req_2_0(exch,
485 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
486 IPC_M_AUDIO_PCM_STOP_CAPTURE, true);
487 async_exchange_end(exch);
488 return ret;
489}
490
491/*
492 * SERVER SIDE
493 */
494static void remote_audio_pcm_get_info_str(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
495static void remote_audio_pcm_query_caps(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
496static void remote_audio_pcm_events_register(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
497static void remote_audio_pcm_events_unregister(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
498static void remote_audio_pcm_get_buffer_pos(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
499static void remote_audio_pcm_test_format(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
500static void remote_audio_pcm_get_buffer(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
501static void remote_audio_pcm_release_buffer(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
502static void remote_audio_pcm_start_playback(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
503static void remote_audio_pcm_stop_playback(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
504static void remote_audio_pcm_start_capture(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
505static void remote_audio_pcm_stop_capture(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
506
507/** Remote audio pcm buffer interface operations. */
508static remote_iface_func_ptr_t remote_audio_pcm_iface_ops[] = {
509 [IPC_M_AUDIO_PCM_GET_INFO_STR] = remote_audio_pcm_get_info_str,
510 [IPC_M_AUDIO_PCM_QUERY_CAPS] = remote_audio_pcm_query_caps,
511 [IPC_M_AUDIO_PCM_REGISTER_EVENTS] = remote_audio_pcm_events_register,
512 [IPC_M_AUDIO_PCM_UNREGISTER_EVENTS] = remote_audio_pcm_events_unregister,
513 [IPC_M_AUDIO_PCM_GET_BUFFER_POS] = remote_audio_pcm_get_buffer_pos,
514 [IPC_M_AUDIO_PCM_TEST_FORMAT] = remote_audio_pcm_test_format,
515 [IPC_M_AUDIO_PCM_GET_BUFFER] = remote_audio_pcm_get_buffer,
516 [IPC_M_AUDIO_PCM_RELEASE_BUFFER] = remote_audio_pcm_release_buffer,
517 [IPC_M_AUDIO_PCM_START_PLAYBACK] = remote_audio_pcm_start_playback,
518 [IPC_M_AUDIO_PCM_STOP_PLAYBACK] = remote_audio_pcm_stop_playback,
519 [IPC_M_AUDIO_PCM_START_CAPTURE] = remote_audio_pcm_start_capture,
520 [IPC_M_AUDIO_PCM_STOP_CAPTURE] = remote_audio_pcm_stop_capture,
521};
522
523/** Remote audio mixer interface structure. */
524remote_iface_t remote_audio_pcm_iface = {
525 .method_count = sizeof(remote_audio_pcm_iface_ops) /
526 sizeof(remote_audio_pcm_iface_ops[0]),
527 .methods = remote_audio_pcm_iface_ops
528};
529
530void remote_audio_pcm_get_info_str(ddf_fun_t *fun, void *iface,
531 ipc_callid_t callid, ipc_call_t *call)
532{
533 const audio_pcm_iface_t *pcm_iface = iface;
534
535 if (!pcm_iface->get_info_str) {
536 async_answer_0(callid, ENOTSUP);
537 return;
538 }
539 const char *name = NULL;
540 const int ret = pcm_iface->get_info_str(fun, &name);
541 const size_t name_size = name ? str_size(name) + 1 : 0;
542 async_answer_1(callid, ret, name_size);
543 /* Send the string. */
544 if (ret == EOK && name_size > 0) {
545 size_t size;
546 ipc_callid_t name_id;
547 if (!async_data_read_receive(&name_id, &size)) {
548 async_answer_0(name_id, EPARTY);
549 return;
550 }
551 if (size != name_size) {
552 async_answer_0(name_id, ELIMIT);
553 return;
554 }
555 async_data_read_finalize(name_id, name, name_size);
556 }
557}
558
559void remote_audio_pcm_query_caps(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
560{
561 const audio_pcm_iface_t *pcm_iface = iface;
562 const audio_cap_t cap = DEV_IPC_GET_ARG1(*call);
563 if (pcm_iface->query_cap) {
564 const unsigned value = pcm_iface->query_cap(fun, cap);
565 async_answer_1(callid, EOK, value);
566 } else {
567 async_answer_0(callid, ENOTSUP);
568 }
569}
570
571static void remote_audio_pcm_events_register(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
572{
573 const audio_pcm_iface_t *pcm_iface = iface;
574 if (!pcm_iface->get_event_session ||
575 !pcm_iface->set_event_session) {
576 async_answer_0(callid, ENOTSUP);
577 return;
578 }
579
580 async_answer_0(callid, EOK);
581
582 ipc_call_t callback_call;
583 ipc_callid_t callback_id = async_get_call(&callback_call);
584 async_sess_t *sess =
585 async_callback_receive_start(EXCHANGE_ATOMIC, &callback_call);
586 if (sess == NULL) {
587 ddf_msg(LVL_DEBUG, "Failed to create event callback");
588 pcm_iface->release_buffer(fun);
589 async_answer_0(callback_id, EAGAIN);
590 return;
591 }
592 const int ret = pcm_iface->set_event_session(fun, sess);
593 if (ret != EOK) {
594 ddf_msg(LVL_DEBUG, "Failed to set event callback.");
595 pcm_iface->release_buffer(fun);
596 async_hangup(sess);
597 async_answer_0(callback_id, ret);
598 return;
599 }
600 ddf_msg(LVL_DEBUG2, "Event session setup OK.");
601 async_answer_0(callback_id, EOK);
602}
603
604static void remote_audio_pcm_events_unregister(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
605{
606 const audio_pcm_iface_t *pcm_iface = iface;
607 if (!pcm_iface->get_event_session ||
608 !pcm_iface->set_event_session) {
609 async_answer_0(callid, ENOTSUP);
610 return;
611 }
612 async_sess_t *sess = pcm_iface->get_event_session(fun);
613 if (sess) {
614 async_hangup(sess);
615 pcm_iface->set_event_session(fun, NULL);
616 }
617 async_answer_0(callid, EOK);
618}
619
620void remote_audio_pcm_get_buffer_pos(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
621{
622 const audio_pcm_iface_t *pcm_iface = iface;
623 size_t pos = 0;
624 const int ret = pcm_iface->get_buffer_pos ?
625 pcm_iface->get_buffer_pos(fun, &pos) : ENOTSUP;
626 async_answer_1(callid, ret, pos);
627}
628
629void remote_audio_pcm_test_format(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
630{
631 const audio_pcm_iface_t *pcm_iface = iface;
632 unsigned channels = DEV_IPC_GET_ARG1(*call);
633 unsigned rate = DEV_IPC_GET_ARG2(*call);
634 pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call);
635 const int ret = pcm_iface->test_format ?
636 pcm_iface->test_format(fun, &channels, &rate, &format) : ENOTSUP;
637 async_answer_3(callid, ret, channels, rate, format);
638}
639
640void remote_audio_pcm_get_buffer(ddf_fun_t *fun, void *iface,
641 ipc_callid_t callid, ipc_call_t *call)
642{
643 const audio_pcm_iface_t *pcm_iface = iface;
644
645 if (!pcm_iface->get_buffer ||
646 !pcm_iface->release_buffer) {
647 async_answer_0(callid, ENOTSUP);
648 return;
649 }
650 void *buffer = NULL;
651 size_t size = DEV_IPC_GET_ARG1(*call);
652 int ret = pcm_iface->get_buffer(fun, &buffer, &size);
653 async_answer_1(callid, ret, size);
654 if (ret != EOK || size == 0)
655 return;
656
657 /* Share the buffer. */
658 size_t share_size = 0;
659 ipc_callid_t share_id = 0;
660
661 ddf_msg(LVL_DEBUG2, "Receiving share request.");
662 if (!async_share_in_receive(&share_id, &share_size)) {
663 ddf_msg(LVL_DEBUG, "Failed to share pcm buffer.");
664 pcm_iface->release_buffer(fun);
665 async_answer_0(share_id, EPARTY);
666 return;
667 }
668
669 ddf_msg(LVL_DEBUG2, "Checking requested share size.");
670 if (share_size != size) {
671 ddf_msg(LVL_DEBUG, "Incorrect pcm buffer size requested.");
672 pcm_iface->release_buffer(fun);
673 async_answer_0(share_id, ELIMIT);
674 return;
675 }
676
677 ddf_msg(LVL_DEBUG2, "Calling share finalize.");
678 ret = async_share_in_finalize(share_id, buffer, AS_AREA_WRITE
679 | AS_AREA_READ);
680 if (ret != EOK) {
681 ddf_msg(LVL_DEBUG, "Failed to share buffer.");
682 pcm_iface->release_buffer(fun);
683 return;
684 }
685
686 ddf_msg(LVL_DEBUG2, "Buffer shared with size %zu.", share_size);
687}
688
689void remote_audio_pcm_release_buffer(ddf_fun_t *fun, void *iface,
690 ipc_callid_t callid, ipc_call_t *call)
691{
692 const audio_pcm_iface_t *pcm_iface = iface;
693
694 const int ret = pcm_iface->release_buffer ?
695 pcm_iface->release_buffer(fun) : ENOTSUP;
696 async_answer_0(callid, ret);
697}
698
699void remote_audio_pcm_start_playback(ddf_fun_t *fun, void *iface,
700 ipc_callid_t callid, ipc_call_t *call)
701{
702 const audio_pcm_iface_t *pcm_iface = iface;
703
704 const unsigned frames = DEV_IPC_GET_ARG1(*call);
705 const unsigned rate = DEV_IPC_GET_ARG2(*call);
706 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT8_MAX;
707 const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX;
708
709 const int ret = pcm_iface->start_playback
710 ? pcm_iface->start_playback(fun, frames, channels, rate, format)
711 : ENOTSUP;
712 async_answer_0(callid, ret);
713}
714
715void remote_audio_pcm_stop_playback(ddf_fun_t *fun, void *iface,
716 ipc_callid_t callid, ipc_call_t *call)
717{
718 const audio_pcm_iface_t *pcm_iface = iface;
719 const bool immediate = DEV_IPC_GET_ARG1(*call);
720
721 const int ret = pcm_iface->stop_playback ?
722 pcm_iface->stop_playback(fun, immediate) : ENOTSUP;
723 async_answer_0(callid, ret);
724}
725
726void remote_audio_pcm_start_capture(ddf_fun_t *fun, void *iface,
727 ipc_callid_t callid, ipc_call_t *call)
728{
729 const audio_pcm_iface_t *pcm_iface = iface;
730
731 const unsigned frames = DEV_IPC_GET_ARG1(*call);
732 const unsigned rate = DEV_IPC_GET_ARG2(*call);
733 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT16_MAX;
734 const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX;
735
736 const int ret = pcm_iface->start_capture
737 ? pcm_iface->start_capture(fun, frames, channels, rate, format)
738 : ENOTSUP;
739 async_answer_0(callid, ret);
740}
741
742void remote_audio_pcm_stop_capture(ddf_fun_t *fun, void *iface,
743 ipc_callid_t callid, ipc_call_t *call)
744{
745 const audio_pcm_iface_t *pcm_iface = iface;
746 const bool immediate = DEV_IPC_GET_ARG1(*call);
747
748 const int ret = pcm_iface->stop_capture ?
749 pcm_iface->stop_capture(fun, immediate) : ENOTSUP;
750 async_answer_0(callid, ret);
751}
752
753/**
754 * @}
755 */
756
Note: See TracBrowser for help on using the repository browser.