summaryrefslogtreecommitdiff
path: root/videopp/inc/omx_vdpp.h
blob: 08699bb88c263eb42c92e6d1d897fea919c8626f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
/*--------------------------------------------------------------------------
Copyright (c) 2013 The Linux Foundation. All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions
  are met:

    * Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above
  copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.
    * Neither the name of The Linux Foundation nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--------------------------------------------------------------------------*/
#ifndef __OMX_VDPP_H__
#define __OMX_VDPP_H__
/*============================================================================
                            O p e n M A X   Component
                                Video Decoder

*//** @file omx_vdpp.h
  This module contains the class definition for openMAX video post-processing component.

*//*========================================================================*/

//////////////////////////////////////////////////////////////////////////////
//                             Include Files
//////////////////////////////////////////////////////////////////////////////

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <inttypes.h>
#include <cstddef>
#include <math.h>

#ifdef _ANDROID_
#define LOG_TAG "OMX-VDPP"

#ifdef USE_ION
#include <linux/msm_ion.h>
#endif
#include <binder/MemoryHeapBase.h>
#include <ui/ANativeObjectBase.h>
extern "C"{
#include <utils/Log.h>
}
#include <linux/videodev2.h>
#include <poll.h>
#define TIMEOUT 5000

#define DEBUG_PRINT_LOW(x, ...) ALOGV("[Entry] "x, ##__VA_ARGS__)
#define DEBUG_PRINT_HIGH(x, ...) ALOGV("[Step] "x, ##__VA_ARGS__)
#define DEBUG_PRINT_ERROR(x, ...) ALOGE("[Error] "x, ##__VA_ARGS__)

#else //_ANDROID_
#define DEBUG_PRINT_LOW printf
#define DEBUG_PRINT_HIGH printf
#define DEBUG_PRINT_ERROR printf
#endif // _ANDROID_

#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
#include <media/hardware/HardwareAPI.h>
#endif

#include <unistd.h>

#if defined (_ANDROID_ICS_)
#include <gralloc_priv.h>
#endif

#include <pthread.h>
#ifndef PC_DEBUG
#include <semaphore.h>
#endif
#include "OMX_Core.h"
#include "OMX_QCOMExtns.h"
#include "OMX_CoreExt.h"
#include "OMX_IndexExt.h"
#include "qc_omx_component.h"
#include <linux/android_pmem.h>
#include <dlfcn.h>

#include <media/msm_vpu.h>
extern "C" {
  OMX_API void * get_omx_component_factory_fn(void); //used by qc_omx_core
}

#ifdef _ANDROID_
    using namespace android;
#endif // _ANDROID_
//////////////////////////////////////////////////////////////////////////////
//                       Module specific globals
//////////////////////////////////////////////////////////////////////////////
#define OMX_SPEC_VERSION  0x00000101

//#define OUTPUT_BUFFER_LOG 1
//#define INPUT_BUFFER_LOG  1
//////////////////////////////////////////////////////////////////////////////
//               Macros
//////////////////////////////////////////////////////////////////////////////
#define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\
                       (unsigned) bufHdr,\
                       (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\
                       (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\
                       (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp)

// BitMask Management logic
#define BITS_PER_BYTE        32
#define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_BYTE - 1)/BITS_PER_BYTE)
#define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_BYTE)
#define BITMASK_FLAG(mIndex) (1 << ((mIndex) % BITS_PER_BYTE))
#define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \
        &=  ~(BITMASK_FLAG(mIndex))
#define BITMASK_SET(mArray,mIndex)  (mArray)[BITMASK_OFFSET(mIndex)] \
        |=  BITMASK_FLAG(mIndex)
#define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
        & BITMASK_FLAG(mIndex))
#define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
        & BITMASK_FLAG(mIndex)) == 0x0)
#define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
        & BITMASK_FLAG(mIndex))
#define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
        & BITMASK_FLAG(mIndex)) == 0x0)

