Volume control for bit-perfect thread.
When there is a track play bit-perfectly, the framework will no longer
apply software volume control in the mixer. In that case, the audio
framework need to send the volume command down to the HAL.
Bug: 262578034
Test: adjust volume while play bit-perfectly
Change-Id: I927a9bd20b7fcce841a133c2786bdc4b352afa30
diff --git a/media/libaudioprocessing/AudioMixer.cpp b/media/libaudioprocessing/AudioMixer.cpp
index c2b82d1..6a39108 100644
--- a/media/libaudioprocessing/AudioMixer.cpp
+++ b/media/libaudioprocessing/AudioMixer.cpp
@@ -116,6 +116,9 @@
track->mKeepContractedChannels = false;
}
+ track->mInputFrameSize = audio_bytes_per_frame(
+ track->channelCount + track->mHapticChannelCount, track->mFormat);
+
// channel masks have changed, does this track need a downmixer?
// update to try using our desired format (if we aren't already using it)
const status_t status = track->prepareForDownmix();
@@ -309,9 +312,8 @@
ALOGV("AudioMixer::%s(%p) teeBuffer=%p", __func__, this, teeBuffer);
unprepareForTee();
if (teeBuffer != nullptr) {
- const size_t frameSize = audio_bytes_per_frame(channelCount + mHapticChannelCount, mFormat);
mTeeBufferProvider.reset(new TeeBufferProvider(
- frameSize, frameSize, kCopyBufferFrameCount,
+ mInputFrameSize, mInputFrameSize, kCopyBufferFrameCount,
(uint8_t*)teeBuffer, mTeeBufferFrameCount));
reconfigureBufferProviders();
}
@@ -590,6 +592,8 @@
t->mAdjustInChannelCount = t->channelCount + t->mHapticChannelCount;
t->mAdjustOutChannelCount = t->channelCount;
t->mKeepContractedChannels = false;
+ t->mInputFrameSize = audio_bytes_per_frame(
+ t->channelCount + t->mHapticChannelCount, t->mFormat);
// Check the downmixing (or upmixing) requirements.
status_t status = t->prepareForDownmix();
if (status != OK) {
@@ -641,6 +645,10 @@
}
break;
}
+ if (t->teeBuffer != nullptr && t->volumeRL == 0) {
+ // Need to mute tee
+ memset(t->teeBuffer, 0, t->mTeeBufferFrameCount * t->mInputFrameSize);
+ }
}
}
}
diff --git a/media/libaudioprocessing/AudioMixerBase.cpp b/media/libaudioprocessing/AudioMixerBase.cpp
index fd06991..427bd55 100644
--- a/media/libaudioprocessing/AudioMixerBase.cpp
+++ b/media/libaudioprocessing/AudioMixerBase.cpp
@@ -152,6 +152,7 @@
AUDIO_CHANNEL_REPRESENTATION_POSITION, AUDIO_CHANNEL_OUT_STEREO);
t->mMixerChannelCount = audio_channel_count_from_out_mask(t->mMixerChannelMask);
t->mTeeBufferFrameCount = 0;
+ t->mInputFrameSize = audio_bytes_per_frame(t->channelCount, t->mFormat);
status_t status = postCreateTrack(t.get());
if (status != OK) return status;
mTracks[name] = t;
@@ -178,6 +179,7 @@
track->channelCount = trackChannelCount;
track->mMixerChannelMask = mixerChannelMask;
track->mMixerChannelCount = mixerChannelCount;
+ track->mInputFrameSize = audio_bytes_per_frame(track->channelCount, track->mFormat);
// Resampler channels may have changed.
track->recreateResampler(mSampleRate);
diff --git a/media/libaudioprocessing/include/media/AudioMixerBase.h b/media/libaudioprocessing/include/media/AudioMixerBase.h
index caccb6a..4bd85d8 100644
--- a/media/libaudioprocessing/include/media/AudioMixerBase.h
+++ b/media/libaudioprocessing/include/media/AudioMixerBase.h
@@ -297,6 +297,8 @@
int32_t mTeeBufferFrameCount;
+ uint32_t mInputFrameSize; // The track input frame size, used for tee buffer
+
protected:
// hooks