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

Commit f7f06151 authored by jiabin's avatar jiabin
Browse files

Add standby mode for aaudio service stream.

When the stream is stopped, everything will remain open but just stop
writing data. But this will keep the DSP running and using power
until the stream is closed.
To resolve this issue, the solution is to put the stream into standby
mode so that the HAL can release the corresponding resource.
When the HAL releases the resource, the shared file descriptor will also
be released. In that case, when the stream is restarted, AAudioService
needs to recreate shared buffer and the client needs to replace the new
shared buffer.

Test: atest AAudioTests
Test: test_steal_exclusive
Bug: 201000721
Bug: 196394385
Bug: 167345722
Bug: 208619472
Change-Id: Ib4f98e7aee72c2e56acd7f2f0ac378a94ec26241
parent 0269adda
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -49,6 +49,12 @@ enum {
};
typedef int32_t aaudio_policy_t;

// Internal error codes. Only used by the framework.
enum {
    AAUDIO_INTERNAL_ERROR_BASE = -1000,
    AAUDIO_ERROR_STANDBY,
};

/**
 * Control whether AAudioStreamBuilder_openStream() will use the new MMAP data path
 * or the older "Legacy" data path.
+12 −0
Original line number Diff line number Diff line
@@ -124,4 +124,16 @@ aaudio_result_t AAudioBinderAdapter::unregisterAudioThread(aaudio_handle_t strea
    return result;
}

aaudio_result_t AAudioBinderAdapter::exitStandby(aaudio_handle_t streamHandle,
                                                 AudioEndpointParcelable &endpointOut) {
    aaudio_result_t result;
    Endpoint endpoint;
    Status status = mDelegate->exitStandby(streamHandle, &endpoint, &result);
    if (!status.isOk()) {
        result = AAudioConvert_androidToAAudioResult(statusTFromBinderStatus(status));
    }
    endpointOut = std::move(endpoint);
    return result;
}

}  // namespace aaudio
+3 −0
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@ public:
    aaudio_result_t unregisterAudioThread(aaudio_handle_t streamHandle,
                                          pid_t clientThreadId) override;

    aaudio_result_t exitStandby(aaudio_handle_t streamHandle,
                                AudioEndpointParcelable &parcelable) override;

private:
    IAAudioService* const mDelegate;
};
+8 −0
Original line number Diff line number Diff line
@@ -201,3 +201,11 @@ aaudio_result_t AAudioBinderClient::unregisterAudioThread(aaudio_handle_t stream

    return service->unregisterAudioThread(streamHandle, clientThreadId);
}

aaudio_result_t AAudioBinderClient::exitStandby(aaudio_handle_t streamHandle,
                                                AudioEndpointParcelable &endpointOut) {
    std::shared_ptr<AAudioServiceInterface> service = getAAudioService();
    if (service.get() == nullptr) return AAUDIO_ERROR_NO_SERVICE;

    return service->exitStandby(streamHandle, endpointOut);
}
+3 −0
Original line number Diff line number Diff line
@@ -108,6 +108,9 @@ public:
        return AAUDIO_ERROR_UNAVAILABLE;
    }

    aaudio_result_t exitStandby(aaudio_handle_t streamHandle,
                                AudioEndpointParcelable &endpointOut) override;

    void onStreamChange(aaudio_handle_t /*handle*/, int32_t /*opcode*/, int32_t /*value*/) {
        // TODO This is just a stub so we can have a client Binder to pass to the service.
        // TODO Implemented in a later CL.
Loading