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

Commit 01eb1640 authored by Eric Laurent's avatar Eric Laurent Committed by Shunkai Yao
Browse files

audio flinger: Bluetooth latency mode control

Add APIs to discover support and control the use
of latency mode control over Bluetooth link.

Bug: 257922898
Test: make

Merged-In: I8d23a40f21465d566f0adc553cfc77e64571395e
Change-Id: I8d23a40f21465d566f0adc553cfc77e64571395e
parent ce466807
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -2426,6 +2426,23 @@ status_t AudioSystem::getSupportedLatencyModes(audio_io_handle_t output,
    return af->getSupportedLatencyModes(output, modes);
}

status_t AudioSystem::setBluetoothLatencyModesEnabled(bool enabled) {
    const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
    if (af == nullptr) {
        return PERMISSION_DENIED;
    }
    return af->setBluetoothLatencyModesEnabled(enabled);
}

status_t AudioSystem::supportsBluetoothLatencyModes(
        bool *support) {
    const sp<IAudioFlinger>& af = AudioSystem::get_audio_flinger();
    if (af == nullptr) {
        return PERMISSION_DENIED;
    }
    return af->supportsBluetoothLatencyModes(support);
}

class CaptureStateListenerImpl : public media::BnCaptureStateListener,
                                 public IBinder::DeathRecipient {
public:
+23 −0
Original line number Diff line number Diff line
@@ -837,6 +837,21 @@ status_t AudioFlingerClientAdapter::getSupportedLatencyModes(
    return NO_ERROR;
}

status_t AudioFlingerClientAdapter::setBluetoothLatencyModesEnabled(bool enabled) {
    return statusTFromBinderStatus(mDelegate->setBluetoothLatencyModesEnabled(enabled));
}

status_t AudioFlingerClientAdapter::supportsBluetoothLatencyModes(bool* support) {
    if (support == nullptr) {
        return BAD_VALUE;
    }

    RETURN_STATUS_IF_ERROR(statusTFromBinderStatus(
            mDelegate->supportsBluetoothLatencyModes(support)));

    return NO_ERROR;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
// AudioFlingerServerAdapter
AudioFlingerServerAdapter::AudioFlingerServerAdapter(
@@ -1357,4 +1372,12 @@ Status AudioFlingerServerAdapter::getSupportedLatencyModes(
    return Status::ok();
}

Status AudioFlingerServerAdapter::setBluetoothLatencyModesEnabled(bool enabled) {
    return Status::fromStatusT(mDelegate->setBluetoothLatencyModesEnabled(enabled));
}

Status AudioFlingerServerAdapter::supportsBluetoothLatencyModes(bool *support) {
    return Status::fromStatusT(mDelegate->supportsBluetoothLatencyModes(support));
}

} // namespace android
+15 −0
Original line number Diff line number Diff line
@@ -246,6 +246,21 @@ interface IAudioFlingerService {
     */
    AudioLatencyMode[] getSupportedLatencyModes(int output);

    /**
     * Requests if the implementation supports controlling the latency modes
     * over the Bleutooth A2DP or LE Audio links. If it does,
     * setRequestedLatencyMode() and getSupportedLatencyModes() APIs can also be used
     * for streams routed to Bluetooth and not just for the spatializer output.
     */
     boolean supportsBluetoothLatencyModes();

    /**
     * Enables or disables the variable Bluetooth latency control mechanism in the
     * audio framework and the audio HAL. This does not apply to the latency mode control
     * on the spatializer output with is a built-in feature.
     */
    void setBluetoothLatencyModesEnabled(boolean enabled);

    // When adding a new method, please review and update
    // IAudioFlinger.h AudioFlingerServerAdapter::Delegate::TransactionCode
    // AudioFlinger.cpp AudioFlinger::onTransactWrapper()
+4 −0
Original line number Diff line number Diff line
@@ -575,6 +575,10 @@ public:
    static status_t getSupportedLatencyModes(audio_io_handle_t output,
            std::vector<audio_latency_mode_t>* modes);

    static status_t setBluetoothLatencyModesEnabled(bool enabled);

    static status_t supportsBluetoothLatencyModes(bool *support);

    // A listener for capture state changes.
    class CaptureStateListener : public virtual RefBase {
    public:
+11 −0
Original line number Diff line number Diff line
@@ -367,6 +367,9 @@ public:
    virtual status_t getSupportedLatencyModes(audio_io_handle_t output,
            std::vector<audio_latency_mode_t>* modes) = 0;

    virtual status_t setBluetoothLatencyModesEnabled(bool enabled) = 0;

    virtual status_t supportsBluetoothLatencyModes(bool* support) = 0;
};

/**
@@ -473,6 +476,8 @@ public:
            audio_latency_mode_t mode) override;
    status_t getSupportedLatencyModes(
            audio_io_handle_t output, std::vector<audio_latency_mode_t>* modes) override;
    status_t setBluetoothLatencyModesEnabled(bool enabled) override;
    status_t supportsBluetoothLatencyModes(bool* support) override;

private:
    const sp<media::IAudioFlingerService> mDelegate;
@@ -564,6 +569,10 @@ public:
            SET_DEVICE_CONNECTED_STATE = media::BnAudioFlingerService::TRANSACTION_setDeviceConnectedState,
            SET_REQUESTED_LATENCY_MODE = media::BnAudioFlingerService::TRANSACTION_setRequestedLatencyMode,
            GET_SUPPORTED_LATENCY_MODES = media::BnAudioFlingerService::TRANSACTION_getSupportedLatencyModes,
            SET_BLUETOOTH_LATENCY_MODES_ENABLED =
                    media::BnAudioFlingerService::TRANSACTION_setBluetoothLatencyModesEnabled,
            SUPPORTS_BLUETOOTH_LATENCY_MODES =
                    media::BnAudioFlingerService::TRANSACTION_supportsBluetoothLatencyModes,
        };

    protected:
@@ -689,6 +698,8 @@ public:
            int output, media::audio::common::AudioLatencyMode mode) override;
    Status getSupportedLatencyModes(int output,
            std::vector<media::audio::common::AudioLatencyMode>* _aidl_return) override;
    Status setBluetoothLatencyModesEnabled(bool enabled) override;
    Status supportsBluetoothLatencyModes(bool* support) override;
private:
    const sp<AudioFlingerServerAdapter::Delegate> mDelegate;
};
Loading