Home | History | Annotate | Download | only in inc
      1 /*
      2  * Copyright (C) Texas Instruments - http://www.ti.com/
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Lesser General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2.1 of the License, or (at your option) any later version.
      8  *
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Lesser General Public License for more details.
     14  *
     15  *
     16  * You should have received a copy of the GNU Lesser General Public
     17  * License along with this library; if not, write to the Free Software
     18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     19  */
     20 
     21 #ifndef OMX_VIDDEC_UTILS__H
     22 #define OMX_VIDDEC_UTILS__H
     23 
     24 #define newmalloc(x) malloc(x)
     25 #define newfree(z) free(z)
     26 #ifdef ANDROID
     27 /* Log for Android system*/
     28 #include <utils/Log.h>
     29 #define LOG_TAG "TI_Video_Decoder"
     30 #endif
     31 #include <cutils/properties.h>
     32 
     33 #ifdef UNDER_CE
     34     #include <windows.h>
     35     #include <oaf_osal.h>
     36     #include <omx_core.h>
     37     #include <pthread.h>
     38     #include <stdlib.h>
     39 #else
     40     #define _XOPEN_SOURCE 600
     41     #include <sys/select.h>
     42     #include <signal.h>
     43     #include <pthread.h>
     44     #include <wchar.h>
     45     #include <unistd.h>
     46     #include <sys/types.h>
     47     #include <malloc.h>
     48     #include <memory.h>
     49     #include <sys/wait.h>
     50     #include <sys/types.h>
     51     #include <sys/stat.h>
     52     #include <fcntl.h>
     53     #include <dbapi.h>
     54     #include <string.h>
     55     #include <stdio.h>
     56     #include <dlfcn.h>
     57     #include <stdarg.h>
     58     #include <errno.h>
     59     #include <sys/ioctl.h>
     60     #include <sys/time.h>
     61     #include <stdlib.h>
     62     #include <semaphore.h>
     63 #endif
     64 
     65 #ifndef KHRONOS_1_1
     66 #define KHRONOS_1_1
     67 #endif
     68 
     69 #define KHRONOS_1_2
     70 #ifndef VIDDEC_SPARK_CODE
     71     #define VIDDEC_SPARK_CODE
     72 #endif
     73 
     74 #ifndef VIDDEC_SN_R8_14
     75     #define VIDDEC_SN_R8_14
     76 #endif
     77 
     78 #define VIDDEC_WAIT_CODE() sched_yield()
     79 
     80 #ifndef UNDER_CE
     81 #ifndef __ENV_CHANGE__
     82 #define __ENV_CHANGE__
     83 #endif
     84 #endif
     85 
     86 #ifndef VIDDEC_ACTIVATEPARSER
     87     #define VIDDEC_ACTIVATEPARSER
     88 #endif
     89 
     90 #define VIDDEC_WMVPOINTERFIXED
     91 #define VIDDEC_HANDLE_FULL_STRM_PROP_OBJ
     92 
     93 #include <sched.h>
     94 #include <OMX_Core.h>
     95 #include <OMX_TI_Debug.h>
     96 #include "OMX_VideoDecoder.h"
     97 #include "OMX_VidDec_CustomCmd.h"
     98 #include "OMX_TI_Common.h"
     99 
    100 
    101 #ifdef KHRONOS_1_1
    102 typedef struct OMX_CONFIG_MACROBLOCKERRORMAPTYPE_TI {
    103     OMX_U32 nSize;
    104     OMX_VERSIONTYPE nVersion;
    105     OMX_U32 nPortIndex;
    106     OMX_U32 nErrMapSize;                /* Size of the Error Map in bytes*/
    107     OMX_U8  ErrMap[(864 * 480) / 256]; /* Error map hint   */
    108 } OMX_CONFIG_MACROBLOCKERRORMAPTYPE_TI;
    109 #endif
    110 
    111 #define VIDDEC_MEMLEVELS 5
    112 typedef enum VIDDEC_ENUM_MEMLEVELS{
    113     VIDDDEC_Enum_MemLevel0 = 0,
    114     VIDDDEC_Enum_MemLevel1,
    115     VIDDDEC_Enum_MemLevel2,
    116     VIDDDEC_Enum_MemLevel3,
    117     VIDDDEC_Enum_MemLevel4
    118 }VIDDEC_ENUM_MEMLEVELS;
    119 
    120 #include "LCML_DspCodec.h"
    121 #include "LCML_Types.h"
    122 #include "LCML_CodecInterface.h"
    123 
    124 #ifdef __PERF_INSTRUMENTATION__
    125 #include "perf.h"
    126 #endif
    127 
    128 /*#define RESOURCE_MANAGER_ENABLED*/
    129 #ifdef RESOURCE_MANAGER_ENABLED
    130         #include <ResourceManagerProxyAPI.h>
    131 #endif
    132 
    133 #ifdef __ENV_CHANGE__
    134     #ifndef ENV_CHANGE_DEF_AUTO
    135         #define ENV_CHANGE_DEF_AUTO          "ON"
    136     #endif
    137     #ifndef ENV_CHANGE_DEF_VALUE
    138         #define ENV_CHANGE_DEF_VALUE         "H264"
    139     #endif
    140     #define ENV_CHANGE_VAL_ON                "ON"
    141     #define ENV_CHANGE_NAME_AUTO             "ENV_CHANGE_AUTO"
    142     #define ENV_CHANGE_NAME_VALUE            "ENV_CHANGE_VALUE"
    143     #define ENV_CHANGE_SET_H264              "H264"
    144     #define ENV_CHANGE_SET_AVC               "AVC"
    145     #define ENV_CHANGE_SET_H263              "H263"
    146     #define ENV_CHANGE_SET_MPEG2             "MPEG2"
    147     #define ENV_CHANGE_SET_MPEG4             "MPEG4"
    148     #define ENV_CHANGE_SET_WMV9              "WMV"
    149 #ifdef VIDDEC_SPARK_CODE
    150     #define ENV_CHANGE_SET_SPARK             "SPARK"
    151 #endif
    152 #endif
    153 
    154 #define VIDDEC_COMPONENTROLES_H263           "video_decoder.h263"
    155 #define VIDDEC_COMPONENTROLES_H264           "video_decoder.avc"
    156 #define VIDDEC_COMPONENTROLES_MPEG2          "video_decoder.mpeg2"
    157 #define VIDDEC_COMPONENTROLES_MPEG4          "video_decoder.mpeg4"
    158 #define VIDDEC_COMPONENTROLES_WMV9           "video_decoder.wmv"
    159 #ifdef VIDDEC_SPARK_CODE
    160     #define VIDDEC_COMPONENTROLES_SPARK       "video_decoder.spark"
    161 #endif
    162 
    163 #define __STD_COMPONENT__
    164 
    165 /*
    166  * MAX_PRIVATE_IN_BUFFERS and MAX_PRIVATE_OUT_BUFFERS must NOT be
    167  * greater than MAX_PRIVATE_BUFFERS. MAX_PRIVATE_BUFFERS is set
    168  * to 6 because 6 overlay buffers are currently being used for
    169  * playback
    170  */
    171 #define MAX_PRIVATE_IN_BUFFERS              6
    172 #define MAX_PRIVATE_OUT_BUFFERS             6
    173 #define MAX_PRIVATE_BUFFERS                 6
    174 #define NUM_OF_PORTS                        2
    175 #define VIDDEC_MAX_NAMESIZE                 128
    176 #define VIDDEC_NOPORT                       0xfffffffe
    177 #define VIDDEC_MPU                          50
    178 
    179 #define IUALG_CMD_SETSTATUS                 3
    180 
    181 #define VERSION_MAJOR                       1
    182 #ifdef KHRONOS_1_1
    183 #define VERSION_MINOR                       0
    184 #else
    185 #define VERSION_MINOR                       0
    186 #endif
    187 #define VERSION_REVISION                    0
    188 #define VERSION_STEP                        0
    189 
    190 #define VIDDEC_COLORFORMAT422               OMX_COLOR_FormatCbYCrY
    191 #define VIDDEC_COLORFORMAT420               OMX_COLOR_FormatYUV420Planar /*OMX_COLOR_FormatYUV420PackedPlanar is not working with OpenCore*/
    192 #define VIDDEC_COLORFORMATUNUSED            OMX_COLOR_FormatUnused
    193 
    194 #define VIDDEC_ZERO                         0
    195 #define VIDDEC_ONE                          1
    196 #define VIDDEC_MINUS                        -1
    197 #define VIDDEC_WMVHEADER                    20
    198 
    199 #define VIDDEC_BUFFERMINCOUNT                   VIDDEC_ONE
    200 #define VIDDEC_PORT_ENABLED                     OMX_TRUE
    201 #define VIDDEC_PORT_POPULATED                   OMX_FALSE
    202 #define VIDDEC_PORT_DOMAIN                      OMX_PortDomainVideo
    203 
    204 #define VIDDEC_DEFAULT_INPUT_BUFFER_SIZE        614400
    205 #define VIDDEC_DEFAULT_OUTPUT_BUFFER_SIZE       614400
    206 #define VIDDEC_DEFAULT_WIDTH                    640
    207 #define VIDDEC_DEFAULT_HEIGHT                   480
    208 #define VIDDEC_DEFAULT_PROCESSMODE              0      /* 0=frmmode; 1=strmmode */
    209 #define VIDDEC_DEFAULT_H264BITSTRMFMT           0      /* 0=bytestrm; 1->4=NAL-bitstrm */
    210 #define MAX_CCD_CNT                             128
    211 #define MAX_NALUDATA_CNT                        128
    212 
    213 #define VIDDEC_INPUT_PORT_COMPRESSIONFORMAT      OMX_VIDEO_CodingMPEG4
    214 #define VIDDEC_OUTPUT_PORT_COMPRESSIONFORMAT      OMX_VIDEO_CodingUnused
    215 #define VIDDEC_INPUT_PORT_BUFFERSUPPLIER        VIDDEC_ZERO
    216 #define VIDDEC_OUTPUT_PORT_BUFFERSUPPLIER       VIDDEC_ZERO
    217 
    218 #define VIDDEC_MIMETYPEH263                     "H263"
    219 #define VIDDEC_MIMETYPEH264                     "H264"
    220 #define VIDDEC_MIMETYPEMPEG4                    "MPEG4"
    221 #define VIDDEC_MIMETYPEWMV                      "WMV"
    222 #define VIDDEC_MIMETYPEYUV                      "YUV"
    223 #ifdef VIDDEC_SPARK_CODE
    224     #define VIDDEC_MIMETYPEWMV_SPARK            "SPARK"
    225 #endif
    226 
    227 #define VIDDEC_INPUT_PORT_NATIVERENDER          NULL
    228 #define VIDDEC_INPUT_PORT_STRIDE                VIDDEC_MINUS
    229 #define VIDDEC_INPUT_PORT_SLICEHEIGHT           VIDDEC_MINUS
    230 
    231 #ifdef __STD_COMPONENT__
    232     #define VIDDEC_INPUT_PORT_BITRATE           (64000)
    233     #define VIDDEC_INPUT_PORT_FRAMERATE         (15 << 16)
    234 #else
    235     #define VIDDEC_INPUT_PORT_BITRATE            VIDDEC_MINUS
    236     #define VIDDEC_INPUT_PORT_FRAMERATE          VIDDEC_MINUS
    237 #endif
    238 #define VIDDEC_INPUT_PORT_FLAGERRORCONCEALMENT  OMX_FALSE
    239 
    240 #define VIDDEC_OUTPUT_PORT_NATIVERENDER         NULL
    241 #define VIDDEC_OUTPUT_PORT_STRIDE               VIDDEC_ZERO
    242 #define VIDDEC_OUTPUT_PORT_SLICEHEIGHT          VIDDEC_ZERO
    243 #define VIDDEC_OUTPUT_PORT_BITRATE              VIDDEC_ZERO
    244 #define VIDDEC_OUTPUT_PORT_FRAMERATE            VIDDEC_ZERO
    245 #define VIDDEC_OUTPUT_PORT_FLAGERRORCONCEALMENT OMX_FALSE
    246 
    247 #define VIDDEC_FACTORFORMAT422                  2
    248 #define VIDDEC_FACTORFORMAT420                  (1.5)
    249 
    250 #define VIDDEC_DEFAULT_MPEG4_PORTINDEX              VIDDEC_INPUT_PORT
    251 #define VIDDEC_DEFAULT_MPEG4_SLICEHEADERSPACING     VIDDEC_ZERO
    252 #define VIDDEC_DEFAULT_MPEG4_SVH                    OMX_FALSE
    253 #define VIDDEC_DEFAULT_MPEG4_GOV                    OMX_FALSE
    254 #define VIDDEC_DEFAULT_MPEG4_PFRAMES                VIDDEC_MINUS
    255 #define VIDDEC_DEFAULT_MPEG4_BFRAMES                VIDDEC_MINUS
    256 #define VIDDEC_DEFAULT_MPEG4_IDCVLCTHRESHOLD        VIDDEC_MINUS
    257 #define VIDDEC_DEFAULT_MPEG4_ACPRED                 OMX_FALSE
    258 #define VIDDEC_DEFAULT_MPEG4_MAXPACKETSIZE          VIDDEC_DEFAULT_INPUT_BUFFER_SIZE
    259 #define VIDDEC_DEFAULT_MPEG4_TIMEINCRES             VIDDEC_MINUS
    260 #define VIDDEC_DEFAULT_MPEG4_PROFILE                OMX_VIDEO_MPEG4ProfileSimple
    261 #define VIDDEC_DEFAULT_MPEG4_LEVEL                  OMX_VIDEO_MPEG4Level1
    262 #define VIDDEC_DEFAULT_MPEG4_ALLOWEDPICTURETYPES    VIDDEC_MINUS
    263 #define VIDDEC_DEFAULT_MPEG4_HEADEREXTENSION        VIDDEC_ONE
    264 #define VIDDEC_DEFAULT_MPEG4_REVERSIBLEVLC          OMX_FALSE
    265 
    266 #define VIDDEC_DEFAULT_MPEG2_PORTINDEX              VIDDEC_INPUT_PORT
    267 #define VIDDEC_DEFAULT_MPEG2_PFRAMES                VIDDEC_MINUS
    268 #define VIDDEC_DEFAULT_MPEG2_BFRAMES                VIDDEC_MINUS
    269 #define VIDDEC_DEFAULT_MPEG2_PROFILE                OMX_VIDEO_MPEG2ProfileSimple
    270 #define VIDDEC_DEFAULT_MPEG2_LEVEL                  OMX_VIDEO_MPEG2LevelLL
    271 #define VIDDEC_DEFAULT_H264_PORTINDEX                 VIDDEC_INPUT_PORT
    272 #define VIDDEC_DEFAULT_H264_SLICEHEADERSPACING        VIDDEC_ZERO
    273 #define VIDDEC_DEFAULT_H264_PFRAMES                   VIDDEC_MINUS
    274 #define VIDDEC_DEFAULT_H264_BFRAMES                   VIDDEC_MINUS
    275 #define VIDDEC_DEFAULT_H264_USEHADAMARD               OMX_FALSE
    276 #define VIDDEC_DEFAULT_H264_REFFRAMES                 VIDDEC_MINUS
    277 #define VIDDEC_DEFAULT_H264_REFIDX10ACTIVEMINUS1      VIDDEC_MINUS
    278 #define VIDDEC_DEFAULT_H264_REFIDX11ACTIVEMINUS1      VIDDEC_MINUS
    279 #define VIDDEC_DEFAULT_H264_ENABLEUEP                 OMX_FALSE
    280 #define VIDDEC_DEFAULT_H264_ENABLEFMO                 OMX_FALSE
    281 #define VIDDEC_DEFAULT_H264_ENABLEASO                 OMX_FALSE
    282 #define VIDDEC_DEFAULT_H264_ENABLERS                  OMX_FALSE
    283 #define VIDDEC_DEFAULT_H264_PROFILE                   OMX_VIDEO_AVCProfileBaseline
    284 #define VIDDEC_DEFAULT_H264_LEVEL                     OMX_VIDEO_AVCLevel1
    285 #define VIDDEC_DEFAULT_H264_ALLOWEDPICTURETYPES       VIDDEC_MINUS
    286 #define VIDDEC_DEFAULT_H264_FRAMEMBSONLY              OMX_FALSE
    287 #define VIDDEC_DEFAULT_H264_MBAFF                     OMX_FALSE
    288 #define VIDDEC_DEFAULT_H264_ENTROPYCODINGCABAC        OMX_FALSE
    289 #define VIDDEC_DEFAULT_H264_WEIGHTEDPPREDICTION       OMX_FALSE
    290 #define VIDDEC_DEFAULT_H264_WEIGHTEDBIPREDICITONMODE  VIDDEC_MINUS
    291 #define VIDDEC_DEFAULT_H264_CONSTIPRED                OMX_FALSE
    292 #define VIDDEC_DEFAULT_H264_DIRECT8X8INFERENCE        OMX_FALSE
    293 #define VIDDEC_DEFAULT_H264_DIRECTSPATIALTEMPORAL     OMX_FALSE
    294 #define VIDDEC_DEFAULT_H264_CABACINITIDC              VIDDEC_MINUS
    295 #define VIDDEC_DEFAULT_H264_LOOPFILTERMODE            OMX_VIDEO_AVCLoopFilterDisable
    296 
    297 #define VIDDEC_DEFAULT_H263_PORTINDEX                 VIDDEC_INPUT_PORT
    298 #define VIDDEC_DEFAULT_H263_PFRAMES                   VIDDEC_MINUS
    299 #define VIDDEC_DEFAULT_H263_BFRAMES                   VIDDEC_MINUS
    300 #define VIDDEC_DEFAULT_H263_PROFILE                   OMX_VIDEO_H263ProfileBaseline
    301 #define VIDDEC_DEFAULT_H263_LEVEL                     OMX_VIDEO_H263Level10
    302 #define VIDDEC_DEFAULT_H263_PLUSPTYPEALLOWED          OMX_FALSE
    303 #define VIDDEC_DEFAULT_H263_ALLOWEDPICTURETYPES       OMX_VIDEO_PictureTypeMax
    304 #define VIDDEC_DEFAULT_H263_FORCEROUNDINGTYPETOZERO   OMX_TRUE
    305 #define VIDDEC_DEFAULT_H263_PICTUREHEADERREPETITION   0
    306 #define VIDDEC_DEFAULT_H263_GOBHEADERINTERVAL         1
    307 
    308 #define VIDDEC_DEFAULT_WMV_PORTINDEX                  VIDDEC_INPUT_PORT
    309 #define VIDDEC_DEFAULT_WMV_FORMAT                     OMX_VIDEO_WMVFormat9
    310 
    311 #define VIDDEC_PIPE_WRITE                             VIDDEC_ONE
    312 #define VIDDEC_PIPE_READ                              VIDDEC_ZERO
    313 
    314 #define VIDDEC_PADDING_FULL                           256
    315 #define VIDDEC_PADDING_HALF                           VIDDEC_PADDING_FULL / 2
    316 
    317 #define VIDDEC_ALIGNMENT                              4
    318 
    319 #define VIDDEC_CLEARFLAGS                             0
    320 #define H264VDEC_SN_MAX_NALUNITS                      1200
    321 
    322 #define VIDDEC_RM_FREC_MPEG4_QCIF                     30
    323 #define VIDDEC_RM_FREC_MPEG4_CIF                      80
    324 #define VIDDEC_RM_FREC_MPEG4_VGA                      165
    325 #define VIDDEC_RM_FREC_MPEG4_720P                     401
    326 
    327 #define VIDDEC_RM_FREC_MPEG2_QCIF                     30
    328 #define VIDDEC_RM_FREC_MPEG2_CIF                      80
    329 #define VIDDEC_RM_FREC_MPEG2_VGA                      165
    330 
    331 #define VIDDEC_RM_FREC_H263_QCIF                      25
    332 #define VIDDEC_RM_FREC_H263_CIF                       60
    333 #define VIDDEC_RM_FREC_H263_VGA                       165
    334 
    335 #define VIDDEC_RM_FREC_H264_QCIF                      85
    336 #define VIDDEC_RM_FREC_H264_CIF                       160
    337 #define VIDDEC_RM_FREC_H264_VGA                       260
    338 
    339 #define VIDDEC_RM_FREC_WMV_QCIF                       55
    340 #define VIDDEC_RM_FREC_WMV_CIF                        100
    341 #define VIDDEC_RM_FREC_WMV_VGA                        300
    342 
    343 #ifdef VIDDEC_SPARK_CODE
    344  #define VIDDEC_RM_FREC_SPARK_QCIF                    55
    345  #define VIDDEC_RM_FREC_SPARK_CIF                     100
    346  #define VIDDEC_RM_FREC_SPARK_VGA                     300
    347 #endif
    348 
    349 #define VIDDEC_MIN_WIDTH                              176
    350 #define VIDDEC_MIN_HEIGHT                             144
    351 
    352 #define VIDDEC_QCIF_WIDTH                             176
    353 #define VIDDEC_QCIF_HEIGHT                            144
    354 
    355 #define VIDDEC_QVGA_WIDTH                             320
    356 #define VIDDEC_QVGA_HEIGHT                            240
    357 
    358 #define VIDDEC_CIF_WIDTH                              352
    359 #define VIDDEC_CIF_HEIGHT                             288
    360 
    361 #define VIDDEC_VGA_WIDTH                              640
    362 #define VIDDEC_VGA_HEIGHT                             480
    363 
    364 #define VIDDEC_D1MAX_WIDTH                            864
    365 #define VIDDEC_D1MAX_HEIGHT                           VIDDEC_D1MAX_WIDTH
    366 
    367 /* In the current release the suport for : VIDDEC_MAX_FRAMERATE  & VIDDEC_MAX_BITRATE
    368  * is not provided by the algorithm. But is require to set this field to a non-zero value */
    369 #define VIDDEC_MAX_FRAMERATE                        30000  /* Max frame rate to be suported * 1000 */
    370 #define VIDDEC_MAX_BITRATE                        8000000  /* Max bit rate (in bits per second) to be suported */
    371 
    372 #define VIDDEC_WMV_PROFILE_ID0                          0
    373 #define VIDDEC_WMV_PROFILE_ID1                          1
    374 #define VIDDEC_WMV_PROFILE_ID2                          2
    375 #define VIDDEC_WMV_PROFILE_ID3                          3
    376 #define VIDDEC_WMV_PROFILE_ID4                          4
    377 #define VIDDEC_WMV_PROFILE_ID5                          5
    378 #define VIDDEC_WMV_PROFILE_ID6                          6
    379 #define VIDDEC_WMV_PROFILE_ID7                          7
    380 #define VIDDEC_WMV_PROFILE_ID8                          8
    381 
    382 #define VIDDEC_MAX_QUEUE_SIZE                           256
    383 #define VIDDEC_WMV_BUFFER_OFFSET                        (255 - 4)
    384 #define VIDDEC_WMV_ELEMSTREAM                           0
    385 #define VIDDEC_WMV_RCVSTREAM                            1
    386 
    387 #define VIDDEC_SN_WMV_ELEMSTREAM                        1
    388 #define VIDDEC_SN_WMV_RCVSTREAM                         2
    389 
    390 #define CSD_POSITION                                    51 /*Codec Specific Data position on the "stream propierties object"(ASF spec)*/
    391 
    392 #ifndef KHRONOS_1_2
    393  #define OMX_BUFFERFLAG_CODECCONFIG 0x00000080
    394 #endif
    395 
    396 typedef struct VIDDEC_CUSTOM_PARAM
    397 {
    398     unsigned char cCustomParamName[128];
    399     OMX_INDEXTYPE nCustomParamIndex;
    400 } VIDDEC_CUSTOM_PARAM;
    401 
    402 typedef enum VIDDEC_CUSTOM_PARAM_INDEX
    403 {
    404 #ifdef KHRONOS_1_2
    405     VideoDecodeCustomParamProcessMode = (OMX_IndexVendorStartUnused + 1),
    406 #else
    407     VideoDecodeCustomParamProcessMode = (OMX_IndexIndexVendorStartUnused + 1),
    408 #endif
    409     VideoDecodeCustomParamH264BitStreamFormat,
    410     VideoDecodeCustomParamWMVProfile,
    411     VideoDecodeCustomParamWMVFileType,
    412     VideoDecodeCustomParamParserEnabled,
    413     VideoDecodeCustomParamIsNALBigEndian,
    414 #ifdef VIDDEC_SPARK_CODE
    415     VideoDecodeCustomParamIsSparkInput,
    416 #endif
    417     VideoDecodeCustomConfigDebug
    418 
    419 #ifdef ANDROID /*To be use by opencore multimedia framework*/
    420     ,
    421     PV_OMX_COMPONENT_CAPABILITY_TYPE_INDEX = 0xFF7A347
    422 #endif
    423 } VIDDEC_CUSTOM_PARAM_INDEX;
    424 
    425 typedef enum VIDDEC_LCML_STATES
    426 {
    427     VidDec_LCML_State_Unload = 0,
    428     VidDec_LCML_State_Load,
    429     VidDec_LCML_State_Init,
    430     VidDec_LCML_State_Pause,
    431     VidDec_LCML_State_Start,
    432     VidDec_LCML_State_Stop,
    433     VidDec_LCML_State_Destroy
    434 } VIDDEC_LCML_STATES;
    435 
    436 typedef enum VIDDEC_RMPROXY_STATES
    437 {
    438     VidDec_RMPROXY_State_Unload = 0,
    439     VidDec_RMPROXY_State_Load,
    440     VidDec_RMPROXY_State_Registered,
    441 } VIDDEC_RMPROXY_STATES;
    442 
    443 /* ======================================================================= */
    444 /**
    445 * @def WMV9DEC_YUVFORMAT_XYZ : YUV ouput chroma format.
    446 */
    447 /* ==================================================================== */
    448 #define WMV9VIDDEC_YUVFORMAT_PLANAR420 (1)
    449 #define WMV9VIDDEC_YUVFORMAT_INTERLEAVED422 (4)
    450 
    451 /* ======================================================================= */
    452 /**
    453 * @def MP4VDEC_YUVFORMAT_XYZ : YUV ouput chroma format.
    454 */
    455 /* ==================================================================== */
    456 #define MP4VIDDEC_YUVFORMAT_PLANAR420 (1)
    457 #define MP4VIDDEC_YUVFORMAT_INTERLEAVED422 (4)
    458 
    459 /* ======================================================================= */
    460 /**
    461 * @def H264VDEC_YUVFORMAT_XYZ : YUV ouput chroma format.
    462 */
    463 /* ==================================================================== */
    464 #define H264VIDDEC_YUVFORMAT_PLANAR420 (0)
    465 #define H264VIDDEC_YUVFORMAT_INTERLEAVED422 (1)
    466 
    467 #define MP2VIDDEC_YUVFORMAT_PLANAR420 (1)
    468 #define MP2VIDDEC_YUVFORMAT_INTERLEAVED422 (4)
    469 
    470 /* ======================================================================= */
    471 /**
    472 * @def MP4VDEC_YUVFORMAT_XYZ : YUV ouput chroma format.
    473 */
    474 /* ==================================================================== */
    475 #define SPARKVIDDEC_YUVFORMAT_PLANAR420 (1)
    476 #define SPARKVIDDEC_YUVFORMAT_INTERLEAVED422 (4)
    477 
    478 typedef enum VIDDEC_PORT_INDEX
    479 {
    480     VIDDEC_INPUT_PORT,
    481     VIDDEC_OUTPUT_PORT
    482 }VIDDEC_PORT_INDEX;
    483 
    484 typedef enum VIDDEC_DEFAULT_INPUT_INDEX
    485 {
    486     VIDDEC_DEFAULT_INPUT_INDEX_H263,
    487     VIDDEC_DEFAULT_INPUT_INDEX_H264,
    488     VIDDEC_DEFAULT_INPUT_INDEX_MPEG4,
    489     VIDDEC_DEFAULT_INPUT_INDEX_WMV9,
    490     VIDDEC_DEFAULT_INPUT_INDEX_MPEG2,
    491 #ifdef VIDDEC_SPARK_CODE
    492     VIDDEC_DEFAULT_INPUT_INDEX_SPARK,
    493 #endif
    494     VIDDEC_DEFAULT_INPUT_INDEX_MAX = 0x7ffffff
    495 }VIDDEC_DEFAULT_INPUT_INDEX;
    496 
    497 typedef enum VIDDEC_DEFAULT_OUTPUT_INDEX
    498 {
    499     VIDDEC_DEFAULT_OUTPUT_INDEX_INTERLEAVED422,
    500     VIDDEC_DEFAULT_OUTPUT_INDEX_PLANAR420,
    501     VIDDEC_DEFAULT_OUTPUT_INDEX_MAX = 0x7ffffff
    502 }VIDDEC_DEFAULT_OUTPUT_INDEX;
    503 
    504 typedef enum VIDDEC_BUFFER_OWNER
    505 {
    506     VIDDEC_BUFFER_WITH_CLIENT = 0x0,
    507     VIDDEC_BUFFER_WITH_COMPONENT,
    508     VIDDEC_BUFFER_WITH_DSP,
    509     VIDDEC_BUFFER_WITH_TUNNELEDCOMP
    510 } VIDDEC_BUFFER_OWNER;
    511 
    512 typedef enum VIDDEC_TYPE_ALLOCATE
    513 {
    514     VIDDEC_TALLOC_USEBUFFER,
    515     VIDDEC_TALLOC_ALLOCBUFFER
    516 }VIDDEC_TYPE_ALLOCATE;
    517 
    518 typedef enum VIDDEC_INIT_VALUE
    519 {
    520     VIDDEC_INIT_ALL,
    521     VIDDEC_INIT_STRUCTS,
    522     VIDDEC_INIT_VARS,
    523     VIDDEC_INIT_H263,
    524     VIDDEC_INIT_H264,
    525     VIDDEC_INIT_MPEG2,
    526     VIDDEC_INIT_MPEG4,
    527     VIDDEC_INIT_WMV9,
    528 #ifdef VIDDEC_SPARK_CODE
    529     VIDDEC_INIT_SPARK,
    530 #endif
    531     VIDDEC_INIT_PLANAR420,
    532     VIDDEC_INIT_INTERLEAVED422,
    533     VIDDEC_INIT_IDLEEXECUTING,
    534     VIIDE_INIT_MAX = 0x7ffffff
    535 }VIDDEC_INIT_VALUE;
    536 
    537 typedef enum VIDDEC_WMV_PROFILES
    538 {
    539     VIDDEC_WMV_PROFILE0,
    540     VIDDEC_WMV_PROFILE1,
    541     VIDDEC_WMV_PROFILE2,
    542     VIDDEC_WMV_PROFILE3,
    543     VIDDEC_WMV_PROFILE4,
    544     VIDDEC_WMV_PROFILE5,
    545     VIDDEC_WMV_PROFILE6,
    546     VIDDEC_WMV_PROFILE7,
    547     VIDDEC_WMV_PROFILE8,
    548     VIDDEC_WMV_PROFILEMAX
    549 }VIDDEC_WMV_PROFILES;
    550 
    551 typedef struct VIDDEC_BUFFER_PRIVATE
    552 {
    553     OMX_BUFFERHEADERTYPE* pBufferHdr;
    554     OMX_PTR pUalgParam;
    555     OMX_U32 nUalgParamSize;
    556     VIDDEC_BUFFER_OWNER eBufferOwner;
    557     VIDDEC_TYPE_ALLOCATE bAllocByComponent;
    558     OMX_U32 nNumber;
    559     OMX_U8* pOriginalBuffer;
    560 #ifdef VIDDEC_WMVPOINTERFIXED
    561      OMX_U8* pTempBuffer;
    562 #endif
    563 } VIDDEC_BUFFER_PRIVATE;
    564 
    565 /*structures and defines for Circular Buffer*/
    566 #define VIDDEC_CBUFFER_LOCK
    567 #define MAX_MULTIPLY                        4
    568 #define CBUFFER_SIZE                        MAX_PRIVATE_BUFFERS * MAX_MULTIPLY
    569 
    570 typedef enum VIDDEC_QUEUE_TYPES {
    571     VIDDEC_QUEUE_OMX_U32,
    572     VIDDEC_QUEUE_OMX_MARKTYPE
    573 } VIDDEC_QUEUE_TYPES;
    574 
    575 typedef struct VIDDEC_QUEUE_TYPE {
    576     OMX_PTR Elements;
    577     OMX_U32 CounterElements[VIDDEC_MAX_QUEUE_SIZE];
    578     OMX_U32 nHead;
    579     OMX_S32 nTail;
    580     OMX_U32 nElements;
    581     OMX_U32 nErrorCount;
    582     pthread_mutex_t mMutex;
    583 }VIDDEC_QUEUE_TYPE;
    584 
    585 typedef enum VIDDEC_CBUFFER_TYPE {
    586     VIDDEC_CBUFFER_MARKDATA,
    587     VIDDEC_CBUFFER_TIMESTAMP,
    588     VIDDEC_CBUFFER_CMDMARKDATA
    589 } VIDDEC_CBUFFER_TYPE;
    590 
    591 typedef struct VIDDEC_CIRCULAR_BUFFER {
    592     OMX_PTR pElement[CBUFFER_SIZE];
    593     VIDDEC_CBUFFER_TYPE nType;
    594 #ifdef VIDDEC_CBUFFER_LOCK
    595     pthread_mutex_t* m_lock;
    596 #endif
    597     OMX_U8 nTail;
    598     OMX_U8 nHead;
    599     OMX_U8 nCount;
    600 } VIDDEC_CIRCULAR_BUFFER;
    601 
    602 typedef struct VIDDEC_CBUFFER_BUFFERFLAGS{
    603     OMX_TICKS       nTimeStamp;
    604     OMX_U32         nFlags;
    605     OMX_U32         nTickCount;
    606     OMX_PTR         pMarkData;
    607     OMX_HANDLETYPE  hMarkTargetComponent;
    608 } VIDDEC_CBUFFER_BUFFERFLAGS;
    609 
    610 typedef struct VIDDEC_PORT_TYPE
    611 {
    612     OMX_HANDLETYPE hTunnelComponent;
    613     OMX_U32 nTunnelPort;
    614     OMX_BUFFERSUPPLIERTYPE eSupplierSetting;
    615     VIDDEC_BUFFER_PRIVATE* pBufferPrivate[MAX_PRIVATE_BUFFERS];
    616     OMX_U8 nBufferCnt;
    617     VIDDEC_CIRCULAR_BUFFER eTimeStamp;
    618 } VIDDEC_PORT_TYPE;
    619 
    620 typedef struct VIDDEC_MUTEX{
    621     OMX_BOOL bEnabled;
    622     OMX_BOOL bSignaled;
    623     OMX_BOOL bInitialized;
    624     OMX_S32 nErrorExist;
    625     pthread_mutex_t mutex;
    626     pthread_cond_t condition;
    627 } VIDDEC_MUTEX;
    628 
    629 typedef struct VIDDEC_SEMAPHORE{
    630     OMX_BOOL bEnabled;
    631     OMX_BOOL bSignaled;
    632     OMX_BOOL bInitialized;
    633     OMX_S32 nErrorExist;
    634     sem_t sSemaphore;
    635 } VIDDEC_SEMAPHORE;
    636 
    637 #ifdef VIDDEC_ACTIVATEPARSER
    638 typedef struct VIDDEC_Point{
    639     OMX_S32 nX;
    640     OMX_S32 nY;
    641 }VIDDEC_Point;
    642 
    643 typedef struct VIDDEC_Rect{
    644     VIDDEC_Point sTl;
    645     VIDDEC_Point sBr;
    646 }VIDDEC_Rect;
    647 
    648 typedef struct VIDDEC_Size{
    649     OMX_S32 nWidth;
    650     OMX_S32 nHeight;
    651 }VIDDEC_Size;
    652 
    653 typedef struct VIDDEC_VideoPictureHeader{
    654     OMX_U32 nOptions;
    655     OMX_S32 nProfile;
    656     OMX_S32 nLevel;
    657     OMX_S32 nVersion;
    658     OMX_U8* cnOptional;
    659     VIDDEC_Size sSizeInMemory;
    660     VIDDEC_Rect sDisplayedRect;
    661     OMX_TICKS nPresentationTimestamp;
    662     OMX_TICKS nDecodingTimestamp;
    663     OMX_U32 nPreDecoderBufferSize;
    664     OMX_U32 nPostDecoderBufferSize;
    665     OMX_U32 nPictureNumber;
    666     OMX_U32 nPictureLayer;
    667     OMX_U8* pcSupplementalData;
    668     OMX_BOOL bIsRandomAccessible;
    669     OMX_S32 nRandomAccessBufferingPeriod;
    670     OMX_U32 nRandomAccessBufferOccupancy;
    671 }VIDDEC_VideoPictureHeader;
    672 
    673 typedef struct VIDDEC_MPEG4VisualVbvParams{
    674     OMX_TICKS nBitRate;
    675     OMX_U32 nVbvBufferSize;
    676     OMX_U32 nVbvOccupancy;
    677 }VIDDEC_MPEG4VisualVbvParams;
    678 
    679 typedef struct VIDDEC_MPEG4VisualVOLHeader{
    680     OMX_U32 nVideoObjectLayerId;
    681     OMX_BOOL bShortVideoHeader;
    682     OMX_BOOL bRandomAccessibleVOL;
    683     OMX_U32 nVideoObjectTypeIndication;
    684     OMX_U32 nVideoObjectLayerVerId;
    685     OMX_U32 nVideoObjectLayerPriority;
    686     OMX_U32 nAspectRatioNum;
    687     OMX_U32 nAspectRatioDenom;
    688     VIDDEC_MPEG4VisualVbvParams sVbvParams;
    689     OMX_U16 nVOPTimeIncrementResolution;
    690     OMX_BOOL bnFnXedVopRate;
    691     OMX_U16 nFnXedVOPTimeIncrement;
    692     OMX_BOOL bDataPartitioning;
    693     OMX_BOOL bReversibleVLC;
    694     OMX_U8* pcUserData;
    695 }VIDDEC_MPEG4VisualVOLHeader ;
    696 
    697 typedef struct VIDDEC_MPEG4YuvConversionMatrix{
    698     OMX_S32 iPostOffset;
    699     OMX_S32 iMatrix;
    700     OMX_S32 iPreOffset;
    701 }VIDDEC_MPEG4YuvConversionMatrix;
    702 
    703 typedef struct VIDDEC_MPEG4YuvFormat{
    704     OMX_U32 iCoefficients;
    705     OMX_U32 iPattern;
    706     OMX_U32 iDataLayout;
    707     VIDDEC_MPEG4YuvConversionMatrix * iYuv2RgbMatrix;
    708     VIDDEC_MPEG4YuvConversionMatrix * iRgb2YuvMatrix;
    709     OMX_U32 iAspectRatioNum;
    710     OMX_U32 iAspectRatioDenom;
    711 }VIDDEC_MPEG4YuvFormat;
    712 
    713 typedef struct VIDDEC_MPEG4UncompressedVideoFormat{
    714     OMX_U32 iDataFormat;
    715     VIDDEC_MPEG4YuvFormat iYuvFormat;
    716     OMX_U32 iRgbFormat;
    717 }VIDDEC_MPEG4UncompressedVideoFormat;
    718 
    719 typedef struct VIDDEC_AVC_ParserParam {
    720     OMX_U32 nBitPosTemp;
    721     OMX_U32 nForbiddenZeroBit;
    722     OMX_U32 nNalRefIdc;
    723     OMX_U32 nProfileIdc;
    724     OMX_U32 nConstraintSet0Flag;
    725     OMX_U32 nConstraintSet1Flag;
    726     OMX_U32 nConstraintSet2Flag;
    727     OMX_U32 nReservedZero5bits;
    728     OMX_U32 nLevelIdc;
    729     OMX_U32 nSeqParameterSetId;
    730     OMX_U32 nLog2MaxFrameNumMinus4;
    731     OMX_U32 nPicOrderCntType;
    732     OMX_U32 nLog2MaxPicOrderCntLsbMinus4;
    733     OMX_S32 nOffsetForNonRefPic;
    734     OMX_S32 nOffsetForTopToBottomField;
    735     OMX_U32 nNumRefFramesInPicOrderCntCycle;
    736     OMX_U32 nNumRefFrames;
    737     OMX_S32 nGapsInFrameNumValueAllowedFlag;
    738     OMX_U32 nPicWidthInMbsMinus1;
    739     OMX_U32 nPicHeightInMapUnitsMinus1;
    740     OMX_U32 nFrameMbsOnlyFlag;
    741     OMX_S32 nMBAdaptiveFrameFieldFlag ;
    742     OMX_U32 nDirect8x8InferenceFlag;
    743     OMX_U32 nFrameCroppingFlag;
    744     OMX_U32 nFrameCropLeftOffset;
    745     OMX_U32 nFrameCropRightOffset;
    746     OMX_U32 nFrameCropTopOffset;
    747     OMX_U32 nFrameCropBottomOffset;
    748 }VIDDEC_AVC_ParserParam;
    749 
    750 typedef struct VIDDEC_MPEG4_ParserParam {
    751     OMX_U32 nIsVisualObjectIdentifier;
    752     OMX_U32 nVisualObjectType;
    753     OMX_U32 nVideoSignalType;
    754     OMX_U32 nVideoFormat;
    755     OMX_U32 nVideoRange;
    756     OMX_U32 nColorDescription;
    757     OMX_U32 NBitZero;
    758     OMX_U32 nVideoObjectTypeIndication;
    759     OMX_U32 nIsVisualObjectLayerIdentifier;
    760     OMX_U32 nLayerVerId;
    761     OMX_U32 nLayerPriority;
    762     OMX_U32 nAspectRadio;
    763     OMX_U32 nParWidth;
    764     OMX_U32 nParHeight;
    765     OMX_U32 nControlParameters;
    766     OMX_U32 nChromaFormat;
    767     OMX_U32 nLowDelay;
    768     OMX_U32 nVbvParameters;
    769     OMX_U32 nBitRate;
    770     OMX_U32 nFirstHalfVbvBufferSize;
    771     OMX_U32 nLatterHalfVbvBufferSize;
    772     OMX_U32 nFirstHalfVbvOccupancy;
    773     OMX_U32 nLatterHalfVbvOccupancy;
    774     OMX_U32 nLayerShape;
    775     OMX_U32 nTimeIncrementResolution;
    776     OMX_U32 nFnXedVopRate;
    777     OMX_U32 nNum_bits;
    778     OMX_U32 nInterlaced;
    779     OMX_U32 nObmc;
    780     OMX_U32 nUFEP;
    781     OMX_U32 NSpriteNotSupported;
    782     OMX_U32 nNot8Bit;
    783     OMX_U32 nQuantPrecision;
    784     OMX_U32 nBitsPerPnXel;
    785     OMX_U32 nIsInverseQuantMethodFirst;
    786     OMX_U32 nComplexityEstimationDisable;
    787     OMX_U32 nIsResyncMarkerDisabled;
    788     OMX_U32 nIsDataPartitioned;
    789     OMX_U32 nRvlc;
    790     OMX_U32 nScalability;
    791     OMX_S32 nSourceFormat;
    792     OMX_BOOL nOutputFormat;
    793     OMX_U32 nCPM;
    794     OMX_U32 nPWI;
    795     OMX_U32 nPHI;
    796 }VIDDEC_MPEG4_ParserParam;
    797 #endif
    798 
    799 #define VIDDEC_RCV_EXTHEADER_SIZE 4
    800 
    801 typedef struct VIDDEC_WMV_RCV_struct {
    802     OMX_U32 nNumFrames : 24;
    803     OMX_U32 nFrameType : 8;
    804     OMX_U32 nID : 32;
    805     OMX_U32 nStructData : 32;
    806     OMX_U32 nVertSize;
    807     OMX_U32 nHorizSize;
    808 } VIDDEC_WMV_RCV_struct;
    809 
    810 typedef union VIDDEC_WMV_RCV_header {
    811     VIDDEC_WMV_RCV_struct sStructRCV;
    812     OMX_U8 pBuffer[sizeof(VIDDEC_WMV_RCV_struct)];
    813 } VIDDEC_WMV_RCV_header;
    814 
    815 typedef struct VIDDEC_SAVE_BUFFER{
    816     OMX_BOOL    bSaveFirstBuffer;
    817     OMX_PTR     pFirstBufferSaved;
    818     OMX_S32     nFilledLen;
    819 }VIDDEC_SAVE_BUFFER;
    820 
    821 #ifdef ANDROID
    822 /** Opencore specific, refer to OpenMax Call Sequences document section 3.2 **/
    823 typedef struct PV_OMXComponentCapabilityFlagsType
    824 {
    825     ////////////////// OMX COMPONENT CAPABILITY RELATED MEMBERS
    826     OMX_BOOL iIsOMXComponentMultiThreaded;
    827     OMX_BOOL iOMXComponentSupportsExternalOutputBufferAlloc;
    828     OMX_BOOL iOMXComponentSupportsExternalInputBufferAlloc;
    829     OMX_BOOL iOMXComponentSupportsMovableInputBuffers;
    830     OMX_BOOL iOMXComponentSupportsPartialFrames;
    831     OMX_BOOL iOMXComponentUsesNALStartCodes;
    832     OMX_BOOL iOMXComponentCanHandleIncompleteFrames;
    833     OMX_BOOL iOMXComponentUsesFullAVCFrames;
    834 } PV_OMXComponentCapabilityFlagsType;
    835 #endif
    836 
    837 typedef struct VIDEO_PROFILE_LEVEL
    838 {
    839     OMX_S32  nProfile;
    840     OMX_S32  nLevel;
    841 } VIDEO_PROFILE_LEVEL_TYPE;
    842 
    843 /**
    844  * Data structure used to ...
    845  *
    846  * STRUCT MEMBERS:
    847  *  pPortParamType        : Add desc here...
    848  *  pInPortDef            : Add desc here...
    849  *  pOutPortDef           : Add desc here...
    850  *  pInPortFormat         : Add desc here...
    851  */
    852 typedef struct VIDDEC_COMPONENT_PRIVATE
    853 {
    854     OMX_PARAM_PORTDEFINITIONTYPE* pInPortDef;
    855     OMX_PARAM_PORTDEFINITIONTYPE* pOutPortDef;
    856     OMX_VIDEO_PARAM_PORTFORMATTYPE* pInPortFormat;
    857     OMX_VIDEO_PARAM_PORTFORMATTYPE* pOutPortFormat;
    858     OMX_PRIORITYMGMTTYPE* pPriorityMgmt;
    859     OMX_PARAM_BUFFERSUPPLIERTYPE* pInBufSupplier;
    860     OMX_PARAM_BUFFERSUPPLIERTYPE* pOutBufSupplier;
    861     OMX_VIDEO_PARAM_AVCTYPE* pH264;
    862     OMX_VIDEO_PARAM_MPEG4TYPE* pMpeg4;
    863     OMX_VIDEO_PARAM_H263TYPE* pH263;
    864     OMX_VIDEO_PARAM_WMVTYPE* pWMV;
    865     OMX_VIDEO_PARAM_MPEG2TYPE* pMpeg2; /* OMX_IndexParamVideoMpeg2 */
    866     OMX_PORT_PARAM_TYPE* pPortParamType;
    867     OMX_PARAM_DEBLOCKINGTYPE* pDeblockingParamType;
    868 #ifdef __STD_COMPONENT__
    869     OMX_PORT_PARAM_TYPE* pPortParamTypeAudio;
    870     OMX_PORT_PARAM_TYPE* pPortParamTypeImage;
    871     OMX_PORT_PARAM_TYPE* pPortParamTypeOthers;
    872 
    873 #endif
    874     OMX_CALLBACKTYPE cbInfo;
    875     OMX_PARAM_PORTDEFINITIONTYPE* pPortDef[NUM_OF_PORTS];
    876     OMX_U8 numPorts;
    877     OMX_COMPONENTTYPE* pHandle;
    878     OMX_STATETYPE eState;
    879     OMX_VERSIONTYPE pComponentVersion;
    880     OMX_VERSIONTYPE pSpecVersion;
    881     OMX_STRING cComponentName;
    882     pthread_t ComponentThread;
    883     int free_inpBuf_Q[2];
    884     int free_outBuf_Q[2];
    885     int filled_inpBuf_Q[2];
    886     int filled_outBuf_Q[2];
    887     int cmdPipe[2];
    888     int cmdDataPipe[2];
    889     OMX_U32 bIsStopping;
    890     OMX_U32 bIsPaused;
    891     OMX_U32 bTransPause;
    892     OMX_U32 ProcessMode;
    893     OMX_U32 H264BitStreamFormat;
    894     OMX_BOOL MPEG4Codec_IsTI;
    895     OMX_BUFFERHEADERTYPE pTempBuffHead;  /*Used for EOS logic*/
    896     OMX_U32 app_nBuf;
    897     OMX_U32 lcml_compID;
    898     void* pLcmlHandle;
    899     void* pModLCML;
    900     OMX_U16 arr[100];
    901     int frameCounter;
    902     LCML_DSP_INTERFACE* pLCML;
    903     VIDDEC_PORT_TYPE* pCompPort[NUM_OF_PORTS];
    904     VIDDEC_WMV_PROFILES wmvProfile;
    905 #ifdef __PERF_INSTRUMENTATION__
    906     PERF_OBJHANDLE pPERF, pPERFcomp;
    907     OMX_U32 lcml_nCntOpReceived;
    908     OMX_U32 lcml_nCntIp;
    909 #endif
    910 #ifdef KHRONOS_1_1
    911     OMX_PARAM_COMPONENTROLETYPE componentRole;
    912     /*MBError Reporting code*/
    913     OMX_CONFIG_MBERRORREPORTINGTYPE eMBErrorReport;
    914     OMX_CONFIG_MACROBLOCKERRORMAPTYPE_TI eMBErrorMapType[MAX_PRIVATE_BUFFERS];
    915     OMX_U8 cMBErrorIndexIn;
    916     OMX_U8 cMBErrorIndexOut;
    917 #endif
    918     OMX_U8 nInMarkBufIndex;                          /* for OMX_MARKTYPE */
    919     OMX_U8 nOutMarkBufIndex;                         /* for OMX_MARKTYPE */
    920     OMX_MARKTYPE arrMarkBufIndex[VIDDEC_MAX_QUEUE_SIZE]; /* for OMX_MARKTYPE */
    921 
    922     OMX_U8 nInCmdMarkBufIndex;                          /* for OMX_MARKTYPE */
    923     OMX_U8 nOutCmdMarkBufIndex;                         /* for OMX_MARKTYPE */
    924     OMX_MARKTYPE arrCmdMarkBufIndex[VIDDEC_MAX_QUEUE_SIZE]; /* for OMX_MARKTYPE */
    925     OMX_U8 nInBufIndex;                          /* for time stamps */
    926     OMX_U8 nOutBufIndex;                         /* for time stamps */
    927     OMX_U64 arrBufIndex[VIDDEC_MAX_QUEUE_SIZE]; /* for time stamps */
    928     OMX_MARKTYPE           MTbuffMark;
    929     VIDDEC_QUEUE_TYPE      qBuffMark;
    930     VIDDEC_QUEUE_TYPE      qCmdMarkData;
    931     VIDDEC_QUEUE_TYPE      qBytesSent;
    932     OMX_U32                nBytesConsumed;
    933     OMX_BOOL               bBuffMarkTaked;
    934     OMX_BOOL               bBuffalreadyMarked;
    935 
    936     OMX_STATETYPE eIdleToLoad;
    937     OMX_STATETYPE eExecuteToIdle;
    938     OMX_BOOL iEndofInputSent;
    939     OMX_BOOL bPipeCleaned;
    940     OMX_BOOL bFirstBuffer;
    941 
    942     OMX_BOOL bParserEnabled;
    943     OMX_BOOL bFlushOut;
    944     void* pUalgParams;
    945     OMX_BOOL bLCMLHalted;
    946     OMX_BOOL bMult16Size;
    947     OMX_BOOL bFirstHeader;
    948     OMX_BOOL bDynamicConfigurationInProgress;
    949     OMX_BOOL bInPortSettingsChanged;
    950     OMX_BOOL bOutPortSettingsChanged;
    951     VIDDEC_SAVE_BUFFER eFirstBuffer;
    952 
    953 
    954 #ifndef UNDER_CE
    955     OMX_BOOL bLCMLOut;
    956 #endif
    957     VIDDEC_RMPROXY_STATES eRMProxyState;
    958 
    959     OMX_U8 nCountInputBFromDsp;
    960     OMX_U8 nCountOutputBFromDsp;
    961     OMX_U8 nCountInputBFromApp;
    962     OMX_U8 nCountOutputBFromApp;
    963 
    964     VIDDEC_CBUFFER_BUFFERFLAGS aBufferFlags[CBUFFER_SIZE];
    965     VIDDEC_LCML_STATES eLCMLState;
    966     OMX_U32 nWMVFileType;
    967     OMX_BOOL bIsNALBigEndian;
    968 #ifdef VIDDEC_SPARK_CODE
    969     OMX_BOOL bIsSparkInput;
    970 #endif
    971     VIDDEC_MUTEX sMutex;
    972     pthread_mutex_t mutexInputBFromApp;
    973     pthread_mutex_t mutexOutputBFromApp;
    974     pthread_mutex_t mutexInputBFromDSP;
    975     pthread_mutex_t mutexOutputBFromDSP;
    976     VIDDEC_MUTEX inputFlushCompletionMutex;
    977     VIDDEC_MUTEX outputFlushCompletionMutex;
    978     OMX_BOOL bIsInputFlushPending;
    979     OMX_BOOL bIsOutputFlushPending;
    980     VIDDEC_MUTEX sDynConfigMutex;
    981     VIDDEC_SEMAPHORE sInSemaphore;
    982     VIDDEC_SEMAPHORE sOutSemaphore;
    983     /* used by RM callback */
    984 #ifdef RESOURCE_MANAGER_ENABLED
    985     RMPROXY_CALLBACKTYPE rmproxyCallback;
    986 #endif
    987     /* used to keep track of preempted state */
    988     OMX_BOOL bPreempted;
    989     /* desired state of this component */
    990     OMX_STATETYPE eDesiredState;
    991     VIDDEC_WMV_RCV_header pBufferRCV;
    992     OMX_BUFFERHEADERTYPE pBufferTemp;
    993     OMX_U32 pRCVExtendedHeader;
    994     OMX_U32 nMemUsage[VIDDEC_MEMLEVELS];
    995     OMX_U32 nDisplayWidth;
    996     OMX_U8* pCodecData; /* codec-specific data coming from the demuxer */
    997     OMX_U32 nCodecDataSize;
    998     OMX_BOOL bVC1Fix;
    999 #ifdef ANDROID /* Specific flag for opencore mmframework */
   1000     PV_OMXComponentCapabilityFlagsType* pPVCapabilityFlags;
   1001 #endif
   1002 
   1003     /* Used to handle config buffer fragmentation on AVC*/
   1004     OMX_BOOL bConfigBufferCompleteAVC;
   1005     OMX_PTR pInternalConfigBufferAVC;
   1006     OMX_U32 nInternalConfigBufferFilledAVC;
   1007     struct OMX_TI_Debug dbg;
   1008     /* track number of codec config data (CCD) units and sizes */
   1009     OMX_U32 aCCDsize[MAX_CCD_CNT];
   1010     OMX_U32 nCCDcnt;
   1011 
   1012     /* indicate if codec config data (CCD)
   1013      * buffer (e.g. SPS/PPS) has been copied
   1014      * to the data buffer.  SPS,PPS,NAL1,...
   1015      * */
   1016     OMX_BOOL bCopiedCCDBuffer;
   1017 
   1018     /* Reference count for pending state change requests */
   1019     OMX_U32 nPendingStateChangeRequests;
   1020     pthread_mutex_t mutexStateChangeRequest;
   1021     pthread_cond_t StateChangeCondition;
   1022 
   1023     // Signal first buffer after config data should have EOS flag
   1024     OMX_BOOL firstBufferEos;
   1025 
   1026 } VIDDEC_COMPONENT_PRIVATE;
   1027 
   1028 /*****************macro definitions*********************/
   1029 /*----------------------------------------------------------------------------*/
   1030 /**
   1031   * OMX_GET_DATABUFF_SIZE() Get the needed buffer data size base in the request.
   1032   *
   1033   * This method will give the needed data buffer size acording with
   1034   * specific requirements from the codec and component.
   1035   *
   1036   * @param _nSizeBytes_     Requested size from client
   1037   *
   1038   **/
   1039 /*----------------------------------------------------------------------------*/
   1040 
   1041 #define OMX_GET_DATABUFF_SIZE(_nSizeBytes_)                         \
   1042          (_nSizeBytes_ + VIDDEC_PADDING_FULL + VIDDEC_WMV_BUFFER_OFFSET + VIDDEC_ALIGNMENT)
   1043 
   1044 
   1045 #define OMX_MALLOC_STRUCT(_pStruct_, _sName_, _memusage_)           \
   1046     _pStruct_ = (_sName_*)malloc(sizeof(_sName_));                  \
   1047     if(_pStruct_ == NULL){                                          \
   1048             eError = OMX_ErrorInsufficientResources;                \
   1049                 goto EXIT;                                          \
   1050     }                                                               \
   1051     /*(_memusage_) += sizeof(_sName_);                               */ \
   1052     memset((_pStruct_), 0x0, sizeof(_sName_));
   1053 
   1054 
   1055 #define OMX_MALLOC_STRUCT_SIZED(_pStruct_, _sName_, _nSize_, _memusage_)    \
   1056     _pStruct_ = (_sName_*)malloc(_nSize_);                                  \
   1057     if(_pStruct_ == NULL){                                                  \
   1058             eError = OMX_ErrorInsufficientResources;                        \
   1059                 goto EXIT;                                                  \
   1060     }                                                                       \
   1061     /*(_memusage_) += _nSize_;                                               */ \
   1062     memset((_pStruct_), 0x0, _nSize_);
   1063 
   1064 #define VIDDEC_MEMUSAGE 0 /*\
   1065     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel0] + \
   1066     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1] + \
   1067     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel2] + \
   1068     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel3] + \
   1069     pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel4]*/
   1070 
   1071 
   1072 /*----------------------------------------------------------------------------*/
   1073 /**
   1074   * OMX_ALIGN_BUFFER() Align the buffer to the desire number of bytes.
   1075   *
   1076   * This method will update the component function pointer to the handle
   1077   *
   1078   * @param _pBuffer_     Pointer to align
   1079   * @param _nBytes_      # of byte to alignment desire
   1080   *
   1081   **/
   1082 /*----------------------------------------------------------------------------*/
   1083 
   1084 #define OMX_ALIGN_BUFFER(_pBuffer_, _nBytes_)                  \
   1085     while((OMX_U8)_pBuffer_ & (_nBytes_-1)){                   \
   1086        _pBuffer_++;                                            \
   1087     }
   1088 
   1089 
   1090 
   1091 #define OMX_MALLOC_BUFFER_VIDDEC(_pBuffer_, _nSize_, _pOriginalBuffer_)	    \
   1092     _pBuffer_ =  OMX_MALLOC_STRUCT_SIZED(_pBuffer_, OMX_U8, _nSize_ + VIDDEC_PADDING_FULL + VIDDEC_WMV_BUFFER_OFFSET + VIDDEC_ALIGNMENT, pComponentPrivate->nMemUsage[VIDDDEC_Enum_MemLevel1]);			\
   1093     _pOriginalBuffer_ = _pBuffer_;					    \
   1094     _pBuffer_ += VIDDEC_PADDING_HALF;					    \
   1095     OMX_ALIGN_BUFFER(_pBuffer_, VIDDEC_ALIGNMENT);
   1096 
   1097 
   1098 /*----------------------------------------------------------------------------*/
   1099 /**
   1100   * OMX_FREE() Free memory
   1101   *
   1102   * This method will free memory and set pointer to NULL
   1103   *
   1104   * @param _pBuffer_     Pointer to free
   1105   *
   1106   **/
   1107 /*----------------------------------------------------------------------------*/
   1108 
   1109 #define OMX_FREE_VIDDEC(_pBuffer_)					    \
   1110     if(_pBuffer_ != NULL){                                                  \
   1111 	free(_pBuffer_);                                                    \
   1112 	_pBuffer_ = NULL;                                                   \
   1113     }
   1114 
   1115 
   1116 
   1117 /*----------------------------------------------------------------------------*/
   1118 /**
   1119   * OMX_FREE_BUFFER_VIDDEC() Free video decoder buffer
   1120   *
   1121   * This method will free video decoder buffer
   1122   *
   1123   * @param _pBuffHead_	    Buffer header pointer
   1124   * @param _pCompPort_	    Component port will give us the reference to the
   1125   *			    desire buffer to free
   1126   *
   1127   **/
   1128 /*----------------------------------------------------------------------------*/
   1129 
   1130 #define OMX_FREE_BUFFER_VIDDEC(_pBuffHead_, _pCompPort_)					    \
   1131     {												    \
   1132 	int _nBufferCount_ = 0;									    \
   1133 	OMX_U8* _pTemp_ = NULL;									    \
   1134 												    \
   1135 	for(_nBufferCount_ = 0; _nBufferCount_ < MAX_PRIVATE_BUFFERS; _nBufferCount_++){	    \
   1136             if(_pCompPort_->pBufferPrivate[_nBufferCount_]->pBufferHdr != NULL){		    \
   1137                 _pTemp_ = (OMX_U8*)_pCompPort_->pBufferPrivate[_nBufferCount_]->pBufferHdr->pBuffer;	\
   1138                 if(_pBuffHead_->pBuffer == _pTemp_){						    \
   1139                     break;									    \
   1140                 }										    \
   1141 	    }											    \
   1142         }											    \
   1143 												    \
   1144         if(_nBufferCount_ == MAX_PRIVATE_BUFFERS){						    \
   1145             OMX_ERROR4(pComponentPrivate->dbg, "Error: Buffer NOT found to free: %p \n", _pBuffHead_->pBuffer);	    \
   1146             goto EXIT;										    \
   1147         }											    \
   1148 												    \
   1149         _pBuffHead_->pBuffer = _pCompPort_->pBufferPrivate[_nBufferCount_]->pOriginalBuffer;		    \
   1150         OMX_PRBUFFER1(pComponentPrivate->dbg, "Free original allocated buffer: %p\n", _pBuffHead_->pBuffer);	\
   1151         OMX_FREE_VIDDEC(_pBuffHead_->pBuffer);							    \
   1152     }
   1153 /*----------------------------------------------------------------------------*/
   1154 /**
   1155   * OMX_WMV_INSERT_CODEC_DATA()
   1156   *
   1157   * This method will insert the codec data to the first frame to be sent to
   1158   * queue in LCML
   1159   *
   1160   * @param _pBuffHead_    Pointer to free
   1161   * @param _pComponentPrivate_  Component private structure to provide needed
   1162   *                             references
   1163   *
   1164   **/
   1165 /*----------------------------------------------------------------------------*/
   1166 
   1167 #define OMX_WMV_INSERT_CODEC_DATA(_pBuffHead_, _pComponentPrivate_)                     \
   1168     {                                                                                   \
   1169         OMX_U8* _pTempBuffer_ = NULL;                                                   \
   1170         /* Copy frame data in a temporary buffer*/                                      \
   1171         OMX_MALLOC_STRUCT_SIZED(_pTempBuffer_, OMX_U8, _pBuffHead_->nFilledLen, NULL);  \
   1172         memcpy (_pTempBuffer_, _pBuffHead_->pBuffer, _pBuffHead_->nFilledLen);          \
   1173                                                                                         \
   1174         /*Copy configuration data at the begining of the buffer*/                       \
   1175         memcpy (_pBuffHead_->pBuffer, _pComponentPrivate_->pCodecData, _pComponentPrivate_->nCodecDataSize);   \
   1176         _pBuffHead_->pBuffer += _pComponentPrivate_->nCodecDataSize;                                           \
   1177         /* Add frame start code */     \
   1178         (*(_pBuffHead_->pBuffer++)) = 0x00;  \
   1179         (*(_pBuffHead_->pBuffer++)) = 0x00;  \
   1180         (*(_pBuffHead_->pBuffer++)) = 0x01;  \
   1181         (*(_pBuffHead_->pBuffer++)) = 0x0d;  \
   1182                                              \
   1183         /* Insert again the frame buffer */  \
   1184         memcpy (_pBuffHead_->pBuffer, _pTempBuffer_, _pBuffHead_->nFilledLen); \
   1185         /* pTempBuffer no longer need*/                                        \
   1186 	OMX_FREE_VIDDEC(_pTempBuffer_);							\
   1187                              \
   1188         _pBuffHead_->pBuffer -= (pComponentPrivate->nCodecDataSize + 4);       \
   1189         _pBuffHead_->nFilledLen += pComponentPrivate->nCodecDataSize + 4;      \
   1190     }
   1191 
   1192 
   1193 
   1194 
   1195 #define OMX_CONF_INIT_STRUCT(_s_, _name_, dbg)       \
   1196     memset((_s_), 0x0, sizeof(_name_));         \
   1197     (_s_)->nSize = sizeof(_name_);              \
   1198     (_s_)->nVersion.s.nVersionMajor = VERSION_MAJOR;      \
   1199     (_s_)->nVersion.s.nVersionMinor = VERSION_MINOR;      \
   1200     (_s_)->nVersion.s.nRevision = VERSION_REVISION;       \
   1201     (_s_)->nVersion.s.nStep = VERSION_STEP;                                             \
   1202     OMX_PRINT0(dbg, "INIT_STRUCT Major 0x%x Minor 0x%x nRevision 0x%x nStep 0x%x\n", \
   1203         (_s_)->nVersion.s.nVersionMajor, (_s_)->nVersion.s.nVersionMinor, \
   1204         (_s_)->nVersion.s.nRevision, (_s_)->nVersion.s.nStep);
   1205 
   1206 #define OMX_CONF_CHK_VERSION(_s_, _name_, _e_, dbg)              \
   1207     OMX_PRINT0(dbg, "CHK_VERSION Size 0x%lx Major 0x%x Minor 0x%x nRevision 0x%x nStep 0x%x\n", \
   1208         (_s_)->nSize, (_s_)->nVersion.s.nVersionMajor, (_s_)->nVersion.s.nVersionMinor, \
   1209         (_s_)->nVersion.s.nRevision, (_s_)->nVersion.s.nStep);              \
   1210     if((_s_)->nSize != sizeof(_name_)) _e_ = OMX_ErrorBadParameter; \
   1211     if(((_s_)->nVersion.s.nVersionMajor != VERSION_MAJOR)||         \
   1212        ((_s_)->nVersion.s.nVersionMinor != VERSION_MINOR)||         \
   1213        ((_s_)->nVersion.s.nRevision != VERSION_REVISION)||              \
   1214        ((_s_)->nVersion.s.nStep != VERSION_STEP)) _e_ = OMX_ErrorVersionMismatch;\
   1215     if(_e_ != OMX_ErrorNone) goto EXIT;
   1216 
   1217 #define OMX_CONF_CHECK_CMD(_ptr1, _ptr2, _ptr3) \
   1218 {                                               \
   1219     if(!_ptr1 || !_ptr2 || !_ptr3){             \
   1220         eError = OMX_ErrorBadParameter;         \
   1221         goto EXIT;                              \
   1222     }                                           \
   1223 }
   1224 
   1225 #define OMX_CONF_SET_ERROR_BAIL(_eError, _eCode)\
   1226 {                                               \
   1227     _eError = _eCode;                           \
   1228     goto EXIT;                                  \
   1229 }
   1230 
   1231 
   1232 #define OMX_PARSER_CHECKLIMIT(_total, _actual, _step) /*  \
   1233     if(((_actual + _step) >> 3) >= _total){                \
   1234     printf("_total %d _actual %d\n",_total,((_actual + _step)>>3)); \
   1235         eError = OMX_ErrorStreamCorrupt;                \
   1236         goto EXIT;                                      \
   1237     }*/
   1238 
   1239 /*sMutex*/
   1240 #define VIDDEC_PTHREAD_MUTEX_INIT(_mutex_)    \
   1241     if(!((_mutex_).bInitialized)) {            \
   1242         pthread_mutex_init (&((_mutex_).mutex), NULL);   \
   1243         pthread_cond_init (&(_mutex_).condition, NULL);\
   1244         (_mutex_).bInitialized = OMX_TRUE;   \
   1245         (_mutex_).bSignaled = OMX_FALSE;     \
   1246         (_mutex_).bEnabled = OMX_FALSE;      \
   1247     }
   1248 
   1249 #define VIDDEC_PTHREAD_MUTEX_DESTROY(_mutex_) \
   1250     if((_mutex_).bInitialized) {             \
   1251         pthread_mutex_destroy (&((_mutex_).mutex));     \
   1252         pthread_cond_destroy (&(_mutex_).condition); \
   1253         (_mutex_).bInitialized = OMX_FALSE;  \
   1254         (_mutex_).bEnabled = OMX_FALSE;      \
   1255     }
   1256 
   1257 #define VIDDEC_PTHREAD_MUTEX_LOCK(_mutex_)    \
   1258     VIDDEC_PTHREAD_MUTEX_INIT ((_mutex_));     \
   1259     (_mutex_).bSignaled = OMX_FALSE;         \
   1260     (_mutex_).nErrorExist = 0; \
   1261     (_mutex_).nErrorExist = pthread_mutex_lock (&(_mutex_).mutex);
   1262 
   1263 #define VIDDEC_PTHREAD_MUTEX_UNLOCK(_mutex_)  \
   1264     VIDDEC_PTHREAD_MUTEX_INIT ((_mutex_));      \
   1265     (_mutex_).nErrorExist = 0; \
   1266     (_mutex_).nErrorExist = pthread_mutex_unlock (&(_mutex_).mutex);
   1267 
   1268 #define VIDDEC_PTHREAD_MUTEX_TRYLOCK(_mutex_) \
   1269     VIDDEC_PTHREAD_MUTEX_INIT ((_mutex_));      \
   1270     (_mutex_).nErrorExist = 0; \
   1271     (_mutex_).nErrorExist = pthread_mutex_trylock (&(_mutex_).mutex);
   1272 
   1273 #define VIDDEC_PTHREAD_MUTEX_SIGNAL(_mutex_)  \
   1274     VIDDEC_PTHREAD_MUTEX_INIT ((_mutex_));      \
   1275     /*if( (_mutex_).bEnabled) {  */              \
   1276     (_mutex_).nErrorExist = 0; \
   1277     (_mutex_).nErrorExist = pthread_cond_signal (&(_mutex_).condition); \
   1278         /*(__mutex.bSignaled = OMX_TRUE;*/  \
   1279     /*}*/
   1280 
   1281 #define VIDDEC_PTHREAD_MUTEX_WAIT(_mutex_)    \
   1282     VIDDEC_PTHREAD_MUTEX_INIT ((_mutex_));      \
   1283     (_mutex_).bEnabled = OMX_TRUE;           \
   1284     /*if (!(__mutex.bSignaled){               */\
   1285     (_mutex_).nErrorExist = 0; \
   1286     (_mutex_).nErrorExist = pthread_cond_wait (&(_mutex_).condition, &(_mutex_).mutex);  \
   1287         (_mutex_).bSignaled = OMX_FALSE;     \
   1288         (_mutex_).bEnabled = OMX_FALSE;      \
   1289     /*}*/
   1290 
   1291 #define VIDDEC_PTHREAD_SEMAPHORE_INIT(_semaphore_)    \
   1292     if(!((_semaphore_).bInitialized)) {            \
   1293         sem_init (&((_semaphore_).sSemaphore), 0, 0);   \
   1294         (_semaphore_).bInitialized = OMX_TRUE;   \
   1295         (_semaphore_).bEnabled = OMX_FALSE;      \
   1296         (_semaphore_).bSignaled = OMX_FALSE;        \
   1297     }
   1298 
   1299 #define VIDDEC_PTHREAD_SEMAPHORE_DESTROY(_semaphore_) \
   1300     if((_semaphore_).bInitialized) {             \
   1301         sem_destroy (&(_semaphore_).sSemaphore);     \
   1302         (_semaphore_).bInitialized = OMX_FALSE;  \
   1303         (_semaphore_).bSignaled = OMX_FALSE;     \
   1304         (_semaphore_).bEnabled = OMX_FALSE;      \
   1305     }
   1306     /*
   1307     printf("post signal %d Enable %d\n",(_semaphore_).bSignaled,(_semaphore_).bEnabled); \
   1308     \
   1309     printf("post out signal %d Enable %d\n",(_semaphore_).bSignaled,(_semaphore_).bEnabled); \
   1310     \
   1311     printf("wait out signal %d Enable %d\n",(_semaphore_).bSignaled,(_semaphore_).bEnabled); \
   1312     printf("wait signal %d Enable %d\n",(_semaphore_).bSignaled,(_semaphore_).bEnabled); \
   1313 
   1314     */
   1315 #define VIDDEC_PTHREAD_SEMAPHORE_POST(_semaphore_)    \
   1316     VIDDEC_PTHREAD_SEMAPHORE_INIT ((_semaphore_));     \
   1317     if((_semaphore_).bEnabled) {     \
   1318         sem_post (&(_semaphore_).sSemaphore);       \
   1319         (_semaphore_).bEnabled = OMX_FALSE;      \
   1320     }               \
   1321     else {          \
   1322         (_semaphore_).bSignaled = OMX_TRUE;      \
   1323         (_semaphore_).bEnabled = OMX_FALSE;     \
   1324     }
   1325 
   1326 #define VIDDEC_PTHREAD_SEMAPHORE_WAIT(_semaphore_)  \
   1327     VIDDEC_PTHREAD_SEMAPHORE_INIT ((_semaphore_));      \
   1328     if(!(_semaphore_).bSignaled) {     \
   1329         (_semaphore_).bEnabled = OMX_TRUE;     \
   1330         sem_wait (&(_semaphore_).sSemaphore);   \
   1331     }       \
   1332     else {  \
   1333         (_semaphore_).bEnabled = OMX_FALSE;     \
   1334         (_semaphore_).bSignaled = OMX_FALSE;      \
   1335     }
   1336 
   1337 #define VIDDEC_EXECUTETOIDLE                                \
   1338     (((pComponentPrivate->eState == OMX_StatePause) ||      \
   1339     (pComponentPrivate->eState == OMX_StateExecuting)) &&   \
   1340     (pComponentPrivate->eExecuteToIdle == OMX_StateIdle))
   1341 
   1342 #define VIDDEC_IDLETOEXECUTE                                \
   1343     (((pComponentPrivate->eState == OMX_StateIdle)) &&      \
   1344     (pComponentPrivate->eExecuteToIdle == OMX_StateExecuting))
   1345 
   1346 #ifdef VIDDEC_SPARK_CODE
   1347  #define VIDDEC_SPARKCHECK \
   1348     ((pComponentPrivate->bIsSparkInput) && \
   1349     (pComponentPrivate->pInPortDef->format.video.eCompressionFormat == OMX_VIDEO_CodingUnused))
   1350 #else
   1351  #define VIDDEC_SPARKCHECK (OMX_FALSE)
   1352 #endif
   1353 
   1354 
   1355 /* DEFINITIONS for parsing the config information & sequence header for WMV*/
   1356  #define VIDDEC_GetUnalignedDword( pb, dw ) \
   1357              (dw) = ((OMX_U32) *(pb + 3) << 24) + \
   1358                     ((OMX_U32) *(pb + 2) << 16) + \
   1359                     ((OMX_U16) *(pb + 1) << 8) + *pb;
   1360 
   1361  #define VIDDEC_GetUnalignedDwordEx( pb, dw )   VIDDEC_GetUnalignedDword( pb, dw ); (pb) += sizeof(OMX_U32);
   1362  #define VIDDEC_LoadDWORD( dw, p )  VIDDEC_GetUnalignedDwordEx( p, dw )
   1363  #ifndef VIDDEC_MAKEFOURCC
   1364  #define VIDDEC_MAKEFOURCC(ch0, ch1, ch2, ch3) \
   1365          ((OMX_U32)(OMX_U8)(ch0) | ((OMX_U32)(OMX_U8)(ch1) << 8) |   \
   1366          ((OMX_U32)(OMX_U8)(ch2) << 16) | ((OMX_U32)(OMX_U8)(ch3) << 24 ))
   1367 
   1368  #define VIDDEC_FOURCC(ch0, ch1, ch2, ch3)  VIDDEC_MAKEFOURCC(ch0, ch1, ch2, ch3)
   1369  #endif
   1370 
   1371  #define FOURCC_WMV3     VIDDEC_FOURCC('W','M','V','3')
   1372  #define FOURCC_WMV2     VIDDEC_FOURCC('W','M','V','2')
   1373  #define FOURCC_WMV1     VIDDEC_FOURCC('W','M','V','1')
   1374  #define FOURCC_WVC1     VIDDEC_FOURCC('W','V','C','1')
   1375 
   1376 
   1377 /*-------function prototypes -------------------------------------------------*/
   1378 typedef OMX_ERRORTYPE (*VIDDEC_fpo)(OMX_HANDLETYPE);
   1379 
   1380 OMX_ERRORTYPE OMX_ComponentInit (OMX_HANDLETYPE hComponent);
   1381 OMX_ERRORTYPE VIDDEC_Start_ComponentThread (OMX_HANDLETYPE pHandle);
   1382 OMX_ERRORTYPE VIDDEC_Stop_ComponentThread(OMX_HANDLETYPE pComponent);
   1383 OMX_ERRORTYPE VIDDEC_HandleCommand (OMX_HANDLETYPE pHandle, OMX_U32 nParam1);
   1384 OMX_ERRORTYPE VIDDEC_DisablePort (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1);
   1385 OMX_ERRORTYPE VIDDEC_EnablePort (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1);
   1386 OMX_ERRORTYPE VIDDEC_HandleDataBuf_FromApp (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1387 OMX_ERRORTYPE VIDDEC_HandleDataBuf_FromDsp (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1388 OMX_ERRORTYPE VIDDEC_HandleFreeDataBuf (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1389 OMX_ERRORTYPE VIDDEC_LCML_Callback (TUsnCodecEvent event, void* argsCb [10]);
   1390 OMX_ERRORTYPE VIDDEC_HandleFreeOutputBufferFromApp (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1391 OMX_ERRORTYPE VIDDEC_InitDSP_Mpeg4Dec (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1392 OMX_ERRORTYPE VIDDEC_InitDSP_Mpeg2Dec (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1393 OMX_ERRORTYPE VIDDEC_InitDSP_H264Dec (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1394 OMX_ERRORTYPE VIDDEC_InitDSP_WMVDec (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1395 #ifdef VIDDEC_SPARK_CODE
   1396 OMX_ERRORTYPE VIDDEC_InitDSP_SparkDec (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1397 #endif
   1398 OMX_ERRORTYPE VIDDEC_ReturnBuffers (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_U32 nParam1, OMX_BOOL bRetDSP);
   1399 OMX_ERRORTYPE VIDDEC_HandleCommandMarkBuffer(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1, OMX_PTR pCmdData);
   1400 OMX_ERRORTYPE VIDDEC_HandleCommandFlush(VIDDEC_COMPONENT_PRIVATE *pComponentPrivate, OMX_U32 nParam1, OMX_BOOL bPass);
   1401 OMX_ERRORTYPE VIDDEC_Load_Defaults (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_S32 nPassing);
   1402 OMX_U32 VIDDEC_GetRMFrecuency(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1403 OMX_ERRORTYPE VIDDEC_Handle_InvalidState (VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1404 
   1405 OMX_ERRORTYPE VIDDEC_CircBuf_Init(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex);
   1406 OMX_ERRORTYPE VIDDEC_CircBuf_Flush(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex);
   1407 OMX_ERRORTYPE VIDDEC_CircBuf_DeInit(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex);
   1408 OMX_ERRORTYPE VIDDEC_CircBuf_Add(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex, OMX_PTR pElement);
   1409 OMX_ERRORTYPE VIDDEC_CircBuf_Remove(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex, OMX_PTR* pElement);
   1410 OMX_ERRORTYPE VIDDEC_CircBuf_Count(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex, OMX_U8* pCount);
   1411 OMX_U8 VIDDEC_CircBuf_GetHead(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, VIDDEC_CBUFFER_TYPE nTypeIndex, VIDDEC_PORT_INDEX nPortIndex);
   1412 OMX_ERRORTYPE VIDDEC_Propagate_Mark(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE *pBuffHead);
   1413 OMX_ERRORTYPE VIDDEC_Queue_Init(VIDDEC_QUEUE_TYPE *queue, VIDDEC_QUEUE_TYPES type);
   1414 OMX_ERRORTYPE VIDDEC_Queue_Flush(VIDDEC_QUEUE_TYPE *queue);
   1415 OMX_ERRORTYPE VIDDEC_Queue_Add(VIDDEC_QUEUE_TYPE *queue, OMX_PTR pElement, VIDDEC_QUEUE_TYPES type);
   1416 OMX_ERRORTYPE VIDDEC_Queue_Remove(VIDDEC_QUEUE_TYPE *queue, OMX_PTR pElement, VIDDEC_QUEUE_TYPES type);
   1417 OMX_ERRORTYPE VIDDEC_Queue_Replace_Tail(VIDDEC_QUEUE_TYPE *queue, OMX_PTR pElement, VIDDEC_QUEUE_TYPES type);
   1418 OMX_ERRORTYPE VIDDEC_Queue_Get_Tail(VIDDEC_QUEUE_TYPE *queue, OMX_PTR pElement,VIDDEC_QUEUE_TYPES type);
   1419 OMX_ERRORTYPE VIDDEC_Queue_Free(VIDDEC_QUEUE_TYPE *queue);
   1420 #ifdef RESOURCE_MANAGER_ENABLED
   1421 void VIDDEC_ResourceManagerCallback(RMPROXY_COMMANDDATATYPE cbData);
   1422 #endif
   1423 #ifdef ANDROID
   1424 OMX_ERRORTYPE VIDDEC_SaveBuffer(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE* pBuffHead);
   1425 OMX_ERRORTYPE VIDDEC_CopyBuffer(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE* pBuffHead);
   1426 #endif
   1427 OMX_ERRORTYPE VIDDEC_UnloadCodec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1428 OMX_ERRORTYPE VIDDEC_LoadCodec(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1429 OMX_ERRORTYPE VIDDEC_Set_SN_StreamType(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1430 OMX_ERRORTYPE VIDDEC_SetMpeg4_Parameters(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1431 
   1432 #ifdef VIDDEC_ACTIVATEPARSER
   1433 OMX_ERRORTYPE VIDDEC_ParseVideo_WMV9_VC1( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead);
   1434 OMX_ERRORTYPE VIDDEC_ParseVideo_WMV9_RCV( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead);
   1435 OMX_ERRORTYPE VIDDEC_ParseHeader(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BUFFERHEADERTYPE *pBuffHead);
   1436 OMX_ERRORTYPE VIDDEC_ParseVideo_MPEG4( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead);
   1437 OMX_ERRORTYPE VIDDEC_ParseVideo_H264(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate,
   1438                                      OMX_BUFFERHEADERTYPE* pBuffHead,OMX_S32* nWidth,
   1439                                      OMX_S32* nHeight, OMX_S32* nCropWidth, OMX_S32* nCropHeight, OMX_U32 nType);
   1440 OMX_ERRORTYPE VIDDEC_ParseVideo_MPEG2( OMX_S32* nWidth, OMX_S32* nHeight, OMX_BUFFERHEADERTYPE *pBuffHead);
   1441 OMX_U32 VIDDEC_GetBits(OMX_U32* nPosition, OMX_U8 nBits, OMX_U8* pBuffer, OMX_BOOL bIcreasePosition);
   1442 OMX_S32 VIDDEC_UVLC_dec(OMX_U32 *nPosition, OMX_U8* pBuffer);
   1443 OMX_ERRORTYPE AddStateTransition(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate);
   1444 OMX_ERRORTYPE RemoveStateTransition(VIDDEC_COMPONENT_PRIVATE* pComponentPrivate, OMX_BOOL bEnableSignal);
   1445 OMX_ERRORTYPE IncrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex);
   1446 OMX_ERRORTYPE DecrementCount (OMX_U8 * pCounter, pthread_mutex_t *pMutex);
   1447 
   1448 #endif
   1449 #endif
   1450