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

Commit 2dd56c9e authored by Phil Burk's avatar Phil Burk Committed by android-build-merger
Browse files

Merge "aaudio: fix intermittent hang and position error" into oc-dr1-dev

am: c1fe2634

Change-Id: I44d29f0bc88935ccba6b365fec242568d35f6079
parents d36be4e4 c1fe2634
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -229,10 +229,13 @@ status_t AAudioConvert_aaudioToAndroidStatus(aaudio_result_t result) {
    case AAUDIO_ERROR_NULL:
        status = UNEXPECTED_NULL;
        break;
    case AAUDIO_ERROR_UNAVAILABLE:
        status = NOT_ENOUGH_DATA;
        break;

    // TODO translate these result codes
    case AAUDIO_ERROR_INTERNAL:
    case AAUDIO_ERROR_UNIMPLEMENTED:
    case AAUDIO_ERROR_UNAVAILABLE:
    case AAUDIO_ERROR_NO_FREE_HANDLES:
    case AAUDIO_ERROR_NO_MEMORY:
    case AAUDIO_ERROR_TIMEOUT:
@@ -268,6 +271,9 @@ aaudio_result_t AAudioConvert_androidToAAudioResult(status_t status) {
    case WOULD_BLOCK:
        result = AAUDIO_ERROR_WOULD_BLOCK;
        break;
    case NOT_ENOUGH_DATA:
        result = AAUDIO_ERROR_UNAVAILABLE;
        break;
    default:
        result = AAUDIO_ERROR_INTERNAL;
        break;
+4 −9
Original line number Diff line number Diff line
@@ -112,10 +112,10 @@ aaudio_result_t AAudioServiceEndpoint::unregisterStream(sp<AAudioServiceStreamSh
}

aaudio_result_t AAudioServiceEndpoint::startStream(sp<AAudioServiceStreamShared> sharedStream) {
    // TODO use real-time technique to avoid mutex, eg. atomic command FIFO
    aaudio_result_t result = AAUDIO_OK;
    std::lock_guard<std::mutex> lock(mLockStreams);
    if (++mRunningStreams == 1) {
        // TODO use real-time technique to avoid mutex, eg. atomic command FIFO
        std::lock_guard<std::mutex> lock(mLockStreams);
        result = getStreamInternal()->requestStart();
        startSharingThread_l();
    }
@@ -123,13 +123,8 @@ aaudio_result_t AAudioServiceEndpoint::startStream(sp<AAudioServiceStreamShared>
}

aaudio_result_t AAudioServiceEndpoint::stopStream(sp<AAudioServiceStreamShared> sharedStream) {
    int numRunningStreams = 0;
    {
        std::lock_guard<std::mutex> lock(mLockStreams);
        numRunningStreams = --mRunningStreams;
    }
    if (numRunningStreams == 0) {
        // Don't call this under a lock because the callbackLoop also uses the lock.
    // Don't lock here because the disconnectRegisteredStreams also uses the lock.
    if (--mRunningStreams == 0) { // atomic
        stopSharingThread();
        getStreamInternal()->requestStop();
    }
+2 −2
Original line number Diff line number Diff line
@@ -73,13 +73,13 @@ public:

    virtual AudioStreamInternal *getStreamInternal() = 0;

    std::atomic<bool>        mCallbackEnabled;
    std::atomic<bool>        mCallbackEnabled{false};

    mutable std::mutex       mLockStreams;

    std::vector<android::sp<AAudioServiceStreamShared>> mRegisteredStreams;

    size_t                   mRunningStreams = 0;
    std::atomic<int>         mRunningStreams{0};

private:
    aaudio_result_t startSharingThread_l();
+2 −0
Original line number Diff line number Diff line
@@ -219,6 +219,8 @@ aaudio_result_t AAudioServiceStreamBase::sendCurrentTimestamp() {
    //          (long long) command.timestamp.timestamp);
        command.what = AAudioServiceMessage::code::TIMESTAMP;
        result = writeUpMessageQueue(&command);
    } else if (result == AAUDIO_ERROR_UNAVAILABLE) {
        result = AAUDIO_OK; // just not available yet, try again later
    }
    return result;
}
+5 −0
Original line number Diff line number Diff line
@@ -163,6 +163,11 @@ protected:

    aaudio_result_t sendCurrentTimestamp();

    /**
     * @param positionFrames
     * @param timeNanos
     * @return AAUDIO_OK or AAUDIO_ERROR_UNAVAILABLE or other negative error
     */
    virtual aaudio_result_t getFreeRunningPosition(int64_t *positionFrames, int64_t *timeNanos) = 0;

    virtual aaudio_result_t getDownDataDescription(AudioEndpointParcelable &parcelable) = 0;
Loading