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 #ifndef PVMF_RECOGNIZER_PLUGIN_H_INCLUDED 19 #define PVMF_RECOGNIZER_PLUGIN_H_INCLUDED 20 21 #ifndef OSCL_BASE_H_INCLUDED 22 #include "oscl_base.h" 23 #endif 24 25 #ifndef OSCL_VECTOR_H_INCLUDED 26 #include "oscl_vector.h" 27 #endif 28 29 #ifndef PVMF_RETURN_CODES_H_INCLUDED 30 #include "pvmf_return_codes.h" 31 #endif 32 33 #ifndef OSCL_STRING_H_INCLUDED 34 #include "oscl_string.h" 35 #endif 36 37 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED 38 #include "oscl_string_containers.h" 39 #endif 40 41 #ifndef PVMF_FORMAT_TYPE_H_INCLUDED 42 #include "pvmf_format_type.h" 43 #endif 44 45 #ifndef PVMF_RECOGNIZER_TYPES_H_INCLUDED 46 #include "pvmf_recognizer_types.h" 47 #endif 48 49 #ifndef PVMI_DATASTREAMUSER_INTERFACE_H_INCLUDED 50 #include "pvmi_datastreamuser_interface.h" 51 #endif 52 53 #ifndef OSCL_MEM_H_INCLUDED 54 #include "oscl_mem.h" 55 #endif 56 /** 57 * An abstract base class for the recognizer plug-in. Every recognizer plug-in should derive from 58 * this base class and implement all the declared methods. 59 **/ 60 class PVMFRecognizerPluginInterface 61 { 62 public: 63 /** 64 * Virtual destructor for the plug-in. All plug-ins should perform any clean up here 65 **/ 66 virtual ~PVMFRecognizerPluginInterface() 67 { 68 }; 69 70 /** 71 * This methods returns a list of format(s) that this plug-in can recognize. Each supported format 72 * is represented by a MIME string. 73 * 74 * @param aSupportedFormatsList 75 * Reference to a list of MIME strings which will be filled in with list of formats that the plug-in can recognize. 76 * 77 * @exception This method can leave with one of the following error codes 78 * OsclErrNoMemory if memory cannot be allocated for the format list 79 * 80 * @returns A PVMF status code to report result of method 81 **/ 82 virtual PVMFStatus SupportedFormats(PVMFRecognizerMIMEStringList& aSupportedFormatsList) = 0; 83 84 /** 85 * This method determines the the specified content is or is not one of the formats recognized by this plug-in 86 * 87 * @param aSourceDataStreamFactory 88 * A reference to a PVMFDataStreamFactory representing the content to recognize 89 * @param aFormatHint 90 * An optional input parameter expressed as a list of MIME string which provides a priori hint for the format 91 * of the content specified by aSourceDataStreamFactory. 92 * @param aRecognizerResult 93 * An output parameter which is a reference to a vector of PVMFRecognizerResult that will contain the recognition 94 * result if the Recognize() method succeeds. 95 * 96 * @exception This method can leave with one of the following error codes 97 * 98 * @returns A PVMF status code to report result of method 99 **/ 100 virtual PVMFStatus Recognize(PVMFDataStreamFactory& aSourceDataStreamFactory, 101 PVMFRecognizerMIMEStringList* aFormatHint, 102 Oscl_Vector<PVMFRecognizerResult, OsclMemAllocator>& aRecognizerResult) = 0; 103 104 /** 105 * This method returns the mininum required bytes in datastream for this plug-in 106 * to be able to recognize its supported formats. 107 * 108 * @param aBytes[out] 109 * A reference to a minimum required bytes 110 * 111 * @returns A PVMF status code to report result of method. 112 * PVMFSuccess in case of success and PVMFFailure otherwise. 113 **/ 114 virtual PVMFStatus GetRequiredMinBytesForRecognition(uint32& aBytes) = 0; 115 }; 116 117 118 /** 119 * An abstract base class to create and destroy a recognizer plug-in. Every recognizer plug-in should have 120 * an associated factory class to provide a standard way to create and destroy the plug-in. 121 **/ 122 class PVMFRecognizerPluginFactory: public HeapBase 123 { 124 public: 125 /** 126 * Virtual destructor for the plug-in factory. All plug-in factory should perform any clean up here 127 **/ 128 virtual ~PVMFRecognizerPluginFactory() 129 { 130 }; 131 132 /** 133 * This method instantiates and returns the recognizer plug-in that the factory is associated with. 134 * 135 * @exception This method can leave with one of the following error codes 136 * OsclErrNoMemory if memory cannot be allocated for the recognizer plug-in 137 * @returns A pointer to the recognizer plug-in instance if creation is successful. 138 **/ 139 virtual PVMFRecognizerPluginInterface* CreateRecognizerPlugin() = 0; 140 141 /** 142 * This method destroys the specified recognizer plug-in pointer as the particular recognizer plug-in 143 * the factory is associated with. 144 * 145 * @param aPlugIn 146 * A pointer to the recognizer plug-in that should be destroyed. 147 * 148 * @exception This method can leave with one of the following error codes 149 * 150 * @returns None 151 **/ 152 virtual void DestroyRecognizerPlugin(PVMFRecognizerPluginInterface* aPlugIn) = 0; 153 }; 154 155 156 /** 157 * Basic templatized recognizer plug-in factory. Can be used if the recognizer plug-in only needs 158 * to be instantiated and destroyed by just new and delete, respectively and no other functionality 159 * is needed from the factory class. 160 **/ 161 template<class T> 162 class PVMFRecognizerPluginFactoryBasic : public PVMFRecognizerPluginFactory 163 { 164 public: 165 virtual ~PVMFRecognizerPluginFactoryBasic() 166 { 167 }; 168 169 PVMFRecognizerPluginInterface* CreateRecognizerPlugin() 170 { 171 T* plugin = OSCL_NEW(T, ()); 172 return plugin; 173 }; 174 175 void DestroyRecognizerPlugin(PVMFRecognizerPluginInterface* aPlugIn) 176 { 177 T* plugin = (T*)aPlugIn; 178 OSCL_DELETE(plugin); 179 }; 180 }; 181 182 #endif // PVMF_RECOGNIZER_PLUGIN_H_INCLUDED 183 184 185 186 187