1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2010 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 #ifndef PVMF_OMX_ENC_NODE_H_INCLUDED
19 #define PVMF_OMX_ENC_NODE_H_INCLUDED
21 #ifndef OSCL_BASE_H_INCLUDED
22 #include "oscl_base.h"
25 #ifndef OSCL_SCHEDULER_AO_H_INCLUDED
26 #include "oscl_scheduler_ao.h"
29 #ifndef PVMF_FORMAT_TYPE_H_INCLUDED
30 #include "pvmf_format_type.h"
33 #ifndef PVMF_NODE_INTERFACE_H_INCLUDED
34 #include "pvmf_node_interface.h"
37 #ifndef OSCL_PRIQUEUE_H_INCLUDED
38 #include "oscl_priqueue.h"
41 #ifndef PVMF_MEDIA_DATA_H_INCLUDED
42 #include "pvmf_media_data.h"
45 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED
46 #include "oscl_mem_mempool.h"
48 #ifndef PVMF_MEMPOOL_H_INCLUDED
49 #include "pvmf_mempool.h"
52 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED
53 #include "pvmf_simple_media_buffer.h"
56 #ifndef PVMF_MEDIA_FRAG_GROUP_H_INCLUDED
57 #include "pvmf_media_frag_group.h"
60 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED
61 #include "pvmf_pool_buffer_allocator.h"
64 #ifndef PVMF_VIDEO_H_INCLUDED
65 #include "pvmf_video.h"
68 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED
69 #include "pvmf_pool_buffer_allocator.h"
72 #ifndef PVMF_NODE_UTILS_H_INCLUDED
73 #include "pvmf_node_utils.h"
76 #ifndef PVMF_OMX_ENC_PORT_H_INCLUDED
77 #include "pvmf_omx_enc_port.h"
80 #ifndef PVMF_OMX_ENC_NODE_EXTENSION_INTERFACE_H_INCLUDED
81 #include "pvmf_omx_enc_node_extension_interface.h"
84 #ifndef PV_VIDEO_ENCNODE_EXTENSION_H_INCLUDED
85 #include "pv_video_encnode_extension.h"
88 #ifndef PVMF_AUDIO_ENCNODE_EXTENSION_H_INCLUDED
89 #include "pvmf_audio_encnode_extension.h"
92 // DV: NOTE - this needs to be fixed
93 //#ifndef __PVM4VENCODER_H
94 //#include "pvm4vencoder.h"
97 #ifndef PVMF_META_DATA_EXTENSION_H_INCLUDED
98 #include "pvmf_meta_data_extension.h"
101 #ifndef PV_MIME_STRING_UTILS_H_INCLUDED
102 #include "pv_mime_string_utils.h"
106 #include "OMX_Core.h"
109 #ifndef OMX_Component_h
110 #include "OMX_Component.h"
113 #ifndef PVMF_OMX_ENC_CALLBACKS_H_INCLUDED
114 #include "pvmf_omx_enc_callbacks.h"
117 #ifndef PV_OMXDEFS_H_INCLUDED
118 #include "pv_omxdefs.h"
121 #ifndef OSCLCONFIG_IO_H_INCLUDED
122 #include "osclconfig_io.h"
124 #ifndef OSCL_MEM_H_INCLUDED
125 #include "oscl_mem.h"
128 #if (PVLOGGER_INST_LEVEL >= PVLOGMSG_INST_REL)
129 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED
130 #include "pvmf_media_clock.h"
134 #ifndef __MEDIA_CLOCK_CONVERTER_H
135 #include "media_clock_converter.h"
138 #ifndef PV_M4V_CONFIG_PARSER_H_INCLUDED
139 #include "m4v_config_parser.h"
142 #define PVMFOMXENCNODE_NUM_CMD_IN_POOL 8
143 #define PVOMXENCMAXNUMDPBFRAMESPLUS1 17
144 #define PVOMXVIDEO_MAX_SUPPORTED_FORMAT 12
145 #define PVOMXAUDIO_MAX_SUPPORTED_FORMAT 31
146 #define PVOMXCOLOR_MAX_SUPPORTED_FORMAT 44
150 typedef struct OutputBufCtrlStruct
152 OMX_BUFFERHEADERTYPE *pBufHdr;
153 OsclAny *pMemPoolEntry;
154 } OutputBufCtrlStruct;
156 typedef struct InputBufCtrlStruct
158 OMX_BUFFERHEADERTYPE *pBufHdr;
159 PVMFSharedMediaDataPtr pMediaData;
160 OsclAny *pMemPoolEntry;
161 } InputBufCtrlStruct;
164 // fwd class declaration
166 //memory allocator type for this node.
167 typedef OsclMemAllocator PVMFOMXEncNodeAllocator;
168 typedef OsclMemAllocDestructDealloc<uint8> PVMFOMXEncNodeAllocDestructDealloc;
171 // CALLBACK PROTOTYPES
172 OMX_ERRORTYPE CallbackEventHandlerEnc(OMX_OUT OMX_HANDLETYPE aComponent,
173 OMX_OUT OMX_PTR aAppData,
174 OMX_OUT OMX_EVENTTYPE aEvent,
175 OMX_OUT OMX_U32 aData1,
176 OMX_OUT OMX_U32 aData2,
177 OMX_OUT OMX_PTR aEventData);
179 OMX_ERRORTYPE CallbackEmptyBufferDoneEnc(OMX_OUT OMX_HANDLETYPE aComponent,
180 OMX_OUT OMX_PTR aAppData,
181 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer);
183 OMX_ERRORTYPE CallbackFillBufferDoneEnc(OMX_OUT OMX_HANDLETYPE aComponent,
184 OMX_OUT OMX_PTR aAppData,
185 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer);
189 //Default values for number of Input/Output buffers. If the component needs more than this, it will be
190 // negotiated. If the component does not need more than this number, the default is used
191 #define NUMBER_INPUT_BUFFER 5
192 // NUMBER_OUTPUT_BUFFER is being used in Mp4 Composer node for File-Writer Thread Queue.
193 // Need to update the same #define in pvmp4ffcn_node.cpp if updated here.
194 #define NUMBER_OUTPUT_BUFFER 9
197 #define MAX_NUM_AMR_FRAMES_PER_BUFFER 25
198 #define PVMF_AMRENC_DEFAULT_SAMPLING_RATE 8000
199 #define PVMF_AMRENC_DEFAULT_NUM_CHANNELS 1
200 #define PVMF_AMRENC_DEFAULT_BITSPERSAMPLE 16
202 #define PVMF_AMRENC_DEFAULT_FRAME_DURATION 20
204 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
205 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
206 /////////////////////////
207 /////////////////////////
208 /////////////////////////
209 // CUSTOM DEALLOCATOR FOR MEDIA DATA SHARED PTR WRAPPER:
210 // 1) Deallocates the underlying output buffer
211 // 2) Deallocates the pvci buffer wrapper and the rest of accompanying structures
212 // Deallocator is created as part of the wrapper, and travels with the buffer wrapper
214 class PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA : public OsclDestructDealloc
217 PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA(Oscl_DefAlloc* allocator, void *pMempoolData) :
218 buf_alloc(allocator), ptr_to_data_to_dealloc(pMempoolData) {};
219 virtual ~PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA() {};
221 virtual void destruct_and_dealloc(OsclAny* ptr)
223 // call buffer deallocator
224 if (buf_alloc != NULL)
226 buf_alloc->deallocate(ptr_to_data_to_dealloc);
229 // this is needed to completely free PVMFMediaDataImpl, since it allocates memory for the frag list
230 ((PVMFMediaDataImpl*)ptr)->~PVMFMediaDataImpl();
235 Oscl_DefAlloc* buf_alloc;
236 void *ptr_to_data_to_dealloc;
241 #define PVMFOMXEncNodeCommandBase PVMFGenericNodeCommand<PVMFOMXEncNodeAllocator>
243 class PVMFOMXEncNodeCommand: public PVMFOMXEncNodeCommandBase
246 //constructor for Custom2 command
247 void Construct(PVMFSessionId s, int32 cmd, int32 arg1, int32 arg2, int32& arg3, const OsclAny*aContext)
249 PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext);
250 iParam1 = (OsclAny*)arg1;
251 iParam2 = (OsclAny*)arg2;
252 iParam3 = (OsclAny*) & arg3;
254 void Parse(int32&arg1, int32&arg2, int32*&arg3)
256 arg1 = (int32)iParam1;
257 arg2 = (int32)iParam2;
258 arg3 = (int32*)iParam3;
261 void Construct(PVMFSessionId s, int32 cmd, PVMFMetadataList* aKeyList, uint32 aStartIndex, int32 aMaxEntries, char* aQueryKey, const OsclAny* aContext)
263 PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext);
264 iStartIndex = aStartIndex;
265 iMaxEntries = aMaxEntries;
267 if (aQueryKey == NULL)
273 if (aQueryKey != NULL)
274 oscl_strncpy(query_key, aQueryKey, oscl_strlen(aQueryKey) + 1);
277 iParam1 = (OsclAny*)aKeyList;
284 void Parse(PVMFMetadataList*& MetaDataListPtr, uint32 &aStartingIndex, int32 &aMaxEntries, char*&aQueryKey)
286 MetaDataListPtr = (PVMFMetadataList*)iParam1;
287 aStartingIndex = iStartIndex;
288 aMaxEntries = iMaxEntries;
289 if (query_key[0] == 0)
295 aQueryKey = query_key;
299 // Constructor and parser for GetNodeMetadataValue
300 void Construct(PVMFSessionId s, int32 cmd, PVMFMetadataList* aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>* aValueList, uint32 aStartIndex, int32 aMaxEntries, const OsclAny* aContext)
302 PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext);
303 iParam1 = (OsclAny*)aKeyList;
304 iParam2 = (OsclAny*)aValueList;
306 iStartIndex = aStartIndex;
307 iMaxEntries = aMaxEntries;
313 void Parse(PVMFMetadataList* &aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>* &aValueList, uint32 &aStartingIndex, int32 &aMaxEntries)
315 aKeyList = (PVMFMetadataList*)iParam1;
316 aValueList = (Oscl_Vector<PvmiKvp, OsclMemAllocator>*)iParam2;
317 aStartingIndex = iStartIndex;
318 aMaxEntries = iMaxEntries;
324 //this routine identifies commands that need to
325 //go at the front of the queue. derived command
326 //classes can override it if needed.
327 return (iCmd == PVOMXENC_NODE_CMD_CANCELALL
328 || iCmd == PVOMXENC_NODE_CMD_CANCELCMD);
331 enum PVOMXEncNodeCmdType
333 PVOMXENC_NODE_CMD_QUERYINTERFACE,
334 PVOMXENC_NODE_CMD_REQUESTPORT,
335 PVOMXENC_NODE_CMD_RELEASEPORT,
336 PVOMXENC_NODE_CMD_INIT,
337 PVOMXENC_NODE_CMD_PREPARE,
338 PVOMXENC_NODE_CMD_START,
339 PVOMXENC_NODE_CMD_STOP,
340 PVOMXENC_NODE_CMD_FLUSH,
341 PVOMXENC_NODE_CMD_PAUSE,
342 PVOMXENC_NODE_CMD_RESET,
343 PVOMXENC_NODE_CMD_CANCELALL,
344 PVOMXENC_NODE_CMD_CANCELCMD,
345 PVOMXENC_NODE_CMD_GETNODEMETADATAKEY,
346 PVOMXENC_NODE_CMD_GETNODEMETADATAVALUE,
347 PVOMXENC_NODE_CMD_INVALID
360 //Default vector reserve size
361 #define PVMF_OMXENC_NODE_COMMAND_VECTOR_RESERVE 10
363 //Starting value for command IDs
364 #define PVMF_OMXENC_NODE_COMMAND_ID_START 6000
366 ////////////////////////////////////////////////////////////////////////////////////////////////////
367 //////////////////////////////////// STRUCTURES FOR ENCODING PARAMETERS ////////////////////////////
368 ////////////////////////////////////////////////////////////////////////////////////////////////////
371 /** Contains supported input format */
372 enum EncVideoInputFormat
380 /** Targeted profile and level to encode. */
381 enum EncM4VProfileLevel
383 /* Non-scalable profile */
384 EI_SIMPLE_LEVEL0 = 0,
393 /* Scalable profile */
394 EI_SIMPLE_SCALABLE_LEVEL0,
395 EI_SIMPLE_SCALABLE_LEVEL1,
396 EI_SIMPLE_SCALABLE_LEVEL2,
398 EI_CORE_SCALABLE_LEVEL1,
399 EI_CORE_SCALABLE_LEVEL2,
400 EI_CORE_SCALABLE_LEVEL3
403 /** Targeted profile to encode. */
406 /* Non-scalable profile */
417 /** Targeted level to encode. */
440 enum TAVCEIOutputFormat
442 /** output in byte stream format according to Annex B */
443 EAVCEI_OUTPUT_ANNEXB,
445 /** output for MP4 file format */
448 /** output in RTP format according to RFC 3984 */
454 /** Type of contents for optimal encoding mode. */
457 /** Content is encoded as fast as possible with error protection */
460 /** Content is encoded as fast as possible without error protection */
463 /** Content is encoded with better quality (slow) with error protection */
464 EI_ENCMODE_STREAMING,
466 /** Content is encoded with better quality (slow) without error protection */
471 /** This structure contains encoder settings. */
472 typedef struct PV_VideoEncodeParam
475 ////////////////////////////////////////////////////////////////////////////////////
476 ////////////////////////// COMMON PARAMETERS ///////////////////////////////////////
477 ////////////////////////////////////////////////////////////////////////////////////
479 /** Specifies an ID that will be used to specify this encoder while returning
480 the bitstream in asynchronous mode. */
484 /** Specifies whether base only (iNumLayer = 1) or base + enhancement layer
485 (iNumLayer =2 ) is to be used. */
488 /** Specifies the width in pixels of the encoded frames. IFrameWidth[0] is for
489 base layer and iFrameWidth[1] is for enhanced layer. */
490 int iFrameWidth[MAX_LAYER];
492 /** Specifies the height in pixels of the encoded frames. IFrameHeight[0] is for
493 base layer and iFrameHeight[1] is for enhanced layer. */
494 int iFrameHeight[MAX_LAYER];
496 /** Specifies the cumulative bit rate in bit per second. IBitRate[0] is for base
497 layer and iBitRate[1] is for base+enhanced layer.*/
498 int iBitRate[MAX_LAYER];
500 /** Specifies maximum instantanious bit rate in bit per second. Only applicable
501 in VBR rate control mode. This parameter deprecates iBufferDelay. IBitRate[0] is
502 for base layer and iBitRate[1] is for base+enhanced layer.*/
503 int iMaxBitRate[MAX_LAYER];
505 /** Specifies the cumulative frame rate in frame per second. IFrameRate[0] is for
506 base layer and iFrameRate[1] is for base+enhanced layer. */
507 float iFrameRate[MAX_LAYER];
509 /** Specifies the rate control algorithm among one of the following constant Q,
510 CBR and VBR. The structure EncRateControlType is defined above.*/
511 PVMFVENRateControlType iRateControlType;
513 /** Specifies the initial quantization parameter for the first I-frame. If constant Q
514 rate control is used, this QP will be used for all the I-frames. This number must be
515 set between 1 and 31, otherwise, Initialize() will fail. */
518 /** Specifies the initial quantization parameter for the first P-frame. If constant Q
519 rate control is used, this QP will be used for all the P-frames. This number must be
520 set between 1 and 31, otherwise, Initialize() will fail. */
523 /** Specifies the initial quantization parameter for the first B-frame. If constant Q
524 rate control is used, this QP will be used for all the B-frames. This number must be
525 set between 1 and 31, otherwise, Initialize() will fail. */
529 /** Specifies the maximum number of P-frames between 2 INTRA frames. An INTRA mode is
530 forced to a frame once this interval is reached. When there is only one I-frame is present
531 at the beginning of the clip, iIFrameInterval should be set to -1. */
532 int32 iIFrameInterval;
534 /** According to iIFrameInterval setting, the minimum number of intra MB per frame is
535 optimally calculated for error resiliency. However, when iIFrameInterval is set to -1,
536 iNumIntraMBRefresh must be specified to guarantee the minimum number of intra
537 macroblocks per frame.*/
538 uint32 iNumIntraMBRefresh;
540 /** Specifies automatic scene detection where I-frame will be used the the first frame
542 bool iSceneDetection;
544 /** Specifies the packet size in bytes which represents the number of bytes between two resync markers.
545 For EI_M4V_DOWNLOAD and EI_H263, if iPacketSize is set to 0, there will be no resync markers in the bitstream.
546 For EI_M4V_STREAMING is parameter must be set to a value greater than 0. For AVC, this value specifies
547 the packet size in bytes which represents the desired number of bytes per NAL.
548 If this number is set to 0, the AVC encoder will encode the entire slice group as one NAL. */
551 /** Specifies the duration of the clip in millisecond.*/
555 ////////////////////////////////////////////////////////////////////////////////////////
556 /////////////////////////// H263/M4V specific parameters ///////////////////////////////
557 ////////////////////////////////////////////////////////////////////////////////////////
559 /** Specifies the profile and level used to encode the bitstream. When present,
560 other settings will be checked against the range allowable by this target profile
561 and level. Fail may be returned from the Initialize call. */
562 EncM4VProfileLevel iProfileLevel;
564 /** Specifies the picture quality factor on the scale of 1 to 10. It trades off
565 the picture quality with the frame rate. Higher frame quality means lower frame rate.
566 Lower frame quality for higher frame rate.*/
570 /** Enable the use of iFrameQuality to determine the frame rate. If it is false,
571 the encoder will try to meet the specified frame rate regardless of the frame quality.*/
572 bool iEnableFrameQuality;
575 /** Specifies high quality but also high complexity mode for rate control. */
579 /** Specifies the search range in pixel unit for motion vector. The range of the
580 motion vector will be of dimension [-iSearchRange.5, +iSearchRange.0]. */
583 /** Specifies the use of 8x8 motion vectors. */
586 /** Specifies the use of half-pel motion vectors. */
589 /** Specifies whether the current frame skipping decision is allowed after encoding
590 the current frame. If there is no memory of what has been coded for the current frame,
591 iNoCurrentSkip has to be on. */
594 /** Specifies that no frame skipping is allowed. Frame skipping is a tool used to
595 control the average number of bits spent to meet the target bit rate. */
599 /** Specify short header mode in MPEG4 */
602 /** Specifies whethere data partitioning mode is used or not. Has no meaning if encoding H.263 or short header */
603 bool iDataPartitioning;
606 /** Specifies whether Resync markers are used or not Has no meaning if iDataPartitioning is on */
610 /** Specifies whether RVLC (reversible VLC) is to be used or not.
614 ////////////////////////////////////////////////////////////////////////////////////////
615 /////////////////////////// H264 specific parameters ///////////////////////////////
616 ////////////////////////////////////////////////////////////////////////////////////////
618 /** Specifies the targeted profile, and will also specifies available tools for iEncMode.
619 If default is used, encoder will choose its own preferred profile. If autodetect is used, encoder
620 will check other settings and choose the right profile that doesn't have any conflicts. */
621 EncAVCProfile iAVCProfile;
623 /** Specifies the target level When present,
624 other settings will be checked against the range allowable by this target level.
625 Fail will returned upon Initialize call. If not known, users must set it to autodetect. Encoder will
626 calculate the right level that doesn't conflict with other settings. */
627 EncAVCLevel iAVCLevel;
629 /** Specifies the encoding mode. This translates to the complexity of encoding modes and
630 error resilient tools. This is for future use - enc mode will be used to set other parameters to appropriate
634 EncEncodingMode iEncMode;
636 /** Specifies that SPS and PPS are retrieved first and sent out-of-band */
637 //bool iOutOfBandParamSet;
639 /** Specifies FSI Buffer input */
642 /** Specifies FSI Buffer Length */
643 uint32 iFSIBuffLength;
645 /** Sets the number of ticks per second used for timing information encoded in MPEG4 bitstream.*/
648 /** Sets the number of ticks in time increment resolution between 2 source frames (equivalent to source frame rate). */
651 /** Sets the interval of non-empty GOB headers in units of GOBs */
652 uint32 iGOBHdrInterval;
654 } PV_VideoEncodeParam;
658 /** Structure for input format information */
659 typedef struct PV_VideoInputFormat
661 /** Contains the width in pixels of the input frame. */
664 /** Contains the height in pixels of the input frame. */
667 /** Contains the input frame rate in the unit of frame per second. */
670 /** Contains Frame Orientation. Used for RGB input. 1 means Bottom_UP RGB, 0 means Top_Down RGB, -1 for video formats other than RGB*/
671 int iFrameOrientation;
673 /** Contains the format of the input video, e.g., YUV 4:2:0, UYVY, RGB24, etc. */
674 EncVideoInputFormat iVideoFormat;
675 } PV_VideoInputFormat;
678 /** Structure for audio encode information */
679 typedef struct PV_AudioEncodeParam
682 // DESCRIPTION: Final sampling frequency used when encoding in Hz.
683 // For example, "44100" Hz.
684 // USAGE: If the input sampling rate is not appropriate (e.g.,
685 // the codec requires a different sampling frequency),
686 // the CAEI will fill this in with the final sampling
687 // rate. The CAEI will perform resampling if the
688 // input sampling frequency is not the same as the output
689 // sampling frequency.
690 uint32 iOutputSamplingRate;
692 // DESCRIPTION: Number of output channels:1=Mono,2=Stereo. (Mono uses 1
693 // channel; Stereo uses 2 channels).
694 // USAGE: The CAEI will fill this in if it needs to convert
695 // the input samples to what is required by the codec.
696 uint8 iOutputNumChannels;
698 // DESCRIPTION: Currently, output bitrate is expressed as GSM-AMR type rate
699 PVMF_GSMAMR_Rate iAMRBitrate;
701 // DESCRIPTION: output bitrate in bits per second for non-AMR codecs
702 uint32 iOutputBitrate;
705 uint32 iMaxNumOutputFramesPerBuffer;
707 // DESCRIPTION: Aac profile types:
708 // PV_AAC_ENC_LC = LC
709 // PV_AAC_ENC_HE = AAC+
710 // PV_AAC_ENC_HE_PS = eAAC+
711 PVMF_AAC_Profile iAacOutputProfile;
713 } PV_AudioEncodeParam;
717 EINTERLEAVE_LR, // interleaved left-right
718 EGROUPED_LR, // non-interleaved left-right
719 ENUM_INTERLEAVE_MODES // number of modes supported
722 /** Structure for input format information */
723 typedef struct PV_AudioInputFormat
727 // DESCRIPTION: Number of bits per sample. For example, set it to "16"
729 // USAGE: The authoring application is required to fill this in.
731 int32 iInputBitsPerSample;
733 // DESCRIPTION: Sampling rate of the input samples in Hz.
734 // For example, set it to "22050" Hz. AMRNB is always 8khz
735 // USAGE: The authoring application is required to fill this in.
736 // If sampling rate is not known until CAEI is initialized,
738 uint32 iInputSamplingRate;
741 // DESCRIPTION: Number of input channels:1=Mono,2=Stereo.(Mono uses 1 channel;
742 // Stereo uses 2 channels).
743 // USAGE: The authoring application is required to fill this in.
745 uint8 iInputNumChannels;
747 // DESCRIPTION: Whether to interleave or not the multi-channel input samples:
748 // EINTERLEAVE_LR = LRLRLRLRLR (interleaved left-right)
749 // EGROUPED_LR = LLLLLL...RRRRRR (non-interleaved left-right)
750 // USAGE: The authoring application is required to fill this in.
752 EInterleaveMode iInputInterleaveMode;
756 } PV_AudioInputFormat;
765 ///////////////////////////////////////////////////////////////////////////////////////////////////////
766 //CAPABILITY AND CONFIG
768 // Structure to hold the key string info for
769 // encnode's capability-and-config
770 struct PVOMXEncNodeKeyStringData
774 PvmiKvpValueType iValueType;
777 // The number of characters to allocate for the key string
778 #define PVOMXENCNODECONFIG_KEYSTRING_SIZE 128
781 // Key string info at the base level ("x-pvmf/encoder/video")
782 // or ("x-pvmf/encoder/audio")
784 #ifdef _TEST_AE_ERROR_HANDLING
785 #define PVOMXENCNODECONFIG_BASE_NUMKEYS 8
787 #define PVOMXENCNODECONFIG_BASE_NUMKEYS 3
790 const PVOMXEncNodeKeyStringData PVOMXEncNodeConfigBaseKeys[PVOMXENCNODECONFIG_BASE_NUMKEYS] =
792 {"sampling_rate", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32},
793 {"channels", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32},
794 {"encoding_mode", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32}
795 #ifdef _TEST_AE_ERROR_HANDLING
796 , {"error_start_init", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_BOOL}
797 , {"error-encode", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32}
798 , {"error-node-cmd", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32}
799 , {"error-config-header", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_BOOL}
800 , {"data-path-stall", PVMI_KVPTYPE_VALUE, PVMI_KVPVALTYPE_UINT32}
804 enum BaseKeys_IndexMapType
806 SAMPLING_RATE = 0, // audio
809 #ifdef _TEST_AE_ERROR_HANDLING
813 , ERROR_CONFIG_HEADER
814 , ERROR_DATAPATH_STALL
818 // default encode parameters
819 #define DEFAULT_BITRATE 32000
820 #define DEFAULT_FRAME_WIDTH 176
821 #define DEFAULT_FRAME_HEIGHT 144
822 #define DEFAULT_FRAME_RATE 5
823 #define DEFAULT_INTRA_PERIOD 10
824 #define DEFAULT_OMX_MP4ENC_QPI 15
825 #define DEFAULT_OMX_MP4ENC_QPP 12
826 #define DEFAULT_OMX_MP4ENC_QPB 12
828 #define DEFAULT_OMX_AVCENC_QPI 25
829 #define DEFAULT_OMX_AVCENC_QPP 30
830 #define DEFAULT_OMX_AVCENC_QPB 33
832 #define PVMF_AVCENC_NODE_SPS_VECTOR_RESERVE 16 // max allowed by standard
833 #define PVMF_AVCENC_NODE_PPS_VECTOR_RESERVE 256 // max allowed by standard
834 #define DEFAULT_PARAMS_SET_LENGTH 256
838 PV_MPEG_VIDEO_SIMPLE_PROFILE = OMX_VIDEO_MPEG4ProfileSimple,
839 PV_MPEG_VIDEO_SIMPLE_SCALABLE_PROFILE = OMX_VIDEO_MPEG4ProfileSimpleScalable,
840 PV_MPEG_VIDEO_CORE_PROFILE = OMX_VIDEO_MPEG4ProfileCore,
841 PV_MPEG_VIDEO_MAIN_PROFILE = OMX_VIDEO_MPEG4ProfileMain,
842 PV_MPEG_VIDEO_N_BIT_PROFILE = OMX_VIDEO_MPEG4ProfileNbit,
843 PV_MPEG_VIDEO_SCALABLE_TEXTURE_PROFILE = OMX_VIDEO_MPEG4ProfileScalableTexture,
844 PV_MPEG_VIDEO_SIMPLE_FACE_ANIMATION_PROFILE = OMX_VIDEO_MPEG4ProfileSimpleFace,
845 PV_MPEG_VIDEO_SIMPLE_FBA_PROFILE = OMX_VIDEO_MPEG4ProfileSimpleFBA,
846 PV_MPEG_VIDEO_BASIC_ANIMATED_TEXTURE_PROFILE = OMX_VIDEO_MPEG4ProfileBasicAnimated,
847 PV_MPEG_VIDEO_HYBRID_PROFILE = OMX_VIDEO_MPEG4ProfileHybrid,
848 PV_MPEG_VIDEO_ADVANCE_REAL_TIME_SIMPLE_PROFILE = OMX_VIDEO_MPEG4ProfileAdvancedRealTime,
849 PV_MPEG_VIDEO_CORE_SCALABLE_PROFILE = OMX_VIDEO_MPEG4ProfileCoreScalable,
850 PV_MPEG_VIDEO_ADVANCE_CODING_EFFICIENCY_PROFILE = OMX_VIDEO_MPEG4ProfileAdvancedCoding,
851 PV_MPEG_VIDEO_ADVANCE_CORE_PROFILE = OMX_VIDEO_MPEG4ProfileAdvancedCore,
852 PV_MPEG_VIDEO_ADVANCE_SCALABLE_TEXTURE_PROFILE = OMX_VIDEO_MPEG4ProfileAdvancedScalable,
853 PV_MPEG_VIDEO_ADVANCE_SIMPLE_PROFILE = OMX_VIDEO_MPEG4ProfileAdvancedSimple,
854 PV_MPEG_VIDEO_KHRONOS_EXTN_PROFILE = OMX_VIDEO_MPEG4ProfileKhronosExtensions,
855 PV_MPEG_VIDEO_RESERVED_PROFILE = OMX_VIDEO_MPEG4ProfileVendorStartUnused,
856 PV_MPEG_VIDEO_MAX_PROFILE = OMX_VIDEO_MPEG4ProfileMax
858 } PVMF_MPEGVideoProfileType;
862 PV_MPEG_VIDEO_LEVEL0 = OMX_VIDEO_MPEG4Level0,
863 PV_MPEG_VIDEO_LEVEL0b = OMX_VIDEO_MPEG4Level0b,
864 PV_MPEG_VIDEO_LEVEL1 = OMX_VIDEO_MPEG4Level1,
865 PV_MPEG_VIDEO_LEVEL2 = OMX_VIDEO_MPEG4Level2,
866 PV_MPEG_VIDEO_LEVEL3 = OMX_VIDEO_MPEG4Level3,
867 PV_MPEG_VIDEO_LEVEL4 = OMX_VIDEO_MPEG4Level4,
868 PV_MPEG_VIDEO_LEVEL4a = OMX_VIDEO_MPEG4Level4a,
869 PV_MPEG_VIDEO_LEVEL5 = OMX_VIDEO_MPEG4Level5,
870 PV_MPEG_VIDEO_KHRONOS_EXTN_LEVEL = OMX_VIDEO_MPEG4LevelKhronosExtensions,
871 PV_MPEG_VIDEO_RESERVED_LEVEL = OMX_VIDEO_MPEG4LevelVendorStartUnused,
872 PV_MPEG_VIDEO_MAX_LEVEL = OMX_VIDEO_MPEG4LevelMax
874 } PVMF_MPEGVideoLevelType;
878 PV_H263_VIDEO_BASELINE_PROFILE = OMX_VIDEO_H263ProfileBaseline,
879 PV_H263_VIDEO_H320_CODING_PROFILE = OMX_VIDEO_H263ProfileH320Coding,
880 PV_H263_VIDEO_BCK_CMPTBLE_PROFILE = OMX_VIDEO_H263ProfileBackwardCompatible,
881 PV_H263_VIDEO_ISWV2_PROFILE = OMX_VIDEO_H263ProfileISWV2,
882 PV_H263_VIDEO_ISWV3_PROFILE = OMX_VIDEO_H263ProfileISWV3,
883 PV_H263_VIDEO_HIGH_COMPRESSION_PROFILE = OMX_VIDEO_H263ProfileHighCompression,
884 PV_H263_VIDEO_INTERNET_PROFILE = OMX_VIDEO_H263ProfileInternet,
885 PV_H263_VIDEO_INTERLACE_PROFILE = OMX_VIDEO_H263ProfileInterlace,
886 PV_H263_VIDEO_HIGH_LATENCY_PROFILE = OMX_VIDEO_H263ProfileHighLatency,
887 PV_H263_VIDEO_KHRONOS_EXTN_PROFILE = OMX_VIDEO_H263ProfileKhronosExtensions,
888 PV_H263_VIDEO_RESERVED_PROFILE = OMX_VIDEO_H263ProfileVendorStartUnused,
889 PV_H263_VIDEO_MAX_PROFILE = OMX_VIDEO_H263ProfileMax
891 } PVMF_H263VideoProfileType;
895 PV_H263_VIDEO_LEVEL10 = OMX_VIDEO_H263Level10,
896 PV_H263_VIDEO_LEVEL20 = OMX_VIDEO_H263Level20,
897 PV_H263_VIDEO_LEVEL30 = OMX_VIDEO_H263Level30,
898 PV_H263_VIDEO_LEVEL40 = OMX_VIDEO_H263Level40,
899 PV_H263_VIDEO_LEVEL45 = OMX_VIDEO_H263Level45,
900 PV_H263_VIDEO_LEVEL50 = OMX_VIDEO_H263Level50,
901 PV_H263_VIDEO_LEVEL60 = OMX_VIDEO_H263Level60,
902 PV_H263_VIDEO_LEVEL70 = OMX_VIDEO_H263Level70,
903 PV_H263_VIDEO_KHRONOS_EXTN_LEVEL = OMX_VIDEO_H263LevelKhronosExtensions,
904 PV_H263_VIDEO_RESERVED_LEVEL = OMX_VIDEO_H263LevelVendorStartUnused,
905 PV_H263_VIDEO_MAX_LEVEL = OMX_VIDEO_H263LevelMax
907 } PVMF_H263VideoLevelType;
911 PV_AVC_VIDEO_BASELINE_PROFILE = OMX_VIDEO_AVCProfileBaseline,
912 PV_AVC_VIDEO_MAIN_PROFILE = OMX_VIDEO_AVCProfileMain,
913 PV_AVC_VIDEO_EXTENDED_PROFILE = OMX_VIDEO_AVCProfileExtended,
914 PV_AVC_VIDEO_HIGH_PROFILE = OMX_VIDEO_AVCProfileHigh,
915 PV_AVC_VIDEO_HIGH10_PROFILE = OMX_VIDEO_AVCProfileHigh10,
916 PV_AVC_VIDEO_HIGH422_PROFILE = OMX_VIDEO_AVCProfileHigh422,
917 PV_AVC_VIDEO_HIGH444_PROFILE = OMX_VIDEO_AVCProfileHigh444,
918 PV_AVC_VIDEO_KHRONOS_EXTN_PROFILE = OMX_VIDEO_AVCProfileKhronosExtensions,
919 PV_AVC_VIDEO_RESERVED_PROFILE = OMX_VIDEO_AVCProfileVendorStartUnused,
920 PV_AVC_VIDEO_MAX_PROFILE = OMX_VIDEO_AVCProfileMax
922 } PVMF_AVCVideoProfileType;
926 PV_AVC_VIDEO_LEVEL1 = OMX_VIDEO_AVCLevel1 ,
927 PV_AVC_VIDEO_LEVEL1b = OMX_VIDEO_AVCLevel1b,
928 PV_AVC_VIDEO_LEVEL11 = OMX_VIDEO_AVCLevel11,
929 PV_AVC_VIDEO_LEVEL12 = OMX_VIDEO_AVCLevel12,
930 PV_AVC_VIDEO_LEVEL13 = OMX_VIDEO_AVCLevel13,
931 PV_AVC_VIDEO_LEVEL2 = OMX_VIDEO_AVCLevel2 ,
932 PV_AVC_VIDEO_LEVEL21 = OMX_VIDEO_AVCLevel21,
933 PV_AVC_VIDEO_LEVEL22 = OMX_VIDEO_AVCLevel22,
934 PV_AVC_VIDEO_LEVEL3 = OMX_VIDEO_AVCLevel3 ,
935 PV_AVC_VIDEO_LEVEL31 = OMX_VIDEO_AVCLevel31,
936 PV_AVC_VIDEO_LEVEL32 = OMX_VIDEO_AVCLevel32,
937 PV_AVC_VIDEO_LEVEL4 = OMX_VIDEO_AVCLevel4 ,
938 PV_AVC_VIDEO_LEVEL41 = OMX_VIDEO_AVCLevel41,
939 PV_AVC_VIDEO_LEVEL42 = OMX_VIDEO_AVCLevel42,
940 PV_AVC_VIDEO_LEVEL5 = OMX_VIDEO_AVCLevel5 ,
941 PV_AVC_VIDEO_LEVEL51 = OMX_VIDEO_AVCLevel51,
942 PV_AVC_VIDEO_KHRONOS_EXTN_LEVEL = OMX_VIDEO_AVCLevelKhronosExtensions,
943 PV_AVC_VIDEO_RESERVED_LEVEL = OMX_VIDEO_AVCLevelVendorStartUnused,
944 PV_AVC_VIDEO_MAX_LEVEL = OMX_VIDEO_AVCLevelMax
946 } PVMF_AVCVideoLevelType;
948 /////////////////////////////////////////////////////////////////////////////////////////
954 //Mimetypes for the custom interface
955 #define PVMF_OMX_ENC_NODE_MIMETYPE "pvxxx/OMXEncNode"
956 #define PVMF_BASEMIMETYPE "pvxxx"
959 typedef PVMFNodeCommandQueue<PVMFOMXEncNodeCommand, PVMFOMXEncNodeAllocator> PVMFOMXEncNodeCmdQ;
963 : public OsclActiveObject
964 , public PVMFNodeInterface
965 , public OsclMemPoolFixedChunkAllocatorObserver
966 , public PVMFOMXEncNodeExtensionInterface
967 , public PVMFMetadataExtensionInterface
968 , public PvmiCapabilityAndConfigBase
969 , public PVVideoEncExtensionInterface
970 , public PVAudioEncExtensionInterface
973 PVMFOMXEncNode(int32 aPriority);
976 // From PVMFNodeInterface
977 PVMFStatus ThreadLogon();
978 PVMFStatus ThreadLogoff();
979 PVMFStatus GetCapability(PVMFNodeCapability& aNodeCapability);
980 PVMFPortIter* GetPorts(const PVMFPortFilter* aFilter = NULL);
981 PVMFCommandId QueryInterface(PVMFSessionId, const PVUuid& aUuid,
982 PVInterface*& aInterfacePtr,
983 const OsclAny* aContext = NULL);
984 PVMFCommandId RequestPort(PVMFSessionId
985 , int32 aPortTag, const PvmfMimeString* aPortConfig = NULL, const OsclAny* aContext = NULL);
986 PVMFCommandId ReleasePort(PVMFSessionId, PVMFPortInterface& aPort, const OsclAny* aContext = NULL);
987 PVMFCommandId Init(PVMFSessionId, const OsclAny* aContext = NULL);
988 PVMFCommandId Prepare(PVMFSessionId, const OsclAny* aContext = NULL);
989 PVMFCommandId Start(PVMFSessionId, const OsclAny* aContext = NULL);
990 PVMFCommandId Stop(PVMFSessionId, const OsclAny* aContext = NULL);
991 PVMFCommandId Flush(PVMFSessionId, const OsclAny* aContext = NULL);
992 PVMFCommandId Pause(PVMFSessionId, const OsclAny* aContext = NULL);
993 PVMFCommandId Reset(PVMFSessionId, const OsclAny* aContext = NULL);
994 PVMFCommandId CancelAllCommands(PVMFSessionId, const OsclAny* aContextData = NULL);
995 PVMFCommandId CancelCommand(PVMFSessionId, PVMFCommandId aCmdId, const OsclAny* aContextData = NULL);
997 // From PVMFPortActivityHandler
998 void HandlePortActivity(const PVMFPortActivity& aActivity);
1001 virtual void addRef();
1002 virtual void removeRef();
1003 virtual bool queryInterface(const PVUuid& uuid, PVInterface*& iface);
1006 //**********begin PVMFMetadataExtensionInterface
1007 PVMFStatus SetMetadataClipIndex(uint32 aClipIndex)
1009 return (aClipIndex == 0) ? PVMFSuccess : PVMFErrArgument;
1011 uint32 GetNumMetadataKeys(char* query_key = NULL);
1012 uint32 GetNumMetadataValues(PVMFMetadataList& aKeyList);
1013 PVMFCommandId GetNodeMetadataKeys(PVMFSessionId aSessionId, PVMFMetadataList& aKeyList, uint32 starting_index, int32 max_entries,
1014 char* query_key = NULL, const OsclAny* aContextData = NULL);
1015 PVMFCommandId GetNodeMetadataValues(PVMFSessionId aSessionId, PVMFMetadataList& aKeyList,
1016 Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 starting_index, int32 max_entries, const OsclAny* aContextData = NULL);
1017 PVMFStatus ReleaseNodeMetadataKeys(PVMFMetadataList& aKeyList, uint32 starting_index, uint32 end_index);
1018 PVMFStatus ReleaseNodeMetadataValues(Oscl_Vector<PvmiKvp, OsclMemAllocator>& aValueList, uint32 starting_index, uint32 end_index);
1019 //**********End PVMFMetadataExtensionInterface
1021 bool VerifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
1023 //********** CB Functions to serve OpenMAX Encoder
1025 //Process callback functions. They will be executed in testapp thread context
1028 //Callback objects - again, these are used only in the case of Multithreaded component
1029 EventHandlerThreadSafeCallbackAOEnc* iThreadSafeHandlerEventHandler;
1030 EmptyBufferDoneThreadSafeCallbackAOEnc* iThreadSafeHandlerEmptyBufferDone;
1031 FillBufferDoneThreadSafeCallbackAOEnc* iThreadSafeHandlerFillBufferDone;
1033 OMX_CALLBACKTYPE iCallbacks; // structure that contains callback ptrs.
1035 // 1) AO OMX component running in the same thread as the OMX node
1036 // In this case, the callbacks can be called directly from the component
1037 // The callback: OMX Component->CallbackEventHandler->EventHandlerProcessing
1038 // The callback can perform do RunIfNotReady
1040 // 2) Multithreaded component
1041 // In this case, the callback is made using the threadsafe callback (TSCB) AO
1042 // Component thread : OMX Component->CallbackEventHandler->TSCB(ReceiveEvent)
1043 // Node thread : TSCB(ProcessEvent)->ProcessCallbackEventHandler_MultiThreaded->EventHandlerProcessing
1046 //==============================================================================
1048 OMX_ERRORTYPE EventHandlerProcessing(OMX_OUT OMX_HANDLETYPE aComponent,
1049 OMX_OUT OMX_PTR aAppData,
1050 OMX_OUT OMX_EVENTTYPE aEvent,
1051 OMX_OUT OMX_U32 aData1,
1052 OMX_OUT OMX_U32 aData2,
1053 OMX_OUT OMX_PTR aEventData);
1055 OMX_ERRORTYPE EmptyBufferDoneProcessing(OMX_OUT OMX_HANDLETYPE aComponent,
1056 OMX_OUT OMX_PTR aAppData,
1057 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer);
1059 OMX_ERRORTYPE FillBufferDoneProcessing(OMX_OUT OMX_HANDLETYPE aComponent,
1060 OMX_OUT OMX_PTR aAppData,
1061 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer);
1063 bool IsComponentMultiThreaded()
1065 return iIsOMXComponentMultiThreaded;
1069 // From PvmiCapabilityAndConfig
1070 PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements, PvmiCapabilityContext aContext);
1071 PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements);
1072 void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements, PvmiKvp* &aRetKVP);
1073 PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int aNumElements);
1075 // Virtual functions of PVVideoEncExtensionInterface
1076 // OSCL_IMPORT_REF void addRef();
1077 // OSCL_IMPORT_REF void removeRef();
1078 // OSCL_IMPORT_REF bool queryInterface(const PVUuid& uuid, PVInterface*& iface);
1079 OSCL_IMPORT_REF bool SetNumLayers(uint32 aNumLayers);
1080 OSCL_IMPORT_REF bool SetOutputBitRate(uint32 aLayer, uint32 aBitRate);
1081 OSCL_IMPORT_REF bool SetMaxOutputBitRate(uint32 aLayer, uint32 aMaxBitRate);
1082 OSCL_IMPORT_REF bool SetOutputFrameSize(uint32 aLayer, uint32 aWidth, uint32 aHeight);
1083 OSCL_IMPORT_REF bool SetOutputFrameRate(uint32 aLayer, OsclFloat aFrameRate);
1084 OSCL_IMPORT_REF bool SetSegmentTargetSize(uint32 aLayer, uint32 aSizeBytes);
1085 OSCL_IMPORT_REF bool SetRateControlType(uint32 aLayer, PVMFVENRateControlType aRateControl);
1086 OSCL_IMPORT_REF bool SetInitialQP(uint32 aLayer, uint32 aQpI, uint32 aQpP, uint32 aQpB);
1087 OSCL_IMPORT_REF bool SetDataPartitioning(bool aDataPartitioning);
1088 OSCL_IMPORT_REF bool SetRVLC(bool aRVLC);
1089 OSCL_IMPORT_REF bool SetIFrameInterval(uint32 aIFrameInterval);
1090 OSCL_IMPORT_REF bool GetVolHeader(OsclRefCounterMemFrag& aVolHeader);
1091 OSCL_IMPORT_REF bool RequestIFrame();
1092 OSCL_IMPORT_REF bool SetSceneDetection(bool aSCD);
1093 OSCL_IMPORT_REF bool SetCodec(PVMFFormatType aCodec);
1095 OSCL_IMPORT_REF bool GetVolHeaderForPort(OsclRefCounterMemFrag& aVolHeader);
1097 PVMFStatus SetCodecType(PVMFFormatType aCodec);
1099 OSCL_IMPORT_REF bool SetFSIParam(uint8* aFSIBuff, int aFSIBuffLength);
1100 OSCL_IMPORT_REF bool SetShortHeader(bool aShortHeaderFlag);
1101 OSCL_IMPORT_REF bool SetResyncMarker(bool aResyncMarkerFlag);
1102 OSCL_IMPORT_REF bool SetTimeIncRes(int32 aTimeIncRes);
1103 OSCL_IMPORT_REF bool SetGOBHdrInterval(uint32 aGOBHdrIntrvl);
1104 OSCL_IMPORT_REF bool UpdateOutputBitRate(uint32 aLayer, uint32 aBitRate);
1105 OSCL_IMPORT_REF bool UpdateOutputFrameRate(uint32 aLayer, OsclFloat aFrameRate);
1106 OSCL_IMPORT_REF bool UpdateIFrameInterval(uint32 aIFrameInterval);
1108 // from AudioEncExtensionInterface
1109 OSCL_IMPORT_REF PVMFStatus SetOutputBitRate(PVMF_GSMAMR_Rate aBitRate);
1110 OSCL_IMPORT_REF PVMFStatus SetMaxNumOutputFramesPerBuffer(uint32 aNumOutputFrames);
1111 OSCL_IMPORT_REF PVMFStatus SetOutputBitRate(uint32 aBitRate);
1112 OSCL_IMPORT_REF PVMFStatus SetOutputNumChannel(uint32 aNumChannel);
1113 OSCL_IMPORT_REF PVMFStatus SetOutputSamplingRate(uint32 aSamplingRate);
1114 OSCL_IMPORT_REF PVMFStatus SetOutputAacProfile(PVMF_AAC_Profile aAacOutputProfile);
1117 PVMFStatus SetInputSamplingRate(uint32 aSamplingRate);
1118 PVMFStatus SetInputBitsPerSample(uint32 aBitsPerSample);
1119 PVMFStatus SetInputNumChannels(uint32 aNumChannels);
1120 uint32 GetAudioOutputBitRate(); // for audio - void
1121 // encoder input format setting
1122 /////////////////////////////////////////////////////
1123 // Encoder settings routine
1124 /////////////////////////////////////////////////////
1125 PVMFStatus SetInputFormat(PVMFFormatType aFormat);
1126 PVMFStatus SetInputFrameSize(uint32 aWidth, uint32 aHeight, uint8 aFrmOrient = 0);
1127 PVMFStatus SetInputFrameRate(OsclFloat aFrameRate);
1130 PVMFFormatType GetCodecType();
1131 uint32 GetVideoOutputBitRate(uint32 aLayer);
1132 uint32 GetVideoMaxOutputBitRate(uint32 aLayer);
1133 uint32 GetDecBufferSize();
1134 OsclFloat GetOutputFrameRate(uint32 aLayer);
1135 PVMFStatus GetOutputFrameSize(uint32 aLayer, uint32& aWidth, uint32& aHeight);
1136 uint32 GetIFrameInterval();
1137 uint32 GetOutputSamplingRate();
1138 uint32 GetOutputNumChannels();
1140 //Profiles can be -- PVMF_MPEGVideoProfileType, PVMF_H263VideoProfileType or PVMF_AVCVideoProfileType
1141 //Levels can be -- PVMF_MPEGVideoLevelType, PVMF_H263VideoLevelType or PVMF_AVCVideoLevelType
1142 PVMFStatus GetProfileAndLevel(uint32& aProfile, uint32& aLevel);
1145 void CommandComplete(PVMFOMXEncNodeCmdQ& aCmdQ, PVMFOMXEncNodeCommand& aCmd, PVMFStatus aStatus, OsclAny* aEventData = NULL);
1147 void DoQueryInterface(PVMFOMXEncNodeCommand&);
1148 void DoRequestPort(PVMFOMXEncNodeCommand&);
1149 void DoReleasePort(PVMFOMXEncNodeCommand&);
1150 void DoInit(PVMFOMXEncNodeCommand&);
1151 void DoPrepare(PVMFOMXEncNodeCommand&);
1152 void DoStart(PVMFOMXEncNodeCommand&);
1153 void DoStop(PVMFOMXEncNodeCommand&);
1154 void DoPause(PVMFOMXEncNodeCommand&);
1155 void DoReset(PVMFOMXEncNodeCommand&);
1156 void DoFlush(PVMFOMXEncNodeCommand&);
1157 PVMFStatus DoGetNodeMetadataKey(PVMFOMXEncNodeCommand&);
1158 PVMFStatus DoGetNodeMetadataValue(PVMFOMXEncNodeCommand&);
1159 void DoCancelAllCommands(PVMFOMXEncNodeCommand&);
1160 void DoCancelCommand(PVMFOMXEncNodeCommand&);
1163 bool ProcessCommand(PVMFOMXEncNodeCommand& aCmd);
1164 bool ProcessIncomingMsg(PVMFPortInterface* aPort);
1165 bool ProcessOutgoingMsg(PVMFPortInterface* aPort);
1166 PVMFStatus HandleProcessingState();
1172 bool NegotiateVideoComponentParameters();
1173 bool SetMP4EncoderParameters();
1174 bool SetH263EncoderParameters();
1175 bool SetH264EncoderParameters();
1177 bool NegotiateAudioComponentParameters();
1178 bool SetAMREncoderParameters();
1179 bool SetAACEncoderParameters();
1181 bool SetDefaultCapabilityFlags();
1182 bool CreateOutMemPool(uint32 num);
1183 bool CreateInputMemPool(uint32 num);
1184 bool ProvideBuffersToComponent(OsclMemPoolFixedChunkAllocator *aMemPool, // allocator
1185 uint32 aAllocSize, // size to allocate from pool (hdr only or hdr+ buffer)
1186 uint32 aNumBuffers, // number of buffers
1187 uint32 aActualBufferSize, // aactual buffer size
1188 uint32 aPortIndex, // port idx
1189 bool aUseBufferOK, // can component use OMX_UseBuffer?
1190 bool aIsThisInputBuffer // is this input or output
1193 bool FreeBuffersFromComponent(OsclMemPoolFixedChunkAllocator *aMemPool, // allocator
1194 uint32 aAllocSize, // size to allocate from pool (hdr only or hdr+ buffer)
1195 uint32 aNumBuffers, // number of buffers
1196 uint32 aPortIndex, // port idx
1197 bool aIsThisInputBuffer // is this input or output
1200 OsclSharedPtr<class PVMFMediaDataImpl> WrapOutputBuffer(uint8 *pData, uint32 aDataLen, OsclAny *pContext);
1201 bool QueueOutputBuffer(OsclSharedPtr<PVMFMediaDataImpl> &mediadataimplout, uint32 aDataLen);
1203 bool SendOutputBufferToOMXComponent();
1204 bool SendInputBufferToOMXComponent();
1207 bool SendEOSBufferToOMXComponent();
1209 bool SendBeginOfMediaStreamCommand(void);
1210 bool SendEndOfTrackCommand(void);
1214 bool ReleaseAllPorts();
1215 bool DeleteOMXEncoder();
1217 void ChangeNodeState(TPVMFNodeInterfaceState aNewState);
1219 void HandleComponentStateChange(OMX_U32 encoder_state);
1221 // Capability And Config Helper Methods
1222 PVMFStatus DoCapConfigGetParametersSync(PvmiKeyType aIdentifier, PvmiKvp*& aParameters, int& aNumParamElements, PvmiCapabilityContext aContext);
1223 PVMFStatus DoCapConfigReleaseParameters(PvmiKvp* aParameters, int aNumElements);
1224 void DoCapConfigSetParameters(PvmiKvp* aParameters, int aNumElements, PvmiKvp* &aRetKVP);
1225 PVMFStatus DoCapConfigVerifyParameters(PvmiKvp* aParameters, int aNumElements);
1227 PVMFStatus GetConfigParameter(PvmiKvp*& aParameters, int& aNumParamElements, int32 aIndex, PvmiKvpAttr aReqattr);
1228 PVMFStatus VerifyAndSetConfigParameter(PvmiKvp& aParameter, bool aSetParam);
1230 PVMFStatus AllocateKvp(PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams);
1232 void freechunkavailable(OsclAny*);
1234 PVMFCommandId QueueCommandL(PVMFOMXEncNodeCommand& aCmd);
1237 int32 PushBackKeyVal(Oscl_Vector<PvmiKvp, OsclMemAllocator>*&, PvmiKvp&);
1238 int32 Push_Back_MetadataKeys(const char*);
1239 int32 Push_Back_MetadataKeys(PVMFMetadataList*&, uint32);
1240 int32 CreateNewArray(char*&, int32);
1241 int32 MemAllocate(OsclAny*& , OsclMemPoolFixedChunkAllocator*, uint32);
1244 OMX_ERRORTYPE FillBufferDoneProcM4V(OMX_OUT OMX_HANDLETYPE aComponent,
1245 OMX_OUT OMX_PTR aAppData,
1246 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer,
1247 OutputBufCtrlStruct *pContext);
1249 OMX_ERRORTYPE FillBufferDoneProcAVC(OMX_OUT OMX_HANDLETYPE aComponent,
1250 OMX_OUT OMX_PTR aAppData,
1251 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer,
1252 OutputBufCtrlStruct *pContext);
1254 OMX_ERRORTYPE FillBufferDoneProcETC(OMX_OUT OMX_HANDLETYPE aComponent,
1255 OMX_OUT OMX_PTR aAppData,
1256 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer,
1257 OutputBufCtrlStruct *pContext);
1259 bool ParseFullAVCFramesIntoNALs(OMX_BUFFERHEADERTYPE* aOutputBuffer);
1260 bool AVCAnnexBGetNALUnit(uint8 *bitstream, uint8 **nal_unit, int32 *size, bool getPtrOnly);
1261 bool CheckM4vVopStartCode(uint8* data, int* len);
1263 friend class PVMFOMXEncPort;
1265 OMX_ERRORTYPE(PVMFOMXEncNode::*iFillBufferDoneProc)(OMX_OUT OMX_HANDLETYPE aComponent,
1266 OMX_OUT OMX_PTR aAppData,
1267 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer,
1268 OutputBufCtrlStruct *pContext);
1271 PVMFPortInterface* iInPort;
1272 PVMFPortInterface* iOutPort;
1275 PVMFOMXEncNodeCmdQ iInputCommands;
1276 PVMFOMXEncNodeCmdQ iCurrentCommand;
1278 // Shared pointer for Media Msg.Input buffer
1279 PVMFSharedMediaDataPtr iDataIn;
1282 // OUTPUT BUFFER RELATED MEMBERS
1285 // Output buffer memory pool
1286 OsclMemPoolFixedChunkAllocator *iOutBufMemoryPool;
1288 // Memory pool for simple media data
1289 OsclMemPoolFixedChunkAllocator *iMediaDataMemPool;
1291 // Size of output buffer (negotiated with component)
1292 uint32 iOMXComponentOutputBufferSize;
1294 // size of output to allocate (OMX_ALLOCATE_BUFFER = size of buf header )
1295 // (OMX_USE_BUFFER = size of buf header + iOMXCoponentOutputBufferSize)
1296 uint32 iOutputAllocSize;
1298 // Number of output buffers (negotiated with component)
1299 uint32 iNumOutputBuffers;
1301 // desired output buffer alignmen (read from the component port)
1302 uint32 iOutputBufferAlignment;
1303 // Number of output buffers in possession of the component or downstream,
1304 // namely, number of unavailable buffers
1305 uint32 iNumOutstandingOutputBuffers;
1307 // flag to prevent sending output buffers downstream during flushing etc.
1308 bool iDoNotSendOutputBuffersDownstreamFlag;
1310 // flag to prevent freeing the buffers twice
1311 bool iOutputBuffersFreed;
1315 // INPUT BUFFER RELATED MEMBERS
1316 OsclMemPoolFixedChunkAllocator *iInBufMemoryPool;
1317 uint32 iOMXComponentInputBufferSize; // size of input buffer that the component sees (negotiated with the component)
1318 uint32 iInputAllocSize; // size of input buffer to allocate (OMX_ALLOCATE_BUFFER = size of buf header )
1319 // (OMX_USE_BUFFER = size of buf header + iOMXCoponentInputBufferSize)
1320 uint32 iNumInputBuffers; // total num of input buffers (negotiated with component)
1322 // desired input buffer alignment (read from the component port)
1323 uint32 iInputBufferAlignment;
1325 uint32 iNumOutstandingInputBuffers; // number of input buffers in use (i.e. unavailable)
1327 // flag to prevent freeing buffers twice
1328 bool iInputBuffersFreed;
1330 // input buffer fragmentation etc.
1331 uint32 iCopyPosition; // for copying memfrag data into a buffer
1332 uint32 iFragmentSizeRemainingToCopy;
1333 bool iIsNewDataFragment;
1336 uint32 iCurrFragNum;
1337 uint32 iCodecSeqNum; // sequence number tracking
1338 uint32 iInPacketSeqNum;
1340 uint32 iInTimestamp;
1343 uint32 iCurrentMsgMarkerBit;
1345 // DYNAMIC PORT RE-CONFIGURATION
1346 uint32 iInputPortIndex;
1347 uint32 iOutputPortIndex;
1348 OMX_PARAM_PORTDEFINITIONTYPE iParamPort;
1349 uint32 iPortIndexForDynamicReconfig;
1350 bool iSecondPortReportedChange;
1351 bool iDynamicReconfigInProgress;
1352 uint32 iSecondPortToReconfig;
1355 ////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS
1356 bool iOMXComponentSupportsExternalOutputBufferAlloc;
1357 bool iOMXComponentSupportsExternalInputBufferAlloc;
1358 bool iOMXComponentSupportsMovableInputBuffers;
1359 bool iOMXComponentUsesNALStartCodes;
1360 bool iOMXComponentSupportsPartialFrames;
1361 bool iOMXComponentCanHandleIncompleteFrames;
1362 bool iOMXComponentUsesFullAVCFrames;
1363 bool iOMXComponentUsesInterleaved2BNALSizes;
1364 bool iOMXComponentUsesInterleaved4BNALSizes;
1366 bool iSetMarkerBitForEveryFrag;
1367 bool iIsOMXComponentMultiThreaded;
1369 // State definitions for HandleProcessingState() state machine
1372 EPVMFOMXEncNodeProcessingState_Idle, //default state after constraction/reset
1373 EPVMFOMXEncNodeProcessingState_ReadyToEncode, //nornal operation state of the encoder
1374 EPVMFOMXEncNodeProcessingState_WaitForOutputBuffer, //wait state for avalible media output buffer
1375 EPVMFOMXEncNodeProcessingState_WaitForOutputPort, //wait state, output port is busy
1376 EPVMFOMXEncNodeProcessingState_WaitForOutgoingQueue, //wait state, outgoing queue
1377 EPVMFOMXEncNodeProcessingState_PortReconfig, // Dynamic Port Reconfiguration - step 1
1378 EPVMFOMXEncNodeProcessingState_WaitForBufferReturn, // step 2
1379 EPVMFOMXEncNodeProcessingState_WaitForPortDisable, // Dynamic Port Reconfiguration - step 3
1380 EPVMFOMXEncNodeProcessingState_PortReEnable, // Dynamic Port Reconfiguration - step 4
1381 EPVMFOMXEncNodeProcessingState_WaitForPortEnable, // step 5
1382 EPVMFOMXEncNodeProcessingState_Stopping // when STOP command is issued, the node has to wait for component to transition into
1383 // idle state. The buffers keep coming back , the node is rescheduled
1384 // to run. Prevent the node from sending buffers back
1385 } PVMFOMXEncNode_ProcessingState;
1387 // State of HandleProcessingState() state machine
1388 PVMFOMXEncNode_ProcessingState iProcessingState;
1390 // Handle of OMX Component
1391 OMX_HANDLETYPE iOMXEncoder;
1393 // Current State of the component
1394 OMX_STATETYPE iCurrentEncoderState;
1399 uint32 iBOSTimestamp;
1402 bool iIsEOSSentToComponent;
1403 bool iIsEOSReceivedFromComponent;
1405 // Send Fsi configuration flag
1408 // Width of encoded frame
1410 // Height of encoded frame
1415 // Pointer to input data fragment
1416 uint8* iBitstreamBuffer;
1417 // Size of input data fragment
1418 int32 iBitstreamSize;
1420 // Output frame sequence counter
1423 // Input frame sequence counter
1426 // Added to Scheduler Flag
1431 PVLogger* iDataPathLogger;
1432 PVLogger* iClockLogger;
1433 PVLogger *iRunlLogger;
1434 const char *iNodeTypeId;
1436 // Counter of fragment read from current Media Msg.Input buffer
1438 // Number of fragments in the Media Msg.Input buffer
1442 // Node configuration update
1443 //PVMFOMXEncNodeConfig iNodeConfig;
1445 // Capability exchange
1446 PVMFNodeCapability iCapability;
1448 // Reference counter for extension
1449 uint32 iExtensionRefCount;
1452 Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> iAvailableMetadataKeys;
1455 bool iEndOfDataReached;
1456 // Time stame upon EOS
1457 PVMFTimestamp iEndOfDataTimestamp;
1459 /* Diagnostic log related */
1460 PVLogger* iDiagnosticsLogger;
1461 bool iDiagnosticsLogged;
1462 void LogDiagnostics();
1464 uint32 iFrameCounter;
1468 uint32 iAvgBitrateValue;
1469 bool iResetInProgress;
1471 bool iStopInResetMsgSent;
1473 PV_VideoEncodeParam iVideoEncodeParam;
1474 PV_VideoInputFormat iVideoInputFormat;
1475 PV_AudioEncodeParam iAudioEncodeParam;
1476 PV_AudioInputFormat iAudioInputFormat;
1478 PVMFFormatType iInFormat;
1479 PVMFFormatType iOutFormat;
1481 PVMFOMXEncNodeAllocDestructDealloc iAlloc;
1482 OsclRefCounterMemFrag iVolHeader; /** Vol header */
1483 OsclRefCounterMemFrag iConfigHeader;
1485 OsclRefCounterMemFrag iParamSet; /* place holder for sps,pps values */
1486 OsclMemoryFragment iSPSs[PVMF_AVCENC_NODE_SPS_VECTOR_RESERVE]; // just ptrs
1487 OsclMemoryFragment iPPSs[PVMF_AVCENC_NODE_PPS_VECTOR_RESERVE]; // just ptrs
1490 bool iSpsPpsSequenceOver;
1491 OsclSharedPtr<PVMFMediaDataImpl> iPreviousMediaData;
1493 uint32* iNALSizeArray;
1494 uint8** iNALPtrArray;
1495 uint32 iNALSizeArrayMaxElems;
1497 uint32 iFirstNALStartCodeSize;
1499 uint32 iEndOfFrameFlagPrevious;
1500 uint32 iKeyFrameFlagPrevious;
1501 uint32 iEndOfNALFlagPrevious;
1502 OMX_TICKS iTimeStampPrevious;
1503 uint32 iBufferLenPrevious;
1505 uint32 iEndOfFrameFlagOut;
1506 uint32 iKeyFrameFlagOut;
1507 uint32 iEndOfNALFlagOut;
1508 OMX_TICKS iTimeStampOut;
1509 uint32 iBufferLenOut;
1511 OutputBufCtrlStruct *out_ctrl_struct_ptr;
1513 InputBufCtrlStruct *in_ctrl_struct_ptr;
1516 // timescale, timestamp conversions
1518 uint32 iInTimeScale;
1519 uint32 iOutTimeScale;
1521 MediaClockConverter iInputTimestampClock;
1522 OMX_TICKS iOMXTicksTimestamp;
1523 OMX_TICKS ConvertTimestampIntoOMXTicks(const MediaClockConverter &src);
1524 uint32 ConvertOMXTicksIntoTimestamp(const OMX_TICKS &src);
1526 bool CheckComponentForMultRoles(OMX_STRING aCompName, OMX_STRING aRole);
1527 bool CheckComponentCapabilities(PVMFFormatType* aOutFormat);
1530 #ifdef _TEST_AE_ERROR_HANDLING
1531 bool iErrorHandlingInit;
1532 uint32 iErrorHandlingEncodeCount;
1534 uint32 iErrorNodeCmd;
1535 bool iErrorConfigHeader;
1536 uint32 iErrorEncodeFlag;
1537 uint32 iErrorDataPathStall;
1542 #endif // PVMF_OMXENC_NODE_H_INCLUDED