#define OMX_CORE_CONTROL_CMDQ_SIZE   200//100
#define OMX_CORE_QCIF_HEIGHT         144
#define OMX_CORE_QCIF_WIDTH          176
#define OMX_CORE_VGA_HEIGHT          480
#define OMX_CORE_VGA_WIDTH           640
#define OMX_CORE_WVGA_HEIGHT         480
#define OMX_CORE_WVGA_WIDTH          800

#ifdef _ANDROID_
#define MAX_NUM_INPUT_OUTPUT_BUFFERS 32
#endif

#define OMX_FRAMEINFO_EXTRADATA 0x00010000
#define OMX_INTERLACE_EXTRADATA 0x00020000
#define OMX_TIMEINFO_EXTRADATA  0x00040000
#define OMX_PORTDEF_EXTRADATA   0x00080000
#define OMX_EXTNUSER_EXTRADATA  0x00100000
#define DRIVER_EXTRADATA_MASK   0x0000FFFF

#define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
                                       sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3))
#define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
                                       sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3))
#define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
                                       sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3))

#define VALID_TS(ts)      ((ts < LLONG_MAX)? true : false)

/* STATUS CODES */
/* Base value for status codes */
#define VDPP_S_BASE	0x40000000
/* Success */
#define VDPP_S_SUCCESS	(VDPP_S_BASE)
/* General failure */
#define VDPP_S_EFAIL	(VDPP_S_BASE + 1)
/* Fatal irrecoverable  failure. Need to  tear down session. */
#define VDPP_S_EFATAL   (VDPP_S_BASE + 2)
/* Error detected in the passed  parameters */
#define VDPP_S_EBADPARAM	(VDPP_S_BASE + 3)
/* Command called in invalid  state. */
#define VDPP_S_EINVALSTATE	(VDPP_S_BASE + 4)
 /* Insufficient OS  resources - thread, memory etc. */
#define VDPP_S_ENOSWRES	(VDPP_S_BASE + 5)
 /* Insufficient HW resources -  core capacity  maxed  out. */
#define VDPP_S_ENOHWRES	(VDPP_S_BASE + 6)
/* Invalid command  called */
#define VDPP_S_EINVALCMD	(VDPP_S_BASE + 7)
/* Command timeout. */
#define VDPP_S_ETIMEOUT	(VDPP_S_BASE + 8)
/* Pre-requirement is  not met for API. */
#define VDPP_S_ENOPREREQ	(VDPP_S_BASE + 9)
/* Command queue is full. */
#define VDPP_S_ECMDQFULL	(VDPP_S_BASE + 10)
/* Command is not supported  by this driver */
#define VDPP_S_ENOTSUPP	(VDPP_S_BASE + 11)
/* Command is not implemented by thedriver. */
#define VDPP_S_ENOTIMPL	(VDPP_S_BASE + 12)
/* Command is not implemented by the driver.  */
#define VDPP_S_BUSY	(VDPP_S_BASE + 13)
#define VDPP_S_INPUT_BITSTREAM_ERR (VDPP_S_BASE + 14)

#define VDPP_INTF_VER	1
#define VDPP_MSG_BASE	0x0000000
/* Codes to identify asynchronous message responses and events that driver
  wants to communicate to the app.*/
