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_ENC_NODE_H_INCLUDED 19 #define PVMF_OMX_ENC_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_FIXEDSIZE_BUFFER_ALLOC_H_INCLUDED 53 #include "pvmf_fixedsize_buffer_alloc.h" 54 #endif 55 56 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED 57 #include "pvmf_simple_media_buffer.h" 58 #endif 59 60 #ifndef PVMF_MEDIA_FRAG_GROUP_H_INCLUDED 61 #include "pvmf_media_frag_group.h" 62 #endif 63 64 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED 65 #include "pvmf_pool_buffer_allocator.h" 66 #endif 67 68 #ifndef PVMF_VIDEO_H_INCLUDED 69 #include "pvmf_video.h" 70 #endif 71 72 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED 73 #include "pvmf_pool_buffer_allocator.h" 74 #endif 75 76 #ifndef PVMF_NODE_UTILS_H_INCLUDED 77 #include "pvmf_node_utils.h" 78 #endif 79 80 #ifndef PVMF_OMX_ENC_PORT_H_INCLUDED 81 #include "pvmf_omx_enc_port.h" 82 #endif 83 84 #ifndef PVMF_OMX_ENC_NODE_EXTENSION_INTERFACE_H_INCLUDED 85 #include "pvmf_omx_enc_node_extension_interface.h" 86 #endif 87 88 #ifndef PV_MP4_H263_ENC_EXTENSION_H_INCLUDED 89 #include "pvmp4h263encextension.h" 90 #endif 91 92 #ifndef PVMF_AUDIO_ENCNODE_EXTENSION_H_INCLUDED 93 #include "pvmf_audio_encnode_extension.h" 94 #endif 95 96 // DV: NOTE - this needs to be fixed 97 //#ifndef __PVM4VENCODER_H 98 //#include "pvm4vencoder.h" 99 //#endif 100 101 #ifndef PVMF_META_DATA_EXTENSION_H_INCLUDED 102 #include "pvmf_meta_data_extension.h" 103 #endif 104 105 #ifndef PV_MIME_STRING_UTILS_H_INCLUDED 106 #include "pv_mime_string_utils.h" 107 #endif 108 109 #ifndef OMX_Core_h 110 #include "OMX_Core.h" 111 #endif 112 113 #ifndef OMX_Component_h 114 #include "OMX_Component.h" 115 #endif 116 117 #ifndef PVMF_OMX_ENC_CALLBACKS_H_INCLUDED 118 #include "pvmf_omx_enc_callbacks.h" 119 #endif 120 121 #ifndef PV_OMXDEFS_H_INCLUDED 122 #include "pv_omxdefs.h" 123 #endif 124 125 #ifndef OSCLCONFIG_IO_H_INCLUDED 126 #include "osclconfig_io.h" 127 #endif 128 #ifndef OSCL_MEM_H_INCLUDED 129 #include "oscl_mem.h" 130 #endif 131 132 #if (PVLOGGER_INST_LEVEL >= PVLOGMSG_INST_REL) 133 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED 134 #include "pvmf_media_clock.h" 135 #endif 136 #endif 137 138 #ifndef __MEDIA_CLOCK_CONVERTER_H 139 #include "media_clock_converter.h" 140 #endif 141 142 #define PVMFOMXENCNODE_NUM_CMD_IN_POOL 8 143 #define PVOMXENCMAXNUMDPBFRAMESPLUS1 17 144 145 146 typedef struct OutputBufCtrlStruct 147 { 148 OMX_BUFFERHEADERTYPE *pBufHdr; 149 } OutputBufCtrlStruct; 150 151 typedef struct InputBufCtrlStruct 152 { 153 OMX_BUFFERHEADERTYPE *pBufHdr; 154 PVMFSharedMediaDataPtr pMediaData; 155 } InputBufCtrlStruct; 156 157 158 // fwd class declaration 159 class PVLogger; 160 //memory allocator type for this node. 161 typedef OsclMemAllocator PVMFOMXEncNodeAllocator; 162 typedef OsclMemAllocDestructDealloc<uint8> PVMFOMXEncNodeAllocDestructDealloc; 163 164 165 // CALLBACK PROTOTYPES 166 OMX_ERRORTYPE CallbackEventHandlerEnc(OMX_OUT OMX_HANDLETYPE aComponent, 167 OMX_OUT OMX_PTR aAppData, 168 OMX_OUT OMX_EVENTTYPE aEvent, 169 OMX_OUT OMX_U32 aData1, 170 OMX_OUT OMX_U32 aData2, 171 OMX_OUT OMX_PTR aEventData); 172 173 OMX_ERRORTYPE CallbackEmptyBufferDoneEnc(OMX_OUT OMX_HANDLETYPE aComponent, 174 OMX_OUT OMX_PTR aAppData, 175 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer); 176 177 OMX_ERRORTYPE CallbackFillBufferDoneEnc(OMX_OUT OMX_HANDLETYPE aComponent, 178 OMX_OUT OMX_PTR aAppData, 179 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer); 180 181 182 183 //Default values for number of Input/Output buffers. If the component needs more than this, it will be 184 // negotiated. If the component does not need more than this number, the default is used 185 #define NUMBER_INPUT_BUFFER 5 186 #define NUMBER_OUTPUT_BUFFER 9 187 188 // for AMR encoder 189 #define MAX_NUM_AMR_FRAMES_PER_BUFFER 25 190 #define PVMF_AMRENC_DEFAULT_SAMPLING_RATE 8000 191 #define PVMF_AMRENC_DEFAULT_NUM_CHANNELS 1 192 #define PVMF_AMRENC_DEFAULT_BITSPERSAMPLE 16 193 // in milliseconds 194 #define PVMF_AMRENC_DEFAULT_FRAME_DURATION 20 195 196 //////////////////////////////////////////////////////////////////////////////////////////////////////////// 197 //////////////////////////////////////////////////////////////////////////////////////////////////////////// 198 ///////////////////////// 199 ///////////////////////// 200 ///////////////////////// 201 // CUSTOM DEALLOCATOR FOR MEDIA DATA SHARED PTR WRAPPER: 202 // 1) Deallocates the underlying output buffer 203 // 2) Deallocates the pvci buffer wrapper and the rest of accompanying structures 204 // Deallocator is created as part of the wrapper, and travels with the buffer wrapper 205 206 class PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA : public OsclDestructDealloc 207 { 208 public: PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA(Oscl_DefAlloc * allocator,void * pMempoolData)209 PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA(Oscl_DefAlloc* allocator, void *pMempoolData) : 210 buf_alloc(allocator), ptr_to_data_to_dealloc(pMempoolData) {}; ~PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA()211 virtual ~PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA() {}; 212 destruct_and_dealloc(OsclAny * ptr)213 virtual void destruct_and_dealloc(OsclAny* ptr) 214 { 215 // call buffer deallocator 216 if (buf_alloc != NULL) 217 { 218 buf_alloc->deallocate(ptr_to_data_to_dealloc); 219 } 220 221 // this is needed to completely free PVMFMediaDataImpl, since it allocates memory for the frag list 222 ((PVMFMediaDataImpl*)ptr)->~PVMFMediaDataImpl(); 223 oscl_free(ptr); 224 } 225 226 private: 227 Oscl_DefAlloc* buf_alloc; 228 void *ptr_to_data_to_dealloc; 229 }; 230 231 232 233 #define PVMFOMXEncNodeCommandBase PVMFGenericNodeCommand<PVMFOMXEncNodeAllocator> 234 235 class PVMFOMXEncNodeCommand: public PVMFOMXEncNodeCommandBase 236 { 237 public: 238 //constructor for Custom2 command Construct(PVMFSessionId s,int32 cmd,int32 arg1,int32 arg2,int32 & arg3,const OsclAny * aContext)239 void Construct(PVMFSessionId s, int32 cmd, int32 arg1, int32 arg2, int32& arg3, const OsclAny*aContext) 240 { 241 PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext); 242 iParam1 = (OsclAny*)arg1; 243 iParam2 = (OsclAny*)arg2; 244 iParam3 = (OsclAny*) & arg3; 245 } Parse(int32 & arg1,int32 & arg2,int32 * & arg3)246 void Parse(int32&arg1, int32&arg2, int32*&arg3) 247 { 248 arg1 = (int32)iParam1; 249 arg2 = (int32)iParam2; 250 arg3 = (int32*)iParam3; 251 } 252 Construct(PVMFSessionId s,int32 cmd,PVMFMetadataList * aKeyList,uint32 aStartIndex,int32 aMaxEntries,char * aQueryKey,const OsclAny * aContext)253 void Construct(PVMFSessionId s, int32 cmd, PVMFMetadataList* aKeyList, uint32 aStartIndex, int32 aMaxEntries, char* aQueryKey, const OsclAny* aContext) 254 { 255 PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext); 256 iStartIndex = aStartIndex; 257 iMaxEntries = aMaxEntries; 258 259 if (aQueryKey == NULL) 260 { 261 query_key[0] = 0; 262 } 263 else 264 { 265 if (aQueryKey != NULL) 266 oscl_strncpy(query_key, aQueryKey, oscl_strlen(aQueryKey) + 1); 267 } 268 269 iParam1 = (OsclAny*)aKeyList; 270 iParam2 = NULL; 271 iParam3 = NULL; 272 iParam4 = NULL; 273 iParam5 = NULL; 274 } 275 Parse(PVMFMetadataList * & MetaDataListPtr,uint32 & aStartingIndex,int32 & aMaxEntries,char * & aQueryKey)276 void Parse(PVMFMetadataList*& MetaDataListPtr, uint32 &aStartingIndex, int32 &aMaxEntries, char*&aQueryKey) 277 { 278 MetaDataListPtr = (PVMFMetadataList*)iParam1; 279 aStartingIndex = iStartIndex; 280 aMaxEntries = iMaxEntries; 281 if (query_key[0] == 0) 282 { 283 aQueryKey = NULL; 284 } 285 else 286 { 287 aQueryKey = query_key; 288 } 289 } 290 291 // Constructor and parser for GetNodeMetadataValue Construct(PVMFSessionId s,int32 cmd,PVMFMetadataList * aKeyList,Oscl_Vector<PvmiKvp,OsclMemAllocator> * aValueList,uint32 aStartIndex,int32 aMaxEntries,const OsclAny * aContext)292 void Construct(PVMFSessionId s, int32 cmd, PVMFMetadataList* aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>* aValueList, uint32 aStartIndex, int32 aMaxEntries, const OsclAny* aContext) 293 { 294 PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext); 295 iParam1 = (OsclAny*)aKeyList; 296 iParam2 = (OsclAny*)aValueList; 297 298 iStartIndex = aStartIndex; 299 iMaxEntries = aMaxEntries; 300 301 iParam3 = NULL; 302 iParam4 = NULL; 303 iParam5 = NULL; 304 } Parse(PVMFMetadataList * & aKeyList,Oscl_Vector<PvmiKvp,OsclMemAllocator> * & aValueList,uint32 & aStartingIndex,int32 & aMaxEntries)305 void Parse(PVMFMetadataList* &aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>* &aValueList, uint32 &aStartingIndex, int32 &aMaxEntries) 306 { 307 aKeyList = (PVMFMetadataList*)iParam1; 308 aValueList = (Oscl_Vector<PvmiKvp, OsclMemAllocator>*)iParam2; 309 aStartingIndex = iStartIndex; 310 aMaxEntries = iMaxEntries; 311 } 312 313 hipri()314 virtual bool hipri() 315 { 316 //this routine identifies commands that need to 317 //go at the front of the queue. derived command 318 //classes can override it if needed. 319 return (iCmd == PVOMXENC_NODE_CMD_CANCELALL 320 || iCmd == PVOMXENC_NODE_CMD_CANCELCMD); 321 } 322 323 enum PVOMXEncNodeCmdType 324 { 325 PVOMXENC_NODE_CMD_QUERYUUID, 326 PVOMXENC_NODE_CMD_QUERYINTERFACE, 327 PVOMXENC_NODE_CMD_REQUESTPORT, 328 PVOMXENC_NODE_CMD_RELEASEPORT, 329 PVOMXENC_NODE_CMD_INIT, 330 PVOMXENC_NODE_CMD_PREPARE, 331 PVOMXENC_NODE_CMD_START, 332 PVOMXENC_NODE_CMD_STOP, 333 PVOMXENC_NODE_CMD_FLUSH, 334 PVOMXENC_NODE_CMD_PAUSE, 335 PVOMXENC_NODE_CMD_RESET, 336 PVOMXENC_NODE_CMD_CANCELALL, 337 PVOMXENC_NODE_CMD_CANCELCMD, 338 PVOMXENC_NODE_CMD_GETNODEMETADATAKEY, 339 PVOMXENC_NODE_CMD_GETNODEMETADATAVALUE, 340 PVOMXENC_NODE_CMD_INVALID 341 }; 342 343 344 345 346 private: 347 uint32 iStartIndex; 348 uint32 iMaxEntries; 349 char query_key[256]; 350 351 }; 352 353 //Default vector reserve size 354 #define PVMF_OMXENC_NODE_COMMAND_VECTOR_RESERVE 10 355 356 //Starting value for command IDs 357 #define PVMF_OMXENC_NODE_COMMAND_ID_START 6000 358 359 //////////////////////////////////////////////////////////////////////////////////////////////////// 360 //////////////////////////////////// STRUCTURES FOR ENCODING PARAMETERS //////////////////////////// 361 //////////////////////////////////////////////////////////////////////////////////////////////////// 362 #define MAX_LAYER 1 363 364 /** Contains supported input format */ 365 enum EncVideoInputFormat 366 { 367 EI_RGB24, 368 EI_RGB12, 369 EI_YUV420, 370 EI_UYVY 371 }; 372 373 /** Type of contents for optimal encoding mode. */ 374 enum EncContentType 375 { 376 /** Content is to be streamed in real-time. */ 377 EI_M4V_STREAMING, 378 379 /** Content is to be downloaded and playbacked later.*/ 380 EI_M4V_DOWNLOAD, 381 382 /** Content is to be 3gpp baseline compliant. */ 383 EI_H263, 384 385 EI_H264 386 }; 387 388 /** Targeted profile and level to encode. */ 389 enum EncM4VProfileLevel 390 { 391 /* Non-scalable profile */ 392 EI_SIMPLE_LEVEL0 = 0, 393 EI_SIMPLE_LEVEL1, 394 EI_SIMPLE_LEVEL2, 395 EI_SIMPLE_LEVEL3, 396 EI_CORE_LEVEL1, 397 EI_CORE_LEVEL2, 398 399 /* Scalable profile */ 400 EI_SIMPLE_SCALABLE_LEVEL0 = 6, 401 EI_SIMPLE_SCALABLE_LEVEL1, 402 EI_SIMPLE_SCALABLE_LEVEL2, 403 404 EI_CORE_SCALABLE_LEVEL1 = 10, 405 EI_CORE_SCALABLE_LEVEL2, 406 EI_CORE_SCALABLE_LEVEL3 407 }; 408 409 /** Targeted profile to encode. */ 410 enum EncAVCProfile 411 { 412 /* Non-scalable profile */ 413 EI_PROFILE_DEFAULT, 414 EI_PROFILE_BASELINE, 415 EI_PROFILE_MAIN, 416 EI_PROFILE_EXTENDED, 417 EI_PROFILE_HIGH, 418 EI_PROFILE_HIGH10, 419 EI_PROFILE_HIGH422, 420 EI_PROFILE_HIGH444 421 }; 422 423 /** Targeted level to encode. */ 424 enum EncAVCLevel 425 { 426 EI_LEVEL_AUTODETECT, 427 EI_LEVEL_1, 428 EI_LEVEL_1B, 429 EI_LEVEL_11, 430 EI_LEVEL_12, 431 EI_LEVEL_13, 432 EI_LEVEL_2, 433 EI_LEVEL_21, 434 EI_LEVEL_22, 435 EI_LEVEL_3, 436 EI_LEVEL_31, 437 EI_LEVEL_32, 438 EI_LEVEL_4, 439 EI_LEVEL_41, 440 EI_LEVEL_42, 441 EI_LEVEL_5, 442 EI_LEVEL_51, 443 }; 444 445 /** Output format */ 446 enum TAVCEIOutputFormat 447 { 448 /** output in byte stream format according to Annex B */ 449 EAVCEI_OUTPUT_ANNEXB, 450 451 /** output for MP4 file format */ 452 EAVCEI_OUTPUT_MP4, 453 454 /** output in RTP format according to RFC 3984 */ 455 EAVCEI_OUTPUT_RTP 456 }; 457 458 459 460 /** Type of contents for optimal encoding mode. */ 461 enum EncEncodingMode 462 { 463 /** Content is encoded as fast as possible with error protection */ 464 EI_ENCMODE_TWOWAY, 465 466 /** Content is encoded as fast as possible without error protection */ 467 EI_ENCMODE_RECORDER, 468 469 /** Content is encoded with better quality (slow) with error protection */ 470 EI_ENCMODE_STREAMING, 471 472 /** Content is encoded with better quality (slow) without error protection */ 473 EI_ENCMODE_DOWNLOAD 474 }; 475 476 477 /** This structure contains encoder settings. */ 478 typedef struct PV_VideoEncodeParam 479 { 480 481 //////////////////////////////////////////////////////////////////////////////////// 482 ////////////////////////// COMMON PARAMETERS /////////////////////////////////////// 483 //////////////////////////////////////////////////////////////////////////////////// 484 485 /** Specifies an ID that will be used to specify this encoder while returning 486 the bitstream in asynchronous mode. */ 487 uint32 iEncodeID; 488 489 490 /** Specifies whether base only (iNumLayer = 1) or base + enhancement layer 491 (iNumLayer =2 ) is to be used. */ 492 int32 iNumLayer; 493 494 /** Specifies the width in pixels of the encoded frames. IFrameWidth[0] is for 495 base layer and iFrameWidth[1] is for enhanced layer. */ 496 int iFrameWidth[MAX_LAYER]; 497 498 /** Specifies the height in pixels of the encoded frames. IFrameHeight[0] is for 499 base layer and iFrameHeight[1] is for enhanced layer. */ 500 int iFrameHeight[MAX_LAYER]; 501 502 /** Specifies the cumulative bit rate in bit per second. IBitRate[0] is for base 503 layer and iBitRate[1] is for base+enhanced layer.*/ 504 int iBitRate[MAX_LAYER]; 505 506 /** Specifies the cumulative frame rate in frame per second. IFrameRate[0] is for 507 base layer and iFrameRate[1] is for base+enhanced layer. */ 508 float iFrameRate[MAX_LAYER]; 509 510 /** Specifies the rate control algorithm among one of the following constant Q, 511 CBR and VBR. The structure EncRateControlType is defined above.*/ 512 PVMFVENRateControlType iRateControlType; 513 514 /** Specifies the initial quantization parameter for the first I-frame. If constant Q 515 rate control is used, this QP will be used for all the I-frames. This number must be 516 set between 1 and 31, otherwise, Initialize() will fail. */ 517 int iIquant[2]; 518 519 /** Specifies the initial quantization parameter for the first P-frame. If constant Q 520 rate control is used, this QP will be used for all the P-frames. This number must be 521 set between 1 and 31, otherwise, Initialize() will fail. */ 522 int iPquant[2]; 523 524 /** Specifies the initial quantization parameter for the first B-frame. If constant Q 525 rate control is used, this QP will be used for all the B-frames. This number must be 526 set between 1 and 31, otherwise, Initialize() will fail. */ 527 int iBquant[2]; 528 529 530 /** Specifies the maximum number of P-frames between 2 INTRA frames. An INTRA mode is 531 forced to a frame once this interval is reached. When there is only one I-frame is present 532 at the beginning of the clip, iIFrameInterval should be set to -1. */ 533 int32 iIFrameInterval; 534 535 /** According to iIFrameInterval setting, the minimum number of intra MB per frame is 536 optimally calculated for error resiliency. However, when iIFrameInterval is set to -1, 537 iNumIntraMBRefresh must be specified to guarantee the minimum number of intra 538 macroblocks per frame.*/ 539 uint32 iNumIntraMBRefresh; 540 541 /** Specifies automatic scene detection where I-frame will be used the the first frame 542 in a new scene. */ 543 bool iSceneDetection; 544 545 /** Specifies the packet size in bytes which represents the number of bytes between two resync markers. 546 For EI_M4V_DOWNLOAD and EI_H263, if iPacketSize is set to 0, there will be no resync markers in the bitstream. 547 For EI_M4V_STREAMING is parameter must be set to a value greater than 0. For AVC, this value specifies 548 the packet size in bytes which represents the desired number of bytes per NAL. 549 If this number is set to 0, the AVC encoder will encode the entire slice group as one NAL. */ 550 uint32 iPacketSize; 551 552 /** Specifies the VBV buffer size which determines the end-to-end delay between the 553 encoder and the decoder. The size is in unit of seconds. For download application, 554 the buffer size can be larger than the streaming application. For 2-way application, 555 this buffer shall be kept minimal. For a special case, in VBR mode, iBufferDelay will 556 be set to -1 to allow buffer underflow. */ 557 float iBufferDelay; 558 559 560 /** Specifies the duration of the clip in millisecond.*/ 561 int32 iClipDuration; 562 563 564 //////////////////////////////////////////////////////////////////////////////////////// 565 /////////////////////////// H263/M4V specific parameters /////////////////////////////// 566 //////////////////////////////////////////////////////////////////////////////////////// 567 568 /** Specifies the profile and level used to encode the bitstream. When present, 569 other settings will be checked against the range allowable by this target profile 570 and level. Fail may be returned from the Initialize call. */ 571 EncM4VProfileLevel iProfileLevel; 572 573 /** Specifies the picture quality factor on the scale of 1 to 10. It trades off 574 the picture quality with the frame rate. Higher frame quality means lower frame rate. 575 Lower frame quality for higher frame rate.*/ 576 int32 iFrameQuality; 577 578 579 /** Enable the use of iFrameQuality to determine the frame rate. If it is false, 580 the encoder will try to meet the specified frame rate regardless of the frame quality.*/ 581 bool iEnableFrameQuality; 582 583 584 /** Specifies high quality but also high complexity mode for rate control. */ 585 bool iRDOptimal; 586 587 588 /** Specifies the search range in pixel unit for motion vector. The range of the 589 motion vector will be of dimension [-iSearchRange.5, +iSearchRange.0]. */ 590 int32 iSearchRange; 591 592 /** Specifies the use of 8x8 motion vectors. */ 593 bool iMV8x8; 594 595 /** Specifies the use of half-pel motion vectors. */ 596 bool iMVHalfPel; 597 598 /** Specifies whether the current frame skipping decision is allowed after encoding 599 the current frame. If there is no memory of what has been coded for the current frame, 600 iNoCurrentSkip has to be on. */ 601 bool iNoCurrentSkip; 602 603 /** Specifies that no frame skipping is allowed. Frame skipping is a tool used to 604 control the average number of bits spent to meet the target bit rate. */ 605 bool iNoFrameSkip; 606 607 608 /** Specify short header mode in MPEG4 */ 609 bool iShortHeader; 610 611 /** Specifies whether data partitioning mode is used or not. Has no meaning if encoding H.263 or short header */ 612 bool iDataPartitioning; 613 614 615 /** Specifies whether Resync markers are used or not Has no meaning if iDataPartitioning is on */ 616 bool iResyncMarker; 617 618 619 /** Specifies whether RVLC (reversible VLC) is to be used or not. 620 */ 621 bool iRVLCEnable; 622 623 //////////////////////////////////////////////////////////////////////////////////////// 624 /////////////////////////// H264 specific parameters /////////////////////////////// 625 //////////////////////////////////////////////////////////////////////////////////////// 626 627 /** Specifies the targeted profile, and will also specifies available tools for iEncMode. 628 If default is used, encoder will choose its own preferred profile. If autodetect is used, encoder 629 will check other settings and choose the right profile that doesn't have any conflicts. */ 630 EncAVCProfile iAVCProfile; 631 632 /** Specifies the target level When present, 633 other settings will be checked against the range allowable by this target level. 634 Fail will returned upon Initialize call. If not known, users must set it to autodetect. Encoder will 635 calculate the right level that doesn't conflict with other settings. */ 636 EncAVCLevel iAVCLevel; 637 638 /** Specifies the encoding mode. This translates to the complexity of encoding modes and 639 error resilient tools. This is for future use - enc mode will be used to set other parameters to appropriate 640 values. 641 */ 642 643 EncEncodingMode iEncMode; 644 645 /** Specifies that SPS and PPS are retrieved first and sent out-of-band */ 646 //bool iOutOfBandParamSet; 647 648 649 } PV_VideoEncodeParam; 650 651 652 653 /** Structure for input format information */ 654 typedef struct PV_VideoInputFormat 655 { 656 /** Contains the width in pixels of the input frame. */ 657 int32 iFrameWidth; 658 659 /** Contains the height in pixels of the input frame. */ 660 int32 iFrameHeight; 661 662 /** Contains the input frame rate in the unit of frame per second. */ 663 float iFrameRate; 664 665 /** Contains Frame Orientation. Used for RGB input. 1 means Bottom_UP RGB, 0 means Top_Down RGB, -1 for video formats other than RGB*/ 666 int iFrameOrientation; 667 668 /** Contains the format of the input video, e.g., YUV 4:2:0, UYVY, RGB24, etc. */ 669 EncVideoInputFormat iVideoFormat; 670 } PV_VideoInputFormat; 671 672 673 /** Structure for audio encode information */ 674 typedef struct PV_AudioEncodeParam 675 { 676 677 // DESCRIPTION: Final sampling frequency used when encoding in Hz. 678 // For example, "44100" Hz. 679 // USAGE: If the input sampling rate is not appropriate (e.g., 680 // the codec requires a different sampling frequency), 681 // the CAEI will fill this in with the final sampling 682 // rate. The CAEI will perform resampling if the 683 // input sampling frequency is not the same as the output 684 // sampling frequency. 685 uint32 iOutputSamplingRate; 686 687 // DESCRIPTION: Number of output channels:1=Mono,2=Stereo. (Mono uses 1 688 // channel; Stereo uses 2 channels). 689 // USAGE: The CAEI will fill this in if it needs to convert 690 // the input samples to what is required by the codec. 691 uint8 iOutputNumChannels; 692 693 // DESCRIPTION: Currently, output bitrate is expressed as GSM-AMR type rate 694 PVMF_GSMAMR_Rate iAMRBitrate; 695 696 // DESCRIPTION: output bitrate in bits per second for non-AMR codecs 697 uint32 iOutputBitrate; 698 699 // 700 uint32 iMaxNumOutputFramesPerBuffer; 701 702 703 } PV_AudioEncodeParam; 704 705 enum EInterleaveMode 706 { 707 EINTERLEAVE_LR, // interleaved left-right 708 EGROUPED_LR, // non-interleaved left-right 709 ENUM_INTERLEAVE_MODES // number of modes supported 710 }; 711 712 /** Structure for input format information */ 713 typedef struct PV_AudioInputFormat 714 { 715 716 717 // DESCRIPTION: Number of bits per sample. For example, set it to "16" 718 // bits for PCM. 719 // USAGE: The authoring application is required to fill this in. 720 // 721 int32 iInputBitsPerSample; 722 723 // DESCRIPTION: Sampling rate of the input samples in Hz. 724 // For example, set it to "22050" Hz. AMRNB is always 8khz 725 // USAGE: The authoring application is required to fill this in. 726 // If sampling rate is not known until CAEI is initialized, 727 // use '0'. 728 uint32 iInputSamplingRate; 729 730 731 // DESCRIPTION: Number of input channels:1=Mono,2=Stereo.(Mono uses 1 channel; 732 // Stereo uses 2 channels). 733 // USAGE: The authoring application is required to fill this in. 734 // 735 uint8 iInputNumChannels; 736 737 // DESCRIPTION: Whether to interleave or not the multi-channel input samples: 738 // EINTERLEAVE_LR = LRLRLRLRLR (interleaved left-right) 739 // EGROUPED_LR = LLLLLL...RRRRRR (non-interleaved left-right) 740 // USAGE: The authoring application is required to fill this in. 741 // 742 EInterleaveMode iInputInterleaveMode; 743 744 745 746 } PV_AudioInputFormat; 747 748 749 750 751 752 753 754 755 /////////////////////////////////////////////////////////////////////////////////////////////////////// 756 //CAPABILITY AND CONFIG 757 758 // Structure to hold the key string info for 759 // encnode's capability-and-config 760 struct PVOMXEncNodeKeyStringData 761 { 762 char iString[64]; 763 PvmiKvpType iType; 764 PvmiKvpValueType iValueType; 765 }; 766 767 // The number of characters to allocate for the key string 768 #define PVOMXENCNODECONFIG_KEYSTRING_SIZE 128 769 770 771 // Key string info at the base level ("x-pvmf/encoder/video") 772 // or ("x-pvmf/encoder/audio") 773 774 #ifdef _TEST_AE_ERROR_HANDLING 775 #define PVOMXENCNODECONFIG_BASE_NUMKEYS 8 776 #else 777 #define PVOMXENCNODECONFIG_BASE_NUMKEYS 3 778 #endif 779 780 const PVOMXEncNodeKeyStringData PVOMXEncNodeConfigBaseKeys[PVOMXENCNODECONFIG_BASE_NUMKEYS] = 781 { 782 {"sampling_rate", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32}, 783 {"channels", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32}, 784 {"encoding_mode", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32} 785 #ifdef _TEST_AE_ERROR_HANDLING 786 , {"error_start_init", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_BOOL} 787 , {"error-encode", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32} 788 , {"error-node-cmd", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32} 789 , {"error-config-header", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_BOOL} 790 , {"data-path-stall", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32} 791 #endif 792 }; 793 794 enum BaseKeys_IndexMapType 795 { 796 SAMPLING_RATE = 0, // audio 797 CHANNELS, // audio 798 ENCODING_MODE // avc 799 #ifdef _TEST_AE_ERROR_HANDLING 800 , ERROR_START_INIT 801 , ERROR_ENCODE 802 , ERROR_NODE_CMD 803 , ERROR_CONFIG_HEADER 804 , ERROR_DATAPATH_STALL 805 #endif 806 }; 807 808 // default encode parameters 809 #define DEFAULT_BITRATE 32000 810 #define DEFAULT_FRAME_WIDTH 176 811 #define DEFAULT_FRAME_HEIGHT 144 812 #define DEFAULT_FRAME_RATE 5 813 #define DEFAULT_I_FRAME_INTERVAL 10 // encode one I frame every 10 seconds. 814 #define DEFAULT_OMX_MP4ENC_QPI 15 815 #define DEFAULT_OMX_MP4ENC_QPP 12 816 #define DEFAULT_OMX_MP4ENC_QPB 12 817 818 #define DEFAULT_OMX_AVCENC_QPI 25 819 #define DEFAULT_OMX_AVCENC_QPP 30 820 #define DEFAULT_OMX_AVCENC_QPB 33 821 822 #define PVMF_AVCENC_NODE_SPS_VECTOR_RESERVE 16 // max allowed by standard 823 #define PVMF_AVCENC_NODE_PPS_VECTOR_RESERVE 256 // max allowed by standard 824 #define DEFAULT_PARAMS_SET_LENGTH 256 825 826 typedef enum 827 { 828 PV_MPEG_VIDEO_SIMPLE_PROFILE = 0, 829 PV_MPEG_VIDEO_SIMPLE_SCALABLE_PROFILE, 830 PV_MPEG_VIDEO_CORE_PROFILE, 831 PV_MPEG_VIDEO_MAIN_PROFILE, 832 PV_MPEG_VIDEO_N_BIT_PROFILE, 833 PV_MPEG_VIDEO_SCALABLE_TEXTURE_PROFILE, 834 PV_MPEG_VIDEO_SIMPLE_FACE_ANIMATION_PROFILE, 835 PV_MPEG_VIDEO_SIMPLE_FBA_PROFILE, 836 PV_MPEG_VIDEO_BASIC_ANIMATED_TEXTURE_PROFILE, 837 PV_MPEG_VIDEO_HYBRID_PROFILE, 838 PV_MPEG_VIDEO_ADVANCE_REAL_TIME_SIMPLE_PROFILE, 839 PV_MPEG_VIDEO_CORE_SCALABLE_PROFILE, 840 PV_MPEG_VIDEO_ADVANCE_CODING_EFFICIENCY_PROFILE, 841 PV_MPEG_VIDEO_ADVANCE_CORE_PROFILE, 842 PV_MPEG_VIDEO_ADVANCE_SCALABLE_TEXTURE_PROFILE, 843 PV_MPEG_VIDEO_SIMPLE_STUDIO_PROFILE, 844 PV_MPEG_VIDEO_CORE_STUDIO_PROFILE, 845 PV_MPEG_VIDEO_ADVANCE_SIMPLE_PROFILE, 846 PV_MPEG_VIDEO_FINE_GRANUALITY_SCALABLE_PROFILE, 847 PV_MPEG_VIDEO_RESERVED_PROFILE 848 } PVMF_MPEGVideoProfileType; 849 850 typedef enum 851 { 852 PV_MPEG_VIDEO_LEVEL0 = 0, 853 PV_MPEG_VIDEO_LEVEL1, 854 PV_MPEG_VIDEO_LEVEL2, 855 PV_MPEG_VIDEO_LEVEL3, 856 PV_MPEG_VIDEO_LEVEL4, 857 PV_MPEG_VIDEO_LEVEL5, 858 PV_MPEG_VIDEO_LEVEL_UNKNOWN 859 860 } PVMF_MPEGVideoLevelType; 861 862 ///////////////////////////////////////////////////////////////////////////////////////// 863 864 865 866 867 868 //Mimetypes for the custom interface 869 #define PVMF_OMX_ENC_NODE_MIMETYPE "pvxxx/OMXEncNode" 870 #define PVMF_BASEMIMETYPE "pvxxx" 871 872 //Command queue type 873 typedef PVMFNodeCommandQueue<PVMFOMXEncNodeCommand, PVMFOMXEncNodeAllocator> PVMFOMXEncNodeCmdQ; 874 875 876 class PVMFOMXEncNode 877 : public OsclActiveObject 878 , public PVMFNodeInterface 879 , public OsclMemPoolFixedChunkAllocatorObserver 880 , public PVMFOMXEncNodeExtensionInterface 881 , public PVMFMetadataExtensionInterface 882 , public PvmiCapabilityAndConfig 883 , public PVMp4H263EncExtensionInterface 884 , public PVAudioEncExtensionInterface 885 { 886 public: 887 PVMFOMXEncNode(int32 aPriority); 888 ~PVMFOMXEncNode(); 889 890 // From PVMFNodeInterface 891 PVMFStatus ThreadLogon(); 892 PVMFStatus ThreadLogoff(); 893 PVMFStatus GetCapability(PVMFNodeCapability& aNodeCapability); 894 PVMFPortIter* GetPorts(const PVMFPortFilter* aFilter = NULL); 895 PVMFCommandId QueryUUID(PVMFSessionId, const PvmfMimeString& aMimeType, 896 Oscl_Vector<PVUuid, PVMFOMXEncNodeAllocator>& aUuids, 897 bool aExactUuidsOnly = false, 898 const OsclAny* aContext = NULL); 899 PVMFCommandId QueryInterface(PVMFSessionId, const PVUuid& aUuid, 900 PVInterface*& aInterfacePtr, 901 const OsclAny* aContext = NULL); 902 PVMFCommandId RequestPort(PVMFSessionId 903 , int32 aPortTag, const PvmfMimeString* aPortConfig = NULL, const OsclAny* aContext = NULL); 904 PVMFCommandId ReleasePort(PVMFSessionId, PVMFPortInterface& aPort, const OsclAny* aContext = NULL); 905 PVMFCommandId Init(PVMFSessionId, const OsclAny* aContext = NULL); 906 PVMFCommandId Prepare(PVMFSessionId, const OsclAny* aContext = NULL); 907 PVMFCommandId Start(PVMFSessionId, const OsclAny* aContext = NULL); 908 PVMFCommandId Stop(PVMFSessionId, const OsclAny* aContext = NULL); 909 PVMFCommandId Flush(PVMFSessionId, const OsclAny* aContext = NULL); 910 PVMFCommandId Pause(PVMFSessionId, const OsclAny* aContext = NULL); 911 PVMFCommandId Reset(PVMFSessionId, const OsclAny* aContext = NULL); 912 PVMFCommandId CancelAllCommands(PVMFSessionId, const OsclAny* aContextData = NULL); 913 PVMFCommandId CancelCommand(PVMFSessionId, PVMFCommandId aCmdId, const OsclAny* aContextData = NULL); 914 915 // From PVMFPortActivityHandler 916 void HandlePortActivity(const PVMFPortActivity& aActivity); 917 918 // From PVInterface 919 virtual void addRef(); 920 virtual void removeRef(); 921 virtual bool queryInterface(const PVUuid& uuid, PVInterface*& iface); 922 923 924 //**********begin PVMFMetadataExtensionInterface 925 uint32 GetNumMetadataKeys(char* query_key = NULL); 926 uint32 GetNumMetadataValues(PVMFMetadataList& aKeyList); 927 PVMFCommandId GetNodeMetadataKeys(PVMFSessionId aSessionId, PVMFMetadataList& aKeyList, uint32 starting_index, int32 max_entries, 928 char* query_key = NULL, const OsclAny* aContextData = NULL); 929 PVMFCommandId GetNodeMetadataValues(PVMFSessionId aSessionId, PVMFMetadataList& aKeyList, 930 Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 starting_index, int32 max_entries, const OsclAny* aContextData = NULL); 931 PVMFStatus ReleaseNodeMetadataKeys(PVMFMetadataList& aKeyList, uint32 starting_index, uint32 end_index); 932 PVMFStatus ReleaseNodeMetadataValues(Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 starting_index, uint32 end_index); 933 //**********End PVMFMetadataExtensionInterface 934 935 bool VerifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements); 936 937 //********** CB Functions to serve OpenMAX Encoder 938 939 //Process callback functions. They will be executed in testapp thread context 940 // These callbacks are used only in the Multithreaded component case 941 OsclReturnCode ProcessCallbackEventHandler_MultiThreaded(OsclAny* P); 942 OsclReturnCode ProcessCallbackEmptyBufferDone_MultiThreaded(OsclAny* P); 943 OsclReturnCode ProcessCallbackFillBufferDone_MultiThreaded(OsclAny* P); 944 945 //Callback objects - again, these are used only in the case of Multithreaded component 946 EventHandlerThreadSafeCallbackAOEnc* iThreadSafeHandlerEventHandler; 947 EmptyBufferDoneThreadSafeCallbackAOEnc* iThreadSafeHandlerEmptyBufferDone; 948 FillBufferDoneThreadSafeCallbackAOEnc* iThreadSafeHandlerFillBufferDone; 949 950 OMX_CALLBACKTYPE iCallbacks; // structure that contains callback ptrs. 951 // OMX CALLBACKS 952 // 1) AO OMX component running in the same thread as the OMX node 953 // In this case, the callbacks can be called directly from the component 954 // The callback: OMX Component->CallbackEventHandler->EventHandlerProcessing 955 // The callback can perform do RunIfNotReady 956 957 // 2) Multithreaded component 958 // In this case, the callback is made using the threadsafe callback (TSCB) AO 959 // Component thread : OMX Component->CallbackEventHandler->TSCB(ReceiveEvent) 960 // Node thread : TSCB(ProcessEvent)->ProcessCallbackEventHandler_MultiThreaded->EventHandlerProcessing 961 962 963 //============================================================================== 964 965 OMX_ERRORTYPE EventHandlerProcessing(OMX_OUT OMX_HANDLETYPE aComponent, 966 OMX_OUT OMX_PTR aAppData, 967 OMX_OUT OMX_EVENTTYPE aEvent, 968 OMX_OUT OMX_U32 aData1, 969 OMX_OUT OMX_U32 aData2, 970 OMX_OUT OMX_PTR aEventData); 971 972 OMX_ERRORTYPE EmptyBufferDoneProcessing(OMX_OUT OMX_HANDLETYPE aComponent, 973 OMX_OUT OMX_PTR aAppData, 974 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer); 975 976 OMX_ERRORTYPE FillBufferDoneProcessing(OMX_OUT OMX_HANDLETYPE aComponent, 977 OMX_OUT OMX_PTR aAppData, 978 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer); 979 980 981 IsComponentMultiThreaded()982 bool IsComponentMultiThreaded() 983 { 984 return iIsOMXComponentMultiThreaded; 985 }; 986 987 988 // From PvmiCapabilityAndConfig 989 void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver); 990 PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements, PvmiCapabilityContext aContext); 991 PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements); 992 void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 993 void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext, PvmiKvp* aParameters, int aNumParamElements); 994 void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext); 995 void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements, PvmiKvp* &aRetKVP); 996 PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements, PvmiKvp*& aRetKVP, OsclAny* aContext = NULL); 997 uint32 getCapabilityMetric(PvmiMIOSession aSession); 998 PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements); 999 1000 // Virtual functions of PVMp4H263EncExtensionInterface 1001 // OSCL_IMPORT_REF void addRef(); 1002 // OSCL_IMPORT_REF void removeRef(); 1003 // OSCL_IMPORT_REF bool queryInterface(const PVUuid& uuid, PVInterface*& iface); 1004 OSCL_IMPORT_REF bool SetNumLayers(uint32 aNumLayers); 1005 OSCL_IMPORT_REF bool SetOutputBitRate(uint32 aLayer, uint32 aBitRate); 1006 OSCL_IMPORT_REF bool SetOutputFrameSize(uint32 aLayer, uint32 aWidth, uint32 aHeight); 1007 OSCL_IMPORT_REF bool SetOutputFrameRate(uint32 aLayer, OsclFloat aFrameRate); 1008 OSCL_IMPORT_REF bool SetSegmentTargetSize(uint32 aLayer, uint32 aSizeBytes); 1009 OSCL_IMPORT_REF bool SetRateControlType(uint32 aLayer, PVMFVENRateControlType aRateControl); 1010 OSCL_IMPORT_REF bool SetDataPartitioning(bool aDataPartitioning); 1011 OSCL_IMPORT_REF bool SetRVLC(bool aRVLC); 1012 OSCL_IMPORT_REF bool SetIFrameInterval(uint32 aIFrameInterval); 1013 OSCL_IMPORT_REF bool GetVolHeader(OsclRefCounterMemFrag& aVolHeader); 1014 OSCL_IMPORT_REF bool RequestIFrame(); 1015 OSCL_IMPORT_REF bool SetSceneDetection(bool aSCD); 1016 OSCL_IMPORT_REF bool SetCodec(PVMFFormatType aCodec); 1017 1018 1019 1020 PVMFStatus SetCodecType(PVMFFormatType aCodec); 1021 1022 OSCL_IMPORT_REF virtual bool SetFSIParam(uint8* aFSIBuff, int aFSIBuffLength); 1023 1024 // from AudioEncExtensionInterface 1025 OSCL_IMPORT_REF PVMFStatus SetOutputBitRate(PVMF_GSMAMR_Rate aBitRate); 1026 OSCL_IMPORT_REF PVMFStatus SetMaxNumOutputFramesPerBuffer(uint32 aNumOutputFrames); 1027 OSCL_IMPORT_REF PVMFStatus SetOutputBitRate(uint32 aBitRate); 1028 OSCL_IMPORT_REF PVMFStatus SetOutputNumChannel(uint32 aNumChannel); 1029 OSCL_IMPORT_REF PVMFStatus SetOutputSamplingRate(uint32 aSamplingRate); 1030 1031 1032 PVMFStatus SetInputSamplingRate(uint32 aSamplingRate); 1033 PVMFStatus SetInputBitsPerSample(uint32 aBitsPerSample); 1034 PVMFStatus SetInputNumChannels(uint32 aNumChannels); 1035 uint32 GetOutputBitRate(); // for audio - void 1036 // encoder input format setting 1037 ///////////////////////////////////////////////////// 1038 // Encoder settings routine 1039 ///////////////////////////////////////////////////// 1040 PVMFStatus SetInputFormat(PVMFFormatType aFormat); 1041 PVMFStatus SetInputFrameSize(uint32 aWidth, uint32 aHeight, uint8 aFrmOrient = 0); 1042 PVMFStatus SetInputFrameRate(OsclFloat aFrameRate); 1043 1044 1045 PVMFFormatType GetCodecType(); 1046 uint32 GetOutputBitRate(uint32 aLayer); 1047 OsclFloat GetOutputFrameRate(uint32 aLayer); 1048 PVMFStatus GetOutputFrameSize(uint32 aLayer, uint32& aWidth, uint32& aHeight); 1049 uint32 GetIFrameInterval(); 1050 uint32 GetOutputSamplingRate(); 1051 uint32 GetOutputNumChannels(); 1052 1053 // Capability exchange 1054 PVMFNodeCapability iCapability; 1055 1056 private: 1057 void CommandComplete(PVMFOMXEncNodeCmdQ& aCmdQ, PVMFOMXEncNodeCommand& aCmd, PVMFStatus aStatus, OsclAny* aEventData = NULL); 1058 1059 void DoQueryUuid(PVMFOMXEncNodeCommand&); 1060 void DoQueryInterface(PVMFOMXEncNodeCommand&); 1061 void DoRequestPort(PVMFOMXEncNodeCommand&); 1062 void DoReleasePort(PVMFOMXEncNodeCommand&); 1063 void DoInit(PVMFOMXEncNodeCommand&); 1064 void DoPrepare(PVMFOMXEncNodeCommand&); 1065 void DoStart(PVMFOMXEncNodeCommand&); 1066 void DoStop(PVMFOMXEncNodeCommand&); 1067 void DoPause(PVMFOMXEncNodeCommand&); 1068 void DoReset(PVMFOMXEncNodeCommand&); 1069 void DoFlush(PVMFOMXEncNodeCommand&); 1070 PVMFStatus DoGetNodeMetadataKey(PVMFOMXEncNodeCommand&); 1071 PVMFStatus DoGetNodeMetadataValue(PVMFOMXEncNodeCommand&); 1072 void DoCancelAllCommands(PVMFOMXEncNodeCommand&); 1073 void DoCancelCommand(PVMFOMXEncNodeCommand&); 1074 1075 void Run(); 1076 bool ProcessCommand(PVMFOMXEncNodeCommand& aCmd); 1077 bool ProcessIncomingMsg(PVMFPortInterface* aPort); 1078 bool ProcessOutgoingMsg(PVMFPortInterface* aPort); 1079 PVMFStatus HandleProcessingState(); 1080 1081 1082 1083 1084 // DV: 1085 bool NegotiateVideoComponentParameters(); 1086 bool SetMP4EncoderParameters(); 1087 bool SetH263EncoderParameters(); 1088 bool SetH264EncoderParameters(); 1089 1090 bool NegotiateAudioComponentParameters(); 1091 bool SetAMREncoderParameters(); 1092 bool SetAACEncoderParameters(); 1093 1094 bool SetDefaultCapabilityFlags(); 1095 bool CreateOutMemPool(uint32 num); 1096 bool CreateInputMemPool(uint32 num); 1097 bool ProvideBuffersToComponent(OsclMemPoolFixedChunkAllocator *aMemPool, // allocator 1098 uint32 aAllocSize, // size to allocate from pool (hdr only or hdr+ buffer) 1099 uint32 aNumBuffers, // number of buffers 1100 uint32 aActualBufferSize, // aactual buffer size 1101 uint32 aPortIndex, // port idx 1102 bool aUseBufferOK, // can component use OMX_UseBuffer? 1103 bool aIsThisInputBuffer // is this input or output 1104 ); 1105 1106 bool FreeBuffersFromComponent(OsclMemPoolFixedChunkAllocator *aMemPool, // allocator 1107 uint32 aAllocSize, // size to allocate from pool (hdr only or hdr+ buffer) 1108 uint32 aNumBuffers, // number of buffers 1109 uint32 aPortIndex, // port idx 1110 bool aIsThisInputBuffer // is this input or output 1111 ); 1112 1113 OsclSharedPtr<class PVMFMediaDataImpl> WrapOutputBuffer(uint8 *pData, uint32 aDataLen, OsclAny *pContext); 1114 bool QueueOutputBuffer(OsclSharedPtr<PVMFMediaDataImpl> &mediadataimplout, uint32 aDataLen); 1115 1116 bool SendOutputBufferToOMXComponent(); 1117 bool SendInputBufferToOMXComponent(); 1118 1119 1120 bool SendEOSBufferToOMXComponent(); 1121 1122 bool SendBeginOfMediaStreamCommand(void); 1123 bool SendEndOfTrackCommand(void); 1124 1125 1126 1127 bool ReleaseAllPorts(); 1128 bool DeleteOMXEncoder(); 1129 1130 void ChangeNodeState(TPVMFNodeInterfaceState aNewState); 1131 1132 void HandleComponentStateChange(OMX_U32 encoder_state); 1133 1134 // Capability And Config Helper Methods 1135 PVMFStatus DoCapConfigGetParametersSync(PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements, PvmiCapabilityContext aContext); 1136 PVMFStatus DoCapConfigReleaseParameters(PvmiKvp* aParameters, int aNumElements); 1137 void DoCapConfigSetParameters(PvmiKvp* aParameters, int aNumElements, PvmiKvp* &aRetKVP); 1138 PVMFStatus DoCapConfigVerifyParameters(PvmiKvp* aParameters, int aNumElements); 1139 1140 PVMFStatus GetConfigParameter(PvmiKvp*& aParameters, int& aNumParamElements, int32 aIndex, PvmiKvpAttr aReqattr); 1141 PVMFStatus VerifyAndSetConfigParameter(PvmiKvp& aParameter, bool aSetParam); 1142 1143 PVMFStatus GetProfileAndLevel(PVMF_MPEGVideoProfileType& aProfile, PVMF_MPEGVideoLevelType& aLevel); 1144 1145 1146 1147 void freechunkavailable(OsclAny*); 1148 1149 PVMFCommandId QueueCommandL(PVMFOMXEncNodeCommand& aCmd); 1150 1151 1152 int32 PushBackKeyVal(Oscl_Vector<PvmiKvp, OsclMemAllocator>*&, PvmiKvp&); 1153 int32 Push_Back_MetadataKeys(const char*); 1154 int32 Push_Back_MetadataKeys(PVMFMetadataList*&, uint32); 1155 int32 CreateNewArray(char*&, int32); 1156 int32 MemAllocate(OsclAny*& , OsclMemPoolFixedChunkAllocator*, uint32); 1157 1158 bool ParseFullAVCFramesIntoNALs(OMX_BUFFERHEADERTYPE* aOutputBuffer); 1159 bool AVCAnnexBGetNALUnit(uint8 *bitstream, uint8 **nal_unit, int32 *size, bool getPtrOnly); 1160 bool CheckM4vVopStartCode(uint8* data, int* len); 1161 1162 friend class PVMFOMXEncPort; 1163 1164 // Ports pointers 1165 PVMFPortInterface* iInPort; 1166 PVMFPortInterface* iOutPort; 1167 1168 // Commands 1169 PVMFOMXEncNodeCmdQ iInputCommands; 1170 PVMFOMXEncNodeCmdQ iCurrentCommand; 1171 1172 // Shared pointer for Media Msg.Input buffer 1173 PVMFSharedMediaDataPtr iDataIn; 1174 1175 1176 // OUTPUT BUFFER RELATED MEMBERS 1177 1178 1179 // Output buffer memory pool 1180 OsclMemPoolFixedChunkAllocator *iOutBufMemoryPool; 1181 1182 // Memory pool for simple media data 1183 OsclMemPoolFixedChunkAllocator *iMediaDataMemPool; 1184 1185 // Size of output buffer (negotiated with component) 1186 uint32 iOMXComponentOutputBufferSize; 1187 1188 // size of output to allocate (OMX_ALLOCATE_BUFFER = size of buf header ) 1189 // (OMX_USE_BUFFER = size of buf header + iOMXCoponentOutputBufferSize) 1190 uint32 iOutputAllocSize; 1191 1192 // Number of output buffers (negotiated with component) 1193 uint32 iNumOutputBuffers; 1194 1195 // Number of output buffers in possession of the component or downstream, 1196 // namely, number of unavailable buffers 1197 uint32 iNumOutstandingOutputBuffers; 1198 1199 // flag to prevent sending output buffers downstream during flushing etc. 1200 bool iDoNotSendOutputBuffersDownstreamFlag; 1201 1202 // flag to prevent freeing the buffers twice 1203 bool iOutputBuffersFreed; 1204 1205 1206 // INPUT BUFFER RELATED MEMBERS 1207 OsclMemPoolFixedChunkAllocator *iInBufMemoryPool; 1208 uint32 iOMXComponentInputBufferSize; // size of input buffer that the component sees (negotiated with the component) 1209 uint32 iInputAllocSize; // size of input buffer to allocate (OMX_ALLOCATE_BUFFER = size of buf header ) 1210 // (OMX_USE_BUFFER = size of buf header + iOMXCoponentInputBufferSize) 1211 uint32 iNumInputBuffers; // total num of input buffers (negotiated with component) 1212 1213 uint32 iNumOutstandingInputBuffers; // number of input buffers in use (i.e. unavailable) 1214 1215 bool iDoNotSaveInputBuffersFlag; 1216 1217 // flag to prevent freeing buffers twice 1218 bool iInputBuffersFreed; 1219 1220 // input buffer fragmentation etc. 1221 uint32 iCopyPosition; // for copying memfrag data into a buffer 1222 uint32 iFragmentSizeRemainingToCopy; 1223 bool iIsNewDataFragment; 1224 1225 // input data info 1226 uint32 iCurrFragNum; 1227 uint32 iCodecSeqNum; // sequence number tracking 1228 uint32 iInPacketSeqNum; 1229 1230 uint32 iInTimestamp; 1231 uint32 iInDuration; 1232 uint32 iInNumFrags; 1233 uint32 iCurrentMsgMarkerBit; 1234 1235 // DYNAMIC PORT RE-CONFIGURATION 1236 uint32 iInputPortIndex; 1237 uint32 iOutputPortIndex; 1238 OMX_PARAM_PORTDEFINITIONTYPE iParamPort; 1239 uint32 iPortIndexForDynamicReconfig; 1240 bool iSecondPortReportedChange; 1241 bool iDynamicReconfigInProgress; 1242 uint32 iSecondPortToReconfig; 1243 1244 1245 1246 OMX_BUFFERHEADERTYPE *iInputBufferToResendToComponent; // ptr to input buffer that is not empty, but that the OMX component returned 1247 // we need to resend this same buffer back to the component 1248 1249 1250 ////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS 1251 bool iOMXComponentSupportsExternalOutputBufferAlloc; 1252 bool iOMXComponentSupportsExternalInputBufferAlloc; 1253 bool iOMXComponentSupportsMovableInputBuffers; 1254 bool iOMXComponentUsesNALStartCodes; 1255 bool iOMXComponentSupportsPartialFrames; 1256 bool iOMXComponentCanHandleIncompleteFrames; 1257 bool iOMXComponentUsesFullAVCFrames; 1258 1259 bool iSetMarkerBitForEveryFrag; 1260 bool iIsOMXComponentMultiThreaded; 1261 1262 // State definitions for HandleProcessingState() state machine 1263 typedef enum 1264 { 1265 EPVMFOMXEncNodeProcessingState_Idle, //default state after constraction/reset 1266 EPVMFOMXEncNodeProcessingState_ReadyToEncode, //nornal operation state of the encoder 1267 EPVMFOMXEncNodeProcessingState_WaitForOutputBuffer, //wait state for avalible media output buffer 1268 EPVMFOMXEncNodeProcessingState_WaitForOutputPort, //wait state, output port is busy 1269 EPVMFOMXEncNodeProcessingState_WaitForOutgoingQueue, //wait state, outgoing queue 1270 EPVMFOMXEncNodeProcessingState_PortReconfig, // Dynamic Port Reconfiguration - step 1 1271 EPVMFOMXEncNodeProcessingState_WaitForBufferReturn, // step 2 1272 EPVMFOMXEncNodeProcessingState_WaitForPortDisable, // Dynamic Port Reconfiguration - step 3 1273 EPVMFOMXEncNodeProcessingState_PortReEnable, // Dynamic Port Reconfiguration - step 4 1274 EPVMFOMXEncNodeProcessingState_WaitForPortEnable, // step 5 1275 EPVMFOMXEncNodeProcessingState_Stopping // when STOP command is issued, the node has to wait for component to transition into 1276 // idle state. The buffers keep coming back , the node is rescheduled 1277 // to run. Prevent the node from sending buffers back 1278 } PVMFOMXEncNode_ProcessingState; 1279 1280 // State of HandleProcessingState() state machine 1281 PVMFOMXEncNode_ProcessingState iProcessingState; 1282 1283 // Handle of OMX Component 1284 OMX_HANDLETYPE iOMXEncoder; 1285 1286 // Current State of the component 1287 OMX_STATETYPE iCurrentEncoderState; 1288 1289 // BOS 1290 bool iSendBOS; 1291 uint32 iStreamID; 1292 uint32 iBOSTimestamp; 1293 1294 //EOS control flags 1295 bool iIsEOSSentToComponent; 1296 bool iIsEOSReceivedFromComponent; 1297 1298 // Send Fsi configuration flag 1299 bool sendYuvFsi; 1300 1301 // Width of encoded frame 1302 int32 iYUVWidth; 1303 // Height of encoded frame 1304 int32 iYUVHeight; 1305 1306 1307 1308 // Pointer to input data fragment 1309 uint8* iBitstreamBuffer; 1310 // Size of input data fragment 1311 int32 iBitstreamSize; 1312 1313 // Output frame sequence counter 1314 uint32 iSeqNum; 1315 1316 // Input frame sequence counter 1317 uint32 iSeqNum_In; 1318 1319 // Added to Scheduler Flag 1320 bool iIsAdded; 1321 1322 // Log related 1323 PVLogger* iLogger; 1324 PVLogger* iDataPathLogger; 1325 PVLogger* iClockLogger; 1326 PVLogger *iRunlLogger; 1327 const char *iNodeTypeId; 1328 1329 // Counter of fragment read from current Media Msg.Input buffer 1330 uint fragnum; 1331 // Number of fragments in the Media Msg.Input buffer 1332 uint numfrags; 1333 1334 1335 // Node configuration update 1336 //PVMFOMXEncNodeConfig iNodeConfig; 1337 1338 // Reference counter for extension 1339 uint32 iExtensionRefCount; 1340 1341 // Vector for KVP 1342 Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> iAvailableMetadataKeys; 1343 1344 // EOS flag 1345 bool iEndOfDataReached; 1346 // Time stame upon EOS 1347 PVMFTimestamp iEndOfDataTimestamp; 1348 1349 /* Diagnostic log related */ 1350 PVLogger* iDiagnosticsLogger; 1351 bool iDiagnosticsLogged; 1352 void LogDiagnostics(); 1353 1354 uint32 iFrameCounter; 1355 1356 1357 1358 uint32 iAvgBitrateValue; 1359 bool iResetInProgress; 1360 bool iResetMsgSent; 1361 bool iStopInResetMsgSent; 1362 1363 PV_VideoEncodeParam iVideoEncodeParam; 1364 PV_VideoInputFormat iVideoInputFormat; 1365 PV_AudioEncodeParam iAudioEncodeParam; 1366 PV_AudioInputFormat iAudioInputFormat; 1367 1368 PVMFFormatType iInFormat; 1369 PVMFFormatType iOutFormat; 1370 1371 PVMFOMXEncNodeAllocDestructDealloc iAlloc; 1372 OsclRefCounterMemFrag iVolHeader; /** Vol header */ 1373 OsclRefCounterMemFrag iConfigHeader; 1374 1375 OsclRefCounterMemFrag iParamSet; /* place holder for sps,pps values */ 1376 OsclMemoryFragment iSPSs[PVMF_AVCENC_NODE_SPS_VECTOR_RESERVE]; // just ptrs 1377 OsclMemoryFragment iPPSs[PVMF_AVCENC_NODE_PPS_VECTOR_RESERVE]; // just ptrs 1378 int iNumSPSs; 1379 int iNumPPSs; 1380 bool iSpsPpsSequenceOver; 1381 OsclSharedPtr<PVMFMediaDataImpl> iPreviousMediaData; 1382 bool iFirstNAL; 1383 uint32* iNALSizeArray; 1384 uint8** iNALPtrArray; 1385 uint32 iNALSizeArrayMaxElems; 1386 uint32 iNumNALs; 1387 uint32 iFirstNALStartCodeSize; 1388 1389 uint32 iEndOfFrameFlagPrevious; 1390 uint32 iKeyFrameFlagPrevious; 1391 uint32 iEndOfNALFlagPrevious; 1392 OMX_TICKS iTimeStampPrevious; 1393 uint32 iBufferLenPrevious; 1394 1395 uint32 iEndOfFrameFlagOut; 1396 uint32 iKeyFrameFlagOut; 1397 uint32 iEndOfNALFlagOut; 1398 OMX_TICKS iTimeStampOut; 1399 uint32 iBufferLenOut; 1400 OsclAny **out_ctrl_struct_ptr ; 1401 OsclAny **out_buff_hdr_ptr ; 1402 OsclAny **in_ctrl_struct_ptr ; 1403 OsclAny **in_buff_hdr_ptr ; 1404 // timescale, timestamp conversions 1405 uint32 iTimeScale; 1406 uint32 iInTimeScale; 1407 uint32 iOutTimeScale; 1408 1409 MediaClockConverter iInputTimestampClock; 1410 OMX_TICKS iOMXTicksTimestamp; 1411 OMX_TICKS ConvertTimestampIntoOMXTicks(const MediaClockConverter &src); 1412 uint32 ConvertOMXTicksIntoTimestamp(const OMX_TICKS &src); 1413 1414 PVInterface* ipExternalInputBufferAllocatorInterface; 1415 PVMFFixedSizeBufferAlloc* ipFixedSizeBufferAlloc; 1416 1417 #ifdef _TEST_AE_ERROR_HANDLING 1418 bool iErrorHandlingInit; 1419 uint32 iErrorHandlingEncodeCount; 1420 int iCountFrames; 1421 uint32 iErrorNodeCmd; 1422 bool iErrorConfigHeader; 1423 uint32 iErrorEncodeFlag; 1424 uint32 iErrorDataPathStall; 1425 #endif 1426 }; 1427 1428 1429 #endif // PVMF_OMXENC_NODE_H_INCLUDED 1430 1431