| 1 | /*
|
|---|
| 2 | * Copyright (c) 2012 Jan Vesely
|
|---|
| 3 | * All rights reserved.
|
|---|
| 4 | *
|
|---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 6 | * modification, are permitted provided that the following conditions
|
|---|
| 7 | * are met:
|
|---|
| 8 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup audio
|
|---|
| 30 | * @brief HelenOS sound server
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #include <assert.h>
|
|---|
| 37 | #include <errno.h>
|
|---|
| 38 | #include <macros.h>
|
|---|
| 39 | #include <stdlib.h>
|
|---|
| 40 | #include <str.h>
|
|---|
| 41 | #include <str_error.h>
|
|---|
| 42 |
|
|---|
| 43 | #include "audio_source.h"
|
|---|
| 44 | #include "audio_sink.h"
|
|---|
| 45 | #include "log.h"
|
|---|
| 46 |
|
|---|
| 47 | /**
|
|---|
| 48 | * Initialize audio source strcture.
|
|---|
| 49 | * @param source The structure to initialize.
|
|---|
| 50 | * @param name String identifier of the audio source.
|
|---|
| 51 | * @param data Backend data.
|
|---|
| 52 | * @param connection_change Connect/disconnect callback.
|
|---|
| 53 | * @param update_available_data Data request callback.
|
|---|
| 54 | * @return Error code.
|
|---|
| 55 | */
|
|---|
| 56 | int audio_source_init(audio_source_t *source, const char *name, void *data,
|
|---|
| 57 | int (*connection_change)(audio_source_t *, bool new),
|
|---|
| 58 | int (*update_available_data)(audio_source_t *, size_t),
|
|---|
| 59 | const pcm_format_t *f)
|
|---|
| 60 | {
|
|---|
| 61 | assert(source);
|
|---|
| 62 | if (!name || !f) {
|
|---|
| 63 | log_debug("Incorrect parameters.");
|
|---|
| 64 | return EINVAL;
|
|---|
| 65 | }
|
|---|
| 66 | link_initialize(&source->link);
|
|---|
| 67 | list_initialize(&source->connections);
|
|---|
| 68 | source->name = str_dup(name);
|
|---|
| 69 | if (!source->name)
|
|---|
| 70 | return ENOMEM;
|
|---|
| 71 | source->private_data = data;
|
|---|
| 72 | source->connection_change = connection_change;
|
|---|
| 73 | source->update_available_data = update_available_data;
|
|---|
| 74 | source->format = *f;
|
|---|
| 75 | log_verbose("Initialized source (%p) '%s'", source, source->name);
|
|---|
| 76 | return EOK;
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| 79 | /**
|
|---|
| 80 | * Release resources claimed by initialization.
|
|---|
| 81 | * @param source The structure to cleanup.
|
|---|
| 82 | */
|
|---|
| 83 | void audio_source_fini(audio_source_t *source)
|
|---|
| 84 | {
|
|---|
| 85 | assert(source);
|
|---|
| 86 | free(source->name);
|
|---|
| 87 | source->name = NULL;
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | /**
|
|---|
| 91 | * @}
|
|---|
| 92 | */
|
|---|