1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2010-2013, 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 met: 6 * Redistributions of source code must retain the above copyright 7 notice, this list of conditions and the following disclaimer. 8 * Redistributions in binary form must reproduce the above copyright 9 notice, this list of conditions and the following disclaimer in the 10 documentation and/or other materials provided with the distribution. 11 * Neither the name of The Linux Foundation nor 12 the names of its contributors may be used to endorse or promote 13 products derived from this software without specific prior written 14 permission. 15 16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 20 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 23 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 25 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 26 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 --------------------------------------------------------------------------*/ 28 #ifndef __OMX_VENC_DEV__ 29 #define __OMX_VENC_DEV__ 30 31 #include "OMX_Types.h" 32 #include "OMX_Core.h" 33 #include "OMX_QCOMExtns.h" 34 #include "qc_omx_component.h" 35 #include "omx_video_common.h" 36 #include <linux/msm_vidc_enc.h> 37 #include <pthread.h> 38 #include <linux/videodev2.h> 39 #include <poll.h> 40 #define TIMEOUT 5000 41 #define MAX_RECON_BUFFERS 4 42 43 void* async_venc_message_thread (void *); 44 45 class venc_dev 46 { 47 public: 48 venc_dev(class omx_venc *venc_class); //constructor 49 ~venc_dev(); //des 50 51 bool venc_open(OMX_U32); 52 void venc_close(); 53 unsigned venc_stop(void); 54 unsigned venc_pause(void); 55 unsigned venc_start(void); 56 unsigned venc_flush(unsigned); 57 #ifdef _ANDROID_ICS_ 58 bool venc_set_meta_mode(bool); 59 #endif 60 unsigned venc_resume(void); 61 unsigned venc_start_done(void); 62 unsigned venc_set_message_thread_id(pthread_t); 63 bool venc_use_buf(void*, unsigned,unsigned); 64 bool venc_free_buf(void*, unsigned); 65 bool venc_empty_buf(void *, void *,unsigned,unsigned); 66 bool venc_fill_buf(void *, void *,unsigned,unsigned); 67 68 bool venc_get_buf_req(unsigned long *,unsigned long *, 69 unsigned long *,unsigned long); 70 bool venc_set_buf_req(unsigned long *,unsigned long *, 71 unsigned long *,unsigned long); 72 bool venc_set_param(void *,OMX_INDEXTYPE); 73 bool venc_set_config(void *configData, OMX_INDEXTYPE index); 74 bool venc_get_profile_level(OMX_U32 *eProfile,OMX_U32 *eLevel); 75 bool venc_max_allowed_bitrate_check(OMX_U32 nTargetBitrate); 76 bool venc_get_seq_hdr(void *, unsigned, unsigned *); 77 bool venc_loaded_start(void); 78 bool venc_loaded_stop(void); 79 bool venc_loaded_start_done(void); 80 bool venc_loaded_stop_done(void); 81 bool venc_get_capability_ltrcount(OMX_U32 *, OMX_U32 *, OMX_U32 *); 82 OMX_U32 m_nDriver_fd; 83 bool m_profile_set; 84 bool m_level_set; 85 pthread_mutex_t loaded_start_stop_mlock; 86 pthread_cond_t loaded_start_stop_cond; 87 88 struct recon_buffer { 89 unsigned char* virtual_address; 90 int pmem_fd; 91 int size; 92 int alignment; 93 int offset; 94 #ifdef USE_ION 95 int ion_device_fd; 96 struct ion_allocation_data alloc_data; 97 struct ion_fd_data ion_alloc_fd; 98 #endif 99 }; 100 101 recon_buffer recon_buff[MAX_RECON_BUFFERS]; 102 int recon_buffers_count; 103 bool m_max_allowed_bitrate_check; 104 int m_eProfile; 105 int m_eLevel; 106 int etb_count; 107 private: 108 struct venc_basecfg m_sVenc_cfg; 109 struct venc_ratectrlcfg rate_ctrl; 110 struct venc_targetbitrate bitrate; 111 struct venc_intraperiod intra_period; 112 struct venc_profile codec_profile; 113 struct ven_profilelevel profile_level; 114 struct venc_switch set_param; 115 struct venc_voptimingcfg time_inc; 116 struct venc_allocatorproperty m_sInput_buff_property; 117 struct venc_allocatorproperty m_sOutput_buff_property; 118 struct venc_sessionqp session_qp; 119 struct venc_qprange qp_range; 120 struct venc_multiclicecfg multislice; 121 struct venc_entropycfg entropy; 122 struct venc_dbcfg dbkfilter; 123 struct venc_intrarefresh intra_refresh; 124 struct venc_headerextension hec; 125 struct venc_voptimingcfg voptimecfg; 126 struct venc_seqheader seqhdr; 127 struct venc_ltrmode ltrmode; 128 struct venc_ltrcount ltrcount; 129 struct venc_ltrperiod ltrperiod; 130 131 bool venc_set_profile_level(OMX_U32 eProfile,OMX_U32 eLevel); 132 bool venc_set_intra_period(OMX_U32 nPFrames, OMX_U32 nBFrames); 133 bool venc_set_target_bitrate(OMX_U32 nTargetBitrate, OMX_U32 config); 134 bool venc_set_ratectrl_cfg(OMX_VIDEO_CONTROLRATETYPE eControlRate); 135 bool venc_set_qp_range(OMX_U32 min_qp, OMX_U32 max_qp); 136 bool venc_set_session_qp(OMX_U32 i_frame_qp, OMX_U32 p_frame_qp); 137 bool venc_set_extradata(OMX_U32 extra_data); 138 bool venc_set_encode_framerate(OMX_U32 encode_framerate, OMX_U32 config); 139 bool venc_set_intra_vop_refresh(OMX_BOOL intra_vop_refresh); 140 bool venc_set_color_format(OMX_COLOR_FORMATTYPE color_format); 141 bool venc_validate_profile_level(OMX_U32 *eProfile, OMX_U32 *eLevel); 142 bool venc_set_multislice_cfg(OMX_INDEXTYPE codec, OMX_U32 slicesize); 143 bool venc_set_entropy_config(OMX_BOOL enable, OMX_U32 i_cabac_level); 144 bool venc_set_inloop_filter(OMX_VIDEO_AVCLOOPFILTERTYPE loop_filter); 145 bool venc_set_intra_refresh (OMX_VIDEO_INTRAREFRESHTYPE intrarefresh, OMX_U32 nMBs); 146 bool venc_set_error_resilience(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* error_resilience); 147 bool venc_set_voptiming_cfg(OMX_U32 nTimeIncRes); 148 void venc_config_print(); 149 bool venc_set_slice_delivery_mode(OMX_BOOL enable); 150 bool venc_set_plusptype(OMX_BOOL enable); 151 bool venc_set_ltrmode(QOMX_VIDEO_LTRMODETYPE mode); 152 bool venc_set_ltrcount(OMX_U32 count); 153 bool venc_set_ltrperiod(OMX_U32 period); 154 bool venc_set_ltruse(OMX_U32 id, OMX_U32 frames); 155 bool venc_color_align(OMX_BUFFERHEADERTYPE *buffer, OMX_U32 width, OMX_U32 height); 156 #ifdef MAX_RES_1080P 157 OMX_U32 pmem_free(); 158 OMX_U32 pmem_allocate(OMX_U32 size, OMX_U32 alignment, OMX_U32 count); 159 OMX_U32 venc_allocate_recon_buffers(); clip2(int x)160 inline int clip2(int x) { 161 x = x -1; 162 x = x | x >> 1; 163 x = x | x >> 2; 164 x = x | x >> 4; 165 x = x | x >> 16; 166 x = x + 1; 167 return x; 168 } 169 #endif 170 }; 171 172 #endif 173