android - Playing Video with OpenGL and MediaCodec -


i'm trying play same video @ same time in 2 different textureviews. i've used code grafika (movieplayer , continuouscaptureactivity) try work (thanks fadden). make problem simpler, i'm trying 1 textureview first.

at moment i've created textureview, , once surfacetexture, create windowsurface , make current. generate textureid generated using fullframerect object.

@override public void onsurfacetextureavailable(surfacetexture surface, int         width, int height) {     msurfacetexture = surface;     meglcore = new eglcore(null, eglcore.flag_try_gles3);     log.d("eglcore", "egl core made");     mdisplaysurface = new windowsurface(meglcore, msurfacetexture);     mdisplaysurface.makecurrent();     log.d("displaysurface", "mdisplaysurface made");     mfullframeblit = new fullframerect(new texture2dprogram(texture2dprogram.programtype.texture_ext));     mtextureid = mfullframeblit.createtextureobject();      //msurfacetexture.attachtoglcontext(mtextureid);     clickplaystop(null); } 

then off-screen surfacetexture, link textureid got above , create surface pass movieplayer thus:

public void clickplaystop(@suppresswarnings("unused") view unused) {     if (mshowstoplabel) {         log.d(tag, "stopping movie");         stopplayback();         // don't update controls here -- let task thread after movie has         // stopped.         //mshowstoplabel = false;         //updatecontrols();     } else {         if (mplaytask != null) {             log.w(tag, "movie playing");             return;         }         log.d(tag, "starting movie");         speedcontrolcallback callback = new speedcontrolcallback();         callback.setfixedplaybackrate(24);          movieplayer player = null;         movietexture = new surfacetexture(mtextureid);         movietexture.setonframeavailablelistener(this);         surface surface = new surface(movietexture);         try {             player = new movieplayer(surface, callback, this);//todo         } catch (ioexception ioe) {             log.e(tag, "unable play movie", ioe);              return;         }          adjustaspectratio(player.getvideowidth(), player.getvideoheight());          mplaytask = new movieplayer.playtask(player, this);         mplaytask.setloopmode(true);           mshowstoplabel = true;         mplaytask.execute();     } } 

the idea surfacetexture gets raw frame can use oes_external texture sample opengl. can call drawframe() eglcontext after setting windowsurface current.

private void drawframe() {     log.d(tag, "drawframe");     if (meglcore == null) {         log.d(tag, "skipping drawframe after shutdown");         return;     }      // latch next frame camera.     mdisplaysurface.makecurrent();     movietexture.updateteximage();     movietexture.gettransformmatrix(mtransformmatrix);      // fill windowsurface it.     int viewwidth = mtextureview.getwidth();     int viewheight = mtextureview.getheight();     gles20.glviewport(0, 0, viewwidth, viewheight);     mfullframeblit.drawframe(mtextureid, mtransformmatrix);     mdisplaysurface.swapbuffers(); } 

if wanted 2 textureviews, idea call makecurrent() , draw each buffer each view, call swapbuffers() after drawing done.

this want do, pretty sure not code doing. me understand need change make work?

@fadden

update: interesting. changed code in onsurfacetextureavailable this:

@override public void onsurfacetextureavailable(surfacetexture surface, int         width, int height) {     msurfacetexture = surface;     textureheight = height;     texturewidth = width;     //meglcore = new eglcore(null, eglcore.flag_try_gles3);     log.d("eglcore", "egl core made");     //mdisplaysurface = new windowsurface(meglcore, msurfacetexture);     //mdisplaysurface.makecurrent();     log.d("displaysurface", "mdisplaysurface made");     //mfullframeblit = new fullframerect(new texture2dprogram(texture2dprogram.programtype.opengl_test));     //mtextureid = mfullframeblit.createtextureobject();     //clickplaystop(null);       // fill surfaceview it.     //int viewwidth = width;     //int viewheight = height;     //gles20.glviewport(0, 0, viewwidth, viewheight);     //mfullframeblit.drawframe(mtextureid, mtransformmatrix);     //mfullframeblit.opengltest();     //mfullframeblit.testdraw(mdisplaysurface.getheight(),mdisplaysurface.getwidth());     //mdisplaysurface.swapbuffers(); } 

so, shouldn't call else, show empty textureview - , see...

empty textureview

thanks fadden help.

so there seemed unknown issue resolved when used new thread decode , produce frames. haven't found out caused original problem, have found way around it.


Comments