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 | 2ce999fce785eb34b3a157db5ab5e17d31e2ea33 (patch) | |
| tree | b5d2e751e6b07754a049033f66c0ec379a810f2f | |
| parent | 04b243d0f5470cfaf67cce5534f9a9fb2e30855c (diff) | |
| parent | bd240c2737913d6ed1982788699f93bbc52330c0 (diff) | |
| download | frameworks_base-2ce999fce785eb34b3a157db5ab5e17d31e2ea33.zip frameworks_base-2ce999fce785eb34b3a157db5ab5e17d31e2ea33.tar.gz frameworks_base-2ce999fce785eb34b3a157db5ab5e17d31e2ea33.tar.bz2 | |
am bd240c27: media: add AudioTrack::getMinFrameCount().
Merge commit 'bd240c2737913d6ed1982788699f93bbc52330c0' into gingerbread
* commit 'bd240c2737913d6ed1982788699f93bbc52330c0':
media: add AudioTrack::getMinFrameCount().
| -rw-r--r-- | include/media/AudioTrack.h | 11 | ||||
| -rw-r--r-- | media/libmedia/AudioTrack.cpp | 29 |
2 files changed, 40 insertions, 0 deletions
diff --git a/include/media/AudioTrack.h b/include/media/AudioTrack.h index c46df1e..ef537f4 100644 --- a/include/media/AudioTrack.h +++ b/include/media/AudioTrack.h @@ -102,6 +102,17 @@ public: typedef void (*callback_t)(int event, void* user, void *info); + /* Returns the minimum frame count required for the successful creation of + * an AudioTrack object. + * Returned status (from utils/Errors.h) can be: + * - NO_ERROR: successful operation + * - NO_INIT: audio server or audio hardware not initialized + */ + + static status_t getMinFrameCount(int* frameCount, + int streamType =-1, + uint32_t sampleRate = 0); + /* Constructs an uninitialized AudioTrack. No connection with * AudioFlinger takes place. */ 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; +} // --------------------------------------------------------------------------- |
