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

Commit 12935731 authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "audio HAL V7.1: add latency mode control APIs"

parents 1cae036e afa586b2
Loading
Loading
Loading
Loading
+86 −0
Original line number Diff line number Diff line
@@ -686,6 +686,7 @@ status_t StreamOutHalHidl::setEventCallback(
    // Codec format callback is supported starting from audio HAL V6.0
    return INVALID_OPERATION;
}

#else

status_t StreamOutHalHidl::getDualMonoMode(audio_dual_mono_mode_t* mode) {
@@ -791,6 +792,84 @@ status_t StreamOutHalHidl::setEventCallback(
}
#endif

#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
using hardware::audio::V7_1::LatencyMode;

status_t StreamOutHalHidl::setLatencyMode(audio_latency_mode_t mode) {
    if (mStream == 0) return NO_INIT;
    return processReturn(
            "setLatencyMode", mStream->setLatencyMode(static_cast<LatencyMode>(mode)));
};

status_t StreamOutHalHidl::getRecommendedLatencyModes(std::vector<audio_latency_mode_t> *modes) {
    if (!mStream) return NO_INIT;
    Result retval;
    Return<void> ret = mStream->getRecommendedLatencyModes(
            [&](Result r, hidl_vec<LatencyMode> hidlModes) {
        retval = r;
        for (size_t i = 0; i < hidlModes.size(); i++) {
            modes->push_back(static_cast<audio_latency_mode_t>(hidlModes[i]));
        }
    });
    return processReturn("getRecommendedLatencyModes", ret, retval);
};

#include PATH(android/hardware/audio/FILE_VERSION/IStreamOutLatencyModeCallback.h)

using hardware::audio::V7_1::IStreamOutLatencyModeCallback;

namespace {
struct StreamOutLatencyModeCallback : public IStreamOutLatencyModeCallback {
    StreamOutLatencyModeCallback(const wp<StreamOutHalHidl>& stream) : mStream(stream) {}

    // IStreamOutLatencyModeCallback implementation
    Return<void> onRecommendedLatencyModeChanged(const hidl_vec<LatencyMode>& hidlModes) override {
        sp<StreamOutHalHidl> stream = mStream.promote();
        if (stream != nullptr) {
            std::vector<audio_latency_mode_t> modes;
            for (size_t i = 0; i < hidlModes.size(); i++) {
                modes.push_back(static_cast<audio_latency_mode_t>(hidlModes[i]));
            }
            stream->onRecommendedLatencyModeChanged(modes);
        }
        return Void();
    }

  private:
    wp<StreamOutHalHidl> mStream;
};
}  // namespace

status_t StreamOutHalHidl::setLatencyModeCallback(
        const sp<StreamOutHalInterfaceLatencyModeCallback>& callback) {

    if (mStream == nullptr) return NO_INIT;
    mLatencyModeCallback = callback;
    status_t status = processReturn(
            "setLatencyModeCallback",
            mStream->setLatencyModeCallback(
                    callback.get() == nullptr ? nullptr : new StreamOutLatencyModeCallback(this)));
    return status;
};

#else

status_t StreamOutHalHidl::setLatencyMode(audio_latency_mode_t mode __unused) {
    return INVALID_OPERATION;
};

status_t StreamOutHalHidl::getRecommendedLatencyModes(
        std::vector<audio_latency_mode_t> *modes __unused) {
    return INVALID_OPERATION;
};

status_t StreamOutHalHidl::setLatencyModeCallback(
        const sp<StreamOutHalInterfaceLatencyModeCallback>& callback __unused) {
    return INVALID_OPERATION;
};

#endif

void StreamOutHalHidl::onWriteReady() {
    sp<StreamOutHalInterfaceCallback> callback = mCallback.load().promote();
    if (callback == 0) return;
@@ -819,6 +898,13 @@ void StreamOutHalHidl::onCodecFormatChanged(const std::basic_string<uint8_t>& me
    callback->onCodecFormatChanged(metadataBs);
}

void StreamOutHalHidl::onRecommendedLatencyModeChanged(
        const std::vector<audio_latency_mode_t>& modes) {
    sp<StreamOutHalInterfaceLatencyModeCallback> callback = mLatencyModeCallback.load().promote();
    if (callback == nullptr) return;
    callback->onRecommendedLatencyModeChanged(modes);
}


StreamInHalHidl::StreamInHalHidl(
        const sp<::android::hardware::audio::CPP_VERSION::IStreamIn>& stream)
+9 −0
Original line number Diff line number Diff line
@@ -189,6 +189,13 @@ class StreamOutHalHidl : public StreamOutHalInterface, public StreamHalHidl {
    // Methods used by StreamCodecFormatCallback (HIDL).
    void onCodecFormatChanged(const std::basic_string<uint8_t>& metadataBs);

    status_t setLatencyMode(audio_latency_mode_t mode) override;
    status_t getRecommendedLatencyModes(std::vector<audio_latency_mode_t> *modes) override;
    status_t setLatencyModeCallback(
            const sp<StreamOutHalInterfaceLatencyModeCallback>& callback) override;

    void onRecommendedLatencyModeChanged(const std::vector<audio_latency_mode_t>& modes);

  private:
    friend class DeviceHalHidl;
    typedef MessageQueue<WriteCommand, hardware::kSynchronizedReadWrite> CommandMQ;
@@ -197,6 +204,8 @@ class StreamOutHalHidl : public StreamOutHalInterface, public StreamHalHidl {

    mediautils::atomic_wp<StreamOutHalInterfaceCallback> mCallback;
    mediautils::atomic_wp<StreamOutHalInterfaceEventCallback> mEventCallback;
    mediautils::atomic_wp<StreamOutHalInterfaceLatencyModeCallback> mLatencyModeCallback;

    const sp<::android::hardware::audio::CPP_VERSION::IStreamOut> mStream;
    std::unique_ptr<CommandMQ> mCommandMQ;
    std::unique_ptr<DataMQ> mDataMQ;
+12 −0
Original line number Diff line number Diff line
@@ -168,6 +168,18 @@ class StreamOutHalLocal : public StreamOutHalInterface, public StreamHalLocal {

    status_t setEventCallback(const sp<StreamOutHalInterfaceEventCallback>& callback) override;

    status_t setLatencyMode(audio_latency_mode_t mode __unused) override {
        return INVALID_OPERATION;
    }
    status_t getRecommendedLatencyModes(
            std::vector<audio_latency_mode_t> *modes __unused) override {
        return INVALID_OPERATION;
    }
    status_t setLatencyModeCallback(
            const sp<StreamOutHalInterfaceLatencyModeCallback>& callback __unused) override {
        return INVALID_OPERATION;
    }

  private:
    audio_stream_out_t *mStream;
    wp<StreamOutHalInterfaceCallback> mCallback;
+48 −0
Original line number Diff line number Diff line
@@ -117,6 +117,18 @@ protected:
    virtual ~StreamOutHalInterfaceEventCallback() {}
};

class StreamOutHalInterfaceLatencyModeCallback : public virtual RefBase {
public:
    /**
     * Called with the new list of supported latency modes when a change occurs.
     */
    virtual void onRecommendedLatencyModeChanged(std::vector<audio_latency_mode_t> modes) = 0;

protected:
    StreamOutHalInterfaceLatencyModeCallback() {}
    virtual ~StreamOutHalInterfaceLatencyModeCallback() {}
};

class StreamOutHalInterface : public virtual StreamHalInterface {
  public:
    // Return the audio hardware driver estimated latency in milliseconds.
@@ -194,6 +206,42 @@ class StreamOutHalInterface : public virtual StreamHalInterface {

    virtual status_t setEventCallback(const sp<StreamOutHalInterfaceEventCallback>& callback) = 0;

    /**
     * Indicates the requested latency mode for this output stream.
     *
     * The requested mode can be one of the modes returned by
     * getRecommendedLatencyModes() API.
     *
     * @param mode the requested latency mode.
     * @return operation completion status.
     */
    virtual status_t setLatencyMode(audio_latency_mode_t mode) = 0;

    /**
     * Indicates which latency modes are currently supported on this output stream.
     * If the transport protocol (e.g Bluetooth A2DP) used by this output stream to reach
     * the output device supports variable latency modes, the HAL indicates which
     * modes are currently supported.
     * The framework can then call setLatencyMode() with one of the supported modes to select
     * the desired operation mode.
     *
     * @param modes currrently supported latency modes.
     * @return operation completion status.
     */
    virtual status_t getRecommendedLatencyModes(std::vector<audio_latency_mode_t> *modes) = 0;

    /**
     * Set the callback interface for notifying changes in supported latency modes.
     *
     * Calling this method with a null pointer will result in releasing
     * the callback.
     *
     * @param callback the registered callback or null to unregister.
     * @return operation completion status.
     */
    virtual status_t setLatencyModeCallback(
            const sp<StreamOutHalInterfaceLatencyModeCallback>& callback) = 0;

  protected:
    virtual ~StreamOutHalInterface() {}
};