Changeset 863 for pjproject/trunk/pjmedia/src/pjmedia/stream.c
- Timestamp:
- Dec 26, 2006 12:11:48 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/stream.c
r846 r863 114 114 unsigned rx_dtmf_count; /**< # of digits in dtmf rx buf.*/ 115 115 char rx_dtmf_buf[32];/**< Incoming DTMF buffer. */ 116 117 /* DTMF callback */ 118 void (*dtmf_cb)(pjmedia_stream*, void*, int); 119 void *dtmf_cb_user_data; 116 120 }; 117 121 … … 380 384 pj_mutex_unlock(stream->jb_mutex); 381 385 382 if (stream->tx_dtmf_count) 386 if (stream->tx_dtmf_count) { 383 387 PJ_LOG(5,(stream->port.info.name.ptr, 384 388 "Sending DTMF digit id %c", 385 389 digitmap[stream->tx_dtmf_buf[0].event])); 390 } 386 391 387 392 } else if (duration == 0) { … … 664 669 stream->last_dtmf_dur = pj_ntohs(event->duration); 665 670 666 /* By convention, we use jitter buffer's mutex to access shared667 * DTMF variables.671 /* If DTMF callback is installed, call the callback, otherwise keep 672 * the DTMF digits in the buffer. 668 673 */ 669 pj_mutex_lock(stream->jb_mutex); 670 if (stream->rx_dtmf_count >= PJ_ARRAY_SIZE(stream->rx_dtmf_buf)) { 671 /* DTMF digits overflow. Discard the oldest digit. */ 672 pj_array_erase(stream->rx_dtmf_buf, sizeof(stream->rx_dtmf_buf[0]), 673 stream->rx_dtmf_count, 0); 674 --stream->rx_dtmf_count; 675 } 676 stream->rx_dtmf_buf[stream->rx_dtmf_count++] = digitmap[event->event]; 677 pj_mutex_unlock(stream->jb_mutex); 674 if (stream->dtmf_cb) { 675 676 stream->dtmf_cb(stream, stream->dtmf_cb_user_data, 677 digitmap[event->event]); 678 679 } else { 680 /* By convention, we use jitter buffer's mutex to access shared 681 * DTMF variables. 682 */ 683 pj_mutex_lock(stream->jb_mutex); 684 if (stream->rx_dtmf_count >= PJ_ARRAY_SIZE(stream->rx_dtmf_buf)) { 685 /* DTMF digits overflow. Discard the oldest digit. */ 686 pj_array_erase(stream->rx_dtmf_buf, 687 sizeof(stream->rx_dtmf_buf[0]), 688 stream->rx_dtmf_count, 0); 689 --stream->rx_dtmf_count; 690 } 691 stream->rx_dtmf_buf[stream->rx_dtmf_count++] = digitmap[event->event]; 692 pj_mutex_unlock(stream->jb_mutex); 693 } 678 694 } 679 695 … … 1369 1385 return PJ_SUCCESS; 1370 1386 } 1387 1388 1389 /* 1390 * Set callback to be called upon receiving DTMF digits. 1391 */ 1392 PJ_DEF(pj_status_t) 1393 pjmedia_stream_set_dtmf_callback(pjmedia_stream *stream, 1394 void (*cb)(pjmedia_stream*, 1395 void *user_data, 1396 int digit), 1397 void *user_data) 1398 { 1399 PJ_ASSERT_RETURN(stream, PJ_EINVAL); 1400 1401 /* By convention, we use jitter buffer's mutex to access DTMF 1402 * digits resources. 1403 */ 1404 pj_mutex_lock(stream->jb_mutex); 1405 1406 stream->dtmf_cb = cb; 1407 stream->dtmf_cb_user_data = user_data; 1408 1409 pj_mutex_unlock(stream->jb_mutex); 1410 1411 return PJ_SUCCESS; 1412 } 1413
Note: See TracChangeset
for help on using the changeset viewer.