[fa60cd69] | 1 | /*
|
---|
| 2 | * Copyright (c) 2013 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 <malloc.h>
|
---|
| 37 | #include <errno.h>
|
---|
| 38 |
|
---|
| 39 | #include "log.h"
|
---|
| 40 | #include "connection.h"
|
---|
| 41 |
|
---|
| 42 | connection_t *connection_create(audio_source_t *source, audio_sink_t *sink)
|
---|
| 43 | {
|
---|
| 44 | assert(source);
|
---|
| 45 | assert(sink);
|
---|
| 46 | connection_t *conn = malloc(sizeof(connection_t));
|
---|
| 47 | if (conn) {
|
---|
| 48 | link_initialize(&conn->source_link);
|
---|
| 49 | link_initialize(&conn->sink_link);
|
---|
| 50 | link_initialize(&conn->hound_link);
|
---|
| 51 | conn->sink = sink;
|
---|
| 52 | conn->source = source;
|
---|
| 53 | list_append(&conn->source_link, &source->connections);
|
---|
| 54 | list_append(&conn->sink_link, &sink->connections);
|
---|
| 55 | audio_sink_set_format(sink, audio_source_format(source));
|
---|
[b893cd6] | 56 | if (source->connection_change)
|
---|
| 57 | source->connection_change(source, true);
|
---|
| 58 | if (sink->connection_change)
|
---|
| 59 | sink->connection_change(sink, true);
|
---|
[6da3baec] | 60 | log_debug("CONNECTED: %s -> %s", source->name, sink->name);
|
---|
[fa60cd69] | 61 | }
|
---|
| 62 | return conn;
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void connection_destroy(connection_t *connection)
|
---|
| 66 | {
|
---|
| 67 | assert(connection);
|
---|
| 68 | assert(!link_in_use(&connection->hound_link));
|
---|
| 69 | list_remove(&connection->source_link);
|
---|
| 70 | list_remove(&connection->sink_link);
|
---|
[6da3baec] | 71 | if (connection->sink && connection->sink->connection_change)
|
---|
| 72 | connection->sink->connection_change(connection->sink, false);
|
---|
| 73 | if (connection->source && connection->source->connection_change)
|
---|
| 74 | connection->source->connection_change(connection->source, false);
|
---|
| 75 | log_debug("DISCONNECTED: %s -> %s",
|
---|
| 76 | connection->source->name, connection->sink->name);
|
---|
[fa60cd69] | 77 | free(connection);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | ssize_t connection_add_source_data(connection_t *connection, void *data,
|
---|
| 81 | size_t size, pcm_format_t format)
|
---|
| 82 | {
|
---|
| 83 | assert(connection);
|
---|
| 84 | if (!data)
|
---|
| 85 | return EBADMEM;
|
---|
| 86 | return audio_source_add_self(connection->source, data, size, &format);
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | int connection_new_data(connection_t *connection, const void *data, size_t size)
|
---|
| 90 | {
|
---|
| 91 | assert(connection);
|
---|
| 92 | return ENOTSUP;
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 |
|
---|
| 96 | /**
|
---|
| 97 | * @}
|
---|
| 98 | */
|
---|