I am decoding H.264 video data received through a websocket with an async Android MediaCodec.
My question is how to handle input buffers when there is no new encoded data to decode?
Currently I queue the input buffers without any data when there is no new encoded data from the websocket:
override fun onInputBufferAvailable(codec: MediaCodec, index: Int) {
if (videoFrames.isNotEmpty()) {
val inputBuffer = codec.getInputBuffer(index)
inputBuffer?.put(videoFrames.removeFirst())
codec.queueInputBuffer(index, 0, currentFrame.size, 0, 0)
} else {
codec.queueInputBuffer(index, 0, 0, 0, 0)
}
}
where videoFrames is a list of frames with encoded video data.
I do it like above because if I alternatively remove the else clause and don't queue the empty input buffer, the input buffer never becomes available again.
Is there a different way of handling this? It feels wrong to me to queue an empty input buffer.