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