Changeset b266f9e in mainline


Ignore:
Timestamp:
2013-04-04T11:15: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:
bf13c9a4
Parents:
6133470
Message:

hound: implement stream creation/destruction

Location:
uspace/srv/audio/hound
Files:
3 edited

Legend:

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

    r6133470 rb266f9e  
    3838
    3939#include "hound_ctx.h"
     40#include "log.h"
    4041
    4142hound_ctx_t *hound_record_ctx_get(const char *name)
     
    4950        if (ctx) {
    5051                link_initialize(&ctx->link);
     52                list_initialize(&ctx->streams);
    5153                ctx->sink = NULL;
    5254                ctx->source = malloc(sizeof(audio_source_t));
     
    7476        if (ctx->sink)
    7577                audio_sink_fini(ctx->sink);
     78        //TODO remove streams
    7679        free(ctx->source);
    7780        free(ctx->sink);
     
    8891{
    8992        assert(ctx);
    90         //TODO fix this
    91         return false;
     93        return ctx->source == NULL;
     94}
     95
     96hound_ctx_stream_t *hound_ctx_create_stream(hound_ctx_t *ctx, int flags,
     97        pcm_format_t format, size_t buffer_size)
     98{
     99        assert(ctx);
     100        hound_ctx_stream_t *stream = malloc(sizeof(hound_ctx_stream_t));
     101        if (stream) {
     102                link_initialize(&stream->link);
     103                stream->ctx = ctx;
     104                stream->flags = flags;
     105                stream->format = format;
     106                stream->allowed_size = buffer_size;
     107                list_append(&stream->link, &ctx->streams);
     108                log_verbose("CTX: %p added stream; flags:%#x ch: %u r:%u f:%s",
     109                    ctx, flags, format.channels, format.sampling_rate,
     110                    pcm_sample_format_str(format.sample_format));
     111        }
     112        return stream;
     113}
     114
     115void hound_ctx_destroy_stream(hound_ctx_stream_t *stream)
     116{
     117        if (stream) {
     118                list_remove(&stream->link);
     119                //TODO free used buffer space
     120                log_verbose("CTX: %p remove stream; flags:%#x ch: %u r:%u f:%s",
     121                    stream->ctx, stream->flags, stream->format.channels,
     122                    stream->format.sampling_rate,
     123                    pcm_sample_format_str(stream->format.sample_format));
     124                free(stream);
     125        }
    92126}
    93127
  • uspace/srv/audio/hound/hound_ctx.h

    r6133470 rb266f9e  
    5454}
    5555
     56typedef struct {
     57        link_t link;
     58        hound_ctx_t *ctx;
     59        pcm_format_t format;
     60        int flags;
     61        size_t allowed_size;
     62} hound_ctx_stream_t;
     63
     64static inline hound_ctx_stream_t *hound_ctx_stream_from_link(link_t *l)
     65{
     66        return l ? list_get_instance(l, hound_ctx_stream_t, link) : NULL;
     67}
     68
     69
    5670hound_ctx_t *hound_record_ctx_get(const char *name);
    5771hound_ctx_t *hound_playback_ctx_get(const char *name);
     
    6175bool hound_ctx_is_record(hound_ctx_t *ctx);
    6276
     77hound_ctx_stream_t *hound_ctx_create_stream(hound_ctx_t *ctx, int flags,
     78        pcm_format_t format, size_t buffer_size);
     79void hound_ctx_destroy_stream(hound_ctx_stream_t *stream);
     80
    6381#endif
    6482
  • uspace/srv/audio/hound/iface.c

    r6133470 rb266f9e  
    112112    pcm_format_t format, size_t size, void **data)
    113113{
    114         log_info("%s: %p, %d %x ch:%u r:%u f:%s", __FUNCTION__, server, id,
     114        assert(data);
     115        assert(server);
     116
     117        log_verbose("%s: %p, %d %x ch:%u r:%u f:%s", __FUNCTION__, server, id,
    115118            flags, format.channels, format.sampling_rate,
    116119            pcm_sample_format_str(format.sample_format));
    117         *data = (void*)"TEST_STREAM";
    118         return ENOTSUP;
     120        hound_ctx_t *ctx = hound_get_ctx_by_id(server, id);
     121        if (!ctx)
     122                return ENOENT;
     123        hound_ctx_stream_t *stream =
     124            hound_ctx_create_stream(ctx, flags, format, size);
     125        if (!stream)
     126                return ENOMEM;
     127        *data = stream;
     128        return EOK;
    119129}
    120130
    121131static int iface_rem_stream(void *server, void *stream)
    122132{
    123         log_info("%s: %p, %s", __FUNCTION__, server, (char *)stream);
    124         return ENOTSUP;
     133        log_verbose("%s: %p, %s", __FUNCTION__, server, (char *)stream);
     134        hound_ctx_destroy_stream(stream);
     135        return EOK;
    125136}
    126137
    127138static int iface_stream_data_read(void *stream, void *buffer, size_t size)
    128139{
    129         log_info("%s: %s, %zu", __FUNCTION__, (char *)stream, size);
     140        log_verbose("%p:, %zu", stream, size);
    130141        return ENOTSUP;
    131142}
     
    133144static int iface_stream_data_write(void *stream, const void *buffer, size_t size)
    134145{
    135         log_info("%s: %s, %zu", __FUNCTION__, (char *)stream, size);
     146        log_verbose("%p: %zu", stream, size);
    136147        return ENOTSUP;
    137148}
Note: See TracChangeset for help on using the changeset viewer.