Skip to content

Instantly share code, notes, and snippets.

@redj
Last active January 24, 2019 17:20
Show Gist options
  • Save redj/04a058fd095b25dceda5661e36467edb to your computer and use it in GitHub Desktop.
Save redj/04a058fd095b25dceda5661e36467edb to your computer and use it in GitHub Desktop.
#include "debug.eh"
#include <jni.h>
#include <android/log.h>
#define printf(...) ((void)__android_log_print(ANDROID_LOG_INFO, "ecere-app", __VA_ARGS__))
import "androidCamera"
class MySurfaceTextureListener
{
jobject javaInstance;
AndroidCamera camera;
// Add data members as needed...
/*void onFrameAvailable(JNIEnv * env, jobject surfaceTexture)
{
// write some eC code here...
camera.onFrameAvailable(env, surfaceTexture);
}*/
// d
}
default:
static void JNICALL jni_onFrameAvailable(JNIEnv * env, jobject instance, jobject surfaceTexture)
{
jclass cls = (*env)->GetObjectClass(env, instance);
jfieldID fidImpl = (*env)->GetFieldID(env, cls, "impl", "J");
jlong impl = (*env)->GetLongField(env, instance, fidImpl);
MySurfaceTextureListener listener = (MySurfaceTextureListener)(uintptr)impl;
//listener.onFrameAvailable(env, surfaceTexture);
}
static void JNICALL jni_onSurfaceTextureAvailable(JNIEnv * env, jobject instance, jobject surfaceTexture, int width, int height)
{
jclass cls = (*env)->GetObjectClass(env, instance);
jfieldID fidImpl = (*env)->GetFieldID(env, cls, "impl", "J");
jlong impl = (*env)->GetLongField(env, instance, fidImpl);
MySurfaceTextureListener listener = (MySurfaceTextureListener)(uintptr)impl;
//listener.onFrameAvailable(env, surfaceTexture);
}
static void JNICALL jni_onSurfaceTextureSizeChanged(JNIEnv * env, jobject instance, jobject surfaceTexture, int width, int height)
{
}
static boolean JNICALL jni_onSurfaceTextureDestroyed(JNIEnv * env, jobject instance, jobject surfaceTexture)
{
return (boolean)JNI_FALSE;
}
static void JNICALL jni_onSurfaceTextureUpdated(JNIEnv * env, jobject instance, jobject surfaceTexture)
{
}
static jlong JNICALL jni_construct(JNIEnv * env, jobject instance)
{
MySurfaceTextureListener mySurfaceTextureListener { javaInstance = instance }; // Take a reference here?
incref mySurfaceTextureListener;
return (jlong)(uintptr)mySurfaceTextureListener;
}
static void JNICALL jni_destruct(JNIEnv * env, jobject instance, jlong eCinst)
{
MySurfaceTextureListener mySurfaceTextureListener = (MySurfaceTextureListener)(uintptr)eCinst;
mySurfaceTextureListener.javaInstance = null;
delete mySurfaceTextureListener;
}
private:
static JNINativeMethod methods[] =
{
{ "onFrameAvailable", "(Landroid/graphics/SurfaceTexture;)V", (void *)&jni_onFrameAvailable },
{ "onSurfaceTextureAvailable", "(Landroid/graphics/SurfaceTexture;I;I;)V", (void *)&jni_onSurfaceTextureAvailable },
{ "onSurfaceTextureSizeChanged", "(Landroid/graphics/SurfaceTexture;I;I;)V", (void *)&jni_onSurfaceTextureSizeChanged },
{ "onSurfaceTextureDestroyed", "(Landroid/graphics/SurfaceTexture;)B", (void *)&jni_onSurfaceTextureDestroyed },
{ "onSurfaceTextureUpdated", "(Landroid/graphics/SurfaceTexture;)V", (void *)&jni_onSurfaceTextureUpdated },
{ "construct", "()J", (void *)&jni_construct },
{ "destruct", "(J)V", (void *)&jni_destruct }
};
jclass * cMySurfaceTextureListener;
bool registerNativeMySurfaceTextureListener(JNIEnv * env)
{
if(ecjni_getClass(__getloc__, env, false, "com/ecere/hello/MySurfaceTextureListener", &cMySurfaceTextureListener))
(*env)->RegisterNatives(env, cMySurfaceTextureListener, methods, sizeof(methods)/sizeof(methods[0]));
return true;
}
package com.ecere.hello;
import android.graphics.SurfaceTexture;
//import android.os.Handler;
//import android.os.Looper;
import android.view.TextureView;
//public class MySurfaceTextureListener implements SurfaceTexture.OnFrameAvailableListener
public class MySurfaceTextureListener implements SurfaceTexture.OnFrameAvailableListener, TextureView.SurfaceTextureListener
{
private long impl;
public MySurfaceTextureListener() { impl = construct(); }
public void finalize() { destruct(impl); }
private native long construct();
private native void destruct(long impl);
public native void onFrameAvailable(SurfaceTexture surfaceTexture);
public native void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height);
// setUpCamera();
// openCamera();
public native void onSurfaceTextureSizeChanged(SurfaceTexture surfaceTexture, int width, int height);
public native boolean onSurfaceTextureDestroyed(SurfaceTexture surfaceTexture);
// return false;
public native void onSurfaceTextureUpdated(SurfaceTexture surfaceTexture);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment