How to use the new OnBufferAvailableListener, USAGE_IO_INPUT, ioReceive() and getSurface() in camera based image processing?

StackOverflow https://stackoverflow.com/questions/20122869

  •  03-08-2022
  •  | 
  •  

Question

In Renderscript, creating Allocation with the USAGE_IO_INPUT flag, and then to use ioReceive() and getSurface() function to implement image processing system, e.g. camera based image processing seems to be a mystery. I can't find any complete sample code but just a few evidence online. E.g. Using a SurfaceTexture filled by Camera preview as Renderscript input Allocation in Jelly Bean, RenderScript's Allocation.getSurface() function always complain "call to OpenGL ES API with no current context" and Using SurfaceTexture in combination with RenderScript.

However, none of these posts have real answers. I found in Android 4.4, there's a new interface called OnBufferAvailableListener. According to the limited document, it seems the purpose of this new interface is to provide a way to receive the SurfaceTexture enabled Allocation (since the document says if USAGE_IO_INPUT is set the Allocation will be used as a SurfaceTexture producer) when it gets updated. But the question is, how to setup a mechanism to make such function work? For instance, in Camera API, the setPreviewTexture(SurfaceTexture surfaceTexture) function allows to link the SurfaceTexture to camera and there was a getSurfaceTexture() function in Renderscript Allocation class (at least the @hide function) which generates the SurfaceTexture which may be sent to the camera API. However, now in Android 4.4 this method is no long there (even the @hide is deleted). So how to make Allocation to be the "SurfaceTexture producer"? When and how to use the functions like ioReceive() and getSurface(). When and how to use the new OnBufferAvailableListener?

I might get the whole picture wrong. If that's the case, would you tell me the circumstances where the set of USAGE_IO_INPUT related API could be used? Thank you very much in advance!

Was it helpful?

Solution

There are no Camera APIs yet producing the necessary buffers. Stay tuned.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top