Initial version

Change-Id: I5a9473876e596e7461e91f971b0243f694f7e8fb
diff --git a/decoder/arm/impeg2d_function_selector.c b/decoder/arm/impeg2d_function_selector.c
new file mode 100644
index 0000000..d43e060
--- /dev/null
+++ b/decoder/arm/impeg2d_function_selector.c
@@ -0,0 +1,119 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector.c
+*
+* @brief
+*  Contains functions to initialize function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_mc.h"
+
+void impeg2d_init_function_ptr_generic(void *pv_codec);
+void impeg2d_init_function_ptr_a9q(void *pv_codec);
+#ifdef ARMV8
+void impeg2d_init_function_ptr_av8(void *pv_codec);
+#endif /* ARMV8 */
+
+void impeg2d_init_function_ptr(void *pv_codec)
+{
+    dec_state_t *ps_codec   = (dec_state_t *)pv_codec;
+    IVD_ARCH_T e_proc_arch  = ps_codec->e_processor_arch;
+
+    switch(e_proc_arch)
+    {
+        case ARCH_ARM_NONEON:
+            impeg2d_init_function_ptr_generic(ps_codec);
+            break;
+#ifndef ARMV8
+        case ARCH_ARM_A5:
+        case ARCH_ARM_A7:
+        case ARCH_ARM_A9:
+        case ARCH_ARM_A15:
+        case ARCH_ARM_A9Q:
+        default:
+        impeg2d_init_function_ptr_a9q(ps_codec);
+            break;
+#else /* ARMV8 */
+        case ARCH_ARMV8_GENERIC:
+        default:
+            impeg2d_init_function_ptr_av8(ps_codec);
+            break;
+#endif /* ARMV8 */
+    }
+}
+
+void impeg2d_init_arch(void *pv_codec)
+{
+    dec_state_t *ps_codec = (dec_state_t *)pv_codec;
+#ifdef DEFAULT_ARCH
+#if DEFAULT_ARCH == D_ARCH_ARM_NONEON
+    ps_codec->e_processor_arch = ARCH_ARM_NONEON;
+#elif DEFAULT_ARCH == D_ARCH_ARMV8_GENERIC
+    ps_codec->e_processor_arch = ARCH_ARMV8_GENERIC;
+#elif DEFAULT_ARCH == D_ARCH_ARM_NEONINTR
+    ps_codec->e_processor_arch = ARCH_ARM_NEONINTR;
+#else
+    ps_codec->e_processor_arch = ARCH_ARM_A9Q;
+#endif
+#else
+    ps_codec->e_processor_arch = ARCH_ARM_A9Q;
+#endif
+}
diff --git a/decoder/arm/impeg2d_function_selector_a9q.c b/decoder/arm/impeg2d_function_selector_a9q.c
new file mode 100644
index 0000000..024145d
--- /dev/null
+++ b/decoder/arm/impeg2d_function_selector_a9q.c
@@ -0,0 +1,100 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector_a9q.c
+*
+* @brief
+*  Contains functions to initialize a9q function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_mc.h"
+
+void impeg2d_init_function_ptr_a9q(dec_state_t *pv_codec)
+{
+    dec_state_t *dec = (dec_state_t *)pv_codec;
+
+    dec->pf_idct_recon[0]                   = &impeg2_idct_recon_dc_a9q;
+    dec->pf_idct_recon[1]                   = &impeg2_idct_recon_dc_mismatch_a9q;
+    dec->pf_idct_recon[2]                   = &impeg2_idct_recon_a9q;
+    dec->pf_idct_recon[3]                   = &impeg2_idct_recon_a9q;
+
+    dec->pf_mc[0]                              = &impeg2d_mc_fullx_fully;
+    dec->pf_mc[1]                              = &impeg2d_mc_fullx_halfy;
+    dec->pf_mc[2]                              = &impeg2d_mc_halfx_fully;
+    dec->pf_mc[3]                              = &impeg2d_mc_halfx_halfy;
+
+    dec->pf_interpolate                     = &impeg2_interpolate_a9q;
+    dec->pf_copy_mb                         = &impeg2_copy_mb_a9q;
+
+    dec->pf_fullx_halfy_8x8                 = &impeg2_mc_fullx_halfy_8x8_a9q;
+    dec->pf_halfx_fully_8x8                 = &impeg2_mc_halfx_fully_8x8_a9q;
+    dec->pf_halfx_halfy_8x8                 = &impeg2_mc_halfx_halfy_8x8_a9q;
+    dec->pf_fullx_fully_8x8                 = &impeg2_mc_fullx_fully_8x8_a9q;
+
+    dec->pf_memset_8bit_8x8_block           = &impeg2_memset_8bit_8x8_block_a9q;
+    dec->pf_memset_16bit_8x8_linear_block   = &impeg2_memset0_16bit_8x8_linear_block_a9q;
+
+    dec->pf_copy_yuv420p_buf                = &impeg2_copy_frm_yuv420p;
+    dec->pf_fmt_conv_yuv420p_to_yuv422ile   = &impeg2_fmt_conv_yuv420p_to_yuv422ile;
+    dec->pf_fmt_conv_yuv420p_to_yuv420sp_uv = &impeg2_fmt_conv_yuv420p_to_yuv420sp_uv_a9q;
+    dec->pf_fmt_conv_yuv420p_to_yuv420sp_vu = &impeg2_fmt_conv_yuv420p_to_yuv420sp_vu_a9q;
+}
+
+
diff --git a/decoder/arm/impeg2d_function_selector_av8.c b/decoder/arm/impeg2d_function_selector_av8.c
new file mode 100644
index 0000000..d163b54
--- /dev/null
+++ b/decoder/arm/impeg2d_function_selector_av8.c
@@ -0,0 +1,103 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector.c
+*
+* @brief
+*  Contains functions to initialize function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ithread.h"
+
+
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_job_queue.h"
+#include "impeg2_globals.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_api.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_mc.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+
+void impeg2d_init_function_ptr_av8(void *pv_codec)
+{
+    dec_state_t *dec = (dec_state_t *)pv_codec;
+
+    dec->pf_idct_recon[0]                   = &impeg2_idct_recon_dc_av8;
+    dec->pf_idct_recon[1]                   = &impeg2_idct_recon_dc_mismatch_av8;
+    dec->pf_idct_recon[2]                   = &impeg2_idct_recon_av8;
+    dec->pf_idct_recon[3]                   = &impeg2_idct_recon_av8;
+
+    dec->pf_mc[0]                              = &impeg2d_mc_fullx_fully;
+    dec->pf_mc[1]                              = &impeg2d_mc_fullx_halfy;
+    dec->pf_mc[2]                              = &impeg2d_mc_halfx_fully;
+    dec->pf_mc[3]                              = &impeg2d_mc_halfx_halfy;
+
+    dec->pf_interpolate                     = &impeg2_interpolate_av8;
+    dec->pf_copy_mb                         = &impeg2_copy_mb_av8;
+
+    dec->pf_fullx_halfy_8x8                 = &impeg2_mc_fullx_halfy_8x8_av8;
+    dec->pf_halfx_fully_8x8                 = &impeg2_mc_halfx_fully_8x8_av8;
+    dec->pf_halfx_halfy_8x8                 = &impeg2_mc_halfx_halfy_8x8_av8;
+    dec->pf_fullx_fully_8x8                 = &impeg2_mc_fullx_fully_8x8_av8;
+
+    dec->pf_memset_8bit_8x8_block           = &impeg2_memset_8bit_8x8_block_av8;
+    dec->pf_memset_16bit_8x8_linear_block   = &impeg2_memset0_16bit_8x8_linear_block_av8;
+
+    dec->pf_copy_yuv420p_buf                = &impeg2_copy_frm_yuv420p;
+    dec->pf_fmt_conv_yuv420p_to_yuv422ile   = &impeg2_fmt_conv_yuv420p_to_yuv422ile;
+    dec->pf_fmt_conv_yuv420p_to_yuv420sp_uv = &impeg2_fmt_conv_yuv420p_to_yuv420sp_uv_av8;
+    dec->pf_fmt_conv_yuv420p_to_yuv420sp_vu = &impeg2_fmt_conv_yuv420p_to_yuv420sp_vu_av8;
+}
diff --git a/decoder/impeg2d.h b/decoder/impeg2d.h
new file mode 100644
index 0000000..fe38046
--- /dev/null
+++ b/decoder/impeg2d.h
@@ -0,0 +1,506 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/*****************************************************************************/
+/*                                                                           */
+/*  File Name         : impeg2d.h                                        */
+/*                                                                           */
+/*  Description       : This file contains all the necessary structure and   */
+/*                      enumeration definitions needed for the Application   */
+/*                      Program Interface(API) of the Ittiam MPEG2 ASP       */
+/*                      Decoder on Cortex A8 - Neon platform                 */
+/*                                                                           */
+/*  List of Functions : impeg2d_api_function                             */
+/*                                                                           */
+/*  Issues / Problems : None                                                 */
+/*                                                                           */
+/*  Revision History  :                                                      */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         26 08 2010   100239(RCY)     Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+
+#ifndef __IMPEG2D_H__
+#define __IMPEG2D_H__
+
+#include "iv.h"
+#include "ivd.h"
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/*****************************************************************************/
+/* Constant Macros                                                           */
+/*****************************************************************************/
+#define EXPORT_MPEG2DEC_FULLCODEC_MEM_RECORDS   22
+
+/*****************************************************************************/
+/* Function Macros                                                           */
+/*****************************************************************************/
+#define IS_IVD_CONCEALMENT_APPLIED(x)           (x & (1 << IVD_APPLIEDCONCEALMENT))
+#define IS_IVD_INSUFFICIENTDATA_ERROR(x)        (x & (1 << IVD_INSUFFICIENTDATA))
+#define IS_IVD_CORRUPTEDDATA_ERROR(x)           (x & (1 << IVD_CORRUPTEDDATA))
+#define IS_IVD_CORRUPTEDHEADER_ERROR(x)         (x & (1 << IVD_CORRUPTEDHEADER))
+#define IS_IVD_UNSUPPORTEDINPUT_ERROR(x)        (x & (1 << IVD_UNSUPPORTEDINPUT))
+#define IS_IVD_UNSUPPORTEDPARAM_ERROR(x)        (x & (1 << IVD_UNSUPPORTEDPARAM))
+#define IS_IVD_FATAL_ERROR(x)                   (x & (1 << IVD_FATALERROR))
+#define IS_IVD_INVALID_BITSTREAM_ERROR(x)       (x & (1 << IVD_INVALID_BITSTREAM))
+#define IS_IVD_INCOMPLETE_BITSTREAM_ERROR(x)    (x & (1 << IVD_INCOMPLETE_BITSTREAM))
+
+#define SET_IVD_CONCEALMENT_APPLIED(x)          ((x) |= (x) | (1 << IVD_APPLIEDCONCEALMENT))
+#define SET_IVD_INSUFFICIENTDATA_ERROR(x)       ((x) |= (x) | (1 << IVD_INSUFFICIENTDATA))
+#define SET_IVD_CORRUPTEDDATA_ERROR(x)          ((x) |= (x) | (1 << IVD_CORRUPTEDDATA))
+#define SET_IVD_CORRUPTEDHEADER_ERROR(x)        ((x) |= (x) | (1 << IVD_CORRUPTEDHEADER))
+#define SET_IVD_UNSUPPORTEDINPUT_ERROR(x)       ((x) |= (x) | (1 << IVD_UNSUPPORTEDINPUT))
+#define SET_IVD_UNSUPPORTEDPARAM_ERROR(x)       ((x) |= (x) | (1 << IVD_UNSUPPORTEDPARAM))
+#define SET_IVD_FATAL_ERROR(x)                  ((x) |= (x) | (1 << IVD_FATALERROR))
+#define SET_IVD_INVALID_BITSTREAM_ERROR(x)      ((x) |= (x) | (1 << IVD_INVALID_BITSTREAM))
+#define SET_IVD_INCOMPLETE_BITSTREAM_ERROR(x)   ((x) |= (x) | (1 << IVD_INCOMPLETE_BITSTREAM))
+
+/*****************************************************************************/
+/* API Function Prototype                                                    */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_function(iv_obj_t *ps_handle,
+                                          void *pv_api_ip,
+                                          void *pv_api_op);
+
+/*****************************************************************************/
+/* Enums                                                                     */
+/*****************************************************************************/
+/* Codec Error codes for MPEG2 ASP Decoder                                   */
+
+typedef enum
+{
+
+    IMPEG2D_UNKNOWN_ERROR = IVD_DUMMY_ELEMENT_FOR_CODEC_EXTENSIONS + 1,
+    /* API calls without init call */
+    IMPEG2D_INIT_NOT_DONE,
+    /* Query number of Memory Records API */
+    IMPEG2D_QUERY_NUM_MEM_REC_FAIL,
+
+    /* Fill Memory Records API */
+    IMPEG2D_FILL_NUM_MEM_REC_NOT_SUFFICIENT,
+
+    /* Initialize Decoder API */
+    IMPEG2D_INIT_DEC_SCR_MEM_INSUFFICIENT,
+    IMPEG2D_INIT_DEC_PER_MEM_INSUFFICIENT,
+    IMPEG2D_INIT_NUM_MEM_REC_NOT_SUFFICIENT,
+    IMPEG2D_INIT_CHROMA_FORMAT_HEIGHT_ERROR,
+
+    /* Decode Sequence Header API */
+    IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND,
+    IMPEG2D_FRM_HDR_MARKER_BIT_NOT_FOUND,
+    IMPEG2D_PROF_LEVEL_NOT_SUPPORTED,
+    IMPEG2D_FMT_NOT_SUPPORTED,
+    IMPEG2D_SCALABILITIY_NOT_SUPPORTED,
+    IMPEG2D_PIC_SIZE_NOT_SUPPORTED,
+
+    /* Search for start code API */
+    //IMPEG2D_SEARCH_START_CODE_FAIL         ,
+    /* Decode Video Frame API    */
+    IMPEG2D_START_CODE_NOT_FOUND,
+    IMPEG2D_MARKER_BIT_NOT_FOUND,
+    IMPEG2D_INVALID_STUFFING,
+    IMPEG2D_PROFILE_LEVEL_NOT_SUP,
+    IMPEG2D_CHROMA_FMT_NOT_SUP,
+    IMPEG2D_SCALABLITY_NOT_SUP,
+    IMPEG2D_FRM_HDR_DECODE_ERR,
+    IMPEG2D_MB_HDR_DECODE_ERR,
+    IMPEG2D_MB_TEX_DECODE_ERR,
+    IMPEG2D_INCORRECT_QUANT_MATRIX,
+    IMPEG2D_INVALID_SKIP_MB,
+    IMPEG2D_NOT_SUPPORTED_ERR,
+    IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR,
+    IMPEG2D_INVALID_PIC_TYPE,
+    IMPEG2D_INVALID_HUFFMAN_CODE,
+    IMPEG2D_NO_FREE_BUF_ERR,
+
+    /* slice header errors */
+    IMPEG2D_INVALID_VERT_SIZE,
+    IMPEG2D_MB_DATA_DECODE_ERR,
+
+    /* Get Display Frame API */
+    IMPEG2D_GET_DISP_FRM_FAIL,
+
+    /* Sample Version limitation */
+    IMPEG2D_SAMPLE_VERSION_LIMIT_ERR,
+    /**
+     * Width/height greater than max width and max height
+     */
+    IMPEG2D_UNSUPPORTED_DIMENSIONS,
+
+    /* Unknown API Command */
+    IMPEG2D_UNKNOWN_API_COMMAND
+
+} IMPEG2D_ERROR_CODES_T;
+
+/*****************************************************************************/
+/* Extended Structures                                                       */
+/*****************************************************************************/
+typedef enum
+{
+    /** Set number of cores/threads to be used */
+    IMPEG2D_CMD_CTL_SET_NUM_CORES = IVD_CMD_CTL_CODEC_SUBCMD_START,
+
+    /** Set processor details */
+    IMPEG2D_CMD_CTL_SET_PROCESSOR = IVD_CMD_CTL_CODEC_SUBCMD_START + 0x001,
+
+    /** Get display buffer dimensions */
+    IMPEG2D_CMD_CTL_GET_BUFFER_DIMENSIONS = IVD_CMD_CTL_CODEC_SUBCMD_START
+                    + 0x100,
+
+} IMPEG2D_CMD_CTL_SUB_CMDS;
+
+/*****************************************************************************/
+/*  Get Number of Memory Records                                             */
+/*****************************************************************************/
+
+typedef struct
+{
+    iv_num_mem_rec_ip_t s_ivd_num_mem_rec_ip_t;
+} impeg2d_num_mem_rec_ip_t;
+
+typedef struct
+{
+    iv_num_mem_rec_op_t s_ivd_num_mem_rec_op_t;
+} impeg2d_num_mem_rec_op_t;
+
+/*****************************************************************************/
+/*  Fill Memory Records                                                      */
+/*****************************************************************************/
+
+typedef struct
+{
+    iv_fill_mem_rec_ip_t s_ivd_fill_mem_rec_ip_t;
+    /* Flag to enable sharing of reference buffers between decoder
+     and application */
+
+    UWORD32 u4_share_disp_buf;
+
+    /* format in which codec has to give out frame data for display */
+    IV_COLOR_FORMAT_T e_output_format;
+
+} impeg2d_fill_mem_rec_ip_t;
+
+typedef struct
+{
+    iv_fill_mem_rec_op_t s_ivd_fill_mem_rec_op_t;
+} impeg2d_fill_mem_rec_op_t;
+
+/*****************************************************************************/
+/*  Retrieve Memory Records                                                  */
+/*****************************************************************************/
+
+typedef struct
+{
+    iv_retrieve_mem_rec_ip_t s_ivd_retrieve_mem_rec_ip_t;
+} impeg2d_retrieve_mem_rec_ip_t;
+
+typedef struct
+{
+    iv_retrieve_mem_rec_op_t s_ivd_retrieve_mem_rec_op_t;
+} impeg2d_retrieve_mem_rec_op_t;
+
+/*****************************************************************************/
+/*   Initialize decoder                                                      */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_init_ip_t s_ivd_init_ip_t;
+    /* Flag to enable sharing of reference buffers between decoder
+     and application */
+    UWORD32 u4_share_disp_buf;
+
+} impeg2d_init_ip_t;
+
+typedef struct
+{
+    ivd_init_op_t s_ivd_init_op_t;
+} impeg2d_init_op_t;
+
+/*****************************************************************************/
+/*   Video Decode                                                            */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_video_decode_ip_t s_ivd_video_decode_ip_t;
+} impeg2d_video_decode_ip_t;
+
+typedef struct
+{
+    ivd_video_decode_op_t s_ivd_video_decode_op_t;
+} impeg2d_video_decode_op_t;
+
+/*****************************************************************************/
+/*   Get Display Frame                                                       */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_get_display_frame_ip_t s_ivd_get_display_frame_ip_t;
+} impeg2d_get_display_frame_ip_t;
+
+typedef struct
+{
+    ivd_get_display_frame_op_t s_ivd_get_display_frame_op_t;
+} impeg2d_get_display_frame_op_t;
+
+/*****************************************************************************/
+/*   Set Display Frame                                                       */
+/*****************************************************************************/
+typedef struct
+{
+    ivd_set_display_frame_ip_t s_ivd_set_display_frame_ip_t;
+} impeg2d_set_display_frame_ip_t;
+
+typedef struct
+{
+    ivd_set_display_frame_op_t s_ivd_set_display_frame_op_t;
+} impeg2d_set_display_frame_op_t;
+
+/*****************************************************************************/
+/*   Release Display Buffers                                                 */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_rel_display_frame_ip_t s_ivd_rel_display_frame_ip_t;
+} impeg2d_rel_display_frame_ip_t;
+
+typedef struct
+{
+    ivd_rel_display_frame_op_t s_ivd_rel_display_frame_op_t;
+} impeg2d_rel_display_frame_op_t;
+
+/*****************************************************************************/
+/*   Video control  Flush                                                    */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_ctl_flush_ip_t s_ivd_ctl_flush_ip_t;
+} impeg2d_ctl_flush_ip_t;
+
+typedef struct
+{
+    ivd_ctl_flush_op_t s_ivd_ctl_flush_op_t;
+} impeg2d_ctl_flush_op_t;
+
+/*****************************************************************************/
+/*   Video control reset                                                     */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_ctl_reset_ip_t s_ivd_ctl_reset_ip_t;
+} impeg2d_ctl_reset_ip_t;
+
+typedef struct
+{
+    ivd_ctl_reset_op_t s_ivd_ctl_reset_op_t;
+} impeg2d_ctl_reset_op_t;
+
+/*****************************************************************************/
+/*   Video control  Set Params                                               */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_ctl_set_config_ip_t s_ivd_ctl_set_config_ip_t;
+} impeg2d_ctl_set_config_ip_t;
+
+typedef struct
+{
+    ivd_ctl_set_config_op_t s_ivd_ctl_set_config_op_t;
+} impeg2d_ctl_set_config_op_t;
+
+/*****************************************************************************/
+/*   Video control:Get Buf Info                                              */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_ctl_getbufinfo_ip_t s_ivd_ctl_getbufinfo_ip_t;
+} impeg2d_ctl_getbufinfo_ip_t;
+
+typedef struct
+{
+    ivd_ctl_getbufinfo_op_t s_ivd_ctl_getbufinfo_op_t;
+} impeg2d_ctl_getbufinfo_op_t;
+
+/*****************************************************************************/
+/*   Video control:Getstatus Call                                            */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_ctl_getstatus_ip_t s_ivd_ctl_getstatus_ip_t;
+} impeg2d_ctl_getstatus_ip_t;
+
+typedef struct
+{
+    ivd_ctl_getstatus_op_t s_ivd_ctl_getstatus_op_t;
+} impeg2d_ctl_getstatus_op_t;
+
+/*****************************************************************************/
+/*   Video control:Get Version Info                                          */
+/*****************************************************************************/
+
+typedef struct
+{
+    ivd_ctl_getversioninfo_ip_t s_ivd_ctl_getversioninfo_ip_t;
+} impeg2d_ctl_getversioninfo_ip_t;
+
+typedef struct
+{
+    ivd_ctl_getversioninfo_op_t s_ivd_ctl_getversioninfo_op_t;
+} impeg2d_ctl_getversioninfo_op_t;
+
+/*****************************************************************************/
+/*   Video control:Disable Qpel                                              */
+/*****************************************************************************/
+
+typedef struct
+{
+    UWORD32 u4_size;
+    IVD_API_COMMAND_TYPE_T e_cmd;
+    IVD_CONTROL_API_COMMAND_TYPE_T e_sub_cmd;
+    UWORD32 u4_num_cores;
+} impeg2d_ctl_set_num_cores_ip_t;
+
+typedef struct
+{
+    UWORD32 u4_size;
+    UWORD32 u4_error_code;
+} impeg2d_ctl_set_num_cores_op_t;
+
+typedef struct
+{
+    /**
+     * size
+     */
+    UWORD32 u4_size;
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T e_cmd;
+    /**
+     * sub cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T e_sub_cmd;
+    /**
+     * Processor type
+     */
+    UWORD32 u4_arch;
+    /**
+     * SOC type
+     */
+    UWORD32 u4_soc;
+
+    /**
+     * num_cores
+     */
+    UWORD32 u4_num_cores;
+
+} impeg2d_ctl_set_processor_ip_t;
+
+typedef struct
+{
+    /**
+     * size
+     */
+    UWORD32 u4_size;
+    /**
+     * error_code
+     */
+    UWORD32 u4_error_code;
+} impeg2d_ctl_set_processor_op_t;
+
+typedef struct
+{
+
+    /**
+     * size
+     */
+    UWORD32 u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T e_cmd;
+
+    /**
+     * sub cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T e_sub_cmd;
+} impeg2d_ctl_get_frame_dimensions_ip_t;
+
+typedef struct
+{
+
+    /**
+     * size
+     */
+    UWORD32 u4_size;
+
+    /**
+     * error_code
+     */
+    UWORD32 u4_error_code;
+
+    /**
+     * x_offset[3]
+     */
+    UWORD32 u4_x_offset[3];
+
+    /**
+     * y_offset[3]
+     */
+    UWORD32 u4_y_offset[3];
+
+    /**
+     * disp_wd[3]
+     */
+    UWORD32 u4_disp_wd[3];
+
+    /**
+     * disp_ht[3]
+     */
+    UWORD32 u4_disp_ht[3];
+
+    /**
+     * buffer_wd[3]
+     */
+    UWORD32 u4_buffer_wd[3];
+
+    /**
+     * buffer_ht[3]
+     */
+    UWORD32 u4_buffer_ht[3];
+} impeg2d_ctl_get_frame_dimensions_op_t;
+
+#ifdef __cplusplus
+} /* closing brace for extern "C" */
+#endif
+
+#endif /* __IMPEG2D_H__ */
diff --git a/decoder/impeg2d_api.h b/decoder/impeg2d_api.h
new file mode 100644
index 0000000..bf3943e
--- /dev/null
+++ b/decoder/impeg2d_api.h
@@ -0,0 +1,149 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/*****************************************************************************/
+/*                                                                           */
+/*  File Name         : impeg2d_api.h                                 */
+/*                                                                           */
+/*  Description       : This file contains all the necessary examples to     */
+/*                      establish a consistent use of Ittiam C coding        */
+/*                      standards (based on Indian Hill C Standards)         */
+/*                                                                           */
+/*  List of Functions : <List the functions defined in this file>            */
+/*                                                                           */
+/*  Issues / Problems : None                                                 */
+/*                                                                           */
+/*  Revision History  :                                                      */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         10 10 2005   Ittiam          Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+
+#ifndef __IMPEG2D_API_H__
+#define __IMPEG2D_API_H__
+
+
+/*****************************************************************************/
+/* Constant Macros                                                           */
+/*****************************************************************************/
+
+
+#define DEBUG_PRINT printf
+
+
+
+
+#define NUM_MEM_RECORDS                 4 *MAX_THREADS+NUM_INT_FRAME_BUFFERS + 5
+
+
+#define SETBIT(a,i)   ((a) |= (1 << i))
+
+
+/*********************/
+/* Codec Versioning  */
+/*********************/
+
+
+
+
+/*****************************************************************************/
+/* Function Declarations                                                     */
+/*****************************************************************************/
+
+IV_API_CALL_STATUS_T impeg2d_api_num_mem_rec(void *pv_api_ip, void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_fill_mem_rec(void *pv_api_ip, void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_init(iv_obj_t *DECHDL,
+                                      void *ps_ip,
+                                      void *ps_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_set_display_frame(iv_obj_t *DECHDL,
+                                          void *pv_api_ip,
+                                          void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_rel_display_frame(iv_obj_t *DECHDL,
+                                                   void *pv_api_ip,
+                                                   void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_retrieve_mem_rec(iv_obj_t *DECHDL,
+                                                        void *pv_api_ip,
+                                                        void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_ctl(iv_obj_t *DECHDL,
+                                       void *pv_api_ip,
+                                       void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_get_version(iv_obj_t *DECHDL,
+                                               void *pv_api_ip,
+                                               void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_get_buf_info(iv_obj_t *DECHDL,
+                                                    void *pv_api_ip,
+                                                    void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_set_flush_mode(iv_obj_t *DECHDL,
+                                                      void *pv_api_ip,
+                                                      void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_set_default(iv_obj_t *DECHDL,
+                                                   void *pv_api_ip,
+                                                   void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_reset(iv_obj_t *DECHDL,
+                                             void *pv_api_ip,
+                                             void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_set_params(iv_obj_t *DECHDL,
+                                                  void *pv_api_ip,
+                                                  void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_get_status(iv_obj_t *DECHDL,
+                                                  void *pv_api_ip,
+                                                  void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_set_params(iv_obj_t *DECHDL,
+                                                  void *pv_api_ip,
+                                                  void *pv_api_op);
+
+void impeg2d_fill_mem_rec(impeg2d_fill_mem_rec_ip_t *ps_ip,
+                            impeg2d_fill_mem_rec_op_t *ps_op);
+
+void impeg2d_dec_frm(void *dec,
+                                impeg2d_video_decode_ip_t *ps_ip,
+                                impeg2d_video_decode_op_t *ps_op);
+
+void impeg2d_dec_hdr(void *dec,
+                               impeg2d_video_decode_ip_t *ps_ip,
+                               impeg2d_video_decode_op_t *ps_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_entity(iv_obj_t *DECHDL,
+                                        void *pv_api_ip,
+                                        void *pv_api_op);
+
+IV_API_CALL_STATUS_T impeg2d_api_check_struct_sanity(iv_obj_t *ps_handle,
+                                                     void *pv_api_ip,
+                                                     void *pv_api_op);
+
+
+
+
+#endif /* __IMPEG2D_API_H__ */
+
diff --git a/decoder/impeg2d_api_main.c b/decoder/impeg2d_api_main.c
new file mode 100755
index 0000000..451eb93
--- /dev/null
+++ b/decoder/impeg2d_api_main.c
@@ -0,0 +1,3258 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/*****************************************************************************/
+/*                                                                           */
+/*  File Name         : decoder_api_main.c                                   */
+/*                                                                           */
+/*  Description       : Functions which recieve the API call from user       */
+/*                                                                           */
+/*  List of Functions : <List the functions defined in this file>            */
+/*                                                                           */
+/*  Issues / Problems : None                                                 */
+/*                                                                           */
+/*  Revision History  :                                                      */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         30 05 2007   Rajneesh        Creation                             */
+/*                                                                           */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+
+/* System include files */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+
+/* User include files */
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ivd.h"
+#include "ithread.h"
+
+#include "impeg2_job_queue.h"
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_mem_func.h"
+
+#include "impeg2d.h"
+#include "impeg2d_api.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_mc.h"
+#include "impeg2d_pic_proc.h"
+
+#define NUM_FRAMES_LIMIT_ENABLED 0
+
+#ifdef LOGO_EN
+#include "impeg2_ittiam_logo.h"
+#define INSERT_LOGO(buf_y, buf_u, buf_v, stride, x_pos, y_pos, yuv_fmt,disp_wd,disp_ht) impeg2_insert_logo(buf_y, buf_u, buf_v, stride, x_pos, y_pos, yuv_fmt,disp_wd,disp_ht);
+#else
+#define INSERT_LOGO(buf_y, buf_u, buf_v, stride, x_pos, y_pos, yuv_fmt,disp_wd,disp_ht)
+#endif
+
+#if NUM_FRAMES_LIMIT_ENABLED
+#define NUM_FRAMES_LIMIT 10000
+#else
+#define NUM_FRAMES_LIMIT 0x7FFFFFFF
+#endif
+
+#define CODEC_NAME              "MPEG2VDEC"
+#define CODEC_RELEASE_TYPE      "eval"
+#define CODEC_RELEASE_VER       "01.00"
+#define CODEC_VENDOR            "ITTIAM"
+
+#define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor)    \
+    strcpy(version_string,"@(#)Id:");                                                               \
+    strcat(version_string,codec_name);                                                              \
+    strcat(version_string,"_");                                                                     \
+    strcat(version_string,codec_release_type);                                                      \
+    strcat(version_string," Ver:");                                                                 \
+    strcat(version_string,codec_release_ver);                                                       \
+    strcat(version_string," Released by ");                                                         \
+    strcat(version_string,codec_vendor);                                                            \
+    strcat(version_string," Build: ");                                                              \
+    strcat(version_string,__DATE__);                                                                \
+    strcat(version_string," @ ");                                                                       \
+    strcat(version_string,__TIME__);
+
+
+#define MIN_OUT_BUFS_420    3
+#define MIN_OUT_BUFS_422ILE 1
+#define MIN_OUT_BUFS_RGB565 1
+#define MIN_OUT_BUFS_420SP  2
+
+
+void impeg2d_init_arch(void *pv_codec);
+void impeg2d_init_function_ptr(void *pv_codec);
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_rel_display_frame                            */
+/*                                                                           */
+/*  Description   : Release displ buffers that will be shared between decoder */
+/*                  and application                                          */
+/*  Inputs        : Error message                                            */
+/*  Globals       : None                                                     */
+/*  Processing    : Just prints error message to console                     */
+/*  Outputs       : Error mesage to the console                              */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : <List any issues or problems with this function>         */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         27 05 2006   Sankar          Creation                             */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_rel_display_frame(iv_obj_t *ps_dechdl,
+                                                   void *pv_api_ip,
+                                                   void *pv_api_op)
+{
+
+    ivd_rel_display_frame_ip_t  *dec_rel_disp_ip;
+    ivd_rel_display_frame_op_t  *dec_rel_disp_op;
+
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+
+
+    dec_rel_disp_ip = (ivd_rel_display_frame_ip_t  *)pv_api_ip;
+    dec_rel_disp_op = (ivd_rel_display_frame_op_t  *)pv_api_op;
+
+    dec_rel_disp_op->u4_error_code = 0;
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+
+    /* If not in shared disp buf mode, return */
+    if(0 == ps_dec_state->u4_share_disp_buf)
+        return IV_SUCCESS;
+
+    if(NULL == ps_dec_state->pv_pic_buf_mg)
+        return IV_SUCCESS;
+
+
+    impeg2_buf_mgr_release(ps_dec_state->pv_pic_buf_mg, dec_rel_disp_ip->u4_disp_buf_id, BUF_MGR_DISP);
+
+    return IV_SUCCESS;
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_set_display_frame                            */
+/*                                                                           */
+/*  Description   : Sets display buffers that will be shared between decoder */
+/*                  and application                                          */
+/*  Inputs        : Error message                                            */
+/*  Globals       : None                                                     */
+/*  Processing    : Just prints error message to console                     */
+/*  Outputs       : Error mesage to the console                              */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : <List any issues or problems with this function>         */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         27 05 2006   Sankar          Creation                             */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_set_display_frame(iv_obj_t *ps_dechdl,
+                                          void *pv_api_ip,
+                                          void *pv_api_op)
+{
+
+    ivd_set_display_frame_ip_t  *dec_disp_ip;
+    ivd_set_display_frame_op_t  *dec_disp_op;
+
+    UWORD32 i;
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    UWORD32 u4_num_disp_bufs;
+
+
+    dec_disp_ip = (ivd_set_display_frame_ip_t  *)pv_api_ip;
+    dec_disp_op = (ivd_set_display_frame_op_t  *)pv_api_op;
+    dec_disp_op->u4_error_code = 0;
+
+    u4_num_disp_bufs = dec_disp_ip->num_disp_bufs;
+    if(u4_num_disp_bufs > BUF_MGR_MAX_CNT)
+        u4_num_disp_bufs = BUF_MGR_MAX_CNT;
+
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    if(ps_dec_state->u4_share_disp_buf)
+    {
+        pic_buf_t *ps_pic_buf;
+        ps_pic_buf = (pic_buf_t *)ps_dec_state->pv_pic_buf_base;
+        for(i = 0; i < u4_num_disp_bufs; i++)
+        {
+
+            ps_pic_buf->pu1_y = dec_disp_ip->s_disp_buffer[i].pu1_bufs[0];
+            if(IV_YUV_420P == ps_dec_state->i4_chromaFormat)
+            {
+                ps_pic_buf->pu1_u = dec_disp_ip->s_disp_buffer[i].pu1_bufs[1];
+                ps_pic_buf->pu1_v = dec_disp_ip->s_disp_buffer[i].pu1_bufs[2];
+            }
+            else
+            {
+                ps_pic_buf->pu1_u = ps_dec_state->pu1_chroma_ref_buf[i];
+                ps_pic_buf->pu1_v = ps_dec_state->pu1_chroma_ref_buf[i] +
+                        ((ps_dec_state->u2_create_max_width * ps_dec_state->u2_create_max_height) >> 2);
+            }
+
+            ps_pic_buf->i4_buf_id = i;
+
+            ps_pic_buf->u1_used_as_ref = 0;
+
+            ps_pic_buf->u4_ts = 0;
+
+            impeg2_buf_mgr_add(ps_dec_state->pv_pic_buf_mg, ps_pic_buf, i);
+            impeg2_buf_mgr_set_status(ps_dec_state->pv_pic_buf_mg, i, BUF_MGR_DISP);
+            ps_pic_buf++;
+
+        }
+    }
+    memcpy(&(ps_dec_state->as_disp_buffers[0]),
+           &(dec_disp_ip->s_disp_buffer),
+           u4_num_disp_bufs * sizeof(ivd_out_bufdesc_t));
+
+    return IV_SUCCESS;
+
+}
+
+IV_API_CALL_STATUS_T impeg2d_api_set_num_cores(iv_obj_t *ps_dechdl,
+                                               void *pv_api_ip,
+                                               void *pv_api_op)
+{
+    impeg2d_ctl_set_num_cores_ip_t   *ps_ip;
+    impeg2d_ctl_set_num_cores_op_t *ps_op;
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+
+    ps_ip  = (impeg2d_ctl_set_num_cores_ip_t *)pv_api_ip;
+    ps_op =  (impeg2d_ctl_set_num_cores_op_t *)pv_api_op;
+
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    if(ps_ip->u4_num_cores > 0)
+    {
+
+
+        WORD32 i;
+        for(i = 0; i < MAX_THREADS; i++)
+            ps_dec_state_multi_core->ps_dec_state[i]->i4_num_cores = ps_ip->u4_num_cores;
+    }
+    else
+    {
+        ps_dec_state->i4_num_cores = 1;
+    }
+    ps_op->u4_error_code = IV_SUCCESS;
+
+    return IV_SUCCESS;
+}
+
+/**
+*******************************************************************************
+*
+* @brief
+*  Sets Processor type
+*
+* @par Description:
+*  Sets Processor type
+*
+* @param[in] ps_codec_obj
+*  Pointer to codec object at API level
+*
+* @param[in] pv_api_ip
+*  Pointer to input argument structure
+*
+* @param[out] pv_api_op
+*  Pointer to output argument structure
+*
+* @returns  Status
+*
+* @remarks
+*
+*
+*******************************************************************************
+*/
+
+IV_API_CALL_STATUS_T impeg2d_set_processor(iv_obj_t *ps_codec_obj,
+                            void *pv_api_ip,
+                            void *pv_api_op)
+{
+    impeg2d_ctl_set_processor_ip_t *ps_ip;
+    impeg2d_ctl_set_processor_op_t *ps_op;
+    dec_state_t *ps_codec;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_codec_obj->pv_codec_handle);
+    ps_codec = ps_dec_state_multi_core->ps_dec_state[0];
+
+    ps_ip = (impeg2d_ctl_set_processor_ip_t *)pv_api_ip;
+    ps_op = (impeg2d_ctl_set_processor_op_t *)pv_api_op;
+
+    ps_codec->e_processor_arch = (IVD_ARCH_T)ps_ip->u4_arch;
+    ps_codec->e_processor_soc = (IVD_SOC_T)ps_ip->u4_soc;
+
+    impeg2d_init_function_ptr(ps_codec);
+
+
+    ps_op->u4_error_code = 0;
+    return IV_SUCCESS;
+}
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_fill_mem_rec                                     */
+/*                                                                           */
+/*  Description   :                                                          */
+/*  Inputs        :                                                          */
+/*  Globals       :                                                          */
+/*  Processing    :                                                          */
+/*  Outputs       :                                                          */
+/*  Returns       :                                                          */
+/*                                                                           */
+/*  Issues        :                                                          */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         17 09 2007  Rajendra C Y          Draft                           */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_fill_mem_rec(impeg2d_fill_mem_rec_ip_t *ps_ip,
+                  impeg2d_fill_mem_rec_op_t *ps_op)
+{
+    UWORD32 u4_i;
+
+    UWORD8 u1_no_rec = 0;
+    UWORD32 max_frm_width,max_frm_height,max_frm_size;
+    iv_mem_rec_t *ps_mem_rec = ps_ip->s_ivd_fill_mem_rec_ip_t.pv_mem_rec_location;
+    WORD32 i4_num_threads;
+    WORD32 i4_share_disp_buf, i4_chroma_format;
+    WORD32 i4_chroma_size;
+
+    max_frm_width = ALIGN16(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_max_frm_wd);
+    max_frm_height = ALIGN16(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_max_frm_ht);
+
+    max_frm_size = (max_frm_width * max_frm_height * 3) >> 1;/* 420 P */
+
+    i4_chroma_size = max_frm_width * max_frm_height / 4;
+
+    if(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_size > offsetof(impeg2d_fill_mem_rec_ip_t, u4_share_disp_buf))
+    {
+#ifndef LOGO_EN
+        i4_share_disp_buf = ps_ip->u4_share_disp_buf;
+#else
+        i4_share_disp_buf = 0;
+#endif
+    }
+    else
+    {
+        i4_share_disp_buf = 0;
+    }
+    if(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_size > offsetof(impeg2d_fill_mem_rec_ip_t, e_output_format))
+    {
+        i4_chroma_format = ps_ip->e_output_format;
+    }
+    else
+    {
+        i4_chroma_format = -1;
+    }
+
+
+    if( (i4_chroma_format != IV_YUV_420P) &&
+        (i4_chroma_format != IV_YUV_420SP_UV) &&
+        (i4_chroma_format != IV_YUV_420SP_VU))
+    {
+        i4_share_disp_buf = 0;
+    }
+
+    /*************************************************************************/
+    /*          Fill the memory requirement XDM Handle         */
+    /*************************************************************************/
+    /* ! */
+    ps_mem_rec->u4_mem_alignment = 128 /* 128 byte alignment*/;
+    ps_mem_rec->e_mem_type      = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+    ps_mem_rec->u4_mem_size     = sizeof(iv_obj_t);
+
+    ps_mem_rec++;
+    u1_no_rec++;
+
+    {
+        /*************************************************************************/
+        /*        Fill the memory requirement for threads context         */
+        /*************************************************************************/
+        /* ! */
+        ps_mem_rec->u4_mem_alignment = 128 /* 128 byte alignment*/;
+        ps_mem_rec->e_mem_type      = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+        ps_mem_rec->u4_mem_size     = sizeof(dec_state_multi_core_t);
+
+        ps_mem_rec++;
+        u1_no_rec++;
+    }
+
+    for(i4_num_threads = 0; i4_num_threads < MAX_THREADS; i4_num_threads++)
+    {
+        /*************************************************************************/
+        /*          Fill the memory requirement for MPEG2 Decoder Context        */
+        /*************************************************************************/
+        /* ! */
+        ps_mem_rec->u4_mem_alignment = 128 /* 128 byte alignment*/;
+        ps_mem_rec->e_mem_type      = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+        ps_mem_rec->u4_mem_size     = sizeof(dec_state_t);
+
+        ps_mem_rec++;
+        u1_no_rec++;
+
+        /* To store thread handle */
+        ps_mem_rec->u4_mem_alignment = 128 /* 128 byte alignment*/;
+        ps_mem_rec->e_mem_type      = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+        ps_mem_rec->u4_mem_size     = ithread_get_handle_size();
+
+        ps_mem_rec++;
+        u1_no_rec++;
+
+        /*************************************************************************/
+        /*      Fill the memory requirement for Motion Compensation Buffers      */
+        /*************************************************************************/
+        ps_mem_rec->u4_mem_alignment = 128 /* 128 byte alignment*/;
+        ps_mem_rec->e_mem_type      = IV_EXTERNAL_CACHEABLE_SCRATCH_MEM;
+
+        /* for mc_fw_buf.pu1_y */
+        ps_mem_rec->u4_mem_size     = MB_LUMA_MEM_SIZE;
+
+        /* for mc_fw_buf.pu1_u */
+        ps_mem_rec->u4_mem_size    += MB_CHROMA_MEM_SIZE;
+
+        /* for mc_fw_buf.pu1_v */
+        ps_mem_rec->u4_mem_size    += MB_CHROMA_MEM_SIZE;
+
+        /* for mc_bk_buf.pu1_y */
+        ps_mem_rec->u4_mem_size    += MB_LUMA_MEM_SIZE;
+
+        /* for mc_bk_buf.pu1_u */
+        ps_mem_rec->u4_mem_size    += MB_CHROMA_MEM_SIZE;
+
+        /* for mc_bk_buf.pu1_v */
+        ps_mem_rec->u4_mem_size    += MB_CHROMA_MEM_SIZE;
+
+        /* for mc_buf.pu1_y */
+        ps_mem_rec->u4_mem_size    += MB_LUMA_MEM_SIZE;
+
+        /* for mc_buf.pu1_u */
+        ps_mem_rec->u4_mem_size    += MB_CHROMA_MEM_SIZE;
+
+        /* for mc_buf.pu1_v */
+        ps_mem_rec->u4_mem_size    += MB_CHROMA_MEM_SIZE;
+
+        ps_mem_rec++;
+        u1_no_rec++;
+
+
+        /*************************************************************************/
+        /*             Fill the memory requirement Stack Context                 */
+        /*************************************************************************/
+        /* ! */
+        ps_mem_rec->u4_mem_alignment = 128 /* 128 byte alignment*/;
+        ps_mem_rec->e_mem_type      = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+        ps_mem_rec->u4_mem_size     = 392;
+
+        ps_mem_rec++;
+        u1_no_rec++;
+    }
+
+
+
+    {
+        /*************************************************************************/
+        /*        Fill the memory requirement for Picture Buffer Manager         */
+        /*************************************************************************/
+        /* ! */
+        ps_mem_rec->u4_mem_alignment = 128 /* 128 byte alignment*/;
+        ps_mem_rec->e_mem_type      = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+        ps_mem_rec->u4_mem_size     = sizeof(buf_mgr_t) + sizeof(pic_buf_t) * BUF_MGR_MAX_CNT;
+
+        ps_mem_rec++;
+        u1_no_rec++;
+    }
+    /*************************************************************************/
+    /*             Internal Frame Buffers                                    */
+    /*************************************************************************/
+/* ! */
+
+    {
+        for(u4_i = 0; u4_i < NUM_INT_FRAME_BUFFERS; u4_i++)
+        {
+            /* ! */
+            ps_mem_rec->u4_mem_alignment = 128 /* 128 byte alignment*/;
+            ps_mem_rec->e_mem_type      = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+            if(0 == i4_share_disp_buf)
+                ps_mem_rec->u4_mem_size     = max_frm_size;
+            else if(IV_YUV_420P != i4_chroma_format)
+            {
+                /* If color format is not 420P and it is shared, then allocate for chroma */
+                ps_mem_rec->u4_mem_size     = i4_chroma_size * 2;
+            }
+            else
+                ps_mem_rec->u4_mem_size     = 64;
+            ps_mem_rec++;
+            u1_no_rec++;
+        }
+    }
+
+
+
+    {
+        WORD32 i4_job_queue_size;
+        WORD32 i4_num_jobs;
+
+        /* One job per row of MBs */
+        i4_num_jobs  = max_frm_height >> 4;
+
+        /* One format convert/frame copy job per row of MBs for non-shared mode*/
+        i4_num_jobs  += max_frm_height >> 4;
+
+
+        i4_job_queue_size = impeg2_jobq_ctxt_size();
+        i4_job_queue_size += i4_num_jobs * sizeof(job_t);
+        ps_mem_rec->u4_mem_size = i4_job_queue_size;
+        ps_mem_rec->u4_mem_alignment = 128;
+        ps_mem_rec->e_mem_type       = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+
+        ps_mem_rec++;
+        u1_no_rec++;
+
+    }
+
+    ps_mem_rec->u4_mem_alignment = 128;
+    ps_mem_rec->e_mem_type       = IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM;
+    ps_mem_rec->u4_mem_size      = sizeof(iv_mem_rec_t) * (NUM_MEM_RECORDS);
+    ps_mem_rec++;
+    u1_no_rec++;
+    ps_op->s_ivd_fill_mem_rec_op_t.u4_num_mem_rec_filled = u1_no_rec;
+    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code = 0;
+}
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_get_version                                  */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         22 10 2008    100356         Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_get_version(iv_obj_t *ps_dechdl,
+                                             void *pv_api_ip,
+                                             void *pv_api_op)
+{
+    char au1_version_string[512];
+
+    impeg2d_ctl_getversioninfo_ip_t *ps_ip;
+    impeg2d_ctl_getversioninfo_op_t *ps_op;
+
+    UNUSED(ps_dechdl);
+
+    ps_ip = (impeg2d_ctl_getversioninfo_ip_t *)pv_api_ip;
+    ps_op = (impeg2d_ctl_getversioninfo_op_t *)pv_api_op;
+
+    ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code = IV_SUCCESS;
+
+    VERSION(au1_version_string, CODEC_NAME, CODEC_RELEASE_TYPE, CODEC_RELEASE_VER,
+            CODEC_VENDOR);
+
+    if((WORD32)ps_ip->s_ivd_ctl_getversioninfo_ip_t.u4_version_buffer_size <= 0)
+    {
+        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code = IV_FAIL;
+        return (IV_FAIL);
+    }
+
+    if(ps_ip->s_ivd_ctl_getversioninfo_ip_t.u4_version_buffer_size
+                    >= (strlen(au1_version_string) + 1))
+    {
+        memcpy(ps_ip->s_ivd_ctl_getversioninfo_ip_t.pv_version_buffer,
+               au1_version_string, (strlen(au1_version_string) + 1));
+        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code = IV_SUCCESS;
+    }
+    else
+    {
+        ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code = IV_FAIL;
+    }
+
+    return (IV_SUCCESS);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_get_buf_info                                 */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         22 10 2008    100356         Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_get_buf_info(iv_obj_t *ps_dechdl,
+                                              void *pv_api_ip,
+                                              void *pv_api_op)
+{
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    impeg2d_ctl_getbufinfo_ip_t *ps_ctl_bufinfo_ip =
+                    (impeg2d_ctl_getbufinfo_ip_t *)pv_api_ip;
+    impeg2d_ctl_getbufinfo_op_t *ps_ctl_bufinfo_op =
+                    (impeg2d_ctl_getbufinfo_op_t *)pv_api_op;
+    UWORD32 u4_i, u4_stride, u4_height;
+    UNUSED(ps_ctl_bufinfo_ip);
+
+    ps_dec_state_multi_core =
+                    (dec_state_multi_core_t *)(ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_num_in_bufs = 1;
+    ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_num_out_bufs = 1;
+
+    if(ps_dec_state->i4_chromaFormat == IV_YUV_420P)
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_num_out_bufs =
+                        MIN_OUT_BUFS_420;
+    }
+    else if((ps_dec_state->i4_chromaFormat == IV_YUV_420SP_UV)
+                    || (ps_dec_state->i4_chromaFormat == IV_YUV_420SP_VU))
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_num_out_bufs =
+                        MIN_OUT_BUFS_420SP;
+    }
+    else if(ps_dec_state->i4_chromaFormat == IV_YUV_422ILE)
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_num_out_bufs =
+                        MIN_OUT_BUFS_422ILE;
+    }
+    else if(ps_dec_state->i4_chromaFormat == IV_RGB_565)
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_num_out_bufs =
+                        MIN_OUT_BUFS_RGB565;
+    }
+    else
+    {
+        //Invalid chroma format; Error code may be updated, verify in testing if needed
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code =
+                        IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED;
+        return IV_FAIL;
+    }
+
+    for(u4_i = 0; u4_i < IVD_VIDDEC_MAX_IO_BUFFERS; u4_i++)
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_in_buf_size[u4_i] =
+                        0;
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[u4_i] =
+                        0;
+    }
+
+    for(u4_i = 0;
+        u4_i < ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_num_in_bufs;
+        u4_i++)
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_in_buf_size[u4_i] =
+                        MAX_BITSTREAM_BUFFER_SIZE;
+    }
+
+    if (0 == ps_dec_state->u4_frm_buf_stride)
+    {
+        if (1 == ps_dec_state->u2_header_done)
+        {
+            u4_stride   = ps_dec_state->u2_horizontal_size;
+        }
+        else
+        {
+            u4_stride   = ps_dec_state->u2_create_max_width;
+        }
+    }
+    else
+    {
+        u4_stride = ps_dec_state->u4_frm_buf_stride;
+    }
+    u4_height = ((ps_dec_state->u2_frame_height + 15) >> 4) << 4;
+
+    if(ps_dec_state->i4_chromaFormat == IV_YUV_420P)
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[0] =
+                        (u4_stride * u4_height);
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[1] =
+                        (u4_stride * u4_height) >> 2;
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[2] =
+                        (u4_stride * u4_height) >> 2;
+    }
+    else if((ps_dec_state->i4_chromaFormat == IV_YUV_420SP_UV)
+                    || (ps_dec_state->i4_chromaFormat == IV_YUV_420SP_VU))
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[0] =
+                        (u4_stride * u4_height);
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[1] =
+                        (u4_stride * u4_height) >> 1;
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[2] = 0;
+    }
+    else if(ps_dec_state->i4_chromaFormat == IV_YUV_422ILE)
+    {
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[0] =
+                        (u4_stride * u4_height) * 2;
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[1] =
+                        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_min_out_buf_size[2] =
+                                        0;
+    }
+
+    /* Adding initialization for 2 uninitialized values */
+    ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_num_disp_bufs = 1;
+    if(ps_dec_state->u4_share_disp_buf)
+        ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_num_disp_bufs =
+                        NUM_INT_FRAME_BUFFERS;
+    ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_size = MAX_FRM_SIZE;
+
+    ps_ctl_bufinfo_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code = IV_SUCCESS;
+
+    return (IV_SUCCESS);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name :  impeg2d_api_set_flush_mode                              */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         08 06 2009    100356         RAVI                                 */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_set_flush_mode(iv_obj_t *ps_dechdl,
+                                                void *pv_api_ip,
+                                                void *pv_api_op)
+{
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    impeg2d_ctl_flush_op_t *ps_ctl_dec_op =
+                    (impeg2d_ctl_flush_op_t*)pv_api_op;
+
+    UNUSED(pv_api_ip);
+
+    ps_dec_state_multi_core =
+                    (dec_state_multi_core_t *)(ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    ps_dec_state->u1_flushfrm = 1;
+
+    ps_ctl_dec_op->s_ivd_ctl_flush_op_t.u4_size =
+                    sizeof(impeg2d_ctl_flush_op_t);
+    ps_ctl_dec_op->s_ivd_ctl_flush_op_t.u4_error_code = IV_SUCCESS;
+
+    return (IV_SUCCESS);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name :  impeg2d_api_set_default                                 */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         08 06 2009    100356         RAVI                                 */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_set_default(iv_obj_t *ps_dechdl,
+                                             void *pv_api_ip,
+                                             void *pv_api_op)
+{
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    impeg2d_ctl_set_config_op_t *ps_ctl_dec_op =
+                    (impeg2d_ctl_set_config_op_t *)pv_api_op;
+
+    UNUSED(pv_api_ip);
+
+    ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_error_code  = IV_SUCCESS;
+    ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_size        =
+                    sizeof(impeg2d_ctl_set_config_op_t);
+
+    ps_dec_state_multi_core =
+                    (dec_state_multi_core_t *)(ps_dechdl->pv_codec_handle);
+    ps_dec_state            = ps_dec_state_multi_core->ps_dec_state[0];
+
+    ps_dec_state->u1_flushfrm   = 0;
+    ps_dec_state->u2_decode_header = 1;
+
+    if (1 == ps_dec_state->u2_header_done)
+    {
+        ps_dec_state->u4_frm_buf_stride = ps_dec_state->u2_frame_width;
+    }
+
+    ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_error_code = IV_SUCCESS;
+
+    return (IV_SUCCESS);
+
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name :  impeg2d_api_reset                                       */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         08 06 2009    100356         RAVI                                 */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_reset(iv_obj_t *ps_dechdl,
+                                       void *pv_api_ip,
+                                       void *pv_api_op)
+{
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    UNUSED(pv_api_ip);
+    impeg2d_ctl_reset_op_t *s_ctl_reset_op = (impeg2d_ctl_reset_op_t *)pv_api_op;
+
+    WORD32 i4_num_threads;
+
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    if(ps_dec_state_multi_core != NULL)
+    {
+        for(i4_num_threads = 0; i4_num_threads < MAX_THREADS; i4_num_threads++)
+        {
+
+            ps_dec_state = ps_dec_state_multi_core->ps_dec_state[i4_num_threads];
+
+
+            /* --------------------------------------------------------------------- */
+            /* Initializations */
+
+            ps_dec_state->u2_header_done    = 0;  /* Header decoding not done */
+            ps_dec_state->u4_frm_buf_stride = 0;
+            ps_dec_state->u2_is_mpeg2       = 0;
+        }
+    }
+    else
+    {
+        s_ctl_reset_op->s_ivd_ctl_reset_op_t.u4_error_code =
+                        IMPEG2D_INIT_NOT_DONE;
+    }
+
+    return(IV_SUCCESS);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name :  impeg2d_api_set_params                                  */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         08 06 2009    100356         RAVI                                 */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_set_params(iv_obj_t *ps_dechdl,void *pv_api_ip,void *pv_api_op)
+{
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    impeg2d_ctl_set_config_ip_t  *ps_ctl_dec_ip = (impeg2d_ctl_set_config_ip_t  *)pv_api_ip;
+    impeg2d_ctl_set_config_op_t  *ps_ctl_dec_op = (impeg2d_ctl_set_config_op_t  *)pv_api_op;
+
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    if((ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.e_vid_dec_mode != IVD_DECODE_HEADER) && (ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.e_vid_dec_mode != IVD_DECODE_FRAME))
+    {
+        ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_error_code = IV_FAIL;
+        return(IV_FAIL);
+    }
+
+    if((ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.e_frm_out_mode != IVD_DISPLAY_FRAME_OUT) && (ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.e_frm_out_mode != IVD_DECODE_FRAME_OUT))
+    {
+        ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_error_code = IV_FAIL;
+        return(IV_FAIL);
+    }
+
+    if( (WORD32) ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.e_frm_skip_mode < IVD_SKIP_NONE)
+    {
+        ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_error_code = IV_FAIL;
+        return(IV_FAIL);
+    }
+
+    if(ps_dec_state->u2_header_done == 1)
+    {
+        if(((WORD32)ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd < 0) ||
+            ((ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd != 0) && (ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd < ps_dec_state->u2_frame_width)))
+        {
+            ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_error_code = IV_FAIL;
+            return(IV_FAIL);
+        }
+
+    }
+    else
+    {
+        if(((WORD32)ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd < 0) ||
+            ((ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd != 0) && (ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd < ps_dec_state->u2_horizontal_size)))
+        {
+            ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_error_code = IV_FAIL;
+            return(IV_FAIL);
+        }
+    }
+
+
+    ps_dec_state->u2_decode_header    = (UWORD8)ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.e_vid_dec_mode;
+
+    if(ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd != 0)
+    {
+        if(ps_dec_state->u2_header_done == 1)
+        {
+            if (ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd > ps_dec_state->u2_frame_width)
+            {
+                ps_dec_state->u4_frm_buf_stride = ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd;
+            }
+        }
+        else
+        {
+            ps_dec_state->u4_frm_buf_stride = ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.u4_disp_wd;
+        }
+
+    }
+    else
+    {
+
+            if(ps_dec_state->u2_header_done == 1)
+            {
+                ps_dec_state->u4_frm_buf_stride = ps_dec_state->u2_frame_width;
+            }
+            else
+            {
+                ps_dec_state->u4_frm_buf_stride = 0;
+            }
+    }
+
+
+        if(ps_ctl_dec_ip->s_ivd_ctl_set_config_ip_t.e_vid_dec_mode  == IVD_DECODE_FRAME)
+        {
+            ps_dec_state->u1_flushfrm = 0;
+        }
+
+
+    ps_ctl_dec_op->s_ivd_ctl_set_config_op_t.u4_error_code = IV_SUCCESS;
+    return(IV_SUCCESS);
+
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name :  impeg2d_api_get_status                                  */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         08 06 2009    100356         RAVI                                 */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_get_status(iv_obj_t *ps_dechdl,
+                                                  void *pv_api_ip,
+                                                  void *pv_api_op)
+{
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    UWORD32 u4_i,u4_stride,u4_height;
+    impeg2d_ctl_getstatus_ip_t *ps_ctl_dec_ip = (impeg2d_ctl_getstatus_ip_t *)pv_api_ip;
+    impeg2d_ctl_getstatus_op_t *ps_ctl_dec_op = (impeg2d_ctl_getstatus_op_t *)pv_api_op;
+    UNUSED(ps_ctl_dec_ip);
+
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_size             = sizeof(impeg2d_ctl_getstatus_op_t);
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_num_disp_bufs    = 1;
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_pic_ht           = ps_dec_state->u2_frame_height;
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_pic_wd           = ps_dec_state->u2_frame_width;
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_frame_rate           = ps_dec_state->u2_framePeriod;
+
+
+    if(ps_dec_state->u2_progressive_sequence == 1)
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.e_content_type          =   IV_PROGRESSIVE ;
+    else
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.e_content_type          = IV_INTERLACED;
+
+
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.e_output_chroma_format  = (IV_COLOR_FORMAT_T)ps_dec_state->i4_chromaFormat;
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_num_in_bufs          = 1;
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_num_out_bufs     = 1;
+
+
+    if(ps_dec_state->i4_chromaFormat == IV_YUV_420P)
+    {
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_num_out_bufs     = MIN_OUT_BUFS_420;
+    }
+    else if(ps_dec_state->i4_chromaFormat == IV_YUV_422ILE)
+    {
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_num_out_bufs     = MIN_OUT_BUFS_422ILE;
+    }
+    else if(ps_dec_state->i4_chromaFormat == IV_RGB_565)
+    {
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
+    }
+    else
+    {
+        //Invalid chroma format; Error code may be updated, verify in testing if needed
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_error_code   = IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED;
+        return IV_FAIL;
+    }
+
+    memset(&ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_in_buf_size[0],0,(sizeof(UWORD32)*IVD_VIDDEC_MAX_IO_BUFFERS));
+    memset(&ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[0],0,(sizeof(UWORD32)*IVD_VIDDEC_MAX_IO_BUFFERS));
+
+    for(u4_i = 0; u4_i < ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_num_in_bufs; u4_i++)
+    {
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_in_buf_size[u4_i] = MAX_BITSTREAM_BUFFER_SIZE;
+    }
+
+    u4_stride = ps_dec_state->u4_frm_buf_stride;
+    u4_height = ((ps_dec_state->u2_frame_height + 15) >> 4) << 4;
+
+    if(ps_dec_state->i4_chromaFormat == IV_YUV_420P)
+    {
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[0] = (u4_stride * u4_height);
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[1] = (u4_stride * u4_height)>>2 ;
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[2] = (u4_stride * u4_height)>>2;
+    }
+    else if((ps_dec_state->i4_chromaFormat == IV_YUV_420SP_UV) || (ps_dec_state->i4_chromaFormat == IV_YUV_420SP_VU))
+    {
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[0] = (u4_stride * u4_height);
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[1] = (u4_stride * u4_height)>>1 ;
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[2] = 0;
+    }
+    else if(ps_dec_state->i4_chromaFormat == IV_YUV_422ILE)
+    {
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[0] = (u4_stride * u4_height)*2;
+        ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[1] = ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_min_out_buf_size[2] = 0;
+    }
+
+    ps_ctl_dec_op->s_ivd_ctl_getstatus_op_t.u4_error_code = IV_SUCCESS;
+
+    return(IV_SUCCESS);
+
+}
+
+/**
+*******************************************************************************
+*
+* @brief
+*  Gets frame dimensions/offsets
+*
+* @par Description:
+*  Gets frame buffer chararacteristics such a x & y offsets  display and
+* buffer dimensions
+*
+* @param[in] ps_codec_obj
+*  Pointer to codec object at API level
+*
+* @param[in] pv_api_ip
+*  Pointer to input argument structure
+*
+* @param[out] pv_api_op
+*  Pointer to output argument structure
+*
+* @returns  Status
+*
+* @remarks
+*
+*
+*******************************************************************************
+*/
+IV_API_CALL_STATUS_T impeg2d_get_frame_dimensions(iv_obj_t *ps_codec_obj,
+                                   void *pv_api_ip,
+                                   void *pv_api_op)
+{
+    impeg2d_ctl_get_frame_dimensions_ip_t *ps_ip;
+    impeg2d_ctl_get_frame_dimensions_op_t *ps_op;
+    WORD32 disp_wd, disp_ht, buffer_wd, buffer_ht, x_offset, y_offset;
+    dec_state_t *ps_codec;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_codec_obj->pv_codec_handle);
+    ps_codec = ps_dec_state_multi_core->ps_dec_state[0];
+
+
+    ps_ip = (impeg2d_ctl_get_frame_dimensions_ip_t *)pv_api_ip;
+    ps_op = (impeg2d_ctl_get_frame_dimensions_op_t *)pv_api_op;
+    UNUSED(ps_ip);
+    if(ps_codec->u2_header_done)
+    {
+        disp_wd = ps_codec->u2_horizontal_size;
+        disp_ht = ps_codec->u2_vertical_size;
+
+        if(0 == ps_codec->u4_share_disp_buf)
+        {
+            buffer_wd = disp_wd;
+            buffer_ht = disp_ht;
+        }
+        else
+        {
+            buffer_wd = ps_codec->u2_frame_width;
+            buffer_ht = ps_codec->u2_frame_height;
+        }
+    }
+    else
+    {
+
+        disp_wd = ps_codec->u2_create_max_width;
+        disp_ht = ps_codec->u2_create_max_height;
+
+        if(0 == ps_codec->u4_share_disp_buf)
+        {
+            buffer_wd = disp_wd;
+            buffer_ht = disp_ht;
+        }
+        else
+        {
+            buffer_wd = ALIGN16(disp_wd);
+            buffer_ht = ALIGN16(disp_ht);
+
+        }
+    }
+    if(ps_codec->u2_frame_width > buffer_wd)
+        buffer_wd = ps_codec->u2_frame_width;
+
+    x_offset = 0;
+    y_offset = 0;
+
+
+    ps_op->u4_disp_wd[0] = disp_wd;
+    ps_op->u4_disp_ht[0] = disp_ht;
+    ps_op->u4_buffer_wd[0] = buffer_wd;
+    ps_op->u4_buffer_ht[0] = buffer_ht;
+    ps_op->u4_x_offset[0] = x_offset;
+    ps_op->u4_y_offset[0] = y_offset;
+
+    ps_op->u4_disp_wd[1] = ps_op->u4_disp_wd[2] = ((ps_op->u4_disp_wd[0] + 1)
+                    >> 1);
+    ps_op->u4_disp_ht[1] = ps_op->u4_disp_ht[2] = ((ps_op->u4_disp_ht[0] + 1)
+                    >> 1);
+    ps_op->u4_buffer_wd[1] = ps_op->u4_buffer_wd[2] = (ps_op->u4_buffer_wd[0]
+                    >> 1);
+    ps_op->u4_buffer_ht[1] = ps_op->u4_buffer_ht[2] = (ps_op->u4_buffer_ht[0]
+                    >> 1);
+    ps_op->u4_x_offset[1] = ps_op->u4_x_offset[2] = (ps_op->u4_x_offset[0]
+                    >> 1);
+    ps_op->u4_y_offset[1] = ps_op->u4_y_offset[2] = (ps_op->u4_y_offset[0]
+                    >> 1);
+
+    if((ps_codec->i4_chromaFormat == IV_YUV_420SP_UV)
+                    || (ps_codec->i4_chromaFormat == IV_YUV_420SP_VU))
+    {
+        ps_op->u4_disp_wd[2] = 0;
+        ps_op->u4_disp_ht[2] = 0;
+        ps_op->u4_buffer_wd[2] = 0;
+        ps_op->u4_buffer_ht[2] = 0;
+        ps_op->u4_x_offset[2] = 0;
+        ps_op->u4_y_offset[2] = 0;
+
+        ps_op->u4_disp_wd[1] <<= 1;
+        ps_op->u4_buffer_wd[1] <<= 1;
+        ps_op->u4_x_offset[1] <<= 1;
+    }
+
+    return IV_SUCCESS;
+
+}
+
+IV_API_CALL_STATUS_T impeg2d_api_function (iv_obj_t *ps_dechdl, void *pv_api_ip,void *pv_api_op)
+{
+    WORD32 i4_cmd;
+    IV_API_CALL_STATUS_T u4_error_code;
+    UWORD32 *pu4_api_ip;
+
+    u4_error_code = impeg2d_api_check_struct_sanity(ps_dechdl,pv_api_ip,pv_api_op);
+    if(IV_SUCCESS != u4_error_code)
+    {
+        return u4_error_code;
+    }
+
+
+    pu4_api_ip  = (UWORD32 *)pv_api_ip;
+    i4_cmd = *(pu4_api_ip + 1);
+
+    switch(i4_cmd)
+    {
+
+    case IV_CMD_GET_NUM_MEM_REC:
+        u4_error_code = impeg2d_api_num_mem_rec((void *)pv_api_ip,(void *)pv_api_op);
+        break;
+
+    case IV_CMD_FILL_NUM_MEM_REC:
+        u4_error_code = impeg2d_api_fill_mem_rec((void *)pv_api_ip,(void *)pv_api_op);
+        break;
+
+    case IV_CMD_INIT:
+        u4_error_code = impeg2d_api_init(ps_dechdl,(void *)pv_api_ip,(void *)pv_api_op);
+        break;
+
+    case IVD_CMD_SET_DISPLAY_FRAME:
+        u4_error_code = impeg2d_api_set_display_frame(ps_dechdl,(void *)pv_api_ip,(void *)pv_api_op);
+        break;
+
+    case IVD_CMD_REL_DISPLAY_FRAME:
+        u4_error_code = impeg2d_api_rel_display_frame(ps_dechdl,(void *)pv_api_ip,(void *)pv_api_op);
+        break;
+
+    case IVD_CMD_VIDEO_DECODE:
+        u4_error_code = impeg2d_api_entity(ps_dechdl, (void *)pv_api_ip,(void *)pv_api_op);
+        break;
+
+    case IV_CMD_RETRIEVE_MEMREC:
+        u4_error_code = impeg2d_api_retrieve_mem_rec(ps_dechdl,(void *)pv_api_ip,(void *)pv_api_op);
+        break;
+
+    case IVD_CMD_VIDEO_CTL:
+        u4_error_code = impeg2d_api_ctl(ps_dechdl,(void *)pv_api_ip,(void *)pv_api_op);
+        break;
+
+    default:
+            break;
+    }
+
+    return(u4_error_code);
+
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_num_mem_rec                                  */
+/*                                                                           */
+/*  Description   : The function get the number mem records library needs    */
+/*  Inputs        : Error message                                            */
+/*  Globals       : None                                                     */
+/*  Processing    : Just prints error message to console                     */
+/*  Outputs       : Error mesage to the console                              */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : <List any issues or problems with this function>         */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         23 09 2010   Hamsalekha          Creation                             */
+/*                                                                           */
+/*****************************************************************************/
+
+
+IV_API_CALL_STATUS_T impeg2d_api_num_mem_rec(void *pv_api_ip,void *pv_api_op)
+{
+    /* To Query No of Memory Records */
+    impeg2d_num_mem_rec_ip_t *ps_query_mem_rec_ip;
+    impeg2d_num_mem_rec_op_t *ps_query_mem_rec_op;
+
+    ps_query_mem_rec_ip = (impeg2d_num_mem_rec_ip_t *)pv_api_ip;
+    ps_query_mem_rec_op = (impeg2d_num_mem_rec_op_t *)pv_api_op;
+
+    UNUSED(ps_query_mem_rec_ip);
+    ps_query_mem_rec_op->s_ivd_num_mem_rec_op_t.u4_size = sizeof(impeg2d_num_mem_rec_op_t);
+
+    ps_query_mem_rec_op->s_ivd_num_mem_rec_op_t.u4_num_mem_rec  = (UWORD32)NUM_MEM_RECORDS;
+
+    ps_query_mem_rec_op->s_ivd_num_mem_rec_op_t.u4_error_code = IV_SUCCESS;
+
+
+    return(IV_SUCCESS);
+
+}
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_fill_mem_rec                                 */
+/*                                                                           */
+/*  Description   : Thsi functions fills details of each mem record lib needs*/
+/*  Inputs        : Error message                                            */
+/*  Globals       : None                                                     */
+/*  Processing    : Just prints error message to console                     */
+/*  Outputs       : Error mesage to the console                              */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : <List any issues or problems with this function>         */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         23 09 2010   Hamsalekha          Creation                         */
+/*                                                                           */
+/*****************************************************************************/
+
+
+IV_API_CALL_STATUS_T impeg2d_api_fill_mem_rec(void *pv_api_ip,void *pv_api_op)
+{
+
+    impeg2d_fill_mem_rec_ip_t *ps_mem_q_ip;
+    impeg2d_fill_mem_rec_op_t *ps_mem_q_op;
+
+
+    ps_mem_q_ip = pv_api_ip;
+    ps_mem_q_op = pv_api_op;
+
+
+    impeg2d_fill_mem_rec((impeg2d_fill_mem_rec_ip_t *)ps_mem_q_ip,
+                           (impeg2d_fill_mem_rec_op_t *)ps_mem_q_op);
+
+
+    return(IV_SUCCESS);
+
+}
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_init                                         */
+/*                                                                           */
+/*  Description   :                                                          */
+/*  Inputs        :                                                          */
+/*  Globals       :                                                          */
+/*  Processing    :                                                          */
+/*  Outputs       :                                                          */
+/*  Returns       :                                                          */
+/*                                                                           */
+/*  Issues        :                                                          */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         17 09 2007  Rajendra C Y          Draft                           */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_init(iv_obj_t *ps_dechdl,
+                                      void *ps_ip,
+                                      void *ps_op)
+{
+    UWORD32 i;
+
+    void *pv;
+    UWORD32 u4_size;
+
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    UWORD32 u4_num_mem_rec;
+    iv_mem_rec_t *ps_mem_rec ;
+    iv_mem_rec_t *ps_frm_buf;
+    iv_obj_t *ps_dec_handle;
+    WORD32 i4_max_wd, i4_max_ht;
+
+    impeg2d_init_ip_t *ps_dec_init_ip;
+    impeg2d_init_op_t *ps_dec_init_op;
+    WORD32 i4_num_threads;
+    UWORD32 u4_share_disp_buf, u4_chroma_format;
+
+    ps_dec_init_ip = (impeg2d_init_ip_t *)ps_ip;
+    ps_dec_init_op = (impeg2d_init_op_t *)ps_op;
+
+    i4_max_wd = ALIGN16(ps_dec_init_ip->s_ivd_init_ip_t.u4_frm_max_wd);
+    i4_max_ht = ALIGN16(ps_dec_init_ip->s_ivd_init_ip_t.u4_frm_max_ht);
+
+    if(ps_dec_init_ip->s_ivd_init_ip_t.u4_size > offsetof(impeg2d_init_ip_t, u4_share_disp_buf))
+    {
+#ifndef LOGO_EN
+        u4_share_disp_buf = ps_dec_init_ip->u4_share_disp_buf;
+#else
+        u4_share_disp_buf = 0;
+#endif
+    }
+    else
+    {
+        u4_share_disp_buf = 0;
+    }
+
+    u4_chroma_format = ps_dec_init_ip->s_ivd_init_ip_t.e_output_format;
+
+    if( (u4_chroma_format != IV_YUV_420P) &&
+        (u4_chroma_format != IV_YUV_420SP_UV) &&
+        (u4_chroma_format != IV_YUV_420SP_VU))
+    {
+        u4_share_disp_buf = 0;
+    }
+
+
+
+
+
+    ps_mem_rec = ps_dec_init_ip->s_ivd_init_ip_t.pv_mem_rec_location;
+    ps_mem_rec ++;
+
+
+    ps_dec_init_op->s_ivd_init_op_t.u4_size = sizeof(impeg2d_init_op_t);
+
+
+    /* Except memTab[0], all other memTabs are initialized to zero */
+    for(i = 1; i < ps_dec_init_ip->s_ivd_init_ip_t.u4_num_mem_rec; i++)
+    {
+        memset(ps_mem_rec->pv_base,0,ps_mem_rec->u4_mem_size);
+        ps_mem_rec++;
+    }
+
+    /* Reinitializing memTab[0] memory base address */
+    ps_mem_rec     = ps_dec_init_ip->s_ivd_init_ip_t.pv_mem_rec_location;
+
+
+    /* memTab[0] is for codec Handle,redundant currently not being used */
+    ps_dec_handle  = ps_mem_rec->pv_base;
+    u4_num_mem_rec = 1;
+    ps_mem_rec++;
+
+
+
+
+
+    /* decoder handle */
+    ps_dec_state_multi_core = ps_mem_rec->pv_base;
+    u4_num_mem_rec++;
+    ps_mem_rec++;
+
+
+    {
+        ps_dec_handle->pv_codec_handle = (void *)ps_dec_state_multi_core; /* Initializing codec context */
+
+        ps_dechdl->pv_codec_handle =  (void *)ps_dec_state_multi_core;
+        ps_dechdl->pv_fxns = (void *)impeg2d_api_function;
+    }
+
+
+    for(i4_num_threads = 0; i4_num_threads < MAX_THREADS; i4_num_threads++)
+    {
+    /*************************************************************************/
+    /*                      For MPEG2 Decoder Context                        */
+    /*************************************************************************/
+    ps_dec_state = ps_mem_rec->pv_base;
+
+    ps_dec_state_multi_core->ps_dec_state[i4_num_threads] = ps_dec_state;
+
+    ps_dec_state->ps_dec_state_multi_core = ps_dec_state_multi_core;
+
+    ps_dec_state->i4_num_cores = 1;
+    /* @ */  /* Used for storing MemRecords */
+     u4_num_mem_rec++;
+     ps_mem_rec++;
+
+     /* Thread handle */
+     ps_dec_state->pv_codec_thread_handle = ps_mem_rec->pv_base;
+     u4_num_mem_rec++;
+     ps_mem_rec++;
+
+    /*************************************************************************/
+    /*                      For Motion Compensation Buffers                  */
+    /*************************************************************************/
+    pv = ps_mem_rec->pv_base;
+
+    /* for mc_fw_buf.pu1_y */
+
+    ps_dec_state->s_mc_fw_buf.pu1_y = pv;
+    pv = (void *)((UWORD8 *)pv + MB_LUMA_MEM_SIZE);
+
+    u4_size = sizeof(UWORD8) * MB_LUMA_MEM_SIZE;
+    /* for mc_fw_buf.pu1_u */
+
+    ps_dec_state->s_mc_fw_buf.pu1_u = pv;
+    pv = (void *)((UWORD8 *)pv + MB_CHROMA_MEM_SIZE);
+
+    u4_size += sizeof(UWORD8) * MB_CHROMA_MEM_SIZE;
+
+    /* for mc_fw_buf.pu1_v */
+
+    ps_dec_state->s_mc_fw_buf.pu1_v = pv;
+    pv = (void *)((UWORD8 *)pv + MB_CHROMA_MEM_SIZE);
+
+    u4_size += sizeof(UWORD8) * MB_CHROMA_MEM_SIZE;
+
+    /* for mc_bk_buf.pu1_y */
+
+    ps_dec_state->s_mc_bk_buf.pu1_y = pv;
+    pv = (void *)((UWORD8 *)pv + MB_LUMA_MEM_SIZE);
+
+    u4_size += sizeof(UWORD8) * MB_LUMA_MEM_SIZE;
+
+    /* for mc_bk_buf.pu1_u */
+
+    ps_dec_state->s_mc_bk_buf.pu1_u = pv;
+    pv = (void *)((UWORD8 *)pv + MB_CHROMA_MEM_SIZE);
+
+    u4_size += sizeof(UWORD8) * MB_CHROMA_MEM_SIZE;
+
+    /* for mc_bk_buf.pu1_v */
+
+    ps_dec_state->s_mc_bk_buf.pu1_v = pv;
+    pv = (void *)((UWORD8 *)pv + MB_CHROMA_MEM_SIZE);
+
+    u4_size += sizeof(UWORD8) * MB_CHROMA_MEM_SIZE;
+
+    /* for mc_buf.pu1_y */
+
+    ps_dec_state->s_mc_buf.pu1_y = pv;
+    pv = (void *)((UWORD8 *)pv + MB_LUMA_MEM_SIZE);
+
+    u4_size += sizeof(UWORD8) * MB_LUMA_MEM_SIZE;
+
+    /* for mc_buf.pu1_u */
+
+    ps_dec_state->s_mc_buf.pu1_u = pv;
+    pv = (void *)((UWORD8 *)pv + MB_CHROMA_MEM_SIZE);
+
+    u4_size += sizeof(UWORD8) * MB_CHROMA_MEM_SIZE;
+
+    /* for mc_buf.pu1_v */
+
+    ps_dec_state->s_mc_buf.pu1_v = pv;
+
+    u4_size += sizeof(UWORD8) * MB_CHROMA_MEM_SIZE;
+
+    u4_num_mem_rec++;
+    ps_mem_rec++;
+
+
+
+    ps_dec_state->pv_pic_buf_mg = 0;
+
+    /*************************************************************************/
+    /*        For saving stack context to support global error handling      */
+    /*************************************************************************/
+    ps_dec_state->pv_stack_cntxt = ps_mem_rec->pv_base;
+    u4_num_mem_rec++;
+    ps_mem_rec++;
+
+    }
+
+
+
+
+
+    /*************************************************************************/
+    /*                          For Picture Buffer Manager                   */
+    /*************************************************************************/
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    ps_dec_state->pv_pic_buf_mg = ps_mem_rec->pv_base;
+    ps_dec_state->pv_pic_buf_base = (UWORD8 *)ps_mem_rec->pv_base + sizeof(buf_mgr_t);
+
+    u4_num_mem_rec++;
+    ps_mem_rec++;
+
+
+
+    for(i4_num_threads = 0; i4_num_threads < MAX_THREADS; i4_num_threads++)
+    {
+
+        ps_dec_state = ps_dec_state_multi_core->ps_dec_state[i4_num_threads];
+
+
+        /* --------------------------------------------------------------------- */
+        /* Initializations */
+
+        ps_dec_state->u2_header_done  = 0;  /* Header decoding not done */
+
+
+        {
+            UWORD32 u4_max_frm_width,u4_max_frm_height;
+
+            u4_max_frm_width = ALIGN16(ps_dec_init_ip->s_ivd_init_ip_t.u4_frm_max_wd);
+            u4_max_frm_height = ALIGN16(ps_dec_init_ip->s_ivd_init_ip_t.u4_frm_max_ht);
+
+            ps_dec_state->u2_create_max_width   = u4_max_frm_width;
+            ps_dec_state->u2_create_max_height  = u4_max_frm_height;
+
+            ps_dec_state->i4_chromaFormat = ps_dec_init_ip->s_ivd_init_ip_t.e_output_format;
+            ps_dec_state->u4_frm_buf_stride  = 0 ;
+            ps_dec_state->u2_frame_width  = u4_max_frm_width;
+            ps_dec_state->u2_picture_width  = u4_max_frm_width;
+            ps_dec_state->u2_horizontal_size  = u4_max_frm_width;
+
+            ps_dec_state->u2_frame_height = u4_max_frm_height;
+            ps_dec_state->u2_vertical_size = u4_max_frm_height;
+            ps_dec_state->u4_share_disp_buf = u4_share_disp_buf;
+        }
+    }
+
+
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    if((ps_dec_state->i4_chromaFormat  == IV_YUV_422ILE)
+        &&((ps_dec_state->u2_vertical_size & 0x1) != 0))
+    {
+        //printf("Error! Height should be multiple of 2 if Chroma format is 422ILE\n");
+        ps_dec_init_op->s_ivd_init_op_t.u4_error_code = IMPEG2D_INIT_CHROMA_FORMAT_HEIGHT_ERROR;
+        return(IV_FAIL);
+
+
+    }
+
+    /* --------------------------------------------------------------------- */
+
+
+/* ! */
+    // picture buffer manager initialization will be done only for first thread
+    impeg2_disp_mgr_init(&ps_dec_state->s_disp_mgr);
+    impeg2_buf_mgr_init((buf_mgr_t *)ps_dec_state->pv_pic_buf_mg);
+
+    /*************************************************************************/
+    /*             Internal Frame Buffers                                    */
+    /*************************************************************************/
+
+
+    /* Set first frame to grey */
+    {
+        ps_frm_buf = ps_mem_rec;
+        memset(ps_frm_buf->pv_base, 128, ps_frm_buf->u4_mem_size);
+        ps_frm_buf++;
+    }
+
+    if(0 == ps_dec_state->u4_share_disp_buf)
+    {
+        pic_buf_t *ps_pic_buf;
+        ps_pic_buf = (pic_buf_t *)ps_dec_state->pv_pic_buf_base;
+        for(i = 0; i < NUM_INT_FRAME_BUFFERS; i++)
+        {
+            UWORD8 *pu1_buf;
+            pu1_buf = ps_mem_rec->pv_base;
+
+            ps_pic_buf->pu1_y = pu1_buf;
+            pu1_buf += i4_max_ht * i4_max_wd;
+
+            ps_pic_buf->pu1_u = pu1_buf;
+            pu1_buf += i4_max_ht * i4_max_wd >> 2;
+
+            ps_pic_buf->pu1_v = pu1_buf;
+            pu1_buf += i4_max_ht * i4_max_wd >> 2;
+
+            ps_pic_buf->i4_buf_id = i;
+
+            ps_pic_buf->u1_used_as_ref = 0;
+
+            ps_pic_buf->u4_ts = 0;
+
+            impeg2_buf_mgr_add(ps_dec_state->pv_pic_buf_mg, ps_pic_buf, i);
+            ps_mem_rec++;
+            ps_pic_buf++;
+        }
+        u4_num_mem_rec += NUM_INT_FRAME_BUFFERS;
+    }
+    else if (ps_dec_state->i4_chromaFormat  != IV_YUV_420P)
+    {
+        for(i = 0; i < NUM_INT_FRAME_BUFFERS; i++)
+        {
+            ps_dec_state->pu1_chroma_ref_buf[i] = ps_mem_rec->pv_base;
+            ps_mem_rec++;
+        }
+
+        u4_num_mem_rec += NUM_INT_FRAME_BUFFERS;
+    }
+    else
+    {
+        ps_mem_rec+=NUM_INT_FRAME_BUFFERS;
+        u4_num_mem_rec += NUM_INT_FRAME_BUFFERS;
+    }
+
+
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+
+    ps_dec_state->pv_jobq_buf = ps_mem_rec->pv_base;
+    ps_dec_state->i4_jobq_buf_size = ps_mem_rec->u4_mem_size;
+    ps_mem_rec++;
+
+    if(u4_num_mem_rec > ps_dec_init_ip->s_ivd_init_ip_t.u4_num_mem_rec)
+    {
+        ps_dec_init_op->s_ivd_init_op_t.u4_error_code = IMPEG2D_INIT_NUM_MEM_REC_NOT_SUFFICIENT;
+        return(IV_FAIL);
+
+    }
+
+    ps_dec_state->u1_flushfrm = 0;
+    ps_dec_state->u1_flushcnt = 0;
+    ps_dec_state->pv_jobq = impeg2_jobq_init(ps_dec_state->pv_jobq_buf, ps_dec_state->i4_jobq_buf_size);
+
+
+    /*************************************************************************/
+    /*        MemTab[12] is used for storing TabRecords      */
+    /*************************************************************************/
+    ps_dec_state->pv_memTab     = (void *)ps_mem_rec->pv_base;
+    memcpy(ps_mem_rec->pv_base,ps_dec_init_ip->s_ivd_init_ip_t.pv_mem_rec_location, ps_mem_rec->u4_mem_size);
+    /* Updating in Decoder Context with memRecords  */
+    u4_num_mem_rec++;
+    ps_mem_rec++;
+    ps_dec_state->u4_num_mem_records = u4_num_mem_rec;
+
+
+    ps_dec_state->u4_num_frames_decoded    = 0;
+    ps_dec_state->aps_ref_pics[0] = NULL;
+    ps_dec_state->aps_ref_pics[1] = NULL;
+
+    ps_dec_init_op->s_ivd_init_op_t.u4_error_code = IV_SUCCESS;
+    impeg2d_init_arch(ps_dec_state);
+
+    impeg2d_init_function_ptr(ps_dec_state);
+
+    return(IV_SUCCESS);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_retrieve_mem_rec                             */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         22 10 2008    100356         Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_retrieve_mem_rec(iv_obj_t *ps_dechdl,
+                                            void *pv_api_ip,
+                                            void *pv_api_op)
+{
+    UWORD32 u4_i;
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+    iv_mem_rec_t *ps_mem_rec;
+    iv_mem_rec_t *ps_temp_rec;
+
+
+
+    impeg2d_retrieve_mem_rec_ip_t *ps_retr_mem_rec_ip;
+    impeg2d_retrieve_mem_rec_op_t *ps_retr_mem_rec_op;
+
+    ps_retr_mem_rec_ip  = (impeg2d_retrieve_mem_rec_ip_t *)pv_api_ip;
+    ps_retr_mem_rec_op  = (impeg2d_retrieve_mem_rec_op_t *)pv_api_op;
+
+    ps_mem_rec          = ps_retr_mem_rec_ip->s_ivd_retrieve_mem_rec_ip_t.pv_mem_rec_location;
+    ps_dec_state_multi_core = (dec_state_multi_core_t *) (ps_dechdl->pv_codec_handle);
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+    ps_temp_rec        = ps_dec_state->pv_memTab;
+
+    for(u4_i = 0; u4_i < (ps_dec_state->u4_num_mem_records);u4_i++)
+    {
+        ps_mem_rec[u4_i].u4_mem_size        = ps_temp_rec[u4_i].u4_mem_size;
+        ps_mem_rec[u4_i].u4_mem_alignment   = ps_temp_rec[u4_i].u4_mem_alignment;
+        ps_mem_rec[u4_i].e_mem_type         = ps_temp_rec[u4_i].e_mem_type;
+        ps_mem_rec[u4_i].pv_base            = ps_temp_rec[u4_i].pv_base;
+    }
+
+    ps_retr_mem_rec_op->s_ivd_retrieve_mem_rec_op_t.u4_error_code       = IV_SUCCESS;
+    ps_retr_mem_rec_op->s_ivd_retrieve_mem_rec_op_t.u4_num_mem_rec_filled   = ps_dec_state->u4_num_mem_records;
+
+    impeg2_jobq_deinit(ps_dec_state->pv_jobq);
+    IMPEG2D_PRINT_STATISTICS();
+
+
+    return(IV_SUCCESS);
+
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name :   impeg2d_api_ctl                                        */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         22 10 2008    100356         Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_ctl(iv_obj_t *ps_dechdl,
+                                     void *pv_api_ip,
+                                     void *pv_api_op)
+{
+    WORD32 i4_sub_cmd;
+    UWORD32 *pu4_api_ip;
+    IV_API_CALL_STATUS_T u4_error_code;
+
+    pu4_api_ip = (UWORD32 *)pv_api_ip;
+    i4_sub_cmd = *(pu4_api_ip + 2);
+
+    switch(i4_sub_cmd)
+    {
+        case IVD_CMD_CTL_GETPARAMS:
+            u4_error_code = impeg2d_api_get_status(ps_dechdl, (void *)pv_api_ip,
+                                                   (void *)pv_api_op);
+            break;
+
+        case IVD_CMD_CTL_SETPARAMS:
+            u4_error_code = impeg2d_api_set_params(ps_dechdl, (void *)pv_api_ip,
+                                                   (void *)pv_api_op);
+            break;
+
+        case IVD_CMD_CTL_RESET:
+            u4_error_code = impeg2d_api_reset(ps_dechdl, (void *)pv_api_ip,
+                                              (void *)pv_api_op);
+            break;
+
+        case IVD_CMD_CTL_SETDEFAULT:
+            u4_error_code = impeg2d_api_set_default(ps_dechdl,
+                                                          (void *)pv_api_ip,
+                                                          (void *)pv_api_op);
+            break;
+
+        case IVD_CMD_CTL_FLUSH:
+            u4_error_code = impeg2d_api_set_flush_mode(ps_dechdl,
+                                                             (void *)pv_api_ip,
+                                                             (void *)pv_api_op);
+            break;
+
+        case IVD_CMD_CTL_GETBUFINFO:
+            u4_error_code = impeg2d_api_get_buf_info(ps_dechdl,
+                                                           (void *)pv_api_ip,
+                                                           (void *)pv_api_op);
+            break;
+
+        case IVD_CMD_CTL_GETVERSION:
+            u4_error_code = impeg2d_api_get_version(ps_dechdl, (void *)pv_api_ip,
+                                                      (void *)pv_api_op);
+            break;
+
+        case IMPEG2D_CMD_CTL_SET_NUM_CORES:
+            u4_error_code = impeg2d_api_set_num_cores(ps_dechdl,
+                                                         (void *)pv_api_ip,
+                                                         (void *)pv_api_op);
+            break;
+
+        case IMPEG2D_CMD_CTL_GET_BUFFER_DIMENSIONS:
+            u4_error_code = impeg2d_get_frame_dimensions(ps_dechdl,
+                                                       (void *)pv_api_ip,
+                                                       (void *)pv_api_op);
+            break;
+
+        case IMPEG2D_CMD_CTL_SET_PROCESSOR:
+            u4_error_code = impeg2d_set_processor(ps_dechdl, (void *)pv_api_ip,
+                                                (void *)pv_api_op);
+            break;
+
+        default:
+            u4_error_code = IV_FAIL;
+            break;
+    }
+
+    return (u4_error_code);
+
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_api_check_struct_sanity                          */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         22 10 2008    100356         Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+IV_API_CALL_STATUS_T impeg2d_api_check_struct_sanity(iv_obj_t *ps_handle,
+                                                    void *pv_api_ip,
+                                                    void *pv_api_op)
+{
+    WORD32  i4_cmd;
+    UWORD32 *pu4_api_ip;
+    UWORD32 *pu4_api_op;
+    WORD32 i,j;
+
+    if(NULL == pv_api_op)
+        return(IV_FAIL);
+
+    if(NULL == pv_api_ip)
+        return(IV_FAIL);
+
+    pu4_api_ip  = (UWORD32 *)pv_api_ip;
+    pu4_api_op  = (UWORD32 *)pv_api_op;
+    i4_cmd = (IVD_API_COMMAND_TYPE_T)*(pu4_api_ip + 1);
+
+    /* error checks on handle */
+    switch(i4_cmd)
+    {
+        case IV_CMD_GET_NUM_MEM_REC:
+        case IV_CMD_FILL_NUM_MEM_REC:
+            break;
+        case IV_CMD_INIT:
+            if(ps_handle == NULL)
+            {
+                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
+                *(pu4_api_op + 1) |= IVD_HANDLE_NULL;
+                return IV_FAIL;
+            }
+
+            if(ps_handle->u4_size != sizeof(iv_obj_t))
+            {
+                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
+                *(pu4_api_op + 1) |= IVD_HANDLE_STRUCT_SIZE_INCORRECT;
+                return IV_FAIL;
+            }
+            break;
+        case IVD_CMD_GET_DISPLAY_FRAME:
+        case IVD_CMD_VIDEO_DECODE:
+        case IV_CMD_RETRIEVE_MEMREC:
+        case IVD_CMD_SET_DISPLAY_FRAME:
+        case IVD_CMD_REL_DISPLAY_FRAME:
+        case IVD_CMD_VIDEO_CTL:
+            {
+            if(ps_handle == NULL)
+            {
+                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
+                *(pu4_api_op + 1) |= IVD_HANDLE_NULL;
+                return IV_FAIL;
+            }
+
+            if(ps_handle->u4_size != sizeof(iv_obj_t))
+            {
+                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
+                *(pu4_api_op + 1) |= IVD_HANDLE_STRUCT_SIZE_INCORRECT;
+                return IV_FAIL;
+            }
+            if(ps_handle->pv_fxns != impeg2d_api_function)
+            {
+                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
+                    *(pu4_api_op + 1) |= IVD_INVALID_HANDLE_NULL;
+                return IV_FAIL;
+            }
+
+            if(ps_handle->pv_codec_handle == NULL)
+            {
+                *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
+                    *(pu4_api_op + 1) |= IVD_INVALID_HANDLE_NULL;
+                return IV_FAIL;
+            }
+            }
+            break;
+        default:
+            *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
+            *(pu4_api_op + 1) |= IVD_INVALID_API_CMD;
+            return IV_FAIL;
+    }
+
+    switch(i4_cmd)
+    {
+        case IV_CMD_GET_NUM_MEM_REC:
+            {
+                impeg2d_num_mem_rec_ip_t *ps_ip = (impeg2d_num_mem_rec_ip_t *)pv_api_ip;
+                impeg2d_num_mem_rec_op_t *ps_op = (impeg2d_num_mem_rec_op_t *)pv_api_op;
+                ps_op->s_ivd_num_mem_rec_op_t.u4_error_code = 0;
+
+                if(ps_ip->s_ivd_num_mem_rec_ip_t.u4_size != sizeof(impeg2d_num_mem_rec_ip_t))
+                {
+                    ps_op->s_ivd_num_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_num_mem_rec_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_op->s_ivd_num_mem_rec_op_t.u4_size != sizeof(impeg2d_num_mem_rec_op_t))
+                {
+                    ps_op->s_ivd_num_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_num_mem_rec_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+            }
+            break;
+        case IV_CMD_FILL_NUM_MEM_REC:
+            {
+                impeg2d_fill_mem_rec_ip_t *ps_ip = (impeg2d_fill_mem_rec_ip_t *)pv_api_ip;
+                impeg2d_fill_mem_rec_op_t *ps_op = (impeg2d_fill_mem_rec_op_t *)pv_api_op;
+                iv_mem_rec_t                  *ps_mem_rec;
+
+                ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code = 0;
+
+                if(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_size != sizeof(impeg2d_fill_mem_rec_ip_t))
+                {
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_op->s_ivd_fill_mem_rec_op_t.u4_size != sizeof(impeg2d_fill_mem_rec_op_t))
+                {
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_max_frm_wd < MIN_WIDTH)
+                {
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code |= IVD_REQUESTED_WIDTH_NOT_SUPPPORTED;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_max_frm_wd > MAX_WIDTH)
+                {
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code |= IVD_REQUESTED_WIDTH_NOT_SUPPPORTED;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_max_frm_ht < MIN_HEIGHT)
+                {
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code |= IVD_REQUESTED_HEIGHT_NOT_SUPPPORTED;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_fill_mem_rec_ip_t.u4_max_frm_ht > MAX_HEIGHT)
+                {
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code |= IVD_REQUESTED_HEIGHT_NOT_SUPPPORTED;
+                    return(IV_FAIL);
+                }
+
+                if(NULL == ps_ip->s_ivd_fill_mem_rec_ip_t.pv_mem_rec_location)
+                {
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code |= IVD_NUM_REC_NOT_SUFFICIENT;
+                    return(IV_FAIL);
+                }
+
+                /* check memrecords sizes are correct */
+                ps_mem_rec  = ps_ip->s_ivd_fill_mem_rec_ip_t.pv_mem_rec_location;
+                for(i=0;i<NUM_MEM_RECORDS;i++)
+                {
+                    if(ps_mem_rec[i].u4_size != sizeof(iv_mem_rec_t))
+                    {
+                        ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                        ps_op->s_ivd_fill_mem_rec_op_t.u4_error_code |= IVD_MEM_REC_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+                }
+            }
+            break;
+
+        case IV_CMD_INIT:
+            {
+                impeg2d_init_ip_t *ps_ip = (impeg2d_init_ip_t *)pv_api_ip;
+                impeg2d_init_op_t *ps_op = (impeg2d_init_op_t *)pv_api_op;
+                iv_mem_rec_t          *ps_mem_rec;
+                UWORD32 u4_tot_num_mem_recs;
+
+                ps_op->s_ivd_init_op_t.u4_error_code = 0;
+
+                if(ps_ip->s_ivd_init_ip_t.u4_size != sizeof(impeg2d_init_ip_t))
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_op->s_ivd_init_op_t.u4_size != sizeof(impeg2d_init_op_t))
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                u4_tot_num_mem_recs = NUM_MEM_RECORDS;
+
+
+
+
+                if(ps_ip->s_ivd_init_ip_t.u4_num_mem_rec > u4_tot_num_mem_recs)
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_NOT_SUFFICIENT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_init_ip_t.u4_frm_max_wd < MIN_WIDTH)
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_WIDTH_NOT_SUPPPORTED;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_init_ip_t.u4_frm_max_wd > MAX_WIDTH)
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_WIDTH_NOT_SUPPPORTED;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_init_ip_t.u4_frm_max_ht < MIN_HEIGHT)
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_HEIGHT_NOT_SUPPPORTED;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_init_ip_t.u4_frm_max_ht > MAX_HEIGHT)
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_HEIGHT_NOT_SUPPPORTED;
+                    return(IV_FAIL);
+                }
+
+                if(NULL == ps_ip->s_ivd_init_ip_t.pv_mem_rec_location)
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_NUM_REC_NOT_SUFFICIENT;
+                    return(IV_FAIL);
+                }
+
+                if((ps_ip->s_ivd_init_ip_t.e_output_format != IV_YUV_420P) &&
+                    (ps_ip->s_ivd_init_ip_t.e_output_format != IV_YUV_422ILE)&&(ps_ip->s_ivd_init_ip_t.e_output_format != IV_YUV_420SP_UV)&&(ps_ip->s_ivd_init_ip_t.e_output_format != IV_YUV_420SP_VU))
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED;
+                    return(IV_FAIL);
+                }
+
+                /* verify number of mem records */
+                if(ps_ip->s_ivd_init_ip_t.u4_num_mem_rec < NUM_MEM_RECORDS)
+                {
+                    ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_NOT_SUFFICIENT;
+                    return IV_FAIL;
+                }
+
+                ps_mem_rec  = ps_ip->s_ivd_init_ip_t.pv_mem_rec_location;
+                /* verify wether first memrecord is handle or not */
+                /*
+                if(ps_mem_rec->pv_base != ps_handle)
+                {
+                     // indicate the incorrect handle error
+                    ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INVALID_HANDLE;
+                    return IV_FAIL;
+                }
+*/
+                /* check memrecords sizes are correct */
+                for(i=0;i < (WORD32)ps_ip->s_ivd_init_ip_t.u4_num_mem_rec ; i++)
+                {
+                    if(ps_mem_rec[i].u4_size != sizeof(iv_mem_rec_t))
+                    {
+                        ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                        ps_op->s_ivd_init_op_t.u4_error_code |= IVD_MEM_REC_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+                }
+
+                /* verify memtabs for overlapping regions */
+                {
+                    UWORD8 *pau1_start[NUM_MEM_RECORDS];
+                    UWORD8 *pau1_end[NUM_MEM_RECORDS];
+
+
+                    pau1_start[0] = (UWORD8 *)(ps_mem_rec[0].pv_base);
+                    pau1_end[0]   = (UWORD8 *)(ps_mem_rec[0].pv_base) + ps_mem_rec[0].u4_mem_size - 1;
+                    for(i = 1; i < (WORD32)ps_ip->s_ivd_init_ip_t.u4_num_mem_rec; i++)
+                    {
+                        /* This array is populated to check memtab overlapp */
+                        pau1_start[i] = (UWORD8 *)(ps_mem_rec[i].pv_base);
+                        pau1_end[i]   = (UWORD8 *)(ps_mem_rec[i].pv_base) + ps_mem_rec[i].u4_mem_size - 1;
+
+                        for(j = 0; j < i; j++)
+                        {
+                            if((pau1_start[i] >= pau1_start[j]) && (pau1_start[i] <= pau1_end[j]))
+                            {
+                                ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_OVERLAP_ERR;
+                                return IV_FAIL;
+                            }
+
+                            if((pau1_end[i] >= pau1_start[j]) && (pau1_end[i] <= pau1_end[j]))
+                            {
+                                ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_OVERLAP_ERR;
+                                return IV_FAIL;
+                            }
+
+                            if((pau1_start[i] < pau1_start[j]) && (pau1_end[i] > pau1_end[j]))
+                            {
+                                ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_OVERLAP_ERR;
+                                return IV_FAIL;
+                            }
+                        }
+                    }
+                }
+
+
+
+
+                {
+                    iv_mem_rec_t    as_mem_rec_ittiam_api[NUM_MEM_RECORDS];
+
+                    impeg2d_fill_mem_rec_ip_t s_fill_mem_rec_ip;
+                    impeg2d_fill_mem_rec_op_t s_fill_mem_rec_op;
+                    IV_API_CALL_STATUS_T e_status;
+                    WORD32 i4_num_memrec;
+                    {
+
+                        iv_num_mem_rec_ip_t s_no_of_mem_rec_query_ip;
+                        iv_num_mem_rec_op_t s_no_of_mem_rec_query_op;
+
+
+                        s_no_of_mem_rec_query_ip.u4_size = sizeof(iv_num_mem_rec_ip_t);
+                        s_no_of_mem_rec_query_op.u4_size = sizeof(iv_num_mem_rec_op_t);
+
+                        s_no_of_mem_rec_query_ip.e_cmd   = IV_CMD_GET_NUM_MEM_REC;
+                        impeg2d_api_function(NULL,
+                                                    (void *)&s_no_of_mem_rec_query_ip,
+                                                    (void *)&s_no_of_mem_rec_query_op);
+
+                        i4_num_memrec  = s_no_of_mem_rec_query_op.u4_num_mem_rec;
+
+
+
+                    }
+
+
+                    /* initialize mem records array with sizes */
+                    for(i = 0; i < i4_num_memrec; i++)
+                    {
+                        as_mem_rec_ittiam_api[i].u4_size = sizeof(iv_mem_rec_t);
+                    }
+
+                    s_fill_mem_rec_ip.s_ivd_fill_mem_rec_ip_t.u4_size                   = sizeof(impeg2d_fill_mem_rec_ip_t);
+                    s_fill_mem_rec_ip.s_ivd_fill_mem_rec_ip_t.e_cmd                     = IV_CMD_FILL_NUM_MEM_REC;
+                    s_fill_mem_rec_ip.s_ivd_fill_mem_rec_ip_t.u4_max_frm_wd             = ps_ip->s_ivd_init_ip_t.u4_frm_max_wd;
+                    s_fill_mem_rec_ip.s_ivd_fill_mem_rec_ip_t.u4_max_frm_ht             = ps_ip->s_ivd_init_ip_t.u4_frm_max_ht;
+                    s_fill_mem_rec_ip.s_ivd_fill_mem_rec_ip_t.pv_mem_rec_location       = as_mem_rec_ittiam_api;
+                    s_fill_mem_rec_ip.u4_share_disp_buf                                 = ps_ip->u4_share_disp_buf;
+                    s_fill_mem_rec_ip.e_output_format                                   = ps_ip->s_ivd_init_ip_t.e_output_format;
+                    s_fill_mem_rec_op.s_ivd_fill_mem_rec_op_t.u4_size                   = sizeof(impeg2d_fill_mem_rec_op_t);
+
+
+                    e_status = impeg2d_api_function(NULL,
+                                                (void *)&s_fill_mem_rec_ip,
+                                                (void *)&s_fill_mem_rec_op);
+                    if(IV_FAIL == e_status)
+                    {
+                        ps_op->s_ivd_init_op_t.u4_error_code = s_fill_mem_rec_op.s_ivd_fill_mem_rec_op_t.u4_error_code;
+                        return(IV_FAIL);
+                    }
+
+
+
+                    for(i = 0; i < i4_num_memrec; i ++)
+                    {
+                        if(ps_mem_rec[i].pv_base == NULL)
+                        {
+                            ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_BASE_NULL;
+                            return IV_FAIL;
+                        }
+#ifdef CHECK_ALIGN
+
+                        if((UWORD32)(ps_mem_rec[i].pv_base) & (ps_mem_rec[i].u4_mem_alignment - 1))
+                        {
+                            ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_ALIGNMENT_ERR;
+                            return IV_FAIL;
+                        }
+#endif //CHECK_ALIGN
+                        if(ps_mem_rec[i].u4_mem_alignment != as_mem_rec_ittiam_api[i].u4_mem_alignment)
+                        {
+                            ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_ALIGNMENT_ERR;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_mem_rec[i].u4_mem_size < as_mem_rec_ittiam_api[i].u4_mem_size)
+                        {
+                            ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_INSUFFICIENT_SIZE;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_mem_rec[i].e_mem_type != as_mem_rec_ittiam_api[i].e_mem_type)
+                        {
+                            if (IV_EXTERNAL_CACHEABLE_SCRATCH_MEM == as_mem_rec_ittiam_api[i].e_mem_type)
+                            {
+                                if (IV_EXTERNAL_CACHEABLE_PERSISTENT_MEM == ps_mem_rec[i].e_mem_type)
+                                {
+                                    continue;
+                                }
+                            }
+                            ps_op->s_ivd_init_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->s_ivd_init_op_t.u4_error_code |= IVD_INIT_DEC_MEM_REC_INCORRECT_TYPE;
+                            return IV_FAIL;
+                        }
+                    }
+                }
+
+
+            }
+            break;
+
+        case IVD_CMD_GET_DISPLAY_FRAME:
+            {
+                impeg2d_get_display_frame_ip_t *ps_ip = (impeg2d_get_display_frame_ip_t *)pv_api_ip;
+                impeg2d_get_display_frame_op_t *ps_op = (impeg2d_get_display_frame_op_t *)pv_api_op;
+
+                ps_op->s_ivd_get_display_frame_op_t.u4_error_code = 0;
+
+                if(ps_ip->s_ivd_get_display_frame_ip_t.u4_size != sizeof(impeg2d_get_display_frame_ip_t))
+                {
+                    ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_op->s_ivd_get_display_frame_op_t.u4_size != sizeof(impeg2d_get_display_frame_op_t))
+                {
+                    ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_get_display_frame_ip_t.s_out_buffer.u4_num_bufs == 0)
+                {
+                    ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
+                    return IV_FAIL;
+                }
+
+                for(i = 0; i< (WORD32)ps_ip->s_ivd_get_display_frame_ip_t.s_out_buffer.u4_num_bufs;i++)
+                {
+                    if(ps_ip->s_ivd_get_display_frame_ip_t.s_out_buffer.pu1_bufs[i] == NULL)
+                    {
+                        ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                        ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_OP_BUF_NULL;
+                        return IV_FAIL;
+                    }
+
+                    if(ps_ip->s_ivd_get_display_frame_ip_t.s_out_buffer.u4_min_out_buf_size[i] == 0)
+                    {
+                        ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                        ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
+                        return IV_FAIL;
+                    }
+                    /*
+                    if(ps_ip->s_ivd_get_display_frame_ip_t.s_out_buffer.u4_min_out_buf_size[i] == 0)
+                    {
+                        ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                        ps_op->s_ivd_get_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
+                        return IV_FAIL;
+                    }
+                    */
+                }
+            }
+            break;
+       case IVD_CMD_REL_DISPLAY_FRAME:
+            {
+                impeg2d_rel_display_frame_ip_t *ps_ip = (impeg2d_rel_display_frame_ip_t *)pv_api_ip;
+                impeg2d_rel_display_frame_op_t *ps_op = (impeg2d_rel_display_frame_op_t *)pv_api_op;
+
+                ps_op->s_ivd_rel_display_frame_op_t.u4_error_code = 0;
+
+                if ((ps_ip->s_ivd_rel_display_frame_ip_t.u4_size != sizeof(impeg2d_rel_display_frame_ip_t))
+                        && (ps_ip->s_ivd_rel_display_frame_ip_t.u4_size != sizeof(ivd_rel_display_frame_ip_t)))
+                {
+                    ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if((ps_op->s_ivd_rel_display_frame_op_t.u4_size != sizeof(impeg2d_rel_display_frame_op_t)) &&
+                        (ps_op->s_ivd_rel_display_frame_op_t.u4_size != sizeof(ivd_rel_display_frame_op_t)))
+                {
+                    ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_rel_display_frame_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+            }
+            break;
+
+
+        case IVD_CMD_SET_DISPLAY_FRAME:
+            {
+                impeg2d_set_display_frame_ip_t *ps_ip = (impeg2d_set_display_frame_ip_t *)pv_api_ip;
+                impeg2d_set_display_frame_op_t *ps_op = (impeg2d_set_display_frame_op_t *)pv_api_op;
+                UWORD32 j, i;
+
+                ps_op->s_ivd_set_display_frame_op_t.u4_error_code = 0;
+
+                if ((ps_ip->s_ivd_set_display_frame_ip_t.u4_size != sizeof(impeg2d_set_display_frame_ip_t))
+                        && (ps_ip->s_ivd_set_display_frame_ip_t.u4_size != sizeof(ivd_set_display_frame_ip_t)))
+                {
+                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if((ps_op->s_ivd_set_display_frame_op_t.u4_size != sizeof(impeg2d_set_display_frame_op_t)) &&
+                        (ps_op->s_ivd_set_display_frame_op_t.u4_size != sizeof(ivd_set_display_frame_op_t)))
+                {
+                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_ip->s_ivd_set_display_frame_ip_t.num_disp_bufs == 0)
+                {
+                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
+                    return IV_FAIL;
+                }
+
+                for(j = 0; j < ps_ip->s_ivd_set_display_frame_ip_t.num_disp_bufs; j++)
+                {
+                    if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_num_bufs == 0)
+                    {
+                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                        ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
+                        return IV_FAIL;
+                    }
+
+                    for(i=0;i< ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_num_bufs;i++)
+                    {
+                        if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].pu1_bufs[i] == NULL)
+                        {
+                            ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_OP_BUF_NULL;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_ip->s_ivd_set_display_frame_ip_t.s_disp_buffer[j].u4_min_out_buf_size[i] == 0)
+                        {
+                            ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->s_ivd_set_display_frame_op_t.u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
+                            return IV_FAIL;
+                        }
+                    }
+                }
+            }
+            break;
+
+        case IVD_CMD_VIDEO_DECODE:
+            {
+                impeg2d_video_decode_ip_t *ps_ip = (impeg2d_video_decode_ip_t *)pv_api_ip;
+                impeg2d_video_decode_op_t *ps_op = (impeg2d_video_decode_op_t *)pv_api_op;
+
+                ps_op->s_ivd_video_decode_op_t.u4_error_code = 0;
+
+                if(ps_ip->s_ivd_video_decode_ip_t.u4_size != sizeof(impeg2d_video_decode_ip_t))
+                {
+                    ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_video_decode_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_op->s_ivd_video_decode_op_t.u4_size != sizeof(impeg2d_video_decode_op_t))
+                {
+                    ps_op->s_ivd_video_decode_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_video_decode_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+            }
+            break;
+
+        case IV_CMD_RETRIEVE_MEMREC:
+            {
+                impeg2d_retrieve_mem_rec_ip_t *ps_ip = (impeg2d_retrieve_mem_rec_ip_t *)pv_api_ip;
+                impeg2d_retrieve_mem_rec_op_t *ps_op = (impeg2d_retrieve_mem_rec_op_t *)pv_api_op;
+                iv_mem_rec_t          *ps_mem_rec;
+
+                ps_op->s_ivd_retrieve_mem_rec_op_t.u4_error_code = 0;
+
+                if(ps_ip->s_ivd_retrieve_mem_rec_ip_t.u4_size != sizeof(impeg2d_retrieve_mem_rec_ip_t))
+                {
+                    ps_op->s_ivd_retrieve_mem_rec_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_retrieve_mem_rec_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                if(ps_op->s_ivd_retrieve_mem_rec_op_t.u4_size != sizeof(impeg2d_retrieve_mem_rec_op_t))
+                {
+                    ps_op->s_ivd_retrieve_mem_rec_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                    ps_op->s_ivd_retrieve_mem_rec_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                    return(IV_FAIL);
+                }
+
+                ps_mem_rec  = ps_ip->s_ivd_retrieve_mem_rec_ip_t.pv_mem_rec_location;
+                /* check memrecords sizes are correct */
+                for(i=0;i < NUM_MEM_RECORDS ; i++)
+                {
+                    if(ps_mem_rec[i].u4_size != sizeof(iv_mem_rec_t))
+                    {
+                        ps_op->s_ivd_retrieve_mem_rec_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                        ps_op->s_ivd_retrieve_mem_rec_op_t.u4_error_code |= IVD_MEM_REC_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+                }
+            }
+            break;
+
+        case IVD_CMD_VIDEO_CTL:
+            {
+                UWORD32 *pu4_ptr_cmd;
+                UWORD32 u4_sub_command;
+
+                pu4_ptr_cmd = (UWORD32 *)pv_api_ip;
+                pu4_ptr_cmd += 2;
+                u4_sub_command = *pu4_ptr_cmd;
+
+                switch(u4_sub_command)
+                {
+                    case IVD_CMD_CTL_SETPARAMS:
+                        {
+                            impeg2d_ctl_set_config_ip_t *ps_ip;
+                            impeg2d_ctl_set_config_op_t *ps_op;
+                            ps_ip = (impeg2d_ctl_set_config_ip_t *)pv_api_ip;
+                            ps_op = (impeg2d_ctl_set_config_op_t *)pv_api_op;
+
+                            ps_op->s_ivd_ctl_set_config_op_t.u4_error_code = 0;
+
+                            if(ps_ip->s_ivd_ctl_set_config_ip_t.u4_size != sizeof(impeg2d_ctl_set_config_ip_t))
+                            {
+                                ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                        }
+                    case IVD_CMD_CTL_SETDEFAULT:
+                        {
+                            impeg2d_ctl_set_config_op_t *ps_op;
+                            ps_op = (impeg2d_ctl_set_config_op_t *)pv_api_op;
+                            ps_op->s_ivd_ctl_set_config_op_t.u4_error_code   = 0;
+
+                            if(ps_op->s_ivd_ctl_set_config_op_t.u4_size != sizeof(impeg2d_ctl_set_config_op_t))
+                            {
+                                ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_set_config_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                        }
+                        break;
+
+                    case IVD_CMD_CTL_GETPARAMS:
+                        {
+                            impeg2d_ctl_getstatus_ip_t *ps_ip;
+                            impeg2d_ctl_getstatus_op_t *ps_op;
+
+                            ps_ip = (impeg2d_ctl_getstatus_ip_t *)pv_api_ip;
+                            ps_op = (impeg2d_ctl_getstatus_op_t *)pv_api_op;
+
+                            ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code   = 0;
+
+                            if(ps_ip->s_ivd_ctl_getstatus_ip_t.u4_size != sizeof(impeg2d_ctl_getstatus_ip_t))
+                            {
+                                ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                            if(ps_op->s_ivd_ctl_getstatus_op_t.u4_size != sizeof(impeg2d_ctl_getstatus_op_t))
+                            {
+                                ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_getstatus_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                        }
+                        break;
+
+                    case IVD_CMD_CTL_GETBUFINFO:
+                        {
+                            impeg2d_ctl_getbufinfo_ip_t *ps_ip;
+                            impeg2d_ctl_getbufinfo_op_t *ps_op;
+                            ps_ip = (impeg2d_ctl_getbufinfo_ip_t *)pv_api_ip;
+                            ps_op = (impeg2d_ctl_getbufinfo_op_t *)pv_api_op;
+
+                            ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code  = 0;
+
+                            if(ps_ip->s_ivd_ctl_getbufinfo_ip_t.u4_size != sizeof(impeg2d_ctl_getbufinfo_ip_t))
+                            {
+                                ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                            if(ps_op->s_ivd_ctl_getbufinfo_op_t.u4_size != sizeof(impeg2d_ctl_getbufinfo_op_t))
+                            {
+                                ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_getbufinfo_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                        }
+                        break;
+
+                    case IVD_CMD_CTL_GETVERSION:
+                        {
+                            impeg2d_ctl_getversioninfo_ip_t *ps_ip;
+                            impeg2d_ctl_getversioninfo_op_t *ps_op;
+                            ps_ip = (impeg2d_ctl_getversioninfo_ip_t *)pv_api_ip;
+                            ps_op = (impeg2d_ctl_getversioninfo_op_t *)pv_api_op;
+
+                            ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code  = 0;
+
+                            if(ps_ip->s_ivd_ctl_getversioninfo_ip_t.u4_size != sizeof(impeg2d_ctl_getversioninfo_ip_t))
+                            {
+                                ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                            if(ps_op->s_ivd_ctl_getversioninfo_op_t.u4_size != sizeof(impeg2d_ctl_getversioninfo_op_t))
+                            {
+                                ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_getversioninfo_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                        }
+                        break;
+
+                    case IVD_CMD_CTL_FLUSH:
+                        {
+                            impeg2d_ctl_flush_ip_t *ps_ip;
+                            impeg2d_ctl_flush_op_t *ps_op;
+                            ps_ip = (impeg2d_ctl_flush_ip_t *)pv_api_ip;
+                            ps_op = (impeg2d_ctl_flush_op_t *)pv_api_op;
+
+                            ps_op->s_ivd_ctl_flush_op_t.u4_error_code = 0;
+
+                            if(ps_ip->s_ivd_ctl_flush_ip_t.u4_size != sizeof(impeg2d_ctl_flush_ip_t))
+                            {
+                                ps_op->s_ivd_ctl_flush_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_flush_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                            if(ps_op->s_ivd_ctl_flush_op_t.u4_size != sizeof(impeg2d_ctl_flush_op_t))
+                            {
+                                ps_op->s_ivd_ctl_flush_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_flush_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                        }
+                        break;
+
+                    case IVD_CMD_CTL_RESET:
+                        {
+                            impeg2d_ctl_reset_ip_t *ps_ip;
+                            impeg2d_ctl_reset_op_t *ps_op;
+                            ps_ip = (impeg2d_ctl_reset_ip_t *)pv_api_ip;
+                            ps_op = (impeg2d_ctl_reset_op_t *)pv_api_op;
+
+                            ps_op->s_ivd_ctl_reset_op_t.u4_error_code    = 0;
+
+                            if(ps_ip->s_ivd_ctl_reset_ip_t.u4_size != sizeof(impeg2d_ctl_reset_ip_t))
+                            {
+                                ps_op->s_ivd_ctl_reset_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_reset_op_t.u4_error_code |= IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                            if(ps_op->s_ivd_ctl_reset_op_t.u4_size != sizeof(impeg2d_ctl_reset_op_t))
+                            {
+                                ps_op->s_ivd_ctl_reset_op_t.u4_error_code  |= 1 << IVD_UNSUPPORTEDPARAM;
+                                ps_op->s_ivd_ctl_reset_op_t.u4_error_code |= IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                                return IV_FAIL;
+                            }
+                        }
+                        break;
+
+                    case IMPEG2D_CMD_CTL_GET_BUFFER_DIMENSIONS:
+                    {
+                        impeg2d_ctl_get_frame_dimensions_ip_t *ps_ip;
+                        impeg2d_ctl_get_frame_dimensions_op_t *ps_op;
+
+                        ps_ip =
+                                        (impeg2d_ctl_get_frame_dimensions_ip_t *)pv_api_ip;
+                        ps_op =
+                                        (impeg2d_ctl_get_frame_dimensions_op_t *)pv_api_op;
+
+                        if(ps_ip->u4_size
+                                        != sizeof(impeg2d_ctl_get_frame_dimensions_ip_t))
+                        {
+                            ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                            IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_op->u4_size
+                                        != sizeof(impeg2d_ctl_get_frame_dimensions_op_t))
+                        {
+                            ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                            IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                            return IV_FAIL;
+                        }
+
+                        break;
+                    }
+
+                    case IMPEG2D_CMD_CTL_SET_NUM_CORES:
+                    {
+                        impeg2d_ctl_set_num_cores_ip_t *ps_ip;
+                        impeg2d_ctl_set_num_cores_op_t *ps_op;
+
+                        ps_ip = (impeg2d_ctl_set_num_cores_ip_t *)pv_api_ip;
+                        ps_op = (impeg2d_ctl_set_num_cores_op_t *)pv_api_op;
+
+                        if(ps_ip->u4_size
+                                        != sizeof(impeg2d_ctl_set_num_cores_ip_t))
+                        {
+                            ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                            IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_op->u4_size
+                                        != sizeof(impeg2d_ctl_set_num_cores_op_t))
+                        {
+                            ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                            IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                            return IV_FAIL;
+                        }
+
+#ifdef MULTICORE
+                        if((ps_ip->u4_num_cores < 1) || (ps_ip->u4_num_cores > MAX_THREADS))
+#else
+                        if(ps_ip->u4_num_cores != 1)
+#endif
+                        {
+                            ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            return IV_FAIL;
+                        }
+                        break;
+                    }
+                    case IMPEG2D_CMD_CTL_SET_PROCESSOR:
+                    {
+                        impeg2d_ctl_set_processor_ip_t *ps_ip;
+                        impeg2d_ctl_set_processor_op_t *ps_op;
+
+                        ps_ip = (impeg2d_ctl_set_processor_ip_t *)pv_api_ip;
+                        ps_op = (impeg2d_ctl_set_processor_op_t *)pv_api_op;
+
+                        if(ps_ip->u4_size
+                                        != sizeof(impeg2d_ctl_set_processor_ip_t))
+                        {
+                            ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                            IVD_IP_API_STRUCT_SIZE_INCORRECT;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_op->u4_size
+                                        != sizeof(impeg2d_ctl_set_processor_op_t))
+                        {
+                            ps_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                            IVD_OP_API_STRUCT_SIZE_INCORRECT;
+                            return IV_FAIL;
+                        }
+
+                        break;
+                    }
+                    default:
+                        break;
+
+                }
+            }
+            break;
+
+        default:
+            {            *(pu4_api_op + 1) |= 1 << IVD_UNSUPPORTEDPARAM;
+                         *(pu4_api_op + 1) |= IVD_UNSUPPORTED_API_CMD;
+                         return IV_FAIL;
+            }
+
+
+    }
+
+    return IV_SUCCESS;
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name :   impeg2d_api_entity                                     */
+/*                                                                           */
+/*  Description   :                                                          */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Outputs       :                                                          */
+/*  Returns       : void                                                     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         22 10 2008    100356         Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+
+
+IV_API_CALL_STATUS_T impeg2d_api_entity(iv_obj_t *ps_dechdl,
+                                        void *pv_api_ip,
+                                        void *pv_api_op)
+{
+    iv_obj_t *ps_dec_handle;
+    dec_state_t *ps_dec_state;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+
+    impeg2d_video_decode_ip_t    *ps_dec_ip;
+
+    impeg2d_video_decode_op_t    *ps_dec_op;
+    WORD32 bytes_remaining;
+    pic_buf_t *ps_disp_pic;
+
+
+
+    ps_dec_ip = (impeg2d_video_decode_ip_t    *)pv_api_ip;
+    ps_dec_op = (impeg2d_video_decode_op_t    *)pv_api_op;
+
+    memset(ps_dec_op,0,sizeof(impeg2d_video_decode_op_t));
+
+    ps_dec_op->s_ivd_video_decode_op_t.u4_size = sizeof(impeg2d_video_decode_op_t);
+    ps_dec_op->s_ivd_video_decode_op_t.u4_output_present = 0;
+    bytes_remaining = ps_dec_ip->s_ivd_video_decode_ip_t.u4_num_Bytes;
+
+    ps_dec_handle = (iv_obj_t *)ps_dechdl;
+
+    if(ps_dechdl == NULL)
+    {
+        return(IV_FAIL);
+    }
+
+
+
+    ps_dec_state_multi_core  = ps_dec_handle->pv_codec_handle;
+    ps_dec_state = ps_dec_state_multi_core->ps_dec_state[0];
+
+    ps_dec_state->ps_disp_frm_buf = &(ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf);
+    if(0 == ps_dec_state->u4_share_disp_buf)
+    {
+        ps_dec_state->ps_disp_frm_buf->pv_y_buf  = ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[0];
+        ps_dec_state->ps_disp_frm_buf->pv_u_buf  = ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[1];
+        ps_dec_state->ps_disp_frm_buf->pv_v_buf  = ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[2];
+    }
+
+    ps_dec_state->ps_disp_pic = NULL;
+    ps_dec_state->i4_frame_decoded = 0;
+    /*rest bytes consumed */
+    ps_dec_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = 0;
+
+    ps_dec_op->s_ivd_video_decode_op_t.u4_error_code           = IV_SUCCESS;
+
+    if((ps_dec_ip->s_ivd_video_decode_ip_t.pv_stream_buffer == NULL)&&(ps_dec_state->u1_flushfrm==0))
+    {
+        ps_dec_op->s_ivd_video_decode_op_t.u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
+        ps_dec_op->s_ivd_video_decode_op_t.u4_error_code |= IVD_DEC_FRM_BS_BUF_NULL;
+        return IV_FAIL;
+    }
+
+
+    if (ps_dec_state->u4_num_frames_decoded > NUM_FRAMES_LIMIT)
+    {
+        ps_dec_op->s_ivd_video_decode_op_t.u4_error_code       = IMPEG2D_SAMPLE_VERSION_LIMIT_ERR;
+        return(IV_FAIL);
+    }
+
+    if(((0 == ps_dec_state->u2_header_done) || (ps_dec_state->u2_decode_header == 1)) && (ps_dec_state->u1_flushfrm == 0))
+    {
+        impeg2d_dec_hdr(ps_dec_state,ps_dec_ip ,ps_dec_op);
+        bytes_remaining -= ps_dec_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed;
+    }
+
+    if((1 != ps_dec_state->u2_decode_header) && ((bytes_remaining > 0) || ps_dec_state->u1_flushfrm))
+    {
+        if(ps_dec_state->u1_flushfrm)
+        {
+            if(ps_dec_state->aps_ref_pics[1] != NULL)
+            {
+                impeg2_disp_mgr_add(&ps_dec_state->s_disp_mgr, ps_dec_state->aps_ref_pics[1], ps_dec_state->aps_ref_pics[1]->i4_buf_id);
+                impeg2_buf_mgr_release(ps_dec_state->pv_pic_buf_mg, ps_dec_state->aps_ref_pics[1]->i4_buf_id, BUF_MGR_REF);
+                impeg2_buf_mgr_release(ps_dec_state->pv_pic_buf_mg, ps_dec_state->aps_ref_pics[0]->i4_buf_id, BUF_MGR_REF);
+
+                ps_dec_state->aps_ref_pics[1] = NULL;
+                ps_dec_state->aps_ref_pics[0] = NULL;
+
+            }
+            else if(ps_dec_state->aps_ref_pics[0] != NULL)
+            {
+                impeg2_disp_mgr_add(&ps_dec_state->s_disp_mgr, ps_dec_state->aps_ref_pics[0], ps_dec_state->aps_ref_pics[0]->i4_buf_id);
+                impeg2_buf_mgr_release(ps_dec_state->pv_pic_buf_mg, ps_dec_state->aps_ref_pics[0]->i4_buf_id, BUF_MGR_REF);
+
+                ps_dec_state->aps_ref_pics[0] = NULL;
+            }
+            ps_dec_ip->s_ivd_video_decode_ip_t.u4_size                 = sizeof(impeg2d_video_decode_ip_t);
+            ps_dec_op->s_ivd_video_decode_op_t.u4_size                 = sizeof(impeg2d_video_decode_op_t);
+
+            ps_disp_pic = impeg2_disp_mgr_get(&ps_dec_state->s_disp_mgr, &ps_dec_state->i4_disp_buf_id);
+
+            ps_dec_state->ps_disp_pic = ps_disp_pic;
+            if(ps_disp_pic == NULL)
+            {
+                ps_dec_op->s_ivd_video_decode_op_t.u4_output_present = 0;
+            }
+            else
+            {
+                WORD32 fmt_conv;
+                if(0 == ps_dec_state->u4_share_disp_buf)
+                {
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.pv_y_buf  = ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[0];
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.pv_u_buf  = ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[1];
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.pv_v_buf  = ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[2];
+                    fmt_conv = 1;
+                }
+                else
+                {
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.pv_y_buf  = ps_disp_pic->pu1_y;
+                    if(IV_YUV_420P == ps_dec_state->i4_chromaFormat)
+                    {
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.pv_u_buf  = ps_disp_pic->pu1_u;
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.pv_v_buf  = ps_disp_pic->pu1_v;
+                        fmt_conv = 0;
+                    }
+                    else
+                    {
+                        UWORD8 *pu1_buf;
+
+                        pu1_buf = ps_dec_state->as_disp_buffers[ps_disp_pic->i4_buf_id].pu1_bufs[1];
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.pv_u_buf  = pu1_buf;
+
+                        pu1_buf = ps_dec_state->as_disp_buffers[ps_disp_pic->i4_buf_id].pu1_bufs[2];
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.pv_v_buf  = pu1_buf;
+                        fmt_conv = 1;
+                    }
+                }
+
+                if(fmt_conv == 1)
+                {
+                    impeg2d_format_convert(ps_dec_state, ps_disp_pic,
+                                         &(ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf),
+                                         0, ps_dec_state->u2_vertical_size);
+                }
+                if(0 == ps_dec_state->u4_share_disp_buf)
+                    impeg2_buf_mgr_release(ps_dec_state->pv_pic_buf_mg, ps_disp_pic->i4_buf_id, BUF_MGR_DISP);
+
+                ps_dec_op->s_ivd_video_decode_op_t.u4_pic_ht = ps_dec_state->u2_vertical_size;
+                ps_dec_op->s_ivd_video_decode_op_t.u4_pic_wd = ps_dec_state->u2_horizontal_size;
+                ps_dec_op->s_ivd_video_decode_op_t.u4_output_present = 1;
+
+                ps_dec_op->s_ivd_video_decode_op_t.u4_disp_buf_id = ps_disp_pic->i4_buf_id;
+                ps_dec_op->s_ivd_video_decode_op_t.u4_ts = ps_disp_pic->u4_ts;
+
+                ps_dec_op->s_ivd_video_decode_op_t.e_output_format = (IV_COLOR_FORMAT_T)ps_dec_state->i4_chromaFormat;
+
+                ps_dec_op->s_ivd_video_decode_op_t.u4_is_ref_flag = (B_PIC != ps_dec_state->e_pic_type);
+
+                ps_dec_op->s_ivd_video_decode_op_t.u4_progressive_frame_flag           = IV_PROGRESSIVE;
+
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_y_wd = ps_dec_state->u2_horizontal_size;
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_y_strd = ps_dec_state->u4_frm_buf_stride;
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_y_ht = ps_dec_state->u2_vertical_size;
+
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_wd = ps_dec_state->u2_horizontal_size >> 1;
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_strd = ps_dec_state->u4_frm_buf_stride >> 1;
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_ht = ps_dec_state->u2_vertical_size >> 1;
+
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_wd = ps_dec_state->u2_horizontal_size >> 1;
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_strd = ps_dec_state->u4_frm_buf_stride >> 1;
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_ht = ps_dec_state->u2_vertical_size >> 1;
+                ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_size = sizeof(ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf);
+
+                switch(ps_dec_state->i4_chromaFormat)
+                {
+                    case IV_YUV_420SP_UV:
+                    case IV_YUV_420SP_VU:
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_wd = ps_dec_state->u2_horizontal_size;
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_strd = ps_dec_state->u4_frm_buf_stride;
+                    break;
+                    case IV_YUV_422ILE:
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_wd = 0;
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_ht = 0;
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_wd = 0;
+                        ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_ht = 0;
+                    break;
+                    default:
+                    break;
+                }
+
+
+            }
+            if(ps_dec_op->s_ivd_video_decode_op_t.u4_output_present)
+            {
+                if(1 == ps_dec_op->s_ivd_video_decode_op_t.u4_output_present)
+                {
+                    INSERT_LOGO(ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[0],
+                                ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[1],
+                                ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[2],
+                                ps_dec_state->u4_frm_buf_stride,
+                                ps_dec_state->u2_horizontal_size,
+                                ps_dec_state->u2_vertical_size,
+                                ps_dec_state->i4_chromaFormat,
+                                ps_dec_state->u2_horizontal_size,
+                                ps_dec_state->u2_vertical_size);
+                }
+                return(IV_SUCCESS);
+            }
+            else
+            {
+                ps_dec_state->u1_flushfrm = 0;
+
+                return(IV_FAIL);
+            }
+
+        }
+        else if(ps_dec_state->u1_flushfrm==0)
+        {
+            ps_dec_ip->s_ivd_video_decode_ip_t.u4_size                 = sizeof(impeg2d_video_decode_ip_t);
+            ps_dec_op->s_ivd_video_decode_op_t.u4_size                 = sizeof(impeg2d_video_decode_op_t);
+            if(ps_dec_ip->s_ivd_video_decode_ip_t.u4_num_Bytes < 4)
+            {
+                ps_dec_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = ps_dec_ip->s_ivd_video_decode_ip_t.u4_num_Bytes;
+                return(IV_FAIL);
+            }
+
+            if(1 == ps_dec_state->u4_share_disp_buf)
+            {
+                if(0 == impeg2_buf_mgr_check_free(ps_dec_state->pv_pic_buf_mg))
+                {
+                    ps_dec_op->s_ivd_video_decode_op_t.u4_error_code =
+                                    (IMPEG2D_ERROR_CODES_T)IVD_DEC_REF_BUF_NULL;
+                    return IV_FAIL;
+                }
+            }
+
+
+            ps_dec_op->s_ivd_video_decode_op_t.e_output_format = (IV_COLOR_FORMAT_T)ps_dec_state->i4_chromaFormat;
+
+            ps_dec_op->s_ivd_video_decode_op_t.u4_is_ref_flag = (B_PIC != ps_dec_state->e_pic_type);
+
+            ps_dec_op->s_ivd_video_decode_op_t.u4_progressive_frame_flag           = IV_PROGRESSIVE;
+
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_y_wd = ps_dec_state->u2_horizontal_size;
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_y_strd = ps_dec_state->u4_frm_buf_stride;
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_y_ht = ps_dec_state->u2_vertical_size;
+
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_wd = ps_dec_state->u2_horizontal_size >> 1;
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_strd = ps_dec_state->u4_frm_buf_stride >> 1;
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_ht = ps_dec_state->u2_vertical_size >> 1;
+
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_wd = ps_dec_state->u2_horizontal_size >> 1;
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_strd = ps_dec_state->u4_frm_buf_stride >> 1;
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_ht = ps_dec_state->u2_vertical_size >> 1;
+            ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_size = sizeof(ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf);
+
+            switch(ps_dec_state->i4_chromaFormat)
+            {
+                case IV_YUV_420SP_UV:
+                case IV_YUV_420SP_VU:
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_wd = ps_dec_state->u2_horizontal_size;
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_strd = ps_dec_state->u4_frm_buf_stride;
+                break;
+                case IV_YUV_422ILE:
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_wd = 0;
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_u_ht = 0;
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_wd = 0;
+                    ps_dec_op->s_ivd_video_decode_op_t.s_disp_frm_buf.u4_v_ht = 0;
+                break;
+                default:
+                break;
+            }
+
+            if( ps_dec_state->u1_flushfrm == 0)
+            {
+                ps_dec_state->u1_flushcnt    = 0;
+
+                /*************************************************************************/
+                /*                              Frame Decode                             */
+                /*************************************************************************/
+
+                impeg2d_dec_frm(ps_dec_state,ps_dec_ip,ps_dec_op);
+
+                if (IVD_ERROR_NONE ==
+                        ps_dec_op->s_ivd_video_decode_op_t.u4_error_code)
+                {
+                    if(ps_dec_state->ps_disp_pic)
+                    ps_dec_op->s_ivd_video_decode_op_t.u4_output_present = 1;
+                    else
+                    ps_dec_op->s_ivd_video_decode_op_t.u4_output_present = 0;
+                    if(ps_dec_state->u1_first_frame_done == 0)
+                    {
+                        ps_dec_state->u1_first_frame_done = 1;
+                    }
+
+                    switch(ps_dec_state->e_pic_type)
+                    {
+                        case I_PIC :
+                        ps_dec_op->s_ivd_video_decode_op_t.e_pic_type = IV_I_FRAME;
+                        break;
+
+                        case P_PIC:
+                        ps_dec_op->s_ivd_video_decode_op_t.e_pic_type = IV_P_FRAME;
+                        break;
+
+                        case B_PIC:
+                        ps_dec_op->s_ivd_video_decode_op_t.e_pic_type = IV_B_FRAME;
+                        break;
+
+                        case D_PIC:
+                        ps_dec_op->s_ivd_video_decode_op_t.e_pic_type = IV_I_FRAME;
+                        break;
+
+                        default :
+                        ps_dec_op->s_ivd_video_decode_op_t.e_pic_type = IV_FRAMETYPE_DEFAULT;
+                        break;
+                    }
+
+                    ps_dec_state->u4_num_frames_decoded++;
+                }
+            }
+            else
+            {
+                ps_dec_state->u1_flushcnt++;
+            }
+        }
+        if(ps_dec_state->ps_disp_pic)
+        {
+            ps_dec_op->s_ivd_video_decode_op_t.u4_disp_buf_id = ps_dec_state->ps_disp_pic->i4_buf_id;
+            ps_dec_op->s_ivd_video_decode_op_t.u4_ts = ps_dec_state->ps_disp_pic->u4_ts;
+
+            if(0 == ps_dec_state->u4_share_disp_buf)
+            {
+                impeg2_buf_mgr_release(ps_dec_state->pv_pic_buf_mg, ps_dec_state->ps_disp_pic->i4_buf_id, BUF_MGR_DISP);
+            }
+        }
+
+        if(1 == ps_dec_op->s_ivd_video_decode_op_t.u4_output_present)
+        {
+            INSERT_LOGO(ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[0],
+                        ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[1],
+                        ps_dec_ip->s_ivd_video_decode_ip_t.s_out_buffer.pu1_bufs[2],
+                        ps_dec_state->u4_frm_buf_stride,
+                        ps_dec_state->u2_horizontal_size,
+                        ps_dec_state->u2_vertical_size,
+                        ps_dec_state->i4_chromaFormat,
+                        ps_dec_state->u2_horizontal_size,
+                        ps_dec_state->u2_vertical_size);
+        }
+
+    }
+
+    ps_dec_op->s_ivd_video_decode_op_t.u4_progressive_frame_flag = 1;
+    ps_dec_op->s_ivd_video_decode_op_t.e4_fld_type     = ps_dec_state->s_disp_op.e4_fld_type;
+
+
+    if(ps_dec_op->s_ivd_video_decode_op_t.u4_error_code)
+        return IV_FAIL;
+    else
+        return IV_SUCCESS;
+}
diff --git a/decoder/impeg2d_bitstream.c b/decoder/impeg2d_bitstream.c
new file mode 100644
index 0000000..92d3785
--- /dev/null
+++ b/decoder/impeg2d_bitstream.c
@@ -0,0 +1,335 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/*****************************************************************************/
+/*                                                                           */
+/*  File Name         : impeg2d_bitstream.c                                  */
+/*                                                                           */
+/*  Description       : This file contains all the necessary examples to     */
+/*                      establish a consistent use of Ittiam C coding        */
+/*                      standards (based on Indian Hill C Standards)         */
+/*                                                                           */
+/*  List of Functions : <List the functions defined in this file>            */
+/*                                                                           */
+/*  Issues / Problems : None                                                 */
+/*                                                                           */
+/*  Revision History  :                                                      */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         10 01 2005   Ittiam          Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+#include <stdlib.h>
+
+#include "iv_datatypedef.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_macros.h"
+#include "impeg2d_bitstream.h"
+
+#define BIT(val,bit)      (UWORD16)(((val) >> (bit)) & 0x1)
+/******************************************************************************
+*
+*  Function Name    : impeg2d_bit_stream_init
+*
+*  Description      : This is a Bitstream initialising function.
+*  Arguments        :
+*  stream           : Pointer to the Bitstream.
+*  byteBuf          : Address of the buffer
+*  size             : Size of the buffer in bytes
+*
+*  Values Returned  : None
+*******************************************************************************/
+void impeg2d_bit_stream_init(stream_t *ps_stream,
+                             UWORD8 *pu1_byte_buf,
+                             UWORD32 u4_max_offset)
+{
+    UWORD8      *pu1_byte_buff;
+    UWORD32     *pu4_word_buf;
+    size_t     u4_byte_addr;
+    UWORD32     u4_temp1,u4_temp2;
+
+    /* Set parameters of the stream structure.Associate the structure with
+       the file */
+    ps_stream->pv_bs_buf           = pu1_byte_buf;
+    ps_stream->u4_offset              = 0;
+
+    /* Take care of unaligned address and create
+       nearest greater aligned address */
+    pu1_byte_buff               = (UWORD8 *)pu1_byte_buf;
+    u4_byte_addr                = (size_t)pu1_byte_buff;
+
+    if((u4_byte_addr & 3) == 1)
+    {
+        u4_temp1                = ((UWORD32)(*pu1_byte_buff++)) << 8;
+        u4_temp1                += ((UWORD32)(*pu1_byte_buff++)) << 16;
+        u4_temp1                += ((UWORD32)(*pu1_byte_buff++)) << 24;
+
+        pu4_word_buf            = (UWORD32 *)pu1_byte_buff;
+
+        ps_stream->u4_offset          = 8;
+    }
+    else if((u4_byte_addr & 3) == 2)
+    {
+        u4_temp1                = ((UWORD32)(*pu1_byte_buff++)) << 16;
+        u4_temp1                += ((UWORD32)(*pu1_byte_buff++)) << 24;
+
+        pu4_word_buf            = (UWORD32 *)pu1_byte_buff;
+
+        ps_stream->u4_offset          = 16;
+    }
+    else if((u4_byte_addr & 3) == 3)
+    {
+        u4_temp1                = (((UWORD32)(*pu1_byte_buff++)) << 24);
+
+        pu4_word_buf            = (UWORD32 *)pu1_byte_buff;
+
+        ps_stream->u4_offset          = 24;
+    }
+    else
+    {
+        pu4_word_buf            = (UWORD32 *)pu1_byte_buff;
+
+        u4_temp1                = *pu4_word_buf++;
+        ps_stream->u4_offset          = 0;
+    }
+
+    /* convert the endian ness from Little endian to Big endian so that bits
+       are in proper order from MSB to LSB */
+    CONV_LE_TO_BE(u4_temp2,u4_temp1)
+
+    /* Read One more word for buf nxt */
+    u4_temp1                    = *pu4_word_buf++;
+    ps_stream->u4_buf              = u4_temp2;
+
+    CONV_LE_TO_BE(u4_temp2,u4_temp1)
+
+    ps_stream->u4_buf_nxt          = u4_temp2;
+
+    ps_stream->pu4_buf_aligned      = pu4_word_buf;
+
+
+    ps_stream->u4_max_offset        = (u4_max_offset << 3) + ps_stream->u4_offset;
+
+    return;
+}
+
+
+
+/******************************************************************************
+*
+*  Function Name    : impeg2d_bit_stream_get_bit
+*
+*  Description      : This is a Bitstream processing function. It reads the
+*                     bit currently pointed by the bit pointer in the buffer and
+*                     advances the pointer by one.
+*  Arguments        :
+*  stream           : Pointer to the Bitstream.
+*
+*  Values Returned  : The bit read(0/1)
+*******************************************************************************/
+INLINE UWORD8 impeg2d_bit_stream_get_bit(stream_t *ps_stream)
+{
+    UWORD32     u4_bit,u4_offset,u4_temp;
+    UWORD32     u4_curr_bit;
+
+    u4_offset               = ps_stream->u4_offset;
+    u4_curr_bit             = u4_offset & 0x1F;
+    u4_bit                  = ps_stream->u4_buf;
+
+    /* Move the current bit read from the current word to the
+       least significant bit positions of 'c'.*/
+    u4_bit                  >>= BITS_IN_INT - u4_curr_bit - 1;
+
+    u4_offset++;
+
+    /* If the last bit of the last word of the buffer has been read update
+       the currrent buf with next, and read next buf from bit stream buffer */
+    if (u4_curr_bit == 31)
+    {
+        ps_stream->u4_buf      = ps_stream->u4_buf_nxt;
+        u4_temp             = *(ps_stream->pu4_buf_aligned)++;
+
+        CONV_LE_TO_BE(ps_stream->u4_buf_nxt,u4_temp)
+    }
+    ps_stream->u4_offset          = u4_offset;
+
+    return (u4_bit & 0x1);
+}
+/******************************************************************************
+*
+*  Function Name    : impeg2d_bit_stream_flush
+*
+*  Description      : This is a Bitstream processing function. It
+*                     advances the bit and byte pointers appropriately
+*
+*  Arguments        :
+*  ctxt             : Pointer to the Bitstream.
+*  numBits          : No of bits to be read
+*
+*  Values Returned  : None
+*******************************************************************************/
+INLINE void impeg2d_bit_stream_flush(void* pv_ctxt, UWORD32 u4_no_of_bits)
+{
+    stream_t *ps_stream = (stream_t *)pv_ctxt;
+
+    FLUSH_BITS(ps_stream->u4_offset,ps_stream->u4_buf,ps_stream->u4_buf_nxt,u4_no_of_bits,ps_stream->pu4_buf_aligned)
+    return;
+}
+/******************************************************************************
+*
+*  Function Name    : impeg2d_bit_stream_flush_to_byte_boundary
+*
+*  Description      : This is a Bitstream processing function.It advances
+*                     the bit and byte pointers to next byte boundary
+*
+*  Arguments        :
+*  stream           : Pointer to the Bitstream.
+*  NoOfBits         : No of bits to be read
+*
+*  Values Returned  : The bits read (upto 32 bits maximum) starting from the
+*                     least significant bit and going towards most significant
+*                     bit in the order of their occurence.
+*******************************************************************************/
+INLINE void impeg2d_bit_stream_flush_to_byte_boundary(void* pv_ctxt)
+{
+    UWORD8 u1_bit_offset;
+    stream_t *ps_stream = (stream_t *)pv_ctxt;
+
+    u1_bit_offset = (ps_stream->u4_offset) & 0x7;
+
+
+    /* if it is not byte aligned make it byte aligned*/
+    if(u1_bit_offset != 0)
+    {
+        impeg2d_bit_stream_flush(ps_stream,(8 - u1_bit_offset));
+    }
+
+
+
+}
+
+
+/******************************************************************************
+*
+*  Function Name    : ibits_next
+*
+*  Description      : This is a Bitstream processing function.It gets the
+*                     specified number of bits from the buffer without
+*                     altering the current pointers. It is used mainly to
+*                     check for some specific pattern of bits like start
+*                     code. This is equivalent to next_bits() function
+*                     defined in MPEG-4 Visual Standard Definition of functions
+*
+*  Arguments        :
+*  ctxt             : Pointer to the Bitstream.
+*  numBits          : No of bits to be read
+*
+*  Values Returned  : The bits read (upto 32 bits maximum) starting from the
+*                     least significant bit and going towards most significant
+*                     bit in the order of their occurence.
+*******************************************************************************/
+INLINE UWORD32 impeg2d_bit_stream_nxt( stream_t  *ps_stream, WORD32 i4_no_of_bits)
+{
+    UWORD32     u4_bits,u4_offset,u4_temp;
+    UWORD8      u4_bit_ptr;
+
+    ASSERT(i4_no_of_bits > 0);
+
+    u4_offset               = ps_stream->u4_offset;
+    u4_bit_ptr              = u4_offset & 0x1F;
+    u4_bits                 = ps_stream->u4_buf << u4_bit_ptr;
+
+    u4_bit_ptr              += i4_no_of_bits;
+    if(32 < u4_bit_ptr)
+    {
+        /*  Read bits from the next word if necessary */
+        u4_temp             = ps_stream->u4_buf_nxt;
+        u4_bit_ptr          &= (BITS_IN_INT - 1);
+
+        u4_temp             = (u4_temp >> (BITS_IN_INT - u4_bit_ptr));
+
+        /* u4_temp consists of bits,if any that had to be read from the next word
+           of the buffer.The bits read from both the words are concatenated and
+           moved to the least significant positions of 'u4_bits'*/
+        u4_bits = (u4_bits >> (32 - i4_no_of_bits)) | u4_temp;
+    }
+    else
+    {
+        u4_bits = (u4_bits >> (32 - i4_no_of_bits));
+    }
+
+    return (u4_bits);
+}
+/******************************************************************************
+*
+*  Function Name    : impeg2d_bit_stream_get
+*
+*  Description      : This is a Bitstream processing function. It reads a
+*                     specified number of bits from the current bit
+*                     position and advances the bit and byte pointers
+*                     appropriately
+*  Arguments        :
+*  ctxt             : Pointer to the Bitstream.
+*  numBits          : No of bits to be read
+*
+*  Values Returned  : The bits read (upto 32 bits maximum) starting from the
+*                     least significant bit and going towards most significant
+*                     bit in the order of their occurence.
+*******************************************************************************/
+
+INLINE UWORD32 impeg2d_bit_stream_get(void* pv_ctxt, UWORD32 u4_num_bits)
+{
+    UWORD32 u4_next_bits = impeg2d_bit_stream_nxt(pv_ctxt, u4_num_bits);
+    impeg2d_bit_stream_flush(pv_ctxt, u4_num_bits);
+    return(u4_next_bits);
+}
+
+
+
+/******************************************************************************
+*
+*  Function Name    : impeg2d_bit_stream_num_bits_read
+*
+*  Description      : This is a Bitstream processing function. It reads a
+*                     specified number of bits from the current bit
+*                     position and advances the bit and byte pointers
+*                     appropriately
+*  Arguments        :
+*  ctxt             : Pointer to the Bitstream.
+*  numBits          : No of bits to be read
+*
+*  Values Returned  : The bits read (upto 16 bits maximum) starting from the
+*                     least significant bit and going towards most significant
+*                     bit in the order of their occurence.
+*******************************************************************************/
+INLINE UWORD32 impeg2d_bit_stream_num_bits_read(void* pv_ctxt)
+{
+    stream_t *u4_no_of_bitsstream = (stream_t *)pv_ctxt;
+    size_t     u4_temp;
+    UWORD32     u4_bits_read;
+    u4_temp         = (size_t)(u4_no_of_bitsstream->pv_bs_buf);
+    u4_temp         &= 0x3;
+    u4_bits_read         = (u4_no_of_bitsstream->u4_offset - (u4_temp << 3));
+
+    return(u4_bits_read);
+
+}
+
+
diff --git a/decoder/impeg2d_bitstream.h b/decoder/impeg2d_bitstream.h
new file mode 100644
index 0000000..4ce4013
--- /dev/null
+++ b/decoder/impeg2d_bitstream.h
@@ -0,0 +1,156 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/*****************************************************************************/
+/*                                                                           */
+/*  File Name         : impeg2d_bitstream.h                                       */
+/*                                                                           */
+/*  Description       : This file contains all the necessary examples to     */
+/*                      establish a consistent use of Ittiam C coding        */
+/*                      standards (based on Indian Hill C Standards)         */
+/*                                                                           */
+/*  List of Functions : <List the functions defined in this file>            */
+/*                                                                           */
+/*  Issues / Problems : None                                                 */
+/*                                                                           */
+/*  Revision History  :                                                      */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         10 01 2005   Ittiam          Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+#ifndef __IMPEG2D_BITSTREAM_H__
+#define __IMPEG2D_BITSTREAM_H__
+
+
+
+/* Structure for the stream */
+typedef struct _stream_t
+{
+    void    *pv_bs_buf;               /* Pointer to buffer containing the
+                                        bitstream                    */
+
+    UWORD32  *pu4_buf_aligned;         /* Pointer to the buffer after alignment correction,
+                                         It points to the currently usable buffer */
+
+    UWORD32  u4_offset;                  /* Offset in the buffer for the current bit */
+
+    UWORD32  u4_buf;                  /* Buffer storing the current word */
+
+    UWORD32  u4_buf_nxt;              /* Buffer storing the next Word */
+
+    UWORD32  u4_max_offset;            /* Max Bit stream buffer offset in bytes for error checks */
+} stream_t;
+
+#define GET_MARKER_BIT(dec,stream)                                             \
+{                                                                              \
+    if (impeg2d_bit_stream_get(stream,1) != 0x1) {                             \
+    /* No need to return error if marker is not present. */                    \
+    }                                                                          \
+}
+
+/* Define A macro for inlining of FlushBits */
+#define     FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_no_bits,pu4_buf_aligned) \
+{                                                                              \
+        UWORD32     u4_temp;                                                   \
+                                                                               \
+        if (((u4_offset & 0x1f) + u4_no_bits)>= 32)                            \
+        {                                                                      \
+            u4_buf              = u4_buf_nxt;                                  \
+                                                                               \
+            u4_temp             = *(pu4_buf_aligned)++;                        \
+                                                                               \
+            CONV_LE_TO_BE(u4_buf_nxt,u4_temp)                                  \
+        }                                                                      \
+        u4_offset               += u4_no_bits;                                 \
+}
+
+/* Macro to initialize the variables from stream */
+#define GET_TEMP_STREAM_DATA(u4_buf,u4_buf_nxt,u4_offset,pu4_buf_aligned,stream)    \
+{                                                                                   \
+    u4_buf = stream->u4_buf;                                                        \
+    u4_buf_nxt = stream->u4_buf_nxt;                                                \
+    u4_offset = stream->u4_offset;                                                     \
+    pu4_buf_aligned = stream->pu4_buf_aligned;                                      \
+}
+
+/* Macro to put the stream variable values back */
+#define PUT_TEMP_STREAM_DATA(u4_buf,u4_buf_nxt,u4_offset,pu4_buf_aligned,stream)    \
+{                                                                                   \
+    stream->u4_buf = u4_buf;                                                        \
+    stream->u4_buf_nxt = u4_buf_nxt;                                                \
+    stream->u4_offset = u4_offset;                                                     \
+    stream->pu4_buf_aligned = pu4_buf_aligned;                                      \
+}
+
+/* Macro to implement the get bits inline (ibits_nxt_inline) */
+#define IBITS_NXT(u4_buf, u4_buf_nxt, u4_offset, u4_bits, no_of_bits)              \
+{                                                                                   \
+    UWORD8 u4_bit_ptr;                                                              \
+    UWORD32 u4_temp;                                                                \
+                                                                                    \
+    u4_bit_ptr  = u4_offset & 0x1F;                                                 \
+    u4_bits     = u4_buf << u4_bit_ptr;                                             \
+                                                                                    \
+    u4_bit_ptr  += no_of_bits;                                                      \
+                                                                                    \
+    if(32 < u4_bit_ptr)                                                             \
+    {                                                                               \
+        /*  Read bits from the next word if necessary */                            \
+        u4_temp     = u4_buf_nxt;                                           \
+        u4_bit_ptr  &= (BITS_IN_INT - 1);                                           \
+                                                                                    \
+        u4_temp     = (u4_temp >> (BITS_IN_INT - u4_bit_ptr));                      \
+                                                                                    \
+    /* u4_temp consists of bits,if any that had to be read from the next word*/     \
+    /* of the buffer.The bits read from both the words are concatenated and*/       \
+    /* moved to the least significant positions of 'u4_bits'*/                      \
+            u4_bits = (u4_bits >> (32 - no_of_bits)) | u4_temp;                     \
+        }                                                                           \
+        else                                                                        \
+        {                                                                           \
+            u4_bits = (u4_bits >> (32 - no_of_bits));                               \
+        }                                                                           \
+}
+
+/* Macro to implement the get bits inline (ibits_get_inline) */
+#define IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,no_of_bits)   \
+{                                                                                   \
+    IBITS_NXT(u4_buf, u4_buf_nxt, u4_offset, u4_bits, no_of_bits)                   \
+    FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,no_of_bits,pu4_buf_aligned)              \
+}
+
+void impeg2d_bit_stream_init(stream_t *stream,
+                             UWORD8 *byteBuf,
+                             UWORD32 u4_max_offset);
+INLINE UWORD8 impeg2d_bit_stream_get_bit(stream_t *stream);
+INLINE void impeg2d_bit_stream_flush(void* ctxt, UWORD32 NoOfBits);
+INLINE void impeg2d_bit_stream_flush_to_byte_boundary(void* ctxt);
+INLINE UWORD32 impeg2d_bit_stream_nxt(stream_t *stream, WORD32 NoOfBits);
+
+INLINE UWORD32 impeg2d_bit_stream_get(void* ctxt, UWORD32 numBits);
+INLINE UWORD32 impeg2d_bit_stream_num_bits_read(void* ctxt);
+
+
+
+
+
+
+
+#endif /* __IMPEG2D_BITSTREAM_H__ */
diff --git a/decoder/impeg2d_d_pic.c b/decoder/impeg2d_d_pic.c
new file mode 100644
index 0000000..a90e16d
--- /dev/null
+++ b/decoder/impeg2d_d_pic.c
@@ -0,0 +1,251 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+
+#include "iv_datatypedef.h"
+#include "impeg2_defs.h"
+#include "impeg2_globals.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_buf_mgr.h"
+
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_vld_tables.h"
+
+#define BLK_SIZE 8
+#define LUMA_BLK_SIZE (2 * (BLK_SIZE))
+#define CHROMA_BLK_SIZE (BLK_SIZE)
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_get_luma_dc_diff                                         */
+/*                                                                           */
+/*  Description   : Decode the DC differential value from the bitstream for  */
+/*                  luma block                                               */
+/*                                                                           */
+/*  Inputs        : stream - Input stream                                    */
+/*                                                                           */
+/*  Globals       : None                                                     */
+/*                                                                           */
+/*  Processing    : Decode the vlc for dc_diff                               */
+/*                                                                           */
+/*  Outputs       : dc_diff - dc differential used in dc prediction          */
+/*                                                                           */
+/*  Returns       : dc_diff - dc differential used in dc prediction          */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+WORD16  impeg2d_get_luma_dc_diff(stream_t *ps_stream)
+{
+    UWORD16 u2_dc_size;
+    WORD16  i2_dc_diff;
+
+    u2_dc_size = impeg2d_dec_vld_symbol(ps_stream,gai2_impeg2d_dct_dc_size[0],
+                        MPEG2_DCT_DC_LUMA_SIZE_LEN) +
+                        MPEG2_DCT_DC_SIZE_OFFSET;
+    if (u2_dc_size != 0)
+    {
+        i2_dc_diff = impeg2d_bit_stream_get(ps_stream,u2_dc_size);
+        if ((i2_dc_diff & (1 << (u2_dc_size - 1))) == 0)
+            i2_dc_diff -= (1 << u2_dc_size) - 1;
+    }
+    else
+    {
+        i2_dc_diff = 0;
+    }
+    return i2_dc_diff;
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_get_chroma_dc_diff                                       */
+/*                                                                           */
+/*  Description   : Decode the DC differential value from the bitstream for  */
+/*                  chroma block                                             */
+/*                                                                           */
+/*  Inputs        : stream - Input stream                                    */
+/*                                                                           */
+/*  Globals       : None                                                     */
+/*                                                                           */
+/*  Processing    : Decode the vlc for dc_diff                               */
+/*                                                                           */
+/*  Outputs       : dc_diff - dc differential used in dc prediction          */
+/*                                                                           */
+/*  Returns       : dc_diff - dc differential used in dc prediction          */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+WORD16  impeg2d_get_chroma_dc_diff(stream_t *ps_stream)
+{
+    UWORD16 u2_dc_size;
+    WORD16  i2_dc_diff;
+    u2_dc_size = impeg2d_dec_vld_symbol(ps_stream,gai2_impeg2d_dct_dc_size[1],
+                        MPEG2_DCT_DC_CHROMA_SIZE_LEN) +
+                        MPEG2_DCT_DC_SIZE_OFFSET;
+    if (u2_dc_size != 0)
+    {
+        i2_dc_diff = impeg2d_bit_stream_get(ps_stream,u2_dc_size);
+        if ((i2_dc_diff & (1 << (u2_dc_size - 1))) == 0)
+            i2_dc_diff -= (1 << u2_dc_size) - 1;
+    }
+    else
+    {
+        i2_dc_diff = 0;
+    }
+    return i2_dc_diff;
+}
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_d_slice
+*
+*  Description     : Decodes I slice
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_d_slice(dec_state_t *ps_dec)
+{
+    UWORD32 i;
+    yuv_buf_t *ps_cur_frm_buf  = &ps_dec->s_cur_frm_buf;
+
+    stream_t   *ps_stream       = &ps_dec->s_bit_stream;
+    UWORD8   *pu1_vld_buf;
+
+    WORD16 i2_dc_diff;
+    UWORD32 u4_frame_width = ps_dec->u2_frame_width;
+    UWORD32 u4_frm_offset = 0;
+    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
+    {
+        u4_frame_width <<= 1;
+        if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
+        {
+            u4_frm_offset = ps_dec->u2_frame_width;
+        }
+    }
+
+    do
+    {
+
+        UWORD32 u4_x_offset, u4_y_offset;
+        UWORD32 u4_blk_pos;
+        WORD16 i2_dc_val;
+
+        UWORD32 u4_dst_x_offset     = u4_frm_offset + (ps_dec->u2_mb_x << 4);
+        UWORD32 u4_dst_y_offset     = (ps_dec->u2_mb_y << 4) * u4_frame_width;
+        UWORD8 *pu1_vld_buf8        = ps_cur_frm_buf->pu1_y + u4_dst_x_offset + u4_dst_y_offset;
+        UWORD32 u4_dst_wd           = u4_frame_width;
+        /*------------------------------------------------------------------*/
+        /* Discard the Macroblock stuffing in case of MPEG-1 stream         */
+        /*------------------------------------------------------------------*/
+        while(impeg2d_bit_stream_nxt(ps_stream,MB_STUFFING_CODE_LEN) == MB_STUFFING_CODE)
+            impeg2d_bit_stream_flush(ps_stream,MB_STUFFING_CODE_LEN);
+
+        /*------------------------------------------------------------------*/
+        /* Flush 2 bits from bitstream [MB_Type and MacroBlockAddrIncrement]*/
+        /*------------------------------------------------------------------*/
+        impeg2d_bit_stream_flush(ps_stream,1);
+
+        if(impeg2d_bit_stream_get(ps_stream, 1) != 0x01)
+        {
+            /* Ignore and continue decoding. */
+        }
+
+        /* Process LUMA blocks of the MB */
+        for(i = 0; i < NUM_LUMA_BLKS; ++i)
+        {
+
+            u4_x_offset    = gai2_impeg2_blk_x_off[i];
+            u4_y_offset    = gai2_impeg2_blk_y_off_frm[i] ;
+            u4_blk_pos     = (u4_y_offset * u4_dst_wd) + u4_x_offset;
+            pu1_vld_buf     = pu1_vld_buf8 + u4_blk_pos;
+
+            i2_dc_diff = impeg2d_get_luma_dc_diff(ps_stream);
+            i2_dc_val = ps_dec->u2_def_dc_pred[Y_LUMA] + i2_dc_diff;
+            ps_dec->u2_def_dc_pred[Y_LUMA] = i2_dc_val;
+            i2_dc_val = CLIP_U8(i2_dc_val);
+
+            ps_dec->pf_memset_8bit_8x8_block(pu1_vld_buf, i2_dc_val, u4_dst_wd);
+        }
+
+
+
+        /* Process U block of the MB */
+
+        u4_dst_x_offset                >>= 1;
+        u4_dst_y_offset                >>= 2;
+        u4_dst_wd                      >>= 1;
+        pu1_vld_buf                     = ps_cur_frm_buf->pu1_u + u4_dst_x_offset + u4_dst_y_offset;
+        i2_dc_diff                     = impeg2d_get_chroma_dc_diff(ps_stream);
+        i2_dc_val                      = ps_dec->u2_def_dc_pred[U_CHROMA] + i2_dc_diff;
+        ps_dec->u2_def_dc_pred[U_CHROMA]    = i2_dc_val;
+        i2_dc_val = CLIP_U8(i2_dc_val);
+        ps_dec->pf_memset_8bit_8x8_block(pu1_vld_buf, i2_dc_val, u4_dst_wd);
+
+
+        /* Process V block of the MB */
+
+        pu1_vld_buf                     = ps_cur_frm_buf->pu1_v + u4_dst_x_offset + u4_dst_y_offset;
+        i2_dc_diff                     = impeg2d_get_chroma_dc_diff(ps_stream);
+        i2_dc_val                      = ps_dec->u2_def_dc_pred[V_CHROMA] + i2_dc_diff;
+        ps_dec->u2_def_dc_pred[V_CHROMA]    = i2_dc_val;
+        i2_dc_val = CLIP_U8(i2_dc_val);
+        ps_dec->pf_memset_8bit_8x8_block(pu1_vld_buf, i2_dc_val, u4_dst_wd);
+
+        /* Common MB processing Steps */
+
+
+        ps_dec->u2_num_mbs_left--;
+        ps_dec->u2_mb_x++;
+
+        if(ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset)
+        {
+            return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
+        }
+        else if ((ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb) && ((ps_dec->s_bit_stream.u4_offset + START_CODE_PREFIX_LEN) < ps_dec->s_bit_stream.u4_max_offset))
+        {
+            ps_dec->u2_mb_x = 0;
+            ps_dec->u2_mb_y++;
+
+        }
+
+        /* Flush end of macro block */
+        impeg2d_bit_stream_flush(ps_stream,1);
+    }
+    while(ps_dec->u2_num_mbs_left != 0 && impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,23) != 0x0);
+    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+}/* End of impeg2d_dec_d_slice() */
diff --git a/decoder/impeg2d_debug.c b/decoder/impeg2d_debug.c
new file mode 100644
index 0000000..ff33290
--- /dev/null
+++ b/decoder/impeg2d_debug.c
@@ -0,0 +1,509 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#include <string.h>
+#include <stdio.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ivd.h"
+#include "impeg2d.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_macros.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_globals.h"
+
+#include "impeg2d_bitstream.h"
+#include "impeg2d_api.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_debug.h"
+
+#if STATISTICS
+WORD32 gai4_impeg2d_idct_inp_last_nonzero_histogram[64] = {0};
+WORD32 gai4_impeg2d_idct_inp_num_nonzero_histogram[64] = {0};
+WORD32 gai4_impeg2d_idct_inp_last_non_zero_row_histogram[8] = {0};
+
+WORD32 gai4_impeg2d_iqnt_inp_last_nonzero_histogram[64] = {0};
+WORD32 gai4_impeg2d_iqnt_inp_num_nonzero_histogram[64] = {0};
+WORD32 gai4_impeg2d_iqnt_inp_last_non_zero_row_histogram[8] = {0};
+
+WORD32 gi4_impeg2d_idct_inp_only_first_coeff = 0;
+WORD32 gi4_impeg2d_idct_inp_only_last_coeff = 0;
+WORD32 gi4_impeg2d_idct_inp_only_first_n_last_coeff = 0;
+WORD32 gi4_impeg2d_idct_cnt = 0;
+
+
+WORD32 gi4_impeg2d_iqnt_inp_only_first_coeff = 0;
+WORD32 gi4_impeg2d_iqnt_inp_only_last_coeff = 0;
+WORD32 gi4_impeg2d_iqnt_inp_only_first_n_last_coeff = 0;
+WORD32 gi4_impeg2d_iqnt_cnt = 0;
+
+
+void impeg2d_iqnt_inp_statistics(WORD16 *pi2_iqnt_inp,
+                                 WORD32 i4_non_zero_cols,
+                                 WORD32 i4_non_zero_rows)
+{
+    WORD32 i, j;
+    WORD32 i4_last_row = 0, i4_last_col = 0;
+    WORD32 i4_num_non_zero = 0;
+    WORD32 i4_non_zero_cols_computed = 0;
+    WORD32 i4_non_zero_rows_computed = 0;
+
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            if(pi2_iqnt_inp[i * 8 + j])
+            {
+                i4_non_zero_cols_computed |= (1 << j);
+                i4_non_zero_rows_computed |= (1 << i);
+            }
+        }
+    }
+
+    if(i4_non_zero_cols_computed != i4_non_zero_cols)
+    {
+        printf("IQ Input: Invalid non_zero_cols 0x%x non_zero_cols_computed 0x%x\n", i4_non_zero_cols, i4_non_zero_cols_computed);
+    }
+    if(i4_non_zero_rows_computed != i4_non_zero_rows)
+    {
+        printf("IQ Input: Invalid non_zero_rows 0x%x non_zero_rows_computed 0x%x\n", i4_non_zero_rows, i4_non_zero_rows_computed);
+    }
+    {
+        WORD32 last_non_zero_row = 32 - CLZ(i4_non_zero_rows);
+        gai4_impeg2d_iqnt_inp_last_non_zero_row_histogram[last_non_zero_row - 1]++;
+    }
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            if(pi2_iqnt_inp[i * 8 + j])
+            {
+                i4_last_col = MAX(i4_last_col, j);
+                i4_last_row = MAX(i4_last_row, i);
+                i4_num_non_zero++;
+            }
+        }
+    }
+    gai4_impeg2d_iqnt_inp_last_nonzero_histogram[i4_last_row * 8 + i4_last_col]++;
+    gai4_impeg2d_iqnt_inp_num_nonzero_histogram[i4_num_non_zero]++;
+    gi4_impeg2d_iqnt_cnt++;
+    /* Check if only (0,0) and (7,7) are non zero */
+    if(i4_num_non_zero == 1)
+    {
+        if(pi2_iqnt_inp[7 * 8 + 7])
+            gi4_impeg2d_iqnt_inp_only_last_coeff++;
+    }
+    if(i4_num_non_zero == 1)
+    {
+        if(pi2_iqnt_inp[0])
+            gi4_impeg2d_iqnt_inp_only_first_coeff++;
+    }
+
+    if(i4_num_non_zero == 2)
+    {
+        if((pi2_iqnt_inp[0]) && (1 == pi2_iqnt_inp[7 * 8 + 7]))
+            gi4_impeg2d_iqnt_inp_only_first_n_last_coeff++;
+    }
+}
+
+void impeg2d_idct_inp_statistics(WORD16 *pi2_idct_inp,
+                                 WORD32 i4_non_zero_cols,
+                                 WORD32 i4_non_zero_rows)
+{
+    WORD32 i, j;
+    WORD32 i4_last_row = 0, i4_last_col = 0;
+    WORD32 i4_num_non_zero = 0;
+    WORD32 i4_non_zero_cols_computed = 0;
+    WORD32 i4_non_zero_rows_computed = 0;
+
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            if(pi2_idct_inp[i * 8 + j])
+            {
+                i4_non_zero_cols_computed |= (1 << j);
+                i4_non_zero_rows_computed |= (1 << i);
+            }
+        }
+    }
+
+    if(i4_non_zero_cols_computed != i4_non_zero_cols)
+    {
+        printf("IDCT Input: Invalid non_zero_cols 0x%x non_zero_cols_computed 0x%x\n", i4_non_zero_cols, i4_non_zero_cols_computed);
+    }
+    if(i4_non_zero_rows_computed != i4_non_zero_rows)
+    {
+        printf("IDCT Input: Invalid non_zero_rows 0x%x non_zero_rows_computed 0x%x\n", i4_non_zero_rows, i4_non_zero_rows_computed);
+    }
+
+    {
+        WORD32 last_non_zero_row = 32 - CLZ(i4_non_zero_rows);
+        gai4_impeg2d_idct_inp_last_non_zero_row_histogram[last_non_zero_row - 1]++;
+    }
+
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            if(pi2_idct_inp[i * 8 + j])
+            {
+                i4_last_col = MAX(i4_last_col, j);
+                i4_last_row = MAX(i4_last_row, i);
+                i4_num_non_zero++;
+            }
+        }
+    }
+    gai4_impeg2d_idct_inp_last_nonzero_histogram[i4_last_row * 8 + i4_last_col]++;
+    gai4_impeg2d_idct_inp_num_nonzero_histogram[i4_num_non_zero]++;
+    gi4_impeg2d_idct_cnt++;
+    /* Check if only (0,0) and (7,7) are non zero */
+    if(i4_num_non_zero == 1)
+    {
+        if(pi2_idct_inp[7 * 8 + 7])
+            gi4_impeg2d_idct_inp_only_last_coeff++;
+    }
+    if(i4_num_non_zero == 1)
+    {
+        if(pi2_idct_inp[0])
+            gi4_impeg2d_idct_inp_only_first_coeff++;
+    }
+
+    if(i4_num_non_zero == 2)
+    {
+        if((pi2_idct_inp[0]) && (1 == pi2_idct_inp[7 * 8 + 7]))
+            gi4_impeg2d_idct_inp_only_first_n_last_coeff++;
+    }
+}
+void impeg2d_print_idct_inp_statistics()
+{
+    WORD32 i, j;
+    WORD32 i4_sum;
+    WORD32 i4_accumulator;
+    i4_sum = 0;
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            i4_sum += gai4_impeg2d_idct_inp_last_nonzero_histogram[i * 8 + j];
+        }
+    }
+    printf("IDCT input : Only last coeff non-zero %8.2f\n", (gi4_impeg2d_idct_inp_only_last_coeff * 100.0) / gi4_impeg2d_idct_cnt);
+    printf("IDCT input : Only first coeff non-zero (Includes DC + mismatch) %8.2f\n", (gi4_impeg2d_idct_inp_only_first_coeff * 100.0) / gi4_impeg2d_idct_cnt);
+
+    printf("IDCT input : Last non-zero coeff histogram\n");
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            double val = gai4_impeg2d_idct_inp_last_nonzero_histogram[i * 8 + j] * 100.0 / i4_sum;
+            printf("%8.2f \t", val);
+
+        }
+        printf("\n");
+    }
+
+    printf("IDCT input : Cumulative Last non-zero coeff histogram\n");
+    i4_accumulator = 0;
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            double val;
+            i4_accumulator += gai4_impeg2d_idct_inp_last_nonzero_histogram[i * 8 + j];
+            val = i4_accumulator * 100.0 / i4_sum;
+
+            printf("%8.2f \t", val);
+
+        }
+        printf("\n");
+    }
+
+
+
+    printf("IDCT input : Number of non-zero coeff histogram\n");
+    i4_sum = 0;
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            i4_sum += gai4_impeg2d_idct_inp_num_nonzero_histogram[i * 8 + j];
+        }
+    }
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            double val = gai4_impeg2d_idct_inp_num_nonzero_histogram[i * 8 + j] * 100.0 / i4_sum;
+            printf("%8.2f \t", val);
+
+        }
+        printf("\n");
+    }
+
+    printf("IDCT input : Cumulative number of non-zero coeffs histogram\n");
+    i4_accumulator = 0;
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            double val;
+            i4_accumulator += gai4_impeg2d_idct_inp_num_nonzero_histogram[i * 8 + j];
+            val = i4_accumulator * 100.0 / i4_sum;
+            printf("%8.2f \t", val);
+
+        }
+        printf("\n");
+    }
+
+    printf("IDCT input : Last non-zero row histogram\n");
+
+
+    {
+        i4_accumulator = 0;
+        for(i = 0; i < 8; i++)
+        {
+            i4_accumulator += gai4_impeg2d_idct_inp_last_non_zero_row_histogram[i];
+        }
+        for(i = 0; i < 8; i++)
+        {
+            double val = gai4_impeg2d_idct_inp_last_non_zero_row_histogram[i] * 100.0 / i4_accumulator;
+            printf("%8.2f \t", val);
+        }
+        printf("\n");
+    }
+
+
+
+
+}
+
+void impeg2d_print_iqnt_inp_statistics()
+{
+    WORD32 i, j;
+    WORD32 i4_sum;
+    WORD32 i4_accumulator;
+    i4_sum = 0;
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            i4_sum += gai4_impeg2d_iqnt_inp_last_nonzero_histogram[i * 8 + j];
+        }
+    }
+    printf("IQnt input : Only last coeff non-zero %8.2f\n", (gi4_impeg2d_iqnt_inp_only_last_coeff * 100.0) / gi4_impeg2d_iqnt_cnt);
+    printf("IQnt input : Only first coeff non-zero (Includes DC + mismatch) %8.2f\n", (gi4_impeg2d_iqnt_inp_only_first_coeff * 100.0) / gi4_impeg2d_idct_cnt);
+
+    printf("IQnt input : Last non-zero coeff histogram\n");
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            double val = gai4_impeg2d_iqnt_inp_last_nonzero_histogram[i * 8 + j] * 100.0 / i4_sum;
+            printf("%8.2f \t", val);
+
+        }
+        printf("\n");
+    }
+
+    printf("IQnt input : Cumulative Last non-zero coeff histogram\n");
+    i4_accumulator = 0;
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            double val;
+            i4_accumulator += gai4_impeg2d_iqnt_inp_last_nonzero_histogram[i * 8 + j];
+            val = i4_accumulator * 100.0 / i4_sum;
+
+            printf("%8.2f \t", val);
+
+        }
+        printf("\n");
+    }
+
+
+
+    printf("IQnt input : Number of non-zero coeff histogram\n");
+    i4_sum = 0;
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            i4_sum += gai4_impeg2d_iqnt_inp_num_nonzero_histogram[i * 8 + j];
+        }
+    }
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            double val = gai4_impeg2d_iqnt_inp_num_nonzero_histogram[i * 8 + j] * 100.0 / i4_sum;
+            printf("%8.2f \t", val);
+
+        }
+        printf("\n");
+    }
+
+    printf("IQnt input : Cumulative number of non-zero coeffs histogram\n");
+    i4_accumulator = 0;
+    for(i = 0; i < 8; i++)
+    {
+        for(j = 0; j < 8; j++)
+        {
+            double val;
+            i4_accumulator += gai4_impeg2d_iqnt_inp_num_nonzero_histogram[i * 8 + j];
+            val = i4_accumulator * 100.0 / i4_sum;
+            printf("%8.2f \t", val);
+
+        }
+        printf("\n");
+    }
+
+    printf("IQnt input : Last non-zero row histogram\n");
+
+
+    {
+        i4_accumulator = 0;
+        for(i = 0; i < 8; i++)
+        {
+            i4_accumulator += gai4_impeg2d_iqnt_inp_last_non_zero_row_histogram[i];
+        }
+        for(i = 0; i < 8; i++)
+        {
+            double val = gai4_impeg2d_iqnt_inp_last_non_zero_row_histogram[i] * 100.0 / i4_accumulator;
+            printf("%8.2f \t", val);
+        }
+        printf("\n");
+    }
+
+}
+
+void impeg2d_print_statistics()
+{
+    impeg2d_print_idct_inp_statistics();
+    impeg2d_print_iqnt_inp_statistics();
+}
+
+
+#endif
+
+#if DEBUG_MB
+
+static UWORD32  u4_debug_frm = 12;
+static UWORD32  u4_debug_mb_x = 3;
+static UWORD32  u4_debug_mb_y = 0;
+
+static UWORD32  u4_debug_frm_num = 0;
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : example_of_a_function                                    */
+/*                                                                           */
+/*  Description   : This function illustrates the use of C coding standards. */
+/*                  switch/case, if, for, block comments have been shown     */
+/*                  here.                                                    */
+/*  Inputs        : <What inputs does the function take?>                    */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Processing    : <Describe how the function operates - include algorithm  */
+/*                  description>                                             */
+/*  Outputs       : <What does the function produce?>                        */
+/*  Returns       : <What does the function return?>                         */
+/*                                                                           */
+/*  Issues        : <List any issues or problems with this function>         */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         13 07 2002   Ittiam          Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_trace_mb_start(UWORD32 u4_mb_x, UWORD32 u4_mb_y)
+{
+    UWORD32 u4_frm_num = impeg2d_frm_num_get();
+
+   if(u4_frm_num == u4_debug_frm && u4_mb_x == u4_debug_mb_x &&  u4_mb_y == u4_debug_mb_y)
+   {
+//       printf("");
+   }
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : example_of_a_function                                    */
+/*                                                                           */
+/*  Description   : This function illustrates the use of C coding standards. */
+/*                  switch/case, if, for, block comments have been shown     */
+/*                  here.                                                    */
+/*  Inputs        : <What inputs does the function take?>                    */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Processing    : <Describe how the function operates - include algorithm  */
+/*                  description>                                             */
+/*  Outputs       : <What does the function produce?>                        */
+/*  Returns       : <What does the function return?>                         */
+/*                                                                           */
+/*  Issues        : <List any issues or problems with this function>         */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         13 07 2002   Ittiam          Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_frm_num_set(void)
+{
+    u4_debug_frm_num++;
+}
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : example_of_a_function                                    */
+/*                                                                           */
+/*  Description   : This function illustrates the use of C coding standards. */
+/*                  switch/case, if, for, block comments have been shown     */
+/*                  here.                                                    */
+/*  Inputs        : <What inputs does the function take?>                    */
+/*  Globals       : <Does it use any global variables?>                      */
+/*  Processing    : <Describe how the function operates - include algorithm  */
+/*                  description>                                             */
+/*  Outputs       : <What does the function produce?>                        */
+/*  Returns       : <What does the function return?>                         */
+/*                                                                           */
+/*  Issues        : <List any issues or problems with this function>         */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         13 07 2002   Ittiam          Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+UWORD32 impeg2d_frm_num_get(void)
+{
+    return(u4_debug_frm_num);
+}
+
+#endif
diff --git a/decoder/impeg2d_debug.h b/decoder/impeg2d_debug.h
new file mode 100644
index 0000000..5780427
--- /dev/null
+++ b/decoder/impeg2d_debug.h
@@ -0,0 +1,121 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/*****************************************************************************/
+/*                                                                           */
+/*  File Name         : c_coding_example.h                                   */
+/*                                                                           */
+/*  Description       : This file contains all the necessary examples to     */
+/*                      establish a consistent use of Ittiam C coding        */
+/*                      standards (based on Indian Hill C Standards)         */
+/*                                                                           */
+/*  List of Functions : <List the functions defined in this file>            */
+/*                                                                           */
+/*  Issues / Problems : None                                                 */
+/*                                                                           */
+/*  Revision History  :                                                      */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         10 01 2005   Ittiam          Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+#ifndef __IMPEG2D_DEBUG_H__
+#define __IMPEG2D_DEBUG_H__
+
+
+/*************************************************************************/
+/* DEBUG                                                                 */
+/*************************************************************************/
+#define DEBUG_MB        0
+
+
+#if DEBUG_MB
+void impeg2d_trace_mb_start(UWORD32 mb_x, UWORD32 mb_y);
+void impeg2d_frm_num_set(void);
+UWORD32 impeg2d_frm_num_get(void);
+
+#define IMPEG2D_TRACE_MB_START(mb_x, mb_y) void impeg2d_trace_mb_start(UWORD32 mb_x, UWORD32 mb_y);
+#define IMPEG2D_FRM_NUM_SET()              void impeg2d_frm_num_set(void);
+#define IMPEG2D_FRM_NUM_GET()              UWORD32 impeg2d_frm_num_get(void);
+#else
+#define IMPEG2D_TRACE_MB_START(mb_x, mb_y)
+#define IMPEG2D_FRM_NUM_SET()
+#define IMPEG2D_FRM_NUM_GET()
+#endif
+
+
+#define STATISTICS  0
+
+#if STATISTICS
+void impeg2d_idct_inp_statistics(WORD16 *pi2_idct_inp, WORD32 non_zero_cols, WORD32 non_zero_rows);
+void impeg2d_iqnt_inp_statistics(WORD16 *pi2_iqnt_inp, WORD32 non_zero_cols, WORD32 non_zero_rows);
+void impeg2d_print_statistics(void);
+#define IMPEG2D_IDCT_INP_STATISTICS(pi2_idct_inp, non_zero_cols, non_zero_rows)  impeg2d_idct_inp_statistics(pi2_idct_inp, non_zero_cols, non_zero_rows)
+#define IMPEG2D_IQNT_INP_STATISTICS(pi2_iqnt_inp, non_zero_cols, non_zero_rows)  impeg2d_iqnt_inp_statistics(pi2_iqnt_inp, non_zero_cols, non_zero_rows)
+#define IMPEG2D_PRINT_STATISTICS()            impeg2d_print_statistics()
+#else
+#define IMPEG2D_IDCT_INP_STATISTICS(pi2_idct_inp, non_zero_cols, non_zero_rows)
+#define IMPEG2D_IQNT_INP_STATISTICS(pi2_iqnt_inp, non_zero_cols, non_zero_rows)
+#define IMPEG2D_PRINT_STATISTICS()
+#endif
+
+
+#if 0
+#define PROFILE_DIS_SKIP_MB
+#define PROFILE_DIS_MC
+#define PROFILE_DIS_INVQUANT
+#define PROFILE_DIS_IDCT
+#define PROFILE_DIS_MEMSET_RESBUF
+#endif
+
+
+#ifdef PROFILE_DIS_SKIP_MB
+#define PROFILE_DISABLE_SKIP_MB() return;
+#else
+#define PROFILE_DISABLE_SKIP_MB()
+#endif
+
+#ifdef PROFILE_DIS_MC
+#define PROFILE_DISABLE_MC_IF0 if(0)
+#define PROFILE_DISABLE_MC_RETURN return;
+#else
+#define PROFILE_DISABLE_MC_IF0
+#define PROFILE_DISABLE_MC_RETURN
+#endif
+
+#ifdef PROFILE_DIS_INVQUANT
+#define PROFILE_DISABLE_INVQUANT_IF0 if(0)
+#else
+#define PROFILE_DISABLE_INVQUANT_IF0
+#endif
+
+#ifdef PROFILE_DIS_IDCT
+#define PROFILE_DISABLE_IDCT_IF0 if(0)
+#else
+#define PROFILE_DISABLE_IDCT_IF0
+#endif
+
+#ifdef PROFILE_DIS_MEMSET_RESBUF
+#define PROFILE_DISABLE_MEMSET_RESBUF_IF0 if(0)
+#else
+#define PROFILE_DISABLE_MEMSET_RESBUF_IF0
+#endif
+
+
+#endif /* __IMPEG2D_DEBUG_H__ */
diff --git a/decoder/impeg2d_dec_hdr.c b/decoder/impeg2d_dec_hdr.c
new file mode 100644
index 0000000..15e61fb
--- /dev/null
+++ b/decoder/impeg2d_dec_hdr.c
@@ -0,0 +1,1733 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ivd.h"
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_platform_macros.h"
+#include "ithread.h"
+#include "impeg2_job_queue.h"
+
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_api.h"
+#include "impeg2d_structs.h"
+#include "impeg2_globals.h"
+#include "impeg2d_pic_proc.h"
+
+
+
+/******************************************************************************
+*  Function Name   : impeg2d_next_start_code
+*
+*  Description     : Peek for next_start_code from the stream_t.
+*
+*  Arguments       :
+*  dec             : Decoder Context
+*
+*  Values Returned : None
+******************************************************************************/
+void impeg2d_next_start_code(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+    ps_stream = &ps_dec->s_bit_stream;
+    impeg2d_bit_stream_flush_to_byte_boundary(ps_stream);
+
+    while ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_PREFIX_LEN) != START_CODE_PREFIX)
+        && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
+    {
+        impeg2d_bit_stream_get(ps_stream,8);
+    }
+    return;
+}
+/******************************************************************************
+*  Function Name   : impeg2d_next_code
+*
+*  Description     : Peek for next_start_code from the stream_t.
+*
+*  Arguments       :
+*  dec             : Decoder Context
+*
+*  Values Returned : None
+******************************************************************************/
+void impeg2d_next_code(dec_state_t *ps_dec, UWORD32 u4_start_code_val)
+{
+    stream_t *ps_stream;
+    ps_stream = &ps_dec->s_bit_stream;
+    impeg2d_bit_stream_flush_to_byte_boundary(ps_stream);
+
+    while ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) != u4_start_code_val)
+        && (ps_dec->s_bit_stream.u4_offset <= ps_dec->s_bit_stream.u4_max_offset))
+    {
+
+        if (impeg2d_bit_stream_get(ps_stream,8) != 0)
+        {
+            /* Ignore stuffing bit errors. */
+        }
+
+    }
+    return;
+}
+/******************************************************************************
+*  Function Name   : impeg2d_peek_next_start_code
+*
+*  Description     : Peek for next_start_code from the stream_t.
+*
+*  Arguments       :
+*  dec             : Decoder Context
+*
+*  Values Returned : None
+******************************************************************************/
+void impeg2d_peek_next_start_code(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+    ps_stream = &ps_dec->s_bit_stream;
+    impeg2d_bit_stream_flush_to_byte_boundary(ps_stream);
+
+    while ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_PREFIX_LEN) != START_CODE_PREFIX)
+        && (ps_dec->s_bit_stream.u4_offset <= ps_dec->s_bit_stream.u4_max_offset))
+    {
+        impeg2d_bit_stream_get(ps_stream,8);
+    }
+    return;
+}
+/******************************************************************************
+*
+*  Function Name   : impeg2d_dec_seq_hdr
+*
+*  Description     : Decodes Sequence header information
+*
+*  Arguments       :
+*  dec             : Decoder Context
+*
+*  Values Returned : None
+******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_seq_hdr(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+    ps_stream = &ps_dec->s_bit_stream;
+    UWORD16 u2_height;
+    UWORD16 u2_width;
+
+    if (impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) != SEQUENCE_HEADER_CODE)
+    {
+        impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+        return IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND;
+
+    }
+    impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+
+    u2_width    = impeg2d_bit_stream_get(ps_stream,12);
+    u2_height   = impeg2d_bit_stream_get(ps_stream,12);
+
+    if ((u2_width != ps_dec->u2_horizontal_size)
+                    || (u2_height != ps_dec->u2_vertical_size))
+    {
+        if (0 == ps_dec->u2_header_done)
+        {
+            /* This is the first time we are reading the resolution */
+            ps_dec->u2_horizontal_size = u2_width;
+            ps_dec->u2_vertical_size = u2_height;
+            if (0 == ps_dec->u4_frm_buf_stride)
+            {
+                ps_dec->u4_frm_buf_stride  = (UWORD32) ALIGN16(u2_width);
+            }
+        }
+        else
+        {
+            if((u2_width > ps_dec->u2_create_max_width)
+                            || (u2_height > ps_dec->u2_create_max_height))
+            {
+                IMPEG2D_ERROR_CODES_T e_error = IMPEG2D_UNSUPPORTED_DIMENSIONS;
+
+                ps_dec->u2_reinit_max_height   = u2_height;
+                ps_dec->u2_reinit_max_width    = u2_width;
+
+                return e_error;
+            }
+            else
+            {
+                /* The resolution has changed */
+                return (IMPEG2D_ERROR_CODES_T)IVD_RES_CHANGED;
+            }
+        }
+    }
+
+    if((ps_dec->u2_horizontal_size > ps_dec->u2_create_max_width)
+                    || (ps_dec->u2_vertical_size > ps_dec->u2_create_max_height))
+    {
+        IMPEG2D_ERROR_CODES_T e_error = IMPEG2D_UNSUPPORTED_DIMENSIONS;
+        return SET_IVD_FATAL_ERROR(e_error);
+    }
+
+
+    /*------------------------------------------------------------------------*/
+    /* Flush the following as they are not being used                         */
+    /* aspect_ratio_info (4 bits)                                             */
+    /*------------------------------------------------------------------------*/
+    ps_dec->u2_aspect_ratio_info = impeg2d_bit_stream_get(ps_stream,4);
+
+    /*------------------------------------------------------------------------*/
+    /* Frame rate code(4 bits)                                                */
+    /*------------------------------------------------------------------------*/
+    ps_dec->u2_frame_rate_code = impeg2d_bit_stream_get(ps_stream,4);
+    /*------------------------------------------------------------------------*/
+    /* Flush the following as they are not being used                         */
+    /* bit_rate_value (18 bits)                                               */
+    /*------------------------------------------------------------------------*/
+    impeg2d_bit_stream_flush(ps_stream,18);
+    GET_MARKER_BIT(ps_dec,ps_stream);
+    /*------------------------------------------------------------------------*/
+    /* Flush the following as they are not being used                         */
+    /* vbv_buffer_size_value(10 bits), constrained_parameter_flag (1 bit)     */
+    /*------------------------------------------------------------------------*/
+    impeg2d_bit_stream_flush(ps_stream,11);
+
+    /*------------------------------------------------------------------------*/
+    /* Quantization matrix for the intra blocks                               */
+    /*------------------------------------------------------------------------*/
+    if(impeg2d_bit_stream_get_bit(ps_stream) == 1)
+    {
+        UWORD16 i;
+        for(i = 0; i < NUM_PELS_IN_BLOCK; i++)
+        {
+            ps_dec->au1_intra_quant_matrix[gau1_impeg2_inv_scan_zig_zag[i]] =  (UWORD8)impeg2d_bit_stream_get(ps_stream,8);
+        }
+
+    }
+    else
+    {
+        memcpy(ps_dec->au1_intra_quant_matrix,gau1_impeg2_intra_quant_matrix_default,
+                NUM_PELS_IN_BLOCK);
+    }
+
+    /*------------------------------------------------------------------------*/
+    /* Quantization matrix for the inter blocks                               */
+    /*------------------------------------------------------------------------*/
+    if(impeg2d_bit_stream_get_bit(ps_stream) == 1)
+    {
+        UWORD16 i;
+        for(i = 0; i < NUM_PELS_IN_BLOCK; i++)
+        {
+            ps_dec->au1_inter_quant_matrix[gau1_impeg2_inv_scan_zig_zag[i]] =   (UWORD8)impeg2d_bit_stream_get(ps_stream,8);
+        }
+    }
+    else
+    {
+        memcpy(ps_dec->au1_inter_quant_matrix,gau1_impeg2_inter_quant_matrix_default,
+            NUM_PELS_IN_BLOCK);
+    }
+    impeg2d_next_start_code(ps_dec);
+
+    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+}
+
+/******************************************************************************
+*
+*  Function Name   : impeg2d_dec_seq_ext
+*
+*  Description     : Gets additional sequence data.
+*
+*  Arguments       :
+*  dec             : Decoder Context
+*
+*  Values Returned : None
+******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_seq_ext(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+
+    ps_stream = &ps_dec->s_bit_stream;
+
+    if (impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) != EXTENSION_START_CODE)
+    {
+        impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+        return IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND;
+
+    }
+    /* Flush the extension start code */
+    impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+
+    /* Flush extension start code identifier */
+    impeg2d_bit_stream_flush(ps_stream,4);
+
+    /*----------------------------------------------------------------------*/
+    /* Profile and Level information                                        */
+    /*----------------------------------------------------------------------*/
+    {
+        UWORD32   u4_esc_bit, u4_profile, u4_level;
+
+        /* Read the profile and level information */
+        /* check_profile_and_level: Table 8-1     */
+        /* [7:7] 1 Escape bit                     */
+        /* [6:4] 3 Profile identification         */
+        /* [3:0] 4 Level identification           */
+
+        u4_esc_bit   = impeg2d_bit_stream_get_bit(ps_stream);
+        u4_profile   = impeg2d_bit_stream_get(ps_stream,3);
+        u4_level     = impeg2d_bit_stream_get(ps_stream,4);
+        UNUSED(u4_profile);
+        UNUSED(u4_level);
+        /*
+        if( escBit == 1                   ||
+            profile < MPEG2_MAIN_PROFILE  ||
+            level < MPEG2_MAIN_LEVEL)
+            */
+        if (1 == u4_esc_bit)
+        {
+            return IMPEG2D_PROF_LEVEL_NOT_SUPPORTED;
+        }
+    }
+
+    ps_dec->u2_progressive_sequence = impeg2d_bit_stream_get_bit(ps_stream);
+
+    /* Read the chrominance format */
+    if(impeg2d_bit_stream_get(ps_stream,2) != 0x1)
+        return IMPEG2D_CHROMA_FMT_NOT_SUP;
+
+    /* Read the 2 most significant bits from horizontal_size */
+    ps_dec->u2_horizontal_size    += (impeg2d_bit_stream_get(ps_stream,2) << 12);
+
+    /* Read the 2 most significant bits from vertical_size */
+    ps_dec->u2_vertical_size      += (impeg2d_bit_stream_get(ps_stream,2) << 12);
+
+    /*-----------------------------------------------------------------------*/
+    /* Flush the following as they are not used now                          */
+    /* bit_rate_extension          12                                        */
+    /* marker_bit                   1                                        */
+    /* vbv_buffer_size_extension    8                                        */
+    /* low_delay                    1                                        */
+    /*-----------------------------------------------------------------------*/
+    impeg2d_bit_stream_flush(ps_stream,12);
+    GET_MARKER_BIT(ps_dec,ps_stream);
+    impeg2d_bit_stream_flush(ps_stream,9);
+    /*-----------------------------------------------------------------------*/
+    /* frame_rate_extension_n       2                                        */
+    /* frame_rate_extension_d       5                                        */
+    /*-----------------------------------------------------------------------*/
+    ps_dec->u2_frame_rate_extension_n = impeg2d_bit_stream_get(ps_stream,2);
+    ps_dec->u2_frame_rate_extension_d = impeg2d_bit_stream_get(ps_stream,5);
+
+    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_seq_disp_ext
+*
+*  Description     : This function is eqvt to sequence_display_extension() of
+*                    standard. It flushes data present as it is not being used
+*
+*  Arguments       :
+*  dec             : Decoder Context
+*
+*  Values Returned : None
+******************************************************************************/
+void impeg2d_dec_seq_disp_ext(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+    ps_stream = &ps_dec->s_bit_stream;
+
+    /*
+    sequence_display_extension()
+    {
+        extension_start_code_identifier 4
+        video_format                    3
+        colour_description              1
+        if (colour_description)
+        {
+            colour_primaries            8
+            transfer_characteristics    8
+            matrix_coefficients         8
+        }
+        display_horizontal_size         14
+        marker_bit                      1
+        display_vertical_size           14
+        next_start_code()
+    }
+    */
+
+    impeg2d_bit_stream_get(ps_stream,7);
+    if (impeg2d_bit_stream_get_bit(ps_stream) == 1)
+    {
+        impeg2d_bit_stream_get(ps_stream,24);
+    }
+
+    /* display_horizontal_size and display_vertical_size */
+    ps_dec->u2_display_horizontal_size = impeg2d_bit_stream_get(ps_stream,14);;
+    GET_MARKER_BIT(ps_dec,ps_stream);
+    ps_dec->u2_display_vertical_size   = impeg2d_bit_stream_get(ps_stream,14);
+
+    impeg2d_next_start_code(ps_dec);
+}
+
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_seq_scale_ext
+*
+*  Description     : This function is eqvt to sequence_scalable_extension() of
+*                    standard.
+*
+*  Arguments       : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_seq_scale_ext(dec_state_t *ps_dec)
+{
+    UNUSED(ps_dec);
+    return IMPEG2D_SCALABILITIY_NOT_SUPPORTED;
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_quant_matrix_ext
+*
+*  Description     : Gets Intra and NonIntra quantizer matrix from the stream.
+*
+*  Arguments       : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_quant_matrix_ext(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+
+    ps_stream = &ps_dec->s_bit_stream;
+    /* Flush extension_start_code_identifier */
+    impeg2d_bit_stream_flush(ps_stream,4);
+
+    /*------------------------------------------------------------------------*/
+    /* Quantization matrix for the intra blocks                               */
+    /*------------------------------------------------------------------------*/
+    if(impeg2d_bit_stream_get(ps_stream,1) == 1)
+    {
+        UWORD16 i;
+        for(i = 0; i < NUM_PELS_IN_BLOCK; i++)
+        {
+            ps_dec->au1_intra_quant_matrix[gau1_impeg2_inv_scan_zig_zag[i]] =  (UWORD8)impeg2d_bit_stream_get(ps_stream,8);
+        }
+
+    }
+
+
+    /*------------------------------------------------------------------------*/
+    /* Quantization matrix for the inter blocks                               */
+    /*------------------------------------------------------------------------*/
+    if(impeg2d_bit_stream_get(ps_stream,1) == 1)
+    {
+        UWORD16 i;
+        for(i = 0; i < NUM_PELS_IN_BLOCK; i++)
+        {
+            ps_dec->au1_inter_quant_matrix[gau1_impeg2_inv_scan_zig_zag[i]] =   (UWORD8)impeg2d_bit_stream_get(ps_stream,8);
+        }
+    }
+
+    /* Note : chroma intra quantizer matrix and chroma non
+    intra quantizer matrix are not needed for 4:2:0 format */
+    impeg2d_next_start_code(ps_dec);
+}
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_pic_disp_ext
+*
+*  Description     : This function is eqvt to picture_display_extension() of
+*                    standard.The parameters are not used by decoder
+*
+*  Arguments       : Pointer to dec_state_t
+*
+*  Values Returned : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_pic_disp_ext(dec_state_t *ps_dec)
+{
+    WORD16 i2_number_of_frame_centre_offsets ;
+    stream_t *ps_stream;
+
+    ps_stream = &ps_dec->s_bit_stream;
+    impeg2d_bit_stream_flush(ps_stream,4);
+
+    if (ps_dec->u2_progressive_sequence)
+    {
+        i2_number_of_frame_centre_offsets = (ps_dec->u2_repeat_first_field) ?
+            2 + ps_dec->u2_top_field_first : 1;
+    }
+    else
+    {
+        i2_number_of_frame_centre_offsets =
+            (ps_dec->u2_picture_structure != FRAME_PICTURE) ?
+            1 : 2 + ps_dec->u2_repeat_first_field;
+    }
+    while(i2_number_of_frame_centre_offsets--)
+    {
+        /* frame_centre_horizontal_offset */
+        impeg2d_bit_stream_get(ps_stream,16);
+        GET_MARKER_BIT(ps_dec,ps_stream);
+        /* frame_centre_vertical_offset */
+        impeg2d_bit_stream_get(ps_stream,16);
+        GET_MARKER_BIT(ps_dec,ps_stream);
+    }
+    impeg2d_next_start_code(ps_dec);
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_itu_t_ext
+*
+*  Description     : This function is eqvt to ITU-T_extension() of
+*                    standard.The parameters are not used by decoder
+*
+*  Arguments       : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_itu_t_ext(dec_state_t *ps_dec)
+{
+  impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,EXT_ID_LEN);
+  impeg2d_next_start_code(ps_dec);
+}
+
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_copyright_ext
+*
+*  Description     : This function is eqvt to copyright_extension() of
+*                    standard. The parameters are not used by decoder
+*
+*  Arguments       : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+
+
+void impeg2d_dec_copyright_ext(dec_state_t *ps_dec)
+{
+    UWORD32 u4_bits_to_flush;
+
+    u4_bits_to_flush = COPYRIGHT_EXTENSION_LEN;
+
+    while(u4_bits_to_flush >= 32 )
+    {
+        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,32);
+        u4_bits_to_flush = u4_bits_to_flush - 32;
+    }
+
+    if(u4_bits_to_flush > 0)
+    {
+        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,u4_bits_to_flush);
+    }
+
+
+  impeg2d_next_start_code(ps_dec);
+}
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_cam_param_ext
+*
+*  Description     : This function is eqvt to camera_parameters_extension() of
+*                    standard. The parameters are not used by decoder
+*
+*  Arguments       : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+
+
+void impeg2d_dec_cam_param_ext(dec_state_t *ps_dec)
+{
+
+    UWORD32 u4_bits_to_flush;
+
+    u4_bits_to_flush = CAMERA_PARAMETER_EXTENSION_LEN;
+
+    while(u4_bits_to_flush >= 32 )
+    {
+        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,32);
+        u4_bits_to_flush = u4_bits_to_flush - 32;
+    }
+
+    if(u4_bits_to_flush > 0)
+    {
+        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,u4_bits_to_flush);
+    }
+
+  impeg2d_next_start_code(ps_dec);
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_grp_of_pic_hdr
+*
+*  Description     : Gets information at the GOP level.
+*
+*  Arguments       : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+
+
+void impeg2d_dec_grp_of_pic_hdr(dec_state_t *ps_dec)
+{
+
+    UWORD32 u4_bits_to_flush;
+
+    u4_bits_to_flush = GROUP_OF_PICTURE_LEN;
+
+    while(u4_bits_to_flush >= 32 )
+    {
+        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,32);
+        u4_bits_to_flush = u4_bits_to_flush - 32;
+    }
+
+    if(u4_bits_to_flush > 0)
+    {
+        impeg2d_bit_stream_flush(&ps_dec->s_bit_stream,u4_bits_to_flush);
+    }
+
+}
+
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_pic_hdr
+*
+*  Description     : Gets the picture header information.
+*
+*  Arguments       : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_pic_hdr(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+    ps_stream = &ps_dec->s_bit_stream;
+
+    impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+    /* Flush temporal reference */
+    impeg2d_bit_stream_get(ps_stream,10);
+
+    /* Picture type */
+    ps_dec->e_pic_type = (e_pic_type_t)impeg2d_bit_stream_get(ps_stream,3);
+    if((ps_dec->e_pic_type < I_PIC) || (ps_dec->e_pic_type > D_PIC))
+    {
+        impeg2d_next_code(ps_dec, PICTURE_START_CODE);
+        return IMPEG2D_INVALID_PIC_TYPE;
+    }
+
+    /* Flush vbv_delay */
+    impeg2d_bit_stream_get(ps_stream,16);
+
+    if(ps_dec->e_pic_type == P_PIC || ps_dec->e_pic_type == B_PIC)
+    {
+        ps_dec->u2_full_pel_forw_vector = impeg2d_bit_stream_get_bit(ps_stream);
+        ps_dec->u2_forw_f_code          = impeg2d_bit_stream_get(ps_stream,3);
+    }
+    if(ps_dec->e_pic_type == B_PIC)
+    {
+        ps_dec->u2_full_pel_back_vector = impeg2d_bit_stream_get_bit(ps_stream);
+        ps_dec->u2_back_f_code          = impeg2d_bit_stream_get(ps_stream,3);
+    }
+
+    if(ps_dec->u2_is_mpeg2 == 0)
+    {
+        ps_dec->au2_f_code[0][0] = ps_dec->au2_f_code[0][1] = ps_dec->u2_forw_f_code;
+        ps_dec->au2_f_code[1][0] = ps_dec->au2_f_code[1][1] = ps_dec->u2_back_f_code;
+    }
+
+    /*-----------------------------------------------------------------------*/
+    /*  Flush the extra bit value                                            */
+    /*                                                                       */
+    /*  while(impeg2d_bit_stream_nxt() == '1')                                  */
+    /*  {                                                                    */
+    /*      extra_bit_picture         1                                      */
+    /*      extra_information_picture 8                                      */
+    /*  }                                                                    */
+    /*  extra_bit_picture             1                                      */
+    /*-----------------------------------------------------------------------*/
+    while (impeg2d_bit_stream_nxt(ps_stream,1) == 1)
+    {
+        impeg2d_bit_stream_get(ps_stream,9);
+    }
+    impeg2d_bit_stream_get_bit(ps_stream);
+    impeg2d_next_start_code(ps_dec);
+
+    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+}
+
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_pic_coding_ext
+*
+*  Description     : Reads more picture level parameters
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_pic_coding_ext(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+
+    ps_stream = &ps_dec->s_bit_stream;
+    impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+    /* extension code identifier */
+    impeg2d_bit_stream_get(ps_stream,4);
+
+    ps_dec->au2_f_code[0][0]             = impeg2d_bit_stream_get(ps_stream,4);
+    ps_dec->au2_f_code[0][1]             = impeg2d_bit_stream_get(ps_stream,4);
+    ps_dec->au2_f_code[1][0]             = impeg2d_bit_stream_get(ps_stream,4);
+    ps_dec->au2_f_code[1][1]             = impeg2d_bit_stream_get(ps_stream,4);
+    ps_dec->u2_intra_dc_precision        = impeg2d_bit_stream_get(ps_stream,2);
+    ps_dec->u2_picture_structure            = impeg2d_bit_stream_get(ps_stream,2);
+    ps_dec->u2_top_field_first              = impeg2d_bit_stream_get_bit(ps_stream);
+    ps_dec->u2_frame_pred_frame_dct         = impeg2d_bit_stream_get_bit(ps_stream);
+    ps_dec->u2_concealment_motion_vectors   = impeg2d_bit_stream_get_bit(ps_stream);
+    ps_dec->u2_q_scale_type                 = impeg2d_bit_stream_get_bit(ps_stream);
+    ps_dec->u2_intra_vlc_format             = impeg2d_bit_stream_get_bit(ps_stream);
+    ps_dec->u2_alternate_scan               = impeg2d_bit_stream_get_bit(ps_stream);
+    ps_dec->u2_repeat_first_field           = impeg2d_bit_stream_get_bit(ps_stream);
+    /* Flush chroma_420_type */
+    impeg2d_bit_stream_get_bit(ps_stream);
+
+    ps_dec->u2_progressive_frame            = impeg2d_bit_stream_get_bit(ps_stream);
+    if (impeg2d_bit_stream_get_bit(ps_stream))
+    {
+        /* Flush v_axis, field_sequence, burst_amplitude, sub_carrier_phase */
+        impeg2d_bit_stream_flush(ps_stream,20);
+    }
+    impeg2d_next_start_code(ps_dec);
+
+
+    if(VERTICAL_SCAN == ps_dec->u2_alternate_scan)
+    {
+        ps_dec->pu1_inv_scan_matrix = (UWORD8 *)gau1_impeg2_inv_scan_vertical;
+    }
+    else
+    {
+        ps_dec->pu1_inv_scan_matrix = (UWORD8 *)gau1_impeg2_inv_scan_zig_zag;
+    }
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_slice
+*
+*  Description     : Reads Slice level parameters and calls functions that
+*                    decode individual MBs of slice
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_slice(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+    UWORD32 u4_slice_vertical_position;
+    UWORD32 u4_slice_vertical_position_extension;
+    IMPEG2D_ERROR_CODES_T e_error;
+
+    ps_stream = &ps_dec->s_bit_stream;
+
+    /*------------------------------------------------------------------------*/
+    /* All the profiles supported require restricted slice structure. Hence   */
+    /* there is no need to store slice_vertical_position. Note that max       */
+    /* height supported does not exceed 2800 and scalablity is not supported  */
+    /*------------------------------------------------------------------------*/
+
+    /* Remove the slice start code */
+    impeg2d_bit_stream_flush(ps_stream,START_CODE_PREFIX_LEN);
+    u4_slice_vertical_position = impeg2d_bit_stream_get(ps_stream, 8);
+    if(u4_slice_vertical_position > 2800)
+    {
+        u4_slice_vertical_position_extension = impeg2d_bit_stream_get(ps_stream, 3);
+        u4_slice_vertical_position += (u4_slice_vertical_position_extension << 7);
+    }
+
+    if((u4_slice_vertical_position > ps_dec->u2_num_vert_mb) ||
+       (u4_slice_vertical_position == 0))
+    {
+        return IMPEG2D_INVALID_VERT_SIZE;
+    }
+
+    // change the mb_y to point to slice_vertical_position
+    u4_slice_vertical_position--;
+    if (ps_dec->u2_mb_y != u4_slice_vertical_position)
+    {
+        ps_dec->u2_mb_y    = u4_slice_vertical_position;
+        ps_dec->u2_mb_x    = 0;
+    }
+    ps_dec->u2_first_mb = 1;
+
+    /*------------------------------------------------------------------------*/
+    /* Quant scale code decoding                                              */
+    /*------------------------------------------------------------------------*/
+    {
+        UWORD16 u2_quant_scale_code;
+        u2_quant_scale_code = impeg2d_bit_stream_get(ps_stream,5);
+        ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
+            gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
+    }
+
+    if (impeg2d_bit_stream_nxt(ps_stream,1) == 1)
+    {
+        impeg2d_bit_stream_flush(ps_stream,9);
+        /* Flush extra bit information */
+        while (impeg2d_bit_stream_nxt(ps_stream,1) == 1)
+        {
+            impeg2d_bit_stream_flush(ps_stream,9);
+        }
+    }
+    impeg2d_bit_stream_get_bit(ps_stream);
+
+    /* Reset the DC predictors to reset values given in Table 7.2 at the start*/
+    /* of slice data */
+    ps_dec->u2_def_dc_pred[Y_LUMA]   = 128 << ps_dec->u2_intra_dc_precision;
+    ps_dec->u2_def_dc_pred[U_CHROMA]   = 128 << ps_dec->u2_intra_dc_precision;
+    ps_dec->u2_def_dc_pred[V_CHROMA]   = 128 << ps_dec->u2_intra_dc_precision;
+    /*------------------------------------------------------------------------*/
+    /* dec->DecMBsinSlice() implements the following psuedo code from standard*/
+    /* do                                                                     */
+    /* {                                                                      */
+    /*      macroblock()                                                      */
+    /* } while (impeg2d_bit_stream_nxt() != '000 0000 0000 0000 0000 0000')      */
+    /*------------------------------------------------------------------------*/
+
+    e_error = ps_dec->pf_decode_slice(ps_dec);
+    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+    {
+        return e_error;
+    }
+
+    /* Check for the MBy index instead of number of MBs left, because the
+     * number of MBs left in case of multi-thread decode is the number of MBs
+     * in that row only
+     */
+    if(ps_dec->u2_mb_y < ps_dec->u2_num_vert_mb)
+        impeg2d_next_start_code(ps_dec);
+
+    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+}
+
+void impeg2d_dec_pic_data_thread(dec_state_t *ps_dec)
+{
+    WORD32 i4_continue_decode;
+
+    WORD32 i4_cur_row, temp;
+    UWORD32 u4_bits_read;
+    WORD32 i4_dequeue_job;
+    IMPEG2D_ERROR_CODES_T e_error;
+
+    i4_cur_row = ps_dec->u2_mb_y + 1;
+
+    i4_continue_decode = 1;
+
+    i4_dequeue_job = 1;
+    do
+    {
+        if(i4_cur_row > ps_dec->u2_num_vert_mb)
+        {
+            i4_continue_decode = 0;
+            break;
+        }
+
+        {
+            if((ps_dec->i4_num_cores> 1) && (i4_dequeue_job))
+            {
+                job_t s_job;
+                IV_API_CALL_STATUS_T e_ret;
+                UWORD8 *pu1_buf;
+
+                e_ret = impeg2_jobq_dequeue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 1);
+                if(e_ret != IV_SUCCESS)
+                    break;
+
+                if(CMD_PROCESS == s_job.i4_cmd)
+                {
+                    pu1_buf = ps_dec->pu1_inp_bits_buf + s_job.i4_bistream_ofst;
+                    impeg2d_bit_stream_init(&(ps_dec->s_bit_stream), pu1_buf,
+                            (ps_dec->u4_num_inp_bytes - s_job.i4_bistream_ofst) + 8);
+                    i4_cur_row      = s_job.i2_start_mb_y;
+                    ps_dec->i4_start_mb_y = s_job.i2_start_mb_y;
+                    ps_dec->i4_end_mb_y = s_job.i2_end_mb_y;
+                    ps_dec->u2_mb_x = 0;
+                    ps_dec->u2_mb_y = ps_dec->i4_start_mb_y;
+                    ps_dec->u2_num_mbs_left = (ps_dec->i4_end_mb_y - ps_dec->i4_start_mb_y) * ps_dec->u2_num_horiz_mb;
+
+                }
+                else
+                {
+                    WORD32 start_row;
+                    WORD32 num_rows;
+                    start_row = s_job.i2_start_mb_y << 4;
+                    num_rows = MIN((s_job.i2_end_mb_y << 4), ps_dec->u2_vertical_size);
+                    num_rows -= start_row;
+                    impeg2d_format_convert(ps_dec, ps_dec->ps_disp_pic,
+                                        ps_dec->ps_disp_frm_buf,
+                                        start_row, num_rows);
+                    break;
+
+                }
+
+            }
+            e_error = impeg2d_dec_slice(ps_dec);
+
+            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+            {
+                impeg2d_next_start_code(ps_dec);
+            }
+        }
+
+        /* Detecting next slice start code */
+        while(1)
+        {
+            // skip (dec->u4_num_cores-1) rows
+            u4_bits_read = impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,START_CODE_LEN);
+            temp = u4_bits_read & 0xFF;
+            i4_continue_decode = (((u4_bits_read >> 8) == 0x01) && (temp) && (temp <= 0xAF));
+
+            if(i4_continue_decode)
+            {
+                /* If the slice is from the same row, then continue decoding without dequeue */
+                if((temp - 1) == i4_cur_row)
+                {
+                    i4_dequeue_job = 0;
+                    break;
+                }
+
+                if(temp < ps_dec->i4_end_mb_y)
+                {
+                    i4_cur_row = ps_dec->u2_mb_y;
+                }
+                else
+                {
+                    i4_dequeue_job = 1;
+                }
+                break;
+
+            }
+            else
+                break;
+        }
+
+    }while(i4_continue_decode);
+    if(ps_dec->i4_num_cores > 1)
+    {
+        while(1)
+        {
+            job_t s_job;
+            IV_API_CALL_STATUS_T e_ret;
+
+            e_ret = impeg2_jobq_dequeue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 1);
+            if(e_ret != IV_SUCCESS)
+                break;
+            if(CMD_FMTCONV == s_job.i4_cmd)
+            {
+                WORD32 start_row;
+                WORD32 num_rows;
+                start_row = s_job.i2_start_mb_y << 4;
+                num_rows = MIN((s_job.i2_end_mb_y << 4), ps_dec->u2_vertical_size);
+                num_rows -= start_row;
+                impeg2d_format_convert(ps_dec, ps_dec->ps_disp_pic,
+                                    ps_dec->ps_disp_frm_buf,
+                                    start_row, num_rows);
+            }
+        }
+    }
+    else
+    {
+        if((NULL != ps_dec->ps_disp_pic) && ((0 == ps_dec->u4_share_disp_buf) || (IV_YUV_420P != ps_dec->i4_chromaFormat)))
+            impeg2d_format_convert(ps_dec, ps_dec->ps_disp_pic,
+                            ps_dec->ps_disp_frm_buf,
+                            0, ps_dec->u2_vertical_size);
+    }
+}
+
+static WORD32 impeg2d_init_thread_dec_ctxt(dec_state_t *ps_dec,
+                                           dec_state_t *ps_dec_thd,
+                                           WORD32 i4_min_mb_y)
+{
+    UNUSED(i4_min_mb_y);
+    ps_dec_thd->i4_start_mb_y = 0;
+    ps_dec_thd->i4_end_mb_y = ps_dec->u2_num_vert_mb;
+    ps_dec_thd->u2_mb_x = 0;
+    ps_dec_thd->u2_mb_y = 0;
+    ps_dec_thd->u2_is_mpeg2 = ps_dec->u2_is_mpeg2;
+    ps_dec_thd->u2_frame_width = ps_dec->u2_frame_width;
+    ps_dec_thd->u2_frame_height = ps_dec->u2_frame_height;
+    ps_dec_thd->u2_picture_width = ps_dec->u2_picture_width;
+    ps_dec_thd->u2_horizontal_size = ps_dec->u2_horizontal_size;
+    ps_dec_thd->u2_vertical_size = ps_dec->u2_vertical_size;
+    ps_dec_thd->u2_create_max_width = ps_dec->u2_create_max_width;
+    ps_dec_thd->u2_create_max_height = ps_dec->u2_create_max_height;
+    ps_dec_thd->u2_header_done = ps_dec->u2_header_done;
+    ps_dec_thd->u2_decode_header = ps_dec->u2_decode_header;
+
+    ps_dec_thd->u2_num_horiz_mb = ps_dec->u2_num_horiz_mb;
+    ps_dec_thd->u2_num_vert_mb = ps_dec->u2_num_vert_mb;
+    ps_dec_thd->u2_num_flds_decoded = ps_dec->u2_num_flds_decoded;
+
+    ps_dec_thd->u4_frm_buf_stride = ps_dec->u4_frm_buf_stride;
+
+    ps_dec_thd->u2_field_dct = ps_dec->u2_field_dct;
+    ps_dec_thd->u2_read_dct_type = ps_dec->u2_read_dct_type;
+
+    ps_dec_thd->u2_read_motion_type = ps_dec->u2_read_motion_type;
+    ps_dec_thd->u2_motion_type = ps_dec->u2_motion_type;
+
+    ps_dec_thd->pu2_mb_type = ps_dec->pu2_mb_type;
+    ps_dec_thd->u2_fld_pic = ps_dec->u2_fld_pic;
+    ps_dec_thd->u2_frm_pic = ps_dec->u2_frm_pic;
+
+    ps_dec_thd->u2_fld_parity = ps_dec->u2_fld_parity;
+
+    ps_dec_thd->au2_fcode_data[0] = ps_dec->au2_fcode_data[0];
+    ps_dec_thd->au2_fcode_data[1] = ps_dec->au2_fcode_data[1];
+
+    ps_dec_thd->u1_quant_scale = ps_dec->u1_quant_scale;
+
+    ps_dec_thd->u2_num_mbs_left = ps_dec->u2_num_mbs_left;
+    ps_dec_thd->u2_first_mb = ps_dec->u2_first_mb;
+    ps_dec_thd->u2_num_skipped_mbs = ps_dec->u2_num_skipped_mbs;
+
+    memcpy(&ps_dec_thd->s_cur_frm_buf, &ps_dec->s_cur_frm_buf, sizeof(yuv_buf_t));
+    memcpy(&ps_dec_thd->as_recent_fld[0][0], &ps_dec->as_recent_fld[0][0], sizeof(yuv_buf_t));
+    memcpy(&ps_dec_thd->as_recent_fld[0][1], &ps_dec->as_recent_fld[0][1], sizeof(yuv_buf_t));
+    memcpy(&ps_dec_thd->as_recent_fld[1][0], &ps_dec->as_recent_fld[1][0], sizeof(yuv_buf_t));
+    memcpy(&ps_dec_thd->as_recent_fld[1][1], &ps_dec->as_recent_fld[1][1], sizeof(yuv_buf_t));
+    memcpy(&ps_dec_thd->as_ref_buf, &ps_dec->as_ref_buf, sizeof(yuv_buf_t) * 2 * 2);
+
+
+    ps_dec_thd->pf_decode_slice = ps_dec->pf_decode_slice;
+
+    ps_dec_thd->pf_vld_inv_quant = ps_dec->pf_vld_inv_quant;
+
+    memcpy(ps_dec_thd->pf_idct_recon, ps_dec->pf_idct_recon, sizeof(ps_dec->pf_idct_recon));
+
+    memcpy(ps_dec_thd->pf_mc, ps_dec->pf_mc, sizeof(ps_dec->pf_mc));
+    ps_dec_thd->pf_interpolate = ps_dec->pf_interpolate;
+    ps_dec_thd->pf_copy_mb = ps_dec->pf_copy_mb;
+    ps_dec_thd->pf_fullx_halfy_8x8              =  ps_dec->pf_fullx_halfy_8x8;
+    ps_dec_thd->pf_halfx_fully_8x8              =  ps_dec->pf_halfx_fully_8x8;
+    ps_dec_thd->pf_halfx_halfy_8x8              =  ps_dec->pf_halfx_halfy_8x8;
+    ps_dec_thd->pf_fullx_fully_8x8              =  ps_dec->pf_fullx_fully_8x8;
+
+    ps_dec_thd->pf_memset_8bit_8x8_block        =  ps_dec->pf_memset_8bit_8x8_block;
+    ps_dec_thd->pf_memset_16bit_8x8_linear_block        =  ps_dec->pf_memset_16bit_8x8_linear_block;
+    ps_dec_thd->pf_copy_yuv420p_buf             =   ps_dec->pf_copy_yuv420p_buf;
+    ps_dec_thd->pf_fmt_conv_yuv420p_to_yuv422ile    =   ps_dec->pf_fmt_conv_yuv420p_to_yuv422ile;
+    ps_dec_thd->pf_fmt_conv_yuv420p_to_yuv420sp_uv  =   ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_uv;
+    ps_dec_thd->pf_fmt_conv_yuv420p_to_yuv420sp_vu  =   ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_vu;
+
+
+    memcpy(ps_dec_thd->au1_intra_quant_matrix, ps_dec->au1_intra_quant_matrix, NUM_PELS_IN_BLOCK * sizeof(UWORD8));
+    memcpy(ps_dec_thd->au1_inter_quant_matrix, ps_dec->au1_inter_quant_matrix, NUM_PELS_IN_BLOCK * sizeof(UWORD8));
+    ps_dec_thd->pu1_inv_scan_matrix = ps_dec->pu1_inv_scan_matrix;
+
+
+    ps_dec_thd->u2_progressive_sequence = ps_dec->u2_progressive_sequence;
+    ps_dec_thd->e_pic_type =  ps_dec->e_pic_type;
+    ps_dec_thd->u2_full_pel_forw_vector = ps_dec->u2_full_pel_forw_vector;
+    ps_dec_thd->u2_forw_f_code =   ps_dec->u2_forw_f_code;
+    ps_dec_thd->u2_full_pel_back_vector = ps_dec->u2_full_pel_back_vector;
+    ps_dec_thd->u2_back_f_code = ps_dec->u2_back_f_code;
+
+    memcpy(ps_dec_thd->ai2_mv, ps_dec->ai2_mv, (2*2*2)*sizeof(WORD16));
+    memcpy(ps_dec_thd->au2_f_code, ps_dec->au2_f_code, (2*2)*sizeof(UWORD16));
+    ps_dec_thd->u2_intra_dc_precision = ps_dec->u2_intra_dc_precision;
+    ps_dec_thd->u2_picture_structure = ps_dec->u2_picture_structure;
+    ps_dec_thd->u2_top_field_first = ps_dec->u2_top_field_first;
+    ps_dec_thd->u2_frame_pred_frame_dct = ps_dec->u2_frame_pred_frame_dct;
+    ps_dec_thd->u2_concealment_motion_vectors = ps_dec->u2_concealment_motion_vectors;
+    ps_dec_thd->u2_q_scale_type =  ps_dec->u2_q_scale_type;
+    ps_dec_thd->u2_intra_vlc_format = ps_dec->u2_intra_vlc_format;
+    ps_dec_thd->u2_alternate_scan = ps_dec->u2_alternate_scan;
+    ps_dec_thd->u2_repeat_first_field = ps_dec->u2_repeat_first_field;
+    ps_dec_thd->u2_progressive_frame = ps_dec->u2_progressive_frame;
+    ps_dec_thd->pu1_inp_bits_buf = ps_dec->pu1_inp_bits_buf;
+    ps_dec_thd->u4_num_inp_bytes = ps_dec->u4_num_inp_bytes;
+    ps_dec_thd->pv_jobq = ps_dec->pv_jobq;
+    ps_dec_thd->pv_jobq_buf = ps_dec->pv_jobq_buf;
+    ps_dec_thd->i4_jobq_buf_size = ps_dec->i4_jobq_buf_size;
+
+
+    ps_dec_thd->u2_frame_rate_code = ps_dec->u2_frame_rate_code;
+    ps_dec_thd->u2_frame_rate_extension_n = ps_dec->u2_frame_rate_extension_n;
+    ps_dec_thd->u2_frame_rate_extension_d = ps_dec->u2_frame_rate_extension_d;
+    ps_dec_thd->u2_framePeriod =   ps_dec->u2_framePeriod;
+    ps_dec_thd->u2_display_horizontal_size = ps_dec->u2_display_horizontal_size;
+    ps_dec_thd->u2_display_vertical_size = ps_dec->u2_display_vertical_size;
+    ps_dec_thd->u2_aspect_ratio_info = ps_dec->u2_aspect_ratio_info;
+
+    ps_dec_thd->ps_func_bi_direct = ps_dec->ps_func_bi_direct;
+    ps_dec_thd->ps_func_forw_or_back = ps_dec->ps_func_forw_or_back;
+
+    return 0;
+
+}
+
+
+WORD32 impeg2d_get_slice_pos(dec_state_multi_core_t *ps_dec_state_multi_core)
+{
+    WORD32 u4_bits;
+    WORD32 i4_row;
+
+
+    dec_state_t *ps_dec = ps_dec_state_multi_core->ps_dec_state[0];
+    WORD32 i4_prev_row;
+    stream_t s_bitstrm;
+    WORD32 i4_start_row;
+    WORD32 i4_slice_bistream_ofst;
+    WORD32 i;
+    s_bitstrm = ps_dec->s_bit_stream;
+    i4_prev_row = -1;
+
+    ps_dec_state_multi_core->ps_dec_state[0]->i4_start_mb_y = 0;
+    ps_dec_state_multi_core->ps_dec_state[1]->i4_start_mb_y = -1;
+    ps_dec_state_multi_core->ps_dec_state[2]->i4_start_mb_y = -1;
+    ps_dec_state_multi_core->ps_dec_state[3]->i4_start_mb_y = -1;
+
+    ps_dec_state_multi_core->ps_dec_state[0]->i4_end_mb_y = ps_dec->u2_num_vert_mb;
+    ps_dec_state_multi_core->ps_dec_state[1]->i4_end_mb_y = -1;
+    ps_dec_state_multi_core->ps_dec_state[2]->i4_end_mb_y = -1;
+    ps_dec_state_multi_core->ps_dec_state[3]->i4_end_mb_y = -1;
+
+    if(ps_dec->i4_num_cores == 1)
+        return 0;
+    /* Reset the jobq to start of the jobq buffer */
+    impeg2_jobq_reset((jobq_t *)ps_dec->pv_jobq);
+
+    i4_start_row = -1;
+    i4_slice_bistream_ofst = 0;
+    while(1)
+    {
+        WORD32 i4_is_slice;
+        u4_bits = impeg2d_bit_stream_nxt(&s_bitstrm,START_CODE_LEN);
+        if(s_bitstrm.u4_offset >= s_bitstrm.u4_max_offset)
+        {
+            break;
+        }
+
+
+        i4_row = u4_bits & 0xFF;
+
+        /* Detect end of frame */
+        i4_is_slice = (((u4_bits >> 8) == 0x01) && (i4_row) && (i4_row <= ps_dec->u2_num_vert_mb));
+        if(!i4_is_slice)
+            break;
+
+        i4_row -= 1;
+
+
+        if(i4_prev_row != i4_row)
+        {
+            /* Create a job for previous slice row */
+            if(i4_start_row != -1)
+            {
+                job_t s_job;
+                IV_API_CALL_STATUS_T ret;
+                s_job.i2_start_mb_y = i4_start_row;
+                s_job.i2_end_mb_y = i4_row;
+                s_job.i4_cmd = CMD_PROCESS;
+                s_job.i4_bistream_ofst = i4_slice_bistream_ofst;
+                ret = impeg2_jobq_queue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 0);
+                if(ret != IV_SUCCESS)
+                    return ret;
+
+            }
+            /* Store current slice's bitstream offset */
+            i4_slice_bistream_ofst = s_bitstrm.u4_offset >> 3;
+            i4_slice_bistream_ofst -= (size_t)s_bitstrm.pv_bs_buf & 3;
+            i4_prev_row = i4_row;
+
+            /* Store current slice's row position */
+            i4_start_row = i4_row;
+
+        }
+
+
+        impeg2d_bit_stream_flush(&s_bitstrm, START_CODE_LEN);
+
+        // flush bytes till next start code
+        /* Flush the bytes till a  start code is encountered  */
+        while(impeg2d_bit_stream_nxt(&s_bitstrm, 24) != START_CODE_PREFIX)
+        {
+            impeg2d_bit_stream_get(&s_bitstrm, 8);
+
+            if(s_bitstrm.u4_offset >= s_bitstrm.u4_max_offset)
+            {
+                break;
+            }
+        }
+    }
+
+    /* Create job for the last slice row */
+    {
+        job_t s_job;
+        IV_API_CALL_STATUS_T e_ret;
+        s_job.i2_start_mb_y = i4_start_row;
+        s_job.i2_end_mb_y = ps_dec->u2_num_vert_mb;
+        s_job.i4_cmd = CMD_PROCESS;
+        s_job.i4_bistream_ofst = i4_slice_bistream_ofst;
+        e_ret = impeg2_jobq_queue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 0);
+        if(e_ret != IV_SUCCESS)
+            return e_ret;
+
+    }
+    if((NULL != ps_dec->ps_disp_pic) && ((0 == ps_dec->u4_share_disp_buf) || (IV_YUV_420P != ps_dec->i4_chromaFormat)))
+    {
+        for(i = 0; i < ps_dec->u2_vertical_size; i+=64)
+        {
+            job_t s_job;
+            IV_API_CALL_STATUS_T ret;
+            s_job.i2_start_mb_y = i;
+            s_job.i2_start_mb_y >>= 4;
+            s_job.i2_end_mb_y = (i + 64);
+            s_job.i2_end_mb_y >>= 4;
+            s_job.i4_cmd = CMD_FMTCONV;
+            s_job.i4_bistream_ofst = 0;
+            ret = impeg2_jobq_queue(ps_dec->pv_jobq, &s_job, sizeof(s_job), 1, 0);
+            if(ret != IV_SUCCESS)
+                return ret;
+
+        }
+    }
+
+    impeg2_jobq_terminate(ps_dec->pv_jobq);
+    ps_dec->i4_bytes_consumed = s_bitstrm.u4_offset >> 3;
+    ps_dec->i4_bytes_consumed -= ((size_t)s_bitstrm.pv_bs_buf & 3);
+
+    return 0;
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_pic_data
+*
+*  Description     : It intializes several parameters and decodes a Picture
+*                    till any slice is left.
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+
+void impeg2d_dec_pic_data(dec_state_t *ps_dec)
+{
+
+    WORD32 i;
+    dec_state_multi_core_t *ps_dec_state_multi_core;
+
+    UWORD32  u4_error_code;
+
+    dec_state_t *ps_dec_thd;
+    WORD32 i4_status;
+    WORD32 i4_min_mb_y;
+
+
+    /* Resetting the MB address and MB coordinates at the start of the Frame */
+    ps_dec->u2_mb_x = ps_dec->u2_mb_y = 0;
+    u4_error_code = 0;
+
+    ps_dec_state_multi_core = ps_dec->ps_dec_state_multi_core;
+    impeg2d_get_slice_pos(ps_dec_state_multi_core);
+
+    i4_min_mb_y = 1;
+    for(i=0; i < ps_dec->i4_num_cores - 1; i++)
+    {
+        // initialize decoder context for thread
+        // launch dec->u4_num_cores-1 threads
+
+        ps_dec_thd = ps_dec_state_multi_core->ps_dec_state[i+1];
+
+        ps_dec_thd->ps_disp_pic = ps_dec->ps_disp_pic;
+        ps_dec_thd->ps_disp_frm_buf = ps_dec->ps_disp_frm_buf;
+
+        i4_status = impeg2d_init_thread_dec_ctxt(ps_dec, ps_dec_thd, i4_min_mb_y);
+        //impeg2d_dec_pic_data_thread(ps_dec_thd);
+
+        if(i4_status == 0)
+        {
+            ithread_create(ps_dec_thd->pv_codec_thread_handle, NULL, (void *)impeg2d_dec_pic_data_thread, ps_dec_thd);
+            ps_dec_state_multi_core->au4_thread_launched[i + 1] = 1;
+            i4_min_mb_y = ps_dec_thd->u2_mb_y + 1;
+        }
+        else
+        {
+            ps_dec_state_multi_core->au4_thread_launched[i + 1] = 0;
+            break;
+        }
+    }
+
+    impeg2d_dec_pic_data_thread(ps_dec);
+
+    // wait for threads to complete
+    for(i=0; i < (ps_dec->i4_num_cores - 1); i++)
+    {
+        if(ps_dec_state_multi_core->au4_thread_launched[i + 1] == 1)
+        {
+            ps_dec_thd = ps_dec_state_multi_core->ps_dec_state[i+1];
+            ithread_join(ps_dec_thd->pv_codec_thread_handle, NULL);
+        }
+    }
+
+    ps_dec->u4_error_code = u4_error_code;
+
+}
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_flush_ext_and_user_data
+*
+*  Description     : Flushes the extension and user data present in the
+*                    stream_t
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_flush_ext_and_user_data(dec_state_t *ps_dec)
+{
+    UWORD32 u4_start_code;
+    stream_t *ps_stream;
+
+    ps_stream    = &ps_dec->s_bit_stream;
+    u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+
+    while(u4_start_code == EXTENSION_START_CODE || u4_start_code == USER_DATA_START_CODE)
+    {
+        impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+        while(impeg2d_bit_stream_nxt(ps_stream,START_CODE_PREFIX_LEN) != START_CODE_PREFIX)
+        {
+            impeg2d_bit_stream_flush(ps_stream,8);
+        }
+        u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+    }
+}
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_user_data
+*
+*  Description     : Flushes the user data present in the stream_t
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_user_data(dec_state_t *ps_dec)
+{
+    UWORD32 u4_start_code;
+    stream_t *ps_stream;
+
+    ps_stream    = &ps_dec->s_bit_stream;
+    u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+
+    while(u4_start_code == USER_DATA_START_CODE)
+    {
+        impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+        while(impeg2d_bit_stream_nxt(ps_stream,START_CODE_PREFIX_LEN) != START_CODE_PREFIX)
+        {
+            impeg2d_bit_stream_flush(ps_stream,8);
+        }
+        u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+    }
+}
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_seq_ext_data
+*
+*  Description     : Decodes the extension data following Sequence
+*                    Extension. It flushes any user data if present
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_seq_ext_data(dec_state_t *ps_dec)
+{
+    stream_t   *ps_stream;
+    UWORD32     u4_start_code;
+    IMPEG2D_ERROR_CODES_T e_error;
+
+    e_error = (IMPEG2D_ERROR_CODES_T) IVD_ERROR_NONE;
+
+    ps_stream      = &ps_dec->s_bit_stream;
+    u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+    while( (u4_start_code == EXTENSION_START_CODE ||
+            u4_start_code == USER_DATA_START_CODE) &&
+            (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE == e_error)
+    {
+        if(u4_start_code == USER_DATA_START_CODE)
+        {
+            impeg2d_dec_user_data(ps_dec);
+        }
+        else
+        {
+            impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+            u4_start_code   = impeg2d_bit_stream_nxt(ps_stream,EXT_ID_LEN);
+            switch(u4_start_code)
+            {
+            case SEQ_DISPLAY_EXT_ID:
+                impeg2d_dec_seq_disp_ext(ps_dec);
+                break;
+            case SEQ_SCALABLE_EXT_ID:
+                e_error = IMPEG2D_SCALABILITIY_NOT_SUPPORTED;
+                break;
+            default:
+                /* In case its a reserved extension code */
+                impeg2d_bit_stream_flush(ps_stream,EXT_ID_LEN);
+                impeg2d_peek_next_start_code(ps_dec);
+                break;
+            }
+        }
+        u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+    }
+    return e_error;
+}
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_pic_ext_data
+*
+*  Description     : Decodes the extension data following Picture Coding
+*                    Extension. It flushes any user data if present
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_pic_ext_data(dec_state_t *ps_dec)
+{
+    stream_t   *ps_stream;
+    UWORD32     u4_start_code;
+    IMPEG2D_ERROR_CODES_T e_error;
+
+    e_error = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+
+    ps_stream      = &ps_dec->s_bit_stream;
+    u4_start_code   = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+    while ( (u4_start_code == EXTENSION_START_CODE ||
+            u4_start_code == USER_DATA_START_CODE) &&
+            (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE == e_error)
+    {
+        if(u4_start_code == USER_DATA_START_CODE)
+        {
+            impeg2d_dec_user_data(ps_dec);
+        }
+        else
+        {
+            impeg2d_bit_stream_flush(ps_stream,START_CODE_LEN);
+            u4_start_code   = impeg2d_bit_stream_nxt(ps_stream,EXT_ID_LEN);
+            switch(u4_start_code)
+            {
+            case QUANT_MATRIX_EXT_ID:
+                impeg2d_dec_quant_matrix_ext(ps_dec);
+                break;
+            case COPYRIGHT_EXT_ID:
+                impeg2d_dec_copyright_ext(ps_dec);
+                break;
+            case PIC_DISPLAY_EXT_ID:
+                impeg2d_dec_pic_disp_ext(ps_dec);
+                break;
+            case CAMERA_PARAM_EXT_ID:
+                impeg2d_dec_cam_param_ext(ps_dec);
+                break;
+            case ITU_T_EXT_ID:
+                impeg2d_dec_itu_t_ext(ps_dec);
+                break;
+            case PIC_SPATIAL_SCALABLE_EXT_ID:
+            case PIC_TEMPORAL_SCALABLE_EXT_ID:
+                e_error = IMPEG2D_SCALABLITY_NOT_SUP;
+                break;
+            default:
+                /* In case its a reserved extension code */
+                impeg2d_bit_stream_flush(ps_stream,EXT_ID_LEN);
+                impeg2d_next_start_code(ps_dec);
+                break;
+            }
+        }
+        u4_start_code = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+    }
+    return e_error;
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_process_video_header
+*
+*  Description     : Processes video sequence header information
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_process_video_header(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+    ps_stream = &ps_dec->s_bit_stream;
+    IMPEG2D_ERROR_CODES_T e_error;
+
+    impeg2d_next_code(ps_dec, SEQUENCE_HEADER_CODE);
+    if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+    {
+        e_error = impeg2d_dec_seq_hdr(ps_dec);
+        if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+        {
+            return e_error;
+        }
+    }
+    else
+    {
+      return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
+    }
+    if (impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) == EXTENSION_START_CODE)
+    {
+        /* MPEG2 Decoder */
+        if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+        {
+            e_error = impeg2d_dec_seq_ext(ps_dec);
+            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+            {
+                return e_error;
+            }
+        }
+        else
+        {
+          return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
+        }
+        if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+        {
+            e_error = impeg2d_dec_seq_ext_data(ps_dec);
+            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+            {
+                return e_error;
+            }
+        }
+        return impeg2d_init_video_state(ps_dec,MPEG_2_VIDEO);
+    }
+    else
+    {
+         /* MPEG1 Decoder */
+        if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+        {
+            impeg2d_flush_ext_and_user_data(ps_dec);
+        }
+        return impeg2d_init_video_state(ps_dec,MPEG_1_VIDEO);
+    }
+}
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_process_video_bit_stream
+*
+*  Description     : Processes video sequence header information
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_process_video_bit_stream(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream;
+    UWORD32 u4_next_bits, u4_start_code_found;
+    IMPEG2D_ERROR_CODES_T e_error;
+
+    ps_stream = &ps_dec->s_bit_stream;
+    impeg2d_next_start_code(ps_dec);
+    /* If the stream is MPEG-2 compliant stream */
+    u4_start_code_found = 0;
+
+    if(ps_dec->u2_is_mpeg2)
+    {
+        /* MPEG2 decoding starts */
+        while((u4_start_code_found == 0) && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
+        {
+            u4_next_bits = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+
+            if(u4_next_bits == SEQUENCE_HEADER_CODE)
+            {
+                if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+                {
+                    e_error = impeg2d_dec_seq_hdr(ps_dec);
+                    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+                    {
+                        return e_error;
+                    }
+
+                    u4_start_code_found = 0;
+
+                }
+                else
+                {
+                    return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
+                }
+
+
+                if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+                {
+                    IMPEG2D_ERROR_CODES_T e_error;
+                    e_error = impeg2d_dec_seq_ext(ps_dec);
+                    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+                    {
+                        return e_error;
+                    }
+                    u4_start_code_found = 0;
+
+                }
+                else
+                {
+                    return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
+                }
+            }
+            else if((u4_next_bits == USER_DATA_START_CODE) || (u4_next_bits == EXTENSION_START_CODE))
+            {
+                if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+                {
+                    impeg2d_dec_seq_ext_data(ps_dec);
+                    u4_start_code_found = 0;
+
+                }
+
+            }
+            else if((ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+                    && (u4_next_bits == GOP_START_CODE))
+            {
+                impeg2d_dec_grp_of_pic_hdr(ps_dec);
+                impeg2d_dec_user_data(ps_dec);
+                u4_start_code_found = 0;
+
+            }
+            else if((ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+                    && (u4_next_bits == PICTURE_START_CODE))
+            {
+
+                e_error = impeg2d_dec_pic_hdr(ps_dec);
+                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+                {
+                    return e_error;
+                }
+                impeg2d_dec_pic_coding_ext(ps_dec);
+                e_error = impeg2d_dec_pic_ext_data(ps_dec);
+                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+                {
+                    return e_error;
+                }
+                impeg2d_pre_pic_dec_proc(ps_dec);
+                impeg2d_dec_pic_data(ps_dec);
+                impeg2d_post_pic_dec_proc(ps_dec);
+                u4_start_code_found = 1;
+            }
+            else
+
+            {
+                FLUSH_BITS(ps_dec->s_bit_stream.u4_offset, ps_dec->s_bit_stream.u4_buf, ps_dec->s_bit_stream.u4_buf_nxt, 8, ps_dec->s_bit_stream.pu4_buf_aligned);
+
+            }
+            if(u4_start_code_found == 0)
+            {
+                impeg2d_next_start_code(ps_dec);
+            }
+        }
+        if((u4_start_code_found == 0) && (ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset))
+        {
+            return IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND;
+        }
+
+    }
+        /* If the stream is MPEG-1 compliant stream */
+    else
+    {
+        while((u4_start_code_found == 0) && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
+        {
+            u4_next_bits = impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN);
+
+            if(impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) == SEQUENCE_HEADER_CODE)
+            {
+                if(ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset)
+                {
+                    e_error = impeg2d_dec_seq_hdr(ps_dec);
+                    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+                    {
+                        return e_error;
+                    }
+
+                    u4_start_code_found = 0;
+                }
+                else
+                {
+                    return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
+                }
+            }
+            else if((ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset) && (u4_next_bits == EXTENSION_START_CODE || u4_next_bits == USER_DATA_START_CODE))
+            {
+                impeg2d_flush_ext_and_user_data(ps_dec);
+                u4_start_code_found = 0;
+            }
+
+
+            else if ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) == GOP_START_CODE)
+                    && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
+            {
+                impeg2d_dec_grp_of_pic_hdr(ps_dec);
+                impeg2d_flush_ext_and_user_data(ps_dec);
+                u4_start_code_found = 0;
+            }
+            else if ((impeg2d_bit_stream_nxt(ps_stream,START_CODE_LEN) == PICTURE_START_CODE)
+                    && (ps_dec->s_bit_stream.u4_offset < ps_dec->s_bit_stream.u4_max_offset))
+            {
+
+                e_error = impeg2d_dec_pic_hdr(ps_dec);
+                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+                {
+                    return e_error;
+                }
+                impeg2d_flush_ext_and_user_data(ps_dec);
+                impeg2d_pre_pic_dec_proc(ps_dec);
+                impeg2d_dec_pic_data(ps_dec);
+                impeg2d_post_pic_dec_proc(ps_dec);
+                u4_start_code_found = 1;
+            }
+            else
+            {
+                FLUSH_BITS(ps_dec->s_bit_stream.u4_offset, ps_dec->s_bit_stream.u4_buf, ps_dec->s_bit_stream.u4_buf_nxt, 8, ps_dec->s_bit_stream.pu4_buf_aligned);
+            }
+            impeg2d_next_start_code(ps_dec);
+
+        }
+        if((u4_start_code_found == 0) && (ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset))
+        {
+           return IMPEG2D_FRM_HDR_START_CODE_NOT_FOUND;
+        }
+    }
+
+    return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+}
diff --git a/decoder/impeg2d_dec_hdr.h b/decoder/impeg2d_dec_hdr.h
new file mode 100644
index 0000000..8bd0378
--- /dev/null
+++ b/decoder/impeg2d_dec_hdr.h
@@ -0,0 +1,51 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/*****************************************************************************/
+/*                                                                           */
+/*  File Name         : impeg2d_dec_hdr.h                                   */
+/*                                                                           */
+/*  Description       : This file contains all the necessary examples to     */
+/*                      establish a consistent use of Ittiam C coding        */
+/*                      standards (based on Indian Hill C Standards)         */
+/*                                                                           */
+/*  List of Functions : <List the functions defined in this file>            */
+/*                                                                           */
+/*  Issues / Problems : None                                                 */
+/*                                                                           */
+/*  Revision History  :                                                      */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         10 10 2005   Ittiam          Draft                                */
+/*                                                                           */
+/*****************************************************************************/
+
+#ifndef __IMPEG2D_DEC_HDR_H__
+#define __IMPEG2D_DEC_HDR_H__
+
+/*****************************************************************************/
+/* Function Declarations                                                     */
+/*****************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_process_video_header(dec_state_t *dec);
+
+IMPEG2D_ERROR_CODES_T impeg2d_process_video_bit_stream(dec_state_t *dec);
+
+
+#endif /* __IMPEG2D_DEC_HDR_H__ */
+
diff --git a/decoder/impeg2d_decoder.c b/decoder/impeg2d_decoder.c
new file mode 100755
index 0000000..ae58675
--- /dev/null
+++ b/decoder/impeg2d_decoder.c
@@ -0,0 +1,292 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/*****************************************************************************/
+/*                                                                           */
+/*  File Name         : mpeg2dec_api_utils.c                                 */
+/*                                                                           */
+/*                                                                           */
+/*  Description       : This file defines the API interface for MPEG2 Decoder*/
+/*                                                                           */
+/*  List of Functions : <List the functions defined in this file>            */
+/*                                                                           */
+/*  Issues / Problems : None                                                 */
+/*                                                                           */
+/*  Revision History  :                                                      */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         17 09 2007  Rajendra C Y       Creation                           */
+/*                                                                           */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+/* System include files */
+
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+
+/* User include files */
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ivd.h"
+#include "ithread.h"
+
+#include "impeg2_job_queue.h"
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_mem_func.h"
+
+#include "impeg2d.h"
+#include "impeg2d_api.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_mc.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_dec_hdr.h"
+
+void impeg2d_next_start_code(dec_state_t *ps_dec);
+void impeg2d_next_code(dec_state_t *ps_dec, UWORD32 u4_start_code_val);
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_dec_hdr                                      */
+/*                                                                           */
+/*  Description   :                                                          */
+/*  Inputs        :                                                          */
+/*  Globals       :                                                          */
+/*  Processing    :                                                          */
+/*  Outputs       :                                                          */
+/*  Returns       :                                                          */
+/*                                                                           */
+/*  Issues        :                                                          */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         17 09 2007  Rajendra C Y          Draft                           */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_dec_hdr(void *pv_dec,impeg2d_video_decode_ip_t *ps_ip,
+                 impeg2d_video_decode_op_t *ps_op)
+{
+
+    UWORD32 u4_bits_read;
+    dec_state_t *ps_dec;
+
+    ps_dec = (dec_state_t *)pv_dec;
+    ps_op->s_ivd_video_decode_op_t.u4_error_code = 0;
+
+    impeg2d_bit_stream_init(&(ps_dec->s_bit_stream),ps_ip->s_ivd_video_decode_ip_t.pv_stream_buffer,
+        ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes);
+
+    {
+        {
+            IMPEG2D_ERROR_CODES_T e_error;
+            e_error = impeg2d_process_video_header(ps_dec);
+            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+            {
+                ps_op->s_ivd_video_decode_op_t.u4_error_code    = e_error;
+
+                u4_bits_read     = impeg2d_bit_stream_num_bits_read(&ps_dec->s_bit_stream);
+
+                ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = u4_bits_read>> 3;
+                if(ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed > ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes)
+                {
+                    ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes;
+                }
+                if(ps_op->s_ivd_video_decode_op_t.u4_error_code == 0)
+                    ps_op->s_ivd_video_decode_op_t.u4_error_code = e_error;
+
+
+                impeg2d_next_code(ps_dec, SEQUENCE_HEADER_CODE);
+                return;
+            }
+        }
+        ps_op->s_ivd_video_decode_op_t.u4_pic_ht = ps_dec->u2_vertical_size;
+        ps_op->s_ivd_video_decode_op_t.u4_pic_wd = ps_dec->u2_horizontal_size;
+
+        ps_op->s_ivd_video_decode_op_t.e_pic_type            = IV_NA_FRAME;
+        ps_op->s_ivd_video_decode_op_t.u4_error_code        = IV_SUCCESS;
+
+        u4_bits_read     = impeg2d_bit_stream_num_bits_read(&ps_dec->s_bit_stream);
+        ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = u4_bits_read>> 3;
+        if(ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed > ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes)
+        {
+            ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes;
+        }
+        ps_op->s_ivd_video_decode_op_t.u4_frame_decoded_flag = 0;
+        /* MOD */
+        ps_dec->u2_header_done = 1;
+        ps_dec->u2_decode_header = 0;
+
+    }
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_dec_frm                                         */
+/*                                                                           */
+/*  Description   :                                                          */
+/*  Inputs        :                                                          */
+/*  Globals       :                                                          */
+/*  Processing    :                                                          */
+/*  Outputs       :                                                          */
+/*  Returns       :                                                          */
+/*                                                                           */
+/*  Issues        :                                                          */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*         17 09 2007  Rajendra C Y          Draft                           */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_dec_frm(void *pv_dec,impeg2d_video_decode_ip_t *ps_ip,
+                 impeg2d_video_decode_op_t *ps_op)
+{
+
+
+    stream_t *ps_stream;
+    UWORD32 u4_size = ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes;
+
+    dec_state_t *ps_dec;
+
+    ps_dec = (dec_state_t *)pv_dec;
+    ps_op->s_ivd_video_decode_op_t.u4_error_code = 0;
+
+    IMPEG2D_FRM_NUM_SET();
+
+    ps_dec->pu1_inp_bits_buf = ps_ip->s_ivd_video_decode_ip_t.pv_stream_buffer;
+    ps_dec->u4_num_inp_bytes = u4_size;
+    ps_stream  = &ps_dec->s_bit_stream;
+
+
+    impeg2d_bit_stream_init(ps_stream,ps_ip->s_ivd_video_decode_ip_t.pv_stream_buffer,u4_size);
+
+    /* @ */ /* Updating the bufferID */
+
+    ps_dec->u4_xdmBufID     = ps_ip->s_ivd_video_decode_ip_t.u4_ts;
+
+    {
+        IMPEG2D_ERROR_CODES_T e_error;
+        /* Process the Bitstream */
+        e_error = impeg2d_process_video_bit_stream(ps_dec);
+        if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+        {
+            ps_op->s_ivd_video_decode_op_t.u4_error_code    = e_error;
+
+            if ((IMPEG2D_ERROR_CODES_T) IVD_RES_CHANGED == e_error)
+            {
+                ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = 0;
+                ps_dec->u2_header_done = 0;
+            }
+            else if (IMPEG2D_UNSUPPORTED_DIMENSIONS == e_error)
+            {
+                ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = 0;
+                ps_dec->u2_header_done = 0;
+
+                ps_op->s_ivd_video_decode_op_t.u4_pic_ht = ps_dec->u2_reinit_max_height;
+                ps_op->s_ivd_video_decode_op_t.u4_pic_wd = ps_dec->u2_reinit_max_width;
+            }
+            else
+            {
+                if(ps_dec->i4_num_cores > 1)
+                    ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = ps_dec->i4_bytes_consumed;
+                else
+                {
+                    ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = (ps_dec->s_bit_stream.u4_offset + 7) >> 3;
+                    ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed -= ((size_t)ps_dec->s_bit_stream.pv_bs_buf & 3);
+                }
+
+                if(ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed
+                                > ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes)
+                {
+                    ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed =
+                                    ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes;
+                }
+
+                impeg2d_next_start_code(ps_dec);
+            }
+
+            if(ps_op->s_ivd_video_decode_op_t.u4_error_code == 0)
+            {
+                ps_op->s_ivd_video_decode_op_t.u4_error_code = e_error;
+            }
+
+            return;
+        }
+    }
+    /**************************************************************************/
+    /* Remove the bytes left till next start code is encountered              */
+    /**************************************************************************/
+    ps_op->s_ivd_video_decode_op_t.u4_error_code  = IV_SUCCESS;
+
+    if(ps_dec->i4_num_cores > 1)
+        ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = ps_dec->i4_bytes_consumed;
+    else
+    {
+        ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = (ps_dec->s_bit_stream.u4_offset + 7) >> 3;
+        ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed -= ((size_t)ps_dec->s_bit_stream.pv_bs_buf & 3);
+    }
+    if(ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed > ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes)
+    {
+        ps_op->s_ivd_video_decode_op_t.u4_num_bytes_consumed = ps_ip->s_ivd_video_decode_ip_t.u4_num_Bytes;
+    }
+    ps_op->s_ivd_video_decode_op_t.u4_pic_ht = ps_dec->u2_vertical_size;
+    ps_op->s_ivd_video_decode_op_t.u4_pic_wd = ps_dec->u2_horizontal_size;
+
+        switch(ps_dec->e_pic_type)
+        {
+        case I_PIC :
+            ps_op->s_ivd_video_decode_op_t.e_pic_type = IV_I_FRAME;
+            break;
+
+        case P_PIC:
+            ps_op->s_ivd_video_decode_op_t.e_pic_type = IV_P_FRAME;
+            break;
+
+        case B_PIC:
+            ps_op->s_ivd_video_decode_op_t.e_pic_type = IV_B_FRAME;
+            break;
+
+        case D_PIC:
+            ps_op->s_ivd_video_decode_op_t.e_pic_type = IV_I_FRAME;
+            break;
+
+        default :
+            ps_op->s_ivd_video_decode_op_t.e_pic_type = IV_FRAMETYPE_DEFAULT;
+            break;
+        }
+
+        ps_op->s_ivd_video_decode_op_t.u4_frame_decoded_flag = ps_dec->i4_frame_decoded;
+        ps_op->s_ivd_video_decode_op_t.u4_new_seq = 0;
+        ps_op->s_ivd_video_decode_op_t.u4_error_code = ps_dec->u4_error_code;
+
+
+}
diff --git a/decoder/impeg2d_function_selector_generic.c b/decoder/impeg2d_function_selector_generic.c
new file mode 100644
index 0000000..b8cdf03
--- /dev/null
+++ b/decoder/impeg2d_function_selector_generic.c
@@ -0,0 +1,103 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector.c
+*
+* @brief
+*  Contains functions to initialize function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ithread.h"
+
+
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_job_queue.h"
+#include "impeg2_globals.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_api.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_mc.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+
+void impeg2d_init_function_ptr_generic(void *pv_codec)
+{
+    dec_state_t *ps_dec = (dec_state_t *)pv_codec;
+
+    ps_dec->pf_idct_recon[0]                   = &impeg2_idct_recon_dc;
+    ps_dec->pf_idct_recon[1]                   = &impeg2_idct_recon_dc_mismatch;
+    ps_dec->pf_idct_recon[2]                   = &impeg2_idct_recon;
+    ps_dec->pf_idct_recon[3]                   = &impeg2_idct_recon;
+
+    ps_dec->pf_mc[0]                              = &impeg2d_mc_fullx_fully;
+    ps_dec->pf_mc[1]                              = &impeg2d_mc_fullx_halfy;
+    ps_dec->pf_mc[2]                              = &impeg2d_mc_halfx_fully;
+    ps_dec->pf_mc[3]                              = &impeg2d_mc_halfx_halfy;
+
+    ps_dec->pf_interpolate                     = &impeg2_interpolate;
+    ps_dec->pf_copy_mb                         = &impeg2_copy_mb;
+
+    ps_dec->pf_fullx_halfy_8x8                 = &impeg2_mc_fullx_halfy_8x8;
+    ps_dec->pf_halfx_fully_8x8                 = &impeg2_mc_halfx_fully_8x8;
+    ps_dec->pf_halfx_halfy_8x8                 = &impeg2_mc_halfx_halfy_8x8;
+    ps_dec->pf_fullx_fully_8x8                 = &impeg2_mc_fullx_fully_8x8;
+
+    ps_dec->pf_memset_8bit_8x8_block           = &impeg2_memset_8bit_8x8_block;
+    ps_dec->pf_memset_16bit_8x8_linear_block   = &impeg2_memset0_16bit_8x8_linear_block;
+
+    ps_dec->pf_copy_yuv420p_buf                = &impeg2_copy_frm_yuv420p;
+    ps_dec->pf_fmt_conv_yuv420p_to_yuv422ile   = &impeg2_fmt_conv_yuv420p_to_yuv422ile;
+    ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_uv = &impeg2_fmt_conv_yuv420p_to_yuv420sp_uv;
+    ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_vu = &impeg2_fmt_conv_yuv420p_to_yuv420sp_vu;
+}
diff --git a/decoder/impeg2d_globals.c b/decoder/impeg2d_globals.c
new file mode 100644
index 0000000..8c71ecf
--- /dev/null
+++ b/decoder/impeg2d_globals.c
@@ -0,0 +1,158 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#include <stdio.h>
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_globals.h"
+#include "impeg2d_mc.h"
+
+/*****************************************************************************/
+/* MC params table                                                           */
+/*****************************************************************************/
+const mc_type_consts_t gas_impeg2d_mc_params_luma[][2] =
+{
+    /* frame prediction in P frame picture */
+    {{1,0,1,1,MB_SIZE,MB_SIZE,0},
+     {1,0,1,1,MB_SIZE,MB_SIZE,0}},
+    /* field prediction in P frame picture */
+    {{2,0,1,2,MB_SIZE/2,MB_SIZE*2,0},
+     {2,0,1,2,MB_SIZE/2,MB_SIZE*2,1}},
+    /* frame prediction in B frame picture */
+    {{1,0,1,1,MB_SIZE,MB_SIZE,0},
+     {1,0,1,1,MB_SIZE,MB_SIZE,0}},
+    /* field prediction in B frame picture */
+    {{2,0,1,2,MB_SIZE/2,MB_SIZE*2,0},
+     {2,0,1,2,MB_SIZE/2,MB_SIZE*2,1}},
+    /* dual prime prediction in P frame picture */
+    {{2,0,1,2,MB_SIZE/2,MB_SIZE*2,0},
+     {2,0,1,2,MB_SIZE/2,MB_SIZE*2,1}},
+
+    /* field prediction in P field picture */
+    {{1,0,2,2,MB_SIZE,MB_SIZE,0},{1,0,2,2,MB_SIZE,MB_SIZE,0}},
+    /* 16x8 prediction in P field picture */
+    {{1,0,2,2,MB_SIZE/2,MB_SIZE,0},{1,8,2,2,MB_SIZE/2,MB_SIZE,(1*MB_SIZE/2)}},
+    /* field prediction in B field picture */
+    {{1,0,2,2,MB_SIZE,MB_SIZE,0},{1,0,2,2,MB_SIZE,MB_SIZE,0}},
+    /* 16x8 prediction in B field picture */
+    {{1,0,2,2,MB_SIZE/2,MB_SIZE,0},{1,8,2,2,MB_SIZE/2,MB_SIZE,(1*MB_SIZE/2)}},
+    /* dual prime prediction in P field picture */
+    {{1,0,2,2,MB_SIZE,MB_SIZE,0},{1,0,2,2,MB_SIZE,MB_SIZE,0}}
+
+};
+
+const mc_type_consts_t gas_impeg2d_mc_params_chroma[10][2] =
+{
+    /* frame prediction in P frame picture */
+    {{1,0,1,1,MB_CHROMA_SIZE,MB_CHROMA_SIZE,0},{1,0,1,1,MB_CHROMA_SIZE,MB_CHROMA_SIZE,0}},
+    /* field prediction in P frame picture */
+    {{2,0,1,2,MB_CHROMA_SIZE/2,MB_CHROMA_SIZE*2,0},{2,0,1,2,MB_CHROMA_SIZE/2,
+    MB_CHROMA_SIZE*2,1}},
+    /* frame prediction in B frame picture */
+    {{1,0,1,1,MB_CHROMA_SIZE,MB_CHROMA_SIZE,0},{1,0,1,1,MB_CHROMA_SIZE,
+    MB_CHROMA_SIZE,0}},
+    /* field prediction in B frame picture */
+    {{2,0,1,2,MB_CHROMA_SIZE/2,MB_CHROMA_SIZE*2,0},{2,0,1,2,MB_CHROMA_SIZE/2,
+    MB_CHROMA_SIZE*2,1}},
+    /* dual prime prediction in P frame picture */
+    {{2,0,1,2,MB_CHROMA_SIZE/2,MB_CHROMA_SIZE*2,0},{2,0,1,2,MB_CHROMA_SIZE/2,
+    MB_CHROMA_SIZE*2,1}},
+
+    /* field prediction in P field picture */
+    {{1,0,2,2,MB_CHROMA_SIZE,MB_CHROMA_SIZE,0},{1,0,2,2,MB_CHROMA_SIZE,
+    MB_CHROMA_SIZE,0}},
+    /* 16x8 prediction in P field picture */
+    {{1,0,2,2,MB_CHROMA_SIZE/2,MB_CHROMA_SIZE,0},{1,4,2,2,MB_CHROMA_SIZE/2,
+    MB_CHROMA_SIZE,(1*MB_CHROMA_SIZE/2)}},
+    /* field prediction in B field picture */
+    {{1,0,2,2,MB_CHROMA_SIZE,MB_CHROMA_SIZE,0},{1,0,2,2,MB_CHROMA_SIZE,
+    MB_CHROMA_SIZE,0}},
+    /* 16x8 prediction in B field picture */
+    {{1,0,2,2,MB_CHROMA_SIZE/2,MB_CHROMA_SIZE,0},{1,4,2,2,MB_CHROMA_SIZE/2,
+    MB_CHROMA_SIZE,(1*MB_CHROMA_SIZE/2)}},
+    /* dual prime prediction in P field picture */
+    {{1,0,2,2,MB_CHROMA_SIZE,MB_CHROMA_SIZE,0},{1,0,2,2,MB_CHROMA_SIZE,
+    MB_CHROMA_SIZE,0}}
+
+};
+
+/*****************************************************************************/
+/* MC function pointer table                                                 */
+/*****************************************************************************/
+const dec_mb_params_t gas_impeg2d_func_frm_fw_or_bk[4] =
+{
+    /*0MV*/
+    {impeg2d_dec_1mv_mb,MC_FRM_FW_OR_BK_1MV,impeg2d_mc_1mv},
+    /* motion_type Field based */
+    {impeg2d_dec_2mv_fw_or_bk_mb,MC_FRM_FW_OR_BK_2MV,impeg2d_mc_fw_or_bk_mb},
+    /* motion_type Frame based */
+    {impeg2d_dec_1mv_mb,MC_FRM_FW_OR_BK_1MV,impeg2d_mc_1mv},
+    /* motion_type Dual prime based */
+    {impeg2d_dec_frm_dual_prime,MC_FRM_FW_DUAL_PRIME_1MV,impeg2d_mc_frm_dual_prime},
+};
+
+const dec_mb_params_t gas_impeg2d_func_fld_fw_or_bk[4] =
+{
+    /*0MV*/
+    {impeg2d_dec_1mv_mb,MC_FRM_FW_OR_BK_1MV,impeg2d_mc_1mv},
+    /* motion_type Field based */
+    {impeg2d_dec_1mv_mb,MC_FLD_FW_OR_BK_1MV,impeg2d_mc_1mv},
+    /* motion_type 16x8 MC */
+    {impeg2d_dec_2mv_fw_or_bk_mb,MC_FLD_FW_OR_BK_2MV,impeg2d_mc_fw_or_bk_mb},
+    /* motion_type Dual prime based */
+    {impeg2d_dec_fld_dual_prime,MC_FLD_FW_DUAL_PRIME_1MV,impeg2d_mc_fld_dual_prime},
+};
+
+
+const dec_mb_params_t gas_impeg2d_func_frm_bi_direct[4] =
+{
+    {NULL,MC_FRM_FW_OR_BK_1MV,NULL},
+    /* motion_type Field based */
+    {impeg2d_dec_4mv_mb,MC_FRM_FW_AND_BK_4MV,impeg2d_mc_4mv},
+    /* motion_type Frame based */
+    {impeg2d_dec_2mv_interp_mb,MC_FRM_FW_AND_BK_2MV,impeg2d_mc_2mv},
+    /* Reserved not applicable */
+    {NULL,MC_FRM_FW_OR_BK_1MV,NULL},
+};
+
+const dec_mb_params_t gas_impeg2d_func_fld_bi_direct[4] =
+{
+    {NULL,MC_FRM_FW_OR_BK_1MV,NULL},
+    /* motion_type Field based */
+    {impeg2d_dec_2mv_interp_mb,MC_FLD_FW_AND_BK_2MV,impeg2d_mc_2mv},
+    /* motion_type 16x8 MC */
+    {impeg2d_dec_4mv_mb,MC_FLD_FW_AND_BK_4MV,impeg2d_mc_4mv},
+    /* Reserved not applicable */
+    {NULL,MC_FRM_FW_OR_BK_1MV,NULL},
+};
diff --git a/decoder/impeg2d_globals.h b/decoder/impeg2d_globals.h
new file mode 100644
index 0000000..5b9c093
--- /dev/null
+++ b/decoder/impeg2d_globals.h
@@ -0,0 +1,43 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#ifndef __IMPEG2D_GLOBALS_H__
+#define __IMPEG2D_GLOBALS_H__
+
+typedef struct
+{
+    UWORD16     mvy_cf;
+    UWORD16     mv_num_cf;
+    UWORD16     frm_wd_cf;
+    UWORD16     src_wd_cf;
+    UWORD32      rows;
+    UWORD32      dst_wd;
+    UWORD32      dst_offset_scale;
+}mc_type_consts_t;
+
+extern const mc_type_consts_t gas_impeg2d_mc_params_luma[][2];
+extern const mc_type_consts_t gas_impeg2d_mc_params_chroma[][2];
+
+extern const dec_mb_params_t gas_impeg2d_func_frm_fw_or_bk[];
+extern const dec_mb_params_t gas_impeg2d_func_fld_fw_or_bk[];
+
+extern const dec_mb_params_t gas_impeg2d_func_frm_bi_direct[];
+extern const dec_mb_params_t gas_impeg2d_func_fld_bi_direct[];
+
+#endif /* __IMPEG2D_GLOBALS_H__ */
diff --git a/decoder/impeg2d_i_pic.c b/decoder/impeg2d_i_pic.c
new file mode 100644
index 0000000..1b45350
--- /dev/null
+++ b/decoder/impeg2d_i_pic.c
@@ -0,0 +1,328 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_globals.h"
+#include "impeg2d_mv_dec.h"
+
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_i_mb_params
+*
+*  Description     : Decoding I MB parameters.
+*
+*  Arguments       :
+*  dec             : Decoder state
+*  stream          : Bitstream
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_i_mb_params(dec_state_t *ps_dec)
+{
+
+    UWORD16 u2_next_bits;
+    UWORD16 u2_bits_to_flush;
+    stream_t *ps_stream = &ps_dec->s_bit_stream;
+
+    /*-----------------------------------------------------------------------*/
+    /* Flush the MBAddrIncr Bit                                              */
+    /*                                                                       */
+    /* Since we are not supporting scalable modes there won't be skipped     */
+    /* macroblocks in I-Picture and the MBAddrIncr will always be 1,         */
+    /* The MBAddrIncr can never be greater than 1 for the simple and main    */
+    /* profile MPEG2.                                                        */
+    /*-----------------------------------------------------------------------*/
+    if(impeg2d_bit_stream_nxt(ps_stream,1) == 1) //Making sure the increment is one.
+    {
+        impeg2d_bit_stream_flush(ps_stream,1);
+    }
+    else if(ps_dec->u2_first_mb && ps_dec->u2_mb_x)
+    {
+        WORD32 i4_mb_add_inc = impeg2d_get_mb_addr_incr(ps_stream);
+
+            //VOLParams->FirstInSlice = 0;
+            /****************************************************************/
+            /* Section 6.3.17                                               */
+            /* The first MB of a slice cannot be skipped                    */
+            /* But the mb_addr_incr can be > 1, because at the beginning of */
+            /* a slice, it indicates the offset from the last MB in the     */
+            /* previous row. Hence for the first slice in a row, the        */
+            /* mb_addr_incr needs to be 1.                                  */
+            /****************************************************************/
+            /* MB_x is set to zero whenever MB_y changes.                   */
+
+            ps_dec->u2_mb_x = i4_mb_add_inc - 1;
+            ps_dec->u2_mb_x = MIN(ps_dec->u2_mb_x, (ps_dec->u2_num_horiz_mb - 1));
+    }
+
+    /*-----------------------------------------------------------------------*/
+    /* Decode the macroblock_type, dct_type and quantiser_scale_code         */
+    /*                                                                       */
+    /* macroblock_type      2 bits [can be either 1 or 01]                   */
+    /* dct_type             1 bit                                            */
+    /* quantiser_scale_code 5 bits                                           */
+    /*-----------------------------------------------------------------------*/
+    u2_next_bits = impeg2d_bit_stream_nxt(ps_stream,8);
+    if(BIT(u2_next_bits,7) == 1)
+    {
+        /* read the dct_type if needed */
+        u2_bits_to_flush = 1;
+        if(ps_dec->u2_read_dct_type)
+        {
+            u2_bits_to_flush++;
+            ps_dec->u2_field_dct = BIT(u2_next_bits,6);
+        }
+    }
+    else
+    {
+        u2_bits_to_flush = 7;
+        /*------------------------------------------------------------------*/
+        /* read the dct_type if needed                                      */
+        /*------------------------------------------------------------------*/
+        if(ps_dec->u2_read_dct_type)
+        {
+            u2_bits_to_flush++;
+            ps_dec->u2_field_dct = BIT(u2_next_bits,5);
+        }
+        else
+        {
+            u2_next_bits >>= 1;
+        }
+        /*------------------------------------------------------------------*/
+        /* Quant scale code decoding                                        */
+        /*------------------------------------------------------------------*/
+        {
+            UWORD16 quant_scale_code;
+            quant_scale_code = u2_next_bits & 0x1F;
+
+            ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
+                gau1_impeg2_non_linear_quant_scale[quant_scale_code] :
+                (quant_scale_code << 1);
+        }
+    }
+    impeg2d_bit_stream_flush(ps_stream,u2_bits_to_flush);
+    /*************************************************************************/
+    /* Decoding of motion vectors if concealment motion vectors are present  */
+    /*************************************************************************/
+    if(ps_dec->u2_concealment_motion_vectors)
+    {
+        if(ps_dec->u2_picture_structure != FRAME_PICTURE)
+            impeg2d_bit_stream_flush(ps_stream,1);
+        impeg2d_dec_mv(ps_stream,ps_dec->ai2_pred_mv[FORW][FIRST],ps_dec->ai2_mv[FORW][FIRST],
+            ps_dec->au2_f_code[FORW],0,0);
+
+        /* Flush the marker bit */
+        if(0 == (impeg2d_bit_stream_get(ps_stream,1)))
+        {
+            /* Ignore marker bit error */
+        }
+
+    }
+    ps_dec->u2_first_mb = 0;
+    return;
+}
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_i_slice
+*
+*  Description     : Decodes I slice
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_i_slice(dec_state_t *ps_dec)
+{
+    WORD16 *pi2_vld_out;
+    UWORD32 i;
+    yuv_buf_t *ps_cur_frm_buf = &ps_dec->s_cur_frm_buf;
+
+    UWORD32 u4_frame_width = ps_dec->u2_frame_width;
+    UWORD32 u4_frm_offset = 0;
+    UWORD8  *pu1_out_p;
+    IMPEG2D_ERROR_CODES_T e_error = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+
+
+    pi2_vld_out = ps_dec->ai2_vld_buf;
+
+
+    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
+    {
+        u4_frame_width <<= 1;
+        if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
+        {
+            u4_frm_offset = ps_dec->u2_frame_width;
+        }
+    }
+
+    do
+    {
+        UWORD32 u4_x_offset,u4_y_offset;
+        UWORD32 u4_blk_pos;
+        UWORD32 u4_x_dst_offset = 0;
+        UWORD32 u4_y_dst_offset = 0;
+
+
+        IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
+
+        impeg2d_dec_i_mb_params(ps_dec);
+
+        u4_x_dst_offset = u4_frm_offset + (ps_dec->u2_mb_x << 4);
+        u4_y_dst_offset = (ps_dec->u2_mb_y << 4) * u4_frame_width;
+        pu1_out_p = ps_cur_frm_buf->pu1_y + u4_x_dst_offset + u4_y_dst_offset;
+
+        for(i = 0; i < NUM_LUMA_BLKS; ++i)
+        {
+
+            e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out,
+                                            ps_dec->pu1_inv_scan_matrix, 1, Y_LUMA, 0);
+            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+            {
+                return e_error;
+            }
+
+            u4_x_offset = gai2_impeg2_blk_x_off[i];
+
+            if(ps_dec->u2_field_dct == 0)
+                u4_y_offset = gai2_impeg2_blk_y_off_frm[i] ;
+            else
+                u4_y_offset = gai2_impeg2_blk_y_off_fld[i] ;
+
+            u4_blk_pos = u4_y_offset * u4_frame_width + u4_x_offset;
+            IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
+
+            PROFILE_DISABLE_IDCT_IF0
+            {
+                WORD32 i4_idx;
+                i4_idx = 1;
+                if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+                    i4_idx = 0;
+
+                ps_dec->pf_idct_recon[i4_idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
+                                                        ps_dec->ai2_idct_stg1,
+                                                        (UWORD8 *)gau1_impeg2_zerobuf,
+                                                        pu1_out_p + u4_blk_pos,
+                                                        8,
+                                                        8,
+                                                        u4_frame_width << ps_dec->u2_field_dct,
+                                                        ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
+
+            }
+
+        }
+
+        /* For U and V blocks, divide the x and y offsets by 2. */
+        u4_x_dst_offset >>= 1;
+        u4_y_dst_offset >>= 2;
+
+        /* In case of chrominance blocks the DCT will be frame DCT */
+        /* i = 0, U component and */
+
+        e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out,
+                                        ps_dec->pu1_inv_scan_matrix, 1, U_CHROMA, 0);
+        if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+        {
+            return e_error;
+        }
+
+        pu1_out_p = ps_cur_frm_buf->pu1_u + u4_x_dst_offset + u4_y_dst_offset;
+        IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
+        PROFILE_DISABLE_IDCT_IF0
+        {
+            WORD32 i4_idx;
+            i4_idx = 1;
+            if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+                i4_idx = 0;
+
+            ps_dec->pf_idct_recon[i4_idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
+                                                    ps_dec->ai2_idct_stg1,
+                                                    (UWORD8 *)gau1_impeg2_zerobuf,
+                                                    pu1_out_p,
+                                                    8,
+                                                    8,
+                                                    u4_frame_width >> 1,
+                                                    ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
+
+        }
+        /* Write the idct_out block to the current frame dec->curFrame*/
+        /* In case of field DCT type, write to alternate lines */
+        e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out,
+                                        ps_dec->pu1_inv_scan_matrix, 1, V_CHROMA, 0);
+        if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+        {
+            return e_error;
+        }
+
+        pu1_out_p = ps_cur_frm_buf->pu1_v + u4_x_dst_offset + u4_y_dst_offset;
+        IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
+        PROFILE_DISABLE_IDCT_IF0
+        {
+            WORD32 i4_idx;
+            i4_idx = 1;
+            if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+                i4_idx = 0;
+            ps_dec->pf_idct_recon[i4_idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
+                                                    ps_dec->ai2_idct_stg1,
+                                                    (UWORD8 *)gau1_impeg2_zerobuf,
+                                                    pu1_out_p,
+                                                    8,
+                                                    8,
+                                                    u4_frame_width >> 1,
+                                                    ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
+        }
+        ps_dec->u2_num_mbs_left--;
+
+
+        ps_dec->u2_mb_x++;
+
+        if(ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset)
+        {
+            return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
+        }
+        else if ((ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb) && ((ps_dec->s_bit_stream.u4_offset + START_CODE_PREFIX_LEN) < ps_dec->s_bit_stream.u4_max_offset))
+        {
+            ps_dec->u2_mb_x = 0;
+            ps_dec->u2_mb_y++;
+        }
+
+    }
+    while(ps_dec->u2_num_mbs_left != 0 && impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,23) != 0x0);
+    return e_error;
+}
diff --git a/decoder/impeg2d_mc.c b/decoder/impeg2d_mc.c
new file mode 100644
index 0000000..da13a8c
--- /dev/null
+++ b/decoder/impeg2d_mc.c
@@ -0,0 +1,1373 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_mc.c
+*
+* @brief
+*  Contains MC function definitions for MPEG2 decoder
+*
+* @author
+*  Harish
+*
+* @par List of Functions:
+* - impeg2d_motion_comp()
+* - impeg2d_motion_comp_recon_buf()
+* - impeg2d_mc_1mv()
+* - impeg2d_mc_fw_or_bk_mb()
+* - impeg2d_mc_frm_dual_prime()
+* - impeg2d_mc_fld_dual_prime()
+* - impeg2d_mc_4mv()
+* - impeg2d_mc_2mv()
+* - impeg2d_dec_intra_mb()
+* - impeg2d_dec_skip_p_mb()
+* - impeg2d_dec_skip_b_mb()
+* - impeg2d_dec_skip_mbs()
+* - impeg2d_dec_0mv_coded_mb()
+* - impeg2d_mc_halfx_halfy()
+* - impeg2d_mc_halfx_fully()
+* - impeg2d_mc_fullx_halfy()
+* - impeg2d_mc_fullx_fully()
+* - impeg2d_set_mc_params()
+*
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_globals.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_mv_dec.h"
+#include "impeg2d_mc.h"
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_motion_comp                                      */
+/*                                                                           */
+/*  Description   : Perform motion compensation and store the resulting block*/
+/*                  in the buf                                               */
+/*                                                                           */
+/*  Inputs        : params - Parameters required to do motion compensation   */
+/*                                                                           */
+/*  Globals       :                                                          */
+/*                                                                           */
+/*  Processing    : Calls appropriate functions depending on the mode of     */
+/*                  compensation                                             */
+/*                                                                           */
+/*  Outputs       : buf       - Buffer for the motion compensation result    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Hairsh M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_motion_comp(dec_state_t *ps_dec, mb_mc_params_t *ps_params,yuv_buf_t *ps_buf)
+{
+
+    PROFILE_DISABLE_MC_RETURN;
+
+    /* Perform motion compensation for Y */
+    ps_dec->pf_mc[ps_params->s_luma.u4_mode]((void *)ps_dec, ps_params->s_ref.pu1_y + ps_params->s_luma.u4_src_offset,
+                ps_params->s_luma.u4_src_wd,
+                ps_buf->pu1_y + ps_params->s_luma.u4_dst_offset_res_buf,
+                ps_params->s_luma.u4_dst_wd_res_buf,
+                ps_params->s_luma.u4_cols,
+                ps_params->s_luma.u4_rows);
+    /* Perform motion compensation for U */
+    ps_dec->pf_mc[ps_params->s_chroma.u4_mode]((void *)ps_dec, ps_params->s_ref.pu1_u + ps_params->s_chroma.u4_src_offset,
+                ps_params->s_chroma.u4_src_wd,
+                ps_buf->pu1_u + ps_params->s_chroma.u4_dst_offset_res_buf,
+                ps_params->s_chroma.u4_dst_wd_res_buf,
+                ps_params->s_chroma.u4_cols,
+                ps_params->s_chroma.u4_rows);
+
+    /* Perform motion compensation for V */
+    ps_dec->pf_mc[ps_params->s_chroma.u4_mode]((void *)ps_dec, ps_params->s_ref.pu1_v + ps_params->s_chroma.u4_src_offset,
+                ps_params->s_chroma.u4_src_wd,
+                ps_buf->pu1_v + ps_params->s_chroma.u4_dst_offset_res_buf,
+                ps_params->s_chroma.u4_dst_wd_res_buf,
+                ps_params->s_chroma.u4_cols,
+                ps_params->s_chroma.u4_rows);
+}
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_motion_comp_recon_buf                          */
+/*                                                                           */
+/*  Description   : Perform motion compensation and store the resulting block*/
+/*                  in the buf                                               */
+/*                                                                           */
+/*  Inputs        : params - Parameters required to do motion compensation   */
+/*                                                                           */
+/*  Globals       :                                                          */
+/*                                                                           */
+/*  Processing    : Calls appropriate functions depending on the mode of     */
+/*                  compensation                                             */
+/*                                                                           */
+/*  Outputs       : buf       - Buffer for the motion compensation result    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_motion_comp_recon_buf(dec_state_t *ps_dec,
+                                     mb_mc_params_t *ps_params,
+                                     yuv_buf_t *ps_dest_buf)
+{
+
+    PROFILE_DISABLE_MC_RETURN;
+
+    /* Perform motion compensation for Y */
+    ps_dec->pf_mc[ps_params->s_luma.u4_mode](ps_dec, ps_params->s_ref.pu1_y + ps_params->s_luma.u4_src_offset,
+                                        ps_params->s_luma.u4_src_wd,
+                                        ps_dest_buf->pu1_y + ps_params->s_luma.u4_dst_offset_cur_frm,
+                                        ps_params->s_luma.u4_dst_wd_cur_frm,
+                                        ps_params->s_luma.u4_cols,
+                                        ps_params->s_luma.u4_rows);
+
+    /* Perform motion compensation for U */
+
+    ps_dec->pf_mc[ps_params->s_chroma.u4_mode](ps_dec, ps_params->s_ref.pu1_u + ps_params->s_chroma.u4_src_offset,
+                                        ps_params->s_chroma.u4_src_wd,
+                                        ps_dest_buf->pu1_u + ps_params->s_chroma.u4_dst_offset_cur_frm,
+                                        ps_params->s_chroma.u4_dst_wd_cur_frm,
+                                        ps_params->s_chroma.u4_cols,
+                                        ps_params->s_chroma.u4_rows);
+
+    /* Perform motion compensation for V */
+    ps_dec->pf_mc[ps_params->s_chroma.u4_mode](ps_dec, ps_params->s_ref.pu1_v + ps_params->s_chroma.u4_src_offset,
+                                        ps_params->s_chroma.u4_src_wd,
+                                        ps_dest_buf->pu1_v + ps_params->s_chroma.u4_dst_offset_cur_frm,
+                                        ps_params->s_chroma.u4_dst_wd_cur_frm,
+                                        ps_params->s_chroma.u4_cols,
+                                        ps_params->s_chroma.u4_rows);
+}
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_1mv                                           */
+/*                                                                           */
+/*  Description   : Perform motion compensation and store the resulting block*/
+/*                  in the buf                                               */
+/*                                                                           */
+/*  Inputs        : params - Parameters required to do motion compensation   */
+/*                                                                           */
+/*  Globals       :                                                          */
+/*                                                                           */
+/*  Processing    : Calls appropriate functions depending on the mode of     */
+/*                  compensation                                             */
+/*                                                                           */
+/*  Outputs       : buf       - Buffer for the motion compensation result    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Hairsh M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_mc_1mv(dec_state_t *ps_dec)
+{
+
+    impeg2d_motion_comp_recon_buf(ps_dec, &ps_dec->as_mb_mc_params[ps_dec->e_mb_pred][FIRST], &ps_dec->s_dest_buf);
+}
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_fw_or_bk_mb                                   */
+/*                                                                           */
+/*  Description   : Perform motion compensation and store the resulting block*/
+/*                  in the buf                                               */
+/*                                                                           */
+/*  Inputs        : params - Parameters required to do motion compensation   */
+/*                                                                           */
+/*  Globals       :                                                          */
+/*                                                                           */
+/*  Processing    : Calls appropriate functions depending on the mode of     */
+/*                  compensation                                             */
+/*                                                                           */
+/*  Outputs       : buf       - Buffer for the motion compensation result    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Hairsh M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_mc_fw_or_bk_mb(dec_state_t *ps_dec)
+{
+    impeg2d_motion_comp_recon_buf(ps_dec, &ps_dec->as_mb_mc_params[FORW][FIRST], &ps_dec->s_dest_buf);
+    impeg2d_motion_comp_recon_buf(ps_dec, &ps_dec->as_mb_mc_params[FORW][SECOND], &ps_dec->s_dest_buf);
+}
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_frm_dual_prime                                */
+/*                                                                           */
+/*  Description   : Perform motion compensation and store the resulting block*/
+/*                  in the buf                                               */
+/*                                                                           */
+/*  Inputs        : params - Parameters required to do motion compensation   */
+/*                                                                           */
+/*  Globals       :                                                          */
+/*                                                                           */
+/*  Processing    : Calls appropriate functions depending on the mode of     */
+/*                  compensation                                             */
+/*                                                                           */
+/*  Outputs       : buf       - Buffer for the motion compensation result    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Hairsh M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_mc_frm_dual_prime(dec_state_t *ps_dec)
+{
+    /************************************************************************/
+    /* Perform Motion Compensation                                          */
+    /************************************************************************/
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[FORW][FIRST], &ps_dec->s_mc_fw_buf);
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[BACK][FIRST], &ps_dec->s_mc_bk_buf);
+
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[FORW][SECOND], &ps_dec->s_mc_fw_buf);
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[BACK][SECOND], &ps_dec->s_mc_bk_buf);
+
+
+
+    ps_dec->pf_interpolate(&ps_dec->s_mc_fw_buf,&ps_dec->s_mc_bk_buf,&ps_dec->s_dest_buf,ps_dec->u2_picture_width);
+}
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_fld_dual_prime                                */
+/*                                                                           */
+/*  Description   : Perform motion compensation and store the resulting block*/
+/*                  in the buf                                               */
+/*                                                                           */
+/*  Inputs        : params - Parameters required to do motion compensation   */
+/*                                                                           */
+/*  Globals       :                                                          */
+/*                                                                           */
+/*  Processing    : Calls appropriate functions depending on the mode of     */
+/*                  compensation                                             */
+/*                                                                           */
+/*  Outputs       : buf       - Buffer for the motion compensation result    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Hairsh M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_mc_fld_dual_prime(dec_state_t *ps_dec)
+{
+    /************************************************************************/
+    /* Perform Motion Compensation                                          */
+    /************************************************************************/
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[FORW][FIRST], &ps_dec->s_mc_fw_buf);
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[FORW][SECOND], &ps_dec->s_mc_bk_buf);
+
+
+    ps_dec->pf_interpolate(&ps_dec->s_mc_fw_buf,&ps_dec->s_mc_bk_buf,&ps_dec->s_dest_buf,ps_dec->u2_picture_width);
+}
+
+
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_4mv                                      */
+/*                                                                           */
+/*  Description   : Perform motion compensation and store the resulting block*/
+/*                  in the buf                                               */
+/*                                                                           */
+/*  Inputs        : params - Parameters required to do motion compensation   */
+/*                                                                           */
+/*  Globals       :                                                          */
+/*                                                                           */
+/*  Processing    : Calls appropriate functions depending on the mode of     */
+/*                  compensation                                             */
+/*                                                                           */
+/*  Outputs       : buf       - Buffer for the motion compensation result    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Hairsh M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_mc_4mv(dec_state_t *ps_dec)
+{
+    /************************************************************************/
+    /* Perform Motion Compensation                                          */
+    /************************************************************************/
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[FORW][FIRST], &ps_dec->s_mc_fw_buf);
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[BACK][FIRST], &ps_dec->s_mc_bk_buf);
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[FORW][SECOND], &ps_dec->s_mc_fw_buf);
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[BACK][SECOND], &ps_dec->s_mc_bk_buf);
+
+    ps_dec->pf_interpolate(&ps_dec->s_mc_fw_buf,&ps_dec->s_mc_bk_buf,&ps_dec->s_dest_buf,ps_dec->u2_picture_width);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_2mv                                         */
+/*                                                                           */
+/*  Description   : Perform motion compensation and store the resulting block*/
+/*                  in the buf                                               */
+/*                                                                           */
+/*  Inputs        : params - Parameters required to do motion compensation   */
+/*                                                                           */
+/*  Globals       :                                                          */
+/*                                                                           */
+/*  Processing    : Calls appropriate functions depending on the mode of     */
+/*                  compensation                                             */
+/*                                                                           */
+/*  Outputs       : buf       - Buffer for the motion compensation result    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         14 09 2005   Hairsh M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_mc_2mv(dec_state_t *ps_dec)
+{
+   /************************************************************************/
+    /* Perform Motion Compensation                                          */
+    /************************************************************************/
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[FORW][FIRST], &ps_dec->s_mc_fw_buf);
+    impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[BACK][FIRST], &ps_dec->s_mc_bk_buf);
+
+    ps_dec->pf_interpolate(&ps_dec->s_mc_fw_buf,&ps_dec->s_mc_bk_buf,&ps_dec->s_dest_buf,ps_dec->u2_picture_width);
+}
+
+/*****************************************************************************
+*  Function Name   : impeg2d_dec_intra_mb
+*
+*  Description     : Performs decoding of Intra MB
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*****************************************************************************/
+void impeg2d_dec_intra_mb(dec_state_t *ps_dec)
+{
+
+    ps_dec->u2_cbp = 0x3F;
+    if(ps_dec->u2_concealment_motion_vectors)
+    {
+
+        stream_t *ps_stream;
+
+        ps_stream = &ps_dec->s_bit_stream;
+        /* Decode the concealment motion vector */
+        impeg2d_dec_mv(ps_stream,ps_dec->ai2_pred_mv[FORW][FIRST],ps_dec->ai2_mv[FORW][FIRST],
+        ps_dec->au2_f_code[FORW],0,ps_dec->u2_fld_pic);
+
+
+        /* Set the second motion vector predictor */
+        ps_dec->ai2_pred_mv[FORW][SECOND][MV_X] = ps_dec->ai2_pred_mv[FORW][FIRST][MV_X];
+        ps_dec->ai2_pred_mv[FORW][SECOND][MV_Y] = ps_dec->ai2_pred_mv[FORW][FIRST][MV_Y];
+
+        /* Flush the marker bit */
+        if(0 == (impeg2d_bit_stream_get(ps_stream,1)))
+        {
+            /* Ignore marker bit error */
+        }
+    }
+    else
+    {
+        /* Reset the motion vector predictors */
+        memset(ps_dec->ai2_pred_mv,0,sizeof(ps_dec->ai2_pred_mv));
+    }
+}
+
+/*****************************************************************************
+*  Function Name   : impeg2d_dec_skip_p_mb
+*
+*  Description     : Performs decoding needed for Skipped MB encountered in
+*                    P Pictures and B Pictures with previous MB not bi-predicted
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*****************************************************************************/
+void impeg2d_dec_skip_p_mb(dec_state_t *ps_dec, WORD32 u4_num_of_mbs)
+{
+    WORD16  *pi2_mv;
+
+    e_mb_type_t e_mb_type;
+    mb_mc_params_t *ps_mc;
+
+
+    WORD32 i4_iter;
+    UWORD32 u4_dst_wd;
+    UWORD32  u4_dst_offset_x;
+    UWORD32  u4_dst_offset_y;
+    UWORD32 u4_frm_offset = 0;
+    yuv_buf_t s_dst;
+
+    u4_dst_wd = ps_dec->u2_frame_width;
+
+    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
+    {
+        u4_dst_wd <<= 1;
+        if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
+        {
+            u4_frm_offset = ps_dec->u2_frame_width;
+        }
+    }
+
+    for (i4_iter = u4_num_of_mbs; i4_iter > 0; i4_iter--)
+    {
+        if(ps_dec->u2_picture_structure == FRAME_PICTURE)
+        {
+            e_mb_type = MC_FRM_FW_AND_BK_2MV;
+        }
+        else
+        {
+            e_mb_type = MC_FLD_FW_AND_BK_2MV;
+        }
+
+        ps_dec->u2_prev_intra_mb = 0;
+        pi2_mv               = (WORD16 *)&(ps_dec->ai2_mv[FORW][FIRST]);
+
+        /* Reset the motion vector predictors */
+        if(ps_dec->e_pic_type == P_PIC)
+        {
+            memset(ps_dec->ai2_pred_mv,0,sizeof(ps_dec->ai2_pred_mv));
+            pi2_mv[MV_X]    = pi2_mv[MV_Y] = 0;
+
+            ps_dec->u2_cbp     = 0;
+
+            pi2_mv           = (WORD16 *)&ps_dec->ai2_mv[FORW][FIRST];
+            ps_mc           = &ps_dec->as_mb_mc_params[FORW][FIRST];
+            ps_mc->s_ref      = ps_dec->as_ref_buf[ps_dec->e_mb_pred][ps_dec->u2_fld_parity];
+
+            impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, e_mb_type, 0,
+                      pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+
+
+            u4_dst_offset_x = (ps_dec->u2_mb_x << 4) + u4_frm_offset;
+            u4_dst_offset_y = (ps_dec->u2_mb_y << 4) * u4_dst_wd;
+
+            s_dst.pu1_y = ps_dec->s_cur_frm_buf.pu1_y + u4_dst_offset_x + u4_dst_offset_y;
+
+            u4_dst_offset_x = u4_dst_offset_x >> 1;
+            u4_dst_offset_y = u4_dst_offset_y >> 2;
+
+            s_dst.pu1_u = ps_dec->s_cur_frm_buf.pu1_u + u4_dst_offset_x + u4_dst_offset_y;
+            s_dst.pu1_v = ps_dec->s_cur_frm_buf.pu1_v + u4_dst_offset_x + u4_dst_offset_y;
+
+
+            ps_mc->s_ref.pu1_y += ps_mc->s_luma.u4_src_offset;
+            ps_mc->s_ref.pu1_u += ps_mc->s_chroma.u4_src_offset;
+            ps_mc->s_ref.pu1_v += ps_mc->s_chroma.u4_src_offset;
+
+            ps_dec->pf_copy_mb(&ps_mc->s_ref, &s_dst, ps_mc->s_luma.u4_src_wd, u4_dst_wd);
+        }
+
+        else
+        {
+            pi2_mv[MV_X]    = ps_dec->ai2_pred_mv[ps_dec->e_mb_pred][FIRST][MV_X];
+            pi2_mv[MV_Y]    = ps_dec->ai2_pred_mv[ps_dec->e_mb_pred][FIRST][MV_Y];
+
+            ps_dec->u2_cbp     = 0;
+
+            pi2_mv           = (WORD16 *)&ps_dec->ai2_mv[FORW][FIRST];
+            ps_mc           = &ps_dec->as_mb_mc_params[FORW][FIRST];
+            ps_mc->s_ref      = ps_dec->as_ref_buf[ps_dec->e_mb_pred][ps_dec->u2_fld_parity];
+
+            impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, e_mb_type, 0,
+                      pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+
+            u4_dst_offset_x = (ps_dec->u2_mb_x << 4) + u4_frm_offset;
+            u4_dst_offset_y = (ps_dec->u2_mb_y << 4) * u4_dst_wd;
+
+            ps_mc->s_luma.u4_dst_offset_res_buf = u4_dst_offset_x + u4_dst_offset_y;
+            ps_mc->s_luma.u4_dst_wd_res_buf = u4_dst_wd;
+
+            u4_dst_offset_x = u4_dst_offset_x >> 1;
+            u4_dst_offset_y = u4_dst_offset_y >> 2;
+
+            ps_mc->s_chroma.u4_dst_offset_res_buf = u4_dst_offset_x + u4_dst_offset_y;
+            ps_mc->s_chroma.u4_dst_wd_res_buf = u4_dst_wd >> 1;
+
+            impeg2d_motion_comp(ps_dec, ps_mc, &ps_dec->s_cur_frm_buf);
+        }
+
+
+        /********************************************************************/
+        /* Common MB processing tasks                                       */
+        /********************************************************************/
+        ps_dec->u2_mb_x++;
+        ps_dec->u2_num_mbs_left--;
+
+        if ((ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb) && ((ps_dec->s_bit_stream.u4_offset + START_CODE_PREFIX_LEN) < ps_dec->s_bit_stream.u4_max_offset))
+        {
+            ps_dec->u2_mb_x = 0;
+            ps_dec->u2_mb_y++;
+        }
+    }
+
+}
+
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_skip_b_mb
+*
+*  Description     : Performs processing needed for Skipped MB encountered in
+*                    B Pictures with previous MB bi-predicted.
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_skip_b_mb(dec_state_t *ps_dec, WORD32 u4_num_of_mbs)
+{
+
+
+    WORD16  *pi2_mv;
+
+    UWORD32 i;
+    e_mb_type_t e_mb_type;
+    mb_mc_params_t *ps_mc;
+
+    WORD32 i4_iter;
+    UWORD32 u4_dst_wd;
+    yuv_buf_t s_dst;
+    UWORD32  u4_dst_offset_x;
+    UWORD32  u4_dst_offset_y;
+    UWORD32 u4_frm_offset = 0;
+
+    u4_dst_wd = ps_dec->u2_frame_width;
+    s_dst = ps_dec->s_cur_frm_buf;
+
+    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
+    {
+        u4_dst_wd <<= 1;
+        if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
+        {
+            u4_frm_offset = ps_dec->u2_frame_width;
+        }
+    }
+
+    for (i4_iter = u4_num_of_mbs; i4_iter > 0; i4_iter--)
+    {
+        ps_dec->u2_prev_intra_mb = 0;
+
+        if(ps_dec->u2_picture_structure == FRAME_PICTURE)
+        {
+            e_mb_type = MC_FRM_FW_AND_BK_2MV;
+        }
+        else
+        {
+            e_mb_type = MC_FLD_FW_AND_BK_2MV;
+        }
+
+        /************************************************************************/
+        /* Setting of first motion vector for B MB                              */
+        /************************************************************************/
+        pi2_mv               = (WORD16 *)&(ps_dec->ai2_mv[FORW][FIRST]);
+        {
+            pi2_mv[MV_X]         = ps_dec->ai2_pred_mv[FORW][FIRST][MV_X];
+            pi2_mv[MV_Y]         = ps_dec->ai2_pred_mv[FORW][FIRST][MV_Y];
+        }
+        /************************************************************************/
+        /* Setting of second motion vector for B MB                             */
+        /************************************************************************/
+        pi2_mv               = (WORD16 *)&(ps_dec->ai2_mv[BACK][FIRST]);
+        {
+            pi2_mv[MV_X]         = ps_dec->ai2_pred_mv[BACK][FIRST][MV_X];
+            pi2_mv[MV_Y]         = ps_dec->ai2_pred_mv[BACK][FIRST][MV_Y];
+        }
+        ps_dec->u2_cbp  = 0;
+
+        for(i = 0; i < 2; i++)
+        {
+            pi2_mv          = (WORD16 *)&ps_dec->ai2_mv[i][FIRST];
+            ps_mc          = &ps_dec->as_mb_mc_params[i][FIRST];
+            ps_mc->s_ref     = ps_dec->as_ref_buf[i][ps_dec->u2_fld_parity];
+
+            impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, e_mb_type, 0, pi2_mv, ps_dec->u2_mb_x,
+                          ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+        }
+
+        impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[FORW][FIRST], &ps_dec->s_mc_fw_buf);
+        impeg2d_motion_comp(ps_dec, &ps_dec->as_mb_mc_params[BACK][FIRST], &ps_dec->s_mc_bk_buf);
+
+        u4_dst_offset_x = (ps_dec->u2_mb_x << 4) + u4_frm_offset;
+        u4_dst_offset_y = (ps_dec->u2_mb_y << 4) * u4_dst_wd;
+
+        s_dst.pu1_y = ps_dec->s_cur_frm_buf.pu1_y + u4_dst_offset_x + u4_dst_offset_y;
+
+        u4_dst_offset_x = u4_dst_offset_x >> 1;
+        u4_dst_offset_y = u4_dst_offset_y >> 2;
+
+        s_dst.pu1_u = ps_dec->s_cur_frm_buf.pu1_u + u4_dst_offset_x + u4_dst_offset_y;
+        s_dst.pu1_v = ps_dec->s_cur_frm_buf.pu1_v + u4_dst_offset_x + u4_dst_offset_y;
+
+        ps_dec->pf_interpolate(&ps_dec->s_mc_fw_buf,&ps_dec->s_mc_bk_buf,&s_dst, u4_dst_wd);
+//        dec->pf_copy_mb(&dec->mc_buf, &dst, MB_SIZE, dst_wd);
+
+        /********************************************************************/
+        /* Common MB processing tasks                                       */
+        /********************************************************************/
+        ps_dec->u2_mb_x++;
+        ps_dec->u2_num_mbs_left--;
+
+        if ((ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb) && ((ps_dec->s_bit_stream.u4_offset + START_CODE_PREFIX_LEN) < ps_dec->s_bit_stream.u4_max_offset))
+        {
+            ps_dec->u2_mb_x = 0;
+            ps_dec->u2_mb_y++;
+        }
+    }
+}
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_skip_mbs
+*
+*  Description     : Performs processing needed for Skipped MB encountered in
+*                    B Pictures with previous MB bi-predicted.
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_skip_mbs(dec_state_t *ps_dec, UWORD16 u2_num_skip_mbs)
+{
+    PROFILE_DISABLE_SKIP_MB();
+
+    if(ps_dec->e_mb_pred == BIDIRECT)
+    {
+        impeg2d_dec_skip_b_mb(ps_dec, u2_num_skip_mbs);
+    }
+    else
+    {
+        impeg2d_dec_skip_p_mb(ps_dec, u2_num_skip_mbs);
+    }
+
+    ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
+    ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
+    ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
+}
+
+
+
+
+/*****************************************************************************
+*  Function Name   : impeg2d_dec_0mv_coded_mb
+*
+*  Description     : Decodes the MB with 0 MV but coded. This can occur in P
+*                    pictures only
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*****************************************************************************/
+void impeg2d_dec_0mv_coded_mb(dec_state_t *ps_dec)
+{
+
+
+    WORD16   *pi2_mv;
+    e_mb_type_t e_mb_type;
+    mb_mc_params_t *ps_mc;
+
+    if(ps_dec->u2_picture_structure == FRAME_PICTURE)
+    {
+        e_mb_type = MC_FRM_FW_AND_BK_2MV;
+    }
+    else
+    {
+        e_mb_type = MC_FLD_FW_AND_BK_2MV;
+    }
+
+
+
+
+    /* Reset the motion vector predictors */
+    memset(ps_dec->ai2_pred_mv,0,sizeof(ps_dec->ai2_pred_mv));
+
+    pi2_mv           = (WORD16 *)&ps_dec->ai2_mv[FORW][FIRST];
+    ps_mc           = &ps_dec->as_mb_mc_params[FORW][FIRST];
+    ps_mc->s_ref      = ps_dec->as_ref_buf[FORW][ps_dec->u2_fld_parity];
+
+    pi2_mv[MV_X] = 0;
+    pi2_mv[MV_Y] = 0;
+
+    impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, e_mb_type, 0,
+              pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_halfx_halfy()                                 */
+/*                                                                           */
+/*  Description   : Gets the buffer from (0.5,0.5) to (8.5,8.5)              */
+/*                  and the above block of size 8 x 8 will be placed as a    */
+/*                  block from the current position of out_buf               */
+/*                                                                           */
+/*  Inputs        : ref - Reference frame from which the block will be       */
+/*                        block will be extracted.                           */
+/*                  ref_wid - WIdth of reference frame                       */
+/*                  out_wid - WIdth of the output frame                      */
+/*                  blk_width  - width of the block                          */
+/*                  blk_width  - height of the block                         */
+/*                                                                           */
+/*  Globals       : None                                                     */
+/*                                                                           */
+/*  Processing    : Point to the (0,0),(1,0),(0,1),(1,1) position in         */
+/*                  the ref frame.Interpolate these four values to get the   */
+/*                  value at(0.5,0.5).Repeat this to get an 8 x 8 block      */
+/*                  using 9 x 9 block from reference frame                   */
+/*                                                                           */
+/*  Outputs       : out -  Output containing the extracted block             */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         05 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_mc_halfx_halfy(void *pv_dec,
+                           UWORD8 *pu1_ref,
+                           UWORD32 u4_ref_wid,
+                           UWORD8 *pu1_out,
+                           UWORD32 u4_out_wid,
+                           UWORD32 u4_blk_width,
+                           UWORD32 u4_blk_height)
+{
+   UWORD8 *pu1_out_ptr,*pu1_ref_ptr;
+   dec_state_t *ps_dec = (dec_state_t *)pv_dec;
+
+        pu1_out_ptr = pu1_out;
+        pu1_ref_ptr = pu1_ref;
+
+    if((u4_blk_width == MB_SIZE) && (u4_blk_height == MB_SIZE))
+    {
+
+        /*luma 16 x 16*/
+
+        /*block 0*/
+        ps_dec->pf_halfx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block1*/
+        pu1_out_ptr = (pu1_out + BLK_SIZE);
+        pu1_ref_ptr = (pu1_ref + BLK_SIZE);
+        ps_dec->pf_halfx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 2*/
+        pu1_out_ptr = pu1_out + BLK_SIZE * u4_out_wid;
+        pu1_ref_ptr = pu1_ref + BLK_SIZE * u4_ref_wid;
+        ps_dec->pf_halfx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 3*/
+        pu1_out_ptr = pu1_out + BLK_SIZE * u4_out_wid + BLK_SIZE;
+        pu1_ref_ptr = pu1_ref + BLK_SIZE * u4_ref_wid + BLK_SIZE;
+        ps_dec->pf_halfx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+
+
+
+    }
+    else if ((u4_blk_width == BLK_SIZE) && (u4_blk_height == BLK_SIZE))
+    {
+        /*chroma 8 x 8*/
+        ps_dec->pf_halfx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+    }
+    else if ((u4_blk_width == MB_SIZE) && (u4_blk_height == BLK_SIZE))
+    {
+        /*block 0*/
+        ps_dec->pf_halfx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 1*/
+        pu1_out_ptr = (pu1_out + BLK_SIZE);
+        pu1_ref_ptr = (pu1_ref + BLK_SIZE);
+        ps_dec->pf_halfx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+    }
+
+    else
+    {
+        UWORD8 *ref_p0,*ref_p1,*ref_p2,*ref_p3;
+        UWORD32 i,j;
+        /* P0-P3 are the pixels in the reference frame and Q is the value being */
+        /* estimated                                                            */
+        /*
+           P0 P1
+             Q
+           P2 P3
+        */
+
+        ref_p0 = pu1_ref;
+        ref_p1 = pu1_ref + 1;
+        ref_p2 = pu1_ref + u4_ref_wid;
+        ref_p3 = pu1_ref + u4_ref_wid + 1;
+
+        for(i = 0; i < u4_blk_height; i++)
+        {
+            for(j = 0; j < u4_blk_width; j++)
+            {
+                *pu1_out++ =   (( (*ref_p0++ )
+                            + (*ref_p1++ )
+                            + (*ref_p2++ )
+                            + (*ref_p3++ ) + 2 ) >> 2);
+            }
+            ref_p0 += u4_ref_wid - u4_blk_width;
+            ref_p1 += u4_ref_wid - u4_blk_width;
+            ref_p2 += u4_ref_wid - u4_blk_width;
+            ref_p3 += u4_ref_wid - u4_blk_width;
+
+            pu1_out    += u4_out_wid - u4_blk_width;
+        }
+    }
+    return;
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_halfx_fully()                                 */
+/*                                                                           */
+/*  Description   : Gets the buffer from (0.5,0) to (8.5,8)                  */
+/*                  and the above block of size 8 x 8 will be placed as a    */
+/*                  block from the current position of out_buf               */
+/*                                                                           */
+/*  Inputs        : ref - Reference frame from which the block will be       */
+/*                        block will be extracted.                           */
+/*                  ref_wid - WIdth of reference frame                       */
+/*                  out_wid - WIdth of the output frame                      */
+/*                  blk_width  - width of the block                          */
+/*                  blk_width  - height of the block                         */
+/*                                                                           */
+/*  Globals       : None                                                     */
+/*                                                                           */
+/*  Processing    : Point to the (0,0) and (1,0) position in the ref frame   */
+/*                  Interpolate these two values to get the value at(0.5,0)  */
+/*                  Repeat this to get an 8 x 8 block using 9 x 8 block from */
+/*                  reference frame                                          */
+/*                                                                           */
+/*  Outputs       : out -  Output containing the extracted block             */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         05 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+
+void impeg2d_mc_halfx_fully(void *pv_dec,
+                            UWORD8 *pu1_ref,
+                            UWORD32 u4_ref_wid,
+                            UWORD8 *pu1_out,
+                            UWORD32 u4_out_wid,
+                            UWORD32 u4_blk_width,
+                            UWORD32 u4_blk_height)
+{
+    UWORD8 *pu1_out_ptr,*pu1_ref_ptr;
+    dec_state_t *ps_dec = (dec_state_t *)pv_dec;
+
+        pu1_out_ptr = pu1_out;
+        pu1_ref_ptr = pu1_ref;
+
+    if((u4_blk_width == MB_SIZE) && (u4_blk_height == MB_SIZE))
+    {
+
+        /*luma 16 x 16*/
+
+        /*block 0*/
+        ps_dec->pf_halfx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block1*/
+        pu1_out_ptr = (pu1_out + BLK_SIZE);
+        pu1_ref_ptr = (pu1_ref + BLK_SIZE);
+        ps_dec->pf_halfx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 2*/
+        pu1_out_ptr = pu1_out + BLK_SIZE * u4_out_wid;
+        pu1_ref_ptr = pu1_ref + BLK_SIZE * u4_ref_wid;
+        ps_dec->pf_halfx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 3*/
+        pu1_out_ptr = pu1_out + BLK_SIZE * u4_out_wid + BLK_SIZE;
+        pu1_ref_ptr = pu1_ref + BLK_SIZE * u4_ref_wid + BLK_SIZE;
+        ps_dec->pf_halfx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+
+
+
+    }
+    else if ((u4_blk_width == BLK_SIZE) && (u4_blk_height == BLK_SIZE))
+    {
+        /*chroma 8 x 8*/
+        ps_dec->pf_halfx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+    }
+    else if ((u4_blk_width == MB_SIZE) && (u4_blk_height == BLK_SIZE))
+    {
+        /*block 0*/
+        ps_dec->pf_halfx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 1*/
+        pu1_out_ptr = (pu1_out + BLK_SIZE);
+        pu1_ref_ptr = (pu1_ref + BLK_SIZE);
+        ps_dec->pf_halfx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+    }
+
+    else
+    {
+        UWORD8 *ref_p0,*ref_p1;
+        UWORD32 i,j;
+
+        /* P0-P3 are the pixels in the reference frame and Q is the value being */
+        /* estimated                                                            */
+        /*
+           P0 Q P1
+        */
+
+        ref_p0 = pu1_ref;
+        ref_p1 = pu1_ref + 1;
+
+        for(i = 0; i < u4_blk_height; i++)
+        {
+            for(j = 0; j < u4_blk_width; j++)
+            {
+                *pu1_out++ =   ((( *ref_p0++ )
+                            + (*ref_p1++) + 1 ) >> 1);
+            }
+            ref_p0 += u4_ref_wid - u4_blk_width;
+            ref_p1 += u4_ref_wid - u4_blk_width;
+
+            pu1_out    += u4_out_wid - u4_blk_width;
+        }
+    }
+    return;
+}
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_fullx_halfy()                                 */
+/*                                                                           */
+/*  Description   : Gets the buffer from (0,0.5) to (8,8.5)                  */
+/*                  and the above block of size 8 x 8 will be placed as a    */
+/*                  block from the current position of out_buf               */
+/*                                                                           */
+/*  Inputs        : ref - Reference frame from which the block will be       */
+/*                        block will be extracted.                           */
+/*                  ref_wid - WIdth of reference frame                       */
+/*                  out_wid - WIdth of the output frame                      */
+/*                  blk_width  - width of the block                          */
+/*                  blk_width  - height of the block                         */
+/*                                                                           */
+/*  Globals       : None                                                     */
+/*                                                                           */
+/*  Processing    : Point to the (0,0) and (0,1)   position in the ref frame */
+/*                  Interpolate these two values to get the value at(0,0.5)  */
+/*                  Repeat this to get an 8 x 8 block using 8 x 9 block from */
+/*                  reference frame                                          */
+/*                                                                           */
+/*  Outputs       : out -  Output containing the extracted block             */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         05 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+void impeg2d_mc_fullx_halfy(void *pv_dec,
+                            UWORD8 *pu1_ref,
+                            UWORD32 u4_ref_wid,
+                            UWORD8 *pu1_out,
+                            UWORD32 u4_out_wid,
+                            UWORD32 u4_blk_width,
+                            UWORD32 u4_blk_height)
+{
+
+    UWORD8 *pu1_out_ptr,*pu1_ref_ptr;
+    dec_state_t *ps_dec = (dec_state_t *)pv_dec;
+        pu1_out_ptr = pu1_out;
+        pu1_ref_ptr = pu1_ref;
+
+    if((u4_blk_width == MB_SIZE) && (u4_blk_height == MB_SIZE))
+    {
+
+        /*luma 16 x 16*/
+
+        /*block 0*/
+        ps_dec->pf_fullx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block1*/
+        pu1_out_ptr = (pu1_out + BLK_SIZE);
+        pu1_ref_ptr = (pu1_ref + BLK_SIZE);
+        ps_dec->pf_fullx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 2*/
+        pu1_out_ptr = pu1_out + BLK_SIZE * u4_out_wid;
+        pu1_ref_ptr = pu1_ref + BLK_SIZE * u4_ref_wid;
+        ps_dec->pf_fullx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 3*/
+        pu1_out_ptr = pu1_out + BLK_SIZE * u4_out_wid + BLK_SIZE;
+        pu1_ref_ptr = pu1_ref + BLK_SIZE * u4_ref_wid + BLK_SIZE;
+        ps_dec->pf_fullx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+
+
+
+    }
+    else if ((u4_blk_width == BLK_SIZE) && (u4_blk_height == BLK_SIZE))
+    {
+        /*chroma 8 x 8*/
+        ps_dec->pf_fullx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+    }
+    else if ((u4_blk_width == MB_SIZE) && (u4_blk_height == BLK_SIZE))
+    {
+        /*block 0*/
+        ps_dec->pf_fullx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 1*/
+        pu1_out_ptr = (pu1_out + BLK_SIZE);
+        pu1_ref_ptr = (pu1_ref + BLK_SIZE);
+        ps_dec->pf_fullx_halfy_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+    }
+
+    else if ((u4_blk_width == BLK_SIZE) && (u4_blk_height == (BLK_SIZE / 2)))
+    {
+        UWORD8 *ref_p0,*ref_p1;
+        UWORD32 i,j;
+        /* P0-P3 are the pixels in the reference frame and Q is the value being */
+        /* estimated                                                            */
+        /*
+           P0
+            x
+           P1
+        */
+        ref_p0 = pu1_ref;
+        ref_p1 = pu1_ref + u4_ref_wid;
+
+        for(i = 0; i < u4_blk_height; i++)
+        {
+            for(j = 0; j < u4_blk_width; j++)
+            {
+                *pu1_out++ =   ((( *ref_p0++)
+                            + (*ref_p1++) + 1 ) >> 1);
+            }
+            ref_p0 += u4_ref_wid - u4_blk_width;
+            ref_p1 += u4_ref_wid - u4_blk_width;
+
+            pu1_out    += u4_out_wid - u4_blk_width;
+        }
+    }
+    return;
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_mc_fullx_fully()                                 */
+/*                                                                           */
+/*  Description   : Gets the buffer from (x,y) to (x+8,y+8)                  */
+/*                  and the above block of size 8 x 8 will be placed as a    */
+/*                  block from the current position of out_buf               */
+/*                                                                           */
+/*  Inputs        : ref - Reference frame from which the block will be       */
+/*                        block will be extracted.                           */
+/*                  ref_wid - WIdth of reference frame                       */
+/*                  out_wid - WIdth of the output frame                      */
+/*                  blk_width  - width of the block                          */
+/*                  blk_width  - height of the block                         */
+/*                                                                           */
+/*  Globals       : None                                                     */
+/*                                                                           */
+/*  Processing    : Point to the (0,0) position in the ref frame             */
+/*                  Get an 8 x 8 block from reference frame                  */
+/*                                                                           */
+/*  Outputs       : out -  Output containing the extracted block             */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         05 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+
+void impeg2d_mc_fullx_fully(void *pv_dec,
+                            UWORD8 *pu1_ref,
+                            UWORD32 u4_ref_wid,
+                            UWORD8 *pu1_out,
+                            UWORD32 u4_out_wid,
+                            UWORD32 u4_blk_width,
+                            UWORD32 u4_blk_height)
+{
+
+    UWORD8 *pu1_out_ptr,*pu1_ref_ptr;
+    dec_state_t *ps_dec = (dec_state_t *)pv_dec;
+
+        pu1_out_ptr = pu1_out;
+        pu1_ref_ptr = pu1_ref;
+
+    if((u4_blk_width == MB_SIZE) && (u4_blk_height == MB_SIZE))
+    {
+
+        /*luma 16 x 16*/
+
+        /*block 0*/
+        ps_dec->pf_fullx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block1*/
+        pu1_out_ptr = (pu1_out + BLK_SIZE);
+        pu1_ref_ptr = (pu1_ref + BLK_SIZE);
+        ps_dec->pf_fullx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 2*/
+        pu1_out_ptr = pu1_out + BLK_SIZE * u4_out_wid;
+        pu1_ref_ptr = pu1_ref + BLK_SIZE * u4_ref_wid;
+        ps_dec->pf_fullx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 3*/
+        pu1_out_ptr = pu1_out + BLK_SIZE * u4_out_wid + BLK_SIZE;
+        pu1_ref_ptr = pu1_ref + BLK_SIZE * u4_ref_wid + BLK_SIZE;
+        ps_dec->pf_fullx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+
+
+
+    }
+    else if ((u4_blk_width == BLK_SIZE) && (u4_blk_height == BLK_SIZE))
+    {
+        /*chroma 8 x 8*/
+        ps_dec->pf_fullx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+    }
+    else if ((u4_blk_width == MB_SIZE) && (u4_blk_height == BLK_SIZE))
+    {
+        /*block 0*/
+        ps_dec->pf_fullx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+        /*block 1*/
+        pu1_out_ptr = (pu1_out + BLK_SIZE);
+        pu1_ref_ptr = (pu1_ref + BLK_SIZE);
+        ps_dec->pf_fullx_fully_8x8(pu1_out_ptr,pu1_ref_ptr,u4_ref_wid,u4_out_wid);
+
+    }
+    else
+    {
+        UWORD32 i;
+
+        for(i = 0; i < u4_blk_height; i++)
+        {
+            memcpy(pu1_out, pu1_ref, u4_blk_width);
+            pu1_ref += u4_ref_wid;
+            pu1_out += u4_out_wid;
+        }
+    }
+    return;
+}
+
+/*******************************************************************************
+*  Function Name   : impeg2d_set_mc_params
+*
+*  Description     : Sets the parameters for Motion Compensation
+*
+*  Arguments       :
+*  luma            : Parameters for luma blocks
+*  chroma          : Parameters for chroma blocks
+*  type            : Motion compensation type
+*  mv_num          : Number of motion vectors
+*  mv              : Motion Vectors
+*  mb_x            : X co-ordinate of MB
+*  mb_y            : Y co-ordinate of MB
+*  frm_wd          : Width of the frame
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_set_mc_params(comp_mc_params_t *ps_luma,
+                           comp_mc_params_t *ps_chroma,
+                           e_mb_type_t e_type,
+                           UWORD16 u2_mv_num,
+                           WORD16 ai2_mv[],
+                           UWORD16 u2_mb_x,
+                           UWORD16 u2_mb_y,
+                           UWORD16 u2_frm_wd,
+                           UWORD16 u2_frm_ht,
+                           UWORD16 u2_picture_width)
+{
+    WORD16 i2_mvy_round;
+    WORD16 i2_mvx_round;
+    const mc_type_consts_t *ps_mc_params;
+    WORD16 i2_mvx_fullp_round;
+    WORD16 i2_mvy_fullp_round;
+    UWORD32 u4_frm_chroma_wd;
+    WORD16 i2_pix_x, i2_pix_y;
+
+    ps_mc_params = &gas_impeg2d_mc_params_luma[e_type][u2_mv_num];
+    /****************************************************************************/
+    /* get luma mc params                                                       */
+    /****************************************************************************/
+    i2_pix_x = MB_SIZE * u2_mb_x + (ai2_mv[MV_X]>>1);
+    i2_pix_y = (MB_SIZE * u2_mb_y  +
+        (ai2_mv[MV_Y]>>1) * ps_mc_params->mvy_cf + u2_mv_num * ps_mc_params->mv_num_cf) * ps_mc_params->frm_wd_cf;
+
+    // clip pix_x and pix_y so as it falls inside the frame boundary
+    CLIP(i2_pix_x, (u2_frm_wd-16), 0);
+    CLIP(i2_pix_y, (u2_frm_ht-16), 0);
+
+    ps_luma->u4_src_offset = i2_pix_x +  i2_pix_y * u2_frm_wd;
+
+
+    /* keep offset  in full pel */
+    ps_luma->u4_rows          = ps_mc_params->rows;
+    ps_luma->u4_cols          = MB_SIZE;
+    ps_luma->u4_dst_wd_res_buf        = ps_mc_params->dst_wd;
+    ps_luma->u4_src_wd        = u2_frm_wd * ps_mc_params->src_wd_cf;
+    ps_luma->u4_dst_offset_res_buf    = ps_mc_params->dst_offset_scale * MB_SIZE;
+    ps_luma->u4_dst_offset_cur_frm    = ps_mc_params->dst_offset_scale * u2_picture_width;
+    ps_luma->u4_mode          = ((ai2_mv[MV_X] & 1) << 1) | (ai2_mv[MV_Y] & 1);
+
+    /****************************************************************************/
+    /* get chroma mc params                                                     */
+    /****************************************************************************/
+    ps_mc_params   = &gas_impeg2d_mc_params_chroma[e_type][u2_mv_num];
+    i2_mvx_round   = ((ai2_mv[MV_X] + IS_NEG(ai2_mv[MV_X]))>>1);
+    i2_mvy_round   = ((ai2_mv[MV_Y] + IS_NEG(ai2_mv[MV_Y]))>>1);
+
+    i2_mvx_fullp_round = (i2_mvx_round>>1);
+    i2_mvy_fullp_round = (i2_mvy_round>>1)*ps_mc_params->mvy_cf;
+
+    u4_frm_chroma_wd = (u2_frm_wd>>1);
+
+    i2_pix_x = (MB_SIZE/2) * u2_mb_x + i2_mvx_fullp_round;
+    i2_pix_y = ((MB_SIZE/2) * u2_mb_y + i2_mvy_fullp_round + u2_mv_num *
+                           ps_mc_params->mv_num_cf)*ps_mc_params->frm_wd_cf;
+
+    CLIP(i2_pix_x, ((u2_frm_wd / 2)-8), 0);
+    CLIP(i2_pix_y, ((u2_frm_ht / 2)-8), 0);
+    ps_chroma->u4_src_offset = i2_pix_x + i2_pix_y * u4_frm_chroma_wd;
+
+
+    /* keep offset  in full pel */
+    ps_chroma->u4_rows = ps_mc_params->rows;
+    ps_chroma->u4_cols        = (MB_SIZE >> 1);
+    ps_chroma->u4_dst_wd_res_buf = ps_mc_params->dst_wd;
+    ps_chroma->u4_src_wd = (u2_frm_wd>>1) * ps_mc_params->src_wd_cf;
+    ps_chroma->u4_dst_offset_res_buf = ps_mc_params->dst_offset_scale * MB_CHROMA_SIZE;
+    ps_chroma->u4_dst_offset_cur_frm = ps_mc_params->dst_offset_scale * (u2_picture_width >> 1);
+    ps_chroma->u4_mode = ((i2_mvx_round & 1) << 1) | (i2_mvy_round & 1);
+
+
+
+    ps_luma->u4_dst_wd_cur_frm = u2_picture_width;
+    ps_chroma->u4_dst_wd_cur_frm = u2_picture_width >> 1;
+
+    if(ps_luma->u4_dst_wd_res_buf == MB_SIZE * 2)
+    {
+        ps_luma->u4_dst_wd_cur_frm = u2_frm_wd << 1;
+        ps_chroma->u4_dst_wd_cur_frm = u2_frm_wd;
+    }
+}
+
+
diff --git a/decoder/impeg2d_mc.h b/decoder/impeg2d_mc.h
new file mode 100644
index 0000000..14f1ef9
--- /dev/null
+++ b/decoder/impeg2d_mc.h
@@ -0,0 +1,78 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_mc.h
+*
+* @brief
+*  Contains MC function declarations for MPEG2 codec
+*
+* @author
+*  Harish
+*
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+#ifndef __IMPEG2D_MC_H__
+#define __IMPEG2D_MC_H__
+
+void impeg2d_dec_2mv_interp_mb(dec_state_t *dec);
+void impeg2d_dec_4mv_mb(dec_state_t *dec);
+
+
+void impeg2d_dec_1mv_mb(dec_state_t *dec);
+void impeg2d_dec_2mv_fw_or_bk_mb(dec_state_t *dec);
+void impeg2d_dec_fld_dual_prime(dec_state_t *dec);
+void impeg2d_dec_frm_dual_prime(dec_state_t *dec);
+
+void impeg2d_mc_1mv(dec_state_t *dec);
+void impeg2d_mc_fw_or_bk_mb(dec_state_t *dec);
+void impeg2d_mc_fld_dual_prime(dec_state_t *dec);
+void impeg2d_mc_frm_dual_prime(dec_state_t *dec);
+void impeg2d_mc_4mv(dec_state_t *dec);
+void impeg2d_mc_2mv(dec_state_t *dec);
+
+void impeg2d_dec_skip_mbs(dec_state_t *dec, UWORD16 num_skip_mbs);
+void impeg2d_dec_0mv_coded_mb(dec_state_t *dec);
+void impeg2d_dec_intra_mb(dec_state_t *dec);
+
+void impeg2d_set_mc_params(comp_mc_params_t *luma,
+                   comp_mc_params_t *chroma,
+                   e_mb_type_t   type,
+                   UWORD16 mv_num,
+                   WORD16 mv[],
+                   UWORD16 mb_x,
+                   UWORD16 mb_y,
+                   UWORD16 frm_wd,
+                   UWORD16 frm_ht,
+                   UWORD16 picture_width);
+
+void impeg2d_motion_comp(dec_state_t *dec, mb_mc_params_t *params,yuv_buf_t *buf);
+
+pf_mc_t impeg2d_mc_halfx_halfy;
+pf_mc_t impeg2d_mc_halfx_fully;
+pf_mc_t impeg2d_mc_fullx_halfy;
+pf_mc_t impeg2d_mc_fullx_fully;
+
+
+#endif /* __IMPEG2D_MC_H__*/
diff --git a/decoder/impeg2d_mv_dec.c b/decoder/impeg2d_mv_dec.c
new file mode 100644
index 0000000..1a30146
--- /dev/null
+++ b/decoder/impeg2d_mv_dec.c
@@ -0,0 +1,499 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#include <stdio.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_globals.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_mv_dec.h"
+#include "impeg2d_mc.h"
+
+/*******************************************************************************
+* Function name : impeg2d_dec_1mv
+*
+* Description   : Decodes a motion vector and updates the predictors
+*
+* Arguments     :
+* stream        : Bitstream
+* predMv        : Prediction for the motion vectors
+* mv            : Motion vectors
+* fCode         : fcode to the used for the decoding
+* shift         : Shift value to be used. This will be equal to
+*                 (mv_format == "field") && (picture_structure == "Frame picture")
+* i             : 0 - MV_X and 1 - MV_Y
+*
+* Value Returned: None
+*******************************************************************************/
+INLINE void impeg2d_dec_1mv(stream_t *ps_stream, WORD16 ai2_pred_mv[], WORD16 ai2_mv[],UWORD16 au2_fCode[],
+           UWORD16 u2_mv_y_shift, WORD16 ai2_dmv[])
+{
+    WORD16  i2_f;
+    WORD16  i2_r_size;
+    WORD16  i2_high,i2_low,i2_range;
+    UWORD32  u4_mv_code;
+    WORD16  i2_delta;
+    UWORD16 u2_first_bit;
+    WORD32 i;
+    WORD32 ai2_shifts[2];
+    UWORD32 u4_buf;
+    UWORD32 u4_buf_nxt;
+    UWORD32 u4_offset;
+    UWORD32 *pu4_buf_aligned;
+
+    ai2_shifts[0] = 0;
+    ai2_shifts[1] = u2_mv_y_shift;
+
+
+    GET_TEMP_STREAM_DATA(u4_buf,u4_buf_nxt,u4_offset,pu4_buf_aligned,ps_stream)
+    for(i = 0; i < 2; i++)
+    {
+        WORD32 i4_shift = ai2_shifts[i];
+        /* Decode the motion_code */
+        IBITS_NXT(u4_buf, u4_buf_nxt, u4_offset, u4_mv_code, MV_CODE_LEN)
+        u2_first_bit    = (u4_mv_code >> (MV_CODE_LEN - 1)) & 0x01;
+        if(u2_first_bit == 1) /* mvCode == 0 */
+        {
+            i2_delta = 0;
+            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,1,pu4_buf_aligned)
+
+            ai2_mv[i] = (ai2_pred_mv[i] >> i4_shift);
+
+            ai2_pred_mv[i] = (ai2_mv[i] << i4_shift);
+
+        }
+        else
+        {
+            UWORD16 u2_index;
+            UWORD16 u2_value;
+            UWORD16 u2_mv_len;
+            UWORD16 u2_abs_mvcode_minus1;
+            UWORD16 u2_sign_bit;
+
+            i2_r_size   = au2_fCode[i] - 1;
+            i2_f       = 1 << i2_r_size;
+            i2_high    = (16 * i2_f) - 1;
+            i2_low     = ((-16) * i2_f);
+            i2_range   = (32 * i2_f);
+
+            u2_index               = (u4_mv_code >> 1) & 0x1FF;
+            u2_value               = gau2_impeg2d_mv_code[u2_index];
+            u2_mv_len               = (u2_value & 0x0F);
+            u2_abs_mvcode_minus1   = (u2_value >> 8) & 0x0FF;
+            u4_mv_code            >>= (MV_CODE_LEN - u2_mv_len - 1);
+            u2_sign_bit             = u4_mv_code & 0x1;
+
+            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,(u2_mv_len + 1),pu4_buf_aligned)
+            i2_delta = u2_abs_mvcode_minus1 * i2_f + 1;
+            if(i2_r_size)
+            {
+                UWORD32 val;
+                IBITS_GET(u4_buf, u4_buf_nxt, u4_offset, val, pu4_buf_aligned, i2_r_size)
+                i2_delta += val;
+            }
+
+            if(u2_sign_bit)
+                i2_delta = -i2_delta;
+
+            ai2_mv[i] = (ai2_pred_mv[i] >> i4_shift) + i2_delta;
+
+            if(ai2_mv[i] < i2_low)
+            {
+                ai2_mv[i] += i2_range;
+            }
+
+            if(ai2_mv[i] > i2_high)
+            {
+                ai2_mv[i] -= i2_range;
+            }
+            ai2_pred_mv[i] = (ai2_mv[i] << i4_shift);
+
+        }
+        if(ai2_dmv)
+        {
+            UWORD32 u4_val;
+            ai2_dmv[i] = 0;
+            IBITS_GET(u4_buf, u4_buf_nxt, u4_offset, u4_val, pu4_buf_aligned, 1)
+            if(u4_val)
+            {
+                IBITS_GET(u4_buf, u4_buf_nxt, u4_offset, u4_val, pu4_buf_aligned, 1)
+                ai2_dmv[i] = gai2_impeg2d_dec_mv[u4_val];
+            }
+        }
+    }
+    PUT_TEMP_STREAM_DATA(u4_buf, u4_buf_nxt, u4_offset, pu4_buf_aligned, ps_stream)
+
+}
+/*******************************************************************************
+* Function name : impeg2d_dec_mv
+*
+* Description   : Decodes a motion vector and updates the predictors
+*
+* Arguments     :
+* stream        : Bitstream
+* predMv        : Prediction for the motion vectors
+* mv            : Motion vectors
+* fCode         : fcode to the used for the decoding
+* shift         : Shift value to be used. This will be equal to
+*                 (mv_format == "field") && (picture_structure == "Frame picture")
+*
+* Value Returned: None
+*******************************************************************************/
+e_field_t impeg2d_dec_mv(stream_t *ps_stream, WORD16 ai2_pred_mv[], WORD16 ai2_mv[],UWORD16 au2_f_code[],
+           UWORD16 u2_shift, UWORD16 u2_fld_sel)
+{
+    e_field_t e_fld;
+    if(u2_fld_sel)
+    {
+        e_fld = (e_field_t)impeg2d_bit_stream_get_bit(ps_stream);
+    }
+    else
+    {
+        e_fld = TOP;
+    }
+
+    impeg2d_dec_1mv(ps_stream,ai2_pred_mv,ai2_mv,au2_f_code,u2_shift,NULL);
+
+    return(e_fld);
+}
+
+/*****************************************************************************
+*  Function Name   : impeg2d_dec_1mv_mb
+*
+*  Description     : Decodes mc params for 1 MV  MB
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*****************************************************************************/
+void impeg2d_dec_1mv_mb(dec_state_t *ps_dec)
+{
+    stream_t         *ps_stream;
+    WORD16          *pi2_mv;
+    e_field_t         e_fld;
+    mb_mc_params_t  *ps_mc;
+    e_pred_direction_t   e_ref_pic;
+
+
+    ps_stream  = &ps_dec->s_bit_stream;
+    e_ref_pic = ps_dec->e_mb_pred;
+    /************************************************************************/
+    /* Decode the motion vector                                             */
+    /************************************************************************/
+    pi2_mv        = (WORD16 *)&ps_dec->ai2_mv[FORW][FIRST];
+    e_fld = impeg2d_dec_mv(ps_stream,ps_dec->ai2_pred_mv[e_ref_pic][FIRST],pi2_mv,
+                ps_dec->au2_f_code[e_ref_pic],0, ps_dec->u2_fld_pic);
+
+    ps_dec->ai2_pred_mv[e_ref_pic][SECOND][MV_X] = ps_dec->ai2_pred_mv[e_ref_pic][FIRST][MV_X];
+    ps_dec->ai2_pred_mv[e_ref_pic][SECOND][MV_Y] = ps_dec->ai2_pred_mv[e_ref_pic][FIRST][MV_Y];
+    /************************************************************************/
+    /* Set the motion vector params                                         */
+    /************************************************************************/
+    ps_mc = &ps_dec->as_mb_mc_params[e_ref_pic][FIRST];
+    ps_mc->s_ref = ps_dec->as_ref_buf[e_ref_pic][e_fld];
+    impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, ps_dec->s_mb_type, 0,
+                  pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+
+}
+
+/*****************************************************************************
+*  Function Name   : impeg2d_dec_2mv_fw_or_bk_mb
+*
+*  Description     : Decodes first part of params for 2 MV Interpolated MB
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*****************************************************************************/
+void impeg2d_dec_2mv_fw_or_bk_mb(dec_state_t *ps_dec)
+{
+    stream_t         *ps_stream;
+    WORD16          *pi2_mv;
+    e_field_t         e_fld;
+    mb_mc_params_t  *ps_mc;
+    e_pred_direction_t   e_ref_pic;
+    UWORD16 i;
+
+    ps_stream  = &ps_dec->s_bit_stream;
+    e_ref_pic = ps_dec->e_mb_pred;
+    for(i = 0; i < 2; i++)
+    {
+        /********************************************************************/
+        /* Decode the first motion vector                                   */
+        /********************************************************************/
+        pi2_mv        = (WORD16 *)&ps_dec->ai2_mv[FORW][i];
+        e_fld = impeg2d_dec_mv(ps_stream,ps_dec->ai2_pred_mv[e_ref_pic][i],pi2_mv,
+                    ps_dec->au2_f_code[e_ref_pic],ps_dec->u2_frm_pic, 1);
+
+        /********************************************************************/
+        /* Set the motion vector params                                     */
+        /********************************************************************/
+        ps_mc = &ps_dec->as_mb_mc_params[FORW][i];
+        ps_mc->s_ref = ps_dec->as_ref_buf[e_ref_pic][e_fld];
+        impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, ps_dec->s_mb_type, i,
+                      pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+    }
+}
+
+/*****************************************************************************
+*  Function Name   : impeg2d_dec_frm_dual_prime
+*
+*  Description     : Decodes first part of params for 2 MV Interpolated MB
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*****************************************************************************/
+void impeg2d_dec_frm_dual_prime(dec_state_t *ps_dec)
+{
+    stream_t         *ps_stream;
+    WORD16          *pi2_mv;
+    mb_mc_params_t  *ps_mc;
+
+    WORD16      ai2_dmv[2];
+    WORD16      *pi2_mv1, *pi2_mv2, *pi2_mv3, *pi2_mv4;
+    UWORD16 i,j;
+
+    pi2_mv1     = (WORD16 *)&(ps_dec->ai2_mv[FORW][FIRST]);
+    pi2_mv2     = (WORD16 *)&(ps_dec->ai2_mv[FORW][SECOND]);
+    pi2_mv3     = (WORD16 *)&(ps_dec->ai2_mv[BACK][FIRST]);
+    pi2_mv4     = (WORD16 *)&(ps_dec->ai2_mv[BACK][SECOND]);
+
+
+
+    ps_stream  = &ps_dec->s_bit_stream;
+
+    /************************************************************************/
+    /* Decode the motion vector MV_X, MV_Y and dmv[0], dmv[1]               */
+    /************************************************************************/
+    impeg2d_dec_1mv(ps_stream,ps_dec->ai2_pred_mv[FORW][FIRST],pi2_mv1,ps_dec->au2_f_code[FORW],ps_dec->u2_frm_pic,ai2_dmv);
+
+    {
+        WORD16 ai2_m[2][2];
+
+        if(ps_dec->u2_top_field_first)
+        {
+            ai2_m[1][0] = 1;
+            ai2_m[0][1] = 3;
+        }
+        else
+        {
+            ai2_m[1][0] = 3;
+            ai2_m[0][1] = 1;
+        }
+
+        pi2_mv2[MV_X] = pi2_mv1[MV_X];
+        pi2_mv2[MV_Y] = pi2_mv1[MV_Y];
+
+        pi2_mv3[MV_X] = ai2_dmv[0] + DIV_2_RND(pi2_mv1[MV_X] * ai2_m[1][0]);
+        pi2_mv4[MV_X] = ai2_dmv[0] + DIV_2_RND(pi2_mv1[MV_X] * ai2_m[0][1]);
+
+        pi2_mv3[MV_Y] = ai2_dmv[1] + DIV_2_RND(pi2_mv1[MV_Y] * ai2_m[1][0]) - 1;
+        pi2_mv4[MV_Y] = ai2_dmv[1] + DIV_2_RND(pi2_mv1[MV_Y] * ai2_m[0][1]) + 1;
+    }
+
+    ps_dec->ai2_pred_mv[FORW][SECOND][MV_X] = ps_dec->ai2_pred_mv[FORW][FIRST][MV_X];
+    ps_dec->ai2_pred_mv[FORW][SECOND][MV_Y] = ps_dec->ai2_pred_mv[FORW][FIRST][MV_Y];
+
+    /************************************************************************/
+    /* Set the motion vector params                                         */
+    /************************************************************************/
+    for(j = 0; j < 2; j++)
+    {
+        for(i = 0; i < 2; i++)
+        {
+            pi2_mv        = (WORD16 *)&ps_dec->ai2_mv[j][i];
+            ps_mc = &ps_dec->as_mb_mc_params[j][i];
+            ps_mc->s_ref = ps_dec->as_ref_buf[FORW][(i ^ j) & 1];
+            impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, ps_dec->s_mb_type, i,
+                      pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+        }
+    }
+
+}
+/*****************************************************************************
+*  Function Name   : impeg2d_dec_fld_dual_prime
+*
+*  Description     : Decodes first part of params for 2 MV Interpolated MB
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*****************************************************************************/
+void impeg2d_dec_fld_dual_prime(dec_state_t *ps_dec)
+{
+    stream_t         *ps_stream;
+    WORD16          *pi2_mv;
+    mb_mc_params_t  *ps_mc;
+
+    WORD16      *pi2_mv1, *pi2_mv2;
+    WORD16      ai2_dmv[2];
+
+
+    pi2_mv1     = (WORD16 *)&(ps_dec->ai2_mv[FORW][FIRST]);
+    pi2_mv2     = (WORD16 *)&(ps_dec->ai2_mv[FORW][SECOND]);
+    ps_stream  = &ps_dec->s_bit_stream;
+
+    /************************************************************************/
+    /* Decode the motion vector MV_X, MV_Y and dmv[0], dmv[1]               */
+    /************************************************************************/
+    impeg2d_dec_1mv(ps_stream,ps_dec->ai2_pred_mv[FORW][FIRST],pi2_mv1,ps_dec->au2_f_code[FORW],0,ai2_dmv);
+
+
+    pi2_mv2[MV_X] = ai2_dmv[0] + DIV_2_RND(pi2_mv1[MV_X]);
+    pi2_mv2[MV_Y] = ai2_dmv[1] + DIV_2_RND(pi2_mv1[MV_Y]);
+
+    if(ps_dec->u2_picture_structure == TOP_FIELD)
+        pi2_mv2[MV_Y] -= 1;
+    else
+        pi2_mv2[MV_Y] += 1;
+
+    ps_dec->ai2_pred_mv[FORW][SECOND][MV_X] = ps_dec->ai2_pred_mv[FORW][FIRST][MV_X];
+    ps_dec->ai2_pred_mv[FORW][SECOND][MV_Y] = ps_dec->ai2_pred_mv[FORW][FIRST][MV_Y];
+
+    /************************************************************************/
+    /* Set the motion vector params                                         */
+    /************************************************************************/
+        pi2_mv        = (WORD16 *)&ps_dec->ai2_mv[FORW][0];
+        ps_mc = &ps_dec->as_mb_mc_params[FORW][0];
+        ps_mc->s_ref = ps_dec->as_ref_buf[FORW][ps_dec->u2_fld_parity];
+        impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, ps_dec->s_mb_type, 0,
+                  pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+
+        pi2_mv        = (WORD16 *)&ps_dec->ai2_mv[FORW][1];
+        ps_mc = &ps_dec->as_mb_mc_params[FORW][1];
+        ps_mc->s_ref = ps_dec->as_ref_buf[FORW][!ps_dec->u2_fld_parity];
+        impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, ps_dec->s_mb_type, 0,
+                  pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+
+
+}
+/*****************************************************************************
+*  Function Name   : impeg2d_dec_4mv_mb
+*
+*  Description     : Decodes first part of params for 2 MV Interpolated MB
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*****************************************************************************/
+void impeg2d_dec_4mv_mb(dec_state_t *ps_dec)
+{
+    stream_t         *ps_stream;
+    WORD16          *pi2_mv;
+    e_field_t         e_fld;
+    mb_mc_params_t  *ps_mc;
+
+    UWORD16 i,j;
+
+    ps_stream  = &ps_dec->s_bit_stream;
+
+    /***********************************************/
+    /* loop for FW & BK                            */
+    /***********************************************/
+    for(j = 0; j < 2; j++)
+    {
+        /***********************************************/
+        /* loop for decoding 2 mvs of same reference frame*/
+        /***********************************************/
+        for(i = 0; i < 2; i++)
+        {
+            /****************************************************************/
+            /* Decode the first motion vector                               */
+            /****************************************************************/
+            pi2_mv        = (WORD16 *)&ps_dec->ai2_mv[j][i];
+            e_fld = impeg2d_dec_mv(ps_stream,ps_dec->ai2_pred_mv[j][i],pi2_mv,
+                        ps_dec->au2_f_code[j],ps_dec->u2_frm_pic, 1);
+
+            /****************************************************************/
+            /* Set the motion vector params                                 */
+            /****************************************************************/
+            ps_mc = &ps_dec->as_mb_mc_params[j][i];
+            ps_mc->s_ref = ps_dec->as_ref_buf[j][e_fld];
+            impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, ps_dec->s_mb_type, i,
+                          pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+        }
+    }
+
+}
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_2mv_interp_mb
+*
+*  Description     : Decodes first part of params for 2 MV Interpolated MB
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_2mv_interp_mb(dec_state_t *ps_dec)
+{
+    stream_t         *ps_stream;
+    WORD16          *pi2_mv;
+    e_field_t         e_fld;
+    mb_mc_params_t  *ps_mc;
+    UWORD16 i;
+
+    ps_stream  = &ps_dec->s_bit_stream;
+
+    for(i = 0; i < 2; i++)
+    {
+        /********************************************************************/
+        /* Decode the first motion vector                                   */
+        /********************************************************************/
+        pi2_mv        = (WORD16 *)&ps_dec->ai2_mv[i][FIRST];
+        e_fld = impeg2d_dec_mv(ps_stream,ps_dec->ai2_pred_mv[i][FIRST],pi2_mv,
+                    ps_dec->au2_f_code[i],0, ps_dec->u2_fld_pic);
+
+        ps_dec->ai2_pred_mv[i][SECOND][MV_X] = ps_dec->ai2_pred_mv[i][FIRST][MV_X];
+        ps_dec->ai2_pred_mv[i][SECOND][MV_Y] = ps_dec->ai2_pred_mv[i][FIRST][MV_Y];
+        /********************************************************************/
+        /* Set the motion vector params                                     */
+        /********************************************************************/
+        ps_mc = &ps_dec->as_mb_mc_params[i][FIRST];
+        ps_mc->s_ref = ps_dec->as_ref_buf[i][e_fld];
+        impeg2d_set_mc_params(&ps_mc->s_luma, &ps_mc->s_chroma, ps_dec->s_mb_type,i,
+                      pi2_mv, ps_dec->u2_mb_x, ps_dec->u2_mb_y, ps_dec->u2_frame_width, ps_dec->u2_frame_height,ps_dec->u2_picture_width);
+    }
+
+}
diff --git a/decoder/impeg2d_mv_dec.h b/decoder/impeg2d_mv_dec.h
new file mode 100644
index 0000000..f6c691e
--- /dev/null
+++ b/decoder/impeg2d_mv_dec.h
@@ -0,0 +1,28 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#ifndef __IMPEG2D_MV_DEC_H__
+#define __IMPEG2D_MV_DEC_H__
+
+e_field_t impeg2d_dec_mv(stream_t *stream, WORD16 predMv[], WORD16 mv[],UWORD16 fCode[],
+           UWORD16 shift,UWORD16 fld_sel);
+INLINE void impeg2d_dec_1mv(stream_t *stream, WORD16 predMv[], WORD16 mv[],UWORD16 fCode[],
+           UWORD16 shift,WORD16 dmv[]);
+
+#endif /* #ifndef __IMPEG2D_MV_DEC_H__  */
diff --git a/decoder/impeg2d_pic_proc.c b/decoder/impeg2d_pic_proc.c
new file mode 100755
index 0000000..3dececb
--- /dev/null
+++ b/decoder/impeg2d_pic_proc.c
@@ -0,0 +1,664 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#include <stdio.h>
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_globals.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+
+void impeg2d_init_function_ptr(void *pv_codec);
+void impeg2d_format_convert(dec_state_t *ps_dec,
+                            pic_buf_t *ps_src_pic,
+                            iv_yuv_buf_t    *ps_disp_frm_buf,
+                            UWORD32 u4_start_row, UWORD32 u4_num_rows)
+{
+    UWORD8  *pu1_src_y,*pu1_src_u,*pu1_src_v;
+    UWORD8  *pu1_dst_y,*pu1_dst_u,*pu1_dst_v;
+
+
+
+    if((NULL == ps_src_pic) || (NULL == ps_src_pic->pu1_y) || (0 == u4_num_rows))
+            return;
+
+    pu1_src_y   = ps_src_pic->pu1_y + (u4_start_row * ps_dec->u2_frame_width);
+    pu1_src_u   = ps_src_pic->pu1_u + ((u4_start_row >> 1) * (ps_dec->u2_frame_width >> 1));
+    pu1_src_v   = ps_src_pic->pu1_v + ((u4_start_row >> 1) *(ps_dec->u2_frame_width >> 1));
+
+    pu1_dst_y  =  (UWORD8 *)ps_disp_frm_buf->pv_y_buf + (u4_start_row *  ps_dec->u4_frm_buf_stride);
+    pu1_dst_u =   (UWORD8 *)ps_disp_frm_buf->pv_u_buf +((u4_start_row >> 1)*(ps_dec->u4_frm_buf_stride >> 1));
+    pu1_dst_v =   (UWORD8 *)ps_disp_frm_buf->pv_v_buf +((u4_start_row >> 1)*(ps_dec->u4_frm_buf_stride >> 1));
+
+    if (IV_YUV_420P == ps_dec->i4_chromaFormat)
+    {
+        ps_dec->pf_copy_yuv420p_buf(pu1_src_y, pu1_src_u, pu1_src_v, pu1_dst_y,
+                                    pu1_dst_u, pu1_dst_v,
+                                    ps_dec->u2_frame_width,
+                                    u4_num_rows,
+                                    ps_dec->u4_frm_buf_stride,
+                                    (ps_dec->u4_frm_buf_stride >> 1),
+                                    (ps_dec->u4_frm_buf_stride >> 1),
+                                    ps_dec->u2_frame_width,
+                                    (ps_dec->u2_frame_width >> 1),
+                                    (ps_dec->u2_frame_width >> 1));
+    }
+    else if (IV_YUV_422ILE == ps_dec->i4_chromaFormat)
+    {
+        void    *pv_yuv422i;
+        UWORD32 u2_height,u2_width,u2_stride_y,u2_stride_u,u2_stride_v;
+        UWORD32 u2_stride_yuv422i;
+
+
+        pv_yuv422i          = (UWORD8 *)ps_disp_frm_buf->pv_y_buf + ((ps_dec->u2_vertical_size)*(ps_dec->u4_frm_buf_stride));
+        u2_height           = u4_num_rows;
+        u2_width            = ps_dec->u2_horizontal_size;
+        u2_stride_y         = ps_dec->u2_frame_width;
+        u2_stride_u         = u2_stride_y >> 1;
+        u2_stride_v         = u2_stride_u;
+        u2_stride_yuv422i   = (0 == ps_dec->u4_frm_buf_stride) ? ps_dec->u2_horizontal_size : ps_dec->u4_frm_buf_stride;
+
+        ps_dec->pf_fmt_conv_yuv420p_to_yuv422ile(pu1_src_y,
+            pu1_src_u,
+            pu1_src_v,
+            pv_yuv422i,
+            u2_width,
+            u2_height,
+            u2_stride_y,
+            u2_stride_u,
+            u2_stride_v,
+            u2_stride_yuv422i);
+
+    }
+    else if((ps_dec->i4_chromaFormat == IV_YUV_420SP_UV) ||
+            (ps_dec->i4_chromaFormat == IV_YUV_420SP_VU))
+    {
+
+        UWORD32 dest_inc_Y=0,dest_inc_UV=0;
+        WORD32 convert_uv_only;
+
+        pu1_dst_u =   (UWORD8 *)ps_disp_frm_buf->pv_u_buf +((u4_start_row >> 1)*(ps_dec->u4_frm_buf_stride));
+        dest_inc_Y =    ps_dec->u4_frm_buf_stride;
+        dest_inc_UV =   ((ps_dec->u4_frm_buf_stride + 1) >> 1) << 1;
+        convert_uv_only = 0;
+        if(1 == ps_dec->u4_share_disp_buf)
+            convert_uv_only = 1;
+
+        if(ps_dec->i4_chromaFormat == IV_YUV_420SP_UV)
+        {
+            ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_uv(pu1_src_y,
+                pu1_src_u,
+                pu1_src_v,
+                pu1_dst_y,
+                pu1_dst_u,
+                u4_num_rows,
+                ps_dec->u2_horizontal_size,
+                ps_dec->u2_frame_width,
+                ps_dec->u2_frame_width >> 1,
+                ps_dec->u2_frame_width >> 1,
+                dest_inc_Y,
+                dest_inc_UV,
+                convert_uv_only);
+        }
+        else
+        {
+            ps_dec->pf_fmt_conv_yuv420p_to_yuv420sp_vu(pu1_src_y,
+                    pu1_src_u,
+                    pu1_src_v,
+                    pu1_dst_y,
+                    pu1_dst_u,
+                    u4_num_rows,
+                    ps_dec->u2_horizontal_size,
+                    ps_dec->u2_frame_width,
+                    ps_dec->u2_frame_width >> 1,
+                    ps_dec->u2_frame_width >> 1,
+                    dest_inc_Y,
+                    dest_inc_UV,
+                    convert_uv_only);
+        }
+
+
+
+    }
+
+}
+
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_get_frm_buf
+*
+*  Description     : Gets YUV component buffers for the frame
+*
+*  Arguments       :
+*  frm_buf         : YUV buffer
+*  frm             : Reference frame
+*  width           : Width of the frame
+*  Height          : Height of the frame
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_get_frm_buf(yuv_buf_t *ps_frm_buf,UWORD8 *pu1_frm,UWORD32 u4_width,UWORD32 u4_height)
+{
+   UWORD32 u4_luma_size = u4_width * u4_height;
+   UWORD32 u4_chroma_size = (u4_width * u4_height)>>2;
+
+   ps_frm_buf->pu1_y = pu1_frm;
+   ps_frm_buf->pu1_u = pu1_frm + u4_luma_size;
+   ps_frm_buf->pu1_v = pu1_frm + u4_luma_size + u4_chroma_size;
+
+}
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_get_bottom_field_buf
+*
+*  Description     : Gets YUV component buffers for bottom field of the frame
+*
+*  Arguments       :
+*  frm_buf         : YUV buffer
+*  frm             : Reference frame
+*  width           : Width of the frame
+*  Height          : Height of the frame
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_get_bottom_field_buf(yuv_buf_t *ps_src_buf,yuv_buf_t *ps_dst_buf,
+                      UWORD32 u4_width)
+{
+   ps_dst_buf->pu1_y = ps_src_buf->pu1_y + u4_width;
+   ps_dst_buf->pu1_u = ps_src_buf->pu1_u + (u4_width>>1);
+   ps_dst_buf->pu1_v = ps_src_buf->pu1_v + (u4_width>>1);
+
+}
+/*******************************************************************************
+*  Function Name   : impeg2d_get_mb_addr_incr
+*
+*  Description     : Decodes the Macroblock address increment
+*
+*  Arguments       :
+*  stream          : Bitstream
+*
+*  Values Returned : Macroblock address increment
+*******************************************************************************/
+UWORD16 impeg2d_get_mb_addr_incr(stream_t *ps_stream)
+{
+    UWORD16 u2_mb_addr_incr = 0;
+    while (impeg2d_bit_stream_nxt(ps_stream,MB_ESCAPE_CODE_LEN) == MB_ESCAPE_CODE)
+    {
+        impeg2d_bit_stream_flush(ps_stream,MB_ESCAPE_CODE_LEN);
+        u2_mb_addr_incr += 33;
+    }
+    u2_mb_addr_incr += impeg2d_dec_vld_symbol(ps_stream,gai2_impeg2d_mb_addr_incr,MB_ADDR_INCR_LEN) +
+        MB_ADDR_INCR_OFFSET;
+    return(u2_mb_addr_incr);
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_init_video_state
+*
+*  Description     : Initializes the Video decoder state
+*
+*  Arguments       :
+*  dec             : Decoder context
+*  videoType       : MPEG_2_Video / MPEG_1_Video
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_init_video_state(dec_state_t *ps_dec, e_video_type_t e_video_type)
+{
+    /*-----------------------------------------------------------------------*/
+    /* Bit Stream  that conforms to MPEG-1 <ISO/IEC 11172-2> standard        */
+    /*-----------------------------------------------------------------------*/
+    if(e_video_type == MPEG_1_VIDEO)
+    {
+        ps_dec->u2_is_mpeg2 = 0;
+
+        /*-------------------------------------------------------------------*/
+        /* force MPEG-1 parameters for proper decoder behavior               */
+        /* see ISO/IEC 13818-2 section D.9.14                                */
+        /*-------------------------------------------------------------------*/
+        ps_dec->u2_progressive_sequence         = 1;
+        ps_dec->u2_intra_dc_precision           = 0;
+        ps_dec->u2_picture_structure            = FRAME_PICTURE;
+        ps_dec->u2_frame_pred_frame_dct         = 1;
+        ps_dec->u2_concealment_motion_vectors   = 0;
+        ps_dec->u2_q_scale_type                 = 0;
+        ps_dec->u2_intra_vlc_format             = 0;
+        ps_dec->u2_alternate_scan               = 0;
+        ps_dec->u2_repeat_first_field           = 0;
+        ps_dec->u2_progressive_frame            = 1;
+        ps_dec->u2_frame_rate_extension_n       = 0;
+        ps_dec->u2_frame_rate_extension_d       = 0;
+
+        ps_dec->pf_vld_inv_quant                  = impeg2d_vld_inv_quant_mpeg1;
+        /*-------------------------------------------------------------------*/
+        /* Setting of parameters other than those mentioned in MPEG2 standard*/
+        /* but used in decoding process.                                     */
+        /*-------------------------------------------------------------------*/
+    }
+    /*-----------------------------------------------------------------------*/
+    /* Bit Stream  that conforms to MPEG-2                                   */
+    /*-----------------------------------------------------------------------*/
+    else
+    {
+        ps_dec->u2_is_mpeg2                  = 1;
+        ps_dec->u2_full_pel_forw_vector   = 0;
+        ps_dec->u2_forw_f_code            = 7;
+        ps_dec->u2_full_pel_back_vector   = 0;
+        ps_dec->u2_back_f_code            = 7;
+        ps_dec->pf_vld_inv_quant       = impeg2d_vld_inv_quant_mpeg2;
+
+
+    }
+
+
+    impeg2d_init_function_ptr(ps_dec);
+
+    /* Set the frame Width and frame Height */
+    ps_dec->u2_frame_height        = ALIGN16(ps_dec->u2_vertical_size);
+    ps_dec->u2_frame_width         = ALIGN16(ps_dec->u2_horizontal_size);
+    ps_dec->u2_num_horiz_mb         = (ps_dec->u2_horizontal_size + 15) >> 4;
+   // dec->u4_frm_buf_stride    = dec->frameWidth;
+    if (ps_dec->u2_frame_height > ps_dec->u2_create_max_height || ps_dec->u2_frame_width > ps_dec->u2_create_max_width)
+    {
+        return IMPEG2D_PIC_SIZE_NOT_SUPPORTED;
+    }
+
+    ps_dec->u2_num_flds_decoded = 0;
+
+    /* Calculate the frame period */
+    {
+        UWORD32 numer;
+        UWORD32 denom;
+        numer = (UWORD32)gau2_impeg2_frm_rate_code[ps_dec->u2_frame_rate_code][1] *
+                                (UWORD32)(ps_dec->u2_frame_rate_extension_d + 1);
+
+        denom = (UWORD32)gau2_impeg2_frm_rate_code[ps_dec->u2_frame_rate_code][0] *
+                                (UWORD32)(ps_dec->u2_frame_rate_extension_n + 1);
+        ps_dec->u2_framePeriod =  (numer * 1000 * 100) / denom;
+    }
+
+
+   if(VERTICAL_SCAN == ps_dec->u2_alternate_scan)
+   {
+    ps_dec->pu1_inv_scan_matrix = (UWORD8 *)gau1_impeg2_inv_scan_vertical;
+   }
+   else
+   {
+    ps_dec->pu1_inv_scan_matrix = (UWORD8 *)gau1_impeg2_inv_scan_zig_zag;
+   }
+   return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+}
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_pre_pic_dec_proc
+*
+*  Description     : Does the processing neccessary before picture decoding
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_pre_pic_dec_proc(dec_state_t *ps_dec)
+{
+    WORD32 u4_get_disp;
+    pic_buf_t *ps_disp_pic;
+    IMPEG2D_ERROR_CODES_T e_error = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+
+    u4_get_disp = 0;
+    ps_disp_pic = NULL;
+
+    /* Field Picture */
+    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
+    {
+        ps_dec->u2_num_vert_mb       = (ps_dec->u2_vertical_size + 31) >> 5;
+
+        if(ps_dec->u2_num_flds_decoded == 0)
+        {
+            pic_buf_t *ps_pic_buf;
+            u4_get_disp = 1;
+
+            ps_pic_buf = impeg2_buf_mgr_get_next_free(ps_dec->pv_pic_buf_mg, &ps_dec->i4_cur_buf_id);
+
+            if (NULL == ps_pic_buf)
+            {
+                return IMPEG2D_NO_FREE_BUF_ERR;
+            }
+
+            impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, BUF_MGR_DISP);
+            impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, BUF_MGR_REF);
+
+            ps_pic_buf->u4_ts = ps_dec->u4_inp_ts;
+            ps_dec->ps_cur_pic = ps_pic_buf;
+            ps_dec->s_cur_frm_buf.pu1_y = ps_pic_buf->pu1_y;
+            ps_dec->s_cur_frm_buf.pu1_u = ps_pic_buf->pu1_u;
+            ps_dec->s_cur_frm_buf.pu1_v = ps_pic_buf->pu1_v;
+        }
+
+        if(ps_dec->u2_picture_structure == TOP_FIELD)
+        {
+            ps_dec->u2_fld_parity = TOP;
+        }
+        else
+        {
+            ps_dec->u2_fld_parity = BOTTOM;
+        }
+        ps_dec->u2_field_dct           = 0;
+        ps_dec->u2_read_dct_type        = 0;
+        ps_dec->u2_read_motion_type     = 1;
+        ps_dec->u2_fld_pic             = 1;
+        ps_dec->u2_frm_pic             = 0;
+        ps_dec->ps_func_forw_or_back     = gas_impeg2d_func_fld_fw_or_bk;
+        ps_dec->ps_func_bi_direct       = gas_impeg2d_func_fld_bi_direct;
+   }
+    /* Frame Picture */
+    else
+    {
+        pic_buf_t *ps_pic_buf;
+
+
+        ps_dec->u2_num_vert_mb       = (ps_dec->u2_vertical_size + 15) >> 4;
+        u4_get_disp = 1;
+        ps_pic_buf = impeg2_buf_mgr_get_next_free(ps_dec->pv_pic_buf_mg, &ps_dec->i4_cur_buf_id);
+
+        if (NULL == ps_pic_buf)
+        {
+            return IMPEG2D_NO_FREE_BUF_ERR;
+        }
+        impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, BUF_MGR_DISP);
+        impeg2_buf_mgr_set_status((buf_mgr_t *)ps_dec->pv_pic_buf_mg, ps_dec->i4_cur_buf_id, BUF_MGR_REF);
+
+        ps_pic_buf->u4_ts = ps_dec->u4_inp_ts;
+        ps_dec->ps_cur_pic = ps_pic_buf;
+        ps_dec->s_cur_frm_buf.pu1_y = ps_pic_buf->pu1_y;
+        ps_dec->s_cur_frm_buf.pu1_u = ps_pic_buf->pu1_u;
+        ps_dec->s_cur_frm_buf.pu1_v = ps_pic_buf->pu1_v;
+
+
+        if(ps_dec->u2_frame_pred_frame_dct == 0)
+        {
+            ps_dec->u2_read_dct_type    = 1;
+            ps_dec->u2_read_motion_type = 1;
+        }
+        else
+        {
+            ps_dec->u2_read_dct_type    = 0;
+            ps_dec->u2_read_motion_type = 0;
+            ps_dec->u2_motion_type     = 2;
+            ps_dec->u2_field_dct       = 0;
+        }
+
+        ps_dec->u2_fld_parity          = TOP;
+        ps_dec->u2_fld_pic             = 0;
+        ps_dec->u2_frm_pic             = 1;
+        ps_dec->ps_func_forw_or_back     = gas_impeg2d_func_frm_fw_or_bk;
+        ps_dec->ps_func_bi_direct       = gas_impeg2d_func_frm_bi_direct;
+   }
+    ps_dec->u2_def_dc_pred[Y_LUMA]   = 128 << ps_dec->u2_intra_dc_precision;
+    ps_dec->u2_def_dc_pred[U_CHROMA]   = 128 << ps_dec->u2_intra_dc_precision;
+    ps_dec->u2_def_dc_pred[V_CHROMA]   = 128 << ps_dec->u2_intra_dc_precision;
+    ps_dec->u2_num_mbs_left  = ps_dec->u2_num_horiz_mb * ps_dec->u2_num_vert_mb;
+    if(u4_get_disp)
+    {
+        if(ps_dec->u4_num_frames_decoded > 1)
+        {
+            ps_disp_pic = impeg2_disp_mgr_get(&ps_dec->s_disp_mgr, &ps_dec->i4_disp_buf_id);
+        }
+        ps_dec->ps_disp_pic = ps_disp_pic;
+        if(ps_disp_pic)
+        {
+            if(1 == ps_dec->u4_share_disp_buf)
+            {
+                ps_dec->ps_disp_frm_buf->pv_y_buf  = ps_disp_pic->pu1_y;
+                if(IV_YUV_420P == ps_dec->i4_chromaFormat)
+                {
+                    ps_dec->ps_disp_frm_buf->pv_u_buf  = ps_disp_pic->pu1_u;
+                    ps_dec->ps_disp_frm_buf->pv_v_buf  = ps_disp_pic->pu1_v;
+                }
+                else
+                {
+                    UWORD8 *pu1_buf;
+
+                    pu1_buf = ps_dec->as_disp_buffers[ps_disp_pic->i4_buf_id].pu1_bufs[1];
+                    ps_dec->ps_disp_frm_buf->pv_u_buf  = pu1_buf;
+
+                    pu1_buf = ps_dec->as_disp_buffers[ps_disp_pic->i4_buf_id].pu1_bufs[2];
+                    ps_dec->ps_disp_frm_buf->pv_v_buf  = pu1_buf;
+                }
+            }
+        }
+    }
+
+
+    switch(ps_dec->e_pic_type)
+    {
+    case I_PIC:
+        {
+            ps_dec->pf_decode_slice = impeg2d_dec_i_slice;
+            break;
+        }
+    case D_PIC:
+        {
+            ps_dec->pf_decode_slice = impeg2d_dec_d_slice;
+            break;
+        }
+    case P_PIC:
+        {
+            ps_dec->pf_decode_slice = impeg2d_dec_p_b_slice;
+            ps_dec->pu2_mb_type       = gau2_impeg2d_p_mb_type;
+            break;
+        }
+    case B_PIC:
+        {
+            ps_dec->pf_decode_slice = impeg2d_dec_p_b_slice;
+            ps_dec->pu2_mb_type       = gau2_impeg2d_b_mb_type;
+            break;
+        }
+    default:
+        return IMPEG2D_INVALID_PIC_TYPE;
+    }
+
+    /*************************************************************************/
+    /* Set the reference pictures                                            */
+    /*************************************************************************/
+
+    /* Error resilience: If forward and backward pictures are going to be NULL*/
+    /* then assign both to the current                                        */
+    /* if one of them NULL then we will assign the non null to the NULL one   */
+
+    if(ps_dec->e_pic_type == P_PIC)
+    {
+        if (NULL == ps_dec->as_recent_fld[1][0].pu1_y)
+        {
+            ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
+        }
+        if (NULL == ps_dec->as_recent_fld[1][1].pu1_y)
+        {
+            impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
+                ps_dec->u2_frame_width);
+        }
+
+        ps_dec->as_ref_buf[FORW][TOP]    = ps_dec->as_recent_fld[1][0];
+        ps_dec->as_ref_buf[FORW][BOTTOM] = ps_dec->as_recent_fld[1][1];
+
+
+    }
+    else if(ps_dec->e_pic_type == B_PIC)
+    {
+        if((NULL == ps_dec->as_recent_fld[1][0].pu1_y) && (NULL == ps_dec->as_recent_fld[0][0].pu1_y))
+        {
+            // assign the current picture to both
+            ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
+            impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
+                ps_dec->u2_frame_width);
+            ps_dec->as_recent_fld[0][0] = ps_dec->s_cur_frm_buf;
+            ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
+        }
+        //Assign the non-null picture to the null picture
+        else if ((NULL != ps_dec->as_recent_fld[1][0].pu1_y) && (NULL == ps_dec->as_recent_fld[0][0].pu1_y))
+        {
+            ps_dec->as_recent_fld[0][0] = ps_dec->as_recent_fld[1][0];
+            ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
+        }
+        else if ((NULL == ps_dec->as_recent_fld[1][0].pu1_y) && (NULL != ps_dec->as_recent_fld[0][0].pu1_y))
+        {
+            ps_dec->as_recent_fld[1][0] = ps_dec->as_recent_fld[0][0];
+            ps_dec->as_recent_fld[1][1] = ps_dec->as_recent_fld[0][1];
+        }
+
+        ps_dec->as_ref_buf[FORW][TOP]    = ps_dec->as_recent_fld[0][0];
+        ps_dec->as_ref_buf[FORW][BOTTOM] = ps_dec->as_recent_fld[0][1];
+        ps_dec->as_ref_buf[BACK][TOP]    = ps_dec->as_recent_fld[1][0];
+        ps_dec->as_ref_buf[BACK][BOTTOM] = ps_dec->as_recent_fld[1][1];
+
+
+    }
+
+    return e_error;
+}
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_post_pic_dec_proc
+*
+*  Description     : Performs processing that is needed at the end of picture
+*                    decode
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_post_pic_dec_proc(dec_state_t *ps_dec)
+{
+
+   WORD32 u4_update_pic_buf = 0;
+    /*************************************************************************/
+    /* Processing at the end of picture                                      */
+    /*************************************************************************/
+    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
+    {
+        ps_dec->u2_num_vert_mb       = (ps_dec->u2_vertical_size + 31) >> 5;
+
+        if(ps_dec->u2_num_flds_decoded == 1)
+        {
+            ps_dec->u2_num_flds_decoded = 0;
+            u4_update_pic_buf = 1;
+        }
+        else
+        {
+            ps_dec->u2_num_flds_decoded = 1;
+        }
+    }
+    else
+    {
+        u4_update_pic_buf = 1;
+    }
+
+    if(u4_update_pic_buf)
+    {
+        ps_dec->i4_frame_decoded = 1;
+        if(ps_dec->e_pic_type != B_PIC)
+        {
+            /* In any sequence first two pictures have to be reference pictures */
+            /* Adding of first picture in the sequence */
+            if(ps_dec->aps_ref_pics[0] == NULL)
+            {
+                ps_dec->aps_ref_pics[0] = ps_dec->ps_cur_pic;
+            }
+
+            /* Adding of second picture in the sequence */
+            else if(ps_dec->aps_ref_pics[1] == NULL)
+            {
+                ps_dec->aps_ref_pics[1] = ps_dec->ps_cur_pic;
+                impeg2_disp_mgr_add(&ps_dec->s_disp_mgr, ps_dec->aps_ref_pics[0], ps_dec->aps_ref_pics[0]->i4_buf_id);
+            }
+            else
+            {
+
+                impeg2_disp_mgr_add(&ps_dec->s_disp_mgr, ps_dec->aps_ref_pics[1], ps_dec->aps_ref_pics[1]->i4_buf_id);
+                impeg2_buf_mgr_release(ps_dec->pv_pic_buf_mg, ps_dec->aps_ref_pics[0]->i4_buf_id, BUF_MGR_REF);
+                ps_dec->aps_ref_pics[0] = ps_dec->aps_ref_pics[1];
+                ps_dec->aps_ref_pics[1] = ps_dec->ps_cur_pic;
+
+            }
+        }
+        else
+        {
+            impeg2_disp_mgr_add(&ps_dec->s_disp_mgr, ps_dec->ps_cur_pic, ps_dec->ps_cur_pic->i4_buf_id);
+
+            impeg2_buf_mgr_release(ps_dec->pv_pic_buf_mg, ps_dec->ps_cur_pic->i4_buf_id, BUF_MGR_REF);
+        }
+
+    }
+    /*************************************************************************/
+    /* Update the list of recent reference pictures                          */
+    /*************************************************************************/
+    if(ps_dec->e_pic_type != B_PIC)
+    {
+        switch(ps_dec->u2_picture_structure)
+        {
+        case FRAME_PICTURE:
+            {
+                ps_dec->as_recent_fld[0][0] = ps_dec->as_recent_fld[1][0];
+                ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
+
+                ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
+                impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
+                ps_dec->u2_frame_width);
+                break;
+            }
+        case TOP_FIELD:
+            {
+                ps_dec->as_recent_fld[0][0] = ps_dec->as_recent_fld[1][0];
+                ps_dec->as_recent_fld[1][0] = ps_dec->s_cur_frm_buf;
+                break;
+            }
+        case BOTTOM_FIELD:
+            {
+                ps_dec->as_recent_fld[0][1] = ps_dec->as_recent_fld[1][1];
+                impeg2d_get_bottom_field_buf(&ps_dec->s_cur_frm_buf, &ps_dec->as_recent_fld[1][1],
+                ps_dec->u2_frame_width);
+                break;
+            }
+        }
+    }
+}
diff --git a/decoder/impeg2d_pic_proc.h b/decoder/impeg2d_pic_proc.h
new file mode 100644
index 0000000..e97dd13
--- /dev/null
+++ b/decoder/impeg2d_pic_proc.h
@@ -0,0 +1,41 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#ifndef __IMPEG2D_PIC_PROC_H__
+#define __IMPEG2D_PIC_PROC_H__
+
+/*****************************************************************************/
+/* Function Declarations                                                     */
+/*****************************************************************************/
+UWORD16 impeg2d_get_mb_addr_incr(stream_t *stream);
+IMPEG2D_ERROR_CODES_T impeg2d_init_video_state(dec_state_t *dec, e_video_type_t videoType);
+IMPEG2D_ERROR_CODES_T impeg2d_pre_pic_dec_proc(dec_state_t *dec);
+void impeg2d_post_pic_dec_proc(dec_state_t *dec);
+IMPEG2D_ERROR_CODES_T impeg2d_dec_i_slice(dec_state_t *dec);
+IMPEG2D_ERROR_CODES_T impeg2d_dec_d_slice(dec_state_t *dec);
+IMPEG2D_ERROR_CODES_T impeg2d_dec_p_b_slice(dec_state_t *dec);
+
+void impeg2d_format_convert(dec_state_t *ps_dec,
+                            pic_buf_t *ps_src_pic,
+                            iv_yuv_buf_t    *ps_disp_frm_buf,
+                            UWORD32 u4_start_row, UWORD32 u4_num_rows);
+
+
+#endif /* __IMPEG2D_PIC_PROC_H__  */
+
diff --git a/decoder/impeg2d_pnb_pic.c b/decoder/impeg2d_pnb_pic.c
new file mode 100644
index 0000000..036c7d1
--- /dev/null
+++ b/decoder/impeg2d_pnb_pic.c
@@ -0,0 +1,698 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#include <stdio.h>
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_mc.h"
+
+#define BLK_SIZE 8
+#define LUMA_BLK_SIZE (2 * (BLK_SIZE))
+#define CHROMA_BLK_SIZE (BLK_SIZE)
+
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_p_mb_params
+*
+*  Description     : Decodes the parameters for P
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_p_mb_params(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream = &ps_dec->s_bit_stream;
+    UWORD16 u2_mb_addr_incr;
+    UWORD16 u2_total_len;
+    UWORD16 u2_len;
+    UWORD16 u2_mb_type;
+    UWORD32 u4_next_word;
+    const dec_mb_params_t *ps_dec_mb_params;
+    if(impeg2d_bit_stream_nxt(ps_stream,1) == 1)
+    {
+        impeg2d_bit_stream_flush(ps_stream,1);
+
+    }
+    else
+    {
+        u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream);
+        if(0 == ps_dec->u2_first_mb)
+        {
+            /****************************************************************/
+            /* If the 2nd member of a field picture pair is a P picture and */
+            /* the first one was an I picture, there cannot be any skipped  */
+            /* MBs in the second field picture                              */
+            /****************************************************************/
+            /*
+            if((dec->picture_structure != FRAME_PICTURE) &&
+                (dec->f->FieldFuncCall != 0) &&
+                (dec->las->u1_last_coded_vop_type == I))
+            {
+                core0_err_handler((void *)(VOLParams),
+                    ITTMPEG2_ERR_INVALID_MB_SKIP);
+            }
+            */
+            /****************************************************************/
+            /* In MPEG-2, the last MB of the row cannot be skipped and the  */
+            /* MBAddrIncr cannot be such that it will take the current MB   */
+            /* beyond the current row                                       */
+            /* In MPEG-1, the slice could start and end anywhere and is not */
+            /* restricted to a row like in MPEG-2. Hence this check should  */
+            /* not be done for MPEG-1 streams.                              */
+            /****************************************************************/
+            if(ps_dec->u2_is_mpeg2 && ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb) )
+            {
+                u2_mb_addr_incr    = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x;
+            }
+
+            impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1));
+        }
+
+    }
+    u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16);
+    /*-----------------------------------------------------------------------*/
+    /* MB type                                                               */
+    /*-----------------------------------------------------------------------*/
+    {
+        u2_mb_type   = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)];
+        u2_len      = BITS(u2_mb_type,15,8);
+        u2_total_len = u2_len;
+        u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len);
+    }
+    /*-----------------------------------------------------------------------*/
+    /* motion type                                                           */
+    /*-----------------------------------------------------------------------*/
+    {
+        if((u2_mb_type & MB_FORW_OR_BACK) &&  ps_dec->u2_read_motion_type)
+        {
+            WORD32 i4_motion_type;
+            ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14);
+            u2_total_len        += MB_MOTION_TYPE_LEN;
+            u4_next_word        = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN);
+            i4_motion_type     = ps_dec->u2_motion_type;
+
+            if((i4_motion_type == 0) ||
+                (i4_motion_type == 4) ||
+                (i4_motion_type >  7))
+            {
+                //TODO : VANG Check for validity
+                i4_motion_type = 1;
+            }
+
+        }
+    }
+    /*-----------------------------------------------------------------------*/
+    /* dct type                                                              */
+    /*-----------------------------------------------------------------------*/
+    {
+        if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type)
+        {
+            ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15);
+            u2_total_len += MB_DCT_TYPE_LEN;
+            u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN);
+        }
+    }
+    /*-----------------------------------------------------------------------*/
+    /* Quant scale code                                                      */
+    /*-----------------------------------------------------------------------*/
+    if(u2_mb_type & MB_QUANT)
+    {
+        UWORD16 u2_quant_scale_code;
+        u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11);
+
+        ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
+            gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
+        u2_total_len += MB_QUANT_SCALE_CODE_LEN;
+    }
+    impeg2d_bit_stream_flush(ps_stream,u2_total_len);
+    /*-----------------------------------------------------------------------*/
+    /* Set the function pointers                                             */
+    /*-----------------------------------------------------------------------*/
+    ps_dec->u2_coded_mb    = (UWORD16)(u2_mb_type & MB_CODED);
+
+    if(u2_mb_type & MB_FORW_OR_BACK)
+    {
+
+        UWORD16 refPic      = !(u2_mb_type & MB_MV_FORW);
+        UWORD16 index       = (ps_dec->u2_motion_type);
+        ps_dec->u2_prev_intra_mb    = 0;
+        ps_dec->e_mb_pred         = (e_pred_direction_t)refPic;
+        ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index];
+        ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
+        ps_dec_mb_params->pf_func_mb_params(ps_dec);
+
+    }
+    else if(u2_mb_type & MB_TYPE_INTRA)
+    {
+        ps_dec->u2_prev_intra_mb    = 1;
+        impeg2d_dec_intra_mb(ps_dec);
+
+    }
+    else
+    {
+        ps_dec->u2_prev_intra_mb    = 0;
+        ps_dec->e_mb_pred = FORW;
+        ps_dec->u2_motion_type = 0;
+        impeg2d_dec_0mv_coded_mb(ps_dec);
+    }
+
+    /*-----------------------------------------------------------------------*/
+    /* decode cbp                                                            */
+    /*-----------------------------------------------------------------------*/
+    if((u2_mb_type & MB_TYPE_INTRA))
+    {
+        ps_dec->u2_cbp  = 0x3f;
+        ps_dec->u2_prev_intra_mb    = 1;
+    }
+    else
+    {
+        ps_dec->u2_prev_intra_mb  = 0;
+        ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
+        ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
+        ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
+        if((ps_dec->u2_coded_mb))
+        {
+            UWORD16 cbpValue;
+            cbpValue  = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)];
+            ps_dec->u2_cbp  = cbpValue & 0xFF;
+            impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF);
+        }
+        else
+        {
+            ps_dec->u2_cbp  = 0;
+        }
+    }
+}
+
+
+/*******************************************************************************
+*
+*  Function Name   : impeg2d_dec_pnb_mb_params
+*
+*  Description     : Decodes the parameters for P and B pictures
+*
+*  Arguments       :
+*  dec             : Decoder context
+*
+*  Values Returned : None
+*******************************************************************************/
+void impeg2d_dec_pnb_mb_params(dec_state_t *ps_dec)
+{
+    stream_t *ps_stream = &ps_dec->s_bit_stream;
+    UWORD16 u2_mb_addr_incr;
+    UWORD16 u2_total_len;
+    UWORD16 u2_len;
+    UWORD16 u2_mb_type;
+    UWORD32 u4_next_word;
+    const dec_mb_params_t *ps_dec_mb_params;
+    if(impeg2d_bit_stream_nxt(ps_stream,1) == 1)
+    {
+        impeg2d_bit_stream_flush(ps_stream,1);
+
+    }
+    else
+    {
+        u2_mb_addr_incr = impeg2d_get_mb_addr_incr(ps_stream);
+
+        if(ps_dec->u2_first_mb)
+        {
+            /****************************************************************/
+            /* Section 6.3.17                                               */
+            /* The first MB of a slice cannot be skipped                    */
+            /* But the mb_addr_incr can be > 1, because at the beginning of */
+            /* a slice, it indicates the offset from the last MB in the     */
+            /* previous row. Hence for the first slice in a row, the        */
+            /* mb_addr_incr needs to be 1.                                  */
+            /****************************************************************/
+            /* MB_x is set to zero whenever MB_y changes.                   */
+            ps_dec->u2_mb_x = u2_mb_addr_incr - 1;
+            /* For error resilience */
+            ps_dec->u2_mb_x = MIN(ps_dec->u2_mb_x, (ps_dec->u2_num_horiz_mb - 1));
+
+            /****************************************************************/
+            /* mb_addr_incr is forced to 1 because in this decoder it is used */
+            /* more as an indicator of the number of MBs skipped than the   */
+            /* as defined by the standard (Section 6.3.17)                  */
+            /****************************************************************/
+            u2_mb_addr_incr = 1;
+            ps_dec->u2_first_mb = 0;
+        }
+        else
+        {
+            /****************************************************************/
+            /* In MPEG-2, the last MB of the row cannot be skipped and the  */
+            /* mb_addr_incr cannot be such that it will take the current MB   */
+            /* beyond the current row                                       */
+            /* In MPEG-1, the slice could start and end anywhere and is not */
+            /* restricted to a row like in MPEG-2. Hence this check should  */
+            /* not be done for MPEG-1 streams.                              */
+            /****************************************************************/
+            if(ps_dec->u2_is_mpeg2 &&
+                ((ps_dec->u2_mb_x + u2_mb_addr_incr) > ps_dec->u2_num_horiz_mb))
+            {
+                u2_mb_addr_incr    = ps_dec->u2_num_horiz_mb - ps_dec->u2_mb_x;
+            }
+
+
+            impeg2d_dec_skip_mbs(ps_dec, (UWORD16)(u2_mb_addr_incr - 1));
+        }
+
+    }
+    u4_next_word = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,16);
+    /*-----------------------------------------------------------------------*/
+    /* MB type                                                               */
+    /*-----------------------------------------------------------------------*/
+    {
+        u2_mb_type   = ps_dec->pu2_mb_type[BITS((UWORD16)u4_next_word,15,10)];
+        u2_len      = BITS(u2_mb_type,15,8);
+        u2_total_len = u2_len;
+        u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << u2_len);
+    }
+    /*-----------------------------------------------------------------------*/
+    /* motion type                                                           */
+    /*-----------------------------------------------------------------------*/
+    {
+        WORD32 i4_motion_type = ps_dec->u2_motion_type;
+
+        if((u2_mb_type & MB_FORW_OR_BACK) &&  ps_dec->u2_read_motion_type)
+        {
+            ps_dec->u2_motion_type = BITS((UWORD16)u4_next_word,15,14);
+            u2_total_len += MB_MOTION_TYPE_LEN;
+            u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_MOTION_TYPE_LEN);
+            i4_motion_type     = ps_dec->u2_motion_type;
+
+        }
+
+
+        if ((u2_mb_type & MB_FORW_OR_BACK) &&
+            ((i4_motion_type == 0) ||
+            (i4_motion_type == 3) ||
+            (i4_motion_type == 4) ||
+            (i4_motion_type >= 7)))
+        {
+            //TODO: VANG Check for validity
+            i4_motion_type = 1;
+        }
+
+    }
+    /*-----------------------------------------------------------------------*/
+    /* dct type                                                              */
+    /*-----------------------------------------------------------------------*/
+    {
+        if((u2_mb_type & MB_CODED) && ps_dec->u2_read_dct_type)
+        {
+            ps_dec->u2_field_dct = BIT((UWORD16)u4_next_word,15);
+            u2_total_len += MB_DCT_TYPE_LEN;
+            u4_next_word = (UWORD16)LSW((UWORD16)u4_next_word << MB_DCT_TYPE_LEN);
+        }
+    }
+    /*-----------------------------------------------------------------------*/
+    /* Quant scale code                                                      */
+    /*-----------------------------------------------------------------------*/
+    if(u2_mb_type & MB_QUANT)
+    {
+        UWORD16 u2_quant_scale_code;
+        u2_quant_scale_code = BITS((UWORD16)u4_next_word,15,11);
+
+        ps_dec->u1_quant_scale = (ps_dec->u2_q_scale_type) ?
+            gau1_impeg2_non_linear_quant_scale[u2_quant_scale_code] : (u2_quant_scale_code << 1);
+        u2_total_len += MB_QUANT_SCALE_CODE_LEN;
+    }
+    impeg2d_bit_stream_flush(ps_stream,u2_total_len);
+    /*-----------------------------------------------------------------------*/
+    /* Set the function pointers                                             */
+    /*-----------------------------------------------------------------------*/
+    ps_dec->u2_coded_mb    = (UWORD16)(u2_mb_type & MB_CODED);
+
+    if(u2_mb_type & MB_BIDRECT)
+    {
+        UWORD16 u2_index       = (ps_dec->u2_motion_type);
+
+        ps_dec->u2_prev_intra_mb    = 0;
+        ps_dec->e_mb_pred         = BIDIRECT;
+        ps_dec_mb_params = &ps_dec->ps_func_bi_direct[u2_index];
+        ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
+        ps_dec_mb_params->pf_func_mb_params(ps_dec);
+    }
+    else if(u2_mb_type & MB_FORW_OR_BACK)
+    {
+
+        UWORD16 u2_refPic      = !(u2_mb_type & MB_MV_FORW);
+        UWORD16 u2_index       = (ps_dec->u2_motion_type);
+        ps_dec->u2_prev_intra_mb    = 0;
+        ps_dec->e_mb_pred         = (e_pred_direction_t)u2_refPic;
+        ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[u2_index];
+        ps_dec->s_mb_type = ps_dec_mb_params->s_mb_type;
+        ps_dec_mb_params->pf_func_mb_params(ps_dec);
+
+    }
+    else if(u2_mb_type & MB_TYPE_INTRA)
+    {
+        ps_dec->u2_prev_intra_mb    = 1;
+        impeg2d_dec_intra_mb(ps_dec);
+
+    }
+    else
+    {
+        ps_dec->u2_prev_intra_mb =0;
+        ps_dec->e_mb_pred = FORW;
+        ps_dec->u2_motion_type = 0;
+        impeg2d_dec_0mv_coded_mb(ps_dec);
+    }
+
+    /*-----------------------------------------------------------------------*/
+    /* decode cbp                                                            */
+    /*-----------------------------------------------------------------------*/
+    if((u2_mb_type & MB_TYPE_INTRA))
+    {
+        ps_dec->u2_cbp  = 0x3f;
+        ps_dec->u2_prev_intra_mb    = 1;
+    }
+    else
+    {
+        ps_dec->u2_prev_intra_mb  = 0;
+        ps_dec->u2_def_dc_pred[Y_LUMA] = 128 << ps_dec->u2_intra_dc_precision;
+        ps_dec->u2_def_dc_pred[U_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
+        ps_dec->u2_def_dc_pred[V_CHROMA] = 128 << ps_dec->u2_intra_dc_precision;
+        if((ps_dec->u2_coded_mb))
+        {
+            UWORD16 cbpValue;
+            cbpValue  = gau2_impeg2d_cbp_code[impeg2d_bit_stream_nxt(ps_stream,MB_CBP_LEN)];
+            ps_dec->u2_cbp  = cbpValue & 0xFF;
+            impeg2d_bit_stream_flush(ps_stream,(cbpValue >> 8) & 0x0FF);
+        }
+        else
+        {
+            ps_dec->u2_cbp  = 0;
+        }
+    }
+}
+
+/*******************************************************************************
+*  Function Name   : impeg2d_dec_p_b_slice
+*
+*  Description     : Decodes P and B slices
+*
+*  Arguments       :
+*  dec             : Decoder state
+*
+*  Values Returned : None
+*******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_dec_p_b_slice(dec_state_t *ps_dec)
+{
+    WORD16 *pi2_vld_out;
+    UWORD32 i;
+    yuv_buf_t *ps_cur_frm_buf      = &ps_dec->s_cur_frm_buf;
+
+    UWORD32 u4_frm_offset          = 0;
+    const dec_mb_params_t *ps_dec_mb_params;
+    IMPEG2D_ERROR_CODES_T e_error   = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+
+    pi2_vld_out = ps_dec->ai2_vld_buf;
+    memset(ps_dec->ai2_pred_mv,0,sizeof(ps_dec->ai2_pred_mv));
+
+    ps_dec->u2_prev_intra_mb    = 0;
+    ps_dec->u2_first_mb       = 1;
+
+    ps_dec->u2_picture_width = ps_dec->u2_frame_width;
+
+    if(ps_dec->u2_picture_structure != FRAME_PICTURE)
+    {
+        ps_dec->u2_picture_width <<= 1;
+        if(ps_dec->u2_picture_structure == BOTTOM_FIELD)
+        {
+            u4_frm_offset = ps_dec->u2_frame_width;
+        }
+    }
+
+    do
+    {
+        UWORD32 u4_x_offset, u4_y_offset;
+
+
+
+        UWORD32 u4_x_dst_offset = 0;
+        UWORD32 u4_y_dst_offset = 0;
+        UWORD8  *pu1_out_p;
+        UWORD8  *pu1_pred;
+        WORD32 u4_pred_strd;
+
+        IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
+
+
+        if(ps_dec->e_pic_type == B_PIC)
+            impeg2d_dec_pnb_mb_params(ps_dec);
+        else
+            impeg2d_dec_p_mb_params(ps_dec);
+
+        IMPEG2D_TRACE_MB_START(ps_dec->u2_mb_x, ps_dec->u2_mb_y);
+
+        u4_x_dst_offset = u4_frm_offset + (ps_dec->u2_mb_x << 4);
+        u4_y_dst_offset = (ps_dec->u2_mb_y << 4) * ps_dec->u2_picture_width;
+        pu1_out_p = ps_cur_frm_buf->pu1_y + u4_x_dst_offset + u4_y_dst_offset;
+        if(ps_dec->u2_prev_intra_mb == 0)
+        {
+            UWORD32 offset_x, offset_y, stride;
+            UWORD16 index = (ps_dec->u2_motion_type);
+            /*only for non intra mb's*/
+            if(ps_dec->e_mb_pred == BIDIRECT)
+            {
+                ps_dec_mb_params = &ps_dec->ps_func_bi_direct[index];
+            }
+            else
+            {
+                ps_dec_mb_params = &ps_dec->ps_func_forw_or_back[index];
+            }
+
+            stride = ps_dec->u2_picture_width;
+
+            offset_x = u4_frm_offset + (ps_dec->u2_mb_x << 4);
+
+            offset_y = (ps_dec->u2_mb_y << 4);
+
+            ps_dec->s_dest_buf.pu1_y = ps_cur_frm_buf->pu1_y + offset_y * stride + offset_x;
+
+            stride = stride >> 1;
+
+            ps_dec->s_dest_buf.pu1_u = ps_cur_frm_buf->pu1_u + (offset_y >> 1) * stride
+                            + (offset_x >> 1);
+
+            ps_dec->s_dest_buf.pu1_v = ps_cur_frm_buf->pu1_v + (offset_y >> 1) * stride
+                            + (offset_x >> 1);
+
+            PROFILE_DISABLE_MC_IF0
+            ps_dec_mb_params->pf_mc(ps_dec);
+
+        }
+        for(i = 0; i < NUM_LUMA_BLKS; ++i)
+        {
+            if((ps_dec->u2_cbp & (1 << (BLOCKS_IN_MB - 1 - i))) != 0)
+            {
+                e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
+                              ps_dec->u2_prev_intra_mb, Y_LUMA, 0);
+                if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+                {
+                    return e_error;
+                }
+
+                u4_x_offset = gai2_impeg2_blk_x_off[i];
+
+                if(ps_dec->u2_field_dct == 0)
+                    u4_y_offset = gai2_impeg2_blk_y_off_frm[i] ;
+                else
+                    u4_y_offset = gai2_impeg2_blk_y_off_fld[i] ;
+
+
+
+
+
+                IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
+
+                PROFILE_DISABLE_IDCT_IF0
+                {
+                    WORD32 idx;
+                    if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+                        idx = 0;
+                    else
+                        idx = 1;
+
+                    if(0 == ps_dec->u2_prev_intra_mb)
+                    {
+                        pu1_pred = pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset;
+                        u4_pred_strd = ps_dec->u2_picture_width << ps_dec->u2_field_dct;
+                    }
+                    else
+                    {
+                        pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
+                        u4_pred_strd = 8;
+                    }
+
+                    ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
+                                                            ps_dec->ai2_idct_stg1,
+                                                            pu1_pred,
+                                                            pu1_out_p + u4_y_offset * ps_dec->u2_picture_width + u4_x_offset,
+                                                            8,
+                                                            u4_pred_strd,
+                                                            ps_dec->u2_picture_width << ps_dec->u2_field_dct,
+                                                            ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
+                }
+            }
+
+        }
+
+        /* For U and V blocks, divide the x and y offsets by 2. */
+        u4_x_dst_offset >>= 1;
+        u4_y_dst_offset >>= 2;
+
+
+        /* In case of chrominance blocks the DCT will be frame DCT */
+        /* i = 0, U component and i = 1 is V componet */
+        if((ps_dec->u2_cbp & 0x02) != 0)
+        {
+            pu1_out_p = ps_cur_frm_buf->pu1_u + u4_x_dst_offset + u4_y_dst_offset;
+            e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
+                          ps_dec->u2_prev_intra_mb, U_CHROMA, 0);
+            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+            {
+                return e_error;
+            }
+
+
+            IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
+
+            PROFILE_DISABLE_IDCT_IF0
+            {
+                WORD32 idx;
+                if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+                    idx = 0;
+                else
+                    idx = 1;
+
+                if(0 == ps_dec->u2_prev_intra_mb)
+                {
+                    pu1_pred = pu1_out_p;
+                    u4_pred_strd = ps_dec->u2_picture_width >> 1;
+                }
+                else
+                {
+                    pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
+                    u4_pred_strd = 8;
+                }
+
+                ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
+                                                        ps_dec->ai2_idct_stg1,
+                                                        pu1_pred,
+                                                        pu1_out_p,
+                                                        8,
+                                                        u4_pred_strd,
+                                                        ps_dec->u2_picture_width >> 1,
+                                                        ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
+
+            }
+
+        }
+
+
+        if((ps_dec->u2_cbp & 0x01) != 0)
+        {
+            pu1_out_p = ps_cur_frm_buf->pu1_v + u4_x_dst_offset + u4_y_dst_offset;
+            e_error = ps_dec->pf_vld_inv_quant(ps_dec, pi2_vld_out, ps_dec->pu1_inv_scan_matrix,
+                          ps_dec->u2_prev_intra_mb, V_CHROMA, 0);
+            if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+            {
+                return e_error;
+            }
+
+
+            IMPEG2D_IDCT_INP_STATISTICS(pi2_vld_out, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
+
+            PROFILE_DISABLE_IDCT_IF0
+            {
+                WORD32 idx;
+                if(1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+                    idx = 0;
+                else
+                    idx = 1;
+                if(0 == ps_dec->u2_prev_intra_mb)
+                {
+                    pu1_pred = pu1_out_p;
+                    u4_pred_strd = ps_dec->u2_picture_width >> 1;
+                }
+                else
+                {
+                    pu1_pred = (UWORD8 *)gau1_impeg2_zerobuf;
+                    u4_pred_strd = 8;
+                }
+
+                ps_dec->pf_idct_recon[idx * 2 + ps_dec->i4_last_value_one](pi2_vld_out,
+                                                        ps_dec->ai2_idct_stg1,
+                                                        pu1_pred,
+                                                        pu1_out_p,
+                                                        8,
+                                                        u4_pred_strd,
+                                                        ps_dec->u2_picture_width >> 1,
+                                                        ~ps_dec->u4_non_zero_cols, ~ps_dec->u4_non_zero_rows);
+
+            }
+        }
+
+
+        ps_dec->u2_num_mbs_left--;
+        ps_dec->u2_first_mb = 0;
+        ps_dec->u2_mb_x++;
+
+        if(ps_dec->s_bit_stream.u4_offset > ps_dec->s_bit_stream.u4_max_offset)
+        {
+            return IMPEG2D_BITSTREAM_BUFF_EXCEEDED_ERR;
+        }
+        else if ((ps_dec->u2_mb_x == ps_dec->u2_num_horiz_mb) && ((ps_dec->s_bit_stream.u4_offset + START_CODE_PREFIX_LEN) < ps_dec->s_bit_stream.u4_max_offset))
+        {
+            ps_dec->u2_mb_x = 0;
+            ps_dec->u2_mb_y++;
+
+        }
+    }
+    while(ps_dec->u2_num_mbs_left != 0 && impeg2d_bit_stream_nxt(&ps_dec->s_bit_stream,23) != 0x0);
+    return e_error;
+}
diff --git a/decoder/impeg2d_structs.h b/decoder/impeg2d_structs.h
new file mode 100755
index 0000000..63a0b03
--- /dev/null
+++ b/decoder/impeg2d_structs.h
@@ -0,0 +1,377 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#ifndef __IMPEG2D_STRUCTS_H__
+#define __IMPEG2D_STRUCTS_H__
+
+typedef enum
+{
+    CMD_PROCESS,
+    CMD_FMTCONV,
+}e_jobq_cmd_t;
+
+/**
+ * Structure to represent a processing job entry
+ */
+typedef struct
+{
+    /**
+     * Command
+     * Currently: PROCESS, FMTCONV are the only two jobs
+     */
+    WORD32 i4_cmd;
+
+    /**
+     * MB y of the starting MB
+     */
+    WORD16 i2_start_mb_y;
+
+    /**
+     * MB y of the last MB
+     */
+
+    WORD16 i2_end_mb_y;
+
+    /**
+     * Bitstream offset for the current job
+     */
+    WORD32 i4_bistream_ofst;
+
+}job_t;
+
+typedef struct
+{
+    /* Params of the reference buffer used as input to MC */
+    UWORD32 u4_src_wd;
+    UWORD32 u4_src_offset;
+
+    /* Params of the buffer where MC output will be written */
+    UWORD32 u4_dst_wd_res_buf;
+    UWORD32 u4_dst_wd_cur_frm;
+    UWORD32 u4_dst_offset_res_buf;
+    UWORD32 u4_dst_offset_cur_frm;
+
+    /* Operation Parameters */
+    UWORD32 u4_rows;
+    UWORD32 u4_cols;
+    UWORD32 u4_mode;
+}comp_mc_params_t;
+
+typedef struct
+{
+    yuv_buf_t        s_ref;
+    comp_mc_params_t s_luma;
+    comp_mc_params_t s_chroma;
+}mb_mc_params_t;
+
+struct _dec_mb_params_t;
+
+typedef UWORD8 pf_inv_quant_t (WORD16 *blk,
+                                UWORD8 *weighting_matrix,
+                                UWORD8 quant_scale,
+                                WORD32 intra_flag,
+                                WORD32 i4_num_coeffs,
+                                WORD16 *pi2_coeffs,
+                                UWORD8 *pu1_pos,
+                                const UWORD8   *scan,
+                                UWORD16 *u2_def_dc_pred,
+                                UWORD16 u2_intra_dc_precision);
+
+typedef IMPEG2D_ERROR_CODES_T  pf_vld_inv_quant_t  (void  *dec,
+                             WORD16       *out_addr,
+                             const UWORD8 *scan,
+                             UWORD16      intra_flag,
+                             UWORD16      colr_comp,
+                             UWORD16      d_picture);
+
+typedef void  pf_mc_t(void *, UWORD8 *, UWORD32 , UWORD8 *, UWORD32 ,
+                 UWORD32 , UWORD32  );
+
+typedef struct dec_state_struct_t
+{
+    WORD16          ai2_vld_buf[NUM_PELS_IN_BLOCK];
+    WORD16          ai2_idct_stg1[NUM_PELS_IN_BLOCK];
+
+
+    UWORD8          au1_intra_quant_matrix[NUM_PELS_IN_BLOCK];
+    UWORD8          au1_inter_quant_matrix[NUM_PELS_IN_BLOCK];
+
+    IMPEG2D_ERROR_CODES_T (*pf_decode_slice)(struct dec_state_struct_t *);
+
+    pf_vld_inv_quant_t *pf_vld_inv_quant;
+
+    pf_idct_recon_t *pf_idct_recon[4];
+
+    pf_mc_t         *pf_mc[4];
+    pf_interpred_t  *pf_fullx_halfy_8x8;
+    pf_interpred_t  *pf_halfx_fully_8x8;
+    pf_interpred_t  *pf_halfx_halfy_8x8;
+    pf_interpred_t  *pf_fullx_fully_8x8;
+
+
+    pf_interpolate_t *pf_interpolate;
+    pf_copy_mb_t     *pf_copy_mb;
+
+    pf_memset0_one_16bit_buf_t *pf_memset_16bit_8x8_linear_block;
+    pf_memset_8bit_t    *pf_memset_8bit_8x8_block;
+    pf_copy_yuv420p_buf_t *pf_copy_yuv420p_buf;
+    pf_fmt_conv_yuv420p_to_yuv422ile_t *pf_fmt_conv_yuv420p_to_yuv422ile;
+    pf_fmt_conv_yuv420p_to_yuv420sp_t  *pf_fmt_conv_yuv420p_to_yuv420sp_uv;
+    pf_fmt_conv_yuv420p_to_yuv420sp_t  *pf_fmt_conv_yuv420p_to_yuv420sp_vu;
+
+    stream_t         s_bit_stream;
+/* @ */
+
+    UWORD16         u2_is_mpeg2; /* 0 if stream is MPEG1 1 otherwise */
+    UWORD16         u2_frame_width;  /* Width of the frame */
+    UWORD16         u2_frame_height; /* Height of the frame */
+    UWORD16         u2_picture_width;
+    UWORD16         u2_horizontal_size;
+    UWORD16         u2_vertical_size;
+    UWORD16         u2_create_max_width;
+    UWORD16         u2_create_max_height;
+    UWORD16         u2_reinit_max_width;
+    UWORD16         u2_reinit_max_height;
+    UWORD16         u2_header_done;
+    UWORD16         u2_decode_header;
+
+    UWORD16         u2_mb_x;
+    UWORD16         u2_mb_y;
+    UWORD16         u2_num_horiz_mb;
+    UWORD16         u2_num_vert_mb;
+    UWORD16         u2_num_flds_decoded;
+    void            *pv_pic_buf_mg;
+
+    UWORD32         u4_frm_buf_stride; /* for display Buffer */
+
+    UWORD16         u2_field_dct;
+    UWORD16         u2_read_dct_type;
+
+    UWORD16         u2_read_motion_type;
+    UWORD16         u2_motion_type;
+
+    const UWORD16   *pu2_mb_type;
+    UWORD16         u2_fld_pic;
+    UWORD16         u2_frm_pic;
+
+    yuv_buf_t       s_cur_frm_buf;
+
+    UWORD16         u2_fld_parity;
+    UWORD16         u2_def_dc_pred[MAX_COLR_COMPS];
+
+    /* Variables related to Motion Vector predictors */
+
+    WORD16          ai2_pred_mv[2][2][2];
+    e_pred_direction_t   e_mb_pred;
+    UWORD16         au2_fcode_data[2];
+
+    /* Variables related to reference pictures */
+    yuv_buf_t       as_recent_fld[2][2];
+
+    UWORD8          u1_quant_scale;
+    UWORD16         u2_num_mbs_left;
+    UWORD16         u2_first_mb;
+    UWORD16         u2_num_skipped_mbs;
+
+    UWORD8          *pu1_inv_scan_matrix;
+
+    UWORD16         u2_progressive_sequence;
+    e_pic_type_t         e_pic_type;
+
+    UWORD16         u2_full_pel_forw_vector;
+    UWORD16         u2_forw_f_code;
+    UWORD16         u2_full_pel_back_vector;
+    UWORD16         u2_back_f_code;
+
+    WORD16          ai2_mv[2][2][2]; /* Motion vectors */
+
+    /* Bitstream code present in Picture coding extension */
+    UWORD16         au2_f_code[2][2];
+    UWORD16         u2_intra_dc_precision;
+    UWORD16         u2_picture_structure;
+    UWORD16         u2_top_field_first;
+    UWORD16         u2_frame_pred_frame_dct;
+    UWORD16         u2_concealment_motion_vectors;
+    UWORD16         u2_q_scale_type;
+    UWORD16         u2_intra_vlc_format;
+    UWORD16         u2_alternate_scan;
+    UWORD16         u2_repeat_first_field;
+    UWORD16         u2_progressive_frame;
+
+
+    /* Bitstream code related to frame rate of the bitstream */
+    UWORD16         u2_frame_rate_code;
+    UWORD16         u2_frame_rate_extension_n;
+    UWORD16         u2_frame_rate_extension_d;
+    UWORD16         u2_framePeriod;   /* Frame period in milli seconds */
+
+    /* Members related to display dimensions of bitstream */
+    /* The size values may not be returned right now. But they are read */
+    /* and can be returned if there is a requirement.                   */
+    UWORD16         u2_display_horizontal_size;
+    UWORD16         u2_display_vertical_size;
+    UWORD16         u2_aspect_ratio_info;
+
+    /* Members related to motion compensation */
+    yuv_buf_t       s_mc_fw_buf;
+    yuv_buf_t       s_mc_bk_buf;
+    yuv_buf_t       s_mc_buf;
+    mb_mc_params_t  as_mb_mc_params[2][2];
+    yuv_buf_t       as_ref_buf[2][2];
+    e_mb_type_t       s_mb_type;
+
+    yuv_buf_t       s_dest_buf;
+
+    /* Variable to handle intra MB */
+    UWORD16         u2_prev_intra_mb;
+    UWORD16         u2_coded_mb;
+
+    /* Bidirect function pointers */
+    const struct _dec_mb_params_t *ps_func_bi_direct;
+
+    /* Forw or Back function pointers */
+    const struct _dec_mb_params_t *ps_func_forw_or_back;
+
+
+    /* CBP of the current MB        */
+    UWORD16         u2_cbp;
+    void            *pv_video_scratch;
+
+
+    /* For global error handling */
+    void            *pv_stack_cntxt;
+
+/* @ */
+    WORD32          i4_chromaFormat;
+    UWORD32         u4_xdmBufID;
+    UWORD32         u4_num_mem_records;
+    /* For holding memRecords */
+    void            *pv_memTab;
+
+    UWORD8          u1_flushfrm;
+    UWORD8          u1_flushcnt;
+    iv_yuv_buf_t    as_frame_buf[MAX_FRAME_BUFFER];
+    iv_yuv_buf_t    ps_yuv_buf;
+
+    ivd_get_display_frame_op_t  s_disp_op;
+
+
+    UWORD32         u4_non_zero_cols;
+    UWORD32         u4_non_zero_rows;
+
+    UWORD32         u4_num_frames_decoded;
+
+    /* Adding error code variable to signal benign errors. */
+    UWORD32         u4_error_code;
+
+    WORD32          i4_num_cores;
+
+    UWORD8          u1_first_frame_done;
+
+    void            *pv_codec_thread_handle;
+    void            *ps_dec_state_multi_core;
+    UWORD32         u4_inp_ts;
+    pic_buf_t       *ps_cur_pic;
+    pic_buf_t       *ps_disp_pic;
+    pic_buf_t       *aps_ref_pics[2];
+
+    WORD32          i4_disp_buf_id;
+    WORD32          i4_cur_buf_id;
+    iv_yuv_buf_t    *ps_disp_frm_buf;
+
+    UWORD32         u4_share_disp_buf;
+    void            *pv_pic_buf_base;
+
+    disp_mgr_t      s_disp_mgr;
+    UWORD8          *pu1_chroma_ref_buf[BUF_MGR_MAX_CNT];
+    ivd_out_bufdesc_t as_disp_buffers[BUF_MGR_MAX_CNT];
+
+    /* Flag to signal last coeff in a 8x8 block is one
+    after mismatch contol */
+    WORD32          i4_last_value_one;
+
+    WORD32          i4_start_mb_y;
+    WORD32          i4_end_mb_y;
+
+    /**
+     * Job queue buffer base
+     */
+    void            *pv_jobq_buf;
+
+    /**
+     * Job Queue mem tab size
+     */
+    WORD32          i4_jobq_buf_size;
+
+    /**
+     * Job Queue context
+     */
+    void            *pv_jobq;
+
+    /* Pointer to input bitstream */
+    UWORD8          *pu1_inp_bits_buf;
+
+    /* Number of bytes in the input bitstream */
+    UWORD32         u4_num_inp_bytes;
+
+    /* Bytes consumed */
+    WORD32          i4_bytes_consumed;
+
+    IVD_ARCH_T      e_processor_arch;
+
+    IVD_SOC_T       e_processor_soc;
+
+    WORD32          i4_frame_decoded;
+
+}dec_state_t;
+
+
+
+
+typedef void (*func_decmb_params)(dec_state_t *);
+typedef void  (*mc_funcs)(dec_state_t *);
+typedef struct _dec_mb_params_t
+{
+    func_decmb_params    pf_func_mb_params;
+    e_mb_type_t            s_mb_type;
+    mc_funcs             pf_mc;
+}dec_mb_params_t;
+
+
+
+#define MAX_THREADS     4
+
+
+#define MAX_MB_ROWS     (MAX_HEIGHT / 16) // number of rows for 1080p
+
+typedef struct _dec_state_multi_core
+{
+    // contains the decoder state of decoder for each thread
+    dec_state_t *ps_dec_state[MAX_THREADS];
+    UWORD32     au4_thread_launched[MAX_THREADS];
+    // number of rows: first thread will populate the row offsets and update
+    // row_offset_cnt. Other threads should pick up offset from this thread
+    // and start decoding
+    UWORD32     au4_row_offset[MAX_MB_ROWS];
+    volatile    UWORD32 u4_row_offset_cnt;
+}dec_state_multi_core_t;
+
+
+
+#endif /* #ifndef __IMPEG2D_STRUCTS_H__ */
diff --git a/decoder/impeg2d_vld.c b/decoder/impeg2d_vld.c
new file mode 100644
index 0000000..972f42a
--- /dev/null
+++ b/decoder/impeg2d_vld.c
@@ -0,0 +1,1183 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+
+
+/*******************************************************************************
+* Function name : impeg2d_dec_vld_symbol
+*
+* Description   : Performs decoding of VLD symbol. It performs decoding by
+*                 processing 1 bit at a time
+*
+* Arguments     :
+* stream        : Bitstream
+* ai2_code_table     : Table used for decoding
+* maxLen        : Maximum Length of the decoded symbol in bits
+*
+* Value Returned: Decoded symbol
+*******************************************************************************/
+WORD16 impeg2d_dec_vld_symbol(stream_t *ps_stream,const WORD16 ai2_code_table[][2],  UWORD16 u2_max_len)
+{
+  UWORD16 u2_data;
+  WORD16  u2_end = 0;
+  UWORD16 u2_org_max_len = u2_max_len;
+  UWORD16 u2_i_bit;
+
+  /* Get the maximum number of bits needed to decode a symbol */
+  u2_data = impeg2d_bit_stream_nxt(ps_stream,u2_max_len);
+  do
+  {
+    u2_max_len--;
+    /* Read one bit at a time from the variable to decode the huffman code */
+    u2_i_bit = (UWORD8)((u2_data >> u2_max_len) & 0x1);
+
+    /* Get the next node pointer or the symbol from the tree */
+    u2_end = ai2_code_table[u2_end][u2_i_bit];
+  }while(u2_end > 0);
+
+  /* Flush the appropriate number of bits from the ps_stream */
+  impeg2d_bit_stream_flush(ps_stream,(UWORD8)(u2_org_max_len - u2_max_len));
+  return(u2_end);
+}
+/*******************************************************************************
+* Function name : impeg2d_fast_dec_vld_symbol
+*
+* Description   : Performs decoding of VLD symbol. It performs decoding by
+*                 processing n bits at a time
+*
+* Arguments     :
+* stream        : Bitstream
+* ai2_code_table     : Code table containing huffman value
+* indexTable    : Index table containing index
+* maxLen        : Maximum Length of the decoded symbol in bits
+*
+* Value Returned: Decoded symbol
+*******************************************************************************/
+WORD16 impeg2d_fast_dec_vld_symbol(stream_t *ps_stream,
+                     const WORD16  ai2_code_table[][2],
+                     const UWORD16 au2_indexTable[][2],
+                     UWORD16 u2_max_len)
+{
+    UWORD16 u2_cur_code;
+    UWORD16 u2_num_bits;
+    UWORD16 u2_vld_offset;
+    UWORD16 u2_start_len;
+    WORD16  u2_value;
+    UWORD16 u2_len;
+    UWORD16 u2_huffCode;
+
+    u2_start_len  = au2_indexTable[0][0];
+    u2_vld_offset = 0;
+    u2_huffCode  = impeg2d_bit_stream_nxt(ps_stream,u2_max_len);
+    do
+    {
+        u2_cur_code = u2_huffCode >> (u2_max_len - u2_start_len);
+        u2_num_bits = ai2_code_table[u2_cur_code + u2_vld_offset][0];
+        if(u2_num_bits == 0)
+        {
+            u2_huffCode  &= ((1 << (u2_max_len - u2_start_len)) - 1);
+            u2_max_len    -= u2_start_len;
+            u2_start_len   = au2_indexTable[ai2_code_table[u2_cur_code + u2_vld_offset][1]][0];
+            u2_vld_offset  = au2_indexTable[ai2_code_table[u2_cur_code + u2_vld_offset][1]][1];
+        }
+        else
+        {
+            u2_value = ai2_code_table[u2_cur_code + u2_vld_offset][1];
+            u2_len   = u2_num_bits;
+        }
+    }while(u2_num_bits == 0);
+    impeg2d_bit_stream_flush(ps_stream,u2_len);
+    return(u2_value);
+}
+/******************************************************************************
+*
+*  Function Name   : impeg2d_dec_ac_coeff_zero
+*
+*  Description     : Decodes using Table B.14
+*
+*  Arguments       : Pointer to VideoObjectLayerStructure
+*
+*  Values Returned : Decoded value
+*
+*  Revision History:
+*
+*         28 02 2002  AR        Creation
+*******************************************************************************/
+UWORD16 impeg2d_dec_ac_coeff_zero(stream_t *ps_stream, UWORD16* pu2_sym_len, UWORD16* pu2_sym_val)
+{
+    UWORD16 u2_offset,u2_decoded_value;
+    UWORD8  u1_shift;
+    UWORD32 u4_bits_read;
+
+    u4_bits_read = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,MPEG2_AC_COEFF_MAX_LEN);
+
+    if ((UWORD16)u4_bits_read >= 0x0800)
+    {
+        u2_offset = (UWORD16)u4_bits_read >> 11;
+    }
+    else if ((UWORD16)u4_bits_read >= 0x40)
+    {
+        u2_offset = 31 + ((UWORD16)u4_bits_read >> 6);
+    }
+    else if ((UWORD16)u4_bits_read >= 0x20)
+    {
+        u2_offset = 64;
+    }
+    else
+    {
+        u2_offset      = 63;
+        u4_bits_read    = (UWORD16)u4_bits_read - 0x10;
+    }
+    /*-----------------------------------------------------------------------
+     * The table gOffset contains both the offset for the group to which the
+     * Vld code belongs in the Ac Coeff Table and the no of bits with which
+     * the BitsRead should be shifted
+     *-----------------------------------------------------------------------*/
+    u2_offset = gau2_impeg2d_offset_zero[u2_offset];
+    u1_shift  = u2_offset & 0xF;
+
+    /*-----------------------------------------------------------------------
+     * Depending upon the vld code, we index exactly to that particular
+     * Vld codes value in the Ac Coeff Table.
+     * (Offset >> 4)       gives the offset for the group in the AcCoeffTable.
+     * (BitsRead >> shift) gives the offset within its group
+     *-----------------------------------------------------------------------*/
+     u2_offset = (u2_offset >> 4) + ((UWORD16)u4_bits_read >> u1_shift);
+    /*-----------------------------------------------------------------------
+     * DecodedValue has the Run, Level and the number of bits used by Vld code
+     *-----------------------------------------------------------------------*/
+    u2_decoded_value = gau2_impeg2d_dct_coeff_zero[u2_offset];
+    if(u2_decoded_value == END_OF_BLOCK)
+    {
+        *pu2_sym_len = 2;
+        *pu2_sym_val = EOB_CODE_VALUE;
+    }
+    else if(u2_decoded_value == ESCAPE_CODE)
+    {
+        *pu2_sym_len     = u2_decoded_value & 0x1F;
+        *pu2_sym_val = ESC_CODE_VALUE;
+    }
+    else
+    {
+        *pu2_sym_len = u2_decoded_value & 0x1F;
+        *pu2_sym_val = u2_decoded_value >> 5;
+    }
+    return(u2_decoded_value);
+}
+
+/******************************************************************************
+*
+*  Function Name   : impeg2d_dec_ac_coeff_one
+*
+*  Description     : Decodes using Table B.15
+*
+*  Arguments       : Pointer to VideoObjectLayerStructure
+*
+*  Values Returned : Decoded value
+*
+*  Revision History:
+*
+*         28 02 2002  AR        Creation
+*******************************************************************************/
+UWORD16 impeg2d_dec_ac_coeff_one(stream_t *ps_stream, UWORD16* pu2_sym_len, UWORD16* pu2_sym_val)
+{
+    UWORD16 u2_offset, u2_decoded_value;
+    UWORD8  u1_shift;
+    UWORD32 u4_bits_read;
+
+
+    u4_bits_read = (UWORD16)impeg2d_bit_stream_nxt(ps_stream,MPEG2_AC_COEFF_MAX_LEN);
+
+    if ((UWORD16)u4_bits_read >= 0x8000)
+    {
+        /* If the MSB of the vld code is 1 */
+        if (((UWORD16)u4_bits_read >> 12) == 0xF)
+            u2_offset = ((UWORD16)u4_bits_read >> 8) & 0xF;
+        else
+            u2_offset = (UWORD16)u4_bits_read >> 11;
+        u2_offset += gau2_impeg2d_offset_one[0];
+    }
+    else if ((UWORD16)u4_bits_read >= 0x400)
+    {
+        u2_offset =(UWORD16) u4_bits_read >> 10;
+        u2_offset = gau2_impeg2d_offset_one[u2_offset];
+        u1_shift = u2_offset & 0xF;
+        u2_offset = (u2_offset >> 4) + ((UWORD16)u4_bits_read >> u1_shift);
+    }
+    else if ((UWORD16)u4_bits_read >= 0x20)
+    {
+        u2_offset = ((UWORD16)u4_bits_read >> 5) + 31;
+        u2_offset = gau2_impeg2d_offset_one[u2_offset];
+        u1_shift = u2_offset & 0xF;
+        u2_offset = (u2_offset >> 4) + ((UWORD16)u4_bits_read >> u1_shift);
+    }
+    else
+    {
+        u2_offset = gau2_impeg2d_offset_one[63] + ((UWORD16)u4_bits_read & 0xF);
+    }
+    /*-----------------------------------------------------------------------
+    * DecodedValue has the Run, Level and the number of bits used by Vld code
+    *-----------------------------------------------------------------------*/
+    u2_decoded_value = gau2_impeg2d_dct_coeff_one[u2_offset];
+
+    if(u2_decoded_value == END_OF_BLOCK)
+    {
+        *pu2_sym_len = 4;
+        *pu2_sym_val = EOB_CODE_VALUE;
+    }
+    else if(u2_decoded_value == ESCAPE_CODE)
+    {
+        *pu2_sym_len     = u2_decoded_value & 0x1F;
+        *pu2_sym_val = ESC_CODE_VALUE;
+    }
+    else
+    {
+        *pu2_sym_len = u2_decoded_value & 0x1F;
+        *pu2_sym_val = u2_decoded_value >> 5;
+    }
+
+    return(u2_decoded_value);
+}
+
+/******************************************************************************
+ *
+ *  Function Name   : impeg2d_vld_inv_quant_mpeg1
+ *
+ *  Description     : Performs VLD operation for MPEG1/2
+ *
+ *  Arguments       :
+ *  state           : VLCD state parameter
+ *  regs            : Registers of VLCD
+ *
+ *  Values Returned : None
+ ******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_vld_inv_quant_mpeg1(
+                             void  *pv_dec,           /* Decoder State */
+                             WORD16       *pi2_out_addr,       /*!< Address where decoded symbols will be stored */
+                             const UWORD8 *pu1_scan,          /*!< Scan table to be used */
+                             UWORD16      u2_intra_flag,      /*!< Intra Macroblock or not */
+                             UWORD16      u2_colr_comp,      /*!< 0 - Luma,1 - U comp, 2 - V comp */
+                             UWORD16      u2_d_picture        /*!< D Picture or not */
+                             )
+{
+    UWORD8  *pu1_weighting_matrix;
+    dec_state_t *ps_dec    = (dec_state_t *) pv_dec;
+    IMPEG2D_ERROR_CODES_T e_error   = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+
+    WORD16  pi2_coeffs[NUM_COEFFS];
+    UWORD8  pu1_pos[NUM_COEFFS];
+    WORD32  i4_num_coeffs;
+
+    /* Perform VLD on the stream to get the coefficients and their positions */
+    e_error = impeg2d_vld_decode(ps_dec, pi2_coeffs, pu1_scan, pu1_pos, u2_intra_flag,
+                                 u2_colr_comp, u2_d_picture, ps_dec->u2_intra_vlc_format,
+                                 ps_dec->u2_is_mpeg2, &i4_num_coeffs);
+    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+    {
+        return e_error;
+    }
+
+    /* For YUV420 format,Select the weighting matrix according to Table 7.5 */
+    pu1_weighting_matrix = (u2_intra_flag == 1) ? ps_dec->au1_intra_quant_matrix:
+                    ps_dec->au1_inter_quant_matrix;
+
+    IMPEG2D_IQNT_INP_STATISTICS(pi2_out_addr, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
+    /* Inverse Quantize the Output of VLD */
+    PROFILE_DISABLE_INVQUANT_IF0
+
+    {
+        /* Clear output matrix */
+        PROFILE_DISABLE_MEMSET_RESBUF_IF0
+        if (1 != (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+        {
+            ps_dec->pf_memset_16bit_8x8_linear_block (pi2_out_addr);
+        }
+
+        impeg2d_inv_quant_mpeg1(pi2_out_addr, pu1_weighting_matrix,
+                                  ps_dec->u1_quant_scale, u2_intra_flag,
+                                  i4_num_coeffs, pi2_coeffs, pu1_pos,
+                                  pu1_scan, &ps_dec->u2_def_dc_pred[u2_colr_comp],
+                                  ps_dec->u2_intra_dc_precision);
+
+        if (0 != pi2_out_addr[0])
+        {
+            /* The first coeff might've become non-zero due to intra_dc_decision
+             * value. So, check here after inverse quantization.
+             */
+            ps_dec->u4_non_zero_cols  |= 0x1;
+            ps_dec->u4_non_zero_rows  |= 0x1;
+        }
+    }
+
+    return e_error;
+}
+
+/******************************************************************************
+  *
+  *  Function Name   : impeg2d_vld_inv_quant_mpeg2
+  *
+  *  Description     : Performs VLD operation for MPEG1/2
+  *
+  *  Arguments       :
+  *  state           : VLCD state parameter
+  *  regs            : Registers of VLCD
+  *
+  *  Values Returned : None
+  ******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_vld_inv_quant_mpeg2(
+                             void  *pv_dec,           /* Decoder State */
+                             WORD16       *pi2_out_addr,       /*!< Address where decoded symbols will be stored */
+                             const UWORD8 *pu1_scan,          /*!< Scan table to be used */
+                             UWORD16      u2_intra_flag,      /*!< Intra Macroblock or not */
+                             UWORD16      u2_colr_comp,      /*!< 0 - Luma,1 - U comp, 2 - V comp */
+                             UWORD16      u2_d_picture        /*!< D Picture or not */
+                             )
+{
+    UWORD8  *pu1_weighting_matrix;
+    WORD32 u4_sum_is_even;
+    dec_state_t *ps_dec = (dec_state_t *)pv_dec;
+    IMPEG2D_ERROR_CODES_T e_error = (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+
+    WORD16  pi2_coeffs[NUM_COEFFS];
+    UWORD8  pi4_pos[NUM_COEFFS];
+    WORD32  i4_num_coeffs;
+
+    /* Perform VLD on the stream to get the coefficients and their positions */
+    e_error = impeg2d_vld_decode(ps_dec, pi2_coeffs, pu1_scan, pi4_pos, u2_intra_flag,
+                                 u2_colr_comp, u2_d_picture, ps_dec->u2_intra_vlc_format,
+                                 ps_dec->u2_is_mpeg2, &i4_num_coeffs);
+    if ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE != e_error)
+    {
+        return e_error;
+    }
+
+    /* For YUV420 format,Select the weighting matrix according to Table 7.5 */
+    pu1_weighting_matrix = (u2_intra_flag == 1) ? ps_dec->au1_intra_quant_matrix:
+                    ps_dec->au1_inter_quant_matrix;
+
+    /*mismatch control for mpeg2*/
+    /* Check if the block has only one non-zero coeff which is DC  */
+    ps_dec->i4_last_value_one = 0;
+
+    IMPEG2D_IQNT_INP_STATISTICS(pi2_out_addr, ps_dec->u4_non_zero_cols, ps_dec->u4_non_zero_rows);
+
+    /* Inverse Quantize the Output of VLD */
+    PROFILE_DISABLE_INVQUANT_IF0
+
+    {
+        /* Clear output matrix */
+        PROFILE_DISABLE_MEMSET_RESBUF_IF0
+        if (1 != (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+        {
+            ps_dec->pf_memset_16bit_8x8_linear_block (pi2_out_addr);
+        }
+
+        u4_sum_is_even  = impeg2d_inv_quant_mpeg2(pi2_out_addr, pu1_weighting_matrix,
+                                                 ps_dec->u1_quant_scale, u2_intra_flag,
+                                                 i4_num_coeffs, pi2_coeffs,
+                                                 pi4_pos, pu1_scan,
+                                                 &ps_dec->u2_def_dc_pred[u2_colr_comp],
+                                                 ps_dec->u2_intra_dc_precision);
+
+        if (0 != pi2_out_addr[0])
+        {
+            /* The first coeff might've become non-zero due to intra_dc_decision
+             * value. So, check here after inverse quantization.
+             */
+            ps_dec->u4_non_zero_cols  |= 0x1;
+            ps_dec->u4_non_zero_rows  |= 0x1;
+        }
+
+        if (1 == (ps_dec->u4_non_zero_cols | ps_dec->u4_non_zero_rows))
+        {
+            ps_dec->i4_last_value_one = 1 - (pi2_out_addr[0] & 1);
+        }
+        else
+        {
+            /*toggle last bit if sum is even ,else retain it as it is*/
+            pi2_out_addr[63]        ^= (u4_sum_is_even & 1);
+
+            if (0 != pi2_out_addr[63])
+            {
+                ps_dec->u4_non_zero_cols  |= 0x80;
+                ps_dec->u4_non_zero_rows  |= 0x80;
+            }
+        }
+    }
+
+    return e_error;
+}
+
+
+/******************************************************************************
+*
+*  Function Name   : impeg2d_vld_decode
+*
+*  Description     : Performs VLD operation for MPEG1/2
+*
+*  Arguments       :
+*  state           : VLCD state parameter
+*  regs            : Registers of VLCD
+*
+*  Values Returned : None
+******************************************************************************/
+IMPEG2D_ERROR_CODES_T impeg2d_vld_decode(
+    dec_state_t *ps_dec,
+    WORD16      *pi2_outAddr,       /*!< Address where decoded symbols will be stored */
+    const UWORD8 *pu1_scan,         /*!< Scan table to be used */
+    UWORD8      *pu1_pos,       /*!< Scan table to be used */
+    UWORD16     u2_intra_flag,      /*!< Intra Macroblock or not */
+    UWORD16     u2_chroma_flag,     /*!< Chroma Block or not */
+    UWORD16     u2_d_picture,       /*!< D Picture or not */
+    UWORD16     u2_intra_vlc_format, /*!< Intra VLC format */
+    UWORD16     u2_mpeg2,          /*!< MPEG-2 or not */
+    WORD32      *pi4_num_coeffs /*!< Returns the number of coeffs in block */
+    )
+{
+
+    UWORD32 u4_sym_len;
+
+    UWORD32 u4_decoded_value;
+    UWORD32 u4_level_first_byte;
+    WORD32  u4_level;
+    UWORD32 u4_run, u4_numCoeffs;
+    UWORD32 u4_buf;
+    UWORD32 u4_buf_nxt;
+    UWORD32 u4_offset;
+    UWORD32 *pu4_buf_aligned;
+    UWORD32 u4_bits;
+    stream_t *ps_stream = &ps_dec->s_bit_stream;
+    WORD32  u4_pos;
+    UWORD32 u4_nz_cols;
+    UWORD32 u4_nz_rows;
+
+    *pi4_num_coeffs = 0;
+
+    ps_dec->u4_non_zero_cols = 0;
+    ps_dec->u4_non_zero_rows = 0;
+    u4_nz_cols = ps_dec->u4_non_zero_cols;
+    u4_nz_rows = ps_dec->u4_non_zero_rows;
+
+    GET_TEMP_STREAM_DATA(u4_buf,u4_buf_nxt,u4_offset,pu4_buf_aligned,ps_stream)
+    /**************************************************************************/
+    /* Decode the DC coefficient in case of Intra block                       */
+    /**************************************************************************/
+    if(u2_intra_flag)
+    {
+        WORD32 dc_size;
+        WORD32 dc_diff;
+        WORD32 maxLen;
+        WORD32 idx;
+
+
+        maxLen = MPEG2_DCT_DC_SIZE_LEN;
+        idx = 0;
+        if(u2_chroma_flag != 0)
+        {
+            maxLen += 1;
+            idx++;
+        }
+
+
+        {
+            WORD16  end = 0;
+            UWORD32 maxLen_tmp = maxLen;
+            UWORD16 m_iBit;
+
+
+            /* Get the maximum number of bits needed to decode a symbol */
+            IBITS_NXT(u4_buf,u4_buf_nxt,u4_offset,u4_bits,maxLen)
+            do
+            {
+                maxLen_tmp--;
+                /* Read one bit at a time from the variable to decode the huffman code */
+                m_iBit = (UWORD8)((u4_bits >> maxLen_tmp) & 0x1);
+
+                /* Get the next node pointer or the symbol from the tree */
+                end = gai2_impeg2d_dct_dc_size[idx][end][m_iBit];
+            }while(end > 0);
+            dc_size = end + MPEG2_DCT_DC_SIZE_OFFSET;
+
+            /* Flush the appropriate number of bits from the stream */
+            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,(maxLen - maxLen_tmp),pu4_buf_aligned)
+
+        }
+
+
+
+        if (dc_size != 0)
+        {
+            UWORD32 u4_bits;
+
+            IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned, dc_size)
+            dc_diff = u4_bits;
+
+            if ((dc_diff & (1 << (dc_size - 1))) == 0) //v Probably the prediction algo?
+                dc_diff -= (1 << dc_size) - 1;
+        }
+        else
+        {
+            dc_diff = 0;
+        }
+
+
+        pi2_outAddr[*pi4_num_coeffs]    = dc_diff;
+        /* This indicates the position of the coefficient. Since this is the DC
+         * coefficient, we put the position as 0.
+         */
+        pu1_pos[*pi4_num_coeffs]    = pu1_scan[0];
+        (*pi4_num_coeffs)++;
+
+        if (0 != dc_diff)
+        {
+            u4_nz_cols |= 0x01;
+            u4_nz_rows |= 0x01;
+        }
+
+        u4_numCoeffs = 1;
+    }
+    /**************************************************************************/
+    /* Decoding of first AC coefficient in case of non Intra block            */
+    /**************************************************************************/
+    else
+    {
+        /* First symbol can be 1s */
+        UWORD32 u4_bits;
+
+        IBITS_NXT(u4_buf,u4_buf_nxt,u4_offset,u4_bits,1)
+
+        if(u4_bits == 1)
+        {
+
+            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,1, pu4_buf_aligned)
+            IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned, 1)
+            if(u4_bits == 1)
+            {
+                pi2_outAddr[*pi4_num_coeffs] = -1;
+            }
+            else
+            {
+                pi2_outAddr[*pi4_num_coeffs] = 1;
+            }
+
+            /* This indicates the position of the coefficient. Since this is the DC
+             * coefficient, we put the position as 0.
+             */
+            pu1_pos[*pi4_num_coeffs]    = pu1_scan[0];
+            (*pi4_num_coeffs)++;
+            u4_numCoeffs = 1;
+
+            u4_nz_cols |= 0x01;
+            u4_nz_rows |= 0x01;
+        }
+        else
+        {
+            u4_numCoeffs = 0;
+        }
+    }
+    if (1 == u2_d_picture)
+    {
+        PUT_TEMP_STREAM_DATA(u4_buf, u4_buf_nxt, u4_offset, pu4_buf_aligned, ps_stream)
+        ps_dec->u4_non_zero_cols  = u4_nz_cols;
+        ps_dec->u4_non_zero_rows  = u4_nz_rows;
+        return ((IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE);
+    }
+
+
+
+        if (1 == u2_intra_vlc_format && u2_intra_flag)
+        {
+
+            while(1)
+            {
+                //Putting the impeg2d_dec_ac_coeff_one function inline.
+
+                UWORD32 lead_zeros;
+                WORD16 DecodedValue;
+
+                u4_sym_len = 17;
+                IBITS_NXT(u4_buf,u4_buf_nxt,u4_offset,u4_bits,u4_sym_len)
+
+                DecodedValue = gau2_impeg2d_tab_one_1_9[u4_bits >> 8];
+                u4_sym_len = (DecodedValue & 0xf);
+                u4_level = DecodedValue >> 9;
+                /* One table lookup */
+                if(0 != u4_level)
+                {
+                    u4_run = ((DecodedValue >> 4) & 0x1f);
+                    u4_numCoeffs       += u4_run;
+                    u4_pos             = pu1_scan[u4_numCoeffs++ & 63];
+                    pu1_pos[*pi4_num_coeffs]    = u4_pos;
+
+                    FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_sym_len,pu4_buf_aligned)
+                    pi2_outAddr[*pi4_num_coeffs]    = u4_level;
+
+                    (*pi4_num_coeffs)++;
+                }
+                else
+                {
+                    if (DecodedValue == END_OF_BLOCK_ONE)
+                    {
+                        u4_sym_len = 4;
+
+                        break;
+                    }
+                    else
+                    {
+                        /*Second table lookup*/
+                        lead_zeros = CLZ(u4_bits) - 20;/* -16 since we are dealing with WORD32 */
+                        if (0 != lead_zeros)
+                        {
+
+                            u4_bits         = (u4_bits >> (6 - lead_zeros)) & 0x001F;
+
+                            /* Flush the number of bits */
+                            if (1 == lead_zeros)
+                            {
+                                u4_sym_len         = ((u4_bits & 0x18) >> 3) == 2 ? 11:10;
+                            }
+                            else
+                            {
+                                u4_sym_len         = 11 + lead_zeros;
+                            }
+                            /* flushing */
+                            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_sym_len,pu4_buf_aligned)
+
+                            /* Calculate the address */
+                            u4_bits         = ((lead_zeros - 1) << 5) + u4_bits;
+
+                            DecodedValue    = gau2_impeg2d_tab_one_10_16[u4_bits];
+
+                            u4_run = BITS(DecodedValue, 8,4);
+                            u4_level = ((WORD16) DecodedValue) >> 9;
+
+                            u4_numCoeffs       += u4_run;
+                            u4_pos             = pu1_scan[u4_numCoeffs++ & 63];
+                            pu1_pos[*pi4_num_coeffs]    = u4_pos;
+                            pi2_outAddr[*pi4_num_coeffs]    = u4_level;
+                            (*pi4_num_coeffs)++;
+                        }
+                        /*********************************************************************/
+                        /* MPEG2 Escape Code                                                 */
+                        /*********************************************************************/
+                        else if(u2_mpeg2 == 1)
+                        {
+                            u4_sym_len         = 6;
+                            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_sym_len,pu4_buf_aligned)
+                                IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,18)
+                                u4_decoded_value    = u4_bits;
+                            u4_run             = (u4_decoded_value >> 12);
+                            u4_level           = (u4_decoded_value & 0x0FFF);
+
+                            if (u4_level)
+                                u4_level = (u4_level - ((u4_level & 0x0800) << 1));
+
+                            u4_numCoeffs       += u4_run;
+                            u4_pos             = pu1_scan[u4_numCoeffs++ & 63];
+                            pu1_pos[*pi4_num_coeffs]    = u4_pos;
+                            pi2_outAddr[*pi4_num_coeffs]    = u4_level;
+                            (*pi4_num_coeffs)++;
+                        }
+                        /*********************************************************************/
+                        /* MPEG1 Escape Code                                                 */
+                        /*********************************************************************/
+                        else
+                        {
+                            /*-----------------------------------------------------------
+                            * MPEG-1 Stream
+                            *
+                            * <See D.9.3 of MPEG-2> Run-level escape syntax
+                            * Run-level values that cannot be coded with a VLC are coded
+                            * by the escape code '0000 01' followed by
+                            * either a 14-bit FLC (127 <= level <= 127),
+                            * or a 22-bit FLC (255 <= level <= 255).
+                            * This is described in Annex B,B.5f of MPEG-1.standard
+                            *-----------------------------------------------------------*/
+
+                            /*-----------------------------------------------------------
+                            * First 6 bits are the value of the Run. Next is First 8 bits
+                            * of Level. These bits decide whether it is 14 bit FLC or
+                            * 22-bit FLC.
+                            *
+                            * If( first 8 bits of Level == '1000000' or '00000000')
+                            *      then its is 22-bit FLC.
+                            * else
+                            *      it is 14-bit FLC.
+                            *-----------------------------------------------------------*/
+                            u4_sym_len         = 6;
+                            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_sym_len,pu4_buf_aligned)
+                                IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,14)
+                                u4_decoded_value     = u4_bits;
+                            u4_run              = (u4_decoded_value >> 8);
+                            u4_level_first_byte = (u4_decoded_value & 0x0FF);
+                            if(u4_level_first_byte & 0x7F)
+                            {
+                                /*-------------------------------------------------------
+                                * First 8 bits of level are neither 1000000 nor 00000000
+                                * Hence 14-bit FLC (Last 8 bits are used to get level)
+                                *
+                                *  Level = (msb of Level_First_Byte is 1)?
+                                *          Level_First_Byte - 256 : Level_First_Byte
+                                *-------------------------------------------------------*/
+                                u4_level = (u4_level_first_byte -
+                                    ((u4_level_first_byte & 0x80) << 1));
+                            }
+                            else
+                            {
+                                /*-------------------------------------------------------
+                                * Next 8 bits are either 1000000 or 00000000
+                                * Hence 22-bit FLC (Last 16 bits are used to get level)
+                                *
+                                *  Level = (msb of Level_First_Byte is 1)?
+                                *          Level_Second_Byte - 256 : Level_Second_Byte
+                                *-------------------------------------------------------*/
+                                IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,8)
+                                    u4_level = u4_bits;
+                                u4_level = (u4_level - (u4_level_first_byte << 1));
+                            }
+                            u4_numCoeffs += u4_run;
+
+                            u4_pos = pu1_scan[u4_numCoeffs++ & 63];
+
+                            pu1_pos[*pi4_num_coeffs]    = u4_pos;
+                            pi2_outAddr[*pi4_num_coeffs]    = u4_level;
+                            (*pi4_num_coeffs)++;
+                        }
+                    }
+                }
+
+                u4_nz_cols |= 1 << (u4_pos & 0x7);
+                u4_nz_rows |= 1 << (u4_pos >> 0x3);
+
+
+            }
+            IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,u4_sym_len)
+            if (u4_numCoeffs > 64)
+            {
+                return IMPEG2D_MB_TEX_DECODE_ERR;
+            }
+        }
+        else
+        {
+            // Inline
+            while(1)
+            {
+
+                UWORD32 lead_zeros;
+                UWORD16 DecodedValue;
+
+                u4_sym_len = 17;
+                IBITS_NXT(u4_buf, u4_buf_nxt, u4_offset, u4_bits, u4_sym_len)
+
+
+                DecodedValue = gau2_impeg2d_tab_zero_1_9[u4_bits >> 8];
+                u4_sym_len = BITS(DecodedValue, 3, 0);
+                u4_level = ((WORD16) DecodedValue) >> 9;
+
+                if (0 != u4_level)
+                {
+                    u4_run = BITS(DecodedValue, 8,4);
+
+                    u4_numCoeffs       += u4_run;
+
+                    u4_pos                 = pu1_scan[u4_numCoeffs++ & 63];
+                    pu1_pos[*pi4_num_coeffs]    = u4_pos;
+
+                    FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_sym_len,pu4_buf_aligned)
+                    pi2_outAddr[*pi4_num_coeffs]    = u4_level;
+                    (*pi4_num_coeffs)++;
+                }
+                else
+                {
+                    if(DecodedValue == END_OF_BLOCK_ZERO)
+                    {
+                        u4_sym_len = 2;
+
+                        break;
+                    }
+                    else
+                    {
+                        lead_zeros = CLZ(u4_bits) - 20;/* -15 since we are dealing with WORD32 */
+                        /*Second table lookup*/
+                        if (0 != lead_zeros)
+                        {
+                            u4_bits         = (u4_bits >> (6 - lead_zeros)) & 0x001F;
+
+                            /* Flush the number of bits */
+                            u4_sym_len         = 11 + lead_zeros;
+
+                            /* Calculate the address */
+                            u4_bits         = ((lead_zeros - 1) << 5) + u4_bits;
+
+                            DecodedValue    = gau2_impeg2d_tab_zero_10_16[u4_bits];
+
+                            u4_run = BITS(DecodedValue, 8,4);
+                            u4_level = ((WORD16) DecodedValue) >> 9;
+
+                            u4_numCoeffs       += u4_run;
+
+                            u4_pos                 = pu1_scan[u4_numCoeffs++ & 63];
+                            pu1_pos[*pi4_num_coeffs]    = u4_pos;
+                            if (1 == lead_zeros)
+                                u4_sym_len--;
+                            /* flushing */
+                            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_sym_len,pu4_buf_aligned)
+                            pi2_outAddr[*pi4_num_coeffs]    = u4_level;
+
+                            (*pi4_num_coeffs)++;
+                        }
+                        /*Escape Sequence*/
+                        else if(u2_mpeg2 == 1)
+                        {
+                            u4_sym_len         = 6;
+                            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_sym_len,pu4_buf_aligned)
+                            IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,18)
+                            u4_decoded_value    = u4_bits;
+                            u4_run             = (u4_decoded_value >> 12);
+                            u4_level           = (u4_decoded_value & 0x0FFF);
+
+                            if (u4_level)
+                                u4_level = (u4_level - ((u4_level & 0x0800) << 1));
+
+                            u4_numCoeffs           += u4_run;
+
+                            u4_pos                 = pu1_scan[u4_numCoeffs++ & 63];
+                            pu1_pos[*pi4_num_coeffs]    = u4_pos;
+                            pi2_outAddr[*pi4_num_coeffs]    = u4_level;
+
+                            (*pi4_num_coeffs)++;
+                        }
+                        /*********************************************************************/
+                        /* MPEG1 Escape Code                                                 */
+                        /*********************************************************************/
+                        else
+                        {
+                            /*-----------------------------------------------------------
+                            * MPEG-1 Stream
+                            *
+                            * <See D.9.3 of MPEG-2> Run-level escape syntax
+                            * Run-level values that cannot be coded with a VLC are coded
+                            * by the escape code '0000 01' followed by
+                            * either a 14-bit FLC (127 <= level <= 127),
+                            * or a 22-bit FLC (255 <= level <= 255).
+                            * This is described in Annex B,B.5f of MPEG-1.standard
+                            *-----------------------------------------------------------*/
+
+                            /*-----------------------------------------------------------
+                            * First 6 bits are the value of the Run. Next is First 8 bits
+                            * of Level. These bits decide whether it is 14 bit FLC or
+                            * 22-bit FLC.
+                            *
+                            * If( first 8 bits of Level == '1000000' or '00000000')
+                            *      then its is 22-bit FLC.
+                            * else
+                            *      it is 14-bit FLC.
+                            *-----------------------------------------------------------*/
+                            u4_sym_len             = 6;
+                            FLUSH_BITS(u4_offset,u4_buf,u4_buf_nxt,u4_sym_len,pu4_buf_aligned)
+                            IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,14)
+                            u4_decoded_value        = u4_bits;
+                            u4_run                 = (u4_decoded_value >> 8);
+                            u4_level_first_byte    = (u4_decoded_value & 0x0FF);
+                            if(u4_level_first_byte & 0x7F)
+                            {
+                                /*-------------------------------------------------------
+                                * First 8 bits of level are neither 1000000 nor 00000000
+                                * Hence 14-bit FLC (Last 8 bits are used to get level)
+                                *
+                                *  Level = (msb of Level_First_Byte is 1)?
+                                *          Level_First_Byte - 256 : Level_First_Byte
+                                *-------------------------------------------------------*/
+                                u4_level = (u4_level_first_byte -
+                                    ((u4_level_first_byte & 0x80) << 1));
+                            }
+                            else
+                            {
+                                /*-------------------------------------------------------
+                                * Next 8 bits are either 1000000 or 00000000
+                                * Hence 22-bit FLC (Last 16 bits are used to get level)
+                                *
+                                *  Level = (msb of Level_First_Byte is 1)?
+                                *          Level_Second_Byte - 256 : Level_Second_Byte
+                                *-------------------------------------------------------*/
+                                IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,8)
+                                u4_level = u4_bits;
+                                u4_level = (u4_level - (u4_level_first_byte << 1));
+                            }
+                            u4_numCoeffs           += u4_run;
+
+                            u4_pos                 = pu1_scan[u4_numCoeffs++ & 63];
+                            pu1_pos[*pi4_num_coeffs]    = u4_pos;
+                            pi2_outAddr[*pi4_num_coeffs]    = u4_level;
+
+                            (*pi4_num_coeffs)++;
+                        }
+                    }
+                }
+
+                u4_nz_cols |= 1 << (u4_pos & 0x7);
+                u4_nz_rows |= 1 << (u4_pos >> 0x3);
+            }
+            if (u4_numCoeffs > 64)
+            {
+                return IMPEG2D_MB_TEX_DECODE_ERR;
+            }
+
+            IBITS_GET(u4_buf,u4_buf_nxt,u4_offset,u4_bits,pu4_buf_aligned,u4_sym_len)
+
+        }
+
+        PUT_TEMP_STREAM_DATA(u4_buf, u4_buf_nxt, u4_offset, pu4_buf_aligned, ps_stream)
+
+        ps_dec->u4_non_zero_cols  = u4_nz_cols;
+        ps_dec->u4_non_zero_rows  = u4_nz_rows;
+
+            return (IMPEG2D_ERROR_CODES_T)IVD_ERROR_NONE;
+}
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_inv_quant_mpeg1                                   */
+/*                                                                           */
+/*  Description   : Inverse quantizes the output of VLD                      */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  blk,              - Block to be inverse quantized                        */
+/*  weighting_matrix  - Matrix to be used in inverse quant                   */
+/*  intra_dc_precision- Precision reqd to scale intra DC value               */
+/*  quant_scale       - Quanization scale for inverse quant                  */
+/*  intra_flag        - Intra or Not                                         */
+/*                                                                           */
+/*  Globals       : None                                                     */
+/*                                                                           */
+/*  Processing    : Implements the inverse quantize equation                 */
+/*                                                                           */
+/*  Outputs       : Inverse quantized values in the block                    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         05 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+UWORD8 impeg2d_inv_quant_mpeg1(WORD16 *pi2_blk,
+                              UWORD8 *pu1_weighting_matrix,
+                              UWORD8 u1_quant_scale,
+                              WORD32 u4_intra_flag,
+                              WORD32 i4_num_coeffs,
+                              WORD16 *pi2_coeffs,
+                              UWORD8 *pu1_pos,
+                              const UWORD8 *pu1_scan,
+                              UWORD16 *pu2_def_dc_pred,
+                              UWORD16 u2_intra_dc_precision)
+{
+    UWORD16 i4_pos;
+
+    WORD32  i4_iter;
+
+    /* Inverse Quantize the predicted DC value for intra MB*/
+    if(u4_intra_flag == 1)
+    {
+        /**************************************************************************/
+        /* Decode the DC coefficient in case of Intra block and also update       */
+        /* DC predictor value of the corresponding color component                */
+        /**************************************************************************/
+        {
+            pi2_coeffs[0]   += *pu2_def_dc_pred;
+            *pu2_def_dc_pred      = pi2_coeffs[0];
+            pi2_coeffs[0]   <<= (3 - u2_intra_dc_precision);
+            pi2_coeffs[0]   = CLIP_S12(pi2_coeffs[0]);
+        }
+
+        pi2_blk[pu1_scan[0]]  = pi2_coeffs[0];
+    }
+    /************************************************************************/
+    /* Inverse quantization of other DCT coefficients                       */
+    /************************************************************************/
+    for(i4_iter = u4_intra_flag; i4_iter < i4_num_coeffs; i4_iter++)
+    {
+
+        WORD16 sign;
+        WORD32 temp, temp1;
+
+        /* Position is the inverse scan of the index stored */
+        i4_pos      = pu1_pos[i4_iter];
+        pi2_blk[i4_pos] = pi2_coeffs[i4_iter];
+
+        sign = SIGN(pi2_blk[i4_pos]);
+        temp = ABS(pi2_blk[i4_pos] << 1);
+
+        /* pi2_coeffs has only non-zero elements. So no need to check
+         * if the coeff is non-zero.
+         */
+        temp = temp + (1 * !u4_intra_flag);
+
+        temp = temp * pu1_weighting_matrix[i4_pos] * u1_quant_scale;
+
+        temp = temp >> 5;
+
+        temp1 = temp | 1;
+
+        temp1 = (temp1 > temp) ? (temp1 - temp) : (temp - temp1);
+
+        temp = temp - temp1;
+
+        if(temp < 0)
+        {
+            temp = 0;
+        }
+
+        temp = temp * sign;
+
+        temp = CLIP_S12(temp);
+
+        pi2_blk[i4_pos] = temp;
+    }
+
+    /*return value is used in the case of mpeg2 for mismatch control*/
+    return  (0);
+} /* End of inv_quant() */
+
+
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : impeg2d_inv_quant_mpeg2                                   */
+/*                                                                           */
+/*  Description   : Inverse quantizes the output of VLD                      */
+/*                                                                           */
+/*  Inputs        :                                                          */
+/*  blk,              - Block to be inverse quantized                        */
+/*  weighting_matrix  - Matrix to be used in inverse quant                   */
+/*  intra_dc_precision- Precision reqd to scale intra DC value               */
+/*  quant_scale       - Quanization scale for inverse quant                  */
+/*  intra_flag        - Intra or Not                                         */
+/*                                                                           */
+/*  Globals       : None                                                     */
+/*                                                                           */
+/*  Processing    : Implements the inverse quantize equation                 */
+/*                                                                           */
+/*  Outputs       : Inverse quantized values in the block                    */
+/*                                                                           */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes                              */
+/*         05 09 2005   Harish M        First Version                        */
+/*                                                                           */
+/*****************************************************************************/
+UWORD8 impeg2d_inv_quant_mpeg2(WORD16 *pi2_blk,
+                              UWORD8 *pu1_weighting_matrix,
+                              UWORD8 u1_quant_scale,
+                              WORD32 u4_intra_flag,
+                              WORD32 i4_num_coeffs,
+                              WORD16 *pi2_coeffs,
+                              UWORD8 *pu1_pos,
+                              const UWORD8 *pu1_scan,
+                              UWORD16 *pu2_def_dc_pred,
+                              UWORD16 u2_intra_dc_precision)
+{
+
+    WORD32  i4_pos;
+    /* Used for Mismatch control */
+    UWORD32 sum;
+
+    WORD32  i4_iter;
+
+    sum = 0;
+
+    /* Inverse Quantize the predicted DC value for intra MB*/
+    if(u4_intra_flag == 1)
+    {
+        /**************************************************************************/
+        /* Decode the DC coefficient in case of Intra block and also update       */
+        /* DC predictor value of the corresponding color component                */
+        /**************************************************************************/
+        {
+            pi2_coeffs[0]   += *pu2_def_dc_pred;
+            *pu2_def_dc_pred      = pi2_coeffs[0];
+            pi2_coeffs[0]   <<= (3 - u2_intra_dc_precision);
+            pi2_coeffs[0]   = CLIP_S12(pi2_coeffs[0]);
+        }
+
+        pi2_blk[pu1_scan[0]]  = pi2_coeffs[0];
+        sum = pi2_blk[0];
+    }
+
+    /************************************************************************/
+    /* Inverse quantization of other DCT coefficients                       */
+    /************************************************************************/
+    for(i4_iter = u4_intra_flag; i4_iter < i4_num_coeffs; i4_iter++)
+    {
+        WORD16 sign;
+        WORD32 temp;
+        /* Position is the inverse scan of the index stored */
+        i4_pos      = pu1_pos[i4_iter];
+        pi2_blk[i4_pos] = pi2_coeffs[i4_iter];
+
+        sign = SIGN(pi2_blk[i4_pos]);
+        temp = ABS(pi2_blk[i4_pos] << 1);
+        temp = temp + (1 * !u4_intra_flag);
+        temp = temp * pu1_weighting_matrix[i4_pos] * u1_quant_scale;
+
+        temp = temp >> 5;
+
+        temp = temp * sign;
+
+        temp = CLIP_S12(temp);
+
+        pi2_blk[i4_pos] = temp;
+
+        sum += temp;
+    }
+    return (sum ^ 1);
+} /* End of inv_quant() */
diff --git a/decoder/impeg2d_vld.h b/decoder/impeg2d_vld.h
new file mode 100644
index 0000000..f52da96
--- /dev/null
+++ b/decoder/impeg2d_vld.h
@@ -0,0 +1,49 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#ifndef __IMPEG2D_VLD_H__
+#define __IMPEG2D_VLD_H__
+
+
+WORD16 impeg2d_dec_vld_symbol(stream_t *stream,const WORD16 codeTable[][2],
+                 UWORD16 maxLen);
+WORD16 impeg2d_fast_dec_vld_symbol(stream_t *stream,
+                     const WORD16  codeTable[][2],
+                     const UWORD16 indexTable[][2],
+                     UWORD16 maxLen);
+IMPEG2D_ERROR_CODES_T impeg2d_vld_decode(dec_state_t *dec, WORD16 *outAddr, /*!< Address where decoded symbols will be stored */
+                                            const UWORD8 *scan, /*!< Scan table to be used */
+                                            UWORD8 *pu1_pos, /*!< Scan table to be used */
+                                            UWORD16 intraFlag, /*!< Intra Macroblock or not */
+                                            UWORD16 chromaFlag, /*!< Chroma Block or not */
+                                            UWORD16 dPicture, /*!< D Picture or not */
+                                            UWORD16 intraVlcFormat, /*!< Intra VLC format */
+                                            UWORD16 mpeg2, /*!< MPEG-2 or not */
+                                            WORD32 *pi4_num_coeffs /*!< Returns the number of coeffs in block */
+                                            );
+
+pf_vld_inv_quant_t impeg2d_vld_inv_quant_mpeg1;
+pf_vld_inv_quant_t impeg2d_vld_inv_quant_mpeg2;
+
+
+pf_inv_quant_t impeg2d_inv_quant_mpeg1;
+pf_inv_quant_t impeg2d_inv_quant_mpeg2;
+
+
+#endif /* #ifndef __IMPEG2D_VLD_H__ */
diff --git a/decoder/impeg2d_vld_tables.c b/decoder/impeg2d_vld_tables.c
new file mode 100644
index 0000000..dba05ec
--- /dev/null
+++ b/decoder/impeg2d_vld_tables.c
@@ -0,0 +1,465 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#include "iv_datatypedef.h"
+#include "impeg2d_vld_tables.h"
+
+/* Table to be used for decoding the MB increment value */
+const WORD16 gai2_impeg2d_mb_addr_incr[][2] =
+{
+  {1,-33},{3,2},{-31,-32},{5,4},{-29,-30},{7,6},{-27,-28},{13,8},{10,9},
+  {-25,-26},{12,11},{-23,-24},{-21,-22},{25,14},{16,15},{-19,-20},{20,17},
+  {19,18},{-17,-18},{-15,-16},{22,21},{-13,-14},{24,23},{-11,-12},{-9,-10},
+  {34,26},{0,27},{31,28},{30,29},{-7,-8},{-5,-6},{33,32},{-3,-4},{-1,-2},
+  {0,35},{36,0},{37,0},{-34,0}
+};
+
+/* Table to be used for decoding the MB type in case of P Pictures */
+const UWORD16 gau2_impeg2d_p_mb_type[] =
+{
+    0x0100, 0x0611, 0x0512, 0x0512, 0x051a, 0x051a, 0x0501, 0x0501, 0x0308, 0x0308,
+    0x0308, 0x0308, 0x0308, 0x0308, 0x0308, 0x0308, 0x0202, 0x0202, 0x0202, 0x0202,
+    0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202, 0x0202,
+    0x0202, 0x0202, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a,
+    0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a,
+    0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a, 0x010a,
+    0x010a, 0x010a, 0x010a, 0x010a
+};
+/* Table to be used for decoding the MB type in case of B Pictures */
+const UWORD16 gau2_impeg2d_b_mb_type[] =
+{
+    0x0100, 0x0611, 0x0616, 0x061a, 0x053e, 0x053e, 0x0501, 0x0501, 0x0408, 0x0408,
+    0x0408, 0x0408, 0x040a, 0x040a, 0x040a, 0x040a, 0x0304, 0x0304, 0x0304, 0x0304,
+    0x0304, 0x0304, 0x0304, 0x0304, 0x0306, 0x0306, 0x0306, 0x0306, 0x0306, 0x0306,
+    0x0306, 0x0306, 0x022c, 0x022c, 0x022c, 0x022c, 0x022c, 0x022c, 0x022c, 0x022c,
+    0x022c, 0x022c, 0x022c, 0x022c, 0x022c, 0x022c, 0x022c, 0x022c, 0x022e, 0x022e,
+    0x022e, 0x022e, 0x022e, 0x022e, 0x022e, 0x022e, 0x022e, 0x022e, 0x022e, 0x022e,
+    0x022e, 0x022e, 0x022e, 0x022e
+};
+/* Table to be used for decoding dmvector[t] */
+const WORD16 gai2_impeg2d_dec_mv[] =
+{
+    1,-1
+};
+
+/* Tables used for motion code decode */
+const UWORD16 gau2_impeg2d_mv_code[] =
+{
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0f0a, 0x0e0a, 0x0d0a, 0x0c0a, 0x0b0a, 0x0a0a, 0x0909, 0x0909,
+    0x0809, 0x0809, 0x0709, 0x0709, 0x0607, 0x0607, 0x0607, 0x0607, 0x0607, 0x0607,
+    0x0607, 0x0607, 0x0507, 0x0507, 0x0507, 0x0507, 0x0507, 0x0507, 0x0507, 0x0507,
+    0x0407, 0x0407, 0x0407, 0x0407, 0x0407, 0x0407, 0x0407, 0x0407, 0x0306, 0x0306,
+    0x0306, 0x0306, 0x0306, 0x0306, 0x0306, 0x0306, 0x0306, 0x0306, 0x0306, 0x0306,
+    0x0306, 0x0306, 0x0306, 0x0306, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204,
+    0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204,
+    0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204,
+    0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204,
+    0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204,
+    0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204,
+    0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0204, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103,
+    0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0103, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002,
+    0x0002, 0x0002
+};
+/* Tables used for cbp decode */
+const UWORD16 gau2_impeg2d_cbp_code[] =
+{
+    0x0100, 0x0100, 0x0927, 0x091b, 0x093b, 0x0937, 0x092f, 0x091f, 0x083a, 0x083a,
+    0x0836, 0x0836, 0x082e, 0x082e, 0x081e, 0x081e, 0x0839, 0x0839, 0x0835, 0x0835,
+    0x082d, 0x082d, 0x081d, 0x081d, 0x0826, 0x0826, 0x081a, 0x081a, 0x0825, 0x0825,
+    0x0819, 0x0819, 0x082b, 0x082b, 0x0817, 0x0817, 0x0833, 0x0833, 0x080f, 0x080f,
+    0x082a, 0x082a, 0x0816, 0x0816, 0x0832, 0x0832, 0x080e, 0x080e, 0x0829, 0x0829,
+    0x0815, 0x0815, 0x0831, 0x0831, 0x080d, 0x080d, 0x0823, 0x0823, 0x0813, 0x0813,
+    0x080b, 0x080b, 0x0807, 0x0807, 0x0722, 0x0722, 0x0722, 0x0722, 0x0712, 0x0712,
+    0x0712, 0x0712, 0x070a, 0x070a, 0x070a, 0x070a, 0x0706, 0x0706, 0x0706, 0x0706,
+    0x0721, 0x0721, 0x0721, 0x0721, 0x0711, 0x0711, 0x0711, 0x0711, 0x0709, 0x0709,
+    0x0709, 0x0709, 0x0705, 0x0705, 0x0705, 0x0705, 0x063f, 0x063f, 0x063f, 0x063f,
+    0x063f, 0x063f, 0x063f, 0x063f, 0x0603, 0x0603, 0x0603, 0x0603, 0x0603, 0x0603,
+    0x0603, 0x0603, 0x0624, 0x0624, 0x0624, 0x0624, 0x0624, 0x0624, 0x0624, 0x0624,
+    0x0618, 0x0618, 0x0618, 0x0618, 0x0618, 0x0618, 0x0618, 0x0618, 0x053e, 0x053e,
+    0x053e, 0x053e, 0x053e, 0x053e, 0x053e, 0x053e, 0x053e, 0x053e, 0x053e, 0x053e,
+    0x053e, 0x053e, 0x053e, 0x053e, 0x0502, 0x0502, 0x0502, 0x0502, 0x0502, 0x0502,
+    0x0502, 0x0502, 0x0502, 0x0502, 0x0502, 0x0502, 0x0502, 0x0502, 0x0502, 0x0502,
+    0x053d, 0x053d, 0x053d, 0x053d, 0x053d, 0x053d, 0x053d, 0x053d, 0x053d, 0x053d,
+    0x053d, 0x053d, 0x053d, 0x053d, 0x053d, 0x053d, 0x0501, 0x0501, 0x0501, 0x0501,
+    0x0501, 0x0501, 0x0501, 0x0501, 0x0501, 0x0501, 0x0501, 0x0501, 0x0501, 0x0501,
+    0x0501, 0x0501, 0x0538, 0x0538, 0x0538, 0x0538, 0x0538, 0x0538, 0x0538, 0x0538,
+    0x0538, 0x0538, 0x0538, 0x0538, 0x0538, 0x0538, 0x0538, 0x0538, 0x0534, 0x0534,
+    0x0534, 0x0534, 0x0534, 0x0534, 0x0534, 0x0534, 0x0534, 0x0534, 0x0534, 0x0534,
+    0x0534, 0x0534, 0x0534, 0x0534, 0x052c, 0x052c, 0x052c, 0x052c, 0x052c, 0x052c,
+    0x052c, 0x052c, 0x052c, 0x052c, 0x052c, 0x052c, 0x052c, 0x052c, 0x052c, 0x052c,
+    0x051c, 0x051c, 0x051c, 0x051c, 0x051c, 0x051c, 0x051c, 0x051c, 0x051c, 0x051c,
+    0x051c, 0x051c, 0x051c, 0x051c, 0x051c, 0x051c, 0x0528, 0x0528, 0x0528, 0x0528,
+    0x0528, 0x0528, 0x0528, 0x0528, 0x0528, 0x0528, 0x0528, 0x0528, 0x0528, 0x0528,
+    0x0528, 0x0528, 0x0514, 0x0514, 0x0514, 0x0514, 0x0514, 0x0514, 0x0514, 0x0514,
+    0x0514, 0x0514, 0x0514, 0x0514, 0x0514, 0x0514, 0x0514, 0x0514, 0x0530, 0x0530,
+    0x0530, 0x0530, 0x0530, 0x0530, 0x0530, 0x0530, 0x0530, 0x0530, 0x0530, 0x0530,
+    0x0530, 0x0530, 0x0530, 0x0530, 0x050c, 0x050c, 0x050c, 0x050c, 0x050c, 0x050c,
+    0x050c, 0x050c, 0x050c, 0x050c, 0x050c, 0x050c, 0x050c, 0x050c, 0x050c, 0x050c,
+    0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420,
+    0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420,
+    0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420, 0x0420,
+    0x0420, 0x0420, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410,
+    0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410,
+    0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410, 0x0410,
+    0x0410, 0x0410, 0x0410, 0x0410, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408,
+    0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408,
+    0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408,
+    0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0408, 0x0404, 0x0404, 0x0404, 0x0404,
+    0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404,
+    0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404,
+    0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x033c, 0x033c,
+    0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c,
+    0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c,
+    0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c,
+    0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c,
+    0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c,
+    0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c, 0x033c,
+    0x033c, 0x033c
+};
+
+
+/* Table B.14 DCT Coefficients Table zero */
+const UWORD16 gau2_impeg2d_dct_coeff_zero[] =
+{
+  2640,2608,2576,2544,12400,32848,30800,28752,26704,24656,22608,63536,61488,
+    59440,57392,55344,1295,1263,1231,1199,1167,1135,1103,1071,1039,2511,2479,
+    2447,2415,2383,2351,2319,1006,974,942,910,878,846,814,782,750,718,686,654,
+    622,590,558,526,20557,18509,10349,6285,4269,2285,2253,493,461,429,397,
+    53293,51245,49197,47149,45101,364,16460,8300,332,4236,14412,43052,41004,
+    300,38956,36908,2220,6252,268,12364,34860,32810,10314,234,4202,2186,30762,
+    28714,8266,ESCAPE_CODE,4167,18471,135,16423,14374,12326,2118,10278,26664,
+    200,24616,22568,6216,2152,168,20520,101,101,101,101,101,101,101,101,8229,
+    8229,8229,8229,8229,8229,8229,8229,6181,6181,6181,6181,6181,6181,6181,6181,
+    68,4132,2083,2083,END_OF_BLOCK,34
+};
+
+/* tab Zero b.14 for 1-9 bits*/
+const UWORD16 gau2_impeg2d_tab_zero_1_9[] =
+{
+    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+    0x01f6, 0x01f6, 0x01f6, 0x01f6, 0x01f6, 0x01f6, 0x01f6, 0x01f6,
+    0x0428, 0x0428, 0xfc28, 0xfc28, 0x0298, 0x0298, 0xfe98, 0xfe98,
+    0x0808, 0x0808, 0xf808, 0xf808, 0x0288, 0x0288, 0xfe88, 0xfe88,
+    0x0277, 0x0277, 0x0277, 0x0277, 0xfe77, 0xfe77, 0xfe77, 0xfe77,
+    0x0267, 0x0267, 0x0267, 0x0267, 0xfe67, 0xfe67, 0xfe67, 0xfe67,
+    0x0417, 0x0417, 0x0417, 0x0417, 0xfc17, 0xfc17, 0xfc17, 0xfc17,
+    0x0257, 0x0257, 0x0257, 0x0257, 0xfe57, 0xfe57, 0xfe57, 0xfe57,
+    0x02d9, 0xfed9, 0x0c09, 0xf409, 0x02c9, 0xfec9, 0x02b9, 0xfeb9,
+    0x0439, 0xfc39, 0x0619, 0xfa19, 0x0a09, 0xf609, 0x02a9, 0xfea9,
+    0x0606, 0x0606, 0x0606, 0x0606, 0x0606, 0x0606, 0x0606, 0x0606,
+    0xfa06, 0xfa06, 0xfa06, 0xfa06, 0xfa06, 0xfa06, 0xfa06, 0xfa06,
+    0x0246, 0x0246, 0x0246, 0x0246, 0x0246, 0x0246, 0x0246, 0x0246,
+    0xfe46, 0xfe46, 0xfe46, 0xfe46, 0xfe46, 0xfe46, 0xfe46, 0xfe46,
+    0x0236, 0x0236, 0x0236, 0x0236, 0x0236, 0x0236, 0x0236, 0x0236,
+    0xfe36, 0xfe36, 0xfe36, 0xfe36, 0xfe36, 0xfe36, 0xfe36, 0xfe36,
+    0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405,
+    0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405, 0x0405,
+    0xfc05, 0xfc05, 0xfc05, 0xfc05, 0xfc05, 0xfc05, 0xfc05, 0xfc05,
+    0xfc05, 0xfc05, 0xfc05, 0xfc05, 0xfc05, 0xfc05, 0xfc05, 0xfc05,
+    0x0225, 0x0225, 0x0225, 0x0225, 0x0225, 0x0225, 0x0225, 0x0225,
+    0x0225, 0x0225, 0x0225, 0x0225, 0x0225, 0x0225, 0x0225, 0x0225,
+    0xfe25, 0xfe25, 0xfe25, 0xfe25, 0xfe25, 0xfe25, 0xfe25, 0xfe25,
+    0xfe25, 0xfe25, 0xfe25, 0xfe25, 0xfe25, 0xfe25, 0xfe25, 0xfe25,
+    0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214,
+    0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214,
+    0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214,
+    0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214,
+    0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14,
+    0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14,
+    0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14,
+    0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03
+};
+
+const UWORD16 gau2_impeg2d_tab_zero_10_16[] =
+{
+    /*Six leading zeros*/
+    0x0300, 0x0300, 0xff00, 0xff00, 0x0450, 0x0450, 0xfc50, 0xfc50,
+    0x0e00, 0x0e00, 0xf200, 0xf200, 0x0620, 0x0620, 0xfa20, 0xfa20,
+    0x0810, 0x0810, 0xf810, 0xf810, 0x02f0, 0x02f0, 0xfef0, 0xfef0,
+    0x02e0, 0x02e0, 0xfee0, 0xfee0, 0x0440, 0x0440, 0xfc40, 0xfc40,
+    /*Seven leading zeros*/
+    0x1602, 0xea02, 0x0482, 0xfc82, 0x0642, 0xfa42, 0x1402, 0xec02,
+    0x0822, 0xf822, 0x0472, 0xfc72, 0x0352, 0xff52, 0x0342, 0xff42,
+    0x1202, 0xee02, 0x0332, 0xff32, 0x0322, 0xff22, 0x0a12, 0xf612,
+    0x0632, 0xfa32, 0x1002, 0xf002, 0x0462, 0xfc62, 0x0312, 0xff12,
+    /*Eight leading zeros*/
+    0x04a3, 0xfca3, 0x0493, 0xfc93, 0x0653, 0xfa53, 0x0833, 0xf833,
+    0x0a23, 0xf623, 0x0e13, 0xf213, 0x0c13, 0xf413, 0x1e03, 0xe203,
+    0x1c03, 0xe403, 0x1a03, 0xe603, 0x1803, 0xe803, 0x03a3, 0xffa3,
+    0x0393, 0xff93, 0x0383, 0xff83, 0x0373, 0xff73, 0x0363, 0xff63,
+    /*Nine leading zeros*/
+    0x3e04, 0xc204, 0x3c04, 0xc404, 0x3a04, 0xc604, 0x3804, 0xc804,
+    0x3604, 0xca04, 0x3404, 0xcc04, 0x3204, 0xce04, 0x3004, 0xd004,
+    0x2e04, 0xd204, 0x2c04, 0xd404, 0x2a04, 0xd604, 0x2804, 0xd804,
+    0x2604, 0xda04, 0x2404, 0xdc04, 0x2204, 0xde04, 0x2004, 0xe004,
+    /*Ten leading zeros*/
+    0x5005, 0xb005, 0x4e05, 0xb205, 0x4c05, 0xb405, 0x4a05, 0xb605,
+    0x4805, 0xb805, 0x4605, 0xba05, 0x4405, 0xbc05, 0x4205, 0xbe05,
+    0x4005, 0xc005, 0x1c15, 0xe415, 0x1a15, 0xe615, 0x1815, 0xe815,
+    0x1615, 0xea15, 0x1415, 0xec15, 0x1215, 0xee15, 0x1015, 0xf015,
+    /*Eleven leading zeros*/
+    0x2416, 0xdc16, 0x2216, 0xde16, 0x2016, 0xe016, 0x1e16, 0xe216,
+    0x0666, 0xfa66, 0x0506, 0xfd06, 0x04f6, 0xfcf6, 0x04e6, 0xfce6,
+    0x04d6, 0xfcd6, 0x04c6, 0xfcc6, 0x04b6, 0xfcb6, 0x03f6, 0xfff6,
+    0x03e6, 0xffe6, 0x03d6, 0xffd6, 0x03c6, 0xffc6, 0x03b6, 0xffb6
+
+};
+
+/* Table B.14 DCT Coefficients Table one */
+const UWORD16 gau2_impeg2d_dct_coeff_one[] =
+{
+    2640,2608,2576,2544,12400,32848,30800,28752,26704,24656,22608,63536,61488,
+    59440,57392,55344,1295,1263,1231,1199,1167,1135,1103,1071,1039,2511,2479,
+    2447,2415,2383,2351,2319,1006,974,942,910,878,846,814,782,750,718,686,654,
+    622,590,558,526,20557,18509,10349,6285,4269,2285,2253,0,0,0,0,53293,51245,
+    49197,47149,45101,16460,8300,0,0,14412,43052,41004,0,38956,36908,0,6252,
+    0,12364,34860,10313,10313,28713,28713,4234,32810,30761,30761,ESCAPE_CODE,
+    14375,16423,12327,4167,230,198,8230,10278,2216,22568,360,328,26664,24616,
+    6216,2184,4133,4133,4133,4133,4133,4133,4133,4133,2117,2117,2117,2117,2117,
+    2117,2117,2117,6181,6181,6181,6181,6181,6181,6181,6181,2083,2083,
+    END_OF_BLOCK,100,18471,18471,2151,2151,20519,20519,263,263,295,295,392,424,
+    4200,8264,456,488,34,34,34,34,34,34,34,34,67,67,67,67,133,165
+};
+
+/* tab Zero b.15 for 1-9 bits*/
+const UWORD16 gau2_impeg2d_tab_one_1_9[] =
+{
+    0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
+    0x01f6, 0x01f6, 0x01f6, 0x01f6, 0x01f6, 0x01f6, 0x01f6, 0x01f6,
+    0x0278, 0x0278, 0xfe78, 0xfe78, 0x0288, 0x0288, 0xfe88, 0xfe88,
+    0x0268, 0x0268, 0xfe68, 0xfe68, 0x0428, 0x0428, 0xfc28, 0xfc28,
+    0x0e07, 0x0e07, 0x0e07, 0x0e07, 0xf207, 0xf207, 0xf207, 0xf207,
+    0x0c07, 0x0c07, 0x0c07, 0x0c07, 0xf407, 0xf407, 0xf407, 0xf407,
+    0x0247, 0x0247, 0x0247, 0x0247, 0xfe47, 0xfe47, 0xfe47, 0xfe47,
+    0x0257, 0x0257, 0x0257, 0x0257, 0xfe57, 0xfe57, 0xfe57, 0xfe57,
+    0x0a19, 0xf619, 0x02b9, 0xfeb9, 0x1609, 0xea09, 0x1409, 0xec09,
+    0x02d9, 0xfed9, 0x02c9, 0xfec9, 0x0439, 0xfc39, 0x0819, 0xf819,
+    0x0226, 0x0226, 0x0226, 0x0226, 0x0226, 0x0226, 0x0226, 0x0226,
+    0xfe26, 0xfe26, 0xfe26, 0xfe26, 0xfe26, 0xfe26, 0xfe26, 0xfe26,
+    0x0416, 0x0416, 0x0416, 0x0416, 0x0416, 0x0416, 0x0416, 0x0416,
+    0xfc16, 0xfc16, 0xfc16, 0xfc16, 0xfc16, 0xfc16, 0xfc16, 0xfc16,
+    0x0236, 0x0236, 0x0236, 0x0236, 0x0236, 0x0236, 0x0236, 0x0236,
+    0xfe36, 0xfe36, 0xfe36, 0xfe36, 0xfe36, 0xfe36, 0xfe36, 0xfe36,
+    0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214,
+    0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214,
+    0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214,
+    0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214, 0x0214,
+    0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14,
+    0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14,
+    0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14,
+    0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14, 0xfe14,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff, 0x01ff,
+    0x0605, 0x0605, 0x0605, 0x0605, 0x0605, 0x0605, 0x0605, 0x0605,
+    0x0605, 0x0605, 0x0605, 0x0605, 0x0605, 0x0605, 0x0605, 0x0605,
+    0xfa05, 0xfa05, 0xfa05, 0xfa05, 0xfa05, 0xfa05, 0xfa05, 0xfa05,
+    0xfa05, 0xfa05, 0xfa05, 0xfa05, 0xfa05, 0xfa05, 0xfa05, 0xfa05,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203, 0x0203,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03, 0xfe03,
+    0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404,
+    0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404,
+    0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404,
+    0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404, 0x0404,
+    0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04,
+    0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04,
+    0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04,
+    0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04, 0xfc04,
+    0x0806, 0x0806, 0x0806, 0x0806, 0x0806, 0x0806, 0x0806, 0x0806,
+    0xf806, 0xf806, 0xf806, 0xf806, 0xf806, 0xf806, 0xf806, 0xf806,
+    0x0a06, 0x0a06, 0x0a06, 0x0a06, 0x0a06, 0x0a06, 0x0a06, 0x0a06,
+    0xf606, 0xf606, 0xf606, 0xf606, 0xf606, 0xf606, 0xf606, 0xf606,
+    0x0298, 0x0298, 0xfe98, 0xfe98, 0x0618, 0x0618, 0xfa18, 0xfa18,
+    0x02a8, 0x02a8, 0xfea8, 0xfea8, 0x1008, 0x1008, 0xf008, 0xf008,
+    0x1208, 0x1208, 0xee08, 0xee08, 0x1809, 0xe809, 0x1a09, 0xe609,
+    0x0629, 0xfa29, 0x0449, 0xfc49, 0x1c09, 0xe409, 0x1e09, 0xe209
+};
+
+const UWORD16 gau2_impeg2d_tab_one_10_16[] =
+{
+    /*Six leading zeros*/
+    0x0458, 0x0458, 0x0458, 0x0458, 0xfc58, 0xfc58, 0xfc58, 0xfc58,
+    0x02e8, 0x02e8, 0x02e8, 0x02e8, 0xfee8, 0xfee8, 0xfee8, 0xfee8,
+    0x0829, 0x0829, 0xf829, 0xf829, 0x0309, 0x0309, 0xff09, 0xff09,
+    0x02f8, 0x02f8, 0x02f8, 0x02f8, 0xfef8, 0xfef8, 0xfef8, 0xfef8,
+    /*Seven leading zeros*/
+    0x000b, 0x000b, 0x048b, 0xfc8b, 0x064b, 0xfa4b, 0x000b, 0x000b,
+    0x000b, 0x000b, 0x047b, 0xfc7b, 0x035b, 0xff5b, 0x034b, 0xff4b,
+    0x000b, 0x000b, 0x033b, 0xff3b, 0x032b, 0xff2b, 0x000b, 0x000b,
+    0x063b, 0xfa3b, 0x000b, 0x000b, 0x046b, 0xfc6b, 0x031b, 0xff1b,
+    /*Eight leading zeros*/
+    0x04ac, 0xfcac, 0x049c, 0xfc9c, 0x065c, 0xfa5c, 0x083c, 0xf83c,
+    0x0a2c, 0xf62c, 0x0e1c, 0xf21c, 0x0c1c, 0xf41c, 0x000c, 0x000c,
+    0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x000c, 0x03ac, 0xffac,
+    0x039c, 0xff9c, 0x038c, 0xff8c, 0x037c, 0xff7c, 0x036c, 0xff6c,
+    /*Nine leading zeros*/
+    0x3e0d, 0xc20d, 0x3c0d, 0xc40d, 0x3a0d, 0xc60d, 0x380d, 0xc80d,
+    0x360d, 0xca0d, 0x340d, 0xcc0d, 0x320d, 0xce0d, 0x300d, 0xd00d,
+    0x2e0d, 0xd20d, 0x2c0d, 0xd40d, 0x2a0d, 0xd60d, 0x280d, 0xd80d,
+    0x260d, 0xda0d, 0x240d, 0xdc0d, 0x220d, 0xde0d, 0x200d, 0xe00d,
+    /*Ten leading zeros*/
+    0x500e, 0xb00e, 0x4e0e, 0xb20e, 0x4c0e, 0xb40e, 0x4a0e, 0xb60e,
+    0x480e, 0xb80e, 0x460e, 0xba0e, 0x440e, 0xbc0e, 0x420e, 0xbe0e,
+    0x400e, 0xc00e, 0x1c1e, 0xe41e, 0x1a1e, 0xe61e, 0x181e, 0xe81e,
+    0x161e, 0xea1e, 0x141e, 0xec1e, 0x121e, 0xee1e, 0x101e, 0xf01e,
+    /*Eleven leading zeros*/
+    0x241f, 0xdc1f, 0x221f, 0xde1f, 0x201f, 0xe01f, 0x1e1f, 0xe21f,
+    0x066f, 0xfa6f, 0x050f, 0xfd0f, 0x04ff, 0xfcff, 0x04ef, 0xfcef,
+    0x04df, 0xfcdf, 0x04cf, 0xfccf, 0x04bf, 0xfcbf, 0x03ff, 0xffff,
+    0x03ef, 0xffef, 0x03df, 0xffdf, 0x03cf, 0xffcf, 0x03bf, 0xffbf
+};
+
+/* Depending upon the various groups identified in the Ac Vld Coeffs the
+following tables are used to index into the DCT Coefficients Tables Zero and
+One defined above */
+const UWORD16 gau2_impeg2d_offset_zero[] =
+{
+    0,
+    1369,
+    1434,1434,
+    1048,1048,1048,1048,
+    2012,2012,2012,2012,2012,2012,2012,2012,
+    2110,2110,2110,2110,2110,2110,2110,2110,2110,2110,2110,2110,2110,2110,
+    2110,2110,
+    258,
+    515,515,
+    772,772,772,772,
+    1158,1158,1158,1158,1158,1158,1158,1158,
+    1402,1402,1402,1402,1402,1402,1402,1402,1402,1402,1402,1402,1402,1402,
+    1402,1402,
+    0,
+    1
+};
+
+const UWORD16 gau2_impeg2d_offset_one[] =
+{
+    132,
+    1386,
+    1353,1353,
+    1418,1418,1418,1418,
+    1032,1032,1032,1032,1032,1032,1032,1032,
+    1996,1996,1996,1996,1996,1996,1996,1996,1996,1996,1996,1996,1996,1996,
+    1996,1996,
+    1,
+    258,258,
+    515,515,515,515,
+    756,756,756,756,756,756,756,756,
+    1142,1142,1142,1142,1142,1142,1142,1142,1142,1142,1142,1142,1142,1142,
+    1142,1142,
+    0
+};
+
+
+/* Table to be used for decoding dct_dc_size_luminance */
+const WORD16 gai2_impeg2d_dct_dc_size[][11][2] =
+{
+    {
+        {3,1},{2,4},{-12,-9},{-11,-10},{-8,5},{-7,6},{-6,7},{-5,8},{-4,9},{-3,10},{-2,-1}
+    },
+    {
+        {1,2},{-12,-11},{-10,3},{-9,4},{-8,5},{-7,6},{-6,7},{-5,8},{-4,9},{-3,10},{-2,-1}
+    }
+};
+
+
diff --git a/decoder/impeg2d_vld_tables.h b/decoder/impeg2d_vld_tables.h
new file mode 100644
index 0000000..75805af
--- /dev/null
+++ b/decoder/impeg2d_vld_tables.h
@@ -0,0 +1,88 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+#ifndef __IMPEG2D_VLD_TABLES_H__
+#define __IMPEG2D_VLD_TABLES_H__
+
+
+#define MB_ADDR_INCR_OFFSET       34
+#define MB_ADDR_INCR_LEN          11
+#define MB_TYPE_LEN               6
+#define MV_CODE_LEN               11
+#define MB_CBP_LEN                9
+
+
+
+#define MB_BIDRECT          0x20
+#define MB_QUANT            0x10
+#define MB_MV_FORW          0x8
+#define MB_MV_BACK          0x4
+#define MB_PATTERN          0x2
+#define MB_TYPE_INTRA       0x1
+#define MB_FORW_OR_BACK     (MB_MV_FORW    | MB_MV_BACK)
+#define MB_CODED            (MB_TYPE_INTRA | MB_PATTERN)
+
+
+#define MPEG2_MB_ADDR_INCR_OFFSET       34
+#define MPEG2_INTRA_MBTYPE_OFFSET       69
+#define MPEG2_INTER_MBTYPE_OFFSET       105
+#define MPEG2_BVOP_MBTYPE_OFFSET        125
+#define MPEG2_DCT_DC_SIZE_OFFSET        12
+#define MPEG2_CBP_OFFSET                64
+#define MPEG2_MOTION_CODE_OFFSET        17
+#define MPEG2_DMV_OFFSET                2
+
+#define MPEG2_AC_COEFF_MAX_LEN          16
+#define MB_ADDR_INCR_LEN                11
+#define MPEG2_INTRA_MBTYPE_LEN          2
+#define MPEG2_INTER_MBTYPE_LEN          6
+
+#define MPEG2_DCT_DC_SIZE_LEN           9
+#define MPEG2_DCT_DC_LUMA_SIZE_LEN      9
+#define MPEG2_DCT_DC_CHROMA_SIZE_LEN    10
+#define MPEG2_CBP_LEN                   9
+#define MPEG2_MOTION_CODE_LEN           11
+#define MPEG2_DMV_LEN                   2
+
+#define END_OF_BLOCK                    0x01
+#define ESCAPE_CODE                     0x06
+
+/* Table to be used for decoding the MB increment value */
+extern const WORD16  gai2_impeg2d_mb_addr_incr[][2];
+extern const WORD16  gai2_impeg2d_dct_dc_size[][11][2];
+
+extern const UWORD16 gau2_impeg2d_dct_coeff_zero[];
+extern const UWORD16 gau2_impeg2d_dct_coeff_one[];
+extern const UWORD16 gau2_impeg2d_offset_zero[];
+extern const UWORD16 gau2_impeg2d_offset_one[];
+
+extern const UWORD16 gau2_impeg2d_tab_zero_1_9[];
+extern const UWORD16 gau2_impeg2d_tab_one_1_9[];
+extern const UWORD16 gau2_impeg2d_tab_zero_10_16[];
+extern const UWORD16 gau2_impeg2d_tab_one_10_16[];
+
+extern const UWORD16 gau2_impeg2d_p_mb_type[];
+extern const UWORD16 gau2_impeg2d_b_mb_type[];
+extern const UWORD16 gau2_impeg2d_mv_code[];
+extern const WORD16  gai2_impeg2d_dec_mv[4];
+extern const UWORD16 gau2_impeg2d_cbp_code[];
+
+
+#endif /* __IMPEG2D_VLD_TABLES_H__ */
+
diff --git a/decoder/ivd.h b/decoder/ivd.h
new file mode 100644
index 0000000..abc6604
--- /dev/null
+++ b/decoder/ivd.h
@@ -0,0 +1,948 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  ivd.h
+*
+* @brief
+*  This file contains all the necessary structure and  enumeration
+* definitions needed for the Application  Program Interface(API) of the
+* Ittiam Video Decoders
+*
+* @author
+*  100239(RCY)
+*
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+
+#ifndef _IVD_H
+#define _IVD_H
+
+/*****************************************************************************/
+/* Constant Macros                                                           */
+/*****************************************************************************/
+#define IVD_VIDDEC_MAX_IO_BUFFERS 64
+/*****************************************************************************/
+/* Typedefs                                                                  */
+/*****************************************************************************/
+
+/*****************************************************************************/
+/* Enums                                                                     */
+/*****************************************************************************/
+
+/* IVD_ARCH_T: Architecture Enumeration                               */
+typedef enum
+{
+    ARCH_NA                 =   0x7FFFFFFF,
+    ARCH_ARM_NONEON         =   0x0,
+    ARCH_ARM_A9Q,
+    ARCH_ARM_A9A,
+    ARCH_ARM_A9,
+    ARCH_ARM_A7,
+    ARCH_ARM_A5,
+    ARCH_ARM_A15,
+    ARCH_ARM_NEONINTR,
+    ARCH_ARMV8_GENERIC,
+    ARCH_X86_GENERIC        =   0x100,
+    ARCH_X86_SSSE3,
+    ARCH_X86_SSE42,
+    ARCH_X86_AVX2,
+    ARCH_MIPS_GENERIC       =   0x200,
+    ARCH_MIPS_32
+}IVD_ARCH_T;
+
+/* IVD_SOC_T: SOC Enumeration                               */
+typedef enum
+{
+    SOC_NA                  = 0x7FFFFFFF,
+    SOC_GENERIC             = 0x0,
+    SOC_HISI_37X            = 0x100,
+}IVD_SOC_T;
+
+/* IVD_FRAME_SKIP_MODE_T:Skip mode Enumeration                               */
+
+typedef enum {
+    IVD_SKIP_NONE                               = 0x7FFFFFFF,
+    IVD_SKIP_P                                  = 0x1,
+    IVD_SKIP_B                                  = 0x2,
+    IVD_SKIP_I                                  = 0x3,
+    IVD_SKIP_IP                                 = 0x4,
+    IVD_SKIP_IB                                 = 0x5,
+    IVD_SKIP_PB                                 = 0x6,
+    IVD_SKIP_IPB                                = 0x7,
+    IVD_SKIP_IDR                                = 0x8,
+    IVD_SKIP_DEFAULT                            = IVD_SKIP_NONE,
+}IVD_FRAME_SKIP_MODE_T;
+
+/* IVD_VIDEO_DECODE_MODE_T: Set decoder to decode either frame worth of data */
+/* or only header worth of data                                              */
+
+typedef enum {
+    IVD_DECODE_MODE_NA                          = 0x7FFFFFFF,
+
+    /* This enables the codec to process all decodable units */
+    IVD_DECODE_FRAME                            = 0x0,
+
+    /* This enables the codec to decode header only */
+    IVD_DECODE_HEADER                           = 0x1,
+
+
+
+}IVD_VIDEO_DECODE_MODE_T;
+
+
+/* IVD_DISPLAY_FRAME_OUT_MODE_T: Video Display Frame Output Mode             */
+
+typedef enum {
+
+    IVD_DISPLAY_ORDER_NA                        = 0x7FFFFFFF,
+    /* To set codec to fill output buffers in display order */
+    IVD_DISPLAY_FRAME_OUT                       = 0x0,
+
+    /* To set codec to fill output buffers in decode order */
+    IVD_DECODE_FRAME_OUT                        = 0x1,
+}IVD_DISPLAY_FRAME_OUT_MODE_T;
+
+
+/* IVD_API_COMMAND_TYPE_T:API command type                                   */
+typedef enum {
+    IVD_CMD_VIDEO_NA                          = 0x7FFFFFFF,
+    IVD_CMD_VIDEO_CTL                         = IV_CMD_DUMMY_ELEMENT + 1,
+    IVD_CMD_VIDEO_DECODE,
+    IVD_CMD_GET_DISPLAY_FRAME,
+    IVD_CMD_REL_DISPLAY_FRAME,
+    IVD_CMD_SET_DISPLAY_FRAME
+}IVD_API_COMMAND_TYPE_T;
+
+/* IVD_CONTROL_API_COMMAND_TYPE_T: Video Control API command type            */
+
+typedef enum {
+    IVD_CMD_NA                          = 0x7FFFFFFF,
+    IVD_CMD_CTL_GETPARAMS               = 0x0,
+    IVD_CMD_CTL_SETPARAMS               = 0x1,
+    IVD_CMD_CTL_RESET                   = 0x2,
+    IVD_CMD_CTL_SETDEFAULT              = 0x3,
+    IVD_CMD_CTL_FLUSH                   = 0x4,
+    IVD_CMD_CTL_GETBUFINFO              = 0x5,
+    IVD_CMD_CTL_GETVERSION              = 0x6,
+    IVD_CMD_CTL_CODEC_SUBCMD_START      = 0x7
+}IVD_CONTROL_API_COMMAND_TYPE_T;
+
+
+/* IVD_ERROR_BITS_T: A UWORD32 container will be used for reporting the error*/
+/* code to the application. The first 8 bits starting from LSB have been     */
+/* reserved for the codec to report internal error details. The rest of the  */
+/* bits will be generic for all video decoders and each bit has an associated*/
+/* meaning as mentioned below. The unused bit fields are reserved for future */
+/* extenstions and will be zero in the current implementation                */
+
+typedef enum {
+    /* Bit 8  - Applied concealment.                                         */
+    IVD_APPLIEDCONCEALMENT                      = 0x8,
+    /* Bit 9 - Insufficient input data.                                     */
+    IVD_INSUFFICIENTDATA                        = 0x9,
+    /* Bit 10 - Data problem/corruption.                                     */
+    IVD_CORRUPTEDDATA                           = 0xa,
+    /* Bit 11 - Header problem/corruption.                                   */
+    IVD_CORRUPTEDHEADER                         = 0xb,
+    /* Bit 12 - Unsupported feature/parameter in input.                      */
+    IVD_UNSUPPORTEDINPUT                        = 0xc,
+    /* Bit 13 - Unsupported input parameter orconfiguration.                 */
+    IVD_UNSUPPORTEDPARAM                        = 0xd,
+    /* Bit 14 - Fatal error (stop the codec).If there is an                  */
+    /* error and this bit is not set, the error is a recoverable one.        */
+    IVD_FATALERROR                              = 0xe,
+    /* Bit 15 - Invalid bitstream. Applies when Bitstream/YUV frame          */
+    /* buffer for encode/decode call is made with non-valid or zero u4_size  */
+    /* data                                                                  */
+    IVD_INVALID_BITSTREAM                       = 0xf,
+    /* Bit 16          */
+    IVD_INCOMPLETE_BITSTREAM                    = 0x10,
+    IVD_ERROR_BITS_T_DUMMY_ELEMENT              = 0x7FFFFFFF
+}IVD_ERROR_BITS_T;
+
+
+/* IVD_CONTROL_API_COMMAND_TYPE_T: Video Control API command type            */
+typedef enum {
+    IVD_ERROR_NONE                              = 0x0,
+    IVD_NUM_MEM_REC_FAILED                      = 0x1,
+    IVD_NUM_REC_NOT_SUFFICIENT                  = 0x2,
+    IVD_FILL_MEM_REC_FAILED                     = 0x3,
+    IVD_REQUESTED_WIDTH_NOT_SUPPPORTED          = 0x4,
+    IVD_REQUESTED_HEIGHT_NOT_SUPPPORTED         = 0x5,
+    IVD_INIT_DEC_FAILED                         = 0x6,
+    IVD_INIT_DEC_NOT_SUFFICIENT                 = 0x7,
+    IVD_INIT_DEC_WIDTH_NOT_SUPPPORTED           = 0x8,
+    IVD_INIT_DEC_HEIGHT_NOT_SUPPPORTED          = 0x9,
+    IVD_INIT_DEC_MEM_NOT_ALIGNED                = 0xa,
+    IVD_INIT_DEC_COL_FMT_NOT_SUPPORTED          = 0xb,
+    IVD_INIT_DEC_MEM_REC_NOT_SUFFICIENT         = 0xc,
+    IVD_GET_VERSION_DATABUFFER_SZ_INSUFFICIENT  = 0xd,
+    IVD_BUFFER_SIZE_SET_TO_ZERO                 = 0xe,
+    IVD_UNEXPECTED_END_OF_STREAM                = 0xf,
+    IVD_SEQUENCE_HEADER_NOT_DECODED             = 0x10,
+    IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED       = 0x11,
+    IVD_MAX_FRAME_LIMIT_REACHED                 = 0x12,
+    IVD_IP_API_STRUCT_SIZE_INCORRECT            = 0x13,
+    IVD_OP_API_STRUCT_SIZE_INCORRECT            = 0x14,
+    IVD_HANDLE_NULL                             = 0x15,
+    IVD_HANDLE_STRUCT_SIZE_INCORRECT            = 0x16,
+    IVD_INVALID_HANDLE_NULL                     = 0x17,
+    IVD_INVALID_API_CMD                         = 0x18,
+    IVD_UNSUPPORTED_API_CMD                     = 0x19,
+    IVD_MEM_REC_STRUCT_SIZE_INCORRECT           = 0x1a,
+    IVD_DISP_FRM_ZERO_OP_BUFS                   = 0x1b,
+    IVD_DISP_FRM_OP_BUF_NULL                    = 0x1c,
+    IVD_DISP_FRM_ZERO_OP_BUF_SIZE               = 0x1d,
+    IVD_DEC_FRM_BS_BUF_NULL                     = 0x1e,
+    IVD_SET_CONFG_INVALID_DEC_MODE              = 0x1f,
+    IVD_SET_CONFG_UNSUPPORTED_DISP_WIDTH        = 0x20,
+    IVD_RESET_FAILED                            = 0x21,
+    IVD_INIT_DEC_MEM_REC_OVERLAP_ERR            = 0x22,
+    IVD_INIT_DEC_MEM_REC_BASE_NULL              = 0x23,
+    IVD_INIT_DEC_MEM_REC_ALIGNMENT_ERR          = 0x24,
+    IVD_INIT_DEC_MEM_REC_INSUFFICIENT_SIZE      = 0x25,
+    IVD_INIT_DEC_MEM_REC_INCORRECT_TYPE         = 0x26,
+    IVD_DEC_NUMBYTES_INV                        = 0x27,
+    IVD_DEC_REF_BUF_NULL                        = 0x28,
+    IVD_DEC_FRM_SKIPPED                         = 0x29,
+    IVD_RES_CHANGED                             = 0x2a,
+    IVD_DUMMY_ELEMENT_FOR_CODEC_EXTENSIONS      = 0x300,
+}IVD_ERROR_CODES_T;
+
+
+/*****************************************************************************/
+/* Structure                                                                 */
+/*****************************************************************************/
+/* structure for passing output buffers to codec during get display buffer   */
+/* call                                                                      */
+typedef struct {
+
+    /**
+     * number of output buffers
+     */
+    UWORD32             u4_num_bufs;
+
+    /**
+     *list of pointers to output buffers
+     */
+    UWORD8              *pu1_bufs[IVD_VIDDEC_MAX_IO_BUFFERS];
+
+    /**
+     * sizes of each output buffer
+     */
+    UWORD32             u4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
+
+}ivd_out_bufdesc_t;
+
+/*****************************************************************************/
+/*   Initialize decoder                                                      */
+/*****************************************************************************/
+
+/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_INIT                              */
+
+
+typedef struct {
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     *  e_cmd
+     */
+    IVD_API_COMMAND_TYPE_T                  e_cmd;
+
+    /**
+     *no memrecords which are allocated on request of codec through fill mem records
+     */
+    UWORD32                                 u4_num_mem_rec;
+    /**
+     * maximum height for which codec should be initialized
+     */
+    UWORD32                                 u4_frm_max_wd;
+    /**
+     * maximum width for which codec should be initialized
+     */
+    UWORD32                                 u4_frm_max_ht;
+    /**
+     * format in which codec has to give out frame data for display
+     */
+    IV_COLOR_FORMAT_T                       e_output_format;
+    /**
+     * pointer to memrecord array, which contains allocated resources
+     */
+    iv_mem_rec_t                            *pv_mem_rec_location;
+}ivd_init_ip_t;
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * u4_error_code
+     */
+    UWORD32                                 u4_error_code;
+}ivd_init_op_t;
+
+
+/*****************************************************************************/
+/*   Video Decode                                                            */
+/*****************************************************************************/
+
+
+/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_VIDEO_DECODE                      */
+
+
+typedef struct {
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * e_cmd
+     */
+    IVD_API_COMMAND_TYPE_T                  e_cmd;
+
+    /**
+     * u4_ts
+     */
+    UWORD32                                 u4_ts;
+
+    /**
+     * u4_num_Bytes
+     */
+    UWORD32                                 u4_num_Bytes;
+
+    /**
+     * pv_stream_buffer
+     */
+    void                                    *pv_stream_buffer;
+
+    /**
+     * output buffer desc
+     */
+    ivd_out_bufdesc_t                       s_out_buffer;
+
+}ivd_video_decode_ip_t;
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * u4_error_code
+     */
+    UWORD32                                 u4_error_code;
+
+    /**
+     * num_bytes_consumed
+     */
+    UWORD32                                 u4_num_bytes_consumed;
+
+    /**
+     * pic_wd
+     */
+    UWORD32                                 u4_pic_wd;
+
+    /**
+     * pic_ht
+     */
+    UWORD32                                 u4_pic_ht;
+
+    /**
+     * pic_type
+     */
+    IV_PICTURE_CODING_TYPE_T                e_pic_type;
+
+    /**
+     * frame_decoded_flag
+     */
+    UWORD32                                 u4_frame_decoded_flag;
+
+    /**
+     * new_seq
+     */
+    UWORD32                                 u4_new_seq;
+
+    /**
+     * output_present
+     */
+    UWORD32                                 u4_output_present;
+
+    /**
+     * progressive_frame_flag
+     */
+    UWORD32                                 u4_progressive_frame_flag;
+
+    /**
+     * is_ref_flag
+     */
+    UWORD32                                 u4_is_ref_flag;
+
+    /**
+     * output_format
+     */
+    IV_COLOR_FORMAT_T                       e_output_format;
+
+    /**
+     * disp_frm_buf
+     */
+    iv_yuv_buf_t                            s_disp_frm_buf;
+
+    /**
+     * fld_type
+     */
+    IV_FLD_TYPE_T                           e4_fld_type;
+
+    /**
+     * ts
+     */
+    UWORD32                                 u4_ts;
+
+    /**
+     * disp_buf_id
+     */
+    UWORD32                                 u4_disp_buf_id;
+}ivd_video_decode_op_t;
+
+
+/*****************************************************************************/
+/*   Get Display Frame                                                       */
+/*****************************************************************************/
+
+
+/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_GET_DISPLAY_FRAME                 */
+
+typedef struct
+{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * e_cmd
+     */
+    IVD_API_COMMAND_TYPE_T                  e_cmd;
+
+    /**
+     * output buffer desc
+     */
+    ivd_out_bufdesc_t                       s_out_buffer;
+
+}ivd_get_display_frame_ip_t;
+
+
+typedef struct
+{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * error_code
+     */
+    UWORD32                                 u4_error_code;
+
+    /**
+     * progressive_frame_flag
+     */
+    UWORD32                                 u4_progressive_frame_flag;
+
+    /**
+     * pic_type
+     */
+    IV_PICTURE_CODING_TYPE_T                e_pic_type;
+
+    /**
+     * is_ref_flag
+     */
+    UWORD32                                 u4_is_ref_flag;
+
+    /**
+     * output_format
+     */
+    IV_COLOR_FORMAT_T                       e_output_format;
+
+    /**
+     * disp_frm_buf
+     */
+    iv_yuv_buf_t                            s_disp_frm_buf;
+
+    /**
+     * fld_type
+     */
+    IV_FLD_TYPE_T                           e4_fld_type;
+
+    /**
+     * ts
+     */
+    UWORD32                                 u4_ts;
+
+    /**
+     * disp_buf_id
+     */
+    UWORD32                                 u4_disp_buf_id;
+}ivd_get_display_frame_op_t;
+
+/*****************************************************************************/
+/*   Set Display Frame                                                       */
+/*****************************************************************************/
+
+
+/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_SET_DISPLAY_FRAME                 */
+
+typedef struct
+{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                  e_cmd;
+
+    /**
+     * num_disp_bufs
+     */
+    UWORD32                                 num_disp_bufs;
+
+    /**
+     * output buffer desc
+     */
+    ivd_out_bufdesc_t                       s_disp_buffer[IVD_VIDDEC_MAX_IO_BUFFERS];
+
+}ivd_set_display_frame_ip_t;
+
+
+typedef struct
+{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * error code
+     */
+    UWORD32                                 u4_error_code;
+}ivd_set_display_frame_op_t;
+
+
+/*****************************************************************************/
+/*   Release Display Frame                                                       */
+/*****************************************************************************/
+
+
+/* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_SET_DISPLAY_FRAME                 */
+
+typedef struct
+{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * e_cmd
+     */
+    IVD_API_COMMAND_TYPE_T                  e_cmd;
+
+    /**
+     * disp_buf_id
+     */
+    UWORD32                                 u4_disp_buf_id;
+}ivd_rel_display_frame_ip_t;
+
+
+typedef struct
+{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * error code
+     */
+    UWORD32                                 u4_error_code;
+}ivd_rel_display_frame_op_t;
+
+/*****************************************************************************/
+/*   Video control  Flush                                                    */
+/*****************************************************************************/
+/* IVD_API_COMMAND_TYPE_T::e_cmd            = IVD_CMD_VIDEO_CTL              */
+/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd    = IVD_CMD_ctl_FLUSH          */
+
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                  e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T          e_sub_cmd;
+}ivd_ctl_flush_ip_t;
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * error code
+     */
+    UWORD32                                 u4_error_code;
+}ivd_ctl_flush_op_t;
+
+/*****************************************************************************/
+/*   Video control reset                                                     */
+/*****************************************************************************/
+/* IVD_API_COMMAND_TYPE_T::e_cmd            = IVD_CMD_VIDEO_CTL              */
+/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd    = IVD_CMD_ctl_RESET          */
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                  e_cmd;
+
+    /**
+     * sub_cmd
+     */
+
+    IVD_CONTROL_API_COMMAND_TYPE_T          e_sub_cmd;
+}ivd_ctl_reset_ip_t;
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                 u4_size;
+
+    /**
+     * error code
+     */
+    UWORD32                                 u4_error_code;
+}ivd_ctl_reset_op_t;
+
+
+/*****************************************************************************/
+/*   Video control  Set Params                                               */
+/*****************************************************************************/
+/* IVD_API_COMMAND_TYPE_T::e_cmd        = IVD_CMD_VIDEO_CTL                  */
+/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_SETPARAMS           */
+/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_SETDEFAULT          */
+
+
+
+typedef struct {
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                      e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+
+    /**
+     * vid_dec_mode
+     */
+    IVD_VIDEO_DECODE_MODE_T                     e_vid_dec_mode;
+
+    /**
+     * disp_wd
+     */
+    UWORD32                                     u4_disp_wd;
+
+    /**
+     * frm_skip_mode
+     */
+    IVD_FRAME_SKIP_MODE_T                       e_frm_skip_mode;
+
+    /**
+     * frm_out_mode
+     */
+    IVD_DISPLAY_FRAME_OUT_MODE_T                e_frm_out_mode;
+}ivd_ctl_set_config_ip_t;
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * u4_error_code
+     */
+    UWORD32                                     u4_error_code;
+}ivd_ctl_set_config_op_t;
+
+/*****************************************************************************/
+/*   Video control:Get Buf Info                                              */
+/*****************************************************************************/
+
+/* IVD_API_COMMAND_TYPE_T::e_cmd         = IVD_CMD_VIDEO_CTL                 */
+/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_GETBUFINFO          */
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     *  e_cmd
+     */
+    IVD_API_COMMAND_TYPE_T                      e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+}ivd_ctl_getbufinfo_ip_t;
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * error code
+     */
+    UWORD32                                     u4_error_code;
+
+    /**
+     * no of display buffer sets required by codec
+     */
+    UWORD32                                     u4_num_disp_bufs;
+
+    /**
+     * no of input buffers required for codec
+     */
+    UWORD32                                     u4_min_num_in_bufs;
+
+    /**
+     * no of output buffers required for codec
+     */
+    UWORD32                                     u4_min_num_out_bufs;
+
+    /**
+     * sizes of each input buffer required
+     */
+    UWORD32                                     u4_min_in_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
+
+    /**
+     * sizes of each output buffer required
+     */
+    UWORD32                                     u4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
+}ivd_ctl_getbufinfo_op_t;
+
+
+/*****************************************************************************/
+/*   Video control:Getstatus Call                                            */
+/*****************************************************************************/
+
+
+/* IVD_API_COMMAND_TYPE_T::e_cmd        = IVD_CMD_VIDEO_CTL                  */
+/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_GETPARAMS           */
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                      e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+}ivd_ctl_getstatus_ip_t;
+
+
+typedef struct{
+
+     /**
+      * u4_size of the structure
+      */
+    UWORD32                  u4_size;
+
+    /**
+      * error code
+      */
+    UWORD32                  u4_error_code;
+
+    /**
+     * no of display buffer sets required by codec
+     */
+    UWORD32                  u4_num_disp_bufs;
+
+    /**
+     * u4_pic_ht
+     */
+    UWORD32                  u4_pic_ht;
+
+    /**
+     * u4_pic_wd
+     */
+    UWORD32                  u4_pic_wd;
+
+    /**
+     * frame_rate
+     */
+    UWORD32                  u4_frame_rate;
+
+    /**
+     * u4_bit_rate
+     */
+    UWORD32                  u4_bit_rate;
+
+    /**
+     * content_type
+     */
+    IV_CONTENT_TYPE_T        e_content_type;
+
+    /**
+     * output_chroma_format
+     */
+    IV_COLOR_FORMAT_T        e_output_chroma_format;
+
+    /**
+     * no of input buffers required for codec
+     */
+    UWORD32                  u4_min_num_in_bufs;
+
+    /**
+     * no of output buffers required for codec
+     */
+    UWORD32                  u4_min_num_out_bufs;
+
+    /**
+     * sizes of each input buffer required
+     */
+    UWORD32                  u4_min_in_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
+
+    /**
+     * sizes of each output buffer required
+     */
+    UWORD32                  u4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
+}ivd_ctl_getstatus_op_t;
+
+
+/*****************************************************************************/
+/*   Video control:Get Version Info                                          */
+/*****************************************************************************/
+
+/* IVD_API_COMMAND_TYPE_T::e_cmd        = IVD_CMD_VIDEO_CTL                  */
+/* IVD_CONTROL_API_COMMAND_TYPE_T::e_sub_cmd=IVD_CMD_ctl_GETVERSION          */
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                      e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+
+    /**
+     * pv_version_buffer
+     */
+    void                                        *pv_version_buffer;
+
+    /**
+     * version_buffer_size
+     */
+    UWORD32                                     u4_version_buffer_size;
+}ivd_ctl_getversioninfo_ip_t;
+
+
+typedef struct{
+    /**
+     * u4_size of the structure
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * error code
+     */
+    UWORD32                                     u4_error_code;
+}ivd_ctl_getversioninfo_op_t;
+
+#endif /* __IVD_H__ */
+
diff --git a/decoder/mips/impeg2d_function_selector.c b/decoder/mips/impeg2d_function_selector.c
new file mode 100644
index 0000000..a72c1f9
--- /dev/null
+++ b/decoder/mips/impeg2d_function_selector.c
@@ -0,0 +1,83 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector.c
+*
+* @brief
+*  Contains functions to initialize function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "iv_datatypedef.h"
+#include "iv.h"
+
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_globals.h"
+#include "impeg2_mem_func.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_macros.h"
+
+#include "ivd.h"
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_structs.h"
+#include "impeg2d_vld_tables.h"
+#include "impeg2d_vld.h"
+#include "impeg2d_pic_proc.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_mc.h"
+
+void impeg2d_init_function_ptr_generic(void *pv_codec);
+
+void impeg2d_init_function_ptr(void *pv_codec)
+{
+    dec_state_t *ps_codec   = (dec_state_t *)pv_codec;
+
+    impeg2d_init_function_ptr_generic(ps_codec);
+}
+
+void impeg2d_init_arch(void *pv_codec)
+{
+    dec_state_t *ps_codec = (dec_state_t *)pv_codec;
+
+    ps_codec->e_processor_arch = ARCH_NA;
+}
diff --git a/decoder/x86/impeg2d_function_selector.c b/decoder/x86/impeg2d_function_selector.c
new file mode 100755
index 0000000..ddadb02
--- /dev/null
+++ b/decoder/x86/impeg2d_function_selector.c
@@ -0,0 +1,117 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector.c
+*
+* @brief
+*  Contains functions to initialize function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* User include files */
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ivd.h"
+#include "ithread.h"
+
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_mem_func.h"
+
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_structs.h"
+
+void impeg2d_init_function_ptr_generic(void *pv_codec);
+void impeg2d_init_function_ptr_ssse3(void *pv_codec);
+void impeg2d_init_function_ptr_sse42(void *pv_codec);
+void impeg2d_init_function_ptr_avx2(void *pv_codec);
+
+void impeg2d_init_function_ptr(void *pv_codec)
+{
+    dec_state_t *ps_codec = (dec_state_t *)pv_codec;
+
+    impeg2d_init_function_ptr_generic(pv_codec);
+    switch(ps_codec->e_processor_arch)
+    {
+        case ARCH_X86_GENERIC:
+            impeg2d_init_function_ptr_generic(pv_codec);
+        break;
+        case ARCH_X86_SSSE3:
+            impeg2d_init_function_ptr_ssse3(pv_codec);
+            break;
+        case ARCH_X86_SSE42:
+            impeg2d_init_function_ptr_sse42(pv_codec);
+        break;
+        case ARCH_X86_AVX2:
+#ifndef DISABLE_AVX2
+            impeg2d_init_function_ptr_avx2(pv_codec);
+#else
+            impeg2d_init_function_ptr_sse42(pv_codec);
+#endif
+        break;
+        default:
+            impeg2d_init_function_ptr_sse42(pv_codec);
+        break;
+    }
+}
+void impeg2d_init_arch(void *pv_codec)
+{
+    dec_state_t *ps_codec = (dec_state_t*) pv_codec;
+
+#ifdef DEFAULT_ARCH
+#if DEFAULT_ARCH == D_ARCH_X86_SSE42
+    ps_codec->e_processor_arch = ARCH_X86_SSE42;
+#elif DEFAULT_ARCH == D_ARCH_X86_SSSE3
+    ps_codec->e_processor_arch = ARCH_X86_SSSE3;
+#elif DEFAULT_ARCH == D_ARCH_X86_AVX2
+    ps_codec->e_processor_arch = D_ARCH_X86_AVX2;
+#else
+    ps_codec->e_processor_arch = ARCH_X86_GENERIC;
+#endif
+#else
+    ps_codec->e_processor_arch = ARCH_X86_SSE42;
+#endif
+
+}
diff --git a/decoder/x86/impeg2d_function_selector_avx2.c b/decoder/x86/impeg2d_function_selector_avx2.c
new file mode 100644
index 0000000..ab5d847
--- /dev/null
+++ b/decoder/x86/impeg2d_function_selector_avx2.c
@@ -0,0 +1,74 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector.c
+*
+* @brief
+*  Contains functions to initialize function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* User include files */
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ivd.h"
+#include "ithread.h"
+
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_mem_func.h"
+
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_structs.h"
+
+void impeg2d_init_function_ptr_avx2(void *pv_codec)
+{
+    dec_state_t *dec = (dec_state_t *)pv_codec;
+
+    dec->pf_idct_recon[0]                   = &impeg2_idct_recon_dc;
+    dec->pf_idct_recon[1]                   = &impeg2_idct_recon_dc_mismatch;
+    dec->pf_idct_recon[2]                   = &impeg2_idct_recon;
+    dec->pf_idct_recon[3]                   = &impeg2_idct_recon;
+}
diff --git a/decoder/x86/impeg2d_function_selector_sse42.c b/decoder/x86/impeg2d_function_selector_sse42.c
new file mode 100644
index 0000000..a4b6673
--- /dev/null
+++ b/decoder/x86/impeg2d_function_selector_sse42.c
@@ -0,0 +1,84 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector.c
+*
+* @brief
+*  Contains functions to initialize function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* User include files */
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ivd.h"
+#include "ithread.h"
+
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_mem_func.h"
+
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_structs.h"
+
+void impeg2d_init_function_ptr_sse42(void *pv_codec)
+{
+    dec_state_t *dec = (dec_state_t *)pv_codec;
+
+    dec->pf_idct_recon[0]                   = &impeg2_idct_recon_dc_sse42;
+    dec->pf_idct_recon[1]                   = &impeg2_idct_recon_dc_mismatch_sse42;
+    dec->pf_idct_recon[2]                   = &impeg2_idct_recon_sse42;
+    dec->pf_idct_recon[3]                   = &impeg2_idct_recon_sse42;
+
+    dec->pf_copy_mb                         = &impeg2_copy_mb_sse42;
+    dec->pf_interpolate                     = &impeg2_interpolate_sse42;
+    dec->pf_halfx_halfy_8x8                 = &impeg2_mc_halfx_halfy_8x8_sse42;
+    dec->pf_halfx_fully_8x8                 = &impeg2_mc_halfx_fully_8x8_sse42;
+    dec->pf_fullx_halfy_8x8                 = &impeg2_mc_fullx_halfy_8x8_sse42;
+    dec->pf_fullx_fully_8x8                 = &impeg2_mc_fullx_fully_8x8_sse42;
+
+    dec->pf_memset_8bit_8x8_block           = &impeg2_memset_8bit_8x8_block_sse42;
+    dec->pf_memset_16bit_8x8_linear_block   = &impeg2_memset0_16bit_8x8_linear_block_sse42;
+}
diff --git a/decoder/x86/impeg2d_function_selector_ssse3.c b/decoder/x86/impeg2d_function_selector_ssse3.c
new file mode 100644
index 0000000..fb6c345
--- /dev/null
+++ b/decoder/x86/impeg2d_function_selector_ssse3.c
@@ -0,0 +1,74 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *****************************************************************************
+ * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
+*/
+/**
+*******************************************************************************
+* @file
+*  impeg2d_function_selector.c
+*
+* @brief
+*  Contains functions to initialize function pointers used in mpeg2
+*
+* @author
+*  Naveen
+*
+* @par List of Functions:
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* User include files */
+#include "iv_datatypedef.h"
+#include "iv.h"
+#include "ivd.h"
+#include "ithread.h"
+
+#include "impeg2_macros.h"
+#include "impeg2_buf_mgr.h"
+#include "impeg2_disp_mgr.h"
+#include "impeg2_defs.h"
+#include "impeg2_platform_macros.h"
+#include "impeg2_inter_pred.h"
+#include "impeg2_idct.h"
+#include "impeg2_format_conv.h"
+#include "impeg2_mem_func.h"
+
+#include "impeg2d.h"
+#include "impeg2d_bitstream.h"
+#include "impeg2d_debug.h"
+#include "impeg2d_structs.h"
+
+void impeg2d_init_function_ptr_ssse3(void *pv_codec)
+{
+    dec_state_t *dec = (dec_state_t *)pv_codec;
+
+    dec->pf_idct_recon[0]                   = &impeg2_idct_recon_dc;
+    dec->pf_idct_recon[1]                   = &impeg2_idct_recon_dc_mismatch;
+    dec->pf_idct_recon[2]                   = &impeg2_idct_recon;
+    dec->pf_idct_recon[3]                   = &impeg2_idct_recon;
+}