Changeset 4338 for pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_media.c
- Timestamp:
- Jan 30, 2013 4:04:23 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/1.x/pjsip/src/pjsua-lib/pjsua_media.c
r4337 r4338 1710 1710 1711 1711 1712 static pj_status_t audio_channel_update(pjsua_call_id call_id, 1713 int prev_media_st, 1714 pjmedia_session_info *sess_info, 1715 const pjmedia_sdp_session *local_sdp, 1716 const pjmedia_sdp_session *remote_sdp) 1717 { 1718 pjsua_call *call = &pjsua_var.calls[call_id]; 1719 pjmedia_stream_info *si = &sess_info->stream_info[0]; 1720 pjmedia_port *media_port; 1721 pj_status_t status; 1722 1723 /* Optionally, application may modify other stream settings here 1724 * (such as jitter buffer parameters, codec ptime, etc.) 1725 */ 1726 si->jb_init = pjsua_var.media_cfg.jb_init; 1727 si->jb_min_pre = pjsua_var.media_cfg.jb_min_pre; 1728 si->jb_max_pre = pjsua_var.media_cfg.jb_max_pre; 1729 si->jb_max = pjsua_var.media_cfg.jb_max; 1730 1731 /* Set SSRC */ 1732 si->ssrc = call->ssrc; 1733 1734 /* Set RTP timestamp & sequence, normally these value are intialized 1735 * automatically when stream session created, but for some cases (e.g: 1736 * call reinvite, call update) timestamp and sequence need to be kept 1737 * contigue. 1738 */ 1739 si->rtp_ts = call->rtp_tx_ts; 1740 si->rtp_seq = call->rtp_tx_seq; 1741 si->rtp_seq_ts_set = call->rtp_tx_seq_ts_set; 1742 1743 #if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0 1744 /* Enable/disable stream keep-alive and NAT hole punch. */ 1745 si->use_ka = pjsua_var.acc[call->acc_id].cfg.use_stream_ka; 1746 #endif 1747 1748 /* Create session based on session info. */ 1749 status = pjmedia_session_create( pjsua_var.med_endpt, sess_info, 1750 &call->med_tp, 1751 call, &call->session ); 1752 if (status != PJ_SUCCESS) { 1753 return status; 1754 } 1755 1756 if (prev_media_st == PJSUA_CALL_MEDIA_NONE) 1757 pjmedia_session_send_rtcp_sdes(call->session); 1758 1759 /* If DTMF callback is installed by application, install our 1760 * callback to the session. 1761 */ 1762 if (pjsua_var.ua_cfg.cb.on_dtmf_digit) { 1763 pjmedia_session_set_dtmf_callback(call->session, 0, 1764 &dtmf_callback, 1765 (void*)(long)(call->index)); 1766 } 1767 1768 /* Get the port interface of the first stream in the session. 1769 * We need the port interface to add to the conference bridge. 1770 */ 1771 pjmedia_session_get_port(call->session, 0, &media_port); 1772 1773 /* Notify application about stream creation. 1774 * Note: application may modify media_port to point to different 1775 * media port 1776 */ 1777 if (pjsua_var.ua_cfg.cb.on_stream_created) { 1778 pjsua_var.ua_cfg.cb.on_stream_created(call_id, call->session, 1779 0, &media_port); 1780 } 1781 1782 /* 1783 * Add the call to conference bridge. 1784 */ 1785 { 1786 char tmp[PJSIP_MAX_URL_SIZE]; 1787 pj_str_t port_name; 1788 1789 port_name.ptr = tmp; 1790 port_name.slen = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, 1791 call->inv->dlg->remote.info->uri, 1792 tmp, sizeof(tmp)); 1793 if (port_name.slen < 1) { 1794 port_name = pj_str("call"); 1795 } 1796 status = pjmedia_conf_add_port( pjsua_var.mconf, 1797 call->inv->pool, 1798 media_port, 1799 &port_name, 1800 (unsigned*)&call->conf_slot); 1801 if (status != PJ_SUCCESS) { 1802 return status; 1803 } 1804 } 1805 1806 return PJ_SUCCESS; 1807 } 1808 1809 1712 1810 /* Internal function: update media channel after SDP negotiation. 1713 1811 * Warning: do not use temporary/flip-flop pool, e.g: inv->pool_prov, … … 1721 1819 { 1722 1820 unsigned i; 1723 int prev_media_st = 0;1821 int prev_media_st; 1724 1822 pjsua_call *call = &pjsua_var.calls[call_id]; 1725 1823 pjmedia_session_info sess_info; 1726 1824 pjmedia_stream_info *si = NULL; 1727 pjmedia_port *media_port;1728 1825 pj_status_t status; 1826 pj_bool_t media_changed = PJ_FALSE; 1729 1827 int audio_idx; 1730 1828 … … 1758 1856 audio_idx = find_audio_index(local_sdp, PJ_TRUE); 1759 1857 1858 /* Get previous media status */ 1859 prev_media_st = call->media_st; 1860 1760 1861 /* Check if media has just been changed. */ 1761 if ( !pjsua_var.media_cfg.no_smart_media_update &&1762 !is_media_changed(call, audio_idx, &sess_info))1862 if (pjsua_var.media_cfg.no_smart_media_update || 1863 is_media_changed(call, audio_idx, &sess_info)) 1763 1864 { 1865 media_changed = PJ_TRUE; 1866 1867 /* Destroy existing media session, if any. */ 1868 stop_media_session(call->index); 1869 } else { 1764 1870 PJ_LOG(4,(THIS_FILE, "Media session for call %d is unchanged", 1765 1871 call_id)); 1766 return PJ_SUCCESS; 1767 } 1768 1769 /* Destroy existing media session, if any. */ 1770 prev_media_st = call->media_st; 1771 stop_media_session(call->index); 1872 } 1873 1772 1874 1773 1875 for (i = 0; i < sess_info.stream_cnt; ++i) { … … 1847 1949 } 1848 1950 1849 1850 /* Optionally, application may modify other stream settings here 1851 * (such as jitter buffer parameters, codec ptime, etc.) 1852 */ 1853 si->jb_init = pjsua_var.media_cfg.jb_init; 1854 si->jb_min_pre = pjsua_var.media_cfg.jb_min_pre; 1855 si->jb_max_pre = pjsua_var.media_cfg.jb_max_pre; 1856 si->jb_max = pjsua_var.media_cfg.jb_max; 1857 1858 /* Set SSRC */ 1859 si->ssrc = call->ssrc; 1860 1861 /* Set RTP timestamp & sequence, normally these value are intialized 1862 * automatically when stream session created, but for some cases (e.g: 1863 * call reinvite, call update) timestamp and sequence need to be kept 1864 * contigue. 1865 */ 1866 si->rtp_ts = call->rtp_tx_ts; 1867 si->rtp_seq = call->rtp_tx_seq; 1868 si->rtp_seq_ts_set = call->rtp_tx_seq_ts_set; 1869 1870 #if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0 1871 /* Enable/disable stream keep-alive and NAT hole punch. */ 1872 si->use_ka = pjsua_var.acc[call->acc_id].cfg.use_stream_ka; 1873 #endif 1874 1875 /* Create session based on session info. */ 1876 status = pjmedia_session_create( pjsua_var.med_endpt, &sess_info, 1877 &call->med_tp, 1878 call, &call->session ); 1879 if (status != PJ_SUCCESS) { 1880 return status; 1881 } 1882 1883 if (prev_media_st == PJSUA_CALL_MEDIA_NONE) 1884 pjmedia_session_send_rtcp_sdes(call->session); 1885 1886 /* If DTMF callback is installed by application, install our 1887 * callback to the session. 1888 */ 1889 if (pjsua_var.ua_cfg.cb.on_dtmf_digit) { 1890 pjmedia_session_set_dtmf_callback(call->session, 0, 1891 &dtmf_callback, 1892 (void*)(long)(call->index)); 1893 } 1894 1895 /* Get the port interface of the first stream in the session. 1896 * We need the port interface to add to the conference bridge. 1897 */ 1898 pjmedia_session_get_port(call->session, 0, &media_port); 1899 1900 /* Notify application about stream creation. 1901 * Note: application may modify media_port to point to different 1902 * media port 1903 */ 1904 if (pjsua_var.ua_cfg.cb.on_stream_created) { 1905 pjsua_var.ua_cfg.cb.on_stream_created(call_id, call->session, 1906 0, &media_port); 1907 } 1908 1909 /* 1910 * Add the call to conference bridge. 1911 */ 1912 { 1913 char tmp[PJSIP_MAX_URL_SIZE]; 1914 pj_str_t port_name; 1915 1916 port_name.ptr = tmp; 1917 port_name.slen = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, 1918 call->inv->dlg->remote.info->uri, 1919 tmp, sizeof(tmp)); 1920 if (port_name.slen < 1) { 1921 port_name = pj_str("call"); 1922 } 1923 status = pjmedia_conf_add_port( pjsua_var.mconf, 1924 call->inv->pool, 1925 media_port, 1926 &port_name, 1927 (unsigned*)&call->conf_slot); 1928 if (status != PJ_SUCCESS) { 1951 if (media_changed) { 1952 status = audio_channel_update(call_id, prev_media_st, &sess_info, 1953 local_sdp, remote_sdp); 1954 if (status != PJ_SUCCESS) 1929 1955 return status; 1930 }1931 1956 } 1932 1957
Note: See TracChangeset
for help on using the changeset viewer.