summaryrefslogtreecommitdiffstats
path: root/media/libmedia
diff options
context:
space:
mode:
authorChia-chi Yeh <chiachi@android.com>2010-06-21 08:54:19 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2010-06-21 08:54:19 -0700
commitc7fa90a661dd9f6107af6a1d9e6dcaa1cb9a34e3 (patch)
tree0359dad8d45e584b4b1b505c060bfebdbe10de40 /media/libmedia
parente6de2667d6bf4bb7b926da6784cc7eb886b93e83 (diff)
parent33005a932c60a0780fe9b7307d5988df3d9f6c26 (diff)
downloadframeworks_av-c7fa90a661dd9f6107af6a1d9e6dcaa1cb9a34e3.zip
frameworks_av-c7fa90a661dd9f6107af6a1d9e6dcaa1cb9a34e3.tar.gz
frameworks_av-c7fa90a661dd9f6107af6a1d9e6dcaa1cb9a34e3.tar.bz2
am bd240c27: media: add AudioTrack::getMinFrameCount().
Merge commit 'bd240c2737913d6ed1982788699f93bbc52330c0' into gingerbread * commit 'bd240c2737913d6ed1982788699f93bbc52330c0': media: add AudioTrack::getMinFrameCount().
Diffstat (limited to 'media/libmedia')
-rw-r--r--media/libmedia/AudioTrack.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/media/libmedia/AudioTrack.cpp b/media/libmedia/AudioTrack.cpp
index 4b61131..2118f8f 100644
--- a/media/libmedia/AudioTrack.cpp
+++ b/media/libmedia/AudioTrack.cpp
@@ -41,6 +41,35 @@
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
namespace android {
+// ---------------------------------------------------------------------------
+
+// static
+status_t AudioTrack::getMinFrameCount(
+ int* frameCount,
+ int streamType,
+ uint32_t sampleRate)
+{
+ int afSampleRate;
+ if (AudioSystem::getOutputSamplingRate(&afSampleRate, streamType) != NO_ERROR) {
+ return NO_INIT;
+ }
+ int afFrameCount;
+ if (AudioSystem::getOutputFrameCount(&afFrameCount, streamType) != NO_ERROR) {
+ return NO_INIT;
+ }
+ uint32_t afLatency;
+ if (AudioSystem::getOutputLatency(&afLatency, streamType) != NO_ERROR) {
+ return NO_INIT;
+ }
+
+ // Ensure that buffer depth covers at least audio hardware latency
+ uint32_t minBufCount = afLatency / ((1000 * afFrameCount) / afSampleRate);
+ if (minBufCount < 2) minBufCount = 2;
+
+ *frameCount = (sampleRate == 0) ? afFrameCount * minBufCount :
+ afFrameCount * minBufCount * sampleRate / afSampleRate;
+ return NO_ERROR;
+}
// ---------------------------------------------------------------------------