Changeset 8de7ef2 in mainline


Ignore:
Timestamp:
2012-07-05T19:31:39Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7ca22e5
Parents:
f8608f2
Message:

libdrv,audio: Add event callback creation to audio iface.

Location:
uspace/lib/drv
Files:
2 edited

Legend:

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

    rf8608f2 r8de7ef2  
    8383/*----------------------------------------------------------------------------*/
    8484int audio_pcm_buffer_get_buffer(async_exch_t *exch, void **buffer, size_t *size,
    85     unsigned *id)
     85    unsigned *id, async_client_conn_t event_rec, void* arg)
    8686{
    8787        if (!exch || !buffer || !size || !id)
     
    9595                void *dst = NULL;
    9696                // FIXME Do we need to know the flags?
    97                 const int ret = async_share_in_start_0_0(exch, buffer_size, &dst);
     97                int ret = async_share_in_start_0_0(exch, buffer_size, &dst);
    9898                if (ret != EOK) {
    9999                        return ret;
    100100                }
     101                ret = async_connect_to_me(exch, 0, 0, 0, event_rec, arg);
     102                if (ret != EOK) {
     103                        return ret;
     104                }
     105
    101106                *buffer = dst;
    102107                *size = buffer_size;
     
    115120/*----------------------------------------------------------------------------*/
    116121int audio_pcm_buffer_start_playback(async_exch_t *exch, unsigned id,
    117     unsigned sample_rate, uint16_t sample_size, uint8_t channels, bool sign)
     122    unsigned parts, unsigned sample_rate, uint16_t sample_size,
     123    uint8_t channels, bool sign)
    118124{
    119125        if (!exch)
    120126                return EINVAL;
    121         sysarg_t packed =
    122             (sample_size << 16) | (channels << 8) | (sign ? 1 : 0);
     127        const sysarg_t packed =
     128            (sample_size << 16) | (channels << 8) |
     129            (parts & 0x7f << 1) | (sign ? 1 : 0);
    123130        return async_req_4_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE),
    124131            IPC_M_AUDIO_PCM_START_PLAYBACK, id, sample_rate, packed);
     
    214221        const audio_pcm_buffer_iface_t *pcm_iface = iface;
    215222
    216         if (!pcm_iface->get_buffer) {
     223        if (!pcm_iface->get_buffer ||
     224            !pcm_iface->release_buffer ||
     225            !pcm_iface->set_event_session) {
    217226                async_answer_0(callid, ENOTSUP);
    218227                return;
     
    221230        size_t size = DEV_IPC_GET_ARG1(*call);
    222231        unsigned id = 0;
    223         const int ret = pcm_iface->get_buffer(fun, &buffer, &size, &id);
     232        int ret = pcm_iface->get_buffer(fun, &buffer, &size, &id);
    224233        async_answer_2(callid, ret, size, id);
     234        if (ret != EOK || size == 0)
     235                return;
     236
    225237        /* Share the buffer. */
    226         if (ret == EOK && size > 0) {
    227                 size_t share_size = 0;
    228                 ipc_callid_t share_id = 0;
    229                 ddf_msg(LVL_DEBUG2, "Calling share receive.");
    230                 if (!async_share_in_receive(&share_id, &share_size)) {
    231                         ddf_msg(LVL_DEBUG, "Failed to share pcm buffer.");
    232                         if (pcm_iface->release_buffer)
    233                                 pcm_iface->release_buffer(fun, id);
    234                         async_answer_0(share_id, EPARTY);
    235                         return;
    236                 }
    237                 ddf_msg(LVL_DEBUG2, "Checking requested share size");
    238                 if (share_size != size) {
    239                         ddf_msg(LVL_DEBUG, "Incorrect pcm buffer size requested.");
    240                         if (pcm_iface->release_buffer)
    241                                 pcm_iface->release_buffer(fun, id);
    242                         async_answer_0(share_id, ELIMIT);
    243                         return;
    244                 }
    245                 ddf_msg(LVL_DEBUG2, "Calling share finalize");
    246                 const int ret = async_share_in_finalize(share_id, buffer, 0);
     238        size_t share_size = 0;
     239        ipc_callid_t share_id = 0;
     240        ddf_msg(LVL_DEBUG2, "Calling share receive.");
     241        if (!async_share_in_receive(&share_id, &share_size)) {
     242                ddf_msg(LVL_DEBUG, "Failed to share pcm buffer.");
     243                if (pcm_iface->release_buffer)
     244                        pcm_iface->release_buffer(fun, id);
     245                async_answer_0(share_id, EPARTY);
     246                return;
     247        }
     248        ddf_msg(LVL_DEBUG2, "Checking requested share size");
     249        if (share_size != size) {
     250                ddf_msg(LVL_DEBUG, "Incorrect pcm buffer size requested.");
     251                if (pcm_iface->release_buffer)
     252                        pcm_iface->release_buffer(fun, id);
     253                async_answer_0(share_id, ELIMIT);
     254                return;
     255        }
     256        ddf_msg(LVL_DEBUG2, "Calling share finalize");
     257        ret = async_share_in_finalize(share_id, buffer, 0);
     258        if (ret != EOK) {
     259                ddf_msg(LVL_DEBUG, "Failed to share buffer");
     260                if (pcm_iface->release_buffer)
     261                        pcm_iface->release_buffer(fun, id);
     262                return;
     263
     264        }
     265        ddf_msg(LVL_DEBUG2, "Buffer shared with size %zu, creating callback.",
     266            share_size);
     267        {
     268                ipc_call_t call;
     269                ipc_callid_t callid = async_get_call(&call);
     270                async_sess_t *sess =
     271                    async_callback_receive_start(EXCHANGE_ATOMIC, &call);
     272                if (sess == NULL) {
     273                        ddf_msg(LVL_DEBUG, "Failed to create event callback");
     274                        pcm_iface->release_buffer(fun, id);
     275                        async_answer_0(callid, EAGAIN);
     276                        return;
     277                }
     278                ret = pcm_iface->set_event_session(fun, id, sess);
    247279                if (ret != EOK) {
    248                         ddf_msg(LVL_DEBUG, "Failed to share buffer");
    249                         if (pcm_iface->release_buffer)
    250                                 pcm_iface->release_buffer(fun, id);
    251                         return;
    252 
    253                 }
    254                 ddf_msg(LVL_DEBUG2, "Buffer shared ok with size %zu.",
    255                     share_size);
     280                        ddf_msg(LVL_DEBUG, "Failed to set event callback.");
     281                        pcm_iface->release_buffer(fun, id);
     282                }
     283                async_answer_0(callid, ret);
    256284        }
    257285}
     
    276304        const unsigned rate = DEV_IPC_GET_ARG2(*call);
    277305        const unsigned size = DEV_IPC_GET_ARG3(*call) >> 16;
    278         const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 8) && UINT8_MAX;
     306        const unsigned channels = (DEV_IPC_GET_ARG3(*call) >> 8) & UINT8_MAX;
     307        const unsigned parts = (DEV_IPC_GET_ARG3(*call) >> 1) & 0x7f;
    279308        const bool sign = (bool)(DEV_IPC_GET_ARG3(*call) & 1);
    280309
    281310        const int ret = pcm_iface->start_playback
    282             ? pcm_iface->start_playback(fun, id, rate, size, channels, sign)
     311            ? pcm_iface->start_playback(fun, id, parts, rate, size, channels, sign)
    283312            : ENOTSUP;
    284313        async_answer_0(callid, ret);
  • uspace/lib/drv/include/audio_pcm_buffer_iface.h

    rf8608f2 r8de7ef2  
    4343
    4444int audio_pcm_buffer_get_info_str(async_exch_t *, const char **);
    45 int audio_pcm_buffer_get_buffer(async_exch_t *, void **, size_t *, unsigned *);
     45int audio_pcm_buffer_get_buffer(async_exch_t *, void **, size_t *, unsigned *,
     46    async_client_conn_t, void *);
    4647int audio_pcm_buffer_release_buffer(async_exch_t *, unsigned);
    4748
    48 int audio_pcm_buffer_start_playback(async_exch_t *, unsigned,
     49int audio_pcm_buffer_start_playback(async_exch_t *, unsigned, unsigned,
    4950    unsigned, uint16_t, uint8_t, bool);
    5051int audio_pcm_buffer_stop_playback(async_exch_t *, unsigned);
     
    5960        int (*get_buffer)(ddf_fun_t *, void **, size_t *, unsigned *);
    6061        int (*release_buffer)(ddf_fun_t *, unsigned);
    61         int (*start_playback)(ddf_fun_t *, unsigned,
     62        int (*set_event_session)(ddf_fun_t *, unsigned, async_sess_t *);
     63        int (*start_playback)(ddf_fun_t *, unsigned, unsigned,
    6264            unsigned, unsigned, unsigned, bool);
    6365        int (*stop_playback)(ddf_fun_t *, unsigned);
Note: See TracChangeset for help on using the changeset viewer.