1 /*-------------------------------------------------------------------------- 2 Copyright (c) 2012-2014, 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 "OMX_QCOMExtns.h" 36 #include "qc_omx_component.h" 37 #include "omx_video_common.h" 38 #include "omx_video_base.h" 39 #include "omx_video_encoder.h" 40 #include <linux/videodev2.h> 41 #include <linux/fb.h> 42 #include <poll.h> 43 #include <gui/ISurfaceComposer.h> 44 #include <gui/SurfaceComposerClient.h> 45 #include <ui/DisplayInfo.h> 46 47 #define TIMEOUT 5*60*1000 48 49 50 struct msm_venc_switch { 51 unsigned char status; 52 }; 53 54 struct msm_venc_allocatorproperty { 55 unsigned long mincount; 56 unsigned long actualcount; 57 unsigned long datasize; 58 unsigned long suffixsize; 59 unsigned long alignment; 60 unsigned long bufpoolid; 61 }; 62 63 struct msm_venc_basecfg { 64 unsigned long input_width; 65 unsigned long input_height; 66 unsigned long dvs_width; 67 unsigned long dvs_height; 68 unsigned long codectype; 69 unsigned long fps_num; 70 unsigned long fps_den; 71 unsigned long targetbitrate; 72 unsigned long inputformat; 73 }; 74 75 struct msm_venc_profile { 76 unsigned long profile; 77 }; 78 struct msm_venc_profilelevel { 79 unsigned long level; 80 }; 81 82 struct msm_venc_sessionqp { 83 unsigned long iframeqp; 84 unsigned long pframeqp; 85 unsigned long bframeqp; 86 }; 87 88 struct msm_venc_initqp { 89 unsigned long iframeqp; 90 unsigned long pframeqp; 91 unsigned long bframeqp; 92 unsigned long enableinitqp; 93 }; 94 95 struct msm_venc_qprange { 96 unsigned long maxqp; 97 unsigned long minqp; 98 }; 99 struct msm_venc_intraperiod { 100 unsigned long num_pframes; 101 unsigned long num_bframes; 102 }; 103 struct msm_venc_seqheader { 104 unsigned char *hdrbufptr; 105 unsigned long bufsize; 106 unsigned long hdrlen; 107 }; 108 109 struct msm_venc_capability { 110 unsigned long codec_types; 111 unsigned long maxframe_width; 112 unsigned long maxframe_height; 113 unsigned long maxtarget_bitrate; 114 unsigned long maxframe_rate; 115 unsigned long input_formats; 116 unsigned char dvs; 117 }; 118 119 struct msm_venc_entropycfg { 120 unsigned longentropysel; 121 unsigned long cabacmodel; 122 }; 123 124 struct msm_venc_dbcfg { 125 unsigned long db_mode; 126 unsigned long slicealpha_offset; 127 unsigned long slicebeta_offset; 128 }; 129 130 struct msm_venc_intrarefresh { 131 unsigned long irmode; 132 unsigned long mbcount; 133 }; 134 135 struct msm_venc_multiclicecfg { 136 unsigned long mslice_mode; 137 unsigned long mslice_size; 138 }; 139 140 struct msm_venc_bufferflush { 141 unsigned long flush_mode; 142 }; 143 144 struct msm_venc_ratectrlcfg { 145 unsigned long rcmode; 146 }; 147 148 struct msm_venc_voptimingcfg { 149 unsigned long voptime_resolution; 150 }; 151 struct msm_venc_framerate { 152 unsigned long fps_denominator; 153 unsigned long fps_numerator; 154 }; 155 156 struct msm_venc_targetbitrate { 157 unsigned long target_bitrate; 158 }; 159 160 161 struct msm_venc_rotation { 162 unsigned long rotation; 163 }; 164 165 struct msm_venc_timeout { 166 unsigned long millisec; 167 }; 168 169 struct msm_venc_headerextension { 170 unsigned long header_extension; 171 }; 172 173 struct msm_venc_video_capability { 174 unsigned int min_width; 175 unsigned int max_width; 176 unsigned int min_height; 177 unsigned int max_height; 178 }; 179 180 struct msm_venc_idrperiod { 181 unsigned long idrperiod; 182 }; 183 184 struct msm_venc_slice_delivery { 185 unsigned long enable; 186 }; 187 188 struct msm_venc_hierlayers { 189 unsigned int numlayers; 190 }; 191 192 struct msm_venc_ltrinfo { 193 unsigned int enabled; 194 unsigned int count; 195 }; 196 197 struct msm_venc_perf_level { 198 unsigned int perflevel; 199 }; 200 201 struct msm_venc_vui_timing_info { 202 unsigned int enabled; 203 }; 204 205 struct msm_venc_peak_bitrate { 206 unsigned int peakbitrate; 207 }; 208 209 enum v4l2_ports { 210 CAPTURE_PORT, 211 OUTPUT_PORT, 212 MAX_PORT 213 }; 214 215 struct extradata_buffer_info { 216 unsigned long buffer_size; 217 char* uaddr; 218 int count; 219 int size; 220 int allocated; 221 #ifdef USE_ION 222 struct venc_ion ion; 223 #endif 224 }; 225 226 class venc_dev 227 { 228 public: 229 venc_dev(class omx_venc *venc_class); //constructor 230 ~venc_dev(); //des 231 232 static void* async_venc_message_thread (void *); 233 bool venc_open(OMX_U32); 234 void venc_close(); 235 unsigned venc_stop(void); 236 unsigned venc_pause(void); 237 unsigned venc_start(void); 238 unsigned venc_flush(unsigned); 239 #ifdef _ANDROID_ICS_ 240 bool venc_set_meta_mode(bool); 241 #endif 242 unsigned venc_resume(void); 243 unsigned venc_start_done(void); 244 unsigned venc_stop_done(void); 245 unsigned venc_set_message_thread_id(pthread_t); 246 bool venc_use_buf(void*, unsigned,unsigned); 247 bool venc_free_buf(void*, unsigned); 248 bool venc_empty_buf(void *, void *,unsigned,unsigned); 249 bool venc_fill_buf(void *, void *,unsigned,unsigned); 250 251 bool venc_get_buf_req(OMX_U32 *,OMX_U32 *, 252 OMX_U32 *,OMX_U32); 253 bool venc_set_buf_req(OMX_U32 *,OMX_U32 *, 254 OMX_U32 *,OMX_U32); 255 bool venc_set_param(void *,OMX_INDEXTYPE); 256 bool venc_set_config(void *configData, OMX_INDEXTYPE index); 257 bool venc_get_profile_level(OMX_U32 *eProfile,OMX_U32 *eLevel); 258 bool venc_get_seq_hdr(void *, unsigned, OMX_U32 *); 259 bool venc_loaded_start(void); 260 bool venc_loaded_stop(void); 261 bool venc_loaded_start_done(void); 262 bool venc_loaded_stop_done(void); 263 bool venc_is_video_session_supported(unsigned long width, unsigned long height); 264 bool venc_color_align(OMX_BUFFERHEADERTYPE *buffer, OMX_U32 width, 265 OMX_U32 height); 266 bool venc_get_performance_level(OMX_U32 *perflevel); 267 bool venc_get_vui_timing_info(OMX_U32 *enabled); 268 bool venc_get_peak_bitrate(OMX_U32 *peakbitrate); 269 bool venc_get_output_log_flag(); 270 int venc_output_log_buffers(const char *buffer_addr, int buffer_len); 271 int venc_input_log_buffers(OMX_BUFFERHEADERTYPE *buffer, int fd, int plane_offset); 272 int venc_extradata_log_buffers(char *buffer_addr); 273 274 struct venc_debug_cap m_debug; 275 OMX_U32 m_nDriver_fd; 276 bool m_profile_set; 277 bool m_level_set; 278 int num_planes; 279 int etb, ebd, ftb, fbd; 280 struct recon_buffer { 281 unsigned char* virtual_address; 282 int pmem_fd; 283 int size; 284 int alignment; 285 int offset; 286 #ifdef USE_ION 287 int ion_device_fd; 288 struct ion_allocation_data alloc_data; 289 struct ion_fd_data ion_alloc_fd; 290 #endif 291 }; 292 293 int stopped; 294 int resume_in_stopped; 295 bool m_max_allowed_bitrate_check; 296 pthread_t m_tid; 297 bool async_thread_created; 298 class omx_venc *venc_handle; 299 OMX_ERRORTYPE allocate_extradata(); 300 void free_extradata(); 301 int append_mbi_extradata(void *, struct msm_vidc_extradata_header*); 302 bool handle_extradata(void *, int); 303 int venc_set_format(int); 304 bool deinterlace_enabled; 305 private: 306 OMX_U32 m_codec; 307 struct msm_venc_basecfg m_sVenc_cfg; 308 struct msm_venc_ratectrlcfg rate_ctrl; 309 struct msm_venc_targetbitrate bitrate; 310 struct msm_venc_intraperiod intra_period; 311 struct msm_venc_profile codec_profile; 312 struct msm_venc_profilelevel profile_level; 313 struct msm_venc_switch set_param; 314 struct msm_venc_voptimingcfg time_inc; 315 struct msm_venc_allocatorproperty m_sInput_buff_property; 316 struct msm_venc_allocatorproperty m_sOutput_buff_property; 317 struct msm_venc_sessionqp session_qp; 318 struct msm_venc_initqp init_qp; 319 struct msm_venc_qprange session_qp_range; 320 struct msm_venc_qprange session_qp_values; 321 struct msm_venc_multiclicecfg multislice; 322 struct msm_venc_entropycfg entropy; 323 struct msm_venc_dbcfg dbkfilter; 324 struct msm_venc_intrarefresh intra_refresh; 325 struct msm_venc_headerextension hec; 326 struct msm_venc_voptimingcfg voptimecfg; 327 struct msm_venc_video_capability capability; 328 struct msm_venc_idrperiod idrperiod; 329 struct msm_venc_slice_delivery slice_mode; 330 struct msm_venc_hierlayers hier_p_layers; 331 struct msm_venc_perf_level performance_level; 332 struct msm_venc_vui_timing_info vui_timing_info; 333 struct msm_venc_peak_bitrate peak_bitrate; 334 335 bool venc_set_profile_level(OMX_U32 eProfile,OMX_U32 eLevel); 336 bool venc_set_intra_period(OMX_U32 nPFrames, OMX_U32 nBFrames); 337 bool venc_set_target_bitrate(OMX_U32 nTargetBitrate, OMX_U32 config); 338 bool venc_set_ratectrl_cfg(OMX_VIDEO_CONTROLRATETYPE eControlRate); 339 bool venc_set_session_qp(OMX_U32 i_frame_qp, OMX_U32 p_frame_qp,OMX_U32 b_frame_qp); 340 bool venc_set_session_qp_range(OMX_U32 min_qp, OMX_U32 max_qp); 341 bool venc_set_encode_framerate(OMX_U32 encode_framerate, OMX_U32 config); 342 bool venc_set_intra_vop_refresh(OMX_BOOL intra_vop_refresh); 343 bool venc_set_color_format(OMX_COLOR_FORMATTYPE color_format); 344 bool venc_validate_profile_level(OMX_U32 *eProfile, OMX_U32 *eLevel); 345 bool venc_set_multislice_cfg(OMX_INDEXTYPE codec, OMX_U32 slicesize); 346 bool venc_set_entropy_config(OMX_BOOL enable, OMX_U32 i_cabac_level); 347 bool venc_set_inloop_filter(OMX_VIDEO_AVCLOOPFILTERTYPE loop_filter); 348 bool venc_set_intra_refresh (OMX_VIDEO_INTRAREFRESHTYPE intrarefresh, OMX_U32 nMBs); 349 bool venc_set_error_resilience(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* error_resilience); 350 bool venc_set_voptiming_cfg(OMX_U32 nTimeIncRes); 351 void venc_config_print(); 352 bool venc_set_slice_delivery_mode(OMX_U32 enable); 353 bool venc_set_extradata(OMX_U32 extra_data, OMX_BOOL enable); 354 bool venc_set_idr_period(OMX_U32 nPFrames, OMX_U32 nIDRPeriod); 355 bool venc_reconfig_reqbufs(); 356 bool venc_set_vpe_rotation(OMX_S32 rotation_angle); 357 bool venc_set_deinterlace(OMX_U32 enable); 358 bool venc_set_ltrmode(OMX_U32 enable, OMX_U32 count); 359 bool venc_set_useltr(); 360 bool venc_set_markltr(); 361 bool venc_enable_initial_qp(QOMX_EXTNINDEX_VIDEO_INITIALQP* initqp); 362 bool venc_set_inband_video_header(OMX_BOOL enable); 363 bool venc_set_au_delimiter(OMX_BOOL enable); 364 bool venc_set_hier_layers(QOMX_VIDEO_HIERARCHICALCODINGTYPE type, OMX_U32 num_layers); 365 bool venc_set_perf_level(QOMX_VIDEO_PERF_LEVEL ePerfLevel); 366 bool venc_set_vui_timing_info(OMX_BOOL enable); 367 bool venc_set_peak_bitrate(OMX_U32 nPeakBitrate); 368 bool venc_set_searchrange(); 369 370 #ifdef MAX_RES_1080P 371 OMX_U32 pmem_free(); 372 OMX_U32 pmem_allocate(OMX_U32 size, OMX_U32 alignment, OMX_U32 count); 373 OMX_U32 venc_allocate_recon_buffers(); 374 inline int clip2(int x) { 375 x = x -1; 376 x = x | x >> 1; 377 x = x | x >> 2; 378 x = x | x >> 4; 379 x = x | x >> 16; 380 x = x + 1; 381 return x; 382 } 383 #endif 384 int metadatamode; 385 bool streaming[MAX_PORT]; 386 bool extradata; 387 struct extradata_buffer_info extradata_info; 388 389 pthread_mutex_t pause_resume_mlock; 390 pthread_cond_t pause_resume_cond; 391 bool paused; 392 int color_format; 393 bool is_searchrange_set; 394 bool enable_mv_narrow_searchrange; 395 DisplayInfo display_info; 396 }; 397 398 enum instance_state { 399 MSM_VIDC_CORE_UNINIT_DONE = 0x0001, 400 MSM_VIDC_CORE_INIT, 401 MSM_VIDC_CORE_INIT_DONE, 402 MSM_VIDC_OPEN, 403 MSM_VIDC_OPEN_DONE, 404 MSM_VIDC_LOAD_RESOURCES, 405 MSM_VIDC_LOAD_RESOURCES_DONE, 406 MSM_VIDC_START, 407 MSM_VIDC_START_DONE, 408 MSM_VIDC_STOP, 409 MSM_VIDC_STOP_DONE, 410 MSM_VIDC_RELEASE_RESOURCES, 411 MSM_VIDC_RELEASE_RESOURCES_DONE, 412 MSM_VIDC_CLOSE, 413 MSM_VIDC_CLOSE_DONE, 414 MSM_VIDC_CORE_UNINIT, 415 }; 416 #endif 417 418