Skip to content

Instantly share code, notes, and snippets.

@jvcleave
Last active November 22, 2018 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jvcleave/b4546bebedcfd8671e3ff68f7696c2c8 to your computer and use it in GitHub Desktop.
Save jvcleave/b4546bebedcfd8671e3ff68f7696c2c8 to your computer and use it in GitHub Desktop.
image_fx test
/*
Copyright (c) 2012, Broadcom Europe Ltd
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// Video deocode demo using OpenMAX IL though the ilcient helper library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bcm_host.h"
#include "ilclient.h"
OMX_ERRORTYPE nullEmptyBufferDone(OMX_HANDLETYPE handle, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* header){return OMX_ErrorNone;};
OMX_ERRORTYPE nullFillBufferDone(OMX_HANDLETYPE handle, OMX_PTR ptr, OMX_BUFFERHEADERTYPE* header){return OMX_ErrorNone;};
OMX_ERRORTYPE nullEventHandler(OMX_HANDLETYPE handle, OMX_PTR ptr, OMX_EVENTTYPE eEvent, OMX_U32 nData1, OMX_U32 nData2, OMX_PTR pEventData){return OMX_ErrorNone;};
#define OMX_IMAGE_FX (OMX_STRING)"OMX.broadcom.image_fx"
#define IMAGE_FX_INPUT_PORT 190
#define IMAGE_FX_OUTPUT_PORT 191
#define OMX_INIT_STRUCTURE(a) \
memset(&(a), 0, sizeof(a)); \
(a).nSize = sizeof(a); \
(a).nVersion.s.nVersionMajor = OMX_VERSION_MAJOR; \
(a).nVersion.s.nVersionMinor = OMX_VERSION_MINOR; \
(a).nVersion.s.nRevision = OMX_VERSION_REVISION; \
(a).nVersion.s.nStep = OMX_VERSION_STEP
void PrintDef(OMX_PARAM_PORTDEFINITIONTYPE def)
{
printf("nPortIndex: %d \n", def.nPortIndex);
printf("eDir: %s \n", (def.eDir == OMX_DirInput ? "in" : "out"));
printf("nBufferCountActual: %d \n", def.nBufferCountActual);
printf("nBufferCountMin: %d \n", def.nBufferCountMin);
printf("nBufferSize: %d \n", (def.nBufferSize >> 16));
printf("nBufferAlignment: %d \n", def.nBufferAlignment);
printf("bEnabled: %d \n", def.bEnabled);
printf("bPopulated: %d \n", def.bPopulated);
printf("bBuffersContiguous: %d \n", def.bBuffersContiguous);
printf("bBuffersContiguous: %d \n", def.bBuffersContiguous);
if (def.eDomain == OMX_PortDomainVideo)
{
printf("eDomain: %s \n", "OMX_PortDomainVideo");
}else
{
printf("eDomain: %s \n", "OMX_PortDomainImage");
}
if (def.eDomain == OMX_PortDomainVideo)
{
printf("video nFrameWidth: %d \n", def.format.video.nFrameWidth);
printf("video nFrameHeight: %d \n", def.format.video.nFrameHeight);
printf("video nStride: %d \n", def.format.video.nStride);
printf("video nSliceHeight: %d \n", def.format.video.nSliceHeight);
printf("video xFramerate: %d \n", (def.format.video.xFramerate >> 16));
printf("video eCompressionFormat: %d \n", def.format.video.eCompressionFormat);
printf("video eColorFormat: %d \n", def.format.video.eColorFormat);
}
if (def.eDomain == OMX_PortDomainImage)
{
printf("image nFrameWidth: %d \n", def.format.image.nFrameWidth);
printf("image nFrameHeight: %d \n", def.format.image.nFrameHeight);
printf("image nStride: %d \n", def.format.image.nStride);
printf("image nSliceHeight: %d \n", def.format.image.nSliceHeight);
printf("image coding type: %d \n", def.format.image.eCompressionFormat);
printf("image eColorFormat: %d \n", def.format.image.eColorFormat);
}
}
void PrintError(OMX_ERRORTYPE error, int lineNumber)
{
printf("ERROR LINE: %d \n", lineNumber);
switch (error)
{
case OMX_ErrorNone: { printf("OMX_ErrorNone \n "); break;}
case OMX_ErrorInsufficientResources: { printf("OMX_ErrorInsufficientResources \n "); break;}
case OMX_ErrorUndefined: { printf("OMX_ErrorUndefined \n "); break;}
case OMX_ErrorInvalidComponentName: { printf("OMX_ErrorInvalidComponentName \n "); break;}
case OMX_ErrorComponentNotFound: { printf("OMX_ErrorComponentNotFound \n "); break;}
case OMX_ErrorInvalidComponent: { printf("OMX_ErrorInvalidComponent \n "); break;}
case OMX_ErrorBadParameter: { printf("OMX_ErrorBadParameter \n "); break;}
case OMX_ErrorNotImplemented: { printf("OMX_ErrorNotImplemented \n "); break;}
case OMX_ErrorUnderflow: { printf("OMX_ErrorUnderflow \n "); break;}
case OMX_ErrorOverflow: { printf("OMX_ErrorOverflow \n "); break;}
case OMX_ErrorHardware: { printf("OMX_ErrorHardware \n "); break;}
case OMX_ErrorInvalidState: { printf("OMX_ErrorInvalidState \n "); break;}
case OMX_ErrorStreamCorrupt: { printf("OMX_ErrorStreamCorrupt \n "); break;}
case OMX_ErrorPortsNotCompatible: { printf("OMX_ErrorPortsNotCompatible \n "); break;}
case OMX_ErrorResourcesLost: { printf("OMX_ErrorResourcesLost \n "); break;}
case OMX_ErrorNoMore: { printf("OMX_ErrorNoMore \n "); break;}
case OMX_ErrorVersionMismatch: { printf("OMX_ErrorVersionMismatch \n "); break;}
case OMX_ErrorNotReady: { printf("OMX_ErrorNotReady \n "); break;}
case OMX_ErrorTimeout: { printf("OMX_ErrorTimeout \n "); break;}
case OMX_ErrorSameState: { printf("OMX_ErrorSameState \n "); break;}
case OMX_ErrorResourcesPreempted: { printf("OMX_ErrorResourcesPreempted \n "); break;}
case OMX_ErrorPortUnresponsiveDuringAllocation: { printf("OMX_ErrorPortUnresponsiveDuringAllocation \n "); break;}
case OMX_ErrorPortUnresponsiveDuringDeallocation: { printf("OMX_ErrorPortUnresponsiveDuringDeallocation \n "); break;}
case OMX_ErrorPortUnresponsiveDuringStop: { printf("OMX_ErrorPortUnresponsiveDuringStop \n "); break;}
case OMX_ErrorIncorrectStateTransition: { printf("OMX_ErrorIncorrectStateTransition \n "); break;}
case OMX_ErrorIncorrectStateOperation: { printf("OMX_ErrorIncorrectStateOperation \n "); break;}
case OMX_ErrorUnsupportedSetting: { printf("OMX_ErrorUnsupportedSetting \n "); break;}
case OMX_ErrorUnsupportedIndex: { printf("OMX_ErrorUnsupportedIndex \n "); break;}
case OMX_ErrorBadPortIndex: { printf("OMX_ErrorBadPortIndex \n "); break;}
case OMX_ErrorPortUnpopulated: { printf("OMX_ErrorPortUnpopulated \n "); break;}
case OMX_ErrorComponentSuspended: { printf("OMX_ErrorComponentSuspended \n "); break;}
case OMX_ErrorDynamicResourcesUnavailable: { printf("OMX_ErrorDynamicResourcesUnavailable \n "); break;}
case OMX_ErrorMbErrorsInFrame: { printf("OMX_ErrorMbErrorsInFrame \n "); break;}
case OMX_ErrorFormatNotDetected: { printf("OMX_ErrorFormatNotDetected \n "); break;}
case OMX_ErrorContentPipeOpenFailed: { printf("OMX_ErrorContentPipeOpenFailed \n "); break;}
case OMX_ErrorContentPipeCreationFailed: { printf("OMX_ErrorContentPipeCreationFailed \n "); break;}
case OMX_ErrorSeperateTablesUsed: { printf("OMX_ErrorSeperateTablesUsed \n "); break;}
case OMX_ErrorTunnelingUnsupported: { printf("OMX_ErrorTunnelingUnsupported \n "); break;}
case OMX_ErrorKhronosExtensions: { printf("OMX_ErrorKhronosExtensions \n "); break;}
case OMX_ErrorVendorStartUnused: { printf("OMX_ErrorVendorStartUnused \n "); break;}
case OMX_ErrorDiskFull: { printf("OMX_ErrorDiskFull \n "); break;}
case OMX_ErrorMaxFileSize: { printf("OMX_ErrorMaxFileSize \n "); break;}
case OMX_ErrorDrmUnauthorised: { printf("OMX_ErrorDrmUnauthorised \n "); break;}
case OMX_ErrorDrmExpired: { printf("OMX_ErrorDrmExpired \n "); break;}
case OMX_ErrorDrmGeneral: { printf("OMX_ErrorDrmGeneral \n "); break;}
default:
break;
}
}
int image_fx_test()
{
OMX_ERRORTYPE error = OMX_ErrorNone;
OMX_CALLBACKTYPE imageFXCallbacks;
imageFXCallbacks.EventHandler = &nullEventHandler;
imageFXCallbacks.EmptyBufferDone = &nullEmptyBufferDone;
imageFXCallbacks.FillBufferDone = &nullFillBufferDone;
OMX_HANDLETYPE imageFX;
error = OMX_GetHandle(&imageFX, OMX_IMAGE_FX, NULL, &imageFXCallbacks);
OMX_INDEXTYPE indexTypes[] =
{
OMX_IndexParamAudioInit,
OMX_IndexParamImageInit,
OMX_IndexParamVideoInit,
OMX_IndexParamOtherInit
};
OMX_PORT_PARAM_TYPE ports;
OMX_INIT_STRUCTURE(ports);
for(int i=0; i < 4; i++)
{
error = OMX_GetParameter(imageFX, indexTypes[i], &ports);
if(error == OMX_ErrorNone)
{
uint32_t j;
for(j=0; j<ports.nPorts; j++)
{
OMX_PARAM_PORTDEFINITIONTYPE portFormat;
OMX_INIT_STRUCTURE(portFormat);
portFormat.nPortIndex = ports.nStartPortNumber+j;
error = OMX_GetParameter(imageFX, OMX_IndexParamPortDefinition, &portFormat);
if(error != OMX_ErrorNone)
{
if(portFormat.bEnabled == OMX_FALSE)
{
continue;
}
}
error = OMX_SendCommand(imageFX, OMX_CommandPortDisable, ports.nStartPortNumber+j, NULL);
printf("PORT #: %d DISABLED\n", ports.nStartPortNumber+j);
}
}
}
error = OMX_SendCommand(imageFX, OMX_CommandStateSet, OMX_StateIdle, NULL);
int ready = 0;
int numAttempts = 0;
while (!ready)
{
OMX_STATETYPE currentState;
error = OMX_GetState(imageFX, &currentState);
if(currentState == OMX_StateIdle)
{
ready = 1;
break;
}else
{
error = OMX_SendCommand(imageFX, OMX_CommandStateSet, OMX_StateIdle, NULL);
}
numAttempts++;
printf("ATTEMPT #: %d \n", numAttempts);
sleep(1);
if(numAttempts >= 10)
{
ready = 1;
printf("TIMED OUT SETTING STATE OMX_StateIdle: %d \n", numAttempts);
}
}
printf("imageFX is OMX_StateIdle: %d \n", numAttempts);
OMX_PARAM_PORTDEFINITIONTYPE def;
OMX_INIT_STRUCTURE(def);
def.nPortIndex = IMAGE_FX_INPUT_PORT;
error = OMX_GetParameter(imageFX, OMX_IndexParamPortDefinition, &def);
PrintError(error, __LINE__);
printf("\n\n INITIAL DEFINITION: \n\n");
PrintDef(def);
def.eDomain = OMX_PortDomainVideo;
error = OMX_SetParameter(imageFX, OMX_IndexParamPortDefinition, &def);
PrintError(error, __LINE__);
error = OMX_GetParameter(imageFX, OMX_IndexParamPortDefinition, &def);
PrintError(error, __LINE__);
printf("\n\n RESULT DEFINITION: \n\n");
PrintDef(def);
return 0;
}
int main (int argc, char **argv)
{
int result = 0;
bcm_host_init();
OMX_Init();
result = image_fx_test();
OMX_Deinit();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment