• 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 #include "pvmf_recognizer_registry.h"
19 #include "pvmf_recognizer_registry_impl.h"
20 
21 #include "oscl_dll.h"
OSCL_DLL_ENTRY_POINT_DEFAULT()22 OSCL_DLL_ENTRY_POINT_DEFAULT()
23 
24 
25 // Need a registry ...
26 #include "oscl_error.h"
27 // Platform has TLS support
28 #define PVMFRECOGNIZER_REGISTRY OsclTLSRegistryEx
29 #define PVMFRECOGNIZER_REGISTRY_ID OSCL_TLS_ID_PVMFRECOGNIZER
30 #define PVMFRECOGNIZER_REGISTRY_WRAPPER OsclTLSEx
31 
32 
33 
34 OSCL_EXPORT_REF PVMFStatus PVMFRecognizerRegistry::Init()
35 {
36     // Check that there is no existing registry
37     PVMFRecognizerRegistryImpl* pvrecregimpl = OSCL_STATIC_CAST(PVMFRecognizerRegistryImpl*, PVMFRECOGNIZER_REGISTRY::getInstance(PVMFRECOGNIZER_REGISTRY_ID));
38     if (pvrecregimpl != NULL)
39     {
40         // Registry is already present so no need to instantiate again
41         // Just increment the refcount
42         (pvrecregimpl->iRefCount)++;
43         return PVMFSuccess;
44     }
45 
46     // Instantiate the registry implementation
47     Oscl_TAlloc<PVMFRecognizerRegistryImpl, OsclMemAllocator> talloc;
48     pvrecregimpl = OSCL_ALLOC_NEW(talloc, PVMFRecognizerRegistryImpl, ());
49     // Save it on singleton or TLS
50     PVMFRECOGNIZER_REGISTRY::registerInstance(pvrecregimpl, PVMFRECOGNIZER_REGISTRY_ID);
51     return PVMFSuccess;
52 }
53 
54 
Cleanup()55 OSCL_EXPORT_REF void PVMFRecognizerRegistry::Cleanup()
56 {
57     // Retrieve the registry implementation instance from singleton or TLS and destroy it
58     PVMFRecognizerRegistryImpl* pvrecregimpl = OSCL_STATIC_CAST(PVMFRecognizerRegistryImpl*, PVMFRECOGNIZER_REGISTRY::getInstance(PVMFRECOGNIZER_REGISTRY_ID));
59     if (pvrecregimpl != NULL)
60     {
61         // First decrement the refcount
62         --(pvrecregimpl->iRefCount);
63         // If the resulting refcount is 0, then delete the instance
64         if ((pvrecregimpl->iRefCount) <= 0)
65         {
66             Oscl_TAlloc<PVMFRecognizerRegistryImpl, OsclMemAllocator> talloc;
67             OSCL_ALLOC_DELETE(pvrecregimpl, talloc, PVMFRecognizerRegistryImpl);
68             // Unregister by putting NULL pointer in singleton or TLS
69             PVMFRECOGNIZER_REGISTRY::registerInstance(NULL, PVMFRECOGNIZER_REGISTRY_ID);
70         }
71     }
72     else
73     {
74         // Registry has already been cleaned up so nothing to do
75     }
76 }
77 
78 
RegisterPlugin(PVMFRecognizerPluginFactory & aPluginFactory)79 OSCL_EXPORT_REF PVMFStatus PVMFRecognizerRegistry::RegisterPlugin(PVMFRecognizerPluginFactory& aPluginFactory)
80 {
81     PVMFRecognizerRegistryImpl* pvrecregimpl = OSCL_STATIC_CAST(PVMFRecognizerRegistryImpl*, PVMFRECOGNIZER_REGISTRY::getInstance(PVMFRECOGNIZER_REGISTRY_ID));
82     if (pvrecregimpl != NULL)
83     {
84         return pvrecregimpl->RegisterPlugin(aPluginFactory);
85     }
86     else
87     {
88         // Registry hasn't been initialized yet. Assert
89         OSCL_ASSERT(false);
90         return PVMFErrNotReady;
91     }
92 }
93 
94 
RemovePlugin(PVMFRecognizerPluginFactory & aPluginFactory)95 OSCL_EXPORT_REF PVMFStatus PVMFRecognizerRegistry::RemovePlugin(PVMFRecognizerPluginFactory& aPluginFactory)
96 {
97     PVMFRecognizerRegistryImpl* pvrecregimpl = OSCL_STATIC_CAST(PVMFRecognizerRegistryImpl*, PVMFRECOGNIZER_REGISTRY::getInstance(PVMFRECOGNIZER_REGISTRY_ID));
98     if (pvrecregimpl != NULL)
99     {
100         return pvrecregimpl->RemovePlugin(aPluginFactory);
101     }
102     else
103     {
104         // Registry hasn't been initialized yet. Assert
105         OSCL_ASSERT(false);
106         return PVMFErrNotReady;
107     }
108 }
109 
110 
OpenSession(PVMFSessionId & aSessionId,PVMFRecognizerCommmandHandler & aCmdHandler)111 OSCL_EXPORT_REF PVMFStatus PVMFRecognizerRegistry::OpenSession(PVMFSessionId& aSessionId, PVMFRecognizerCommmandHandler& aCmdHandler)
112 {
113     PVMFRecognizerRegistryImpl* pvrecregimpl = OSCL_STATIC_CAST(PVMFRecognizerRegistryImpl*, PVMFRECOGNIZER_REGISTRY::getInstance(PVMFRECOGNIZER_REGISTRY_ID));
114     if (pvrecregimpl != NULL)
115     {
116         return pvrecregimpl->OpenSession(aSessionId, aCmdHandler);
117     }
118     else
119     {
120         // Registry hasn't been initialized yet. Assert
121         OSCL_ASSERT(false);
122         return PVMFErrNotReady;
123     }
124 }
125 
126 
CloseSession(PVMFSessionId aSessionId)127 OSCL_EXPORT_REF PVMFStatus PVMFRecognizerRegistry::CloseSession(PVMFSessionId aSessionId)
128 {
129     PVMFRecognizerRegistryImpl* pvrecregimpl = OSCL_STATIC_CAST(PVMFRecognizerRegistryImpl*, PVMFRECOGNIZER_REGISTRY::getInstance(PVMFRECOGNIZER_REGISTRY_ID));
130     if (pvrecregimpl != NULL)
131     {
132         return pvrecregimpl->CloseSession(aSessionId);
133     }
134     else
135     {
136         // Registry hasn't been initialized yet. Assert
137         OSCL_ASSERT(false);
138         return PVMFErrNotReady;
139     }
140 }
141 
142 
Recognize(PVMFSessionId aSessionId,PVMFDataStreamFactory & aSourceDataStreamFactory,PVMFRecognizerMIMEStringList * aFormatHint,Oscl_Vector<PVMFRecognizerResult,OsclMemAllocator> & aRecognizerResult,OsclAny * aCmdContext,uint32 aTimeout)143 OSCL_EXPORT_REF PVMFCommandId PVMFRecognizerRegistry::Recognize(PVMFSessionId aSessionId, PVMFDataStreamFactory& aSourceDataStreamFactory, PVMFRecognizerMIMEStringList* aFormatHint,
144         Oscl_Vector<PVMFRecognizerResult, OsclMemAllocator>& aRecognizerResult, OsclAny* aCmdContext, uint32 aTimeout)
145 {
146     PVMFRecognizerRegistryImpl* pvrecregimpl = OSCL_STATIC_CAST(PVMFRecognizerRegistryImpl*, PVMFRECOGNIZER_REGISTRY::getInstance(PVMFRECOGNIZER_REGISTRY_ID));
147     if (pvrecregimpl != NULL)
148     {
149         return pvrecregimpl->Recognize(aSessionId, aSourceDataStreamFactory, aFormatHint, aRecognizerResult, aCmdContext, aTimeout);
150     }
151     else
152     {
153         // Registry hasn't been initialized yet. Assert
154         OSCL_ASSERT(false);
155         OSCL_LEAVE(OsclErrNotReady);
156         return 0;
157     }
158 }
159 
160 
CancelCommand(PVMFSessionId aSessionId,PVMFCommandId aCommandToCancelId,OsclAny * aCmdContext)161 OSCL_EXPORT_REF PVMFCommandId PVMFRecognizerRegistry::CancelCommand(PVMFSessionId aSessionId, PVMFCommandId aCommandToCancelId, OsclAny* aCmdContext)
162 {
163     PVMFRecognizerRegistryImpl* pvrecregimpl = OSCL_STATIC_CAST(PVMFRecognizerRegistryImpl*, PVMFRECOGNIZER_REGISTRY::getInstance(PVMFRECOGNIZER_REGISTRY_ID));
164     if (pvrecregimpl != NULL)
165     {
166         return pvrecregimpl->CancelCommand(aSessionId, aCommandToCancelId, aCmdContext);
167     }
168     else
169     {
170         // Registry hasn't been initialized yet. Assert
171         OSCL_ASSERT(false);
172         OSCL_LEAVE(OsclErrNotReady);
173         return 0;
174     }
175 }
176 
177 
178 
179 
180