Merge "Fix potential NULL dereference in Visualizer effect"
diff --git a/include/media/IOMX.h b/include/media/IOMX.h
index 9790f84..ef01688 100644
--- a/include/media/IOMX.h
+++ b/include/media/IOMX.h
@@ -150,12 +150,6 @@
OMX_U32 port_index, size_t size, buffer_id *buffer,
void **buffer_data, sp<NativeHandle> *native_handle) = 0;
- // Allocate an OMX buffer of size |allotedSize|. Use |params| as the backup buffer, which
- // may be larger.
- virtual status_t allocateBufferWithBackup(
- OMX_U32 port_index, const sp<IMemory> ¶ms,
- buffer_id *buffer, OMX_U32 allottedSize) = 0;
-
virtual status_t freeBuffer(
OMX_U32 port_index, buffer_id buffer) = 0;
@@ -189,6 +183,9 @@
OMX_INDEXTYPE *index) = 0;
virtual status_t dispatchMessage(const omx_message &msg) = 0;
+
+ // TODO: this is temporary, will be removed when quirks move to OMX side
+ virtual status_t setQuirks(OMX_U32 quirks) = 0;
};
struct omx_message {
diff --git a/include/media/stagefright/ACodec.h b/include/media/stagefright/ACodec.h
index cc1e1d0..c02742c 100644
--- a/include/media/stagefright/ACodec.h
+++ b/include/media/stagefright/ACodec.h
@@ -242,7 +242,6 @@
AString mComponentName;
uint32_t mFlags;
- uint32_t mQuirks;
sp<IOMX> mOMX;
sp<IOMXNode> mOMXNode;
int32_t mNodeGeneration;
diff --git a/media/libeffects/downmix/Android.mk b/media/libeffects/downmix/Android.mk
index e0ca8af..78601d5 100644
--- a/media/libeffects/downmix/Android.mk
+++ b/media/libeffects/downmix/Android.mk
@@ -20,5 +20,6 @@
$(call include-path-for, audio-utils)
LOCAL_CFLAGS += -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libeffects/downmix/EffectDownmix.c b/media/libeffects/downmix/EffectDownmix.c
index 9823c55..6cbe78d 100644
--- a/media/libeffects/downmix/EffectDownmix.c
+++ b/media/libeffects/downmix/EffectDownmix.c
@@ -389,7 +389,6 @@
downmix_module_t *pDwmModule = (downmix_module_t *) self;
downmix_object_t *pDownmixer;
- int retsize;
if (pDwmModule == NULL || pDwmModule->context.state == DOWNMIX_STATE_UNINITIALIZED) {
return -EINVAL;
diff --git a/media/libeffects/loudness/Android.mk b/media/libeffects/loudness/Android.mk
index 55d0611..3db4a79 100644
--- a/media/libeffects/loudness/Android.mk
+++ b/media/libeffects/loudness/Android.mk
@@ -8,6 +8,7 @@
dsp/core/dynamic_range_compression.cpp
LOCAL_CFLAGS+= -O2 -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/media/libeffects/loudness/EffectLoudnessEnhancer.cpp b/media/libeffects/loudness/EffectLoudnessEnhancer.cpp
index a5a1a3f..11c6133 100644
--- a/media/libeffects/loudness/EffectLoudnessEnhancer.cpp
+++ b/media/libeffects/loudness/EffectLoudnessEnhancer.cpp
@@ -194,7 +194,6 @@
effect_handle_t *pHandle) {
ALOGV("LELib_Create()");
int ret;
- int i;
if (pHandle == NULL || uuid == NULL) {
return -EINVAL;
@@ -311,7 +310,6 @@
void *pCmdData, uint32_t *replySize, void *pReplyData) {
LoudnessEnhancerContext * pContext = (LoudnessEnhancerContext *)self;
- int retsize;
if (pContext == NULL || pContext->mState == LOUDNESS_ENHANCER_STATE_UNINITIALIZED) {
return -EINVAL;
diff --git a/media/libeffects/lvm/lib/Android.mk b/media/libeffects/lvm/lib/Android.mk
index bb56c75..afc87bb 100644
--- a/media/libeffects/lvm/lib/Android.mk
+++ b/media/libeffects/lvm/lib/Android.mk
@@ -120,6 +120,7 @@
$(LOCAL_PATH)/StereoWidening/lib
LOCAL_CFLAGS += -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
include $(BUILD_STATIC_LIBRARY)
@@ -177,4 +178,5 @@
$(LOCAL_PATH)/Common/src
LOCAL_CFLAGS += -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
include $(BUILD_STATIC_LIBRARY)
diff --git a/media/libeffects/lvm/wrapper/Android.mk b/media/libeffects/lvm/wrapper/Android.mk
index 4e38e3d..9051587 100644
--- a/media/libeffects/lvm/wrapper/Android.mk
+++ b/media/libeffects/lvm/wrapper/Android.mk
@@ -10,6 +10,7 @@
Bundle/EffectBundle.cpp
LOCAL_CFLAGS += -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
LOCAL_MODULE:= libbundlewrapper
@@ -40,6 +41,7 @@
Reverb/EffectReverb.cpp
LOCAL_CFLAGS += -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
LOCAL_MODULE:= libreverbwrapper
diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
index d7b5f65..8aed146 100644
--- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
+++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp
@@ -501,8 +501,6 @@
//----------------------------------------------------------------------------
int LvmBundle_init(EffectContext *pContext){
- int status;
-
ALOGV("\tLvmBundle_init start");
pContext->config.inputCfg.accessMode = EFFECT_BUFFER_ACCESS_READ;
@@ -716,7 +714,6 @@
int frameCount,
EffectContext *pContext){
- LVM_ControlParams_t ActiveParams; /* Current control Parameters */
LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */
LVM_INT16 *pOutTmp;
@@ -1040,7 +1037,6 @@
void LvmEffect_free(EffectContext *pContext){
LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */
- LVM_ControlParams_t params; /* Control Parameters */
LVM_MemTab_t MemTab;
/* Free the algorithm memory */
@@ -2007,8 +2003,6 @@
int status = 0;
int32_t *pParamTemp = (int32_t *)pParam;
int32_t param = *pParamTemp++;
- int32_t param2;
- char *name;
//ALOGV("\tBassBoost_getParameter start");
@@ -2125,7 +2119,6 @@
int status = 0;
int32_t *pParamTemp = (int32_t *)pParam;
int32_t param = *pParamTemp++;
- char *name;
//ALOGV("\tVirtualizer_getParameter start");
@@ -2282,7 +2275,6 @@
uint32_t *pValueSize,
void *pValue){
int status = 0;
- int bMute = 0;
int32_t *pParamTemp = (int32_t *)pParam;
int32_t param = *pParamTemp++;
int32_t param2;
@@ -2540,10 +2532,8 @@
uint32_t *pValueSize,
void *pValue){
int status = 0;
- int bMute = 0;
int32_t *pParamTemp = (int32_t *)pParam;
int32_t param = *pParamTemp++;;
- char *name;
//ALOGV("\tVolume_getParameter start");
@@ -2873,11 +2863,8 @@
audio_buffer_t *inBuffer,
audio_buffer_t *outBuffer){
EffectContext * pContext = (EffectContext *) self;
- LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */
int status = 0;
int processStatus = 0;
- LVM_INT16 *in = (LVM_INT16 *)inBuffer->raw;
- LVM_INT16 *out = (LVM_INT16 *)outBuffer->raw;
//ALOGV("\tEffect_process Start : Enabled = %d Called = %d (%8d %8d %8d)",
//pContext->pBundledContext->NumberEffectsEnabled,pContext->pBundledContext->NumberEffectsCalled,
@@ -3006,7 +2993,6 @@
uint32_t *replySize,
void *pReplyData){
EffectContext * pContext = (EffectContext *) self;
- int retsize;
//ALOGV("\t\nEffect_command start");
@@ -3390,7 +3376,6 @@
int16_t leftdB, rightdB;
int16_t maxdB, pandB;
int32_t vol_ret[2] = {1<<24,1<<24}; // Apply no volume
- int status = 0;
LVM_ControlParams_t ActiveParams; /* Current control Parameters */
LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */
diff --git a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
index f7dcdda..f8b1a8e 100644
--- a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
+++ b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp
@@ -326,6 +326,7 @@
} \
}
+#if 0
//----------------------------------------------------------------------------
// MonoTo2I_32()
//----------------------------------------------------------------------------
@@ -384,6 +385,7 @@
return;
}
+#endif
static inline int16_t clamp16(int32_t sample)
{
@@ -559,7 +561,6 @@
void Reverb_free(ReverbContext *pContext){
LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
- LVREV_ControlParams_st params; /* Control Parameters */
LVREV_MemoryTable_st MemTab;
/* Free the algorithm memory */
@@ -708,8 +709,6 @@
//----------------------------------------------------------------------------
int Reverb_init(ReverbContext *pContext){
- int status;
-
ALOGV("\tReverb_init start");
CHECK_ARG(pContext != NULL);
@@ -1542,7 +1541,6 @@
int status = 0;
int32_t *pParamTemp = (int32_t *)pParam;
int32_t param = *pParamTemp++;
- char *name;
t_reverb_settings *pProperties;
//ALOGV("\tReverb_getParameter start");
@@ -1898,7 +1896,6 @@
uint32_t *replySize,
void *pReplyData){
android::ReverbContext * pContext = (android::ReverbContext *) self;
- int retsize;
LVREV_ControlParams_st ActiveParams; /* Current control Parameters */
LVREV_ReturnStatus_en LvmStatus=LVREV_SUCCESS; /* Function call status */
diff --git a/media/libeffects/preprocessing/Android.mk b/media/libeffects/preprocessing/Android.mk
index bd67aa1..60030ac 100644
--- a/media/libeffects/preprocessing/Android.mk
+++ b/media/libeffects/preprocessing/Android.mk
@@ -28,5 +28,6 @@
-DWEBRTC_POSIX
LOCAL_CFLAGS += -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
include $(BUILD_SHARED_LIBRARY)
diff --git a/media/libeffects/preprocessing/PreProcessing.cpp b/media/libeffects/preprocessing/PreProcessing.cpp
index f48bac1..ccfd29c 100644
--- a/media/libeffects/preprocessing/PreProcessing.cpp
+++ b/media/libeffects/preprocessing/PreProcessing.cpp
@@ -933,7 +933,6 @@
int Session_SetConfig(preproc_session_t *session, effect_config_t *config)
{
- uint32_t sr;
uint32_t inCnl = audio_channel_count_from_in_mask(config->inputCfg.channels);
uint32_t outCnl = audio_channel_count_from_in_mask(config->outputCfg.channels);
@@ -1153,7 +1152,6 @@
preproc_session_t *PreProc_GetSession(int32_t procId, int32_t sessionId, int32_t ioId)
{
size_t i;
- int free = -1;
for (i = 0; i < PREPROC_NUM_SESSIONS; i++) {
if (sSessions[i].io == ioId) {
if (sSessions[i].createdMsk & (1 << procId)) {
@@ -1210,7 +1208,6 @@
audio_buffer_t *outBuffer)
{
preproc_effect_t * effect = (preproc_effect_t *)self;
- int status = 0;
if (effect == NULL){
ALOGV("PreProcessingFx_Process() ERROR effect == NULL");
@@ -1402,8 +1399,6 @@
void *pReplyData)
{
preproc_effect_t * effect = (preproc_effect_t *) self;
- int retsize;
- int status;
if (effect == NULL){
return -EINVAL;
@@ -1777,7 +1772,6 @@
audio_buffer_t *outBuffer __unused)
{
preproc_effect_t * effect = (preproc_effect_t *)self;
- int status = 0;
if (effect == NULL){
ALOGW("PreProcessingFx_ProcessReverse() ERROR effect == NULL");
@@ -1926,7 +1920,6 @@
int PreProcessingLib_Release(effect_handle_t interface)
{
- int status;
ALOGV("EffectRelease start %p", interface);
if (PreProc_Init() != 0) {
return sInitStatus;
diff --git a/media/libeffects/proxy/Android.mk b/media/libeffects/proxy/Android.mk
index 2ba452e..0acf1c0 100644
--- a/media/libeffects/proxy/Android.mk
+++ b/media/libeffects/proxy/Android.mk
@@ -23,6 +23,7 @@
EffectProxy.cpp
LOCAL_CFLAGS+= -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
LOCAL_SHARED_LIBRARIES := liblog libcutils libutils libdl libeffects
diff --git a/media/libeffects/proxy/EffectProxy.cpp b/media/libeffects/proxy/EffectProxy.cpp
index 62d3fd3..b16a98b 100644
--- a/media/libeffects/proxy/EffectProxy.cpp
+++ b/media/libeffects/proxy/EffectProxy.cpp
@@ -44,12 +44,6 @@
};
-static const effect_descriptor_t *const gDescriptors[] =
-{
- &gProxyDescriptor,
-};
-
-
int EffectProxyCreate(const effect_uuid_t *uuid,
int32_t sessionId,
int32_t ioId,
diff --git a/media/libeffects/visualizer/Android.mk b/media/libeffects/visualizer/Android.mk
index c92c543..ddcc565 100644
--- a/media/libeffects/visualizer/Android.mk
+++ b/media/libeffects/visualizer/Android.mk
@@ -7,6 +7,7 @@
EffectVisualizer.cpp
LOCAL_CFLAGS+= -O2 -fvisibility=hidden
+LOCAL_CFLAGS += -Wall -Werror
LOCAL_SHARED_LIBRARIES := \
libcutils \
diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp
index 21fddb1..4c71907 100644
--- a/media/libeffects/visualizer/EffectVisualizer.cpp
+++ b/media/libeffects/visualizer/EffectVisualizer.cpp
@@ -233,7 +233,6 @@
int32_t /*ioId*/,
effect_handle_t *pHandle) {
int ret;
- int i;
if (pHandle == NULL || uuid == NULL) {
return -EINVAL;
@@ -415,7 +414,6 @@
void *pCmdData, uint32_t *replySize, void *pReplyData) {
VisualizerContext * pContext = (VisualizerContext *)self;
- int retsize;
if (pContext == NULL || pContext->mState == VISUALIZER_STATE_UNINITIALIZED) {
return -EINVAL;
diff --git a/media/libmedia/IOMX.cpp b/media/libmedia/IOMX.cpp
index fb05fef..9360777 100644
--- a/media/libmedia/IOMX.cpp
+++ b/media/libmedia/IOMX.cpp
@@ -50,7 +50,6 @@
STORE_META_DATA_IN_BUFFERS,
PREPARE_FOR_ADAPTIVE_PLAYBACK,
ALLOC_SECURE_BUFFER,
- ALLOC_BUFFER_WITH_BACKUP,
FREE_BUFFER,
FILL_BUFFER,
EMPTY_BUFFER,
@@ -62,6 +61,7 @@
CONFIGURE_VIDEO_TUNNEL_MODE,
UPDATE_NATIVE_HANDLE_IN_META,
DISPATCH_MESSAGE,
+ SET_QUIRKS,
};
class BpOMX : public BpInterface<IOMX> {
@@ -478,28 +478,6 @@
return err;
}
- virtual status_t allocateBufferWithBackup(
- OMX_U32 port_index, const sp<IMemory> ¶ms,
- buffer_id *buffer, OMX_U32 allottedSize) {
- Parcel data, reply;
- data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor());
- data.writeInt32(port_index);
- data.writeStrongBinder(IInterface::asBinder(params));
- data.writeInt32(allottedSize);
- remote()->transact(ALLOC_BUFFER_WITH_BACKUP, data, &reply);
-
- status_t err = reply.readInt32();
- if (err != OK) {
- *buffer = 0;
-
- return err;
- }
-
- *buffer = (buffer_id)reply.readInt32();
-
- return err;
- }
-
virtual status_t freeBuffer(
OMX_U32 port_index, buffer_id buffer) {
Parcel data, reply;
@@ -597,6 +575,16 @@
return reply.readInt32();
}
+
+ virtual status_t setQuirks(OMX_U32 quirks) {
+ Parcel data, reply;
+ data.writeInterfaceToken(IOMXNode::getInterfaceDescriptor());
+ data.writeInt32(quirks);
+
+ remote()->transact(SET_QUIRKS, data, &reply);
+
+ return reply.readInt32();
+ }
};
IMPLEMENT_META_INTERFACE(OMX, "android.hardware.IOMX");
@@ -1050,34 +1038,6 @@
return NO_ERROR;
}
- case ALLOC_BUFFER_WITH_BACKUP:
- {
- CHECK_OMX_INTERFACE(IOMXNode, data, reply);
-
- OMX_U32 port_index = data.readInt32();
- sp<IMemory> params =
- interface_cast<IMemory>(data.readStrongBinder());
- OMX_U32 allottedSize = data.readInt32();
-
- if (params == NULL) {
- ALOGE("b/26392700");
- reply->writeInt32(INVALID_OPERATION);
- return NO_ERROR;
- }
-
- buffer_id buffer;
- status_t err = allocateBufferWithBackup(
- port_index, params, &buffer, allottedSize);
-
- reply->writeInt32(err);
-
- if (err == OK) {
- reply->writeInt32((int32_t)buffer);
- }
-
- return NO_ERROR;
- }
-
case FREE_BUFFER:
{
CHECK_OMX_INTERFACE(IOMXNode, data, reply);
@@ -1178,6 +1138,17 @@
return NO_ERROR;
}
+ case SET_QUIRKS:
+ {
+ CHECK_OMX_INTERFACE(IOMXNode, data, reply);
+
+ OMX_U32 quirks = data.readInt32();
+
+ reply->writeInt32(setQuirks(quirks));
+
+ return NO_ERROR;
+ }
+
default:
return BBinder::onTransact(code, data, reply, flags);
}
diff --git a/media/libstagefright/ACodec.cpp b/media/libstagefright/ACodec.cpp
index e4047c8..93d4199 100644
--- a/media/libstagefright/ACodec.cpp
+++ b/media/libstagefright/ACodec.cpp
@@ -510,7 +510,6 @@
ACodec::ACodec()
: mSampleRate(0),
- mQuirks(0),
mNodeGeneration(0),
mUsingNativeWindow(false),
mNativeWindowUsageBits(0),
@@ -881,11 +880,6 @@
info.mRenderInfo = NULL;
info.mNativeHandle = NULL;
- uint32_t requiresAllocateBufferBit =
- (portIndex == kPortIndexInput)
- ? kRequiresAllocateBufferOnInputPorts
- : kRequiresAllocateBufferOnOutputPorts;
-
if (portIndex == kPortIndexInput && (mFlags & kFlagIsSecure)) {
mem.clear();
@@ -909,11 +903,9 @@
new ABuffer(ptr != NULL ? ptr : (void *)native_handle_ptr, bufSize));
info.mNativeHandle = native_handle;
info.mCodecData = info.mData;
- } else if (mQuirks & requiresAllocateBufferBit) {
- err = mOMXNode->allocateBufferWithBackup(
- portIndex, mem, &info.mBufferID, allottedSize);
} else {
- err = mOMXNode->useBuffer(portIndex, mem, &info.mBufferID, allottedSize);
+ err = mOMXNode->useBuffer(
+ portIndex, mem, &info.mBufferID, allottedSize);
}
if (mem != NULL) {
@@ -6233,7 +6225,6 @@
mCodec->mNativeWindowUsageBits = 0;
mCodec->mOMX.clear();
mCodec->mOMXNode.clear();
- mCodec->mQuirks = 0;
mCodec->mFlags = 0;
mCodec->mInputMetadataType = kMetadataBufferTypeInvalid;
mCodec->mOutputMetadataType = kMetadataBufferTypeInvalid;
@@ -6407,7 +6398,7 @@
mCodec->mFlags |= kFlagPushBlankBuffersToNativeWindowOnShutdown;
}
- mCodec->mQuirks = quirks;
+ omxNode->setQuirks(quirks);
mCodec->mOMX = omx;
mCodec->mOMXNode = omxNode;
diff --git a/media/libstagefright/MediaCodecSource.cpp b/media/libstagefright/MediaCodecSource.cpp
index 137a924..8391d76 100644
--- a/media/libstagefright/MediaCodecSource.cpp
+++ b/media/libstagefright/MediaCodecSource.cpp
@@ -860,6 +860,7 @@
}
MediaBuffer *mbuf = new MediaBuffer(outbuf->size());
+ mbuf->setObserver(this);
mbuf->add_ref();
if (!(flags & MediaCodec::BUFFER_FLAG_CODECCONFIG)) {
@@ -913,7 +914,6 @@
mbuf->meta_data()->setInt32(kKeyIsSyncFrame, true);
}
memcpy(mbuf->data(), outbuf->data(), outbuf->size());
- mbuf->setObserver(this);
{
Mutexed<Output>::Locked output(mOutput);
diff --git a/media/libstagefright/include/OMXNodeInstance.h b/media/libstagefright/include/OMXNodeInstance.h
index 640f840..30d0b75 100644
--- a/media/libstagefright/include/OMXNodeInstance.h
+++ b/media/libstagefright/include/OMXNodeInstance.h
@@ -101,10 +101,6 @@
OMX_U32 portIndex, size_t size, OMX::buffer_id *buffer,
void **buffer_data, sp<NativeHandle> *native_handle);
- status_t allocateBufferWithBackup(
- OMX_U32 portIndex, const sp<IMemory> ¶ms,
- OMX::buffer_id *buffer, OMX_U32 allottedSize);
-
status_t freeBuffer(OMX_U32 portIndex, OMX::buffer_id buffer);
status_t fillBuffer(OMX::buffer_id buffer, int fenceFd);
@@ -122,6 +118,8 @@
status_t getExtensionIndex(
const char *parameterName, OMX_INDEXTYPE *index);
+ status_t setQuirks(OMX_U32 quirks);
+
bool isSecure() const {
return mIsSecure;
}
@@ -150,6 +148,7 @@
bool mQueriedProhibitedExtensions;
SortedVector<OMX_INDEXTYPE> mProhibitedExtensions;
bool mIsSecure;
+ uint32_t mQuirks;
// Lock only covers mOMXBufferSource and mOMXOutputListener. We can't always
// use mLock because of rare instances where we'd end up locking it recursively.
@@ -251,7 +250,7 @@
// buffer.)
status_t updateGraphicBufferInMeta_l(
OMX_U32 portIndex, const sp<GraphicBuffer> &graphicBuffer,
- OMX::buffer_id buffer, OMX_BUFFERHEADERTYPE *header, bool updateCodecBuffer);
+ OMX::buffer_id buffer, OMX_BUFFERHEADERTYPE *header);
status_t createGraphicBufferSource(
OMX_U32 portIndex, android_dataspace dataSpace,
diff --git a/media/libstagefright/omx/OMXNodeInstance.cpp b/media/libstagefright/omx/OMXNodeInstance.cpp
index b747895..e45507c 100644
--- a/media/libstagefright/omx/OMXNodeInstance.cpp
+++ b/media/libstagefright/omx/OMXNodeInstance.cpp
@@ -46,6 +46,15 @@
static const OMX_U32 kPortIndexInput = 0;
static const OMX_U32 kPortIndexOutput = 1;
+// Quirk still supported, even though deprecated
+enum Quirks {
+ kRequiresAllocateBufferOnInputPorts = 1,
+ kRequiresAllocateBufferOnOutputPorts = 2,
+
+ kQuirksMask = kRequiresAllocateBufferOnInputPorts
+ | kRequiresAllocateBufferOnOutputPorts,
+};
+
#define CLOGW(fmt, ...) ALOGW("[%p:%s] " fmt, mHandle, mName, ##__VA_ARGS__)
#define CLOG_ERROR_IF(cond, fn, err, fmt, ...) \
@@ -98,18 +107,16 @@
struct BufferMeta {
explicit BufferMeta(
- const sp<IMemory> &mem, OMX_U32 portIndex, bool copyToOmx,
- bool copyFromOmx, OMX_U8 *backup)
+ const sp<IMemory> &mem, OMX_U32 portIndex, bool copy, OMX_U8 *backup)
: mMem(mem),
- mCopyFromOmx(copyFromOmx),
- mCopyToOmx(copyToOmx),
+ mCopyFromOmx(portIndex == kPortIndexOutput && copy),
+ mCopyToOmx(portIndex == kPortIndexInput && copy),
mPortIndex(portIndex),
mBackup(backup) {
}
- explicit BufferMeta(size_t size, OMX_U32 portIndex)
- : mSize(size),
- mCopyFromOmx(false),
+ explicit BufferMeta(OMX_U32 portIndex)
+ : mCopyFromOmx(false),
mCopyToOmx(false),
mPortIndex(portIndex),
mBackup(NULL) {
@@ -129,7 +136,7 @@
}
// check component returns proper range
- sp<ABuffer> codec = getBuffer(header, false /* backup */, true /* limit */);
+ sp<ABuffer> codec = getBuffer(header, true /* limit */);
memcpy((OMX_U8 *)mMem->pointer() + header->nOffset, codec->data(), codec->size());
}
@@ -144,14 +151,9 @@
header->nFilledLen);
}
- // return either the codec or the backup buffer
- sp<ABuffer> getBuffer(const OMX_BUFFERHEADERTYPE *header, bool backup, bool limit) {
- sp<ABuffer> buf;
- if (backup && mMem != NULL) {
- buf = new ABuffer(mMem->pointer(), mMem->size());
- } else {
- buf = new ABuffer(header->pBuffer, header->nAllocLen);
- }
+ // return the codec buffer
+ sp<ABuffer> getBuffer(const OMX_BUFFERHEADERTYPE *header, bool limit) {
+ sp<ABuffer> buf = new ABuffer(header->pBuffer, header->nAllocLen);
if (limit) {
if (header->nOffset + header->nFilledLen > header->nOffset
&& header->nOffset + header->nFilledLen <= header->nAllocLen) {
@@ -183,7 +185,6 @@
sp<GraphicBuffer> mGraphicBuffer;
sp<NativeHandle> mNativeHandle;
sp<IMemory> mMem;
- size_t mSize;
bool mCopyFromOmx;
bool mCopyToOmx;
OMX_U32 mPortIndex;
@@ -339,6 +340,7 @@
mDying(false),
mSailed(false),
mQueriedProhibitedExtensions(false),
+ mQuirks(0),
mBufferIDCount(0),
mShouldRestorePts(false),
mRestorePtsFailed(false)
@@ -907,43 +909,64 @@
return BAD_VALUE;
}
- // metadata buffers are not connected cross process
- // use a backup buffer instead of the actual buffer
BufferMeta *buffer_meta;
- bool useBackup = mMetadataType[portIndex] != kMetadataBufferTypeInvalid;
- OMX_U8 *data = static_cast<OMX_U8 *>(params->pointer());
- // allocate backup buffer
- if (useBackup) {
- data = new (std::nothrow) OMX_U8[allottedSize];
- if (data == NULL) {
- return NO_MEMORY;
- }
- memset(data, 0, allottedSize);
+ OMX_BUFFERHEADERTYPE *header;
+ OMX_ERRORTYPE err = OMX_ErrorNone;
+ bool isMetadata = mMetadataType[portIndex] != kMetadataBufferTypeInvalid;
- // if we are not connecting the buffers, the sizes must match
- if (allottedSize != params->size()) {
- CLOG_ERROR(useBuffer, BAD_VALUE, SIMPLE_BUFFER(portIndex, (size_t)allottedSize, data));
- delete[] data;
- return BAD_VALUE;
- }
+ uint32_t requiresAllocateBufferBit =
+ (portIndex == kPortIndexInput)
+ ? kRequiresAllocateBufferOnInputPorts
+ : kRequiresAllocateBufferOnOutputPorts;
+ if (mQuirks & requiresAllocateBufferBit) {
+ // metadata buffers are not connected cross process; only copy if not meta.
buffer_meta = new BufferMeta(
- params, portIndex, false /* copyToOmx */, false /* copyFromOmx */, data);
+ params, portIndex, !isMetadata /* copy */, NULL /* data */);
+
+ err = OMX_AllocateBuffer(
+ mHandle, &header, portIndex, buffer_meta, allottedSize);
+
+ if (err != OMX_ErrorNone) {
+ CLOG_ERROR(allocateBuffer, err,
+ SIMPLE_BUFFER(portIndex, (size_t)allottedSize, params->pointer()));
+ }
} else {
- buffer_meta = new BufferMeta(
- params, portIndex, false /* copyToOmx */, false /* copyFromOmx */, NULL);
+ OMX_U8 *data = static_cast<OMX_U8 *>(params->pointer());
+
+ // metadata buffers are not connected cross process
+ // use a backup buffer instead of the actual buffer
+ if (isMetadata) {
+ // if we are not connecting the buffers, the sizes must match
+ if (allottedSize != params->size()) {
+ CLOG_ERROR(useBuffer, BAD_VALUE, SIMPLE_BUFFER(portIndex, (size_t)allottedSize, data));
+ return BAD_VALUE;
+ }
+
+ data = new (std::nothrow) OMX_U8[allottedSize];
+ if (data == NULL) {
+ return NO_MEMORY;
+ }
+ memset(data, 0, allottedSize);
+
+ buffer_meta = new BufferMeta(
+ params, portIndex, false /* copy */, data);
+ } else {
+ buffer_meta = new BufferMeta(
+ params, portIndex, false /* copy */, NULL);
+ }
+
+ err = OMX_UseBuffer(
+ mHandle, &header, portIndex, buffer_meta,
+ allottedSize, data);
+
+ if (err != OMX_ErrorNone) {
+ CLOG_ERROR(useBuffer, err, SIMPLE_BUFFER(
+ portIndex, (size_t)allottedSize, data));
+ }
}
- OMX_BUFFERHEADERTYPE *header;
-
- OMX_ERRORTYPE err = OMX_UseBuffer(
- mHandle, &header, portIndex, buffer_meta,
- allottedSize, data);
-
if (err != OMX_ErrorNone) {
- CLOG_ERROR(useBuffer, err, SIMPLE_BUFFER(
- portIndex, (size_t)allottedSize, data));
-
delete buffer_meta;
buffer_meta = NULL;
@@ -1090,7 +1113,7 @@
status_t OMXNodeInstance::updateGraphicBufferInMeta_l(
OMX_U32 portIndex, const sp<GraphicBuffer>& graphicBuffer,
- OMX::buffer_id buffer, OMX_BUFFERHEADERTYPE *header, bool updateCodecBuffer) {
+ OMX::buffer_id buffer, OMX_BUFFERHEADERTYPE *header) {
// No need to check |graphicBuffer| since NULL is valid for it as below.
if (header == NULL) {
ALOGE("b/25884056");
@@ -1102,14 +1125,9 @@
}
BufferMeta *bufferMeta = (BufferMeta *)(header->pAppPrivate);
- sp<ABuffer> data = bufferMeta->getBuffer(
- header, !updateCodecBuffer /* backup */, false /* limit */);
+ sp<ABuffer> data = bufferMeta->getBuffer(header, false /* limit */);
bufferMeta->setGraphicBuffer(graphicBuffer);
MetadataBufferType metaType = mMetadataType[portIndex];
- // we use gralloc source only in the codec buffers
- if (metaType == kMetadataBufferTypeGrallocSource && !updateCodecBuffer) {
- metaType = kMetadataBufferTypeANWBuffer;
- }
if (metaType == kMetadataBufferTypeGrallocSource
&& data->capacity() >= sizeof(VideoGrallocMetadata)) {
VideoGrallocMetadata &metadata = *(VideoGrallocMetadata *)(data->data());
@@ -1138,10 +1156,9 @@
OMX::buffer_id buffer) {
Mutex::Autolock autoLock(mLock);
OMX_BUFFERHEADERTYPE *header = findBufferHeader(buffer, portIndex);
- // update backup buffer for input, codec buffer for output
+
return updateGraphicBufferInMeta_l(
- portIndex, graphicBuffer, buffer, header,
- true /* updateCodecBuffer */);
+ portIndex, graphicBuffer, buffer, header);
}
status_t OMXNodeInstance::updateNativeHandleInMeta(
@@ -1159,9 +1176,7 @@
}
BufferMeta *bufferMeta = (BufferMeta *)(header->pAppPrivate);
- // update backup buffer
- sp<ABuffer> data = bufferMeta->getBuffer(
- header, false /* backup */, false /* limit */);
+ sp<ABuffer> data = bufferMeta->getBuffer(header, false /* limit */);
bufferMeta->setNativeHandle(nativeHandle);
if (mMetadataType[portIndex] == kMetadataBufferTypeNativeHandleSource
&& data->capacity() >= sizeof(VideoNativeHandleMetadata)) {
@@ -1342,7 +1357,7 @@
Mutex::Autolock autoLock(mLock);
- BufferMeta *buffer_meta = new BufferMeta(size, portIndex);
+ BufferMeta *buffer_meta = new BufferMeta(portIndex);
OMX_BUFFERHEADERTYPE *header;
@@ -1384,60 +1399,6 @@
return OK;
}
-status_t OMXNodeInstance::allocateBufferWithBackup(
- OMX_U32 portIndex, const sp<IMemory> ¶ms,
- OMX::buffer_id *buffer, OMX_U32 allottedSize) {
- if (params == NULL || buffer == NULL) {
- ALOGE("b/25884056");
- return BAD_VALUE;
- }
-
- Mutex::Autolock autoLock(mLock);
- if (allottedSize > params->size() || portIndex >= NELEM(mNumPortBuffers)) {
- return BAD_VALUE;
- }
-
- // metadata buffers are not connected cross process; only copy if not meta
- bool copy = mMetadataType[portIndex] == kMetadataBufferTypeInvalid;
-
- BufferMeta *buffer_meta = new BufferMeta(
- params, portIndex,
- (portIndex == kPortIndexInput) && copy /* copyToOmx */,
- (portIndex == kPortIndexOutput) && copy /* copyFromOmx */,
- NULL /* data */);
-
- OMX_BUFFERHEADERTYPE *header;
-
- OMX_ERRORTYPE err = OMX_AllocateBuffer(
- mHandle, &header, portIndex, buffer_meta, allottedSize);
- if (err != OMX_ErrorNone) {
- CLOG_ERROR(allocateBufferWithBackup, err,
- SIMPLE_BUFFER(portIndex, (size_t)allottedSize, params->pointer()));
- delete buffer_meta;
- buffer_meta = NULL;
-
- *buffer = 0;
-
- return StatusFromOMXError(err);
- }
-
- CHECK_EQ(header->pAppPrivate, buffer_meta);
-
- *buffer = makeBufferID(header);
-
- addActiveBuffer(portIndex, *buffer);
-
- sp<IOMXBufferSource> bufferSource(getBufferSource());
- if (bufferSource != NULL && portIndex == kPortIndexInput) {
- bufferSource->onInputBufferAdded(*buffer);
- }
-
- CLOG_BUFFER(allocateBufferWithBackup, NEW_BUFFER_FMT(*buffer, portIndex, "%zu@%p :> %u@%p",
- params->size(), params->pointer(), allottedSize, header->pBuffer));
-
- return OK;
-}
-
status_t OMXNodeInstance::freeBuffer(
OMX_U32 portIndex, OMX::buffer_id buffer) {
Mutex::Autolock autoLock(mLock);
@@ -1661,8 +1622,7 @@
}
status_t err = updateGraphicBufferInMeta_l(
- kPortIndexInput, graphicBuffer, buffer, header,
- true /* updateCodecBuffer */);
+ kPortIndexInput, graphicBuffer, buffer, header);
if (err != OK) {
CLOG_ERROR(emptyGraphicBuffer, err, FULL_BUFFER(
(intptr_t)header->pBuffer, header, fenceFd));
@@ -1732,7 +1692,17 @@
status_t OMXNodeInstance::dispatchMessage(const omx_message &msg) {
mDispatcher->post(msg, true /*realTime*/);
- return OMX_ErrorNone;
+ return OK;
+}
+
+status_t OMXNodeInstance::setQuirks(OMX_U32 quirks) {
+ if (quirks & ~kQuirksMask) {
+ return BAD_VALUE;
+ }
+
+ mQuirks = quirks;
+
+ return OK;
}
bool OMXNodeInstance::handleMessage(omx_message &msg) {
diff --git a/media/libstagefright/omx/tests/OMXHarness.cpp b/media/libstagefright/omx/tests/OMXHarness.cpp
index a940c51..ea99e53 100644
--- a/media/libstagefright/omx/tests/OMXHarness.cpp
+++ b/media/libstagefright/omx/tests/OMXHarness.cpp
@@ -210,9 +210,9 @@
buffer.mFlags = 0;
CHECK(buffer.mMemory != NULL);
- err = mOMXNode->allocateBufferWithBackup(
+ err = mOMXNode->useBuffer(
portIndex, buffer.mMemory, &buffer.mID, buffer.mMemory->size());
- EXPECT_SUCCESS(err, "allocateBuffer");
+ EXPECT_SUCCESS(err, "useBuffer");
buffers->push(buffer);
}