Instrument unwritten samples queue.

Change-Id: Id77387314d340a5118490cf08e7bbc37c7366b25
Reorganize maintenance loop.

Change-Id: I4aaa2985dc6df726ae2c5ecb7df248e0cc18983e