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

Commit e13ac73a authored by Glenn Kasten's avatar Glenn Kasten Committed by Android (Google) Code Review
Browse files

Merge "Simplify code"

parents e7c84be4 7d3be3a3
Loading
Loading
Loading
Loading
+11 −34
Original line number Original line Diff line number Diff line
@@ -2688,7 +2688,6 @@ bool AudioFlinger::DirectOutputThread::threadLoop()
    sp<Track> trackToRemove;
    sp<Track> trackToRemove;
    sp<Track> activeTrack;
    sp<Track> activeTrack;
    nsecs_t standbyTime = systemTime();
    nsecs_t standbyTime = systemTime();
    int8_t *curBuf;
    size_t mixBufferSize = mFrameCount*mFrameSize;
    size_t mixBufferSize = mFrameCount*mFrameSize;
    uint32_t activeSleepTime = activeSleepTimeUs();
    uint32_t activeSleepTime = activeSleepTimeUs();
    uint32_t idleSleepTime = idleSleepTimeUs();
    uint32_t idleSleepTime = idleSleepTimeUs();
@@ -2892,7 +2891,7 @@ bool AudioFlinger::DirectOutputThread::threadLoop()
        if (CC_LIKELY(mixerStatus == MIXER_TRACKS_READY)) {
        if (CC_LIKELY(mixerStatus == MIXER_TRACKS_READY)) {
            AudioBufferProvider::Buffer buffer;
            AudioBufferProvider::Buffer buffer;
            size_t frameCount = mFrameCount;
            size_t frameCount = mFrameCount;
            curBuf = (int8_t *)mMixBuffer;
            int8_t *curBuf = (int8_t *)mMixBuffer;
            // output audio to hardware
            // output audio to hardware
            while (frameCount) {
            while (frameCount) {
                buffer.frameCount = frameCount;
                buffer.frameCount = frameCount;
@@ -3254,7 +3253,7 @@ void AudioFlinger::DuplicatingThread::removeOutputTrack(MixerThread *thread)
{
{
    Mutex::Autolock _l(mLock);
    Mutex::Autolock _l(mLock);
    for (size_t i = 0; i < mOutputTracks.size(); i++) {
    for (size_t i = 0; i < mOutputTracks.size(); i++) {
        if (mOutputTracks[i]->thread() == (ThreadBase *)thread) {
        if (mOutputTracks[i]->thread() == thread) {
            mOutputTracks[i]->destroy();
            mOutputTracks[i]->destroy();
            mOutputTracks.removeAt(i);
            mOutputTracks.removeAt(i);
            updateWaitTime();
            updateWaitTime();
@@ -4502,10 +4501,9 @@ status_t AudioFlinger::PlaybackThread::OutputTrack::obtainBuffer(AudioBufferProv
void AudioFlinger::PlaybackThread::OutputTrack::clearBufferQueue()
void AudioFlinger::PlaybackThread::OutputTrack::clearBufferQueue()
{
{
    size_t size = mBufferQueue.size();
    size_t size = mBufferQueue.size();
    Buffer *pBuffer;


    for (size_t i = 0; i < size; i++) {
    for (size_t i = 0; i < size; i++) {
        pBuffer = mBufferQueue.itemAt(i);
        Buffer *pBuffer = mBufferQueue.itemAt(i);
        delete [] pBuffer->mBuffer;
        delete [] pBuffer->mBuffer;
        delete pBuffer;
        delete pBuffer;
    }
    }
@@ -4577,10 +4575,8 @@ AudioFlinger::NotificationClient::~NotificationClient()
void AudioFlinger::NotificationClient::binderDied(const wp<IBinder>& who)
void AudioFlinger::NotificationClient::binderDied(const wp<IBinder>& who)
{
{
    sp<NotificationClient> keep(this);
    sp<NotificationClient> keep(this);
    {
    mAudioFlinger->removeNotificationClient(mPid);
    mAudioFlinger->removeNotificationClient(mPid);
}
}
}


// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------


@@ -5555,8 +5551,7 @@ status_t AudioFlinger::closeOutput(audio_io_handle_t output)
                }
                }
            }
            }
        }
        }
        void *param2 = NULL;
        audioConfigChanged_l(AudioSystem::OUTPUT_CLOSED, output, NULL);
        audioConfigChanged_l(AudioSystem::OUTPUT_CLOSED, output, param2);
        mPlaybackThreads.removeItem(output);
        mPlaybackThreads.removeItem(output);
    }
    }
    thread->exit();
    thread->exit();
@@ -5700,8 +5695,7 @@ status_t AudioFlinger::closeInput(audio_io_handle_t input)
        }
        }


        ALOGV("closeInput() %d", input);
        ALOGV("closeInput() %d", input);
        void *param2 = NULL;
        audioConfigChanged_l(AudioSystem::INPUT_CLOSED, input, NULL);
        audioConfigChanged_l(AudioSystem::INPUT_CLOSED, input, param2);
        mRecordThreads.removeItem(input);
        mRecordThreads.removeItem(input);
    }
    }
    thread->exit();
    thread->exit();
@@ -5733,8 +5727,7 @@ status_t AudioFlinger::setStreamOutput(audio_stream_type_t stream, audio_io_hand


    for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
    for (size_t i = 0; i < mPlaybackThreads.size(); i++) {
        PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
        PlaybackThread *thread = mPlaybackThreads.valueAt(i).get();
        if (thread != dstThread &&
        if (thread != dstThread && thread->type() != ThreadBase::DIRECT) {
            thread->type() != ThreadBase::DIRECT) {
            MixerThread *srcThread = (MixerThread *)thread;
            MixerThread *srcThread = (MixerThread *)thread;
            srcThread->setStreamValid(stream, false);
            srcThread->setStreamValid(stream, false);
            srcThread->invalidateTracks(stream);
            srcThread->invalidateTracks(stream);
@@ -5857,33 +5850,20 @@ void AudioFlinger::purgeStaleEffects_l() {
// checkPlaybackThread_l() must be called with AudioFlinger::mLock held
// checkPlaybackThread_l() must be called with AudioFlinger::mLock held
AudioFlinger::PlaybackThread *AudioFlinger::checkPlaybackThread_l(audio_io_handle_t output) const
AudioFlinger::PlaybackThread *AudioFlinger::checkPlaybackThread_l(audio_io_handle_t output) const
{
{
    PlaybackThread *thread = NULL;
    return mPlaybackThreads.valueFor(output).get();
    if (mPlaybackThreads.indexOfKey(output) >= 0) {
        thread = (PlaybackThread *)mPlaybackThreads.valueFor(output).get();
    }
    return thread;
}
}


// checkMixerThread_l() must be called with AudioFlinger::mLock held
// checkMixerThread_l() must be called with AudioFlinger::mLock held
AudioFlinger::MixerThread *AudioFlinger::checkMixerThread_l(audio_io_handle_t output) const
AudioFlinger::MixerThread *AudioFlinger::checkMixerThread_l(audio_io_handle_t output) const
{
{
    PlaybackThread *thread = checkPlaybackThread_l(output);
    PlaybackThread *thread = checkPlaybackThread_l(output);
    if (thread != NULL) {
    return thread != NULL && thread->type() != ThreadBase::DIRECT ? (MixerThread *) thread : NULL;
        if (thread->type() == ThreadBase::DIRECT) {
            thread = NULL;
        }
    }
    return (MixerThread *)thread;
}
}


// checkRecordThread_l() must be called with AudioFlinger::mLock held
// checkRecordThread_l() must be called with AudioFlinger::mLock held
AudioFlinger::RecordThread *AudioFlinger::checkRecordThread_l(audio_io_handle_t input) const
AudioFlinger::RecordThread *AudioFlinger::checkRecordThread_l(audio_io_handle_t input) const
{
{
    RecordThread *thread = NULL;
    return mRecordThreads.valueFor(input).get();
    if (mRecordThreads.indexOfKey(input) >= 0) {
        thread = (RecordThread *)mRecordThreads.valueFor(input).get();
    }
    return thread;
}
}


uint32_t AudioFlinger::nextUniqueId()
uint32_t AudioFlinger::nextUniqueId()
@@ -6246,10 +6226,7 @@ sp<AudioFlinger::EffectHandle> AudioFlinger::ThreadBase::createEffect_l(
        goto Exit;
        goto Exit;
    }
    }
    // Only Pre processor effects are allowed on input threads and only on input threads
    // Only Pre processor effects are allowed on input threads and only on input threads
    if ((mType == RECORD &&
    if ((mType == RECORD) != ((desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC)) {
            (desc->flags & EFFECT_FLAG_TYPE_MASK) != EFFECT_FLAG_TYPE_PRE_PROC) ||
            (mType != RECORD &&
                    (desc->flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_PRE_PROC)) {
        ALOGW("createEffect_l() effect %s (flags %08x) created on wrong thread type %d",
        ALOGW("createEffect_l() effect %s (flags %08x) created on wrong thread type %d",
                desc->name, desc->flags, mType);
                desc->name, desc->flags, mType);
        lStatus = BAD_VALUE;
        lStatus = BAD_VALUE;
+3 −3
Original line number Original line Diff line number Diff line
@@ -766,7 +766,7 @@ private:
            virtual status_t    start(pid_t tid);
            virtual status_t    start(pid_t tid);
            virtual void        stop();
            virtual void        stop();
                    bool        write(int16_t* data, uint32_t frames);
                    bool        write(int16_t* data, uint32_t frames);
                    bool        bufferQueueEmpty() const { return (mBufferQueue.size() == 0) ? true : false; }
                    bool        bufferQueueEmpty() const { return mBufferQueue.size() == 0; }
                    bool        isActive() const { return mActive; }
                    bool        isActive() const { return mActive; }
            const wp<ThreadBase>& thread() const { return mThread; }
            const wp<ThreadBase>& thread() const { return mThread; }


@@ -994,8 +994,8 @@ private:
              uint32_t nextUniqueId();
              uint32_t nextUniqueId();


              status_t moveEffectChain_l(int sessionId,
              status_t moveEffectChain_l(int sessionId,
                                     AudioFlinger::PlaybackThread *srcThread,
                                     PlaybackThread *srcThread,
                                     AudioFlinger::PlaybackThread *dstThread,
                                     PlaybackThread *dstThread,
                                     bool reRegister);
                                     bool reRegister);
              PlaybackThread *primaryPlaybackThread_l();
              PlaybackThread *primaryPlaybackThread_l();
              uint32_t primaryOutputDevice_l();
              uint32_t primaryOutputDevice_l();
+4 −4
Original line number Original line Diff line number Diff line
@@ -556,7 +556,7 @@ void AudioMixer::volumeRampStereo(track_t* t, int32_t* out, size_t frameCount, i
    }
    }
    t->prevVolume[0] = vl;
    t->prevVolume[0] = vl;
    t->prevVolume[1] = vr;
    t->prevVolume[1] = vr;
    t->adjustVolumeRamp((aux != NULL));
    t->adjustVolumeRamp(aux != NULL);
}
}


void AudioMixer::volumeStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp, int32_t* aux)
void AudioMixer::volumeStereo(track_t* t, int32_t* out, size_t frameCount, int32_t* temp, int32_t* aux)
@@ -862,7 +862,7 @@ void AudioMixer::process__genericNoResampling(state_t* state, int64_t pts)
                while (outFrames) {
                while (outFrames) {
                    size_t inFrames = (t.frameCount > outFrames)?outFrames:t.frameCount;
                    size_t inFrames = (t.frameCount > outFrames)?outFrames:t.frameCount;
                    if (inFrames) {
                    if (inFrames) {
                        (t.hook)(&t, outTemp + (BLOCKSIZE-outFrames)*MAX_NUM_CHANNELS, inFrames, state->resampleTemp, aux);
                        t.hook(&t, outTemp + (BLOCKSIZE-outFrames)*MAX_NUM_CHANNELS, inFrames, state->resampleTemp, aux);
                        t.frameCount -= inFrames;
                        t.frameCount -= inFrames;
                        outFrames -= inFrames;
                        outFrames -= inFrames;
                        if (CC_UNLIKELY(aux != NULL)) {
                        if (CC_UNLIKELY(aux != NULL)) {
@@ -944,7 +944,7 @@ void AudioMixer::process__genericResampling(state_t* state, int64_t pts)
            // the resampler.
            // the resampler.
            if ((t.needs & NEEDS_RESAMPLE__MASK) == NEEDS_RESAMPLE_ENABLED) {
            if ((t.needs & NEEDS_RESAMPLE__MASK) == NEEDS_RESAMPLE_ENABLED) {
                t.resampler->setPTS(pts);
                t.resampler->setPTS(pts);
                (t.hook)(&t, outTemp, numFrames, state->resampleTemp, aux);
                t.hook(&t, outTemp, numFrames, state->resampleTemp, aux);
            } else {
            } else {


                size_t outFrames = 0;
                size_t outFrames = 0;
@@ -961,7 +961,7 @@ void AudioMixer::process__genericResampling(state_t* state, int64_t pts)
                    if (CC_UNLIKELY(aux != NULL)) {
                    if (CC_UNLIKELY(aux != NULL)) {
                        aux += outFrames;
                        aux += outFrames;
                    }
                    }
                    (t.hook)(&t, outTemp + outFrames*MAX_NUM_CHANNELS, t.buffer.frameCount, state->resampleTemp, aux);
                    t.hook(&t, outTemp + outFrames*MAX_NUM_CHANNELS, t.buffer.frameCount, state->resampleTemp, aux);
                    outFrames += t.buffer.frameCount;
                    outFrames += t.buffer.frameCount;
                    t.bufferProvider->releaseBuffer(&t.buffer);
                    t.bufferProvider->releaseBuffer(&t.buffer);
                }
                }
+1 −2
Original line number Original line Diff line number Diff line
@@ -114,7 +114,6 @@ private:
    struct state_t;
    struct state_t;
    struct track_t;
    struct track_t;


    typedef void (*mix_t)(state_t* state, int64_t pts);
    typedef void (*hook_t)(track_t* t, int32_t* output, size_t numOutFrames, int32_t* temp, int32_t* aux);
    typedef void (*hook_t)(track_t* t, int32_t* output, size_t numOutFrames, int32_t* temp, int32_t* aux);
    static const int BLOCKSIZE = 16; // 4 cache lines
    static const int BLOCKSIZE = 16; // 4 cache lines


@@ -167,7 +166,7 @@ private:
        uint32_t        enabledTracks;
        uint32_t        enabledTracks;
        uint32_t        needsChanged;
        uint32_t        needsChanged;
        size_t          frameCount;
        size_t          frameCount;
        mix_t           hook;
        void            (*hook)(state_t* state, int64_t pts);   // one of process__*, never NULL
        int32_t         *outputTemp;
        int32_t         *outputTemp;
        int32_t         *resampleTemp;
        int32_t         *resampleTemp;
        int32_t         reserved[2];
        int32_t         reserved[2];
+1 −2
Original line number Original line Diff line number Diff line
@@ -604,8 +604,7 @@ void AudioPolicyService::setPreProcessorEnabled(InputDesc *inputDesc, bool enabl
{
{
    Vector<sp<AudioEffect> > fxVector = inputDesc->mEffects;
    Vector<sp<AudioEffect> > fxVector = inputDesc->mEffects;
    for (size_t i = 0; i < fxVector.size(); i++) {
    for (size_t i = 0; i < fxVector.size(); i++) {
        sp<AudioEffect> fx = fxVector.itemAt(i);
        fxVector.itemAt(i)->setEnabled(enabled);
        fx->setEnabled(enabled);
    }
    }
}
}