FastPath: Update for clang tidy
Clean for clang-tidy.
Test: ALLOW_LOCAL_TIDY_TRUE=1 mm -j .
Bug: 284390461
Merged-In: Ie46c1f5c4ba6ad397f345c6904c567bcbf5b82ae
Change-Id: Ie46c1f5c4ba6ad397f345c6904c567bcbf5b82ae
diff --git a/services/audioflinger/fastpath/Android.bp b/services/audioflinger/fastpath/Android.bp
index fb49430..c4aa171 100644
--- a/services/audioflinger/fastpath/Android.bp
+++ b/services/audioflinger/fastpath/Android.bp
@@ -1,3 +1,11 @@
+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 = [
// https://clang.llvm.org/extra/clang-tidy/checks/list.html
@@ -58,19 +66,11 @@
"-bugprone-parent-virtual-call",
"-cert-dcl59-cpp",
"-cert-err34-c",
- "-google-build-namespaces",
- "-google-build-using-namespace",
- "-google-default-arguments",
"-google-runtime-int",
- "-misc-const-correctness",
"-misc-non-private-member-variables-in-classes",
"-modernize-concat-nested-namespaces",
"-modernize-loop-convert",
"-modernize-use-default-member-init",
- "-modernize-use-equals-default",
- "-modernize-use-nullptr",
- "-modernize-use-override",
- "-modernize-use-using",
"-performance-no-int-to-ptr",
]
diff --git a/services/audioflinger/fastpath/AutoPark.h b/services/audioflinger/fastpath/AutoPark.h
index 83f6b7d..6e68327 100644
--- a/services/audioflinger/fastpath/AutoPark.h
+++ b/services/audioflinger/fastpath/AutoPark.h
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#pragma once
+
namespace android {
// T is FastMixer or FastCapture
diff --git a/services/audioflinger/fastpath/FastCapture.cpp b/services/audioflinger/fastpath/FastCapture.cpp
index 2963202..5c76649 100644
--- a/services/audioflinger/fastpath/FastCapture.cpp
+++ b/services/audioflinger/fastpath/FastCapture.cpp
@@ -33,8 +33,8 @@
/*static*/ const FastCaptureState FastCapture::sInitial;
FastCapture::FastCapture() : FastThread("cycleC_ms", "loadC_us"),
- mInputSource(NULL), mInputSourceGen(0), mPipeSink(NULL), mPipeSinkGen(0),
- mReadBuffer(NULL), mReadBufferState(-1), mFormat(Format_Invalid), mSampleRate(0),
+ mInputSource(nullptr), mInputSourceGen(0), mPipeSink(nullptr), mPipeSinkGen(0),
+ mReadBuffer(nullptr), mReadBufferState(-1), mFormat(Format_Invalid), mSampleRate(0),
// mDummyDumpState
mTotalNativeFramesRead(0)
{
@@ -44,10 +44,6 @@
mDummyDumpState = &mDummyFastCaptureDumpState;
}
-FastCapture::~FastCapture()
-{
-}
-
FastCaptureStateQueue* FastCapture::sq()
{
return &mSQ;
@@ -95,11 +91,11 @@
bool eitherChanged = false;
// check for change in input HAL configuration
- NBAIO_Format previousFormat = mFormat;
+ const NBAIO_Format previousFormat = mFormat;
if (current->mInputSourceGen != mInputSourceGen) {
mInputSource = current->mInputSource;
mInputSourceGen = current->mInputSourceGen;
- if (mInputSource == NULL) {
+ if (mInputSource == nullptr) {
mFormat = Format_Invalid;
mSampleRate = 0;
} else {
@@ -122,19 +118,19 @@
}
// 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()));
}
if ((!Format_isEqual(mFormat, previousFormat)) || (frameCount != previous->mFrameCount)) {
// FIXME to avoid priority inversion, don't free here
free(mReadBuffer);
- mReadBuffer = NULL;
+ mReadBuffer = nullptr;
if (frameCount > 0 && mSampleRate > 0) {
// 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
// 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);
memset(mReadBuffer, 0, bufferSize); // if posix_memalign fails, will segv here.
mPeriodNs = (frameCount * 1000000000LL) / mSampleRate; // 1.00
@@ -166,9 +162,9 @@
AudioBufferProvider* fastPatchRecordBufferProvider = current->mFastPatchRecordBufferProvider;
AudioBufferProvider::Buffer patchBuffer;
- if (fastPatchRecordBufferProvider != 0) {
+ if (fastPatchRecordBufferProvider != nullptr) {
patchBuffer.frameCount = ~0;
- status_t status = fastPatchRecordBufferProvider->getNextBuffer(&patchBuffer);
+ const status_t status = fastPatchRecordBufferProvider->getNextBuffer(&patchBuffer);
if (status != NO_ERROR) {
frameCount = 0;
} else if (patchBuffer.frameCount < frameCount) {
@@ -179,11 +175,11 @@
}
if ((command & FastCaptureState::READ) /*&& isWarm*/) {
- ALOG_ASSERT(mInputSource != NULL);
- ALOG_ASSERT(mReadBuffer != NULL);
+ ALOG_ASSERT(mInputSource != nullptr);
+ ALOG_ASSERT(mReadBuffer != nullptr);
dumpState->mReadSequence++;
ATRACE_BEGIN("read");
- ssize_t framesRead = mInputSource->read(mReadBuffer, frameCount);
+ const ssize_t framesRead = mInputSource->read(mReadBuffer, frameCount);
ATRACE_END();
dumpState->mReadSequence++;
if (framesRead >= 0) {
@@ -201,8 +197,8 @@
}
if (command & FastCaptureState::WRITE) {
- ALOG_ASSERT(mPipeSink != NULL);
- ALOG_ASSERT(mReadBuffer != NULL);
+ ALOG_ASSERT(mPipeSink != nullptr);
+ ALOG_ASSERT(mReadBuffer != nullptr);
if (mReadBufferState < 0) {
memset(mReadBuffer, 0, frameCount * Format_frameSize(mFormat));
mReadBufferState = frameCount;
@@ -211,23 +207,23 @@
if (current->mSilenceCapture) {
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;
- if (fastPatchRecordBufferProvider != 0) {
+ if (fastPatchRecordBufferProvider != nullptr) {
// This indicates the fast track is a patch record, update the cblk by
// calling releaseBuffer().
memcpy_by_audio_format(patchBuffer.raw, current->mFastPatchRecordFormat,
mReadBuffer, mFormat.mFormat, framesWritten * mFormat.mChannelCount);
patchBuffer.frameCount = framesWritten;
fastPatchRecordBufferProvider->releaseBuffer(&patchBuffer);
- } else if (cblk != NULL && framesWritten > 0) {
+ } else if (cblk != nullptr && framesWritten > 0) {
// FIXME This supports at most one fast capture client.
// 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.
- 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);
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)) {
// client is never in server process, so don't use FUTEX_WAKE_PRIVATE
(void) syscall(__NR_futex, &cblk->mFutex, FUTEX_WAKE, 1);
diff --git a/services/audioflinger/fastpath/FastCapture.h b/services/audioflinger/fastpath/FastCapture.h
index c3817c0..657a324 100644
--- a/services/audioflinger/fastpath/FastCapture.h
+++ b/services/audioflinger/fastpath/FastCapture.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_CAPTURE_H
-#define ANDROID_AUDIO_FAST_CAPTURE_H
+#pragma once
#include "FastThread.h"
#include "StateQueue.h"
@@ -24,13 +23,12 @@
namespace android {
-typedef StateQueue<FastCaptureState> FastCaptureStateQueue;
+using FastCaptureStateQueue = StateQueue<FastCaptureState>;
class FastCapture : public FastThread {
public:
FastCapture();
- virtual ~FastCapture();
FastCaptureStateQueue* sq();
@@ -38,13 +36,13 @@
FastCaptureStateQueue mSQ;
// callouts
- virtual const FastThreadState *poll();
- virtual void setNBLogWriter(NBLog::Writer *logWriter);
- virtual void onIdle();
- virtual void onExit();
- virtual bool isSubClassCommand(FastThreadState::Command command);
- virtual void onStateChange();
- virtual void onWork();
+ const FastThreadState *poll() override;
+ void setNBLogWriter(NBLog::Writer *logWriter) override;
+ void onIdle() override;
+ void onExit() override;
+ bool isSubClassCommand(FastThreadState::Command command) override;
+ void onStateChange() override;
+ void onWork() override;
static const FastCaptureState sInitial;
@@ -65,5 +63,3 @@
}; // class FastCapture
} // namespace android
-
-#endif // ANDROID_AUDIO_FAST_CAPTURE_H
diff --git a/services/audioflinger/fastpath/FastCaptureDumpState.cpp b/services/audioflinger/fastpath/FastCaptureDumpState.cpp
index 243dfa5..e0ac9cc 100644
--- a/services/audioflinger/fastpath/FastCaptureDumpState.cpp
+++ b/services/audioflinger/fastpath/FastCaptureDumpState.cpp
@@ -29,19 +29,15 @@
{
}
-FastCaptureDumpState::~FastCaptureDumpState()
-{
-}
-
void FastCaptureDumpState::dump(int fd) const
{
if (mCommand == FastCaptureState::INITIAL) {
dprintf(fd, " FastCapture not initialized\n");
return;
}
- double measuredWarmupMs = (mMeasuredWarmupTs.tv_sec * 1000.0) +
+ const double measuredWarmupMs = (mMeasuredWarmupTs.tv_sec * 1000.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"
" readErrors=%u sampleRate=%u frameCount=%zu\n"
" measuredWarmup=%.3g ms, warmupCycles=%u period=%.2f ms\n"
diff --git a/services/audioflinger/fastpath/FastCaptureDumpState.h b/services/audioflinger/fastpath/FastCaptureDumpState.h
index 34ce456..e205518 100644
--- a/services/audioflinger/fastpath/FastCaptureDumpState.h
+++ b/services/audioflinger/fastpath/FastCaptureDumpState.h
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_CAPTURE_DUMP_STATE_H
-#define ANDROID_AUDIO_FAST_CAPTURE_DUMP_STATE_H
+#pragma once
#include <stdint.h>
+#include <type_traits>
#include "Configuration.h"
#include "FastThreadDumpState.h"
@@ -25,7 +25,6 @@
struct FastCaptureDumpState : FastThreadDumpState {
FastCaptureDumpState();
- /*virtual*/ ~FastCaptureDumpState();
void dump(int fd) const; // should only be called on a stable copy, not the original
@@ -38,6 +37,7 @@
bool mSilenced = false; // capture is silenced
};
-} // namespace android
+// No virtuals
+static_assert(!std::is_polymorphic_v<FastCaptureDumpState>);
-#endif // ANDROID_AUDIO_FAST_CAPTURE_DUMP_STATE_H
+} // namespace android
diff --git a/services/audioflinger/fastpath/FastCaptureState.cpp b/services/audioflinger/fastpath/FastCaptureState.cpp
index 918ba9c..d2df62a 100644
--- a/services/audioflinger/fastpath/FastCaptureState.cpp
+++ b/services/audioflinger/fastpath/FastCaptureState.cpp
@@ -19,11 +19,7 @@
namespace android {
FastCaptureState::FastCaptureState() : FastThreadState(),
- mInputSource(NULL), mInputSourceGen(0), mPipeSink(NULL), mPipeSinkGen(0), mFrameCount(0)
-{
-}
-
-FastCaptureState::~FastCaptureState()
+ mInputSource(nullptr), mInputSourceGen(0), mPipeSink(nullptr), mPipeSinkGen(0), mFrameCount(0)
{
}
@@ -31,7 +27,7 @@
const char *FastCaptureState::commandToString(Command command)
{
const char *str = FastThreadState::commandToString(command);
- if (str != NULL) {
+ if (str != nullptr) {
return str;
}
switch (command) {
diff --git a/services/audioflinger/fastpath/FastCaptureState.h b/services/audioflinger/fastpath/FastCaptureState.h
index f949275..82ea0ed 100644
--- a/services/audioflinger/fastpath/FastCaptureState.h
+++ b/services/audioflinger/fastpath/FastCaptureState.h
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_CAPTURE_STATE_H
-#define ANDROID_AUDIO_FAST_CAPTURE_STATE_H
+#pragma once
+#include <type_traits>
#include <media/nbaio/NBAIO.h>
#include <media/AudioBufferProvider.h>
#include "FastThreadState.h"
@@ -27,7 +27,6 @@
// Represent a single state of the fast capture
struct FastCaptureState : FastThreadState {
FastCaptureState();
- /*virtual*/ ~FastCaptureState();
// all pointer fields use raw pointers; objects are owned and ref-counted by RecordThread
NBAIO_Source* mInputSource; // HAL input device, must already be negotiated
@@ -55,6 +54,7 @@
static const char *commandToString(Command command);
}; // struct FastCaptureState
-} // namespace android
+// No virtuals.
+static_assert(!std::is_polymorphic_v<FastCaptureState>);
-#endif // ANDROID_AUDIO_FAST_CAPTURE_STATE_H
+} // namespace android
diff --git a/services/audioflinger/fastpath/FastMixer.cpp b/services/audioflinger/fastpath/FastMixer.cpp
index 080b0a6..e13adab 100644
--- a/services/audioflinger/fastpath/FastMixer.cpp
+++ b/services/audioflinger/fastpath/FastMixer.cpp
@@ -61,13 +61,13 @@
: FastThread("cycle_ms", "load_us"),
// mFastTrackNames
// mGenerations
- mOutputSink(NULL),
+ mOutputSink(nullptr),
mOutputSinkGen(0),
- mMixer(NULL),
- mSinkBuffer(NULL),
+ mMixer(nullptr),
+ mSinkBuffer(nullptr),
mSinkBufferSize(0),
mSinkChannelCount(FCC_2),
- mMixerBuffer(NULL),
+ mMixerBuffer(nullptr),
mMixerBufferSize(0),
mMixerBufferState(UNDEFINED),
mFormat(Format_Invalid),
@@ -99,10 +99,6 @@
#endif
}
-FastMixer::~FastMixer()
-{
-}
-
FastMixerStateQueue* FastMixer::sq()
{
return &mSQ;
@@ -229,13 +225,13 @@
unsigned previousTrackMask;
// check for change in output HAL configuration
- NBAIO_Format previousFormat = mFormat;
+ const NBAIO_Format previousFormat = mFormat;
if (current->mOutputSinkGen != mOutputSinkGen) {
mOutputSink = current->mOutputSink;
mOutputSinkGen = current->mOutputSinkGen;
mSinkChannelMask = current->mSinkChannelMask;
mBalance.setChannelMask(mSinkChannelMask);
- if (mOutputSink == NULL) {
+ if (mOutputSink == nullptr) {
mFormat = Format_Invalid;
mSampleRate = 0;
mSinkChannelCount = 0;
@@ -259,11 +255,11 @@
if ((!Format_isEqual(mFormat, previousFormat)) || (frameCount != previous->mFrameCount)) {
// FIXME to avoid priority inversion, don't delete here
delete mMixer;
- mMixer = NULL;
+ mMixer = nullptr;
free(mMixerBuffer);
- mMixerBuffer = NULL;
+ mMixerBuffer = nullptr;
free(mSinkBuffer);
- mSinkBuffer = NULL;
+ mSinkBuffer = nullptr;
if (frameCount > 0 && mSampleRate > 0) {
// FIXME new may block for unbounded time at internal mutex of the heap
// implementation; it would be better to have normal mixer allocate for us
@@ -320,7 +316,7 @@
// process removed tracks first to avoid running out of track names
unsigned removedTracks = previousTrackMask & ~currentTrackMask;
while (removedTracks != 0) {
- int i = __builtin_ctz(removedTracks);
+ const int i = __builtin_ctz(removedTracks);
removedTracks &= ~(1 << i);
updateMixerTrack(i, REASON_REMOVE);
// don't reset track dump state, since other side is ignoring it
@@ -329,7 +325,7 @@
// now process added tracks
unsigned addedTracks = currentTrackMask & ~previousTrackMask;
while (addedTracks != 0) {
- int i = __builtin_ctz(addedTracks);
+ const int i = __builtin_ctz(addedTracks);
addedTracks &= ~(1 << i);
updateMixerTrack(i, REASON_ADD);
}
@@ -338,7 +334,7 @@
// but may have a different buffer provider or volume provider
unsigned modifiedTracks = currentTrackMask & previousTrackMask;
while (modifiedTracks != 0) {
- int i = __builtin_ctz(modifiedTracks);
+ const int i = __builtin_ctz(modifiedTracks);
modifiedTracks &= ~(1 << i);
updateMixerTrack(i, REASON_MODIFY);
}
@@ -373,8 +369,8 @@
const FastMixerState::Command command = mCommand;
const size_t frameCount = current->mFrameCount;
- if ((command & FastMixerState::MIX) && (mMixer != NULL) && mIsWarm) {
- ALOG_ASSERT(mMixerBuffer != NULL);
+ if ((command & FastMixerState::MIX) && (mMixer != nullptr) && mIsWarm) {
+ ALOG_ASSERT(mMixerBuffer != nullptr);
// AudioMixer::mState.enabledTracks is undefined if mState.hook == process__validate,
// so we keep a side copy of enabledTracks
@@ -383,7 +379,7 @@
// for each track, update volume and check for underrun
unsigned currentTrackMask = current->mTrackMask;
while (currentTrackMask != 0) {
- int i = __builtin_ctz(currentTrackMask);
+ const int i = __builtin_ctz(currentTrackMask);
currentTrackMask &= ~(1 << i);
const FastTrack* fastTrack = ¤t->mFastTracks[i];
@@ -406,8 +402,8 @@
fastTrack->mBufferProvider->onTimestamp(perTrackTimestamp);
const int name = i;
- if (fastTrack->mVolumeProvider != NULL) {
- gain_minifloat_packed_t vlr = fastTrack->mVolumeProvider->getVolumeLR();
+ if (fastTrack->mVolumeProvider != nullptr) {
+ const gain_minifloat_packed_t vlr = fastTrack->mVolumeProvider->getVolumeLR();
float vlf = float_from_gain(gain_minifloat_unpack_left(vlr));
float vrf = float_from_gain(gain_minifloat_unpack_right(vlr));
@@ -418,7 +414,7 @@
// takes a tryLock, which can block
// up to 1 ms. If enough active tracks all blocked in sequence, this would result
// in the overall fast mix cycle being delayed. Should use a non-blocking FIFO.
- size_t framesReady = fastTrack->mBufferProvider->framesReady();
+ const size_t framesReady = fastTrack->mBufferProvider->framesReady();
if (ATRACE_ENABLED()) {
// I wish we had formatted trace names
char traceName[16];
@@ -464,7 +460,8 @@
mMixerBufferState = UNDEFINED;
}
//bool didFullWrite = false; // dumpsys could display a count of partial writes
- if ((command & FastMixerState::WRITE) && (mOutputSink != NULL) && (mMixerBuffer != NULL)) {
+ if ((command & FastMixerState::WRITE)
+ && (mOutputSink != nullptr) && (mMixerBuffer != nullptr)) {
if (mMixerBufferState == UNDEFINED) {
memset(mMixerBuffer, 0, mMixerBufferSize);
mMixerBufferState = ZEROED;
@@ -481,7 +478,7 @@
mBalance.process((float *)mMixerBuffer, frameCount);
// prepare the buffer used to write to sink
- void *buffer = mSinkBuffer != NULL ? mSinkBuffer : mMixerBuffer;
+ void *buffer = mSinkBuffer != nullptr ? mSinkBuffer : mMixerBuffer;
if (mFormat.mFormat != mMixerBufferFormat) { // sink format not the same as mixer format
memcpy_by_audio_format(buffer, mFormat.mFormat, mMixerBuffer, mMixerBufferFormat,
frameCount * Format_channelCount(mFormat));
@@ -493,7 +490,7 @@
audio_bytes_per_sample(mFormat.mFormat),
frameCount * audio_bytes_per_frame(mAudioChannelCount, mFormat.mFormat));
}
- // if non-NULL, then duplicate write() to this non-blocking sink
+ // if non-nullptr, then duplicate write() to this non-blocking sink
#ifdef TEE_SINK
mTee.write(buffer, frameCount);
#endif
@@ -501,7 +498,7 @@
// but this code should be modified to handle both non-blocking and blocking sinks
dumpState->mWriteSequence++;
ATRACE_BEGIN("write");
- ssize_t framesWritten = mOutputSink->write(buffer, frameCount);
+ const ssize_t framesWritten = mOutputSink->write(buffer, frameCount);
ATRACE_END();
dumpState->mWriteSequence++;
if (framesWritten >= 0) {
diff --git a/services/audioflinger/fastpath/FastMixer.h b/services/audioflinger/fastpath/FastMixer.h
index 9847507..ab7bfe1 100644
--- a/services/audioflinger/fastpath/FastMixer.h
+++ b/services/audioflinger/fastpath/FastMixer.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_MIXER_H
-#define ANDROID_AUDIO_FAST_MIXER_H
+#pragma once
#include <atomic>
#include <audio_utils/Balance.h>
@@ -29,7 +28,7 @@
class AudioMixer;
-typedef StateQueue<FastMixerState> FastMixerStateQueue;
+using FastMixerStateQueue = StateQueue<FastMixerState>;
class FastMixer : public FastThread {
@@ -37,7 +36,6 @@
/** FastMixer constructor takes as param the parent MixerThread's io handle (id)
for purposes of identification. */
explicit FastMixer(audio_io_handle_t threadIoHandle);
- virtual ~FastMixer();
FastMixerStateQueue* sq();
@@ -51,13 +49,13 @@
FastMixerStateQueue mSQ;
// callouts
- virtual const FastThreadState *poll();
- virtual void setNBLogWriter(NBLog::Writer *logWriter);
- virtual void onIdle();
- virtual void onExit();
- virtual bool isSubClassCommand(FastThreadState::Command command);
- virtual void onStateChange();
- virtual void onWork();
+ const FastThreadState *poll() override;
+ void setNBLogWriter(NBLog::Writer *logWriter) override;
+ void onIdle() override;
+ void onExit() override;
+ bool isSubClassCommand(FastThreadState::Command command) override;
+ void onStateChange() override;
+ void onWork() override;
enum Reason {
REASON_REMOVE,
@@ -115,5 +113,3 @@
}; // class FastMixer
} // namespace android
-
-#endif // ANDROID_AUDIO_FAST_MIXER_H
diff --git a/services/audioflinger/fastpath/FastMixerDumpState.cpp b/services/audioflinger/fastpath/FastMixerDumpState.cpp
index d041882..f48f539 100644
--- a/services/audioflinger/fastpath/FastMixerDumpState.cpp
+++ b/services/audioflinger/fastpath/FastMixerDumpState.cpp
@@ -37,15 +37,11 @@
{
}
-FastMixerDumpState::~FastMixerDumpState()
-{
-}
-
// helper function called by qsort()
static int compare_uint32_t(const void *pa, const void *pb)
{
- uint32_t a = *(const uint32_t *)pa;
- uint32_t b = *(const uint32_t *)pb;
+ const uint32_t a = *(const uint32_t *)pa;
+ const uint32_t b = *(const uint32_t *)pb;
if (a < b) {
return -1;
} else if (a > b) {
@@ -61,9 +57,9 @@
dprintf(fd, " FastMixer not initialized\n");
return;
}
- double measuredWarmupMs = (mMeasuredWarmupTs.tv_sec * 1000.0) +
+ const double measuredWarmupMs = (mMeasuredWarmupTs.tv_sec * 1000.0) +
(mMeasuredWarmupTs.tv_nsec / 1000000.0);
- double mixPeriodSec = (double) mFrameCount / mSampleRate;
+ const double mixPeriodSec = (double) mFrameCount / mSampleRate;
dprintf(fd, " FastMixer command=%s writeSequence=%u framesWritten=%u\n"
" numTracks=%u writeErrors=%u underruns=%u overruns=%u\n"
" sampleRate=%u frameCount=%zu measuredWarmup=%.3g ms, warmupCycles=%u\n"
@@ -99,16 +95,16 @@
// the mean account for 99.73% of the population. So if we take each tail to be 1/1000 of the
// sample set, we get 99.8% combined, or close to three standard deviations.
static const uint32_t kTailDenominator = 1000;
- uint32_t *tail = n >= kTailDenominator ? new uint32_t[n] : NULL;
+ uint32_t *tail = n >= kTailDenominator ? new uint32_t[n] : nullptr;
// loop over all the samples
for (uint32_t j = 0; j < n; ++j) {
- size_t i = oldestClosed++ & (mSamplingN - 1);
- uint32_t wallNs = mMonotonicNs[i];
- if (tail != NULL) {
+ const size_t i = oldestClosed++ & (mSamplingN - 1);
+ const uint32_t wallNs = mMonotonicNs[i];
+ if (tail != nullptr) {
tail[j] = wallNs;
}
wall.add(wallNs);
- uint32_t sampleLoadNs = mLoadNs[i];
+ const uint32_t sampleLoadNs = mLoadNs[i];
loadNs.add(sampleLoadNs);
#ifdef CPU_FREQUENCY_STATISTICS
uint32_t sampleCpukHz = mCpukHz[i];
@@ -146,10 +142,10 @@
" mean=%.1f min=%.1f max=%.1f stddev=%.1f\n",
loadMHz.getMean(), loadMHz.getMin(), loadMHz.getMax(), loadMHz.getStdDev());
#endif
- if (tail != NULL) {
+ if (tail != nullptr) {
qsort(tail, n, sizeof(uint32_t), compare_uint32_t);
// assume same number of tail samples on each side, left and right
- uint32_t count = n / kTailDenominator;
+ const uint32_t count = n / kTailDenominator;
audio_utils::Statistics<double> left, right;
for (uint32_t i = 0; i < count; ++i) {
left.add(tail[i]);
@@ -175,7 +171,7 @@
FastMixerState::sMaxFastTracks, trackMask);
dprintf(fd, " Index Active Full Partial Empty Recent Ready Written\n");
for (uint32_t i = 0; i < FastMixerState::sMaxFastTracks; ++i, trackMask >>= 1) {
- bool isActive = trackMask & 1;
+ const bool isActive = trackMask & 1;
const FastTrackDump *ftDump = &mTracks[i];
const FastTrackUnderruns& underruns = ftDump->mUnderruns;
const char *mostRecent;
diff --git a/services/audioflinger/fastpath/FastMixerDumpState.h b/services/audioflinger/fastpath/FastMixerDumpState.h
index 294ef78..91d85b1 100644
--- a/services/audioflinger/fastpath/FastMixerDumpState.h
+++ b/services/audioflinger/fastpath/FastMixerDumpState.h
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_MIXER_DUMP_STATE_H
-#define ANDROID_AUDIO_FAST_MIXER_DUMP_STATE_H
+#pragma once
#include <stdint.h>
+#include <type_traits>
#include <audio_utils/TimestampVerifier.h>
#include "Configuration.h"
#include "FastThreadDumpState.h"
@@ -55,15 +55,16 @@
// Represents the dump state of a fast track
struct FastTrackDump {
FastTrackDump() : mFramesReady(0) { }
- /*virtual*/ ~FastTrackDump() { }
FastTrackUnderruns mUnderruns;
size_t mFramesReady; // most recent value only; no long-term statistics kept
int64_t mFramesWritten; // last value from track
};
+// No virtuals.
+static_assert(!std::is_polymorphic_v<FastTrackDump>);
+
struct FastMixerDumpState : FastThreadDumpState {
FastMixerDumpState();
- /*virtual*/ ~FastMixerDumpState();
void dump(int fd) const; // should only be called on a stable copy, not the original
@@ -81,6 +82,7 @@
TimestampVerifier<int64_t /* frame count */, int64_t /* time ns */> mTimestampVerifier;
};
-} // namespace android
+// No virtuals.
+static_assert(!std::is_polymorphic_v<FastMixerDumpState>);
-#endif // ANDROID_AUDIO_FAST_MIXER_DUMP_STATE_H
+} // namespace android
diff --git a/services/audioflinger/fastpath/FastMixerState.cpp b/services/audioflinger/fastpath/FastMixerState.cpp
index b98842d..dbccb10 100644
--- a/services/audioflinger/fastpath/FastMixerState.cpp
+++ b/services/audioflinger/fastpath/FastMixerState.cpp
@@ -23,30 +23,22 @@
namespace android {
FastTrack::FastTrack() :
- mBufferProvider(NULL), mVolumeProvider(NULL),
+ mBufferProvider(nullptr), mVolumeProvider(nullptr),
mChannelMask(AUDIO_CHANNEL_OUT_STEREO), mFormat(AUDIO_FORMAT_INVALID), mGeneration(0)
{
}
-FastTrack::~FastTrack()
-{
-}
-
FastMixerState::FastMixerState() : FastThreadState(),
// mFastTracks
- mFastTracksGen(0), mTrackMask(0), mOutputSink(NULL), mOutputSinkGen(0),
+ mFastTracksGen(0), mTrackMask(0), mOutputSink(nullptr), mOutputSinkGen(0),
mFrameCount(0)
{
- int ok = pthread_once(&sMaxFastTracksOnce, sMaxFastTracksInit);
+ const int ok = pthread_once(&sMaxFastTracksOnce, sMaxFastTracksInit);
if (ok != 0) {
ALOGE("%s pthread_once failed: %d", __func__, ok);
}
}
-FastMixerState::~FastMixerState()
-{
-}
-
// static
unsigned FastMixerState::sMaxFastTracks = kDefaultFastTracks;
@@ -57,7 +49,7 @@
const char *FastMixerState::commandToString(Command command)
{
const char *str = FastThreadState::commandToString(command);
- if (str != NULL) {
+ if (str != nullptr) {
return str;
}
switch (command) {
@@ -72,9 +64,9 @@
void FastMixerState::sMaxFastTracksInit()
{
char value[PROPERTY_VALUE_MAX];
- if (property_get("ro.audio.max_fast_tracks", value, NULL) > 0) {
+ if (property_get("ro.audio.max_fast_tracks", value, nullptr /* default_value */) > 0) {
char *endptr;
- unsigned long ul = strtoul(value, &endptr, 0);
+ const unsigned long ul = strtoul(value, &endptr, 0);
if (*endptr == '\0' && kMinFastTracks <= ul && ul <= kMaxFastTracks) {
sMaxFastTracks = (unsigned) ul;
}
diff --git a/services/audioflinger/fastpath/FastMixerState.h b/services/audioflinger/fastpath/FastMixerState.h
index ce3cc14..f40f612 100644
--- a/services/audioflinger/fastpath/FastMixerState.h
+++ b/services/audioflinger/fastpath/FastMixerState.h
@@ -14,10 +14,10 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_MIXER_STATE_H
-#define ANDROID_AUDIO_FAST_MIXER_STATE_H
+#pragma once
#include <math.h>
+#include <type_traits>
#include <audio_utils/minifloat.h>
#include <system/audio.h>
@@ -38,13 +38,12 @@
virtual gain_minifloat_packed_t getVolumeLR() = 0;
protected:
VolumeProvider() { }
- virtual ~VolumeProvider() { }
+ virtual ~VolumeProvider() = default;
};
// Represents the state of a fast track
struct FastTrack {
FastTrack();
- /*virtual*/ ~FastTrack();
ExtendedAudioBufferProvider* mBufferProvider; // must be NULL if inactive, or non-NULL if active
VolumeProvider* mVolumeProvider; // optional; if NULL then full-scale
@@ -56,10 +55,12 @@
float mHapticMaxAmplitude = NAN; // max amplitude allowed for haptic data
};
+// No virtuals.
+static_assert(!std::is_polymorphic_v<FastTrack>);
+
// Represents a single state of the fast mixer
struct FastMixerState : FastThreadState {
FastMixerState();
- /*virtual*/ ~FastMixerState();
// These are the minimum, maximum, and default values for maximum number of fast tracks
static const unsigned kMinFastTracks = 2;
@@ -95,6 +96,7 @@
}; // struct FastMixerState
-} // namespace android
+// No virtuals.
+static_assert(!std::is_polymorphic_v<FastMixerState>);
-#endif // ANDROID_AUDIO_FAST_MIXER_STATE_H
+} // namespace android
diff --git a/services/audioflinger/fastpath/FastThread.cpp b/services/audioflinger/fastpath/FastThread.cpp
index cadbbec..77071dc 100644
--- a/services/audioflinger/fastpath/FastThread.cpp
+++ b/services/audioflinger/fastpath/FastThread.cpp
@@ -40,7 +40,7 @@
FastThread::FastThread(const char *cycleMs, const char *loadUs) : Thread(false /*canCallJava*/),
// re-initialized to &sInitial by subclass constructor
- mPrevious(NULL), mCurrent(NULL),
+ mPrevious(nullptr), mCurrent(nullptr),
/* mOldTs({0, 0}), */
mOldTsValid(false),
mSleepNs(-1),
@@ -51,8 +51,8 @@
mWarmupNsMin(0),
mWarmupNsMax(LONG_MAX),
// re-initialized to &mDummySubclassDumpState by subclass constructor
- mDummyDumpState(NULL),
- mDumpState(NULL),
+ mDummyDumpState(nullptr),
+ mDumpState(nullptr),
mIgnoreNextOverrun(true),
#ifdef FAST_THREAD_STATISTICS
// mOldLoad
@@ -84,10 +84,6 @@
strlcpy(mLoadUs, loadUs, sizeof(mLoadUs));
}
-FastThread::~FastThread()
-{
-}
-
bool FastThread::threadLoop()
{
// LOGT now works even if tlNBLogWriter is nullptr, but we're considering changing that,
@@ -100,7 +96,7 @@
if (mSleepNs > 0) {
ALOG_ASSERT(mSleepNs < 1000000000);
const struct timespec req = {0, mSleepNs};
- nanosleep(&req, NULL);
+ nanosleep(&req, nullptr);
} else {
sched_yield();
}
@@ -110,7 +106,7 @@
// poll for state change
const FastThreadState *next = poll();
- if (next == NULL) {
+ if (next == nullptr) {
// continue to use the default initial state until a real state is available
// FIXME &sInitial not available, should save address earlier
//ALOG_ASSERT(mCurrent == &sInitial && previous == &sInitial);
@@ -121,8 +117,8 @@
if (next != mCurrent) {
// As soon as possible of learning of a new dump area, start using it
- mDumpState = next->mDumpState != NULL ? next->mDumpState : mDummyDumpState;
- tlNBLogWriter = next->mNBLogWriter != NULL ?
+ mDumpState = next->mDumpState != nullptr ? next->mDumpState : mDummyDumpState;
+ tlNBLogWriter = next->mNBLogWriter != nullptr ?
next->mNBLogWriter : mDummyNBLogWriter.get();
setNBLogWriter(tlNBLogWriter); // This is used for debugging only
@@ -149,7 +145,7 @@
mCurrent = next;
}
#if !LOG_NDEBUG
- next = NULL; // not referenced again
+ next = nullptr; // not referenced again
#endif
mDumpState->mCommand = mCommand;
@@ -167,12 +163,12 @@
// FIXME consider checking previous state and only perform if previous != COLD_IDLE
if (mCurrent->mColdGen != mColdGen) {
int32_t *coldFutexAddr = mCurrent->mColdFutexAddr;
- ALOG_ASSERT(coldFutexAddr != NULL);
- int32_t old = android_atomic_dec(coldFutexAddr);
+ ALOG_ASSERT(coldFutexAddr != nullptr);
+ const int32_t old = android_atomic_dec(coldFutexAddr);
if (old <= 0) {
- syscall(__NR_futex, coldFutexAddr, FUTEX_WAIT_PRIVATE, old - 1, NULL);
+ syscall(__NR_futex, coldFutexAddr, FUTEX_WAIT_PRIVATE, old - 1, nullptr);
}
- int policy = sched_getscheduler(0) & ~SCHED_RESET_ON_FORK;
+ const int policy = sched_getscheduler(0) & ~SCHED_RESET_ON_FORK;
if (!(policy == SCHED_FIFO || policy == SCHED_RR)) {
ALOGE("did not receive expected priority boost on time");
}
@@ -267,7 +263,7 @@
mSleepNs = -1;
if (mIsWarm) {
if (sec > 0 || nsec > mUnderrunNs) {
- ATRACE_NAME("underrun");
+ ATRACE_NAME("underrun"); // NOLINT(misc-const-correctness)
// FIXME only log occasionally
ALOGV("underrun: time since last cycle %d.%03ld sec",
(int) sec, nsec / 1000000L);
@@ -298,7 +294,7 @@
#ifdef FAST_THREAD_STATISTICS
if (mIsWarm) {
// advance the FIFO queue bounds
- size_t i = mBounds & (mDumpState->mSamplingN - 1);
+ const size_t i = mBounds & (mDumpState->mSamplingN - 1);
mBounds = (mBounds & 0xFFFF0000) | ((mBounds + 1) & 0xFFFF);
if (mFull) {
//mBounds += 0x10000;
diff --git a/services/audioflinger/fastpath/FastThread.h b/services/audioflinger/fastpath/FastThread.h
index 2f0f73f..84dc4d2 100644
--- a/services/audioflinger/fastpath/FastThread.h
+++ b/services/audioflinger/fastpath/FastThread.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_THREAD_H
-#define ANDROID_AUDIO_FAST_THREAD_H
+#pragma once
#include "Configuration.h"
#ifdef CPU_FREQUENCY_STATISTICS
@@ -31,11 +30,10 @@
public:
FastThread(const char *cycleMs, const char *loadUs);
- virtual ~FastThread();
private:
// implement Thread::threadLoop()
- virtual bool threadLoop();
+ bool threadLoop() override;
protected:
// callouts to subclass in same lexical order as they were in original FastMixer.cpp
@@ -93,5 +91,3 @@
}; // class FastThread
} // namespace android
-
-#endif // ANDROID_AUDIO_FAST_THREAD_H
diff --git a/services/audioflinger/fastpath/FastThreadDumpState.cpp b/services/audioflinger/fastpath/FastThreadDumpState.cpp
index e91073f..09d4744 100644
--- a/services/audioflinger/fastpath/FastThreadDumpState.cpp
+++ b/services/audioflinger/fastpath/FastThreadDumpState.cpp
@@ -34,17 +34,13 @@
#endif
}
-FastThreadDumpState::~FastThreadDumpState()
-{
-}
-
#ifdef FAST_THREAD_STATISTICS
void FastThreadDumpState::increaseSamplingN(uint32_t samplingN)
{
if (samplingN <= mSamplingN || samplingN > kSamplingN || roundup(samplingN) != samplingN) {
return;
}
- uint32_t additional = samplingN - mSamplingN;
+ const uint32_t additional = samplingN - mSamplingN;
// sample arrays aren't accessed atomically with respect to the bounds,
// so clearing reduces chance for dumpsys to read random uninitialized samples
memset(&mMonotonicNs[mSamplingN], 0, sizeof(mMonotonicNs[0]) * additional);
diff --git a/services/audioflinger/fastpath/FastThreadDumpState.h b/services/audioflinger/fastpath/FastThreadDumpState.h
index 0b20e55..63e81d3 100644
--- a/services/audioflinger/fastpath/FastThreadDumpState.h
+++ b/services/audioflinger/fastpath/FastThreadDumpState.h
@@ -14,8 +14,9 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_THREAD_DUMP_STATE_H
-#define ANDROID_AUDIO_FAST_THREAD_DUMP_STATE_H
+#pragma once
+
+#include <type_traits>
#include "Configuration.h"
#include "FastThreadState.h"
@@ -30,7 +31,6 @@
// It has a different lifetime than the FastThread, and so it can't be a member of FastThread.
struct FastThreadDumpState {
FastThreadDumpState();
- /*virtual*/ ~FastThreadDumpState();
FastThreadState::Command mCommand; // current command
uint32_t mUnderruns; // total number of underruns
@@ -67,6 +67,7 @@
}; // struct FastThreadDumpState
-} // namespace android
+// No virtuals.
+static_assert(!std::is_polymorphic_v<FastThreadDumpState>);
-#endif // ANDROID_AUDIO_FAST_THREAD_DUMP_STATE_H
+} // namespace android
diff --git a/services/audioflinger/fastpath/FastThreadState.cpp b/services/audioflinger/fastpath/FastThreadState.cpp
index ad5f31f..e6cb353 100644
--- a/services/audioflinger/fastpath/FastThreadState.cpp
+++ b/services/audioflinger/fastpath/FastThreadState.cpp
@@ -20,12 +20,8 @@
namespace android {
FastThreadState::FastThreadState() :
- mCommand(INITIAL), mColdFutexAddr(NULL), mColdGen(0), mDumpState(NULL), mNBLogWriter(NULL)
-
-{
-}
-
-FastThreadState::~FastThreadState()
+ mCommand(INITIAL), mColdFutexAddr(nullptr), mColdGen(0), mDumpState(nullptr)
+ , mNBLogWriter(nullptr)
{
}
@@ -38,7 +34,7 @@
case FastThreadState::COLD_IDLE: return "COLD_IDLE";
case FastThreadState::EXIT: return "EXIT";
}
- return NULL;
+ return nullptr;
}
} // namespace android
diff --git a/services/audioflinger/fastpath/FastThreadState.h b/services/audioflinger/fastpath/FastThreadState.h
index 9fb4e06..2b8b079 100644
--- a/services/audioflinger/fastpath/FastThreadState.h
+++ b/services/audioflinger/fastpath/FastThreadState.h
@@ -14,9 +14,9 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_FAST_THREAD_STATE_H
-#define ANDROID_AUDIO_FAST_THREAD_STATE_H
+#pragma once
+#include <type_traits>
#include "Configuration.h"
#include <stdint.h>
#include <media/nblog/NBLog.h>
@@ -28,9 +28,8 @@
// Represents a single state of a FastThread
struct FastThreadState {
FastThreadState();
- /*virtual*/ ~FastThreadState();
- typedef uint32_t Command;
+ using Command = uint32_t;
static const Command
INITIAL = 0, // used only for the initial state
HOT_IDLE = 1, // do nothing
@@ -50,6 +49,7 @@
static const char *commandToString(Command command);
}; // struct FastThreadState
-} // namespace android
+// No virtuals.
+static_assert(!std::is_polymorphic_v<FastThreadState>);
-#endif // ANDROID_AUDIO_FAST_THREAD_STATE_H
+} // namespace android
diff --git a/services/audioflinger/fastpath/StateQueue.cpp b/services/audioflinger/fastpath/StateQueue.cpp
index 38ce2c2..c466b9f 100644
--- a/services/audioflinger/fastpath/StateQueue.cpp
+++ b/services/audioflinger/fastpath/StateQueue.cpp
@@ -41,8 +41,8 @@
// Constructor and destructor
template<typename T> StateQueue<T>::StateQueue() :
- mAck(NULL), mCurrent(NULL),
- mMutating(&mStates[0]), mExpecting(NULL),
+ mAck(nullptr), mCurrent(nullptr),
+ mMutating(&mStates[0]), mExpecting(nullptr),
mInMutation(false), mIsDirty(false), mIsInitialized(false)
#ifdef STATE_QUEUE_DUMP
, mObserverDump(&mObserverDummyDump), mMutatorDump(&mMutatorDummyDump)
@@ -51,10 +51,6 @@
atomic_init(&mNext, static_cast<uintptr_t>(0));
}
-template<typename T> StateQueue<T>::~StateQueue()
-{
-}
-
// Observer APIs
template<typename T> const T* StateQueue<T>::poll()
@@ -112,7 +108,7 @@
#endif
// wait for prior push to be acknowledged
- if (mExpecting != NULL) {
+ if (mExpecting != nullptr) {
#ifdef STATE_QUEUE_DUMP
unsigned count = 0;
#endif
@@ -120,7 +116,7 @@
const T *ack = (const T *) mAck; // no additional barrier needed
if (ack == mExpecting) {
// unnecessary as we're about to rewrite
- //mExpecting = NULL;
+ //mExpecting = nullptr;
break;
}
if (block == BLOCK_NEVER) {
@@ -132,7 +128,7 @@
}
++count;
#endif
- nanosleep(&req, NULL);
+ nanosleep(&req, nullptr);
}
#ifdef STATE_QUEUE_DUMP
if (count > 1) {
@@ -156,14 +152,14 @@
// optionally wait for this push or a prior push to be acknowledged
if (block == BLOCK_UNTIL_ACKED) {
- if (mExpecting != NULL) {
+ if (mExpecting != nullptr) {
#ifdef STATE_QUEUE_DUMP
unsigned count = 0;
#endif
for (;;) {
const T *ack = (const T *) mAck; // no additional barrier needed
if (ack == mExpecting) {
- mExpecting = NULL;
+ mExpecting = nullptr;
break;
}
#ifdef STATE_QUEUE_DUMP
@@ -172,7 +168,7 @@
}
++count;
#endif
- nanosleep(&req, NULL);
+ nanosleep(&req, nullptr);
}
#ifdef STATE_QUEUE_DUMP
if (count > 1) {
diff --git a/services/audioflinger/fastpath/StateQueue.h b/services/audioflinger/fastpath/StateQueue.h
index 27f6a28..dff8f3f 100644
--- a/services/audioflinger/fastpath/StateQueue.h
+++ b/services/audioflinger/fastpath/StateQueue.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef ANDROID_AUDIO_STATE_QUEUE_H
-#define ANDROID_AUDIO_STATE_QUEUE_H
+#pragma once
#include <stdatomic.h>
@@ -128,7 +127,7 @@
public:
StateQueue();
- virtual ~StateQueue();
+ virtual ~StateQueue() = default; // why is this virtual?
// Observer APIs
@@ -211,5 +210,3 @@
}; // class StateQueue
} // namespace android
-
-#endif // ANDROID_AUDIO_STATE_QUEUE_H