source: mainline/uspace/lib/hound/src/client.c@ 059490c2

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

libhound: Add protocol header

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[36774cf]1/*
2 * Copyright (c) 2012 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 libhound
30 * @addtogroup audio
31 * @{
32 */
33/** @file
34 * Common USB functions.
35 */
36#include <adt/list.h>
37#include <errno.h>
38#include <loc.h>
39#include <str.h>
40#include <stdlib.h>
41#include <stdio.h>
42#include <libarch/types.h>
43
44#include "client.h"
[059490c2]45#include "protocol.h"
[36774cf]46
47/***
48 * CLIENT SIDE
49 ***/
50
51typedef struct hound_stream {
52 link_t link;
53 async_exch_t *exch;
54} hound_stream_t;
55
56typedef struct hound_context {
[059490c2]57 hound_sess_t *session;
[36774cf]58 const char *name;
59 bool record;
60 list_t stream_list;
61 hound_stream_t *main_stream;
62 struct {
63 pcm_sample_format_t sample;
64 unsigned channels;
65 unsigned rate;
66 size_t bsize;
67 } main_format;
68 unsigned id;
69} hound_context_t;
70
71
72static hound_context_t *hound_context_create(const char *name, bool record,
73 unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
74{
75 hound_context_t *new_context = malloc(sizeof(hound_context_t));
76 if (new_context) {
77 char *cont_name;
78 int ret = asprintf(&cont_name, "%llu:%s", task_get_id(), name);
79 if (ret < 0) {
80 free(new_context);
81 return NULL;
82 }
83 list_initialize(&new_context->stream_list);
84 new_context->name = cont_name;
85 new_context->record = record;
[059490c2]86 new_context->session = hound_service_connect(HOUND_SERVICE);
[36774cf]87 new_context->main_stream = NULL;
88 new_context->main_format.sample = format;
89 new_context->main_format.rate = rate;
90 new_context->main_format.channels = channels;
91 new_context->main_format.bsize = bsize;
92 if (!new_context->session) {
93 free(new_context->name);
94 free(new_context);
95 return NULL;
96 }
97 async_exch_t *exch = async_exchange_begin(new_context->session);
98 //TODO: register context
99 async_exchange_end(exch);
100 }
101 return new_context;
102}
103
104hound_context_t * hound_context_create_playback(const char *name,
105 unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
106{
107 return hound_context_create(name, false, channels, rate, format, bsize);
108}
109
110hound_context_t * hound_context_create_capture(const char *name,
111 unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)
112{
113 return hound_context_create(name, true, channels, rate, format, bsize);
114}
115
116void hound_context_destroy(hound_context_t *hound)
117{
118 assert(hound);
119}
120
121int hound_context_enable(hound_context_t *hound)
122{
123 assert(hound);
124 return ENOTSUP;
125}
126int hound_context_disable(hound_context_t *hound)
127{
128 assert(hound);
129 return ENOTSUP;
130}
131
132int hound_get_output_targets(const char **names, size_t *count)
133{
134 assert(names);
135 assert(count);
136 return ENOTSUP;
137}
138
139int hound_get_input_targets(const char **names, size_t *count)
140{
141 assert(names);
142 assert(count);
143 return ENOTSUP;
144}
145
146int hound_context_connect_target(hound_context_t *hound, const char* target)
147{
148 assert(hound);
149 return ENOTSUP;
150}
151
152int hound_context_disconnect_target(hound_context_t *hound, const char* target)
153{
154 assert(hound);
155 return ENOTSUP;
156}
157
158int hound_context_set_main_stream_format(hound_context_t *hound,
159 unsigned channels, unsigned rate, pcm_sample_format_t format);
160int hound_write_main_stream(hound_context_t *hound,
161 const void *data, size_t size);
162int hound_read_main_stream(hound_context_t *hound, void *data, size_t size);
163int hound_write_replace_main_stream(hound_context_t *hound,
164 const void *data, size_t size);
165int hound_write_immediate_stream(hound_context_t *hound,
166 const void *data, size_t size);
167
168/**
169 * @}
170 */
Note: See TracBrowser for help on using the repository browser.