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

Commit b9e722bd authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "Rename mixBuffer to mMixerBuffer in FastMixer"

parents 7b2b401a 45d68d36
Loading
Loading
Loading
Loading
+18 −18
Original line number Original line Diff line number Diff line
@@ -52,8 +52,8 @@ FastMixer::FastMixer() : FastThread(),
    outputSink(NULL),
    outputSink(NULL),
    outputSinkGen(0),
    outputSinkGen(0),
    mixer(NULL),
    mixer(NULL),
    mixBuffer(NULL),
    mMixerBuffer(NULL),
    mixBufferState(UNDEFINED),
    mMixerBufferState(UNDEFINED),
    format(Format_Invalid),
    format(Format_Invalid),
    sampleRate(0),
    sampleRate(0),
    fastTracksGen(0),
    fastTracksGen(0),
@@ -108,7 +108,7 @@ void FastMixer::onIdle()
void FastMixer::onExit()
void FastMixer::onExit()
{
{
    delete mixer;
    delete mixer;
    delete[] mixBuffer;
    delete[] mMixerBuffer;
}
}


bool FastMixer::isSubClassCommand(FastThreadState::Command command)
bool FastMixer::isSubClassCommand(FastThreadState::Command command)
@@ -154,14 +154,14 @@ void FastMixer::onStateChange()
        // FIXME to avoid priority inversion, don't delete here
        // FIXME to avoid priority inversion, don't delete here
        delete mixer;
        delete mixer;
        mixer = NULL;
        mixer = NULL;
        delete[] mixBuffer;
        delete[] mMixerBuffer;
        mixBuffer = NULL;
        mMixerBuffer = NULL;
        if (frameCount > 0 && sampleRate > 0) {
        if (frameCount > 0 && sampleRate > 0) {
            // FIXME new may block for unbounded time at internal mutex of the heap
            // FIXME new may block for unbounded time at internal mutex of the heap
            //       implementation; it would be better to have normal mixer allocate for us
            //       implementation; it would be better to have normal mixer allocate for us
            //       to avoid blocking here and to prevent possible priority inversion
            //       to avoid blocking here and to prevent possible priority inversion
            mixer = new AudioMixer(frameCount, sampleRate, FastMixerState::kMaxFastTracks);
            mixer = new AudioMixer(frameCount, sampleRate, FastMixerState::kMaxFastTracks);
            mixBuffer = new short[frameCount * FCC_2];
            mMixerBuffer = new short[frameCount * FCC_2];
            periodNs = (frameCount * 1000000000LL) / sampleRate;    // 1.00
            periodNs = (frameCount * 1000000000LL) / sampleRate;    // 1.00
            underrunNs = (frameCount * 1750000000LL) / sampleRate;  // 1.75
            underrunNs = (frameCount * 1750000000LL) / sampleRate;  // 1.75
            overrunNs = (frameCount * 500000000LL) / sampleRate;    // 0.50
            overrunNs = (frameCount * 500000000LL) / sampleRate;    // 0.50
@@ -174,7 +174,7 @@ void FastMixer::onStateChange()
            forceNs = 0;
            forceNs = 0;
            warmupNs = 0;
            warmupNs = 0;
        }
        }
        mixBufferState = UNDEFINED;
        mMixerBufferState = UNDEFINED;
