Note that there are some explanatory texts on larger screens.

plurals
  1. POSurfaceTexture updateTexImage to shared 2 EGLContexts - Problems on Android 4.4
    primarykey
    data
    text
    <p>I am referring to this excellent example of how to encode the preview frames of the camera directly into an mp4 file: <a href="http://bigflake.com/mediacodec/CameraToMpegTest.java.txt" rel="nofollow">http://bigflake.com/mediacodec/CameraToMpegTest.java.txt</a></p> <p>I have adopted the code in the way that I also would like to render the preview image on the screen. Therefore I got something like a GLTextureView with its own EGLContext. This Context is then used as shared EGLContext when I create the EGLContext for the encoder rendering:</p> <pre><code>mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext, attrib_list, 0); </code></pre> <p>In my render-loop I followed the tip of fadden... for every frame I do the following:</p> <ol> <li>first I wait for the new image to arrive on the SurfaceTexture with awaitNewImage()</li> <li>then I set the GLTextureView's context current and render the frame on it</li> <li>after that I set the encoders context current and render the frame on it</li> </ol> <p>This looks something like that:</p> <pre><code>mFrameWatcher.awaitNewImage(); mSurfaceTexture.updateTexImage(); _textureView.getEGLManager().makeCurrent(); _textureView.requestRender(); mInputSurface.makeCurrent(); mInputSurface.requestRender(); </code></pre> <p>This worked well while I tested it only on my Nexus 4 with Android 4.3.</p> <p>However, since I got the new Nexus 5 with Android 4.4 the encoder only gets 2 different frames per second from the SurfaceTexture... but these 2 frames are repeatedly drawn... so he encodes 15 times the same frame. ALTHOUGH the frames are rendered correct to my GLTextureView with 30 different frames per second. I first thought this might be a Nexus 5 problem - so I updated another Nexus 4 to Android 4.4... but it is the same on the Nexus 4 now.</p> <p>I played around a bit - and finally I was able to solve the problem, by detaching and re-attaching the SurfaceTexture to the different context's when I switch them. This looks something like this:</p> <pre><code>mFrameWatcher.awaitNewImage(); mSurfaceTexture.updateTexImage(); _textureView.getEGLManager().makeCurrent(); _textureView.requestRender(); mSurfaceTexture.detachFromGLContext(); mInputSurface.makeCurrent(); mSurfaceTexture.attachToGLContext(_textureViewRenderer.getTextureId()); mInputSurface.requestRender(); mSurfaceTexture.detachFromGLContext(); _textureView.getEGLManager().makeCurrent(); mSurfaceTexture.attachToGLContext(_textureViewRenderer.getTextureId()); </code></pre> <p>My question now is: Is this the correct way to do this? Honestly I thought the re-attaching of the SurfaceTexture should not be necessary when I use shared contexts. Also the re-attaching takes quite a long time... 3-6 ms for every frame with peeks on 12 ms, which could be better used for rendering. Am I doing/understanding somethind wrong here? Why did it work like a charm on the Nexus 4 with 4.3 without the need to re-attach the SurfaceTexture?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload