To all the fellow sufferers out there, answering my own question.
The real issue actually was feeding raw PCM data to encoder input. Android docs are vague on how to exactly feed in the data into the input buffer (ok, it has actually more to do with ByteBuffer behaviour to be honest):
int inputBufferIndex = codec.dequeueInputBuffer(timeoutUs);
if (inputBufferIndex >= 0) {
// fill inputBuffers[inputBufferIndex] with valid data
...
codec.queueInputBuffer(inputBufferIndex, ...);
}
My interpretation was to add data as following:
inputBuffers[inputBufferIndex].clear();
inputBuffers[inputBufferIndex].put(audioPCMbuffer);
codec.queueInputBuffer(inputBufferIndex, ...);
The above code has one bit missing: flip the position of the ByteBuffer!
inputBuffers[inputBufferIndex].flip();
Keeping it here for the future reference as it was quite hard to find simple code to see the implementation.