source: mainline/uspace/srv/audio/hound/connection.c@ 5029c788

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

hound: add connection fifo, implement stream mixing

  • Property mode set to 100644
File size: 3.7 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#include <malloc.h>
37#include <errno.h>
38
39#include "log.h"
40#include "connection.h"
41
42connection_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) {
[5029c788]48 list_initialize(&conn->fifo);
[fa60cd69]49 link_initialize(&conn->source_link);
50 link_initialize(&conn->sink_link);
51 link_initialize(&conn->hound_link);
52 conn->sink = sink;
53 conn->source = source;
54 list_append(&conn->source_link, &source->connections);
55 list_append(&conn->sink_link, &sink->connections);
56 audio_sink_set_format(sink, audio_source_format(source));
[b893cd6]57 if (source->connection_change)
58 source->connection_change(source, true);
59 if (sink->connection_change)
60 sink->connection_change(sink, true);
[6da3baec]61 log_debug("CONNECTED: %s -> %s", source->name, sink->name);
[fa60cd69]62 }
63 return conn;
64}
65
66void connection_destroy(connection_t *connection)
67{
68 assert(connection);
69 assert(!link_in_use(&connection->hound_link));
70 list_remove(&connection->source_link);
71 list_remove(&connection->sink_link);
[6da3baec]72 if (connection->sink && connection->sink->connection_change)
73 connection->sink->connection_change(connection->sink, false);
74 if (connection->source && connection->source->connection_change)
75 connection->source->connection_change(connection->source, false);
[5029c788]76 while (!list_empty(&connection->fifo)) {
77 link_t *l = list_first(&connection->fifo);
78 audio_data_link_t *data = audio_data_link_list_instance(l);
79 list_remove(&data->link);
80 audio_data_link_destroy(data);
81 }
[6da3baec]82 log_debug("DISCONNECTED: %s -> %s",
83 connection->source->name, connection->sink->name);
[fa60cd69]84 free(connection);
85}
86
87ssize_t connection_add_source_data(connection_t *connection, void *data,
88 size_t size, pcm_format_t format)
89{
90 assert(connection);
91 if (!data)
92 return EBADMEM;
93 return audio_source_add_self(connection->source, data, size, &format);
94}
95
[5029c788]96int connection_push_data(connection_t *connection, audio_data_t *adata)
[fa60cd69]97{
98 assert(connection);
[5029c788]99 assert(adata);
100 audio_data_link_t *alink = audio_data_link_create(adata);
101 if (!alink) {
102 log_warning("Failed to buffer %zu bytes of data.", adata->size);
103 return ENOMEM;
104 }
105 log_fatal("Pushed new data to connection fifo");
106 list_append(&alink->link, &connection->fifo);
107 return EOK;
[fa60cd69]108}
109
110
111/**
112 * @}
113 */
Note: See TracBrowser for help on using the repository browser.