Changeset 3b6c1d4 in mainline


Ignore:
Timestamp:
2013-04-02T15:13:12Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
62beb4b
Parents:
2d1fdcad
Message:

hound: implement context manipulation

Location:
uspace/srv/audio/hound
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/audio/hound/Makefile

    r2d1fdcad r3b6c1d4  
    4747        audio_source.c \
    4848        hound.c \
     49        hound_ctx.c \
    4950        iface.c \
    5051        main.c
  • uspace/srv/audio/hound/hound.c

    r2d1fdcad r3b6c1d4  
    7575        FIND_BY_NAME(sink);
    7676}
     77
    7778static int hound_disconnect_internal(hound_t *hound, const char* source_name, const char* sink_name);
    7879
     
    8283        fibril_mutex_initialize(&hound->list_guard);
    8384        list_initialize(&hound->devices);
     85        list_initialize(&hound->contexts);
    8486        list_initialize(&hound->sources);
    8587        list_initialize(&hound->sinks);
    8688        return EOK;
     89}
     90
     91int hound_add_ctx(hound_t *hound, hound_ctx_t *ctx)
     92{
     93        log_info("Trying to add context %p", ctx);
     94        assert(hound);
     95        if (!ctx)
     96                return EINVAL;
     97        list_append(&ctx->link, &hound->contexts);
     98        //TODO register sinks/sources
     99        return EOK;
     100}
     101
     102int hound_remove_ctx(hound_t *hound, hound_ctx_t *ctx)
     103{
     104        assert(hound);
     105        if (!ctx)
     106                return EINVAL;
     107        list_remove(&ctx->link);
     108        return EOK;
     109}
     110
     111hound_ctx_t *hound_get_ctx_by_id(hound_t *hound, hound_context_id_t id)
     112{
     113        assert(hound);
     114
     115        //TODO locking
     116
     117        list_foreach(hound->contexts, it) {
     118                hound_ctx_t *ctx = hound_ctx_from_link(it);
     119                if (hound_ctx_get_id(ctx) == id)
     120                        return ctx;
     121        }
     122        return NULL;
    87123}
    88124
  • uspace/srv/audio/hound/hound.h

    r2d1fdcad r3b6c1d4  
    4343#include <fibril_synch.h>
    4444#include <pcm/format.h>
     45#include <hound/protocol.h>
    4546
     47#include "hound_ctx.h"
    4648#include "audio_source.h"
    4749#include "audio_sink.h"
     
    5153        fibril_mutex_t list_guard;
    5254        list_t devices;
     55        list_t contexts;
    5356        list_t sources;
    5457        list_t sinks;
     
    5659
    5760int hound_init(hound_t *hound);
     61int hound_add_ctx(hound_t *hound, hound_ctx_t *ctx);
     62int hound_remove_ctx(hound_t *hound, hound_ctx_t *ctx);
     63hound_ctx_t *hound_get_ctx_by_id(hound_t *hound, hound_context_id_t id);
     64
    5865int hound_add_device(hound_t *hound, service_id_t id, const char* name);
    5966int hound_add_source(hound_t *hound, audio_source_t *source);
  • uspace/srv/audio/hound/iface.c

    r2d1fdcad r3b6c1d4  
    3838#include <hound/protocol.h>
    3939#include <malloc.h>
     40
     41#include "hound.h"
     42#include "hound_ctx.h"
    4043#include "log.h"
    4144
     
    4346    const char *name, bool record)
    4447{
    45         log_info("%s: %p, %s, %s", __FUNCTION__, server, name, record ? "REC" : "PLAY");
    46         *id = 1;
    47         return EOK;
     48        assert(server);
     49        assert(id);
     50        assert(name);
     51
     52        hound_ctx_t *ctx = record ? hound_record_ctx_get(name) :
     53            hound_playback_ctx_get(name);
     54        if (!ctx)
     55                return ENOMEM;
     56
     57        const int ret = hound_add_ctx(server, ctx);
     58        if (ret != EOK)
     59                hound_ctx_destroy(ctx);
     60        else
     61                *id = hound_ctx_get_id(ctx);
     62        return ret;
    4863}
    4964
    5065static int iface_rem_context(void *server, hound_context_id_t id)
    5166{
     67        assert(server);
     68        hound_ctx_t *ctx = hound_get_ctx_by_id(server, id);
     69        if (!ctx)
     70                return EINVAL;
     71        hound_remove_ctx(server, ctx);
     72        hound_ctx_destroy(ctx);
    5273        log_info("%s: %p, %d", __FUNCTION__, server, id);
    53         return ENOTSUP;
     74        return EOK;
    5475}
    5576
    5677static bool iface_is_record_context(void *server, hound_context_id_t id)
    5778{
     79        assert(server);
     80        hound_ctx_t *ctx = hound_get_ctx_by_id(server, id);
     81        if (!ctx)
     82                return false;
    5883        log_info("%s: %p, %d", __FUNCTION__, server, id);
    59         return false;
     84        return hound_ctx_is_record(ctx);
    6085}
    6186
     
    7398{
    7499        log_info("%s: %p, %s -> %s", __FUNCTION__, server, source, sink);
    75         return EOK;
     100        return ENOTSUP;
    76101}
    77102
     
    89114            pcm_sample_format_str(format.sample_format));
    90115        *data = (void*)"TEST_STREAM";
    91         return EOK;
     116        return ENOTSUP;
    92117}
    93118
Note: See TracChangeset for help on using the changeset viewer.