Changeset 3758 for pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
- Timestamp:
- Sep 20, 2011 10:07:55 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_vid.c
r3756 r3758 324 324 */ 325 325 326 /* 327 * Get the preview window handle associated with the capture device, if any. 328 */ 329 PJ_DEF(pjsua_vid_win_id) pjsua_vid_preview_get_win(pjmedia_vid_dev_index id) 326 static pjsua_vid_win_id vid_preview_get_win(pjmedia_vid_dev_index id, 327 pj_bool_t running_only) 330 328 { 331 329 pjsua_vid_win_id wid = PJSUA_INVALID_ID; … … 348 346 } 349 347 } 348 349 if (wid != PJSUA_INVALID_ID && running_only) { 350 pjsua_vid_win *w = &pjsua_var.win[wid]; 351 wid = w->preview_running ? wid : PJSUA_INVALID_ID; 352 } 353 350 354 PJSUA_UNLOCK(); 351 355 352 356 return wid; 357 } 358 359 /* 360 * NOTE: internal function don't use this!!! Use vid_preview_get_win() 361 * instead. This is because this function will only return window ID 362 * if preview is currently running. 363 */ 364 PJ_DEF(pjsua_vid_win_id) pjsua_vid_preview_get_win(pjmedia_vid_dev_index id) 365 { 366 return vid_preview_get_win(id, PJ_TRUE); 353 367 } 354 368 … … 394 408 /* If type is preview, check if it exists already */ 395 409 if (type == PJSUA_WND_TYPE_PREVIEW) { 396 wid = pjsua_vid_preview_get_win(cap_id);410 wid = vid_preview_get_win(cap_id, PJ_FALSE); 397 411 if (wid != PJSUA_INVALID_ID) { 398 412 /* Yes, it exists */ … … 421 435 /* Done */ 422 436 *id = wid; 423 PJ_LOG(4,(THIS_FILE, "Window already exist: %d", wid));424 437 pj_log_pop_indent(); 425 return PJ_SUCCESS; 438 439 return status; 426 440 } 427 441 } … … 826 840 } 827 841 828 wid = pjsua_vid_preview_get_win(call_med->strm.v.cap_dev); 842 /* Note: calling pjsua_vid_preview_get_win() even though 843 * create_vid_win() will automatically create the window 844 * if it doesn't exist, because create_vid_win() will modify 845 * existing window SHOW/HIDE value. 846 */ 847 wid = vid_preview_get_win(call_med->strm.v.cap_dev, PJ_FALSE); 829 848 if (wid == PJSUA_INVALID_ID) { 830 849 /* Create preview video window */ … … 1043 1062 1044 1063 w = &pjsua_var.win[wid]; 1064 if (w->preview_running) { 1065 PJSUA_UNLOCK(); 1066 pj_log_pop_indent(); 1067 return PJ_SUCCESS; 1068 } 1045 1069 1046 1070 /* Start renderer, unless it's native preview */ 1047 if (!w->is_native) { 1071 if (w->is_native && !pjmedia_vid_port_is_running(w->vp_cap)) { 1072 pjmedia_vid_dev_stream *cap_dev; 1073 pj_bool_t enabled = PJ_TRUE; 1074 1075 cap_dev = pjmedia_vid_port_get_stream(w->vp_cap); 1076 status = pjmedia_vid_dev_stream_set_cap( 1077 cap_dev, PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW, 1078 &enabled); 1079 if (status != PJ_SUCCESS) { 1080 PJ_PERROR(1,(THIS_FILE, status, 1081 "Error activating native preview, falling back " 1082 "to software preview..")); 1083 w->is_native = PJ_FALSE; 1084 } 1085 } 1086 1087 if (!w->is_native && !pjmedia_vid_port_is_running(w->vp_rend)) { 1048 1088 status = pjmedia_vid_port_start(w->vp_rend); 1049 1089 if (status != PJ_SUCCESS) { … … 1055 1095 1056 1096 /* Start capturer */ 1057 status = pjmedia_vid_port_start(w->vp_cap); 1058 if (status != PJ_SUCCESS) { 1059 PJSUA_UNLOCK(); 1060 pj_log_pop_indent(); 1061 return status; 1097 if (!pjmedia_vid_port_is_running(w->vp_cap)) { 1098 status = pjmedia_vid_port_start(w->vp_cap); 1099 if (status != PJ_SUCCESS) { 1100 PJSUA_UNLOCK(); 1101 pj_log_pop_indent(); 1102 return status; 1103 } 1062 1104 } 1063 1105 1064 1106 inc_vid_win(wid); 1107 w->preview_running = PJ_TRUE; 1065 1108 1066 1109 PJSUA_UNLOCK(); … … 1075 1118 { 1076 1119 pjsua_vid_win_id wid = PJSUA_INVALID_ID; 1077 1078 PJ_LOG(4,(THIS_FILE, "Stopping preview for cap_dev=%d", id)); 1079 pj_log_push_indent(); 1120 pjsua_vid_win *w; 1121 pj_status_t status; 1080 1122 1081 1123 PJSUA_LOCK(); … … 1087 1129 } 1088 1130 1089 dec_vid_win(wid); 1131 PJ_LOG(4,(THIS_FILE, "Stopping preview for cap_dev=%d", id)); 1132 pj_log_push_indent(); 1133 1134 w = &pjsua_var.win[wid]; 1135 if (w->preview_running) { 1136 if (w->is_native) { 1137 pjmedia_vid_dev_stream *cap_dev; 1138 pj_bool_t enabled = PJ_FALSE; 1139 1140 cap_dev = pjmedia_vid_port_get_stream(w->vp_cap); 1141 status = pjmedia_vid_dev_stream_set_cap( 1142 cap_dev, PJMEDIA_VID_DEV_CAP_INPUT_PREVIEW, 1143 &enabled); 1144 } else { 1145 status = pjmedia_vid_port_stop(w->vp_rend); 1146 } 1147 1148 if (status != PJ_SUCCESS) { 1149 PJ_PERROR(1,(THIS_FILE, status, "Error stopping %spreview", 1150 (w->is_native ? "native " : ""))); 1151 PJSUA_UNLOCK(); 1152 pj_log_pop_indent(); 1153 return status; 1154 } 1155 1156 dec_vid_win(wid); 1157 w->preview_running = PJ_FALSE; 1158 } 1090 1159 1091 1160 PJSUA_UNLOCK(); … … 1674 1743 /* = Attach stream port to the new capture device = */ 1675 1744 1676 new_wid = pjsua_vid_preview_get_win(cap_dev); 1745 /* Note: calling pjsua_vid_preview_get_win() even though 1746 * create_vid_win() will automatically create the window 1747 * if it doesn't exist, because create_vid_win() will modify 1748 * existing window SHOW/HIDE value. 1749 */ 1750 new_wid = vid_preview_get_win(cap_dev, PJ_FALSE); 1677 1751 if (new_wid == PJSUA_INVALID_ID) { 1678 1752 /* Create preview video window */
Note: See TracChangeset
for help on using the changeset viewer.