Home | History | Annotate | Download | only in include
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 #ifndef PV_OMXCORE_H_INCLUDED
     19 #define PV_OMXCORE_H_INCLUDED
     20 
     21 #ifndef PV_OMXDEFS_H_INCLUDED
     22 #include "pv_omxdefs.h"
     23 #endif
     24 
     25 #ifndef PV_OMX_QUEUE_H_INCLUDED
     26 #include "pv_omx_queue.h"
     27 #endif
     28 
     29 #ifndef OMX_Types_h
     30 #include "OMX_Types.h"
     31 #endif
     32 
     33 #ifndef OSCL_BASE_INCLUDED_H
     34 #include "oscl_base.h"
     35 #endif
     36 
     37 #ifndef OSCL_UUID_H_INCLUDED
     38 #include "oscl_uuid.h"
     39 #endif
     40 
     41 
     42 #ifndef OMX_Core_h
     43 #include "OMX_Core.h"
     44 #endif
     45 
     46 #ifndef OMX_Component_h
     47 #include "OMX_Component.h"
     48 #endif
     49 
     50 #if PROXY_INTERFACE
     51 #ifndef OMX_PROXY_INTERFACE_H_INCLUDED
     52 #include "omx_proxy_interface.h"
     53 #endif
     54 #endif
     55 
     56 #ifndef USE_CML2_CONFIG
     57 
     58 
     59 #ifdef ANDROID
     60 
     61 // NOTE: if at least one component uses dynamic loading,
     62 // USE_DYNAMIC_LOAD_OMX_COMPONENT needs to be 1
     63 #define USE_DYNAMIC_LOAD_OMX_COMPONENTS 0
     64 
     65 #define DYNAMIC_LOAD_OMX_AVC_COMPONENT 0
     66 #define DYNAMIC_LOAD_OMX_M4V_COMPONENT 0
     67 #define DYNAMIC_LOAD_OMX_H263_COMPONENT 0
     68 #define DYNAMIC_LOAD_OMX_WMV_COMPONENT 0
     69 #define DYNAMIC_LOAD_OMX_AAC_COMPONENT 0
     70 #define DYNAMIC_LOAD_OMX_AMR_COMPONENT 0
     71 #define DYNAMIC_LOAD_OMX_MP3_COMPONENT 0
     72 #define DYNAMIC_LOAD_OMX_WMA_COMPONENT 0
     73 
     74 #define DYNAMIC_LOAD_OMX_AMRENC_COMPONENT 0
     75 #define DYNAMIC_LOAD_OMX_M4VENC_COMPONENT 0
     76 #define DYNAMIC_LOAD_OMX_H263ENC_COMPONENT 0
     77 #define DYNAMIC_LOAD_OMX_AVCENC_COMPONENT 0
     78 #define DYNAMIC_LOAD_OMX_AACENC_COMPONENT 0
     79 
     80 #else
     81 
     82 #define USE_DYNAMIC_LOAD_OMX_COMPONENTS 0
     83 
     84 #define DYNAMIC_LOAD_OMX_AVC_COMPONENT 0
     85 #define DYNAMIC_LOAD_OMX_M4V_COMPONENT 0
     86 #define DYNAMIC_LOAD_OMX_H263_COMPONENT 0
     87 #define DYNAMIC_LOAD_OMX_WMV_COMPONENT 0
     88 #define DYNAMIC_LOAD_OMX_AAC_COMPONENT 0
     89 #define DYNAMIC_LOAD_OMX_AMR_COMPONENT 0
     90 #define DYNAMIC_LOAD_OMX_MP3_COMPONENT 0
     91 #define DYNAMIC_LOAD_OMX_WMA_COMPONENT 0
     92 
     93 #define DYNAMIC_LOAD_OMX_AMRENC_COMPONENT 0
     94 #define DYNAMIC_LOAD_OMX_M4VENC_COMPONENT 0
     95 #define DYNAMIC_LOAD_OMX_H263ENC_COMPONENT 0
     96 #define DYNAMIC_LOAD_OMX_AVCENC_COMPONENT 0
     97 #define DYNAMIC_LOAD_OMX_AACENC_COMPONENT 0
     98 
     99 #endif
    100 #endif
    101 
    102 #if USE_DYNAMIC_LOAD_OMX_COMPONENTS
    103 #ifndef OSCL_SHARED_LIBRARY_H_INCLUDED
    104 #include "oscl_shared_library.h"
    105 #endif
    106 #endif
    107 
    108 #define MAX_ROLES_SUPPORTED 3
    109 
    110 #ifdef __cplusplus
    111 extern "C"
    112 {
    113 #endif
    114 
    115     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_GetComponentsOfRole(
    116         OMX_IN      OMX_STRING role,
    117         OMX_INOUT   OMX_U32 *pNumComps,
    118         OMX_INOUT   OMX_U8  **compNames);
    119 
    120     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_APIENTRY OMX_ComponentNameEnum(
    121         OMX_OUT OMX_STRING cComponentName,
    122         OMX_IN  OMX_U32 nNameLength,
    123         OMX_IN  OMX_U32 nIndex);
    124 
    125     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_APIENTRY OMX_FreeHandle(OMX_IN OMX_HANDLETYPE hComponent);
    126 
    127     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_APIENTRY OMX_GetHandle(OMX_OUT OMX_HANDLETYPE* pHandle,
    128             OMX_IN  OMX_STRING cComponentName,
    129             OMX_IN  OMX_PTR pAppData,
    130             OMX_IN  OMX_CALLBACKTYPE* pCallBacks);
    131 
    132     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_GetRolesOfComponent(
    133         OMX_IN      OMX_STRING compName,
    134         OMX_INOUT   OMX_U32* pNumRoles,
    135         OMX_OUT     OMX_U8** roles);
    136 
    137     OSCL_IMPORT_REF  OMX_ERRORTYPE OMX_SetupTunnel(
    138         OMX_IN  OMX_HANDLETYPE hOutput,
    139         OMX_IN  OMX_U32 nPortOutput,
    140         OMX_IN  OMX_HANDLETYPE hInput,
    141         OMX_IN  OMX_U32 nPortInput);
    142 
    143     OSCL_IMPORT_REF OMX_ERRORTYPE   OMX_GetContentPipe(
    144         OMX_OUT  OMX_HANDLETYPE *hPipe,
    145         OMX_IN   OMX_STRING szURI);
    146 
    147     OSCL_IMPORT_REF OMX_BOOL OMXConfigParser(
    148         OMX_PTR aInputParameters,
    149         OMX_PTR aOutputParameters);
    150 
    151 
    152 #ifdef __cplusplus
    153 }
    154 #endif
    155 
    156 
    157 
    158 #if USE_DYNAMIC_LOAD_OMX_COMPONENTS
    159 //Dynamic loading interface definitions
    160 #define PV_OMX_SHARED_INTERFACE OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x67)
    161 #define PV_OMX_CREATE_INTERFACE OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x68)
    162 #define PV_OMX_DESTROY_INTERFACE OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x69)
    163 #define PV_OMX_AVCDEC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x6a)
    164 #define PV_OMX_M4VDEC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x6b)
    165 #define PV_OMX_H263DEC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x6c)
    166 #define PV_OMX_WMVDEC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x6d)
    167 #define PV_OMX_AACDEC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x6e)
    168 #define PV_OMX_AMRDEC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x6f)
    169 #define PV_OMX_MP3DEC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x70)
    170 #define PV_OMX_WMADEC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x71)
    171 #define PV_OMX_AVCENC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x72)
    172 #define PV_OMX_M4VENC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x73)
    173 #define PV_OMX_H263ENC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x74)
    174 #define PV_OMX_AMRENC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x75)
    175 #define PV_OMX_AACENC_UUID OsclUuid(0x1d4769f0,0xca0c,0x11dc,0x95,0xff,0x08,0x00,0x20,0x0c,0x9a,0x76)
    176 
    177 #define OMX_MAX_LIB_PATH 256
    178 
    179 class OmxSharedLibraryInterface
    180 {
    181     public:
    182         virtual OsclAny *QueryOmxComponentInterface(const OsclUuid& aOmxTypeId, const OsclUuid& aInterfaceId) = 0;
    183         virtual ~OmxSharedLibraryInterface() {}
    184 };
    185 #endif // USE_DYNAMIC_LOAD_OMX_COMPONENTS
    186 
    187 // PV additions to OMX_EXTRADATATYPE enum
    188 #define OMX_ExtraDataNALSizeArray 0x7F123321 // random value above 0x7F000000 (start of the unused range for vendors)
    189 
    190 class ComponentRegistrationType
    191 {
    192     public:
    193         // name of the component used as identifier
    194         OMX_STRING      ComponentName;
    195         OMX_STRING      RoleString[MAX_ROLES_SUPPORTED];
    196         OMX_U32         NumberOfRolesSupported;
    197         // pointer to factory function to be called when component needs to be instantiated
    198         OMX_ERRORTYPE(*FunctionPtrCreateComponent)(OMX_OUT OMX_HANDLETYPE* pHandle, OMX_IN  OMX_PTR pAppData,
    199                 OMX_PTR pProxy, OMX_STRING aOmxLibName, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount);
    200         // pointer to function that destroys the component and its AO
    201         OMX_ERRORTYPE(*FunctionPtrDestroyComponent)(OMX_IN OMX_HANDLETYPE pHandle, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount);
    202         //This function will return the role string
    203         void GetRolesOfComponent(OMX_STRING* aRole_string)
    204         {
    205             for (OMX_U32 ii = 0; ii < NumberOfRolesSupported; ii++)
    206             {
    207                 aRole_string[ii] = RoleString[ii];
    208             }
    209         }
    210 
    211         // for dynamic loading
    212         OMX_STRING             SharedLibraryName;
    213         OMX_PTR                SharedLibraryPtr;
    214         OMX_PTR                SharedLibraryOsclUuid;
    215         OMX_U32                SharedLibraryRefCounter;
    216 
    217 };
    218 
    219 typedef struct CoreDescriptorType
    220 {
    221     QueueType* pMessageQueue; // The output queue for the messages to be send to the components
    222 } CoreDescriptorType;
    223 
    224 
    225 /** This structure contains all the fields of a message handled by the core */
    226 struct CoreMessage
    227 {
    228     OMX_COMPONENTTYPE* pComponent; /// A reference to the main structure that defines a component. It represents the target of the message
    229     OMX_S32 MessageType; /// the flag that specifies if the message is a command, a warning or an error
    230     OMX_S32 MessageParam1; /// the first field of the message. Its use is the same as specified for the command in OpenMAX spec
    231     OMX_S32 MessageParam2; /// the second field of the message. Its use is the same as specified for the command in OpenMAX spec
    232     OMX_PTR pCmdData; /// This pointer could contain some proprietary data not covered by the standard
    233 };
    234 
    235 typedef struct PV_OMXComponentCapabilityFlagsType
    236 {
    237     ////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS
    238     OMX_BOOL iIsOMXComponentMultiThreaded;
    239     OMX_BOOL iOMXComponentSupportsExternalOutputBufferAlloc;
    240     OMX_BOOL iOMXComponentSupportsExternalInputBufferAlloc;
    241     OMX_BOOL iOMXComponentSupportsMovableInputBuffers;
    242     OMX_BOOL iOMXComponentSupportsPartialFrames;
    243     OMX_BOOL iOMXComponentUsesNALStartCodes;
    244     OMX_BOOL iOMXComponentCanHandleIncompleteFrames;
    245     OMX_BOOL iOMXComponentUsesFullAVCFrames;
    246 
    247 } PV_OMXComponentCapabilityFlagsType;
    248 
    249 class OMXGlobalData
    250 {
    251     public:
    252         OMXGlobalData()
    253                 : iInstanceCount(1),
    254                 iOsclInit(false),
    255                 iNumBaseInstance(0),
    256                 iComponentIndex(0)
    257         {
    258             for (OMX_S32 ii = 0; ii < MAX_INSTANTIATED_COMPONENTS; ii++)
    259             {
    260                 ipInstantiatedComponentReg[ii] = NULL;
    261             }
    262         }
    263 
    264         uint32 iInstanceCount;
    265 
    266         bool iOsclInit; //did we do OsclInit in OMX_Init?  if so we must cleanup in OMX_Deinit.
    267 
    268 
    269         //Number of base instances
    270         OMX_U32 iNumBaseInstance;
    271 
    272         // Array to store component handles for future recognition of components etc.
    273         OMX_HANDLETYPE iComponentHandle[MAX_INSTANTIATED_COMPONENTS];
    274         OMX_U32 iComponentIndex;
    275 
    276         // Array of supported component types (e.g. MP4, AVC, AAC, etc.)
    277         // they need to be registered
    278         // For each OMX Component type (e.g. Mp3, AVC, AAC) there is one entry in this table that contains info
    279         // such as component type, factory, destructor functions, library name for dynamic loading etc.
    280         // when the omx component is registered (at OMX_Init)
    281         ComponentRegistrationType* ipRegTemplateList[MAX_SUPPORTED_COMPONENTS];
    282 
    283 
    284         // Array of pointers - For each OMX component that gets instantiated - the pointer to its registry structure
    285         // is saved here. This information is needed when the component is to be destroyed
    286 
    287         ComponentRegistrationType* ipInstantiatedComponentReg[MAX_INSTANTIATED_COMPONENTS];
    288         // array of function pointers. For each component, a destructor function is assigned
    289         //OMX_ERRORTYPE(*ComponentDestructor[MAX_INSTANTIATED_COMPONENTS])(OMX_IN OMX_HANDLETYPE pHandle, OMX_PTR &aOmxLib, OMX_PTR aOsclUuid, OMX_U32 &aRefCount);
    290 
    291 #if PROXY_INTERFACE
    292         ProxyApplication_OMX* ipProxyTerm[MAX_INSTANTIATED_COMPONENTS];
    293 #endif
    294 
    295 };
    296 
    297     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_MasterInit();
    298     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_MasterDeinit();
    299 
    300     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_MasterGetComponentsOfRole(
    301         OMX_IN          OMX_STRING role,
    302         OMX_INOUT       OMX_U32 *pNumComps,
    303         OMX_INOUT       OMX_U8 **compNames);
    304 
    305     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_APIENTRY OMX_MasterComponentNameEnum(
    306         OMX_OUT OMX_STRING cComponentName,
    307         OMX_IN  OMX_U32 nNameLength,
    308         OMX_IN  OMX_U32 nIndex);
    309 
    310     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_APIENTRY OMX_MasterFreeHandle(OMX_IN OMX_HANDLETYPE hComponent);
    311 
    312     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_APIENTRY OMX_MasterGetHandle(OMX_OUT OMX_HANDLETYPE* pHandle,
    313             OMX_IN  OMX_STRING cComponentName,
    314             OMX_IN  OMX_PTR pAppData,
    315             OMX_IN  OMX_CALLBACKTYPE* pCallBacks,
    316             OMX_IN  OMX_BOOL bHWAccelerated = OMX_TRUE);
    317 
    318     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_MasterGetRolesOfComponent(
    319         OMX_IN      OMX_STRING compName,
    320         OMX_INOUT   OMX_U32* pNumRoles,
    321         OMX_OUT     OMX_U8** roles);
    322 
    323     OSCL_IMPORT_REF OMX_BOOL OMX_MasterConfigParser(
    324         OMX_PTR aInputParameters,
    325         OMX_PTR aOutputParameters);
    326 
    327     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_MasterSetupTunnel(
    328          OMX_IN  OMX_HANDLETYPE hOutput,
    329          OMX_IN  OMX_U32 nPortOutput,
    330          OMX_IN  OMX_HANDLETYPE hInput,
    331          OMX_IN  OMX_U32 nPortInput);
    332 
    333     OSCL_IMPORT_REF OMX_ERRORTYPE OMX_MasterGetContentPipe(
    334          OMX_OUT OMX_HANDLETYPE *hPipe,
    335          OMX_IN OMX_STRING szURI);
    336 
    337 #endif
    338