audio: Treat PCM offload the same as compressed offload
Test: MediaPlayer PCM playback
Test: atest AudioTrackOffloadTest
Test: atest MediaPlayerTest
Test: atest CtsMediaAudioTestCases
Flag: EXEMPT bugfix
Bug: 357483620
Change-Id: Ib3b272a3d4571f2d23f2ac2e78a7c7d8c0b18b5c
diff --git a/media/libaudioclient/AudioTrack.cpp b/media/libaudioclient/AudioTrack.cpp
index e2386ca..161c4d5 100644
--- a/media/libaudioclient/AudioTrack.cpp
+++ b/media/libaudioclient/AudioTrack.cpp
@@ -2401,12 +2401,14 @@
int32_t flags = android_atomic_and(
~(CBLK_UNDERRUN | CBLK_LOOP_CYCLE | CBLK_LOOP_FINAL | CBLK_BUFFER_END), &mCblk->mFlags);
+ const bool isOffloaded = isOffloaded_l();
+ const bool isOffloadedOrDirect = isOffloadedOrDirect_l();
// Check for track invalidation
if (flags & CBLK_INVALID) {
// for offloaded tracks restoreTrack_l() will just update the sequence and clear
// AudioSystem cache. We should not exit here but after calling the callback so
// that the upper layers can recreate the track
- if (!isOffloadedOrDirect_l() || (mSequence == mObservedSequence)) {
+ if (!isOffloadedOrDirect || (mSequence == mObservedSequence)) {
status_t status __unused = restoreTrack_l("processAudioBuffer");
// FIXME unused status
// after restoration, continue below to make sure that the loop and buffer events
@@ -2576,7 +2578,7 @@
mObservedSequence = sequence;
callback->onNewIAudioTrack();
// for offloaded tracks, just wait for the upper layers to recreate the track
- if (isOffloadedOrDirect()) {
+ if (isOffloadedOrDirect) {
return NS_INACTIVE;
}
}
@@ -2664,7 +2666,7 @@
__func__, mPortId, mRemainingFrames, avail, audioBuffer.frameCount, nonContig, err);
if (err != NO_ERROR) {
if (err == TIMED_OUT || err == WOULD_BLOCK || err == -EINTR ||
- (isOffloaded() && (err == DEAD_OBJECT))) {
+ (isOffloaded && (err == DEAD_OBJECT))) {
// FIXME bug 25195759
return 1000000;
}
@@ -2750,7 +2752,7 @@
// buffer size and skip the loop entirely.
nsecs_t myns;
- if (audio_has_proportional_frames(mFormat)) {
+ if (!isOffloaded && audio_has_proportional_frames(mFormat)) {
// time to wait based on buffer occupancy
const nsecs_t datans = mRemainingFrames <= avail ? 0 :
framesToNanoseconds(mRemainingFrames - avail, sampleRate, speed);
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 7c7d812..cd997b2 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -7151,7 +7151,7 @@
uint32_t DirectOutputThread::activeSleepTimeUs() const
{
uint32_t time;
- if (audio_has_proportional_frames(mFormat)) {
+ if (audio_has_proportional_frames(mFormat) && mType != OFFLOAD) {
time = PlaybackThread::activeSleepTimeUs();
} else {
time = kDirectMinSleepTimeUs;
@@ -7162,7 +7162,7 @@
uint32_t DirectOutputThread::idleSleepTimeUs() const
{
uint32_t time;
- if (audio_has_proportional_frames(mFormat)) {
+ if (audio_has_proportional_frames(mFormat) && mType != OFFLOAD) {
time = (uint32_t)(((mFrameCount * 1000) / mSampleRate) * 1000) / 2;
} else {
time = kDirectMinSleepTimeUs;
@@ -7173,7 +7173,7 @@
uint32_t DirectOutputThread::suspendSleepTimeUs() const
{
uint32_t time;
- if (audio_has_proportional_frames(mFormat)) {
+ if (audio_has_proportional_frames(mFormat) && mType != OFFLOAD) {
time = (uint32_t)(((mFrameCount * 1000) / mSampleRate) * 1000);
} else {
time = kDirectMinSleepTimeUs;
@@ -7190,7 +7190,7 @@
// no delay on outputs with HW A/V sync
if (usesHwAvSync()) {
mStandbyDelayNs = 0;
- } else if ((mType == OFFLOAD) && !audio_has_proportional_frames(mFormat)) {
+ } else if (mType == OFFLOAD) {
mStandbyDelayNs = kOffloadStandbyDelayNs;
} else {
mStandbyDelayNs = microseconds(mActiveSleepTimeUs*2);