diff --git a/packages/camera/camera/CHANGELOG.md b/packages/camera/camera/CHANGELOG.md index f5b783d5114b..1a6eceb957b1 100644 --- a/packages/camera/camera/CHANGELOG.md +++ b/packages/camera/camera/CHANGELOG.md @@ -1,8 +1,4 @@ -## NEXT - -* Fixed a crash in iOS when using image stream due to threading issue. - -## 0.9.4+5 +## 0.9.4+5 * Fixes bug where calling a method after the camera was closed resulted in a Java `IllegalStateException` exception. * Fixes integration tests. diff --git a/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj b/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj index ad0ece9adbd2..feb789f2ecba 100644 --- a/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj +++ b/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj @@ -20,9 +20,6 @@ 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; - E0C6E2002770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FD2770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m */; }; - E0C6E2012770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FE2770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m */; }; - E0C6E2022770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C6E1FF2770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m */; }; E487C86026D686A10034AC92 /* CameraPreviewPauseTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E487C85F26D686A10034AC92 /* CameraPreviewPauseTests.m */; }; F6EE622F2710A6FC00905E4A /* MockFLTThreadSafeFlutterResult.m in Sources */ = {isa = PBXBuildFile; fileRef = F6EE622E2710A6FC00905E4A /* MockFLTThreadSafeFlutterResult.m */; }; /* End PBXBuildFile section */ @@ -77,9 +74,6 @@ 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 9C5CC6CAD53AD388B2694F3A /* Pods-RunnerTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.debug.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.debug.xcconfig"; sourceTree = ""; }; A24F9E418BA48BCC7409B117 /* Pods-RunnerTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RunnerTests.release.xcconfig"; path = "Target Support Files/Pods-RunnerTests/Pods-RunnerTests.release.xcconfig"; sourceTree = ""; }; - E0C6E1FD2770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeMethodChannelTests.m; sourceTree = ""; }; - E0C6E1FE2770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeTextureRegistryTests.m; sourceTree = ""; }; - E0C6E1FF2770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThreadSafeEventChannelTests.m; sourceTree = ""; }; E487C85F26D686A10034AC92 /* CameraPreviewPauseTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CameraPreviewPauseTests.m; sourceTree = ""; }; F63F9EED27143B19002479BF /* MockFLTThreadSafeFlutterResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MockFLTThreadSafeFlutterResult.h; sourceTree = ""; }; F6EE622E2710A6FC00905E4A /* MockFLTThreadSafeFlutterResult.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MockFLTThreadSafeFlutterResult.m; sourceTree = ""; }; @@ -113,9 +107,6 @@ 03BB766C2665316900CE5A93 /* Info.plist */, 033B94BD269C40A200B4DF97 /* CameraMethodChannelTests.m */, 03F6F8B126CBB4670024B8D3 /* ThreadSafeFlutterResultTests.m */, - E0C6E1FF2770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m */, - E0C6E1FD2770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m */, - E0C6E1FE2770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m */, E487C85F26D686A10034AC92 /* CameraPreviewPauseTests.m */, F6EE622E2710A6FC00905E4A /* MockFLTThreadSafeFlutterResult.m */, F63F9EED27143B19002479BF /* MockFLTThreadSafeFlutterResult.h */, @@ -248,7 +239,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1100; ORGANIZATIONNAME = "The Flutter Authors"; TargetAttributes = { 03BB76672665316900CE5A93 = { @@ -387,9 +378,6 @@ E487C86026D686A10034AC92 /* CameraPreviewPauseTests.m in Sources */, F6EE622F2710A6FC00905E4A /* MockFLTThreadSafeFlutterResult.m in Sources */, 334733EA2668111C00DCC49E /* CameraOrientationTests.m in Sources */, - E0C6E2022770F01A00EA6AA3 /* ThreadSafeEventChannelTests.m in Sources */, - E0C6E2012770F01A00EA6AA3 /* ThreadSafeTextureRegistryTests.m in Sources */, - E0C6E2002770F01A00EA6AA3 /* ThreadSafeMethodChannelTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/packages/camera/camera/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/packages/camera/camera/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index f4b3c1099001..1447e08231be 100644 --- a/packages/camera/camera/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/packages/camera/camera/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - -@interface ThreadSafeEventChannelTests : XCTestCase -@end - -@implementation ThreadSafeEventChannelTests { - FLTThreadSafeEventChannel *_channel; - XCTestExpectation *_mainThreadExpectation; -} - -- (void)setUp { - [super setUp]; - id mockEventChannel = OCMClassMock([FlutterEventChannel class]); - - _mainThreadExpectation = - [[XCTestExpectation alloc] initWithDescription:@"invokeMethod must be called in main thread"]; - _channel = [[FLTThreadSafeEventChannel alloc] initWithEventChannel:mockEventChannel]; - - OCMStub([mockEventChannel setStreamHandler:[OCMArg any]]).andDo(^(NSInvocation *invocation) { - if (NSThread.isMainThread) { - [self->_mainThreadExpectation fulfill]; - } - }); -} - -- (void)testSetStreamHandler_shouldStayOnMainThreadIfCalledFromMainThread { - [_channel setStreamHandler:nil]; - [self waitForExpectations:@[ _mainThreadExpectation ] timeout:1]; -} - -- (void)testSetStreamHandler_shouldDispatchToMainThreadIfCalledFromBackgroundThread { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self->_channel setStreamHandler:nil]; - }); - [self waitForExpectations:@[ _mainThreadExpectation ] timeout:1]; -} - -@end diff --git a/packages/camera/camera/example/ios/RunnerTests/ThreadSafeMethodChannelTests.m b/packages/camera/camera/example/ios/RunnerTests/ThreadSafeMethodChannelTests.m deleted file mode 100644 index a7cabbd92e37..000000000000 --- a/packages/camera/camera/example/ios/RunnerTests/ThreadSafeMethodChannelTests.m +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -@import camera; -@import XCTest; -#import - -@interface ThreadSafeMethodChannelTests : XCTestCase -@end - -@implementation ThreadSafeMethodChannelTests { - FLTThreadSafeMethodChannel *_channel; - XCTestExpectation *_mainThreadExpectation; -} - -- (void)setUp { - [super setUp]; - id mockMethodChannel = OCMClassMock([FlutterMethodChannel class]); - - _mainThreadExpectation = - [[XCTestExpectation alloc] initWithDescription:@"invokeMethod must be called in main thread"]; - _channel = [[FLTThreadSafeMethodChannel alloc] initWithMethodChannel:mockMethodChannel]; - - OCMStub([mockMethodChannel invokeMethod:[OCMArg any] arguments:[OCMArg any]]) - .andDo(^(NSInvocation *invocation) { - if (NSThread.isMainThread) { - [self->_mainThreadExpectation fulfill]; - } - }); -} - -- (void)testInvokeMethod_shouldStayOnMainThreadIfCalledFromMainThread { - [_channel invokeMethod:@"foo" arguments:nil]; - - [self waitForExpectations:@[ _mainThreadExpectation ] timeout:1]; -} - -- (void)testInvokeMethod__shouldDispatchToMainThreadIfCalledFromBackgroundThread { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self->_channel invokeMethod:@"foo" arguments:nil]; - }); - [self waitForExpectations:@[ _mainThreadExpectation ] timeout:1]; -} - -@end diff --git a/packages/camera/camera/example/ios/RunnerTests/ThreadSafeTextureRegistryTests.m b/packages/camera/camera/example/ios/RunnerTests/ThreadSafeTextureRegistryTests.m deleted file mode 100644 index 73a9fb8e3c3d..000000000000 --- a/packages/camera/camera/example/ios/RunnerTests/ThreadSafeTextureRegistryTests.m +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -@import camera; -@import XCTest; -#import - -@interface ThreadSafeTextureRegistryTests : XCTestCase -@end - -@implementation ThreadSafeTextureRegistryTests { - FLTThreadSafeTextureRegistry *_registry; - XCTestExpectation *_registerTextureExpectation; - XCTestExpectation *_unregisterTextureExpectation; - XCTestExpectation *_textureFrameAvailableExpectation; -} - -- (void)setUp { - [super setUp]; - id mockTextureRegistry = OCMProtocolMock(@protocol(FlutterTextureRegistry)); - _registry = [[FLTThreadSafeTextureRegistry alloc] initWithTextureRegistry:mockTextureRegistry]; - - _registerTextureExpectation = [[XCTestExpectation alloc] - initWithDescription:@"registerTexture must be called in main thread"]; - _unregisterTextureExpectation = [[XCTestExpectation alloc] - initWithDescription:@"unregisterTexture must be called in main thread"]; - _textureFrameAvailableExpectation = [[XCTestExpectation alloc] - initWithDescription:@"textureFrameAvailable must be called in main thread"]; - - OCMStub([mockTextureRegistry registerTexture:[OCMArg any]]).andDo(^(NSInvocation *invocation) { - if (NSThread.isMainThread) { - [self->_registerTextureExpectation fulfill]; - } - }); - - OCMStub([mockTextureRegistry unregisterTexture:0]).andDo(^(NSInvocation *invocation) { - if (NSThread.isMainThread) { - [self->_unregisterTextureExpectation fulfill]; - } - }); - - OCMStub([mockTextureRegistry textureFrameAvailable:0]).andDo(^(NSInvocation *invocation) { - if (NSThread.isMainThread) { - [self->_textureFrameAvailableExpectation fulfill]; - } - }); -} - -- (void)testShouldStayOnMainThreadIfCalledFromMainThread { - NSObject *anyTexture = OCMProtocolMock(@protocol(FlutterTexture)); - [_registry registerTextureSync:anyTexture]; - [_registry textureFrameAvailable:0]; - [_registry unregisterTexture:0]; - [self waitForExpectations:@[ - _registerTextureExpectation, _unregisterTextureExpectation, _textureFrameAvailableExpectation - ] - timeout:1]; -} - -- (void)testShouldDispatchToMainThreadIfCalledFromBackgroundThread { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - NSObject *anyTexture = OCMProtocolMock(@protocol(FlutterTexture)); - [self->_registry registerTextureSync:anyTexture]; - [self->_registry textureFrameAvailable:0]; - [self->_registry unregisterTexture:0]; - }); - [self waitForExpectations:@[ - _registerTextureExpectation, _unregisterTextureExpectation, _textureFrameAvailableExpectation - ] - timeout:1]; -} - -@end diff --git a/packages/camera/camera/ios/Classes/CameraPlugin.m b/packages/camera/camera/ios/Classes/CameraPlugin.m index 448727963ab3..2c12081da807 100644 --- a/packages/camera/camera/ios/Classes/CameraPlugin.m +++ b/packages/camera/camera/ios/Classes/CameraPlugin.m @@ -10,10 +10,7 @@ #import #import #import -#import "FLTThreadSafeEventChannel.h" #import "FLTThreadSafeFlutterResult.h" -#import "FLTThreadSafeMethodChannel.h" -#import "FLTThreadSafeTextureRegistry.h" @interface FLTSavePhotoDelegate : NSObject @property(readonly, nonatomic) NSString *path; @@ -308,7 +305,7 @@ @interface FLTCam : NSObject *)messen FlutterEventChannel *eventChannel = [FlutterEventChannel eventChannelWithName:@"plugins.flutter.io/camera/imageStream" binaryMessenger:messenger]; - FLTThreadSafeEventChannel *threadSafeEventChannel = - [[FLTThreadSafeEventChannel alloc] initWithEventChannel:eventChannel]; _imageStreamHandler = [[FLTImageStreamHandler alloc] init]; - [threadSafeEventChannel setStreamHandler:_imageStreamHandler]; + [eventChannel setStreamHandler:_imageStreamHandler]; _isStreamingImages = YES; } else { @@ -1290,10 +1285,10 @@ - (void)setUpCaptureSessionForAudio { @end @interface CameraPlugin () -@property(readonly, nonatomic) FLTThreadSafeTextureRegistry *registry; +@property(readonly, nonatomic) NSObject *registry; @property(readonly, nonatomic) NSObject *messenger; @property(readonly, nonatomic) FLTCam *camera; -@property(readonly, nonatomic) FLTThreadSafeMethodChannel *deviceEventMethodChannel; +@property(readonly, nonatomic) FlutterMethodChannel *deviceEventMethodChannel; @end @implementation CameraPlugin { @@ -1313,7 +1308,7 @@ - (instancetype)initWithRegistry:(NSObject *)registry messenger:(NSObject *)messenger { self = [super init]; NSAssert(self, @"super init cannot be nil"); - _registry = [[FLTThreadSafeTextureRegistry alloc] initWithTextureRegistry:registry]; + _registry = registry; _messenger = messenger; [self initDeviceEventMethodChannel]; [self startOrientationListener]; @@ -1321,11 +1316,9 @@ - (instancetype)initWithRegistry:(NSObject *)registry } - (void)initDeviceEventMethodChannel { - FlutterMethodChannel *methodChannel = + _deviceEventMethodChannel = [FlutterMethodChannel methodChannelWithName:@"flutter.io/cameraPlugin/device" binaryMessenger:_messenger]; - _deviceEventMethodChannel = - [[FLTThreadSafeMethodChannel alloc] initWithMethodChannel:methodChannel]; } - (void)startOrientationListener { @@ -1424,7 +1417,7 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call if (_camera) { [_camera close]; } - int64_t textureId = [self.registry registerTextureSync:cam]; + int64_t textureId = [self.registry registerTexture:cam]; _camera = cam; [result sendSuccessWithData:@{ @"cameraId" : @(textureId), @@ -1453,10 +1446,8 @@ - (void)handleMethodCallAsync:(FlutterMethodCall *)call methodChannelWithName:[NSString stringWithFormat:@"flutter.io/cameraPlugin/camera%lu", (unsigned long)cameraId] binaryMessenger:_messenger]; - FLTThreadSafeMethodChannel *threadSafeMethodChannel = - [[FLTThreadSafeMethodChannel alloc] initWithMethodChannel:methodChannel]; - _camera.methodChannel = threadSafeMethodChannel; - [threadSafeMethodChannel + _camera.methodChannel = methodChannel; + [methodChannel invokeMethod:@"initialized" arguments:@{ @"previewWidth" : @(_camera.previewSize.width), diff --git a/packages/camera/camera/ios/Classes/FLTThreadSafeEventChannel.h b/packages/camera/camera/ios/Classes/FLTThreadSafeEventChannel.h deleted file mode 100644 index dd84a6733d64..000000000000 --- a/packages/camera/camera/ios/Classes/FLTThreadSafeEventChannel.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * Wrapper for FlutterEventChannel that always sends events on the main thread - */ -@interface FLTThreadSafeEventChannel : NSObject - -/** - * Creates a FLTThreadSafeEventChannel by wrapping a FlutterEventChannel object. - * @param channel The FlutterEventChannel object to be wrapped. - */ -- (instancetype)initWithEventChannel:(FlutterEventChannel *)channel; - -/* - * Registers a handler for stream setup requests from the Flutter side on main thread. - */ -- (void)setStreamHandler:(nullable NSObject *)handler; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/camera/camera/ios/Classes/FLTThreadSafeEventChannel.m b/packages/camera/camera/ios/Classes/FLTThreadSafeEventChannel.m deleted file mode 100644 index 418d83c37849..000000000000 --- a/packages/camera/camera/ios/Classes/FLTThreadSafeEventChannel.m +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "FLTThreadSafeEventChannel.h" - -@implementation FLTThreadSafeEventChannel { - FlutterEventChannel *_channel; -} - -- (instancetype)initWithEventChannel:(FlutterEventChannel *)channel { - self = [super init]; - if (self) { - _channel = channel; - } - return self; -} - -- (void)setStreamHandler:(NSObject *)handler { - if (!NSThread.isMainThread) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self->_channel setStreamHandler:handler]; - }); - } else { - [_channel setStreamHandler:handler]; - } -} - -@end diff --git a/packages/camera/camera/ios/Classes/FLTThreadSafeMethodChannel.h b/packages/camera/camera/ios/Classes/FLTThreadSafeMethodChannel.h deleted file mode 100644 index db99d0f7f66a..000000000000 --- a/packages/camera/camera/ios/Classes/FLTThreadSafeMethodChannel.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * Wrapper for FlutterMethodChannel that always invokes messages on the main thread - */ -@interface FLTThreadSafeMethodChannel : NSObject - -/** - * Creates a FLTThreadSafeMethodChannel by wrapping a FlutterMethodChannel object. - * @param channel The FlutterMethodChannel object to be wrapped. - */ -- (instancetype)initWithMethodChannel:(FlutterMethodChannel *)channel; - -/** - * Invokes the specified flutter method with the specified arguments on main thread. - */ -- (void)invokeMethod:(NSString *)method arguments:(nullable id)arguments; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/camera/camera/ios/Classes/FLTThreadSafeMethodChannel.m b/packages/camera/camera/ios/Classes/FLTThreadSafeMethodChannel.m deleted file mode 100644 index e62fd5bb3af8..000000000000 --- a/packages/camera/camera/ios/Classes/FLTThreadSafeMethodChannel.m +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "FLTThreadSafeMethodChannel.h" - -@implementation FLTThreadSafeMethodChannel { - FlutterMethodChannel *_channel; -} - -- (instancetype)initWithMethodChannel:(FlutterMethodChannel *)channel { - self = [super init]; - if (self) { - _channel = channel; - } - return self; -} - -- (void)invokeMethod:(NSString *)method arguments:(id)arguments { - if (!NSThread.isMainThread) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self->_channel invokeMethod:method arguments:arguments]; - }); - } else { - [_channel invokeMethod:method arguments:arguments]; - } -} - -@end diff --git a/packages/camera/camera/ios/Classes/FLTThreadSafeTextureRegistry.h b/packages/camera/camera/ios/Classes/FLTThreadSafeTextureRegistry.h deleted file mode 100644 index 34ee4400bcc1..000000000000 --- a/packages/camera/camera/ios/Classes/FLTThreadSafeTextureRegistry.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import - -NS_ASSUME_NONNULL_BEGIN - -/** - * Wrapper for FlutterTextureRegistry that always sends events on the main thread - */ -@interface FLTThreadSafeTextureRegistry : NSObject - -/** - * Creates a FLTThreadSafeTextureRegistry by wrapping an object conforming to - * FlutterTextureRegistry. - * @param registry The FlutterTextureRegistry object to be wrapped. - */ -- (instancetype)initWithTextureRegistry:(NSObject *)registry; - -/** - * Registers a `FlutterTexture` for usage in Flutter and returns an id that can be used to reference - * that texture when calling into Flutter with channels. Textures must be registered on the - * main thread. On success returns the pointer to the registered texture, else returns 0. - * - * Runs on main thread. - */ -- (int64_t)registerTextureSync:(NSObject *)texture; - -/** - * Notifies Flutter that the content of the previously registered texture has been updated. - * - * This will trigger a call to `-[FlutterTexture copyPixelBuffer]` on the raster thread. - * - * Runs on main thread. - */ -- (void)textureFrameAvailable:(int64_t)textureId; - -/** - * Unregisters a `FlutterTexture` that has previously regeistered with `registerTexture:`. Textures - * must be unregistered on the main thread. - * - * Runs on main thread. - * - * @param textureId The result that was previously returned from `registerTexture:`. - */ -- (void)unregisterTexture:(int64_t)textureId; - -@end - -NS_ASSUME_NONNULL_END diff --git a/packages/camera/camera/ios/Classes/FLTThreadSafeTextureRegistry.m b/packages/camera/camera/ios/Classes/FLTThreadSafeTextureRegistry.m deleted file mode 100644 index 103c61cce6fd..000000000000 --- a/packages/camera/camera/ios/Classes/FLTThreadSafeTextureRegistry.m +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#import "FLTThreadSafeTextureRegistry.h" - -@implementation FLTThreadSafeTextureRegistry { - NSObject *_registry; -} - -- (instancetype)initWithTextureRegistry:(NSObject *)registry { - self = [super init]; - if (self) { - _registry = registry; - } - return self; -} - -- (int64_t)registerTextureSync:(NSObject *)texture { - if (!NSThread.isMainThread) { - __block int64_t textureId; - // We cannot use async API (with completion block) because completion block does not work for - // separate functions (e.g. `dispose` and `create` are separately registered functions). It's - // hard to tell if the developers had made implicit assumption of the synchronous nature of the - // original API when implementing this plugin. Use dispatch_sync to keep - // FlutterTextureRegistry's sychronous API, so that we don't introduce new potential race - // conditions. We do not break priority inversion here since it's the background thread waiting - // for main thread. - dispatch_sync(dispatch_get_main_queue(), ^{ - textureId = [self->_registry registerTexture:texture]; - }); - return textureId; - } else { - return [_registry registerTexture:texture]; - } -} - -- (void)textureFrameAvailable:(int64_t)textureId { - if (!NSThread.isMainThread) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self->_registry textureFrameAvailable:textureId]; - }); - } else { - [_registry textureFrameAvailable:textureId]; - } -} - -- (void)unregisterTexture:(int64_t)textureId { - if (!NSThread.isMainThread) { - dispatch_async(dispatch_get_main_queue(), ^{ - [self->_registry unregisterTexture:textureId]; - }); - } else { - [_registry unregisterTexture:textureId]; - } -} - -@end diff --git a/packages/camera/camera/ios/Classes/camera-umbrella.h b/packages/camera/camera/ios/Classes/camera-umbrella.h index c55276e31147..b0fd493b24df 100644 --- a/packages/camera/camera/ios/Classes/camera-umbrella.h +++ b/packages/camera/camera/ios/Classes/camera-umbrella.h @@ -4,10 +4,7 @@ #import #import -#import #import -#import -#import FOUNDATION_EXPORT double cameraVersionNumber; FOUNDATION_EXPORT const unsigned char cameraVersionString[];