Changeset 2cc5c835 in mainline
- Timestamp:
- 2012-07-15T15:14:10Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 57e8b3b
- Parents:
- b497018
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/dplay/dplay.c
rb497018 r2cc5c835 63 63 fibril_mutex_t mutex; 64 64 fibril_condvar_t cv; 65 a sync_exch_t *device;65 audio_pcm_sess_t *device; 66 66 } playback_t; 67 67 68 static void playback_initialize(playback_t *pb, a sync_exch_t *exch)69 { 70 assert( exch);68 static void playback_initialize(playback_t *pb, audio_pcm_sess_t *sess) 69 { 70 assert(sess); 71 71 assert(pb); 72 72 pb->buffer.base = NULL; … … 75 75 pb->playing = false; 76 76 pb->source = NULL; 77 pb->device = exch;77 pb->device = sess; 78 78 fibril_mutex_initialize(&pb->mutex); 79 79 fibril_condvar_initialize(&pb->cv); … … 168 168 } 169 169 170 devman_handle_t pcm_handle; 171 int ret = devman_fun_get_handle(device, &pcm_handle, 0); 172 if (ret != EOK) { 173 printf("Failed to get device(%s) handle: %s.\n", 174 device, str_error(ret)); 175 return 1; 176 } 177 178 async_sess_t *session = devman_device_connect( 179 EXCHANGE_SERIALIZE, pcm_handle, IPC_FLAG_BLOCKING); 170 audio_pcm_sess_t *session = audio_pcm_open(device); 180 171 if (!session) { 181 172 printf("Failed to connect to device.\n"); … … 183 174 } 184 175 185 async_exch_t *exch = async_exchange_begin(session);186 if (!exch) {187 ret = EPARTY;188 printf("Failed to start session exchange.\n");189 goto close_session;190 }191 176 const char* info = NULL; 192 ret = audio_pcm_get_info_str(exch, &info);177 int ret = audio_pcm_get_info_str(session, &info); 193 178 if (ret != EOK) { 194 179 printf("Failed to get PCM info.\n"); … … 199 184 200 185 playback_t pb; 201 playback_initialize(&pb, exch);186 playback_initialize(&pb, session); 202 187 203 188 ret = audio_pcm_get_buffer(pb.device, &pb.buffer.base, … … 236 221 cleanup: 237 222 munmap(pb.buffer.base, pb.buffer.size); 238 audio_pcm_release_buffer( exch);223 audio_pcm_release_buffer(pb.device); 239 224 close_session: 240 async_exchange_end(exch); 241 async_hangup(session); 225 audio_pcm_close(session); 242 226 return ret == EOK ? 0 : 1; 243 227 } -
uspace/app/drec/drec.c
rb497018 r2cc5c835 65 65 } buffer; 66 66 FILE* file; 67 a sync_exch_t *device;67 audio_pcm_sess_t *device; 68 68 } record_t; 69 69 70 static void record_initialize(record_t *rec, a sync_exch_t *exch)71 { 72 assert( exch);70 static void record_initialize(record_t *rec, audio_pcm_sess_t *sess) 71 { 72 assert(sess); 73 73 assert(rec); 74 74 rec->buffer.base = NULL; … … 76 76 rec->buffer.position = NULL; 77 77 rec->file = NULL; 78 rec->device = exch;78 rec->device = sess; 79 79 } 80 80 … … 151 151 } 152 152 153 devman_handle_t pcm_handle; 154 int ret = devman_fun_get_handle(device, &pcm_handle, 0); 155 if (ret != EOK) { 156 printf("Failed to get device(%s) handle: %s.\n", 157 device, str_error(ret)); 158 return 1; 159 } 160 161 async_sess_t *session = devman_device_connect( 162 EXCHANGE_SERIALIZE, pcm_handle, IPC_FLAG_BLOCKING); 153 154 audio_pcm_sess_t *session = audio_pcm_open(device); 163 155 if (!session) { 164 156 printf("Failed to connect to device.\n"); … … 166 158 } 167 159 168 async_exch_t *exch = async_exchange_begin(session);169 if (!exch) {170 ret = EPARTY;171 printf("Failed to start session exchange.\n");172 goto close_session;173 }174 160 const char* info = NULL; 175 ret = audio_pcm_get_info_str(exch, &info);161 int ret = audio_pcm_get_info_str(session, &info); 176 162 if (ret != EOK) { 177 163 printf("Failed to get PCM info.\n"); … … 182 168 183 169 record_t rec; 184 record_initialize(&rec, exch);170 record_initialize(&rec, session); 185 171 186 172 ret = audio_pcm_get_buffer(rec.device, &rec.buffer.base, … … 220 206 cleanup: 221 207 munmap(rec.buffer.base, rec.buffer.size); 222 audio_pcm_release_buffer( exch);208 audio_pcm_release_buffer(rec.device); 223 209 close_session: 224 async_exchange_end(exch);225 210 async_hangup(session); 226 211 return ret == EOK ? 0 : 1; -
uspace/lib/drv/generic/remote_audio_pcm.c
rb497018 r2cc5c835 33 33 34 34 #include <async.h> 35 #include <devman.h> 35 36 #include <ddf/log.h> 36 37 #include <errno.h> … … 55 56 * CLIENT SIDE 56 57 */ 57 int audio_pcm_get_info_str(async_exch_t *exch, const char **name) 58 { 59 if (!exch) 60 return EINVAL; 58 audio_pcm_sess_t *audio_pcm_open(const char *name) 59 { 60 devman_handle_t device_handle = 0; 61 const int ret = devman_fun_get_handle(name, &device_handle, 0); 62 if (ret != EOK) 63 return NULL; 64 return devman_device_connect(EXCHANGE_SERIALIZE, device_handle, 65 IPC_FLAG_BLOCKING); 66 } 67 68 audio_pcm_sess_t *audio_pcm_open_service(service_id_t id) 69 { 70 return loc_service_connect(EXCHANGE_SERIALIZE, id, IPC_FLAG_BLOCKING); 71 } 72 73 void audio_pcm_close(audio_pcm_sess_t *sess) 74 { 75 if (sess) 76 async_hangup(sess); 77 } 78 79 int audio_pcm_get_info_str(audio_pcm_sess_t *sess, const char **name) 80 { 81 async_exch_t *exch = async_exchange_begin(sess); 61 82 sysarg_t name_size; 62 83 const int ret = async_req_1_1(exch, … … 69 90 * as it waits for read request */ 70 91 async_data_read_start(exch, (void*)-1, 0); 92 async_exchange_end(exch); 71 93 return ENOMEM; 72 94 } … … 75 97 if (ret != EOK) { 76 98 free(name_place); 99 async_exchange_end(exch); 77 100 return ret; 78 101 } 79 102 *name = name_place; 80 103 } 81 return ret; 82 } 83 84 int audio_pcm_get_buffer(async_exch_t *exch, void **buffer, size_t *size, 104 async_exchange_end(exch); 105 return ret; 106 } 107 108 int audio_pcm_get_buffer(audio_pcm_sess_t *sess, void **buffer, size_t *size, 85 109 async_client_conn_t event_rec, void* arg) 86 110 { 87 if (! exch || !buffer || !size)111 if (!buffer || !size) 88 112 return EINVAL; 113 114 async_exch_t *exch = async_exchange_begin(sess); 89 115 90 116 sysarg_t buffer_size = *size; … … 96 122 int ret = async_share_in_start_0_0(exch, buffer_size, &dst); 97 123 if (ret != EOK) { 124 async_exchange_end(exch); 98 125 return ret; 99 126 } 100 127 ret = async_connect_to_me(exch, 0, 0, 0, event_rec, arg); 101 128 if (ret != EOK) { 129 async_exchange_end(exch); 102 130 return ret; 103 131 } … … 106 134 *size = buffer_size; 107 135 } 108 return ret; 109 } 110 111 int audio_pcm_release_buffer(async_exch_t *exch) 112 { 113 if (!exch) 114 return EINVAL; 115 return async_req_1_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 136 async_exchange_end(exch); 137 return ret; 138 } 139 140 int audio_pcm_release_buffer(audio_pcm_sess_t *sess) 141 { 142 async_exch_t *exch = async_exchange_begin(sess); 143 const int ret = async_req_1_0(exch, 144 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 116 145 IPC_M_AUDIO_PCM_RELEASE_BUFFER); 117 } 118 119 int audio_pcm_start_playback(async_exch_t *exch, unsigned parts, 146 async_exchange_end(exch); 147 return ret; 148 } 149 150 int audio_pcm_start_playback(audio_pcm_sess_t *sess, unsigned parts, 120 151 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 121 152 { 122 if (!exch)123 return EINVAL;124 153 if (parts > UINT8_MAX || channels > UINT8_MAX) 125 154 return EINVAL; … … 127 156 const sysarg_t packed = 128 157 (parts << 24) | (channels << 16) | (format & UINT16_MAX); 129 return async_req_3_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 130 IPC_M_AUDIO_PCM_START_PLAYBACK, sample_rate, packed); 131 } 132 133 int audio_pcm_stop_playback(async_exch_t *exch) 134 { 135 if (!exch) 136 return EINVAL; 137 return async_req_1_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 158 async_exch_t *exch = async_exchange_begin(sess); 159 const int ret = async_req_3_0(exch, 160 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 161 IPC_M_AUDIO_PCM_START_PLAYBACK, 162 sample_rate, packed); 163 async_exchange_end(exch); 164 return ret; 165 } 166 167 int audio_pcm_stop_playback(audio_pcm_sess_t *sess) 168 { 169 async_exch_t *exch = async_exchange_begin(sess); 170 const int ret = async_req_1_0(exch, 171 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 138 172 IPC_M_AUDIO_PCM_STOP_PLAYBACK); 139 } 140 141 int audio_pcm_start_record(async_exch_t *exch, unsigned parts, 173 async_exchange_end(exch); 174 return ret; 175 } 176 177 int audio_pcm_start_record(audio_pcm_sess_t *sess, unsigned parts, 142 178 unsigned channels, unsigned sample_rate, pcm_sample_format_t format) 143 179 { 144 if (!exch)145 return EINVAL;146 180 if (parts > UINT8_MAX || channels > UINT8_MAX) 147 181 return EINVAL; … … 149 183 const sysarg_t packed = 150 184 (parts << 24) | (channels << 16) | (format & UINT16_MAX); 151 return async_req_3_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 152 IPC_M_AUDIO_PCM_START_RECORD, sample_rate, packed); 153 } 154 155 int audio_pcm_stop_record(async_exch_t *exch) 156 { 157 if (!exch) 158 return EINVAL; 159 return async_req_1_0(exch, DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), 160 IPC_M_AUDIO_PCM_STOP_RECORD); 185 async_exch_t *exch = async_exchange_begin(sess); 186 const int ret = async_req_3_0(exch, 187 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_START_RECORD, 188 sample_rate, packed); 189 async_exchange_end(exch); 190 return ret; 191 } 192 193 int audio_pcm_stop_record(audio_pcm_sess_t *sess) 194 { 195 async_exch_t *exch = async_exchange_begin(sess); 196 const int ret = async_req_1_0(exch, 197 DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_STOP_RECORD); 198 async_exchange_end(exch); 199 return ret; 161 200 } 162 201 -
uspace/lib/drv/include/audio_pcm_iface.h
rb497018 r2cc5c835 39 39 #include <async.h> 40 40 #include <bool.h> 41 #include <loc.h> 41 42 #include <pcm_sample_format.h> 42 43 … … 50 51 }; 51 52 53 typedef async_sess_t audio_pcm_sess_t; 52 54 53 int audio_pcm_get_info_str(async_exch_t *, const char **); 54 int audio_pcm_get_buffer(async_exch_t *, void **, size_t *, 55 audio_pcm_sess_t *audio_pcm_open(const char *); 56 audio_pcm_sess_t *audio_pcm_open_service(service_id_t service); 57 void audio_pcm_close(audio_pcm_sess_t *); 58 59 int audio_pcm_get_info_str(audio_pcm_sess_t *, const char **); 60 int audio_pcm_get_buffer(audio_pcm_sess_t *, void **, size_t *, 55 61 async_client_conn_t, void *); 56 int audio_pcm_release_buffer(a sync_exch_t *);62 int audio_pcm_release_buffer(audio_pcm_sess_t *); 57 63 58 int audio_pcm_start_playback(a sync_exch_t *, unsigned,64 int audio_pcm_start_playback(audio_pcm_sess_t *, unsigned, 59 65 unsigned, unsigned, pcm_sample_format_t); 60 int audio_pcm_stop_playback(a sync_exch_t *);66 int audio_pcm_stop_playback(audio_pcm_sess_t *); 61 67 62 int audio_pcm_start_record(a sync_exch_t *, unsigned,68 int audio_pcm_start_record(audio_pcm_sess_t *, unsigned, 63 69 unsigned, unsigned, pcm_sample_format_t); 64 int audio_pcm_stop_record(a sync_exch_t *);70 int audio_pcm_stop_record(audio_pcm_sess_t *); 65 71 66 72 /** Audio pcm communication interface. */ -
uspace/srv/audio/hound/audio_device.c
rb497018 r2cc5c835 42 42 #include <str_error.h> 43 43 44 #include <audio_pcm_iface.h>45 44 46 45 #include "audio_device.h" … … 54 53 static int get_buffer(audio_device_t *dev); 55 54 static int release_buffer(audio_device_t *dev); 56 static int start_playback(audio_device_t *dev);57 static int stop_playback(audio_device_t *dev);58 static int start_recording(audio_device_t *dev);59 static int stop_recording(audio_device_t *dev);60 55 61 56 … … 66 61 dev->id = id; 67 62 dev->name = str_dup(name); 68 dev->sess = loc_service_connect(EXCHANGE_SERIALIZE, id, 0);63 dev->sess = audio_pcm_open_service(id); 69 64 if (!dev->sess) { 70 65 log_debug("Failed to connect to device \"%s\"", name); … … 108 103 } 109 104 110 ret = start_playback(dev); 105 /* Fill the buffer first */ 106 audio_sink_mix_inputs(&dev->sink, 107 dev->buffer.base, dev->buffer.size); 108 109 ret = audio_pcm_start_playback(dev->sess, BUFFER_BLOCKS, 110 dev->sink.format.channels, dev->sink.format.sampling_rate, 111 dev->sink.format.sample_format); 111 112 if (ret != EOK) { 112 113 log_error("Failed to start playback: %s", … … 119 120 assert(!new); 120 121 log_verbose("No connections on device sink '%s'", sink->name); 121 int ret = stop_playback(dev);122 int ret = audio_pcm_stop_playback(dev->sess); 122 123 if (ret != EOK) { 123 124 log_error("Failed to start playback: %s", … … 147 148 return ret; 148 149 } 149 ret = start_recording(dev); 150 ret = audio_pcm_start_record(dev->sess, BUFFER_BLOCKS, 151 dev->sink.format.channels, dev->sink.format.sampling_rate, 152 dev->sink.format.sample_format); 150 153 if (ret != EOK) { 151 154 log_error("Failed to start recording: %s", … … 155 158 } 156 159 } else { /* Disconnected */ 157 int ret = stop_recording(dev);160 int ret = audio_pcm_stop_record(dev->sess); 158 161 if (ret != EOK) { 159 162 log_error("Failed to start recording: %s", … … 229 232 dev->buffer.size = 0; 230 233 231 async_exch_t *exch = async_exchange_begin(dev->sess); 232 const int ret = audio_pcm_get_buffer(exch, &dev->buffer.base, 234 return audio_pcm_get_buffer(dev->sess, &dev->buffer.base, 233 235 &dev->buffer.size, device_event_callback, dev); 234 async_exchange_end(exch); 235 return ret; 236 } 237 238 #define CHECK_BUFFER_AND_CONNECTION() \ 239 do { \ 240 assert(dev); \ 241 if (!dev->sess) { \ 242 log_debug("No connection to device"); \ 243 return EIO; \ 244 } \ 245 if (!dev->buffer.base) { \ 246 log_debug("We don't have a buffer"); \ 247 return ENOENT; \ 248 } \ 249 } while (0) 250 236 } 251 237 252 238 static int release_buffer(audio_device_t *dev) 253 239 { 254 CHECK_BUFFER_AND_CONNECTION(); 255 256 async_exch_t *exch = async_exchange_begin(dev->sess); 257 const int ret = audio_pcm_release_buffer(exch); 258 async_exchange_end(exch); 240 assert(dev); 241 assert(dev->buffer.base); 242 243 const int ret = audio_pcm_release_buffer(dev->sess); 259 244 if (ret == EOK) { 260 245 dev->buffer.base = NULL; 261 246 dev->buffer.size = 0; 262 247 dev->buffer.position = NULL; 248 } else { 249 log_debug("Failed to release buffer: %s", str_error(ret)); 263 250 } 264 251 return ret; 265 252 } 266 267 static int start_playback(audio_device_t *dev)268 {269 CHECK_BUFFER_AND_CONNECTION();270 271 /* Fill the buffer first */272 audio_sink_mix_inputs(&dev->sink, dev->buffer.base, dev->buffer.size);273 274 async_exch_t *exch = async_exchange_begin(dev->sess);275 const int ret = audio_pcm_start_playback(exch,276 BUFFER_BLOCKS, dev->sink.format.channels,277 dev->sink.format.sampling_rate, dev->sink.format.sample_format);278 async_exchange_end(exch);279 return ret;280 }281 282 static int stop_playback(audio_device_t *dev)283 {284 CHECK_BUFFER_AND_CONNECTION();285 286 async_exch_t *exch = async_exchange_begin(dev->sess);287 const int ret = audio_pcm_stop_playback(exch);288 async_exchange_end(exch);289 return ret;290 }291 292 static int start_recording(audio_device_t *dev)293 {294 CHECK_BUFFER_AND_CONNECTION();295 296 async_exch_t *exch = async_exchange_begin(dev->sess);297 const int ret = audio_pcm_start_record(exch,298 BUFFER_BLOCKS, dev->sink.format.channels,299 dev->sink.format.sampling_rate, dev->sink.format.sample_format);300 async_exchange_end(exch);301 return ret;302 }303 304 static int stop_recording(audio_device_t *dev)305 {306 CHECK_BUFFER_AND_CONNECTION();307 308 async_exch_t *exch = async_exchange_begin(dev->sess);309 const int ret = audio_pcm_stop_record(exch);310 async_exchange_end(exch);311 return ret;312 }313 314 253 /** 315 254 * @} -
uspace/srv/audio/hound/audio_device.h
rb497018 r2cc5c835 43 43 #include <errno.h> 44 44 #include <ipc/loc.h> 45 #include <audio_pcm_iface.h> 45 46 46 47 #include "audio_source.h" … … 50 51 link_t link; 51 52 service_id_t id; 52 a sync_sess_t *sess;53 audio_pcm_sess_t *sess; 53 54 char *name; 54 55 struct {
Note:
See TracChangeset
for help on using the changeset viewer.