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

Commit 54eb53e7 authored by Andy Hung's avatar Andy Hung
Browse files

FastPath: Update for clang tidy

Clean for clang-tidy.

Test: ALLOW_LOCAL_TIDY_TRUE=1 mm -j .
Bug: 284390461
Change-Id: Ie46c1f5c4ba6ad397f345c6904c567bcbf5b82ae
parent 5772cdc7
Loading
Loading
Loading
Loading
+8 −8
Original line number Original line Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_av_services_audioflinger_license"],
}


fastpath_tidy_errors = [
fastpath_tidy_errors = [
    // https://clang.llvm.org/extra/clang-tidy/checks/list.html
    // https://clang.llvm.org/extra/clang-tidy/checks/list.html
@@ -58,19 +66,11 @@ fastpath_tidy_errors = [
    "-bugprone-parent-virtual-call",
    "-bugprone-parent-virtual-call",
    "-cert-dcl59-cpp",
    "-cert-dcl59-cpp",
    "-cert-err34-c",
    "-cert-err34-c",
    "-google-build-namespaces",
    "-google-build-using-namespace",
    "-google-default-arguments",
    "-google-runtime-int",
    "-google-runtime-int",
    "-misc-const-correctness",
    "-misc-non-private-member-variables-in-classes",
    "-misc-non-private-member-variables-in-classes",
    "-modernize-concat-nested-namespaces",
    "-modernize-concat-nested-namespaces",
    "-modernize-loop-convert",
    "-modernize-loop-convert",
    "-modernize-use-default-member-init",
    "-modernize-use-default-member-init",
    "-modernize-use-equals-default",
    "-modernize-use-nullptr",
    "-modernize-use-override",
    "-modernize-use-using",
    "-performance-no-int-to-ptr",
    "-performance-no-int-to-ptr",
]
]


+2 −0
Original line number Original line Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#pragma once

namespace android {
namespace android {


// T is FastMixer or FastCapture
// T is FastMixer or FastCapture
+19 −23
Original line number Original line Diff line number Diff line
@@ -33,8 +33,8 @@ namespace android {
/*static*/ const FastCaptureState FastCapture::sInitial;
/*static*/ const FastCaptureState FastCapture::sInitial;


FastCapture::FastCapture() : FastThread("cycleC_ms", "loadC_us"),
FastCapture::FastCapture() : FastThread("cycleC_ms", "loadC_us"),
    mInputSource(NULL), mInputSourceGen(0), mPipeSink(NULL), mPipeSinkGen(0),
    mInputSource(nullptr), mInputSourceGen(0), mPipeSink(nullptr), mPipeSinkGen(0),
    mReadBuffer(NULL), mReadBufferState(-1), mFormat(Format_Invalid), mSampleRate(0),
    mReadBuffer(nullptr), mReadBufferState(-1), mFormat(Format_Invalid), mSampleRate(0),
    // mDummyDumpState
    // mDummyDumpState
    mTotalNativeFramesRead(0)
    mTotalNativeFramesRead(0)
{
{
@@ -44,10 +44,6 @@ FastCapture::FastCapture() : FastThread("cycleC_ms", "loadC_us"),
    mDummyDumpState = &mDummyFastCaptureDumpState;
    mDummyDumpState = &mDummyFastCaptureDumpState;
}
}


FastCapture::~FastCapture()
{
}

FastCaptureStateQueue* FastCapture::sq()
FastCaptureStateQueue* FastCapture::sq()
{
{
    return &mSQ;
    return &mSQ;
@@ -95,11 +91,11 @@ void FastCapture::onStateChange()
    bool eitherChanged = false;
    bool eitherChanged = false;


    // check for change in input HAL configuration
    // check for change in input HAL configuration
    NBAIO_Format previousFormat = mFormat;
    const NBAIO_Format previousFormat = mFormat;
    if (current->mInputSourceGen != mInputSourceGen) {
    if (current->mInputSourceGen != mInputSourceGen) {
        mInputSource = current->mInputSource;
        mInputSource = current->mInputSource;
        mInputSourceGen = current->mInputSourceGen;
        mInputSourceGen = current->mInputSourceGen;
        if (mInputSource == NULL) {
        if (mInputSource == nullptr) {
            mFormat = Format_Invalid;
            mFormat = Format_Invalid;
            mSampleRate = 0;
            mSampleRate = 0;
        } else {
        } else {
@@ -122,19 +118,19 @@ void FastCapture::onStateChange()
    }
    }


    // input source and pipe sink must be compatible
    // input source and pipe sink must be compatible
    if (eitherChanged && mInputSource != NULL && mPipeSink != NULL) {
    if (eitherChanged && mInputSource != nullptr && mPipeSink != nullptr) {
        ALOG_ASSERT(Format_isEqual(mFormat, mPipeSink->format()));
        ALOG_ASSERT(Format_isEqual(mFormat, mPipeSink->format()));
    }
    }


    if ((!Format_isEqual(mFormat, previousFormat)) || (frameCount != previous->mFrameCount)) {
    if ((!Format_isEqual(mFormat, previousFormat)) || (frameCount != previous->mFrameCount)) {
        // FIXME to avoid priority inversion, don't free here
        // FIXME to avoid priority inversion, don't free here
        free(mReadBuffer);
        free(mReadBuffer);
        mReadBuffer = NULL;
        mReadBuffer = nullptr;
        if (frameCount > 0 && mSampleRate > 0) {
        if (frameCount > 0 && mSampleRate > 0) {
            // FIXME new may block for unbounded time at internal mutex of the heap
            // FIXME new may block for unbounded time at internal mutex of the heap
            //       implementation; it would be better to have normal capture thread allocate for
            //       implementation; it would be better to have normal capture thread allocate for
            //       us to avoid blocking here and to prevent possible priority inversion
            //       us to avoid blocking here and to prevent possible priority inversion
            size_t bufferSize = frameCount * Format_frameSize(mFormat);
            const size_t bufferSize = frameCount * Format_frameSize(mFormat);
            (void)posix_memalign(&mReadBuffer, 32, bufferSize);
            (void)posix_memalign(&mReadBuffer, 32, bufferSize);
            memset(mReadBuffer, 0, bufferSize); // if posix_memalign fails, will segv here.
            memset(mReadBuffer, 0, bufferSize); // if posix_memalign fails, will segv here.
            mPeriodNs = (frameCount * 1000000000LL) / mSampleRate;      // 1.00
            mPeriodNs = (frameCount * 1000000000LL) / mSampleRate;      // 1.00
@@ -166,9 +162,9 @@ void FastCapture::onWork()
    AudioBufferProvider* fastPatchRecordBufferProvider = current->mFastPatchRecordBufferProvider;
    AudioBufferProvider* fastPatchRecordBufferProvider = current->mFastPatchRecordBufferProvider;
    AudioBufferProvider::Buffer patchBuffer;
    AudioBufferProvider::Buffer patchBuffer;


    if (fastPatchRecordBufferProvider != 0) {
    if (fastPatchRecordBufferProvider != nullptr) {
        patchBuffer.frameCount = ~0;
        patchBuffer.frameCount = ~0;
        status_t status = fastPatchRecordBufferProvider->getNextBuffer(&patchBuffer);
        const status_t status = fastPatchRecordBufferProvider->getNextBuffer(&patchBuffer);
        if (status != NO_ERROR) {
        if (status != NO_ERROR) {
            frameCount = 0;
            frameCount = 0;
        } else if (patchBuffer.frameCount < frameCount) {
        } else if (patchBuffer.frameCount < frameCount) {
@@ -179,11 +175,11 @@ void FastCapture::onWork()
    }
    }


    if ((command & FastCaptureState::READ) /*&& isWarm*/) {
    if ((command & FastCaptureState::READ) /*&& isWarm*/) {
        ALOG_ASSERT(mInputSource != NULL);
        ALOG_ASSERT(mInputSource != nullptr);
        ALOG_ASSERT(mReadBuffer != NULL);
        ALOG_ASSERT(mReadBuffer != nullptr);
        dumpState->mReadSequence++;
        dumpState->mReadSequence++;
        ATRACE_BEGIN("read");
        ATRACE_BEGIN("read");
        ssize_t framesRead = mInputSource->read(mReadBuffer, frameCount);
        const ssize_t framesRead = mInputSource->read(mReadBuffer, frameCount);
        ATRACE_END();
        ATRACE_END();
        dumpState->mReadSequence++;
        dumpState->mReadSequence++;
        if (framesRead >= 0) {
        if (framesRead >= 0) {
@@ -201,8 +197,8 @@ void FastCapture::onWork()
    }
    }


    if (command & FastCaptureState::WRITE) {
    if (command & FastCaptureState::WRITE) {
        ALOG_ASSERT(mPipeSink != NULL);
        ALOG_ASSERT(mPipeSink != nullptr);
        ALOG_ASSERT(mReadBuffer != NULL);
        ALOG_ASSERT(mReadBuffer != nullptr);
        if (mReadBufferState < 0) {
        if (mReadBufferState < 0) {
            memset(mReadBuffer, 0, frameCount * Format_frameSize(mFormat));
            memset(mReadBuffer, 0, frameCount * Format_frameSize(mFormat));
            mReadBufferState = frameCount;
            mReadBufferState = frameCount;
@@ -211,23 +207,23 @@ void FastCapture::onWork()
            if (current->mSilenceCapture) {
            if (current->mSilenceCapture) {
                memset(mReadBuffer, 0, mReadBufferState * Format_frameSize(mFormat));
                memset(mReadBuffer, 0, mReadBufferState * Format_frameSize(mFormat));
            }
            }
            ssize_t framesWritten = mPipeSink->write(mReadBuffer, mReadBufferState);
            const ssize_t framesWritten = mPipeSink->write(mReadBuffer, mReadBufferState);
            audio_track_cblk_t* cblk = current->mCblk;
            audio_track_cblk_t* cblk = current->mCblk;
            if (fastPatchRecordBufferProvider != 0) {
            if (fastPatchRecordBufferProvider != nullptr) {
                // This indicates the fast track is a patch record, update the cblk by
                // This indicates the fast track is a patch record, update the cblk by
                // calling releaseBuffer().
                // calling releaseBuffer().
                memcpy_by_audio_format(patchBuffer.raw, current->mFastPatchRecordFormat,
                memcpy_by_audio_format(patchBuffer.raw, current->mFastPatchRecordFormat,
                        mReadBuffer, mFormat.mFormat, framesWritten * mFormat.mChannelCount);
                        mReadBuffer, mFormat.mFormat, framesWritten * mFormat.mChannelCount);
                patchBuffer.frameCount = framesWritten;
                patchBuffer.frameCount = framesWritten;
                fastPatchRecordBufferProvider->releaseBuffer(&patchBuffer);
                fastPatchRecordBufferProvider->releaseBuffer(&patchBuffer);
            } else if (cblk != NULL && framesWritten > 0) {
            } else if (cblk != nullptr && framesWritten > 0) {
                // FIXME This supports at most one fast capture client.
                // FIXME This supports at most one fast capture client.
                //       To handle multiple clients this could be converted to an array,
                //       To handle multiple clients this could be converted to an array,
                //       or with a lot more work the control block could be shared by all clients.
                //       or with a lot more work the control block could be shared by all clients.
                int32_t rear = cblk->u.mStreaming.mRear;
                const int32_t rear = cblk->u.mStreaming.mRear;
                android_atomic_release_store(framesWritten + rear, &cblk->u.mStreaming.mRear);
                android_atomic_release_store(framesWritten + rear, &cblk->u.mStreaming.mRear);
                cblk->mServer += framesWritten;
                cblk->mServer += framesWritten;
                int32_t old = android_atomic_or(CBLK_FUTEX_WAKE, &cblk->mFutex);
                const int32_t old = android_atomic_or(CBLK_FUTEX_WAKE, &cblk->mFutex);
                if (!(old & CBLK_FUTEX_WAKE)) {
                if (!(old & CBLK_FUTEX_WAKE)) {
                    // client is never in server process, so don't use FUTEX_WAKE_PRIVATE
                    // client is never in server process, so don't use FUTEX_WAKE_PRIVATE
                    (void) syscall(__NR_futex, &cblk->mFutex, FUTEX_WAKE, 1);
                    (void) syscall(__NR_futex, &cblk->mFutex, FUTEX_WAKE, 1);
+9 −13
Original line number Original line Diff line number Diff line
@@ -14,8 +14,7 @@
 * limitations under the License.
 * limitations under the License.
 */
 */


#ifndef ANDROID_AUDIO_FAST_CAPTURE_H
#pragma once
#define ANDROID_AUDIO_FAST_CAPTURE_H


#include "FastThread.h"
#include "FastThread.h"
#include "StateQueue.h"
#include "StateQueue.h"
@@ -24,13 +23,12 @@


namespace android {
namespace android {


typedef StateQueue<FastCaptureState> FastCaptureStateQueue;
using FastCaptureStateQueue = StateQueue<FastCaptureState>;


class FastCapture : public FastThread {
class FastCapture : public FastThread {


public:
public:
            FastCapture();
            FastCapture();
    virtual ~FastCapture();


            FastCaptureStateQueue*  sq();
            FastCaptureStateQueue*  sq();


@@ -38,13 +36,13 @@ private:
            FastCaptureStateQueue   mSQ;
            FastCaptureStateQueue   mSQ;


    // callouts
    // callouts
    virtual const FastThreadState *poll();
    const FastThreadState *poll() override;
    virtual void setNBLogWriter(NBLog::Writer *logWriter);
    void setNBLogWriter(NBLog::Writer *logWriter) override;
    virtual void onIdle();
    void onIdle() override;
    virtual void onExit();
    void onExit() override;
    virtual bool isSubClassCommand(FastThreadState::Command command);
    bool isSubClassCommand(FastThreadState::Command command) override;
    virtual void onStateChange();
    void onStateChange() override;
    virtual void onWork();
    void onWork() override;


    static const FastCaptureState sInitial;
    static const FastCaptureState sInitial;


@@ -65,5 +63,3 @@ private:
};  // class FastCapture
};  // class FastCapture


}   // namespace android
}   // namespace android

#endif  // ANDROID_AUDIO_FAST_CAPTURE_H
+2 −6
Original line number Original line Diff line number Diff line
@@ -29,19 +29,15 @@ FastCaptureDumpState::FastCaptureDumpState() : FastThreadDumpState(),
{
{
}
}


FastCaptureDumpState::~FastCaptureDumpState()
{
}

void FastCaptureDumpState::dump(int fd) const
void FastCaptureDumpState::dump(int fd) const
{
{
    if (mCommand == FastCaptureState::INITIAL) {
    if (mCommand == FastCaptureState::INITIAL) {
        dprintf(fd, "  FastCapture not initialized\n");
        dprintf(fd, "  FastCapture not initialized\n");
        return;
        return;
    }
    }
    double measuredWarmupMs = (mMeasuredWarmupTs.tv_sec * 1000.0) +
    const double measuredWarmupMs = (mMeasuredWarmupTs.tv_sec * 1000.0) +
            (mMeasuredWarmupTs.tv_nsec / 1000000.0);
            (mMeasuredWarmupTs.tv_nsec / 1000000.0);
    double periodSec = (double) mFrameCount / mSampleRate;
    const double periodSec = (double) mFrameCount / mSampleRate;
    dprintf(fd, "  FastCapture command=%s readSequence=%u framesRead=%u\n"
    dprintf(fd, "  FastCapture command=%s readSequence=%u framesRead=%u\n"
                "              readErrors=%u sampleRate=%u frameCount=%zu\n"
                "              readErrors=%u sampleRate=%u frameCount=%zu\n"
                "              measuredWarmup=%.3g ms, warmupCycles=%u period=%.2f ms\n"
                "              measuredWarmup=%.3g ms, warmupCycles=%u period=%.2f ms\n"
Loading