How to understand the underneath of setDisplay/setSurface/setPrewviewDisplay/setPreviewTexture for Android

感情迁移 提交于 2019-12-11 13:26:00

问题


Since Android api level 1, We can attach a MediaPlayer or Camera to the Surface with setDisplay or setPrewviewDisplay, then image data can be transfered to gpu and processed much faster.

After SurfaceTexture is introduced, We can create our own texture with the target GL_TEXTURE_EXTERNAL_OES and attach the MediaPlayer or Camera to opengl es.

These are well known, but what I want to talk about is the underneath which is about Android graphics architecture.(Android Graphics architecture)

The data produced is on the CPU side, so it must be transferred to GPU in a very fast way.

Why does every Android device transfer the data so fast and how to make it underneath?

Or is this a hardware issue which has nothing to do with Android?


回答1:


The data is not produced on the CPU side. The camera and hardware video codecs store their data in buffers allocated by the kernel gralloc mechanism (referenced from native code through the non-public GraphicBuffer). Surfaces communicate through BufferQueue objects, which pass the frames around by handle, without copying the data itself.

It's up to the OEM to ensure that the camera, video codecs, and GPU can use common formats. The YUV output by the video codec must be something that the GLES implementation can handle as an external texture. This is also why EGL_RECORDABLE_ANDROID is needed when sending GLES rendering to a MediaCodec... need to let the EGL implementation know that the frame it's rendering must be recognizable by the video codec.



来源:https://stackoverflow.com/questions/35236964/how-to-understand-the-underneath-of-setdisplay-setsurface-setprewviewdisplay-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!