[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 | #ifndef CONNECTION_H_
|
---|
| 37 | #define CONNECTION_H_
|
---|
| 38 |
|
---|
| 39 | #include <assert.h>
|
---|
| 40 | #include <adt/list.h>
|
---|
| 41 | #include <pcm/format.h>
|
---|
| 42 |
|
---|
[5029c788] | 43 | #include "audio_data.h"
|
---|
[fa60cd69] | 44 | #include "audio_source.h"
|
---|
| 45 | #include "audio_sink.h"
|
---|
| 46 |
|
---|
[c799138] | 47 | /** Source->sink connection structure */
|
---|
[fa60cd69] | 48 | typedef struct {
|
---|
[c799138] | 49 | /** Source's connections link */
|
---|
[fa60cd69] | 50 | link_t source_link;
|
---|
[c799138] | 51 | /** Sink's connections link */
|
---|
[fa60cd69] | 52 | link_t sink_link;
|
---|
[c799138] | 53 | /** Hound's connections link */
|
---|
[fa60cd69] | 54 | link_t hound_link;
|
---|
[c799138] | 55 | /** audio data pipe */
|
---|
[50179b63] | 56 | audio_pipe_t fifo;
|
---|
[c799138] | 57 | /** Target sink */
|
---|
[fa60cd69] | 58 | audio_sink_t *sink;
|
---|
[c799138] | 59 | /** Target source */
|
---|
[fa60cd69] | 60 | audio_source_t *source;
|
---|
| 61 | } connection_t;
|
---|
| 62 |
|
---|
[c799138] | 63 | /**
|
---|
| 64 | * List instance helper.
|
---|
| 65 | * @param l link
|
---|
| 66 | * @return pointer to a connection structure, NULL on failure.
|
---|
| 67 | */
|
---|
[1433ecda] | 68 | static inline connection_t *connection_from_source_list(link_t *l)
|
---|
[fa60cd69] | 69 | {
|
---|
[6da3baec] | 70 | return l ? list_get_instance(l, connection_t, source_link) : NULL;
|
---|
[fa60cd69] | 71 | }
|
---|
| 72 |
|
---|
[c799138] | 73 | /**
|
---|
| 74 | * List instance helper.
|
---|
| 75 | * @param l link
|
---|
| 76 | * @return pointer to a connection structure, NULL on failure.
|
---|
| 77 | */
|
---|
[1433ecda] | 78 | static inline connection_t *connection_from_hound_list(link_t *l)
|
---|
[fa60cd69] | 79 | {
|
---|
[6da3baec] | 80 | return l ? list_get_instance(l, connection_t, hound_link) : NULL;
|
---|
[fa60cd69] | 81 | }
|
---|
| 82 |
|
---|
| 83 | connection_t *connection_create(audio_source_t *source, audio_sink_t *sink);
|
---|
| 84 | void connection_destroy(connection_t *connection);
|
---|
| 85 |
|
---|
[b7fd2a0] | 86 | errno_t connection_add_source_data(connection_t *connection, void *data,
|
---|
[fa60cd69] | 87 | size_t size, pcm_format_t format);
|
---|
| 88 |
|
---|
[b7fd2a0] | 89 | errno_t connection_push_data(connection_t *connection, audio_data_t *adata);
|
---|
[fa60cd69] | 90 |
|
---|
[c799138] | 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 | */
|
---|
[fa60cd69] | 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;
|
---|
[c799138] | 101 | // TODO assert?
|
---|
[fa60cd69] | 102 | return connection->source ? "unnamed source" : "no source";
|
---|
| 103 | }
|
---|
| 104 |
|
---|
[c799138] | 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 | */
|
---|
[fa60cd69] | 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;
|
---|
[c799138] | 115 | // TODO assert?
|
---|
| 116 | return connection->source ? "unnamed sink" : "no sink";
|
---|
[fa60cd69] | 117 | }
|
---|
| 118 |
|
---|
| 119 | #endif
|
---|
| 120 | /**
|
---|
| 121 | * @}
|
---|
| 122 | */
|
---|