[53a7fda] | 1 | /*
|
---|
| 2 | * Copyright (c) 2011 Jan Vesely
|
---|
| 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 |
|
---|
| 29 | /** @addtogroup libdrv
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #include <async.h>
|
---|
| 36 | #include <errno.h>
|
---|
| 37 | #include <assert.h>
|
---|
| 38 | #include <str.h>
|
---|
[9be30cdf] | 39 | #include <macros.h>
|
---|
[53a7fda] | 40 |
|
---|
| 41 | #include "audio_mixer_iface.h"
|
---|
| 42 | #include "ddf/driver.h"
|
---|
| 43 |
|
---|
| 44 | typedef enum {
|
---|
| 45 | /** Asks for basic mixer info: Mixer name and number of controllable
|
---|
| 46 | * items.
|
---|
| 47 | * Answer:
|
---|
| 48 | * - ENOTSUP - call not supported
|
---|
| 49 | * - EOK - call successful, info is valid
|
---|
| 50 | * Answer arguments:
|
---|
| 51 | * - Mixer name
|
---|
| 52 | * - Number of controllable items
|
---|
| 53 | */
|
---|
| 54 | IPC_M_AUDIO_MIXER_GET_INFO,
|
---|
| 55 |
|
---|
| 56 | /** Asks for item mixer info: Item name and number of controllable
|
---|
| 57 | * channels.
|
---|
| 58 | * Answer:
|
---|
| 59 | * - ENOTSUP - call not supported
|
---|
| 60 | * - ENOENT - no such item
|
---|
| 61 | * - EOK - call successful, info is valid
|
---|
| 62 | * Answer arguments:
|
---|
| 63 | * - Item name
|
---|
| 64 | * - Number of controllable channels
|
---|
| 65 | */
|
---|
| 66 | IPC_M_AUDIO_MIXER_GET_ITEM_INFO,
|
---|
| 67 |
|
---|
[1912b45] | 68 | /** Set new control item setting
|
---|
[53a7fda] | 69 | * Answer:
|
---|
| 70 | * - ENOTSUP - call not supported
|
---|
[1912b45] | 71 | * - ENOENT - no such control item
|
---|
[53a7fda] | 72 | * - EOK - call successful, info is valid
|
---|
| 73 | */
|
---|
[1912b45] | 74 | IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL,
|
---|
[53a7fda] | 75 |
|
---|
[1912b45] | 76 | /** Get control item setting
|
---|
[53a7fda] | 77 | * Answer:
|
---|
| 78 | * - ENOTSUP - call not supported
|
---|
[1912b45] | 79 | * - ENOENT - no such control item
|
---|
[53a7fda] | 80 | * - EOK - call successful, info is valid
|
---|
| 81 | */
|
---|
[1912b45] | 82 | IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL,
|
---|
[53a7fda] | 83 | } audio_mixer_iface_funcs_t;
|
---|
| 84 |
|
---|
| 85 | /*
|
---|
| 86 | * CLIENT SIDE
|
---|
| 87 | */
|
---|
[8a7d78cc] | 88 |
|
---|
| 89 | /**
|
---|
| 90 | * Query audio mixer for basic info (name and items count).
|
---|
| 91 | * @param[in] exch IPC exchange connected to the device
|
---|
| 92 | * @param[out] name Audio mixer string identifier
|
---|
| 93 | * @param[out] items Number of items controlled by the mixer.
|
---|
| 94 | * @return Error code.
|
---|
| 95 | */
|
---|
[33b8d024] | 96 | errno_t audio_mixer_get_info(async_exch_t *exch, char **name, unsigned *items)
|
---|
[53a7fda] | 97 | {
|
---|
| 98 | if (!exch)
|
---|
| 99 | return EINVAL;
|
---|
| 100 | sysarg_t name_size, itemc;
|
---|
[b7fd2a0] | 101 | const errno_t ret = async_req_1_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
|
---|
[53a7fda] | 102 | IPC_M_AUDIO_MIXER_GET_INFO, &name_size, &itemc);
|
---|
| 103 | if (ret == EOK && name) {
|
---|
| 104 | char *name_place = calloc(1, name_size);
|
---|
| 105 | if (!name_place) {
|
---|
[7c3fb9b] | 106 | /*
|
---|
| 107 | * Make the other side fail
|
---|
| 108 | * as it waits for read request
|
---|
| 109 | */
|
---|
[1433ecda] | 110 | async_data_read_start(exch, (void *)-1, 0);
|
---|
[53a7fda] | 111 | return ENOMEM;
|
---|
| 112 | }
|
---|
[b7fd2a0] | 113 | const errno_t ret =
|
---|
[53a7fda] | 114 | async_data_read_start(exch, name_place, name_size);
|
---|
| 115 | if (ret != EOK) {
|
---|
| 116 | free(name_place);
|
---|
| 117 | return ret;
|
---|
| 118 | }
|
---|
| 119 | *name = name_place;
|
---|
| 120 | }
|
---|
| 121 | if (ret == EOK && items)
|
---|
| 122 | *items = itemc;
|
---|
| 123 | return ret;
|
---|
| 124 | }
|
---|
[4bbfb93] | 125 |
|
---|
[8a7d78cc] | 126 | /**
|
---|
| 127 | * Query audio mixer for item specific info (name and channels count).
|
---|
| 128 | * @param[in] exch IPC exchange connected to the device
|
---|
| 129 | * @param[in] item The control item
|
---|
| 130 | * @param[out] name Control item string identifier.
|
---|
| 131 | * @param[out] channles Number of channels associated with this control item.
|
---|
| 132 | * @return Error code.
|
---|
| 133 | */
|
---|
[b7fd2a0] | 134 | errno_t audio_mixer_get_item_info(async_exch_t *exch, unsigned item,
|
---|
[33b8d024] | 135 | char **name, unsigned *levels)
|
---|
[53a7fda] | 136 | {
|
---|
| 137 | if (!exch)
|
---|
| 138 | return EINVAL;
|
---|
[1912b45] | 139 | sysarg_t name_size, lvls;
|
---|
[b7fd2a0] | 140 | const errno_t ret = async_req_2_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
|
---|
[1912b45] | 141 | IPC_M_AUDIO_MIXER_GET_ITEM_INFO, item, &name_size, &lvls);
|
---|
[53a7fda] | 142 | if (ret == EOK && name) {
|
---|
| 143 | char *name_place = calloc(1, name_size);
|
---|
| 144 | if (!name_place) {
|
---|
[7c3fb9b] | 145 | /*
|
---|
| 146 | * Make the other side fail
|
---|
| 147 | * as it waits for read request
|
---|
| 148 | */
|
---|
[1433ecda] | 149 | async_data_read_start(exch, (void *)-1, 0);
|
---|
[53a7fda] | 150 | return ENOMEM;
|
---|
| 151 | }
|
---|
[b7fd2a0] | 152 | const errno_t ret =
|
---|
[53a7fda] | 153 | async_data_read_start(exch, name_place, name_size);
|
---|
| 154 | if (ret != EOK) {
|
---|
| 155 | free(name_place);
|
---|
| 156 | return ret;
|
---|
| 157 | }
|
---|
| 158 | *name = name_place;
|
---|
| 159 | }
|
---|
[1912b45] | 160 | if (ret == EOK && levels)
|
---|
| 161 | *levels = lvls;
|
---|
[53a7fda] | 162 | return ret;
|
---|
| 163 | }
|
---|
[4bbfb93] | 164 |
|
---|
[8a7d78cc] | 165 | /**
|
---|
[1912b45] | 166 | * Set control item to a new level.
|
---|
[8a7d78cc] | 167 | * @param[in] exch IPC exchange connected to the device.
|
---|
| 168 | * @param[in] item The control item controlling the channel.
|
---|
[1912b45] | 169 | * @param[in] level The new value.
|
---|
[8a7d78cc] | 170 | * @return Error code.
|
---|
| 171 | */
|
---|
[b7fd2a0] | 172 | errno_t audio_mixer_set_item_level(async_exch_t *exch, unsigned item,
|
---|
[1912b45] | 173 | unsigned level)
|
---|
[53a7fda] | 174 | {
|
---|
| 175 | if (!exch)
|
---|
| 176 | return EINVAL;
|
---|
[1912b45] | 177 | return async_req_3_0(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
|
---|
| 178 | IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL, item, level);
|
---|
[53a7fda] | 179 | }
|
---|
[4bbfb93] | 180 |
|
---|
[8a7d78cc] | 181 | /**
|
---|
[1912b45] | 182 | * Get current level of a control item.
|
---|
[8a7d78cc] | 183 | * @param[in] exch IPC exchange connected to the device.
|
---|
| 184 | * @param[in] item The control item controlling the channel.
|
---|
| 185 | * @param[in] channel The channel index.
|
---|
[1912b45] | 186 | * @param[out] level Currently set value.
|
---|
[8a7d78cc] | 187 | * @return Error code.
|
---|
| 188 | */
|
---|
[b7fd2a0] | 189 | errno_t audio_mixer_get_item_level(async_exch_t *exch, unsigned item,
|
---|
[1912b45] | 190 | unsigned *level)
|
---|
[53a7fda] | 191 | {
|
---|
| 192 | if (!exch)
|
---|
| 193 | return EINVAL;
|
---|
[1912b45] | 194 | sysarg_t current;
|
---|
[b7fd2a0] | 195 | const errno_t ret = async_req_2_1(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE),
|
---|
[1912b45] | 196 | IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL, item, ¤t);
|
---|
| 197 | if (ret == EOK && level)
|
---|
| 198 | *level = current;
|
---|
[53a7fda] | 199 | return ret;
|
---|
| 200 | }
|
---|
| 201 |
|
---|
| 202 | /*
|
---|
| 203 | * SERVER SIDE
|
---|
| 204 | */
|
---|
[984a9ba] | 205 | static void remote_audio_mixer_get_info(ddf_fun_t *, void *, ipc_call_t *);
|
---|
| 206 | static void remote_audio_mixer_get_item_info(ddf_fun_t *, void *, ipc_call_t *);
|
---|
| 207 | static void remote_audio_mixer_get_item_level(ddf_fun_t *, void *, ipc_call_t *);
|
---|
| 208 | static void remote_audio_mixer_set_item_level(ddf_fun_t *, void *, ipc_call_t *);
|
---|
[53a7fda] | 209 |
|
---|
| 210 | /** Remote audio mixer interface operations. */
|
---|
[9be30cdf] | 211 | static const remote_iface_func_ptr_t remote_audio_mixer_iface_ops[] = {
|
---|
[53a7fda] | 212 | [IPC_M_AUDIO_MIXER_GET_INFO] = remote_audio_mixer_get_info,
|
---|
| 213 | [IPC_M_AUDIO_MIXER_GET_ITEM_INFO] = remote_audio_mixer_get_item_info,
|
---|
[1912b45] | 214 | [IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL] = remote_audio_mixer_get_item_level,
|
---|
| 215 | [IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL] = remote_audio_mixer_set_item_level,
|
---|
[53a7fda] | 216 | };
|
---|
| 217 |
|
---|
| 218 | /** Remote audio mixer interface structure. */
|
---|
[7f80313] | 219 | const remote_iface_t remote_audio_mixer_iface = {
|
---|
[9be30cdf] | 220 | .method_count = ARRAY_SIZE(remote_audio_mixer_iface_ops),
|
---|
[53a7fda] | 221 | .methods = remote_audio_mixer_iface_ops
|
---|
| 222 | };
|
---|
[4bbfb93] | 223 |
|
---|
[984a9ba] | 224 | void remote_audio_mixer_get_info(ddf_fun_t *fun, void *iface, ipc_call_t *icall)
|
---|
[53a7fda] | 225 | {
|
---|
| 226 | audio_mixer_iface_t *mixer_iface = iface;
|
---|
| 227 |
|
---|
| 228 | if (!mixer_iface->get_info) {
|
---|
[984a9ba] | 229 | async_answer_0(icall, ENOTSUP);
|
---|
[53a7fda] | 230 | return;
|
---|
| 231 | }
|
---|
[984a9ba] | 232 |
|
---|
[53a7fda] | 233 | const char *name = NULL;
|
---|
| 234 | unsigned items = 0;
|
---|
[b7fd2a0] | 235 | const errno_t ret = mixer_iface->get_info(fun, &name, &items);
|
---|
[53a7fda] | 236 | const size_t name_size = name ? str_size(name) + 1 : 0;
|
---|
[984a9ba] | 237 | async_answer_2(icall, ret, name_size, items);
|
---|
| 238 |
|
---|
[53a7fda] | 239 | /* Send the name. */
|
---|
| 240 | if (ret == EOK && name_size > 0) {
|
---|
[984a9ba] | 241 | ipc_call_t call;
|
---|
[53a7fda] | 242 | size_t size;
|
---|
[984a9ba] | 243 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 244 | async_answer_0(&call, EPARTY);
|
---|
[53a7fda] | 245 | return;
|
---|
| 246 | }
|
---|
[984a9ba] | 247 |
|
---|
[53a7fda] | 248 | if (size != name_size) {
|
---|
[984a9ba] | 249 | async_answer_0(&call, ELIMIT);
|
---|
[53a7fda] | 250 | return;
|
---|
| 251 | }
|
---|
[984a9ba] | 252 |
|
---|
| 253 | async_data_read_finalize(&call, name, name_size);
|
---|
[53a7fda] | 254 | }
|
---|
| 255 | }
|
---|
[4bbfb93] | 256 |
|
---|
[984a9ba] | 257 | void remote_audio_mixer_get_item_info(ddf_fun_t *fun, void *iface,
|
---|
| 258 | ipc_call_t *icall)
|
---|
[53a7fda] | 259 | {
|
---|
| 260 | audio_mixer_iface_t *mixer_iface = iface;
|
---|
| 261 |
|
---|
| 262 | if (!mixer_iface->get_item_info) {
|
---|
[984a9ba] | 263 | async_answer_0(icall, ENOTSUP);
|
---|
[53a7fda] | 264 | return;
|
---|
| 265 | }
|
---|
| 266 |
|
---|
[984a9ba] | 267 | const unsigned item = DEV_IPC_GET_ARG1(*icall);
|
---|
[53a7fda] | 268 | const char *name = NULL;
|
---|
[1912b45] | 269 | unsigned values = 0;
|
---|
[b7fd2a0] | 270 | const errno_t ret = mixer_iface->get_item_info(fun, item, &name, &values);
|
---|
[53a7fda] | 271 | const size_t name_size = name ? str_size(name) + 1 : 0;
|
---|
[984a9ba] | 272 | async_answer_2(icall, ret, name_size, values);
|
---|
| 273 |
|
---|
[53a7fda] | 274 | /* Send the name. */
|
---|
| 275 | if (ret == EOK && name_size > 0) {
|
---|
[984a9ba] | 276 | ipc_call_t call;
|
---|
[53a7fda] | 277 | size_t size;
|
---|
[984a9ba] | 278 | if (!async_data_read_receive(&call, &size)) {
|
---|
| 279 | async_answer_0(&call, EPARTY);
|
---|
[53a7fda] | 280 | return;
|
---|
| 281 | }
|
---|
[984a9ba] | 282 |
|
---|
[53a7fda] | 283 | if (size != name_size) {
|
---|
[984a9ba] | 284 | async_answer_0(&call, ELIMIT);
|
---|
[53a7fda] | 285 | return;
|
---|
| 286 | }
|
---|
[984a9ba] | 287 |
|
---|
| 288 | async_data_read_finalize(&call, name, name_size);
|
---|
[53a7fda] | 289 | }
|
---|
| 290 | }
|
---|
[4bbfb93] | 291 |
|
---|
[984a9ba] | 292 | void remote_audio_mixer_set_item_level(ddf_fun_t *fun, void *iface,
|
---|
| 293 | ipc_call_t *icall)
|
---|
[53a7fda] | 294 | {
|
---|
| 295 | audio_mixer_iface_t *mixer_iface = iface;
|
---|
| 296 |
|
---|
[1912b45] | 297 | if (!mixer_iface->set_item_level) {
|
---|
[984a9ba] | 298 | async_answer_0(icall, ENOTSUP);
|
---|
[53a7fda] | 299 | return;
|
---|
| 300 | }
|
---|
[984a9ba] | 301 |
|
---|
| 302 | const unsigned item = DEV_IPC_GET_ARG1(*icall);
|
---|
| 303 | const unsigned value = DEV_IPC_GET_ARG2(*icall);
|
---|
[b7fd2a0] | 304 | const errno_t ret = mixer_iface->set_item_level(fun, item, value);
|
---|
[984a9ba] | 305 | async_answer_0(icall, ret);
|
---|
[53a7fda] | 306 | }
|
---|
[4bbfb93] | 307 |
|
---|
[984a9ba] | 308 | void remote_audio_mixer_get_item_level(ddf_fun_t *fun, void *iface,
|
---|
| 309 | ipc_call_t *icall)
|
---|
[53a7fda] | 310 | {
|
---|
| 311 | audio_mixer_iface_t *mixer_iface = iface;
|
---|
| 312 |
|
---|
[1912b45] | 313 | if (!mixer_iface->get_item_level) {
|
---|
[984a9ba] | 314 | async_answer_0(icall, ENOTSUP);
|
---|
[53a7fda] | 315 | return;
|
---|
| 316 | }
|
---|
[984a9ba] | 317 |
|
---|
| 318 | const unsigned item = DEV_IPC_GET_ARG1(*icall);
|
---|
[1912b45] | 319 | unsigned current = 0;
|
---|
[b7fd2a0] | 320 | const errno_t ret =
|
---|
[1912b45] | 321 | mixer_iface->get_item_level(fun, item, ¤t);
|
---|
[984a9ba] | 322 | async_answer_1(icall, ret, current);
|
---|
[53a7fda] | 323 | }
|
---|
| 324 |
|
---|
| 325 | /**
|
---|
| 326 | * @}
|
---|
| 327 | */
|
---|