Changeset eceb300 in mainline
- Timestamp:
- 2012-07-15T20:51:20Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 50fa3f7
- Parents:
- a9aae16e
- Location:
- uspace/srv/audio/hound
- Files:
-
- 1 deleted
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/audio/hound/Makefile
ra9aae16e receb300 32 32 EXTRA_CFLAGS = \ 33 33 -DNAME="\"hound\"" \ 34 -I$(LIBDRV_PREFIX)/include 34 -I$(LIBDRV_PREFIX)/include \ 35 -I$(LIBHOUND_PREFIX)/include 35 36 36 37 LIBS = \ 37 $(LIBDRV_PREFIX)/libdrv.a 38 $(LIBDRV_PREFIX)/libdrv.a \ 39 $(LIBHOUND_PREFIX)/libhound.a 38 40 39 41 SOURCES = \ -
uspace/srv/audio/hound/main.c
ra9aae16e receb300 38 38 #include <bool.h> 39 39 #include <errno.h> 40 #include <loc.h>41 40 #include <stdio.h> 42 41 #include <stdlib.h> 43 42 #include <str_error.h> 43 #include <hound/server.h> 44 44 45 45 46 #include "hound.h" … … 51 52 #include "audio_client.h" 52 53 #include "log.h" 53 #include "protocol.h"54 54 55 55 static hound_t hound; 56 56 57 static inline audio_format_t read_format(const ipc_call_t *call) 58 { 59 audio_format_t format = { 60 .channels = IPC_GET_ARG1(*call), 61 .sampling_rate = IPC_GET_ARG2(*call), 62 .sample_format = IPC_GET_ARG3(*call), 63 }; 64 return format; 65 } 66 static inline const char *get_name() 67 { 68 size_t size = 0; 69 ipc_callid_t callid; 70 async_data_write_receive(&callid, &size); 71 char *buffer = malloc(size); 72 if (buffer) { 73 async_data_write_finalize(callid, buffer, size); 74 buffer[size - 1] = 0; 75 log_verbose("Got name from client: %s", buffer); 76 } 77 return buffer; 78 } 79 static inline async_sess_t *get_session() 80 { 81 ipc_call_t call; 82 ipc_callid_t callid = async_get_call(&call); 83 async_sess_t *s = async_callback_receive_start(EXCHANGE_ATOMIC, &call); 84 async_answer_0(callid, s ? EOK : ENOMEM); 85 if (s) { 86 log_verbose("Received callback session"); 87 } else 88 log_debug("Failed to receive callback session"); 89 return s; 90 } 91 57 static int device_callback(service_id_t id, const char *name) 58 { 59 return hound_add_device(&hound, id, name); 60 } 92 61 93 62 static void scan_for_devices(void) 94 63 { 95 static bool cat_resolved = false; 96 static category_id_t cat; 97 98 if (!cat_resolved) { 99 log_verbose("Resolving category \"%s\".", CATEGORY); 100 const int ret = loc_category_get_id(CATEGORY, &cat, 101 IPC_FLAG_BLOCKING); 102 if (ret != EOK) { 103 log_error("Failed to get category: %s", str_error(ret)); 104 return; 105 } 106 cat_resolved = true; 107 } 108 109 log_verbose("Getting available services in category."); 110 111 service_id_t *svcs = NULL; 112 size_t count = 0; 113 const int ret = loc_category_get_svcs(cat, &svcs, &count); 114 if (ret != EOK) { 115 log_error("Failed to get audio devices: %s", str_error(ret)); 116 return; 117 } 118 119 for (unsigned i = 0; i < count; ++i) { 120 char *name = NULL; 121 int ret = loc_service_get_name(svcs[i], &name); 122 if (ret != EOK) { 123 log_error("Failed to get dev name: %s", str_error(ret)); 124 continue; 125 } 126 ret = hound_add_device(&hound, svcs[i], name); 127 if (ret != EOK && ret != EEXISTS) { 128 log_error("Failed to add audio device \"%s\": %s", 129 name, str_error(ret)); 130 } 131 free(name); 132 } 133 134 free(svcs); 64 hound_server_devices_iterate(device_callback); 135 65 } 136 66 … … 141 71 LIST_INITIALIZE(local_playback); 142 72 LIST_INITIALIZE(local_recording); 73 audio_format_t format = {0}; 74 const char *name = NULL; 75 async_sess_t *sess = NULL; 143 76 144 77 while (1) { … … 147 80 switch (IPC_GET_IMETHOD(call)) { 148 81 case HOUND_REGISTER_PLAYBACK: { 149 const audio_format_t format = read_format(&call);150 const char *name = get_name();151 async_sess_t *sess = get_session();82 hound_server_get_register_params(&name, &sess, 83 &format.channels, &format.sampling_rate, 84 &format.sample_format); 152 85 audio_client_t *client = 153 86 audio_client_get_playback(name, &format, sess); … … 173 106 } 174 107 case HOUND_REGISTER_RECORDING: { 175 const audio_format_t format = read_format(&call);176 const char *name = get_name();177 async_sess_t *sess = get_session();178 audio_client_t * 108 hound_server_get_register_params(&name, &sess, 109 &format.channels, &format.sampling_rate, 110 &format.sample_format); 111 audio_client_t *client = 179 112 audio_client_get_recording(name, &format, sess); 180 113 free(name); … … 197 130 } 198 131 case HOUND_UNREGISTER_PLAYBACK: { 199 const char *name = get_name(); 132 const char *name = NULL; 133 hound_server_get_unregister_params(&name); 200 134 int ret = ENOENT; 201 135 list_foreach(local_playback, it) { … … 217 151 } 218 152 case HOUND_UNREGISTER_RECORDING: { 219 const char *name = get_name(); 153 const char *name = NULL; 154 hound_server_get_unregister_params(&name); 220 155 int ret = ENOENT; 221 156 list_foreach(local_recording, it) { … … 237 172 } 238 173 case HOUND_CONNECT: { 239 const char * name_a = get_name();240 const char *name_b = get_name();241 const int ret = hound_connect(&hound, name_a, name_b);174 const char *source = NULL, *sink = NULL; 175 hound_server_get_connection_params(&source, &sink); 176 const int ret = hound_connect(&hound, source, sink); 242 177 if (ret != EOK) 243 178 log_error("Failed to connect '%s' to '%s': %s", 244 name_a, name_b, str_error(ret));245 free( name_a);246 free( name_b);179 source, sink, str_error(ret)); 180 free(source); 181 free(sink); 247 182 async_answer_0(callid, ret); 248 183 break; 249 184 } 250 185 case HOUND_DISCONNECT: { 251 const char * name_a = get_name();252 const char *name_b = get_name();253 const int ret = hound_disconnect(&hound, name_a, name_b);186 const char *source = NULL, *sink = NULL; 187 hound_server_get_connection_params(&source, &sink); 188 const int ret = hound_disconnect(&hound, source, sink); 254 189 if (ret != EOK) 255 190 log_error("Failed to disconnect '%s' from '%s'" 256 ": %s", name_a, name_b, str_error(ret));257 free( name_a);258 free( name_b);191 ": %s", source, sink, str_error(ret)); 192 free(source); 193 free(sink); 259 194 async_answer_0(callid, ret); 260 195 break; … … 282 217 audio_client_destroy(client); 283 218 } 284 //TODO remove all clients285 219 return; 286 220 } … … 300 234 301 235 async_set_client_connection(client_connection); 302 ret = loc_server_register(NAME); 236 237 service_id_t id = 0; 238 ret = hound_server_register(NAME, &id); 303 239 if (ret != EOK) { 304 log_fatal("Failed to register sound server: %s", 240 log_fatal("Failed to register server: %s", str_error(ret)); 241 return -ret; 242 } 243 244 ret = hound_server_set_device_change_callback(scan_for_devices); 245 if (ret != EOK) { 246 log_fatal("Failed to register for device changes: %s", 305 247 str_error(ret)); 306 return -ret; 307 } 308 309 char fqdn[LOC_NAME_MAXLEN + 1]; 310 snprintf(fqdn, LOC_NAME_MAXLEN, "%s/%s", NAMESPACE, NAME); 311 service_id_t id = 0; 312 ret = loc_service_register(fqdn, &id); 313 if (ret != EOK) { 314 log_fatal("Failed to register sound service: %s", 315 str_error(ret)); 316 return -ret; 317 } 318 319 ret = loc_register_cat_change_cb(scan_for_devices); 320 if (ret != EOK) { 321 log_fatal("Failed to register for category changes: %s", 322 str_error(ret)); 323 loc_service_unregister(id); 248 hound_server_unregister(id); 324 249 return -ret; 325 250 }
Note:
See TracChangeset
for help on using the changeset viewer.