Changeset 94e46c9 in mainline for uspace/drv/audio/hdaudio/pcm_iface.c


Ignore:
Timestamp:
2015-05-23T04:09:11Z (9 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
b5143bd
Parents:
a25d893 (diff), 0683992 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Mainline changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/audio/hdaudio/pcm_iface.c

    ra25d893 r94e46c9  
    100100static unsigned hda_query_cap(ddf_fun_t *fun, audio_cap_t cap)
    101101{
     102        hda_t *hda = fun_to_hda(fun);
     103
    102104        ddf_msg(LVL_NOTE, "hda_query_cap(%d)", cap);
    103105        switch (cap) {
    104106        case AUDIO_CAP_PLAYBACK:
    105107        case AUDIO_CAP_INTERRUPT:
     108                /* XXX Only if we have an output converter */
    106109                return 1;
     110        case AUDIO_CAP_CAPTURE:
     111                /* Yes if we have an input converter */
     112                return hda->ctl->codec->in_aw >= 0;
    107113        case AUDIO_CAP_BUFFER_POS:
    108         case AUDIO_CAP_CAPTURE:
    109114                return 0;
    110115        case AUDIO_CAP_MAX_BUFFER:
     
    148153{
    149154        hda_t *hda = fun_to_hda(fun);
     155        int rc;
    150156
    151157        hda_lock(hda);
    152158
    153159        ddf_msg(LVL_NOTE, "hda_get_buffer(): hda=%p", hda);
     160        if (hda->pcm_buffers != NULL) {
     161                hda_unlock(hda);
     162                return EBUSY;
     163        }
     164
     165        ddf_msg(LVL_NOTE, "hda_get_buffer() - allocate stream buffers");
     166        rc = hda_stream_buffers_alloc(hda, &hda->pcm_buffers);
     167        if (rc != EOK) {
     168                assert(rc == ENOMEM);
     169                hda_unlock(hda);
     170                return ENOMEM;
     171        }
     172
     173        ddf_msg(LVL_NOTE, "hda_get_buffer() - fill info");
     174        /* XXX This is only one buffer */
     175        *buffer = hda->pcm_buffers->buf[0];
     176        *size = hda->pcm_buffers->bufsize * hda->pcm_buffers->nbuffers;
     177
     178        ddf_msg(LVL_NOTE, "hda_get_buffer() returing EOK, buffer=%p, size=%zu",
     179            *buffer, *size);
     180
     181        hda_unlock(hda);
     182        return EOK;
     183}
     184
     185static int hda_get_buffer_position(ddf_fun_t *fun, size_t *pos)
     186{
     187        ddf_msg(LVL_NOTE, "hda_get_buffer_position()");
     188        return ENOTSUP;
     189}
     190
     191static int hda_set_event_session(ddf_fun_t *fun, async_sess_t *sess)
     192{
     193        hda_t *hda = fun_to_hda(fun);
     194
     195        ddf_msg(LVL_NOTE, "hda_set_event_session()");
     196        hda_lock(hda);
     197        hda->ev_sess = sess;
     198        hda_unlock(hda);
     199
     200        return EOK;
     201}
     202
     203static async_sess_t *hda_get_event_session(ddf_fun_t *fun)
     204{
     205        hda_t *hda = fun_to_hda(fun);
     206        async_sess_t *sess;
     207
     208        ddf_msg(LVL_NOTE, "hda_get_event_session()");
     209
     210        hda_lock(hda);
     211        sess = hda->ev_sess;
     212        hda_unlock(hda);
     213
     214        return sess;
     215}
     216
     217static int hda_release_buffer(ddf_fun_t *fun)
     218{
     219        hda_t *hda = fun_to_hda(fun);
     220
     221        hda_lock(hda);
     222
     223        ddf_msg(LVL_NOTE, "hda_release_buffer()");
     224        if (hda->pcm_buffers == NULL) {
     225                hda_unlock(hda);
     226                return EINVAL;
     227        }
     228
     229        hda_stream_buffers_free(hda->pcm_buffers);
     230        hda->pcm_buffers = NULL;
     231
     232        hda_unlock(hda);
     233        return EOK;
     234}
     235
     236static int hda_start_playback(ddf_fun_t *fun, unsigned frames,
     237    unsigned channels, unsigned rate, pcm_sample_format_t format)
     238{
     239        hda_t *hda = fun_to_hda(fun);
     240        int rc;
     241
     242        ddf_msg(LVL_NOTE, "hda_start_playback()");
     243        hda_lock(hda);
     244
    154245        if (hda->pcm_stream != NULL) {
    155246                hda_unlock(hda);
     
    162253        fmt = (fmt_base_44khz << fmt_base) | (fmt_bits_16 << fmt_bits_l) | 1;
    163254
    164         ddf_msg(LVL_NOTE, "hda_get_buffer() - create stream");
    165         hda->pcm_stream = hda_stream_create(hda, sdir_output, fmt);
     255        ddf_msg(LVL_NOTE, "hda_start_playback() - create output stream");
     256        hda->pcm_stream = hda_stream_create(hda, sdir_output, hda->pcm_buffers,
     257            fmt);
    166258        if (hda->pcm_stream == NULL) {
    167259                hda_unlock(hda);
    168260                return EIO;
    169261        }
    170 
    171         ddf_msg(LVL_NOTE, "hda_get_buffer() - fill info");
    172         /* XXX This is only one buffer */
    173         *buffer = hda->pcm_stream->buf[0];
    174         *size = hda->pcm_stream->bufsize * hda->pcm_stream->nbuffers;
    175 
    176         ddf_msg(LVL_NOTE, "hda_get_buffer() retturing EOK, buffer=%p, size=%zu",
    177             *buffer, *size);
    178 
    179         hda_unlock(hda);
    180         return EOK;
    181 }
    182 
    183 static int hda_get_buffer_position(ddf_fun_t *fun, size_t *pos)
    184 {
    185         ddf_msg(LVL_NOTE, "hda_get_buffer_position()");
    186         return ENOTSUP;
    187 }
    188 
    189 static int hda_set_event_session(ddf_fun_t *fun, async_sess_t *sess)
    190 {
    191         hda_t *hda = fun_to_hda(fun);
    192 
    193         ddf_msg(LVL_NOTE, "hda_set_event_session()");
    194         hda_lock(hda);
    195         hda->ev_sess = sess;
    196         hda_unlock(hda);
    197 
    198         return EOK;
    199 }
    200 
    201 static async_sess_t *hda_get_event_session(ddf_fun_t *fun)
    202 {
    203         hda_t *hda = fun_to_hda(fun);
    204         async_sess_t *sess;
    205 
    206         ddf_msg(LVL_NOTE, "hda_get_event_session()");
    207 
    208         hda_lock(hda);
    209         sess = hda->ev_sess;
    210         hda_unlock(hda);
    211 
    212         return sess;
    213 }
    214 
    215 static int hda_release_buffer(ddf_fun_t *fun)
    216 {
    217         hda_t *hda = fun_to_hda(fun);
    218 
    219         hda_lock(hda);
    220 
    221         ddf_msg(LVL_NOTE, "hda_release_buffer()");
    222         if (hda->pcm_stream == NULL) {
    223                 hda_unlock(hda);
    224                 return EINVAL;
    225         }
    226 
    227         hda_stream_destroy(hda->pcm_stream);
    228         hda->pcm_stream = NULL;
    229 
    230         hda_unlock(hda);
    231         return EOK;
    232 }
    233 
    234 static int hda_start_playback(ddf_fun_t *fun, unsigned frames,
    235     unsigned channels, unsigned rate, pcm_sample_format_t format)
    236 {
    237         hda_t *hda = fun_to_hda(fun);
    238         int rc;
    239 
    240         ddf_msg(LVL_NOTE, "hda_start_playback()");
    241         hda_lock(hda);
    242262
    243263        rc = hda_out_converter_setup(hda->ctl->codec, hda->pcm_stream);
    244264        if (rc != EOK) {
     265                hda_stream_destroy(hda->pcm_stream);
     266                hda->pcm_stream = NULL;
    245267                hda_unlock(hda);
    246268                return rc;
    247269        }
    248270
     271        hda->playing = true;
    249272        hda_stream_start(hda->pcm_stream);
    250         hda->playing = true;
    251273        hda_unlock(hda);
    252274        return EOK;
     
    262284        hda_stream_reset(hda->pcm_stream);
    263285        hda->playing = false;
     286        hda_stream_destroy(hda->pcm_stream);
     287        hda->pcm_stream = NULL;
     288
    264289        hda_unlock(hda);
    265290
     
    271296    unsigned rate, pcm_sample_format_t format)
    272297{
     298        hda_t *hda = fun_to_hda(fun);
     299        int rc;
     300
    273301        ddf_msg(LVL_NOTE, "hda_start_capture()");
    274         return ENOTSUP;
     302        hda_lock(hda);
     303
     304        if (hda->pcm_stream != NULL) {
     305                hda_unlock(hda);
     306                return EBUSY;
     307        }
     308
     309        /* XXX Choose appropriate parameters */
     310        uint32_t fmt;
     311        /* 48 kHz, 16-bits, 1 channel */
     312        fmt = (fmt_base_44khz << fmt_base) | (fmt_bits_16 << fmt_bits_l) | 1;
     313
     314        ddf_msg(LVL_NOTE, "hda_start_capture() - create input stream");
     315        hda->pcm_stream = hda_stream_create(hda, sdir_input, hda->pcm_buffers,
     316            fmt);
     317        if (hda->pcm_stream == NULL) {
     318                hda_unlock(hda);
     319                return EIO;
     320        }
     321
     322        rc = hda_in_converter_setup(hda->ctl->codec, hda->pcm_stream);
     323        if (rc != EOK) {
     324                hda_stream_destroy(hda->pcm_stream);
     325                hda->pcm_stream = NULL;
     326                hda_unlock(hda);
     327                return rc;
     328        }
     329
     330        hda->capturing = true;
     331        hda_stream_start(hda->pcm_stream);
     332        hda_unlock(hda);
     333        return EOK;
    275334}
    276335
    277336static int hda_stop_capture(ddf_fun_t *fun, bool immediate)
    278337{
     338        hda_t *hda = fun_to_hda(fun);
     339
    279340        ddf_msg(LVL_NOTE, "hda_stop_capture()");
    280         return ENOTSUP;
     341        hda_lock(hda);
     342        hda_stream_stop(hda->pcm_stream);
     343        hda_stream_reset(hda->pcm_stream);
     344        hda->capturing = false;
     345        hda_stream_destroy(hda->pcm_stream);
     346        hda->pcm_stream = NULL;
     347        hda_unlock(hda);
     348
     349        hda_pcm_event(hda, PCM_EVENT_CAPTURE_TERMINATED);
     350        return EOK;
    281351}
    282352
Note: See TracChangeset for help on using the changeset viewer.