fix: Make HardwareBuffers compile optionally (opt-out in minSdkVersion <26) (#1910)
* fix: Make HardwareBuffers compile optionally * chore: Format C++ code * fix: Fix if
This commit is contained in:
parent
83c0cdb030
commit
8d90dcc476
@ -85,6 +85,7 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr
|
|||||||
if (name == "toArrayBuffer") {
|
if (name == "toArrayBuffer") {
|
||||||
jsi::HostFunctionType toArrayBuffer = [=](jsi::Runtime& runtime, const jsi::Value& thisArg, const jsi::Value* args,
|
jsi::HostFunctionType toArrayBuffer = [=](jsi::Runtime& runtime, const jsi::Value& thisArg, const jsi::Value* args,
|
||||||
size_t count) -> jsi::Value {
|
size_t count) -> jsi::Value {
|
||||||
|
#if __ANDROID_API__ >= 26
|
||||||
AHardwareBuffer* hardwareBuffer = this->frame->getHardwareBuffer();
|
AHardwareBuffer* hardwareBuffer = this->frame->getHardwareBuffer();
|
||||||
|
|
||||||
AHardwareBuffer_Desc bufferDescription;
|
AHardwareBuffer_Desc bufferDescription;
|
||||||
@ -120,6 +121,9 @@ jsi::Value FrameHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& pr
|
|||||||
AHardwareBuffer_release(hardwareBuffer);
|
AHardwareBuffer_release(hardwareBuffer);
|
||||||
|
|
||||||
return arrayBuffer;
|
return arrayBuffer;
|
||||||
|
#else
|
||||||
|
throw jsi::JSError(runtime, "Frame.toArrayBuffer() is only available if minSdkVersion is set to 26 or higher!");
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forUtf8(runtime, "toArrayBuffer"), 0, toArrayBuffer);
|
return jsi::Function::createFromHostFunction(runtime, jsi::PropNameID::forUtf8(runtime, "toArrayBuffer"), 0, toArrayBuffer);
|
||||||
}
|
}
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
#include "JFrame.h"
|
#include "JFrame.h"
|
||||||
|
|
||||||
#include <android/hardware_buffer_jni.h>
|
|
||||||
#include <fbjni/ByteBuffer.h>
|
|
||||||
#include <fbjni/fbjni.h>
|
#include <fbjni/fbjni.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include <android/hardware_buffer_jni.h>
|
||||||
|
|
||||||
namespace vision {
|
namespace vision {
|
||||||
|
|
||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
@ -59,11 +59,13 @@ int JFrame::getBytesPerRow() const {
|
|||||||
return getBytesPerRowMethod(self());
|
return getBytesPerRowMethod(self());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if __ANDROID_API__ >= 26
|
||||||
AHardwareBuffer* JFrame::getHardwareBuffer() const {
|
AHardwareBuffer* JFrame::getHardwareBuffer() const {
|
||||||
static const auto getHardwareBufferMethod = getClass()->getMethod<jobject()>("getHardwareBufferBoxed");
|
static const auto getHardwareBufferMethod = getClass()->getMethod<jobject()>("getHardwareBufferBoxed");
|
||||||
auto hardwareBuffer = getHardwareBufferMethod(self());
|
auto hardwareBuffer = getHardwareBufferMethod(self());
|
||||||
return AHardwareBuffer_fromHardwareBuffer(jni::Environment::current(), hardwareBuffer.get());
|
return AHardwareBuffer_fromHardwareBuffer(jni::Environment::current(), hardwareBuffer.get());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void JFrame::incrementRefCount() {
|
void JFrame::incrementRefCount() {
|
||||||
static const auto incrementRefCountMethod = getClass()->getMethod<void()>("incrementRefCount");
|
static const auto incrementRefCountMethod = getClass()->getMethod<void()>("incrementRefCount");
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <android/hardware_buffer.h>
|
|
||||||
#include <fbjni/ByteBuffer.h>
|
|
||||||
#include <fbjni/fbjni.h>
|
#include <fbjni/fbjni.h>
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
|
#include <android/hardware_buffer.h>
|
||||||
|
|
||||||
namespace vision {
|
namespace vision {
|
||||||
|
|
||||||
using namespace facebook;
|
using namespace facebook;
|
||||||
@ -27,7 +27,10 @@ public:
|
|||||||
jlong getTimestamp() const;
|
jlong getTimestamp() const;
|
||||||
local_ref<JString> getOrientation() const;
|
local_ref<JString> getOrientation() const;
|
||||||
local_ref<JString> getPixelFormat() const;
|
local_ref<JString> getPixelFormat() const;
|
||||||
|
#if __ANDROID_API__ >= 26
|
||||||
AHardwareBuffer* getHardwareBuffer() const;
|
AHardwareBuffer* getHardwareBuffer() const;
|
||||||
|
#endif
|
||||||
|
|
||||||
void incrementRefCount();
|
void incrementRefCount();
|
||||||
void decrementRefCount();
|
void decrementRefCount();
|
||||||
void close();
|
void close();
|
||||||
|
Loading…
Reference in New Issue
Block a user