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

Commit 4dfe626b authored by wjiang's avatar wjiang Committed by Abhisek Devkota
Browse files

framework/av: Check for NULL pointer of mCblk and zero division error

latency calculation happens in two places: AudioTrack::latency() and
AudioTrack::dump(). Need to add null pointer and zero division check on
both of these places.

Change-Id: I9cbe8c1c00a390cd626bdbf202124f27e60eb3e3
Fixed-CRs: 548514
parent af8b665c
Loading
Loading
Loading
Loading
+10 −3
Original line number Original line Diff line number Diff line
@@ -500,7 +500,9 @@ uint32_t AudioTrack::latency() const
        uint32_t newLatency = 0;
        uint32_t newLatency = 0;
        AudioSystem::getLatency(mOutput, mStreamType, &afLatency);
        AudioSystem::getLatency(mOutput, mStreamType, &afLatency);
        if(0 != mSampleRate) {
        if(0 != mSampleRate) {
            newLatency = afLatency + (1000*mCblk->frameCount_) / mSampleRate;
            newLatency = (mCblk == NULL) ? afLatency : (afLatency + (1000*mCblk->frameCount_) / mSampleRate);
        } else {
            newLatency = afLatency;
        }
        }
        ALOGV("latency() mLatency = %d, newLatency = %d", mLatency, newLatency);
        ALOGV("latency() mLatency = %d, newLatency = %d", mLatency, newLatency);
        return newLatency;
        return newLatency;
@@ -1972,7 +1974,12 @@ status_t AudioTrack::dump(int fd, const Vector<String16>& args) const
#ifdef QCOM_DIRECTTRACK
#ifdef QCOM_DIRECTTRACK
    uint32_t afLatency = 0;
    uint32_t afLatency = 0;
    AudioSystem::getLatency(mOutput, mStreamType, &afLatency);
    AudioSystem::getLatency(mOutput, mStreamType, &afLatency);
    snprintf(buffer, 255, "  state(%d), latency (%d)\n", mState, afLatency + (1000*mCblk->frameCount_) / mSampleRate);
    if(0 != mSampleRate) {
        snprintf(buffer, 255, "  state(%d), latency (%d)\n", mState,
                (mCblk == NULL) ? afLatency : (afLatency + (1000*mCblk->frameCount_) / mSampleRate));
    } else {
        snprintf(buffer, 255, "  state(%d), latency (%d)\n", mState, afLatency);
    }
#else
#else
    snprintf(buffer, 255, "  state(%d), latency (%d)\n", mState, mLatency);
    snprintf(buffer, 255, "  state(%d), latency (%d)\n", mState, mLatency);
#endif
#endif