Changeset 1912b45 in mainline for uspace/lib/drv/generic/remote_audio_mixer.c
- Timestamp:
- 2013-04-10T20:52:26Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5b77efc
- Parents:
- 8a7d78cc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/drv/generic/remote_audio_mixer.c
r8a7d78cc r1912b45 65 65 IPC_M_AUDIO_MIXER_GET_ITEM_INFO, 66 66 67 /** Asks for channel name and number of volume levels.67 /** Set new control item setting 68 68 * Answer: 69 69 * - ENOTSUP - call not supported 70 * - ENOENT - no such c hannel70 * - ENOENT - no such control item 71 71 * - EOK - call successful, info is valid 72 * Answer arguments:73 * - Channel name74 * - Volume levels75 72 */ 76 IPC_M_AUDIO_MIXER_ GET_CHANNEL_INFO,77 78 /** Set channel mute status73 IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL, 74 75 /** Get control item setting 79 76 * Answer: 80 77 * - ENOTSUP - call not supported 81 * - ENOENT - no such c hannel78 * - ENOENT - no such control item 82 79 * - EOK - call successful, info is valid 83 80 */ 84 IPC_M_AUDIO_MIXER_CHANNEL_MUTE_SET, 85 86 /** Get channel mute status 87 * Answer: 88 * - ENOTSUP - call not supported 89 * - ENOENT - no such channel 90 * - EOK - call successful, info is valid 91 * Answer arguments: 92 * - Channel mute status 93 */ 94 IPC_M_AUDIO_MIXER_CHANNEL_MUTE_GET, 95 96 /** Set channel volume level 97 * Answer: 98 * - ENOTSUP - call not supported 99 * - ENOENT - no such channel 100 * - EOK - call successful, info is valid 101 */ 102 IPC_M_AUDIO_MIXER_CHANNEL_VOLUME_SET, 103 104 /** Get channel volume level 105 * Answer: 106 * - ENOTSUP - call not supported 107 * - ENOENT - no such channel 108 * - EOK - call successful, info is valid 109 * Answer arguments: 110 * - Channel volume level 111 * - Channel maximum volume level 112 */ 113 IPC_M_AUDIO_MIXER_CHANNEL_VOLUME_GET, 81 IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL, 114 82 } audio_mixer_iface_funcs_t; 115 83 … … 162 130 */ 163 131 int audio_mixer_get_item_info(async_exch_t *exch, unsigned item, 164 const char **name, unsigned * channels)132 const char **name, unsigned *levels) 165 133 { 166 134 if (!exch) 167 135 return EINVAL; 168 sysarg_t name_size, chans;136 sysarg_t name_size, lvls; 169 137 const int ret = async_req_2_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE), 170 IPC_M_AUDIO_MIXER_GET_ITEM_INFO, item, &name_size, & chans);138 IPC_M_AUDIO_MIXER_GET_ITEM_INFO, item, &name_size, &lvls); 171 139 if (ret == EOK && name) { 172 140 char *name_place = calloc(1, name_size); … … 185 153 *name = name_place; 186 154 } 187 if (ret == EOK && chans)188 * channels = chans;155 if (ret == EOK && levels) 156 *levels = lvls; 189 157 return ret; 190 158 } 191 159 192 160 /** 193 * Query audio mixer for channel specific info (name and volume levels).161 * Set control item to a new level. 194 162 * @param[in] exch IPC exchange connected to the device. 195 * @param[in] item TH control item controlling the channel. 196 * @param[in] channel The channel. 197 * @param[out] name Audio channel string identifier. 198 * @param[out] volume_levels Number of volume levels. 163 * @param[in] item The control item controlling the channel. 164 * @param[in] level The new value. 199 165 * @return Error code. 200 166 */ 201 int audio_mixer_ get_channel_info(async_exch_t *exch, unsigned item,202 unsigned channel, const char **name, unsigned *volume_levels)167 int audio_mixer_set_item_level(async_exch_t *exch, unsigned item, 168 unsigned level) 203 169 { 204 170 if (!exch) 205 171 return EINVAL; 206 sysarg_t name_size, levels; 207 const int ret = async_req_3_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE), 208 IPC_M_AUDIO_MIXER_GET_CHANNEL_INFO, item, channel, 209 &name_size, &levels); 210 if (ret == EOK && name) { 211 char *name_place = calloc(1, name_size); 212 if (!name_place) { 213 /* Make the other side fail 214 * as it waits for read request */ 215 async_data_read_start(exch, (void*)-1, 0); 216 return ENOMEM; 217 } 218 const int ret = 219 async_data_read_start(exch, name_place, name_size); 220 if (ret != EOK) { 221 free(name_place); 222 return ret; 223 } 224 *name = name_place; 225 } 226 if (ret == EOK && volume_levels) 227 *volume_levels = levels; 228 return ret; 229 } 230 231 /** 232 * Set MUTE status on an audio channel. 172 return async_req_3_0(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE), 173 IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL, item, level); 174 } 175 176 /** 177 * Get current level of a control item. 233 178 * @param[in] exch IPC exchange connected to the device. 234 179 * @param[in] item The control item controlling the channel. 235 180 * @param[in] channel The channel index. 236 * @param[ in] mute_status A new MUTE status.181 * @param[out] level Currently set value. 237 182 * @return Error code. 238 183 */ 239 int audio_mixer_ channel_mute_set(async_exch_t *exch, unsigned item,240 unsigned channel, bool mute_status)184 int audio_mixer_get_item_level(async_exch_t *exch, unsigned item, 185 unsigned *level) 241 186 { 242 187 if (!exch) 243 188 return EINVAL; 244 return async_req_4_0(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE), 245 IPC_M_AUDIO_MIXER_CHANNEL_MUTE_SET, item, channel, mute_status); 246 } 247 248 /** 249 * Get MUTE status on an audio channel. 250 * @param[in] exch IPC exchange connected to the device. 251 * @param[in] item The control item controlling the channel. 252 * @param[in] channel The channel index. 253 * @param[out] mute_status Currently set MUTE status. 254 * @return Error code. 255 */ 256 int audio_mixer_channel_mute_get(async_exch_t *exch, unsigned item, 257 unsigned channel, bool *mute_status) 258 { 259 if (!exch) 260 return EINVAL; 261 sysarg_t mute; 262 const int ret = async_req_3_1(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE), 263 IPC_M_AUDIO_MIXER_CHANNEL_MUTE_GET, item, channel, &mute); 264 if (ret == EOK && mute_status) 265 *mute_status = (bool)mute; 266 return ret; 267 } 268 269 /** 270 * Set VOLUME LEVEL on an audio channel. 271 * @param[in] exch IPC exchange connected to the device. 272 * @param[in] item The control item controlling the channel. 273 * @param[in] channel The channel index. 274 * @param[in] volume A new VOLUME LEVEL. 275 * @return Error code. 276 */ 277 int audio_mixer_channel_volume_set(async_exch_t *exch, unsigned item, 278 unsigned channel, unsigned volume) 279 { 280 if (!exch) 281 return EINVAL; 282 return async_req_4_0(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE), 283 IPC_M_AUDIO_MIXER_CHANNEL_VOLUME_SET, item, channel, volume); 284 } 285 286 /** 287 * Get VOLUME LEVEL on an audio channel. 288 * @param[in] exch IPC exchange connected to the device. 289 * @param[in] item The control item controlling the channel. 290 * @param[in] channel The channel index. 291 * @param[out] volume_current Currently set VOLUME LEVEL. 292 * @param[out] volume_max Maximum VOLUME LEVEL. 293 * @return Error code. 294 */ 295 int audio_mixer_channel_volume_get(async_exch_t *exch, unsigned item, 296 unsigned channel, unsigned *volume_current, unsigned *volume_max) 297 { 298 if (!exch) 299 return EINVAL; 300 sysarg_t current, max; 301 const int ret = async_req_3_2(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE), 302 IPC_M_AUDIO_MIXER_CHANNEL_VOLUME_GET, item, channel, 303 ¤t, &max); 304 if (ret == EOK && volume_current) 305 *volume_current = current; 306 if (ret == EOK && volume_max) 307 *volume_max = max; 189 sysarg_t current; 190 const int ret = async_req_2_1(exch, DEV_IFACE_ID(AUDIO_MIXER_IFACE), 191 IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL, item, ¤t); 192 if (ret == EOK && level) 193 *level = current; 308 194 return ret; 309 195 } … … 314 200 static void remote_audio_mixer_get_info(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 315 201 static void remote_audio_mixer_get_item_info(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 316 static void remote_audio_mixer_get_channel_info(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 317 static void remote_audio_mixer_channel_mute_set(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 318 static void remote_audio_mixer_channel_mute_get(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 319 static void remote_audio_mixer_channel_volume_set(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 320 static void remote_audio_mixer_channel_volume_get(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 202 static void remote_audio_mixer_get_item_level(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 203 static void remote_audio_mixer_set_item_level(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *); 321 204 322 205 /** Remote audio mixer interface operations. */ … … 324 207 [IPC_M_AUDIO_MIXER_GET_INFO] = remote_audio_mixer_get_info, 325 208 [IPC_M_AUDIO_MIXER_GET_ITEM_INFO] = remote_audio_mixer_get_item_info, 326 [IPC_M_AUDIO_MIXER_GET_CHANNEL_INFO] = remote_audio_mixer_get_channel_info, 327 [IPC_M_AUDIO_MIXER_CHANNEL_MUTE_SET] = remote_audio_mixer_channel_mute_set, 328 [IPC_M_AUDIO_MIXER_CHANNEL_MUTE_GET] = remote_audio_mixer_channel_mute_get, 329 [IPC_M_AUDIO_MIXER_CHANNEL_VOLUME_SET] = remote_audio_mixer_channel_volume_set, 330 [IPC_M_AUDIO_MIXER_CHANNEL_VOLUME_GET] = remote_audio_mixer_channel_volume_get, 209 [IPC_M_AUDIO_MIXER_GET_ITEM_LEVEL] = remote_audio_mixer_get_item_level, 210 [IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL] = remote_audio_mixer_set_item_level, 331 211 }; 332 212 … … 380 260 const unsigned item = DEV_IPC_GET_ARG1(*call); 381 261 const char *name = NULL; 382 unsigned channels = 0;383 const int ret = mixer_iface->get_item_info(fun, item, &name, & channels);262 unsigned values = 0; 263 const int ret = mixer_iface->get_item_info(fun, item, &name, &values); 384 264 const size_t name_size = name ? str_size(name) + 1 : 0; 385 async_answer_2(callid, ret, name_size, channels);265 async_answer_2(callid, ret, name_size, values); 386 266 /* Send the name. */ 387 267 if (ret == EOK && name_size > 0) { … … 400 280 } 401 281 402 void remote_audio_mixer_ get_channel_info(282 void remote_audio_mixer_set_item_level( 403 283 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call) 404 284 { 405 285 audio_mixer_iface_t *mixer_iface = iface; 406 286 407 if (!mixer_iface-> get_channel_info) {287 if (!mixer_iface->set_item_level) { 408 288 async_answer_0(callid, ENOTSUP); 409 289 return; 410 290 } 411 412 291 const unsigned item = DEV_IPC_GET_ARG1(*call); 413 const unsigned channel = DEV_IPC_GET_ARG2(*call); 414 const char *name = NULL; 415 unsigned levels = 0; 416 const int ret = 417 mixer_iface->get_channel_info(fun, item, channel, &name, &levels); 418 const size_t name_size = name ? str_size(name) + 1 : 0; 419 async_answer_2(callid, ret, name_size, levels); 420 /* Send the name. */ 421 if (ret == EOK && name_size > 0) { 422 size_t size; 423 ipc_callid_t name_id; 424 if (!async_data_read_receive(&name_id, &size)) { 425 async_answer_0(name_id, EPARTY); 426 return; 427 } 428 if (size != name_size) { 429 async_answer_0(name_id, ELIMIT); 430 return; 431 } 432 async_data_read_finalize(name_id, name, name_size); 433 } 434 } 435 436 void remote_audio_mixer_channel_mute_set( 292 const unsigned value = DEV_IPC_GET_ARG2(*call); 293 const int ret = mixer_iface->set_item_level(fun, item, value); 294 async_answer_0(callid, ret); 295 } 296 297 void remote_audio_mixer_get_item_level( 437 298 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call) 438 299 { 439 300 audio_mixer_iface_t *mixer_iface = iface; 440 301 441 if (!mixer_iface-> channel_mute_set) {302 if (!mixer_iface->get_item_level) { 442 303 async_answer_0(callid, ENOTSUP); 443 304 return; 444 305 } 445 306 const unsigned item = DEV_IPC_GET_ARG1(*call); 446 const unsigned channel = DEV_IPC_GET_ARG2(*call); 447 const bool mute = DEV_IPC_GET_ARG3(*call); 448 const int ret = mixer_iface->channel_mute_set(fun, item, channel, mute); 449 async_answer_0(callid, ret); 450 } 451 452 void remote_audio_mixer_channel_mute_get( 453 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call) 454 { 455 audio_mixer_iface_t *mixer_iface = iface; 456 457 if (!mixer_iface->channel_mute_get) { 458 async_answer_0(callid, ENOTSUP); 459 return; 460 } 461 const unsigned item = DEV_IPC_GET_ARG1(*call); 462 const unsigned channel = DEV_IPC_GET_ARG2(*call); 463 bool mute = false; 307 unsigned current = 0; 464 308 const int ret = 465 mixer_iface->channel_mute_get(fun, item, channel, &mute); 466 async_answer_1(callid, ret, mute); 467 } 468 469 void remote_audio_mixer_channel_volume_set( 470 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call) 471 { 472 audio_mixer_iface_t *mixer_iface = iface; 473 474 if (!mixer_iface->channel_volume_set) { 475 async_answer_0(callid, ENOTSUP); 476 return; 477 } 478 const unsigned item = DEV_IPC_GET_ARG1(*call); 479 const unsigned channel = DEV_IPC_GET_ARG2(*call); 480 const unsigned level = DEV_IPC_GET_ARG3(*call); 481 const int ret = 482 mixer_iface->channel_volume_set(fun, item, channel, level); 483 async_answer_0(callid, ret); 484 } 485 486 void remote_audio_mixer_channel_volume_get( 487 ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call) 488 { 489 audio_mixer_iface_t *mixer_iface = iface; 490 491 if (!mixer_iface->channel_volume_get) { 492 async_answer_0(callid, ENOTSUP); 493 return; 494 } 495 const unsigned item = DEV_IPC_GET_ARG1(*call); 496 const unsigned channel = DEV_IPC_GET_ARG2(*call); 497 unsigned current = 0, max = 0; 498 const int ret = 499 mixer_iface->channel_volume_get(fun, item, channel, ¤t, &max); 500 async_answer_2(callid, ret, current, max); 309 mixer_iface->get_item_level(fun, item, ¤t); 310 async_answer_1(callid, ret, current); 501 311 } 502 312
Note:
See TracChangeset
for help on using the changeset viewer.