Skip to content

Commit

Permalink
Merge branch 'video-single-cb-android' of github.com:spoonconsulting/…
Browse files Browse the repository at this point in the history
…cordova-plugin-simple-camera-preview into video-single-cb-android
  • Loading branch information
dinitri committed Jul 16, 2024
2 parents e0188d3 + 3c7ffc7 commit 4945379
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 40 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [2.0.22](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.21...v2.0.22) (2024-07-12)
* **iOS:** Release memory when exiting capture preview

## [2.0.21](https://github.com/spoonconsulting/cordova-plugin-simple-camera-preview/compare/v2.0.20...v2.0.21) (2024-07-05)
* **iOS:** Release memory consumption

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@spoonconsulting/cordova-plugin-simple-camera-preview",
"version": "2.0.21",
"version": "2.0.22",
"description": "Cordova plugin that allows camera interaction from HTML code for showing camera preview below or on top of the HTML.",
"keywords": [
"cordova",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<plugin id="@spoonconsulting/cordova-plugin-simple-camera-preview" version="2.0.21" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<plugin id="@spoonconsulting/cordova-plugin-simple-camera-preview" version="2.0.22" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">

<name>cordova-plugin-simple-camera-preview</name>
<description>Cordova plugin that allows camera interaction from HTML code. Show camera preview popup on top of the HTML.</description>
Expand Down
2 changes: 2 additions & 0 deletions src/ios/CameraRenderController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
CVOpenGLESTextureRef _lumaTexture;
}

-(void) deallocateRenderMemory;

@property (nonatomic) CameraSessionManager *sessionManager;
@property (nonatomic) CIContext *ciContext;
@property (nonatomic) CIImage *latestFrame;
Expand Down
44 changes: 11 additions & 33 deletions src/ios/CameraRenderController.m
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,6 @@ - (void) viewWillAppear:(BOOL)animated {
});
}

- (void) viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
[self.view removeFromSuperview];
[EAGLContext setCurrentContext:nil];
self.context = nil;
[self deallocateRenderMemory];
self.ciContext = nil;
}

- (void) appplicationIsActive:(NSNotification *)notification {
dispatch_async(self.sessionManager.sessionQueue, ^{
if (!self.sessionManager.session.running){
Expand All @@ -77,10 +66,6 @@ - (void) appplicationIsActive:(NSNotification *)notification {
}

- (void) applicationEnteredForeground:(NSNotification *)notification {
// dispatch_async(self.sessionManager.sessionQueue, ^{
// NSLog(@"Stopping session");
// [self.sessionManager.session stopRunning];
// });
[self.view removeFromSuperview];
[EAGLContext setCurrentContext:nil];
self.context = nil;
Expand Down Expand Up @@ -157,24 +142,6 @@ -(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMS
}
}

- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];

[EAGLContext setCurrentContext:nil];
self.context = nil;
[self deallocateRenderMemory];
self.ciContext = nil;
CVBufferRelease(_pixelBuffer);
_pixelBuffer = nil;
}

- (void)dealloc {
[EAGLContext setCurrentContext:nil];
self.context = nil;
[self deallocateRenderMemory];
self.ciContext = nil;
}

- (BOOL)shouldAutorotate {
return YES;
}
Expand All @@ -200,6 +167,17 @@ -(void) deallocateRenderMemory {
CFRelease(_videoTextureCache);
_videoTextureCache = nil;
}
if(_lumaTexture) {
CVOpenGLESTextureCacheFlush(_lumaTexture, 0);
CFRelease(_lumaTexture);
_lumaTexture = nil;
}
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationWillEnterForegroundNotification object:nil];
[self.view removeFromSuperview];
[EAGLContext setCurrentContext:nil];
self.context = nil;
self.ciContext = nil;
}

@end
1 change: 1 addition & 0 deletions src/ios/CameraSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ - (void)deallocSession {
if (self.sessionQueue) {
self.sessionQueue = nil;
}
self.device = nil;
}

@end
7 changes: 4 additions & 3 deletions src/ios/SimpleCameraPreview.m
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ - (void) disable:(CDVInvokedUrlCommand*)command {
for(AVCaptureOutput *output in self.sessionManager.session.outputs) {
[self.sessionManager.session removeOutput:output];
}
self.sessionManager.delegate = nil;
[self.sessionManager deallocSession];
self.sessionManager = nil;
dispatch_async(dispatch_get_main_queue(), ^{
[self.cameraRenderController willMoveToParentViewController:nil];
[self.cameraRenderController.view removeFromSuperview];
if(self.viewController.parentViewController != nil) {
[self.cameraRenderController removeFromParentViewController];
}
[self.cameraRenderController removeFromParentViewController];
[self.cameraRenderController deallocateRenderMemory];
self.cameraRenderController = nil;
[self deallocateMemory];
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_OK] callbackId:command.callbackId];
Expand Down Expand Up @@ -236,6 +236,7 @@ - (NSDictionary *)getGPSDictionaryForLocation {
[gps setObject:[formatter stringFromDate:location.timestamp] forKey:(NSString *)kCGImagePropertyGPSTimeStamp];
[formatter setDateFormat:@"yyyy:MM:dd"];
[gps setObject:[formatter stringFromDate:location.timestamp] forKey:(NSString *)kCGImagePropertyGPSDateStamp];
formatter = nil;

// Latitude
CGFloat latitude = location.coordinate.latitude;
Expand Down

0 comments on commit 4945379

Please sign in to comment.