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/media/libaudiohal/StreamHalLocal.cpp b/media/libaudiohal/StreamHalLocal.cpp
index cd97cc8..59314eb 100644
--- a/media/libaudiohal/StreamHalLocal.cpp
+++ b/media/libaudiohal/StreamHalLocal.cpp
@@ -140,7 +140,7 @@
return mStream->get_next_write_timestamp(mStream, timestamp);
}
-status_t StreamOutHalLocal::setCallback(sp<StreamOutHalInterfaceCallback> callback) {
+status_t StreamOutHalLocal::setCallback(wp<StreamOutHalInterfaceCallback> callback) {
if (mStream->set_callback == NULL) return INVALID_OPERATION;
status_t result = mStream->set_callback(mStream, StreamOutHalLocal::asyncCallback, this);
if (result == OK) {