#define VDPP_MSG_INVALID	(VDPP_MSG_BASE + 0)
#define VDPP_MSG_RESP_INPUT_BUFFER_DONE	(VDPP_MSG_BASE + 1)
#define VDPP_MSG_RESP_OUTPUT_BUFFER_DONE	(VDPP_MSG_BASE + 2)
#define VDPP_MSG_RESP_INPUT_FLUSHED	(VDPP_MSG_BASE + 3)
#define VDPP_MSG_RESP_OUTPUT_FLUSHED	(VDPP_MSG_BASE + 4)
#define VDPP_MSG_RESP_FLUSH_INPUT_DONE	(VDPP_MSG_BASE + 5)
#define VDPP_MSG_RESP_FLUSH_OUTPUT_DONE	(VDPP_MSG_BASE + 6)
#define VDPP_MSG_RESP_START_DONE	(VDPP_MSG_BASE + 7)
#define VDPP_MSG_RESP_STOP_DONE	(VDPP_MSG_BASE + 8)
#define VDPP_MSG_RESP_PAUSE_DONE	(VDPP_MSG_BASE + 9)
#define VDPP_MSG_RESP_RESUME_DONE	(VDPP_MSG_BASE + 10)
#define VDPP_MSG_RESP_RESOURCE_LOADED	(VDPP_MSG_BASE + 11)
#define VDPP_EVT_RESOURCES_LOST	(VDPP_MSG_BASE + 12)
#define VDPP_MSG_EVT_CONFIG_CHANGED	(VDPP_MSG_BASE + 13)
#define VDPP_MSG_EVT_HW_ERROR	(VDPP_MSG_BASE + 14)
#define VDPP_MSG_EVT_INFO_CONFIG_CHANGED	(VDPP_MSG_BASE + 15)
#define VDPP_MSG_EVT_INFO_FIELD_DROPPED	(VDPP_MSG_BASE + 16)

#define VDPP_MSG_EVT_ACTIVE_REGION_DETECTION_STATUS	(VDPP_MSG_BASE + 17)


#define VP_INPUT_BUFFER_COUNT_INTERLACE 4
#define VP_OUTPUT_BUFFER_COUNT 4

#define VDPP_SESSION 1
//#define STUB_VPU 1
//#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA)

enum port_indexes
{
    OMX_CORE_INPUT_PORT_INDEX        =0,
    OMX_CORE_OUTPUT_PORT_INDEX       =1
};
#ifdef USE_ION
struct vdpp_ion
{
    int ion_device_fd;
    struct ion_fd_data fd_ion_data;
    struct ion_allocation_data ion_alloc_data;
};
#endif

struct extradata_buffer_info {
	int buffer_size;
	char* uaddr;
	int count;
	int size;
#ifdef USE_ION
	struct vdpp_ion ion;
#endif
};

struct vdpp_picsize {
	uint32_t frame_width;
	uint32_t frame_height;
	uint32_t stride;
	uint32_t scan_lines;
};

enum vdpp_interlaced_format {
	VDPP_InterlaceFrameProgressive = 0x1,
	VDPP_InterlaceInterleaveFrameTopFieldFirst = 0x2,
	VDPP_InterlaceInterleaveFrameBottomFieldFirst = 0x4
};

enum vdpp_buffer {
	VDPP_BUFFER_TYPE_INPUT,
	VDPP_BUFFER_TYPE_OUTPUT
};

struct vdpp_allocatorproperty {
	enum vdpp_buffer buffer_type;
	uint32_t mincount;
	uint32_t maxcount;
	uint32_t actualcount;
	size_t buffer_size;
	uint32_t alignment;
	uint32_t buf_poolid;
	size_t meta_buffer_size;
};

struct vdpp_bufferpayload {
	void *bufferaddr;
	size_t buffer_len;
	int pmem_fd;
	size_t offset;
	size_t mmaped_size;
};

struct vdpp_framesize {
	uint32_t   left;
	uint32_t   top;
	uint32_t   right;
	uint32_t   bottom;
};

struct vdpp_setbuffer_cmd {
	enum vdpp_buffer buffer_type;
	struct vdpp_bufferpayload buffer;
};

struct vdpp_output_frameinfo {
	void *bufferaddr;
	size_t offset;
	size_t len;
	uint32_t flags;
	int64_t time_stamp;
	void *client_data;
	struct vdpp_framesize framesize;

};

union vdpp_msgdata {
    struct v4l2_rect ar_result;
	struct vdpp_output_frameinfo output_frame;
	void *input_frame_clientdata;
};

struct vdpp_msginfo {
	uint32_t status_code;
	uint32_t msgcode;
	union vdpp_msgdata msgdata;
	size_t msgdatasize;
};

struct vdpp_framerate {
	unsigned long fps_denominator;
	unsigned long fps_numerator;
};

#ifdef STUB_VPU
typedef struct vcap_etb_ftb_info
{
    int etb_cnt; // only simulate 1-to-1
    __u32	etb_index;
	size_t  etb_len;
    int ftb_cnt;
    __u32   ftb_index;
	size_t  ftb_len;
}vcap_etb_ftb_info;
#endif

