Home | History | Annotate | Download | only in inc
      1 /*--------------------------------------------------------------------------
      2 Copyright (c) 2010 - 2017, The Linux Foundation. All rights reserved.
      3 
      4   Redistribution and use in source and binary forms, with or without
      5   modification, are permitted provided that the following conditions
      6   are met:
      7 
      8     * Redistributions of source code must retain the above copyright
      9   notice, this list of conditions and the following disclaimer.
     10     * Redistributions in binary form must reproduce the above
     11   copyright notice, this list of conditions and the following
     12       disclaimer in the documentation and/or other materials provided
     13       with the distribution.
     14     * Neither the name of The Linux Foundation nor the names of its
     15       contributors may be used to endorse or promote products derived
     16       from this software without specific prior written permission.
     17 
     18 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     19 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     21 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     25 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     27 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     28 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 --------------------------------------------------------------------------*/
     30 #ifndef __OMX_VDEC_H__
     31 #define __OMX_VDEC_H__
     32 /*============================================================================
     33                             O p e n M A X   Component
     34                                 Video Decoder
     35 
     36 *//** @file comx_vdec.h
     37   This module contains the class definition for openMAX decoder component.
     38 
     39 *//*========================================================================*/
     40 
     41 //////////////////////////////////////////////////////////////////////////////
     42 //                             Include Files
     43 //////////////////////////////////////////////////////////////////////////////
     44 
     45 #include <stdlib.h>
     46 #include <stdio.h>
     47 #include <string.h>
     48 #include <inttypes.h>
     49 #include <cstddef>
     50 #include <cutils/atomic.h>
     51 #include <qdMetaData.h>
     52 #include <color_metadata.h>
     53 #include <media/msm_media_info.h>
     54 
     55 static ptrdiff_t x;
     56 
     57 #ifdef _ANDROID_
     58 #ifdef MAX_RES_720P
     59 #define LOG_TAG "OMX-VDEC-720P"
     60 #elif MAX_RES_1080P
     61 #define LOG_TAG "OMX-VDEC-1080P"
     62 #else
     63 #define LOG_TAG "OMX-VDEC"
     64 #endif
     65 
     66 #ifdef USE_ION
     67 #include <linux/msm_ion.h>
     68 //#include <binder/MemoryHeapIon.h>
     69 //#else
     70 #endif
     71 extern "C" {
     72 #include <utils/Log.h>
     73 }
     74 #include <linux/videodev2.h>
     75 #include <poll.h>
     76 #include "hevc_utils.h"
     77 #define TIMEOUT 5000
     78 #endif // _ANDROID_
     79 
     80 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
     81 #define STRINGIFY_ENUMS
     82 #include <media/hardware/HardwareAPI.h>
     83 #endif
     84 
     85 #include <unistd.h>
     86 
     87 #if defined (_ANDROID_ICS_)
     88 #include <gralloc_priv.h>
     89 #endif
     90 
     91 #include <pthread.h>
     92 #ifndef PC_DEBUG
     93 #include <semaphore.h>
     94 #endif
     95 #include "OMX_Core.h"
     96 #include "OMX_QCOMExtns.h"
     97 #include "OMX_Skype_VideoExtensions.h"
     98 #include "OMX_VideoExt.h"
     99 #include "OMX_IndexExt.h"
    100 #include "qc_omx_component.h"
    101 #include <linux/msm_vidc_dec.h>
    102 #include <media/msm_vidc.h>
    103 #include "frameparser.h"
    104 #ifdef MAX_RES_1080P
    105 #include "mp4_utils.h"
    106 #endif
    107 #include "extra_data_handler.h"
    108 #include "ts_parser.h"
    109 #include "vidc_color_converter.h"
    110 #include "vidc_debug.h"
    111 #include "vidc_vendor_extensions.h"
    112 #ifdef _ANDROID_
    113 #include <cutils/properties.h>
    114 #else
    115 #define PROPERTY_VALUE_MAX 92
    116 #endif
    117 extern "C" {
    118     OMX_API void * get_omx_component_factory_fn(void);
    119 }
    120 
    121 //////////////////////////////////////////////////////////////////////////////
    122 //                       Module specific globals
    123 //////////////////////////////////////////////////////////////////////////////
    124 #define OMX_SPEC_VERSION  0x00000101
    125 #define OMX_INIT_STRUCT(_s_, _name_)         \
    126     memset((_s_), 0x0, sizeof(_name_));      \
    127 (_s_)->nSize = sizeof(_name_);               \
    128 (_s_)->nVersion.nVersion = OMX_SPEC_VERSION  \
    129 
    130 
    131 //////////////////////////////////////////////////////////////////////////////
    132 //               Macros
    133 //////////////////////////////////////////////////////////////////////////////
    134 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\
    135         (unsigned) bufHdr,\
    136         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\
    137         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\
    138         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp)
    139 
    140 // BitMask Management logic
    141 #define BITS_PER_INDEX        64
    142 #define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_INDEX - 1)/BITS_PER_INDEX)
    143 #define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_INDEX)
    144 #define BITMASK_FLAG(mIndex) ((uint64_t)1 << ((mIndex) % BITS_PER_INDEX))
    145 #define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \
    146     &=  ~(BITMASK_FLAG(mIndex))
    147 #define BITMASK_SET(mArray,mIndex)  (mArray)[BITMASK_OFFSET(mIndex)] \
    148     |=  BITMASK_FLAG(mIndex)
    149 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
    150         & BITMASK_FLAG(mIndex))
    151 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
    152             & BITMASK_FLAG(mIndex)) == 0x0)
    153 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
    154         & BITMASK_FLAG(mIndex))
    155 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
    156             & BITMASK_FLAG(mIndex)) == 0x0)
    157 
    158 #define OMX_CORE_CONTROL_CMDQ_SIZE   100
    159 #define OMX_CORE_QCIF_HEIGHT         144
    160 #define OMX_CORE_QCIF_WIDTH          176
    161 #define OMX_CORE_VGA_HEIGHT          480
    162 #define OMX_CORE_VGA_WIDTH           640
    163 #define OMX_CORE_WVGA_HEIGHT         480
    164 #define OMX_CORE_WVGA_WIDTH          800
    165 #define OMX_CORE_FWVGA_HEIGHT        480
    166 #define OMX_CORE_FWVGA_WIDTH         864
    167 
    168 #define DESC_BUFFER_SIZE (8192 * 16)
    169 
    170 #ifdef _ANDROID_
    171 #define MAX_NUM_INPUT_OUTPUT_BUFFERS 64
    172 #endif
    173 
    174 #define MIN_NUM_INPUT_OUTPUT_EXTRADATA_BUFFERS 32 // 32 (max cap when VPP enabled)
    175 
    176 #define OMX_FRAMEINFO_EXTRADATA 0x00010000
    177 #define OMX_INTERLACE_EXTRADATA 0x00020000
    178 #define OMX_TIMEINFO_EXTRADATA  0x00040000
    179 #define OMX_PORTDEF_EXTRADATA   0x00080000
    180 #define OMX_EXTNUSER_EXTRADATA  0x00100000
    181 #define OMX_FRAMEDIMENSION_EXTRADATA  0x00200000
    182 #define OMX_FRAMEPACK_EXTRADATA 0x00400000
    183 #define OMX_QP_EXTRADATA        0x00800000
    184 #define OMX_BITSINFO_EXTRADATA  0x01000000
    185 #define OMX_VQZIPSEI_EXTRADATA  0x02000000
    186 #define OMX_OUTPUTCROP_EXTRADATA 0x04000000
    187 
    188 #define OMX_VUI_DISPLAY_INFO_EXTRADATA  0x08000000
    189 #define OMX_MPEG2_SEQDISP_INFO_EXTRADATA 0x10000000
    190 #define OMX_VPX_COLORSPACE_INFO_EXTRADATA  0x20000000
    191 #define OMX_VC1_SEQDISP_INFO_EXTRADATA  0x40000000
    192 #define OMX_DISPLAY_INFO_EXTRADATA  0x80000000
    193 #define OMX_HDR_COLOR_INFO_EXTRADATA  0x100000000
    194 #define DRIVER_EXTRADATA_MASK   0x0000FFFF
    195 
    196 #define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    197             sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3))
    198 #define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    199             sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3))
    200 #define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    201             sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3))
    202 #define OMX_FRAMEDIMENSION_EXTRADATA_SIZE (sizeof(OMX_OTHER_EXTRADATATYPE) +\
    203             sizeof(OMX_QCOM_EXTRADATA_FRAMEDIMENSION) + 3)&(~3)
    204 #define OMX_FRAMEPACK_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    205             sizeof(OMX_QCOM_FRAME_PACK_ARRANGEMENT) + 3)&(~3))
    206 #define OMX_QP_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    207             sizeof(OMX_QCOM_EXTRADATA_QP) + 3)&(~3))
    208 #define OMX_BITSINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    209             sizeof(OMX_QCOM_EXTRADATA_BITS_INFO) + 3)&(~3))
    210 #define OMX_VQZIPSEI_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    211             sizeof(OMX_QCOM_EXTRADATA_VQZIPSEI) + 3)&(~3))
    212 #define OMX_USERDATA_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    213             + 3)&(~3))
    214 
    215 //  Define next macro with required values to enable default extradata,
    216 //    VDEC_EXTRADATA_MB_ERROR_MAP
    217 //    OMX_INTERLACE_EXTRADATA
    218 //    OMX_FRAMEINFO_EXTRADATA
    219 //    OMX_TIMEINFO_EXTRADATA
    220 
    221 //#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA)
    222 
    223 enum port_indexes {
    224     OMX_CORE_INPUT_PORT_INDEX        =0,
    225     OMX_CORE_OUTPUT_PORT_INDEX       =1,
    226     OMX_CORE_INPUT_EXTRADATA_INDEX   =2,
    227     OMX_CORE_OUTPUT_EXTRADATA_INDEX  =3
    228 };
    229 enum vidc_perf_level {
    230     VIDC_SVS = 0,
    231     VIDC_NOMINAL = 1,
    232     VIDC_TURBO = 2
    233 };
    234 
    235 enum turbo_mode {
    236     TURBO_MODE_NONE = 0x0,
    237     TURBO_MODE_CLIENT_REQUESTED = 0x1,
    238     TURBO_MODE_HIGH_FPS = 0x2,
    239     TURBO_MODE_MAX = 0xFF
    240 };
    241 
    242 #ifdef USE_ION
    243 struct vdec_ion {
    244     int ion_device_fd;
    245     struct ion_fd_data fd_ion_data;
    246     struct ion_allocation_data ion_alloc_data;
    247 };
    248 #endif
    249 
    250 struct vdec_ion_map_info {
    251     bool free_buffer;
    252     unsigned char *base_address;
    253     int map_size;
    254     int offset;
    255 };
    256 
    257 #ifdef _MSM8974_
    258 struct extradata_buffer_info {
    259     unsigned long buffer_size;
    260     char* uaddr;
    261     int count;
    262     int size;
    263 #ifdef USE_ION
    264     struct vdec_ion ion;
    265 #endif
    266 };
    267 #endif
    268 
    269 struct video_driver_context {
    270     int video_driver_fd;
    271     enum vdec_codec decoder_format;
    272     enum vdec_output_fromat output_format;
    273     enum vdec_interlaced_format interlace;
    274     enum vdec_output_order picture_order;
    275     struct vdec_framesize frame_size;
    276     struct vdec_picsize video_resolution;
    277     struct vdec_allocatorproperty ip_buf;
    278     struct vdec_allocatorproperty op_buf;
    279     struct vdec_bufferpayload *ptr_inputbuffer;
    280     struct vdec_bufferpayload *ptr_outputbuffer;
    281     struct vdec_output_frameinfo *ptr_respbuffer;
    282 #ifdef USE_ION
    283     struct vdec_ion *ip_buf_ion_info;
    284     struct vdec_ion *op_buf_ion_info;
    285     struct vdec_ion h264_mv;
    286     struct vdec_ion meta_buffer;
    287     struct vdec_ion meta_buffer_iommu;
    288 #endif
    289     struct vdec_ion_map_info *op_buf_map_info;
    290     struct vdec_framerate frame_rate;
    291     unsigned extradata;
    292     bool timestamp_adjust;
    293     char kind[128];
    294     bool idr_only_decoding;
    295     unsigned disable_dmx;
    296 #ifdef _MSM8974_
    297     struct extradata_buffer_info extradata_info;
    298     int num_planes;
    299 #endif
    300 };
    301 
    302 struct video_decoder_capability {
    303     unsigned int min_width;
    304     unsigned int max_width;
    305     unsigned int min_height;
    306     unsigned int max_height;
    307 };
    308 
    309 struct debug_cap {
    310     bool in_buffer_log;
    311     bool out_buffer_log;
    312     bool out_meta_buffer_log;
    313     char infile_name[PROPERTY_VALUE_MAX + 36];
    314     char outfile_name[PROPERTY_VALUE_MAX + 36];
    315     char out_ymetafile_name[PROPERTY_VALUE_MAX + 36];
    316     char out_uvmetafile_name[PROPERTY_VALUE_MAX + 36];
    317     char log_loc[PROPERTY_VALUE_MAX];
    318     FILE *infile;
    319     FILE *outfile;
    320     FILE *out_ymeta_file;
    321     FILE *out_uvmeta_file;
    322 };
    323 
    324 struct dynamic_buf_list {
    325     long fd;
    326     long dup_fd;
    327     OMX_U32 offset;
    328     OMX_U32 ref_count;
    329     void *buffaddr;
    330     long mapped_size;
    331 };
    332 
    333 struct extradata_info {
    334     OMX_BOOL output_crop_updated;
    335     OMX_CONFIG_RECTTYPE output_crop_rect;
    336     OMX_U32 output_width;
    337     OMX_U32 output_height;
    338 };
    339 
    340 // OMX video decoder class
    341 class omx_vdec: public qc_omx_component
    342 {
    343 
    344     public:
    345         omx_vdec();  // constructor
    346         virtual ~omx_vdec();  // destructor
    347 
    348         static int async_message_process (void *context, void* message);
    349         static void process_event_cb(void *ctxt,unsigned char id);
    350 
    351         OMX_ERRORTYPE allocate_buffer(
    352                 OMX_HANDLETYPE hComp,
    353                 OMX_BUFFERHEADERTYPE **bufferHdr,
    354                 OMX_U32 port,
    355                 OMX_PTR appData,
    356                 OMX_U32 bytes
    357                 );
    358 
    359 
    360         OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp);
    361 
    362         OMX_ERRORTYPE component_init(OMX_STRING role);
    363 
    364         OMX_ERRORTYPE component_role_enum(
    365                 OMX_HANDLETYPE hComp,
    366                 OMX_U8 *role,
    367                 OMX_U32 index
    368                 );
    369 
    370         OMX_ERRORTYPE component_tunnel_request(
    371                 OMX_HANDLETYPE hComp,
    372                 OMX_U32 port,
    373                 OMX_HANDLETYPE  peerComponent,
    374                 OMX_U32 peerPort,
    375                 OMX_TUNNELSETUPTYPE *tunnelSetup
    376                 );
    377 
    378         OMX_ERRORTYPE empty_this_buffer(
    379                 OMX_HANDLETYPE hComp,
    380                 OMX_BUFFERHEADERTYPE *buffer
    381                 );
    382 
    383 
    384 
    385         OMX_ERRORTYPE fill_this_buffer(
    386                 OMX_HANDLETYPE hComp,
    387                 OMX_BUFFERHEADERTYPE *buffer
    388                 );
    389 
    390 
    391         OMX_ERRORTYPE free_buffer(
    392                 OMX_HANDLETYPE hComp,
    393                 OMX_U32 port,
    394                 OMX_BUFFERHEADERTYPE *buffer
    395                 );
    396 
    397         OMX_ERRORTYPE get_component_version(
    398                 OMX_HANDLETYPE hComp,
    399                 OMX_STRING componentName,
    400                 OMX_VERSIONTYPE *componentVersion,
    401                 OMX_VERSIONTYPE *specVersion,
    402                 OMX_UUIDTYPE *componentUUID
    403                 );
    404 
    405         OMX_ERRORTYPE get_config(
    406                 OMX_HANDLETYPE hComp,
    407                 OMX_INDEXTYPE configIndex,
    408                 OMX_PTR configData
    409                 );
    410 
    411         OMX_ERRORTYPE get_extension_index(
    412                 OMX_HANDLETYPE hComp,
    413                 OMX_STRING paramName,
    414                 OMX_INDEXTYPE *indexType
    415                 );
    416 
    417         OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp,
    418                 OMX_INDEXTYPE  paramIndex,
    419                 OMX_PTR        paramData);
    420 
    421         OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp,
    422                 OMX_STATETYPE *state);
    423 
    424 
    425 
    426         OMX_ERRORTYPE send_command(OMX_HANDLETYPE  hComp,
    427                 OMX_COMMANDTYPE cmd,
    428                 OMX_U32         param1,
    429                 OMX_PTR         cmdData);
    430 
    431 
    432         OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE   hComp,
    433                 OMX_CALLBACKTYPE *callbacks,
    434                 OMX_PTR          appData);
    435 
    436         OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp,
    437                 OMX_INDEXTYPE  configIndex,
    438                 OMX_PTR        configData);
    439 
    440         OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp,
    441                 OMX_INDEXTYPE  paramIndex,
    442                 OMX_PTR        paramData);
    443 
    444         OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE      hComp,
    445                 OMX_BUFFERHEADERTYPE **bufferHdr,
    446                 OMX_U32              port,
    447                 OMX_PTR              appData,
    448                 OMX_U32              bytes,
    449                 OMX_U8               *buffer);
    450 
    451         OMX_ERRORTYPE  use_input_heap_buffers(
    452                 OMX_HANDLETYPE            hComp,
    453                 OMX_BUFFERHEADERTYPE** bufferHdr,
    454                 OMX_U32                   port,
    455                 OMX_PTR                   appData,
    456                 OMX_U32                   bytes,
    457                 OMX_U8*                   buffer);
    458 
    459         OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE     hComp,
    460                 OMX_BUFFERHEADERTYPE **bufferHdr,
    461                 OMX_U32              port,
    462                 OMX_PTR              appData,
    463                 void *               eglImage);
    464         void complete_pending_buffer_done_cbs();
    465         struct video_driver_context drv_ctx;
    466         int m_poll_efd;
    467 #ifdef _MSM8974_
    468         OMX_ERRORTYPE allocate_extradata();
    469         void free_extradata();
    470         int update_resolution(int width, int height, int stride, int scan_lines);
    471         OMX_ERRORTYPE is_video_session_supported();
    472 #endif
    473         int  m_pipe_in;
    474         int  m_pipe_out;
    475         pthread_t msg_thread_id;
    476         pthread_t async_thread_id;
    477         bool is_component_secure();
    478         void buf_ref_add(int nPortIndex);
    479         void buf_ref_remove();
    480         OMX_BUFFERHEADERTYPE* get_omx_output_buffer_header(int index);
    481         OMX_ERRORTYPE set_dpb(bool is_split_mode, int dpb_color_format);
    482         OMX_ERRORTYPE decide_dpb_buffer_mode(bool split_opb_dpb_with_same_color_fmt);
    483         void request_perf_level(enum vidc_perf_level perf_level);
    484         int dpb_bit_depth;
    485         bool async_thread_force_stop;
    486         volatile bool message_thread_stop;
    487         struct extradata_info m_extradata_info;
    488         int m_progressive;
    489 
    490         enum dither_type {
    491             DITHER_DISABLE = 0,
    492             DITHER_COLORSPACE_EXCEPTBT2020,
    493             DITHER_ALL_COLORSPACE
    494         };
    495         enum dither_type m_dither_config;
    496 
    497         enum color_space_type {
    498             BT2020 = 0,
    499             EXCEPT_BT2020,
    500             UNKNOWN
    501         };
    502         enum color_space_type m_color_space;
    503 
    504     private:
    505         // Bit Positions
    506         enum flags_bit_positions {
    507             // Defer transition to IDLE
    508             OMX_COMPONENT_IDLE_PENDING            =0x1,
    509             // Defer transition to LOADING
    510             OMX_COMPONENT_LOADING_PENDING         =0x2,
    511             // First  Buffer Pending
    512             OMX_COMPONENT_FIRST_BUFFER_PENDING    =0x3,
    513             // Second Buffer Pending
    514             OMX_COMPONENT_SECOND_BUFFER_PENDING   =0x4,
    515             // Defer transition to Enable
    516             OMX_COMPONENT_INPUT_ENABLE_PENDING    =0x5,
    517             // Defer transition to Enable
    518             OMX_COMPONENT_OUTPUT_ENABLE_PENDING   =0x6,
    519             // Defer transition to Disable
    520             OMX_COMPONENT_INPUT_DISABLE_PENDING   =0x7,
    521             // Defer transition to Disable
    522             OMX_COMPONENT_OUTPUT_DISABLE_PENDING  =0x8,
    523             //defer flush notification
    524             OMX_COMPONENT_OUTPUT_FLUSH_PENDING    =0x9,
    525             OMX_COMPONENT_INPUT_FLUSH_PENDING    =0xA,
    526             OMX_COMPONENT_PAUSE_PENDING          =0xB,
    527             OMX_COMPONENT_EXECUTE_PENDING        =0xC,
    528             OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD,
    529             OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE,
    530             OMX_COMPONENT_FLUSH_DEFERRED = 0xF
    531         };
    532 
    533         // Deferred callback identifiers
    534         enum {
    535             //Event Callbacks from the vdec component thread context
    536             OMX_COMPONENT_GENERATE_EVENT       = 0x1,
    537             //Buffer Done callbacks from the vdec component thread context
    538             OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2,
    539             //Frame Done callbacks from the vdec component thread context
    540             OMX_COMPONENT_GENERATE_FRAME_DONE  = 0x3,
    541             //Buffer Done callbacks from the vdec component thread context
    542             OMX_COMPONENT_GENERATE_FTB         = 0x4,
    543             //Frame Done callbacks from the vdec component thread context
    544             OMX_COMPONENT_GENERATE_ETB         = 0x5,
    545             //Command
    546             OMX_COMPONENT_GENERATE_COMMAND     = 0x6,
    547             //Push-Pending Buffers
    548             OMX_COMPONENT_PUSH_PENDING_BUFS    = 0x7,
    549             // Empty Buffer Done callbacks
    550             OMX_COMPONENT_GENERATE_EBD         = 0x8,
    551             //Flush Event Callbacks from the vdec component thread context
    552             OMX_COMPONENT_GENERATE_EVENT_FLUSH       = 0x9,
    553             OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A,
    554             OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B,
    555             OMX_COMPONENT_GENERATE_FBD = 0xc,
    556             OMX_COMPONENT_GENERATE_START_DONE = 0xD,
    557             OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE,
    558             OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF,
    559             OMX_COMPONENT_GENERATE_STOP_DONE = 0x10,
    560             OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11,
    561             OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12,
    562             OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13,
    563             OMX_COMPONENT_GENERATE_EOS_DONE = 0x14,
    564             OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15,
    565             OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16,
    566             OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x17,
    567             OMX_COMPONENT_GENERATE_HARDWARE_OVERLOAD = 0x18,
    568             OMX_COMPONENT_CLOSE_MSG = 0x19
    569         };
    570 
    571         enum vc1_profile_type {
    572             VC1_SP_MP_RCV = 1,
    573             VC1_AP = 2
    574         };
    575 
    576 #ifdef _MSM8974_
    577         enum v4l2_ports {
    578             CAPTURE_PORT,
    579             OUTPUT_PORT,
    580             MAX_PORT
    581         };
    582 #endif
    583 
    584         struct omx_event {
    585             unsigned long param1;
    586             unsigned long param2;
    587             unsigned long id;
    588         };
    589 
    590         struct omx_cmd_queue {
    591             omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE];
    592             unsigned long m_read;
    593             unsigned long m_write;
    594             unsigned long m_size;
    595 
    596             omx_cmd_queue();
    597             ~omx_cmd_queue();
    598             bool insert_entry(unsigned long p1, unsigned long p2, unsigned long id);
    599             bool pop_entry(unsigned long *p1,unsigned long *p2, unsigned long *id);
    600             // get msgtype of the first ele from the queue
    601             unsigned get_q_msg_type();
    602 
    603         };
    604         struct v4l2_capability cap;
    605 #ifdef _ANDROID_
    606         struct ts_entry {
    607             OMX_TICKS timestamp;
    608             bool valid;
    609         };
    610 
    611         struct ts_arr_list {
    612             ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS];
    613 
    614             ts_arr_list();
    615             ~ts_arr_list();
    616 
    617             bool insert_ts(OMX_TICKS ts);
    618             bool pop_min_ts(OMX_TICKS &ts);
    619             bool reset_ts_list();
    620         };
    621 #endif
    622 
    623         struct desc_buffer_hdr {
    624             OMX_U8 *buf_addr;
    625             OMX_U32 desc_data_size;
    626         };
    627         bool allocate_done(void);
    628         bool allocate_input_done(void);
    629         bool allocate_output_done(void);
    630         bool allocate_output_extradata_done(void);
    631 
    632         OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
    633         OMX_ERRORTYPE free_input_buffer(unsigned int bufferindex,
    634                 OMX_BUFFERHEADERTYPE *pmem_bufferHdr);
    635         OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
    636         void free_output_buffer_header();
    637         void free_input_buffer_header();
    638         void free_output_extradata_buffer_header();
    639 
    640         OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE       hComp,
    641                 OMX_BUFFERHEADERTYPE **bufferHdr,
    642                 OMX_U32              port,
    643                 OMX_PTR              appData,
    644                 OMX_U32              bytes);
    645 
    646 
    647         OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE       hComp,
    648                 OMX_BUFFERHEADERTYPE **bufferHdr,
    649                 OMX_U32              port,
    650                 OMX_PTR              appData,
    651                 OMX_U32              bytes);
    652 
    653         OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE       hComp,
    654                 OMX_BUFFERHEADERTYPE **bufferHdr,
    655                 OMX_U32 port,OMX_PTR appData,
    656                 OMX_U32              bytes);
    657         OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp,
    658                 OMX_BUFFERHEADERTYPE   **bufferHdr,
    659                 OMX_U32                port,
    660                 OMX_PTR                appData,
    661                 OMX_U32                bytes,
    662                 OMX_U8                 *buffer);
    663         OMX_ERRORTYPE use_client_output_extradata_buffer(OMX_HANDLETYPE hComp,
    664                 OMX_BUFFERHEADERTYPE   **bufferHdr,
    665                 OMX_U32                port,
    666                 OMX_PTR                appData,
    667                 OMX_U32                bytes,
    668                 OMX_U8                 *buffer);
    669         OMX_ERRORTYPE get_supported_profile_level(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType);
    670 
    671         OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index);
    672         OMX_ERRORTYPE allocate_output_headers();
    673         OMX_ERRORTYPE allocate_client_output_extradata_headers();
    674         bool execute_omx_flush(OMX_U32);
    675         bool execute_output_flush();
    676         bool execute_input_flush();
    677         void notify_flush_done(void *ctxt);
    678         OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp,
    679                 OMX_BUFFERHEADERTYPE * buffer);
    680 
    681         OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp,
    682                 OMX_BUFFERHEADERTYPE * buffer);
    683         OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE       hComp,
    684                 OMX_BUFFERHEADERTYPE *buffer);
    685 
    686         OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp,
    687                 OMX_BUFFERHEADERTYPE *buffer
    688                 );
    689 
    690         OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp);
    691         OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp);
    692         OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp);
    693         OMX_ERRORTYPE push_input_hevc (OMX_HANDLETYPE hComp);
    694         OMX_ERRORTYPE push_input_vc1 (OMX_HANDLETYPE hComp);
    695 
    696         OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE       hComp,
    697                 OMX_BUFFERHEADERTYPE *buffer);
    698         bool release_done();
    699 
    700         bool release_output_done();
    701         bool release_input_done();
    702         bool release_output_extradata_done();
    703         OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop);
    704         OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop);
    705         OMX_ERRORTYPE start_port_reconfig();
    706         OMX_ERRORTYPE update_picture_resolution();
    707         int stream_off(OMX_U32 port);
    708         void adjust_timestamp(OMX_S64 &act_timestamp);
    709         void set_frame_rate(OMX_S64 act_timestamp);
    710         void handle_extradata_secure(OMX_BUFFERHEADERTYPE *p_buf_hdr);
    711         void handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr);
    712         void convert_color_space_info(OMX_U32 primaries, OMX_U32 range,
    713             OMX_U32 transfer, OMX_U32 matrix, ColorSpace_t *color_space,
    714             ColorAspects *aspects);
    715         bool handle_color_space_info(void *data,
    716                                      ColorSpace_t *color_space,
    717                                      ColorMetaData* color_mdata,
    718                                      bool& set_color_aspects_only);
    719         void set_colorspace_in_handle(ColorSpace_t color, unsigned int buf_index);
    720         void print_debug_color_aspects(ColorAspects *aspects, const char *prefix);
    721         void print_debug_hdr_color_info(HDRStaticInfo *hdr_info, const char *prefix);
    722         void print_debug_hdr_color_info_mdata(ColorMetaData* color_mdata);
    723         bool handle_content_light_level_info(void* data, ContentLightLevel* light_level_mdata);
    724         bool handle_mastering_display_color_info(void* data, MasteringDisplay* mastering_display_mdata);
    725         void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    726         void set_colormetadata_in_handle(ColorMetaData *color_mdata, unsigned int buf_index);
    727         void prepare_color_aspects_metadata(OMX_U32 primaries, OMX_U32 range,
    728                                             OMX_U32 transfer, OMX_U32 matrix,
    729                                             ColorMetaData *color_mdata);
    730 #ifdef _MSM8974_
    731         void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    732                 OMX_U32 interlaced_format_type);
    733         OMX_ERRORTYPE enable_extradata(OMX_U64 requested_extradata, bool is_internal,
    734                 bool enable = true);
    735         void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    736                 OMX_U32 num_conceal_mb,
    737                 OMX_U32 recovery_sei_flag,
    738                 OMX_U32 picture_type,
    739                 OMX_U32 frame_rate,
    740                 OMX_TICKS time_stamp,
    741                 struct msm_vidc_panscan_window_payload *panscan_payload,
    742                 struct vdec_aspectratioinfo *aspect_ratio_info);
    743 #else
    744         void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    745                 OMX_U32 interlaced_format_type, OMX_U32 buf_index);
    746         OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true);
    747 #endif
    748         void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    749                 OMX_U32 num_conceal_mb,
    750                 OMX_U32 recovery_sei_flag,
    751                 OMX_U32 picture_type,
    752                 OMX_S64 timestamp,
    753                 OMX_U32 frame_rate,
    754                 struct vdec_aspectratioinfo *aspect_ratio_info);
    755         void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info,
    756                 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info);
    757         void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    758         OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn);
    759         void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    760         void append_frame_dimension_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    761         void append_extn_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_extn);
    762         void append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_user);
    763         void append_concealmb_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    764                 OMX_OTHER_EXTRADATATYPE *p_concealmb, OMX_U8 *conceal_mb_data);
    765         void append_framepack_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    766                 struct msm_vidc_s3d_frame_packing_payload *s3d_frame_packing_payload);
    767         void append_qp_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    768                 struct msm_vidc_frame_qp_payload *qp_payload);
    769         void append_bitsinfo_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    770                 struct msm_vidc_frame_bits_info_payload *bits_payload);
    771         void append_vqzip_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    772                 struct msm_vidc_vqzip_sei_payload *vqzip_payload);
    773         void insert_demux_addr_offset(OMX_U32 address_offset);
    774         void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr);
    775         OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr);
    776         OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    777 
    778         bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
    779                 OMX_U32 alignment);
    780 #ifdef USE_ION
    781         int alloc_map_ion_memory(OMX_U32 buffer_size,
    782                 OMX_U32 alignment, struct ion_allocation_data *alloc_data,
    783                 struct ion_fd_data *fd_data,int flag);
    784         void free_ion_memory(struct vdec_ion *buf_ion_info);
    785 #endif
    786 
    787 
    788         OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE  hComp,
    789                 OMX_COMMANDTYPE cmd,
    790                 OMX_U32         param1,
    791                 OMX_PTR         cmdData);
    792         bool post_event( unsigned long p1,
    793                 unsigned long p2,
    794                 unsigned long id
    795                    );
    796         inline int clip2(int x) {
    797             x = x -1;
    798             x = x | x >> 1;
    799             x = x | x >> 2;
    800             x = x | x >> 4;
    801             x = x | x >> 16;
    802             x = x + 1;
    803             return x;
    804         }
    805 
    806 #ifdef MAX_RES_1080P
    807         OMX_ERRORTYPE vdec_alloc_h264_mv();
    808         void vdec_dealloc_h264_mv();
    809         OMX_ERRORTYPE vdec_alloc_meta_buffers();
    810         void vdec_dealloc_meta_buffers();
    811 #endif
    812 
    813         inline void omx_report_error () {
    814             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
    815                 DEBUG_PRINT_ERROR("ERROR: Sending OMX_ErrorHardware to Client");
    816                 m_error_propogated = true;
    817                 m_cb.EventHandler(&m_cmp,m_app_data,
    818                         OMX_EventError,OMX_ErrorHardware,0,NULL);
    819             }
    820         }
    821 
    822         inline void omx_report_unsupported_setting () {
    823             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
    824                 DEBUG_PRINT_ERROR(
    825                         "ERROR: Sending OMX_ErrorUnsupportedSetting to Client");
    826                 m_error_propogated = true;
    827                 m_cb.EventHandler(&m_cmp, m_app_data,
    828                         OMX_EventError, OMX_ErrorUnsupportedSetting, 0, NULL);
    829             }
    830         }
    831         inline void omx_report_hw_overload () {
    832             if (m_cb.EventHandler && !m_error_propogated && m_state != OMX_StateLoaded) {
    833                 DEBUG_PRINT_ERROR(
    834                         "ERROR: Sending OMX_ErrorInsufficientResources to Client");
    835                 m_error_propogated = true;
    836                 m_cb.EventHandler(&m_cmp, m_app_data,
    837                         OMX_EventError, OMX_ErrorInsufficientResources, 0, NULL);
    838             }
    839         }
    840 
    841 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
    842         OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data);
    843 #endif
    844 #if defined (_ANDROID_ICS_)
    845         struct nativebuffer {
    846             native_handle_t *nativehandle;
    847             private_handle_t *privatehandle;
    848             int inuse;
    849         };
    850         nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS];
    851 #endif
    852 
    853         //*************************************************************
    854         //*******************MEMBER VARIABLES *************************
    855         //*************************************************************
    856         pthread_mutex_t       m_lock;
    857         pthread_mutex_t       c_lock;
    858         pthread_mutex_t       buf_lock;
    859         //sem to handle the minimum procesing of commands
    860         sem_t                 m_cmd_lock;
    861         sem_t                 m_safe_flush;
    862         bool              m_error_propogated;
    863         // compression format
    864         OMX_VIDEO_CODINGTYPE eCompressionFormat;
    865         // OMX State
    866         OMX_STATETYPE m_state;
    867         // Application data
    868         OMX_PTR m_app_data;
    869         // Application callbacks
    870         OMX_CALLBACKTYPE m_cb;
    871         OMX_PRIORITYMGMTTYPE m_priority_mgm ;
    872         OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier;
    873         // fill this buffer queue
    874         omx_cmd_queue         m_ftb_q;
    875         // Command Q for rest of the events
    876         omx_cmd_queue         m_cmd_q;
    877         omx_cmd_queue         m_etb_q;
    878         // Input memory pointer
    879         OMX_BUFFERHEADERTYPE  *m_inp_mem_ptr;
    880         // Output memory pointer
    881         OMX_BUFFERHEADERTYPE  *m_out_mem_ptr;
    882         // Client extradata memory pointer
    883         OMX_BUFFERHEADERTYPE  *m_client_output_extradata_mem_ptr;
    884         // number of input bitstream error frame count
    885         unsigned int m_inp_err_count;
    886 #ifdef _ANDROID_
    887         // Timestamp list
    888         ts_arr_list           m_timestamp_list;
    889 #endif
    890 
    891         bool input_flush_progress;
    892         bool output_flush_progress;
    893         bool input_use_buffer;
    894         bool output_use_buffer;
    895         bool ouput_egl_buffers;
    896         OMX_BOOL m_use_output_pmem;
    897         OMX_BOOL m_out_mem_region_smi;
    898         OMX_BOOL m_out_pvt_entry_pmem;
    899 
    900         int pending_input_buffers;
    901         int pending_output_buffers;
    902         // bitmask array size for output side
    903         uint64_t m_out_bm_count;
    904         // bitmask array size for input side
    905         uint64_t m_inp_bm_count;
    906         // bitmask array size for extradata
    907         uint64_t m_out_extradata_bm_count;
    908         //Input port Populated
    909         OMX_BOOL m_inp_bPopulated;
    910         //Output port Populated
    911         OMX_BOOL m_out_bPopulated;
    912         // encapsulate the waiting states.
    913         uint64_t m_flags;
    914 
    915         // store I/P PORT state
    916         OMX_BOOL m_inp_bEnabled;
    917         // store O/P PORT state
    918         OMX_BOOL m_out_bEnabled;
    919         OMX_U32 m_in_alloc_cnt;
    920         OMX_U8                m_cRole[OMX_MAX_STRINGNAME_SIZE];
    921         // Platform specific details
    922         OMX_QCOM_PLATFORM_PRIVATE_LIST      *m_platform_list;
    923         OMX_QCOM_PLATFORM_PRIVATE_ENTRY     *m_platform_entry;
    924         OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info;
    925         // SPS+PPS sent as part of set_config
    926         OMX_VENDOR_EXTRADATATYPE            m_vendor_config;
    927 
    928         /*Variables for arbitrary Byte parsing support*/
    929         frame_parse m_frame_parser;
    930         h264_stream_parser *h264_parser;
    931         MP4_Utils mp4_headerparser;
    932         HEVC_Utils m_hevc_utils;
    933 
    934         omx_cmd_queue m_input_pending_q;
    935         omx_cmd_queue m_input_free_q;
    936         bool arbitrary_bytes;
    937         OMX_BUFFERHEADERTYPE  h264_scratch;
    938         OMX_BUFFERHEADERTYPE  *psource_frame;
    939         OMX_BUFFERHEADERTYPE  *pdest_frame;
    940         OMX_BUFFERHEADERTYPE  *m_inp_heap_ptr;
    941         OMX_BUFFERHEADERTYPE  **m_phdr_pmem_ptr;
    942         unsigned int m_heap_inp_bm_count;
    943         codec_type codec_type_parse;
    944         bool first_frame_meta;
    945         unsigned frame_count;
    946         unsigned nal_count;
    947         unsigned nal_length;
    948         bool look_ahead_nal;
    949         int first_frame;
    950         unsigned char *first_buffer;
    951         int first_frame_size;
    952         unsigned char m_hwdevice_name[80];
    953         FILE *m_device_file_ptr;
    954         enum vc1_profile_type m_vc1_profile;
    955         OMX_S64 h264_last_au_ts;
    956         OMX_U32 h264_last_au_flags;
    957         OMX_U32 m_demux_offsets[8192];
    958         OMX_U32 m_demux_entries;
    959         OMX_U32 m_disp_hor_size;
    960         OMX_U32 m_disp_vert_size;
    961         OMX_S64 prev_ts;
    962         OMX_S64 prev_ts_actual;
    963         bool rst_prev_ts;
    964         OMX_U32 frm_int;
    965         OMX_U32 m_fps_received;
    966         float   m_fps_prev;
    967         bool m_drc_enable;
    968 
    969         struct vdec_allocatorproperty op_buf_rcnfg;
    970         bool in_reconfig;
    971         OMX_NATIVE_WINDOWTYPE m_display_id;
    972         OMX_U32 client_extradata;
    973 #ifdef _ANDROID_
    974         bool m_debug_timestamp;
    975         bool perf_flag;
    976         OMX_U32 proc_frms, latency;
    977         perf_metrics fps_metrics;
    978         perf_metrics dec_time;
    979         bool m_reject_avc_1080p_mp;
    980         bool m_enable_android_native_buffers;
    981         bool m_use_android_native_buffers;
    982         bool m_debug_extradata;
    983         bool m_debug_concealedmb;
    984         bool m_disable_dynamic_buf_mode;
    985         OMX_U32 m_conceal_color;
    986 #endif
    987 
    988 
    989         struct h264_mv_buffer {
    990             unsigned char* buffer;
    991             int size;
    992             int count;
    993             int pmem_fd;
    994             int offset;
    995         };
    996         h264_mv_buffer h264_mv_buff;
    997 
    998         struct meta_buffer {
    999             unsigned char* buffer;
   1000             int size;
   1001             int count;
   1002             int pmem_fd;
   1003             int pmem_fd_iommu;
   1004             int offset;
   1005         };
   1006         meta_buffer meta_buff;
   1007         extra_data_handler extra_data_handle;
   1008         OMX_PARAM_PORTDEFINITIONTYPE m_port_def;
   1009         OMX_QCOM_FRAME_PACK_ARRANGEMENT m_frame_pack_arrangement;
   1010         omx_time_stamp_reorder time_stamp_dts;
   1011         desc_buffer_hdr *m_desc_buffer_ptr;
   1012         bool secure_mode;
   1013         bool allocate_native_handle;
   1014         bool external_meta_buffer;
   1015         bool external_meta_buffer_iommu;
   1016         OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata;
   1017         OMX_OTHER_EXTRADATATYPE *m_other_extradata;
   1018         bool codec_config_flag;
   1019 #ifdef _MSM8974_
   1020         int capture_capability;
   1021         int output_capability;
   1022         bool streaming[MAX_PORT];
   1023         OMX_FRAMESIZETYPE framesize;
   1024         OMX_CONFIG_RECTTYPE rectangle;
   1025         OMX_U32 prev_n_filled_len;
   1026         bool is_down_scalar_enabled;
   1027         bool m_force_down_scalar;
   1028 #endif
   1029         struct custom_buffersize {
   1030             OMX_U32 input_buffersize;
   1031         } m_custom_buffersize;
   1032         bool m_power_hinted;
   1033         bool is_q6_platform;
   1034         OMX_ERRORTYPE power_module_register();
   1035         OMX_ERRORTYPE power_module_deregister();
   1036         bool msg_thread_created;
   1037         bool async_thread_created;
   1038 
   1039         OMX_VIDEO_PARAM_PROFILELEVELTYPE m_profile_lvl;
   1040         OMX_U32 m_profile;
   1041 
   1042         //variables to handle dynamic buffer mode
   1043         bool dynamic_buf_mode;
   1044         struct dynamic_buf_list *out_dynamic_list;
   1045         OMX_U32 m_reconfig_width;
   1046         OMX_U32 m_reconfig_height;
   1047         bool m_smoothstreaming_mode;
   1048         bool m_decode_order_mode;
   1049 
   1050         bool m_input_pass_buffer_fd;
   1051         DescribeColorAspectsParams m_client_color_space;
   1052         DescribeColorAspectsParams m_internal_color_space;
   1053 
   1054         // HDRStaticInfo defined in HardwareAPI.h
   1055         DescribeHDRStaticInfoParams m_client_hdr_info;
   1056         DescribeHDRStaticInfoParams m_internal_hdr_info;
   1057         bool m_change_client_hdr_info;
   1058         pthread_mutex_t m_hdr_info_client_lock;
   1059         ColorMetaData m_color_mdata;
   1060 
   1061         OMX_U32 operating_frame_rate;
   1062         uint8_t m_need_turbo;
   1063 
   1064         OMX_U32 m_smoothstreaming_width;
   1065         OMX_U32 m_smoothstreaming_height;
   1066         OMX_ERRORTYPE enable_smoothstreaming();
   1067         OMX_ERRORTYPE enable_adaptive_playback(unsigned long width, unsigned long height);
   1068         bool is_thulium_v1;
   1069         bool m_disable_ubwc_mode;
   1070         bool m_disable_split_mode;
   1071         bool m_enable_downscalar;
   1072         OMX_U32 m_downscalar_width;
   1073         OMX_U32 m_downscalar_height;
   1074         int decide_downscalar();
   1075         int enable_downscalar();
   1076         int disable_downscalar();
   1077 
   1078         unsigned int m_fill_output_msg;
   1079         bool client_set_fps;
   1080         unsigned int stereo_output_mode;
   1081         class allocate_color_convert_buf
   1082         {
   1083             public:
   1084                 allocate_color_convert_buf();
   1085                 ~allocate_color_convert_buf();
   1086                 void set_vdec_client(void *);
   1087                 void update_client();
   1088                 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format);
   1089                 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format);
   1090                 bool update_buffer_req();
   1091                 bool get_buffer_req(unsigned int &buffer_size);
   1092                 OMX_ERRORTYPE set_buffer_req(OMX_U32 buffer_size, OMX_U32 actual_count);
   1093                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr();
   1094                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
   1095                 OMX_BUFFERHEADERTYPE* get_dr_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
   1096                 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header);
   1097                 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header);
   1098                 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
   1099                         OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,
   1100                         OMX_U32 bytes);
   1101                 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
   1102                 bool is_color_conversion_enabled() {return enabled;}
   1103             private:
   1104 #define MAX_COUNT MAX_NUM_INPUT_OUTPUT_BUFFERS
   1105                 omx_vdec *omx;
   1106                 bool enabled;
   1107                 OMX_COLOR_FORMATTYPE ColorFormat;
   1108                 void init_members();
   1109                 bool color_convert_mode;
   1110                 ColorConvertFormat dest_format;
   1111                 class omx_c2d_conv c2d;
   1112                 unsigned int allocated_count;
   1113                 unsigned int buffer_size_req;
   1114                 unsigned int buffer_alignment_req;
   1115                 OMX_U32 m_c2d_width;
   1116                 OMX_U32 m_c2d_height;
   1117                 OMX_QCOM_PLATFORM_PRIVATE_LIST      m_platform_list_client[MAX_COUNT];
   1118                 OMX_QCOM_PLATFORM_PRIVATE_ENTRY     m_platform_entry_client[MAX_COUNT];
   1119                 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT];
   1120                 OMX_BUFFERHEADERTYPE  m_out_mem_ptr_client[MAX_COUNT];
   1121 #ifdef USE_ION
   1122                 struct vdec_ion op_buf_ion_info[MAX_COUNT];
   1123 #endif
   1124                 unsigned char *pmem_baseaddress[MAX_COUNT];
   1125                 int pmem_fd[MAX_COUNT];
   1126                 OMX_ERRORTYPE cache_ops(unsigned int index, unsigned int cmd);
   1127                 inline OMX_ERRORTYPE cache_clean_buffer(unsigned int index) {
   1128                     return cache_ops(index, ION_IOC_CLEAN_CACHES);
   1129                 }
   1130                 OMX_ERRORTYPE cache_clean_invalidate_buffer(unsigned int index) {
   1131                     return cache_ops(index, ION_IOC_CLEAN_INV_CACHES);
   1132                 }
   1133         };
   1134 #if  defined (_MSM8960_) || defined (_MSM8974_)
   1135         allocate_color_convert_buf client_buffers;
   1136 #endif
   1137         struct video_decoder_capability m_decoder_capability;
   1138         struct debug_cap m_debug;
   1139         int log_input_buffers(const char *, int);
   1140         int log_output_buffers(OMX_BUFFERHEADERTYPE *);
   1141 #ifdef _MSM8974_
   1142         void send_codec_config();
   1143 #endif
   1144         OMX_TICKS m_last_rendered_TS;
   1145         volatile int32_t m_queued_codec_config_count;
   1146         OMX_U32 current_perf_level;
   1147         bool secure_scaling_to_non_secure_opb;
   1148 	bool m_force_compressed_for_dpb;
   1149         bool m_is_display_session;
   1150         class perf_lock {
   1151             private:
   1152                 pthread_mutex_t mlock;
   1153 
   1154             public:
   1155                 perf_lock() {
   1156                     pthread_mutex_init(&mlock, NULL);
   1157                 }
   1158 
   1159                 ~perf_lock() {
   1160                     pthread_mutex_destroy(&mlock);
   1161                 }
   1162 
   1163                 void lock() {
   1164                     pthread_mutex_lock(&mlock);
   1165                 }
   1166 
   1167                 void unlock() {
   1168                     pthread_mutex_unlock(&mlock);
   1169                 }
   1170         };
   1171 
   1172         class perf_control {
   1173             // 2 cores will be requested if framerate is beyond 45 fps
   1174             static const int MIN_FRAME_DURATION_FOR_PERF_REQUEST_US = (1e6 / 45);
   1175             typedef int (*perf_lock_acquire_t)(int, int, int*, int);
   1176             typedef int (*perf_lock_release_t)(int);
   1177 
   1178             private:
   1179                 void *m_perf_lib;
   1180                 int m_perf_handle;
   1181                 perf_lock_acquire_t m_perf_lock_acquire;
   1182                 perf_lock_release_t m_perf_lock_release;
   1183                 bool load_lib();
   1184                 struct mpctl_stats {
   1185                   int vid_inst_count;
   1186                   bool vid_acquired;
   1187                   int vid_disp_handle;
   1188                 };
   1189                 static struct mpctl_stats mpctl_obj;
   1190                 static perf_lock m_perf_lock;
   1191 
   1192             public:
   1193                 perf_control();
   1194                 ~perf_control();
   1195                 void request_cores(int frame_duration_us);
   1196                 void send_hint_to_mpctl(bool state);
   1197         };
   1198         perf_control m_perf_control;
   1199 
   1200         static OMX_COLOR_FORMATTYPE getPreferredColorFormatNonSurfaceMode(OMX_U32 index) {
   1201             //On Android, we default to standard YUV formats for non-surface use-cases
   1202             //where apps prefer known color formats.
   1203             OMX_COLOR_FORMATTYPE formatsNonSurfaceMode[] = {
   1204                 [0] = OMX_COLOR_FormatYUV420SemiPlanar,
   1205                 [1] = OMX_COLOR_FormatYUV420Planar,
   1206                 [2] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
   1207                 [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
   1208                 [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed,
   1209             };
   1210             return (index < sizeof(formatsNonSurfaceMode) / sizeof(OMX_COLOR_FORMATTYPE)) ?
   1211                 formatsNonSurfaceMode[index] : OMX_COLOR_FormatMax;
   1212         }
   1213 
   1214         OMX_COLOR_FORMATTYPE getPreferredColorFormatDefaultMode(OMX_U32 index) {
   1215             //for surface mode (normal playback), advertise native/accelerated formats first
   1216             OMX_COLOR_FORMATTYPE format = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m;
   1217 
   1218             if (!m_disable_ubwc_mode) {
   1219                 OMX_COLOR_FORMATTYPE formatsDefault[] = {
   1220                     [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mCompressed,
   1221                     [1] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
   1222                     [2] = OMX_COLOR_FormatYUV420SemiPlanar,
   1223                     [3] = OMX_COLOR_FormatYUV420Planar,
   1224                     [4] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
   1225                 };
   1226                 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ?
   1227                     formatsDefault[index] : OMX_COLOR_FormatMax;
   1228             } else {
   1229                 OMX_COLOR_FORMATTYPE formatsDefault[] = {
   1230                     [0] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32m,
   1231                     [1] = OMX_COLOR_FormatYUV420SemiPlanar,
   1232                     [2] = OMX_COLOR_FormatYUV420Planar,
   1233                     [3] = (OMX_COLOR_FORMATTYPE)QOMX_COLOR_FORMATYUV420PackedSemiPlanar32mMultiView,
   1234                 };
   1235                 format = (index < sizeof(formatsDefault) / sizeof(OMX_COLOR_FORMATTYPE)) ?
   1236                     formatsDefault[index] : OMX_COLOR_FormatMax;
   1237             }
   1238             return format;
   1239         }
   1240 
   1241         static OMX_ERRORTYPE describeColorFormat(OMX_PTR params);
   1242         void prefetchNewBuffers();
   1243 
   1244         class client_extradata_info {
   1245             private:
   1246                 OMX_U32 size; // size of extradata of each frame
   1247                 OMX_U32 buffer_count;
   1248                 OMX_BOOL enable;
   1249 
   1250             public:
   1251                 client_extradata_info() {
   1252                     size = VENUS_EXTRADATA_SIZE(4096, 2160);;
   1253                     buffer_count = 0;
   1254                     enable = OMX_FALSE;
   1255                 }
   1256 
   1257                 ~client_extradata_info() {
   1258                 }
   1259 
   1260                 bool set_extradata_info(OMX_U32 size, OMX_U32 buffer_count) {
   1261                     this->size = size;
   1262                     this->buffer_count = buffer_count;
   1263                     return true;
   1264                 }
   1265                 void enable_client_extradata(OMX_BOOL enable) {
   1266                     this->enable = enable;
   1267                 }
   1268                 bool is_client_extradata_enabled() {
   1269                     return enable;
   1270                 }
   1271                 OMX_U32 getSize() const {
   1272                     return size;
   1273                 }
   1274                 OMX_U32 getBufferCount() const {
   1275                     return buffer_count;
   1276                 }
   1277         };
   1278         client_extradata_info m_client_out_extradata_info;
   1279 
   1280         OMX_ERRORTYPE get_vendor_extension_config(
   1281                 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext);
   1282         OMX_ERRORTYPE set_vendor_extension_config(
   1283                 OMX_CONFIG_ANDROID_VENDOR_EXTENSIONTYPE *ext);
   1284 
   1285         void init_vendor_extensions (VendorExtensionStore&);
   1286 
   1287         // list of extensions is not mutable after initialization
   1288         const VendorExtensionStore mVendorExtensionStore;
   1289 };
   1290 
   1291 #ifdef _MSM8974_
   1292 enum instance_state {
   1293     MSM_VIDC_CORE_UNINIT_DONE = 0x0001,
   1294     MSM_VIDC_CORE_INIT,
   1295     MSM_VIDC_CORE_INIT_DONE,
   1296     MSM_VIDC_OPEN,
   1297     MSM_VIDC_OPEN_DONE,
   1298     MSM_VIDC_LOAD_RESOURCES,
   1299     MSM_VIDC_LOAD_RESOURCES_DONE,
   1300     MSM_VIDC_START,
   1301     MSM_VIDC_START_DONE,
   1302     MSM_VIDC_STOP,
   1303     MSM_VIDC_STOP_DONE,
   1304     MSM_VIDC_RELEASE_RESOURCES,
   1305     MSM_VIDC_RELEASE_RESOURCES_DONE,
   1306     MSM_VIDC_CLOSE,
   1307     MSM_VIDC_CLOSE_DONE,
   1308     MSM_VIDC_CORE_UNINIT,
   1309 };
   1310 
   1311 enum vidc_resposes_id {
   1312     MSM_VIDC_DECODER_FLUSH_DONE = 0x11,
   1313     MSM_VIDC_DECODER_EVENT_CHANGE,
   1314 };
   1315 
   1316 #endif // _MSM8974_
   1317 
   1318 #endif // __OMX_VDEC_H__
   1319