- Timestamp:
- Oct 9, 2006 9:09:51 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/pasound.c
r744 r759 228 228 229 229 230 /* Get PortAudio default input device ID */ 231 static int pa_get_default_input_dev(int channel_count) 232 { 233 int i, count; 234 235 /* Enumerate the host api's for the default devices, and return 236 * the device with suitable channels. 237 */ 238 count = Pa_GetHostApiCount(); 239 for (i=0; i < count; ++i) { 240 const PaHostApiInfo *pHAInfo; 241 242 pHAInfo = Pa_GetHostApiInfo(i); 243 if (!pHAInfo) 244 continue; 245 246 if (pHAInfo->defaultInputDevice >= 0) { 247 const PaDeviceInfo *paDevInfo; 248 249 paDevInfo = Pa_GetDeviceInfo(pHAInfo->defaultInputDevice); 250 251 if (paDevInfo->maxInputChannels >= channel_count) 252 return pHAInfo->defaultInputDevice; 253 } 254 } 255 256 /* If still no device is found, enumerate all devices */ 257 count = Pa_GetDeviceCount(); 258 for (i=0; i<count; ++i) { 259 const PaDeviceInfo *paDevInfo; 260 261 paDevInfo = Pa_GetDeviceInfo(i); 262 if (paDevInfo->maxInputChannels >= channel_count) 263 return i; 264 } 265 266 return -1; 267 } 268 269 /* Get PortAudio default output device ID */ 270 static int pa_get_default_output_dev(int channel_count) 271 { 272 int i, count; 273 274 /* Enumerate the host api's for the default devices, and return 275 * the device with suitable channels. 276 */ 277 count = Pa_GetHostApiCount(); 278 for (i=0; i < count; ++i) { 279 const PaHostApiInfo *pHAInfo; 280 281 pHAInfo = Pa_GetHostApiInfo(i); 282 if (!pHAInfo) 283 continue; 284 285 if (pHAInfo->defaultOutputDevice >= 0) { 286 const PaDeviceInfo *paDevInfo; 287 288 paDevInfo = Pa_GetDeviceInfo(pHAInfo->defaultOutputDevice); 289 290 if (paDevInfo->maxOutputChannels >= channel_count) 291 return pHAInfo->defaultOutputDevice; 292 } 293 } 294 295 /* If still no device is found, enumerate all devices */ 296 count = Pa_GetDeviceCount(); 297 for (i=0; i<count; ++i) { 298 const PaDeviceInfo *paDevInfo; 299 300 paDevInfo = Pa_GetDeviceInfo(i); 301 if (paDevInfo->maxOutputChannels >= channel_count) 302 return i; 303 } 304 305 return -1; 306 } 307 308 230 309 /* 231 310 * Open stream. … … 251 330 252 331 if (index <= 0) { 253 int count = Pa_GetDeviceCount(); 254 for (index=0; index<count; ++index) { 255 paDevInfo = Pa_GetDeviceInfo(index); 256 if (paDevInfo->maxInputChannels >= (int)channel_count) 257 break; 258 } 259 if (index == count) { 332 index = pa_get_default_input_dev(channel_count); 333 if (index < 0) { 260 334 /* No such device. */ 261 335 return PJMEDIA_ENOSNDREC; 262 336 } 263 } else {264 paDevInfo = Pa_GetDeviceInfo(index); 265 if (!paDevInfo) { 266 /* Assumed it is "No such device" error. */ 267 return PJMEDIA_ESNDINDEVID;268 }337 } 338 339 paDevInfo = Pa_GetDeviceInfo(index); 340 if (!paDevInfo) { 341 /* Assumed it is "No such device" error. */ 342 return PJMEDIA_ESNDINDEVID; 269 343 } 270 344 … … 352 426 353 427 if (index <= 0) { 354 int count = Pa_GetDeviceCount(); 355 for (index=0; index<count; ++index) { 356 paDevInfo = Pa_GetDeviceInfo(index); 357 if (paDevInfo->maxOutputChannels >= (int)channel_count) 358 break; 359 } 360 if (index == count) { 428 index = pa_get_default_output_dev(channel_count); 429 if (index < 0) { 361 430 /* No such device. */ 362 431 return PJMEDIA_ENOSNDPLAY; 363 432 } 364 } else {365 paDevInfo = Pa_GetDeviceInfo(index); 366 if (!paDevInfo) { 367 /* Assumed it is "No such device" error. */ 368 return PJMEDIA_ESNDINDEVID;369 }433 } 434 435 paDevInfo = Pa_GetDeviceInfo(index); 436 if (!paDevInfo) { 437 /* Assumed it is "No such device" error. */ 438 return PJMEDIA_ESNDINDEVID; 370 439 } 371 440 … … 461 530 462 531 if (rec_id <= 0) { 463 int count = Pa_GetDeviceCount(); 464 for (rec_id=0; rec_id<count; ++rec_id) { 465 paRecDevInfo = Pa_GetDeviceInfo(rec_id); 466 if (paRecDevInfo->maxInputChannels >= (int)channel_count) 467 break; 468 } 469 if (rec_id == count) { 532 rec_id = pa_get_default_input_dev(channel_count); 533 if (rec_id < 0) { 470 534 /* No such device. */ 471 535 return PJMEDIA_ENOSNDREC; 472 536 } 473 } else {474 paRecDevInfo = Pa_GetDeviceInfo(rec_id); 475 if (!paRecDevInfo) { 476 /* Assumed it is "No such device" error. */ 477 return PJMEDIA_ESNDINDEVID;478 }537 } 538 539 paRecDevInfo = Pa_GetDeviceInfo(rec_id); 540 if (!paRecDevInfo) { 541 /* Assumed it is "No such device" error. */ 542 return PJMEDIA_ESNDINDEVID; 479 543 } 480 544 481 545 if (play_id <= 0) { 482 int count = Pa_GetDeviceCount(); 483 for (play_id=0; play_id<count; ++play_id) { 484 paPlayDevInfo = Pa_GetDeviceInfo(play_id); 485 if (paPlayDevInfo->maxOutputChannels >= (int)channel_count) 486 break; 487 } 488 if (play_id == count) { 546 play_id = pa_get_default_output_dev(channel_count); 547 if (play_id < 0) { 489 548 /* No such device. */ 490 549 return PJMEDIA_ENOSNDPLAY; 491 550 } 492 } else { 493 paPlayDevInfo = Pa_GetDeviceInfo(play_id); 494 if (!paPlayDevInfo) { 495 /* Assumed it is "No such device" error. */ 496 return PJMEDIA_ESNDINDEVID; 497 } 498 } 551 } 552 553 paPlayDevInfo = Pa_GetDeviceInfo(play_id); 554 if (!paPlayDevInfo) { 555 /* Assumed it is "No such device" error. */ 556 return PJMEDIA_ESNDINDEVID; 557 } 558 499 559 500 560 if (bits_per_sample == 8)
Note: See TracChangeset
for help on using the changeset viewer.