- Timestamp:
- Aug 3, 2016 10:22:29 AM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-videodev/darwin_dev.m
r5372 r5406 233 233 darwin_sizes[idx++].preset_str = AVCaptureSessionPreset1920x1080; 234 234 #endif 235 } 236 237 static void dispatch_sync_on_main_queue(void (^block)(void)) 238 { 239 if ([NSThread isMainThread]) { 240 block(); 241 } else { 242 dispatch_sync(dispatch_get_main_queue(), block); 243 } 235 244 } 236 245 … … 944 953 if (strm->prev_layer) { 945 954 CALayer *prev_layer = strm->prev_layer; 946 dispatch_async(dispatch_get_main_queue(),^{955 dispatch_sync_on_main_queue(^{ 947 956 [prev_layer removeFromSuperlayer]; 948 957 [prev_layer release]; … … 970 979 971 980 /* Preview layer instantiation should be in main thread! */ 972 dispatch_ async(dispatch_get_main_queue(),^{981 dispatch_sync_on_main_queue(^{ 973 982 /* Create preview layer */ 974 983 AVCaptureVideoPreviewLayer *prev_layer = … … 1075 1084 UIView *view = (UIView *)pval; 1076 1085 strm->param.window.info.ios.window = (void *)pval; 1077 dispatch_ async(dispatch_get_main_queue(),^{1086 dispatch_sync_on_main_queue(^{ 1078 1087 [view addSubview:strm->render_view]; 1079 1088 }); … … 1088 1097 r.size = CGSizeMake(strm->param.disp_size.w, 1089 1098 strm->param.disp_size.h); 1090 dispatch_ async(dispatch_get_main_queue(),^{1099 dispatch_sync_on_main_queue(^{ 1091 1100 strm->render_view.bounds = r; 1092 1101 if (strm->prev_layer) … … 1100 1109 pj_memcpy(&strm->param.window_pos, pval, 1101 1110 sizeof(strm->param.window_pos)); 1102 dispatch_ async(dispatch_get_main_queue(),^{1111 dispatch_sync_on_main_queue(^{ 1103 1112 strm->render_view.center = 1104 1113 CGPointMake(strm->param.window_pos.x + … … 1112 1121 case PJMEDIA_VID_DEV_CAP_OUTPUT_HIDE: 1113 1122 { 1114 dispatch_ async(dispatch_get_main_queue(),^{1123 dispatch_sync_on_main_queue(^{ 1115 1124 strm->render_view.hidden = (BOOL)(*((pj_bool_t *)pval)); 1116 1125 }); … … 1134 1143 if (strm->param.dir == PJMEDIA_DIR_RENDER) { 1135 1144 #if TARGET_OS_IPHONE 1136 dispatch_async(dispatch_get_main_queue(),^{1145 dispatch_sync_on_main_queue(^{ 1137 1146 strm->render_view.transform = 1138 1147 CGAffineTransformMakeRotation( … … 1219 1228 1220 1229 if (stream->cap_session) { 1221 if ([NSThread isMainThread]){1230 dispatch_sync_on_main_queue(^{ 1222 1231 [stream->cap_session startRunning]; 1223 } else { 1224 dispatch_sync(dispatch_get_main_queue(), ^{ 1225 [stream->cap_session startRunning]; 1226 }); 1227 } 1232 }); 1228 1233 1229 1234 if (![stream->cap_session isRunning]) { … … 1251 1256 1252 1257 /* Perform video display in a background thread */ 1253 dispatch_ async(dispatch_get_main_queue(),^{1258 dispatch_sync_on_main_queue(^{ 1254 1259 [stream->vout_delegate update_image]; 1255 1260 }); … … 1269 1274 PJ_LOG(4, (THIS_FILE, "Stopping Darwin video stream")); 1270 1275 1271 if ([NSThread isMainThread]) { 1272 [stream->cap_session stopRunning]; 1273 } else { 1274 dispatch_sync(dispatch_get_main_queue(), ^{ 1275 [stream->cap_session stopRunning]; 1276 }); 1277 } 1276 dispatch_sync_on_main_queue(^{ 1277 [stream->cap_session stopRunning]; 1278 }); 1278 1279 1279 1280 return PJ_SUCCESS; … … 1313 1314 if (stream->prev_layer) { 1314 1315 CALayer *prev_layer = stream->prev_layer; 1315 dispatch_ async(dispatch_get_main_queue(),^{1316 dispatch_sync_on_main_queue(^{ 1316 1317 [prev_layer removeFromSuperlayer]; 1317 1318 [prev_layer release]; … … 1322 1323 if (stream->render_view) { 1323 1324 UIView *view = stream->render_view; 1324 dispatch_ async(dispatch_get_main_queue(),^{1325 dispatch_sync_on_main_queue(^{ 1325 1326 [view removeFromSuperview]; 1326 1327 [view release];
Note: See TracChangeset
for help on using the changeset viewer.