• 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 nodes required for mp4 playback.
20 */
21 #ifndef PVMF_NODE_SHARED_LIB_INTERFACE_H_INCLUDED
22 #include "pvmf_node_shared_lib_interface.h"
23 #endif
24 
25 #ifndef PVMF_MP4FFPARSER_FACTORY_H_INCLUDED
26 #include "pvmf_mp4ffparser_factory.h"
27 #endif
28 
29 #ifndef PVMP4FFREC_FACTORY_H_INCLUDED
30 #include "pvmp4ffrec_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 #ifndef PVMFMP4NODEREG_H_INCLUDED
46 #include "pvmfmp4nodereg.h"
47 #endif
48 
49 #define MP4_LIB_NAME "libopencore_mp4local.so"
50 
51 #define NODE_REGISTRY_LIB_NAME_MAX_LENGTH 64
52 
53 typedef PVMFNodeInterface*(* LPFN_NODE_CREATE_FUNC)(int32);
54 
55 typedef bool (* LPFN_NODE_RELEASE_FUNC)(PVMFNodeInterface *);
56 
57 // Factory functions
CreateMp4ParserNode(int32 aPriority)58 PVMFNodeInterface* Mp4NodesCoreLibraryLoader::CreateMp4ParserNode(int32 aPriority)
59 {
60     OsclSharedLibrary* mp4SharedLibrary = NULL;
61     OSCL_StackString<NODE_REGISTRY_LIB_NAME_MAX_LENGTH> libname(MP4_LIB_NAME);
62 
63     // Need to load the library for the node
64     mp4SharedLibrary = OSCL_NEW(OsclSharedLibrary, (libname));
65     OsclLibStatus result = mp4SharedLibrary->LoadLib();
66     if (OsclLibSuccess != result)
67     {
68         return NULL;
69     }
70 
71     mp4SharedLibrary->AddRef();
72 
73     // Query for create function
74     OsclAny* interfacePtr = NULL;
75 
76     mp4SharedLibrary->QueryInterface(PV_NODE_INTERFACE, (OsclAny*&)interfacePtr);
77 
78     NodeSharedLibraryInterface* nodeIntPtr = OSCL_DYNAMIC_CAST(NodeSharedLibraryInterface*, interfacePtr);
79 
80     OsclAny* createFuncTemp = nodeIntPtr->QueryNodeInterface(KPVMFMP4FFParserNodeUuid, PV_CREATE_NODE_INTERFACE);
81 
82     LPFN_NODE_CREATE_FUNC nodeCreateFunc = OSCL_DYNAMIC_CAST(PVMFNodeInterface * (*)(int32), createFuncTemp);
83 
84     if (NULL != nodeCreateFunc)
85     {
86         PVMFNodeInterface* node = NULL;
87         // call the real node factory function
88         node = (*(nodeCreateFunc))(aPriority);
89         if (NULL == node)
90         {
91             mp4SharedLibrary->RemoveRef();
92 
93             if (OsclLibSuccess == mp4SharedLibrary->Close())
94             {
95                 // Close will unload the library if refcount is 0
96                 OSCL_DELETE(mp4SharedLibrary);
97             }
98 
99             return NULL;
100         }
101         node->SetSharedLibraryPtr(mp4SharedLibrary);
102         return node;
103     }
104     return NULL;
105 }
106 
107 
DeleteMp4ParserNode(PVMFNodeInterface * aNode)108 bool Mp4NodesCoreLibraryLoader::DeleteMp4ParserNode(PVMFNodeInterface* aNode)
109 {
110     bool bStatus = false;
111     OsclSharedLibrary* mp4SharedLibrary = NULL;
112 
113     if (NULL == aNode)
114     {
115         return false;
116     }
117 
118     // Retrieve shared library pointer
119     mp4SharedLibrary = aNode->GetSharedLibraryPtr();
120 
121     if (NULL != mp4SharedLibrary)
122     {
123         // Query for release function
124         OsclAny* interfacePtr = NULL;
125 
126         mp4SharedLibrary->QueryInterface(PV_NODE_INTERFACE, (OsclAny*&)interfacePtr);
127 
128         NodeSharedLibraryInterface* nodeIntPtr = OSCL_DYNAMIC_CAST(NodeSharedLibraryInterface*, interfacePtr);
129 
130         OsclAny* releaseFuncTemp = nodeIntPtr->QueryNodeInterface(KPVMFMP4FFParserNodeUuid, PV_RELEASE_NODE_INTERFACE);
131 
132         LPFN_NODE_RELEASE_FUNC nodeReleaseFunc = OSCL_DYNAMIC_CAST(bool (*)(PVMFNodeInterface*), releaseFuncTemp);
133 
134         if (NULL != nodeReleaseFunc)
135         {
136             bStatus = (*(nodeReleaseFunc))(aNode);
137         }
138 
139         mp4SharedLibrary->RemoveRef();
140 
141         if (OsclLibSuccess == mp4SharedLibrary->Close())
142         {
143             // Close will unload the library if refcount is 0
144             OSCL_DELETE(mp4SharedLibrary);
145         }
146     }
147 
148     return bStatus;
149 }
150 
151 class Mp4NodesRegistryInterface: public OsclSharedLibraryInterface,
152         public NodeRegistryPopulatorInterface,
153         public RecognizerPopulatorInterface
154 {
155     public:
Mp4NodesRegistryInterface()156         Mp4NodesRegistryInterface() {};
157 
158         // From NodeRegistryPopulatorInterface
RegisterAllNodes(PVPlayerNodeRegistryInterface * aRegistry,OsclAny * & aContext)159         void RegisterAllNodes(PVPlayerNodeRegistryInterface* aRegistry, OsclAny*& aContext)
160         {
161             PVPlayerNodeInfo nodeinfo;
162 
163             OSCL_StackString<NODE_REGISTRY_LIB_NAME_MAX_LENGTH> libname = MP4_LIB_NAME;
164 
165             Oscl_Vector<PVPlayerNodeInfo, OsclMemAllocator>* nodeList = new Oscl_Vector<PVPlayerNodeInfo, OsclMemAllocator>;
166 
167             //For PVMFMP4FFParserNode
168             nodeinfo.iInputTypes.clear();
169             nodeinfo.iInputTypes.push_back(PVMF_MIME_MPEG4FF);
170             nodeinfo.iNodeUUID = KPVMFMP4FFParserNodeUuid;
171             nodeinfo.iOutputType.clear();
172             nodeinfo.iOutputType.push_back(PVMF_MIME_FORMAT_UNKNOWN);
173             nodeinfo.iNodeCreateFunc = (Mp4NodesCoreLibraryLoader::CreateMp4ParserNode);
174             nodeinfo.iNodeReleaseFunc = (Mp4NodesCoreLibraryLoader::DeleteMp4ParserNode);
175 
176             aRegistry->RegisterNode(nodeinfo);
177 
178             nodeList->push_back(nodeinfo);
179 
180             aContext = (OsclAny *)nodeList;
181 
182         };
183 
184         // From NodeRegistryPopulatorInterface
UnregisterAllNodes(PVPlayerNodeRegistryInterface * aRegistry,OsclAny * aContext)185         void UnregisterAllNodes(PVPlayerNodeRegistryInterface* aRegistry, OsclAny* aContext)
186         {
187             if (NULL != aContext)
188             {
189                 Oscl_Vector<PVPlayerNodeInfo, OsclMemAllocator>* nodeList = (Oscl_Vector<PVPlayerNodeInfo, OsclMemAllocator> *)aContext;
190 
191                 while (!nodeList->empty())
192                 {
193                     PVPlayerNodeInfo tmpnode = nodeList->front();
194                     aRegistry->UnregisterNode(tmpnode);
195                     nodeList->erase(nodeList->begin());
196                 }
197 
198                 delete nodeList;
199             }
200         };
201 
202 
203         // From RecognizerPopulatorInterface
RegisterAllRecognizers(PVPlayerRecognizerRegistryInterface * aRegistry,OsclAny * & aContext)204         void RegisterAllRecognizers(PVPlayerRecognizerRegistryInterface* aRegistry, OsclAny*& aContext)
205         {
206             PVMFRecognizerPluginFactory* tmpfac = NULL;
207 
208             Oscl_Vector<PVMFRecognizerPluginFactory*, OsclMemAllocator>* pluginList =
209                 new Oscl_Vector<PVMFRecognizerPluginFactory*, OsclMemAllocator>;
210 
211             tmpfac =
212                 OSCL_STATIC_CAST(PVMFRecognizerPluginFactory*, OSCL_NEW(PVMP4FFRecognizerFactory, ()));
213             aRegistry->RegisterRecognizer(tmpfac);
214 
215             pluginList->push_back(tmpfac);
216 
217             aContext = (OsclAny *)pluginList;
218         };
219 
220 
UnregisterAllRecognizers(PVPlayerRecognizerRegistryInterface * aRegistry,OsclAny * aContext)221         void UnregisterAllRecognizers(PVPlayerRecognizerRegistryInterface* aRegistry, OsclAny* aContext)
222         {
223             if (NULL != aContext)
224             {
225                 Oscl_Vector<PVMFRecognizerPluginFactory*, OsclMemAllocator>* pluginList = (Oscl_Vector<PVMFRecognizerPluginFactory*, OsclMemAllocator>*)aContext;
226 
227                 while (!pluginList->empty())
228                 {
229                     PVMFRecognizerPluginFactory* tmpfac = pluginList->front();
230 
231                     aRegistry->UnregisterRecognizer(tmpfac);
232 
233                     pluginList->erase(pluginList->begin());
234 
235                     OSCL_DELETE(tmpfac);
236                 }
237 
238                 delete pluginList;
239             }
240         };
241 
242         // From OsclSharedLibraryInterface
SharedLibraryLookup(const OsclUuid & aInterfaceId)243         OsclAny* SharedLibraryLookup(const OsclUuid& aInterfaceId)
244         {
245             if (aInterfaceId == PV_NODE_REGISTRY_POPULATOR_INTERFACE)
246             {
247                 return OSCL_STATIC_CAST(NodeRegistryPopulatorInterface*, this);
248             }
249             else if (aInterfaceId == PV_RECOGNIZER_POPULATOR_INTERFACE)
250             {
251                 return OSCL_STATIC_CAST(RecognizerPopulatorInterface*, this);
252             }
253             return NULL;
254         };
255 };
256 
257 
258 extern "C"
259 {
PVGetInterface(void)260     OSCL_EXPORT_REF OsclSharedLibraryInterface *PVGetInterface(void)
261     {
262         return OSCL_NEW(Mp4NodesRegistryInterface, ());
263     }
PVReleaseInterface(OsclSharedLibraryInterface * aInstance)264     OSCL_EXPORT_REF void PVReleaseInterface(OsclSharedLibraryInterface* aInstance)
265     {
266         OSCL_DELETE(aInstance);
267     }
268 }
269 
270