CSD: enable CSD for MMap threads
Using the buffer provided by the AAudio service to add values to the
sound dosage.
Test: OboeTester with AAudio and MMap
Bug: 264254430
Change-Id: I38b7d3b69bc8d6923f848bc504c6290ae1961cbc
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 0f65aec..743f94b 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -2045,6 +2045,21 @@
return AudioSystem::getStrategyForStream(stream);
}
+// startMelComputation_l() must be called with AudioFlinger::mLock held
+void AudioFlinger::ThreadBase::startMelComputation_l(
+ const sp<audio_utils::MelProcessor>& /*processor*/)
+{
+ // Do nothing
+ ALOGW("%s: ThreadBase does not support CSD", __func__);
+}
+
+// stopMelComputation_l() must be called with AudioFlinger::mLock held
+void AudioFlinger::ThreadBase::stopMelComputation_l()
+{
+ // Do nothing
+ ALOGW("%s: ThreadBase does not support CSD", __func__);
+}
+
// ----------------------------------------------------------------------------
// Playback
// ----------------------------------------------------------------------------
@@ -3470,14 +3485,16 @@
return bytesWritten;
}
-void AudioFlinger::PlaybackThread::startMelComputation(
+// startMelComputation_l() must be called with AudioFlinger::mLock held
+void AudioFlinger::PlaybackThread::startMelComputation_l(
const sp<audio_utils::MelProcessor>& processor)
{
auto outputSink = static_cast<AudioStreamOutSink*>(mOutputSink.get());
outputSink->startMelComputation(processor);
}
-void AudioFlinger::PlaybackThread::stopMelComputation()
+// stopMelComputation_l() must be called with AudioFlinger::mLock held
+void AudioFlinger::PlaybackThread::stopMelComputation_l()
{
auto outputSink = static_cast<AudioStreamOutSink*>(mOutputSink.get());
outputSink->stopMelComputation();
@@ -10135,7 +10152,6 @@
return INVALID_OPERATION;
}
-
void AudioFlinger::MmapThread::readHalParameters_l()
{
status_t result = mHalStream->getAudioProperties(&mSampleRate, &mChannelMask, &mHALFormat);
@@ -10818,12 +10834,32 @@
}
status_t AudioFlinger::MmapPlaybackThread::reportData(const void* buffer, size_t frameCount) {
- // TODO(264254430): send the data to mel processor.
- (void) buffer;
- (void) frameCount;
+ // Send to MelProcessor for sound dose measurement.
+ auto processor = mMelProcessor.load();
+ if (processor) {
+ processor->process(buffer, frameCount * mFrameSize);
+ }
+
return NO_ERROR;
}
+// startMelComputation_l() must be called with AudioFlinger::mLock held
+void AudioFlinger::MmapPlaybackThread::startMelComputation_l(
+ const sp<audio_utils::MelProcessor>& processor)
+{
+ ALOGV("%s: starting mel processor for thread %d", __func__, id());
+ if (processor != nullptr) {
+ mMelProcessor = processor;
+ }
+}
+
+// stopMelComputation_l() must be called with AudioFlinger::mLock held
+void AudioFlinger::MmapPlaybackThread::stopMelComputation_l()
+{
+ ALOGV("%s: stopping mel processor for thread %d", __func__, id());
+ mMelProcessor = nullptr;
+}
+
void AudioFlinger::MmapPlaybackThread::dumpInternals_l(int fd, const Vector<String16>& args)
{
MmapThread::dumpInternals_l(fd, args);