Package 

Class ByteBufferFrameManager


  • 
    public class ByteBufferFrameManager
    extends FrameManager<Array<byte>>
                        

    This class manages the allocation of byte buffers and Frame objects. We are interested in recycling both of them, especially byte[] buffers which can create a lot of overhead. The pool size applies to both the Frame pool and the byte[] pool - it makes sense to use the same number since they are consumed at the same time. We can work in two modes, depending on whether a BufferCallback is passed to the constructor. The modes changes the buffer behavior. 1. BUFFER_MODE_DISPATCH: in this mode, as soon as we have a buffer, it is dispatched to the BufferCallback. The callback should then fill the buffer, and finally call getFrame to receive a frame. This is used for Camera1. 2. BUFFER_MODE_ENQUEUE: in this mode, the manager internally keeps a queue of byte buffers, instead of handing them to the callback. The users can ask for buffers through getBuffer. This buffer can be filled with data and used to get a frame getFrame, or, in case it was not filled, returned to the queue using onBufferUnused. This is used for Camera2.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      public interface ByteBufferFrameManager.BufferCallback

      Receives callbacks on buffer availability(when a Frame is released, we reuse its buffer).

    • Method Summary

      Modifier and Type Method Description
      void setUp(int format, @NonNull() Size size, @NonNull() Angles angles) Allocates a mPoolSize number of buffers.
      Array<byte> getBuffer() Returns a new byte buffer than can be filled.
      void onBufferUnused(@NonNull() Array<byte> buffer) Can be called if the buffer obtained by getBuffer was not used to construct a frame, so it can be put back into the queue.
      void release() Releases all frames controlled by this manager andclears the pool.In BUFFER_MODE_ENQUEUE, releases also all the buffers.
      • Methods inherited from class com.otaliastudios.cameraview.frame.FrameManager

        getFrame, getFrameBytes, getFrameDataClass, getPoolSize
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ByteBufferFrameManager

        ByteBufferFrameManager(int poolSize, ByteBufferFrameManager.BufferCallback callback)
        Construct a new frame manager.
        Parameters:
        poolSize - the size of the backing pool.
        callback - a callback
    • Method Detail

      • setUp

         void setUp(int format, @NonNull() Size size, @NonNull() Angles angles)

        Allocates a mPoolSize number of buffers. Should be called oncethe preview size and the image format value are known.This method can be called again after release has been called.

        Parameters:
        format - the image format
        size - the frame size
        angles - angle object
      • getBuffer

        @Nullable() Array<byte> getBuffer()

        Returns a new byte buffer than can be filled.This can only be called in BUFFER_MODE_ENQUEUE mode! Where the framemanager also holds a queue of the byte buffers.If not null, the buffer returned by this method can be filled and used to geta new frame through getFrame.

      • onBufferUnused

         void onBufferUnused(@NonNull() Array<byte> buffer)

        Can be called if the buffer obtained by getBuffer was not used to construct a frame, so it can be put back into the queue.

        Parameters:
        buffer - a buffer
      • release

         void release()

        Releases all frames controlled by this manager andclears the pool.In BUFFER_MODE_ENQUEUE, releases also all the buffers.