aaudio: defer closing of stream until safe

When a client asks to close the stream, we mark it as
closeable. When the last client finishes with the stream
then we actually close it.  References to the stream are counted.

This will prevent a stream from getting closed while another thread is
trying to start it or stop it, etc.

Test: CTS nativemedia/aaudio
Change-Id: Ic1c7eceded6bff9899f37a5e7d9f2b695b8cdc97
4 files changed