I have an app that manages its own GLSurfaceView and now I want to use Android 4.3\'s new MediaCodec feature that takes a Surface as input.
In all the examples I\'ve see
No, it doesn't work that way. The input surface must be created with createInputSurface()
.
Bear in mind that a "surface" isn't a buffer of data, it's a queue of buffers for which the producer and consumer endpoints are often in different processes. There are a lot of moving pieces that need to be set up. Also note that Surface
and EGLSurface
are two different things that, while often used together, aren't closely related.
The API seems lumpy and weird because... it is. The implementation of Surface
has changed quite a bit over the years -- the underpinnings used to be far less general, so most of the APIs for altering endpoints aren't exposed. The (underspecified) MediaCodec
API is still evolving.
There's an example of presenting the same content (camera preview) to GLSurfaceView
and MediaCodec
in Grafika. It sounds like you're trying to do something similar. (If not, update your question, and I'll update the answer.)