Fix non-blocking playback threads creation
Because PlaybackThread calls StreamOutHal::setCallback inside
the constructor, onFirstRef gets called while the vtable pointer
is set to PlaybackThread's vtable, not to its subclass vtable.
onFirstRef launches a thread which starts calling methods
that are abstract in PlaybackThread.
Fixed by changing the type of StreamOutHal::setCallback argument
from "sp" to "wp", as creating a weak pointer does not increase
strong refs count and thus doesn't call onFirstRef.
Bug: 31856492
Change-Id: I0d51bc73ca88b4b235260ed773870ecb7dac55d0
Test: added logging to verify the order of calls
diff --git a/include/media/audiohal/StreamHalInterface.h b/include/media/audiohal/StreamHalInterface.h
index 5a7b4b6..8f42fe7 100644
--- a/include/media/audiohal/StreamHalInterface.h
+++ b/include/media/audiohal/StreamHalInterface.h
@@ -102,7 +102,7 @@
// Set the callback for notifying completion of non-blocking write and drain.
// The callback must be owned by someone else. The output stream does not own it
// to avoid strong pointer loops.
- virtual status_t setCallback(sp<StreamOutHalInterfaceCallback> callback) = 0;
+ virtual status_t setCallback(wp<StreamOutHalInterfaceCallback> callback) = 0;
// Returns whether pause and resume operations are supported.
virtual status_t supportsPauseAndResume(bool *supportsPause, bool *supportsResume) = 0;