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 | #ifndef CONNECTION_H_
|
---|
37 | #define CONNECTION_H_
|
---|
38 |
|
---|
39 | #include <assert.h>
|
---|
40 | #include <adt/list.h>
|
---|
41 | #include <pcm/format.h>
|
---|
42 |
|
---|
43 | #include "audio_data.h"
|
---|
44 | #include "audio_source.h"
|
---|
45 | #include "audio_sink.h"
|
---|
46 |
|
---|
47 | /** Source->sink connection structure */
|
---|
48 | typedef struct {
|
---|
49 | /** Source's connections link */
|
---|
50 | link_t source_link;
|
---|
51 | /** Sink's connections link */
|
---|
52 | link_t sink_link;
|
---|
53 | /** Hound's connections link */
|
---|
54 | link_t hound_link;
|
---|
55 | /** audio data pipe */
|
---|
56 | audio_pipe_t fifo;
|
---|
57 | /** Target sink */
|
---|
58 | audio_sink_t *sink;
|
---|
59 | /** Target source */
|
---|
60 | audio_source_t *source;
|
---|
61 | } connection_t;
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * List instance helper.
|
---|
65 | * @param l link
|
---|
66 | * @return pointer to a connection structure, NULL on failure.
|
---|
67 | */
|
---|
68 | static inline connection_t *connection_from_source_list(link_t *l)
|
---|
69 | {
|
---|
70 | return l ? list_get_instance(l, connection_t, source_link) : NULL;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * List instance helper.
|
---|
75 | * @param l link
|
---|
76 | * @return pointer to a connection structure, NULL on failure.
|
---|
77 | */
|
---|
78 | static inline connection_t *connection_from_hound_list(link_t *l)
|
---|
79 | {
|
---|
80 | return l ? list_get_instance(l, connection_t, hound_link) : NULL;
|
---|
81 | }
|
---|
82 |
|
---|
83 | connection_t *connection_create(audio_source_t *source, audio_sink_t *sink);
|
---|
84 | void connection_destroy(connection_t *connection);
|
---|
85 |
|
---|
86 | errno_t connection_add_source_data(connection_t *connection, void *data,
|
---|
87 | size_t size, pcm_format_t format);
|
---|
88 |
|
---|
89 | errno_t connection_push_data(connection_t *connection, audio_data_t *adata);
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * Source name getter.
|
---|
93 | * @param connection Connection to the source.
|
---|
94 | * @param valid string identifier, "no source" or "unnamed source" on failure.
|
---|
95 | */
|
---|
96 | static inline const char *connection_source_name(connection_t *connection)
|
---|
97 | {
|
---|
98 | assert(connection);
|
---|
99 | if (connection->source && connection->source->name)
|
---|
100 | return connection->source->name;
|
---|
101 | // TODO assert?
|
---|
102 | return connection->source ? "unnamed source" : "no source";
|
---|
103 | }
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Sink name getter.
|
---|
107 | * @param connection Connection to the sink.
|
---|
108 | * @param valid string identifier, "no source" or "unnamed source" on failure.
|
---|
109 | */
|
---|
110 | static inline const char *connection_sink_name(connection_t *connection)
|
---|
111 | {
|
---|
112 | assert(connection);
|
---|
113 | if (connection->sink && connection->sink->name)
|
---|
114 | return connection->sink->name;
|
---|
115 | // TODO assert?
|
---|
116 | return connection->source ? "unnamed sink" : "no sink";
|
---|
117 | }
|
---|
118 |
|
---|
119 | #endif
|
---|
120 | /**
|
---|
121 | * @}
|
---|
122 | */
|
---|