PDA

View Full Version : OMX_AllocateBuffer failing



chandrashekar
06-06-2010, 11:46 PM
Hi I'm New to omxIL. I'm trying to decode a sample .264 content on FSL imx_51 platorm running on Android 2.0 ,
After calling OMX_GetHandle, the component is created and moves to OMX_StateLoaded.
But after OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateIdle, 0)
The same component is not moving to OMX_StateIdle.
Also OMX_AllocateBuffer is failing.
Anyone please go through my below code. Help me out.


Here is code,
#include "test.h"

appPrivateType* appPriv;



int main()
{
OMX_ERRORTYPE eError = OMX_ErrorNone;
int i;
bool present = false;
char szCompName[256];
OMX_U32 no_of_roles;
OMX_U8 **string_of_roles;
int index;

pAppData = (OMX_PTR) malloc(sizeof(OMX_PTR));
eError = OMX_Init(); //Step 1
check_err(eError,"OMX_Init");

for (i=0; OMX_ErrorNoMore != eError; i++)
{
eError = OMX_ComponentNameEnum((OMX_STRING)szCompName, 256, i);
if (OMX_ErrorNone == eError)
fprintf(stderr,"Component %d: %s\n",i,(OMX_STRING) szCompName);
else
fprintf(stderr,"OMX_ComponentNameEnum Component ERROR\n");

if(strstr((const char*) szCompName,"video_decoder.avc"))
{
fprintf(stderr,"Found h/w decoder for avc\n");
present = true;
}
}

eError = OMX_GetRolesOfComponent(CompName, &no_of_roles, NULL); //Step 2 Call the OMX Init API OMX_Init
check_err(eError,"OMX_GetRolesOfComponent");

if(no_of_roles == 0) {
fprintf(stderr, "The Number or roles is 0.\nThe component selected is not correct for the purpose of this test.\nExiting...\n");
}
else {
string_of_roles = (OMX_U8**)malloc(no_of_roles * sizeof(OMX_STRING));
for (index = 0; index < no_of_roles; index++) {
*(string_of_roles + index) =(OMX_U8*) malloc(no_of_roles * OMX_MAX_STRINGNAME_SIZE);
}

eError = OMX_GetRolesOfComponent(CompName, &no_of_roles, string_of_roles);
check_err(eError,"OMX_GetRolesOfComponent");

if(string_of_roles != NULL) {
for (index = 0; index < no_of_roles; index++)
{
fprintf(stderr, "The role %i for the component: %s \n", (index + 1), *(string_of_roles+index));
}

}
else
{
fprintf(stderr, "role string is NULL!!! Exiting...\n");
}
}

videodeccallbacks.EventHandler = videodecEventHandler;
videodeccallbacks.EmptyBufferDone = videodecEmptyBufferDone; //Assign CallBack Functions
videodeccallbacks.FillBufferDone = videodecFillBufferDone;

if(present == true)
{
eError = OMX_ErrorNone;
appPriv = (appPrivateType*) malloc(sizeof(appPrivateType));

if(appPriv == NULL)
{
fprintf(stderr,"malloc failed for appPriv\n");
cleanup(appPriv->videodechandle);
}

eError = OMX_GetHandle(&appPriv->videodechandle, CompName,pAppData , &videodeccallbacks); //step3 try to create Required OMX Component
check_err(eError,"OMX_GetHandle");

setHeader(&paramRole, sizeof(OMX_PARAM_COMPONENTROLETYPE));
eError = OMX_GetParameter(appPriv->videodechandle, OMX_IndexParamStandardComponentRole, &paramRole);
check_err(eError,"OMX_GetParameter");
fprintf(stderr, "The role currently set is %s\n", paramRole.cRole);

buffer_out_size = out_width * out_height * 3/2; //yuv420 format -- bpp = 12
pInBuffer1 = pInBuffer2 = NULL;
pOutBuffer1 = pOutBuffer2 = NULL;

fprintf(stderr,"buffer_insize = %d buffer_outsize = %d\n",(int)buffer_in_size,(int)buffer_in_size);

//eError = OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
//check_err(eError,"OMX_SendCommand OMX_StateLoaded");

OMX_STATETYPE eState;
OMX_GetState(appPriv->videodechandle, &eState);
GetState(eState);
eError = OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateIdle, 0); //step 4 Send state change command to OMX component to OMX_StateIdle
check_err(eError,"OMX_SendCommand OMX_StateIdle");
OMX_GetState(appPriv->videodechandle, &eState);
GetState(eState);

eError = OMX_AllocateBuffer(appPriv->videodechandle, &pInBuffer1, 0, NULL, buffer_in_size); // Allocate Buffer
check_err(eError,"OMX_AllocateBuffer P1");

eError = OMX_AllocateBuffer(appPriv->videodechandle, &pInBuffer2, 0, NULL, buffer_in_size);
check_err(eError,"OMX_AllocateBuffer P2");

eError = OMX_AllocateBuffer(appPriv->videodechandle, &pOutBuffer1, 1, NULL, buffer_out_size);
check_err(eError,"OMX_AllocateBuffer P3");

eError = OMX_AllocateBuffer(appPriv->videodechandle, &pOutBuffer2, 1, NULL, buffer_out_size);
check_err(eError,"OMX_AllocateBuffer P4");

eError = OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateIdle, 0); //step 4 Send state change command to OMX component to OMX_StateIdle
check_err(eError,"OMX_SendCommand OMX_StateIdle");

//eError = OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateLoaded, NULL);
// check_err(eError,"OMX_SendCommand OMX_StateLoaded");
#if 0
#endif
// eError = OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateIdle, NULL);
// eError = OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateExecuting, NULL);
// check_err(eError,"OMX_SendCommand OMX_StateExecuting");
#if 0
eError = OMX_FillThisBuffer(appPriv->videodechandle, pOutBuffer1);
check_err(eError,"OMX_FillThisBuffer");

eError = OMX_FillThisBuffer(appPriv->videodechandle, pOutBuffer2);
check_err(eError,"OMX_FillThisBuffer");
#endif
free(appPriv);
cleanup(appPriv->videodechandle);
}
return 0;
}

static void setHeader(OMX_PTR header, OMX_U32 size) {

OMX_VERSIONTYPE* ver = (OMX_VERSIONTYPE*)(header + sizeof(OMX_U32));
fprintf(stderr,"%s:%s",__FILE__,__func__);
*((OMX_U32*)header) = size;
ver->s.nVersionMajor = VERSIONMAJOR;
ver->s.nVersionMinor = VERSIONMINOR;
ver->s.nRevision = VERSIONREVISION;
ver->s.nStep = VERSIONSTEP;
}

void check_err(OMX_ERRORTYPE eError, const char* notification)
{
if(eError!=OMX_ErrorNone)
{
fprintf(stderr,"Error Due to %s\n",notification);
OMX_Deinit();
}
else
fprintf(stderr,"successfull %s\n",notification);
}

void cleanup(OMX_HANDLETYPE videodechandle)
{
fprintf(stderr,"%s:%s",__FILE__,__func__);

OMX_FreeHandle(videodechandle);
OMX_Deinit();
}


void GetState(OMX_STATETYPE state)
{
switch ((int)state)
{
case OMX_StateInvalid:
fprintf(stderr,"%s:%s:State changed OMX_StateInvalid \n",__func__,__FILE__);
break;
case OMX_StateLoaded:
fprintf(stderr,"%s:%s:State changed OMX_StateLoaded\n",__func__,__FILE__);
break;
case OMX_StateIdle:
fprintf(stderr,"%s:%s:State changed OMX_StateIdle\n",__func__,__FILE__);
break;
case OMX_StateExecuting:
fprintf(stderr,"%s:%s:State changed OMX_StateExecuting\n",__func__,__FILE__);
break;
case OMX_StatePause:
fprintf(stderr,"%s:%s:State changed OMX_StatePause\n",__func__,__FILE__);
break;
case OMX_StateWaitForResources:
fprintf(stderr,"%s:%s:State changed OMX_StateWaitForResources\n",__func__,__FILE__);
break;
default :
fprintf(stderr,"%s:%s:State changed Unknwon State\n",__func__,__FILE__);

}
}

OMX_ERRORTYPE videodecEventHandler( OMX_OUT OMX_HANDLETYPE hComponent,OMX_OUT OMX_PTR pAppData, OMX_OUT OMX_EVENTTYPE eEvent, OMX_OUT OMX_U32 Data1, OMX_OUT OMX_U32 Data2, OMX_OUT OMX_PTR pEventData) {

fprintf(stderr,"%s:%s:Event count = %d\n",__func__,__FILE__,++event_count);
OMX_ERRORTYPE eError = OMX_ErrorNone;

switch(eEvent){
case OMX_EventCmdComplete:
fprintf(stderr,"OMX_EventCmdComplete\n");
break;

case OMX_EventError:
fprintf(stderr,"OMX_EventError\n");
break;

case OMX_EventMark:
fprintf(stderr,"OMX_EventMark\n");
break;

case OMX_EventPortSettingsChanged:
fprintf(stderr,"OMX_EventPortSettingsChanged\n");
break;

case OMX_EventBufferFlag:
fprintf(stderr,"OMX_EventBufferFlag\n");
break;

case OMX_EventResourcesAcquired:
fprintf(stderr,"OMX_EventResourcesAcquired\n");
break;

case OMX_EventComponentResumed:
fprintf(stderr,"OMX_EventComponentResumed\n");
break;

case OMX_EventDynamicResourcesAvailable:
fprintf(stderr,"OMX_EventDynamicResourcesAvailable\n");
break;

case OMX_EventPortFormatDetected:
fprintf(stderr,"OMX_EventPortFormatDetected\n");
break;

case OMX_EventKhronosExtensions:
fprintf(stderr,"OMX_EventKhronosExtensions\n");
break;
case OMX_EventMax:
fprintf(stderr,"OMX_EventMax\n");
break;
case OMX_EventVendorStartUnused:
fprintf(stderr,"OMX_EventVendorStartUnused\n");
break;
default :
fprintf(stderr,"Unknown EVENT\n");

}

if(eEvent == OMX_EventCmdComplete)
{

fprintf(stderr,"%s:%s:State changed \n",__func__,__FILE__);

if (Data1 == OMX_CommandStateSet)
{
fprintf(stderr,"%s:%s:State changed \n",__func__,__FILE__);

switch ((int)Data2)
{
case OMX_StateInvalid:
fprintf(stderr,"%s:%s:State changed OMX_StateInvalid \n",__func__,__FILE__);
break;
case OMX_StateLoaded:
fprintf(stderr,"%s:%s:State changed OMX_StateLoaded\n",__func__,__FILE__);
break;
case OMX_StateIdle:
fprintf(stderr,"%s:%s:State changed OMX_StateIdle\n",__func__,__FILE__);
break;
case OMX_StateExecuting:
fprintf(stderr,"%s:%s:State changed OMX_StateExecuting\n",__func__,__FILE__);
break;
case OMX_StatePause:
fprintf(stderr,"%s:%s:State changed OMX_StatePause\n",__func__,__FILE__);
break;
case OMX_StateWaitForResources:
fprintf(stderr,"%s:%s:State changed OMX_StateWaitForResources\n",__func__,__FILE__);
break;
}
// tsem_up(appPriv->decoderEventSem);
}
#if 0
else if(OMX_CommandPortEnable || OMX_CommandPortDisable)
{
fprintf(stderr, "In %s Received Port Enable/Disable Event\n",__func__);
// tsem_up(appPriv->decoderEventSem);
}
#endif
}
else if(eEvent == OMX_EventPortSettingsChanged)
{
fprintf(stderr, "\n port settings change event handler in %s \n", __func__);
if(Data2 == 0)
{
setPortParameters();
}
}
else if(eEvent == OMX_EventBufferFlag) {
fprintf(stderr,"Buffer Event\n");
}

return OMX_ErrorNone;
}

int setPortParameters()
{

OMX_ERRORTYPE eError = OMX_ErrorNone;

fprintf(stderr,"%s:%s\n",__FILE__,__func__);
paramPort.nPortIndex = 1;
setHeader(&paramPort, sizeof(OMX_PARAM_PORTDEFINITIONTYPE));
eError = OMX_GetParameter(appPriv->videodechandle, OMX_IndexParamPortDefinition, &paramPort);
new_out_width = paramPort.format.video.nFrameWidth;
new_out_height = paramPort.format.video.nFrameHeight;
fprintf(stderr, "input picture width : %d height : %d \n", (int)new_out_width, (int)new_out_height);

return eError;
}

OMX_ERRORTYPE videodecEmptyBufferDone( OMX_OUT OMX_HANDLETYPE hComponent,OMX_OUT OMX_PTR pAppData, OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer)
{

fprintf(stderr,"%s:%s",__func__,__FILE__);
return OMX_ErrorNone;
}

OMX_ERRORTYPE videodecFillBufferDone(OMX_OUT OMX_HANDLETYPE hComponent,OMX_OUT OMX_PTR pAppData, OMX_OUT OMX_BUFFERHEADERTYPE* pBuffer)
{
fprintf(stderr,"%s:%s",__func__,__FILE__);
return OMX_ErrorNone;

}

rnixon
06-16-2010, 04:44 PM
But after OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateIdle, 0)
The same component is not moving to OMX_StateIdle.
The component will only move to idle once all its (enabled) ports are populated.


Also OMX_AllocateBuffer is failing.
What's the error that's being returned?

rnixon
06-16-2010, 04:53 PM
OMX_STATETYPE eState;
OMX_GetState(appPriv->videodechandle, &eState);
GetState(eState);
eError = OMX_SendCommand(appPriv->videodechandle, OMX_CommandStateSet, OMX_StateIdle, 0); //step 4 Send state change command to OMX component to OMX_StateIdle
check_err(eError,"OMX_SendCommand OMX_StateIdle");
OMX_GetState(appPriv->videodechandle, &eState);
GetState(eState);
The OMX_GetState() calls around the OMX_SendCommand() call may indicate that you think that the state will change during the call. This is not guaranteed, as OMX_SendCommand() is defined as asynhronous - a callback will be received when the command completes. Depending upon the implementation, in general, this may or may not be before you return from OMX_SendCommand().

As you haven't disabled the component's ports, you're guaranteed that the state will still be idle after the above call to OMX_SendCommand(), as the ports are not yet populated.

him7403
10-13-2011, 12:55 AM
Its because of the state is not changing to idle.

I think you are getting the error: 80001000, Insufficient Resources.

With Android app, it doesn't have the system privilege. So it doesn't get the resources as it needs.

I am looking for a solution. how to use omx with android?