Reputation: 41
In Android Java side, following code can be used to output the mediacodec
to a GL texture.
int [] hTex = new int[1];
GLES20.glGenTextures(1, hTex, 0);
SurfaceTexture mSTexture = new SurfaceTexture(hTex[0]);
Surface s = new Surface(mSTexture);
mPlayer = new PlayerThread(s);
But how to do that in NDK?
I can useglGenTextures
to create a GL texture, but the param type of AMediaCodec_configure
is ANativeWindow*
, is there a way to convert it?
Upvotes: 2
Views: 1724
Reputation: 11
The project I am recently working on also has to get the ANativeWindow* from a gl texture. Here is how I did it with JNI:
First, get a surfacetexture 'jobject' from your gl texture
jclass surfacetexture_class = Env->FindClass("android/graphics/SurfaceTexture");
jmethodID surfacetexture_init = Env->GetMethodID(surfacetexture_class, "<init>", "(I)V");
jobject surfacetexture_obj = Env->NewObject(surfacetexture_class, surfacetexture_init, (jint)your_gl_texture);
Then, convert the jobject surfacetexture to native ASurfaceTexture* using ASurfaceTexture_fromSurfaceTexture(Env, surfacetexture_obj)
Finally, ASurfaceTexture_acquireANativeWindow(surfacetexture)
gives you the ANativeWindow* associated with your gl texture
Upvotes: 1