diff options
author | Chia-chi Yeh <chiachi@android.com> | 2010-06-21 08:54:19 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2010-06-21 08:54:19 -0700 |
commit | c7fa90a661dd9f6107af6a1d9e6dcaa1cb9a34e3 (patch) | |
tree | 0359dad8d45e584b4b1b505c060bfebdbe10de40 /media/libmedia | |
parent | e6de2667d6bf4bb7b926da6784cc7eb886b93e83 (diff) | |
parent | 33005a932c60a0780fe9b7307d5988df3d9f6c26 (diff) | |
download | frameworks_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.cpp | 29 |
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; +} // --------------------------------------------------------------------------- |