Changeset 1676
- Timestamp:
- Jan 11, 2008 8:22:57 AM (17 years ago)
- Location:
- pjproject/trunk/pjmedia
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/include/pjmedia/tonegen.h
r974 r1676 108 108 * the last tone has been played. 109 109 */ 110 PJMEDIA_TONEGEN_LOOP = 1 110 PJMEDIA_TONEGEN_LOOP = 1, 111 112 /** 113 * Disable mutex protection to the tone generator. 114 */ 115 PJMEDIA_TONEGEN_NO_LOCK = 2 111 116 }; 112 117 -
pjproject/trunk/pjmedia/src/pjmedia/tonegen.c
r1266 r1676 19 19 #include <pjmedia/tonegen.h> 20 20 #include <pjmedia/errno.h> 21 #include <pjmedia/silencedet.h> 21 22 #include <pj/assert.h> 22 23 #include <pj/ctype.h> 24 #include <pj/lock.h> 25 #include <pj/log.h> 23 26 #include <pj/pool.h> 24 27 … … 229 232 230 233 #define SIGNATURE PJMEDIA_PORT_SIGNATURE('t', 'n', 'g', 'n') 234 #define THIS_FILE "tonegen.c" 235 236 #if 0 237 # define TRACE_(expr) PJ_LOG(4,expr) 238 #else 239 # define TRACE_(expr) 240 #endif 231 241 232 242 struct tonegen … … 237 247 unsigned options; 238 248 unsigned playback_options; 249 250 /* lock */ 251 pj_lock_t *lock; 239 252 240 253 /* Digit map */ … … 279 292 static pj_status_t tonegen_get_frame(pjmedia_port *this_port, 280 293 pjmedia_frame *frame); 294 static pj_status_t tonegen_destroy(pjmedia_port *this_port); 281 295 282 296 /* … … 294 308 pjmedia_port **p_port) 295 309 { 296 const pj_str_t STR_TONE_GEN = pj_str("tone -gen");310 const pj_str_t STR_TONE_GEN = pj_str("tonegen"); 297 311 struct tonegen *tonegen; 298 312 pj_status_t status; … … 316 330 tonegen->options = options; 317 331 tonegen->base.get_frame = &tonegen_get_frame; 332 tonegen->base.on_destroy = &tonegen_destroy; 318 333 tonegen->digit_map = &digit_map; 334 335 /* Lock */ 336 if (options & PJMEDIA_TONEGEN_NO_LOCK) { 337 status = pj_lock_create_null_mutex(pool, "tonegen", &tonegen->lock); 338 } else { 339 status = pj_lock_create_simple_mutex(pool, "tonegen", &tonegen->lock); 340 } 341 342 if (status != PJ_SUCCESS) { 343 return status; 344 } 345 346 TRACE_((THIS_FILE, "Tonegen created: %u/%u/%u/%u", clock_rate, 347 channel_count, samples_per_frame, bits_per_sample)); 319 348 320 349 /* Done */ … … 356 385 struct tonegen *tonegen = (struct tonegen*) port; 357 386 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVAL); 387 388 TRACE_((THIS_FILE, "tonegen_stop()")); 389 390 pj_lock_acquire(tonegen->lock); 358 391 tonegen->count = 0; 359 392 tonegen->cur_digit = 0; 360 393 tonegen->dig_samples = 0; 394 pj_lock_release(tonegen->lock); 395 361 396 return PJ_SUCCESS; 362 397 } 363 398 399 400 /* 401 * Callback to destroy tonegen 402 */ 403 static pj_status_t tonegen_destroy(pjmedia_port *port) 404 { 405 struct tonegen *tonegen = (struct tonegen*) port; 406 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVAL); 407 408 TRACE_((THIS_FILE, "tonegen_destroy()")); 409 410 pj_lock_acquire(tonegen->lock); 411 pj_lock_release(tonegen->lock); 412 413 pj_lock_destroy(tonegen->lock); 414 415 return PJ_SUCCESS; 416 } 364 417 365 418 /* … … 375 428 PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVAL); 376 429 430 pj_lock_acquire(tonegen->lock); 431 377 432 if (tonegen->count == 0) { 378 433 /* We don't have digits to play */ 379 434 frame->type = PJMEDIA_FRAME_TYPE_NONE; 380 return PJ_SUCCESS;435 goto on_return; 381 436 } 382 437 … … 389 444 tonegen->dig_samples = 0; 390 445 446 TRACE_((THIS_FILE, "tonegen_get_frame(): rewind")); 447 391 448 } else { 392 449 tonegen->count = 0; 450 tonegen->cur_digit = 0; 393 451 frame->type = PJMEDIA_FRAME_TYPE_NONE; 394 return PJ_SUCCESS; 452 TRACE_((THIS_FILE, "tonegen_get_frame(): no more digit")); 453 goto on_return; 395 454 } 396 455 } … … 403 462 tonegen->cur_digit++; 404 463 tonegen->dig_samples = 0; 464 465 TRACE_((THIS_FILE, "tonegen_get_frame(): next digit")); 405 466 } 406 467 … … 415 476 tonegen->dig_samples = 0; 416 477 478 TRACE_((THIS_FILE, "tonegen_get_frame(): rewind")); 479 417 480 } else { 418 481 tonegen->count = 0; 482 tonegen->cur_digit = 0; 419 483 frame->type = PJMEDIA_FRAME_TYPE_NONE; 420 return PJ_SUCCESS; 484 TRACE_((THIS_FILE, "tonegen_get_frame(): no more digit")); 485 goto on_return; 421 486 } 422 487 } … … 463 528 464 529 /* Move to next digit if we're finished with this tone */ 465 if (tonegen->dig_samples == on_samp + off_samp) {530 if (tonegen->dig_samples >= on_samp + off_samp) { 466 531 tonegen->cur_digit++; 467 532 tonegen->dig_samples = 0; … … 486 551 frame->size = port->info.bytes_per_frame; 487 552 553 TRACE_((THIS_FILE, "tonegen_get_frame(): frame created, level=%u", 554 pjmedia_calc_avg_signal((pj_int16_t*)frame->buf, frame->size/2))); 555 488 556 if (tonegen->cur_digit >= tonegen->count) { 489 557 if ((tonegen->options|tonegen->playback_options)&PJMEDIA_TONEGEN_LOOP) … … 493 561 tonegen->dig_samples = 0; 494 562 563 TRACE_((THIS_FILE, "tonegen_get_frame(): rewind")); 564 495 565 } else { 496 566 tonegen->count = 0; 497 } 498 } 499 567 tonegen->cur_digit = 0; 568 569 TRACE_((THIS_FILE, "tonegen_get_frame(): no more digit")); 570 } 571 } 572 573 on_return: 574 pj_lock_release(tonegen->lock); 500 575 return PJ_SUCCESS; 501 576 } … … 519 594 PJ_ASSERT_RETURN(count+tonegen->count <= PJMEDIA_TONEGEN_MAX_DIGITS, 520 595 PJ_ETOOMANY); 596 597 pj_lock_acquire(tonegen->lock); 521 598 522 599 /* Set playback options */ … … 538 615 tonegen->count += count; 539 616 617 pj_lock_release(tonegen->lock); 618 540 619 return PJ_SUCCESS; 541 620 } … … 552 631 struct tonegen *tonegen = (struct tonegen*) port; 553 632 pjmedia_tone_desc tones[PJMEDIA_TONEGEN_MAX_DIGITS]; 554 const pjmedia_tone_digit_map *map = tonegen->digit_map;633 const pjmedia_tone_digit_map *map; 555 634 unsigned i; 556 635 … … 558 637 count && digits, PJ_EINVAL); 559 638 PJ_ASSERT_RETURN(count < PJMEDIA_TONEGEN_MAX_DIGITS, PJ_ETOOMANY); 639 640 pj_lock_acquire(tonegen->lock); 641 642 map = tonegen->digit_map; 560 643 561 644 for (i=0; i<count; ++i) { … … 568 651 break; 569 652 } 570 if (j == map->count) 653 if (j == map->count) { 654 pj_lock_release(tonegen->lock); 571 655 return PJMEDIA_RTP_EINDTMF; 656 } 572 657 573 658 tones[i].freq1 = map->digits[j].freq1; … … 578 663 } 579 664 665 pj_lock_release(tonegen->lock); 666 580 667 return pjmedia_tonegen_play(port, count, tones, options); 581 668 } … … 610 697 PJ_ASSERT_RETURN(m != NULL, PJ_EINVAL); 611 698 699 pj_lock_acquire(tonegen->lock); 700 612 701 tonegen->digit_map = m; 613 702 703 pj_lock_release(tonegen->lock); 704 614 705 return PJ_SUCCESS; 615 706 }
Note: See TracChangeset
for help on using the changeset viewer.