Changeset c799138 in mainline for uspace/srv/audio/hound/hound_ctx.c


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

hound: doxygen and cleanup

File:
1 edited

Legend:

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

    rf0a647c rc799138  
    4545static int update_data(audio_source_t *source, size_t size);
    4646
     47/**
     48 * Allocate and initialize hound context structure.
     49 * @param name String identifier.
     50 * @return Pointer to a new context structure, NULL on failure
     51 *
     52 * Creates record context structure.
     53 */
    4754hound_ctx_t *hound_record_ctx_get(const char *name)
    4855{
    49         return NULL;
    50 }
    51 
     56        hound_ctx_t *ctx = malloc(sizeof(hound_ctx_t));
     57        if (ctx) {
     58                link_initialize(&ctx->link);
     59                list_initialize(&ctx->streams);
     60                fibril_mutex_initialize(&ctx->guard);
     61                ctx->source = NULL;
     62                ctx->sink = malloc(sizeof(audio_sink_t));
     63                if (!ctx->sink) {
     64                        free(ctx);
     65                        return NULL;
     66                }
     67                // TODO provide sink functions
     68                const int ret = audio_sink_init(ctx->sink, name, ctx, NULL,
     69                    NULL, &AUDIO_FORMAT_DEFAULT);
     70                if (ret != EOK) {
     71                        free(ctx->sink);
     72                        free(ctx);
     73                        return NULL;
     74                }
     75        }
     76        return ctx;
     77}
     78
     79/**
     80 * Allocate and initialize hound context structure.
     81 * @param name String identifier.
     82 * @return Pointer to a new context structure, NULL on failure
     83 *
     84 * Creates record context structure.
     85 */
    5286hound_ctx_t *hound_playback_ctx_get(const char *name)
    5387{
     
    74108}
    75109
     110/**
     111 * Destroy existing context structure.
     112 * @param ctx hound cotnext to destroy.
     113 */
    76114void hound_ctx_destroy(hound_ctx_t *ctx)
    77115{
     
    88126}
    89127
     128/**
     129 * Retrieve associated context id.
     130 * @param ctx hound context.
     131 * @return context id of the context.
     132 */
    90133hound_context_id_t hound_ctx_get_id(hound_ctx_t *ctx)
    91134{
     
    94137}
    95138
     139/**
     140 * Query playback/record status of a hound context.
     141 * @param ctx Hound context.
     142 * @return True if ctx  is a recording context.
     143 */
    96144bool hound_ctx_is_record(hound_ctx_t *ctx)
    97145{
     
    104152 * STREAMS
    105153 */
     154
     155/** Hound stream structure. */
    106156typedef struct hound_ctx_stream {
     157        /** Hound context streams link */
    107158        link_t link;
     159        /** Audio data pipe */
    108160        audio_pipe_t fifo;
     161        /** Parent context */
    109162        hound_ctx_t *ctx;
     163        /** Stream data format */
    110164        pcm_format_t format;
     165        /** Stream modifiers */
    111166        int flags;
     167        /** Maximum allowed buffer size */
    112168        size_t allowed_size;
     169        /** Fifo access synchronization */
    113170        fibril_mutex_t guard;
     171        /** buffer status change condition */
    114172        fibril_condvar_t change;
    115173} hound_ctx_stream_t;
    116174
     175/**
     176 * List instance helper.
     177 * @param l link
     178 * @return pointer to a hound context structure, NULL on failure.
     179 */
    117180static inline hound_ctx_stream_t *hound_ctx_stream_from_link(link_t *l)
    118181{
     
    120183}
    121184
     185/**
     186 * New stream append helper.
     187 * @param ctx hound context.
     188 * @param stream A new stream.
     189 */
    122190static inline void stream_append(hound_ctx_t *ctx, hound_ctx_stream_t *stream)
    123191{
     
    129197}
    130198
     199/**
     200 * Old stream remove helper.
     201 * @param ctx hound context.
     202 * @param stream An old stream.
     203 */
    131204static inline void stream_remove(hound_ctx_t *ctx, hound_ctx_stream_t *stream)
    132205{
     
    138211}
    139212
     213/**
     214 * Create new stream.
     215 * @param ctx Assocaited hound context.
     216 * @param flags Stream modidfiers.
     217 * @param format PCM data format.
     218 * @param buffer_size Maximum allowed buffer size.
     219 * @return Pointer to a new stream structure, NULL on failure.
     220 */
    140221hound_ctx_stream_t *hound_ctx_create_stream(hound_ctx_t *ctx, int flags,
    141222        pcm_format_t format, size_t buffer_size)
     
    160241}
    161242
     243/**
     244 * Destroy existing stream structure.
     245 * @param stream The stream to destroy.
     246 *
     247 * The function will print warning if there are data in the buffer.
     248 */
    162249void hound_ctx_destroy_stream(hound_ctx_stream_t *stream)
    163250{
     
    177264}
    178265
    179 
     266/**
     267 * Write new data to a stream.
     268 * @param stream The destination stream.
     269 * @param data audio data buffer.
     270 * @param size size of the @p data buffer.
     271 * @return Error code.
     272 */
    180273int hound_ctx_stream_write(hound_ctx_stream_t *stream, const void *data,
    181274    size_t size)
     
    199292}
    200293
     294/**
     295 * Read data from a buffer.
     296 * @param stream The source buffer.
     297 * @param data Destination data buffer.
     298 * @param size Size of the @p data buffer.
     299 * @return Error code.
     300 */
    201301int hound_ctx_stream_read(hound_ctx_stream_t *stream, void *data, size_t size)
    202302{
     
    205305}
    206306
     307/**
     308 * Add (mix) stream data to the destination buffer.
     309 * @param stream The source stream.
     310 * @param data Destination audio buffer.
     311 * @param size Size of the @p data buffer.
     312 * @param format Destination data format.
     313 * @return Size of the destination buffer touch with stream's data,
     314 *         error code on failure.
     315 */
    207316ssize_t hound_ctx_stream_add_self(hound_ctx_stream_t *stream, void *data,
    208317    size_t size, const pcm_format_t *f)
     
    216325}
    217326
     327/**
     328 * Block until the stream's buffer is empty.
     329 * @param stream Target stream.
     330 */
    218331void hound_ctx_stream_drain(hound_ctx_stream_t *stream)
    219332{
     
    226339}
    227340
     341/**
     342 * Update context data.
     343 * @param source Source abstraction.
     344 * @param size Required size in source's format.
     345 * @return error code.
     346 *
     347 * Mixes data from all streams and pushes it to all connections.
     348 */
    228349int update_data(audio_source_t *source, size_t size)
    229350{
Note: See TracChangeset for help on using the changeset viewer.