Ignore:
Timestamp:
2013-04-10T20:52:26Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5b77efc
Parents:
8a7d78cc
Message:

Make pcm control iface generic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/drv/generic/remote_audio_mixer.c

    r8a7d78cc r1912b45  
    6565        IPC_M_AUDIO_MIXER_GET_ITEM_INFO,
    6666
    67         /** Asks for channel name and number of volume levels.
     67        /** Set new control item setting
    6868         * Answer:
    6969         * - ENOTSUP - call not supported
    70          * - ENOENT - no such channel
     70         * - ENOENT - no such control item
    7171         * - EOK - call successful, info is valid
    72          * Answer arguments:
    73          * - Channel name
    74          * - Volume levels
    7572         */
    76         IPC_M_AUDIO_MIXER_GET_CHANNEL_INFO,
    77 
    78         /** Set channel mute status
     73        IPC_M_AUDIO_MIXER_SET_ITEM_LEVEL,
     74
     75        /** Get control item setting
    7976         * Answer:
    8077         * - ENOTSUP - call not supported
    81          * - ENOENT - no such channel
     78         * - ENOENT - no such control item
    8279         * - EOK - call successful, info is valid
    8380         */
    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,
    11482} audio_mixer_iface_funcs_t;
    11583
     
    162130 */
    163131int audio_mixer_get_item_info(async_exch_t *exch, unsigned item,
    164     const char **name, unsigned *channels)
     132    const char **name, unsigned *levels)
    165133{
    166134        if (!exch)
    167135                return EINVAL;
    168         sysarg_t name_size, chans;
     136        sysarg_t name_size, lvls;
    169137        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);
    171139        if (ret == EOK && name) {
    172140                char *name_place = calloc(1, name_size);
     
    185153                *name = name_place;
    186154        }
    187         if (ret == EOK && chans)
    188                 *channels = chans;
     155        if (ret == EOK && levels)
     156                *levels = lvls;
    189157        return ret;
    190158}
    191159
    192160/**
    193  * Query audio mixer for channel specific info (name and volume levels).
     161 * Set control item to a new level.
    194162 * @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.
    199165 * @return Error code.
    200166 */
    201 int audio_mixer_get_channel_info(async_exch_t *exch, unsigned item,
    202     unsigned channel, const char **name, unsigned *volume_levels)
     167int audio_mixer_set_item_level(async_exch_t *exch, unsigned item,
     168    unsigned level)
    203169{
    204170        if (!exch)
    205171                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.
    233178 * @param[in] exch IPC exchange connected to the device.
    234179 * @param[in] item The control item controlling the channel.
    235180 * @param[in] channel The channel index.
    236  * @param[in] mute_status A new MUTE status.
     181 * @param[out] level Currently set value.
    237182 * @return Error code.
    238183 */
    239 int audio_mixer_channel_mute_set(async_exch_t *exch, unsigned item,
    240     unsigned channel, bool mute_status)
     184int audio_mixer_get_item_level(async_exch_t *exch, unsigned item,
     185    unsigned *level)
    241186{
    242187        if (!exch)
    243188                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             &current, &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, &current);
     192        if (ret == EOK && level)
     193                *level = current;
    308194        return ret;
    309195}
     
    314200static void remote_audio_mixer_get_info(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    315201static 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 *);
     202static void remote_audio_mixer_get_item_level(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
     203static void remote_audio_mixer_set_item_level(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
    321204
    322205/** Remote audio mixer interface operations. */
     
    324207        [IPC_M_AUDIO_MIXER_GET_INFO] = remote_audio_mixer_get_info,
    325208        [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,
    331211};
    332212
     
    380260        const unsigned item = DEV_IPC_GET_ARG1(*call);
    381261        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);
    384264        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);
    386266        /* Send the name. */
    387267        if (ret == EOK && name_size > 0) {
     
    400280}
    401281
    402 void remote_audio_mixer_get_channel_info(
     282void remote_audio_mixer_set_item_level(
    403283    ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
    404284{
    405285        audio_mixer_iface_t *mixer_iface = iface;
    406286
    407         if (!mixer_iface->get_channel_info) {
     287        if (!mixer_iface->set_item_level) {
    408288                async_answer_0(callid, ENOTSUP);
    409289                return;
    410290        }
    411 
    412291        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
     297void remote_audio_mixer_get_item_level(
    437298    ddf_fun_t *fun, void *iface, ipc_callid_t callid, ipc_call_t *call)
    438299{
    439300        audio_mixer_iface_t *mixer_iface = iface;
    440301
    441         if (!mixer_iface->channel_mute_set) {
     302        if (!mixer_iface->get_item_level) {
    442303                async_answer_0(callid, ENOTSUP);
    443304                return;
    444305        }
    445306        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;
    464308        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, &current, &max);
    500         async_answer_2(callid, ret, current, max);
     309            mixer_iface->get_item_level(fun, item, &current);
     310        async_answer_1(callid, ret, current);
    501311}
    502312
Note: See TracChangeset for help on using the changeset viewer.