Changeset 9e1800c in mainline for uspace/lib/hound/src/client.c
- Timestamp:
- 2013-03-17T16:23:57Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bd5860f
- Parents:
- 504f1ea3
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/hound/src/client.c
r504f1ea3 r9e1800c 42 42 #include <libarch/types.h> 43 43 44 #include "protocol.h" 44 45 #include "client.h" 45 #include "protocol.h"46 46 47 47 /*** … … 51 51 typedef struct hound_stream { 52 52 link_t link; 53 pcm_format_t format; 53 54 async_exch_t *exch; 55 hound_context_t *context; 54 56 } hound_stream_t; 55 57 … … 59 61 bool record; 60 62 list_t stream_list; 61 hound_stream_t *main_stream;62 63 struct { 63 pcm_sample_format_t sample; 64 unsigned channels; 65 unsigned rate; 64 hound_stream_t *stream; 65 pcm_format_t format; 66 66 size_t bsize; 67 } main _format;68 unsignedid;67 } main; 68 hound_context_id_t id; 69 69 } hound_context_t; 70 70 71 71 72 72 static hound_context_t *hound_context_create(const char *name, bool record, 73 unsigned channels, unsigned rate, pcm_sample_format_t format, size_t bsize)73 pcm_format_t format, size_t bsize) 74 74 { 75 75 hound_context_t *new_context = malloc(sizeof(hound_context_t)); … … 85 85 new_context->record = record; 86 86 new_context->session = hound_service_connect(HOUND_SERVICE); 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; 87 new_context->main.stream = NULL; 88 new_context->main.format = format; 89 new_context->main.bsize = bsize; 92 90 if (!new_context->session) { 93 91 free(new_context->name); … … 95 93 return NULL; 96 94 } 97 async_exch_t *exch = async_exchange_begin(new_context->session); 98 //TODO: register context 99 async_exchange_end(exch); 95 new_context->id = hound_service_register_context( 96 new_context->session, new_context->name); 97 if (new_context->id <= 0) { 98 free(new_context->name); 99 free(new_context); 100 return NULL; 101 } 100 102 } 101 103 return new_context; … … 103 105 104 106 hound_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);107 pcm_format_t format, size_t bsize) 108 { 109 return hound_context_create(name, false, format, bsize); 108 110 } 109 111 110 112 hound_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);113 pcm_format_t format, size_t bsize) 114 { 115 return hound_context_create(name, true, format, bsize); 114 116 } 115 117 … … 117 119 { 118 120 assert(hound); 121 hound_service_unregister_context(hound->session, hound->id); 122 hound_service_disconnect(hound->session); 123 free(hound->name); 124 free(hound); 119 125 } 120 126 … … 156 162 } 157 163 164 hound_stream_t *hound_stream_create(hound_context_t *hound, unsigned flags, 165 pcm_format_t format, size_t bsize) 166 { 167 assert(hound); 168 async_exch_t *stream_exch = async_exchange_begin(hound->session); 169 if (!stream_exch) 170 return NULL; 171 hound_stream_t *new_stream = malloc(sizeof(hound_stream_t)); 172 if (new_stream) { 173 link_initialize(&new_stream->link); 174 new_stream->exch = stream_exch; 175 new_stream->format = format; 176 new_stream->context = hound; 177 int ret = hound_service_stream_enter(new_stream->exch, 178 hound->id, flags, format, bsize); 179 if (ret != EOK) { 180 async_exchange_end(new_stream->exch); 181 free(new_stream); 182 return NULL; 183 } 184 list_append(&new_stream->link, &hound->stream_list); 185 } 186 return new_stream; 187 } 188 189 void hound_stream_destroy(hound_stream_t *stream) 190 { 191 if (stream) { 192 // TODO drain? 193 hound_service_stream_exit(stream->exch); 194 async_exchange_end(stream->exch); 195 list_remove(&stream->link); 196 free(stream); 197 } 198 } 199 200 int hound_stream_write(hound_stream_t *stream, const void *data, size_t size) 201 { 202 assert(stream); 203 if (!data || size == 0) 204 return EBADMEM; 205 return hound_service_stream_write(stream->exch, data, size); 206 } 207 208 int hound_stream_read(hound_stream_t *stream, void *data, size_t size) 209 { 210 assert(stream); 211 if (!data || size == 0) 212 return EBADMEM; 213 return hound_service_stream_read(stream->exch, data, size); 214 } 215 216 static hound_stream_t * hound_get_main_stream(hound_context_t *hound) 217 { 218 assert(hound); 219 if (!hound->main.stream) 220 hound->main.stream = hound_stream_create(hound, 0, 221 hound->main.format, hound->main.bsize); 222 return hound->main.stream; 223 } 224 225 int hound_write_main_stream(hound_context_t *hound, 226 const void *data, size_t size) 227 { 228 assert(hound); 229 hound_stream_t *mstream = hound_get_main_stream(hound); 230 if (!mstream) 231 return ENOMEM; 232 return hound_stream_write(mstream, data, size); 233 } 234 235 int hound_read_main_stream(hound_context_t *hound, void *data, size_t size) 236 { 237 assert(hound); 238 hound_stream_t *mstream = hound_get_main_stream(hound); 239 if (!mstream) 240 return ENOMEM; 241 return hound_stream_read(mstream, data, size); 242 } 243 244 int hound_write_replace_main_stream(hound_context_t *hound, 245 const void *data, size_t size) 246 { 247 assert(hound); 248 if (!data || size == 0) 249 return EBADMEM; 250 // TODO implement 251 return ENOTSUP; 252 } 253 158 254 int hound_context_set_main_stream_format(hound_context_t *hound, 159 unsigned channels, unsigned rate, pcm_sample_format_t format); 160 int hound_write_main_stream(hound_context_t *hound, 161 const void *data, size_t size); 162 int hound_read_main_stream(hound_context_t *hound, void *data, size_t size); 163 int hound_write_replace_main_stream(hound_context_t *hound, 164 const void *data, size_t size); 165 int hound_write_immediate_stream(hound_context_t *hound, 166 const void *data, size_t size); 255 unsigned channels, unsigned rate, pcm_sample_format_t format) 256 { 257 assert(hound); 258 // TODO implement 259 return ENOTSUP; 260 } 261 262 int hound_write_immediate(hound_context_t *hound, pcm_format_t format, 263 const void *data, size_t size) 264 { 265 assert(hound); 266 hound_stream_t *tmpstream = hound_stream_create(hound, 0, format, size); 267 if (!tmpstream) 268 return ENOMEM; 269 const int ret = hound_stream_write(tmpstream, data, size); 270 if (ret == EOK) { 271 //TODO drain? 272 hound_service_stream_drain(tmpstream->exch); 273 } 274 hound_stream_destroy(tmpstream); 275 return ret; 276 } 277 167 278 168 279 /**
Note:
See TracChangeset
for help on using the changeset viewer.