struct video_vpu_context
{
    int video_vpu_fd;
    uint32_t output_format;
    enum   v4l2_field interlace;
    struct vdpp_picsize video_resolution_input;
    struct vdpp_picsize video_resolution_output;
    struct vdpp_allocatorproperty ip_buf;
    struct vdpp_allocatorproperty op_buf;
    struct vdpp_bufferpayload *ptr_inputbuffer;
    struct vdpp_bufferpayload *ptr_outputbuffer;
    struct vdpp_output_frameinfo *ptr_respbuffer;
#ifdef USE_ION
    struct vdpp_ion *ip_buf_ion_info;
    struct vdpp_ion *op_buf_ion_info;
#endif
    struct vdpp_framerate frame_rate;
    bool timestamp_adjust;
    char kind[128];
	struct extradata_buffer_info extradata_info;
    int input_num_planes;
    int output_num_planes;
    double input_bytesperpixel[2];
    double output_bytesperpixel[2];
    int sessionsSupported;
    int sessionAttached;
#ifdef STUB_VPU
    bool thread_exit;
    vcap_etb_ftb_info etb_ftb_info;
    sem_t             async_lock;
#endif
};

typedef struct _VdppExtensionData_t
{
    bool                           activeRegionDetectionDirtyFlag;
    QOMX_ACTIVEREGIONDETECTIONTYPE activeRegionDetection;
    bool                                  activeRegionDetectionStatusDirtyFlag;
    QOMX_ACTIVEREGIONDETECTION_STATUSTYPE activeRegionDetectionStatus;
    bool                  scalingModeDirtyFlag;
    QOMX_SCALINGMODETYPE  scalingMode;
    bool                    noiseReductionDirtyFlag;
    QOMX_NOISEREDUCTIONTYPE noiseReduction;
    bool                      imageEnhancementDirtyFlag;
    QOMX_IMAGEENHANCEMENTTYPE imageEnhancement;
} VdppExtensionData_t;

// OMX video decoder class
class omx_vdpp: public qc_omx_component
{

public:
    omx_vdpp();  // constructor
    virtual ~omx_vdpp();  // destructor

    static int async_message_process (void *context, void* message);
    static void process_event_cb(void *ctxt,unsigned char id);
    struct omx_event
    {
        unsigned param1;
        unsigned param2;
        unsigned id;
    };
    struct omx_cmd_queue
    {
        omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE];
        unsigned m_read;
        unsigned m_write;
        unsigned m_size;

