- Timestamp:
- Mar 18, 2011 7:54:50 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/2.0-dev/pjsip/src/pjsua-lib/pjsua_media.c
r3457 r3463 1474 1474 maudcnt = acc->cfg.max_audio_cnt; 1475 1475 for (mi=0; mi<maudcnt; ++mi) { 1476 maudidx[mi] = mi;1476 maudidx[mi] = (pj_uint8_t)mi; 1477 1477 media_types[mi] = PJMEDIA_TYPE_AUDIO; 1478 1478 } … … 1836 1836 pjmedia_stream_destroy(strm); 1837 1837 call_med->strm.a.stream = NULL; 1838 1839 PJ_LOG(4,(THIS_FILE, "Media session call%02d:%d is destroyed",1840 call_id, mi));1841 1838 } 1842 } 1839 } else if (call_med->type == PJMEDIA_TYPE_VIDEO) { 1840 pjmedia_vid_stream *strm = call_med->strm.v.stream; 1841 1842 if (strm) { 1843 pjmedia_rtcp_stat stat; 1844 1845 if (call_med->strm.v.capturer) { 1846 pjmedia_vid_port_stop(call_med->strm.v.capturer); 1847 pjmedia_vid_port_destroy(call_med->strm.v.capturer); 1848 call_med->strm.v.capturer = NULL; 1849 } 1850 1851 if (call_med->strm.v.renderer) { 1852 pjmedia_vid_port_stop(call_med->strm.v.renderer); 1853 pjmedia_vid_port_destroy(call_med->strm.v.renderer); 1854 call_med->strm.v.renderer = NULL; 1855 } 1856 1857 if ((call_med->dir & PJMEDIA_DIR_ENCODING) && 1858 (pjmedia_vid_stream_get_stat(strm, &stat) == PJ_SUCCESS)) 1859 { 1860 /* Save RTP timestamp & sequence, so when media session is 1861 * restarted, those values will be restored as the initial 1862 * RTP timestamp & sequence of the new media session. So in 1863 * the same call session, RTP timestamp and sequence are 1864 * guaranteed to be contigue. 1865 */ 1866 call_med->rtp_tx_seq_ts_set = 1 | (1 << 1); 1867 call_med->rtp_tx_seq = stat.rtp_tx_last_seq; 1868 call_med->rtp_tx_ts = stat.rtp_tx_last_ts; 1869 } 1870 1871 pjmedia_vid_stream_destroy(strm); 1872 call_med->strm.v.stream = NULL; 1873 } 1874 } 1875 1876 PJ_LOG(4,(THIS_FILE, "Media session call%02d:%d is destroyed", 1877 call_id, mi)); 1843 1878 call_med->state = PJSUA_CALL_MEDIA_NONE; 1844 1879 } … … 2099 2134 } 2100 2135 2136 static pj_status_t video_channel_update(pjsua_call_media *call_med, 2137 pj_pool_t *tmp_pool, 2138 const pjmedia_sdp_session *local_sdp, 2139 const pjmedia_sdp_session *remote_sdp) 2140 { 2141 pjsua_call *call = call_med->call; 2142 pjmedia_vid_stream_info the_si, *si = &the_si; 2143 pjmedia_port *media_port; 2144 unsigned strm_idx = call_med->idx; 2145 pj_status_t status; 2146 2147 status = pjmedia_vid_stream_info_from_sdp(si, tmp_pool, pjsua_var.med_endpt, 2148 local_sdp, remote_sdp, strm_idx); 2149 if (status != PJ_SUCCESS) 2150 return status; 2151 2152 /* Check if no media is active */ 2153 if (si->dir == PJMEDIA_DIR_NONE) { 2154 /* Call media state */ 2155 call_med->state = PJSUA_CALL_MEDIA_NONE; 2156 2157 /* Call media direction */ 2158 call_med->dir = PJMEDIA_DIR_NONE; 2159 2160 } else { 2161 pjmedia_transport_info tp_info; 2162 2163 /* Start/restart media transport */ 2164 status = pjmedia_transport_media_start(call_med->tp, 2165 tmp_pool, local_sdp, 2166 remote_sdp, strm_idx); 2167 if (status != PJ_SUCCESS) 2168 return status; 2169 2170 call_med->tp_st = PJSUA_MED_TP_RUNNING; 2171 2172 /* Get remote SRTP usage policy */ 2173 pjmedia_transport_info_init(&tp_info); 2174 pjmedia_transport_get_info(call_med->tp, &tp_info); 2175 if (tp_info.specific_info_cnt > 0) { 2176 unsigned i; 2177 for (i = 0; i < tp_info.specific_info_cnt; ++i) { 2178 if (tp_info.spc_info[i].type == PJMEDIA_TRANSPORT_TYPE_SRTP) 2179 { 2180 pjmedia_srtp_info *srtp_info = 2181 (pjmedia_srtp_info*) tp_info.spc_info[i].buffer; 2182 2183 call_med->rem_srtp_use = srtp_info->peer_use; 2184 break; 2185 } 2186 } 2187 } 2188 2189 /* Optionally, application may modify other stream settings here 2190 * (such as jitter buffer parameters, codec ptime, etc.) 2191 */ 2192 si->jb_init = pjsua_var.media_cfg.jb_init; 2193 si->jb_min_pre = pjsua_var.media_cfg.jb_min_pre; 2194 si->jb_max_pre = pjsua_var.media_cfg.jb_max_pre; 2195 si->jb_max = pjsua_var.media_cfg.jb_max; 2196 2197 /* Set SSRC */ 2198 si->ssrc = call_med->ssrc; 2199 2200 /* Set RTP timestamp & sequence, normally these value are intialized 2201 * automatically when stream session created, but for some cases (e.g: 2202 * call reinvite, call update) timestamp and sequence need to be kept 2203 * contigue. 2204 */ 2205 si->rtp_ts = call_med->rtp_tx_ts; 2206 si->rtp_seq = call_med->rtp_tx_seq; 2207 si->rtp_seq_ts_set = call_med->rtp_tx_seq_ts_set; 2208 2209 #if defined(PJMEDIA_STREAM_ENABLE_KA) && PJMEDIA_STREAM_ENABLE_KA!=0 2210 /* Enable/disable stream keep-alive and NAT hole punch. */ 2211 si->use_ka = pjsua_var.acc[call->acc_id].cfg.use_stream_ka; 2212 #endif 2213 2214 /* Create session based on session info. */ 2215 status = pjmedia_vid_stream_create(pjsua_var.med_endpt, NULL, si, 2216 call_med->tp, NULL, 2217 &call_med->strm.v.stream); 2218 if (status != PJ_SUCCESS) 2219 return status; 2220 2221 /* Start stream */ 2222 status = pjmedia_vid_stream_start(call_med->strm.v.stream); 2223 if (status != PJ_SUCCESS) 2224 return status; 2225 2226 /* Setup decoding direction */ 2227 if (si->dir & PJMEDIA_DIR_DECODING) { 2228 pjmedia_vid_port_param vport_param; 2229 2230 status = pjmedia_vid_stream_get_port(call_med->strm.v.stream, 2231 PJMEDIA_DIR_DECODING, 2232 &media_port); 2233 if (status != PJ_SUCCESS) 2234 return status; 2235 2236 status = pjmedia_vid_dev_default_param( 2237 tmp_pool, PJMEDIA_VID_DEFAULT_RENDER_DEV, 2238 &vport_param.vidparam); 2239 if (status != PJ_SUCCESS) 2240 return status; 2241 2242 pjmedia_format_copy(&vport_param.vidparam.fmt, 2243 &media_port->info.fmt); 2244 2245 vport_param.vidparam.dir = PJMEDIA_DIR_RENDER; 2246 vport_param.active = PJ_TRUE; 2247 2248 /* Create video renderer */ 2249 status = pjmedia_vid_port_create(tmp_pool, &vport_param, 2250 &call_med->strm.v.renderer); 2251 if (status != PJ_SUCCESS) 2252 return status; 2253 2254 /* Connect the video renderer to media_port */ 2255 status = pjmedia_vid_port_connect(call_med->strm.v.renderer, 2256 media_port, PJ_FALSE); 2257 if (status != PJ_SUCCESS) 2258 return status; 2259 2260 /* Start the video renderer */ 2261 status = pjmedia_vid_port_start(call_med->strm.v.renderer); 2262 if (status != PJ_SUCCESS) 2263 return status; 2264 } 2265 2266 /* Setup encoding direction */ 2267 if (si->dir & PJMEDIA_DIR_ENCODING) { 2268 pjmedia_vid_port_param vport_param; 2269 2270 status = pjmedia_vid_stream_get_port(call_med->strm.v.stream, 2271 PJMEDIA_DIR_ENCODING, 2272 &media_port); 2273 if (status != PJ_SUCCESS) 2274 return status; 2275 2276 status = pjmedia_vid_dev_default_param( 2277 tmp_pool, PJMEDIA_VID_DEFAULT_CAPTURE_DEV, 2278 &vport_param.vidparam); 2279 if (status != PJ_SUCCESS) 2280 return status; 2281 2282 pjmedia_format_copy(&vport_param.vidparam.fmt, 2283 &media_port->info.fmt); 2284 2285 vport_param.vidparam.dir = PJMEDIA_DIR_CAPTURE; 2286 vport_param.active = PJ_TRUE; 2287 2288 /* Create video capturer */ 2289 status = pjmedia_vid_port_create(tmp_pool, &vport_param, 2290 &call_med->strm.v.capturer); 2291 if (status != PJ_SUCCESS) 2292 return status; 2293 2294 /* Connect the video capturer to media_port */ 2295 status = pjmedia_vid_port_connect(call_med->strm.v.capturer, 2296 media_port, PJ_FALSE); 2297 if (status != PJ_SUCCESS) 2298 return status; 2299 2300 /* Start the video capturer */ 2301 status = pjmedia_vid_port_start(call_med->strm.v.capturer); 2302 if (status != PJ_SUCCESS) 2303 return status; 2304 } 2305 2306 /* Call media direction */ 2307 call_med->dir = si->dir; 2308 2309 /* Call media state */ 2310 if (call->local_hold) 2311 call_med->state = PJSUA_CALL_MEDIA_LOCAL_HOLD; 2312 else if (call_med->dir == PJMEDIA_DIR_DECODING) 2313 call_med->state = PJSUA_CALL_MEDIA_REMOTE_HOLD; 2314 else 2315 call_med->state = PJSUA_CALL_MEDIA_ACTIVE; 2316 } 2317 2318 /* Print info. */ 2319 { 2320 char info[80]; 2321 int info_len = 0; 2322 int len; 2323 const char *dir; 2324 2325 switch (si->dir) { 2326 case PJMEDIA_DIR_NONE: 2327 dir = "inactive"; 2328 break; 2329 case PJMEDIA_DIR_ENCODING: 2330 dir = "sendonly"; 2331 break; 2332 case PJMEDIA_DIR_DECODING: 2333 dir = "recvonly"; 2334 break; 2335 case PJMEDIA_DIR_ENCODING_DECODING: 2336 dir = "sendrecv"; 2337 break; 2338 default: 2339 dir = "unknown"; 2340 break; 2341 } 2342 len = pj_ansi_sprintf( info+info_len, 2343 ", stream #%d: %.*s (%s)", strm_idx, 2344 (int)si->codec_info.encoding_name.slen, 2345 si->codec_info.encoding_name.ptr, 2346 dir); 2347 if (len > 0) 2348 info_len += len; 2349 PJ_LOG(4,(THIS_FILE,"Media updates%s", info)); 2350 } 2351 2352 return PJ_SUCCESS; 2353 } 2354 2355 2101 2356 pj_status_t pjsua_media_channel_update(pjsua_call_id call_id, 2102 2357 const pjmedia_sdp_session *local_sdp, … … 2106 2361 pj_pool_t *tmp_pool = call->inv->pool_prov; 2107 2362 unsigned mi; 2108 pj_status_t status ;2363 pj_status_t status = PJ_SUCCESS; 2109 2364 2110 2365 if (pjsua_get_state() != PJSUA_STATE_RUNNING) … … 2135 2390 local_sdp, remote_sdp); 2136 2391 if (call->audio_idx==-1 && status==PJ_SUCCESS && 2137 2392 call_med->strm.a.stream) 2138 2393 { 2139 2394 call->audio_idx = mi; … … 2141 2396 break; 2142 2397 case PJMEDIA_TYPE_VIDEO: 2143 PJ_LOG(4,(THIS_FILE, "-x-x-x-x- Updating video for stream %d", mi)); 2398 status = video_channel_update(call_med, tmp_pool, 2399 local_sdp, remote_sdp); 2144 2400 break; 2145 2401 default:
Note: See TracChangeset
for help on using the changeset viewer.