Changeset 5051
- Timestamp:
- Apr 8, 2015 1:00:57 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_dev.m
r5002 r5051 66 66 }; 67 67 68 /* qtdevice info */68 /* ios device info */ 69 69 struct ios_dev_info 70 70 { … … 73 73 }; 74 74 75 /* qtfactory */75 /* ios factory */ 76 76 struct ios_factory 77 77 { … … 112 112 AVCaptureVideoDataOutput *video_output; 113 113 VOutDelegate *vout_delegate; 114 dispatch_queue_t queue; 114 115 void *capture_buf; 115 116 AVCaptureVideoPreviewLayer *prev_layer; … … 628 629 strm->cap_session = [[AVCaptureSession alloc] init]; 629 630 if (!strm->cap_session) { 631 PJ_LOG(2, (THIS_FILE, "Unable to create AV capture session")); 630 632 status = PJ_ENOMEM; 631 633 goto on_error; … … 668 670 deviceInputWithDevice:dev 669 671 error: &error]; 670 if (!strm->dev_input) { 672 if (error || !strm->dev_input) { 673 PJ_LOG(2, (THIS_FILE, "Unable to get input capture device")); 671 674 status = PJMEDIA_EVID_SYSERR; 672 675 goto on_error; 673 676 } 674 [strm->cap_session addInput:strm->dev_input];675 677 676 strm->video_output = [[[AVCaptureVideoDataOutput alloc] init] 677 autorelease]; 678 if (!strm->video_output) { 678 if ([strm->cap_session canAddInput:strm->dev_input]) { 679 [strm->cap_session addInput:strm->dev_input]; 680 } else { 681 PJ_LOG(2, (THIS_FILE, "Unable to add input capture device")); 679 682 status = PJMEDIA_EVID_SYSERR; 680 683 goto on_error; 681 684 } 682 685 686 strm->video_output = [[AVCaptureVideoDataOutput alloc] init]; 687 if (!strm->video_output) { 688 PJ_LOG(2, (THIS_FILE, "Unable to create AV video output")); 689 status = PJ_ENOMEM; 690 goto on_error; 691 } 692 693 /* Configure the video output */ 683 694 strm->video_output.alwaysDiscardsLateVideoFrames = YES; 684 [strm->cap_session addOutput:strm->video_output];685 686 /* Configure the video output */687 strm->vout_delegate = [VOutDelegate alloc];688 strm->vout_delegate->stream = strm;689 dispatch_queue_t queue = dispatch_queue_create("myQueue", NULL);690 [strm->video_output setSampleBufferDelegate:strm->vout_delegate691 queue:queue];692 dispatch_release(queue);693 694 695 strm->video_output.videoSettings = 695 696 [NSDictionary dictionaryWithObjectsAndKeys: 696 697 [NSNumber numberWithInt:ifi->ios_format], 697 698 kCVPixelBufferPixelFormatTypeKey, nil]; 698 699 700 strm->vout_delegate = [VOutDelegate alloc]; 701 strm->vout_delegate->stream = strm; 702 strm->queue = dispatch_queue_create("vout_queue", 703 DISPATCH_QUEUE_SERIAL); 704 [strm->video_output setSampleBufferDelegate:strm->vout_delegate 705 queue:strm->queue]; 706 707 if ([strm->cap_session canAddOutput:strm->video_output]) { 708 [strm->cap_session addOutput:strm->video_output]; 709 } else { 710 PJ_LOG(2, (THIS_FILE, "Unable to add video data output")); 711 status = PJMEDIA_EVID_SYSERR; 712 goto on_error; 713 } 714 699 715 /* Prepare capture buffer if it's planar format */ 700 716 if (strm->is_planar) … … 819 835 if (!strm->render_view) 820 836 ios_init_view(strm); 821 822 837 823 838 /* Preview layer instantiation should be in main thread! */ … … 1005 1020 } 1006 1021 1007 if (![stream->cap_session isRunning]) 1022 if (![stream->cap_session isRunning]) { 1023 PJ_LOG(3, (THIS_FILE, "Unable to start iOS capture session")); 1008 1024 return PJ_EUNKNOWN; 1025 } 1009 1026 } 1010 1027 … … 1037 1054 struct ios_stream *stream = (struct ios_stream*)strm; 1038 1055 1039 PJ_UNUSED_ARG(stream); 1040 1056 if (!stream->cap_session || ![stream->cap_session isRunning]) 1057 return PJ_SUCCESS; 1058 1041 1059 PJ_LOG(4, (THIS_FILE, "Stopping iOS video stream")); 1042 1060 1043 if (stream->cap_session && [stream->cap_session isRunning]) { 1044 if ([NSThread isMainThread]) { 1061 if ([NSThread isMainThread]) { 1062 [stream->cap_session stopRunning]; 1063 } else { 1064 dispatch_sync(dispatch_get_main_queue(), ^{ 1045 1065 [stream->cap_session stopRunning]; 1046 } else { 1047 dispatch_sync(dispatch_get_main_queue(), ^{ 1048 [stream->cap_session stopRunning]; 1049 }); 1050 } 1066 }); 1051 1067 } 1052 1068 … … 1065 1081 1066 1082 if (stream->cap_session) { 1067 [stream->cap_session removeInput:stream->dev_input]; 1083 if (stream->dev_input) { 1084 [stream->cap_session removeInput:stream->dev_input]; 1085 stream->dev_input = nil; 1086 } 1068 1087 [stream->cap_session removeOutput:stream->video_output]; 1069 1088 [stream->cap_session release]; 1070 1089 stream->cap_session = nil; 1071 }1072 if (stream->dev_input) {1073 stream->dev_input = nil;1074 1090 } 1075 1091 1092 if (stream->video_output) { 1093 [stream->video_output release]; 1094 stream->video_output = nil; 1095 } 1096 1076 1097 if (stream->vout_delegate) { 1077 1098 [stream->vout_delegate release]; 1078 1099 stream->vout_delegate = nil; 1079 }1080 if (stream->video_output) {1081 stream->video_output = nil;1082 1100 } 1083 1101 … … 1105 1123 } 1106 1124 1125 if (stream->queue) { 1126 dispatch_release(stream->queue); 1127 stream->queue = nil; 1128 } 1129 1107 1130 pj_pool_release(stream->pool); 1108 1131
Note: See TracChangeset
for help on using the changeset viewer.