- Timestamp:
- May 20, 2006 3:44:55 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/dsound.c
r451 r462 47 47 #define DEFAULT_BUFFER_COUNT 8 48 48 49 #define MAX_HARDWARE 16 50 51 struct dsound_dev_info 52 { 53 pjmedia_snd_dev_info info; 54 LPGUID lpGuid; 55 }; 56 57 static unsigned dev_count; 58 static struct dsound_dev_info dev_info[MAX_HARDWARE]; 59 49 60 50 61 … … 117 128 */ 118 129 static pj_status_t init_player_stream( struct dsound_stream *ds_strm, 130 int dev_id, 119 131 unsigned clock_rate, 120 132 unsigned channel_count, … … 133 145 PJ_ASSERT_RETURN(buffer_count <= MAX_PACKET_BUFFER_COUNT, PJ_EINVAL); 134 146 147 /* Check device ID */ 148 if (dev_id == -1) 149 dev_id = 0; 150 151 PJ_ASSERT_RETURN(dev_id>=0 && dev_id < (int)dev_count, PJ_EINVAL); 152 135 153 /* 136 154 * Create DirectSound device. 137 155 */ 138 hr = DirectSoundCreate(NULL, &ds_strm->ds.play.lpDs, NULL); 156 hr = DirectSoundCreate(dev_info[dev_id].lpGuid, &ds_strm->ds.play.lpDs, 157 NULL); 139 158 if (FAILED(hr)) 140 159 return PJ_RETURN_OS_ERROR(hr); … … 226 245 */ 227 246 static pj_status_t init_capture_stream( struct dsound_stream *ds_strm, 247 int dev_id, 228 248 unsigned clock_rate, 229 249 unsigned channel_count, … … 242 262 243 263 264 /* Check device id */ 265 if (dev_id == -1) 266 dev_id = 0; 267 268 PJ_ASSERT_RETURN(dev_id>=0 && dev_id < (int)dev_count, PJ_EINVAL); 269 244 270 /* 245 271 * Creating recorder device. 246 272 */ 247 hr = DirectSoundCaptureCreate(NULL, &ds_strm->ds.capture.lpDs, NULL); 273 hr = DirectSoundCaptureCreate(dev_info[dev_id].lpGuid, 274 &ds_strm->ds.capture.lpDs, NULL); 248 275 if (FAILED(hr)) 249 276 return PJ_RETURN_OS_ERROR(hr); … … 502 529 503 530 531 /* DirectSound enum device callback */ 532 static BOOL CALLBACK DSEnumCallback( LPGUID lpGuid, LPCSTR lpcstrDescription, 533 LPCSTR lpcstrModule, LPVOID lpContext) 534 { 535 unsigned index, max = sizeof(dev_info[index].info.name); 536 pj_bool_t is_capture_device = (lpContext != NULL); 537 538 539 PJ_UNUSED_ARG(lpcstrModule); 540 541 542 /* Put the capture and playback of the same devices to the same 543 * dev_info item, by looking at the GUID. 544 */ 545 for (index=0; index<dev_count; ++index) { 546 if (dev_info[index].lpGuid == lpGuid) 547 break; 548 } 549 550 if (index == dev_count) 551 ++dev_count; 552 else if (dev_count >= MAX_HARDWARE) { 553 pj_assert(!"Too many DirectSound hardware found"); 554 PJ_LOG(4,(THIS_FILE, "Too many hardware found, some devices will " 555 "not be listed")); 556 return FALSE; 557 } 558 559 strncpy(dev_info[index].info.name, lpcstrDescription, max); 560 dev_info[index].info.name[max-1] = '\0'; 561 dev_info[index].lpGuid = lpGuid; 562 dev_info[index].info.default_samples_per_sec = 44100; 563 564 /* Just assumed that device supports stereo capture/playback */ 565 if (is_capture_device) 566 dev_info[index].info.input_count+=2; 567 else 568 dev_info[index].info.output_count+=2; 569 570 return TRUE; 571 } 572 504 573 505 574 /* … … 508 577 PJ_DEF(pj_status_t) pjmedia_snd_init(pj_pool_factory *factory) 509 578 { 579 HRESULT hr; 580 unsigned i; 581 510 582 pool_factory = factory; 583 584 /* Enumerate sound playback devices */ 585 hr = DirectSoundEnumerate(&DSEnumCallback, NULL); 586 if (FAILED(hr)) 587 return PJ_RETURN_OS_ERROR(hr); 588 589 /* Enumerate sound capture devices */ 590 hr = DirectSoundEnumerate(&DSEnumCallback, (void*)1); 591 if (FAILED(hr)) 592 return PJ_RETURN_OS_ERROR(hr); 593 594 PJ_LOG(4,(THIS_FILE, "DirectSound initialized, found %d devices:", 595 dev_count)); 596 for (i=0; i<dev_count; ++i) { 597 PJ_LOG(4,(THIS_FILE, " dev_id %d: %s (in=%d, out=%d)", 598 i, dev_info[i].info.name, 599 dev_info[i].info.input_count, 600 dev_info[i].info.output_count)); 601 } 602 511 603 return PJ_SUCCESS; 512 604 } … … 525 617 PJ_DEF(int) pjmedia_snd_get_dev_count(void) 526 618 { 527 return 1;619 return dev_count; 528 620 } 529 621 … … 533 625 PJ_DEF(const pjmedia_snd_dev_info*) pjmedia_snd_get_dev_info(unsigned index) 534 626 { 535 static pjmedia_snd_dev_info info; 536 537 PJ_UNUSED_ARG(index); 538 539 pj_memset(&info, 0, sizeof(info)); 540 541 info.default_samples_per_sec = 44100; 542 info.input_count = 1; 543 info.output_count = 1; 544 pj_ansi_strcpy(info.name, "Default DirectSound Device"); 545 546 return &info; 627 PJ_ASSERT_RETURN(index < dev_count, NULL); 628 629 return &dev_info[index].info; 547 630 } 548 631 … … 577 660 PJ_ASSERT_RETURN(bits_per_sample == BITS_PER_SAMPLE, PJ_EINVAL); 578 661 579 /* Don't support device at present */580 PJ_UNUSED_ARG(rec_id);581 PJ_UNUSED_ARG(play_id);582 583 584 662 /* Create and Initialize stream descriptor */ 585 663 pool = pj_pool_create(pool_factory, "dsound-dev", 1000, 1000, NULL); … … 602 680 /* Create player stream */ 603 681 if (dir & PJMEDIA_DIR_PLAYBACK) { 604 status = init_player_stream( &strm->play_strm, clock_rate,682 status = init_player_stream( &strm->play_strm, play_id, clock_rate, 605 683 channel_count, samples_per_frame, 606 684 DEFAULT_BUFFER_COUNT ); … … 613 691 /* Create capture stream */ 614 692 if (dir & PJMEDIA_DIR_CAPTURE) { 615 status = init_capture_stream( &strm->rec_strm, clock_rate,693 status = init_capture_stream( &strm->rec_strm, rec_id, clock_rate, 616 694 channel_count, samples_per_frame, 617 695 DEFAULT_BUFFER_COUNT); … … 709 787 if (FAILED(hr)) 710 788 return PJ_RETURN_OS_ERROR(hr); 789 PJ_LOG(5,(THIS_FILE, "DirectSound playback stream started")); 711 790 } 712 791 … … 716 795 if (FAILED(hr)) 717 796 return PJ_RETURN_OS_ERROR(hr); 797 PJ_LOG(5,(THIS_FILE, "DirectSound capture stream started")); 718 798 } 719 799
Note: See TracChangeset
for help on using the changeset viewer.