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

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

hound: Hook listings and connection routines

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