Changeset 3438 for pjproject/trunk/pjmedia/src/pjmedia-audiodev/alsa_dev.c
- Timestamp:
- Mar 11, 2011 6:57:24 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-audiodev/alsa_dev.c
r3079 r3438 58 58 static pj_status_t alsa_factory_init(pjmedia_aud_dev_factory *f); 59 59 static pj_status_t alsa_factory_destroy(pjmedia_aud_dev_factory *f); 60 static pj_status_t alsa_factory_refresh(pjmedia_aud_dev_factory *f); 60 61 static unsigned alsa_factory_get_dev_count(pjmedia_aud_dev_factory *f); 61 62 static pj_status_t alsa_factory_get_dev_info(pjmedia_aud_dev_factory *f, … … 93 94 pj_pool_factory *pf; 94 95 pj_pool_t *pool; 96 pj_pool_t *base_pool; 95 97 96 98 unsigned dev_cnt; … … 134 136 &alsa_factory_get_dev_info, 135 137 &alsa_factory_default_param, 136 &alsa_factory_create_stream 138 &alsa_factory_create_stream, 139 &alsa_factory_refresh 137 140 }; 138 141 … … 146 149 &alsa_stream_destroy 147 150 }; 151 152 static void null_alsa_error_handler (const char *file, 153 int line, 154 const char *function, 155 int err, 156 const char *fmt, 157 ...) 158 { 159 PJ_UNUSED_ARG(file); 160 PJ_UNUSED_ARG(line); 161 PJ_UNUSED_ARG(function); 162 PJ_UNUSED_ARG(err); 163 PJ_UNUSED_ARG(fmt); 164 } 148 165 149 166 static void alsa_error_handler (const char *file, … … 175 192 176 193 177 static pj_status_t add_dev (struct alsa_factory *af, int card, int device)194 static pj_status_t add_dev (struct alsa_factory *af, const char *dev_name) 178 195 { 179 196 pjmedia_aud_dev_info *adi; 180 char dev_name[32];181 197 snd_pcm_t* pcm; 182 198 int pb_result, ca_result; … … 187 203 adi = &af->devs[af->dev_cnt]; 188 204 189 TRACE_((THIS_FILE, "add_dev (%d, %d): Enter", card, device)); 190 sprintf (dev_name, ALSA_DEVICE_NAME, card, device); 205 TRACE_((THIS_FILE, "add_dev (%s): Enter", dev_name)); 191 206 192 207 /* Try to open the device in playback mode */ … … 246 261 pj_pool_t *pool; 247 262 248 pool = pj_pool_create(pf, "alsa_aud ", 256, 256, NULL);263 pool = pj_pool_create(pf, "alsa_aud_base", 256, 256, NULL); 249 264 af = PJ_POOL_ZALLOC_T(pool, struct alsa_factory); 250 265 af->pf = pf; 251 af-> pool = pool;266 af->base_pool = pool; 252 267 af->base.op = &alsa_factory_op; 253 268 … … 259 274 static pj_status_t alsa_factory_init(pjmedia_aud_dev_factory *f) 260 275 { 276 pj_status_t status = alsa_factory_refresh(f); 277 if (PJ_SUCCESS != status) 278 return status; 279 280 PJ_LOG(4,(THIS_FILE, "ALSA initialized")); 281 return PJ_SUCCESS; 282 } 283 284 285 /* API: destroy factory */ 286 static pj_status_t alsa_factory_destroy(pjmedia_aud_dev_factory *f) 287 { 261 288 struct alsa_factory *af = (struct alsa_factory*)f; 262 int card, device; 289 290 if (af->pool) 291 pj_pool_release(af->pool); 292 293 if (af->base_pool) { 294 pj_pool_t *pool = af->base_pool; 295 af->base_pool = NULL; 296 pj_pool_release(pool); 297 } 298 299 /* Restore handler */ 300 snd_lib_error_set_handler(NULL); 301 302 return PJ_SUCCESS; 303 } 304 305 306 /* API: refresh the device list */ 307 static pj_status_t alsa_factory_refresh(pjmedia_aud_dev_factory *f) 308 { 309 struct alsa_factory *af = (struct alsa_factory*)f; 310 char **hints, **n; 311 int err; 263 312 264 313 TRACE_((THIS_FILE, "pjmedia_snd_init: Enumerate sound devices")); 314 315 if (af->pool != NULL) { 316 pj_pool_release(af->pool); 317 af->pool = NULL; 318 } 319 320 af->pool = pj_pool_create(af->pf, "alsa_aud", 256, 256, NULL); 321 af->dev_cnt = 0; 322 265 323 /* Enumerate sound devices */ 266 for (card=0; card<MAX_SOUND_CARDS; card++) { 267 for (device=0; device<MAX_SOUND_DEVICES_PER_CARD; device++) { 268 add_dev(af, card, device); 324 err = snd_device_name_hint(-1, "pcm", (void***)&hints); 325 if (err != 0) 326 return PJMEDIA_EAUD_SYSERR; 327 328 /* Set a null error handler prior to enumeration to suppress errors */ 329 snd_lib_error_set_handler(null_alsa_error_handler); 330 331 n = hints; 332 while (*n != NULL) { 333 char *name = snd_device_name_get_hint(*n, "NAME"); 334 if (name != NULL && 0 != strcmp("null", name)) { 335 add_dev(af, name); 336 free(name); 269 337 } 338 n++; 270 339 } 271 340 … … 273 342 * error messages about invalid card/device ID. 274 343 */ 275 snd_lib_error_set_handler (alsa_error_handler); 344 snd_lib_error_set_handler(alsa_error_handler); 345 346 err = snd_device_name_free_hint((void**)hints); 276 347 277 348 PJ_LOG(4,(THIS_FILE, "ALSA driver found %d devices", af->dev_cnt)); 278 return PJ_SUCCESS;279 }280 281 282 /* API: destroy factory */283 static pj_status_t alsa_factory_destroy(pjmedia_aud_dev_factory *f)284 {285 struct alsa_factory *af = (struct alsa_factory*)f;286 287 if (af->pool) {288 pj_pool_t *pool = af->pool;289 af->pool = NULL;290 pj_pool_release(pool);291 }292 293 /* Restore handler */294 snd_lib_error_set_handler(NULL);295 349 296 350 return PJ_SUCCESS;
Note: See TracChangeset
for help on using the changeset viewer.