- Timestamp:
- Aug 3, 2016 10:22:29 AM (8 years ago)
- Location:
- pjproject/trunk/pjmedia/src/pjmedia-videodev
- Files:
-
- 2 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]; -
pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_opengl_dev.m
r5052 r5406 20 20 #include <pj/assert.h> 21 21 #include <pj/log.h> 22 #include <pj/os.h> 22 23 23 24 #if defined(PJMEDIA_HAS_VIDEO) && PJMEDIA_HAS_VIDEO != 0 && \ … … 129 130 } 130 131 132 static void dispatch_sync_on_main_queue(void (^block)(void)) 133 { 134 if ([NSThread isMainThread]) { 135 block(); 136 } else { 137 dispatch_sync(dispatch_get_main_queue(), block); 138 } 139 } 140 131 141 @implementation GLView 132 142 … … 267 277 268 278 rect = CGRectMake(0, 0, strm->param.disp_size.w, strm->param.disp_size.h); 269 strm->gl_view = [[GLView alloc] initWithFrame:rect]; 279 dispatch_sync_on_main_queue(^{ 280 strm->gl_view = [[GLView alloc] initWithFrame:rect]; 281 }); 270 282 if (!strm->gl_view) 271 283 return PJ_ENOMEM; … … 405 417 UIView *view = (UIView *)pval; 406 418 strm->param.window.info.ios.window = (void *)pval; 407 dispatch_async(dispatch_get_main_queue(), 408 ^{[view addSubview:strm->gl_view];}); 419 dispatch_sync_on_main_queue(^{[view addSubview:strm->gl_view];}); 409 420 return PJ_SUCCESS; 410 421 } else if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_RESIZE) { 411 422 pj_memcpy(&strm->param.disp_size, pval, sizeof(strm->param.disp_size)); 412 dispatch_ async(dispatch_get_main_queue(),^{423 dispatch_sync_on_main_queue(^{ 413 424 strm->gl_view.bounds = CGRectMake(0, 0, strm->param.disp_size.w, 414 425 strm->param.disp_size.h); … … 417 428 } else if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_POSITION) { 418 429 pj_memcpy(&strm->param.window_pos, pval, sizeof(strm->param.window_pos)); 419 dispatch_ async(dispatch_get_main_queue(),^{430 dispatch_sync_on_main_queue(^{ 420 431 strm->gl_view.center = CGPointMake(strm->param.window_pos.x + 421 432 strm->param.disp_size.w/2.0, … … 425 436 return PJ_SUCCESS; 426 437 } else if (cap == PJMEDIA_VID_DEV_CAP_OUTPUT_HIDE) { 427 dispatch_ async(dispatch_get_main_queue(),^{438 dispatch_sync_on_main_queue(^{ 428 439 strm->gl_view.hidden = (BOOL)(*((pj_bool_t *)pval)); 429 440 }); … … 433 444 if (strm->param.orient == PJMEDIA_ORIENT_UNKNOWN) 434 445 return PJ_SUCCESS; 435 dispatch_ async(dispatch_get_main_queue(),^{446 dispatch_sync_on_main_queue(^{ 436 447 strm->gl_view.transform = 437 448 CGAffineTransformMakeRotation(((int)strm->param.orient-1) *
Note: See TracChangeset
for help on using the changeset viewer.