• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 /* This file defines a PV NodeSharedLibrary interface that populates the
19    registry with the download manager node.
20 */
21 #ifndef PVMFDOWNLOADNODEREG_H_INCLUDED
22 #include "pvmfdownloadnodereg.h"
23 #endif
24 
25 #ifndef PVMF_NODE_SHARED_LIB_INTERFACE_H_INCLUDED
26 #include "pvmf_node_shared_lib_interface.h"
27 #endif
28 
29 #ifndef PVMF_DOWNLOADMANAGER_FACTORY_H_INCLUDED
30 #include "pvmf_downloadmanager_factory.h"
31 #endif
32 
33 #ifndef PVMF_RECOGNIZER_REGISTRY_H_INCLUDED
34 #include "pvmf_recognizer_registry.h"
35 #endif
36 
37 #ifndef OSCLCONFIG_H_INCLUDED
38 #include "osclconfig.h"
39 #endif
40 
41 #ifndef OSCL_SHARED_LIBRARY_H_INCLUDED
42 #include "oscl_shared_library.h"
43 #endif
44 
45 #define DOWNLOAD_LIB_NAME "libopencore_download.so"
46 
47 #define NODE_REGISTRY_LIB_NAME_MAX_LENGTH 64
48 
49 typedef PVMFNodeInterface*(* LPFN_NODE_CREATE_FUNC)(int32);
50 
51 typedef bool (* LPFN_NODE_RELEASE_FUNC)(PVMFNodeInterface *);
52 
53 // Factory functions
CreateDownloadManagerNode(int32 aPriority)54 PVMFNodeInterface* DownloadNodesCoreLibraryLoader::CreateDownloadManagerNode(int32 aPriority)
55 {
56     OsclSharedLibrary* downloadSharedLibrary = NULL;
57     OSCL_StackString<NODE_REGISTRY_LIB_NAME_MAX_LENGTH> libname(DOWNLOAD_LIB_NAME);
58 
59     // Need to load the library for the node
60     downloadSharedLibrary = OSCL_NEW(OsclSharedLibrary, (libname));
61     OsclLibStatus result = downloadSharedLibrary->LoadLib();
62     if (OsclLibSuccess != result)
63     {
64         return NULL;
65     }
66 
67     downloadSharedLibrary->AddRef();
68 
69     // Query for create function
70     OsclAny* interfacePtr = NULL;
71 
72     downloadSharedLibrary->QueryInterface(PV_NODE_INTERFACE, (OsclAny*&)interfacePtr);
73 
74     NodeSharedLibraryInterface* nodeIntPtr = OSCL_DYNAMIC_CAST(NodeSharedLibraryInterface*, interfacePtr);
75 
76     OsclAny* createFuncTemp = nodeIntPtr->QueryNodeInterface(KPVMFDownloadManagerNodeUuid, PV_CREATE_NODE_INTERFACE);
77 
78     LPFN_NODE_CREATE_FUNC nodeCreateFunc = OSCL_DYNAMIC_CAST(PVMFNodeInterface * (*)(int32), createFuncTemp);
79 
80     if (NULL != nodeCreateFunc)
81     {
82         PVMFNodeInterface* node = NULL;
83         // call the real node factory function
84         node = (*(nodeCreateFunc))(aPriority);
85         if (NULL == node)
86         {
87             downloadSharedLibrary->RemoveRef();
88 
89             if (OsclLibSuccess == downloadSharedLibrary->Close())
90             {
91                 // Close will unload the library if refcount is 0
92                 OSCL_DELETE(downloadSharedLibrary);
93             }
94 
95             return NULL;
96         }
97         node->SetSharedLibraryPtr(downloadSharedLibrary);
98         return node;
99     }
100     return NULL;
101 }
102 
103 
DeleteDownloadManagerNode(PVMFNodeInterface * aNode)104 bool DownloadNodesCoreLibraryLoader::DeleteDownloadManagerNode(PVMFNodeInterface* aNode)
105 {
106     bool bStatus = false;
107     OsclSharedLibrary* downloadSharedLibrary = NULL;
108 
109     if (NULL == aNode)
110     {
111         return false;
112     }
113 
114     // Retrieve shared library pointer
115     downloadSharedLibrary = aNode->GetSharedLibraryPtr();
116 
117     if (NULL != downloadSharedLibrary)
118     {
119         // Query for release function
120         OsclAny* interfacePtr = NULL;
121 
122         downloadSharedLibrary->QueryInterface(PV_NODE_INTERFACE, (OsclAny*&)interfacePtr);
123 
124         NodeSharedLibraryInterface* nodeIntPtr = OSCL_DYNAMIC_CAST(NodeSharedLibraryInterface*, interfacePtr);
125 
126         OsclAny* releaseFuncTemp = nodeIntPtr->QueryNodeInterface(KPVMFDownloadManagerNodeUuid, PV_RELEASE_NODE_INTERFACE);
127 
128         LPFN_NODE_RELEASE_FUNC nodeReleaseFunc = OSCL_DYNAMIC_CAST(bool (*)(PVMFNodeInterface*), releaseFuncTemp);
129 
130         if (NULL != nodeReleaseFunc)
131         {
132             bStatus = (*(nodeReleaseFunc))(aNode);
133         }
134 
135         downloadSharedLibrary->RemoveRef();
136 
137         if (OsclLibSuccess == downloadSharedLibrary->Close())
138         {
139             // Close will unload the library if refcount is 0
140             OSCL_DELETE(downloadSharedLibrary);
141         }
142     }
143 
144     return bStatus;
145 }
146 
147 
148 
149 class DownloadNodesRegistryInterface: public OsclSharedLibraryInterface,
150         public NodeRegistryPopulatorInterface,
151         public RecognizerPopulatorInterface
152 {
153     public:
DownloadNodesRegistryInterface()154         DownloadNodesRegistryInterface() {};
155 
156         // From NodeRegistryPopulatorInterface
RegisterAllNodes(PVPlayerNodeRegistryInterface * aRegistry,OsclAny * & aContext)157         void RegisterAllNodes(PVPlayerNodeRegistryInterface* aRegistry, OsclAny*& aContext)
158         {
159             PVPlayerNodeInfo nodeinfo;
160 
161             OSCL_StackString<NODE_REGISTRY_LIB_NAME_MAX_LENGTH> libname(DOWNLOAD_LIB_NAME);
162 
163             Oscl_Vector<PVPlayerNodeInfo, OsclMemAllocator>* nodeList = new Oscl_Vector<PVPlayerNodeInfo, OsclMemAllocator>;
164 
165             //For PVMFDownloadManagerNode
166             nodeinfo.iInputTypes.clear();
167             nodeinfo.iInputTypes.push_back(PVMF_MIME_DATA_SOURCE_HTTP_URL);
168             nodeinfo.iInputTypes.push_back(PVMF_MIME_DATA_SOURCE_PVX_FILE);
169             nodeinfo.iInputTypes.push_back(PVMF_MIME_DATA_SOURCE_SHOUTCAST_URL);
170             nodeinfo.iNodeUUID = KPVMFDownloadManagerNodeUuid;
171             nodeinfo.iOutputType.clear();
172             nodeinfo.iOutputType.push_back(PVMF_MIME_FORMAT_UNKNOWN);
173             nodeinfo.iNodeCreateFunc = (DownloadNodesCoreLibraryLoader::CreateDownloadManagerNode);
174             nodeinfo.iNodeReleaseFunc = (DownloadNodesCoreLibraryLoader::DeleteDownloadManagerNode);
175 
176             aRegistry->RegisterNode(nodeinfo);
177 
178             nodeList->push_back(nodeinfo);
179 
180             aContext = (OsclAny *)nodeList;
181         };
182 
183         // From NodeRegistryPopulatorInterface
UnregisterAllNodes(PVPlayerNodeRegistryInterface * aRegistry,OsclAny * aContext)184         void UnregisterAllNodes(PVPlayerNodeRegistryInterface* aRegistry, OsclAny* aContext)
185         {
186             if (NULL != aContext)
187             {
188                 Oscl_Vector<PVPlayerNodeInfo, OsclMemAllocator>* nodeList = (Oscl_Vector<PVPlayerNodeInfo, OsclMemAllocator> *)aContext;
189 
190                 while (!nodeList->empty())
191                 {
192                     PVPlayerNodeInfo tmpnode = nodeList->front();
193                     aRegistry->UnregisterNode(tmpnode);
194                     nodeList->erase(nodeList->begin());
195                 }
196 
197                 delete nodeList;
198             }
199         };
200 
201 
202         // From RecognizerPopulatorInterface
RegisterAllRecognizers(PVPlayerRecognizerRegistryInterface * aRegistry,OsclAny * & aContext)203         void RegisterAllRecognizers(PVPlayerRecognizerRegistryInterface* aRegistry, OsclAny*& aContext)
204         {
205             OSCL_UNUSED_ARG(aRegistry);
206             OSCL_UNUSED_ARG(aContext);
207         };
208 
209 
UnregisterAllRecognizers(PVPlayerRecognizerRegistryInterface * aRegistry,OsclAny * aContext)210         void UnregisterAllRecognizers(PVPlayerRecognizerRegistryInterface* aRegistry, OsclAny* aContext)
211         {
212             OSCL_UNUSED_ARG(aRegistry);
213             OSCL_UNUSED_ARG(aContext);
214         };
215 
216         // From OsclSharedLibraryInterface
SharedLibraryLookup(const OsclUuid & aInterfaceId)217         OsclAny* SharedLibraryLookup(const OsclUuid& aInterfaceId)
218         {
219             if (aInterfaceId == PV_NODE_REGISTRY_POPULATOR_INTERFACE)
220             {
221                 return OSCL_STATIC_CAST(NodeRegistryPopulatorInterface*, this);
222             }
223             return NULL;
224         };
225 };
226 
227 
228 extern "C"
229 {
PVGetInterface(void)230     OSCL_EXPORT_REF OsclSharedLibraryInterface* PVGetInterface(void)
231     {
232         return OSCL_NEW(DownloadNodesRegistryInterface, ());
233     }
PVReleaseInterface(OsclSharedLibraryInterface * aInstance)234     OSCL_EXPORT_REF void PVReleaseInterface(OsclSharedLibraryInterface* aInstance)
235     {
236         OSCL_DELETE(aInstance);
237     }
238 }
239 
240