Home | History | Annotate | Download | only in inc
      1 /*--------------------------------------------------------------------------
      2 Copyright (c) 2010-2012, 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 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 <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_stop_done(void);
     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   OMX_U32 m_nDriver_fd;
     82   bool m_profile_set;
     83   bool m_level_set;
     84   pthread_mutex_t loaded_start_stop_mlock;
     85   pthread_cond_t loaded_start_stop_cond;
     86 
     87   struct recon_buffer {
     88 	  unsigned char* virtual_address;
     89 	  int pmem_fd;
     90 	  int size;
     91 	  int alignment;
     92 	  int offset;
     93 #ifdef USE_ION
     94           int ion_device_fd;
     95           struct ion_allocation_data alloc_data;
     96           struct ion_fd_data ion_alloc_fd;
     97 #endif
     98 	  };
     99 
    100   recon_buffer recon_buff[MAX_RECON_BUFFERS];
    101   int recon_buffers_count;
    102   bool m_max_allowed_bitrate_check;
    103   int m_eProfile;
    104   int m_eLevel;
    105   int etb_count;
    106 private:
    107   class omx_venc *venc_encoder;
    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_multiclicecfg       multislice;
    120   struct venc_entropycfg          entropy;
    121   struct venc_dbcfg               dbkfilter;
    122   struct venc_intrarefresh        intra_refresh;
    123   struct venc_headerextension     hec;
    124   struct venc_voptimingcfg        voptimecfg;
    125   struct venc_seqheader           seqhdr;
    126 
    127   bool venc_set_profile_level(OMX_U32 eProfile,OMX_U32 eLevel);
    128   bool venc_set_intra_period(OMX_U32 nPFrames, OMX_U32 nBFrames);
    129   bool venc_set_target_bitrate(OMX_U32 nTargetBitrate, OMX_U32 config);
    130   bool venc_set_ratectrl_cfg(OMX_VIDEO_CONTROLRATETYPE eControlRate);
    131   bool venc_set_session_qp(OMX_U32 i_frame_qp, OMX_U32 p_frame_qp);
    132   bool venc_set_extradata(OMX_U32 extra_data);
    133   bool venc_set_encode_framerate(OMX_U32 encode_framerate, OMX_U32 config);
    134   bool venc_set_intra_vop_refresh(OMX_BOOL intra_vop_refresh);
    135   bool venc_set_color_format(OMX_COLOR_FORMATTYPE color_format);
    136   bool venc_validate_profile_level(OMX_U32 *eProfile, OMX_U32 *eLevel);
    137   bool venc_set_multislice_cfg(OMX_INDEXTYPE codec, OMX_U32 slicesize);
    138   bool venc_set_entropy_config(OMX_BOOL enable, OMX_U32 i_cabac_level);
    139   bool venc_set_inloop_filter(OMX_VIDEO_AVCLOOPFILTERTYPE loop_filter);
    140   bool venc_set_intra_refresh (OMX_VIDEO_INTRAREFRESHTYPE intrarefresh, OMX_U32 nMBs);
    141   bool venc_set_error_resilience(OMX_VIDEO_PARAM_ERRORCORRECTIONTYPE* error_resilience);
    142   bool venc_set_voptiming_cfg(OMX_U32 nTimeIncRes);
    143   void venc_config_print();
    144   bool venc_set_slice_delivery_mode(OMX_BOOL enable);
    145   bool venc_set_inband_video_header(OMX_BOOL enable);
    146   bool venc_set_bitstream_restrict_in_vui(OMX_BOOL enable);
    147 #ifdef MAX_RES_1080P
    148   OMX_U32 pmem_free();
    149   OMX_U32 pmem_allocate(OMX_U32 size, OMX_U32 alignment, OMX_U32 count);
    150   OMX_U32 venc_allocate_recon_buffers();
    151   inline int clip2(int x)
    152   {
    153 	  x = x -1;
    154 	  x = x | x >> 1;
    155 	  x = x | x >> 2;
    156 	  x = x | x >> 4;
    157 	  x = x | x >> 16;
    158 	  x = x + 1;
    159 	  return x;
    160   }
    161 #endif
    162 };
    163 
    164 #endif
    165