Changeset feeac0d in mainline for uspace/srv/audio


Ignore:
Timestamp:
2013-09-10T16:32:35Z (12 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4982d87
Parents:
e8d6ce2
Message:

Simplify use of list_foreach.

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

Legend:

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

    re8d6ce2 rfeeac0d  
    140140
    141141        pcm_format_silence(dest, size, &sink->format);
    142         list_foreach(sink->connections, it) {
    143                 connection_t * conn = connection_from_sink_list(it);
     142        list_foreach(sink->connections, sink_link, connection_t, conn) {
    144143                const int ret = connection_add_source_data(
    145144                    conn, dest, size, sink->format);
  • uspace/srv/audio/hound/audio_source.c

    re8d6ce2 rfeeac0d  
    106106                return ENOMEM;
    107107
    108         list_foreach(source->connections, it) {
    109                 connection_t *conn = connection_from_source_list(it);
     108        list_foreach(source->connections, source_link, connection_t, conn) {
    110109                const int ret = connection_push_data(conn, adata);
    111110                if (ret != EOK) {
  • uspace/srv/audio/hound/connection.h

    re8d6ce2 rfeeac0d  
    7676 * @return pointer to a connection structure, NULL on failure.
    7777 */
    78 static inline connection_t * connection_from_sink_list(link_t *l)
    79 {
    80         return l ? list_get_instance(l, connection_t, sink_link) : NULL;
    81 }
    82 
    83 /**
    84  * List instance helper.
    85  * @param l link
    86  * @return pointer to a connection structure, NULL on failure.
    87  */
    8878static inline connection_t * connection_from_hound_list(link_t *l)
    8979{
  • uspace/srv/audio/hound/hound.c

    re8d6ce2 rfeeac0d  
    4747#include "str_error.h"
    4848
    49 #define FIND_BY_NAME(type) \
    50 do { \
    51         assert(list); \
    52         assert(name); \
    53         list_foreach(*list, it) { \
    54                 audio_ ## type ## _t *dev = \
    55                     audio_ ## type ## _list_instance(it); \
    56                 if (str_cmp(name, dev->name) == 0) { \
    57                         log_debug("%s with name '%s' is in the list", \
    58                             #type, name); \
    59                         return dev; \
    60                 } \
    61         } \
    62         return NULL; \
    63 } while (0)
    64 
    6549/**
    6650 * Search devices by name.
     
    6852 * @return Pointer to the found device, NULL on failure.
    6953 */
    70 static audio_device_t * find_device_by_name(list_t *list, const char *name)
    71 {
    72         FIND_BY_NAME(device);
     54static audio_device_t *find_device_by_name(list_t *list, const char *name)
     55{
     56        assert(list);
     57        assert(name);
     58
     59        list_foreach(*list, link, audio_device_t, dev) {
     60                if (str_cmp(name, dev->name) == 0) {
     61                        log_debug("device with name '%s' is in the list",
     62                            name);
     63                        return dev;
     64                }
     65        }
     66
     67        return NULL;
    7368}
    7469
     
    7873 * @return Pointer to the found source, NULL on failure.
    7974 */
    80 static audio_source_t * find_source_by_name(list_t *list, const char *name)
    81 {
    82         FIND_BY_NAME(source);
     75static audio_source_t *find_source_by_name(list_t *list, const char *name)
     76{
     77        assert(list);
     78        assert(name);
     79
     80        list_foreach(*list, link, audio_source_t, dev) {
     81                if (str_cmp(name, dev->name) == 0) {
     82                        log_debug("source with name '%s' is in the list",
     83                            name);
     84                        return dev;
     85                }
     86        }
     87
     88        return NULL;
    8389}
    8490
     
    8894 * @return Pointer to the found sink, NULL on failure.
    8995 */
    90 static audio_sink_t * find_sink_by_name(list_t *list, const char *name)
    91 {
    92         FIND_BY_NAME(sink);
     96static audio_sink_t *find_sink_by_name(list_t *list, const char *name)
     97{
     98        assert(list);
     99        assert(name);
     100
     101        list_foreach(*list, link, audio_sink_t, dev) {
     102                if (str_cmp(name, dev->name) == 0) {
     103                        log_debug("sink with name '%s' is in the list",
     104                            name);
     105                        return dev;
     106                }
     107        }
     108
     109        return NULL;
    93110}
    94111
     
    111128                log_warning("Removing sink '%s' while still connected.", sink->name);
    112129        while (!list_empty(&sink->connections)) {
    113                 connection_t *conn =
    114                     connection_from_sink_list(list_first(&sink->connections));
     130                connection_t *conn = list_get_instance(
     131                    list_first(&sink->connections), connection_t, sink_link);
    115132                list_remove(&conn->hound_link);
    116133                connection_destroy(conn);
     
    128145static void hound_remove_source_internal(hound_t *hound, audio_source_t *source)
    129146{
    130         assert(hound);
    131         assert(source);
    132147        log_verbose("Removing source '%s'.", source->name);
    133148        if (!list_empty(&source->connections))
    134149                log_warning("Removing source '%s' while still connected.", source->name);
    135150        while (!list_empty(&source->connections)) {
    136                 connection_t *conn =
    137                     connection_from_source_list(list_first(&source->connections));
    138                 assert(conn);
     151                connection_t *conn = list_get_instance(
     152                    list_first(&source->connections), connection_t, source_link);
    139153                list_remove(&conn->hound_link);
    140154                connection_destroy(conn);
     
    223237        fibril_mutex_lock(&hound->list_guard);
    224238        hound_ctx_t *res = NULL;
    225         list_foreach(hound->contexts, it) {
    226                 hound_ctx_t *ctx = hound_ctx_from_link(it);
     239        list_foreach(hound->contexts, link, hound_ctx_t, ctx) {
    227240                if (hound_ctx_get_id(ctx) == id) {
    228241                        res = ctx;
     
    251264        }
    252265
    253         list_foreach(hound->devices, it) {
    254                 audio_device_t *dev = audio_device_list_instance(it);
     266        list_foreach(hound->devices, link, audio_device_t, dev) {
    255267                if (dev->id == id) {
    256268                        log_debug("Device with id %zu is already present", id);
  • uspace/srv/audio/hound/hound_ctx.c

    re8d6ce2 rfeeac0d  
    176176
    177177/**
    178  * List instance helper.
    179  * @param l link
    180  * @return pointer to a hound context structure, NULL on failure.
    181  */
    182 static inline hound_ctx_stream_t *hound_ctx_stream_from_link(link_t *l)
    183 {
    184         return l ? list_get_instance(l, hound_ctx_stream_t, link) : NULL;
    185 }
    186 
    187 /**
    188178 * New stream append helper.
    189179 * @param ctx hound context.
     
    417407        pcm_format_silence(buffer, size, &source->format);
    418408        fibril_mutex_lock(&ctx->guard);
    419         list_foreach(ctx->streams, it) {
    420                 hound_ctx_stream_t *stream = hound_ctx_stream_from_link(it);
     409        list_foreach(ctx->streams, link, hound_ctx_stream_t, stream) {
    421410                ssize_t copied = hound_ctx_stream_add_self(
    422411                    stream, buffer, size, &source->format);
     
    426415        log_verbose("CTX: %p. Pushing audio to %u connections", ctx,
    427416            list_count(&source->connections));
    428         list_foreach(source->connections, it) {
    429                 connection_t *conn = connection_from_source_list(it);
     417        list_foreach(source->connections, source_link, connection_t, conn) {
    430418                connection_push_data(conn, adata);
    431419        }
     
    444432        /* count available data */
    445433        size_t available_frames = -1;  /* this is ugly.... */
    446         list_foreach(sink->connections, it) {
    447                 connection_t *conn = connection_from_source_list(it);
     434        list_foreach(sink->connections, source_link, connection_t, conn) {
    448435                available_frames = min(available_frames,
    449436                    audio_pipe_frames(&conn->fifo));
     
    466453        /* mix data */
    467454        pcm_format_silence(buffer, bsize, &sink->format);
    468         list_foreach(sink->connections, it) {
    469                 connection_t *conn = connection_from_source_list(it);
     455        list_foreach(sink->connections, source_link, connection_t, conn) {
    470456                /* This should not trigger data update on the source */
    471457                const size_t copied = connection_add_source_data(
     
    476462        }
    477463        /* push to all streams */
    478         list_foreach(ctx->streams, it) {
    479                 hound_ctx_stream_t *stream = hound_ctx_stream_from_link(it);
     464        list_foreach(ctx->streams, link, hound_ctx_stream_t, stream) {
    480465                const int ret = stream_push_data(stream, adata);
    481466                if (ret != EOK)
  • uspace/srv/audio/hound/hound_ctx.h

    re8d6ce2 rfeeac0d  
    5858} hound_ctx_t;
    5959
    60 /**
    61  * List instance helper.
    62  * @param l link
    63  * @return pointer to a hound context structure, NULL on failure.
    64  */
    65 static inline hound_ctx_t *hound_ctx_from_link(link_t *l)
    66 {
    67         return l ? list_get_instance(l, hound_ctx_t, link) : NULL;
    68 }
    69 
    7060typedef struct hound_ctx_stream hound_ctx_stream_t;
    7161
Note: See TracChangeset for help on using the changeset viewer.