From 4c6e77ff8e18a1551320a6b42f6a45e19dcce748 Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Mon, 21 Sep 2015 12:44:54 -0700 Subject: AudioFlinger: Clear record buffers when starting RecordThread Bug: 24211743 Bug: 24267152 Change-Id: I58c55e56b85067b71e4e300f947b4dfc159637ba --- services/audioflinger/FastCapture.cpp | 4 +++- services/audioflinger/Threads.cpp | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'services/audioflinger') diff --git a/services/audioflinger/FastCapture.cpp b/services/audioflinger/FastCapture.cpp index 79ac12b..1bba5f6 100644 --- a/services/audioflinger/FastCapture.cpp +++ b/services/audioflinger/FastCapture.cpp @@ -131,7 +131,9 @@ void FastCapture::onStateChange() // FIXME new may block for unbounded time at internal mutex of the heap // implementation; it would be better to have normal capture thread allocate for // us to avoid blocking here and to prevent possible priority inversion - (void)posix_memalign(&mReadBuffer, 32, frameCount * Format_frameSize(mFormat)); + size_t bufferSize = frameCount * Format_frameSize(mFormat); + (void)posix_memalign(&mReadBuffer, 32, bufferSize); + memset(mReadBuffer, 0, bufferSize); // if posix_memalign fails, will segv here. mPeriodNs = (frameCount * 1000000000LL) / mSampleRate; // 1.00 mUnderrunNs = (frameCount * 1750000000LL) / mSampleRate; // 1.75 mOverrunNs = (frameCount * 500000000LL) / mSampleRate; // 0.50 diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp index 0a7d4a2..246f6ba 100644 --- a/services/audioflinger/Threads.cpp +++ b/services/audioflinger/Threads.cpp @@ -6926,6 +6926,7 @@ void AudioFlinger::RecordThread::readInputParameters_l() mRsmpInFrames = mFrameCount * 7; mRsmpInFramesP2 = roundup(mRsmpInFrames); free(mRsmpInBuffer); + mRsmpInBuffer = NULL; // TODO optimize audio capture buffer sizes ... // Here we calculate the size of the sliding buffer used as a source @@ -6935,7 +6936,9 @@ void AudioFlinger::RecordThread::readInputParameters_l() // The current value is higher than necessary. However it should not add to latency. // Over-allocate beyond mRsmpInFramesP2 to permit a HAL read past end of buffer - (void)posix_memalign(&mRsmpInBuffer, 32, (mRsmpInFramesP2 + mFrameCount - 1) * mFrameSize); + size_t bufferSize = (mRsmpInFramesP2 + mFrameCount - 1) * mFrameSize; + (void)posix_memalign(&mRsmpInBuffer, 32, bufferSize); + memset(mRsmpInBuffer, 0, bufferSize); // if posix_memalign fails, will segv here. // AudioRecord mSampleRate and mChannelCount are constant due to AudioRecord API constraints. // But if thread's mSampleRate or mChannelCount changes, how will that affect active tracks? -- cgit v1.1 From 954ca45ac30539a49f179580b667b0ab1056d113 Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Wed, 9 Sep 2015 14:39:02 -0700 Subject: For static obtainBuffer(), do not set mUnreleased if acknowledging flush. static audio tracks use obtainBuffer() to update position in start(). Bug: 22938515 Change-Id: I8ae32f6cce4d122386d2cf8982e158049b04ba9a --- services/audioflinger/Tracks.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'services/audioflinger') diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp index b3fac0b..0e24b52 100644 --- a/services/audioflinger/Tracks.cpp +++ b/services/audioflinger/Tracks.cpp @@ -715,6 +715,7 @@ status_t AudioFlinger::PlaybackThread::Track::start(AudioSystem::sync_event_t ev // But in this case we know the mixer thread (whether normal mixer or fast mixer) // isn't looking at this track yet: we still hold the normal mixer thread lock, // and for fast tracks the track is not yet in the fast mixer thread's active set. + // For static tracks, this is used to acknowledge change in position or loop. ServerProxy::Buffer buffer; buffer.mFrameCount = 1; (void) mAudioTrackServerProxy->obtainBuffer(&buffer, true /*ackFlush*/); -- cgit v1.1 From aba407f1a6378ac2518d0d76d0d18419b7722a81 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 20 Aug 2015 16:18:53 -0700 Subject: audioflinger: increase shared memory heap size Bug: 21093153. Change-Id: I389af11451b01ce49fdb8957e2f322ba1925a62e (cherry picked from commit da73b6c7474aaa5616f0214e238776f12717f32b) --- services/audioflinger/AudioFlinger.cpp | 10 +++++++--- services/audioflinger/AudioFlinger.h | 8 +++++++- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'services/audioflinger') diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 9ec5802..fab1ef5 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1352,12 +1352,16 @@ sp AudioFlinger::getEffectThread_l(int sessionId, AudioFlinger::Client::Client(const sp& audioFlinger, pid_t pid) : RefBase(), mAudioFlinger(audioFlinger), - // FIXME should be a "k" constant not hard-coded, in .h or ro. property, see 4 lines below - mMemoryDealer(new MemoryDealer(1024*1024, "AudioFlinger::Client")), mPid(pid), mTimedTrackCount(0) { - // 1 MB of address space is good for 32 tracks, 8 buffers each, 4 KB/buffer + size_t heapSize = kClientSharedHeapSizeBytes; + // Increase heap size on non low ram devices to limit risk of reconnection failure for + // invalidated tracks + if (!audioFlinger->isLowRamDevice()) { + heapSize *= kClientSharedHeapSizeMultiplier; + } + mMemoryDealer = new MemoryDealer(heapSize, "AudioFlinger::Client"); } // Client destructor must be called with AudioFlinger::mClientLock held diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index 20c34ef..08fa70d 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -88,6 +88,12 @@ class ServerProxy; static const nsecs_t kDefaultStandbyTimeInNsecs = seconds(3); + +// Max shared memory size for audio tracks and audio records per client process +static const size_t kClientSharedHeapSizeBytes = 1024*1024; +// Shared memory size multiplier for non low ram devices +static const size_t kClientSharedHeapSizeMultiplier = 4; + #define INCLUDING_FROM_AUDIOFLINGER_H class AudioFlinger : @@ -423,7 +429,7 @@ private: Client(const Client&); Client& operator = (const Client&); const sp mAudioFlinger; - const sp mMemoryDealer; + sp mMemoryDealer; const pid_t mPid; Mutex mTimedTrackLock; -- cgit v1.1