Search code examples
androidopengl-esandroid-ndkandroid-image

How does Android's ImageWriter work under the hood?


I have a custom Camera2 OpenGL pipeline to process frames from a Camera device.

I have two target EGLSurfaces that I just send the EXTERNAL_OES OpenGL texture to using a pass-through Shader. This is pretty efficient, but I found the ImageWriter API from Android and it seems to do exactly what I am doing with my OpenGL pipeline - just with way less code.

I'm wondering how this compares to an OpenGL pipeline? Does ImageWriter have any other kind of extra features or optimizations? Does ImageWriter skip the PRIVATE -> RGB conversion that happens in an EXTERNAL_OES OpenGL texture?

Is it recommended to switch to ImageWriter instead of my custom C++ OpenGL pipeline?


Solution

  • An OpenGL pipeline loads the camera frames as textures into the GPU, lets you apply any sort of rendering effect to them, and then lets you output the resulting frames to wherever you're wanting them to go.

    An ImageWriter is just a queue of Android graphics buffers. It doesn't do anything besides move buffers from producer A to consumer B.

    So what is the purpose of your OpenGL pipeline? If you're not applying any edits in your shader code, why does it exist? For making multiple copies of your input frames, or to convert the frames to RGB? Or something else? ImageWriter is more power-efficient since it doesn't need to spin up the GPU to do work, but it's much less flexible and capable than EGL.