        omx_cmd_queue();
        ~omx_cmd_queue();
        bool insert_entry(unsigned p1, unsigned p2, unsigned id);
        bool pop_entry(unsigned *p1,unsigned *p2, unsigned *id);
        // get msgtype of the first ele from the queue
        unsigned get_q_msg_type();

    };

    OMX_ERRORTYPE allocate_buffer(
                                   OMX_HANDLETYPE hComp,
                                   OMX_BUFFERHEADERTYPE **bufferHdr,
                                   OMX_U32 port,
                                   OMX_PTR appData,
                                   OMX_U32 bytes
                                  );


    OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp);

    OMX_ERRORTYPE component_init(OMX_STRING role);

    OMX_ERRORTYPE component_role_enum(
                                       OMX_HANDLETYPE hComp,
                                       OMX_U8 *role,
                                       OMX_U32 index
                                      );

    OMX_ERRORTYPE component_tunnel_request(
                                            OMX_HANDLETYPE hComp,
                                            OMX_U32 port,
                                            OMX_HANDLETYPE  peerComponent,
                                            OMX_U32 peerPort,
                                            OMX_TUNNELSETUPTYPE *tunnelSetup
                                           );

    OMX_ERRORTYPE empty_this_buffer(
                                     OMX_HANDLETYPE hComp,
                                     OMX_BUFFERHEADERTYPE *buffer
                                    );



    OMX_ERRORTYPE fill_this_buffer(
                                    OMX_HANDLETYPE hComp,
                                    OMX_BUFFERHEADERTYPE *buffer
                                   );


    OMX_ERRORTYPE free_buffer(
                              OMX_HANDLETYPE hComp,
                              OMX_U32 port,
                              OMX_BUFFERHEADERTYPE *buffer
                              );

    OMX_ERRORTYPE get_component_version(
                                        OMX_HANDLETYPE hComp,
                                        OMX_STRING componentName,
                                        OMX_VERSIONTYPE *componentVersion,
                                        OMX_VERSIONTYPE *specVersion,
                                        OMX_UUIDTYPE *componentUUID
                                        );

    OMX_ERRORTYPE get_config(
                              OMX_HANDLETYPE hComp,
                              OMX_INDEXTYPE configIndex,
                              OMX_PTR configData
                             );

    OMX_ERRORTYPE get_extension_index(
                                      OMX_HANDLETYPE hComp,
                                      OMX_STRING paramName,
                                      OMX_INDEXTYPE *indexType
                                      );

    OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp,
                                OMX_INDEXTYPE  paramIndex,
                                OMX_PTR        paramData);

    OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp,
                            OMX_STATETYPE *state);



    OMX_ERRORTYPE send_command(OMX_HANDLETYPE  hComp,
                               OMX_COMMANDTYPE cmd,
                               OMX_U32         param1,
                               OMX_PTR         cmdData);


    OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE   hComp,
                                OMX_CALLBACKTYPE *callbacks,
                                OMX_PTR          appData);

    OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp,
                             OMX_INDEXTYPE  configIndex,
                             OMX_PTR        configData);

    OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp,
                                OMX_INDEXTYPE  paramIndex,
                                OMX_PTR        paramData);

    OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE      hComp,
                             OMX_BUFFERHEADERTYPE **bufferHdr,
                             OMX_U32              port,
                             OMX_PTR              appData,
                             OMX_U32              bytes,
                             OMX_U8               *buffer);

    OMX_ERRORTYPE  use_input_heap_buffers(
                          OMX_HANDLETYPE            hComp,
                          OMX_BUFFERHEADERTYPE** bufferHdr,
                          OMX_U32                   port,
                          OMX_PTR                   appData,
                          OMX_U32                   bytes,
                          OMX_U8*                   buffer);

    OMX_ERRORTYPE  use_input_buffers(
                          OMX_HANDLETYPE            hComp,
                          OMX_BUFFERHEADERTYPE** bufferHdr,
                          OMX_U32                   port,
                          OMX_PTR                   appData,
                          OMX_U32                   bytes,
                          OMX_U8*                   buffer);

    OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE     hComp,
                                OMX_BUFFERHEADERTYPE **bufferHdr,
                                OMX_U32              port,
                                OMX_PTR              appData,
                                void *               eglImage);

    void complete_pending_buffer_done_cbs();
    struct video_vpu_context drv_ctx;
    int update_resolution(uint32_t width, uint32_t height, uint32_t stride, uint32_t scan_lines);

    int  m_pipe_in;
    int  m_pipe_out;
    int  m_ctrl_in;
    int  m_ctrl_out;

    pthread_t msg_thread_id;
    pthread_t async_thread_id;
    omx_cmd_queue m_index_q;
    bool m_ar_callback_setup;
