Home | History | Annotate | Download | only in inc
      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
      6   are met:
      7 
      8     * Redistributions of source code must retain the above copyright
      9   notice, this list of conditions and the following disclaimer.
     10     * Redistributions in binary form must reproduce the above
     11   copyright notice, this list of conditions and the following
     12       disclaimer in the documentation and/or other materials provided
     13       with the distribution.
     14     * Neither the name of The Linux Foundation nor the names of its
     15       contributors may be used to endorse or promote products derived
     16       from this software without specific prior written permission.
     17 
     18 THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
     19 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
     21 ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     25 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     26 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     27 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     28 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 --------------------------------------------------------------------------*/
     30 #ifndef __OMX_VDEC_H__
     31 #define __OMX_VDEC_H__
     32 /*============================================================================
     33                             O p e n M A X   Component
     34                                 Video Decoder
     35 
     36 *//** @file comx_vdec.h
     37   This module contains the class definition for openMAX decoder component.
     38 
     39 *//*========================================================================*/
     40 
     41 //////////////////////////////////////////////////////////////////////////////
     42 //                             Include Files
     43 //////////////////////////////////////////////////////////////////////////////
     44 
     45 #include <stdlib.h>
     46 #include <stdio.h>
     47 #include <string.h>
     48 #include <inttypes.h>
     49 #include <cstddef>
     50 
     51 static ptrdiff_t x;
     52 
     53 #ifdef _ANDROID_
     54 #ifdef MAX_RES_720P
     55 #define LOG_TAG "OMX-VDEC-720P"
     56 #elif MAX_RES_1080P
     57 #define LOG_TAG "OMX-VDEC-1080P"
     58 #else
     59 #define LOG_TAG "OMX-VDEC"
     60 #endif
     61 
     62 #ifdef USE_ION
     63 #include <linux/msm_ion.h>
     64 //#include <binder/MemoryHeapIon.h>
     65 //#else
     66 #endif
     67 #include <binder/MemoryHeapBase.h>
     68 #include <ui/ANativeObjectBase.h>
     69 extern "C" {
     70 #include <utils/Log.h>
     71 }
     72 #include <linux/videodev2.h>
     73 #include <poll.h>
     74 #define TIMEOUT 5000
     75 
     76 #else //_ANDROID_
     77 #define DEBUG_PRINT_LOW printf
     78 #define DEBUG_PRINT_HIGH printf
     79 #define DEBUG_PRINT_ERROR printf
     80 #endif // _ANDROID_
     81 
     82 #ifdef _MSM8974_
     83 #define DEBUG_PRINT_LOW
     84 #define DEBUG_PRINT_HIGH printf
     85 #define DEBUG_PRINT_ERROR printf
     86 #endif
     87 
     88 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
     89 #include <media/hardware/HardwareAPI.h>
     90 #endif
     91 
     92 #include <unistd.h>
     93 
     94 #if defined (_ANDROID_ICS_)
     95 #include <gralloc_priv.h>
     96 #endif
     97 
     98 #include <pthread.h>
     99 #ifndef PC_DEBUG
    100 #include <semaphore.h>
    101 #endif
    102 #include "OMX_Core.h"
    103 #include "OMX_QCOMExtns.h"
    104 #include "qc_omx_component.h"
    105 #include <linux/msm_vidc_dec.h>
    106 #include <media/msm_vidc.h>
    107 #include "frameparser.h"
    108 #ifdef MAX_RES_1080P
    109 #include "mp4_utils.h"
    110 #endif
    111 #include <linux/android_pmem.h>
    112 #include "extra_data_handler.h"
    113 #include "ts_parser.h"
    114 #include "vidc_color_converter.h"
    115 extern "C" {
    116     OMX_API void * get_omx_component_factory_fn(void);
    117 }
    118 
    119 #ifdef _ANDROID_
    120 using namespace android;
    121 #ifdef USE_ION
    122 class VideoHeap : public MemoryHeapBase
    123 {
    124     public:
    125         VideoHeap(int devicefd, size_t size, void* base,struct ion_handle *handle,int mapfd);
    126         virtual ~VideoHeap() {}
    127     private:
    128         int m_ion_device_fd;
    129         struct ion_handle *m_ion_handle;
    130 };
    131 #else
    132 // local pmem heap object
    133 class VideoHeap : public MemoryHeapBase
    134 {
    135     public:
    136         VideoHeap(int fd, size_t size, void* base);
    137         virtual ~VideoHeap() {}
    138 };
    139 #endif
    140 #endif // _ANDROID_
    141 //////////////////////////////////////////////////////////////////////////////
    142 //                       Module specific globals
    143 //////////////////////////////////////////////////////////////////////////////
    144 #define OMX_SPEC_VERSION  0x00000101
    145 
    146 
    147 //////////////////////////////////////////////////////////////////////////////
    148 //               Macros
    149 //////////////////////////////////////////////////////////////////////////////
    150 #define PrintFrameHdr(bufHdr) DEBUG_PRINT("bufHdr %x buf %x size %d TS %d\n",\
    151         (unsigned) bufHdr,\
    152         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->pBuffer,\
    153         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nFilledLen,\
    154         (unsigned)((OMX_BUFFERHEADERTYPE *)bufHdr)->nTimeStamp)
    155 
    156 // BitMask Management logic
    157 #define BITS_PER_BYTE        32
    158 #define BITMASK_SIZE(mIndex) (((mIndex) + BITS_PER_BYTE - 1)/BITS_PER_BYTE)
    159 #define BITMASK_OFFSET(mIndex) ((mIndex)/BITS_PER_BYTE)
    160 #define BITMASK_FLAG(mIndex) (1 << ((mIndex) % BITS_PER_BYTE))
    161 #define BITMASK_CLEAR(mArray,mIndex) (mArray)[BITMASK_OFFSET(mIndex)] \
    162     &=  ~(BITMASK_FLAG(mIndex))
    163 #define BITMASK_SET(mArray,mIndex)  (mArray)[BITMASK_OFFSET(mIndex)] \
    164     |=  BITMASK_FLAG(mIndex)
    165 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
    166         & BITMASK_FLAG(mIndex))
    167 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
    168             & BITMASK_FLAG(mIndex)) == 0x0)
    169 #define BITMASK_PRESENT(mArray,mIndex) ((mArray)[BITMASK_OFFSET(mIndex)] \
    170         & BITMASK_FLAG(mIndex))
    171 #define BITMASK_ABSENT(mArray,mIndex) (((mArray)[BITMASK_OFFSET(mIndex)] \
    172             & BITMASK_FLAG(mIndex)) == 0x0)
    173 
    174 #define OMX_CORE_CONTROL_CMDQ_SIZE   100
    175 #define OMX_CORE_QCIF_HEIGHT         144
    176 #define OMX_CORE_QCIF_WIDTH          176
    177 #define OMX_CORE_VGA_HEIGHT          480
    178 #define OMX_CORE_VGA_WIDTH           640
    179 #define OMX_CORE_WVGA_HEIGHT         480
    180 #define OMX_CORE_WVGA_WIDTH          800
    181 
    182 #define DESC_BUFFER_SIZE (8192 * 16)
    183 
    184 #ifdef _ANDROID_
    185 #define MAX_NUM_INPUT_OUTPUT_BUFFERS 32
    186 #endif
    187 
    188 #define OMX_FRAMEINFO_EXTRADATA 0x00010000
    189 #define OMX_INTERLACE_EXTRADATA 0x00020000
    190 #define OMX_TIMEINFO_EXTRADATA  0x00040000
    191 #define OMX_PORTDEF_EXTRADATA   0x00080000
    192 #define OMX_EXTNUSER_EXTRADATA  0x00100000
    193 #define DRIVER_EXTRADATA_MASK   0x0000FFFF
    194 
    195 #define OMX_INTERLACE_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    196             sizeof(OMX_STREAMINTERLACEFORMAT) + 3)&(~3))
    197 #define OMX_FRAMEINFO_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    198             sizeof(OMX_QCOM_EXTRADATA_FRAMEINFO) + 3)&(~3))
    199 #define OMX_PORTDEF_EXTRADATA_SIZE ((sizeof(OMX_OTHER_EXTRADATATYPE) +\
    200             sizeof(OMX_PARAM_PORTDEFINITIONTYPE) + 3)&(~3))
    201 
    202 //  Define next macro with required values to enable default extradata,
    203 //    VDEC_EXTRADATA_MB_ERROR_MAP
    204 //    OMX_INTERLACE_EXTRADATA
    205 //    OMX_FRAMEINFO_EXTRADATA
    206 //    OMX_TIMEINFO_EXTRADATA
    207 
    208 //#define DEFAULT_EXTRADATA (OMX_FRAMEINFO_EXTRADATA|OMX_INTERLACE_EXTRADATA)
    209 
    210 enum port_indexes {
    211     OMX_CORE_INPUT_PORT_INDEX        =0,
    212     OMX_CORE_OUTPUT_PORT_INDEX       =1
    213 };
    214 #ifdef USE_ION
    215 struct vdec_ion {
    216     int ion_device_fd;
    217     struct ion_fd_data fd_ion_data;
    218     struct ion_allocation_data ion_alloc_data;
    219 };
    220 #endif
    221 
    222 #ifdef _MSM8974_
    223 struct extradata_buffer_info {
    224     int buffer_size;
    225     char* uaddr;
    226     int count;
    227     int size;
    228 #ifdef USE_ION
    229     struct vdec_ion ion;
    230 #endif
    231 };
    232 #endif
    233 
    234 struct video_driver_context {
    235     int video_driver_fd;
    236     enum vdec_codec decoder_format;
    237     enum vdec_output_fromat output_format;
    238     enum vdec_interlaced_format interlace;
    239     enum vdec_output_order picture_order;
    240     struct vdec_picsize video_resolution;
    241     struct vdec_allocatorproperty ip_buf;
    242     struct vdec_allocatorproperty op_buf;
    243     struct vdec_bufferpayload *ptr_inputbuffer;
    244     struct vdec_bufferpayload *ptr_outputbuffer;
    245     struct vdec_output_frameinfo *ptr_respbuffer;
    246 #ifdef USE_ION
    247     struct vdec_ion *ip_buf_ion_info;
    248     struct vdec_ion *op_buf_ion_info;
    249     struct vdec_ion h264_mv;
    250     struct vdec_ion meta_buffer;
    251     struct vdec_ion meta_buffer_iommu;
    252 #endif
    253     struct vdec_framerate frame_rate;
    254     unsigned extradata;
    255     bool timestamp_adjust;
    256     char kind[128];
    257     bool idr_only_decoding;
    258     unsigned disable_dmx;
    259 #ifdef _MSM8974_
    260     struct extradata_buffer_info extradata_info;
    261     int num_planes;
    262 #endif
    263 };
    264 
    265 #ifdef _ANDROID_
    266 class DivXDrmDecrypt;
    267 #endif //_ANDROID_
    268 
    269 struct video_decoder_capability {
    270     unsigned int min_width;
    271     unsigned int max_width;
    272     unsigned int min_height;
    273     unsigned int max_height;
    274 };
    275 
    276 struct dynamic_buf_list {
    277     OMX_U32 fd;
    278     OMX_U32 dup_fd;
    279     OMX_U32 offset;
    280     OMX_U32 ref_count;
    281 };
    282 
    283 // OMX video decoder class
    284 class omx_vdec: public qc_omx_component
    285 {
    286 
    287     public:
    288         omx_vdec();  // constructor
    289         virtual ~omx_vdec();  // destructor
    290 
    291         static int async_message_process (void *context, void* message);
    292         static void process_event_cb(void *ctxt,unsigned char id);
    293 
    294         OMX_ERRORTYPE allocate_buffer(
    295                 OMX_HANDLETYPE hComp,
    296                 OMX_BUFFERHEADERTYPE **bufferHdr,
    297                 OMX_U32 port,
    298                 OMX_PTR appData,
    299                 OMX_U32 bytes
    300                 );
    301 
    302 
    303         OMX_ERRORTYPE component_deinit(OMX_HANDLETYPE hComp);
    304 
    305         OMX_ERRORTYPE component_init(OMX_STRING role);
    306 
    307         OMX_ERRORTYPE component_role_enum(
    308                 OMX_HANDLETYPE hComp,
    309                 OMX_U8 *role,
    310                 OMX_U32 index
    311                 );
    312 
    313         OMX_ERRORTYPE component_tunnel_request(
    314                 OMX_HANDLETYPE hComp,
    315                 OMX_U32 port,
    316                 OMX_HANDLETYPE  peerComponent,
    317                 OMX_U32 peerPort,
    318                 OMX_TUNNELSETUPTYPE *tunnelSetup
    319                 );
    320 
    321         OMX_ERRORTYPE empty_this_buffer(
    322                 OMX_HANDLETYPE hComp,
    323                 OMX_BUFFERHEADERTYPE *buffer
    324                 );
    325 
    326 
    327 
    328         OMX_ERRORTYPE fill_this_buffer(
    329                 OMX_HANDLETYPE hComp,
    330                 OMX_BUFFERHEADERTYPE *buffer
    331                 );
    332 
    333 
    334         OMX_ERRORTYPE free_buffer(
    335                 OMX_HANDLETYPE hComp,
    336                 OMX_U32 port,
    337                 OMX_BUFFERHEADERTYPE *buffer
    338                 );
    339 
    340         OMX_ERRORTYPE get_component_version(
    341                 OMX_HANDLETYPE hComp,
    342                 OMX_STRING componentName,
    343                 OMX_VERSIONTYPE *componentVersion,
    344                 OMX_VERSIONTYPE *specVersion,
    345                 OMX_UUIDTYPE *componentUUID
    346                 );
    347 
    348         OMX_ERRORTYPE get_config(
    349                 OMX_HANDLETYPE hComp,
    350                 OMX_INDEXTYPE configIndex,
    351                 OMX_PTR configData
    352                 );
    353 
    354         OMX_ERRORTYPE get_extension_index(
    355                 OMX_HANDLETYPE hComp,
    356                 OMX_STRING paramName,
    357                 OMX_INDEXTYPE *indexType
    358                 );
    359 
    360         OMX_ERRORTYPE get_parameter(OMX_HANDLETYPE hComp,
    361                 OMX_INDEXTYPE  paramIndex,
    362                 OMX_PTR        paramData);
    363 
    364         OMX_ERRORTYPE get_state(OMX_HANDLETYPE hComp,
    365                 OMX_STATETYPE *state);
    366 
    367 
    368 
    369         OMX_ERRORTYPE send_command(OMX_HANDLETYPE  hComp,
    370                 OMX_COMMANDTYPE cmd,
    371                 OMX_U32         param1,
    372                 OMX_PTR         cmdData);
    373 
    374 
    375         OMX_ERRORTYPE set_callbacks(OMX_HANDLETYPE   hComp,
    376                 OMX_CALLBACKTYPE *callbacks,
    377                 OMX_PTR          appData);
    378 
    379         OMX_ERRORTYPE set_config(OMX_HANDLETYPE hComp,
    380                 OMX_INDEXTYPE  configIndex,
    381                 OMX_PTR        configData);
    382 
    383         OMX_ERRORTYPE set_parameter(OMX_HANDLETYPE hComp,
    384                 OMX_INDEXTYPE  paramIndex,
    385                 OMX_PTR        paramData);
    386 
    387         OMX_ERRORTYPE use_buffer(OMX_HANDLETYPE      hComp,
    388                 OMX_BUFFERHEADERTYPE **bufferHdr,
    389                 OMX_U32              port,
    390                 OMX_PTR              appData,
    391                 OMX_U32              bytes,
    392                 OMX_U8               *buffer);
    393 
    394         OMX_ERRORTYPE  use_input_heap_buffers(
    395                 OMX_HANDLETYPE            hComp,
    396                 OMX_BUFFERHEADERTYPE** bufferHdr,
    397                 OMX_U32                   port,
    398                 OMX_PTR                   appData,
    399                 OMX_U32                   bytes,
    400                 OMX_U8*                   buffer);
    401 
    402         OMX_ERRORTYPE use_EGL_image(OMX_HANDLETYPE     hComp,
    403                 OMX_BUFFERHEADERTYPE **bufferHdr,
    404                 OMX_U32              port,
    405                 OMX_PTR              appData,
    406                 void *               eglImage);
    407         void complete_pending_buffer_done_cbs();
    408         struct video_driver_context drv_ctx;
    409 #ifdef _MSM8974_
    410         OMX_ERRORTYPE allocate_extradata();
    411         void free_extradata();
    412         int update_resolution(int width, int height, int stride, int scan_lines);
    413         OMX_ERRORTYPE is_video_session_supported();
    414 #endif
    415         int  m_pipe_in;
    416         int  m_pipe_out;
    417         pthread_t msg_thread_id;
    418         pthread_t async_thread_id;
    419         bool is_component_secure();
    420         void buf_ref_add(OMX_U32 fd, OMX_U32 offset);
    421         void buf_ref_remove(OMX_U32 fd, OMX_U32 offset);
    422 
    423     private:
    424         // Bit Positions
    425         enum flags_bit_positions {
    426             // Defer transition to IDLE
    427             OMX_COMPONENT_IDLE_PENDING            =0x1,
    428             // Defer transition to LOADING
    429             OMX_COMPONENT_LOADING_PENDING         =0x2,
    430             // First  Buffer Pending
    431             OMX_COMPONENT_FIRST_BUFFER_PENDING    =0x3,
    432             // Second Buffer Pending
    433             OMX_COMPONENT_SECOND_BUFFER_PENDING   =0x4,
    434             // Defer transition to Enable
    435             OMX_COMPONENT_INPUT_ENABLE_PENDING    =0x5,
    436             // Defer transition to Enable
    437             OMX_COMPONENT_OUTPUT_ENABLE_PENDING   =0x6,
    438             // Defer transition to Disable
    439             OMX_COMPONENT_INPUT_DISABLE_PENDING   =0x7,
    440             // Defer transition to Disable
    441             OMX_COMPONENT_OUTPUT_DISABLE_PENDING  =0x8,
    442             //defer flush notification
    443             OMX_COMPONENT_OUTPUT_FLUSH_PENDING    =0x9,
    444             OMX_COMPONENT_INPUT_FLUSH_PENDING    =0xA,
    445             OMX_COMPONENT_PAUSE_PENDING          =0xB,
    446             OMX_COMPONENT_EXECUTE_PENDING        =0xC,
    447             OMX_COMPONENT_OUTPUT_FLUSH_IN_DISABLE_PENDING =0xD,
    448             OMX_COMPONENT_DISABLE_OUTPUT_DEFERRED=0xE
    449         };
    450 
    451         // Deferred callback identifiers
    452         enum {
    453             //Event Callbacks from the vdec component thread context
    454             OMX_COMPONENT_GENERATE_EVENT       = 0x1,
    455             //Buffer Done callbacks from the vdec component thread context
    456             OMX_COMPONENT_GENERATE_BUFFER_DONE = 0x2,
    457             //Frame Done callbacks from the vdec component thread context
    458             OMX_COMPONENT_GENERATE_FRAME_DONE  = 0x3,
    459             //Buffer Done callbacks from the vdec component thread context
    460             OMX_COMPONENT_GENERATE_FTB         = 0x4,
    461             //Frame Done callbacks from the vdec component thread context
    462             OMX_COMPONENT_GENERATE_ETB         = 0x5,
    463             //Command
    464             OMX_COMPONENT_GENERATE_COMMAND     = 0x6,
    465             //Push-Pending Buffers
    466             OMX_COMPONENT_PUSH_PENDING_BUFS    = 0x7,
    467             // Empty Buffer Done callbacks
    468             OMX_COMPONENT_GENERATE_EBD         = 0x8,
    469             //Flush Event Callbacks from the vdec component thread context
    470             OMX_COMPONENT_GENERATE_EVENT_FLUSH       = 0x9,
    471             OMX_COMPONENT_GENERATE_EVENT_INPUT_FLUSH = 0x0A,
    472             OMX_COMPONENT_GENERATE_EVENT_OUTPUT_FLUSH = 0x0B,
    473             OMX_COMPONENT_GENERATE_FBD = 0xc,
    474             OMX_COMPONENT_GENERATE_START_DONE = 0xD,
    475             OMX_COMPONENT_GENERATE_PAUSE_DONE = 0xE,
    476             OMX_COMPONENT_GENERATE_RESUME_DONE = 0xF,
    477             OMX_COMPONENT_GENERATE_STOP_DONE = 0x10,
    478             OMX_COMPONENT_GENERATE_HARDWARE_ERROR = 0x11,
    479             OMX_COMPONENT_GENERATE_ETB_ARBITRARY = 0x12,
    480             OMX_COMPONENT_GENERATE_PORT_RECONFIG = 0x13,
    481             OMX_COMPONENT_GENERATE_EOS_DONE = 0x14,
    482             OMX_COMPONENT_GENERATE_INFO_PORT_RECONFIG = 0x15,
    483             OMX_COMPONENT_GENERATE_INFO_FIELD_DROPPED = 0x16,
    484             OMX_COMPONENT_GENERATE_UNSUPPORTED_SETTING = 0x17,
    485         };
    486 
    487         enum vc1_profile_type {
    488             VC1_SP_MP_RCV = 1,
    489             VC1_AP = 2
    490         };
    491 
    492 #ifdef _MSM8974_
    493         enum v4l2_ports {
    494             CAPTURE_PORT,
    495             OUTPUT_PORT,
    496             MAX_PORT
    497         };
    498 #endif
    499 
    500         struct omx_event {
    501             unsigned param1;
    502             unsigned param2;
    503             unsigned id;
    504         };
    505 
    506         struct omx_cmd_queue {
    507             omx_event m_q[OMX_CORE_CONTROL_CMDQ_SIZE];
    508             unsigned m_read;
    509             unsigned m_write;
    510             unsigned m_size;
    511 
    512             omx_cmd_queue();
    513             ~omx_cmd_queue();
    514             bool insert_entry(unsigned p1, unsigned p2, unsigned id);
    515             bool pop_entry(unsigned *p1,unsigned *p2, unsigned *id);
    516             // get msgtype of the first ele from the queue
    517             unsigned get_q_msg_type();
    518 
    519         };
    520 
    521 #ifdef _ANDROID_
    522         struct ts_entry {
    523             OMX_TICKS timestamp;
    524             bool valid;
    525         };
    526 
    527         struct ts_arr_list {
    528             ts_entry m_ts_arr_list[MAX_NUM_INPUT_OUTPUT_BUFFERS];
    529 
    530             ts_arr_list();
    531             ~ts_arr_list();
    532 
    533             bool insert_ts(OMX_TICKS ts);
    534             bool pop_min_ts(OMX_TICKS &ts);
    535             bool reset_ts_list();
    536         };
    537 #endif
    538 
    539         struct desc_buffer_hdr {
    540             OMX_U8 *buf_addr;
    541             OMX_U32 desc_data_size;
    542         };
    543         bool allocate_done(void);
    544         bool allocate_input_done(void);
    545         bool allocate_output_done(void);
    546 
    547         OMX_ERRORTYPE free_input_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
    548         OMX_ERRORTYPE free_input_buffer(unsigned int bufferindex,
    549                 OMX_BUFFERHEADERTYPE *pmem_bufferHdr);
    550         OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
    551         void free_output_buffer_header();
    552         void free_input_buffer_header();
    553 
    554         OMX_ERRORTYPE allocate_input_heap_buffer(OMX_HANDLETYPE       hComp,
    555                 OMX_BUFFERHEADERTYPE **bufferHdr,
    556                 OMX_U32              port,
    557                 OMX_PTR              appData,
    558                 OMX_U32              bytes);
    559 
    560 
    561         OMX_ERRORTYPE allocate_input_buffer(OMX_HANDLETYPE       hComp,
    562                 OMX_BUFFERHEADERTYPE **bufferHdr,
    563                 OMX_U32              port,
    564                 OMX_PTR              appData,
    565                 OMX_U32              bytes);
    566 
    567         OMX_ERRORTYPE allocate_output_buffer(OMX_HANDLETYPE       hComp,
    568                 OMX_BUFFERHEADERTYPE **bufferHdr,
    569                 OMX_U32 port,OMX_PTR appData,
    570                 OMX_U32              bytes);
    571         OMX_ERRORTYPE use_output_buffer(OMX_HANDLETYPE hComp,
    572                 OMX_BUFFERHEADERTYPE   **bufferHdr,
    573                 OMX_U32                port,
    574                 OMX_PTR                appData,
    575                 OMX_U32                bytes,
    576                 OMX_U8                 *buffer);
    577 #ifdef MAX_RES_720P
    578         OMX_ERRORTYPE get_supported_profile_level_for_720p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType);
    579 #endif
    580 #ifdef MAX_RES_1080P
    581         OMX_ERRORTYPE get_supported_profile_level_for_1080p(OMX_VIDEO_PARAM_PROFILELEVELTYPE *profileLevelType);
    582 #endif
    583 
    584         OMX_ERRORTYPE allocate_desc_buffer(OMX_U32 index);
    585         OMX_ERRORTYPE allocate_output_headers();
    586         bool execute_omx_flush(OMX_U32);
    587         bool execute_output_flush();
    588         bool execute_input_flush();
    589         OMX_ERRORTYPE empty_buffer_done(OMX_HANDLETYPE hComp,
    590                 OMX_BUFFERHEADERTYPE * buffer);
    591 
    592         OMX_ERRORTYPE fill_buffer_done(OMX_HANDLETYPE hComp,
    593                 OMX_BUFFERHEADERTYPE * buffer);
    594         OMX_ERRORTYPE empty_this_buffer_proxy(OMX_HANDLETYPE       hComp,
    595                 OMX_BUFFERHEADERTYPE *buffer);
    596 
    597         OMX_ERRORTYPE empty_this_buffer_proxy_arbitrary(OMX_HANDLETYPE hComp,
    598                 OMX_BUFFERHEADERTYPE *buffer
    599                 );
    600 
    601         OMX_ERRORTYPE push_input_buffer (OMX_HANDLETYPE hComp);
    602         OMX_ERRORTYPE push_input_sc_codec (OMX_HANDLETYPE hComp);
    603         OMX_ERRORTYPE push_input_h264 (OMX_HANDLETYPE hComp);
    604         OMX_ERRORTYPE push_input_vc1 (OMX_HANDLETYPE hComp);
    605 
    606         OMX_ERRORTYPE fill_this_buffer_proxy(OMX_HANDLETYPE       hComp,
    607                 OMX_BUFFERHEADERTYPE *buffer);
    608         bool release_done();
    609 
    610         bool release_output_done();
    611         bool release_input_done();
    612         OMX_ERRORTYPE get_buffer_req(vdec_allocatorproperty *buffer_prop);
    613         OMX_ERRORTYPE set_buffer_req(vdec_allocatorproperty *buffer_prop);
    614         OMX_ERRORTYPE start_port_reconfig();
    615         OMX_ERRORTYPE update_picture_resolution();
    616         int stream_off(OMX_U32 port);
    617         void adjust_timestamp(OMX_S64 &act_timestamp);
    618         void set_frame_rate(OMX_S64 act_timestamp);
    619         void handle_extradata_secure(OMX_BUFFERHEADERTYPE *p_buf_hdr);
    620         void handle_extradata(OMX_BUFFERHEADERTYPE *p_buf_hdr);
    621         void print_debug_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    622 #ifdef _MSM8974_
    623         void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    624                 OMX_U32 interlaced_format_type);
    625         OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool is_internal,
    626                 bool enable = true);
    627         void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    628                 OMX_U32 num_conceal_mb,
    629                 OMX_U32 picture_type,
    630                 OMX_U32 frame_rate,
    631                 struct msm_vidc_panscan_window_payload *panscan_payload,
    632                 struct vdec_aspectratioinfo *aspect_ratio_info);
    633 #else
    634         void append_interlace_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    635                 OMX_U32 interlaced_format_type, OMX_U32 buf_index);
    636         OMX_ERRORTYPE enable_extradata(OMX_U32 requested_extradata, bool enable = true);
    637 #endif
    638         void append_frame_info_extradata(OMX_OTHER_EXTRADATATYPE *extra,
    639                 OMX_U32 num_conceal_mb,
    640                 OMX_U32 picture_type,
    641                 OMX_S64 timestamp,
    642                 OMX_U32 frame_rate,
    643                 struct vdec_aspectratioinfo *aspect_ratio_info);
    644         void fill_aspect_ratio_info(struct vdec_aspectratioinfo *aspect_ratio_info,
    645                 OMX_QCOM_EXTRADATA_FRAMEINFO *frame_info);
    646         void append_terminator_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    647         OMX_ERRORTYPE update_portdef(OMX_PARAM_PORTDEFINITIONTYPE *portDefn);
    648         void append_portdef_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    649         void append_extn_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_extn);
    650         void append_user_extradata(OMX_OTHER_EXTRADATATYPE *extra, OMX_OTHER_EXTRADATATYPE *p_user);
    651         void insert_demux_addr_offset(OMX_U32 address_offset);
    652         void extract_demux_addr_offsets(OMX_BUFFERHEADERTYPE *buf_hdr);
    653         OMX_ERRORTYPE handle_demux_data(OMX_BUFFERHEADERTYPE *buf_hdr);
    654         OMX_U32 count_MB_in_extradata(OMX_OTHER_EXTRADATATYPE *extra);
    655 
    656         bool align_pmem_buffers(int pmem_fd, OMX_U32 buffer_size,
    657                 OMX_U32 alignment);
    658 #ifdef USE_ION
    659         int alloc_map_ion_memory(OMX_U32 buffer_size,
    660                 OMX_U32 alignment, struct ion_allocation_data *alloc_data,
    661                 struct ion_fd_data *fd_data,int flag);
    662         void free_ion_memory(struct vdec_ion *buf_ion_info);
    663 #endif
    664 
    665 
    666         OMX_ERRORTYPE send_command_proxy(OMX_HANDLETYPE  hComp,
    667                 OMX_COMMANDTYPE cmd,
    668                 OMX_U32         param1,
    669                 OMX_PTR         cmdData);
    670         bool post_event( unsigned int p1,
    671                 unsigned int p2,
    672                 unsigned int id
    673                    );
    674         inline int clip2(int x) {
    675             x = x -1;
    676             x = x | x >> 1;
    677             x = x | x >> 2;
    678             x = x | x >> 4;
    679             x = x | x >> 16;
    680             x = x + 1;
    681             return x;
    682         }
    683 
    684 #ifdef MAX_RES_1080P
    685         OMX_ERRORTYPE vdec_alloc_h264_mv();
    686         void vdec_dealloc_h264_mv();
    687         OMX_ERRORTYPE vdec_alloc_meta_buffers();
    688         void vdec_dealloc_meta_buffers();
    689 #endif
    690 
    691         inline void omx_report_error () {
    692             if (m_cb.EventHandler && !m_error_propogated) {
    693                 ALOGE("\nERROR: Sending OMX_EventError to Client");
    694                 m_error_propogated = true;
    695                 m_cb.EventHandler(&m_cmp,m_app_data,
    696                         OMX_EventError,OMX_ErrorHardware,0,NULL);
    697             }
    698         }
    699 
    700         inline void omx_report_unsupported_setting () {
    701             if (m_cb.EventHandler && !m_error_propogated) {
    702                 DEBUG_PRINT_ERROR(
    703                         "\nERROR: Sending OMX_ErrorUnsupportedSetting to Client");
    704                 m_error_propogated = true;
    705                 m_cb.EventHandler(&m_cmp,m_app_data,
    706                         OMX_EventError,OMX_ErrorUnsupportedSetting,0,NULL);
    707             }
    708         }
    709 #ifdef _ANDROID_
    710         OMX_ERRORTYPE createDivxDrmContext();
    711 #endif //_ANDROID_
    712 #if defined (_ANDROID_HONEYCOMB_) || defined (_ANDROID_ICS_)
    713         OMX_ERRORTYPE use_android_native_buffer(OMX_IN OMX_HANDLETYPE hComp, OMX_PTR data);
    714 #endif
    715 #if defined (_ANDROID_ICS_)
    716         struct nativebuffer {
    717             native_handle_t *nativehandle;
    718             private_handle_t *privatehandle;
    719             int inuse;
    720         };
    721         nativebuffer native_buffer[MAX_NUM_INPUT_OUTPUT_BUFFERS];
    722 #endif
    723 
    724         class auto_lock {
    725             public:
    726             auto_lock(pthread_mutex_t *lock)
    727                 : mLock(lock) {
    728                 if (mLock)
    729                     pthread_mutex_lock(mLock);
    730             }
    731             ~auto_lock() {
    732                 if (mLock)
    733                     pthread_mutex_unlock(mLock);
    734             }
    735             private:
    736             pthread_mutex_t *mLock;
    737         };
    738         //*************************************************************
    739         //*******************MEMBER VARIABLES *************************
    740         //*************************************************************
    741         pthread_mutex_t       m_lock;
    742         pthread_mutex_t       c_lock;
    743         pthread_mutex_t       e_lock;
    744         //sem to handle the minimum procesing of commands
    745         sem_t                 m_cmd_lock;
    746         bool              m_error_propogated;
    747         // compression format
    748         OMX_VIDEO_CODINGTYPE eCompressionFormat;
    749         // OMX State
    750         OMX_STATETYPE m_state;
    751         // Application data
    752         OMX_PTR m_app_data;
    753         // Application callbacks
    754         OMX_CALLBACKTYPE m_cb;
    755         OMX_PRIORITYMGMTTYPE m_priority_mgm ;
    756         OMX_PARAM_BUFFERSUPPLIERTYPE m_buffer_supplier;
    757         // fill this buffer queue
    758         omx_cmd_queue         m_ftb_q;
    759         // Command Q for rest of the events
    760         omx_cmd_queue         m_cmd_q;
    761         omx_cmd_queue         m_etb_q;
    762         // Input memory pointer
    763         OMX_BUFFERHEADERTYPE  *m_inp_mem_ptr;
    764         // Output memory pointer
    765         OMX_BUFFERHEADERTYPE  *m_out_mem_ptr;
    766         // number of input bitstream error frame count
    767         unsigned int m_inp_err_count;
    768 #ifdef _ANDROID_
    769         // Timestamp list
    770         ts_arr_list           m_timestamp_list;
    771 #endif
    772 
    773         bool input_flush_progress;
    774         bool output_flush_progress;
    775         bool input_use_buffer;
    776         bool output_use_buffer;
    777         bool ouput_egl_buffers;
    778         OMX_BOOL m_use_output_pmem;
    779         OMX_BOOL m_out_mem_region_smi;
    780         OMX_BOOL m_out_pvt_entry_pmem;
    781 
    782         int pending_input_buffers;
    783         int pending_output_buffers;
    784         // bitmask array size for output side
    785         unsigned int m_out_bm_count;
    786         // bitmask array size for input side
    787         unsigned int m_inp_bm_count;
    788         //Input port Populated
    789         OMX_BOOL m_inp_bPopulated;
    790         //Output port Populated
    791         OMX_BOOL m_out_bPopulated;
    792         // encapsulate the waiting states.
    793         unsigned int m_flags;
    794 
    795 #ifdef _ANDROID_
    796         // Heap pointer to frame buffers
    797         struct vidc_heap {
    798             sp<MemoryHeapBase>    video_heap_ptr;
    799         };
    800         struct vidc_heap *m_heap_ptr;
    801         unsigned int m_heap_count;
    802 #endif //_ANDROID_
    803         // store I/P PORT state
    804         OMX_BOOL m_inp_bEnabled;
    805         // store O/P PORT state
    806         OMX_BOOL m_out_bEnabled;
    807         OMX_U32 m_in_alloc_cnt;
    808         OMX_U8                m_cRole[OMX_MAX_STRINGNAME_SIZE];
    809         // Platform specific details
    810         OMX_QCOM_PLATFORM_PRIVATE_LIST      *m_platform_list;
    811         OMX_QCOM_PLATFORM_PRIVATE_ENTRY     *m_platform_entry;
    812         OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO *m_pmem_info;
    813         // SPS+PPS sent as part of set_config
    814         OMX_VENDOR_EXTRADATATYPE            m_vendor_config;
    815 
    816         /*Variables for arbitrary Byte parsing support*/
    817         frame_parse m_frame_parser;
    818         omx_cmd_queue m_input_pending_q;
    819         omx_cmd_queue m_input_free_q;
    820         bool arbitrary_bytes;
    821         OMX_BUFFERHEADERTYPE  h264_scratch;
    822         OMX_BUFFERHEADERTYPE  *psource_frame;
    823         OMX_BUFFERHEADERTYPE  *pdest_frame;
    824         OMX_BUFFERHEADERTYPE  *m_inp_heap_ptr;
    825         OMX_BUFFERHEADERTYPE  **m_phdr_pmem_ptr;
    826         unsigned int m_heap_inp_bm_count;
    827         codec_type codec_type_parse;
    828         bool first_frame_meta;
    829         unsigned frame_count;
    830         unsigned nal_count;
    831         unsigned nal_length;
    832         bool look_ahead_nal;
    833         int first_frame;
    834         unsigned char *first_buffer;
    835         int first_frame_size;
    836         unsigned char m_hwdevice_name[80];
    837         FILE *m_device_file_ptr;
    838         enum vc1_profile_type m_vc1_profile;
    839         OMX_S64 h264_last_au_ts;
    840         OMX_U32 h264_last_au_flags;
    841         OMX_U32 m_demux_offsets[8192];
    842         OMX_U32 m_demux_entries;
    843         OMX_U32 m_disp_hor_size;
    844         OMX_U32 m_disp_vert_size;
    845 
    846         OMX_S64 prev_ts;
    847         bool rst_prev_ts;
    848         OMX_U32 frm_int;
    849 
    850         struct vdec_allocatorproperty op_buf_rcnfg;
    851         bool in_reconfig;
    852         OMX_NATIVE_WINDOWTYPE m_display_id;
    853         h264_stream_parser *h264_parser;
    854         OMX_U32 client_extradata;
    855 #ifdef _ANDROID_
    856         bool m_debug_timestamp;
    857         bool perf_flag;
    858         OMX_U32 proc_frms, latency;
    859         perf_metrics fps_metrics;
    860         perf_metrics dec_time;
    861         bool m_enable_android_native_buffers;
    862         bool m_use_android_native_buffers;
    863         bool m_debug_extradata;
    864         bool m_debug_concealedmb;
    865         bool m_reject_avc_1080p_mp;
    866 #endif
    867 #ifdef MAX_RES_1080P
    868         MP4_Utils mp4_headerparser;
    869 #endif
    870 
    871         struct h264_mv_buffer {
    872             unsigned char* buffer;
    873             int size;
    874             int count;
    875             int pmem_fd;
    876             int offset;
    877         };
    878         h264_mv_buffer h264_mv_buff;
    879 
    880         struct meta_buffer {
    881             unsigned char* buffer;
    882             int size;
    883             int count;
    884             int pmem_fd;
    885             int pmem_fd_iommu;
    886             int offset;
    887         };
    888         meta_buffer meta_buff;
    889         extra_data_handler extra_data_handle;
    890 #ifdef _ANDROID_
    891         DivXDrmDecrypt* iDivXDrmDecrypt;
    892 #endif //_ANDROID_
    893         OMX_PARAM_PORTDEFINITIONTYPE m_port_def;
    894         omx_time_stamp_reorder time_stamp_dts;
    895         desc_buffer_hdr *m_desc_buffer_ptr;
    896         bool secure_mode;
    897         bool external_meta_buffer;
    898         bool external_meta_buffer_iommu;
    899         OMX_QCOM_EXTRADATA_FRAMEINFO *m_extradata;
    900         bool codec_config_flag;
    901 #ifdef _MSM8974_
    902         int capture_capability;
    903         int output_capability;
    904         bool streaming[MAX_PORT];
    905         OMX_CONFIG_RECTTYPE rectangle;
    906         int prev_n_filled_len;
    907 #endif
    908         bool m_power_hinted;
    909         OMX_ERRORTYPE power_module_register();
    910         OMX_ERRORTYPE power_module_deregister();
    911         bool msg_thread_created;
    912         bool async_thread_created;
    913 
    914         OMX_VIDEO_PARAM_PROFILELEVELTYPE m_profile_lvl;
    915         OMX_U32 m_profile;
    916 
    917         //variables to handle dynamic buffer mode
    918         bool dynamic_buf_mode;
    919         struct dynamic_buf_list *out_dynamic_list;
    920 
    921         //added for smoothstreaming
    922         bool mInSmoothstreamingMode;
    923 
    924         unsigned int m_fill_output_msg;
    925         bool client_set_fps;
    926         class allocate_color_convert_buf
    927         {
    928             public:
    929                 allocate_color_convert_buf();
    930                 ~allocate_color_convert_buf();
    931                 void set_vdec_client(void *);
    932                 void update_client();
    933                 bool set_color_format(OMX_COLOR_FORMATTYPE dest_color_format);
    934                 bool get_color_format(OMX_COLOR_FORMATTYPE &dest_color_format);
    935                 bool update_buffer_req();
    936                 bool get_buffer_req(unsigned int &buffer_size);
    937                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr();
    938                 OMX_BUFFERHEADERTYPE* get_il_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
    939                 OMX_BUFFERHEADERTYPE* get_dr_buf_hdr(OMX_BUFFERHEADERTYPE *input_hdr);
    940                 OMX_BUFFERHEADERTYPE* convert(OMX_BUFFERHEADERTYPE *header);
    941                 OMX_BUFFERHEADERTYPE* queue_buffer(OMX_BUFFERHEADERTYPE *header);
    942                 OMX_ERRORTYPE allocate_buffers_color_convert(OMX_HANDLETYPE hComp,
    943                         OMX_BUFFERHEADERTYPE **bufferHdr,OMX_U32 port,OMX_PTR appData,
    944                         OMX_U32 bytes);
    945                 OMX_ERRORTYPE free_output_buffer(OMX_BUFFERHEADERTYPE *bufferHdr);
    946             private:
    947 #define MAX_COUNT 32
    948                 omx_vdec *omx;
    949                 bool enabled;
    950                 OMX_COLOR_FORMATTYPE ColorFormat;
    951                 void init_members();
    952                 bool color_convert_mode;
    953                 ColorConvertFormat dest_format;
    954                 class omx_c2d_conv c2d;
    955                 unsigned int allocated_count;
    956                 unsigned int buffer_size_req;
    957                 unsigned int buffer_alignment_req;
    958                 OMX_QCOM_PLATFORM_PRIVATE_LIST      m_platform_list_client[MAX_COUNT];
    959                 OMX_QCOM_PLATFORM_PRIVATE_ENTRY     m_platform_entry_client[MAX_COUNT];
    960                 OMX_QCOM_PLATFORM_PRIVATE_PMEM_INFO m_pmem_info_client[MAX_COUNT];
    961                 OMX_BUFFERHEADERTYPE  m_out_mem_ptr_client[MAX_COUNT];
    962 #ifdef USE_ION
    963                 struct vdec_ion op_buf_ion_info[MAX_COUNT];
    964 #endif
    965                 unsigned char *pmem_baseaddress[MAX_COUNT];
    966                 int pmem_fd[MAX_COUNT];
    967                 struct vidc_heap {
    968                     sp<MemoryHeapBase>    video_heap_ptr;
    969                 };
    970                 struct vidc_heap m_heap_ptr[MAX_COUNT];
    971         };
    972 #if  defined (_MSM8960_) || defined (_MSM8974_)
    973         allocate_color_convert_buf client_buffers;
    974 #endif
    975         struct video_decoder_capability m_decoder_capability;
    976 #ifdef _MSM8974_
    977         void send_codec_config();
    978 #endif
    979 };
    980 
    981 #ifdef _MSM8974_
    982 enum instance_state {
    983     MSM_VIDC_CORE_UNINIT_DONE = 0x0001,
    984     MSM_VIDC_CORE_INIT,
    985     MSM_VIDC_CORE_INIT_DONE,
    986     MSM_VIDC_OPEN,
    987     MSM_VIDC_OPEN_DONE,
    988     MSM_VIDC_LOAD_RESOURCES,
    989     MSM_VIDC_LOAD_RESOURCES_DONE,
    990     MSM_VIDC_START,
    991     MSM_VIDC_START_DONE,
    992     MSM_VIDC_STOP,
    993     MSM_VIDC_STOP_DONE,
    994     MSM_VIDC_RELEASE_RESOURCES,
    995     MSM_VIDC_RELEASE_RESOURCES_DONE,
    996     MSM_VIDC_CLOSE,
    997     MSM_VIDC_CLOSE_DONE,
    998     MSM_VIDC_CORE_UNINIT,
    999 };
   1000 
   1001 enum vidc_resposes_id {
   1002     MSM_VIDC_DECODER_FLUSH_DONE = 0x11,
   1003     MSM_VIDC_DECODER_EVENT_CHANGE,
   1004 };
   1005 
   1006 #endif // _MSM8974_
   1007 
   1008 #endif // __OMX_VDEC_H__
   1009