fix: Fix crash when accessing planesCount
or bytesPerRow
(#380)
* fix: Fix `bytesPerRow` and `planeCount` crashing * use direct call * Call `getPlanesCount` and `getBytesPerRow` through java * revert camerapage changes * remove removed header import * Update CameraPage.tsx
This commit is contained in:
parent
d06bcf648c
commit
0d3f2cbd9d
@ -22,25 +22,27 @@ int JImageProxy::getHeight() {
|
||||
return getWidthMethod(self());
|
||||
}
|
||||
|
||||
alias_ref<JClass> getUtilsClass() {
|
||||
static const auto ImageProxyUtilsClass = findClassStatic("com/mrousavy/camera/frameprocessor/ImageProxyUtils");
|
||||
return ImageProxyUtilsClass;
|
||||
}
|
||||
|
||||
bool JImageProxy::getIsValid() {
|
||||
static const auto utilsClass = findClassStatic("com/mrousavy/camera/frameprocessor/ImageProxyUtils");
|
||||
auto utilsClass = getUtilsClass();
|
||||
static const auto isImageProxyValidMethod = utilsClass->getStaticMethod<jboolean(JImageProxy::javaobject)>("isImageProxyValid");
|
||||
return isImageProxyValidMethod(utilsClass, self());
|
||||
}
|
||||
|
||||
int JImageProxy::getPlaneCount() {
|
||||
static const auto getPlanesMethod = getClass()->getMethod<JArrayClass<jobject>()>("getPlanes");
|
||||
auto planes = getPlanesMethod(self());
|
||||
return planes->size();
|
||||
int JImageProxy::getPlanesCount() {
|
||||
auto utilsClass = getUtilsClass();
|
||||
static const auto getPlanesCountMethod = utilsClass->getStaticMethod<jint(JImageProxy::javaobject)>("getPlanesCount");
|
||||
return getPlanesCountMethod(utilsClass, self());
|
||||
}
|
||||
|
||||
int JImageProxy::getBytesPerRow() {
|
||||
static const auto getPlanesMethod = getClass()->getMethod<JArrayClass<jobject>()>("getPlanes");
|
||||
auto planes = getPlanesMethod(self());
|
||||
auto firstPlane = planes->getElement(0);
|
||||
|
||||
static const auto getRowStrideMethod = findClassLocal("android/media/Image$PlaneProxy")->getMethod<int()>("getRowStride");
|
||||
return getRowStrideMethod(firstPlane.get());
|
||||
auto utilsClass = getUtilsClass();
|
||||
static const auto getBytesPerRowMethod = utilsClass->getStaticMethod<jint(JImageProxy::javaobject)>("getBytesPerRow");
|
||||
return getBytesPerRowMethod(utilsClass, self());
|
||||
}
|
||||
|
||||
void JImageProxy::close() {
|
||||
|
@ -16,7 +16,7 @@ struct JImageProxy : public facebook::jni::JavaClass<JImageProxy> {
|
||||
int getWidth();
|
||||
int getHeight();
|
||||
bool getIsValid();
|
||||
int getPlaneCount();
|
||||
int getPlanesCount();
|
||||
int getBytesPerRow();
|
||||
void close();
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ jsi::Value JImageProxyHostObject::get(jsi::Runtime& runtime, const jsi::PropName
|
||||
}
|
||||
if (name == "planesCount") {
|
||||
this->assertIsFrameStrong(runtime, name);
|
||||
return jsi::Value(this->frame->getPlaneCount());
|
||||
return jsi::Value(this->frame->getPlanesCount());
|
||||
}
|
||||
|
||||
return jsi::Value::undefined();
|
||||
|
@ -7,6 +7,7 @@ import androidx.annotation.Keep;
|
||||
import androidx.camera.core.ImageProxy;
|
||||
import com.facebook.proguard.annotations.DoNotStrip;
|
||||
|
||||
@SuppressWarnings("unused") // used through JNI
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
public class ImageProxyUtils {
|
||||
@ -26,4 +27,16 @@ public class ImageProxyUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
public static int getPlanesCount(ImageProxy imageProxy) {
|
||||
return imageProxy.getPlanes().length;
|
||||
}
|
||||
|
||||
@DoNotStrip
|
||||
@Keep
|
||||
public static int getBytesPerRow(ImageProxy imageProxy) {
|
||||
return imageProxy.getPlanes()[0].getRowStride();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user