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));
|
---|
56 | if (source->connection_change)
|
---|
57 | source->connection_change(source, true);
|
---|
58 | if (sink->connection_change)
|
---|
59 | sink->connection_change(sink, true);
|
---|
60 | }
|
---|
61 | return conn;
|
---|
62 | }
|
---|
63 |
|
---|
64 | void connection_destroy(connection_t *connection)
|
---|
65 | {
|
---|
66 | assert(connection);
|
---|
67 | assert(!link_in_use(&connection->hound_link));
|
---|
68 | list_remove(&connection->source_link);
|
---|
69 | list_remove(&connection->sink_link);
|
---|
70 | connection->sink->connection_change(connection->sink, false);
|
---|
71 | connection->source->connection_change(connection->source, false);
|
---|
72 | free(connection);
|
---|
73 | }
|
---|
74 |
|
---|
75 | ssize_t connection_add_source_data(connection_t *connection, void *data,
|
---|
76 | size_t size, pcm_format_t format)
|
---|
77 | {
|
---|
78 | assert(connection);
|
---|
79 | if (!data)
|
---|
80 | return EBADMEM;
|
---|
81 | return audio_source_add_self(connection->source, data, size, &format);
|
---|
82 | }
|
---|
83 |
|
---|
84 | int connection_new_data(connection_t *connection, const void *data, size_t size)
|
---|
85 | {
|
---|
86 | assert(connection);
|
---|
87 | return ENOTSUP;
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * @}
|
---|
93 | */
|
---|