Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15897e45 authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

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
parent ad111520
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ class StreamOutHalInterface : public virtual StreamHalInterface {
    // 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;
+1 −1
Original line number Diff line number Diff line
@@ -140,7 +140,7 @@ status_t StreamOutHalLocal::getNextWriteTimestamp(int64_t *timestamp) {
    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) {
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ class StreamOutHalLocal : public StreamOutHalInterface, public StreamHalLocal {
    virtual status_t getNextWriteTimestamp(int64_t *timestamp);

    // Set the callback for notifying completion of non-blocking write and drain.
    virtual status_t setCallback(sp<StreamOutHalInterfaceCallback> callback);
    virtual status_t setCallback(wp<StreamOutHalInterfaceCallback> callback);

    // Returns whether pause and resume operations are supported.
    virtual status_t supportsPauseAndResume(bool *supportsPause, bool *supportsResume);