Changeset 876f5561 in mainline for uspace/lib/hound/src/client.c


Ignore:
Timestamp:
2013-04-10T23:06:52Z (12 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f0a647c
Parents:
eb0ef51
Message:

libhound: doxygen

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/hound/src/client.c

    reb0ef51 r876f5561  
    4545#include "client.h"
    4646
    47 /***
    48  * CLIENT SIDE
    49  ***/
    50 
     47/** Stream structure */
    5148typedef struct hound_stream {
     49        /** link in context's list */
    5250        link_t link;
     51        /** audio data format fo the stream */
    5352        pcm_format_t format;
     53        /** IPC exchange representing the stream (in STREAM MODE) */
    5454        async_exch_t *exch;
     55        /** parent context */
    5556        hound_context_t *context;
     57        /** Stream flags */
    5658        int flags;
    5759} hound_stream_t;
    5860
     61/**
     62 * Linked list isntacen helper function.
     63 * @param l link
     64 * @return hound stream isntance.
     65 */
    5966static inline hound_stream_t * hound_stream_from_link(link_t *l)
    6067{
     
    6269}
    6370
     71/** Hound client context structure */
    6472typedef struct hound_context {
     73        /** Audio session */
    6574        hound_sess_t *session;
     75        /** context name, reported to the daemon */
    6676        const char *name;
     77        /** True if the instance is record context */
    6778        bool record;
     79        /** List of associated streams */
    6880        list_t stream_list;
     81        /** Main stream helper structure */
    6982        struct {
    7083                hound_stream_t *stream;
     
    7285                size_t bsize;
    7386        } main;
     87        /** Assigned context id */
    7488        hound_context_id_t id;
    7589} hound_context_t;
    7690
    77 
     91/**
     92 * Alloc and initialize context structure.
     93 * @param name Base for the real context name, will add task id.
     94 * @param record True if the new context should capture audio data.
     95 * @param format PCM format of the main pipe.
     96 * @param bsize Server size buffer size of the main stream.
     97 * @return valid pointer to initialized structure on success, NULL on failure
     98 */
    7899static hound_context_t *hound_context_create(const char *name, bool record,
    79100    pcm_format_t format, size_t bsize)
     
    111132}
    112133
     134/**
     135 * Playback context helper function.
     136 * @param name Base for the real context name, will add task id.
     137 * @param format PCM format of the main pipe.
     138 * @param bsize Server size buffer size of the main stream.
     139 * @return valid pointer to initialized structure on success, NULL on failure
     140 */
    113141hound_context_t * hound_context_create_playback(const char *name,
    114142    pcm_format_t format, size_t bsize)
     
    117145}
    118146
     147/**
     148 * Record context helper function.
     149 * @param name Base for the real context name, will add task id.
     150 * @param format PCM format of the main pipe.
     151 * @param bsize Server size buffer size of the main stream.
     152 * @return valid pointer to initialized structure on success, NULL on failure
     153 */
    119154hound_context_t * hound_context_create_capture(const char *name,
    120155    pcm_format_t format, size_t bsize)
     
    123158}
    124159
     160/**
     161 * Correctly dispose of the hound context structure.
     162 * @param hound context to remove.
     163 *
     164 * The function will destroy all associated streams first. Pointers
     165 * to these structures will become invalid and the function will block
     166 * if any of these stream needs to be drained first.
     167 */
    125168void hound_context_destroy(hound_context_t *hound)
    126169{
     
    139182}
    140183
     184/**
     185 * Get a list of possible connection targets.
     186 * @param[in] hound Hound context.
     187 * @param[out] names list of target string ids.
     188 * @param[out] count Number of elements in @p names list
     189 * @return Error code.
     190 *
     191 * The function will return deice sinks or source based on the context type.
     192 */
    141193int hound_context_get_available_targets(hound_context_t *hound,
    142194    const char ***names, size_t *count)
     
    149201}
    150202
     203/**
     204 * Get a list of targets connected to the context.
     205 * @param[in] hound Hound context.
     206 * @param[out] names list of target string ids.
     207 * @param[out] count Number of elements in @p names list
     208 * @return Error code.
     209 */
    151210int hound_context_get_connected_targets(hound_context_t *hound,
    152211    const char ***names, size_t *count)
     
    160219}
    161220
     221/**
     222 * Create a new connection to the target.
     223 * @param hound Hound context.
     224 * @param target String identifier of the desired target.
     225 * @return Error code.
     226 *
     227 * The function recognizes special 'HOUND_DEFAULT_TARGET' and will
     228 * connect to the first possible target if it is passed this value.
     229 */
    162230int hound_context_connect_target(hound_context_t *hound, const char* target)
    163231{
     
    189257}
    190258
     259/**
     260 * Destroy a connection to the target.
     261 * @param hound Hound context.
     262 * @param target String identifier of the desired target.
     263 * @return Error code.
     264 */
    191265int hound_context_disconnect_target(hound_context_t *hound, const char* target)
    192266{
     
    203277}
    204278
     279/**
     280 * Create a new stream associated with the context.
     281 * @param hound Hound context.
     282 * @param flags new stream flags.
     283 * @param format new stream PCM format.
     284 * @param bzise new stream server side buffer size (in bytes)
     285 * @return Valid pointer to a stream instance, NULL on failure.
     286 */
    205287hound_stream_t *hound_stream_create(hound_context_t *hound, unsigned flags,
    206288    pcm_format_t format, size_t bsize)
     
    229311}
    230312
     313/**
     314 * Destroy existing stream
     315 * @param stream The stream to destroy.
     316 *
     317 * Function will wait until the server side buffer is empty if the
     318 * HOUND_STREAM_DRAIN_ON_EXIT flag was set on creation.
     319 */
    231320void hound_stream_destroy(hound_stream_t *stream)
    232321{
     
    241330}
    242331
     332/**
     333 * Send new data to a stream.
     334 * @param stream The target stream
     335 * @param data data buffer
     336 * @param size size of the @p data buffer.
     337 * @return error code.
     338 */
    243339int hound_stream_write(hound_stream_t *stream, const void *data, size_t size)
    244340{
     
    249345}
    250346
     347/**
     348 * Get data from a stream.
     349 * @param stream The target stream.
     350 * @param data data buffer.
     351 * @param size size of the @p data buffer.
     352 * @return error code.
     353 */
    251354int hound_stream_read(hound_stream_t *stream, void *data, size_t size)
    252355{
     
    257360}
    258361
     362/**
     363 * Main stream getter function.
     364 * @param hound Houndcontext.
     365 * @return Valid stream pointer, NULL on failure.
     366 *
     367 * The function will create new stream, or return a pointer to the exiting one
     368 * if it exists.
     369 */
    259370static hound_stream_t * hound_get_main_stream(hound_context_t *hound)
    260371{
     
    267378}
    268379
     380/**
     381 * Send new data to the main stream.
     382 * @param stream The target stream
     383 * @param data data buffer
     384 * @param size size of the @p data buffer.
     385 * @return error code.
     386 */
    269387int hound_write_main_stream(hound_context_t *hound,
    270388    const void *data, size_t size)
    271389{
    272390        assert(hound);
     391        if (hound->record)
     392                return EINVAL;
     393
    273394        hound_stream_t *mstream = hound_get_main_stream(hound);
    274395        if (!mstream)
     
    277398}
    278399
     400/**
     401 * Get data from the main stream.
     402 * @param stream The target stream
     403 * @param data data buffer
     404 * @param size size of the @p data buffer.
     405 * @return error code.
     406 */
    279407int hound_read_main_stream(hound_context_t *hound, void *data, size_t size)
    280408{
    281409        assert(hound);
     410        if (!hound->record)
     411                return EINVAL;
    282412        hound_stream_t *mstream = hound_get_main_stream(hound);
    283413        if (!mstream)
     
    286416}
    287417
     418/**
     419 * Destroy the old main stream and replace it with a new one with fresh data.
     420 * @param hound Hound context.
     421 * @param data data buffer.
     422 * @param size size of the @p data buffer.
     423 * @return error code.
     424 *
     425 * NOT IMPLEMENTED
     426 */
    288427int hound_write_replace_main_stream(hound_context_t *hound,
    289428    const void *data, size_t size)
     
    296435}
    297436
    298 int hound_context_set_main_stream_format(hound_context_t *hound,
    299     unsigned channels, unsigned rate, pcm_sample_format_t format)
     437/**
     438 * Destroy the old main stream and replace it with a new one using new params.
     439 * @param hound Hound context.
     440 * @param channels
     441 * @return error code.
     442 *
     443 * NOT IMPLEMENTED
     444 */
     445int hound_context_set_main_stream_params(hound_context_t *hound,
     446    pcm_format_t format, size_t bsize)
    300447{
    301448        assert(hound);
     
    304451}
    305452
     453/**
     454 * Write data immediately to a new stream, and wait for it to drain.
     455 * @param hound Hound context.
     456 * @param format pcm data format.
     457 * @param data data buffer
     458 * @param size @p data buffer size
     459 * @return Error code.
     460 *
     461 * This functnion creates a new stream writes the data, ti waits for the stream
     462 * to drain and destroys it before returning.
     463 */
    306464int hound_write_immediate(hound_context_t *hound, pcm_format_t format,
    307465    const void *data, size_t size)
    308466{
    309467        assert(hound);
     468        if (hound->record)
     469                return EINVAL;
    310470        hound_stream_t *tmpstream = hound_stream_create(hound, 0, format, size);
    311471        if (!tmpstream)
     
    319479        return ret;
    320480}
    321 
    322 
    323481/**
    324482 * @}
Note: See TracChangeset for help on using the changeset viewer.