feat: Implement Frame.close()
(#229)
* Implement `Frame.close()` * close frame in dtor * Update JImageProxyHostObject.cpp * fix close * Check if closed * remove a few logs * r * fix `isValid` and `isReady` * Add JImage * Release JNI frame ref on destroy * fix pod setup * Fix isValid call * Fix `close` not returning a function * throw error if closed twice * iOS: Schedule `console.error` call on JS thread * Android: Log Frame Processor Error to JS * fix syntax * Check if valid `toString()` * Update Frame.ts * Remove `isReady` * Fix JImage accessors * remove `JImage` C++ sources * Throw error if accessing props on closed Frame * Delete `JImage.h`
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.mrousavy.camera.frameprocessor;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.media.Image;
|
||||
import androidx.camera.core.ImageProxy;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
public class ImageProxyUtils {
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
@DoNotStrip
|
||||
public static boolean isImageProxyValid(ImageProxy imageProxy) {
|
||||
try {
|
||||
Image image = imageProxy.getImage();
|
||||
if (image == null) return false;
|
||||
// will throw an exception if the image is already closed
|
||||
imageProxy.getImage().getCropRect();
|
||||
// no exception thrown, image must still be valid.
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
// exception thrown, image has already been closed.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user