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

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

libdrv, audio: Remove long forgotten code.

  • Property mode set to 100644
File size: 20.0 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(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/**
361 * Stop current playback.
362 *
363 * @param sess Audio device session.
364 *
365 * @return Error code.
366 */
367int audio_pcm_stop_playback(audio_pcm_sess_t *sess)
368{
369 async_exch_t *exch = async_exchange_begin(sess);
370 const int ret = async_req_1_0(exch,
371 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
372 IPC_M_AUDIO_PCM_STOP_PLAYBACK);
373 async_exchange_end(exch);
374 return ret;
375}
376
377/**
378 * Start capture on buffer from position 0.
379 *
380 * @param sess Audio device session.
381 * @param frames Size of fragment (in frames).
382 * @param channels Number of channels.
383 * @param sample_rate Sampling rate (for one channel).
384 * @param format Sample format.
385 *
386 * @return Error code.
387 *
388 * Event will be generated after every fragment. Set fragment size to
389 * 0 to turn off event generation.
390 */
391int audio_pcm_start_capture(audio_pcm_sess_t *sess, unsigned frames,
392 unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
393{
394 if (channels > UINT16_MAX)
395 return EINVAL;
396 assert((format & UINT16_MAX) == format);
397 const sysarg_t packed = (channels << 16) | (format & UINT16_MAX);
398 async_exch_t *exch = async_exchange_begin(sess);
399 const int ret = async_req_4_0(exch,
400 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_START_CAPTURE,
401 frames, sample_rate, packed);
402 async_exchange_end(exch);
403 return ret;
404}
405
406/**
407 * Stop current playback.
408 *
409 * @param sess Audio device session.
410 *
411 * @return Error code.
412 */
413int audio_pcm_stop_capture(audio_pcm_sess_t *sess)
414{
415 async_exch_t *exch = async_exchange_begin(sess);
416 const int ret = async_req_1_0(exch,
417 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_STOP_CAPTURE);
418 async_exchange_end(exch);
419 return ret;
420}
421
422/*
423 * SERVER SIDE
424 */
425static void remote_audio_pcm_get_info_str(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
426static void remote_audio_pcm_query_caps(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
427static void remote_audio_pcm_events_register(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
428static void remote_audio_pcm_events_unregister(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
429static void remote_audio_pcm_get_buffer_pos(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
430static void remote_audio_pcm_test_format(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
431static void remote_audio_pcm_get_buffer(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
432static void remote_audio_pcm_release_buffer(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
433static void remote_audio_pcm_start_playback(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
434static void remote_audio_pcm_stop_playback(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
435static void remote_audio_pcm_start_capture(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
436static void remote_audio_pcm_stop_capture(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
437
438/** Remote audio pcm buffer interface operations. */
439static remote_iface_func_ptr_t remote_audio_pcm_iface_ops[] = {
440 [IPC_M_AUDIO_PCM_GET_INFO_STR] = remote_audio_pcm_get_info_str,
441 [IPC_M_AUDIO_PCM_QUERY_CAPS] = remote_audio_pcm_query_caps,
442 [IPC_M_AUDIO_PCM_REGISTER_EVENTS] = remote_audio_pcm_events_register,
443 [IPC_M_AUDIO_PCM_UNREGISTER_EVENTS] = remote_audio_pcm_events_unregister,
444 [IPC_M_AUDIO_PCM_GET_BUFFER_POS] = remote_audio_pcm_get_buffer_pos,
445 [IPC_M_AUDIO_PCM_TEST_FORMAT] = remote_audio_pcm_test_format,
446 [IPC_M_AUDIO_PCM_GET_BUFFER] = remote_audio_pcm_get_buffer,
447 [IPC_M_AUDIO_PCM_RELEASE_BUFFER] = remote_audio_pcm_release_buffer,
448 [IPC_M_AUDIO_PCM_START_PLAYBACK] = remote_audio_pcm_start_playback,
449 [IPC_M_AUDIO_PCM_STOP_PLAYBACK] = remote_audio_pcm_stop_playback,
450 [IPC_M_AUDIO_PCM_START_CAPTURE] = remote_audio_pcm_start_capture,
451 [IPC_M_AUDIO_PCM_STOP_CAPTURE] = remote_audio_pcm_stop_capture,
452};
453
454/** Remote audio mixer interface structure. */
455remote_iface_t remote_audio_pcm_iface = {
456 .method_count = sizeof(remote_audio_pcm_iface_ops) /
457 sizeof(remote_audio_pcm_iface_ops[0]),
458 .methods = remote_audio_pcm_iface_ops
459};
460
461void remote_audio_pcm_get_info_str(ddf_fun_t *fun, void *iface,
462 ipc_callid_t callid, ipc_call_t *call)
463{
464 const audio_pcm_iface_t *pcm_iface = iface;
465
466 if (!pcm_iface->get_info_str) {
467 async_answer_0(callid, ENOTSUP);
468 return;
469 }
470 const char *name = NULL;
471 const int ret = pcm_iface->get_info_str(fun, &name);
472 const size_t name_size = name ? str_size(name) + 1 : 0;
473 async_answer_1(callid, ret, name_size);
474 /* Send the string. */
475 if (ret == EOK && name_size > 0) {
476 size_t size;
477 ipc_callid_t name_id;
478 if (!async_data_read_receive(&name_id, &size)) {
479 async_answer_0(name_id, EPARTY);
480 return;
481 }
482 if (size != name_size) {
483 async_answer_0(name_id, ELIMIT);
484 return;
485 }
486 async_data_read_finalize(name_id, name, name_size);
487 }
488}
489
490void remote_audio_pcm_query_caps(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
491{
492 const audio_pcm_iface_t *pcm_iface = iface;
493 const audio_cap_t cap = DEV_IPC_GET_ARG1(*call);
494 if (pcm_iface->query_cap) {
495 const unsigned value = pcm_iface->query_cap(fun, cap);
496 async_answer_1(callid, EOK, value);
497 } else {
498 async_answer_0(callid, ENOTSUP);
499 }
500}
501
502static void remote_audio_pcm_events_register(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
503{
504 const audio_pcm_iface_t *pcm_iface = iface;
505 if (!pcm_iface->get_event_session ||
506 !pcm_iface->set_event_session) {
507 async_answer_0(callid, ENOTSUP);
508 return;
509 }
510
511 async_answer_0(callid, EOK);
512
513 ipc_call_t callback_call;
514 ipc_callid_t callback_id = async_get_call(&callback_call);
515 async_sess_t *sess =
516 async_callback_receive_start(EXCHANGE_ATOMIC, &callback_call);
517 if (sess == NULL) {
518 ddf_msg(LVL_DEBUG, "Failed to create event callback");
519 pcm_iface->release_buffer(fun);
520 async_answer_0(callback_id, EAGAIN);
521 return;
522 }
523 const int ret = pcm_iface->set_event_session(fun, sess);
524 if (ret != EOK) {
525 ddf_msg(LVL_DEBUG, "Failed to set event callback.");
526 pcm_iface->release_buffer(fun);
527 async_hangup(sess);
528 async_answer_0(callback_id, ret);
529 return;
530 }
531 ddf_msg(LVL_DEBUG2, "Event session setup OK.");
532 async_answer_0(callback_id, EOK);
533}
534
535static void remote_audio_pcm_events_unregister(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
536{
537 const audio_pcm_iface_t *pcm_iface = iface;
538 if (!pcm_iface->get_event_session ||
539 !pcm_iface->set_event_session) {
540 async_answer_0(callid, ENOTSUP);
541 return;
542 }
543 async_sess_t *sess = pcm_iface->get_event_session(fun);
544 if (sess) {
545 async_hangup(sess);
546 pcm_iface->set_event_session(fun, NULL);
547 }
548 async_answer_0(callid, EOK);
549}
550
551void remote_audio_pcm_get_buffer_pos(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
552{
553 const audio_pcm_iface_t *pcm_iface = iface;
554 size_t pos = 0;
555 const int ret = pcm_iface->get_buffer_pos ?
556 pcm_iface->get_buffer_pos(fun, &pos) : ENOTSUP;
557 async_answer_1(callid, ret, pos);
558}
559
560void remote_audio_pcm_test_format(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
561{
562 const audio_pcm_iface_t *pcm_iface = iface;
563 unsigned channels = DEV_IPC_GET_ARG1(*call);
564 unsigned rate = DEV_IPC_GET_ARG2(*call);
565 pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call);
566 const int ret = pcm_iface->test_format ?
567 pcm_iface->test_format(fun, &channels, &rate, &format) : ENOTSUP;
568 async_answer_3(callid, ret, channels, rate, format);
569}
570
571void remote_audio_pcm_get_buffer(ddf_fun_t *fun, void *iface,
572 ipc_callid_t callid, ipc_call_t *call)
573{
574 const audio_pcm_iface_t *pcm_iface = iface;
575
576 if (!pcm_iface->get_buffer ||
577 !pcm_iface->release_buffer) {
578 async_answer_0(callid, ENOTSUP);
579 return;
580 }
581 void *buffer = NULL;
582 size_t size = DEV_IPC_GET_ARG1(*call);
583 int ret = pcm_iface->get_buffer(fun, &buffer, &size);
584 async_answer_1(callid, ret, size);
585 if (ret != EOK || size == 0)
586 return;
587
588 /* Share the buffer. */
589 size_t share_size = 0;
590 ipc_callid_t share_id = 0;
591
592 ddf_msg(LVL_DEBUG2, "Receiving share request.");
593 if (!async_share_in_receive(&share_id, &share_size)) {
594 ddf_msg(LVL_DEBUG, "Failed to share pcm buffer.");
595 pcm_iface->release_buffer(fun);
596 async_answer_0(share_id, EPARTY);
597 return;
598 }
599
600 ddf_msg(LVL_DEBUG2, "Checking requested share size.");
601 if (share_size != size) {
602 ddf_msg(LVL_DEBUG, "Incorrect pcm buffer size requested.");
603 pcm_iface->release_buffer(fun);
604 async_answer_0(share_id, ELIMIT);
605 return;
606 }
607
608 ddf_msg(LVL_DEBUG2, "Calling share finalize.");
609 ret = async_share_in_finalize(share_id, buffer, AS_AREA_WRITE
610 | AS_AREA_READ);
611 if (ret != EOK) {
612 ddf_msg(LVL_DEBUG, "Failed to share buffer.");
613 pcm_iface->release_buffer(fun);
614 return;
615 }
616
617 ddf_msg(LVL_DEBUG2, "Buffer shared with size %zu.", share_size);
618}
619
620void remote_audio_pcm_release_buffer(ddf_fun_t *fun, void *iface,
621 ipc_callid_t callid, ipc_call_t *call)
622{
623 const audio_pcm_iface_t *pcm_iface = iface;
624
625 const int ret = pcm_iface->release_buffer ?
626 pcm_iface->release_buffer(fun) : ENOTSUP;
627 async_answer_0(callid, ret);
628}
629
630void remote_audio_pcm_start_playback(ddf_fun_t *fun, void *iface,
631 ipc_callid_t callid, ipc_call_t *call)
632{
633 const audio_pcm_iface_t *pcm_iface = iface;
634
635 const unsigned frames = DEV_IPC_GET_ARG1(*call);
636 const unsigned rate = DEV_IPC_GET_ARG2(*call);
637 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT8_MAX;
638 const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX;
639
640 const int ret = pcm_iface->start_playback
641 ? pcm_iface->start_playback(fun, frames, channels, rate, format)
642 : ENOTSUP;
643 async_answer_0(callid, ret);
644}
645
646void remote_audio_pcm_stop_playback(ddf_fun_t *fun, void *iface,
647 ipc_callid_t callid, ipc_call_t *call)
648{
649 const audio_pcm_iface_t *pcm_iface = iface;
650
651 const int ret = pcm_iface->stop_playback ?
652 pcm_iface->stop_playback(fun) : ENOTSUP;
653 async_answer_0(callid, ret);
654}
655
656void remote_audio_pcm_start_capture(ddf_fun_t *fun, void *iface,
657 ipc_callid_t callid, ipc_call_t *call)
658{
659 const audio_pcm_iface_t *pcm_iface = iface;
660
661 const unsigned frames = DEV_IPC_GET_ARG1(*call);
662 const unsigned rate = DEV_IPC_GET_ARG2(*call);
663 const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT16_MAX;
664 const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX;
665
666 const int ret = pcm_iface->start_capture
667 ? pcm_iface->start_capture(fun, frames, channels, rate, format)
668 : ENOTSUP;
669 async_answer_0(callid, ret);
670}
671
672void remote_audio_pcm_stop_capture(ddf_fun_t *fun, void *iface,
673 ipc_callid_t callid, ipc_call_t *call)
674{
675 const audio_pcm_iface_t *pcm_iface = iface;
676
677 const int ret = pcm_iface->stop_capture ?
678 pcm_iface->stop_capture(fun) : ENOTSUP;
679 async_answer_0(callid, ret);
680}
681
682/**
683 * @}
684 */
685
Note: See TracBrowser for help on using the repository browser.