Ignore:
Timestamp:
2012-07-13T03:24:17Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d93a5a6f
Parents:
d01e635
Message:

hound: Only few more TODOs left

File:
1 edited

Legend:

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

    rd01e635 r1df3018a  
    4242
    4343#include "audio_source.h"
     44#include "audio_sink.h"
    4445#include "log.h"
    4546
    4647
    47 int audio_source_init(audio_source_t *source, const char* name)
     48int audio_source_init(audio_source_t *source, const char *name, void *data,
     49    int (*connection_change)(audio_source_t *),
     50    int (*update_available_data)(audio_source_t *, size_t),
     51    const audio_format_t *f)
    4852{
    4953        assert(source);
    50         if (!name) {
     54        if (!name || !f) {
    5155                log_debug("Incorrect parameters.");
    5256                return EINVAL;
     
    5458        link_initialize(&source->link);
    5559        source->name = str_dup(name);
    56         source->connected_change.hook = NULL;
    57         source->connected_change.arg = NULL;
    58         source->get_data.hook = NULL;
    59         source->get_data.arg = NULL;
    60         source->available.base = NULL;
    61         source->available.size = 0;
    62         log_verbose("Initialized source (%p) '%s' with ANY audio format",
    63             source, source->name);
     60        source->private_data = data;
     61        source->connection_change = connection_change;
     62        source->update_available_data = update_available_data;
     63        source->connected_sink = NULL;
     64        source->format = *f;
     65        source->available_data.base = NULL;
     66        source->available_data.size = 0;
     67        log_verbose("Initialized source (%p) '%s'", source, source->name);
    6468        return EOK;
    6569}
    6670
    67 int audio_source_connected(audio_source_t *source, const audio_format_t *f)
     71void audio_source_fini(audio_source_t *source)
     72{
     73        if (!source)
     74                return;
     75        assert(source->connected_sink == NULL);
     76        free(source->name);
     77        free(source);
     78}
     79
     80int audio_source_connected(audio_source_t *source, struct audio_sink *sink)
    6881{
    6982        assert(source);
    70         if (!f) {
    71                 log_debug("Incorrect parameters.");
    72                 return EINVAL;
     83        audio_sink_t *old_sink = source->connected_sink;
     84        const audio_format_t old_format = source->format;
     85
     86        source->connected_sink = sink;
     87        if (audio_format_is_any(&source->format)) {
     88                assert(sink);
     89                assert(!audio_format_is_any(&sink->format));
     90                source->format = sink->format;
    7391        }
    74         if (source->connected_change.hook)
    75                 source->connected_change.hook(source->connected_change.arg, f);
     92        if (source->connection_change) {
     93                const int ret = source->connection_change(source);
     94                if (ret != EOK) {
     95                        source->format = old_format;
     96                        source->connected_sink = old_sink;
     97                        return ret;
     98                }
     99        }
    76100        return EOK;
    77101}
     
    96120                return ENOTSUP;
    97121        }
    98 
    99         if (source->available.size == 0) {
    100                 log_debug("No data to add");
    101                 return EOVERFLOW; /* In fact this is underflow... */
     122        if (source->available_data.base == NULL ||
     123            source->available_data.size == 0) {
     124                int ret = EOVERFLOW; /* In fact this is underflow... */
     125                if (source->update_available_data)
     126                        ret = source->update_available_data(source, size);
     127                if (ret != EOK) {
     128                        log_debug("No data to add");
     129                        return ret;
     130                }
    102131        }
    103132
    104         const size_t real_size = min(size, source->available.size);
     133        const size_t real_size = min(size, source->available_data.size);
    105134        const int ret =
    106             audio_format_mix(buffer, source->available.base, real_size, f);
     135            audio_format_mix(buffer, source->available_data.base, real_size, f);
    107136        if (ret != EOK) {
    108137                log_debug("Mixing failed");
    109138                return ret;
    110139        }
    111         source->available.base += real_size;
    112         source->available.size -= real_size;
     140        source->available_data.base += real_size;
     141        source->available_data.size -= real_size;
     142        buffer += real_size;
     143        size -= real_size;
     144
     145        //TODO update data again
     146        if (size)
     147                log_warning("not enough data");
     148
    113149        return EOK;
    114150}
Note: See TracChangeset for help on using the changeset viewer.