Loading media/libmedia/AudioTrack.cpp +24 −14 Original line number Original line Diff line number Diff line Loading @@ -1019,13 +1019,6 @@ create_new_track: cblk->lock.unlock(); cblk->lock.unlock(); } } // restart track if it was disabled by audioflinger due to previous underrun if (mActive && (cblk->flags & CBLK_DISABLED_MSK)) { android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags); ALOGW("obtainBuffer() track %p disabled, restarting", this); mAudioTrack->start(); } cblk->waitTimeMs = 0; cblk->waitTimeMs = 0; if (framesReq > framesAvail) { if (framesReq > framesAvail) { Loading Loading @@ -1057,6 +1050,14 @@ void AudioTrack::releaseBuffer(Buffer* audioBuffer) { { AutoMutex lock(mLock); AutoMutex lock(mLock); mCblk->stepUser(audioBuffer->frameCount); mCblk->stepUser(audioBuffer->frameCount); if (audioBuffer->frameCount > 0) { // restart track if it was disabled by audioflinger due to previous underrun if (mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); ALOGW("releaseBuffer() track %p disabled, restarting", this); mAudioTrack->start(); } } } } // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- Loading @@ -1077,6 +1078,10 @@ ssize_t AudioTrack::write(const void* buffer, size_t userSize) ALOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); ALOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); if (userSize == 0) { return 0; } // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed // while we are accessing the cblk // while we are accessing the cblk mLock.lock(); mLock.lock(); Loading Loading @@ -1157,14 +1162,18 @@ status_t TimedAudioTrack::allocateTimedBuffer(size_t size, sp<IMemory>* buffer) status_t TimedAudioTrack::queueTimedBuffer(const sp<IMemory>& buffer, status_t TimedAudioTrack::queueTimedBuffer(const sp<IMemory>& buffer, int64_t pts) int64_t pts) { { status_t status = mAudioTrack->queueTimedBuffer(buffer, pts); { AutoMutex lock(mLock); // restart track if it was disabled by audioflinger due to previous underrun // restart track if it was disabled by audioflinger due to previous underrun if (mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { if (buffer->size() != 0 && status == NO_ERROR && mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); ALOGW("queueTimedBuffer() track %p disabled, restarting", this); ALOGW("queueTimedBuffer() track %p disabled, restarting", this); mAudioTrack->start(); mAudioTrack->start(); } } } return mAudioTrack->queueTimedBuffer(buffer, pts); return status; } } status_t TimedAudioTrack::setMediaTimeTransform(const LinearTransform& xform, status_t TimedAudioTrack::setMediaTimeTransform(const LinearTransform& xform, Loading Loading @@ -1276,6 +1285,7 @@ bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread) usleep(WAIT_PERIOD_MS*1000); usleep(WAIT_PERIOD_MS*1000); break; break; } } if (writtenSize > reqSize) writtenSize = reqSize; if (writtenSize > reqSize) writtenSize = reqSize; if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { Loading Loading
media/libmedia/AudioTrack.cpp +24 −14 Original line number Original line Diff line number Diff line Loading @@ -1019,13 +1019,6 @@ create_new_track: cblk->lock.unlock(); cblk->lock.unlock(); } } // restart track if it was disabled by audioflinger due to previous underrun if (mActive && (cblk->flags & CBLK_DISABLED_MSK)) { android_atomic_and(~CBLK_DISABLED_ON, &cblk->flags); ALOGW("obtainBuffer() track %p disabled, restarting", this); mAudioTrack->start(); } cblk->waitTimeMs = 0; cblk->waitTimeMs = 0; if (framesReq > framesAvail) { if (framesReq > framesAvail) { Loading Loading @@ -1057,6 +1050,14 @@ void AudioTrack::releaseBuffer(Buffer* audioBuffer) { { AutoMutex lock(mLock); AutoMutex lock(mLock); mCblk->stepUser(audioBuffer->frameCount); mCblk->stepUser(audioBuffer->frameCount); if (audioBuffer->frameCount > 0) { // restart track if it was disabled by audioflinger due to previous underrun if (mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); ALOGW("releaseBuffer() track %p disabled, restarting", this); mAudioTrack->start(); } } } } // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- Loading @@ -1077,6 +1078,10 @@ ssize_t AudioTrack::write(const void* buffer, size_t userSize) ALOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); ALOGV("write %p: %d bytes, mActive=%d", this, userSize, mActive); if (userSize == 0) { return 0; } // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed // acquire a strong reference on the IMemory and IAudioTrack so that they cannot be destroyed // while we are accessing the cblk // while we are accessing the cblk mLock.lock(); mLock.lock(); Loading Loading @@ -1157,14 +1162,18 @@ status_t TimedAudioTrack::allocateTimedBuffer(size_t size, sp<IMemory>* buffer) status_t TimedAudioTrack::queueTimedBuffer(const sp<IMemory>& buffer, status_t TimedAudioTrack::queueTimedBuffer(const sp<IMemory>& buffer, int64_t pts) int64_t pts) { { status_t status = mAudioTrack->queueTimedBuffer(buffer, pts); { AutoMutex lock(mLock); // restart track if it was disabled by audioflinger due to previous underrun // restart track if it was disabled by audioflinger due to previous underrun if (mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { if (buffer->size() != 0 && status == NO_ERROR && mActive && (mCblk->flags & CBLK_DISABLED_MSK)) { android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); android_atomic_and(~CBLK_DISABLED_ON, &mCblk->flags); ALOGW("queueTimedBuffer() track %p disabled, restarting", this); ALOGW("queueTimedBuffer() track %p disabled, restarting", this); mAudioTrack->start(); mAudioTrack->start(); } } } return mAudioTrack->queueTimedBuffer(buffer, pts); return status; } } status_t TimedAudioTrack::setMediaTimeTransform(const LinearTransform& xform, status_t TimedAudioTrack::setMediaTimeTransform(const LinearTransform& xform, Loading Loading @@ -1276,6 +1285,7 @@ bool AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread) usleep(WAIT_PERIOD_MS*1000); usleep(WAIT_PERIOD_MS*1000); break; break; } } if (writtenSize > reqSize) writtenSize = reqSize; if (writtenSize > reqSize) writtenSize = reqSize; if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { if (mFormat == AUDIO_FORMAT_PCM_8_BIT && !(mFlags & AUDIO_OUTPUT_FLAG_DIRECT)) { Loading