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 PVAUTHORENGINE_H_INCLUDED 19 #define PVAUTHORENGINE_H_INCLUDED 20 21 #ifndef OSCL_BASE_H_INCLUDED 22 #include "oscl_base.h" 23 #endif 24 #ifndef OSCL_MEM_H_INCLUDED 25 #include "oscl_mem.h" 26 #endif 27 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED 28 #include "oscl_scheduler_ao.h" 29 #endif 30 #ifndef PVLOGGER_H_INCLUDED 31 #include "pvlogger.h" 32 #endif 33 #ifndef PV_UUID_H_INCLUDED 34 #include "pv_uuid.h" 35 #endif 36 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED 37 #include "pvmf_node_interface.h" 38 #endif 39 #ifndef PV_ENGINE_TYPES_H_INCLUDED 40 #include "pv_engine_types.h" 41 #endif 42 #ifndef PV_ENGINE_OBSERVER_H_INCLUDED 43 #include "pv_engine_observer.h" 44 #endif 45 #ifndef PVAUTHORENGINEINTERFACE_H_INCLUDED 46 #include "pvauthorengineinterface.h" 47 #endif 48 #ifndef PVAE_NODE_UTILITY_H_INCLUDED 49 #include "pvaenodeutility.h" 50 #endif 51 52 #ifndef PVMI_CONFIG_AND_CAPABILITY_H_INCLUDED 53 #include "pvmi_config_and_capability.h" 54 #endif 55 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED 56 #include "pvmf_media_clock.h" 57 #endif 58 59 #define K3gpComposerMimeType "/x-pvmf/ff-mux/3gp" 60 #define KMP4ComposerMimeType "/x-pvmf/ff-mux/mp4" 61 #define KAmrNbEncMimeType "/x-pvmf/audio/encode/amr-nb" 62 #define KAMRWbEncMimeType "/x-pvmf/audio/encode/amr-wb" 63 #define KH263EncMimeType "/x-pvmf/video/encode/h263" 64 #define KH264EncMimeType "/x-pvmf/video/encode/h264" 65 #define KMp4EncMimeType "/x-pvmf/video/encode/mp4" 66 #define KTextEncMimeType "/x-pvmf/text/encode/txt" 67 68 //MIME strings for .amr and .aac composer 69 #define KAMRNbComposerMimeType "/x-pvmf/ff-mux/amr-nb" 70 #define KAMRWbComposerMimeType "/x-pvmf/ff-mux/amr-wb" 71 #define KAACADIFComposerMimeType "/x-pvmf/ff-mux/adif" 72 #define KAACADTSComposerMimeType "/x-pvmf/ff-mux/adts" 73 #define KAACADIFEncMimeType "/x-pvmf/audio/encode/aac/adif" 74 #define KAACADTSEncMimeType "/x-pvmf/audio/encode/aac/adts" 75 #define KAACMP4EncMimeType "/x-pvmf/audio/encode/X-MPEG4-AUDIO" 76 //end of changes 77 78 /** 79 * Enumeration of types of asychronous commands that can be issued to PV Author Engine 80 */ 81 typedef enum 82 { 83 PVAE_CMD_SET_LOG_APPENDER, 84 PVAE_CMD_REMOVE_LOG_APPENDER, 85 PVAE_CMD_SET_LOG_LEVEL, 86 PVAE_CMD_GET_LOG_LEVEL, 87 PVAE_CMD_OPEN, 88 PVAE_CMD_CLOSE, 89 PVAE_CMD_ADD_DATA_SOURCE, 90 PVAE_CMD_REMOVE_DATA_SOURCE, 91 PVAE_CMD_SELECT_COMPOSER, 92 PVAE_CMD_ADD_MEDIA_TRACK, 93 PVAE_CMD_ADD_DATA_SINK, 94 PVAE_CMD_REMOVE_DATA_SINK, 95 PVAE_CMD_INIT, 96 PVAE_CMD_RESET, 97 PVAE_CMD_START, 98 PVAE_CMD_PAUSE, 99 PVAE_CMD_RESUME, 100 PVAE_CMD_STOP, 101 PVAE_CMD_QUERY_UUID, 102 PVAE_CMD_QUERY_INTERFACE, 103 PVAE_CMD_GET_SDK_INFO, 104 PVAE_CMD_GET_SDK_MODULE_INFO, 105 PVAE_CMD_CANCEL_ALL_COMMANDS, 106 PVAE_CMD_STOP_MAX_SIZE, 107 PVAE_CMD_STOP_MAX_DURATION, 108 PVAE_CMD_STOP_EOS_REACHED, 109 PVAE_CMD_CAPCONFIG_SET_PARAMETERS 110 } PVAECmdType; 111 112 // Structure to hold the key string info for 113 // player engine's capability-and-config 114 struct PVAuthorKeyStringData 115 { 116 char iString[64]; 117 PvmiKvpType iType; 118 PvmiKvpValueType iValueType; 119 }; 120 121 // The number of characters to allocate for the key string 122 #define PVAUTHORCONFIG_KEYSTRING_SIZE 128 123 124 // Key string info at the base level ("x-pvmf/author/") 125 #define PVAUTHORCONFIG_BASE_NUMKEYS 3 126 const PVAuthorKeyStringData PVAuthorConfigBaseKeys[PVAUTHORCONFIG_BASE_NUMKEYS] = 127 { 128 //These are dummy keys, to be changed in future 129 {"dummy1", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_INT32}, 130 {"dummy2", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_INT32}, 131 //It is necessary to have this key for the PVAuthorConfigProdInfoKeys to work 132 //Do not change the position of this key in the array 133 {"productinfo", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_INT32} 134 //add more keys here 135 }; 136 137 // Key string info at the productinfo level ("x-pvmf/author/productinfo/") 138 #define PVAUTHORCONFIG_PRODINFO_NUMKEYS 2 139 const PVAuthorKeyStringData PVAuthorConfigProdInfoKeys[PVAUTHORCONFIG_PRODINFO_NUMKEYS] = 140 { 141 {"dummyprod1", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_INT32}, 142 {"dummyprod2", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_INT32} 143 }; 144 145 146 /** 147 * PVAuthorEngine Class 148 */ 149 class PVAuthorEngine : public PVAuthorEngineInterface, 150 public OsclTimerObject, 151 public PVMFNodeErrorEventObserver, 152 public PVMFNodeInfoEventObserver, 153 public PVAENodeUtilObserver, 154 public PvmiCapabilityAndConfig 155 { 156 public: 157 static PVAuthorEngineInterface* Create(PVCommandStatusObserver* aCmdStatusObserver, 158 PVErrorEventObserver *aErrorEventObserver, PVInformationalEventObserver *aInfoEventObserver); 159 ~PVAuthorEngine(); 160 161 ///////////////////////////////////////////////////////// 162 // Pure virtuals from PVAuthorEngineInterface 163 ///////////////////////////////////////////////////////// 164 OSCL_IMPORT_REF PVCommandId SetLogAppender(const char* aTag, PVLoggerAppender& aAppender, 165 const OsclAny* aContextData = NULL); 166 OSCL_IMPORT_REF PVCommandId RemoveLogAppender(const char* aTag, PVLoggerAppender& aAppender, 167 const OsclAny* aContextData = NULL); 168 OSCL_IMPORT_REF PVCommandId SetLogLevel(const char* aTag, int32 aLevel, bool aSetSubtree = false, 169 const OsclAny* aContextData = NULL); 170 OSCL_IMPORT_REF PVCommandId GetLogLevel(const char* aTag, PVLogLevelInfo& aLogInfo, const OsclAny* aContextData = NULL); 171 OSCL_IMPORT_REF PVCommandId Open(const OsclAny* aContextData = NULL); 172 OSCL_IMPORT_REF PVCommandId Close(const OsclAny* aContextData = NULL); 173 OSCL_IMPORT_REF PVCommandId AddDataSource(const PVMFNodeInterface& aDataSource, const OsclAny* aContextData = NULL); 174 OSCL_IMPORT_REF PVCommandId RemoveDataSource(const PVMFNodeInterface& aDataSource, const OsclAny* aContextData = NULL); 175 OSCL_IMPORT_REF PVCommandId SelectComposer(const PvmfMimeString& aComposerType, PVInterface*& aConfigInterface, 176 const OsclAny* aContextData = NULL); 177 OSCL_IMPORT_REF PVCommandId SelectComposer(const PVUuid& aComposerUuid, PVInterface*& aConfigInterface, 178 const OsclAny* aContextData = NULL); 179 OSCL_IMPORT_REF PVCommandId AddMediaTrack(const PVMFNodeInterface& aDataSource, const PvmfMimeString& aEncoderType, 180 const OsclAny* aComposer, PVInterface*& aConfigInterface, 181 const OsclAny* aContextData = NULL); 182 OSCL_IMPORT_REF PVCommandId AddMediaTrack(const PVMFNodeInterface& aDataSource, const PVUuid& aEncoderUuid, 183 const OsclAny* aComposer, PVInterface*& aConfigInterface, 184 const OsclAny* aContextData = NULL); 185 OSCL_IMPORT_REF PVCommandId AddDataSink(const PVMFNodeInterface& aDataSink, const OsclAny* aComposer, 186 const OsclAny* aContextData = NULL); 187 OSCL_IMPORT_REF PVCommandId RemoveDataSink(const PVMFNodeInterface& aDataSink, const OsclAny* aContextData = NULL); 188 OSCL_IMPORT_REF PVCommandId Init(const OsclAny* aContextData = NULL); 189 OSCL_IMPORT_REF PVCommandId Reset(const OsclAny* aContextData = NULL); 190 OSCL_IMPORT_REF PVCommandId Start(const OsclAny* aContextData = NULL); 191 OSCL_IMPORT_REF PVCommandId Pause(const OsclAny* aContextData = NULL); 192 OSCL_IMPORT_REF PVCommandId Resume(const OsclAny* aContextData = NULL); 193 OSCL_IMPORT_REF PVCommandId Stop(const OsclAny* aContextData = NULL); 194 OSCL_IMPORT_REF PVCommandId QueryUUID(const PvmfMimeString& aMimeType, 195 Oscl_Vector<PVUuid, OsclMemAllocator>& aUuids, 196 bool aExactUuidsOnly = false, 197 const OsclAny* aContextData = NULL); 198 OSCL_IMPORT_REF PVCommandId QueryInterface(const PVUuid& aUuid, 199 PVInterface*& aInterfacePtr, 200 const OsclAny* aContextData = NULL); 201 OSCL_IMPORT_REF PVAEState GetPVAuthorState(); 202 OSCL_IMPORT_REF PVCommandId GetSDKInfo(PVSDKInfo& aSDKInfo, const OsclAny* aContextData = NULL); 203 OSCL_IMPORT_REF PVCommandId GetSDKModuleInfo(PVSDKModuleInfo& aSDKModuleInfo, const OsclAny* aContextData = NULL); 204 OSCL_IMPORT_REF PVCommandId CancelAllCommands(const OsclAny* aContextData = NULL); 205 206 // Implement pure virtual from PVMFNodeErrorEventObserver 207 void HandleNodeErrorEvent(const PVMFAsyncEvent& aEvent); 208 209 // Implement pure virtual from PVMFNodeInfoEventObserver 210 void HandleNodeInformationalEvent(const PVMFAsyncEvent& aEvent); 211 212 // Implement pure virtuals from PVAENodeUtilObserver 213 void NodeUtilCommandCompleted(const PVMFCmdResp& aResponse); 214 void NodeUtilErrorEvent(const PVMFAsyncEvent& aEvent); 215 // capability and configuration class implemented here 216 // virtual functions of PvmiCapabilityAndConfig class implemented here 217 218 void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver); 219 PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements, PvmiCapabilityContext aContext); 220 PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements); 221 void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 222 void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext, PvmiKvp* aParameters, int aNumParamElements); 223 void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 224 void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements, PvmiKvp* &aRetKVP); 225 PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements, PvmiKvp*& aRetKVP, OsclAny* aContext = NULL); 226 uint32 getCapabilityMetric(PvmiMIOSession aSession); 227 PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements); 228 // functions used by cap-config class virtual functions 229 bool queryInterface(const PVUuid& uuid, PVInterface*& iface); 230 PVMFStatus DoQueryNodeCapConfig(char* aKeySubString, Oscl_Vector<PVInterface*, OsclMemAllocator>& aNodeCapConfigIF); 231 void addRef(); 232 void removeRef(); 233 private: 234 PVAuthorEngine(); 235 void Construct(PVCommandStatusObserver *aCmdObserver, PVErrorEventObserver *aErrorObserver, 236 PVInformationalEventObserver *aInfoObserver); 237 238 // From OsclTimerObject 239 void Run(); 240 241 // Command handling functions 242 void Dispatch(PVEngineCommand& aCmd); 243 void Dispatch(PVEngineAsyncEvent& aEvent); 244 void PushCmdInFront(PVEngineCommand& aCmd); 245 void CompleteEngineCommand(PVEngineCommand& aCmd, PVMFStatus aStatus, 246 OsclAny* aResponseData = NULL, int32 aResponseDataSize = 0); 247 PVMFStatus DoOpen(PVEngineCommand& aCmd); 248 PVMFStatus DoClose(PVEngineCommand& aCmd); 249 PVMFStatus DoAddDataSource(PVEngineCommand& aCmd); 250 PVMFStatus DoRemoveDataSource(PVEngineCommand& aCmd); 251 PVMFStatus DoSelectComposer(PVEngineCommand& aCmd); 252 PVMFStatus DoAddMediaTrack(PVEngineCommand& aCmd); 253 PVMFStatus DoAddDataSink(PVEngineCommand& aCmd); 254 PVMFStatus DoRemoveDataSink(PVEngineCommand& aCmd); 255 PVMFStatus DoInit(PVEngineCommand& aCmd); 256 PVMFStatus DoReset(PVEngineCommand& aCmd); 257 PVMFStatus DoStart(PVEngineCommand& aCmd); 258 PVMFStatus DoPause(PVEngineCommand& aCmd); 259 PVMFStatus DoResume(PVEngineCommand& aCmd); 260 PVMFStatus DoStop(PVEngineCommand& aCmd); 261 PVMFStatus DoQueryInterface(PVEngineCommand& aCmd); 262 PVMFStatus DoStopMaxSizeDuration(); 263 264 // Registry function 265 PVMFStatus QueryRegistry(const PvmfMimeString& aMimeType, PVUuid& aUuid); 266 267 // Author engine state functions 268 void SetPVAEState(PVAEState aState); GetPVAEState()269 PVAEState GetPVAEState() 270 { 271 return iState; 272 } 273 274 // Find the container that holds the specified node 275 PVAENodeContainer* GetNodeContainer(PVAENodeContainerVector& aNodeContainerVector, PVMFNodeInterface* aNode); 276 277 /** 278 * Check if the specified format is supported 279 */ 280 PVMFStatus IsCompressedFormatDataSource(PVAENodeContainer* aDataSrc, bool& aIsCompressedFormat); 281 282 /** 283 * Resets the graph. All nodes will be disconnected. 284 */ 285 void ResetGraph(); 286 287 /** 288 * All nodes(except source nodes) will be destroyed. 289 * All nodes are removed from node vectors. 290 * Source node pools are destroyed when RemoveDataSource API is executed. 291 */ 292 void ResetNodeContainers(); 293 /** 294 * Query configuration interface for the specified encoder or composer node 295 * 296 * When implementing support for a new composer or encoder node, this method will 297 * need to be modified to query for configuration interface(s) of the new node. 298 * 299 * @param aNodeContainer Node container of composer node to perform query on 300 * @return Completion status 301 */ 302 PVMFStatus QueryNodeConfig(PVAENodeContainer* aNodeContainer, PVInterface*& aInterface); 303 304 /** 305 * Configure file format composer 306 * 307 * When implementing support for a new file format composer node, this method will 308 * need to be updated to configure the new composer node. 309 * 310 * @param aComposerMimeType Composer Mime type 311 * @return Completion status 312 */ 313 PVMFStatus ConfigureComposer(const PvmfMimeString& aComposerMimeType); 314 315 /** 316 * Configure encoder 317 * 318 * If the encoder node supports multiple output formats, the engine will need to 319 * configure the encoder to encode output to the format type specified by the 320 * client in AddMediaTrack. 321 * 322 * When implementing support for a new encoder node, this method might need to 323 * be updated to configure the new node. 324 * 325 * @param aMimeType Encoder Mime type specified by client 326 * @return Completion status 327 */ 328 PVMFStatus ConfigureEncoder(const PvmfMimeString& aMimeType); 329 330 /** 331 * Get the PVMFFormatType corresponding to the specified encoder mime type 332 * 333 * When implementing support for a new encoding type, this method will need 334 * to be updated to return the format type mapped to this new encoding type. 335 * 336 * @param aFormatType Output parameter to store the PVMFFormatType 337 * @param aMimeType Mime type to be converted to PVMFFormatType 338 * @return PVMFSuccess if a mapping for the Mime type is found, else return PVMFFailure. 339 */ 340 PVMFStatus GetPvmfFormatString(PvmfMimeString& aMimeType, const PvmfMimeString& aNodeMimeType); 341 342 PVAENodeContainer* AllocateNodeContainer(PVMFNodeInterface* aNode); 343 PVMFStatus DeallocateNodeContainer(PVAENodeContainerVector& aVector, PVMFNodeInterface* aNode); 344 345 // private functions used internally in cap-config class functions 346 //f(n) used in SetParametersSync function of cap-config class 347 PVMFStatus DoCapConfigSetParameters(PVEngineCommand& aCmd, bool aSyncCmd = false); // f(n) used in SetParametersSync function of cap-config class 348 //f(n) used in GetParametersSync function of cap-config class 349 PVMFStatus DoCapConfigGetParametersSync(PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements, PvmiCapabilityContext aContext); 350 //f(n) used in ReleaseParametersSync function of cap-config class 351 PVMFStatus DoCapConfigReleaseParameters(PvmiKvp* aParameters, int aNumElements); 352 //f(n) used in VerifyParametersSync function of cap-config class 353 PVMFStatus DoCapConfigVerifyParameters(PvmiKvp* aParameters, int aNumElements); 354 PVMFStatus DoVerifyAndSetAuthorParameter(PvmiKvp& aParameter, bool aSetParam); 355 PVMFStatus DoVerifyAndSetAuthorProductInfoParameter(PvmiKvp& aParameter, bool aSetParam); 356 PVMFStatus DoGetAuthorProductInfoParameter(PvmiKvp*& aParameters, int& aNumParamElements, int32 aIndex, PvmiKvpAttr reqattr); 357 PVMFStatus DoGetAuthorParameter(PvmiKvp*& aParameters, int& aNumParamElements, int32 aIndex, PvmiKvpAttr reqattr); 358 private: 359 360 // Engine commands 361 Oscl_Vector<PVEngineCommand, OsclMemAllocator> iPendingCmds; 362 Oscl_Vector<PVEngineAsyncEvent, OsclMemAllocator> iPendingEvents; 363 PVCommandId iCommandId; 364 365 // Engine observers 366 PVCommandStatusObserver* iCmdStatusObserver; 367 PVInformationalEventObserver* iInfoEventObserver; 368 PVErrorEventObserver* iErrorEventObserver; 369 370 // Node utility and storage 371 PVAuthorEngineNodeUtility iNodeUtil; 372 PVAENodeContainerVector iDataSourcePool; 373 PVAENodeContainerVector iDataSinkPool; 374 PVAENodeContainerVector iDataSourceNodes; 375 PVAENodeContainerVector iEncoderNodes; 376 PVAENodeContainerVector iComposerNodes; 377 PVAENodeContainerVector iAllNodes; 378 379 PVMFFormatType iEncodedVideoFormat; 380 PVAEState iState; 381 PVLogger* iLogger; 382 int32 iCapConfigContext; 383 PvmiConfigAndCapabilityCmdObserver *iCfgCapCmdObserver; 384 int iAsyncNumElements; 385 bool iDoResetNodeContainers; 386 387 //authoring clock related 388 PVMFTimebase_Tickcount iAuthorClockTimebase; 389 PVMFMediaClock iAuthorClock; 390 PVMFStatus SendAuthoringClockToDataSources(bool aReset = false); 391 392 PVMFStatus lastNodeCommandError; 393 }; 394 395 396 397 #endif // PVAUTHORENGINE_H_INCLUDED 398 399 400