aaudio: fix crash from callbacks during close

Move some code from release_l() into a new close_l().
Also stop callbacks before freeing memory in the
FixedBlockReader.

The AudioTrack and AudioRecord callbacks can occur
up until their destructors are called. This can lead
to race conditions if the AAudio stream is dismantled
while the AudioTrack or AudioRecord is still alive.
The AudioRecord was being deleted but not the AudioTrack.
That caused some streams to fail if they were using
a FixedBlockReader, which is used when the app
calls AAudioStreamBuilder_setFramesPerDataCallback().

There was also a problem with a few functions like
AAudioStream_getFramesPerBurst() or AAudioStream_getTimestamp(),
which would crash if called after AAudioStream_release( for
INPUT streams.

Bug: 161914201
Bug: 163165126
Test: see bug for repro of the crash
Test: atest CtsNativeMediaAAudioTestCases
Change-Id: If8f6f6f17ffe06eae98eb8b3930bca08c49a15f8
Merged-In: If8f6f6f17ffe06eae98eb8b3930bca08c49a15f8
(cherry picked from commit 320910fcf1e7d7729f37f95f591093191414e73f)
diff --git a/media/libaaudio/include/aaudio/AAudio.h b/media/libaaudio/include/aaudio/AAudio.h
index a47f189..cab8929 100644
--- a/media/libaaudio/include/aaudio/AAudio.h
+++ b/media/libaaudio/include/aaudio/AAudio.h
@@ -1035,6 +1035,11 @@
  * but still allow queries to the stream to occur from other threads. This often
  * happens if you are monitoring stream progress from a UI thread.
  *
+ * NOTE: This function is only fully implemented for MMAP streams,
+ * which are low latency streams supported by some devices.
+ * On other "Legacy" streams some audio resources will still be in use
+ * and some callbacks may still be in process after this call.
+ *
  * @param stream reference provided by AAudioStreamBuilder_openStream()
  * @return {@link #AAUDIO_OK} or a negative error.
  */