[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) {
|
---|
| 116 | const int ret = loc_category_get_id("audio-pcm", &pcm_id,
|
---|
| 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;
|
---|
| 125 | const int ret = loc_category_get_svcs(pcm_id, &svcs, &count);
|
---|
| 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;
|
---|
| 145 | const int ret = devman_fun_get_handle(name, &device_handle, 0);
|
---|
| 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 | */
|
---|
[2cc5c835] | 186 | int audio_pcm_get_info_str(audio_pcm_sess_t *sess, const char **name)
|
---|
| 187 | {
|
---|
[20840922] | 188 | if (!name)
|
---|
| 189 | return EINVAL;
|
---|
[2cc5c835] | 190 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[c09ad29e] | 191 | sysarg_t name_size;
|
---|
| 192 | const int ret = async_req_1_1(exch,
|
---|
| 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 | }
|
---|
| 204 | const int ret =
|
---|
| 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.
|
---|
| 223 | * @param val Place to store queried value.
|
---|
| 224 | *
|
---|
| 225 | * @return Error code.
|
---|
| 226 | */
|
---|
[5337491] | 227 | int audio_pcm_query_cap(audio_pcm_sess_t *sess, audio_cap_t cap)
|
---|
[2e01b3f] | 228 | {
|
---|
| 229 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[fa91c0f] | 230 | sysarg_t value = 0;
|
---|
[2e01b3f] | 231 | const int ret = async_req_2_1(exch,
|
---|
| 232 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_QUERY_CAPS,
|
---|
[fa91c0f] | 233 | cap, &value);
|
---|
| 234 | async_exchange_end(exch);
|
---|
[5337491] | 235 | if (ret == EOK)
|
---|
| 236 | return value;
|
---|
[fa91c0f] | 237 | return ret;
|
---|
| 238 | }
|
---|
| 239 |
|
---|
[ad1aedc] | 240 | /**
|
---|
| 241 | * Query current position in device buffer.
|
---|
| 242 | *
|
---|
| 243 | * @param sess Audio device session.
|
---|
| 244 | * @param pos Place to store the result.
|
---|
| 245 | *
|
---|
| 246 | * @return Error code.
|
---|
| 247 | *
|
---|
| 248 | * Works for both playback and capture.
|
---|
| 249 | */
|
---|
[fa91c0f] | 250 | int audio_pcm_get_buffer_pos(audio_pcm_sess_t *sess, size_t *pos)
|
---|
| 251 | {
|
---|
| 252 | if (!pos)
|
---|
| 253 | return EINVAL;
|
---|
| 254 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[7ed6ee2] | 255 | sysarg_t value = 0;
|
---|
[fa91c0f] | 256 | const int ret = async_req_1_1(exch,
|
---|
| 257 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 258 | IPC_M_AUDIO_PCM_GET_BUFFER_POS, &value);
|
---|
| 259 | if (ret == EOK)
|
---|
| 260 | *pos = value;
|
---|
| 261 | async_exchange_end(exch);
|
---|
[2e01b3f] | 262 | return ret;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[ad1aedc] | 265 | /**
|
---|
| 266 | * Test format parameters for device support.
|
---|
| 267 | *
|
---|
| 268 | * @param sess Audio device session.
|
---|
| 269 | * @param channels Number of channels
|
---|
| 270 | * @param rate Sampling rate.
|
---|
| 271 | * @format Sample format.
|
---|
| 272 | *
|
---|
| 273 | * @return Error code.
|
---|
| 274 | *
|
---|
| 275 | * Works for both playback and capture. This function modifies provided
|
---|
| 276 | * parameters to the nearest values supported by the device.
|
---|
| 277 | */
|
---|
[63c34d7] | 278 | int audio_pcm_test_format(audio_pcm_sess_t *sess, unsigned *channels,
|
---|
| 279 | unsigned *rate, pcm_sample_format_t *format)
|
---|
| 280 | {
|
---|
| 281 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 282 | sysarg_t channels_arg = channels ? *channels : 0;
|
---|
| 283 | sysarg_t rate_arg = rate ? *rate : 0;
|
---|
| 284 | sysarg_t format_arg = format ? *format : 0;
|
---|
| 285 | const int ret = async_req_4_3(exch,
|
---|
| 286 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 287 | IPC_M_AUDIO_PCM_TEST_FORMAT, channels_arg, rate_arg, format_arg,
|
---|
| 288 | &channels_arg, &rate_arg, &format_arg);
|
---|
| 289 | async_exchange_end(exch);
|
---|
| 290 |
|
---|
| 291 | /* All OK or something has changed. Verify that it was not one of the
|
---|
| 292 | * params we care about */
|
---|
| 293 | if ((ret == EOK || ret == ELIMIT)
|
---|
| 294 | && (!channels || *channels == channels_arg)
|
---|
| 295 | && (!rate || *rate == rate_arg)
|
---|
| 296 | && (!format || *format == format_arg))
|
---|
| 297 | return EOK;
|
---|
| 298 | if (channels)
|
---|
| 299 | *channels = channels_arg;
|
---|
| 300 | if (rate)
|
---|
| 301 | *rate = rate_arg;
|
---|
| 302 | if (format)
|
---|
| 303 | *format = format_arg;
|
---|
| 304 | return ret;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
[018ab50] | 307 | /**
|
---|
| 308 | * Register callback for device generated events.
|
---|
| 309 | *
|
---|
| 310 | * @param sess Audio device session.
|
---|
| 311 | * @param event_rec Event callback function.
|
---|
| 312 | * @param arg Event callback custom parameter.
|
---|
| 313 | *
|
---|
| 314 | * @return Error code.
|
---|
| 315 | */
|
---|
| 316 | int audio_pcm_register_event_callback(audio_pcm_sess_t *sess,
|
---|
[b688fd8] | 317 | async_port_handler_t event_callback, void *arg)
|
---|
[018ab50] | 318 | {
|
---|
| 319 | if (!event_callback)
|
---|
| 320 | return EINVAL;
|
---|
| 321 |
|
---|
| 322 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[f9b2cb4c] | 323 |
|
---|
[018ab50] | 324 | int ret = async_req_1_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 325 | IPC_M_AUDIO_PCM_REGISTER_EVENTS);
|
---|
| 326 | if (ret == EOK) {
|
---|
[f9b2cb4c] | 327 | port_id_t port;
|
---|
| 328 | ret = async_create_callback_port(exch, INTERFACE_AUDIO_PCM_CB, 0, 0,
|
---|
| 329 | event_callback, arg, &port);
|
---|
[018ab50] | 330 | }
|
---|
[f9b2cb4c] | 331 |
|
---|
[018ab50] | 332 | async_exchange_end(exch);
|
---|
| 333 | return ret;
|
---|
| 334 | }
|
---|
| 335 |
|
---|
| 336 | /**
|
---|
| 337 | * Unregister callback for device generated events.
|
---|
| 338 | *
|
---|
| 339 | * @param sess Audio device session.
|
---|
| 340 | *
|
---|
| 341 | * @return Error code.
|
---|
| 342 | */
|
---|
| 343 | int audio_pcm_unregister_event_callback(audio_pcm_sess_t *sess)
|
---|
| 344 | {
|
---|
| 345 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 346 | const int ret = async_req_1_0(exch,
|
---|
| 347 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 348 | IPC_M_AUDIO_PCM_UNREGISTER_EVENTS);
|
---|
| 349 | async_exchange_end(exch);
|
---|
| 350 | return ret;
|
---|
| 351 | }
|
---|
| 352 |
|
---|
[ad1aedc] | 353 | /**
|
---|
| 354 | * Get device accessible playback/capture buffer.
|
---|
| 355 | *
|
---|
| 356 | * @param sess Audio device session.
|
---|
| 357 | * @param buffer Place to store pointer to the buffer.
|
---|
| 358 | * @param size Place to store buffer size (bytes).
|
---|
| 359 | *
|
---|
| 360 | * @return Error code.
|
---|
| 361 | */
|
---|
[018ab50] | 362 | int audio_pcm_get_buffer(audio_pcm_sess_t *sess, void **buffer, size_t *size)
|
---|
[c09ad29e] | 363 | {
|
---|
[2cc5c835] | 364 | if (!buffer || !size)
|
---|
[c09ad29e] | 365 | return EINVAL;
|
---|
[00006e0] | 366 |
|
---|
[2cc5c835] | 367 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 368 |
|
---|
[b497018] | 369 | sysarg_t buffer_size = *size;
|
---|
[018ab50] | 370 | int ret = async_req_2_1(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 371 | IPC_M_AUDIO_PCM_GET_BUFFER, (sysarg_t)buffer_size, &buffer_size);
|
---|
[c09ad29e] | 372 | if (ret == EOK) {
|
---|
[722912e] | 373 | void *dst = NULL;
|
---|
[018ab50] | 374 | ret = async_share_in_start_0_0(exch, buffer_size, &dst);
|
---|
[8de7ef2] | 375 | if (ret != EOK) {
|
---|
[2cc5c835] | 376 | async_exchange_end(exch);
|
---|
[8de7ef2] | 377 | return ret;
|
---|
| 378 | }
|
---|
[c09ad29e] | 379 | *buffer = dst;
|
---|
| 380 | *size = buffer_size;
|
---|
[00006e0] | 381 | }
|
---|
[2cc5c835] | 382 | async_exchange_end(exch);
|
---|
[c09ad29e] | 383 | return ret;
|
---|
| 384 | }
|
---|
[4bbfb93] | 385 |
|
---|
[ad1aedc] | 386 | /**
|
---|
| 387 | * Release device accessible playback/capture buffer.
|
---|
| 388 | *
|
---|
| 389 | * @param sess Audio device session.
|
---|
| 390 | *
|
---|
| 391 | * @return Error code.
|
---|
| 392 | */
|
---|
[2cc5c835] | 393 | int audio_pcm_release_buffer(audio_pcm_sess_t *sess)
|
---|
[c09ad29e] | 394 | {
|
---|
[2cc5c835] | 395 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 396 | const int ret = async_req_1_0(exch,
|
---|
| 397 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
[b497018] | 398 | IPC_M_AUDIO_PCM_RELEASE_BUFFER);
|
---|
[2cc5c835] | 399 | async_exchange_end(exch);
|
---|
| 400 | return ret;
|
---|
[c09ad29e] | 401 | }
|
---|
[4bbfb93] | 402 |
|
---|
[ad1aedc] | 403 | /**
|
---|
| 404 | * Start playback on buffer from position 0.
|
---|
| 405 | *
|
---|
| 406 | * @param sess Audio device session.
|
---|
| 407 | * @param frames Size of fragment (in frames).
|
---|
| 408 | * @param channels Number of channels.
|
---|
| 409 | * @param sample_rate Sampling rate (for one channel).
|
---|
| 410 | * @param format Sample format.
|
---|
| 411 | *
|
---|
| 412 | * @return Error code.
|
---|
| 413 | *
|
---|
| 414 | * Event will be generated after every fragment. Set fragment size to
|
---|
| 415 | * 0 to turn off event generation.
|
---|
| 416 | */
|
---|
[92b638c] | 417 | int audio_pcm_start_playback_fragment(audio_pcm_sess_t *sess, unsigned frames,
|
---|
[346643c] | 418 | unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
|
---|
[c09ad29e] | 419 | {
|
---|
[57e8b3b] | 420 | if (channels > UINT16_MAX)
|
---|
[346643c] | 421 | return EINVAL;
|
---|
| 422 | assert((format & UINT16_MAX) == format);
|
---|
[57e8b3b] | 423 | const sysarg_t packed = (channels << 16) | (format & UINT16_MAX);
|
---|
[2cc5c835] | 424 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[57e8b3b] | 425 | const int ret = async_req_4_0(exch,
|
---|
[2cc5c835] | 426 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 427 | IPC_M_AUDIO_PCM_START_PLAYBACK,
|
---|
[57e8b3b] | 428 | frames, sample_rate, packed);
|
---|
[2cc5c835] | 429 | async_exchange_end(exch);
|
---|
| 430 | return ret;
|
---|
[c09ad29e] | 431 | }
|
---|
[92b638c] | 432 | /**
|
---|
| 433 | * Stops playback after current fragment.
|
---|
| 434 | *
|
---|
| 435 | * @param sess Audio device session.
|
---|
| 436 | *
|
---|
| 437 | * @return Error code.
|
---|
| 438 | */
|
---|
| 439 | int audio_pcm_last_playback_fragment(audio_pcm_sess_t *sess)
|
---|
| 440 | {
|
---|
| 441 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 442 | const int ret = async_req_2_0(exch,
|
---|
| 443 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 444 | IPC_M_AUDIO_PCM_STOP_PLAYBACK, false);
|
---|
| 445 | async_exchange_end(exch);
|
---|
| 446 | return ret;
|
---|
| 447 | }
|
---|
[4bbfb93] | 448 |
|
---|
[ad1aedc] | 449 | /**
|
---|
[92b638c] | 450 | * Start playback on buffer from the current position.
|
---|
| 451 | *
|
---|
| 452 | * @param sess Audio device session.
|
---|
| 453 | * @param channels Number of channels.
|
---|
| 454 | * @param sample_rate Sampling rate (for one channel).
|
---|
| 455 | * @param format Sample format.
|
---|
| 456 | *
|
---|
| 457 | * @return Error code.
|
---|
| 458 | */
|
---|
| 459 | int audio_pcm_start_playback(audio_pcm_sess_t *sess,
|
---|
| 460 | unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
|
---|
| 461 | {
|
---|
| 462 | return audio_pcm_start_playback_fragment(
|
---|
| 463 | sess, 0, channels, sample_rate, format);
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | /**
|
---|
| 467 | * Immediately stops current playback.
|
---|
[ad1aedc] | 468 | *
|
---|
| 469 | * @param sess Audio device session.
|
---|
| 470 | *
|
---|
| 471 | * @return Error code.
|
---|
| 472 | */
|
---|
[62310d7] | 473 | int audio_pcm_stop_playback_immediate(audio_pcm_sess_t *sess)
|
---|
[c09ad29e] | 474 | {
|
---|
[2cc5c835] | 475 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[92b638c] | 476 | const int ret = async_req_2_0(exch,
|
---|
[2cc5c835] | 477 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
[92b638c] | 478 | IPC_M_AUDIO_PCM_STOP_PLAYBACK, true);
|
---|
[2cc5c835] | 479 | async_exchange_end(exch);
|
---|
| 480 | return ret;
|
---|
[c09ad29e] | 481 | }
|
---|
[4bbfb93] | 482 |
|
---|
[62310d7] | 483 | /**
|
---|
| 484 | * Stops playback at the end of the current fragment.
|
---|
| 485 | *
|
---|
| 486 | * @param sess Audio device session.
|
---|
| 487 | *
|
---|
| 488 | * @return Error code.
|
---|
| 489 | */
|
---|
| 490 | int audio_pcm_stop_playback(audio_pcm_sess_t *sess)
|
---|
| 491 | {
|
---|
| 492 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 493 | const int ret = async_req_2_0(exch,
|
---|
| 494 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 495 | IPC_M_AUDIO_PCM_STOP_PLAYBACK, false);
|
---|
| 496 | async_exchange_end(exch);
|
---|
| 497 | return ret;
|
---|
| 498 | }
|
---|
| 499 |
|
---|
[ad1aedc] | 500 | /**
|
---|
[92b638c] | 501 | * Start capture on buffer from the current position.
|
---|
[ad1aedc] | 502 | *
|
---|
| 503 | * @param sess Audio device session.
|
---|
| 504 | * @param frames Size of fragment (in frames).
|
---|
| 505 | * @param channels Number of channels.
|
---|
| 506 | * @param sample_rate Sampling rate (for one channel).
|
---|
| 507 | * @param format Sample format.
|
---|
| 508 | *
|
---|
| 509 | * @return Error code.
|
---|
| 510 | *
|
---|
| 511 | * Event will be generated after every fragment. Set fragment size to
|
---|
| 512 | * 0 to turn off event generation.
|
---|
| 513 | */
|
---|
[92b638c] | 514 | int audio_pcm_start_capture_fragment(audio_pcm_sess_t *sess, unsigned frames,
|
---|
[346643c] | 515 | unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
|
---|
[c09ad29e] | 516 | {
|
---|
[57e8b3b] | 517 | if (channels > UINT16_MAX)
|
---|
[346643c] | 518 | return EINVAL;
|
---|
| 519 | assert((format & UINT16_MAX) == format);
|
---|
[57e8b3b] | 520 | const sysarg_t packed = (channels << 16) | (format & UINT16_MAX);
|
---|
[2cc5c835] | 521 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[57e8b3b] | 522 | const int ret = async_req_4_0(exch,
|
---|
[d86c9736] | 523 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_START_CAPTURE,
|
---|
[57e8b3b] | 524 | frames, sample_rate, packed);
|
---|
[2cc5c835] | 525 | async_exchange_end(exch);
|
---|
| 526 | return ret;
|
---|
[c09ad29e] | 527 | }
|
---|
[4bbfb93] | 528 |
|
---|
[ad1aedc] | 529 | /**
|
---|
[92b638c] | 530 | * Start capture on buffer from the current position.
|
---|
| 531 | *
|
---|
| 532 | * @param sess Audio device session.
|
---|
| 533 | * @param channels Number of channels.
|
---|
| 534 | * @param sample_rate Sampling rate (for one channel).
|
---|
| 535 | * @param format Sample format.
|
---|
| 536 | *
|
---|
| 537 | * @return Error code.
|
---|
| 538 | */
|
---|
| 539 | int audio_pcm_start_capture(audio_pcm_sess_t *sess,
|
---|
| 540 | unsigned channels, unsigned sample_rate, pcm_sample_format_t format)
|
---|
| 541 | {
|
---|
| 542 | return audio_pcm_start_capture_fragment(
|
---|
| 543 | sess, 0, channels, sample_rate, format);
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | /**
|
---|
| 547 | * Stops capture at the end of current fragment.
|
---|
| 548 | *
|
---|
| 549 | * Won't work if capture was started with fragment size 0.
|
---|
| 550 | * @param sess Audio device session.
|
---|
| 551 | *
|
---|
| 552 | * @return Error code.
|
---|
| 553 | */
|
---|
| 554 | int audio_pcm_last_capture_fragment(audio_pcm_sess_t *sess)
|
---|
| 555 | {
|
---|
| 556 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 557 | const int ret = async_req_2_0(exch,
|
---|
| 558 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 559 | IPC_M_AUDIO_PCM_STOP_CAPTURE, false);
|
---|
| 560 | async_exchange_end(exch);
|
---|
| 561 | return ret;
|
---|
| 562 | }
|
---|
| 563 |
|
---|
| 564 | /**
|
---|
| 565 | * Immediately stops current capture.
|
---|
[ad1aedc] | 566 | *
|
---|
| 567 | * @param sess Audio device session.
|
---|
| 568 | *
|
---|
| 569 | * @return Error code.
|
---|
| 570 | */
|
---|
[62310d7] | 571 | int audio_pcm_stop_capture_immediate(audio_pcm_sess_t *sess)
|
---|
[c09ad29e] | 572 | {
|
---|
[2cc5c835] | 573 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
[92b638c] | 574 | const int ret = async_req_2_0(exch,
|
---|
| 575 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 576 | IPC_M_AUDIO_PCM_STOP_CAPTURE, true);
|
---|
[2cc5c835] | 577 | async_exchange_end(exch);
|
---|
| 578 | return ret;
|
---|
[c09ad29e] | 579 | }
|
---|
| 580 |
|
---|
[62310d7] | 581 | /**
|
---|
| 582 | * Stops capture at the end of the current fragment.
|
---|
| 583 | *
|
---|
| 584 | * @param sess Audio device session.
|
---|
| 585 | *
|
---|
| 586 | * @return Error code.
|
---|
| 587 | */
|
---|
| 588 | int audio_pcm_stop_capture(audio_pcm_sess_t *sess)
|
---|
| 589 | {
|
---|
| 590 | async_exch_t *exch = async_exchange_begin(sess);
|
---|
| 591 | const int ret = async_req_2_0(exch,
|
---|
| 592 | DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
|
---|
| 593 | IPC_M_AUDIO_PCM_STOP_CAPTURE, false);
|
---|
| 594 | async_exchange_end(exch);
|
---|
| 595 | return ret;
|
---|
| 596 | }
|
---|
| 597 |
|
---|
[c09ad29e] | 598 | /*
|
---|
| 599 | * SERVER SIDE
|
---|
| 600 | */
|
---|
| 601 | static void remote_audio_pcm_get_info_str(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[2e01b3f] | 602 | static void remote_audio_pcm_query_caps(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[018ab50] | 603 | static void remote_audio_pcm_events_register(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 604 | static void remote_audio_pcm_events_unregister(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[fa91c0f] | 605 | static void remote_audio_pcm_get_buffer_pos(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[63c34d7] | 606 | static void remote_audio_pcm_test_format(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[c09ad29e] | 607 | static void remote_audio_pcm_get_buffer(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 608 | static void remote_audio_pcm_release_buffer(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 609 | static void remote_audio_pcm_start_playback(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 610 | static void remote_audio_pcm_stop_playback(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[d86c9736] | 611 | static void remote_audio_pcm_start_capture(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
| 612 | static void remote_audio_pcm_stop_capture(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
|
---|
[c09ad29e] | 613 |
|
---|
| 614 | /** Remote audio pcm buffer interface operations. */
|
---|
[9be30cdf] | 615 | static const remote_iface_func_ptr_t remote_audio_pcm_iface_ops[] = {
|
---|
[c09ad29e] | 616 | [IPC_M_AUDIO_PCM_GET_INFO_STR] = remote_audio_pcm_get_info_str,
|
---|
[2e01b3f] | 617 | [IPC_M_AUDIO_PCM_QUERY_CAPS] = remote_audio_pcm_query_caps,
|
---|
[018ab50] | 618 | [IPC_M_AUDIO_PCM_REGISTER_EVENTS] = remote_audio_pcm_events_register,
|
---|
| 619 | [IPC_M_AUDIO_PCM_UNREGISTER_EVENTS] = remote_audio_pcm_events_unregister,
|
---|
[fa91c0f] | 620 | [IPC_M_AUDIO_PCM_GET_BUFFER_POS] = remote_audio_pcm_get_buffer_pos,
|
---|
[63c34d7] | 621 | [IPC_M_AUDIO_PCM_TEST_FORMAT] = remote_audio_pcm_test_format,
|
---|
[c09ad29e] | 622 | [IPC_M_AUDIO_PCM_GET_BUFFER] = remote_audio_pcm_get_buffer,
|
---|
| 623 | [IPC_M_AUDIO_PCM_RELEASE_BUFFER] = remote_audio_pcm_release_buffer,
|
---|
| 624 | [IPC_M_AUDIO_PCM_START_PLAYBACK] = remote_audio_pcm_start_playback,
|
---|
| 625 | [IPC_M_AUDIO_PCM_STOP_PLAYBACK] = remote_audio_pcm_stop_playback,
|
---|
[d86c9736] | 626 | [IPC_M_AUDIO_PCM_START_CAPTURE] = remote_audio_pcm_start_capture,
|
---|
| 627 | [IPC_M_AUDIO_PCM_STOP_CAPTURE] = remote_audio_pcm_stop_capture,
|
---|
[c09ad29e] | 628 | };
|
---|
| 629 |
|
---|
| 630 | /** Remote audio mixer interface structure. */
|
---|
[7f80313] | 631 | const remote_iface_t remote_audio_pcm_iface = {
|
---|
[9be30cdf] | 632 | .method_count = ARRAY_SIZE(remote_audio_pcm_iface_ops),
|
---|
[c09ad29e] | 633 | .methods = remote_audio_pcm_iface_ops
|
---|
| 634 | };
|
---|
[4bbfb93] | 635 |
|
---|
[c09ad29e] | 636 | void remote_audio_pcm_get_info_str(ddf_fun_t *fun, void *iface,
|
---|
| 637 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 638 | {
|
---|
[90f05b0f] | 639 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
[c09ad29e] | 640 |
|
---|
| 641 | if (!pcm_iface->get_info_str) {
|
---|
| 642 | async_answer_0(callid, ENOTSUP);
|
---|
| 643 | return;
|
---|
| 644 | }
|
---|
| 645 | const char *name = NULL;
|
---|
| 646 | const int ret = pcm_iface->get_info_str(fun, &name);
|
---|
| 647 | const size_t name_size = name ? str_size(name) + 1 : 0;
|
---|
| 648 | async_answer_1(callid, ret, name_size);
|
---|
| 649 | /* Send the string. */
|
---|
| 650 | if (ret == EOK && name_size > 0) {
|
---|
| 651 | size_t size;
|
---|
| 652 | ipc_callid_t name_id;
|
---|
| 653 | if (!async_data_read_receive(&name_id, &size)) {
|
---|
| 654 | async_answer_0(name_id, EPARTY);
|
---|
| 655 | return;
|
---|
| 656 | }
|
---|
| 657 | if (size != name_size) {
|
---|
| 658 | async_answer_0(name_id, ELIMIT);
|
---|
| 659 | return;
|
---|
| 660 | }
|
---|
| 661 | async_data_read_finalize(name_id, name, name_size);
|
---|
| 662 | }
|
---|
| 663 | }
|
---|
[4bbfb93] | 664 |
|
---|
[2e01b3f] | 665 | void remote_audio_pcm_query_caps(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 666 | {
|
---|
| 667 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
| 668 | const audio_cap_t cap = DEV_IPC_GET_ARG1(*call);
|
---|
| 669 | if (pcm_iface->query_cap) {
|
---|
| 670 | const unsigned value = pcm_iface->query_cap(fun, cap);
|
---|
| 671 | async_answer_1(callid, EOK, value);
|
---|
| 672 | } else {
|
---|
| 673 | async_answer_0(callid, ENOTSUP);
|
---|
| 674 | }
|
---|
| 675 | }
|
---|
[018ab50] | 676 |
|
---|
| 677 | static void remote_audio_pcm_events_register(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 678 | {
|
---|
| 679 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
| 680 | if (!pcm_iface->get_event_session ||
|
---|
| 681 | !pcm_iface->set_event_session) {
|
---|
| 682 | async_answer_0(callid, ENOTSUP);
|
---|
| 683 | return;
|
---|
| 684 | }
|
---|
| 685 |
|
---|
| 686 | async_answer_0(callid, EOK);
|
---|
| 687 |
|
---|
| 688 | ipc_call_t callback_call;
|
---|
| 689 | ipc_callid_t callback_id = async_get_call(&callback_call);
|
---|
| 690 | async_sess_t *sess =
|
---|
| 691 | async_callback_receive_start(EXCHANGE_ATOMIC, &callback_call);
|
---|
| 692 | if (sess == NULL) {
|
---|
| 693 | ddf_msg(LVL_DEBUG, "Failed to create event callback");
|
---|
| 694 | async_answer_0(callback_id, EAGAIN);
|
---|
| 695 | return;
|
---|
| 696 | }
|
---|
| 697 | const int ret = pcm_iface->set_event_session(fun, sess);
|
---|
| 698 | if (ret != EOK) {
|
---|
| 699 | ddf_msg(LVL_DEBUG, "Failed to set event callback.");
|
---|
| 700 | async_hangup(sess);
|
---|
| 701 | async_answer_0(callback_id, ret);
|
---|
| 702 | return;
|
---|
| 703 | }
|
---|
| 704 | async_answer_0(callback_id, EOK);
|
---|
| 705 | }
|
---|
| 706 |
|
---|
| 707 | static void remote_audio_pcm_events_unregister(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 708 | {
|
---|
| 709 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
| 710 | if (!pcm_iface->get_event_session ||
|
---|
| 711 | !pcm_iface->set_event_session) {
|
---|
| 712 | async_answer_0(callid, ENOTSUP);
|
---|
| 713 | return;
|
---|
| 714 | }
|
---|
| 715 | async_sess_t *sess = pcm_iface->get_event_session(fun);
|
---|
| 716 | if (sess) {
|
---|
| 717 | async_hangup(sess);
|
---|
| 718 | pcm_iface->set_event_session(fun, NULL);
|
---|
| 719 | }
|
---|
| 720 | async_answer_0(callid, EOK);
|
---|
| 721 | }
|
---|
| 722 |
|
---|
[fa91c0f] | 723 | void remote_audio_pcm_get_buffer_pos(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
| 724 | {
|
---|
| 725 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
| 726 | size_t pos = 0;
|
---|
| 727 | const int ret = pcm_iface->get_buffer_pos ?
|
---|
| 728 | pcm_iface->get_buffer_pos(fun, &pos) : ENOTSUP;
|
---|
| 729 | async_answer_1(callid, ret, pos);
|
---|
| 730 | }
|
---|
[2e01b3f] | 731 |
|
---|
| 732 | void remote_audio_pcm_test_format(ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
|
---|
[63c34d7] | 733 | {
|
---|
| 734 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
| 735 | unsigned channels = DEV_IPC_GET_ARG1(*call);
|
---|
| 736 | unsigned rate = DEV_IPC_GET_ARG2(*call);
|
---|
| 737 | pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call);
|
---|
| 738 | const int ret = pcm_iface->test_format ?
|
---|
| 739 | pcm_iface->test_format(fun, &channels, &rate, &format) : ENOTSUP;
|
---|
| 740 | async_answer_3(callid, ret, channels, rate, format);
|
---|
| 741 | }
|
---|
| 742 |
|
---|
[c09ad29e] | 743 | void remote_audio_pcm_get_buffer(ddf_fun_t *fun, void *iface,
|
---|
| 744 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 745 | {
|
---|
[90f05b0f] | 746 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
[c09ad29e] | 747 |
|
---|
[8de7ef2] | 748 | if (!pcm_iface->get_buffer ||
|
---|
[018ab50] | 749 | !pcm_iface->release_buffer) {
|
---|
[c09ad29e] | 750 | async_answer_0(callid, ENOTSUP);
|
---|
| 751 | return;
|
---|
| 752 | }
|
---|
| 753 | void *buffer = NULL;
|
---|
[00006e0] | 754 | size_t size = DEV_IPC_GET_ARG1(*call);
|
---|
[b497018] | 755 | int ret = pcm_iface->get_buffer(fun, &buffer, &size);
|
---|
| 756 | async_answer_1(callid, ret, size);
|
---|
[8de7ef2] | 757 | if (ret != EOK || size == 0)
|
---|
| 758 | return;
|
---|
| 759 |
|
---|
[c09ad29e] | 760 | /* Share the buffer. */
|
---|
[8de7ef2] | 761 | size_t share_size = 0;
|
---|
| 762 | ipc_callid_t share_id = 0;
|
---|
[7364c6ee] | 763 |
|
---|
| 764 | ddf_msg(LVL_DEBUG2, "Receiving share request.");
|
---|
[8de7ef2] | 765 | if (!async_share_in_receive(&share_id, &share_size)) {
|
---|
| 766 | ddf_msg(LVL_DEBUG, "Failed to share pcm buffer.");
|
---|
[b497018] | 767 | pcm_iface->release_buffer(fun);
|
---|
[8de7ef2] | 768 | async_answer_0(share_id, EPARTY);
|
---|
| 769 | return;
|
---|
| 770 | }
|
---|
[7364c6ee] | 771 |
|
---|
| 772 | ddf_msg(LVL_DEBUG2, "Checking requested share size.");
|
---|
[8de7ef2] | 773 | if (share_size != size) {
|
---|
| 774 | ddf_msg(LVL_DEBUG, "Incorrect pcm buffer size requested.");
|
---|
[b497018] | 775 | pcm_iface->release_buffer(fun);
|
---|
[8de7ef2] | 776 | async_answer_0(share_id, ELIMIT);
|
---|
| 777 | return;
|
---|
| 778 | }
|
---|
[7364c6ee] | 779 |
|
---|
| 780 | ddf_msg(LVL_DEBUG2, "Calling share finalize.");
|
---|
| 781 | ret = async_share_in_finalize(share_id, buffer, AS_AREA_WRITE
|
---|
| 782 | | AS_AREA_READ);
|
---|
[8de7ef2] | 783 | if (ret != EOK) {
|
---|
[7364c6ee] | 784 | ddf_msg(LVL_DEBUG, "Failed to share buffer.");
|
---|
[b497018] | 785 | pcm_iface->release_buffer(fun);
|
---|
[8de7ef2] | 786 | return;
|
---|
| 787 | }
|
---|
[7364c6ee] | 788 |
|
---|
[018ab50] | 789 | ddf_msg(LVL_DEBUG2, "Buffer shared with size %zu.", share_size);
|
---|
[c09ad29e] | 790 | }
|
---|
[4bbfb93] | 791 |
|
---|
[c09ad29e] | 792 | void remote_audio_pcm_release_buffer(ddf_fun_t *fun, void *iface,
|
---|
| 793 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 794 | {
|
---|
[90f05b0f] | 795 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
[c09ad29e] | 796 |
|
---|
| 797 | const int ret = pcm_iface->release_buffer ?
|
---|
[b497018] | 798 | pcm_iface->release_buffer(fun) : ENOTSUP;
|
---|
[c09ad29e] | 799 | async_answer_0(callid, ret);
|
---|
| 800 | }
|
---|
[4bbfb93] | 801 |
|
---|
[c09ad29e] | 802 | void remote_audio_pcm_start_playback(ddf_fun_t *fun, void *iface,
|
---|
| 803 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 804 | {
|
---|
[90f05b0f] | 805 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
[c09ad29e] | 806 |
|
---|
[57e8b3b] | 807 | const unsigned frames = DEV_IPC_GET_ARG1(*call);
|
---|
| 808 | const unsigned rate = DEV_IPC_GET_ARG2(*call);
|
---|
| 809 | const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT8_MAX;
|
---|
| 810 | const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX;
|
---|
[c09ad29e] | 811 |
|
---|
| 812 | const int ret = pcm_iface->start_playback
|
---|
[57e8b3b] | 813 | ? pcm_iface->start_playback(fun, frames, channels, rate, format)
|
---|
[c09ad29e] | 814 | : ENOTSUP;
|
---|
| 815 | async_answer_0(callid, ret);
|
---|
| 816 | }
|
---|
[4bbfb93] | 817 |
|
---|
[c09ad29e] | 818 | void remote_audio_pcm_stop_playback(ddf_fun_t *fun, void *iface,
|
---|
| 819 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 820 | {
|
---|
[90f05b0f] | 821 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
[92b638c] | 822 | const bool immediate = DEV_IPC_GET_ARG1(*call);
|
---|
[c09ad29e] | 823 |
|
---|
| 824 | const int ret = pcm_iface->stop_playback ?
|
---|
[92b638c] | 825 | pcm_iface->stop_playback(fun, immediate) : ENOTSUP;
|
---|
[c09ad29e] | 826 | async_answer_0(callid, ret);
|
---|
| 827 | }
|
---|
[4bbfb93] | 828 |
|
---|
[d86c9736] | 829 | void remote_audio_pcm_start_capture(ddf_fun_t *fun, void *iface,
|
---|
[c09ad29e] | 830 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 831 | {
|
---|
[90f05b0f] | 832 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
[c09ad29e] | 833 |
|
---|
[57e8b3b] | 834 | const unsigned frames = DEV_IPC_GET_ARG1(*call);
|
---|
| 835 | const unsigned rate = DEV_IPC_GET_ARG2(*call);
|
---|
| 836 | const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 16) & UINT16_MAX;
|
---|
| 837 | const pcm_sample_format_t format = DEV_IPC_GET_ARG3(*call) & UINT16_MAX;
|
---|
[c09ad29e] | 838 |
|
---|
[d86c9736] | 839 | const int ret = pcm_iface->start_capture
|
---|
| 840 | ? pcm_iface->start_capture(fun, frames, channels, rate, format)
|
---|
[c09ad29e] | 841 | : ENOTSUP;
|
---|
| 842 | async_answer_0(callid, ret);
|
---|
| 843 | }
|
---|
[4bbfb93] | 844 |
|
---|
[d86c9736] | 845 | void remote_audio_pcm_stop_capture(ddf_fun_t *fun, void *iface,
|
---|
[c09ad29e] | 846 | ipc_callid_t callid, ipc_call_t *call)
|
---|
| 847 | {
|
---|
[90f05b0f] | 848 | const audio_pcm_iface_t *pcm_iface = iface;
|
---|
[92b638c] | 849 | const bool immediate = DEV_IPC_GET_ARG1(*call);
|
---|
[c09ad29e] | 850 |
|
---|
[d86c9736] | 851 | const int ret = pcm_iface->stop_capture ?
|
---|
[92b638c] | 852 | pcm_iface->stop_capture(fun, immediate) : ENOTSUP;
|
---|
[c09ad29e] | 853 | async_answer_0(callid, ret);
|
---|
| 854 | }
|
---|
| 855 |
|
---|
| 856 | /**
|
---|
| 857 | * @}
|
---|
| 858 | */
|
---|
| 859 |
|
---|