#if !LOG_NDEBUG
#if !LOG_NDEBUG
        for (unsigned i = 0; i < FastMixerState::kMaxFastTracks; ++i) {
        for (unsigned i = 0; i < FastMixerState::kMaxFastTracks; ++i) {
            fastTrackNames[i] = -1;
            fastTrackNames[i] = -1;
@@ -192,7 +192,7 @@ void FastMixer::onStateChange()
    const unsigned currentTrackMask = current->mTrackMask;
    const unsigned currentTrackMask = current->mTrackMask;
    dumpState->mTrackMask = currentTrackMask;
    dumpState->mTrackMask = currentTrackMask;
    if (current->mFastTracksGen != fastTracksGen) {
    if (current->mFastTracksGen != fastTracksGen) {
        ALOG_ASSERT(mixBuffer != NULL);
        ALOG_ASSERT(mMixerBuffer != NULL);
        int name;
        int name;


        // process removed tracks first to avoid running out of track names
        // process removed tracks first to avoid running out of track names
@@ -229,7 +229,7 @@ void FastMixer::onStateChange()
                fastTrackNames[i] = name;
                fastTrackNames[i] = name;
                mixer->setBufferProvider(name, bufferProvider);
                mixer->setBufferProvider(name, bufferProvider);
                mixer->setParameter(name, AudioMixer::TRACK, AudioMixer::MAIN_BUFFER,
                mixer->setParameter(name, AudioMixer::TRACK, AudioMixer::MAIN_BUFFER,
                        (void *) mixBuffer);
                        (void *) mMixerBuffer);
                // newly allocated track names default to full scale volume
                // newly allocated track names default to full scale volume
                mixer->setParameter(name, AudioMixer::TRACK, AudioMixer::FORMAT,
                mixer->setParameter(name, AudioMixer::TRACK, AudioMixer::FORMAT,
                        (void *)(uintptr_t)fastTrack->mFormat);
                        (void *)(uintptr_t)fastTrack->mFormat);
@@ -362,26 +362,26 @@ void FastMixer::onWork()


        // process() is CPU-bound
        // process() is CPU-bound
        mixer->process(pts);
        mixer->process(pts);
        mixBufferState = MIXED;
        mMixerBufferState = MIXED;
    } else if (mixBufferState == MIXED) {
    } else if (mMixerBufferState == MIXED) {
        mixBufferState = UNDEFINED;
        mMixerBufferState = UNDEFINED;
    }
    }
    //bool didFullWrite = false;    // dumpsys could display a count of partial writes
    //bool didFullWrite = false;    // dumpsys could display a count of partial writes
    if ((command & FastMixerState::WRITE) && (outputSink != NULL) && (mixBuffer != NULL)) {
    if ((command & FastMixerState::WRITE) && (outputSink != NULL) && (mMixerBuffer != NULL)) {
        if (mixBufferState == UNDEFINED) {
        if (mMixerBufferState == UNDEFINED) {
            memset(mixBuffer, 0, frameCount * FCC_2 * sizeof(short));
            memset(mMixerBuffer, 0, frameCount * FCC_2 * sizeof(short));
            mixBufferState = ZEROED;
            mMixerBufferState = ZEROED;
        }
        }
        // if non-NULL, then duplicate write() to this non-blocking sink
        // if non-NULL, then duplicate write() to this non-blocking sink
        NBAIO_Sink* teeSink;
        NBAIO_Sink* teeSink;
        if ((teeSink = current->mTeeSink) != NULL) {
        if ((teeSink = current->mTeeSink) != NULL) {
            (void) teeSink->write(mixBuffer, frameCount);
            (void) teeSink->write(mMixerBuffer, frameCount);
        }
        }
        // FIXME write() is non-blocking and lock-free for a properly implemented NBAIO sink,
        // FIXME write() is non-blocking and lock-free for a properly implemented NBAIO sink,
        //       but this code should be modified to handle both non-blocking and blocking sinks
        //       but this code should be modified to handle both non-blocking and blocking sinks
        dumpState->mWriteSequence++;
        dumpState->mWriteSequence++;
        ATRACE_BEGIN("write");
        ATRACE_BEGIN("write");
        ssize_t framesWritten = outputSink->write(mixBuffer, frameCount);
        ssize_t framesWritten = outputSink->write(mMixerBuffer, frameCount);
        ATRACE_END();
        ATRACE_END();
        dumpState->mWriteSequence++;
        dumpState->mWriteSequence++;
        if (framesWritten >= 0) {
        if (framesWritten >= 0) {
+2 −2
Original line number Original line Diff line number Diff line
@@ -61,8 +61,8 @@ private:
    NBAIO_Sink *outputSink;
    NBAIO_Sink *outputSink;
    int outputSinkGen;
    int outputSinkGen;
    AudioMixer* mixer;
    AudioMixer* mixer;
    short *mixBuffer;
    short *mMixerBuffer;
    enum {UNDEFINED, MIXED, ZEROED} mixBufferState;
    enum {UNDEFINED, MIXED, ZEROED} mMixerBufferState;
    NBAIO_Format format;
    NBAIO_Format format;
    unsigned sampleRate;
    unsigned sampleRate;
    int fastTracksGen;
    int fastTracksGen;