Changeset 876f5561 in mainline for uspace/lib/hound/src/client.c
- Timestamp:
- 2013-04-10T23:06:52Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f0a647c
- Parents:
- eb0ef51
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/hound/src/client.c
reb0ef51 r876f5561 45 45 #include "client.h" 46 46 47 /*** 48 * CLIENT SIDE 49 ***/ 50 47 /** Stream structure */ 51 48 typedef struct hound_stream { 49 /** link in context's list */ 52 50 link_t link; 51 /** audio data format fo the stream */ 53 52 pcm_format_t format; 53 /** IPC exchange representing the stream (in STREAM MODE) */ 54 54 async_exch_t *exch; 55 /** parent context */ 55 56 hound_context_t *context; 57 /** Stream flags */ 56 58 int flags; 57 59 } hound_stream_t; 58 60 61 /** 62 * Linked list isntacen helper function. 63 * @param l link 64 * @return hound stream isntance. 65 */ 59 66 static inline hound_stream_t * hound_stream_from_link(link_t *l) 60 67 { … … 62 69 } 63 70 71 /** Hound client context structure */ 64 72 typedef struct hound_context { 73 /** Audio session */ 65 74 hound_sess_t *session; 75 /** context name, reported to the daemon */ 66 76 const char *name; 77 /** True if the instance is record context */ 67 78 bool record; 79 /** List of associated streams */ 68 80 list_t stream_list; 81 /** Main stream helper structure */ 69 82 struct { 70 83 hound_stream_t *stream; … … 72 85 size_t bsize; 73 86 } main; 87 /** Assigned context id */ 74 88 hound_context_id_t id; 75 89 } hound_context_t; 76 90 77 91 /** 92 * Alloc and initialize context structure. 93 * @param name Base for the real context name, will add task id. 94 * @param record True if the new context should capture audio data. 95 * @param format PCM format of the main pipe. 96 * @param bsize Server size buffer size of the main stream. 97 * @return valid pointer to initialized structure on success, NULL on failure 98 */ 78 99 static hound_context_t *hound_context_create(const char *name, bool record, 79 100 pcm_format_t format, size_t bsize) … … 111 132 } 112 133 134 /** 135 * Playback context helper function. 136 * @param name Base for the real context name, will add task id. 137 * @param format PCM format of the main pipe. 138 * @param bsize Server size buffer size of the main stream. 139 * @return valid pointer to initialized structure on success, NULL on failure 140 */ 113 141 hound_context_t * hound_context_create_playback(const char *name, 114 142 pcm_format_t format, size_t bsize) … … 117 145 } 118 146 147 /** 148 * Record context helper function. 149 * @param name Base for the real context name, will add task id. 150 * @param format PCM format of the main pipe. 151 * @param bsize Server size buffer size of the main stream. 152 * @return valid pointer to initialized structure on success, NULL on failure 153 */ 119 154 hound_context_t * hound_context_create_capture(const char *name, 120 155 pcm_format_t format, size_t bsize) … … 123 158 } 124 159 160 /** 161 * Correctly dispose of the hound context structure. 162 * @param hound context to remove. 163 * 164 * The function will destroy all associated streams first. Pointers 165 * to these structures will become invalid and the function will block 166 * if any of these stream needs to be drained first. 167 */ 125 168 void hound_context_destroy(hound_context_t *hound) 126 169 { … … 139 182 } 140 183 184 /** 185 * Get a list of possible connection targets. 186 * @param[in] hound Hound context. 187 * @param[out] names list of target string ids. 188 * @param[out] count Number of elements in @p names list 189 * @return Error code. 190 * 191 * The function will return deice sinks or source based on the context type. 192 */ 141 193 int hound_context_get_available_targets(hound_context_t *hound, 142 194 const char ***names, size_t *count) … … 149 201 } 150 202 203 /** 204 * Get a list of targets connected to the context. 205 * @param[in] hound Hound context. 206 * @param[out] names list of target string ids. 207 * @param[out] count Number of elements in @p names list 208 * @return Error code. 209 */ 151 210 int hound_context_get_connected_targets(hound_context_t *hound, 152 211 const char ***names, size_t *count) … … 160 219 } 161 220 221 /** 222 * Create a new connection to the target. 223 * @param hound Hound context. 224 * @param target String identifier of the desired target. 225 * @return Error code. 226 * 227 * The function recognizes special 'HOUND_DEFAULT_TARGET' and will 228 * connect to the first possible target if it is passed this value. 229 */ 162 230 int hound_context_connect_target(hound_context_t *hound, const char* target) 163 231 { … … 189 257 } 190 258 259 /** 260 * Destroy a connection to the target. 261 * @param hound Hound context. 262 * @param target String identifier of the desired target. 263 * @return Error code. 264 */ 191 265 int hound_context_disconnect_target(hound_context_t *hound, const char* target) 192 266 { … … 203 277 } 204 278 279 /** 280 * Create a new stream associated with the context. 281 * @param hound Hound context. 282 * @param flags new stream flags. 283 * @param format new stream PCM format. 284 * @param bzise new stream server side buffer size (in bytes) 285 * @return Valid pointer to a stream instance, NULL on failure. 286 */ 205 287 hound_stream_t *hound_stream_create(hound_context_t *hound, unsigned flags, 206 288 pcm_format_t format, size_t bsize) … … 229 311 } 230 312 313 /** 314 * Destroy existing stream 315 * @param stream The stream to destroy. 316 * 317 * Function will wait until the server side buffer is empty if the 318 * HOUND_STREAM_DRAIN_ON_EXIT flag was set on creation. 319 */ 231 320 void hound_stream_destroy(hound_stream_t *stream) 232 321 { … … 241 330 } 242 331 332 /** 333 * Send new data to a stream. 334 * @param stream The target stream 335 * @param data data buffer 336 * @param size size of the @p data buffer. 337 * @return error code. 338 */ 243 339 int hound_stream_write(hound_stream_t *stream, const void *data, size_t size) 244 340 { … … 249 345 } 250 346 347 /** 348 * Get data from a stream. 349 * @param stream The target stream. 350 * @param data data buffer. 351 * @param size size of the @p data buffer. 352 * @return error code. 353 */ 251 354 int hound_stream_read(hound_stream_t *stream, void *data, size_t size) 252 355 { … … 257 360 } 258 361 362 /** 363 * Main stream getter function. 364 * @param hound Houndcontext. 365 * @return Valid stream pointer, NULL on failure. 366 * 367 * The function will create new stream, or return a pointer to the exiting one 368 * if it exists. 369 */ 259 370 static hound_stream_t * hound_get_main_stream(hound_context_t *hound) 260 371 { … … 267 378 } 268 379 380 /** 381 * Send new data to the main stream. 382 * @param stream The target stream 383 * @param data data buffer 384 * @param size size of the @p data buffer. 385 * @return error code. 386 */ 269 387 int hound_write_main_stream(hound_context_t *hound, 270 388 const void *data, size_t size) 271 389 { 272 390 assert(hound); 391 if (hound->record) 392 return EINVAL; 393 273 394 hound_stream_t *mstream = hound_get_main_stream(hound); 274 395 if (!mstream) … … 277 398 } 278 399 400 /** 401 * Get data from the main stream. 402 * @param stream The target stream 403 * @param data data buffer 404 * @param size size of the @p data buffer. 405 * @return error code. 406 */ 279 407 int hound_read_main_stream(hound_context_t *hound, void *data, size_t size) 280 408 { 281 409 assert(hound); 410 if (!hound->record) 411 return EINVAL; 282 412 hound_stream_t *mstream = hound_get_main_stream(hound); 283 413 if (!mstream) … … 286 416 } 287 417 418 /** 419 * Destroy the old main stream and replace it with a new one with fresh data. 420 * @param hound Hound context. 421 * @param data data buffer. 422 * @param size size of the @p data buffer. 423 * @return error code. 424 * 425 * NOT IMPLEMENTED 426 */ 288 427 int hound_write_replace_main_stream(hound_context_t *hound, 289 428 const void *data, size_t size) … … 296 435 } 297 436 298 int hound_context_set_main_stream_format(hound_context_t *hound, 299 unsigned channels, unsigned rate, pcm_sample_format_t format) 437 /** 438 * Destroy the old main stream and replace it with a new one using new params. 439 * @param hound Hound context. 440 * @param channels 441 * @return error code. 442 * 443 * NOT IMPLEMENTED 444 */ 445 int hound_context_set_main_stream_params(hound_context_t *hound, 446 pcm_format_t format, size_t bsize) 300 447 { 301 448 assert(hound); … … 304 451 } 305 452 453 /** 454 * Write data immediately to a new stream, and wait for it to drain. 455 * @param hound Hound context. 456 * @param format pcm data format. 457 * @param data data buffer 458 * @param size @p data buffer size 459 * @return Error code. 460 * 461 * This functnion creates a new stream writes the data, ti waits for the stream 462 * to drain and destroys it before returning. 463 */ 306 464 int hound_write_immediate(hound_context_t *hound, pcm_format_t format, 307 465 const void *data, size_t size) 308 466 { 309 467 assert(hound); 468 if (hound->record) 469 return EINVAL; 310 470 hound_stream_t *tmpstream = hound_stream_create(hound, 0, format, size); 311 471 if (!tmpstream) … … 319 479 return ret; 320 480 } 321 322 323 481 /** 324 482 * @}
Note:
See TracChangeset
for help on using the changeset viewer.