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

Commit e47a66b9 authored by Alexy Joseph's avatar Alexy Joseph Committed by Steve Kondik
Browse files

libmedia: AudioTrack offload only for STREAM_MUSIC

If the values set for stream type or attributes->usage
is not one of the supported values, then these tracks
should not be offloaded. Fix this by checking
the appropriate flags

CRs-Fixed: 833895

Change-Id: Ibd1b426d4c0cc4d2bd968aaf7571aa7d1838800f
parent efbf1458
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -687,6 +687,9 @@ protected:
            // increment mPosition by the delta of mServer, and return new value of mPosition
            uint32_t updateAndGetPosition_l();

            static bool decideTrackOffloadFromStreamType(const audio_stream_type_t sType);

            static bool decideTrackOffloadfromAttributes(const audio_attributes_t *pAttributes);
    // Next 4 fields may be changed if IAudioTrack is re-created, but always != 0
#ifdef QCOM_DIRECTTRACK
    sp<IDirectTrack>        mDirectTrack;
+49 −9
Original line number Diff line number Diff line
@@ -383,10 +383,13 @@ status_t AudioTrack::set(
        return INVALID_OPERATION;
    }

    mCanOffloadPcmTrack = decideTrackOffloadFromStreamType(streamType);

     // handle default values first.
    if (streamType == AUDIO_STREAM_DEFAULT) {
        streamType = AUDIO_STREAM_MUSIC;
    }

    if (pAttributes == NULL) {
        if (uint32_t(streamType) >= AUDIO_STREAM_PUBLIC_CNT) {
            ALOGE("Invalid stream type %d", streamType);
@@ -399,6 +402,7 @@ status_t AudioTrack::set(
        memcpy(&mAttributes, pAttributes, sizeof(audio_attributes_t));
        ALOGV("Building AudioTrack with attributes: usage=%d content=%d flags=0x%x tags=[%s]",
                mAttributes.usage, mAttributes.content_type, mAttributes.flags, mAttributes.tags);
        mCanOffloadPcmTrack = decideTrackOffloadfromAttributes(&mAttributes);
        mStreamType = AUDIO_STREAM_DEFAULT;
    }

@@ -864,13 +868,20 @@ void AudioTrack::pause()
            // here can be slightly off.

            // TODO: check return code for getRenderPosition.

            if (mIsPcmTrackOffloaded) {
                uint32_t tempPos = 0;
                tempPos = (mState == STATE_STOPPED || mState == STATE_FLUSHED) ?
                    0 : updateAndGetPosition_l();
                mPausedPosition = (tempPos / (mChannelCount * audio_bytes_per_sample(mFormat)));
                ALOGV("TrackOffload::pause for offload, cache current position %u", mPausedPosition);
            } else {
                uint32_t halFrames;
                AudioSystem::getRenderPosition(mOutput, &halFrames, &mPausedPosition);
                ALOGV("AudioTrack::pause for offload, cache current position %u", mPausedPosition);
            }
        }
    }
}

status_t AudioTrack::setVolume(float left, float right)
{
@@ -1216,14 +1227,15 @@ status_t AudioTrack::createTrack_l()
    audio_io_handle_t output = AUDIO_IO_HANDLE_NONE;
    audio_stream_type_t streamType = mStreamType;
    audio_attributes_t *attr = (mStreamType == AUDIO_STREAM_DEFAULT) ? &mAttributes : NULL;
    mCanOffloadPcmTrack = false;
    mIsPcmTrackOffloaded = false;
    mPcmTrackOffloadInfo = AUDIO_INFO_INITIALIZER;

    // Check if the track can be offloaded. Store the decision in mCanOffloadPcmTrack
    // if stream type was not set, then do not try to offload track
    if (mCanOffloadPcmTrack) {
        mCanOffloadPcmTrack = canOffloadTrack(mStreamType, mFormat, mChannelMask, mFlags,
                                  mTransfer, &mAttributes, mOffloadInfo);

    }

    if(mCanOffloadPcmTrack) {
        ALOGV("TrackOffload: Tying to create PCM Offload track");
@@ -2600,4 +2612,32 @@ void AudioTrack::AudioTrackThread::pauseInternal(nsecs_t ns)
    mPausedNs = ns;
}

bool AudioTrack::decideTrackOffloadFromStreamType(const audio_stream_type_t sType){

   bool decision = false;
   if(sType != AUDIO_STREAM_DEFAULT) {
       decision = true;
   }

   return decision;
}

bool AudioTrack::decideTrackOffloadfromAttributes(const audio_attributes_t *pAttributes) {

    bool decision = false;
    if (pAttributes == NULL) {
       return decision;
    }

    if ((pAttributes->usage == AUDIO_USAGE_MEDIA) ||
        (pAttributes->usage == AUDIO_USAGE_GAME)) {
        //the track can potentially be offloaded
        decision = true;
    } else {
        ALOGV("TrackOffload: do not offload the track if attributes->usage is not media/game");
    }

    return decision;
}

}; // namespace android