Home | History | Annotate | Download | only in inc
      1 /*--------------------------------------------------------------------------
      2 Copyright (c) 2012-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 are
      6 met:
      7     * Redistributions of source code must retain the above copyright
      8       notice, this list of conditions and the following disclaimer.
      9     * Redistributions in binary form must reproduce the above
     10       copyright notice, this list of conditions and the following
     11       disclaimer in the documentation and/or other materials provided
     12       with the distribution.
     13     * Neither the name of The Linux Foundation nor the names of its
     14       contributors may be used to endorse or promote products derived
     15       from this software without specific prior written permission.
     16 
     17 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     18 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     20 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     25 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     26 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     27 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28 --------------------------------------------------------------------------*/
     29 #ifndef __OMX_VENC_DEV__
     30 #define __OMX_VENC_DEV__
     31 
     32 #include "OMX_Types.h"
     33 #include "OMX_Core.h"
     34 #include "OMX_VideoExt.h"
     35 #include "QComOMXMetadata.h"
     36 #include "OMX_QCOMExtns.h"
     37 #include "qc_omx_component.h"
     38 #ifdef _VQZIP_
     39 #include "VQZip.h"
     40 #endif
     41 
     42 #ifdef _PQ_
     43 #include "gpustats.h"
     44 #endif
     45 #include "omx_video_common.h"
     46 #include "omx_video_base.h"
     47 #include "omx_video_encoder.h"
     48 #include <linux/videodev2.h>
     49 #include <media/msm_vidc.h>
     50 #include <poll.h>
     51 #include <list>
     52 
     53 #define TIMEOUT 5*60*1000
     54 #define BIT(num) (1 << (num))
     55 #define MAX_HYB_HIERP_LAYERS 6
     56 #define MAX_AVC_HP_LAYERS (4)
     57 #define MAX_V4L2_BUFS 64 //VB2_MAX_FRAME
     58 
     59 enum hier_type {
     60     HIER_NONE = 0x0,
     61     HIER_P = 0x1,
     62     HIER_B = 0x2,
     63     HIER_P_HYBRID = 0x3,
     64 };
     65 
     66 struct msm_venc_switch {
     67     unsigned char    status;
     68 };
     69 
     70 struct msm_venc_allocatorproperty {
     71     unsigned long     mincount;
     72     unsigned long     actualcount;
     73     unsigned long     datasize;
     74     unsigned long     suffixsize;
     75     unsigned long     alignment;
     76     unsigned long     bufpoolid;
     77 };
     78 
     79 struct msm_venc_basecfg {
     80     unsigned long    input_width;
     81     unsigned long    input_height;
     82     unsigned long    dvs_width;
     83     unsigned long    dvs_height;
     84     unsigned long    codectype;
     85     unsigned long    fps_num;
     86     unsigned long    fps_den;
     87     unsigned long    targetbitrate;
     88     unsigned long    inputformat;
     89 };
     90 
     91 struct msm_venc_profile {
     92     unsigned long    profile;
     93 };
     94 struct msm_venc_profilelevel {
     95     unsigned long    level;
     96 };
     97 
     98 struct msm_venc_sessionqp {
     99     unsigned long    iframeqp;
    100     unsigned long    pframeqp;
    101     unsigned long    bframeqp;
    102 };
    103 
    104 struct msm_venc_initqp {
    105     unsigned long    iframeqp;
    106     unsigned long    pframeqp;
    107     unsigned long    bframeqp;
    108     unsigned long    enableinitqp;
    109 };
    110 
    111 struct msm_venc_qprange {
    112     unsigned long    maxqp;
    113     unsigned long    minqp;
    114 };
    115 
    116 struct msm_venc_ipb_qprange {
    117     unsigned long    max_i_qp;
    118     unsigned long    min_i_qp;
    119     unsigned long    max_p_qp;
    120     unsigned long    min_p_qp;
    121     unsigned long    max_b_qp;
    122     unsigned long    min_b_qp;
    123 };
    124 
    125 struct msm_venc_intraperiod {
    126     unsigned long    num_pframes;
    127     unsigned long    num_bframes;
    128 };
    129 struct msm_venc_seqheader {
    130     unsigned char *hdrbufptr;
    131     unsigned long    bufsize;
    132     unsigned long    hdrlen;
    133 };
    134 
    135 struct msm_venc_capability {
    136     unsigned long    codec_types;
    137     unsigned long    maxframe_width;
    138     unsigned long    maxframe_height;
    139     unsigned long    maxtarget_bitrate;
    140     unsigned long    maxframe_rate;
    141     unsigned long    input_formats;
    142     unsigned char    dvs;
    143 };
    144 
    145 struct msm_venc_entropycfg {
    146     unsigned longentropysel;
    147     unsigned long    cabacmodel;
    148 };
    149 
    150 struct msm_venc_dbcfg {
    151     unsigned long    db_mode;
    152     unsigned long    slicealpha_offset;
    153     unsigned long    slicebeta_offset;
    154 };
    155 
    156 struct msm_venc_intrarefresh {
    157     unsigned long    irmode;
    158     unsigned long    mbcount;
    159 };
    160 
    161 struct msm_venc_multiclicecfg {
    162     unsigned long    mslice_mode;
    163     unsigned long    mslice_size;
    164 };
    165 
    166 struct msm_venc_bufferflush {
    167     unsigned long    flush_mode;
    168 };
    169 
    170 struct msm_venc_ratectrlcfg {
    171     unsigned long    rcmode;
    172 };
    173 
    174 struct    msm_venc_voptimingcfg {
    175     unsigned long    voptime_resolution;
    176 };
    177 struct msm_venc_framerate {
    178     unsigned long    fps_denominator;
    179     unsigned long    fps_numerator;
    180 };
    181 
    182 struct msm_venc_targetbitrate {
    183     unsigned long    target_bitrate;
    184 };
    185 
    186 
    187 struct msm_venc_rotation {
    188     unsigned long    rotation;
    189 };
    190 
    191 struct msm_venc_timeout {
    192     unsigned long    millisec;
    193 };
    194 
    195 struct msm_venc_headerextension {
    196     unsigned long    header_extension;
    197 };
    198 
    199 struct msm_venc_video_capability {
    200     unsigned int min_width;
    201     unsigned int max_width;
    202     unsigned int min_height;
    203     unsigned int max_height;
    204 };
    205 
    206 struct msm_venc_idrperiod {
    207     unsigned long idrperiod;
    208 };
    209 
    210 struct msm_venc_slice_delivery {
    211     unsigned long enable;
    212 };
    213 
    214 struct msm_venc_hierlayers {
    215     unsigned int numlayers;
    216     enum hier_type hier_mode;
    217 };
    218 
    219 struct msm_venc_ltrinfo {
    220     unsigned int enabled;
    221     unsigned int count;
    222 };
    223 
    224 struct msm_venc_perf_level {
    225     unsigned int perflevel;
    226 };
    227 
    228 struct msm_venc_vui_timing_info {
    229     unsigned int enabled;
    230 };
    231 
    232 struct msm_venc_vqzip_sei_info {
    233     unsigned int enabled;
    234 };
    235 
    236 struct msm_venc_peak_bitrate {
    237     unsigned int peakbitrate;
    238 };
    239 
    240 struct msm_venc_vpx_error_resilience {
    241     unsigned int enable;
    242 };
    243 
    244 struct msm_venc_priority {
    245     OMX_U32 priority;
    246 };
    247 
    248 struct msm_venc_hybrid_hp {
    249    unsigned int nSize;
    250    unsigned int nKeyFrameInterval;
    251    unsigned int nTemporalLayerBitrateRatio[OMX_VIDEO_MAX_HP_LAYERS];
    252    unsigned int nMinQuantizer;
    253    unsigned int nMaxQuantizer;
    254    unsigned int nHpLayers;
    255 };
    256 
    257 struct msm_venc_color_space {
    258     OMX_U32 primaries;
    259     OMX_U32 range;
    260     OMX_U32 matrix_coeffs;
    261     OMX_U32 transfer_chars;
    262 };
    263 
    264 struct msm_venc_temporal_layers {
    265     enum hier_type hier_mode;
    266     OMX_U32 nMaxLayers;
    267     OMX_U32 nMaxBLayers;
    268     OMX_U32 nPLayers;
    269     OMX_U32 nBLayers;
    270     OMX_BOOL bIsBitrateRatioValid;
    271     // cumulative ratio: eg [25, 50, 75, 100] means [L0=25%, L1=25%, L2=25%, L3=25%]
    272     OMX_U32 nTemporalLayerBitrateRatio[OMX_VIDEO_ANDROID_MAXTEMPORALLAYERS];
    273     // Layerwise ratio: eg [L0=25%, L1=25%, L2=25%, L3=25%]
    274     OMX_U32 nTemporalLayerBitrateFraction[OMX_VIDEO_ANDROID_MAXTEMPORALLAYERS];
    275 };
    276 
    277 enum v4l2_ports {
    278     CAPTURE_PORT,
    279     OUTPUT_PORT,
    280     MAX_PORT
    281 };
    282 
    283 struct extradata_buffer_info {
    284     unsigned long buffer_size;
    285     char* uaddr;
    286     int count;
    287     int size;
    288     OMX_BOOL allocated;
    289     enum v4l2_ports port_index;
    290 #ifdef USE_ION
    291     struct venc_ion ion;
    292     unsigned int m_ion_dev;
    293 #endif
    294     bool vqzip_sei_found;
    295 };
    296 
    297 struct statistics {
    298     struct timeval prev_tv;
    299     int prev_fbd;
    300     int bytes_generated;
    301 };
    302 
    303 enum rc_modes {
    304     RC_VBR_VFR = BIT(0),
    305     RC_VBR_CFR = BIT(1),
    306     RC_CBR_VFR = BIT(2),
    307     RC_CBR_CFR = BIT(3),
    308     RC_MBR_CFR = BIT(4),
    309     RC_MBR_VFR = BIT(5),
    310     RC_ALL = (RC_VBR_VFR | RC_VBR_CFR
    311         | RC_CBR_VFR | RC_CBR_CFR | RC_MBR_CFR | RC_MBR_VFR)
    312 };
    313 
    314 class venc_dev
    315 {
    316     public:
    317         venc_dev(class omx_venc *venc_class); //constructor
    318         ~venc_dev(); //des
    319 
    320         static void* async_venc_message_thread (void *);
    321         bool venc_open(OMX_U32);
    322         void venc_close();
    323         unsigned venc_stop(void);
    324         unsigned venc_pause(void);
    325         unsigned venc_start(void);
    326         unsigned venc_flush(unsigned);
    327 #ifdef _ANDROID_ICS_
    328         bool venc_set_meta_mode(bool);
    329 #endif
    330         unsigned venc_resume(void);
    331         unsigned venc_start_done(void);
    332         unsigned venc_stop_done(void);
    333         unsigned venc_set_message_thread_id(pthread_t);
    334         bool venc_use_buf(void*, unsigned,unsigned);
    335         bool venc_free_buf(void*, unsigned);
    336         bool venc_empty_buf(void *, void *,unsigned,unsigned);
    337         bool venc_fill_buf(void *, void *,unsigned,unsigned);
    338 
    339         bool venc_get_buf_req(OMX_U32 *,OMX_U32 *,
    340                 OMX_U32 *,OMX_U32);
    341         bool venc_set_buf_req(OMX_U32 *,OMX_U32 *,
    342                 OMX_U32 *,OMX_U32);
    343         bool venc_set_param(void *,OMX_INDEXTYPE);
    344         bool venc_set_config(void *configData, OMX_INDEXTYPE index);
    345         bool venc_h264_transform_8x8(OMX_BOOL enable);
    346         bool venc_get_profile_level(OMX_U32 *eProfile,OMX_U32 *eLevel);
    347         bool venc_get_seq_hdr(void *, unsigned, unsigned *);
    348         bool venc_get_dimensions(OMX_U32 portIndex, OMX_U32 *w, OMX_U32 *h);
    349         bool venc_loaded_start(void);
    350         bool venc_loaded_stop(void);
    351         bool venc_loaded_start_done(void);
    352         bool venc_loaded_stop_done(void);
    353         bool venc_is_video_session_supported(unsigned long width, unsigned long height);
    354         bool venc_color_align(OMX_BUFFERHEADERTYPE *buffer, OMX_U32 width,
    355                         OMX_U32 height);
    356         bool venc_get_performance_level(OMX_U32 *perflevel);
    357         bool venc_get_vui_timing_info(OMX_U32 *enabled);
    358         bool venc_get_vqzip_sei_info(OMX_U32 *enabled);
    359         bool venc_get_peak_bitrate(OMX_U32 *peakbitrate);
    360         bool venc_get_batch_size(OMX_U32 *size);
    361         bool venc_get_pq_status(OMX_BOOL *pq_status);
    362         bool venc_get_temporal_layer_caps(OMX_U32 * /*nMaxLayers*/,
    363                 OMX_U32 * /*nMaxBLayers*/);
    364         bool venc_get_output_log_flag();
    365         bool venc_check_valid_config();
    366         int venc_output_log_buffers(const char *buffer_addr, int buffer_len);
    367         int venc_input_log_buffers(OMX_BUFFERHEADERTYPE *buffer, int fd, int plane_offset,
    368                         unsigned long inputformat);
    369         int venc_extradata_log_buffers(char *buffer_addr);
    370         bool venc_set_bitrate_type(OMX_U32 type);
    371 
    372 #ifdef _VQZIP_
    373         class venc_dev_vqzip
    374         {
    375             public:
    376                 venc_dev_vqzip();
    377                 ~venc_dev_vqzip();
    378                 bool init();
    379                 void deinit();
    380                 struct VQZipConfig pConfig;
    381                 int tempSEI[300];
    382                 int fill_stats_data(void* pBuf, void *pStats);
    383                 typedef void (*vqzip_deinit_t)(void*);
    384                 typedef void* (*vqzip_init_t)(void);
    385                 typedef VQZipStatus (*vqzip_compute_stats_t)(void* const , const void * const , const VQZipConfig* ,VQZipStats*);
    386             private:
    387                 pthread_mutex_t lock;
    388                 void *mLibHandle;
    389                 void *mVQZIPHandle;
    390                 vqzip_init_t mVQZIPInit;
    391                 vqzip_deinit_t mVQZIPDeInit;
    392                 vqzip_compute_stats_t mVQZIPComputeStats;
    393         };
    394         venc_dev_vqzip vqzip;
    395 #endif
    396 
    397 #ifdef _PQ_
    398         class venc_dev_pq
    399         {
    400             public:
    401                 venc_dev_pq();
    402                 ~venc_dev_pq();
    403                 bool is_pq_enabled;
    404                 bool is_pq_force_disable;
    405                 bool is_YUV_format_uncertain;
    406                 pthread_mutex_t lock;
    407                 struct extradata_buffer_info roi_extradata_info;
    408                 bool init(unsigned long);
    409                 void deinit();
    410                 void get_caps();
    411                 int configure(unsigned long width, unsigned long height);
    412                 bool is_pq_handle_valid();
    413                 bool is_color_format_supported(unsigned long);
    414                 bool reinit(unsigned long);
    415                 struct gpu_stats_lib_input_config pConfig;
    416                 int fill_pq_stats(struct v4l2_buffer buf, unsigned int data_offset);
    417                 gpu_stats_lib_caps_t caps;
    418                 typedef gpu_stats_lib_op_status (*gpu_stats_lib_init_t)(void**, enum perf_hint gpu_hint, enum color_compression_format format);
    419                 typedef gpu_stats_lib_op_status (*gpu_stats_lib_deinit_t)(void*);
    420                 typedef gpu_stats_lib_op_status (*gpu_stats_lib_get_caps_t)(void* handle, gpu_stats_lib_caps_t *caps);
    421                 typedef gpu_stats_lib_op_status (*gpu_stats_lib_configure_t)(void* handle, gpu_stats_lib_input_config *input_t);
    422                 typedef gpu_stats_lib_op_status (*gpu_stats_lib_fill_data_t)(void *handle, gpu_stats_lib_buffer_params_t *yuv_input,
    423                         gpu_stats_lib_buffer_params_t *roi_input,
    424                         gpu_stats_lib_buffer_params_t *stats_output, void *addr, void *user_data);
    425             private:
    426                 void *mLibHandle;
    427                 void *mPQHandle;
    428                 gpu_stats_lib_init_t mPQInit;
    429                 gpu_stats_lib_get_caps_t mPQGetCaps;
    430                 gpu_stats_lib_configure_t mPQConfigure;
    431                 gpu_stats_lib_deinit_t mPQDeInit;
    432                 gpu_stats_lib_fill_data_t mPQComputeStats;
    433                 unsigned long configured_format;
    434         };
    435         venc_dev_pq m_pq;
    436         bool venc_check_for_pq(void);
    437         void venc_configure_pq(void);
    438         void venc_try_enable_pq(void);
    439 #endif
    440         struct venc_debug_cap m_debug;
    441         OMX_U32 m_nDriver_fd;
    442         int m_poll_efd;
    443         bool m_profile_set;
    444         bool m_level_set;
    445         int num_input_planes, num_output_planes;
    446         int etb, ebd, ftb, fbd;
    447         struct recon_buffer {
    448             unsigned char* virtual_address;
    449             int pmem_fd;
    450             int size;
    451             int alignment;
    452             int offset;
    453 #ifdef USE_ION
    454             int ion_device_fd;
    455             struct ion_allocation_data alloc_data;
    456             struct ion_fd_data ion_alloc_fd;
    457 #endif
    458         };
    459 
    460         int stopped;
    461         int resume_in_stopped;
    462         bool m_max_allowed_bitrate_check;
    463         pthread_t m_tid;
    464         bool async_thread_created;
    465         bool async_thread_force_stop;
    466         class omx_venc *venc_handle;
    467         OMX_ERRORTYPE allocate_extradata(struct extradata_buffer_info *extradata_info, int flags);
    468         void free_extradata_all();
    469         void free_extradata(struct extradata_buffer_info *extradata_info);
    470         int append_mbi_extradata(void *, struct msm_vidc_extradata_header*);
    471         bool handle_output_extradata(void *, int);
    472         bool handle_input_extradata(struct v4l2_buffer);
    473         int venc_set_format(int);
    474         bool deinterlace_enabled;
    475         bool hw_overload;
    476         bool is_gralloc_source_ubwc;
    477         bool is_camera_source_ubwc;
    478         bool is_csc_enabled;
    479         OMX_U32 fd_list[64];
    480 
    481     private:
    482         OMX_U32                             m_codec;
    483         struct msm_venc_basecfg             m_sVenc_cfg;
    484         struct msm_venc_ratectrlcfg         rate_ctrl;
    485         struct msm_venc_targetbitrate       bitrate;
    486         struct msm_venc_intraperiod         intra_period;
    487         struct msm_venc_profile             codec_profile;
    488         struct msm_venc_profilelevel        profile_level;
    489         struct msm_venc_switch              set_param;
    490         struct msm_venc_voptimingcfg        time_inc;
    491         struct msm_venc_allocatorproperty   m_sInput_buff_property;
    492         struct msm_venc_allocatorproperty   m_sOutput_buff_property;
    493         struct msm_venc_sessionqp           session_qp;
    494         struct msm_venc_initqp              init_qp;
    495         struct msm_venc_qprange             session_qp_range;
    496         struct msm_venc_qprange             session_qp_values;
    497         struct msm_venc_ipb_qprange         session_ipb_qp_values;
    498         struct msm_venc_multiclicecfg       multislice;
    499         struct msm_venc_entropycfg          entropy;
    500         struct msm_venc_dbcfg               dbkfilter;
    501         struct msm_venc_intrarefresh        intra_refresh;
    502         struct msm_venc_headerextension     hec;
    503         struct msm_venc_voptimingcfg        voptimecfg;
    504         struct msm_venc_video_capability    capability;
    505         struct msm_venc_idrperiod           idrperiod;
    506         struct msm_venc_slice_delivery      slice_mode;
    507         struct msm_venc_hierlayers          hier_layers;
    508         struct msm_venc_perf_level          performance_level;
    509         struct msm_venc_vui_timing_info     vui_timing_info;
    510         struct msm_venc_vqzip_sei_info      vqzip_sei_info;
    511         struct msm_venc_peak_bitrate        peak_bitrate;
    512         struct msm_venc_ltrinfo             ltrinfo;
    513         struct msm_venc_vpx_error_resilience vpx_err_resilience;
    514         struct msm_venc_priority            sess_priority;
    515         OMX_U32                             operating_rate;
    516         int rc_off_level;
    517         struct msm_venc_hybrid_hp           hybrid_hp;
    518         struct msm_venc_color_space         color_space;
    519         msm_venc_temporal_layers            temporal_layers_config;
    520 
    521         bool venc_set_profile_level(OMX_U32 eProfile,OMX_U32 eLevel);
    522         bool venc_set_intra_period(OMX_U32 nPFrames, OMX_U32 nBFrames);
    523         bool venc_set_target_bitrate(OMX_U32 nTargetBitrate, OMX_U32 config);
    524         bool venc_set_ratectrl_cfg(OMX_VIDEO_CONTROLRATETYPE eControlRate);
    525         bool venc_set_session_qp(OMX_U32 i_frame_qp, OMX_U32 p_frame_qp,OMX_U32 b_frame_qp);
    526         bool venc_set_session_qp_range(OMX_U32 min_qp, OMX_U32 max_qp);
    527         bool venc_set_session_qp_range_packed(OMX_U32 min_qp, OMX_U32 max_qp);
    528         bool venc_set_encode_framerate(OMX_U32 encode_framerate, OMX_U32 config);
    529         bool venc_set_intra_vop_refresh(OMX_BOOL intra_vop_refresh);
    530         bool venc_set_color_format(OMX_COLOR_FORMATTYPE color_format);
    531         bool venc_validate_profile_level(OMX_U32 *eProfile, OMX_U32 *eLevel);
    532         bool venc_set_multislice_cfg(OMX_INDEXTYPE codec, OMX_U32 slicesize);
    533         bool venc_set_entropy_config(OMX_BOOL enable, OMX_U32 i_cabac_level);
    534         bool venc_set_inloop_filter(OMX_VIDEO_AVCLOOPFILTERTYPE loop_filter);
    535         bool venc_set_intra_refresh (OMX_VIDEO_INTRAREFRESHTYPE intrarefresh, OMX_U32 nMBs);
    536         bool venc_set_error_resilience(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* error_resilience);
    537         bool venc_set_voptiming_cfg(OMX_U32 nTimeIncRes);
    538         void venc_config_print();
    539         bool venc_set_slice_delivery_mode(OMX_U32 enable);
    540         bool venc_set_extradata(OMX_U32 extra_data, OMX_BOOL enable);
    541         bool venc_set_idr_period(OMX_U32 nPFrames, OMX_U32 nIDRPeriod);
    542         bool venc_reconfig_reqbufs();
    543         bool venc_set_vpe_rotation(OMX_S32 rotation_angle);
    544         bool venc_set_deinterlace(OMX_U32 enable);
    545         bool venc_set_ltrmode(OMX_U32 enable, OMX_U32 count);
    546         bool venc_enable_initial_qp(QOMX_EXTNINDEX_VIDEO_INITIALQP* initqp);
    547         bool venc_set_useltr(OMX_U32 frameIdx);
    548         bool venc_set_markltr(OMX_U32 frameIdx);
    549         bool venc_set_inband_video_header(OMX_BOOL enable);
    550         bool venc_set_au_delimiter(OMX_BOOL enable);
    551         bool venc_set_hier_layers(QOMX_VIDEO_HIERARCHICALCODINGTYPE type, OMX_U32 num_layers);
    552         bool venc_set_perf_level(QOMX_VIDEO_PERF_LEVEL ePerfLevel);
    553         bool venc_set_vui_timing_info(OMX_BOOL enable);
    554         bool venc_set_peak_bitrate(OMX_U32 nPeakBitrate);
    555         bool venc_set_searchrange();
    556         bool venc_set_vpx_error_resilience(OMX_BOOL enable);
    557         bool venc_set_perf_mode(OMX_U32 mode);
    558         bool venc_set_mbi_statistics_mode(OMX_U32 mode);
    559         bool venc_set_vqzip_sei_type(OMX_BOOL enable);
    560         bool venc_set_hybrid_hierp(QOMX_EXTNINDEX_VIDEO_HYBRID_HP_MODE* hhp);
    561         bool venc_set_batch_size(OMX_U32 size);
    562         bool venc_calibrate_gop();
    563         bool venc_set_vqzip_defaults();
    564         int venc_get_index_from_fd(OMX_U32 ion_fd, OMX_U32 buffer_fd);
    565         bool venc_validate_hybridhp_params(OMX_U32 layers, OMX_U32 bFrames, OMX_U32 count, int mode);
    566         bool venc_set_hierp_layers(OMX_U32 hierp_layers);
    567         bool venc_set_baselayerid(OMX_U32 baseid);
    568         bool venc_set_qp(OMX_U32 nQp);
    569         bool venc_set_aspectratio(void *nSar);
    570         bool venc_set_priority(OMX_U32 priority);
    571         bool venc_set_session_priority(OMX_U32 priority);
    572         bool venc_set_operatingrate(OMX_U32 rate);
    573         bool venc_set_layer_bitrates(OMX_U32 *pLayerBitrates, OMX_U32 numLayers);
    574         bool venc_set_lowlatency_mode(OMX_BOOL enable);
    575         bool venc_set_low_latency(OMX_BOOL enable);
    576         bool venc_set_roi_qp_info(OMX_QTI_VIDEO_CONFIG_ROIINFO *roiInfo);
    577         bool venc_set_blur_resolution(OMX_QTI_VIDEO_CONFIG_BLURINFO *blurInfo);
    578         bool venc_set_colorspace(OMX_U32 primaries, OMX_U32 range, OMX_U32 transfer_chars, OMX_U32 matrix_coeffs);
    579         OMX_ERRORTYPE venc_set_temporal_layers(OMX_VIDEO_PARAM_ANDROID_TEMPORALLAYERINGTYPE *pTemporalParams);
    580         OMX_ERRORTYPE venc_set_temporal_layers_internal();
    581         bool venc_set_iframesize_type(QOMX_VIDEO_IFRAMESIZE_TYPE type);
    582 
    583 #ifdef MAX_RES_1080P
    584         OMX_U32 pmem_free();
    585         OMX_U32 pmem_allocate(OMX_U32 size, OMX_U32 alignment, OMX_U32 count);
    586         OMX_U32 venc_allocate_recon_buffers();
    587         inline int clip2(int x) {
    588             x = x -1;
    589             x = x | x >> 1;
    590             x = x | x >> 2;
    591             x = x | x >> 4;
    592             x = x | x >> 16;
    593             x = x + 1;
    594             return x;
    595         }
    596 #endif
    597         int metadatamode;
    598         bool streaming[MAX_PORT];
    599         bool extradata;
    600         struct extradata_buffer_info input_extradata_info;
    601         struct extradata_buffer_info output_extradata_info;
    602 
    603         pthread_mutex_t pause_resume_mlock;
    604         pthread_cond_t pause_resume_cond;
    605         bool paused;
    606         int color_format;
    607         bool is_searchrange_set;
    608         bool enable_mv_narrow_searchrange;
    609         int supported_rc_modes;
    610         bool is_thulium_v1;
    611         bool camera_mode_enabled;
    612         OMX_BOOL low_latency_mode;
    613         struct roidata {
    614             bool dirty;
    615             OMX_TICKS timestamp;
    616             OMX_QTI_VIDEO_CONFIG_ROIINFO info;
    617         };
    618         bool m_roi_enabled;
    619         pthread_mutex_t m_roilock;
    620         std::list<roidata> m_roilist;
    621         void get_roi_for_timestamp(struct roidata &roi, OMX_TICKS timestamp);
    622         bool venc_empty_batch (OMX_BUFFERHEADERTYPE *buf, unsigned index);
    623         static const int kMaxBuffersInBatch = 16;
    624         unsigned int mBatchSize;
    625         struct BatchInfo {
    626             BatchInfo();
    627             /* register a buffer and obtain its unique id (v4l2-buf-id)
    628              */
    629             int registerBuffer(int bufferId);
    630             /* retrieve the buffer given its v4l2-buf-id
    631              */
    632             int retrieveBufferAt(int v4l2Id);
    633             bool isPending(int bufferId);
    634 
    635           private:
    636             static const int kMaxBufs = 64;
    637             static const int kBufIDFree = -1;
    638             pthread_mutex_t mLock;
    639             int mBufMap[64];  // Map with slots for each buffer
    640             size_t mNumPending;
    641 
    642         };
    643         BatchInfo mBatchInfo;
    644         bool mUseAVTimerTimestamps;
    645 };
    646 
    647 enum instance_state {
    648     MSM_VIDC_CORE_UNINIT_DONE = 0x0001,
    649     MSM_VIDC_CORE_INIT,
    650     MSM_VIDC_CORE_INIT_DONE,
    651     MSM_VIDC_OPEN,
    652     MSM_VIDC_OPEN_DONE,
    653     MSM_VIDC_LOAD_RESOURCES,
    654     MSM_VIDC_LOAD_RESOURCES_DONE,
    655     MSM_VIDC_START,
    656     MSM_VIDC_START_DONE,
    657     MSM_VIDC_STOP,
    658     MSM_VIDC_STOP_DONE,
    659     MSM_VIDC_RELEASE_RESOURCES,
    660     MSM_VIDC_RELEASE_RESOURCES_DONE,
    661     MSM_VIDC_CLOSE,
    662     MSM_VIDC_CLOSE_DONE,
    663     MSM_VIDC_CORE_UNINIT,
    664 };
    665 #endif
    666 
    667