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