Changeset 2021 for pjproject/trunk
- Timestamp:
- Jun 14, 2008 7:42:37 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
r2018 r2021 25 25 //#define STEREO_DEMO 26 26 27 /* Ringtones */ 28 #define RINGBACK_FREQ1 440 29 #define RINGBACK_FREQ2 480 30 #define RINGBACK_ON 2000 31 #define RINGBACK_OFF 4000 32 33 #define RING_FREQ1 500 34 #define RING_FREQ2 660 35 #define RING_ON 100 36 #define RING_OFF 100 37 #define RING_INTERVAL 4000 38 39 27 40 /* Call specific data */ 28 41 struct call_data 29 42 { 30 43 pj_timer_entry timer; 44 pj_bool_t ringback_on; 45 pj_bool_t ring_on; 31 46 }; 32 47 … … 87 102 int capture_dev, playback_dev; 88 103 unsigned capture_lat, playback_lat; 104 105 pj_bool_t no_tones; 106 int ringback_slot; 107 int ringback_cnt; 108 pjmedia_port *ringback_port; 109 int ring_slot; 110 int ring_cnt; 111 pjmedia_port *ring_port; 112 89 113 } app_config; 90 114 … … 105 129 #endif 106 130 pj_status_t app_destroy(void); 131 132 static void ringback_start(pjsua_call_id call_id); 133 static void ring_start(pjsua_call_id call_id); 134 static void ring_stop(pjsua_call_id call_id); 135 107 136 108 137 /***************************************************************************** … … 205 234 puts (" Specify N=-1 (default) to disable this feature."); 206 235 puts (" Specify N=0 for instant close when unused."); 236 puts (" --no-tones Disable audible tones"); 207 237 208 238 puts (""); … … 265 295 cfg->capture_lat = PJMEDIA_SND_DEFAULT_REC_LATENCY; 266 296 cfg->playback_lat = PJMEDIA_SND_DEFAULT_PLAY_LATENCY; 297 cfg->ringback_slot = PJSUA_INVALID_ID; 298 cfg->ring_slot = PJSUA_INVALID_ID; 267 299 268 300 for (i=0; i<PJ_ARRAY_SIZE(cfg->acc_cfg); ++i) … … 426 458 OPT_TLS_NEG_TIMEOUT, 427 459 OPT_CAPTURE_DEV, OPT_PLAYBACK_DEV, 428 OPT_CAPTURE_LAT, OPT_PLAYBACK_LAT, 460 OPT_CAPTURE_LAT, OPT_PLAYBACK_LAT, OPT_NO_TONES, 429 461 OPT_STDOUT_REFRESH, OPT_STDOUT_REFRESH_TEXT, 430 462 OPT_AUTO_UPDATE_NAT,OPT_USE_COMPACT_FORM,OPT_DIS_CODEC … … 519 551 { "stdout-refresh-text", 1, 0, OPT_STDOUT_REFRESH_TEXT}, 520 552 { "snd-auto-close", 1, 0, OPT_SND_AUTO_CLOSE}, 553 { "no-tones", 0, 0, OPT_NO_TONES}, 521 554 { NULL, 0, 0, 0} 522 555 }; … … 1115 1148 case OPT_SND_AUTO_CLOSE: 1116 1149 cfg->media_cfg.snd_auto_close_time = atoi(pj_optarg); 1150 break; 1151 1152 case OPT_NO_TONES: 1153 cfg->no_tones = PJ_TRUE; 1117 1154 break; 1118 1155 … … 1518 1555 pj_strcat2(&cfg, line); 1519 1556 } 1557 if (config->no_tones) { 1558 pj_strcat2(&cfg, "--no-tones\n"); 1559 } 1520 1560 1521 1561 /* Sound device latency */ … … 1694 1734 */ 1695 1735 1736 static void ringback_start(pjsua_call_id call_id) 1737 { 1738 if (app_config.no_tones) 1739 return; 1740 1741 if (app_config.call_data[call_id].ringback_on) 1742 return; 1743 1744 app_config.call_data[call_id].ringback_on = PJ_TRUE; 1745 1746 if (++app_config.ringback_cnt==1 && 1747 app_config.ringback_slot!=PJSUA_INVALID_ID) 1748 { 1749 pjmedia_tone_desc tone; 1750 1751 pj_bzero(&tone, sizeof(tone)); 1752 tone.freq1 = RINGBACK_FREQ1; 1753 tone.freq2 = RINGBACK_FREQ2; 1754 tone.on_msec = RINGBACK_ON; 1755 tone.off_msec = RINGBACK_OFF; 1756 pjmedia_tonegen_play(app_config.ringback_port, 1, &tone, 1757 PJMEDIA_TONEGEN_LOOP); 1758 1759 pjsua_conf_connect(app_config.ringback_slot, 0); 1760 } 1761 } 1762 1763 static void ring_stop(pjsua_call_id call_id) 1764 { 1765 if (app_config.no_tones) 1766 return; 1767 1768 if (app_config.call_data[call_id].ringback_on) { 1769 app_config.call_data[call_id].ringback_on = PJ_FALSE; 1770 1771 pj_assert(app_config.ringback_cnt>0); 1772 if (--app_config.ringback_cnt == 0 && 1773 app_config.ringback_slot!=PJSUA_INVALID_ID) 1774 { 1775 pjsua_conf_disconnect(app_config.ringback_slot, 0); 1776 pjmedia_tonegen_stop(app_config.ringback_port); 1777 } 1778 } 1779 1780 if (app_config.call_data[call_id].ring_on) { 1781 app_config.call_data[call_id].ring_on = PJ_FALSE; 1782 1783 pj_assert(app_config.ring_cnt>0); 1784 if (--app_config.ring_cnt == 0 && 1785 app_config.ring_slot!=PJSUA_INVALID_ID) 1786 { 1787 pjsua_conf_disconnect(app_config.ring_slot, 0); 1788 pjmedia_tonegen_stop(app_config.ring_port); 1789 } 1790 } 1791 } 1792 1793 static void ring_start(pjsua_call_id call_id) 1794 { 1795 if (app_config.no_tones) 1796 return; 1797 1798 if (app_config.call_data[call_id].ring_on) 1799 return; 1800 1801 app_config.call_data[call_id].ring_on = PJ_TRUE; 1802 1803 if (++app_config.ring_cnt==1 && 1804 app_config.ring_slot!=PJSUA_INVALID_ID) 1805 { 1806 unsigned i; 1807 pjmedia_tone_desc tone[3]; 1808 1809 pj_bzero(&tone, sizeof(tone)); 1810 for (i=0; i<PJ_ARRAY_SIZE(tone); ++i) { 1811 tone[i].freq1 = RING_FREQ1; 1812 tone[i].freq2 = RING_FREQ2; 1813 tone[i].on_msec = RING_ON; 1814 tone[i].off_msec = RING_OFF; 1815 } 1816 tone[PJ_ARRAY_SIZE(tone)-1].off_msec = RING_INTERVAL; 1817 1818 pjmedia_tonegen_play(app_config.ring_port, PJ_ARRAY_SIZE(tone), 1819 tone, PJMEDIA_TONEGEN_LOOP); 1820 1821 pjsua_conf_connect(app_config.ring_slot, 0); 1822 } 1823 } 1824 1696 1825 /* 1697 1826 * Find next call when current call is disconnected or when user … … 1794 1923 1795 1924 if (call_info.state == PJSIP_INV_STATE_DISCONNECTED) { 1925 1926 /* Stop all ringback for this call */ 1927 ring_stop(call_id); 1796 1928 1797 1929 /* Cancel duration timer, if any */ … … 1855 1987 reason = msg->line.status.reason; 1856 1988 1989 /* Start ringback for 180 for UAC unless there's SDP in 180 */ 1990 if (call_info.role==PJSIP_ROLE_UAC && code==180 && 1991 msg->body == NULL && 1992 call_info.media_status==PJSUA_CALL_MEDIA_NONE) 1993 { 1994 ringback_start(call_id); 1995 } 1996 1857 1997 PJ_LOG(3,(THIS_FILE, "Call %d state changed to %s (%d %.*s)", 1858 1998 call_id, call_info.state_text.ptr, … … 1883 2023 1884 2024 pjsua_call_get_info(call_id, &call_info); 2025 2026 /* Start ringback */ 2027 ring_start(call_id); 1885 2028 1886 2029 if (app_config.auto_answer > 0) { … … 1977 2120 1978 2121 pjsua_call_get_info(call_id, &call_info); 2122 2123 /* Stop ringback */ 2124 ring_stop(call_id); 1979 2125 1980 2126 if (call_info.media_status == PJSUA_CALL_MEDIA_ACTIVE) { … … 3688 3834 pj_memcpy(&tcp_cfg, &app_config.udp_cfg, sizeof(tcp_cfg)); 3689 3835 3836 /* Create ringback tones */ 3837 if (app_config.no_tones == PJ_FALSE) { 3838 pj_str_t name; 3839 3840 /* Ringback tone (call is ringing) */ 3841 name = pj_str("ringback"); 3842 status = pjmedia_tonegen_create2(app_config.pool, &name, 8000, 1, 160, 3843 16, PJMEDIA_TONEGEN_LOOP, 3844 &app_config.ringback_port); 3845 if (status != PJ_SUCCESS) 3846 goto on_error; 3847 3848 status = pjsua_conf_add_port(app_config.pool, app_config.ringback_port, 3849 &app_config.ringback_slot); 3850 if (status != PJ_SUCCESS) 3851 goto on_error; 3852 3853 /* Ring (to alert incoming call) */ 3854 name = pj_str("ring"); 3855 status = pjmedia_tonegen_create2(app_config.pool, &name, 8000, 1, 160, 3856 16, PJMEDIA_TONEGEN_LOOP, 3857 &app_config.ring_port); 3858 if (status != PJ_SUCCESS) 3859 goto on_error; 3860 3861 status = pjsua_conf_add_port(app_config.pool, app_config.ring_port, 3862 &app_config.ring_slot); 3863 if (status != PJ_SUCCESS) 3864 goto on_error; 3865 3866 } 3867 3690 3868 /* Add UDP transport unless it's disabled. */ 3691 3869 if (!app_config.no_udp) { … … 3876 4054 } 3877 4055 #endif 4056 4057 /* Close ringback port */ 4058 if (app_config.ringback_port && 4059 app_config.ringback_slot != PJSUA_INVALID_ID) 4060 { 4061 pjsua_conf_remove_port(app_config.ringback_slot); 4062 app_config.ringback_slot = PJSUA_INVALID_ID; 4063 pjmedia_port_destroy(app_config.ringback_port); 4064 app_config.ringback_port = NULL; 4065 } 4066 4067 /* Close ring port */ 4068 if (app_config.ring_port && app_config.ring_slot != PJSUA_INVALID_ID) { 4069 pjsua_conf_remove_port(app_config.ring_slot); 4070 app_config.ring_slot = PJSUA_INVALID_ID; 4071 pjmedia_port_destroy(app_config.ring_port); 4072 app_config.ring_port = NULL; 4073 } 3878 4074 3879 4075 /* Close tone generators */
Note: See TracChangeset
for help on using the changeset viewer.