summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/OMXCodec.cpp
diff options
context:
space:
mode:
authorLajos Molnar <lajos@google.com>2014-02-13 15:29:49 -0800
committerLajos Molnar <lajos@google.com>2014-03-11 14:20:00 -0700
commite257e5ebefdd50f808ee3b4d1596db261c9b62dd (patch)
treebe6e8e59e410550afb7046e5a5b5c10abe6047ea /media/libstagefright/OMXCodec.cpp
parent3a0fb34ed9fcb665e71cc055abde520af393c493 (diff)
downloadframeworks_av-e257e5ebefdd50f808ee3b4d1596db261c9b62dd.zip
frameworks_av-e257e5ebefdd50f808ee3b4d1596db261c9b62dd.tar.gz
frameworks_av-e257e5ebefdd50f808ee3b4d1596db261c9b62dd.tar.bz2
mediaplayer: keep more buffers with the BufferQueue
Change OMX buffer allocation policy to allocate nBufferCountMin + what is required for the BQ. For the BQ, try to allocate 2 additional buffers than the minimum undequeued count. Also account for the fact that BQ may return one less than the actual minimum undequeued count. In most cases the resulting number of buffers ends up being the same as with the previous policy, but we keep more buffers with the BQ. Change-Id: I826db8bf7dd333b620299dba60bf1b81b228275d Bug: 12080418
Diffstat (limited to 'media/libstagefright/OMXCodec.cpp')
-rw-r--r--media/libstagefright/OMXCodec.cpp38
1 files changed, 29 insertions, 9 deletions
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 4d3b5bd..545ca9d 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -94,6 +94,7 @@ static sp<MediaSource> InstantiateSoftwareEncoder(
#define CODEC_LOGI(x, ...) ALOGI("[%s] "x, mComponentName, ##__VA_ARGS__)
#define CODEC_LOGV(x, ...) ALOGV("[%s] "x, mComponentName, ##__VA_ARGS__)
+#define CODEC_LOGW(x, ...) ALOGW("[%s] "x, mComponentName, ##__VA_ARGS__)
#define CODEC_LOGE(x, ...) ALOGE("[%s] "x, mComponentName, ##__VA_ARGS__)
struct OMXCodecObserver : public BnOMXObserver {
@@ -1803,21 +1804,40 @@ status_t OMXCodec::allocateOutputBuffersFromNativeWindow() {
strerror(-err), -err);
return err;
}
-
- // XXX: Is this the right logic to use? It's not clear to me what the OMX
- // buffer counts refer to - how do they account for the renderer holding on
- // to buffers?
- if (def.nBufferCountActual < def.nBufferCountMin + minUndequeuedBufs) {
- OMX_U32 newBufferCount = def.nBufferCountMin + minUndequeuedBufs;
+ // FIXME: assume that surface is controlled by app (native window
+ // returns the number for the case when surface is not controlled by app)
+ minUndequeuedBufs++;
+
+ // Use conservative allocation while also trying to reduce starvation
+ //
+ // 1. allocate at least nBufferCountMin + minUndequeuedBuffers - that is the
+ // minimum needed for the consumer to be able to work
+ // 2. try to allocate two (2) additional buffers to reduce starvation from
+ // the consumer
+ CODEC_LOGI("OMX-buffers: min=%u actual=%u undeq=%d",
+ def.nBufferCountMin, def.nBufferCountActual, minUndequeuedBufs);
+
+ for (OMX_U32 extraBuffers = 2; /* condition inside loop */; extraBuffers--) {
+ OMX_U32 newBufferCount =
+ def.nBufferCountMin + minUndequeuedBufs + extraBuffers;
def.nBufferCountActual = newBufferCount;
err = mOMX->setParameter(
mNode, OMX_IndexParamPortDefinition, &def, sizeof(def));
- if (err != OK) {
- CODEC_LOGE("setting nBufferCountActual to %lu failed: %d",
- newBufferCount, err);
+
+ if (err == OK) {
+ minUndequeuedBufs += extraBuffers;
+ break;
+ }
+
+ CODEC_LOGW("setting nBufferCountActual to %lu failed: %d",
+ newBufferCount, err);
+ /* exit condition */
+ if (extraBuffers == 0) {
return err;
}
}
+ CODEC_LOGI("OMX-buffers: min=%u actual=%u undeq=%d",
+ def.nBufferCountMin, def.nBufferCountActual, minUndequeuedBufs);
err = native_window_set_buffer_count(
mNativeWindow.get(), def.nBufferCountActual);