Home | History | Annotate | Download | only in src
      1 #define LOG_TAG "omx_interface"
      2 #include <utils/Log.h>
      3 
      4 #include "pvlogger.h"
      5 
      6 #include "pv_omxcore.h"
      7 #include "omx_interface.h"
      8 
      9 // this is the name of the original SO that contains your OMX core
     10 #define OMX_CORE_LIBRARY "libOMX_Core.so"
     11 
     12 class TIOMXInterface : public OMXInterface
     13 {
     14     public:
     15         // Handle to the OMX core library
     16         void* ipHandle;
     17 
     18         ~TIOMXInterface()
     19         {
     20             if ((NULL != ipHandle) && (0 != dlclose(ipHandle)))
     21             {
     22                 // dlclose() returns non-zero value if close failed, check for errors
     23                 const char* pErr = dlerror();
     24                 if (NULL != pErr)
     25                 {
     26                     LOGE("TIOMXInterface: Error closing library: %s\n", pErr);
     27                 }
     28                 else
     29                 {
     30                     LOGE("OsclSharedLibrary::Close: Error closing library, no error reported");
     31                 }
     32             }
     33 
     34             ipHandle = NULL;
     35         };
     36 
     37         OsclAny* SharedLibraryLookup(const OsclUuid& aInterfaceId)
     38         {
     39             // Make sure ipHandle is valid. If ipHandle is NULL, the dlopen
     40             // call failed.
     41             if (ipHandle && aInterfaceId == OMX_INTERFACE_ID)
     42             {
     43                 LOGD("TIOMXInterface: library lookup success\n");
     44                 // the library lookup was successful
     45                 return this;
     46             }
     47             // the ID doesn't match
     48             LOGE("TIOMXInterface: library lookup failed\n");
     49             return NULL;
     50         };
     51 
     52         static TIOMXInterface* Instance()
     53         {
     54             LOGD("TIOMXInterface: creating interface\n");
     55             return OSCL_NEW(TIOMXInterface, ());
     56         };
     57 
     58         bool UnloadWhenNotUsed(void)
     59         {
     60             // As of 9/22/08, the PV OMX core library can not be
     61             // safely unloaded and reloaded when the proxy interface
     62             // is enabled.
     63             return false;
     64         };
     65 
     66     private:
     67 
     68         TIOMXInterface()
     69         {
     70             LOGD("Calling DLOPEN on OMX_CORE_LIBRARY (%s)\n", OMX_CORE_LIBRARY);
     71             ipHandle = dlopen(OMX_CORE_LIBRARY, RTLD_NOW);
     72 
     73             if (NULL == ipHandle)
     74             {
     75                 pOMX_Init = NULL;
     76                 pOMX_Deinit = NULL;
     77                 pOMX_ComponentNameEnum = NULL;
     78                 pOMX_GetHandle = NULL;
     79                 pOMX_FreeHandle = NULL;
     80                 pOMX_GetComponentsOfRole = NULL;
     81                 pOMX_GetRolesOfComponent = NULL;
     82                 pOMX_SetupTunnel = NULL;
     83                 pOMX_GetContentPipe = NULL;
     84                 // added extra method to enable config parsing without instantiating the component
     85                 pOMXConfigParser = NULL;
     86 
     87                 // check for errors
     88                 const char* pErr = dlerror();
     89                 if (NULL == pErr)
     90                 {
     91                     // No error reported, but no handle to the library
     92                     LOGE("OsclLib::LoadLibrary: Error opening "
     93                          "library (%s) but no error reported\n", OMX_CORE_LIBRARY);
     94                 }
     95                 else
     96                 {
     97                     // Error reported
     98                     LOGE("OsclLib::LoadLibrary: Error opening "
     99                          "library (%s): %s\n", OMX_CORE_LIBRARY, pErr);
    100                 }
    101             }
    102             else
    103             {
    104                 LOGD("DLOPEN SUCCEEDED (%s)\n", OMX_CORE_LIBRARY);
    105                 // Lookup all the symbols in the OMX core
    106                 pOMX_Init = (tpOMX_Init)dlsym(ipHandle, "TIOMX_Init");
    107                 pOMX_Deinit = (tpOMX_Deinit)dlsym(ipHandle, "TIOMX_Deinit");
    108                 pOMX_ComponentNameEnum = (tpOMX_ComponentNameEnum)dlsym(ipHandle, "TIOMX_ComponentNameEnum");
    109                 pOMX_GetHandle = (tpOMX_GetHandle)dlsym(ipHandle, "TIOMX_GetHandle");
    110                 pOMX_FreeHandle = (tpOMX_FreeHandle)dlsym(ipHandle, "TIOMX_FreeHandle");
    111                 pOMX_GetComponentsOfRole = (tpOMX_GetComponentsOfRole)dlsym(ipHandle, "TIOMX_GetComponentsOfRole");
    112                 pOMX_GetRolesOfComponent = (tpOMX_GetRolesOfComponent)dlsym(ipHandle, "TIOMX_GetRolesOfComponent");
    113                 pOMX_SetupTunnel = (tpOMX_SetupTunnel)dlsym(ipHandle, "TIOMX_SetupTunnel");
    114                 pOMXConfigParser = (tpOMXConfigParser)dlsym(ipHandle, "TIOMXConfigParserRedirect");
    115                 pOMX_GetContentPipe = NULL; // (tpOMX_GetContentPipe)dlsym(ipHandle, "OMX_GetContentPipe");
    116             }
    117         };
    118 
    119 };
    120 
    121 // function to obtain the interface object from the shared library
    122 extern "C"
    123 {
    124     OSCL_EXPORT_REF OsclAny* PVGetInterface()
    125     {
    126         return TIOMXInterface::Instance();
    127     }
    128 
    129     OSCL_EXPORT_REF void PVReleaseInterface(OsclSharedLibraryInterface* aInstance)
    130     {
    131         TIOMXInterface* instance = (TIOMXInterface*)aInstance;
    132         if (instance)
    133             OSCL_DELETE(instance);
    134     }
    135 }
    136 
    137