Changeset c799138 in mainline for uspace/srv/audio/hound/hound_ctx.c
- Timestamp:
- 2013-04-11T01:34:41Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 250828a
- Parents:
- f0a647c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/hound_ctx.c
rf0a647c rc799138 45 45 static int update_data(audio_source_t *source, size_t size); 46 46 47 /** 48 * Allocate and initialize hound context structure. 49 * @param name String identifier. 50 * @return Pointer to a new context structure, NULL on failure 51 * 52 * Creates record context structure. 53 */ 47 54 hound_ctx_t *hound_record_ctx_get(const char *name) 48 55 { 49 return NULL; 50 } 51 56 hound_ctx_t *ctx = malloc(sizeof(hound_ctx_t)); 57 if (ctx) { 58 link_initialize(&ctx->link); 59 list_initialize(&ctx->streams); 60 fibril_mutex_initialize(&ctx->guard); 61 ctx->source = NULL; 62 ctx->sink = malloc(sizeof(audio_sink_t)); 63 if (!ctx->sink) { 64 free(ctx); 65 return NULL; 66 } 67 // TODO provide sink functions 68 const int ret = audio_sink_init(ctx->sink, name, ctx, NULL, 69 NULL, &AUDIO_FORMAT_DEFAULT); 70 if (ret != EOK) { 71 free(ctx->sink); 72 free(ctx); 73 return NULL; 74 } 75 } 76 return ctx; 77 } 78 79 /** 80 * Allocate and initialize hound context structure. 81 * @param name String identifier. 82 * @return Pointer to a new context structure, NULL on failure 83 * 84 * Creates record context structure. 85 */ 52 86 hound_ctx_t *hound_playback_ctx_get(const char *name) 53 87 { … … 74 108 } 75 109 110 /** 111 * Destroy existing context structure. 112 * @param ctx hound cotnext to destroy. 113 */ 76 114 void hound_ctx_destroy(hound_ctx_t *ctx) 77 115 { … … 88 126 } 89 127 128 /** 129 * Retrieve associated context id. 130 * @param ctx hound context. 131 * @return context id of the context. 132 */ 90 133 hound_context_id_t hound_ctx_get_id(hound_ctx_t *ctx) 91 134 { … … 94 137 } 95 138 139 /** 140 * Query playback/record status of a hound context. 141 * @param ctx Hound context. 142 * @return True if ctx is a recording context. 143 */ 96 144 bool hound_ctx_is_record(hound_ctx_t *ctx) 97 145 { … … 104 152 * STREAMS 105 153 */ 154 155 /** Hound stream structure. */ 106 156 typedef struct hound_ctx_stream { 157 /** Hound context streams link */ 107 158 link_t link; 159 /** Audio data pipe */ 108 160 audio_pipe_t fifo; 161 /** Parent context */ 109 162 hound_ctx_t *ctx; 163 /** Stream data format */ 110 164 pcm_format_t format; 165 /** Stream modifiers */ 111 166 int flags; 167 /** Maximum allowed buffer size */ 112 168 size_t allowed_size; 169 /** Fifo access synchronization */ 113 170 fibril_mutex_t guard; 171 /** buffer status change condition */ 114 172 fibril_condvar_t change; 115 173 } hound_ctx_stream_t; 116 174 175 /** 176 * List instance helper. 177 * @param l link 178 * @return pointer to a hound context structure, NULL on failure. 179 */ 117 180 static inline hound_ctx_stream_t *hound_ctx_stream_from_link(link_t *l) 118 181 { … … 120 183 } 121 184 185 /** 186 * New stream append helper. 187 * @param ctx hound context. 188 * @param stream A new stream. 189 */ 122 190 static inline void stream_append(hound_ctx_t *ctx, hound_ctx_stream_t *stream) 123 191 { … … 129 197 } 130 198 199 /** 200 * Old stream remove helper. 201 * @param ctx hound context. 202 * @param stream An old stream. 203 */ 131 204 static inline void stream_remove(hound_ctx_t *ctx, hound_ctx_stream_t *stream) 132 205 { … … 138 211 } 139 212 213 /** 214 * Create new stream. 215 * @param ctx Assocaited hound context. 216 * @param flags Stream modidfiers. 217 * @param format PCM data format. 218 * @param buffer_size Maximum allowed buffer size. 219 * @return Pointer to a new stream structure, NULL on failure. 220 */ 140 221 hound_ctx_stream_t *hound_ctx_create_stream(hound_ctx_t *ctx, int flags, 141 222 pcm_format_t format, size_t buffer_size) … … 160 241 } 161 242 243 /** 244 * Destroy existing stream structure. 245 * @param stream The stream to destroy. 246 * 247 * The function will print warning if there are data in the buffer. 248 */ 162 249 void hound_ctx_destroy_stream(hound_ctx_stream_t *stream) 163 250 { … … 177 264 } 178 265 179 266 /** 267 * Write new data to a stream. 268 * @param stream The destination stream. 269 * @param data audio data buffer. 270 * @param size size of the @p data buffer. 271 * @return Error code. 272 */ 180 273 int hound_ctx_stream_write(hound_ctx_stream_t *stream, const void *data, 181 274 size_t size) … … 199 292 } 200 293 294 /** 295 * Read data from a buffer. 296 * @param stream The source buffer. 297 * @param data Destination data buffer. 298 * @param size Size of the @p data buffer. 299 * @return Error code. 300 */ 201 301 int hound_ctx_stream_read(hound_ctx_stream_t *stream, void *data, size_t size) 202 302 { … … 205 305 } 206 306 307 /** 308 * Add (mix) stream data to the destination buffer. 309 * @param stream The source stream. 310 * @param data Destination audio buffer. 311 * @param size Size of the @p data buffer. 312 * @param format Destination data format. 313 * @return Size of the destination buffer touch with stream's data, 314 * error code on failure. 315 */ 207 316 ssize_t hound_ctx_stream_add_self(hound_ctx_stream_t *stream, void *data, 208 317 size_t size, const pcm_format_t *f) … … 216 325 } 217 326 327 /** 328 * Block until the stream's buffer is empty. 329 * @param stream Target stream. 330 */ 218 331 void hound_ctx_stream_drain(hound_ctx_stream_t *stream) 219 332 { … … 226 339 } 227 340 341 /** 342 * Update context data. 343 * @param source Source abstraction. 344 * @param size Required size in source's format. 345 * @return error code. 346 * 347 * Mixes data from all streams and pushes it to all connections. 348 */ 228 349 int update_data(audio_source_t *source, size_t size) 229 350 {
Note:
See TracChangeset
for help on using the changeset viewer.