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