From 1ee2a02ee471d8c5d7b3c3bd3ab720f3dcfea056 Mon Sep 17 00:00:00 2001 From: Shivaprasad Hongal Date: Thu, 30 Jul 2015 18:00:18 -0700 Subject: Stagefright: Enable custom allocation mode. Enable custom allocation mode Change-Id: Idf3f6c0eb9d17d361d2e5b6c36b1fe7586236565 --- include/media/stagefright/ACodec.h | 9 ++++++++- media/libavextensions/media/AVMediaExtensions.h | 6 ++++++ media/libmedia/ICrypto.cpp | 5 +++++ media/libmedia/IOMX.cpp | 3 +++ media/libstagefright/ACodec.cpp | 22 +++++++++++++++------- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h index aaaf2d1..33fb963 100644 --- a/include/media/stagefright/ACodec.h +++ b/include/media/stagefright/ACodec.h @@ -177,6 +177,7 @@ protected: sp mGraphicBuffer; int mFenceFd; FrameRenderTracker::Info *mRenderInfo; + int mCustomData; // The following field and 4 methods are used for debugging only bool mIsReadFence; @@ -275,7 +276,7 @@ protected: status_t setCyclicIntraMacroblockRefresh(const sp &msg, int32_t mode); status_t allocateBuffersOnPort(OMX_U32 portIndex); status_t freeBuffersOnPort(OMX_U32 portIndex); - status_t freeBuffer(OMX_U32 portIndex, size_t i); + virtual status_t freeBuffer(OMX_U32 portIndex, size_t i); status_t handleSetSurface(const sp &surface); status_t setupNativeWindowSizeFormatAndUsage( @@ -436,6 +437,12 @@ protected: virtual status_t getVQZIPInfo(const sp &msg) { return OK; } + virtual bool canAllocateBuffer(OMX_U32 /* portIndex */) { + return false; + } + virtual void enableCustomAllocationMode(const sp &/* msg */) {} + virtual status_t allocateBuffer( + OMX_U32 portIndex, size_t bufSize, BufferInfo &info); sp createObserver(); diff --git a/media/libavextensions/media/AVMediaExtensions.h b/media/libavextensions/media/AVMediaExtensions.h index ea5245c..6cf39f2 100644 --- a/media/libavextensions/media/AVMediaExtensions.h +++ b/media/libavextensions/media/AVMediaExtensions.h @@ -37,6 +37,7 @@ namespace android { class MediaRecorder; +class Parcel; /* * Common delegate to the classes in libstagefright */ @@ -60,6 +61,11 @@ struct AVMediaUtils { } virtual sp createMediaRecorder(const String16& opPackageName); + virtual void writeCustomData( + Parcel * /* reply */, void * /* buffer_data */) {} + virtual void readCustomData( + const Parcel * /* reply */, void ** /*buffer_data */ ) {} + virtual void closeFileDescriptor(void * /* buffer_ptr */) {} // ----- NO TRESSPASSING BEYOND THIS LINE ------ DECLARE_LOADABLE_SINGLETON(AVMediaUtils); }; diff --git a/media/libmedia/ICrypto.cpp b/media/libmedia/ICrypto.cpp index 9f65bde..f80357f 100644 --- a/media/libmedia/ICrypto.cpp +++ b/media/libmedia/ICrypto.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace android { @@ -136,6 +137,7 @@ struct BpCrypto : public BpInterface { if (secure) { data.writeInt64(static_cast(reinterpret_cast(dstPtr))); + AVMediaUtils::get()->writeCustomData(&data, dstPtr); } remote()->transact(DECRYPT, data, &reply); @@ -297,6 +299,7 @@ status_t BnCrypto::onTransact( void *secureBufferId, *dstPtr; if (secure) { secureBufferId = reinterpret_cast(static_cast(data.readInt64())); + AVMediaUtils::get()->readCustomData(&data, &secureBufferId); } else { dstPtr = malloc(totalSize); CHECK(dstPtr != NULL); @@ -332,6 +335,8 @@ status_t BnCrypto::onTransact( } free(dstPtr); dstPtr = NULL; + } else { + AVMediaUtils::get()->closeFileDescriptor(dstPtr); } delete[] subSamples; diff --git a/media/libmedia/IOMX.cpp b/media/libmedia/IOMX.cpp index 16da65e..ac2e872 100644 --- a/media/libmedia/IOMX.cpp +++ b/media/libmedia/IOMX.cpp @@ -22,6 +22,7 @@ #include #include #include +#include namespace android { @@ -472,6 +473,7 @@ public: *buffer = (buffer_id)reply.readInt32(); *buffer_data = (void *)reply.readInt64(); + AVMediaUtils::get()->readCustomData(&reply, buffer_data); return err; } @@ -974,6 +976,7 @@ status_t BnOMX::onTransact( if (err == OK) { reply->writeInt32((int32_t)buffer); reply->writeInt64((uintptr_t)buffer_data); + AVMediaUtils::get()->writeCustomData(reply, buffer_data); } return NO_ERROR; diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp index 97a0be0..238cd47 100644 --- a/media/libstagefright/ACodec.cpp +++ b/media/libstagefright/ACodec.cpp @@ -832,15 +832,11 @@ status_t ACodec::allocateBuffersOnPort(OMX_U32 portIndex) { : OMXCodec::kRequiresAllocateBufferOnOutputPorts; if ((portIndex == kPortIndexInput && (mFlags & kFlagIsSecure)) - || (portIndex == kPortIndexOutput && usingMetadataOnEncoderOutput())) { + || (portIndex == kPortIndexOutput && usingMetadataOnEncoderOutput()) + || canAllocateBuffer(portIndex)) { mem.clear(); - void *ptr; - err = mOMX->allocateBuffer( - mNode, portIndex, bufSize, &info.mBufferID, - &ptr); - - info.mData = new ABuffer(ptr, bufSize); + err = allocateBuffer(portIndex, bufSize, info); } else if (mQuirks & requiresAllocateBufferBit) { err = mOMX->allocateBufferWithBackup( mNode, portIndex, mem, &info.mBufferID, allottedSize); @@ -1643,6 +1639,8 @@ status_t ACodec::configureCodec( return err; } + enableCustomAllocationMode(msg); + int32_t bitRate = 0; // FLAC encoder doesn't need a bitrate, other encoders do if (encoder && strcasecmp(mime, MEDIA_MIMETYPE_AUDIO_FLAC) @@ -6385,6 +6383,16 @@ sp ACodec::createObserver() { return observer; } +status_t ACodec::allocateBuffer( + OMX_U32 portIndex, size_t bufSize, BufferInfo &info) { + void *ptr; + status_t err = mOMX->allocateBuffer( + mNode, portIndex, bufSize, &info.mBufferID, &ptr); + + info.mData = new ABuffer(ptr, bufSize); + return err; +} + bool ACodec::ExecutingState::onOMXFrameRendered(int64_t mediaTimeUs, nsecs_t systemNano) { mCodec->onFrameRendered(mediaTimeUs, systemNano); return true; -- cgit v1.1