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

Commit b537e909 authored by Mikhail Naganov's avatar Mikhail Naganov Committed by Cherrypicker Worker
Browse files

libaudiohal: Respect channel count when setting hw gain

The AIDL contract requires passing a gain value per channel.
The legacy API was using a single gain value for input,
and stereo gain for output. Adapt these to the actual channel
count.

Bug: 326853618
Test: m
(cherry picked from https://android-review.googlesource.com/q/commit:222fdf9571d9aa060460b73db08b739b0b300584)
Merged-In: Ic4179d41d569231255f9e497032d369df19ec6ba
Change-Id: Ic4179d41d569231255f9e497032d369df19ec6ba
parent 5c0ed421
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -616,7 +616,19 @@ status_t StreamOutHalAidl::getLatency(uint32_t *latency) {
status_t StreamOutHalAidl::setVolume(float left, float right) {
    TIME_CHECK();
    if (!mStream) return NO_INIT;
    return statusTFromBinderStatus(mStream->setHwVolume({left, right}));
    size_t channelCount = audio_channel_out_mask_from_count(mConfig.channel_mask);
    if (channelCount == 0) channelCount = 2;
    std::vector<float> volumes(channelCount);
    if (channelCount == 1) {
        volumes[0] = (left + right) / 2;
    } else {
        volumes[0] = left;
        volumes[1] = right;
        for (size_t i = 2; i < channelCount; ++i) {
            volumes[i] = (left + right) / 2;
        }
    }
    return statusTFromBinderStatus(mStream->setHwVolume(volumes));
}

status_t StreamOutHalAidl::selectPresentation(int presentationId, int programId) {
@@ -928,7 +940,9 @@ StreamInHalAidl::StreamInHalAidl(
status_t StreamInHalAidl::setGain(float gain) {
    TIME_CHECK();
    if (!mStream) return NO_INIT;
    return statusTFromBinderStatus(mStream->setHwGain({gain}));
    const size_t channelCount = audio_channel_count_from_in_mask(mConfig.channel_mask);
    std::vector<float> gains(channelCount != 0 ? channelCount : 1, gain);
    return statusTFromBinderStatus(mStream->setHwGain(gains));
}

status_t StreamInHalAidl::read(void *buffer, size_t bytes, size_t *read) {