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