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_OMX_BASEDEC_NODE_H_INCLUDED 19 #define PVMF_OMX_BASEDEC_NODE_H_INCLUDED 20 21 #ifndef OSCL_BASE_H_INCLUDED 22 #include "oscl_base.h" 23 #endif 24 25 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED 26 #include "oscl_scheduler_ao.h" 27 #endif 28 29 #ifndef PVMF_FORMAT_TYPE_H_INCLUDED 30 #include "pvmf_format_type.h" 31 #endif 32 33 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED 34 #include "pvmf_node_interface.h" 35 #endif 36 37 #ifndef OSCL_PRIQUEUE_H_INCLUDED 38 #include "oscl_priqueue.h" 39 #endif 40 41 #ifndef PVMF_MEDIA_DATA_H_INCLUDED 42 #include "pvmf_media_data.h" 43 #endif 44 45 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED 46 #include "oscl_mem_mempool.h" 47 #endif 48 #ifndef PVMF_MEMPOOL_H_INCLUDED 49 #include "pvmf_mempool.h" 50 #endif 51 52 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED 53 #include "pvmf_simple_media_buffer.h" 54 #endif 55 56 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED 57 #include "pvmf_pool_buffer_allocator.h" 58 #endif 59 60 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED 61 #include "pvmf_pool_buffer_allocator.h" 62 #endif 63 64 #ifndef PVMF_NODE_UTILS_H_INCLUDED 65 #include "pvmf_node_utils.h" 66 #endif 67 68 #ifndef PVMF_OMX_BASEDEC_PORT_H_INCLUDED 69 #include "pvmf_omx_basedec_port.h" 70 #endif 71 72 #ifndef PVMF_OMX_BASEDEC_NODE_EXTENSION_INTERFACE_H_INCLUDED 73 #include "pvmf_omx_basedec_node_extension_interface.h" 74 #endif 75 76 #ifndef PVMF_META_DATA_EXTENSION_H_INCLUDED 77 #include "pvmf_meta_data_extension.h" 78 #endif 79 80 #ifndef PV_MIME_STRING_UTILS_H_INCLUDED 81 #include "pv_mime_string_utils.h" 82 #endif 83 84 #ifndef OMX_Core_h 85 #include "OMX_Core.h" 86 #endif 87 88 #ifndef OMX_Component_h 89 #include "OMX_Component.h" 90 #endif 91 92 #ifndef PVMF_OMX_BASEDEC_CALLBACKS_H_INCLUDED 93 #include "pvmf_omx_basedec_callbacks.h" 94 #endif 95 96 #ifndef OSCLCONFIG_IO_H_INCLUDED 97 #include "osclconfig_io.h" 98 #endif 99 #ifndef OSCL_MEM_H_INCLUDED 100 #include "oscl_mem.h" 101 #endif 102 103 #if (PVLOGGER_INST_LEVEL >= PVLOGMSG_INST_REL) 104 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED 105 #include "pvmf_media_clock.h" 106 #endif 107 #endif 108 109 #ifndef PVMF_FIXEDSIZE_BUFFER_ALLOC_H_INCLUDED 110 #include "pvmf_fixedsize_buffer_alloc.h" 111 #endif 112 113 #ifndef __MEDIA_CLOCK_CONVERTER_H 114 #include "media_clock_converter.h" 115 #endif 116 117 #define MAX_NAL_PER_FRAME 100 118 119 typedef struct OutputBufCtrlStruct 120 { 121 OMX_BUFFERHEADERTYPE *pBufHdr; 122 } OutputBufCtrlStruct; 123 124 #if 0 125 typedef struct InputBufCtrlStruct 126 { 127 OMX_BUFFERHEADERTYPE *pBufHdr; 128 PVMFSharedMediaDataPtr pMediaData; 129 } InputBufCtrlStruct; 130 #else 131 class InputBufCtrlStruct 132 { 133 public: 134 InputBufCtrlStruct(): pBufHdr(NULL) {} 135 136 public: 137 OMX_BUFFERHEADERTYPE *pBufHdr; 138 PVMFSharedMediaDataPtr pMediaData; 139 }; 140 #endif 141 142 143 // fwd class declaration 144 class PVLogger; 145 //memory allocator type for this node. 146 typedef OsclMemAllocator PVMFOMXBaseDecNodeAllocator; 147 148 149 // CALLBACK PROTOTYPES 150 OMX_ERRORTYPE CallbackEventHandler(OMX_OUT OMX_HANDLETYPE aComponent, 151 OMX_OUT OMX_PTR aAppData, 152 OMX_OUT OMX_EVENTTYPE aEvent, 153 OMX_OUT OMX_U32 aData1, 154 OMX_OUT OMX_U32 aData2, 155 OMX_OUT OMX_PTR aEventData); 156 157 OMX_ERRORTYPE CallbackEmptyBufferDone(OMX_OUT OMX_HANDLETYPE aComponent, 158 OMX_OUT OMX_PTR aAppData, 159 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer); 160 161 OMX_ERRORTYPE CallbackFillBufferDone(OMX_OUT OMX_HANDLETYPE aComponent, 162 OMX_OUT OMX_PTR aAppData, 163 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer); 164 165 166 167 //Default values for number of Input/Output buffers. If the component needs more than this, it will be 168 // negotiated. If the component does not need more than this number, the default is used 169 #define NUMBER_INPUT_BUFFER 5 170 #define NUMBER_OUTPUT_BUFFER 9 171 172 // nal start code is 0001 173 #define NAL_START_CODE_SIZE 4 174 const unsigned char NAL_START_CODE[4] = {0, 0, 0, 1}; 175 176 //////////////////////////////////////////////////////////////////////////////////////////////////////////// 177 //////////////////////////////////////////////////////////////////////////////////////////////////////////// 178 ///////////////////////// 179 ///////////////////////// 180 ///////////////////////// 181 // CUSTOM DEALLOCATOR FOR MEDIA DATA SHARED PTR WRAPPER: 182 // 1) Deallocates the underlying output buffer 183 // 2) Deallocates the pvci buffer wrapper and the rest of accompanying structures 184 // Deallocator is created as part of the wrapper, and travels with the buffer wrapper 185 186 class PVOMXDecBufferSharedPtrWrapperCombinedCleanupDA : public OsclDestructDealloc 187 { 188 public: 189 PVOMXDecBufferSharedPtrWrapperCombinedCleanupDA(Oscl_DefAlloc* allocator, void *pMempoolData) : 190 buf_alloc(allocator), ptr_to_data_to_dealloc(pMempoolData) {}; 191 virtual ~PVOMXDecBufferSharedPtrWrapperCombinedCleanupDA() {}; 192 193 virtual void destruct_and_dealloc(OsclAny* ptr) 194 { 195 // call buffer deallocator 196 if (buf_alloc != NULL) 197 { 198 buf_alloc->deallocate(ptr_to_data_to_dealloc); 199 } 200 201 // finally, free the shared ptr wrapper memory 202 oscl_free(ptr); 203 } 204 205 private: 206 Oscl_DefAlloc* buf_alloc; 207 void *ptr_to_data_to_dealloc; 208 }; 209 210 211 #define PVMFOMXBaseDecNodeCommandBase PVMFGenericNodeCommand<PVMFOMXBaseDecNodeAllocator> 212 213 class PVMFOMXBaseDecNodeCommand: public PVMFOMXBaseDecNodeCommandBase 214 { 215 public: 216 //constructor for Custom2 command 217 void Construct(PVMFSessionId s, int32 cmd, int32 arg1, int32 arg2, int32& arg3, const OsclAny*aContext) 218 { 219 PVMFOMXBaseDecNodeCommandBase::Construct(s, cmd, aContext); 220 iParam1 = (OsclAny*)arg1; 221 iParam2 = (OsclAny*)arg2; 222 iParam3 = (OsclAny*) & arg3; 223 } 224 void Parse(int32&arg1, int32&arg2, int32*&arg3) 225 { 226 arg1 = (int32)iParam1; 227 arg2 = (int32)iParam2; 228 arg3 = (int32*)iParam3; 229 } 230 231 void Construct(PVMFSessionId s, int32 cmd, PVMFMetadataList* aKeyList, uint32 aStartIndex, int32 aMaxEntries, char* aQueryKey, const OsclAny* aContext) 232 { 233 PVMFOMXBaseDecNodeCommandBase::Construct(s, cmd, aContext); 234 iStartIndex = aStartIndex; 235 iMaxEntries = aMaxEntries; 236 237 if (aQueryKey == NULL) 238 { 239 query_key[0] = 0; 240 } 241 else 242 { 243 if (aQueryKey != NULL) 244 oscl_strncpy(query_key, aQueryKey, oscl_strlen(aQueryKey) + 1); 245 } 246 247 iParam1 = (OsclAny*)aKeyList; 248 iParam2 = NULL; 249 iParam3 = NULL; 250 iParam4 = NULL; 251 iParam5 = NULL; 252 } 253 254 void Parse(PVMFMetadataList*& MetaDataListPtr, uint32 &aStartingIndex, int32 &aMaxEntries, char*&aQueryKey) 255 { 256 MetaDataListPtr = (PVMFMetadataList*)iParam1; 257 aStartingIndex = iStartIndex; 258 aMaxEntries = iMaxEntries; 259 if (query_key[0] == 0) 260 { 261 aQueryKey = NULL; 262 } 263 else 264 { 265 aQueryKey = query_key; 266 } 267 } 268 269 // Constructor and parser for GetNodeMetadataValue 270 void Construct(PVMFSessionId s, int32 cmd, PVMFMetadataList* aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>* aValueList, uint32 aStartIndex, int32 aMaxEntries, const OsclAny* aContext) 271 { 272 PVMFOMXBaseDecNodeCommandBase::Construct(s, cmd, aContext); 273 iParam1 = (OsclAny*)aKeyList; 274 iParam2 = (OsclAny*)aValueList; 275 276 iStartIndex = aStartIndex; 277 iMaxEntries = aMaxEntries; 278 279 iParam3 = NULL; 280 iParam4 = NULL; 281 iParam5 = NULL; 282 } 283 void Parse(PVMFMetadataList* &aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>* &aValueList, uint32 &aStartingIndex, int32 &aMaxEntries) 284 { 285 aKeyList = (PVMFMetadataList*)iParam1; 286 aValueList = (Oscl_Vector<PvmiKvp, OsclMemAllocator>*)iParam2; 287 aStartingIndex = iStartIndex; 288 aMaxEntries = iMaxEntries; 289 } 290 291 virtual bool hipri() 292 { 293 //this routine identifies commands that need to 294 //go at the front of the queue. derived command 295 //classes can override it if needed. 296 return (iCmd == PVOMXBASEDEC_NODE_CMD_CANCELALL 297 || iCmd == PVOMXBASEDEC_NODE_CMD_CANCELCMD); 298 } 299 300 enum PVOMXBaseDecNodeCmdType 301 { 302 PVOMXBASEDEC_NODE_CMD_QUERYUUID, 303 PVOMXBASEDEC_NODE_CMD_QUERYINTERFACE, 304 PVOMXBASEDEC_NODE_CMD_INIT, 305 PVOMXBASEDEC_NODE_CMD_PREPARE, 306 PVOMXBASEDEC_NODE_CMD_REQUESTPORT, 307 PVOMXBASEDEC_NODE_CMD_START, 308 PVOMXBASEDEC_NODE_CMD_PAUSE, 309 PVOMXBASEDEC_NODE_CMD_STOP, 310 PVOMXBASEDEC_NODE_CMD_FLUSH, 311 PVOMXBASEDEC_NODE_CMD_RELEASEPORT, 312 PVOMXBASEDEC_NODE_CMD_RESET, 313 PVOMXBASEDEC_NODE_CMD_CANCELCMD, 314 PVOMXBASEDEC_NODE_CMD_CANCELALL, 315 PVOMXBASEDEC_NODE_CMD_INVALID, 316 PVOMXBASEDEC_NODE_CMD_GETNODEMETADATAKEY, 317 PVOMXBASEDEC_NODE_CMD_GETNODEMETADATAVALUE 318 }; 319 320 private: 321 uint32 iStartIndex; 322 uint32 iMaxEntries; 323 char query_key[256]; 324 325 }; 326 327 //Default vector reserve size 328 #define PVMF_OMXBASEDEC_NODE_COMMAND_VECTOR_RESERVE 10 329 330 //Starting value for command IDs 331 #define PVMF_OMXBASEDEC_NODE_COMMAND_ID_START 6000 332 333 /////////////////////////////////////////////////////////////////////////////////////////////////////// 334 //CAPABILITY AND CONFIG 335 336 // Structure to hold the key string info for 337 // capability-and-config 338 struct PVOMXBaseDecNodeKeyStringData 339 { 340 char iString[64]; 341 PvmiKvpType iType; 342 PvmiKvpValueType iValueType; 343 }; 344 345 // The number of characters to allocate for the key string 346 #define PVOMXBASEDECNODECONFIG_KEYSTRING_SIZE 128 347 348 //Mimetypes for the custom interface 349 #define PVMF_OMX_BASE_DEC_NODE_MIMETYPE "pvxxx/OMXBaseDecNode" 350 #define PVMF_BASEMIMETYPE "pvxxx" 351 352 //Command queue type 353 typedef PVMFNodeCommandQueue<PVMFOMXBaseDecNodeCommand, PVMFOMXBaseDecNodeAllocator> PVMFOMXBaseDecNodeCmdQ; 354 355 356 class PVMFOMXBaseDecNode 357 : public OsclActiveObject 358 , public PVMFNodeInterface 359 , public OsclMemPoolFixedChunkAllocatorObserver 360 , public PVMFOMXBaseDecNodeExtensionInterface 361 , public PVMFMetadataExtensionInterface 362 , public PvmiCapabilityAndConfig 363 364 { 365 public: 366 OSCL_IMPORT_REF PVMFOMXBaseDecNode(int32 aPriority, const char aAOName[], bool aHwAccelerated = true); 367 OSCL_IMPORT_REF virtual ~PVMFOMXBaseDecNode(); 368 369 // From PVMFNodeInterface 370 OSCL_IMPORT_REF virtual PVMFStatus ThreadLogon() = 0; 371 OSCL_IMPORT_REF PVMFStatus ThreadLogoff(); 372 OSCL_IMPORT_REF PVMFStatus GetCapability(PVMFNodeCapability& aNodeCapability); 373 OSCL_IMPORT_REF PVMFPortIter* GetPorts(const PVMFPortFilter* aFilter = NULL); 374 OSCL_IMPORT_REF PVMFCommandId QueryUUID(PVMFSessionId, const PvmfMimeString& aMimeType, 375 Oscl_Vector<PVUuid, PVMFOMXBaseDecNodeAllocator>& aUuids, 376 bool aExactUuidsOnly = false, 377 const OsclAny* aContext = NULL); 378 OSCL_IMPORT_REF PVMFCommandId QueryInterface(PVMFSessionId, const PVUuid& aUuid, 379 PVInterface*& aInterfacePtr, 380 const OsclAny* aContext = NULL); 381 OSCL_IMPORT_REF PVMFCommandId RequestPort(PVMFSessionId 382 , int32 aPortTag, const PvmfMimeString* aPortConfig = NULL, const OsclAny* aContext = NULL); 383 OSCL_IMPORT_REF PVMFCommandId ReleasePort(PVMFSessionId, PVMFPortInterface& aPort, const OsclAny* aContext = NULL); 384 OSCL_IMPORT_REF PVMFCommandId Init(PVMFSessionId, const OsclAny* aContext = NULL); 385 OSCL_IMPORT_REF PVMFCommandId Prepare(PVMFSessionId, const OsclAny* aContext = NULL); 386 OSCL_IMPORT_REF PVMFCommandId Start(PVMFSessionId, const OsclAny* aContext = NULL); 387 OSCL_IMPORT_REF PVMFCommandId Stop(PVMFSessionId, const OsclAny* aContext = NULL); 388 OSCL_IMPORT_REF PVMFCommandId Flush(PVMFSessionId, const OsclAny* aContext = NULL); 389 OSCL_IMPORT_REF PVMFCommandId Pause(PVMFSessionId, const OsclAny* aContext = NULL); 390 OSCL_IMPORT_REF PVMFCommandId Reset(PVMFSessionId, const OsclAny* aContext = NULL); 391 OSCL_IMPORT_REF PVMFCommandId CancelAllCommands(PVMFSessionId, const OsclAny* aContextData = NULL); 392 OSCL_IMPORT_REF PVMFCommandId CancelCommand(PVMFSessionId, PVMFCommandId aCmdId, const OsclAny* aContextData = NULL); 393 394 // From PVMFPortActivityHandler 395 OSCL_IMPORT_REF void HandlePortActivity(const PVMFPortActivity& aActivity); 396 397 // From PVInterface 398 OSCL_IMPORT_REF virtual void addRef(); 399 OSCL_IMPORT_REF virtual void removeRef(); 400 OSCL_IMPORT_REF virtual bool queryInterface(const PVUuid& uuid, PVInterface*& iface); 401 OSCL_IMPORT_REF virtual PVMFStatus SetDecoderNodeConfiguration(PVMFOMXBaseDecNodeConfig& aConfig); 402 403 //**********begin PVMFMetadataExtensionInterface 404 OSCL_IMPORT_REF virtual uint32 GetNumMetadataKeys(char* query_key = NULL) = 0; 405 OSCL_IMPORT_REF virtual uint32 GetNumMetadataValues(PVMFMetadataList& aKeyList) = 0; 406 OSCL_IMPORT_REF PVMFCommandId GetNodeMetadataKeys(PVMFSessionId aSessionId, PVMFMetadataList& aKeyList, uint32 starting_index, int32 max_entries, 407 char* query_key = NULL, const OsclAny* aContextData = NULL); 408 OSCL_IMPORT_REF PVMFCommandId GetNodeMetadataValues(PVMFSessionId aSessionId, PVMFMetadataList& aKeyList, 409 Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 starting_index, int32 max_entries, const OsclAny* aContextData = NULL); 410 OSCL_IMPORT_REF PVMFStatus ReleaseNodeMetadataKeys(PVMFMetadataList& aKeyList, uint32 starting_index, uint32 end_index); 411 OSCL_IMPORT_REF PVMFStatus ReleaseNodeMetadataValues(Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 starting_index, uint32 end_index); 412 //**********End PVMFMetadataExtensionInterface 413 OSCL_IMPORT_REF virtual bool VerifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements) = 0; 414 415 //********** CB Functions to serve OpenMAX Decoder 416 417 //Process callback functions. They will be executed in testapp thread context 418 // These callbacks are used only in the Multithreaded component case 419 OSCL_IMPORT_REF OsclReturnCode ProcessCallbackEventHandler_MultiThreaded(OsclAny* P); 420 OSCL_IMPORT_REF OsclReturnCode ProcessCallbackEmptyBufferDone_MultiThreaded(OsclAny* P); 421 OSCL_IMPORT_REF OsclReturnCode ProcessCallbackFillBufferDone_MultiThreaded(OsclAny* P); 422 423 //Callback objects - again, these are used only in the case of Multithreaded component 424 EventHandlerThreadSafeCallbackAO* iThreadSafeHandlerEventHandler; 425 EmptyBufferDoneThreadSafeCallbackAO* iThreadSafeHandlerEmptyBufferDone; 426 FillBufferDoneThreadSafeCallbackAO* iThreadSafeHandlerFillBufferDone; 427 428 OMX_CALLBACKTYPE iCallbacks; // structure that contains callback ptrs. 429 // OMX CALLBACKS 430 // 1) AO OMX component running in the same thread as the OMX node 431 // In this case, the callbacks can be called directly from the component 432 // The callback: OMX Component->CallbackEventHandler->EventHandlerProcessing 433 // The callback can perform do RunIfNotReady 434 435 // 2) Multithreaded component 436 // In this case, the callback is made using the threadsafe callback (TSCB) AO 437 // Component thread : OMX Component->CallbackEventHandler->TSCB(ReceiveEvent) 438 // Node thread : TSCB(ProcessEvent)->ProcessCallbackEventHandler_MultiThreaded->EventHandlerProcessing 439 440 441 //============================================================================== 442 443 OSCL_IMPORT_REF virtual OMX_ERRORTYPE EventHandlerProcessing(OMX_OUT OMX_HANDLETYPE aComponent, 444 OMX_OUT OMX_PTR aAppData, 445 OMX_OUT OMX_EVENTTYPE aEvent, 446 OMX_OUT OMX_U32 aData1, 447 OMX_OUT OMX_U32 aData2, 448 OMX_OUT OMX_PTR aEventData) = 0; 449 450 OSCL_IMPORT_REF OMX_ERRORTYPE EmptyBufferDoneProcessing(OMX_OUT OMX_HANDLETYPE aComponent, 451 OMX_OUT OMX_PTR aAppData, 452 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer); 453 454 OSCL_IMPORT_REF OMX_ERRORTYPE FillBufferDoneProcessing(OMX_OUT OMX_HANDLETYPE aComponent, 455 OMX_OUT OMX_PTR aAppData, 456 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer); 457 458 bool IsComponentMultiThreaded() 459 { 460 return iIsOMXComponentMultiThreaded; 461 }; 462 463 // From PvmiCapabilityAndConfig 464 OSCL_IMPORT_REF void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver); 465 OSCL_IMPORT_REF PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements, PvmiCapabilityContext aContext); 466 OSCL_IMPORT_REF PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements); 467 OSCL_IMPORT_REF void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 468 OSCL_IMPORT_REF void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext, PvmiKvp* aParameters, int aNumParamElements); 469 OSCL_IMPORT_REF void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 470 OSCL_IMPORT_REF void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements, PvmiKvp* &aRetKVP); 471 OSCL_IMPORT_REF PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements, PvmiKvp*& aRetKVP, OsclAny* aContext = NULL); 472 OSCL_IMPORT_REF uint32 getCapabilityMetric(PvmiMIOSession aSession); 473 OSCL_IMPORT_REF PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements); 474 OSCL_IMPORT_REF virtual bool ProcessIncomingMsg(PVMFPortInterface* aPort); 475 OSCL_IMPORT_REF void Run(); 476 protected: 477 OSCL_IMPORT_REF void CommandComplete(PVMFOMXBaseDecNodeCmdQ& aCmdQ, PVMFOMXBaseDecNodeCommand& aCmd, PVMFStatus aStatus, OsclAny* aEventData = NULL); 478 479 virtual void DoQueryUuid(PVMFOMXBaseDecNodeCommand&) = 0; 480 void DoQueryInterface(PVMFOMXBaseDecNodeCommand&); 481 virtual void DoRequestPort(PVMFOMXBaseDecNodeCommand&) = 0; 482 virtual void DoReleasePort(PVMFOMXBaseDecNodeCommand&) = 0; 483 void DoInit(PVMFOMXBaseDecNodeCommand&); 484 void DoPrepare(PVMFOMXBaseDecNodeCommand&); 485 void DoStart(PVMFOMXBaseDecNodeCommand&); 486 void DoStop(PVMFOMXBaseDecNodeCommand&); 487 void DoPause(PVMFOMXBaseDecNodeCommand&); 488 void DoReset(PVMFOMXBaseDecNodeCommand&); 489 void DoFlush(PVMFOMXBaseDecNodeCommand&); 490 virtual PVMFStatus DoGetNodeMetadataKey(PVMFOMXBaseDecNodeCommand&) = 0; 491 virtual PVMFStatus DoGetNodeMetadataValue(PVMFOMXBaseDecNodeCommand&) = 0; 492 void DoCancelAllCommands(PVMFOMXBaseDecNodeCommand&); 493 void DoCancelCommand(PVMFOMXBaseDecNodeCommand&); 494 495 bool ProcessCommand(PVMFOMXBaseDecNodeCommand& aCmd); 496 bool ProcessOutgoingMsg(PVMFPortInterface* aPort); 497 PVMFStatus HandleProcessingState(); 498 virtual PVMFStatus HandlePortReEnable() = 0; 499 500 virtual bool InitDecoder(PVMFSharedMediaDataPtr&) = 0; 501 502 OSCL_IMPORT_REF OsclAny* AllocateKVPKeyArray(int32& aLeaveCode, PvmiKvpValueType aValueType, int32 aNumElements); 503 int32 PushKVPKey(OSCL_HeapString<OsclMemAllocator>& aString, PVMFMetadataList* aKeyList) 504 { 505 int32 leavecode = OsclErrNone; 506 OSCL_TRY(leavecode, aKeyList->push_back(aString)); 507 return leavecode; 508 } 509 510 int32 PushKVPKey(const char* aString, PVMFMetadataList& aKeyList) 511 { 512 int32 leavecode = OsclErrNone; 513 OSCL_TRY(leavecode, aKeyList.push_back(aString)); 514 return leavecode; 515 } 516 517 int32 PushKVP(PvmiKvp aKVP, Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList) 518 { 519 int32 leavecode = OsclErrNone; 520 OSCL_TRY(leavecode, aValueList.push_back(aKVP)); 521 return leavecode; 522 } 523 524 int32 AllocateChunkFromMemPool(OsclAny*& aCtrlStructPtr, OsclMemPoolFixedChunkAllocator *aMemPool, int32 aAllocSize) 525 { 526 int32 leavecode = OsclErrNone; 527 OSCL_TRY(leavecode, aCtrlStructPtr = (OsclAny *) aMemPool->allocate(aAllocSize)); 528 return leavecode; 529 } 530 531 // DV: 532 virtual bool NegotiateComponentParameters(OMX_PTR aOutputParameters) = 0; 533 534 bool SetDefaultCapabilityFlags(); 535 OSCL_IMPORT_REF bool CreateOutMemPool(uint32 num); 536 OSCL_IMPORT_REF bool CreateInputMemPool(uint32 num); 537 OSCL_IMPORT_REF bool ProvideBuffersToComponent(OsclMemPoolFixedChunkAllocator *aMemPool, // allocator 538 uint32 aAllocSize, // size to allocate from pool (hdr only or hdr+ buffer) 539 uint32 aNumBuffers, // number of buffers 540 uint32 aActualBufferSize, // aactual buffer size 541 uint32 aPortIndex, // port idx 542 bool aUseBufferOK, // can component use OMX_UseBuffer? 543 bool aIsThisInputBuffer // is this input or output 544 ); 545 546 bool FreeBuffersFromComponent(OsclMemPoolFixedChunkAllocator *aMemPool, // allocator 547 uint32 aAllocSize, // size to allocate from pool (hdr only or hdr+ buffer) 548 uint32 aNumBuffers, // number of buffers 549 uint32 aPortIndex, // port idx 550 bool aIsThisInputBuffer // is this input or output 551 ); 552 553 OsclSharedPtr<class PVMFMediaDataImpl> WrapOutputBuffer(uint8 *pData, uint32 aDataLen, OsclAny *pContext); 554 virtual bool QueueOutputBuffer(OsclSharedPtr<PVMFMediaDataImpl> &mediadataimplout, uint32 aDataLen) = 0; 555 556 bool SendOutputBufferToOMXComponent(); 557 OSCL_IMPORT_REF bool SendInputBufferToOMXComponent(); 558 559 OSCL_IMPORT_REF bool SendConfigBufferToOMXComponent(uint8 *initbuffer, uint32 initbufsize); 560 bool SendEOSBufferToOMXComponent(); 561 562 bool HandleRepositioning(void); 563 bool SendBeginOfMediaStreamCommand(void); 564 bool SendEndOfTrackCommand(void); 565 566 bool AppendExtraDataToBuffer(InputBufCtrlStruct* aInputBuffer, OMX_EXTRADATATYPE aType, uint8* aExtraData, uint8 aDataLength); 567 568 virtual bool ReleaseAllPorts() = 0; 569 bool DeleteOMXBaseDecoder(); 570 571 OSCL_IMPORT_REF void ChangeNodeState(TPVMFNodeInterfaceState aNewState); 572 573 OSCL_IMPORT_REF void HandleComponentStateChange(OMX_U32 decoder_state); 574 575 // Capability And Config Helper Methods 576 OSCL_IMPORT_REF virtual PVMFStatus DoCapConfigGetParametersSync(PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements, PvmiCapabilityContext aContext); 577 OSCL_IMPORT_REF virtual PVMFStatus DoCapConfigReleaseParameters(PvmiKvp* aParameters, int aNumElements); 578 OSCL_IMPORT_REF virtual void DoCapConfigSetParameters(PvmiKvp* aParameters, int aNumElements, PvmiKvp* &aRetKVP); 579 OSCL_IMPORT_REF virtual PVMFStatus DoCapConfigVerifyParameters(PvmiKvp* aParameters, int aNumElements); 580 581 // From OsclMemPoolFixedChunkAllocatorObserver 582 OSCL_IMPORT_REF void freechunkavailable(OsclAny*); 583 584 OSCL_IMPORT_REF PVMFCommandId QueueCommandL(PVMFOMXBaseDecNodeCommand& aCmd); 585 586 friend class PVMFOMXBaseDecPort; 587 588 // Ports pointers 589 PVMFPortInterface* iInPort; 590 PVMFPortInterface* iOutPort; 591 592 // Commands 593 PVMFOMXBaseDecNodeCmdQ iInputCommands; 594 PVMFOMXBaseDecNodeCmdQ iCurrentCommand; 595 596 // Shared pointer for Media Msg.Input buffer 597 PVMFSharedMediaDataPtr iDataIn; 598 599 // OUTPUT BUFFER RELATED MEMBERS 600 // Output buffer memory pool 601 OsclMemPoolFixedChunkAllocator *iOutBufMemoryPool; 602 603 // Memory pool for simple media data 604 OsclMemPoolFixedChunkAllocator *iMediaDataMemPool; 605 606 // Fragment pool for format specific info 607 PVMFBufferPoolAllocator iFsiFragmentAlloc; 608 // Fragment pool for private data format specific info 609 PVMFBufferPoolAllocator iPrivateDataFsiFragmentAlloc; 610 611 // Size of output buffer (negotiated with component) 612 uint32 iOMXComponentOutputBufferSize; 613 614 // size of output to allocate (OMX_ALLOCATE_BUFFER = size of buf header ) 615 // (OMX_USE_BUFFER = size of buf header + iOMXCoponentOutputBufferSize) 616 uint32 iOutputAllocSize; 617 618 // Number of output buffers (negotiated with component) 619 uint32 iNumOutputBuffers; 620 621 // Number of output buffers in possession of the component or downstream, 622 // namely, number of unavailable buffers 623 uint32 iNumOutstandingOutputBuffers; 624 625 // flag to prevent sending output buffers downstream during flushing etc. 626 bool iDoNotSendOutputBuffersDownstreamFlag; 627 628 // flag to prevent freeing the buffers twice 629 bool iOutputBuffersFreed; 630 631 632 OsclAny *ipPrivateData; 633 634 // INPUT BUFFER RELATED MEMBERS 635 OsclMemPoolFixedChunkAllocator *iInBufMemoryPool; 636 uint32 iOMXComponentInputBufferSize; // size of input buffer that the component sees (negotiated with the component) 637 uint32 iInputAllocSize; // size of input buffer to allocate (OMX_ALLOCATE_BUFFER = size of buf header ) 638 // (OMX_USE_BUFFER = size of buf header + iOMXCoponentInputBufferSize) 639 uint32 iNumInputBuffers; // total num of input buffers (negotiated with component) 640 641 uint32 iNumOutstandingInputBuffers; // number of input buffers in use (i.e. unavailable) 642 643 bool iDoNotSaveInputBuffersFlag; 644 645 // flag to prevent freeing buffers twice 646 bool iInputBuffersFreed; 647 648 // input buffer fragmentation etc. 649 uint32 iCopyPosition; // for copying memfrag data into a buffer 650 uint32 iFragmentSizeRemainingToCopy; 651 bool iIsNewDataFragment; 652 // partial frame assembly logic flags 653 bool iFirstPieceOfPartialFrame; 654 bool iObtainNewInputBuffer; 655 bool iKeepDroppingMsgsUntilMarkerBit; 656 bool iFirstDataMsgAfterBOS; 657 InputBufCtrlStruct *iInputBufferUnderConstruction; 658 bool iIncompleteFrame; 659 660 OSCL_IMPORT_REF void DropCurrentBufferUnderConstruction(); 661 OSCL_IMPORT_REF void SendIncompleteBufferUnderConstruction(); 662 663 // input data info 664 uint32 iCurrFragNum; 665 uint32 iCodecSeqNum; // sequence number tracking 666 uint32 iInPacketSeqNum; 667 668 uint32 iInTimestamp; 669 uint32 iInDuration; 670 uint32 iInNumFrags; 671 uint32 iCurrentMsgMarkerBit; 672 673 // DYNAMIC PORT RE-CONFIGURATION 674 uint32 iInputPortIndex; 675 uint32 iOutputPortIndex; 676 OMX_PARAM_PORTDEFINITIONTYPE iParamPort; 677 uint32 iPortIndexForDynamicReconfig; 678 bool iSecondPortReportedChange; 679 bool iDynamicReconfigInProgress; 680 uint32 iSecondPortToReconfig; 681 bool iPauseCommandWasSentToComponent; 682 bool iStopCommandWasSentToComponent; 683 684 OMX_BUFFERHEADERTYPE *iInputBufferToResendToComponent; // ptr to input buffer that is not empty, but that the OMX component returned 685 // we need to resend this same buffer back to the component 686 687 ////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS 688 bool iOMXComponentSupportsExternalOutputBufferAlloc; 689 bool iOMXComponentSupportsExternalInputBufferAlloc; 690 bool iOMXComponentSupportsMovableInputBuffers; 691 bool iSetMarkerBitForEveryFrag; // is every fragment complete frame (e.g. AVC file playback = each fragment is a NAL) 692 bool iIsOMXComponentMultiThreaded; 693 bool iOMXComponentSupportsPartialFrames; 694 bool iOMXComponentUsesNALStartCodes; 695 bool iOMXComponentUsesFullAVCFrames; 696 bool iOMXComponentCanHandleIncompleteFrames; 697 698 // State definitions for HandleProcessingState() state machine 699 typedef enum 700 { 701 EPVMFOMXBaseDecNodeProcessingState_Idle, //default state after constraction/reset 702 EPVMFOMXBaseDecNodeProcessingState_InitDecoder, //initialization of H264 decoder after handle was obtained 703 EPVMFOMXBaseDecNodeProcessingState_WaitForInitCompletion, // waiting for init completion 704 EPVMFOMXBaseDecNodeProcessingState_ReadyToDecode, //nornal operation state of the decoder 705 EPVMFOMXBaseDecNodeProcessingState_WaitForOutputBuffer, //wait state for avalible media output buffer 706 EPVMFOMXBaseDecNodeProcessingState_WaitForOutputPort, //wait state, output port is busy 707 EPVMFOMXBaseDecNodeProcessingState_WaitForOutgoingQueue, //wait state, outgoing queue 708 EPVMFOMXBaseDecNodeProcessingState_PortReconfig, // Dynamic Port Reconfiguration - step 1 709 EPVMFOMXBaseDecNodeProcessingState_WaitForBufferReturn, // step 2 710 EPVMFOMXBaseDecNodeProcessingState_WaitForPortDisable, // Dynamic Port Reconfiguration - step 3 711 EPVMFOMXBaseDecNodeProcessingState_PortReEnable, // Dynamic Port Reconfiguration - step 4 712 EPVMFOMXBaseDecNodeProcessingState_WaitForPortEnable, // step 5 713 EPVMFOMXBaseDecNodeProcessingState_Stopping, // when STOP command is issued, the node has to wait for component to transition into 714 // idle state. The buffers keep coming back , the node is rescheduled 715 // to run. Prevent the node from sending buffers back 716 EPVMFOMXBaseDecNodeProcessingState_Pausing // when PAUSE command is issued, the node has to wait for component to transition into 717 // paused state. 718 // Video: This prevents the node from sending buffers back 719 // Audio: The buffers may still keep coming back , the node is rescheduled 720 // to run. Prevent the node from sending buffers back to component 721 722 } PVMFOMXBaseDecNode_ProcessingState; 723 724 // State of HandleProcessingState() state machine 725 PVMFOMXBaseDecNode_ProcessingState iProcessingState; 726 727 // Handle of OMX Component 728 OMX_HANDLETYPE iOMXDecoder; 729 730 // Current State of the component 731 OMX_STATETYPE iCurrentDecoderState; 732 733 // BOS 734 bool iSendBOS; 735 uint32 iStreamID; 736 uint32 iBOSTimestamp; 737 738 // repositioning related flags 739 bool iIsRepositioningRequestSentToComponent; 740 bool iIsRepositionDoneReceivedFromComponent; 741 bool iIsOutputPortFlushed; 742 bool iIsInputPortFlushed; 743 744 //EOS control flags 745 bool iIsEOSSentToComponent; 746 bool iIsEOSReceivedFromComponent; 747 748 // Send Fsi configuration flag 749 bool sendFsi; 750 751 // Pointer to input data fragment 752 uint8* iBitstreamBuffer; 753 // Size of input data fragment 754 int32 iBitstreamSize; 755 756 // Output frame sequence counter 757 uint32 iSeqNum; 758 759 // Input frame sequence counter 760 uint32 iSeqNum_In; 761 762 // Added to Scheduler Flag 763 bool iIsAdded; 764 765 // Log related 766 PVLogger* iLogger; 767 PVLogger* iDataPathLogger; 768 PVLogger* iClockLogger; 769 PVLogger *iRunlLogger; 770 771 // Counter of fragment read from current Media Msg.Input buffer 772 uint fragnum; 773 // Number of fragments in the Media Msg.Input buffer 774 uint numfrags; 775 776 // Time stamp to be used on output buffer 777 uint32 iOutTimeStamp; 778 779 // Node configuration update 780 PVMFOMXBaseDecNodeConfig iNodeConfig; 781 782 // Capability exchange 783 PVMFNodeCapability iCapability; 784 785 // Reference counter for extension 786 uint32 iExtensionRefCount; 787 788 // Vector for KVP 789 Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> iAvailableMetadataKeys; 790 791 // EOS flag 792 bool iEndOfDataReached; 793 // Time stame upon EOS 794 PVMFTimestamp iEndOfDataTimestamp; 795 796 /* Diagnostic log related */ 797 PVLogger* iDiagnosticsLogger; 798 bool iDiagnosticsLogged; 799 void LogDiagnostics(); 800 801 uint32 iFrameCounter; 802 803 uint32 iAvgBitrateValue; 804 bool iResetInProgress; 805 bool iResetMsgSent; 806 bool iStopInResetMsgSent; 807 808 // AVC NAL counter and size array 809 uint32 iNALCount; 810 uint32 iNALSizeArray[MAX_NAL_PER_FRAME]; // NAL count shouldn't exceed 100 811 812 OsclAny **out_ctrl_struct_ptr ; 813 OsclAny **out_buff_hdr_ptr ; 814 OsclAny **in_ctrl_struct_ptr ; 815 OsclAny **in_buff_hdr_ptr ; 816 817 PVInterface* ipExternalOutputBufferAllocatorInterface; 818 PVMFFixedSizeBufferAlloc* ipFixedSizeBufferAlloc; 819 bool iCompactFSISettingSucceeded; 820 821 // Timestamp, timescale, OMX Ticks related conversions 822 uint32 iInTimeScale; 823 uint32 iOutTimeScale; 824 uint32 iTimeScale; 825 MediaClockConverter iInputTimestampClock; 826 OMX_TICKS iOMXTicksTimestamp; 827 OSCL_IMPORT_REF OMX_TICKS ConvertTimestampIntoOMXTicks(const MediaClockConverter &src); 828 uint32 ConvertOMXTicksIntoTimestamp(const OMX_TICKS &src); 829 OMX_BOOL bHWAccelerated; 830 }; 831 832 833 #endif // PVMF_OMXBASEDEC_NODE_H_INCLUDED 834 835