Changeset 1f440f5f in mainline


Ignore:
Timestamp:
2013-04-05T14:34:41Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
6d74977
Parents:
f04603e
Message:

hound: implement data update for hound_ctx

pushes data to every connection

File:
1 edited

Legend:

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

    rf04603e r1f440f5f  
    4040#include "hound_ctx.h"
    4141#include "audio_data.h"
     42#include "connection.h"
    4243#include "log.h"
     44
     45static int update_data(audio_source_t *source, size_t size);
    4346
    4447hound_ctx_t *hound_record_ctx_get(const char *name)
     
    6063                }
    6164                const int ret = audio_source_init(ctx->source, name, ctx, NULL,
    62                     NULL, &AUDIO_FORMAT_ANY);
     65                    update_data, &AUDIO_FORMAT_DEFAULT);
    6366                if (ret != EOK) {
    6467                        free(ctx->source);
     
    9598        return ctx->source == NULL;
    9699}
     100
    97101
    98102/*
     
    140144                if (audio_pipe_bytes(&stream->fifo))
    141145                        log_warning("Destroying stream with non empty buffer");
    142                 audio_pipe_fini(&stream->fifo);
    143146                log_verbose("CTX: %p remove stream (%zu/%zu); "
    144147                    "flags:%#x ch: %u r:%u f:%s",
     
    147150                    stream->format.channels, stream->format.sampling_rate,
    148151                    pcm_sample_format_str(stream->format.sample_format));
     152                audio_pipe_fini(&stream->fifo);
    149153                free(stream);
    150154        }
     
    156160{
    157161        assert(stream);
    158         log_verbose("%p:, %zu", stream, size);
     162        log_verbose("%p: %zu", stream, size);
    159163
    160164        if (stream->allowed_size && size > stream->allowed_size)
     
    188192{
    189193        assert(stream);
     194        log_debug("Draining stream");
    190195        while (audio_pipe_bytes(&stream->fifo))
    191196                async_usleep(10000);
     
    198203}
    199204
     205
     206int update_data(audio_source_t *source, size_t size)
     207{
     208        assert(source);
     209        assert(source->private_data);
     210        hound_ctx_t *ctx = source->private_data;
     211        void *buffer = malloc(size);
     212        if (!buffer)
     213                return ENOMEM;
     214        audio_data_t *adata = audio_data_create(buffer, size, source->format);
     215        if (!adata) {
     216                free(buffer);
     217                return ENOMEM;
     218        }
     219        log_verbose("CTX: %p. Mixing %zu streams", ctx,
     220            list_count(&ctx->streams));
     221        pcm_format_silence(buffer, size, &source->format);
     222        list_foreach(ctx->streams, it) {
     223                hound_ctx_stream_t *stream = hound_ctx_stream_from_link(it);
     224                hound_ctx_stream_add_self(stream, buffer, size, &source->format);
     225        }
     226        log_verbose("CTX: %p. Pushing audio to %zu connections", ctx,
     227            list_count(&source->connections));
     228        list_foreach(source->connections, it) {
     229                connection_t *conn = connection_from_source_list(it);
     230                connection_push_data(conn, adata);
     231        }
     232        return EOK;
     233}
     234
    200235/**
    201236 * @}
Note: See TracChangeset for help on using the changeset viewer.