private:
    // Bit Positions
    enum flags_bit_positions
    {
        // Defer transition to IDLE
        OMX_COMPONENT_IDLE_PENDING            =0x1,
        // Defer transition to LOADING
        OMX_COMPONENT_LOADING_PENDING         =0x2,
        // First  Buffer Pending
        OMX_COMPONENT_FIRST_BUFFER_PENDING    =0x3,
        // Second Buffer Pending
        OMX_COMPONENT_SECOND_BUFFER_PENDING   =0x4,
        // Defer transition to Enable
        OMX_COMPONENT_INPUT_ENABLE_PENDING    =0x5,
        // Defer transition to Enable
        OMX_COMPONENT_OUTPUT_ENABLE_PENDING   =0x6,
        // Defer transition to Disable
        OMX_COMPONENT_INPUT_DISABLE_PENDING   =0x7,
        // Defer transition to Disable
        OMX_COMPONENT_OUTPUT_DISABLE_PENDING  =0x8,
        //defer flush notification
        OMX_COMPONENT_OUTPUT_FLUSH_PENDING    =0x9,
        OMX_COMPONENT_INPUT_FLUSH_PENDING    =0xA,
        OMX_COMPONENT_PAUSE_PENDING          =0xB,
        OMX_COMPONENT_EXECUTE_PENDING        =0xC,
        OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD,
        OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE
    };

    // Deferred callback identifiers
    enum
    {
        //Event Callbacks from the vidpp component thread context
        OMX_COMPONENT_GENERATE_EVENT       = 0x1,
        //Buffer Done callbacks from the vidpp component thread context
        OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2,
        //Frame Done callbacks from the vidpp component thread context
        OMX_COMPONENT_GENERATE_FRAME_DONE  = 0x3,
        //Buffer Done callbacks from the vidpp component thread context
        OMX_COMPONENT_GENERATE_FTB         = 0x4,
        //Frame Done callbacks from the vidpp component thread context
        OMX_COMPONENT_GENERATE_ETB         = 0x5,
        //Command
        OMX_COMPONENT_GENERATE_COMMAND     = 0x6,
        //Push-Pending Buffers
        OMX_COMPONENT_PUSH_PENDING_BUFS    = 0x7,
        // Empty Buffer Done callbacks
        OMX_COMPONENT_GENERATE_EBD         = 0x8,
        //Flush Event Callbacks from the vidpp component thread context
        OMX_COMPONENT_GENERATE_EVENT_FLUSH       = 0x9,
        OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A,
        OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B,
        OMX_COMPONENT_GENERATE_FBD = 0xc,
        OMX_COMPONENT_GENERATE_START_DONE = 0xD,
        OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE,
        OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF,
        OMX_COMPONENT_GENERATE_STOP_DONE = 0x10,
        OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11,
        OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12,
        OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13,
        OMX_COMPONENT_GENERATE_EOS_DONE = 0x14,
        OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15,
        OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16,
        OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x17,

        // extensions
        OMX_COMPONENT_GENERATE_ACTIVE_REGION_DETECTION_STATUS = 0x18,
    };

    enum v4l2_ports
    {
        CAPTURE_PORT,
        OUTPUT_PORT,
        MAX_PORT
    };

#ifdef _ANDROID_
    struct ts_entry
    {
        OMX_TICKS timestamp;
        bool valid;
    };

    struct ts_arr_list
    {
        ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS];

        ts_arr_list();
        ~ts_arr_list();

        bool insert_ts(OMX_TICKS ts);
        bool pop_min_ts(OMX_TICKS &ts);
        bool reset_ts_list();
    };
#endif

    bool allocate_done(void);
    bool allocate_input_done(void);
    bool allocate_output_done(void);

    OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
    OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
    void free_output_buffer_header();
    void free_input_buffer_header();

    OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE       hComp,
                                             OMX_BUFFERHEADERTYPE **bufferHdr,
                                             OMX_U32              port,
                                             OMX_PTR              appData,
                                             OMX_U32              bytes);

    OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE       hComp,
                                        OMX_BUFFERHEADERTYPE **bufferHdr,
                                        OMX_U32              port,
                                        OMX_PTR              appData,
                                        OMX_U32              bytes);

    OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE       hComp,
                                         OMX_BUFFERHEADERTYPE **bufferHdr,
                                         OMX_U32 port,OMX_PTR appData,
                                         OMX_U32              bytes);
    OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp,
                                   OMX_BUFFERHEADERTYPE   **bufferHdr,
                                   OMX_U32                port,
                                   OMX_PTR                appData,
                                   OMX_U32                bytes,
                                   OMX_U8                 *buffer);

    OMX_ERRORTYPE allocate_output_headers();
    bool execute_omx_flush(OMX_U32);
    bool execute_output_flush();
    bool execute_input_flush();
    OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp,
                                    OMX_BUFFERHEADERTYPE * buffer);

    OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp,
                                    OMX_BUFFERHEADERTYPE * buffer);
    OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE       hComp,
                                        OMX_BUFFERHEADERTYPE *buffer);

    OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE       hComp,
                                       OMX_BUFFERHEADERTYPE *buffer);
    bool release_done();

    bool release_output_done();
    bool release_input_done();
    OMX_ERRORTYPE get_buffer_req(vdpp_allocatorproperty *buffer_prop);
    OMX_ERRORTYPE set_buffer_req(vdpp_allocatorproperty *buffer_prop);
    OMX_ERRORTYPE start_port_reconfig();

    int stream_off(OMX_U32 port);
    void adjust_timestamp(OMX_S64 &act_timestamp);
    void set_frame_rate(OMX_S64 act_timestamp);
    OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true);
    OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn);
    bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
                            OMX_U32 alignment);
