summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorHaynes Mathew George <hgeorge@codeaurora.org>2014-10-09 20:06:00 +0800
committerChris Elliott <chriselliott@google.com>2014-10-14 17:20:37 +0000
commit8c0417c173d1fd618ae54e2d721b0ec360ea70cc (patch)
treec079d953bc10a492f8145a3984a929bb9b936254 /media
parente6b5d4c2d58a02184dd97815b5f76980025379bc (diff)
downloadframeworks_av-8c0417c173d1fd618ae54e2d721b0ec360ea70cc.zip
frameworks_av-8c0417c173d1fd618ae54e2d721b0ec360ea70cc.tar.gz
frameworks_av-8c0417c173d1fd618ae54e2d721b0ec360ea70cc.tar.bz2
audio: prevent larger than required sleeps - DO NOT MERGE
b/17962037 From: Haynes Mathew George <hgeorge@codeaurora.org> Date: Wed, 26 Mar 2014 16:18:42 -0700 Subject: [PATCH] AudioTrack: prevent larger than required sleeps AudioTrackThread can end up waiting for larger than necessary time for free space to be available in the cblk. Fix this by waiting on the cblk futex instead of the (internal) condition variable. Change-Id: I75bd14cd46f3b75afe0ea8bd9b48d7a2f95f654a
Diffstat (limited to 'media')
-rw-r--r--media/libmedia/AudioTrack.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index e290627..4cc50cc 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -18,15 +18,21 @@
//#define LOG_NDEBUG 0
#define LOG_TAG "AudioTrack"
+#define ATRACE_TAG ATRACE_TAG_AUDIO
#include <sys/resource.h>
#include <audio_utils/primitives.h>
#include <binder/IPCThreadState.h>
#include <media/AudioTrack.h>
#include <utils/Log.h>
+#include <utils/Trace.h>
#include <private/media/AudioTrackShared.h>
#include <media/IAudioFlinger.h>
+extern "C" {
+#include "../private/bionic_futex.h"
+}
+
#define WAIT_PERIOD_MS 10
#define WAIT_STREAM_END_TIMEOUT_SEC 120
@@ -1606,7 +1612,21 @@ nsecs_t AudioTrack::processAudioBuffer(const sp<AudioTrackThread>& thread)
if (ns < 0 || myns < ns) {
ns = myns;
}
- return ns;
+ int32_t old = android_atomic_and(~CBLK_FUTEX_WAKE, &mCblk->mFutex);
+ char str[64] = {0};
+ struct timespec ts;
+
+ snprintf(str, sizeof(str), "futex_wait timeout %lld Us", ns/1000LL);
+
+ ATRACE_BEGIN(str);
+ ts.tv_sec = 0;
+ ts.tv_nsec = ns;
+ // wait for max ns allowing server to wake us up if possible
+ int ret = __futex_syscall4(&mCblk->mFutex,
+ FUTEX_WAIT,
+ old & ~CBLK_FUTEX_WAKE, &ts);
+ ATRACE_END();
+ return 0; //retry immediately as space (possibly) became available
}
}