mirror of https://github.com/LIJI32/SameBoy.git
Fix a race condition with camera emulation
This commit is contained in:
parent
0b77662504
commit
8600f96fa2
|
@ -1091,39 +1091,39 @@ didReceiveNotificationResponse:(UNNotificationResponse *)response
|
|||
|
||||
- (void)cameraRequestUpdate
|
||||
{
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
@try {
|
||||
if (!_cameraSession) {
|
||||
NSError *error;
|
||||
AVCaptureDevice *device = [self captureDevice];
|
||||
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice: device error: &error];
|
||||
|
||||
if (!input) {
|
||||
GB_camera_updated(&_gb);
|
||||
return;
|
||||
}
|
||||
|
||||
_cameraOutput = [[AVCaptureVideoDataOutput alloc] init];
|
||||
[_cameraOutput setVideoSettings: @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)}];
|
||||
[_cameraOutput setSampleBufferDelegate:self
|
||||
queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
|
||||
|
||||
|
||||
|
||||
_cameraSession = [AVCaptureSession new];
|
||||
_cameraSession.sessionPreset = AVCaptureSessionPreset352x288;
|
||||
|
||||
[_cameraSession addInput: input];
|
||||
[_cameraSession addOutput: _cameraOutput];
|
||||
_cameraConnection = [_cameraOutput connectionWithMediaType: AVMediaTypeVideo];
|
||||
_cameraConnection.videoOrientation = AVCaptureVideoOrientationPortrait;
|
||||
[_cameraSession startRunning];
|
||||
@try {
|
||||
if (!_cameraSession) {
|
||||
NSError *error;
|
||||
AVCaptureDevice *device = [self captureDevice];
|
||||
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice: device error: &error];
|
||||
|
||||
if (!input) {
|
||||
GB_camera_updated(&_gb);
|
||||
return;
|
||||
}
|
||||
|
||||
_cameraOutput = [[AVCaptureVideoDataOutput alloc] init];
|
||||
[_cameraOutput setVideoSettings: @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)}];
|
||||
[_cameraOutput setSampleBufferDelegate:self
|
||||
queue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)];
|
||||
|
||||
|
||||
|
||||
_cameraSession = [AVCaptureSession new];
|
||||
_cameraSession.sessionPreset = AVCaptureSessionPreset352x288;
|
||||
|
||||
[_cameraSession addInput: input];
|
||||
[_cameraSession addOutput: _cameraOutput];
|
||||
_cameraConnection = [_cameraOutput connectionWithMediaType: AVMediaTypeVideo];
|
||||
_cameraConnection.videoOrientation = AVCaptureVideoOrientationPortrait;
|
||||
[_cameraSession startRunning];
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
/* I have not tested camera support on many devices, so we catch exceptions just in case. */
|
||||
GB_camera_updated(&_gb);
|
||||
}
|
||||
}
|
||||
@catch (NSException *exception) {
|
||||
/* I have not tested camera support on many devices, so we catch exceptions just in case. */
|
||||
GB_camera_updated(&_gb);
|
||||
}
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
_cameraNeedsUpdate = true;
|
||||
[_disableCameraTimer invalidate];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
|
Loading…
Reference in New Issue