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

Commit 48287b5e authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Make getHwAvSync strongly typed above libaudiohal

This CL lays the foundation and pattern for converting more parameters
to a strongly typed interface.

Test: TBD
Change-Id: I5503da3f68c543e441ede4d381518a8e5601fe8c
parent 50e93468
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -515,6 +515,18 @@ status_t DeviceHalHidl::setConnectedState(const struct audio_port_v7 *port, bool
    return processReturn("setConnectedState", mDevice->setConnectedState(hidlAddress, connected));
}

error::Result<audio_hw_sync_t> DeviceHalHidl::getHwAvSync() {
    if (mDevice == 0) return NO_INIT;
    audio_hw_sync_t value;
    Result result;
    Return<void> ret = mDevice->getHwAvSync([&value, &result](Result r, audio_hw_sync_t v) {
        value = v;
        result = r;
    });
    RETURN_IF_ERROR(processReturn("getHwAvSync", ret, result));
    return value;
}

status_t DeviceHalHidl::dump(int fd, const Vector<String16>& args) {
    if (mDevice == 0) return NO_INIT;
    native_handle_t* hidlHandle = native_handle_create(1, 0);
+2 −0
Original line number Diff line number Diff line
@@ -134,6 +134,8 @@ class DeviceHalHidl : public DeviceHalInterface, public ConversionHelperHidl

    status_t setConnectedState(const struct audio_port_v7 *port, bool connected) override;

    error::Result<audio_hw_sync_t> getHwAvSync() override;

    status_t dump(int fd, const Vector<String16>& args) override;

  private:
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

#include <android/media/audio/common/AudioMMapPolicyInfo.h>
#include <android/media/audio/common/AudioMMapPolicyType.h>
#include <error/Result.h>
#include <media/audiohal/EffectHalInterface.h>
#include <media/MicrophoneInfo.h>
#include <system/audio.h>
@@ -131,6 +132,8 @@ class DeviceHalInterface : public RefBase
    // Update the connection status of an external device.
    virtual status_t setConnectedState(const struct audio_port_v7 *port, bool connected) = 0;

    virtual error::Result<audio_hw_sync_t> getHwAvSync() = 0;

    virtual status_t dump(int fd, const Vector<String16>& args) = 0;

  protected:
+4 −8
Original line number Diff line number Diff line
@@ -2493,21 +2493,17 @@ audio_hw_sync_t AudioFlinger::getAudioHwSyncForSession(audio_session_t sessionId
    if (dev == nullptr) {
        return AUDIO_HW_SYNC_INVALID;
    }
    String8 reply;
    AudioParameter param;
    if (dev->getParameters(String8(AudioParameter::keyHwAvSync), &reply) == OK) {
        param = AudioParameter(reply);
    }

    int value;
    if (param.getInt(String8(AudioParameter::keyHwAvSync), value) != NO_ERROR) {
    error::Result<audio_hw_sync_t> result = dev->getHwAvSync();
    if (!result.ok()) {
        ALOGW("getAudioHwSyncForSession error getting sync for session %d", sessionId);
        return AUDIO_HW_SYNC_INVALID;
    }
    audio_hw_sync_t value = VALUE_OR_FATAL(result);

    // allow only one session for a given HW A/V sync ID.
    for (size_t i = 0; i < mHwAvSyncIds.size(); i++) {
        if (mHwAvSyncIds.valueAt(i) == (audio_hw_sync_t)value) {
        if (mHwAvSyncIds.valueAt(i) == value) {
            ALOGV("getAudioHwSyncForSession removing ID %d for session %d",
                  value, mHwAvSyncIds.keyAt(i));
            mHwAvSyncIds.removeItemsAt(i);