#ifdef USE_ION
    int alloc_map_ion_memory(OMX_U32 buffer_size,
              OMX_U32 alignment, struct ion_allocation_data *alloc_data,
              struct ion_fd_data *fd_data,int flag);
    void free_ion_memory(struct vdpp_ion *buf_ion_info);
#endif


    OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE  hComp,
                                     OMX_COMMANDTYPE cmd,
                                     OMX_U32         param1,
                                     OMX_PTR         cmdData);
    bool post_event( unsigned int p1,
                     unsigned int p2,
                     unsigned int id
                    );

    void setFormatParams(int pixelFormat, double bytesperpixel[], unsigned char *planesCount);

    int openInput(const char* inputName);

    /**
      * int clip2 - return an integer value in 2 to the nth power
      * legacy code from video decoder  (rounded up till 256)
      *
      */
    inline int clip2(int x)
    {
        x = x -1;
        x = x | x >> 1;
        x = x | x >> 2;
        x = x | x >> 4;
        x = x | x >> 16;
        x = x + 1;
        return x;
    }
    /**
      * int paddedFrameWidth - return frame width in a multiple of 128 (rounded up).
      *
      * @width - the original frame width.
      */
    inline int paddedFrameWidth(int width)
    {
        int i = 0;
        while(1)
        {
            if(width <= 128*i)
            {
		    //LOGE("paddedFrameWidth: padded width is %d", 128*i);
                return 128*i; /* return width in closest multiple of 128. */
            }
            i++;
        }
    }

    /**
      * int roundToNearestInt - round to nearest integer value.
      *
      * @value - the decimal value to be rounded to nearest integer.
      */
    inline int roundToNearestInt(double value)
    {
	    if((ceil(value) - value) > 0.5)
		    return floor(value);
	    else
		    return ceil(value);
    }

    inline void omx_report_error ()
    {
        if (m_cb.EventHandler && !m_error_propogated)
        {
            ALOGE("\nERROR: Sending OMX_EventError to Client");
            m_error_propogated = true;
            m_cb.EventHandler(&m_cmp,m_app_data,
                  OMX_EventError,OMX_ErrorHardware,0,NULL);
        }
    }

    inline void omx_report_unsupported_setting ()
    {
        if (m_cb.EventHandler && !m_error_propogated)
        {
            DEBUG_PRINT_ERROR(
               "\nERROR: Sending OMX_ErrorUnsupportedSetting to Client");
            m_error_propogated = true;
            m_cb.EventHandler(&m_cmp,m_app_data,
                  OMX_EventError,OMX_ErrorUnsupportedSetting,0,NULL);
        }
    }

#if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
    OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data);
#endif
#if defined (_ANDROID_ICS_)
    struct nativebuffer{
        native_handle_t *nativehandle;
	private_handle_t *privatehandle;
        int inuse;
    };
    nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS];
