1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2012, Code Aurora Forum. 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 Code Aurora 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 "omx_video_base.h" 37 #include "omx_video_encoder.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 struct msm_venc_switch{ 46 unsigned char status; 47 }; 48 49 struct msm_venc_allocatorproperty{ 50 unsigned long mincount; 51 unsigned long maxcount; 52 unsigned long actualcount; 53 unsigned long datasize; 54 unsigned long suffixsize; 55 unsigned long alignment; 56 unsigned long bufpoolid; 57 }; 58 59 struct msm_venc_basecfg{ 60 unsigned long input_width; 61 unsigned long input_height; 62 unsigned long dvs_width; 63 unsigned long dvs_height; 64 unsigned long codectype; 65 unsigned long fps_num; 66 unsigned long fps_den; 67 unsigned long targetbitrate; 68 unsigned long inputformat; 69 }; 70 71 struct msm_venc_profile{ 72 unsigned long profile; 73 }; 74 struct msm_venc_profilelevel{ 75 unsigned long level; 76 }; 77 78 struct msm_venc_sessionqp{ 79 unsigned long iframeqp; 80 unsigned long pframqp; 81 unsigned long bframqp; 82 }; 83 84 struct msm_venc_qprange{ 85 unsigned long maxqp; 86 unsigned long minqp; 87 }; 88 struct msm_venc_intraperiod{ 89 unsigned long num_pframes; 90 unsigned long num_bframes; 91 }; 92 struct msm_venc_seqheader{ 93 unsigned char *hdrbufptr; 94 unsigned long bufsize; 95 unsigned long hdrlen; 96 }; 97 98 struct msm_venc_capability{ 99 unsigned long codec_types; 100 unsigned long maxframe_width; 101 unsigned long maxframe_height; 102 unsigned long maxtarget_bitrate; 103 unsigned long maxframe_rate; 104 unsigned long input_formats; 105 unsigned char dvs; 106 }; 107 108 struct msm_venc_entropycfg{ 109 unsigned longentropysel; 110 unsigned long cabacmodel; 111 }; 112 113 struct msm_venc_dbcfg{ 114 unsigned long db_mode; 115 unsigned long slicealpha_offset; 116 unsigned long slicebeta_offset; 117 }; 118 119 struct msm_venc_intrarefresh{ 120 unsigned long irmode; 121 unsigned long mbcount; 122 }; 123 124 struct msm_venc_multiclicecfg{ 125 unsigned long mslice_mode; 126 unsigned long mslice_size; 127 }; 128 129 struct msm_venc_bufferflush{ 130 unsigned long flush_mode; 131 }; 132 133 struct msm_venc_ratectrlcfg{ 134 unsigned long rcmode; 135 }; 136 137 struct msm_venc_voptimingcfg{ 138 unsigned long voptime_resolution; 139 }; 140 struct msm_venc_framerate{ 141 unsigned long fps_denominator; 142 unsigned long fps_numerator; 143 }; 144 145 struct msm_venc_targetbitrate{ 146 unsigned long target_bitrate; 147 }; 148 149 150 struct msm_venc_rotation{ 151 unsigned long rotation; 152 }; 153 154 struct msm_venc_timeout{ 155 unsigned long millisec; 156 }; 157 158 struct msm_venc_headerextension{ 159 unsigned long header_extension; 160 }; 161 162 class venc_dev 163 { 164 public: 165 venc_dev(class omx_venc *venc_class); //constructor 166 ~venc_dev(); //des 167 168 bool venc_open(OMX_U32); 169 void venc_close(); 170 unsigned venc_stop(void); 171 unsigned venc_pause(void); 172 unsigned venc_start(void); 173 unsigned venc_flush(unsigned); 174 #ifdef _ANDROID_ICS_ 175 bool venc_set_meta_mode(bool); 176 #endif 177 unsigned venc_resume(void); 178 unsigned venc_start_done(void); 179 unsigned venc_stop_done(void); 180 bool venc_use_buf(void*, unsigned,unsigned); 181 bool venc_free_buf(void*, unsigned); 182 bool venc_empty_buf(void *, void *,unsigned,unsigned); 183 bool venc_fill_buf(void *, void *,unsigned,unsigned); 184 185 bool venc_get_buf_req(unsigned long *,unsigned long *, 186 unsigned long *,unsigned long); 187 bool venc_set_buf_req(unsigned long *,unsigned long *, 188 unsigned long *,unsigned long); 189 bool venc_set_param(void *,OMX_INDEXTYPE); 190 bool venc_set_config(void *configData, OMX_INDEXTYPE index); 191 bool venc_get_profile_level(OMX_U32 *eProfile,OMX_U32 *eLevel); 192 bool venc_get_seq_hdr(void *, unsigned, unsigned *); 193 bool venc_loaded_start(void); 194 bool venc_loaded_stop(void); 195 bool venc_loaded_start_done(void); 196 bool venc_loaded_stop_done(void); 197 OMX_U32 m_nDriver_fd; 198 bool m_profile_set; 199 bool m_level_set; 200 struct recon_buffer { 201 unsigned char* virtual_address; 202 int pmem_fd; 203 int size; 204 int alignment; 205 int offset; 206 #ifdef USE_ION 207 int ion_device_fd; 208 struct ion_allocation_data alloc_data; 209 struct ion_fd_data ion_alloc_fd; 210 #endif 211 }; 212 213 recon_buffer recon_buff[MAX_RECON_BUFFERS]; 214 int recon_buffers_count; 215 bool m_max_allowed_bitrate_check; 216 int etb_count; 217 class omx_venc *venc_handle; 218 private: 219 struct msm_venc_basecfg m_sVenc_cfg; 220 struct msm_venc_ratectrlcfg rate_ctrl; 221 struct msm_venc_targetbitrate bitrate; 222 struct msm_venc_intraperiod intra_period; 223 struct msm_venc_profile codec_profile; 224 struct msm_venc_profilelevel profile_level; 225 struct msm_venc_switch set_param; 226 struct msm_venc_voptimingcfg time_inc; 227 struct msm_venc_allocatorproperty m_sInput_buff_property; 228 struct msm_venc_allocatorproperty m_sOutput_buff_property; 229 struct msm_venc_sessionqp session_qp; 230 struct msm_venc_multiclicecfg multislice; 231 struct msm_venc_entropycfg entropy; 232 struct msm_venc_dbcfg dbkfilter; 233 struct msm_venc_intrarefresh intra_refresh; 234 struct msm_venc_headerextension hec; 235 struct msm_venc_voptimingcfg voptimecfg; 236 237 bool venc_set_profile_level(OMX_U32 eProfile,OMX_U32 eLevel); 238 bool venc_set_intra_period(OMX_U32 nPFrames, OMX_U32 nBFrames); 239 bool venc_set_target_bitrate(OMX_U32 nTargetBitrate, OMX_U32 config); 240 bool venc_set_ratectrl_cfg(OMX_VIDEO_CONTROLRATETYPE eControlRate); 241 bool venc_set_session_qp(OMX_U32 i_frame_qp, OMX_U32 p_frame_qp,OMX_U32 b_frame_qp); 242 bool venc_set_encode_framerate(OMX_U32 encode_framerate, OMX_U32 config); 243 bool venc_set_intra_vop_refresh(OMX_BOOL intra_vop_refresh); 244 bool venc_set_color_format(OMX_COLOR_FORMATTYPE color_format); 245 bool venc_validate_profile_level(OMX_U32 *eProfile, OMX_U32 *eLevel); 246 bool venc_set_multislice_cfg(OMX_INDEXTYPE codec, OMX_U32 slicesize); 247 bool venc_set_entropy_config(OMX_BOOL enable, OMX_U32 i_cabac_level); 248 bool venc_set_inloop_filter(OMX_VIDEO_AVCLOOPFILTERTYPE loop_filter); 249 bool venc_set_intra_refresh (OMX_VIDEO_INTRAREFRESHTYPE intrarefresh, OMX_U32 nMBs); 250 bool venc_set_error_resilience(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* error_resilience); 251 bool venc_set_voptiming_cfg(OMX_U32 nTimeIncRes); 252 void venc_config_print(); 253 #ifdef MAX_RES_1080P 254 OMX_U32 pmem_free(); 255 OMX_U32 pmem_allocate(OMX_U32 size, OMX_U32 alignment, OMX_U32 count); 256 OMX_U32 venc_allocate_recon_buffers(); clip2(int x)257 inline int clip2(int x) 258 { 259 x = x -1; 260 x = x | x >> 1; 261 x = x | x >> 2; 262 x = x | x >> 4; 263 x = x | x >> 16; 264 x = x + 1; 265 return x; 266 } 267 #endif 268 }; 269 270 enum instance_state { 271 MSM_VIDC_CORE_UNINIT_DONE = 0x0001, 272 MSM_VIDC_CORE_INIT, 273 MSM_VIDC_CORE_INIT_DONE, 274 MSM_VIDC_OPEN, 275 MSM_VIDC_OPEN_DONE, 276 MSM_VIDC_LOAD_RESOURCES, 277 MSM_VIDC_LOAD_RESOURCES_DONE, 278 MSM_VIDC_START, 279 MSM_VIDC_START_DONE, 280 MSM_VIDC_STOP, 281 MSM_VIDC_STOP_DONE, 282 MSM_VIDC_RELEASE_RESOURCES, 283 MSM_VIDC_RELEASE_RESOURCES_DONE, 284 MSM_VIDC_CLOSE, 285 MSM_VIDC_CLOSE_DONE, 286 MSM_VIDC_CORE_UNINIT, 287 }; 288 #endif 289