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 #include "pvmf_protocol_engine_node_registry.h"
19 #include "pvmf_protocol_engine_node_common.h"
20
21
22
23 #if (BUILD_PROGRESSIVE_DOWNLOAD_PLUGIN)
24 #include "pvmf_protocol_engine_node_progressive_download_container_factory.h"
25 #endif
26
27 #if(BUILD_PROGRESSIVE_STREAMING_PLUGIN)
28 #include "pvmf_protocol_engine_node_progressive_streaming_container_factory.h"
29 #endif
30
31 #if(BUILD_SHOUTCAST_PLUGIN)
32 #include "pvmf_protocol_engine_node_shoutcast_container_factory.h"
33 #endif
34
35 #if(BUILD_FASTTRACK_DOWNLOAD_PLUGIN)
36 #include "pvmf_protocol_engine_node_fasttrack_download_container_factory.h"
37 #endif
38
39 #if(BUILD_WMHTTPSTREAMING_PLUGIN)
40 #include "pvmf_protocol_engine_node_wm_http_streaming_container_factory.h"
41 #endif
42
43 #ifdef USE_LOADABLE_MODULES
44 #include "oscl_shared_library.h"
45 #include "oscl_library_list.h"
46 #include "oscl_configfile_list.h"
47 #include "osclconfig_lib.h"
48 #include "oscl_shared_lib_interface.h"
49 #endif //USE_LOADABLE_MODULES
50
51
52 #define DEFAULT_NODE_REGISTRY_RESERVED_NUMBER 16
53 #define PROGRESSIVE_STREAMING_TYPE_BIT 1
54
55
PVMFProtocolEngineNodeRegistry()56 PVMFProtocolEngineNodeRegistry::PVMFProtocolEngineNodeRegistry() : iTypeVecIndex(0xFFFFFFFF)
57 {
58 PVMFProtocolEngineContainerInfo aContainerInfo;
59 iTypeVec.reserve(DEFAULT_NODE_REGISTRY_RESERVED_NUMBER);
60
61 #if(BUILD_PROGRESSIVE_DOWNLOAD_PLUGIN)
62 aContainerInfo.iSourceType = PVMF_MIME_DATA_SOURCE_HTTP_URL;
63 aContainerInfo.iProtocolEngineContainerUUID = KPVMFProtocolEngineNodeProgressiveDownloadUuid;
64 aContainerInfo.iProtocolEngineContainerCreateFunc = PVMFProtocolEngineNodeProgressiveDownloadContainerFactory::Create;
65 aContainerInfo.iProtocolEngineContainerReleaseFunc = PVMFProtocolEngineNodeProgressiveDownloadContainerFactory::Delete;
66 iTypeVec.push_back(aContainerInfo);
67 aContainerInfo.clear();
68 #endif
69
70 #if(BUILD_PROGRESSIVE_STREAMING_PLUGIN)
71 aContainerInfo.iSourceType = PVMF_MIME_DATA_SOURCE_HTTP_URL;
72 aContainerInfo.iSourceExtraInfo = PROGRESSIVE_STREAMING_TYPE_BIT;
73 aContainerInfo.iProtocolEngineContainerUUID = KPVMFProtocolEngineNodeProgressiveStreamingUuid;
74 aContainerInfo.iProtocolEngineContainerCreateFunc = PVMFProtocolEngineNodeProgressiveStreamingContainerFactory::Create;
75 aContainerInfo.iProtocolEngineContainerReleaseFunc = PVMFProtocolEngineNodeProgressiveStreamingContainerFactory::Delete;
76 iTypeVec.push_back(aContainerInfo);
77 aContainerInfo.clear();
78 #endif
79
80 #if(BUILD_SHOUTCAST_PLUGIN)
81 aContainerInfo.iSourceType = PVMF_MIME_DATA_SOURCE_SHOUTCAST_URL;
82 aContainerInfo.iProtocolEngineContainerUUID = KPVMFProtocolEngineNodeShoutcastUuid;
83 aContainerInfo.iProtocolEngineContainerCreateFunc = PVMFProtocolEngineNodeShoutcastContainerFactory::Create;
84 aContainerInfo.iProtocolEngineContainerReleaseFunc = PVMFProtocolEngineNodeShoutcastContainerFactory::Delete;
85 iTypeVec.push_back(aContainerInfo);
86 aContainerInfo.clear();
87 #endif
88
89 #if(BUILD_FASTTRACK_DOWNLOAD_PLUGIN)
90 aContainerInfo.iSourceType = PVMF_MIME_DATA_SOURCE_PVX_FILE;
91 aContainerInfo.iProtocolEngineContainerUUID = KPVMFProtocolEngineNodeFasttrackDownloadContainerUuid;
92 aContainerInfo.iProtocolEngineContainerCreateFunc = PVMFProtocolEngineNodeFasttrackDownloadContainerFactory::Create;
93 aContainerInfo.iProtocolEngineContainerReleaseFunc = PVMFProtocolEngineNodeFasttrackDownloadContainerFactory::Delete;
94 iTypeVec.push_back(aContainerInfo);
95 aContainerInfo.clear();
96 #endif
97
98 #if(BUILD_WMHTTPSTREAMING_PLUGIN)
99 aContainerInfo.iSourceType = PVMF_MIME_DATA_SOURCE_MS_HTTP_STREAMING_URL;
100 aContainerInfo.iProtocolEngineContainerUUID = KPVMFProtocolEngineNodeWMHttpStreamingUuid;
101 aContainerInfo.iProtocolEngineContainerCreateFunc = PVMFProtocolEngineNodeWMHttpStreamingContainerFactory::Create;
102 aContainerInfo.iProtocolEngineContainerReleaseFunc = PVMFProtocolEngineNodeWMHttpStreamingContainerFactory::Delete;
103 iTypeVec.push_back(aContainerInfo);
104 #endif
105
106 iLogger = PVLogger::GetLoggerObject("PVMFProtocolEngineNode");;
107 }
108
109
~PVMFProtocolEngineNodeRegistry()110 PVMFProtocolEngineNodeRegistry::~PVMFProtocolEngineNodeRegistry()
111 {
112 iTypeVec.clear();
113 RemoveLoadableModules();
114 }
115
CheckPluginAvailability(PVMFFormatType & aSourceFormat,OsclAny * aSourceData)116 bool PVMFProtocolEngineNodeRegistry::CheckPluginAvailability(PVMFFormatType& aSourceFormat, OsclAny* aSourceData)
117 {
118 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::CheckPluginAvailability() IN"));
119
120 PVMFFormatType aSourceType = aSourceFormat;
121 if (aSourceFormat == PVMF_MIME_DATA_SOURCE_HTTP_URL && aSourceData == NULL) aSourceType = PVMF_MIME_DATA_SOURCE_MS_HTTP_STREAMING_URL;
122
123 for (uint32 i = 0; i < iTypeVec.size(); i++)
124 {
125 if (iTypeVec[i].iSourceType == aSourceType)
126 {
127 iTypeVecIndex = i;
128 return true;
129 }
130 }
131
132 // load plug-ins for further checkup
133 uint32 j = iTypeVec.size();
134 AddLoadableModules();
135
136 for (; j < iTypeVec.size(); j++)
137 {
138 if (iTypeVec[j].iSourceType == aSourceType)
139 {
140 iTypeVecIndex = j;
141 return true;
142 }
143 }
144
145 return false;
146 }
147
CreateProtocolEngineContainer(OsclAny * & aPluginInfo,PVMFProtocolEngineNode * aNode)148 ProtocolContainer* PVMFProtocolEngineNodeRegistry::CreateProtocolEngineContainer(OsclAny* &aPluginInfo, PVMFProtocolEngineNode* aNode)
149 {
150 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::CreateProtocolEngineContainer() IN"));
151
152 if (iTypeVecIndex == 0xFFFFFFFF) return NULL;
153 RecheckPlugin(aPluginInfo);
154 ProtocolContainer* aProtocolContainer = (*(iTypeVec[iTypeVecIndex].iProtocolEngineContainerCreateFunc))(aNode);
155 aPluginInfo = (OsclAny*)(iTypeVec[iTypeVecIndex].iSourceExtraInfo);
156 return aProtocolContainer;
157 }
158
ReleaseProtocolEngineContainer(ProtocolContainer * aContainer)159 bool PVMFProtocolEngineNodeRegistry::ReleaseProtocolEngineContainer(ProtocolContainer *aContainer)
160 {
161 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::ReleaseProtocolEngineContainer() IN"));
162
163 if (NULL == aContainer) return false;
164 if (iTypeVecIndex == 0xFFFFFFFF) return false;
165 (*(iTypeVec[iTypeVecIndex].iProtocolEngineContainerReleaseFunc))(aContainer);
166 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::ReleaseProtocolEngineContainer() OUT"));
167 return true;
168 }
169
170
RecheckPlugin(OsclAny * aNewPluginInfo)171 bool PVMFProtocolEngineNodeRegistry::RecheckPlugin(OsclAny* aNewPluginInfo)
172 {
173 uint32 isProgessiveStreaming = (aNewPluginInfo == NULL ? 0 : (uint32)aNewPluginInfo);
174 if (isProgessiveStreaming != iTypeVec[iTypeVecIndex].iSourceExtraInfo)
175 {
176 for (uint32 i = 0; i < iTypeVec.size(); i++)
177 {
178 if (iTypeVec[i].iSourceExtraInfo == isProgessiveStreaming &&
179 iTypeVec[i].iSourceType == iTypeVec[iTypeVecIndex].iSourceType)
180 {
181 iTypeVecIndex = i;
182 return true;
183 }
184 }
185 }
186 return false;
187 }
188
AddLoadableModules()189 void PVMFProtocolEngineNodeRegistry::AddLoadableModules()
190 {
191 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::AddLoadableModules() IN"));
192
193 #ifdef USE_LOADABLE_MODULES
194
195 OsclConfigFileList aCfgList;
196 // collects all config files from the project specified directory
197 if (NULL != PV_DYNAMIC_LOADING_CONFIG_FILE_PATH)
198 {
199 OSCL_HeapString<OsclMemAllocator> configFilePath = PV_DYNAMIC_LOADING_CONFIG_FILE_PATH;
200 aCfgList.Populate(configFilePath);
201 }
202 // populate libraries from all config files
203 for (uint k = 0; k < aCfgList.Size(); k++)
204 {
205 OsclLibraryList libList;
206 libList.Populate(PVMF_PROTOCOL_ENGINE_NODE_REGISTRY_POPULATOR_INTERFACE, aCfgList.GetConfigfileAt(k));
207
208 for (uint32 i = 0; i < libList.Size(); i++)
209 {
210 OsclSharedLibrary* lib = OSCL_NEW(OsclSharedLibrary, ());
211 if (lib->LoadLib(libList.GetLibraryPathAt(i)) == OsclLibSuccess)
212 {
213 OsclAny* interfacePtr = NULL;
214 OsclLibStatus result = lib->QueryInterface(PVMF_PROTOCOL_ENGINE_NODE_REGISTRY_POPULATOR_INTERFACE, (OsclAny*&)interfacePtr);
215 if (result == OsclLibSuccess && interfacePtr != NULL)
216 {
217 struct PVProtocolEngineNodeSharedLibInfo *libInfo =
218 (struct PVProtocolEngineNodeSharedLibInfo *)oscl_malloc(sizeof(struct PVProtocolEngineNodeSharedLibInfo));
219 if (NULL != libInfo)
220 {
221 libInfo->iLib = lib;
222
223 PVMFProtocolEngineNodeRegistryPopulatorInterface* nodeLibIntPtr = OSCL_DYNAMIC_CAST(PVMFProtocolEngineNodeRegistryPopulatorInterface*, interfacePtr);
224 libInfo->iNodeLibIfacePtr = nodeLibIntPtr;
225 nodeLibIntPtr->Register(this);
226
227 // save for depopulation later
228 iNodeLibInfoList.push_front(libInfo);
229 continue;
230 }
231 }
232 }
233 lib->Close();
234 OSCL_DELETE(lib);
235 }
236 }
237 #endif
238 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::AddLoadableModules() OUT"));
239 }
240
RemoveLoadableModules()241 void PVMFProtocolEngineNodeRegistry::RemoveLoadableModules()
242 {
243 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::RemoveLoadableModules() IN"));
244
245 #ifdef USE_LOADABLE_MODULES
246 // remove all dynamic nodes now
247 // unregister node one by one
248 while (!iNodeLibInfoList.empty())
249 {
250 struct PVProtocolEngineNodeSharedLibInfo *libInfo = iNodeLibInfoList.front();
251 iNodeLibInfoList.erase(iNodeLibInfoList.begin());
252
253 OsclSharedLibrary* lib = libInfo->iLib;
254 PVMFProtocolEngineNodeRegistryPopulatorInterface* nodeIntPtr = libInfo->iNodeLibIfacePtr;
255 oscl_free(libInfo);
256
257 nodeIntPtr->Unregister(this);
258
259 lib->Close();
260 OSCL_DELETE(lib);
261 }
262 #endif
263 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::RemoveLoadableModules() OUT"));
264 }
265
RegisterProtocolEngineContainer(PVMFProtocolEngineContainerInfo * aInfo)266 void PVMFProtocolEngineNodeRegistry::RegisterProtocolEngineContainer(PVMFProtocolEngineContainerInfo *aInfo)
267 {
268 LOGINFO((0, "PVMFProtocolEngineNodeRegistry::RegisterProtocolEngineContainer() IN"));
269 if (aInfo) iTypeVec.push_back(*aInfo);
270 }
271
272
273
274
275
276
277
278
279