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

Commit 0688880d authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

audioflinger and hal: Compatibility fixes for Treble

 1. Treat both reply size being 0 and reply buffer being NULL
    as an indication that the reply isn't needed.

 2. Synchronize both input and output effect chain buffers,
    and avoid excessive copies when the input buffer is the same as
    the output buffer.

 3. Improve effect chain debug dump by showing both
    "external" and "allocated" pointers for effect audio data buffers.

Bug: 34368451
Change-Id: I56aba6908408b5fce3f15c8d29138555101e8720
Test: volume controls works when both Bass Boost and EQ effects enabled
parent dffb51f4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ status_t EffectHalHidl::command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdDa
    }
    status_t status;
    uint32_t replySizeStub = 0;
    if (replySize == nullptr) replySize = &replySizeStub;
    if (replySize == nullptr || pReplyData == nullptr) replySize = &replySizeStub;
    Return<void> ret = mEffect->command(cmdCode, hidlData, *replySize,
            [&](int32_t s, const hidl_vec<uint8_t>& result) {
                status = s;
+26 −7
Original line number Diff line number Diff line
@@ -1630,12 +1630,17 @@ void AudioFlinger::EffectChain::process_l()
        // and 'update' / 'commit' do nothing for allocated buffers, thus
        // it's not needed to consider any other buffers here.
        mInBuffer->update();
        if (mInBuffer->audioBuffer()->raw != mOutBuffer->audioBuffer()->raw) {
            mOutBuffer->update();
        }
        for (size_t i = 0; i < size; i++) {
            mEffects[i]->process();
        }
        mInBuffer->commit();
        if (mInBuffer->audioBuffer()->raw != mOutBuffer->audioBuffer()->raw) {
            mOutBuffer->commit();
        }
    }
    bool doResetVolume = false;
    for (size_t i = 0; i < size; i++) {
        doResetVolume = mEffects[i]->updateState() || doResetVolume;
@@ -1935,6 +1940,17 @@ void AudioFlinger::EffectChain::syncHalEffectsState()
    }
}

static void dumpInOutBuffer(
        char *dump, size_t dumpSize, bool isInput, EffectBufferHalInterface *buffer) {
    if (buffer->externalData() != nullptr) {
        snprintf(dump, dumpSize, "%p -> %p",
                isInput ? buffer->externalData() : buffer->audioBuffer()->raw,
                isInput ? buffer->audioBuffer()->raw : buffer->externalData());
    } else {
        snprintf(dump, dumpSize, "%p", buffer->audioBuffer()->raw);
    }
}

void AudioFlinger::EffectChain::dump(int fd, const Vector<String16>& args)
{
    const size_t SIZE = 256;
@@ -1952,11 +1968,14 @@ void AudioFlinger::EffectChain::dump(int fd, const Vector<String16>& args)
            result.append("\tCould not lock mutex:\n");
        }

        result.append("\tIn buffer   Out buffer   Active tracks:\n");
        snprintf(buffer, SIZE, "\t%p  %p   %d\n",
                mInBuffer->audioBuffer(),
                mOutBuffer->audioBuffer(),
                mActiveTrackCnt);
        char inBufferStr[64], outBufferStr[64];
        dumpInOutBuffer(inBufferStr, sizeof(inBufferStr), true, mInBuffer.get());
        dumpInOutBuffer(outBufferStr, sizeof(outBufferStr), false, mOutBuffer.get());
        snprintf(buffer, SIZE, "\t%-*s%-*s   Active tracks:\n",
                (int)strlen(inBufferStr), "In buffer    ",
                (int)strlen(outBufferStr), "Out buffer      ");
        result.append(buffer);
        snprintf(buffer, SIZE, "\t%s   %s   %d\n", inBufferStr, outBufferStr, mActiveTrackCnt);
        result.append(buffer);
        write(fd, result.string(), result.size());