Changeset f1438e5 in mainline


Ignore:
Timestamp:
2013-04-05T12:20:18Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
50179b63
Parents:
d988ef2
Message:

hound: switch streams to audio pipe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/audio/hound/hound_ctx.c

    rd988ef2 rf1438e5  
    101101typedef struct hound_ctx_stream {
    102102        link_t link;
    103         list_t fifo;
     103        audio_pipe_t fifo;
    104104        hound_ctx_t *ctx;
    105105        pcm_format_t format;
    106106        int flags;
    107107        size_t allowed_size;
    108         size_t current_size;
    109108} hound_ctx_stream_t;
    110109
     
    120119        hound_ctx_stream_t *stream = malloc(sizeof(hound_ctx_stream_t));
    121120        if (stream) {
    122                 list_initialize(&stream->fifo);
     121                audio_pipe_init(&stream->fifo);
    123122                link_initialize(&stream->link);
    124123                stream->ctx = ctx;
     
    126125                stream->format = format;
    127126                stream->allowed_size = buffer_size;
    128                 stream->current_size = 0;
    129127                list_append(&stream->link, &ctx->streams);
    130128                log_verbose("CTX: %p added stream; flags:%#x ch: %u r:%u f:%s",
     
    140138                //TODO consider DRAIN FLAG
    141139                list_remove(&stream->link);
    142                 if (!list_empty(&stream->fifo))
     140                if (audio_pipe_bytes(&stream->fifo))
    143141                        log_warning("Destroying stream with non empty buffer");
    144                 while (!list_empty(&stream->fifo)) {
    145                         link_t *l = list_first(&stream->fifo);
    146                         audio_data_link_t *data =
    147                             audio_data_link_list_instance(l);
    148                         list_remove(l);
    149                         audio_data_link_destroy(data);
    150                 }
     142                audio_pipe_fini(&stream->fifo);
    151143                log_verbose("CTX: %p remove stream (%zu/%zu); "
    152144                    "flags:%#x ch: %u r:%u f:%s",
    153                     stream->ctx, stream->current_size, stream->allowed_size,
    154                     stream->flags, stream->format.channels,
    155                     stream->format.sampling_rate,
     145                    stream->ctx, audio_pipe_bytes(&stream->fifo),
     146                    stream->allowed_size, stream->flags,
     147                    stream->format.channels, stream->format.sampling_rate,
    156148                    pcm_sample_format_str(stream->format.sample_format));
    157149                free(stream);
     
    170162
    171163        if (stream->allowed_size &&
    172             (stream->current_size + size > stream->allowed_size))
     164            (audio_pipe_bytes(&stream->fifo) + size > stream->allowed_size))
    173165                return EBUSY;
    174166
    175         audio_data_link_t *adatalink =
    176             audio_data_link_create_data(data, size, stream->format);
    177         if (adatalink) {
    178                 list_append(&adatalink->link, &stream->fifo);
    179                 stream->current_size += size;
    180                 return EOK;
    181         }
    182         log_warning("Failed to enqueue %zu bytes of data.", size);
    183         return ENOMEM;
     167        return audio_pipe_push_data(&stream->fifo, data, size, stream->format);
    184168}
    185169
     
    194178{
    195179        assert(stream);
    196         const size_t src_frame_size = pcm_format_frame_size(&stream->format);
    197         const size_t dst_frame_size = pcm_format_frame_size(f);
    198         //TODO consider sample rate
    199         size_t needed_frames = size / dst_frame_size;
    200         while (needed_frames > 0 && !list_empty(&stream->fifo)) {
    201                 link_t *l = list_first(&stream->fifo);
    202                 audio_data_link_t *alink = audio_data_link_list_instance(l);
    203                 /* Get actual audio data chunk */
    204                 const size_t available_frames =
    205                     audio_data_link_available_frames(alink);
    206                 const size_t copy_frames = min(available_frames, needed_frames);
    207                 const size_t copy_size = copy_frames * dst_frame_size;
    208 
    209                 /* Copy audio data */
    210                 pcm_format_convert_and_mix(data, copy_size,
    211                     audio_data_link_start(alink),
    212                     audio_data_link_remain_size(alink),
    213                     &alink->adata->format, f);
    214 
    215                 /* Update values */
    216                 needed_frames -= copy_frames;
    217                 data += copy_size;
    218                 alink->position += (copy_frames * src_frame_size);
    219                 if (audio_data_link_remain_size(alink) == 0) {
    220                         list_remove(&alink->link);
    221                         audio_data_link_destroy(alink);
    222                 } else {
    223                         assert(needed_frames == 0);
    224                 }
    225         }
    226         return ENOTSUP;
     180        const ssize_t copied_size =
     181            audio_pipe_mix_data(&stream->fifo, data, size, f);
     182        if (copied_size != (ssize_t)size)
     183                log_warning("Not enough data in stream buffer");
     184        return copied_size > 0 ? EOK : copied_size;
    227185}
    228186
     
    230188{
    231189        assert(stream);
    232         while (!list_empty(&stream->fifo))
     190        while (audio_pipe_bytes(&stream->fifo))
    233191                async_usleep(10000);
    234192}
Note: See TracChangeset for help on using the changeset viewer.