source: mainline/uspace/srv/audio/hound/connection.h@ 7f84430

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 7f84430 was bee5349, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

hound: add data available callback

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[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]48typedef 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 */
[fa60cd69]68static inline connection_t * connection_from_source_list(link_t *l)
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 */
[fa60cd69]78static inline connection_t * connection_from_sink_list(link_t *l)
79{
[6da3baec]80 return l ? list_get_instance(l, connection_t, sink_link) : NULL;
[fa60cd69]81}
82
[c799138]83/**
84 * List instance helper.
85 * @param l link
86 * @return pointer to a connection structure, NULL on failure.
87 */
[fa60cd69]88static inline connection_t * connection_from_hound_list(link_t *l)
89{
[6da3baec]90 return l ? list_get_instance(l, connection_t, hound_link) : NULL;
[fa60cd69]91}
92
93connection_t *connection_create(audio_source_t *source, audio_sink_t *sink);
94void connection_destroy(connection_t *connection);
95
96ssize_t connection_add_source_data(connection_t *connection, void *data,
97 size_t size, pcm_format_t format);
98
[bee5349]99int connection_push_data(connection_t *connection, audio_data_t *adata);
[fa60cd69]100
[c799138]101/**
102 * Source name getter.
103 * @param connection Connection to the source.
104 * @param valid string identifier, "no source" or "unnamed source" on failure.
105 */
[fa60cd69]106static inline const char *connection_source_name(connection_t *connection)
107{
108 assert(connection);
109 if (connection->source && connection->source->name)
110 return connection->source->name;
[c799138]111 // TODO assert?
[fa60cd69]112 return connection->source ? "unnamed source" : "no source";
113}
114
[c799138]115/**
116 * Sink name getter.
117 * @param connection Connection to the sink.
118 * @param valid string identifier, "no source" or "unnamed source" on failure.
119 */
[fa60cd69]120static inline const char *connection_sink_name(connection_t *connection)
121{
122 assert(connection);
123 if (connection->sink && connection->sink->name)
124 return connection->sink->name;
[c799138]125 // TODO assert?
126 return connection->source ? "unnamed sink" : "no sink";
[fa60cd69]127}
128
129
130#endif
131/**
132 * @}
133 */
Note: See TracBrowser for help on using the repository browser.