Ignore:
File:
1 edited

Legend:

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

    r4a5ae542 r57a2208  
    100100static unsigned hda_query_cap(ddf_fun_t *fun, audio_cap_t cap)
    101101{
    102         hda_t *hda = fun_to_hda(fun);
    103 
    104102        ddf_msg(LVL_NOTE, "hda_query_cap(%d)", cap);
    105103        switch (cap) {
    106104        case AUDIO_CAP_PLAYBACK:
    107105        case AUDIO_CAP_INTERRUPT:
    108                 /* XXX Only if we have an output converter */
    109106                return 1;
     107        case AUDIO_CAP_BUFFER_POS:
    110108        case AUDIO_CAP_CAPTURE:
    111                 /* Yes if we have an input converter */
    112                 return hda->ctl->codec->in_aw >= 0;
    113         case AUDIO_CAP_BUFFER_POS:
    114109                return 0;
    115110        case AUDIO_CAP_MAX_BUFFER:
     
    153148{
    154149        hda_t *hda = fun_to_hda(fun);
    155         int rc;
    156150
    157151        hda_lock(hda);
    158152
    159153        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 
    185 static 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 
    191 static 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 
    203 static 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 
    217 static 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 
    236 static 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 
    245154        if (hda->pcm_stream != NULL) {
    246155                hda_unlock(hda);
     
    253162        fmt = (fmt_base_44khz << fmt_base) | (fmt_bits_16 << fmt_bits_l) | 1;
    254163
    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);
     164        ddf_msg(LVL_NOTE, "hda_get_buffer() - create stream");
     165        hda->pcm_stream = hda_stream_create(hda, sdir_output, fmt);
    258166        if (hda->pcm_stream == NULL) {
    259167                hda_unlock(hda);
    260168                return EIO;
    261169        }
     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
     183static 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
     189static 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
     201static 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
     215static 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
     234static 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);
    262242
    263243        rc = hda_out_converter_setup(hda->ctl->codec, hda->pcm_stream);
    264244        if (rc != EOK) {
    265                 hda_stream_destroy(hda->pcm_stream);
    266                 hda->pcm_stream = NULL;
    267245                hda_unlock(hda);
    268246                return rc;
    269247        }
    270248
     249        hda_stream_start(hda->pcm_stream);
    271250        hda->playing = true;
    272         hda_stream_start(hda->pcm_stream);
    273251        hda_unlock(hda);
    274252        return EOK;
     
    284262        hda_stream_reset(hda->pcm_stream);
    285263        hda->playing = false;
    286         hda_stream_destroy(hda->pcm_stream);
    287         hda->pcm_stream = NULL;
    288 
    289264        hda_unlock(hda);
    290265
     
    296271    unsigned rate, pcm_sample_format_t format)
    297272{
    298         hda_t *hda = fun_to_hda(fun);
    299         int rc;
    300 
    301273        ddf_msg(LVL_NOTE, "hda_start_capture()");
    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;
     274        return ENOTSUP;
    334275}
    335276
    336277static int hda_stop_capture(ddf_fun_t *fun, bool immediate)
    337278{
    338         hda_t *hda = fun_to_hda(fun);
    339 
    340279        ddf_msg(LVL_NOTE, "hda_stop_capture()");
    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;
     280        return ENOTSUP;
    351281}
    352282
Note: See TracChangeset for help on using the changeset viewer.