source: mainline/uspace/srv/audio/hound/iface.c@ e5bc912

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

Fix printf compile issues

  • Property mode set to 100644
File size: 4.9 KB
Line 
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/**
30 * @addtogroup audio
31 * @brief HelenOS sound server.
32 * @{
33 */
34/** @file
35 */
36
37#include <errno.h>
38#include <hound/protocol.h>
39#include <inttypes.h>
40#include <malloc.h>
41
42#include "hound.h"
43#include "hound_ctx.h"
44#include "log.h"
45
46static int iface_add_context(void *server, hound_context_id_t *id,
47 const char *name, bool record)
48{
49 assert(server);
50 assert(id);
51 assert(name);
52
53 hound_ctx_t *ctx = record ? hound_record_ctx_get(name) :
54 hound_playback_ctx_get(name);
55 if (!ctx)
56 return ENOMEM;
57
58 const int ret = hound_add_ctx(server, ctx);
59 if (ret != EOK)
60 hound_ctx_destroy(ctx);
61 else
62 *id = hound_ctx_get_id(ctx);
63 return ret;
64}
65
66static int iface_rem_context(void *server, hound_context_id_t id)
67{
68 assert(server);
69 hound_ctx_t *ctx = hound_get_ctx_by_id(server, id);
70 if (!ctx)
71 return EINVAL;
72 int ret = hound_remove_ctx(server, ctx);
73 if (ret != EOK)
74 return ret;
75 hound_ctx_destroy(ctx);
76 log_info("%s: %p, %#" PRIxn, __FUNCTION__, server, id);
77 return EOK;
78}
79
80static bool iface_is_record_context(void *server, hound_context_id_t id)
81{
82 assert(server);
83 hound_ctx_t *ctx = hound_get_ctx_by_id(server, id);
84 if (!ctx)
85 return false;
86 return hound_ctx_is_record(ctx);
87}
88
89static int iface_get_list(void *server, const char ***list, size_t *size,
90 const char *connection, int flags)
91{
92 log_info("%s: %p, %zu, %s, %#x\n", __FUNCTION__, server, *size,
93 connection, flags);
94 if ((flags & (HOUND_SINK_DEVS | HOUND_SINK_APPS)) != 0)
95 return hound_list_sinks(server, list, size);
96 if ((flags & (HOUND_SOURCE_DEVS | HOUND_SOURCE_APPS)) != 0)
97 return hound_list_sources(server, list, size);
98 return ENOTSUP;
99}
100
101static int iface_connect(void *server, const char *source, const char *sink)
102{
103 log_info("%s: %p, %s -> %s", __FUNCTION__, server, source, sink);
104 return hound_connect(server, source, sink);
105}
106
107static int iface_disconnect(void *server, const char *source, const char *sink)
108{
109 log_info("%s: %p, %s -> %s", __FUNCTION__, server, source, sink);
110 return hound_disconnect(server, source, sink);
111}
112
113static int iface_add_stream(void *server, hound_context_id_t id, int flags,
114 pcm_format_t format, size_t size, void **data)
115{
116 assert(data);
117 assert(server);
118
119 log_verbose("%s: %p, %" PRIxn " %x ch:%u r:%u f:%s", __FUNCTION__,
120 server, id, flags, format.channels, format.sampling_rate,
121 pcm_sample_format_str(format.sample_format));
122 hound_ctx_t *ctx = hound_get_ctx_by_id(server, id);
123 if (!ctx)
124 return ENOENT;
125 hound_ctx_stream_t *stream =
126 hound_ctx_create_stream(ctx, flags, format, size);
127 if (!stream)
128 return ENOMEM;
129 *data = stream;
130 return EOK;
131}
132
133static int iface_rem_stream(void *server, void *stream)
134{
135 hound_ctx_destroy_stream(stream);
136 return EOK;
137}
138
139static int iface_drain_stream(void *stream)
140{
141 hound_ctx_stream_drain(stream);
142 return EOK;
143}
144
145static int iface_stream_data_read(void *stream, void *buffer, size_t size)
146{
147 return hound_ctx_stream_read(stream, buffer, size);
148}
149
150static int iface_stream_data_write(void *stream, const void *buffer, size_t size)
151{
152 return hound_ctx_stream_write(stream, buffer, size);
153}
154
155hound_server_iface_t hound_iface = {
156 .add_context = iface_add_context,
157 .rem_context = iface_rem_context,
158 .is_record_context = iface_is_record_context,
159 .get_list = iface_get_list,
160 .connect = iface_connect,
161 .disconnect = iface_disconnect,
162 .add_stream = iface_add_stream,
163 .rem_stream = iface_rem_stream,
164 .drain_stream = iface_drain_stream,
165 .stream_data_write = iface_stream_data_write,
166 .stream_data_read = iface_stream_data_read,
167 .server = NULL,
168};
Note: See TracBrowser for help on using the repository browser.