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