BufferPool
Created by pedro on 29/7/26.
Pool of reusable ByteArray to avoid allocating one per encoded frame.
An encoded frame must be copied out of the MediaCodec output buffer before giving it back to the codec, so the copy is unavoidable, but the allocation is not. At 6Mbps a stream allocates around 750KB/s of short lived arrays, and all of it ends in the GC.
Buffers are grouped in power of two size classes so a frame gets the smallest available array able to contain it. Arrays are handed out dirty (never zeroed) because the caller always writes the whole frame and reads it back limited to the frame size.
Thread safe: acquired from the encoder thread and released from the sender thread.