OSDN Git Service

RIO-8546: Add support for changing bit rate/frame rate/intra refresh rate to OMXEncNode.
[android-x86/external-opencore.git] / nodes / pvomxencnode / src / pvmf_omx_enc_node.h
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2010 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_SIMPLE_MEDIA_BUFFER_H_INCLUDED
53 #include "pvmf_simple_media_buffer.h"
54 #endif
55
56 #ifndef PVMF_MEDIA_FRAG_GROUP_H_INCLUDED
57 #include "pvmf_media_frag_group.h"
58 #endif
59
60 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED
61 #include "pvmf_pool_buffer_allocator.h"
62 #endif
63
64 #ifndef PVMF_VIDEO_H_INCLUDED
65 #include "pvmf_video.h"
66 #endif
67
68 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED
69 #include "pvmf_pool_buffer_allocator.h"
70 #endif
71
72 #ifndef PVMF_NODE_UTILS_H_INCLUDED
73 #include "pvmf_node_utils.h"
74 #endif
75
76 #ifndef PVMF_OMX_ENC_PORT_H_INCLUDED
77 #include "pvmf_omx_enc_port.h"
78 #endif
79
80 #ifndef PVMF_OMX_ENC_NODE_EXTENSION_INTERFACE_H_INCLUDED
81 #include "pvmf_omx_enc_node_extension_interface.h"
82 #endif
83
84 #ifndef PV_VIDEO_ENCNODE_EXTENSION_H_INCLUDED
85 #include "pv_video_encnode_extension.h"
86 #endif
87
88 #ifndef PVMF_AUDIO_ENCNODE_EXTENSION_H_INCLUDED
89 #include "pvmf_audio_encnode_extension.h"
90 #endif
91
92 // DV: NOTE - this needs to be fixed
93 //#ifndef __PVM4VENCODER_H
94 //#include "pvm4vencoder.h"
95 //#endif
96
97 #ifndef PVMF_META_DATA_EXTENSION_H_INCLUDED
98 #include "pvmf_meta_data_extension.h"
99 #endif
100
101 #ifndef PV_MIME_STRING_UTILS_H_INCLUDED
102 #include "pv_mime_string_utils.h"
103 #endif
104
105 #ifndef OMX_Core_h
106 #include "OMX_Core.h"
107 #endif
108
109 #ifndef OMX_Component_h
110 #include "OMX_Component.h"
111 #endif
112
113 #ifndef PVMF_OMX_ENC_CALLBACKS_H_INCLUDED
114 #include "pvmf_omx_enc_callbacks.h"
115 #endif
116
117 #ifndef PV_OMXDEFS_H_INCLUDED
118 #include "pv_omxdefs.h"
119 #endif
120
121 #ifndef OSCLCONFIG_IO_H_INCLUDED
122 #include "osclconfig_io.h"
123 #endif
124 #ifndef OSCL_MEM_H_INCLUDED
125 #include "oscl_mem.h"
126 #endif
127
128 #if (PVLOGGER_INST_LEVEL >= PVLOGMSG_INST_REL)
129 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED
130 #include "pvmf_media_clock.h"
131 #endif
132 #endif
133
134 #ifndef __MEDIA_CLOCK_CONVERTER_H
135 #include "media_clock_converter.h"
136 #endif
137
138 #ifndef PV_M4V_CONFIG_PARSER_H_INCLUDED
139 #include "m4v_config_parser.h"
140 #endif
141
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
147
148
149
150 typedef struct OutputBufCtrlStruct
151 {
152     OMX_BUFFERHEADERTYPE *pBufHdr;
153     OsclAny *pMemPoolEntry;
154 } OutputBufCtrlStruct;
155
156 typedef struct InputBufCtrlStruct
157 {
158     OMX_BUFFERHEADERTYPE *pBufHdr;
159     PVMFSharedMediaDataPtr pMediaData;
160     OsclAny *pMemPoolEntry;
161 } InputBufCtrlStruct;
162
163
164 // fwd class declaration
165 class PVLogger;
166 //memory allocator type for this node.
167 typedef OsclMemAllocator PVMFOMXEncNodeAllocator;
168 typedef OsclMemAllocDestructDealloc<uint8> PVMFOMXEncNodeAllocDestructDealloc;
169
170
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);
178
179 OMX_ERRORTYPE CallbackEmptyBufferDoneEnc(OMX_OUT OMX_HANDLETYPE aComponent,
180         OMX_OUT OMX_PTR aAppData,
181         OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer);
182
183 OMX_ERRORTYPE CallbackFillBufferDoneEnc(OMX_OUT OMX_HANDLETYPE aComponent,
184                                         OMX_OUT OMX_PTR aAppData,
185                                         OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer);
186
187
188
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
195
196 // for AMR encoder
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
201 // in milliseconds
202 #define PVMF_AMRENC_DEFAULT_FRAME_DURATION 20
203
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
213
214 class PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA : public OsclDestructDealloc
215 {
216     public:
217         PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA(Oscl_DefAlloc* allocator, void *pMempoolData) :
218                 buf_alloc(allocator), ptr_to_data_to_dealloc(pMempoolData) {};
219         virtual ~PVOMXEncBufferSharedPtrWrapperCombinedCleanupDA() {};
220
221         virtual void destruct_and_dealloc(OsclAny* ptr)
222         {
223             // call buffer deallocator
224             if (buf_alloc != NULL)
225             {
226                 buf_alloc->deallocate(ptr_to_data_to_dealloc);
227             }
228
229             // this is needed to completely free PVMFMediaDataImpl, since it allocates memory for the frag list
230             ((PVMFMediaDataImpl*)ptr)->~PVMFMediaDataImpl();
231             oscl_free(ptr);
232         }
233
234     private:
235         Oscl_DefAlloc* buf_alloc;
236         void *ptr_to_data_to_dealloc;
237 };
238
239
240
241 #define PVMFOMXEncNodeCommandBase PVMFGenericNodeCommand<PVMFOMXEncNodeAllocator>
242
243 class PVMFOMXEncNodeCommand: public PVMFOMXEncNodeCommandBase
244 {
245     public:
246         //constructor for Custom2 command
247         void Construct(PVMFSessionId s, int32 cmd, int32 arg1, int32 arg2, int32& arg3, const OsclAny*aContext)
248         {
249             PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext);
250             iParam1 = (OsclAny*)arg1;
251             iParam2 = (OsclAny*)arg2;
252             iParam3 = (OsclAny*) & arg3;
253         }
254         void Parse(int32&arg1, int32&arg2, int32*&arg3)
255         {
256             arg1 = (int32)iParam1;
257             arg2 = (int32)iParam2;
258             arg3 = (int32*)iParam3;
259         }
260
261         void Construct(PVMFSessionId s, int32 cmd, PVMFMetadataList* aKeyList, uint32 aStartIndex, int32 aMaxEntries, char* aQueryKey, const OsclAny* aContext)
262         {
263             PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext);
264             iStartIndex = aStartIndex;
265             iMaxEntries = aMaxEntries;
266
267             if (aQueryKey == NULL)
268             {
269                 query_key[0] = 0;
270             }
271             else
272             {
273                 if (aQueryKey != NULL)
274                     oscl_strncpy(query_key, aQueryKey, oscl_strlen(aQueryKey) + 1);
275             }
276
277             iParam1 = (OsclAny*)aKeyList;
278             iParam2 = NULL;
279             iParam3 = NULL;
280             iParam4 = NULL;
281             iParam5 = NULL;
282         }
283
284         void Parse(PVMFMetadataList*& MetaDataListPtr, uint32 &aStartingIndex, int32 &aMaxEntries, char*&aQueryKey)
285         {
286             MetaDataListPtr = (PVMFMetadataList*)iParam1;
287             aStartingIndex = iStartIndex;
288             aMaxEntries = iMaxEntries;
289             if (query_key[0] == 0)
290             {
291                 aQueryKey = NULL;
292             }
293             else
294             {
295                 aQueryKey = query_key;
296             }
297         }
298
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)
301         {
302             PVMFOMXEncNodeCommandBase::Construct(s, cmd, aContext);
303             iParam1 = (OsclAny*)aKeyList;
304             iParam2 = (OsclAny*)aValueList;
305
306             iStartIndex = aStartIndex;
307             iMaxEntries = aMaxEntries;
308
309             iParam3 = NULL;
310             iParam4 = NULL;
311             iParam5 = NULL;
312         }
313         void Parse(PVMFMetadataList* &aKeyList, Oscl_Vector<PvmiKvp, OsclMemAllocator>* &aValueList, uint32 &aStartingIndex, int32 &aMaxEntries)
314         {
315             aKeyList = (PVMFMetadataList*)iParam1;
316             aValueList = (Oscl_Vector<PvmiKvp, OsclMemAllocator>*)iParam2;
317             aStartingIndex = iStartIndex;
318             aMaxEntries = iMaxEntries;
319         }
320
321
322         virtual bool hipri()
323         {
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);
329         }
330
331         enum PVOMXEncNodeCmdType
332         {
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
348         };
349
350
351
352
353     private:
354         uint32 iStartIndex;
355         uint32 iMaxEntries;
356         char query_key[256];
357
358 };
359
360 //Default vector reserve size
361 #define PVMF_OMXENC_NODE_COMMAND_VECTOR_RESERVE 10
362
363 //Starting value for command IDs
364 #define PVMF_OMXENC_NODE_COMMAND_ID_START 6000
365
366 ////////////////////////////////////////////////////////////////////////////////////////////////////
367 //////////////////////////////////// STRUCTURES FOR ENCODING PARAMETERS ////////////////////////////
368 ////////////////////////////////////////////////////////////////////////////////////////////////////
369 #define MAX_LAYER 1
370
371 /** Contains supported input format */
372 enum EncVideoInputFormat
373 {
374     EI_RGB24,
375     EI_RGB12,
376     EI_YUV420,
377     EI_UYVY
378 };
379
380 /** Targeted profile and level to encode. */
381 enum EncM4VProfileLevel
382 {
383     /* Non-scalable profile */
384     EI_SIMPLE_LEVEL0 = 0,
385     EI_SIMPLE_LEVEL1,
386     EI_SIMPLE_LEVEL2,
387     EI_SIMPLE_LEVEL3,
388     EI_SIMPLE_LEVEL4A,
389     EI_SIMPLE_LEVEL5,
390     EI_CORE_LEVEL1,
391     EI_CORE_LEVEL2,
392
393     /* Scalable profile */
394     EI_SIMPLE_SCALABLE_LEVEL0,
395     EI_SIMPLE_SCALABLE_LEVEL1,
396     EI_SIMPLE_SCALABLE_LEVEL2,
397
398     EI_CORE_SCALABLE_LEVEL1,
399     EI_CORE_SCALABLE_LEVEL2,
400     EI_CORE_SCALABLE_LEVEL3
401 };
402
403 /** Targeted profile to encode. */
404 enum EncAVCProfile
405 {
406     /* Non-scalable profile */
407     EI_PROFILE_DEFAULT,
408     EI_PROFILE_BASELINE,
409     EI_PROFILE_MAIN,
410     EI_PROFILE_EXTENDED,
411     EI_PROFILE_HIGH,
412     EI_PROFILE_HIGH10,
413     EI_PROFILE_HIGH422,
414     EI_PROFILE_HIGH444
415 };
416
417 /** Targeted level to encode. */
418 enum EncAVCLevel
419 {
420     EI_LEVEL_AUTODETECT,
421     EI_LEVEL_1,
422     EI_LEVEL_1B,
423     EI_LEVEL_11,
424     EI_LEVEL_12,
425     EI_LEVEL_13,
426     EI_LEVEL_2,
427     EI_LEVEL_21,
428     EI_LEVEL_22,
429     EI_LEVEL_3,
430     EI_LEVEL_31,
431     EI_LEVEL_32,
432     EI_LEVEL_4,
433     EI_LEVEL_41,
434     EI_LEVEL_42,
435     EI_LEVEL_5,
436     EI_LEVEL_51,
437 };
438
439 /** Output format */
440 enum TAVCEIOutputFormat
441 {
442     /** output in byte stream format according to Annex B */
443     EAVCEI_OUTPUT_ANNEXB,
444
445     /** output for MP4 file format */
446     EAVCEI_OUTPUT_MP4,
447
448     /** output in RTP format according to RFC 3984 */
449     EAVCEI_OUTPUT_RTP
450 };
451
452
453
454 /** Type of contents for optimal encoding mode. */
455 enum EncEncodingMode
456 {
457     /** Content is encoded as fast as possible with error protection */
458     EI_ENCMODE_TWOWAY,
459
460     /** Content is encoded as fast as possible without error protection */
461     EI_ENCMODE_RECORDER,
462
463     /** Content is encoded with better quality (slow) with error protection */
464     EI_ENCMODE_STREAMING,
465
466     /** Content is encoded with better quality (slow) without error protection */
467     EI_ENCMODE_DOWNLOAD
468 };
469
470
471 /** This structure contains encoder settings. */
472 typedef struct PV_VideoEncodeParam
473 {
474
475 ////////////////////////////////////////////////////////////////////////////////////
476 ////////////////////////// COMMON PARAMETERS ///////////////////////////////////////
477 ////////////////////////////////////////////////////////////////////////////////////
478
479     /** Specifies an  ID that will be used to specify this encoder while returning
480     the bitstream in asynchronous mode. */
481     uint32              iEncodeID;
482
483
484     /** Specifies whether base only (iNumLayer = 1) or base + enhancement layer
485     (iNumLayer =2 ) is to be used. */
486     int32               iNumLayer;
487
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];
491
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];
495
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];
499
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];
504
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];
508
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;
512
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. */
516     int                 iIquant[2];
517
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. */
521     int                 iPquant[2];
522
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. */
526     int                 iBquant[2];
527
528
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;
533
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;
539
540     /** Specifies automatic scene detection where I-frame will be used the the first frame
541     in a new scene. */
542     bool                iSceneDetection;
543
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. */
549     uint32              iPacketSize;
550
551     /** Specifies the duration of the clip in millisecond.*/
552     int32               iClipDuration;
553
554
555 ////////////////////////////////////////////////////////////////////////////////////////
556 /////////////////////////// H263/M4V specific parameters ///////////////////////////////
557 ////////////////////////////////////////////////////////////////////////////////////////
558
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;
563
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.*/
567     int32               iFrameQuality;
568
569
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;
573
574
575     /** Specifies high quality but also high complexity mode for rate control. */
576     bool                iRDOptimal;
577
578
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]. */
581     int32               iSearchRange;
582
583     /** Specifies the use of 8x8 motion vectors. */
584     bool                iMV8x8;
585
586     /** Specifies the use of half-pel motion vectors. */
587     bool                iMVHalfPel;
588
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. */
592     bool                iNoCurrentSkip;
593
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. */
596     bool                iNoFrameSkip;
597
598
599     /** Specify short header mode in MPEG4 */
600     bool                iShortHeader;
601
602     /** Specifies whethere data partitioning mode is used or not. Has no meaning if encoding H.263 or short header */
603     bool                iDataPartitioning;
604
605
606     /** Specifies whether Resync markers are used or not Has no meaning if iDataPartitioning is on */
607     bool                iResyncMarker;
608
609
610     /** Specifies whether RVLC (reversible VLC) is to be used or not.
611     */
612     bool                iRVLCEnable;
613
614 ////////////////////////////////////////////////////////////////////////////////////////
615 /////////////////////////// H264 specific parameters ///////////////////////////////
616 ////////////////////////////////////////////////////////////////////////////////////////
617
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;
622
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;
628
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
631     values.
632     */
633
634     EncEncodingMode     iEncMode;
635
636     /** Specifies that SPS and PPS are retrieved first and sent out-of-band */
637     //bool              iOutOfBandParamSet;
638
639     /** Specifies FSI Buffer input */
640     uint8*              iFSIBuff;
641
642     /** Specifies FSI Buffer Length */
643     uint32             iFSIBuffLength;
644
645     /** Sets the number of ticks per second used for timing information encoded in MPEG4 bitstream.*/
646     int32                 iTimeIncRes;
647
648     /** Sets the number of ticks in time increment resolution between 2 source frames (equivalent to source frame rate). */
649     int32                 iTickPerSrc;
650
651     /** Sets the interval of non-empty GOB headers in units of GOBs */
652     uint32                 iGOBHdrInterval;
653
654 } PV_VideoEncodeParam;
655
656
657
658 /** Structure for input format information */
659 typedef struct PV_VideoInputFormat
660 {
661     /** Contains the width in pixels of the input frame. */
662     int32           iFrameWidth;
663
664     /** Contains the height in pixels of the input frame. */
665     int32           iFrameHeight;
666
667     /** Contains the input frame rate in the unit of frame per second. */
668     float           iFrameRate;
669
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;
672
673     /** Contains the format of the input video, e.g., YUV 4:2:0, UYVY, RGB24, etc. */
674     EncVideoInputFormat     iVideoFormat;
675 } PV_VideoInputFormat;
676
677
678 /** Structure for audio encode information */
679 typedef struct PV_AudioEncodeParam
680 {
681
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;
691
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;
697
698     // DESCRIPTION: Currently, output bitrate is expressed as GSM-AMR type rate
699     PVMF_GSMAMR_Rate iAMRBitrate;
700
701     // DESCRIPTION: output bitrate in bits per second for non-AMR codecs
702     uint32  iOutputBitrate;
703
704     //
705     uint32  iMaxNumOutputFramesPerBuffer;
706
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;
712
713 } PV_AudioEncodeParam;
714
715 enum EInterleaveMode
716 {
717     EINTERLEAVE_LR,        // interleaved left-right
718     EGROUPED_LR,           // non-interleaved left-right
719     ENUM_INTERLEAVE_MODES  // number of modes supported
720 };
721
722 /** Structure for input format information */
723 typedef struct PV_AudioInputFormat
724 {
725
726
727     // DESCRIPTION: Number of bits per sample. For example, set it to "16"
728     //              bits for PCM.
729     // USAGE:       The authoring application is required to fill this in.
730     //
731     int32 iInputBitsPerSample;
732
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,
737     //              use '0'.
738     uint32 iInputSamplingRate;
739
740
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.
744     //
745     uint8 iInputNumChannels;
746
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.
751     //
752     EInterleaveMode iInputInterleaveMode;
753
754
755
756 } PV_AudioInputFormat;
757
758
759
760
761
762
763
764
765 ///////////////////////////////////////////////////////////////////////////////////////////////////////
766 //CAPABILITY AND CONFIG
767
768 // Structure to hold the key string info for
769 // encnode's capability-and-config
770 struct PVOMXEncNodeKeyStringData
771 {
772     char iString[64];
773     PvmiKvpType iType;
774     PvmiKvpValueType iValueType;
775 };
776
777 // The number of characters to allocate for the key string
778 #define PVOMXENCNODECONFIG_KEYSTRING_SIZE 128
779
780
781 // Key string info at the base level ("x-pvmf/encoder/video")
782 //                                or ("x-pvmf/encoder/audio")
783
784 #ifdef _TEST_AE_ERROR_HANDLING
785 #define PVOMXENCNODECONFIG_BASE_NUMKEYS 8
786 #else
787 #define PVOMXENCNODECONFIG_BASE_NUMKEYS 3
788 #endif
789
790 const PVOMXEncNodeKeyStringData PVOMXEncNodeConfigBaseKeys[PVOMXENCNODECONFIG_BASE_NUMKEYS] =
791 {
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}
801 #endif
802 };
803
804 enum BaseKeys_IndexMapType
805 {
806     SAMPLING_RATE = 0, // audio
807     CHANNELS,           // audio
808     ENCODING_MODE       // avc
809 #ifdef _TEST_AE_ERROR_HANDLING
810     , ERROR_START_INIT
811     , ERROR_ENCODE
812     , ERROR_NODE_CMD
813     , ERROR_CONFIG_HEADER
814     , ERROR_DATAPATH_STALL
815 #endif
816 };
817
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
827
828 #define DEFAULT_OMX_AVCENC_QPI 25
829 #define DEFAULT_OMX_AVCENC_QPP 30
830 #define DEFAULT_OMX_AVCENC_QPB 33
831
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
835
836 typedef enum
837 {
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
857
858 } PVMF_MPEGVideoProfileType;
859
860 typedef enum
861 {
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
873
874 } PVMF_MPEGVideoLevelType;
875
876 typedef enum
877 {
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
890
891 } PVMF_H263VideoProfileType;
892
893 typedef enum
894 {
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
906
907 } PVMF_H263VideoLevelType;
908
909 typedef enum
910 {
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
921
922 } PVMF_AVCVideoProfileType;
923
924 typedef enum
925 {
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
945
946 } PVMF_AVCVideoLevelType;
947
948 /////////////////////////////////////////////////////////////////////////////////////////
949
950
951
952
953
954 //Mimetypes for the custom interface
955 #define PVMF_OMX_ENC_NODE_MIMETYPE "pvxxx/OMXEncNode"
956 #define PVMF_BASEMIMETYPE "pvxxx"
957
958 //Command queue type
959 typedef PVMFNodeCommandQueue<PVMFOMXEncNodeCommand, PVMFOMXEncNodeAllocator> PVMFOMXEncNodeCmdQ;
960
961
962 class PVMFOMXEncNode
963         : public OsclActiveObject
964         , public PVMFNodeInterface
965         , public OsclMemPoolFixedChunkAllocatorObserver
966         , public PVMFOMXEncNodeExtensionInterface
967         , public PVMFMetadataExtensionInterface
968         , public PvmiCapabilityAndConfigBase
969         , public PVVideoEncExtensionInterface
970         , public PVAudioEncExtensionInterface
971 {
972     public:
973         PVMFOMXEncNode(int32 aPriority);
974         ~PVMFOMXEncNode();
975
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);
996
997         // From PVMFPortActivityHandler
998         void HandlePortActivity(const PVMFPortActivity& aActivity);
999
1000         // From PVInterface
1001         virtual void addRef();
1002         virtual void removeRef();
1003         virtual bool queryInterface(const PVUuid& uuid, PVInterface*& iface);
1004
1005
1006         //**********begin PVMFMetadataExtensionInterface
1007         PVMFStatus SetMetadataClipIndex(uint32 aClipIndex)
1008         {
1009             return (aClipIndex == 0) ? PVMFSuccess : PVMFErrArgument;
1010         }
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
1020
1021         bool VerifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
1022
1023         //********** CB Functions to serve OpenMAX Encoder
1024
1025         //Process callback functions. They will be executed in testapp thread context
1026
1027
1028         //Callback objects - again, these are used only in the case of Multithreaded component
1029         EventHandlerThreadSafeCallbackAOEnc*     iThreadSafeHandlerEventHandler;
1030         EmptyBufferDoneThreadSafeCallbackAOEnc* iThreadSafeHandlerEmptyBufferDone;
1031         FillBufferDoneThreadSafeCallbackAOEnc*  iThreadSafeHandlerFillBufferDone;
1032
1033         OMX_CALLBACKTYPE       iCallbacks; // structure that contains callback ptrs.
1034         // OMX CALLBACKS
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
1039
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
1044
1045
1046         //==============================================================================
1047
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);
1054
1055         OMX_ERRORTYPE EmptyBufferDoneProcessing(OMX_OUT OMX_HANDLETYPE aComponent,
1056                                                 OMX_OUT OMX_PTR aAppData,
1057                                                 OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer);
1058
1059         OMX_ERRORTYPE FillBufferDoneProcessing(OMX_OUT OMX_HANDLETYPE aComponent,
1060                                                OMX_OUT OMX_PTR aAppData,
1061                                                OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer);
1062
1063         bool IsComponentMultiThreaded()
1064         {
1065             return iIsOMXComponentMultiThreaded;
1066         };
1067
1068
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);
1074
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);
1094
1095         OSCL_IMPORT_REF bool GetVolHeaderForPort(OsclRefCounterMemFrag& aVolHeader);
1096
1097         PVMFStatus SetCodecType(PVMFFormatType aCodec);
1098
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);
1107
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);
1115
1116
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);
1128
1129
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();
1139
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);
1143
1144     private:
1145         void CommandComplete(PVMFOMXEncNodeCmdQ& aCmdQ, PVMFOMXEncNodeCommand& aCmd, PVMFStatus aStatus, OsclAny* aEventData = NULL);
1146
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&);
1161
1162         void Run();
1163         bool ProcessCommand(PVMFOMXEncNodeCommand& aCmd);
1164         bool ProcessIncomingMsg(PVMFPortInterface* aPort);
1165         bool ProcessOutgoingMsg(PVMFPortInterface* aPort);
1166         PVMFStatus HandleProcessingState();
1167
1168
1169
1170
1171         // DV:
1172         bool NegotiateVideoComponentParameters();
1173         bool SetMP4EncoderParameters();
1174         bool SetH263EncoderParameters();
1175         bool SetH264EncoderParameters();
1176
1177         bool NegotiateAudioComponentParameters();
1178         bool SetAMREncoderParameters();
1179         bool SetAACEncoderParameters();
1180
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
1191                                       );
1192
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
1198                                      );
1199
1200         OsclSharedPtr<class PVMFMediaDataImpl> WrapOutputBuffer(uint8 *pData, uint32 aDataLen, OsclAny *pContext);
1201         bool QueueOutputBuffer(OsclSharedPtr<PVMFMediaDataImpl> &mediadataimplout, uint32 aDataLen);
1202
1203         bool SendOutputBufferToOMXComponent();
1204         bool SendInputBufferToOMXComponent();
1205
1206
1207         bool SendEOSBufferToOMXComponent();
1208
1209         bool SendBeginOfMediaStreamCommand(void);
1210         bool SendEndOfTrackCommand(void);
1211
1212
1213
1214         bool ReleaseAllPorts();
1215         bool DeleteOMXEncoder();
1216
1217         void ChangeNodeState(TPVMFNodeInterfaceState aNewState);
1218
1219         void HandleComponentStateChange(OMX_U32 encoder_state);
1220
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);
1226
1227         PVMFStatus GetConfigParameter(PvmiKvp*& aParameters, int& aNumParamElements, int32 aIndex, PvmiKvpAttr aReqattr);
1228         PVMFStatus VerifyAndSetConfigParameter(PvmiKvp& aParameter, bool aSetParam);
1229
1230         PVMFStatus AllocateKvp(PvmiKvp*& aKvp, PvmiKeyType aKey, int32 aNumParams);
1231
1232         void freechunkavailable(OsclAny*);
1233
1234         PVMFCommandId QueueCommandL(PVMFOMXEncNodeCommand& aCmd);
1235
1236
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);
1242
1243
1244         OMX_ERRORTYPE FillBufferDoneProcM4V(OMX_OUT OMX_HANDLETYPE aComponent,
1245                                             OMX_OUT OMX_PTR aAppData,
1246                                             OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer,
1247                                             OutputBufCtrlStruct *pContext);
1248
1249         OMX_ERRORTYPE FillBufferDoneProcAVC(OMX_OUT OMX_HANDLETYPE aComponent,
1250                                             OMX_OUT OMX_PTR aAppData,
1251                                             OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer,
1252                                             OutputBufCtrlStruct *pContext);
1253
1254         OMX_ERRORTYPE FillBufferDoneProcETC(OMX_OUT OMX_HANDLETYPE aComponent,
1255                                             OMX_OUT OMX_PTR aAppData,
1256                                             OMX_OUT OMX_BUFFERHEADERTYPE* aBuffer,
1257                                             OutputBufCtrlStruct *pContext);
1258
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);
1262
1263         friend class PVMFOMXEncPort;
1264
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);
1269
1270         // Ports pointers
1271         PVMFPortInterface* iInPort;
1272         PVMFPortInterface* iOutPort;
1273
1274         // Commands
1275         PVMFOMXEncNodeCmdQ iInputCommands;
1276         PVMFOMXEncNodeCmdQ iCurrentCommand;
1277
1278         // Shared pointer for Media Msg.Input buffer
1279         PVMFSharedMediaDataPtr iDataIn;
1280
1281
1282         // OUTPUT BUFFER RELATED MEMBERS
1283
1284
1285         // Output buffer memory pool
1286         OsclMemPoolFixedChunkAllocator *iOutBufMemoryPool;
1287
1288         // Memory pool for simple media data
1289         OsclMemPoolFixedChunkAllocator *iMediaDataMemPool;
1290
1291         // Size of output buffer (negotiated with component)
1292         uint32 iOMXComponentOutputBufferSize;
1293
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;
1297
1298         // Number of output buffers (negotiated with component)
1299         uint32 iNumOutputBuffers;
1300
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;
1306
1307         // flag to prevent sending output buffers downstream during flushing etc.
1308         bool iDoNotSendOutputBuffersDownstreamFlag;
1309
1310         // flag to prevent freeing the buffers twice
1311         bool iOutputBuffersFreed;
1312
1313
1314
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)
1321
1322         // desired input buffer alignment (read from the component port)
1323         uint32 iInputBufferAlignment;
1324
1325         uint32 iNumOutstandingInputBuffers; // number of input buffers in use (i.e. unavailable)
1326
1327         // flag to prevent freeing buffers twice
1328         bool iInputBuffersFreed;
1329
1330         // input buffer fragmentation etc.
1331         uint32 iCopyPosition;               // for copying memfrag data into a buffer
1332         uint32 iFragmentSizeRemainingToCopy;
1333         bool    iIsNewDataFragment;
1334
1335         // input data info
1336         uint32 iCurrFragNum;
1337         uint32 iCodecSeqNum;    // sequence number tracking
1338         uint32 iInPacketSeqNum;
1339
1340         uint32 iInTimestamp;
1341         uint32 iInDuration;
1342         uint32 iInNumFrags;
1343         uint32 iCurrentMsgMarkerBit;
1344
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;
1353
1354
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;
1365
1366         bool iSetMarkerBitForEveryFrag;
1367         bool iIsOMXComponentMultiThreaded;
1368
1369         // State definitions for HandleProcessingState() state machine
1370         typedef enum
1371         {
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;
1386
1387         // State of HandleProcessingState() state machine
1388         PVMFOMXEncNode_ProcessingState iProcessingState;
1389
1390         // Handle of OMX Component
1391         OMX_HANDLETYPE iOMXEncoder;
1392
1393         // Current State of the component
1394         OMX_STATETYPE iCurrentEncoderState;
1395
1396         // BOS
1397         bool iSendBOS;
1398         uint32 iStreamID;
1399         uint32 iBOSTimestamp;
1400
1401         //EOS control flags
1402         bool iIsEOSSentToComponent;
1403         bool iIsEOSReceivedFromComponent;
1404
1405         // Send Fsi configuration flag
1406         bool    sendYuvFsi;
1407
1408         // Width of encoded frame
1409         int32 iYUVWidth;
1410         // Height of encoded frame
1411         int32 iYUVHeight;
1412
1413
1414
1415         // Pointer to input data fragment
1416         uint8* iBitstreamBuffer;
1417         // Size of input data fragment
1418         int32 iBitstreamSize;
1419
1420         // Output frame sequence counter
1421         uint32 iSeqNum;
1422
1423         // Input frame sequence counter
1424         uint32 iSeqNum_In;
1425
1426         // Added to Scheduler Flag
1427         bool iIsAdded;
1428
1429         // Log related
1430         PVLogger* iLogger;
1431         PVLogger* iDataPathLogger;
1432         PVLogger* iClockLogger;
1433         PVLogger *iRunlLogger;
1434         const char *iNodeTypeId;
1435
1436         // Counter of fragment read from current Media Msg.Input buffer
1437         uint fragnum;
1438         // Number of fragments in the Media Msg.Input buffer
1439         uint numfrags;
1440
1441
1442         // Node configuration update
1443         //PVMFOMXEncNodeConfig iNodeConfig;
1444
1445         // Capability exchange
1446         PVMFNodeCapability iCapability;
1447
1448         // Reference counter for extension
1449         uint32 iExtensionRefCount;
1450
1451         // Vector for KVP
1452         Oscl_Vector<OSCL_HeapString<OsclMemAllocator>, OsclMemAllocator> iAvailableMetadataKeys;
1453
1454         // EOS flag
1455         bool iEndOfDataReached;
1456         // Time stame upon EOS
1457         PVMFTimestamp iEndOfDataTimestamp;
1458
1459         /* Diagnostic log related */
1460         PVLogger* iDiagnosticsLogger;
1461         bool iDiagnosticsLogged;
1462         void LogDiagnostics();
1463
1464         uint32 iFrameCounter;
1465
1466
1467
1468         uint32 iAvgBitrateValue;
1469         bool iResetInProgress;
1470         bool iResetMsgSent;
1471         bool iStopInResetMsgSent;
1472
1473         PV_VideoEncodeParam iVideoEncodeParam;
1474         PV_VideoInputFormat iVideoInputFormat;
1475         PV_AudioEncodeParam iAudioEncodeParam;
1476         PV_AudioInputFormat iAudioInputFormat;
1477
1478         PVMFFormatType iInFormat;
1479         PVMFFormatType iOutFormat;
1480
1481         PVMFOMXEncNodeAllocDestructDealloc iAlloc;
1482         OsclRefCounterMemFrag iVolHeader; /** Vol header */
1483         OsclRefCounterMemFrag iConfigHeader;
1484
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
1488         int   iNumSPSs;
1489         int   iNumPPSs;
1490         bool iSpsPpsSequenceOver;
1491         OsclSharedPtr<PVMFMediaDataImpl> iPreviousMediaData;
1492         bool iFirstNAL;
1493         uint32* iNALSizeArray;
1494         uint8** iNALPtrArray;
1495         uint32 iNALSizeArrayMaxElems;
1496         uint32 iNumNALs;
1497         uint32 iFirstNALStartCodeSize;
1498
1499         uint32 iEndOfFrameFlagPrevious;
1500         uint32 iKeyFrameFlagPrevious;
1501         uint32 iEndOfNALFlagPrevious;
1502         OMX_TICKS iTimeStampPrevious;
1503         uint32 iBufferLenPrevious;
1504
1505         uint32 iEndOfFrameFlagOut;
1506         uint32 iKeyFrameFlagOut;
1507         uint32 iEndOfNALFlagOut;
1508         OMX_TICKS iTimeStampOut;
1509         uint32 iBufferLenOut;
1510
1511         OutputBufCtrlStruct *out_ctrl_struct_ptr;
1512
1513         InputBufCtrlStruct *in_ctrl_struct_ptr;
1514
1515
1516         // timescale, timestamp conversions
1517         uint32 iTimeScale;
1518         uint32 iInTimeScale;
1519         uint32 iOutTimeScale;
1520
1521         MediaClockConverter iInputTimestampClock;
1522         OMX_TICKS iOMXTicksTimestamp;
1523         OMX_TICKS ConvertTimestampIntoOMXTicks(const MediaClockConverter &src);
1524         uint32 ConvertOMXTicksIntoTimestamp(const OMX_TICKS &src);
1525
1526         bool CheckComponentForMultRoles(OMX_STRING aCompName, OMX_STRING aRole);
1527         bool CheckComponentCapabilities(PVMFFormatType* aOutFormat);
1528
1529
1530 #ifdef _TEST_AE_ERROR_HANDLING
1531         bool   iErrorHandlingInit;
1532         uint32 iErrorHandlingEncodeCount;
1533         int    iCountFrames;
1534         uint32 iErrorNodeCmd;
1535         bool iErrorConfigHeader;
1536         uint32 iErrorEncodeFlag;
1537         uint32 iErrorDataPathStall;
1538 #endif
1539 };
1540
1541
1542 #endif // PVMF_OMXENC_NODE_H_INCLUDED
1543