Changeset 633 for pjproject/trunk/pjmedia/src/pjmedia/conference.c
- Timestamp:
- Jul 29, 2006 11:14:47 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/conference.c
r582 r633 30 30 #include <pj/string.h> 31 31 32 32 33 /* CONF_DEBUG enables detailed operation of the conference bridge. 33 34 * Beware that it prints large amounts of logs (several lines per frame). … … 58 59 #define BYTES_PER_SAMPLE 2 59 60 61 #define SIGNATURE PJMEDIA_PORT_SIGNATURE('C', 'O', 'N', 'F') 62 #define SIGNATURE_PORT PJMEDIA_PORT_SIGNATURE('C', 'O', 'N', 'P') 60 63 #define NORMAL_LEVEL 128 61 64 #define SLOT_TYPE unsigned … … 197 200 static pj_status_t get_frame(pjmedia_port *this_port, 198 201 pjmedia_frame *frame); 202 static pj_status_t get_frame_pasv(pjmedia_port *this_port, 203 pjmedia_frame *frame); 199 204 static pj_status_t destroy_port(pjmedia_port *this_port); 200 205 … … 329 334 } 330 335 331 /* 332 * Create port zero for the sound device. 333 */ 334 static pj_status_t create_sound_port( pj_pool_t *pool, 335 pjmedia_conf *conf ) 336 337 /* 338 * Add passive port. 339 */ 340 static pj_status_t create_pasv_port( pjmedia_conf *conf, 341 pj_pool_t *pool, 342 const pj_str_t *name, 343 pjmedia_port *port, 344 struct conf_port **p_conf_port) 336 345 { 337 346 struct conf_port *conf_port; 338 pj_str_t name = { "Master/sound", 12 };339 347 unsigned i; 340 348 pj_status_t status; 341 349 342 343 344 350 /* Create port */ 345 status = create_conf_port(pool, conf, NULL, &name, &conf_port);351 status = create_conf_port(pool, conf, port, name, &conf_port); 346 352 if (status != PJ_SUCCESS) 347 goto on_error;348 349 /* Sound devicehas rx buffers. */353 return status; 354 355 /* Passive port has rx buffers. */ 350 356 for (i=0; i<RX_BUF_COUNT; ++i) { 351 357 conf_port->snd_buf[i] = pj_pool_zalloc(pool, conf->samples_per_frame * 352 358 sizeof(conf_port->snd_buf[0][0])); 353 359 if (conf_port->snd_buf[i] == NULL) { 354 status = PJ_ENOMEM; 355 goto on_error; 360 return PJ_ENOMEM; 356 361 } 357 362 } … … 359 364 conf_port->snd_read_pos = 0; 360 365 361 362 /* Set to port zero */ 363 conf->ports[0] = conf_port; 364 conf->port_cnt++; 366 *p_conf_port = conf_port; 367 368 return PJ_SUCCESS; 369 } 370 371 372 /* 373 * Create port zero for the sound device. 374 */ 375 static pj_status_t create_sound_port( pj_pool_t *pool, 376 pjmedia_conf *conf ) 377 { 378 struct conf_port *conf_port; 379 pj_str_t name = { "Master/sound", 12 }; 380 pj_status_t status; 381 382 383 status = create_pasv_port(conf, pool, &name, NULL, &conf_port); 384 if (status != PJ_SUCCESS) 385 return status; 365 386 366 387 … … 395 416 396 417 418 /* Add the port to the bridge */ 419 conf->ports[0] = conf_port; 420 conf->port_cnt++; 421 422 397 423 PJ_LOG(5,(THIS_FILE, "Sound device successfully created for port 0")); 398 424 return PJ_SUCCESS; 399 400 on_error:401 return status;402 403 425 } 404 426 … … 416 438 { 417 439 pjmedia_conf *conf; 440 const pj_str_t name = { "Conf", 4 }; 418 441 pj_status_t status; 419 442 … … 443 466 PJ_ASSERT_RETURN(conf->master_port, PJ_ENOMEM); 444 467 445 conf->master_port->info.bits_per_sample = bits_per_sample; 446 conf->master_port->info.bytes_per_frame = samples_per_frame * 447 bits_per_sample / 8; 448 conf->master_port->info.channel_count = channel_count; 449 conf->master_port->info.encoding_name = pj_str("pcm"); 450 conf->master_port->info.has_info = 1; 451 conf->master_port->info.name = pj_str("sound-dev"); 452 conf->master_port->info.need_info = 0; 453 conf->master_port->info.pt = 0xFF; 454 conf->master_port->info.clock_rate = clock_rate; 455 conf->master_port->info.samples_per_frame = samples_per_frame; 456 conf->master_port->info.signature = 0; 457 conf->master_port->info.type = PJMEDIA_TYPE_AUDIO; 468 pjmedia_port_info_init(&conf->master_port->info, &name, SIGNATURE, 469 clock_rate, channel_count, bits_per_sample, 470 samples_per_frame); 471 472 conf->master_port->port_data.pdata = conf; 473 conf->master_port->port_data.ldata = 0; 458 474 459 475 conf->master_port->get_frame = &get_frame; 460 476 conf->master_port->put_frame = &put_frame; 461 477 conf->master_port->on_destroy = &destroy_port; 462 463 conf->master_port->user_data = conf;464 478 465 479 … … 545 559 static pj_status_t destroy_port(pjmedia_port *this_port) 546 560 { 547 pjmedia_conf *conf = this_port-> user_data;561 pjmedia_conf *conf = this_port->port_data.pdata; 548 562 return pjmedia_conf_destroy(conf); 549 563 } … … 630 644 return PJ_SUCCESS; 631 645 } 646 647 648 /* 649 * Add passive port. 650 */ 651 PJ_DEF(pj_status_t) pjmedia_conf_add_passive_port( pjmedia_conf *conf, 652 pj_pool_t *pool, 653 const pj_str_t *name, 654 unsigned clock_rate, 655 unsigned channel_count, 656 unsigned samples_per_frame, 657 unsigned bits_per_sample, 658 unsigned options, 659 unsigned *p_slot, 660 pjmedia_port **p_port ) 661 { 662 struct conf_port *conf_port; 663 pjmedia_port *port; 664 unsigned index; 665 pj_str_t tmp; 666 pj_status_t status; 667 668 PJ_ASSERT_RETURN(conf && pool, PJ_EINVAL); 669 670 /* For this version of PJMEDIA, port MUST have the same number of 671 * PCM channels. 672 */ 673 if (channel_count != conf->channel_count) { 674 pj_assert(!"Number of channels mismatch"); 675 return PJMEDIA_ENCCHANNEL; 676 } 677 678 /* For this version, options must be zero */ 679 PJ_ASSERT_RETURN(options == 0, PJ_EINVAL); 680 PJ_UNUSED_ARG(options); 681 682 pj_mutex_lock(conf->mutex); 683 684 if (conf->port_cnt >= conf->max_ports) { 685 pj_assert(!"Too many ports"); 686 pj_mutex_unlock(conf->mutex); 687 return PJ_ETOOMANY; 688 } 689 690 /* Find empty port in the conference bridge. */ 691 for (index=0; index < conf->max_ports; ++index) { 692 if (conf->ports[index] == NULL) 693 break; 694 } 695 696 pj_assert(index != conf->max_ports); 697 698 if (name == NULL) { 699 name = &tmp; 700 701 tmp.ptr = pj_pool_alloc(pool, 20); 702 tmp.slen = pj_ansi_sprintf(tmp.ptr, "ConfPort#%d", index); 703 } 704 705 /* Create and initialize the media port structure. */ 706 port = pj_pool_zalloc(pool, sizeof(pjmedia_port)); 707 PJ_ASSERT_RETURN(port, PJ_ENOMEM); 708 709 pjmedia_port_info_init(&port->info, name, SIGNATURE_PORT, 710 clock_rate, channel_count, bits_per_sample, 711 samples_per_frame); 712 713 port->port_data.pdata = conf; 714 port->port_data.ldata = index; 715 716 port->get_frame = &get_frame_pasv; 717 port->put_frame = &put_frame; 718 port->on_destroy = NULL; 719 720 721 /* Create conf port structure. */ 722 status = create_pasv_port(conf, pool, name, port, &conf_port); 723 if (status != PJ_SUCCESS) { 724 pj_mutex_unlock(conf->mutex); 725 return status; 726 } 727 728 729 /* Put the port. */ 730 conf->ports[index] = conf_port; 731 conf->port_cnt++; 732 733 /* Done. */ 734 if (p_slot) 735 *p_slot = index; 736 if (p_port) 737 *p_port = port; 738 739 pj_mutex_unlock(conf->mutex); 740 741 return PJ_SUCCESS; 742 } 743 632 744 633 745 … … 1363 1475 pjmedia_frame *frame) 1364 1476 { 1365 pjmedia_conf *conf = this_port-> user_data;1477 pjmedia_conf *conf = this_port->port_data.pdata; 1366 1478 unsigned ci, cj, i, j; 1367 1479 … … 1419 1531 1420 1532 /* Get frame from this port. 1421 * For port zero (sound port) , get the frame from the rx_buffer1422 * instead.1533 * For port zero (sound port) and passive ports, get the frame from 1534 * the rx_buffer instead. 1423 1535 */ 1424 if ( i==0) {1536 if (conf_port->port == NULL) { 1425 1537 pj_int16_t *snd_buf; 1426 1538 … … 1616 1728 1617 1729 /* 1730 * get_frame() for passive port 1731 */ 1732 static pj_status_t get_frame_pasv(pjmedia_port *this_port, 1733 pjmedia_frame *frame) 1734 { 1735 pj_assert(0); 1736 return -1; 1737 } 1738 1739 1740 /* 1618 1741 * Recorder callback. 1619 1742 */ … … 1621 1744 const pjmedia_frame *frame) 1622 1745 { 1623 pjmedia_conf *conf = this_port-> user_data;1624 struct conf_port * snd_port = conf->ports[0];1746 pjmedia_conf *conf = this_port->port_data.pdata; 1747 struct conf_port *port = conf->ports[this_port->port_data.ldata]; 1625 1748 const pj_int16_t *input = frame->buf; 1626 1749 pj_int16_t *target_snd_buf; … … 1632 1755 1633 1756 /* Skip if this port is muted/disabled. */ 1634 if ( snd_port->rx_setting != PJMEDIA_PORT_ENABLE) {1757 if (port->rx_setting != PJMEDIA_PORT_ENABLE) { 1635 1758 return PJ_SUCCESS; 1636 1759 } 1637 1760 1638 1761 /* Skip if no port is listening to the microphone */ 1639 if ( snd_port->listener_cnt == 0) {1762 if (port->listener_cnt == 0) { 1640 1763 return PJ_SUCCESS; 1641 1764 } … … 1643 1766 1644 1767 /* Determine which rx_buffer to fill in */ 1645 target_snd_buf = snd_port->snd_buf[snd_port->snd_write_pos];1768 target_snd_buf = port->snd_buf[port->snd_write_pos]; 1646 1769 1647 1770 /* Copy samples from audio device to target rx_buffer */ … … 1649 1772 1650 1773 /* Switch buffer */ 1651 snd_port->snd_write_pos = (snd_port->snd_write_pos+1)%RX_BUF_COUNT;1652 1653 1654 return PJ_SUCCESS; 1655 } 1656 1774 port->snd_write_pos = (port->snd_write_pos+1)%RX_BUF_COUNT; 1775 1776 1777 return PJ_SUCCESS; 1778 } 1779
Note: See TracChangeset
for help on using the changeset viewer.