Loading services/audioflinger/Threads.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -2126,6 +2126,7 @@ ssize_t AudioFlinger::PlaybackThread::threadLoop_write() size_t totalFramesWritten = mNormalSink->framesWritten(); if (totalFramesWritten >= mLatchD.mTimestamp.mPosition) { mLatchD.mUnpresentedFrames = totalFramesWritten - mLatchD.mTimestamp.mPosition; // mLatchD.mFramesReleased is set in threadloop_mix() mLatchDValid = true; } } Loading Loading @@ -3093,6 +3094,18 @@ void AudioFlinger::MixerThread::threadLoop_mix() sleepTime = 0; standbyTime = systemTime() + standbyDelay; //TODO: delay standby when effects have a tail mLatchD.mFramesReleased.clear(); { Mutex::Autolock _l(mLock); size_t size = mActiveTracks.size(); for (size_t i = 0; i < size; i++) { sp<Track> t = mActiveTracks[i].promote(); if (t != 0) { mLatchD.mFramesReleased.add(t.get(), t->mAudioTrackServerProxy->framesReleased()); } } } } void AudioFlinger::MixerThread::threadLoop_sleepTime() Loading services/audioflinger/Threads.h +1 −0 Original line number Diff line number Diff line Loading @@ -819,6 +819,7 @@ private: struct { AudioTimestamp mTimestamp; uint32_t mUnpresentedFrames; KeyedVector<Track *, uint32_t> mFramesReleased; } mLatchD, mLatchQ; bool mLatchDValid; // true means mLatchD is valid, and clock it into latch at next opportunity bool mLatchQValid; // true means mLatchQ is valid Loading services/audioflinger/Tracks.cpp +9 −1 Original line number Diff line number Diff line Loading @@ -898,7 +898,15 @@ status_t AudioFlinger::PlaybackThread::Track::getTimestamp(AudioTimestamp& times uint32_t unpresentedFrames = ((int64_t) playbackThread->mLatchQ.mUnpresentedFrames * mSampleRate) / playbackThread->mSampleRate; uint32_t framesWritten = mAudioTrackServerProxy->framesReleased(); // FIXME Since we're using a raw pointer as the key, it is theoretically possible // for a brand new track to share the same address as a recently destroyed // track, and thus for us to get the frames released of the wrong track. // It is unlikely that we would be able to call getTimestamp() so quickly // right after creating a new track. Nevertheless, the index here should // be changed to something that is unique. Or use a completely different strategy. ssize_t i = playbackThread->mLatchQ.mFramesReleased.indexOfKey(this); uint32_t framesWritten = i >= 0 ? playbackThread->mLatchQ.mFramesReleased[i] : mAudioTrackServerProxy->framesReleased(); bool checkPreviousTimestamp = mPreviousValid && framesWritten >= mPreviousFramesWritten; if (framesWritten < unpresentedFrames) { mPreviousValid = false; Loading Loading
services/audioflinger/Threads.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -2126,6 +2126,7 @@ ssize_t AudioFlinger::PlaybackThread::threadLoop_write() size_t totalFramesWritten = mNormalSink->framesWritten(); if (totalFramesWritten >= mLatchD.mTimestamp.mPosition) { mLatchD.mUnpresentedFrames = totalFramesWritten - mLatchD.mTimestamp.mPosition; // mLatchD.mFramesReleased is set in threadloop_mix() mLatchDValid = true; } } Loading Loading @@ -3093,6 +3094,18 @@ void AudioFlinger::MixerThread::threadLoop_mix() sleepTime = 0; standbyTime = systemTime() + standbyDelay; //TODO: delay standby when effects have a tail mLatchD.mFramesReleased.clear(); { Mutex::Autolock _l(mLock); size_t size = mActiveTracks.size(); for (size_t i = 0; i < size; i++) { sp<Track> t = mActiveTracks[i].promote(); if (t != 0) { mLatchD.mFramesReleased.add(t.get(), t->mAudioTrackServerProxy->framesReleased()); } } } } void AudioFlinger::MixerThread::threadLoop_sleepTime() Loading
services/audioflinger/Threads.h +1 −0 Original line number Diff line number Diff line Loading @@ -819,6 +819,7 @@ private: struct { AudioTimestamp mTimestamp; uint32_t mUnpresentedFrames; KeyedVector<Track *, uint32_t> mFramesReleased; } mLatchD, mLatchQ; bool mLatchDValid; // true means mLatchD is valid, and clock it into latch at next opportunity bool mLatchQValid; // true means mLatchQ is valid Loading
services/audioflinger/Tracks.cpp +9 −1 Original line number Diff line number Diff line Loading @@ -898,7 +898,15 @@ status_t AudioFlinger::PlaybackThread::Track::getTimestamp(AudioTimestamp& times uint32_t unpresentedFrames = ((int64_t) playbackThread->mLatchQ.mUnpresentedFrames * mSampleRate) / playbackThread->mSampleRate; uint32_t framesWritten = mAudioTrackServerProxy->framesReleased(); // FIXME Since we're using a raw pointer as the key, it is theoretically possible // for a brand new track to share the same address as a recently destroyed // track, and thus for us to get the frames released of the wrong track. // It is unlikely that we would be able to call getTimestamp() so quickly // right after creating a new track. Nevertheless, the index here should // be changed to something that is unique. Or use a completely different strategy. ssize_t i = playbackThread->mLatchQ.mFramesReleased.indexOfKey(this); uint32_t framesWritten = i >= 0 ? playbackThread->mLatchQ.mFramesReleased[i] : mAudioTrackServerProxy->framesReleased(); bool checkPreviousTimestamp = mPreviousValid && framesWritten >= mPreviousFramesWritten; if (framesWritten < unpresentedFrames) { mPreviousValid = false; Loading