#endif


    //*************************************************************
    //*******************MEMBER VARIABLES *************************
    //*************************************************************
    pthread_mutex_t       m_lock;
    //sem to handle the minimum procesing of commands
    sem_t                 m_cmd_lock;
    bool              m_error_propogated;

    // OMX State
    OMX_STATETYPE m_state;
    // Application data
    OMX_PTR m_app_data;
    // Application callbacks
    OMX_CALLBACKTYPE m_cb;
    OMX_PRIORITYMGMTTYPE m_priority_mgm ;
    OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier;
    // fill this buffer queue
    omx_cmd_queue         m_ftb_q;
    // Command Q for rest of the events
    omx_cmd_queue         m_cmd_q;
    omx_cmd_queue         m_etb_q;
    // Input memory pointer
    OMX_BUFFERHEADERTYPE  *m_inp_mem_ptr;
    // Output memory pointer
    OMX_BUFFERHEADERTYPE  *m_out_mem_ptr;
    // number of input bitstream error frame count
    unsigned int m_inp_err_count;
#ifdef _ANDROID_
    // Timestamp list
    ts_arr_list           m_timestamp_list;
#endif

    bool input_flush_progress;
    bool output_flush_progress;
    bool input_use_buffer;
    bool output_use_buffer;
    bool ouput_egl_buffers;
    OMX_BOOL m_use_output_pmem;
    OMX_BOOL m_out_mem_region_smi;
    OMX_BOOL m_out_pvt_entry_pmem;

    int pending_input_buffers;
    int pending_output_buffers;

    int input_qbuf_count;
    int input_dqbuf_count;
    int output_qbuf_count;
    int output_dqbuf_count;

#ifdef OUTPUT_BUFFER_LOG
    int output_buffer_write_counter;
    int input_buffer_write_counter;
#endif
    // bitmask array size for output side
    unsigned int m_out_bm_count;
    // bitmask array size for input side
    unsigned int m_inp_bm_count;
    //Input port Populated
    OMX_BOOL m_inp_bPopulated;
    //Output port Populated
    OMX_BOOL m_out_bPopulated;
    // encapsulate the waiting states.
    unsigned int m_flags;

    // store I/P PORT state
    OMX_BOOL m_inp_bEnabled;
    // store O/P PORT state
    OMX_BOOL m_out_bEnabled;
    OMX_U32 m_in_alloc_cnt;
    OMX_U8                m_cRole[OMX_MAX_STRINGNAME_SIZE];
    // Platform specific details
    OMX_QCOM_PLATFORM_PRIVATE_LIST      *m_platform_list;
    OMX_QCOM_PLATFORM_PRIVATE_ENTRY     *m_platform_entry;
    OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info;

    /*Variables for arbitrary Byte parsing support*/
    omx_cmd_queue m_input_pending_q;
    omx_cmd_queue m_input_free_q;

    OMX_BUFFERHEADERTYPE  *psource_frame;
    OMX_BUFFERHEADERTYPE  *pdest_frame;
    OMX_BUFFERHEADERTYPE  *m_inp_heap_ptr;
    OMX_BUFFERHEADERTYPE  **m_phdr_pmem_ptr;
    unsigned int m_heap_inp_bm_count;

    OMX_S64 prev_ts;
    bool rst_prev_ts;
    OMX_U32 frm_int;

    struct vdpp_allocatorproperty op_buf_rcnfg;
    bool in_reconfig;
    OMX_U32 client_extradata;
#ifdef _ANDROID_
    bool m_debug_timestamp;
    bool perf_flag;
    OMX_U32 proc_frms, latency;
    bool m_enable_android_native_buffers;
    bool m_use_android_native_buffers;
    bool m_debug_extradata;
    bool m_debug_concealedmb;
#endif

    OMX_PARAM_PORTDEFINITIONTYPE m_port_def;

    int capture_capability;
    int output_capability;
    bool streaming[MAX_PORT];
    OMX_CONFIG_RECTTYPE rectangle;
	int prev_n_filled_len;

    bool msg_thread_created;
    bool async_thread_created;

    unsigned int m_fill_output_msg;
    bool client_set_fps;
    bool interlace_user_flag;
    // OMX extensions
    VdppExtensionData_t mExtensionData;
};
#endif // __OMX_VDPP_H__