java - Activity messed after playing YUV video use opengles on Android -
i use opengl es jni play yuv video, video ok.
but when close glsurfaceview , return main activity.
the characters , images display in main activity become messed.
all icons becomes black solid rectangle. characters becomes white solid rectangle.
the code likes come webrtc , modified else. i'm c programmer , not familiar opengl. it's big problem me solve problem.
i create handle in jni this:
bool isattached = false; jnienv* env = null; if (_jvm->getenv((void**) &env, jni_version_1_4) != jni_ok) { // try attach thread , env // attach thread jvm jint res = _jvm->attachcurrentthread(&env, null); // jni env thread if ((res < 0) || !env) { loge("%s: not attach thread jvm (%d, %p)", __function__, res, env); return -1; } isattached = true; } // vieandroidgles20 class jclass javarenderclasslocal = reinterpret_cast<jclass> (env->findclass("com/wg/rgc/library/gl/vieandroidgles20")); if (!javarenderclasslocal) { loge("%s: not find vieandroidgles20", __function__); return -1; } _javarenderclass = reinterpret_cast<jclass> (env->newglobalref(javarenderclasslocal)); if (!_javarenderclass) { loge("%s: not create java surfaceholder class reference", __function__); return -1; } // delete local class ref, use global ref env->deletelocalref(javarenderclasslocal); jmethodid ciduseopengl = env->getstaticmethodid(_javarenderclass, "useopengl2", "(ljava/lang/object;)z"); if (ciduseopengl == null) { loge("%s: not useopengl id", __function__); return false; } jboolean res = env->callstaticbooleanmethod(_javarenderclass, ciduseopengl, (jobject) _ptrwindow); // create reference object (to tell jni referencing // after function has returned) _javarenderobj = reinterpret_cast<jobject> (env->newglobalref((jobject)_ptrwindow)); if (!_javarenderobj) { loge("%s: not create java surfacerender object reference", __function__); return -1; } // method id redraw function _redrawcid = env->getmethodid(_javarenderclass, "redraw", "()v"); if (_redrawcid == null) { loge("%s: not redraw id", __function__); return -1; } _registernativecid = env->getmethodid(_javarenderclass, "registernativeobject", "(j)v"); if (_registernativecid == null) { loge("%s: not registernativeobject id", __function__); return -1; } _deregisternativecid = env->getmethodid(_javarenderclass, "deregisternativeobject", "()v"); if (_deregisternativecid == null) { loge("%s: not deregisternativeobject id", __function__); return -1; } jninativemethod nativefunctions[2] = { { "drawnative", "(j)v", (void*) &androidnativeopengl2channel::drawnativestatic, }, { "createopenglnative", "(jii)i", (void*) &androidnativeopengl2channel::createopenglnativestatic }, }; if (env->registernatives(_javarenderclass, nativefunctions, 2) == 0) { loge("%s: registered native functions", __function__); } else { loge("%s: failed register native functions", __function__); return -1; } env->callvoidmethod(_javarenderobj, _registernativecid, (jlong) this); if (isattached) { if (_jvm->detachcurrentthread() < 0) { loge("%s: not detach thread jvm", __function__); } } loge("%s done", __function__); if (_openglrenderer.setcoordinates(0, 1.0, 1.0, 0, 0) != 0) { return -1; } isalreadyinit = 1; //init finish return 0;
and close handle in jni this:
bool isattached = false; jnienv* env = null; if (_jvm->getenv((void**) &env, jni_version_1_4) != jni_ok) { // try attach thread , env // attach thread jvm jint res = _jvm->attachcurrentthread(&env, null); // jni env thread if ((res < 0) || !env) { loge("%s: not attach thread jvm (%d, %p)", __function__, res, env); env = null; } else { isattached = true; } } if (env && _deregisternativecid) { env->callvoidmethod(_javarenderobj, _deregisternativecid); } env->deleteglobalref(_javarenderobj); env->deleteglobalref(_javarenderclass); if (isattached) { if (_jvm->detachcurrentthread() < 0) { loge("%s: not detach thread jvm", __function__); } }
the method env->callvoidmethod(_javarenderobj, _deregisternativecid); called java method in java src:
nativefunctionlock.lock(); nativefunctionsregisted = false; openglcreated = false; this.nativeobject = 0; nativefunctionlock.unlock();
the code in java src looks extends glsurfaceview , implements glsurfaceview.renderer. in jni code registered method native method in java. code complicated me understand , boss request me fix problem quickly. can't figure out why after playing yuv video , every image , characters become rectangles. how did happen?
you delete texture after rendering, can try keep them, , deallocate them when app terminated
Comments
Post a Comment