Changeset 4845 for pjproject/trunk/pjsip/src/pjsua2/media.cpp
- Timestamp:
- May 19, 2014 5:51:10 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua2/media.cpp
r4793 r4845 424 424 425 425 /////////////////////////////////////////////////////////////////////////////// 426 427 ToneGenerator::ToneGenerator() 428 : pool(NULL), tonegen(NULL) 429 { 430 } 431 432 ToneGenerator::~ToneGenerator() 433 { 434 if (tonegen) { 435 unregisterMediaPort(); 436 pjmedia_port_destroy(tonegen); 437 tonegen = NULL; 438 } 439 if (pool) { 440 pj_pool_release(pool); 441 pool = NULL; 442 } 443 } 444 445 void ToneGenerator::createToneGenerator(unsigned clock_rate, 446 unsigned channel_count) throw(Error) 447 { 448 pj_status_t status; 449 450 if (pool) { 451 PJSUA2_RAISE_ERROR(PJ_EEXISTS); 452 } 453 454 pool = pjsua_pool_create( "tonegen%p", 512, 512); 455 if (!pool) { 456 PJSUA2_RAISE_ERROR(PJ_ENOMEM); 457 } 458 459 status = pjmedia_tonegen_create( pool, clock_rate, channel_count, 460 clock_rate * 20 / 1000, 16, 461 0, &tonegen); 462 if (status != PJ_SUCCESS) { 463 PJSUA2_RAISE_ERROR(status); 464 } 465 466 registerMediaPort(tonegen); 467 } 468 469 bool ToneGenerator::isBusy() const 470 { 471 return tonegen && pjmedia_tonegen_is_busy(tonegen) != 0; 472 } 473 474 void ToneGenerator::stop() throw(Error) 475 { 476 pj_status_t status; 477 478 if (!tonegen) { 479 PJSUA2_RAISE_ERROR(PJ_EINVALIDOP); 480 } 481 482 status = pjmedia_tonegen_stop(tonegen); 483 PJSUA2_CHECK_RAISE_ERROR2(status, "ToneGenerator::stop()"); 484 } 485 486 void ToneGenerator::rewind() throw(Error) 487 { 488 pj_status_t status; 489 490 if (!tonegen) { 491 PJSUA2_RAISE_ERROR(PJ_EINVALIDOP); 492 } 493 494 status = pjmedia_tonegen_rewind(tonegen); 495 PJSUA2_CHECK_RAISE_ERROR2(status, "ToneGenerator::rewind()"); 496 } 497 498 void ToneGenerator::play(const ToneDescVector &tones, 499 bool loop) throw(Error) 500 { 501 pj_status_t status; 502 503 if (!tonegen) { 504 PJSUA2_RAISE_ERROR(PJ_EINVALIDOP); 505 } 506 if (tones.size() == 0) { 507 PJSUA2_RAISE_ERROR(PJ_EINVAL); 508 } 509 510 status = pjmedia_tonegen_play(tonegen, tones.size(), &tones[0], 511 loop? PJMEDIA_TONEGEN_LOOP : 0); 512 PJSUA2_CHECK_RAISE_ERROR2(status, "ToneGenerator::play()"); 513 } 514 515 void ToneGenerator::playDigits(const ToneDigitVector &digits, 516 bool loop) throw(Error) 517 { 518 pj_status_t status; 519 520 if (!tonegen) { 521 PJSUA2_RAISE_ERROR(PJ_EINVALIDOP); 522 } 523 if (digits.size() == 0) { 524 PJSUA2_RAISE_ERROR(PJ_EINVAL); 525 } 526 527 status = pjmedia_tonegen_play_digits(tonegen, digits.size(), &digits[0], 528 loop? PJMEDIA_TONEGEN_LOOP : 0); 529 PJSUA2_CHECK_RAISE_ERROR2(status, "ToneGenerator::playDigits()"); 530 } 531 532 ToneDigitMapVector ToneGenerator::getDigitMap() const throw(Error) 533 { 534 const pjmedia_tone_digit_map *pdm; 535 ToneDigitMapVector tdm; 536 unsigned i; 537 pj_status_t status; 538 539 if (!tonegen) { 540 PJSUA2_RAISE_ERROR(PJ_EINVALIDOP); 541 } 542 543 status = pjmedia_tonegen_get_digit_map(tonegen, &pdm); 544 PJSUA2_CHECK_RAISE_ERROR2(status, "ToneGenerator::getDigitMap()"); 545 546 for (i=0; i<pdm->count; ++i) { 547 ToneDigitMapDigit d; 548 char str_digit[2]; 549 550 str_digit[0] = pdm->digits[i].digit; 551 str_digit[1] = '\0'; 552 553 d.digit = str_digit; 554 d.freq1 = pdm->digits[i].freq1; 555 d.freq2 = pdm->digits[i].freq2; 556 557 tdm.push_back(d); 558 } 559 560 return tdm; 561 } 562 563 void ToneGenerator::setDigitMap(const ToneDigitMapVector &digit_map) 564 throw(Error) 565 { 566 unsigned i; 567 pj_status_t status; 568 569 if (!tonegen) { 570 PJSUA2_RAISE_ERROR(PJ_EINVALIDOP); 571 } 572 573 digitMap.count = digit_map.size(); 574 if (digitMap.count > PJ_ARRAY_SIZE(digitMap.digits)) 575 digitMap.count = PJ_ARRAY_SIZE(digitMap.digits); 576 577 for (i=0; i<digitMap.count; ++i) { 578 digitMap.digits[i].digit = digit_map[i].digit.c_str()[0]; 579 digitMap.digits[i].freq1 = digit_map[i].freq1; 580 digitMap.digits[i].freq2 = digit_map[i].freq2; 581 } 582 583 status = pjmedia_tonegen_set_digit_map(tonegen, &digitMap); 584 PJSUA2_CHECK_RAISE_ERROR2(status, "ToneGenerator::setDigitMap()"); 585 } 586 587 588 /////////////////////////////////////////////////////////////////////////////// 426 589 void AudioDevInfo::fromPj(const pjmedia_aud_dev_info &dev_info) 427 590 {
Note: See TracChangeset
for help on using the changeset viewer.