take a nap if too little space in ring buffer

If ring buffer is too full to hold the next packet load of frames,
sleep for double the time it should take to drain the buffer
sufficiently, then check again.

Also, factor out decode_packet().