summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/ACodec.cpp
diff options
context:
space:
mode:
authorLajos Molnar <lajos@google.com>2015-05-06 11:52:00 -0700
committerLajos Molnar <lajos@google.com>2015-05-07 13:59:14 -0700
commit011778fd4cb9606b68bfea1ed483d73c04fc6dcd (patch)
tree95c668c8b5f3ae6afb072750366e24d53d7be2c6 /media/libstagefright/ACodec.cpp
parentdd248abd2c3e5e82b0049d40c7e9fb741fd4540c (diff)
downloadframeworks_av-011778fd4cb9606b68bfea1ed483d73c04fc6dcd.zip
frameworks_av-011778fd4cb9606b68bfea1ed483d73c04fc6dcd.tar.gz
frameworks_av-011778fd4cb9606b68bfea1ed483d73c04fc6dcd.tar.bz2
stagefright: enable experiments
Bug: 20894716 Change-Id: I8c05b99dca8b3099a3a1b2b465f0f58bef786572
Diffstat (limited to 'media/libstagefright/ACodec.cpp')
-rw-r--r--media/libstagefright/ACodec.cpp52
1 files changed, 49 insertions, 3 deletions
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index 006f07d..0843ad1 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -422,6 +422,7 @@ ACodec::ACodec()
mChannelMask(0),
mDequeueCounter(0),
mStoreMetaDataInOutputBuffers(false),
+ mLegacyAdaptiveExperiment(false),
mMetaDataBuffersToSubmit(0),
mRepeatFrameDelayUs(-1ll),
mMaxPtsGapUs(-1ll),
@@ -619,6 +620,7 @@ status_t ACodec::handleSetSurface(const sp<Surface> &surface) {
const BufferInfo &info = buffers[i];
// skip undequeued buffers for meta data mode
if (mStoreMetaDataInOutputBuffers
+ && !mLegacyAdaptiveExperiment
&& info.mStatus == BufferInfo::OWNED_BY_NATIVE_WINDOW) {
ALOGV("skipping buffer %p", info.mGraphicBuffer->getNativeBuffer());
continue;
@@ -635,7 +637,7 @@ status_t ACodec::handleSetSurface(const sp<Surface> &surface) {
}
// cancel undequeued buffers to new surface
- if (!mStoreMetaDataInOutputBuffers) {
+ if (!mStoreMetaDataInOutputBuffers || mLegacyAdaptiveExperiment) {
for (size_t i = 0; i < buffers.size(); ++i) {
const BufferInfo &info = buffers[i];
if (info.mStatus == BufferInfo::OWNED_BY_NATIVE_WINDOW) {
@@ -970,6 +972,44 @@ status_t ACodec::allocateOutputMetaDataBuffers() {
return err;
mNumUndequeuedBuffers = minUndequeuedBuffers;
+ if (mLegacyAdaptiveExperiment) {
+ // preallocate buffers
+ static_cast<Surface *>(mNativeWindow.get())
+ ->getIGraphicBufferProducer()->allowAllocation(true);
+
+ ALOGV("[%s] Allocating %u buffers from a native window of size %u on "
+ "output port",
+ mComponentName.c_str(), bufferCount, bufferSize);
+
+ // Dequeue buffers then cancel them all
+ for (OMX_U32 i = 0; i < bufferCount; i++) {
+ ANativeWindowBuffer *buf;
+ err = native_window_dequeue_buffer_and_wait(mNativeWindow.get(), &buf);
+ if (err != 0) {
+ ALOGE("dequeueBuffer failed: %s (%d)", strerror(-err), -err);
+ break;
+ }
+
+ sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(buf, false));
+ BufferInfo info;
+ info.mStatus = BufferInfo::OWNED_BY_US;
+ info.mGraphicBuffer = graphicBuffer;
+ mBuffers[kPortIndexOutput].push(info);
+ }
+
+ for (OMX_U32 i = 0; i < mBuffers[kPortIndexOutput].size(); i++) {
+ BufferInfo *info = &mBuffers[kPortIndexOutput].editItemAt(i);
+ status_t error = cancelBufferToNativeWindow(info);
+ if (err == OK) {
+ err = error;
+ }
+ }
+
+ mBuffers[kPortIndexOutput].clear();
+ static_cast<Surface*>(mNativeWindow.get())
+ ->getIGraphicBufferProducer()->allowAllocation(false);
+ }
+
ALOGV("[%s] Allocating %u meta buffers on output port",
mComponentName.c_str(), bufferCount);
@@ -1085,7 +1125,7 @@ ACodec::BufferInfo *ACodec::dequeueBufferFromNativeWindow() {
// same is possible in meta mode, in which case, it will be treated
// as a normal buffer, which is not desirable.
// TODO: fix this.
- if (!stale && !mStoreMetaDataInOutputBuffers) {
+ if (!stale && (!mStoreMetaDataInOutputBuffers || mLegacyAdaptiveExperiment)) {
ALOGI("dequeued unrecognized (stale) buffer %p. discarding", buf);
stale = true;
}
@@ -1418,6 +1458,7 @@ status_t ACodec::configureCodec(
bool haveNativeWindow = msg->findObject("native-window", &obj)
&& obj != NULL && video && !encoder;
mStoreMetaDataInOutputBuffers = false;
+ mLegacyAdaptiveExperiment = false;
if (video && !encoder) {
inputFormat->setInt32("adaptive-playback", false);
@@ -1555,6 +1596,9 @@ status_t ACodec::configureCodec(
ALOGV("[%s] storeMetaDataInBuffers succeeded",
mComponentName.c_str());
mStoreMetaDataInOutputBuffers = true;
+ mLegacyAdaptiveExperiment = ADebug::isExperimentEnabled(
+ "legacy-adaptive", !msg->contains("no-experiments"));
+
inputFormat->setInt32("adaptive-playback", true);
}
@@ -4169,7 +4213,9 @@ bool ACodec::BaseState::onMessageReceived(const sp<AMessage> &msg) {
sp<RefBase> obj;
CHECK(msg->findObject("surface", &obj));
- status_t err = mCodec->handleSetSurface(static_cast<Surface *>(obj.get()));
+ status_t err =
+ ADebug::isExperimentEnabled("legacy-setsurface") ? BAD_VALUE :
+ mCodec->handleSetSurface(static_cast<Surface *>(obj.get()));
sp<AMessage> response = new AMessage;
response->setInt32("err", err);