Changeset fa60cd69 in mainline
- Timestamp:
- 2013-04-02T19:06:27Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 35ab943
- Parents:
- 39c4d1f
- Location:
- uspace/srv/audio/hound
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/Makefile
r39c4d1f rfa60cd69 46 46 audio_sink.c \ 47 47 audio_source.c \ 48 connection.c \ 48 49 hound.c \ 49 50 hound_ctx.c \ -
uspace/srv/audio/hound/audio_client.c
r39c4d1f rfa60cd69 55 55 56 56 static int client_sink_connection_change(audio_sink_t *sink, bool new); 57 static int client_source_connection_change(audio_source_t *source );57 static int client_source_connection_change(audio_source_t *source, bool new); 58 58 static int client_source_update_data(audio_source_t *source, size_t size); 59 59 … … 111 111 } 112 112 113 static int client_source_connection_change(audio_source_t *source )113 static int client_source_connection_change(audio_source_t *source, bool new) 114 114 { 115 115 assert(source); 116 116 audio_client_t *client = source->private_data; 117 if (source->connected_sink) { 117 if (new && list_count(&source->connections) == 1) { 118 assert(!client->exch); 118 119 client->exch = async_exchange_begin(client->sess); 119 120 return client->exch ? EOK : ENOMEM; 120 121 } 121 async_exchange_end(client->exch); 122 client->exch = NULL; 122 if (list_count(&source->connections) == 0) { 123 assert(!new); 124 async_exchange_end(client->exch); 125 client->exch = NULL; 126 } 123 127 return EOK; 124 128 } -
uspace/srv/audio/hound/audio_device.c
r39c4d1f rfa60cd69 49 49 50 50 static int device_sink_connection_callback(audio_sink_t *sink, bool new); 51 static int device_source_connection_callback(audio_source_t *source );51 static int device_source_connection_callback(audio_source_t *source, bool new); 52 52 static void device_event_callback(ipc_callid_t iid, ipc_call_t *icall, void *arg); 53 53 static int device_check_format(audio_sink_t* sink); … … 94 94 assert(sink); 95 95 audio_device_t *dev = sink->private_data; 96 if (new && list_count(&sink-> sources) == 1) {96 if (new && list_count(&sink->connections) == 1) { 97 97 log_verbose("First connection on device sink '%s'", sink->name); 98 98 … … 104 104 } 105 105 audio_pcm_register_event_callback(dev->sess, 106 device_event_callback, dev); 106 device_event_callback, dev);\ 107 // TODO set formats 107 108 108 109 /* Fill the buffer first */ … … 110 111 dev->buffer.base, dev->buffer.size); 111 112 113 log_verbose("Mixed inputs: %zu/(%u * %u)", 114 dev->buffer.size, BUFFER_PARTS, pcm_format_frame_size(&dev->sink.format)); 112 115 const unsigned frames = dev->buffer.size / 113 116 (BUFFER_PARTS * pcm_format_frame_size(&dev->sink.format)); 117 log_verbose("FRAME COUNT %u", frames); 114 118 ret = audio_pcm_start_playback_fragment(dev->sess, frames, 115 119 dev->sink.format.channels, dev->sink.format.sampling_rate, … … 122 126 } 123 127 } 124 if (list_count(&sink-> sources) == 0) {128 if (list_count(&sink->connections) == 0) { 125 129 assert(!new); 126 130 log_verbose("No connections on device sink '%s'", sink->name); … … 142 146 } 143 147 144 static int device_source_connection_callback(audio_source_t *source )148 static int device_source_connection_callback(audio_source_t *source, bool new) 145 149 { 146 150 assert(source); 147 151 audio_device_t *dev = source->private_data; 148 if ( source->connected_sink) {152 if (new && list_count(&source->connections)) { 149 153 int ret = get_buffer(dev); 150 154 if (ret != EOK) { … … 164 168 return ret; 165 169 } 166 } else { /* Disconnected */ 170 } 171 if (list_count(&source->connections) == 0) { /* Disconnected */ 172 assert(!new); 167 173 int ret = audio_pcm_stop_capture(dev->sess); 168 174 if (ret != EOK) { -
uspace/srv/audio/hound/audio_sink.c
r39c4d1f rfa60cd69 41 41 42 42 #include "audio_sink.h" 43 #include "connection.h" 43 44 #include "log.h" 44 45 … … 54 55 } 55 56 link_initialize(&sink->link); 56 list_initialize(&sink-> sources);57 list_initialize(&sink->connections); 57 58 sink->name = str_dup(name); 58 59 sink->private_data = private_data; … … 67 68 { 68 69 assert(sink); 70 assert(list_empty(&sink->connections)); 69 71 assert(!sink->private_data); 70 72 free(sink->name); … … 72 74 } 73 75 76 #if 0 74 77 int audio_sink_add_source(audio_sink_t *sink, audio_source_t *source) 75 78 { … … 92 95 93 96 audio_source_connected(source, sink); 94 95 97 if (sink->connection_change) { 96 98 log_verbose("Calling connection change"); … … 98 100 if (ret != EOK) { 99 101 log_debug("Connection hook failed."); 100 audio_source_connected(source, NULL);101 list_remove(&source->link);102 sink->format = old_format;102 // audio_source_connected(source, NULL); 103 // list_remove(&source->link); 104 // sink->format = old_format; 103 105 return ret; 104 106 } … … 109 111 return EOK; 110 112 } 113 #endif 111 114 112 115 int audio_sink_set_format(audio_sink_t *sink, const pcm_format_t *format) … … 118 121 return EEXISTS; 119 122 } 120 const pcm_format_t old_format ;123 const pcm_format_t old_format = sink->format; 121 124 122 125 if (pcm_format_is_any(format)) { … … 140 143 } 141 144 145 #if 0 142 146 int audio_sink_remove_source(audio_sink_t *sink, audio_source_t *source) 143 147 { … … 157 161 return EOK; 158 162 } 163 #endif 159 164 160 165 … … 165 170 166 171 pcm_format_silence(dest, size, &sink->format); 167 list_foreach(sink-> sources, it) {168 audio_source_t *source = audio_source_list_instance(it);169 const int ret = 170 audio_source_add_self(source, dest, size, &sink->format);172 list_foreach(sink->connections, it) { 173 connection_t * conn = connection_from_sink_list(it); 174 const int ret = connection_add_source_data( 175 conn, dest, size, sink->format); 171 176 if (ret != EOK) { 172 log_warning("Failed to mixsource %s: %s",173 source->name, str_error(ret));177 log_warning("Failed to add source %s: %s", 178 connection_source_name(conn), str_error(ret)); 174 179 } 175 180 } -
uspace/srv/audio/hound/audio_sink.h
r39c4d1f rfa60cd69 49 49 struct audio_sink { 50 50 link_t link; 51 list_t sources;51 list_t connections; 52 52 const char *name; 53 53 pcm_format_t format; … … 68 68 69 69 int audio_sink_set_format(audio_sink_t *sink, const pcm_format_t *format); 70 int audio_sink_add_source(audio_sink_t *sink, audio_source_t *source);71 int audio_sink_remove_source(audio_sink_t *sink, audio_source_t *source);70 //int audio_sink_add_source(audio_sink_t *sink, audio_source_t *source); 71 //int audio_sink_remove_source(audio_sink_t *sink, audio_source_t *source); 72 72 void audio_sink_mix_inputs(audio_sink_t *sink, void* dest, size_t size); 73 73 -
uspace/srv/audio/hound/audio_source.c
r39c4d1f rfa60cd69 47 47 48 48 int audio_source_init(audio_source_t *source, const char *name, void *data, 49 int (*connection_change)(audio_source_t * ),49 int (*connection_change)(audio_source_t *, bool new), 50 50 int (*update_available_data)(audio_source_t *, size_t), 51 51 const pcm_format_t *f) … … 57 57 } 58 58 link_initialize(&source->link); 59 list_initialize(&source->connections); 59 60 source->name = str_dup(name); 60 61 source->private_data = data; 61 62 source->connection_change = connection_change; 62 63 source->update_available_data = update_available_data; 63 source->connected_sink = NULL;64 64 source->format = *f; 65 65 source->available_data.base = NULL; … … 73 73 { 74 74 assert(source); 75 assert(source->connected_sink == NULL);76 75 free(source->name); 77 76 source->name = NULL; 78 }79 80 int audio_source_connected(audio_source_t *source, struct audio_sink *sink)81 {82 assert(source);83 audio_sink_t *old_sink = source->connected_sink;84 const pcm_format_t old_format = source->format;85 86 source->connected_sink = sink;87 if (pcm_format_is_any(&source->format)) {88 assert(sink);89 assert(!pcm_format_is_any(&sink->format));90 source->format = sink->format;91 }92 if (source->connection_change) {93 const int ret = source->connection_change(source);94 if (ret != EOK) {95 source->format = old_format;96 source->connected_sink = old_sink;97 return ret;98 }99 }100 return EOK;101 77 } 102 78 -
uspace/srv/audio/hound/audio_source.h
r39c4d1f rfa60cd69 45 45 struct audio_source { 46 46 link_t link; 47 list_t connections; 47 48 const char *name; 48 49 pcm_format_t format; 49 50 void *private_data; 50 int (*connection_change)(audio_source_t *source );51 int (*connection_change)(audio_source_t *source, bool added); 51 52 int (*update_available_data)(audio_source_t *source, size_t size); 52 struct audio_sink *connected_sink;53 53 struct { 54 54 void *position; … … 64 64 65 65 int audio_source_init(audio_source_t *source, const char *name, void *data, 66 int (*connection_change)(audio_source_t * ),66 int (*connection_change)(audio_source_t *, bool), 67 67 int (*update_available_data)(audio_source_t *, size_t), 68 68 const pcm_format_t *f); 69 69 void audio_source_fini(audio_source_t *source); 70 int audio_source_connected(audio_source_t *source, struct audio_sink *sink);70 //int audio_source_connected(audio_source_t *source, struct audio_sink *sink); 71 71 int audio_source_add_self(audio_source_t *source, void *buffer, size_t size, 72 72 const pcm_format_t *f); -
uspace/srv/audio/hound/hound.c
r39c4d1f rfa60cd69 43 43 #include "audio_sink.h" 44 44 #include "audio_source.h" 45 #include "connection.h" 45 46 #include "log.h" 46 47 #include "errno.h" … … 86 87 list_initialize(&hound->sources); 87 88 list_initialize(&hound->sinks); 89 list_initialize(&hound->connections); 88 90 return EOK; 89 91 } … … 207 209 return EEXISTS; 208 210 } 209 list_foreach(hound->sinks, it) {210 audio_sink_t *sink = audio_sink_list_instance(it);211 if (find_source_by_name(&sink->sources, source->name)) {212 log_debug("Source by that name already exists");213 fibril_mutex_unlock(&hound->list_guard);214 return EEXISTS;215 }216 }217 211 list_append(&source->link, &hound->sources); 218 212 fibril_mutex_unlock(&hound->list_guard); … … 245 239 log_verbose("Removing source '%s'.", source->name); 246 240 fibril_mutex_lock(&hound->list_guard); 247 if (!list_member(&source->link, &hound->sources)) { 248 assert(source->connected_sink); 249 hound_disconnect_internal(hound, source->name, 250 source->connected_sink->name); 251 } 241 252 242 list_remove(&source->link); 253 243 fibril_mutex_unlock(&hound->list_guard); … … 263 253 fibril_mutex_lock(&hound->list_guard); 264 254 265 if (!list_empty(&sink-> sources)) {255 if (!list_empty(&sink->connections)) { 266 256 // TODO disconnect instead 267 257 fibril_mutex_unlock(&hound->list_guard); … … 278 268 log_verbose("Connecting '%s' to '%s'.", source_name, sink_name); 279 269 fibril_mutex_lock(&hound->list_guard); 270 271 if (list_empty(&hound->sinks)) { 272 fibril_mutex_unlock(&hound->list_guard); 273 log_debug("No sinks available"); 274 return EINVAL; 275 } 276 277 if (list_empty(&hound->sources)) { 278 fibril_mutex_unlock(&hound->list_guard); 279 log_debug("No sinks available"); 280 return EINVAL; 281 } 280 282 281 283 audio_source_t *source = … … 294 296 return ENOENT; 295 297 } 296 list_remove(&source->link); 297 const int ret = audio_sink_add_source(sink, source); 298 if (ret != EOK) { 299 log_debug("Failed add source to sink list: %s", str_error(ret)); 300 list_append(&source->link, &hound->sources); 301 } 302 fibril_mutex_unlock(&hound->list_guard); 298 connection_t *conn = connection_create(source, sink); 299 if (!conn) { 300 fibril_mutex_unlock(&hound->list_guard); 301 log_debug("Failed to create connection"); 302 return ENOMEM; 303 } 304 list_append(&conn->hound_link, &hound->connections); 305 fibril_mutex_unlock(&hound->list_guard); 306 log_debug("CONNECTED: %s -> %s", source_name, sink_name); 303 307 return EOK; 304 308 } … … 317 321 assert(hound); 318 322 assert(fibril_mutex_is_locked(&hound->list_guard)); 319 log_verbose("Disconnecting '%s' to '%s'.", source_name, sink_name); 320 321 audio_sink_t *sink = 322 audio_sink_list_instance(list_first(&hound->sinks)); 323 if (str_cmp(sink_name, "default") != 0) 324 sink = find_sink_by_name(&hound->sinks, sink_name); 325 326 audio_source_t *source = 327 audio_source_list_instance(list_first(&hound->sources)); 328 if (str_cmp(source_name, "default") != 0) 329 source = sink ? find_source_by_name(&sink->sources, source_name) : NULL; 330 if (!source || !sink) { 331 log_debug("Source (%p), or sink (%p) not found", source, sink); 332 return ENOENT; 333 } 334 const int ret = audio_sink_remove_source(sink, source); 335 if (ret != EOK) { 336 log_debug("Failed remove source to sink list: %s", str_error(ret)); 337 } else { 338 list_append(&source->link, &hound->sources); 339 } 323 log_debug("Disconnecting '%s' to '%s'.", source_name, sink_name); 324 325 list_foreach_safe(hound->connections, it, next) { 326 connection_t *conn = connection_from_hound_list(it); 327 if (str_cmp(connection_source_name(conn), source_name) == 0 || 328 str_cmp(connection_sink_name(conn), sink_name) == 0) { 329 log_debug("Removing %s -> %s", connection_source_name(conn), 330 connection_sink_name(conn)); 331 list_remove(it); 332 connection_destroy(conn); 333 } 334 } 335 340 336 return EOK; 341 337 } -
uspace/srv/audio/hound/hound.h
r39c4d1f rfa60cd69 56 56 list_t sources; 57 57 list_t sinks; 58 list_t connections; 58 59 } hound_t; 59 60 -
uspace/srv/audio/hound/main.c
r39c4d1f rfa60cd69 132 132 hound_server_get_unregister_params(&name); 133 133 int ret = ENOENT; 134 list_foreach (local_playback, it) {134 list_foreach_safe(local_playback, it, next) { 135 135 audio_client_t *client = 136 136 audio_client_list_instance(it); 137 log_fatal("UNREGISTER_PLAYBACK %p", client); 137 138 if (str_cmp(client->name, name) == 0) { 138 139 ret = hound_remove_source(&hound, … … 213 214 list_first(&local_playback)); 214 215 list_remove(&client->link); 216 log_fatal("CASE 0 %p", client); 215 217 hound_remove_source(&hound, &client->source); 216 218 audio_client_destroy(client);
Note:
See TracChangeset
for help on using the changeset viewer.