OSDN Git Service

RIO-8910: Fix for MP3 parser returning incorrect value for bitrate key
[android-x86/external-opencore.git] / android / extension_handler_registry.cpp
1 //#define LOG_NDEBUG 0
2 #define LOG_TAG "RegistryLoader"
3 #include <utils/Log.h>
4
5 #include "extension_handler_registry.h"
6 #include "PVPlayerExtHandler.h"
7
8 #include "oscl_shared_library.h"
9 #include "oscl_library_list.h"
10 #include "oscl_configfile_list.h"
11 #include "osclconfig_lib.h"
12 #include "oscl_shared_lib_interface.h"
13
14
15 PVPlayerExtensionRegistry::PVPlayerExtensionRegistry()
16 {
17     // The default value reserved is 4
18     mType.reserve(4);
19     LOGV("PVPlayerExtensionRegistry::PVPlayerExtensionRegistry OUT");
20 }
21
22 PVPlayerExtensionRegistry::~PVPlayerExtensionRegistry()
23 {
24     mType.clear();
25     LOGV("PVPlayerExtensionRegistry::~PVPlayerExtensionRegistry OUT");
26 }
27
28 void PVPlayerExtensionRegistry::loadPVPlayerExtensions(const OSCL_String& configFilePath)
29 {
30     LOGV("PVPlayerExtensionRegistry::loadPVPlayerExtensions() IN");
31     OsclLibraryList libList;
32     libList.Populate(PV_EXTN_REGISTRY_POPULATOR_INTERFACE, configFilePath);
33
34     for (unsigned int i = 0; i < libList.Size(); i++)
35     {
36         OsclSharedLibrary* lib = OSCL_NEW(OsclSharedLibrary, ());
37         if (lib->LoadLib(libList.GetLibraryPathAt(i)) == OsclLibSuccess) {
38             OsclAny* interfacePtr = NULL;
39             OsclLibStatus result = lib->QueryInterface(PV_EXTN_REGISTRY_POPULATOR_INTERFACE, (OsclAny*&)interfacePtr);
40             if (result == OsclLibSuccess && interfacePtr != NULL) {
41                 PVPlayerExtnSharedLibInfo *libInfo = (PVPlayerExtnSharedLibInfo *)oscl_malloc(sizeof(PVPlayerExtnSharedLibInfo));
42                 if (NULL != libInfo) {
43                     libInfo->mLib = lib;
44                     ExtnRegPopulatorInterface* extnIntPtr = OSCL_DYNAMIC_CAST(ExtnRegPopulatorInterface*, interfacePtr);
45                     libInfo->mExtnLibIfacePtr = extnIntPtr;
46                     extnIntPtr->registerExtensions(this);
47                     // save for depopulation later
48                     mExtnIfaceInfoList.push_front(libInfo);
49                     continue;
50                 }
51             } else {
52                 LOGV("PVPlayerExtensionRegistry::loadPVPlayerExtensions() QueryInterface() of PV_EXTNIFACE_REGISTRY_POPULATOR_INTERFACE for library %s failed.", libList.GetLibraryPathAt(i).get_cstr());
53             }
54         } else {
55             LOGV("PVPlayerExtensionRegistry::loadPVPlayerExtensions() LoadLib() of library %s failed.", libList.GetLibraryPathAt(i).get_cstr());
56         }
57         lib->Close();
58         OSCL_DELETE(lib);
59     }
60     LOGV("PVPlayerExtensionRegistry::loadPVPlayerExtensions() OUT");
61 }
62
63 void PVPlayerExtensionRegistry::removePVPlayerExtensions()
64 {
65     LOGV("PVPlayerExtensionRegistry::removePVPlayerExtensions() IN");
66
67     while (!mExtnIfaceInfoList.empty())
68     {
69         PVPlayerExtnSharedLibInfo *libInfo = mExtnIfaceInfoList.front();
70         mExtnIfaceInfoList.erase(mExtnIfaceInfoList.begin());
71
72         OsclSharedLibrary* lib = libInfo->mLib;
73         oscl_free(libInfo);
74         lib->Close();
75         OSCL_DELETE(lib);
76     }
77     LOGV("PVPlayerExtensionRegistry::removePVPlayerExtensions() OUT");
78 }
79
80 IDispatch* PVPlayerExtensionRegistry::createExtension(const String16& extnIfaceUID,PVPlayerExtensionHandler& extnHandler )
81 {
82     LOGV("PVPlayerExtensionRegistry::createExtension() IN");
83     bool foundFlag = false;
84     uint32 extnSearchCount = 0;
85
86     while (extnSearchCount < mType.size())
87     {
88         //Search if the UUID's will match
89         if (extnIfaceUID == (String16(mType[extnSearchCount].mExtnUID))) {
90             //Since the UUID's match set the flag to true
91             foundFlag = true;
92             break;
93         }
94         extnSearchCount++;
95     }
96     
97     if (foundFlag) {
98         PVPlayerExtnInfo* extnInfo = &mType[extnSearchCount];
99         IDispatch* extInterface = NULL;
100
101         if (NULL != extnInfo->mExtnCreateFunc) {
102             extInterface = (*(mType[extnSearchCount].mExtnCreateFunc))(extnHandler);
103         }
104         LOGV("PVPlayerExtensionRegistry::createExtension OUT extInterface = %d", (int32_t)extInterface);
105         return extInterface;
106     } else {
107         LOGV("PVPlayerExtensionRegistry::createExtension OUT");
108         return NULL;
109     }
110 }
111
112 void PVPlayerExtnPopulator::populate(PVPlayerExtensionRegistry& extnIfaceRegistry)
113 {
114     LOGV("PVPlayerExtnPopulator::populate IN");
115     OsclConfigFileList aCfgList;
116     // collects all config files from the project specified directory
117     if (NULL != PV_DYNAMIC_LOADING_CONFIG_FILE_PATH) {
118         OSCL_HeapString<OsclMemAllocator> configFilePath = PV_DYNAMIC_LOADING_CONFIG_FILE_PATH;
119         aCfgList.Populate(configFilePath);
120     }
121     // populate libraries from all config files
122     for (uint k = 0; k < aCfgList.Size(); k++)
123     {
124         extnIfaceRegistry.loadPVPlayerExtensions(aCfgList.GetConfigfileAt(k));
125     }
126     LOGV("PVPlayerExtnPopulator::populate OUT");
127 }
128 void PVPlayerExtnPopulator::depopulate(PVPlayerExtensionRegistry& extnIfaceRegistry)
129 {
130     extnIfaceRegistry.removePVPlayerExtensions();
131     LOGV("PVPlayerExtnPopulator::depopulate OUT");
132 }