Changeset 5962 for pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
- Timestamp:
- Apr 1, 2019 7:28:24 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
r5961 r5962 250 250 { 251 251 pj_status_t status = PJ_SUCCESS; 252 pjsua_vid_win_id wid = vid_preview_get_win(id, PJ_FALSE);252 pjsua_vid_win_id wid; 253 253 254 PJSUA_LOCK(); 255 wid = vid_preview_get_win(id, PJ_FALSE); 254 256 if (wid != PJSUA_INVALID_ID) { 255 257 pjsua_vid_win *w; … … 260 262 261 263 status = pjmedia_vid_dev_stream_set_cap(cap_dev, cap, pval); 262 if (status != PJ_SUCCESS) 264 if (status != PJ_SUCCESS) { 265 PJSUA_UNLOCK(); 263 266 return status; 267 } 264 268 } else { 265 269 status = PJ_ENOTFOUND; 266 270 } 271 PJSUA_UNLOCK(); 267 272 268 273 if (keep) { … … 293 298 { 294 299 pj_status_t status = PJ_SUCCESS; 295 pjsua_vid_win_id wid = vid_preview_get_win(id, PJ_FALSE);300 pjsua_vid_win_id wid; 296 301 302 PJSUA_LOCK(); 303 wid = vid_preview_get_win(id, PJ_FALSE); 297 304 if (wid != PJSUA_INVALID_ID) { 298 305 pjsua_vid_win *w; … … 303 310 304 311 status = pjmedia_vid_dev_stream_get_cap(cap_dev, cap, pval); 312 313 PJSUA_UNLOCK(); 305 314 } else { 306 315 pjmedia_vid_dev_info info; 307 316 317 PJSUA_UNLOCK(); 318 308 319 status = pjmedia_vid_dev_get_info(id, &info); 309 320 if (status != PJ_SUCCESS) … … 535 546 pjsua_vid_win_id wid; 536 547 pjsua_vid_win *w; 537 548 pjsua_conf_port_id conf_id = PJSUA_INVALID_ID; 549 550 PJSUA_LOCK(); 538 551 wid = vid_preview_get_win(id, PJ_TRUE); 539 if (wid == PJSUA_INVALID_ID) 540 return PJSUA_INVALID_ID; 541 542 w = &pjsua_var.win[wid]; 543 return w->cap_slot; 544 } 545 546 547 PJ_DEF(void) pjsua_vid_win_reset(pjsua_vid_win_id wid) 552 if (wid != PJSUA_INVALID_ID) { 553 w = &pjsua_var.win[wid]; 554 conf_id = w->cap_slot; 555 } 556 PJSUA_UNLOCK(); 557 558 return conf_id; 559 } 560 561 562 void pjsua_vid_win_reset(pjsua_vid_win_id wid) 548 563 { 549 564 pjsua_vid_win *w = &pjsua_var.win[wid]; … … 896 911 } 897 912 913 static pj_status_t setup_vid_capture(pjsua_call_media *call_med) 914 { 915 pjsua_acc *acc_enc = &pjsua_var.acc[call_med->call->acc_id]; 916 pjmedia_port *media_port; 917 pjsua_vid_win *w; 918 pjsua_vid_win_id wid; 919 pj_bool_t just_created = PJ_FALSE; 920 pj_status_t status; 921 922 /* Retrieve stream encoding port */ 923 status = pjmedia_vid_stream_get_port(call_med->strm.v.stream, 924 PJMEDIA_DIR_ENCODING, 925 &media_port); 926 if (status != PJ_SUCCESS) 927 return status; 928 929 PJSUA_LOCK(); 930 931 /* Note: calling pjsua_vid_preview_get_win() even though 932 * create_vid_win() will automatically create the window 933 * if it doesn't exist, because create_vid_win() will modify 934 * existing window SHOW/HIDE value. 935 */ 936 wid = vid_preview_get_win(call_med->strm.v.cap_dev, PJ_FALSE); 937 if (wid == PJSUA_INVALID_ID) { 938 /* Create preview video window */ 939 status = create_vid_win(PJSUA_WND_TYPE_PREVIEW, 940 &media_port->info.fmt, 941 call_med->strm.v.rdr_dev, 942 call_med->strm.v.cap_dev, 943 PJSUA_HIDE_WINDOW, 944 acc_enc->cfg.vid_wnd_flags, 945 NULL, 946 &wid); 947 if (status != PJ_SUCCESS) 948 goto on_error; 949 950 just_created = PJ_TRUE; 951 } 952 953 w = &pjsua_var.win[wid]; 954 #if ENABLE_EVENT 955 pjmedia_event_subscribe(NULL, &call_media_on_event, 956 call_med, w->vp_cap); 957 #endif 958 959 /* Connect capturer to stream encoding (via conf) */ 960 status = pjsua_vid_conf_connect(w->cap_slot, 961 call_med->strm.v.strm_enc_slot, 962 NULL); 963 if (status != PJ_SUCCESS) 964 goto on_error; 965 966 /* Start capturer */ 967 if (just_created) { 968 status = pjmedia_vid_port_start(w->vp_cap); 969 if (status != PJ_SUCCESS) 970 goto on_error; 971 } 972 973 /* Done */ 974 inc_vid_win(wid); 975 call_med->strm.v.cap_win_id = wid; 976 977 PJSUA_UNLOCK(); 978 979 return PJ_SUCCESS; 980 981 on_error: 982 PJSUA_UNLOCK(); 983 return status; 984 } 985 898 986 /* Internal function: update video channel after SDP negotiation. 899 987 * Warning: do not use temporary/flip-flop pool, e.g: inv->pool_prov, … … 1021 1109 1022 1110 /* Create stream video window */ 1111 PJSUA_LOCK(); 1023 1112 status = create_vid_win(PJSUA_WND_TYPE_STREAM, 1024 1113 &media_port->info.fmt, … … 1031 1120 &wid); 1032 1121 if (status != PJ_SUCCESS) { 1122 PJSUA_UNLOCK(); 1033 1123 pj_log_pop_indent(); 1034 1124 goto on_error; … … 1052 1142 &call_med->strm.v.strm_dec_slot); 1053 1143 if (status != PJ_SUCCESS) { 1144 PJSUA_UNLOCK(); 1054 1145 pj_log_pop_indent(); 1055 1146 goto on_error; … … 1060 1151 w->rend_slot, NULL); 1061 1152 if (status != PJ_SUCCESS) { 1153 PJSUA_UNLOCK(); 1062 1154 pj_log_pop_indent(); 1063 1155 goto on_error; … … 1067 1159 status = pjmedia_vid_port_start(w->vp_rend); 1068 1160 if (status != PJ_SUCCESS) { 1161 PJSUA_UNLOCK(); 1069 1162 pj_log_pop_indent(); 1070 1163 goto on_error; … … 1074 1167 inc_vid_win(wid); 1075 1168 call_med->strm.v.rdr_win_id = wid; 1169 PJSUA_UNLOCK(); 1076 1170 pj_log_pop_indent(); 1077 1171 } 1078 1172 1079 1173 /* Setup encoding direction */ 1080 if (si->dir & PJMEDIA_DIR_ENCODING && !call->local_hold) 1081 { 1082 pjsua_acc *acc_enc = &pjsua_var.acc[call_med->call->acc_id]; 1083 pjsua_vid_win *w; 1084 pjsua_vid_win_id wid; 1085 pj_bool_t just_created = PJ_FALSE; 1086 1174 if (si->dir & PJMEDIA_DIR_ENCODING) { 1087 1175 PJ_LOG(4,(THIS_FILE, "Setting up TX..")); 1088 1176 pj_log_push_indent(); … … 1092 1180 PJMEDIA_DIR_ENCODING, 1093 1181 &media_port); 1094 if (status != PJ_SUCCESS) { 1095 pj_log_pop_indent(); 1182 if (status != PJ_SUCCESS) 1096 1183 goto on_error; 1097 } 1098 1099 /* Note: calling pjsua_vid_preview_get_win() even though 1100 * create_vid_win() will automatically create the window 1101 * if it doesn't exist, because create_vid_win() will modify 1102 * existing window SHOW/HIDE value. 1103 */ 1104 wid = vid_preview_get_win(call_med->strm.v.cap_dev, PJ_FALSE); 1105 if (wid == PJSUA_INVALID_ID) { 1106 /* Create preview video window */ 1107 status = create_vid_win(PJSUA_WND_TYPE_PREVIEW, 1108 &media_port->info.fmt, 1109 call_med->strm.v.rdr_dev, 1110 call_med->strm.v.cap_dev, 1111 PJSUA_HIDE_WINDOW, 1112 acc_enc->cfg.vid_wnd_flags, 1113 NULL, 1114 &wid); 1115 if (status != PJ_SUCCESS) { 1116 pj_log_pop_indent(); 1117 return status; 1118 } 1119 just_created = PJ_TRUE; 1120 } 1121 1122 w = &pjsua_var.win[wid]; 1123 #if ENABLE_EVENT 1124 pjmedia_event_subscribe(NULL, &call_media_on_event, 1125 call_med, w->vp_cap); 1126 #endif 1127 1184 1128 1185 /* Register stream encoding to conf, using tmp_pool should be fine 1129 1186 * as bridge will create its own pool (using tmp_pool factory). … … 1131 1188 status = pjsua_vid_conf_add_port(tmp_pool, media_port, NULL, 1132 1189 &call_med->strm.v.strm_enc_slot); 1133 if (status != PJ_SUCCESS) {1134 pj_log_pop_indent();1135 goto on_error;1136 }1137 1138 /* Connect capturer to stream encoding (via conf) */1139 status = pjsua_vid_conf_connect(w->cap_slot,1140 call_med->strm.v.strm_enc_slot,1141 NULL);1142 if (status != PJ_SUCCESS) {1143 pj_log_pop_indent();1144 goto on_error;1145 }1146 1147 /* Start capturer */1148 if (just_created && acc->cfg.vid_out_auto_transmit) {1149 status = pjmedia_vid_port_start(w->vp_cap);1150 if (status != PJ_SUCCESS) {1151 pj_log_pop_indent();1152 goto on_error;1153 }1154 w->cap_started = PJ_TRUE;1155 }1156 1157 /* Done */1158 inc_vid_win(wid);1159 call_med->strm.v.cap_win_id = wid;1160 pj_log_pop_indent();1161 1162 } else if (si->dir & PJMEDIA_DIR_ENCODING && call->local_hold) {1163 /* This is similar as above, but we are on local hold. So1164 * we just get the stream encoding port and add it to the1165 * video conference, in order for the stream to be able to1166 * keep sending keep-alive.1167 */1168 PJ_LOG(4,(THIS_FILE, "Setting up TX.."));1169 1170 status = pjmedia_vid_stream_get_port(call_med->strm.v.stream,1171 PJMEDIA_DIR_ENCODING,1172 &media_port);1173 1190 if (status != PJ_SUCCESS) 1174 1191 goto on_error; 1175 1192 1176 status = pjsua_vid_conf_add_port(tmp_pool, media_port, NULL, 1177 &call_med->strm.v.strm_enc_slot); 1178 if (status != PJ_SUCCESS) 1179 goto on_error; 1180 } 1181 1193 if (!call->local_hold && acc->cfg.vid_out_auto_transmit) { 1194 status = setup_vid_capture(call_med); 1195 if (status != PJ_SUCCESS) 1196 goto on_error; 1197 } 1198 1199 pj_log_pop_indent(); 1200 } 1182 1201 } 1183 1202 … … 1224 1243 pjmedia_vid_stream_send_rtcp_bye(strm); 1225 1244 1245 PJSUA_LOCK(); 1226 1246 if (call_med->strm.v.cap_win_id != PJSUA_INVALID_ID) { 1227 1247 pjsua_vid_win *w = &pjsua_var.win[call_med->strm.v.cap_win_id]; … … 1248 1268 call_med->strm.v.rdr_win_id = PJSUA_INVALID_ID; 1249 1269 } 1270 PJSUA_UNLOCK(); 1250 1271 1251 1272 if ((call_med->dir & PJMEDIA_DIR_ENCODING) && … … 2103 2124 2104 2125 /* == Apply the new capture device == */ 2105 2126 PJSUA_LOCK(); 2106 2127 wid = call_med->strm.v.cap_win_id; 2107 2128 w = &pjsua_var.win[wid]; … … 2118 2139 w->preview_cap_id = cap_dev; 2119 2140 call_med->strm.v.cap_dev = cap_dev; 2141 2142 PJSUA_UNLOCK(); 2120 2143 /* Yay, change capturer done! */ 2121 2144 return PJ_SUCCESS; … … 2127 2150 status = pjmedia_vid_stream_get_port(call_med->strm.v.stream, 2128 2151 PJMEDIA_DIR_ENCODING, &media_port); 2129 if (status != PJ_SUCCESS) 2152 if (status != PJ_SUCCESS) { 2153 PJSUA_UNLOCK(); 2130 2154 return status; 2155 } 2131 2156 2132 2157 pjmedia_event_unsubscribe(NULL, &call_media_on_event, call_med, … … 2136 2161 status = pjsua_vid_conf_disconnect(w->cap_slot, 2137 2162 call_med->strm.v.strm_enc_slot); 2138 if (status != PJ_SUCCESS) 2163 if (status != PJ_SUCCESS) { 2164 PJSUA_UNLOCK(); 2139 2165 return status; 2166 } 2140 2167 2141 2168 … … 2197 2224 call_med->strm.v.cap_win_id = new_wid; 2198 2225 dec_vid_win(wid); 2226 2227 PJSUA_UNLOCK(); 2199 2228 2200 2229 return PJ_SUCCESS; … … 2217 2246 status = pjsua_vid_conf_connect(w->cap_slot, 2218 2247 call_med->strm.v.strm_enc_slot, NULL); 2219 if (status != PJ_SUCCESS) 2248 if (status != PJ_SUCCESS) { 2249 PJSUA_UNLOCK(); 2220 2250 return status; 2251 } 2221 2252 2222 2253 #if ENABLE_EVENT … … 2225 2256 call_med, w->vp_cap); 2226 2257 #endif 2258 2259 PJSUA_UNLOCK(); 2227 2260 2228 2261 return status; … … 2259 2292 2260 2293 if (enable) { 2261 pjsua_vid_win *w; 2262 pjsua_vid_win_id wid; 2263 2264 wid = vid_preview_get_win(call_med->strm.v.cap_dev, PJ_FALSE); 2265 pj_assert(wid != PJSUA_INVALID_ID); 2266 2267 w = &pjsua_var.win[wid]; 2268 2269 if (!w->cap_started) { 2270 /* Start the video capture first */ 2271 status = pjmedia_vid_port_start(w->vp_cap); 2294 if (call_med->strm.v.cap_win_id == PJSUA_INVALID_ID) { 2295 /* Setup the video capture first */ 2296 status = setup_vid_capture(call_med); 2272 2297 if (status != PJ_SUCCESS) 2273 2298 return status; 2274 w->cap_started = PJ_TRUE;2275 2299 } 2276 2300 … … 2279 2303 PJMEDIA_DIR_ENCODING); 2280 2304 } else { 2305 pjsua_vid_win_id wid; 2306 pjsua_vid_win *w; 2307 2281 2308 /* Pause stream in encoding direction */ 2282 2309 status = pjmedia_vid_stream_pause( call_med->strm.v.stream, 2283 2310 PJMEDIA_DIR_ENCODING); 2311 2312 PJSUA_LOCK(); 2313 2314 wid = vid_preview_get_win(call_med->strm.v.cap_dev, PJ_FALSE); 2315 if (wid != PJSUA_INVALID_ID) { 2316 w = &pjsua_var.win[wid]; 2317 2318 /* Unsubscribe event */ 2319 pjmedia_event_unsubscribe(NULL, &call_media_on_event, call_med, 2320 w->vp_cap); 2321 2322 /* Disconnect from video conference */ 2323 pjsua_vid_conf_disconnect(w->cap_slot, 2324 call_med->strm.v.strm_enc_slot); 2325 2326 /* Decrement ref count of the video window */ 2327 dec_vid_win(call_med->strm.v.cap_win_id); 2328 call_med->strm.v.cap_win_id = PJSUA_INVALID_ID; 2329 } 2330 2331 PJSUA_UNLOCK(); 2284 2332 } 2285 2333
Note: See TracChangeset
for help on using the changeset viewer.