Render Android MediaCodec output on two views for VR Headset compatibility

586 views Asked by At

What I know so far is that I need to use a SurfaceTexture that can be rendered on two TextureViews simultaneously. So it will be: MediaCodec -> SurfaceTexture -> 2x TextureViews

But how do I get a SurfaceTexture programmaticly to be used in the MediaCodec? As far as I know a new SurfaceTexture is created for every TextureView, so if I have two TextureViews in my activity, I will get two TextureViews!? Thats one to much... ;)

Or is there any other way to render the MediaCodec Output to a screen twice?

1

There are 1 answers

2
fadden On

Do you actually require two TextureViews, or is that just for convenience?

You could, for example, have a single SurfaceView or TextureView that covers the entire screen, and then just render on the left and right sides with GLES. With the video output in a SurfaceTexture, you can render it however you like. The "texture from camera" activity in Grafika demonstrates various ways to manipulate image from a video source.

If you really want two TextureViews, you can have them. Use a single EGL context for the SurfaceTexture and both TextureViews, and just switch between EGL surfaces with eglMakeCurrent() when it's time to render.

In any event, you should be creating your own SurfaceTexture to receive the video, not using one that comes from a TextureView -- see e.g. this bit of code.