encoder: fix invalid free of raw buffers am: 3e73f0d562 am: 39fd5ebf08 am: af5bd177be am: a45e73ed02

Original change: https://googleplex-android-review.googlesource.com/c/platform/external/libavc/+/14392080

Change-Id: I0de10d4ce0ac4b79c8a9db0b07fd6082fca8a08d
diff --git a/Android.bp b/Android.bp
index 732d386..ae0567e 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,7 +1,11 @@
 cc_library_static {
     name: "libavcdec",
     vendor_available: true,
-    shared_libs: ["liblog", "libcutils",],
+    host_supported: true,
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
 
     cflags: [
         "-fPIC",
@@ -240,12 +244,21 @@
         // cfi: true,
         blacklist: "libavc_blacklist.txt",
     },
+    apex_available: [
+        "//apex_available:platform", // used by libstagefright_soft_avcdec
+        "com.android.media.swcodec",
+    ],
+    min_sdk_version: "29",
 }
 
 cc_library_static {
     name: "libavcenc",
     vendor_available: true,
-    shared_libs: ["liblog", "libcutils",],
+    host_supported: true,
+    shared_libs: [
+        "liblog",
+        "libcutils",
+    ],
 
     cflags: [
         "-DNDEBUG",
@@ -320,6 +333,7 @@
         "encoder/irc_vbr_str_prms.c",
         "encoder/ime.c",
         "encoder/ime_distortion_metrics.c",
+        "encoder/ih264e_sei.c",
     ],
 
     arch: {
@@ -509,6 +523,11 @@
         // cfi: true,
         blacklist: "libavc_blacklist.txt",
     },
+    apex_available: [
+        "//apex_available:platform", //due to libstagefright_soft_avcenc
+        "com.android.media.swcodec",
+    ],
+    min_sdk_version: "29",
 }
 
 subdirs = ["test"]
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..46c9162
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,212 @@
+cmake_minimum_required(VERSION 3.5)
+
+set(AVC_ROOT "${CMAKE_CURRENT_SOURCE_DIR}")
+set(AVC_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}")
+
+if("${AVC_ROOT}" STREQUAL "${AVC_CONFIG_DIR}")
+  message(
+    FATAL_ERROR
+      "Building from within the libavc source tree is not supported.\n"
+      "Hint: Run these commands\n"
+      "$ rm -rf CMakeCache.txt CMakeFiles\n"
+      "$ mkdir -p ./build\n"
+      "$ cd ./build\n"
+      "And re-run CMake from the build directory.")
+endif()
+
+set(THREADS_PREFER_PTHREAD_FLAG ON)
+find_package(Threads REQUIRED)
+set(CMAKE_STATIC_LIBRARY_PREFIX "")
+
+if(SANITIZE)
+  string(TOLOWER ${SANITIZE} SANITIZE)
+
+  set(CMAKE_SANITIZER_C_FLAGS "-fno-omit-frame-pointer -fsanitize=${SANITIZE}")
+  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_SANITIZER_C_FLAGS}")
+endif()
+
+list(APPEND LIBAVCDEC_SRCS
+            "${AVC_ROOT}/common/ih264_buf_mgr.c"
+            "${AVC_ROOT}/common/ih264_disp_mgr.c"
+            "${AVC_ROOT}/common/ih264_inter_pred_filters.c"
+            "${AVC_ROOT}/common/ih264_luma_intra_pred_filters.c"
+            "${AVC_ROOT}/common/ih264_chroma_intra_pred_filters.c"
+            "${AVC_ROOT}/common/ih264_padding.c"
+            "${AVC_ROOT}/common/ih264_mem_fns.c"
+            "${AVC_ROOT}/common/ih264_deblk_edge_filters.c"
+            "${AVC_ROOT}/common/ih264_iquant_itrans_recon.c"
+            "${AVC_ROOT}/common/ih264_ihadamard_scaling.c"
+            "${AVC_ROOT}/common/ih264_weighted_pred.c"
+            "${AVC_ROOT}/common/ithread.c"
+            "${AVC_ROOT}/decoder/ih264d_cabac.c"
+            "${AVC_ROOT}/decoder/ih264d_parse_mb_header.c"
+            "${AVC_ROOT}/decoder/ih264d_parse_cabac.c"
+            "${AVC_ROOT}/decoder/ih264d_process_intra_mb.c"
+            "${AVC_ROOT}/decoder/ih264d_inter_pred.c"
+            "${AVC_ROOT}/decoder/ih264d_parse_bslice.c"
+            "${AVC_ROOT}/decoder/ih264d_parse_pslice.c"
+            "${AVC_ROOT}/decoder/ih264d_parse_islice.c"
+            "${AVC_ROOT}/decoder/ih264d_cabac_init_tables.c"
+            "${AVC_ROOT}/decoder/ih264d_bitstrm.c"
+            "${AVC_ROOT}/decoder/ih264d_compute_bs.c"
+            "${AVC_ROOT}/decoder/ih264d_deblocking.c"
+            "${AVC_ROOT}/decoder/ih264d_parse_headers.c"
+            "${AVC_ROOT}/decoder/ih264d_mb_utils.c"
+            "${AVC_ROOT}/decoder/ih264d_mvpred.c"
+            "${AVC_ROOT}/decoder/ih264d_utils.c"
+            "${AVC_ROOT}/decoder/ih264d_process_bslice.c"
+            "${AVC_ROOT}/decoder/ih264d_process_pslice.c"
+            "${AVC_ROOT}/decoder/ih264d_parse_slice.c"
+            "${AVC_ROOT}/decoder/ih264d_quant_scaling.c"
+            "${AVC_ROOT}/decoder/ih264d_parse_cavlc.c"
+            "${AVC_ROOT}/decoder/ih264d_dpb_mgr.c"
+            "${AVC_ROOT}/decoder/ih264d_nal.c"
+            "${AVC_ROOT}/decoder/ih264d_sei.c"
+            "${AVC_ROOT}/decoder/ih264d_tables.c"
+            "${AVC_ROOT}/decoder/ih264d_vui.c"
+            "${AVC_ROOT}/decoder/ih264d_format_conv.c"
+            "${AVC_ROOT}/decoder/ih264d_thread_parse_decode.c"
+            "${AVC_ROOT}/decoder/ih264d_api.c"
+            "${AVC_ROOT}/decoder/ih264d_thread_compute_bs.c"
+            "${AVC_ROOT}/decoder/ih264d_function_selector_generic.c")
+
+list(APPEND LIBAVCDEC_X86_SRCS
+            "${AVC_ROOT}/decoder/x86/ih264d_function_selector.c"
+            "${AVC_ROOT}/decoder/x86/ih264d_function_selector_sse42.c"
+            "${AVC_ROOT}/decoder/x86/ih264d_function_selector_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_inter_pred_filters_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_deblk_luma_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_deblk_chroma_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_padding_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_mem_fns_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_iquant_itrans_recon_dc_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_iquant_itrans_recon_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_luma_intra_pred_filters_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_chroma_intra_pred_filters_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_iquant_itrans_recon_sse42.c"
+            "${AVC_ROOT}/common/x86/ih264_weighted_pred_sse42.c"
+            "${AVC_ROOT}/common/x86/ih264_ihadamard_scaling_sse42.c")
+
+set(LIBAVCDEC_INCLUDES ${AVC_ROOT}/common ${AVC_ROOT}/decoder)
+
+set(LIBAVCDEC_X86_C_FLAGS
+    "-DX86 -DDISABLE_AVX2 -msse4.2 -mno-avx -DDEFAULT_ARCH=D_ARCH_X86_SSE42")
+set(LIBAVCDEC_X86_INCLUDES ${AVC_ROOT}/common/x86 ${AVC_ROOT}/decoder/x86)
+set(LIBAVCDEC_C_FLAGS "${LIBAVCDEC_X86_C_FLAGS}")
+
+include_directories(${LIBAVCDEC_INCLUDES} ${LIBAVCDEC_X86_INCLUDES})
+add_library(libavcdec ${LIBAVCDEC_SRCS} ${LIBAVCDEC_X86_SRCS})
+set_target_properties(libavcdec PROPERTIES COMPILE_FLAGS "${LIBAVCDEC_C_FLAGS}")
+
+list(APPEND AVCDEC_SRCS "${AVC_ROOT}/test/decoder/main.c")
+
+add_executable(avcdec ${AVCDEC_SRCS})
+set_target_properties(avcdec
+                      PROPERTIES COMPILE_FLAGS "-DMD5_DISABLE -DPROFILE_ENABLE")
+target_link_libraries(avcdec libavcdec Threads::Threads)
+
+list(APPEND LIBAVCENC_SRCS
+            "${AVC_ROOT}/common/ih264_resi_trans_quant.c"
+            "${AVC_ROOT}/common/ih264_iquant_itrans_recon.c"
+            "${AVC_ROOT}/common/ih264_ihadamard_scaling.c"
+            "${AVC_ROOT}/common/ih264_inter_pred_filters.c"
+            "${AVC_ROOT}/common/ih264_luma_intra_pred_filters.c"
+            "${AVC_ROOT}/common/ih264_chroma_intra_pred_filters.c"
+            "${AVC_ROOT}/common/ih264_padding.c"
+            "${AVC_ROOT}/common/ih264_mem_fns.c"
+            "${AVC_ROOT}/common/ih264_deblk_edge_filters.c"
+            "${AVC_ROOT}/common/ih264_deblk_tables.c"
+            "${AVC_ROOT}/common/ih264_cavlc_tables.c"
+            "${AVC_ROOT}/common/ih264_cabac_tables.c"
+            "${AVC_ROOT}/common/ih264_common_tables.c"
+            "${AVC_ROOT}/common/ih264_trans_data.c"
+            "${AVC_ROOT}/common/ih264_buf_mgr.c"
+            "${AVC_ROOT}/common/ih264_dpb_mgr.c"
+            "${AVC_ROOT}/common/ih264_list.c"
+            "${AVC_ROOT}/common/ithread.c"
+            "${AVC_ROOT}/encoder/ih264e_globals.c"
+            "${AVC_ROOT}/encoder/ih264e_intra_modes_eval.c"
+            "${AVC_ROOT}/encoder/ih264e_half_pel.c"
+            "${AVC_ROOT}/encoder/ih264e_mc.c"
+            "${AVC_ROOT}/encoder/ih264e_me.c"
+            "${AVC_ROOT}/encoder/ih264e_rc_mem_interface.c"
+            "${AVC_ROOT}/encoder/ih264e_time_stamp.c"
+            "${AVC_ROOT}/encoder/ih264e_modify_frm_rate.c"
+            "${AVC_ROOT}/encoder/ih264e_rate_control.c"
+            "${AVC_ROOT}/encoder/ih264e_core_coding.c"
+            "${AVC_ROOT}/encoder/ih264e_deblk.c"
+            "${AVC_ROOT}/encoder/ih264e_api.c"
+            "${AVC_ROOT}/encoder/ih264e_process.c"
+            "${AVC_ROOT}/encoder/ih264e_encode.c"
+            "${AVC_ROOT}/encoder/ih264e_utils.c"
+            "${AVC_ROOT}/encoder/ih264e_version.c"
+            "${AVC_ROOT}/encoder/ih264e_bitstream.c"
+            "${AVC_ROOT}/encoder/ih264e_cavlc.c"
+            "${AVC_ROOT}/encoder/ih264e_cabac_init.c"
+            "${AVC_ROOT}/encoder/ih264e_cabac.c"
+            "${AVC_ROOT}/encoder/ih264e_cabac_encode.c"
+            "${AVC_ROOT}/encoder/ih264e_encode_header.c"
+            "${AVC_ROOT}/encoder/ih264e_function_selector_generic.c"
+            "${AVC_ROOT}/encoder/ih264e_fmt_conv.c"
+            "${AVC_ROOT}/encoder/ih264e_sei.c"
+            "${AVC_ROOT}/encoder/irc_rate_control_api.c"
+            "${AVC_ROOT}/encoder/irc_bit_allocation.c"
+            "${AVC_ROOT}/encoder/irc_cbr_buffer_control.c"
+            "${AVC_ROOT}/encoder/irc_est_sad.c"
+            "${AVC_ROOT}/encoder/irc_fixed_point_error_bits.c"
+            "${AVC_ROOT}/encoder/irc_frame_info_collector.c"
+            "${AVC_ROOT}/encoder/irc_mb_model_based.c"
+            "${AVC_ROOT}/encoder/irc_picture_type.c"
+            "${AVC_ROOT}/encoder/irc_rd_model.c"
+            "${AVC_ROOT}/encoder/irc_vbr_storage_vbv.c"
+            "${AVC_ROOT}/encoder/irc_vbr_str_prms.c"
+            "${AVC_ROOT}/encoder/ime.c"
+            "${AVC_ROOT}/encoder/ime_distortion_metrics.c")
+
+list(APPEND LIBAVCENC_X86_SRCS
+            "${AVC_ROOT}/encoder/x86/ih264e_function_selector.c"
+            "${AVC_ROOT}/encoder/x86/ih264e_function_selector_sse42.c"
+            "${AVC_ROOT}/encoder/x86/ih264e_function_selector_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_iquant_itrans_recon_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_iquant_itrans_recon_dc_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_ihadamard_scaling_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_inter_pred_filters_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_mem_fns_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_padding_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_luma_intra_pred_filters_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_chroma_intra_pred_filters_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_deblk_chroma_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_deblk_luma_ssse3.c"
+            "${AVC_ROOT}/common/x86/ih264_iquant_itrans_recon_sse42.c"
+            "${AVC_ROOT}/common/x86/ih264_ihadamard_scaling_sse42.c"
+            "${AVC_ROOT}/common/x86/ih264_resi_trans_quant_sse42.c"
+            "${AVC_ROOT}/common/x86/ih264_weighted_pred_sse42.c"
+            "${AVC_ROOT}/encoder/x86/ih264e_half_pel_ssse3.c"
+            "${AVC_ROOT}/encoder/x86/ih264e_intra_modes_eval_ssse3.c"
+            "${AVC_ROOT}/encoder/x86/ime_distortion_metrics_sse42.c")
+
+set(LIBAVCENC_INCLUDES ${AVC_ROOT}/common ${AVC_ROOT}/encoder)
+
+set(LIBAVCENC_X86_C_FLAGS "-msse4.2 -mno-avx -UHP_PL -DN_MB_ENABLE")
+set(LIBAVCENC_C_FLAGS "${LIBAVCENC_X86_C_FLAGS}")
+set(LIBAVCENC_X86_INCLUDES ${AVC_ROOT}/common/x86 ${AVC_ROOT}/encoder/x86)
+
+include_directories(${LIBAVCENC_INCLUDES} ${LIBAVCENC_X86_INCLUDES})
+add_library(libavcenc ${LIBAVCENC_SRCS} ${LIBAVCENC_X86_SRCS})
+set_target_properties(libavcenc PROPERTIES COMPILE_FLAGS "${LIBAVCENC_C_FLAGS}")
+
+list(APPEND AVCENC_SRCS
+            "${AVC_ROOT}/test/encoder/main.c"
+            "${AVC_ROOT}/test/encoder/psnr.c"
+            "${AVC_ROOT}/test/encoder/input.c"
+            "${AVC_ROOT}/test/encoder/output.c"
+            "${AVC_ROOT}/test/encoder/recon.c")
+
+add_executable(avcenc ${AVCENC_SRCS})
+set_target_properties(avcenc
+                      PROPERTIES COMPILE_FLAGS
+                                 "-DARM -DMD5_DISABLE -DPROFILE_ENABLE")
+target_link_libraries(avcenc
+                      libavcenc
+                      Threads::Threads
+                      m)
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..ecf8b8e
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,2 @@
+[Hook Scripts]
+mainline_hook = ${REPO_ROOT}/frameworks/av/tools/mainline_hook_project.sh
diff --git a/common/ih264_defs.h b/common/ih264_defs.h
index b26a5a4..9c84be9 100644
--- a/common/ih264_defs.h
+++ b/common/ih264_defs.h
@@ -611,6 +611,16 @@
 #define MAX_H264_QP 51
 
 /**
+ * @brief  Minimum delta scale supported in H264 spec
+ */
+#define MIN_H264_DELTA_SCALE (-128)
+
+/**
+ * @brief  Maximum delta scale supported in H264 spec
+ */
+#define MAX_H264_DELTA_SCALE 127
+
+/**
  * @breif  Total number of transform sizes
  * used for sizeID while getting scale matrix
  */
@@ -690,4 +700,50 @@
 #define TOP_MB_AVAILABLE_MASK       0x04
 #define TOP_RIGHT_MB_AVAILABLE_MASK 0x08
 
+/**
+******************************************************************************
+ *  @brief  SEI macros
+******************************************************************************
+ */
+/*
+ * @brief  specifies the number of colour primary components of the mastering display
+ */
+#define NUM_SEI_MDCV_PRIMARIES      3
+
+/*
+ * @brief  specifies the number of colour primary components of the nominal content colour volume
+ */
+#define NUM_SEI_CCV_PRIMARIES       3
+
+#define DISPLAY_PRIMARIES_X_UPPER_LIMIT                37000
+#define DISPLAY_PRIMARIES_X_LOWER_LIMIT                5
+#define DISPLAY_PRIMARIES_X_DIVISION_FACTOR            5
+
+#define DISPLAY_PRIMARIES_Y_UPPER_LIMIT                42000
+#define DISPLAY_PRIMARIES_Y_LOWER_LIMIT                5
+#define DISPLAY_PRIMARIES_Y_DIVISION_FACTOR            5
+
+#define WHITE_POINT_X_UPPER_LIMIT                      37000
+#define WHITE_POINT_X_LOWER_LIMIT                      5
+#define WHITE_POINT_X_DIVISION_FACTOR                  5
+
+#define WHITE_POINT_Y_UPPER_LIMIT                      42000
+#define WHITE_POINT_Y_LOWER_LIMIT                      5
+#define WHITE_POINT_Y_DIVISION_FACTOR                  5
+
+#define MAX_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT        100000000
+#define MAX_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT        50000
+#define MAX_DISPLAY_MASTERING_LUMINANCE_DIVISION_FACTOR    10000
+
+#define MIN_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT        50000
+#define MIN_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT        1
+
+#define AMBIENT_LIGHT_X_UPPER_LIMIT        50000
+#define AMBIENT_LIGHT_Y_UPPER_LIMIT        50000
+
+#define CCV_PRIMARIES_X_UPPER_LIMIT        5000000
+#define CCV_PRIMARIES_X_LOWER_LIMIT        -5000000
+#define CCV_PRIMARIES_Y_UPPER_LIMIT        5000000
+#define CCV_PRIMARIES_Y_LOWER_LIMIT        -5000000
+
 #endif /* IH264_DEFS_H_ */
diff --git a/common/ih264_structs.h b/common/ih264_structs.h
index 0a7c940..d1eaeac 100644
--- a/common/ih264_structs.h
+++ b/common/ih264_structs.h
@@ -1719,4 +1719,200 @@
     UWORD32     b16_chroma_csbp: 8;
 }inter_mb_t;
 
+/**
+ * Structure to hold Mastering Display Color Volume SEI
+ */
+typedef struct
+{
+    /**
+     * Array to store the display_primaries_x values
+     */
+    UWORD16 au2_display_primaries_x[NUM_SEI_MDCV_PRIMARIES];
+
+    /**
+     * Array to store the display_primaries_y values
+     */
+    UWORD16 au2_display_primaries_y[NUM_SEI_MDCV_PRIMARIES];
+
+    /**
+     * Variable to store the white point x value
+     */
+    UWORD16 u2_white_point_x;
+
+    /**
+     * Variable to store the white point y value
+     */
+    UWORD16 u2_white_point_y;
+
+    /**
+     * Variable to store the max display mastering luminance value
+     */
+    UWORD32 u4_max_display_mastering_luminance;
+
+    /**
+     * Variable to store the min display mastering luminance value
+     */
+    UWORD32 u4_min_display_mastering_luminance;
+}sei_mdcv_params_t;
+
+
+/**
+ *  Structure for Content Light Level Info
+ *
+ */
+typedef struct
+{
+    /**
+     * The maximum pixel intensity of all samples
+     */
+    UWORD16 u2_max_content_light_level;
+
+    /**
+     * The average pixel intensity of all samples
+     */
+    UWORD16 u2_max_pic_average_light_level;
+}sei_cll_params_t;
+
+
+/**
+ * Structure to hold Ambient viewing environment SEI
+ */
+typedef struct
+{
+    /**
+     * specifies the environmental illluminance of the ambient viewing environment
+     */
+    UWORD32 u4_ambient_illuminance;
+
+    /*
+     * specify the normalized x chromaticity coordinates of the
+     * environmental ambient light in the nominal viewing environment
+     */
+    UWORD16 u2_ambient_light_x;
+
+    /*
+    * specify the normalized y chromaticity coordinates of the
+    * environmental ambient light in the nominal viewing environment
+    */
+    UWORD16 u2_ambient_light_y;
+}sei_ave_params_t;
+
+
+/**
+ * Structure to hold Content color volume SEI
+ */
+typedef struct
+{
+    /*
+     * Flag used to control persistence of CCV SEI messages
+     */
+    UWORD8 u1_ccv_cancel_flag;
+
+    /*
+     * specifies the persistence of the CCV SEI message for the current layer
+     */
+    UWORD8 u1_ccv_persistence_flag;
+
+    /*
+     * specifies the presence of syntax elements ccv_primaries_x and ccv_primaries_y
+     */
+    UWORD8 u1_ccv_primaries_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_min_luminance_value is present
+     */
+    UWORD8 u1_ccv_min_luminance_value_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_max_luminance_value is present
+     */
+    UWORD8 u1_ccv_max_luminance_value_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_avg_luminance_value is present
+     */
+    UWORD8 u1_ccv_avg_luminance_value_present_flag;
+
+    /*
+     * shall be equal to 0 in bitstreams conforming to this version. Other values
+     * for reserved_zero_2bits are reserved for future use
+     */
+    UWORD8 u1_ccv_reserved_zero_2bits;
+
+    /*
+     * specify the normalized x chromaticity coordinates of the colour
+     * primary component c of the nominal content colour volume
+     */
+    WORD32 ai4_ccv_primaries_x[NUM_SEI_CCV_PRIMARIES];
+
+    /*
+     * specify the normalized y chromaticity coordinates of the colour
+     * primary component c of the nominal content colour volume
+     */
+    WORD32 ai4_ccv_primaries_y[NUM_SEI_CCV_PRIMARIES];
+
+    /*
+     * specifies the normalized minimum luminance value
+     */
+    UWORD32 u4_ccv_min_luminance_value;
+
+    /*
+     * specifies the normalized maximum luminance value
+     */
+    UWORD32 u4_ccv_max_luminance_value;
+
+    /*
+     * specifies the normalized average luminance value
+     */
+    UWORD32 u4_ccv_avg_luminance_value;
+}sei_ccv_params_t;
+
+
+/**
+ * Structure to hold SEI parameters Info
+ */
+typedef struct
+{
+    /**
+     *  mastering display color volume info present flag
+     */
+    UWORD8 u1_sei_mdcv_params_present_flag;
+
+    /*
+     * MDCV parameters
+     */
+    sei_mdcv_params_t s_sei_mdcv_params;
+
+    /**
+     * content light level info present flag
+     */
+    UWORD8 u1_sei_cll_params_present_flag;
+
+    /*
+     * CLL parameters
+     */
+    sei_cll_params_t s_sei_cll_params;
+
+    /**
+     * ambient viewing environment info present flag
+     */
+    UWORD8 u1_sei_ave_params_present_flag;
+
+    /*
+     * AVE parameters
+     */
+    sei_ave_params_t s_sei_ave_params;
+
+    /**
+     * content color volume info present flag
+     */
+    UWORD8 u1_sei_ccv_params_present_flag;
+
+    /*
+     * CCV parameters
+     */
+    sei_ccv_params_t s_sei_ccv_params;
+} sei_params_t;
+
+
 #endif /* _IH264_STRUCTS_H_ */
diff --git a/decoder/ih264d.h b/decoder/ih264d.h
index 83f8a1f..fa9d7f1 100644
--- a/decoder/ih264d.h
+++ b/decoder/ih264d.h
@@ -198,7 +198,20 @@
     IH264D_CMD_CTL_GPU_ENABLE_DISABLE    = IVD_CMD_CTL_CODEC_SUBCMD_START + 0x200,
 
     /** Set degrade level */
-    IH264D_CMD_CTL_DEGRADE               = IVD_CMD_CTL_CODEC_SUBCMD_START + 0x300
+    IH264D_CMD_CTL_DEGRADE               = IVD_CMD_CTL_CODEC_SUBCMD_START + 0x300,
+
+    /** Get SEI MDCV parameters */
+    IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS   = IVD_CMD_CTL_CODEC_SUBCMD_START + 0x301,
+
+    /** Get SEI CLL parameters */
+    IH264D_CMD_CTL_GET_SEI_CLL_PARAMS    = IVD_CMD_CTL_CODEC_SUBCMD_START + 0x302,
+
+    /** Get SEI AVE parameters */
+    IH264D_CMD_CTL_GET_SEI_AVE_PARAMS    = IVD_CMD_CTL_CODEC_SUBCMD_START + 0x303,
+
+    /** Get SEI CCV parameters */
+    IH264D_CMD_CTL_GET_SEI_CCV_PARAMS    = IVD_CMD_CTL_CODEC_SUBCMD_START + 0x304
+
 }IH264D_CMD_CTL_SUB_CMDS;
 /*****************************************************************************/
 /*   Video control  Flush                                                    */
@@ -469,6 +482,252 @@
     UWORD32                                     u4_max_dec_frame_buffering;
 }ih264d_ctl_get_vui_params_op_t;
 
+
+typedef struct
+{
+    /**
+     * u4_size
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                      e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+}ih264d_ctl_get_sei_mdcv_params_ip_t;
+
+typedef struct
+{
+    /**
+     * u4_size
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * error_code
+     */
+    UWORD32                                     u4_error_code;
+
+    /**
+     * Array to store the display_primaries_x values
+     */
+    UWORD16                                     au2_display_primaries_x[NUM_SEI_MDCV_PRIMARIES];
+
+    /**
+     * Array to store the display_primaries_y values
+     */
+    UWORD16                                     au2_display_primaries_y[NUM_SEI_MDCV_PRIMARIES];
+
+    /**
+     * Variable to store the white point x value
+     */
+    UWORD16                                     u2_white_point_x;
+
+    /**
+     * Variable to store the white point y value
+     */
+    UWORD16                                     u2_white_point_y;
+
+    /**
+     * Variable to store the max display mastering luminance value
+     */
+    UWORD32                                     u4_max_display_mastering_luminance;
+
+    /**
+     * Variable to store the min display mastering luminance value
+     */
+    UWORD32                                     u4_min_display_mastering_luminance;
+}ih264d_ctl_get_sei_mdcv_params_op_t;
+
+typedef struct
+{
+    /**
+     * u4_size
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                      e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+}ih264d_ctl_get_sei_cll_params_ip_t;
+
+typedef struct
+{
+    /**
+     * u4_size
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * error_code
+     */
+    UWORD32                                     u4_error_code;
+
+    /**
+     * The maximum pixel intensity of all samples
+     */
+    UWORD16                                     u2_max_content_light_level;
+
+    /**
+     * The average pixel intensity of all samples
+     */
+    UWORD16                                     u2_max_pic_average_light_level;
+} ih264d_ctl_get_sei_cll_params_op_t;
+
+typedef struct
+{
+    /**
+     * u4_size
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                      e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+}ih264d_ctl_get_sei_ave_params_ip_t;
+
+typedef struct
+{
+    /**
+     * u4_size
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * error_code
+     */
+    UWORD32                                     u4_error_code;
+
+    /**
+     * specifies the environmental illluminance of the ambient viewing environment
+     */
+    UWORD32                                     u4_ambient_illuminance;
+
+    /*
+     * specify the normalized x chromaticity coordinates of the
+     * environmental ambient light in the nominal viewing environment
+     */
+    UWORD16                                     u2_ambient_light_x;
+
+    /*
+     * specify the normalized y chromaticity coordinates of the
+     * environmental ambient light in the nominal viewing environment
+     */
+    UWORD16                                     u2_ambient_light_y;
+} ih264d_ctl_get_sei_ave_params_op_t;
+
+typedef struct
+{
+    /**
+     * u4_size
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * cmd
+     */
+    IVD_API_COMMAND_TYPE_T                      e_cmd;
+
+    /**
+     * sub_cmd
+     */
+    IVD_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+}ih264d_ctl_get_sei_ccv_params_ip_t;
+
+typedef struct
+{
+    /**
+     * u4_size
+     */
+    UWORD32                                     u4_size;
+
+    /**
+     * error_code
+     */
+    UWORD32                                     u4_error_code;
+
+    /*
+     * Flag used to control persistence of CCV SEI messages
+     */
+    UWORD8                                      u1_ccv_cancel_flag;
+
+    /*
+     * specifies the persistence of the CCV SEI message for the current layer
+     */
+    UWORD8                                      u1_ccv_persistence_flag;
+
+    /*
+     * specifies the presence of syntax elements ccv_primaries_x and ccv_primaries_y
+     */
+    UWORD8                                      u1_ccv_primaries_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_min_luminance_value is present
+     */
+    UWORD8                                      u1_ccv_min_luminance_value_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_max_luminance_value is present
+     */
+    UWORD8                                      u1_ccv_max_luminance_value_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_avg_luminance_value is present
+     */
+    UWORD8                                      u1_ccv_avg_luminance_value_present_flag;
+
+    /*
+     * shall be equal to 0 in bitstreams conforming to this version. Other values
+     * for reserved_zero_2bits are reserved for future use
+     */
+    UWORD8                                      u1_ccv_reserved_zero_2bits;
+
+    /*
+     * specify the normalized x chromaticity coordinates of the colour
+     * primary component c of the nominal content colour volume
+     */
+    WORD32                                      ai4_ccv_primaries_x[NUM_SEI_CCV_PRIMARIES];
+
+    /*
+     * specify the normalized y chromaticity coordinates of the colour
+     * primary component c of the nominal content colour volume
+     */
+    WORD32                                      ai4_ccv_primaries_y[NUM_SEI_CCV_PRIMARIES];
+
+    /*
+     * specifies the normalized minimum luminance value
+     */
+    UWORD32                                     u4_ccv_min_luminance_value;
+
+    /*
+     * specifies the normalized maximum luminance value
+     */
+    UWORD32                                     u4_ccv_max_luminance_value;
+
+    /*
+     * specifies the normalized average luminance value
+     */
+    UWORD32                                     u4_ccv_avg_luminance_value;
+} ih264d_ctl_get_sei_ccv_params_op_t;
+
+
 #ifdef __cplusplus
 } /* closing brace for extern "C" */
 #endif
diff --git a/decoder/ih264d_api.c b/decoder/ih264d_api.c
index 02b706c..3a73938 100644
--- a/decoder/ih264d_api.c
+++ b/decoder/ih264d_api.c
@@ -103,7 +103,7 @@
 #define CODEC_RELEASE_VER       "05.00"
 #define CODEC_VENDOR            "ITTIAM"
 #define MAXVERSION_STRLEN       511
-#ifdef __ANDROID__
+#ifdef ANDROID
 #define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor)    \
     snprintf(version_string, MAXVERSION_STRLEN,                                                     \
              "@(#)Id:%s_%s Ver:%s Released by %s",                                                  \
@@ -139,6 +139,22 @@
                              void *pv_api_ip,
                              void *pv_api_op);
 
+WORD32 ih264d_get_sei_mdcv_params(iv_obj_t *dec_hdl,
+                                  void *pv_api_ip,
+                                  void *pv_api_op);
+
+WORD32 ih264d_get_sei_cll_params(iv_obj_t *dec_hdl,
+                                 void *pv_api_ip,
+                                 void *pv_api_op);
+
+WORD32 ih264d_get_sei_ave_params(iv_obj_t *dec_hdl,
+                                 void *pv_api_ip,
+                                 void *pv_api_op);
+
+WORD32 ih264d_get_sei_ccv_params(iv_obj_t *dec_hdl,
+                                 void *pv_api_ip,
+                                 void *pv_api_op);
+
 WORD32 ih264d_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op);
 
 WORD32 ih264d_deblock_display(dec_struct_t *ps_dec);
@@ -155,6 +171,31 @@
 void ih264d_fill_output_struct_from_context(dec_struct_t *ps_dec,
                                             ivd_video_decode_op_t *ps_dec_op);
 
+/*!
+ **************************************************************************
+ * \if Function name : ih264d_export_sei_params \endif
+ *
+ * \brief
+ *    Exports sei params from decoder to application.
+ *
+ * \return
+ *    0 on Success and error code otherwise
+ **************************************************************************
+ */
+
+void ih264d_export_sei_params(ivd_sei_decode_op_t *ps_sei_decode_op, dec_struct_t *ps_dec)
+{
+    WORD32 i4_status = IV_SUCCESS;
+    sei *ps_sei = (sei *)ps_dec->pv_disp_sei_params;
+
+    i4_status = ih264d_export_sei_mdcv_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
+    i4_status = ih264d_export_sei_cll_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
+    i4_status = ih264d_export_sei_ave_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
+    i4_status = ih264d_export_sei_ccv_params(ps_sei_decode_op, ps_sei, &ps_dec->s_sei_export);
+
+    UNUSED(i4_status);
+}
+
 static IV_API_CALL_STATUS_T api_check_struct_sanity(iv_obj_t *ps_handle,
                                                     void *pv_api_ip,
                                                     void *pv_api_op)
@@ -777,6 +818,114 @@
 
                     break;
                 }
+                case IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS:
+                {
+                    ih264d_ctl_get_sei_mdcv_params_ip_t *ps_ip;
+                    ih264d_ctl_get_sei_mdcv_params_op_t *ps_op;
+
+                    ps_ip = (ih264d_ctl_get_sei_mdcv_params_ip_t *)pv_api_ip;
+                    ps_op = (ih264d_ctl_get_sei_mdcv_params_op_t *)pv_api_op;
+
+                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_mdcv_params_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(ih264d_ctl_get_sei_mdcv_params_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 IH264D_CMD_CTL_GET_SEI_CLL_PARAMS:
+                {
+                    ih264d_ctl_get_sei_cll_params_ip_t *ps_ip;
+                    ih264d_ctl_get_sei_cll_params_op_t *ps_op;
+
+                    ps_ip = (ih264d_ctl_get_sei_cll_params_ip_t *)pv_api_ip;
+                    ps_op = (ih264d_ctl_get_sei_cll_params_op_t *)pv_api_op;
+
+                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_cll_params_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(ih264d_ctl_get_sei_cll_params_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 IH264D_CMD_CTL_GET_SEI_AVE_PARAMS:
+                {
+                    ih264d_ctl_get_sei_ave_params_ip_t *ps_ip;
+                    ih264d_ctl_get_sei_ave_params_op_t *ps_op;
+
+                    ps_ip = (ih264d_ctl_get_sei_ave_params_ip_t *)pv_api_ip;
+                    ps_op = (ih264d_ctl_get_sei_ave_params_op_t *)pv_api_op;
+
+                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_ave_params_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(ih264d_ctl_get_sei_ave_params_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 IH264D_CMD_CTL_GET_SEI_CCV_PARAMS:
+                {
+                    ih264d_ctl_get_sei_ccv_params_ip_t *ps_ip;
+                    ih264d_ctl_get_sei_ccv_params_op_t *ps_op;
+
+                    ps_ip = (ih264d_ctl_get_sei_ccv_params_ip_t *)pv_api_ip;
+                    ps_op = (ih264d_ctl_get_sei_ccv_params_op_t *)pv_api_op;
+
+                    if(ps_ip->u4_size != sizeof(ih264d_ctl_get_sei_ccv_params_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(ih264d_ctl_get_sei_ccv_params_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 IH264D_CMD_CTL_SET_NUM_CORES:
                 {
                     ih264d_ctl_set_num_cores_ip_t *ps_ip;
@@ -939,6 +1088,9 @@
     size = sizeof(sei);
     memset(ps_dec->ps_sei, 0, size);
 
+    size = sizeof(sei);
+    memset(ps_dec->ps_sei_parse, 0, size);
+
     size = sizeof(dpb_commands_t);
     memset(ps_dec->ps_dpb_cmds, 0, size);
 
@@ -1187,6 +1339,7 @@
     PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_pic_buf_base);
     PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dec_err_status);
     PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sei);
+    PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_sei_parse);
     PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_dpb_cmds);
     PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_bitstrm);
     PS_DEC_ALIGNED_FREE(ps_dec, ps_dec->ps_cur_slice);
@@ -1358,6 +1511,12 @@
     memset(pv_buf, 0, size);
     ps_dec->ps_sei = (sei *)pv_buf;
 
+    size = sizeof(sei);
+    pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
+    RETURN_IF((NULL == pv_buf), IV_FAIL);
+    memset(pv_buf, 0, size);
+    ps_dec->ps_sei_parse = (sei *)pv_buf;
+
     size = sizeof(dpb_commands_t);
     pv_buf = pf_aligned_alloc(pv_mem_ctxt, 128, size);
     RETURN_IF((NULL == pv_buf), IV_FAIL);
@@ -1640,6 +1799,10 @@
         case ERROR_INV_RANGE_QP_T:
         case ERROR_INV_SPS_PPS_T:
         case ERROR_INV_SLICE_HDR_T:
+        case ERROR_INV_SEI_MDCV_PARAMS:
+        case ERROR_INV_SEI_CLL_PARAMS:
+        case ERROR_INV_SEI_AVE_PARAMS:
+        case ERROR_INV_SEI_CCV_PARAMS:
             temp = 1 << IVD_CORRUPTEDHEADER;
             break;
 
@@ -2038,6 +2201,8 @@
             ps_dec->u4_output_present = 1;
 
         }
+        ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
+
         ih264d_release_display_field(ps_dec, &(ps_dec->s_disp_op));
 
         ps_dec_op->u4_pic_wd = (UWORD32)ps_dec->u2_disp_width;
@@ -3342,7 +3507,22 @@
             ret = ih264d_get_vui_params(dec_hdl, (void *)pv_api_ip,
                                         (void *)pv_api_op);
             break;
-
+        case IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS:
+            ret = ih264d_get_sei_mdcv_params(dec_hdl, (void *)pv_api_ip,
+                                             (void *)pv_api_op);
+            break;
+        case IH264D_CMD_CTL_GET_SEI_CLL_PARAMS:
+            ret = ih264d_get_sei_cll_params(dec_hdl, (void *)pv_api_ip,
+                                            (void *)pv_api_op);
+            break;
+        case IH264D_CMD_CTL_GET_SEI_AVE_PARAMS:
+            ret = ih264d_get_sei_ave_params(dec_hdl, (void *)pv_api_ip,
+                                            (void *)pv_api_op);
+            break;
+        case IH264D_CMD_CTL_GET_SEI_CCV_PARAMS:
+            ret = ih264d_get_sei_ccv_params(dec_hdl, (void *)pv_api_ip,
+                                            (void *)pv_api_op);
+            break;
         case IH264D_CMD_CTL_SET_PROCESSOR:
             ret = ih264d_set_processor(dec_hdl, (void *)pv_api_ip,
                                        (void *)pv_api_op);
@@ -3635,6 +3815,238 @@
 
     return IV_SUCCESS;
 }
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_get_sei_mdcv_params                               */
+/*                                                                           */
+/*  Description   : This function populates SEI mdcv message in              */
+/*                     output structure                                      */
+/*  Inputs        : iv_obj_t decoder handle                                  */
+/*                : pv_api_ip pointer to input structure                     */
+/*                : pv_api_op pointer to output structure                    */
+/*  Outputs       :                                                          */
+/*  Returns       : returns 0; 1 with error code when MDCV is not present    */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                                                           */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_get_sei_mdcv_params(iv_obj_t *dec_hdl,
+                                  void *pv_api_ip,
+                                  void *pv_api_op)
+{
+    ih264d_ctl_get_sei_mdcv_params_ip_t *ps_ip;
+    ih264d_ctl_get_sei_mdcv_params_op_t *ps_op;
+    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
+    sei_mdcv_params_t *ps_sei_mdcv;
+    WORD32 i4_count;
+
+    ps_ip = (ih264d_ctl_get_sei_mdcv_params_ip_t *)pv_api_ip;
+    ps_op = (ih264d_ctl_get_sei_mdcv_params_op_t *)pv_api_op;
+    UNUSED(ps_ip);
+
+    if(0 == ps_dec->s_sei_export.u1_sei_mdcv_params_present_flag)
+    {
+        ps_op->u4_error_code = ERROR_SEI_MDCV_PARAMS_NOT_FOUND;
+        return IV_FAIL;
+    }
+
+    ps_sei_mdcv = &ps_dec->s_sei_export.s_sei_mdcv_params;
+
+    for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
+    {
+        ps_op->au2_display_primaries_x[i4_count] = ps_sei_mdcv->au2_display_primaries_x[i4_count];
+        ps_op->au2_display_primaries_y[i4_count] = ps_sei_mdcv->au2_display_primaries_y[i4_count];
+    }
+
+    ps_op->u2_white_point_x = ps_sei_mdcv->u2_white_point_x;
+    ps_op->u2_white_point_y = ps_sei_mdcv->u2_white_point_y;
+    ps_op->u4_max_display_mastering_luminance = ps_sei_mdcv->u4_max_display_mastering_luminance;
+    ps_op->u4_min_display_mastering_luminance = ps_sei_mdcv->u4_min_display_mastering_luminance;
+
+    return IV_SUCCESS;
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_get_sei_cll_params                                */
+/*                                                                           */
+/*  Description   : This function populates SEI cll message in               */
+/*                     output structure                                      */
+/*  Inputs        : iv_obj_t decoder handle                                  */
+/*                : pv_api_ip pointer to input structure                     */
+/*                : pv_api_op pointer to output structure                    */
+/*  Outputs       :                                                          */
+/*  Returns       : returns 0; 1 with error code when CLL is not present     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                                                           */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_get_sei_cll_params(iv_obj_t *dec_hdl,
+                                 void *pv_api_ip,
+                                 void *pv_api_op)
+{
+    ih264d_ctl_get_sei_cll_params_ip_t *ps_ip;
+    ih264d_ctl_get_sei_cll_params_op_t *ps_op;
+    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
+    sei_cll_params_t *ps_sei_cll;
+
+    ps_ip = (ih264d_ctl_get_sei_cll_params_ip_t *)pv_api_ip;
+    ps_op = (ih264d_ctl_get_sei_cll_params_op_t *)pv_api_op;
+    UNUSED(ps_ip);
+
+    if(0 == ps_dec->s_sei_export.u1_sei_cll_params_present_flag)
+    {
+        ps_op->u4_error_code = ERROR_SEI_CLL_PARAMS_NOT_FOUND;
+        return IV_FAIL;
+    }
+
+    ps_sei_cll = &ps_dec->s_sei_export.s_sei_cll_params;
+
+    ps_op->u2_max_content_light_level = ps_sei_cll->u2_max_content_light_level;
+    ps_op->u2_max_pic_average_light_level = ps_sei_cll->u2_max_pic_average_light_level;
+
+    return IV_SUCCESS;
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_get_sei_ave_params                                */
+/*                                                                           */
+/*  Description   : This function populates SEI ave message in               */
+/*                     output structure                                      */
+/*  Inputs        : iv_obj_t decoder handle                                  */
+/*                : pv_api_ip pointer to input structure                     */
+/*                : pv_api_op pointer to output structure                    */
+/*  Outputs       :                                                          */
+/*  Returns       : returns 0; 1 with error code when AVE is not present     */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                                                           */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_get_sei_ave_params(iv_obj_t *dec_hdl,
+                                 void *pv_api_ip,
+                                 void *pv_api_op)
+{
+    ih264d_ctl_get_sei_ave_params_ip_t *ps_ip;
+    ih264d_ctl_get_sei_ave_params_op_t *ps_op;
+    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
+    sei_ave_params_t *ps_sei_ave;
+
+    ps_ip = (ih264d_ctl_get_sei_ave_params_ip_t *)pv_api_ip;
+    ps_op = (ih264d_ctl_get_sei_ave_params_op_t *)pv_api_op;
+    UNUSED(ps_ip);
+
+    if(0 == ps_dec->s_sei_export.u1_sei_ave_params_present_flag)
+    {
+        ps_op->u4_error_code = ERROR_SEI_AVE_PARAMS_NOT_FOUND;
+        return IV_FAIL;
+    }
+
+    ps_sei_ave = &ps_dec->s_sei_export.s_sei_ave_params;
+
+    ps_op->u4_ambient_illuminance = ps_sei_ave->u4_ambient_illuminance;
+    ps_op->u2_ambient_light_x = ps_sei_ave->u2_ambient_light_x;
+    ps_op->u2_ambient_light_y = ps_sei_ave->u2_ambient_light_y;
+
+    return IV_SUCCESS;
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_get_sei_ccv_params                                */
+/*                                                                           */
+/*  Description   : This function populates SEI mdcv message in              */
+/*                     output structure                                      */
+/*  Inputs        : iv_obj_t decoder handle                                  */
+/*                : pv_api_ip pointer to input structure                     */
+/*                : pv_api_op pointer to output structure                    */
+/*  Outputs       :                                                          */
+/*  Returns       : returns 0; 1 with error code when CCV is not present    */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                                                           */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_get_sei_ccv_params(iv_obj_t *dec_hdl,
+                                 void *pv_api_ip,
+                                 void *pv_api_op)
+{
+    ih264d_ctl_get_sei_ccv_params_ip_t *ps_ip;
+    ih264d_ctl_get_sei_ccv_params_op_t *ps_op;
+    dec_struct_t *ps_dec = dec_hdl->pv_codec_handle;
+    sei_ccv_params_t *ps_sei_ccv;
+    WORD32 i4_count;
+
+    ps_ip = (ih264d_ctl_get_sei_ccv_params_ip_t *)pv_api_ip;
+    ps_op = (ih264d_ctl_get_sei_ccv_params_op_t *)pv_api_op;
+    UNUSED(ps_ip);
+
+    if(0 == ps_dec->s_sei_export.u1_sei_ccv_params_present_flag)
+    {
+        ps_op->u4_error_code = ERROR_SEI_CCV_PARAMS_NOT_FOUND;
+        return IV_FAIL;
+    }
+
+    ps_sei_ccv = &ps_dec->s_sei_export.s_sei_ccv_params;
+
+    ps_op->u1_ccv_cancel_flag = ps_sei_ccv->u1_ccv_cancel_flag;
+
+    if(0 == ps_op->u1_ccv_cancel_flag)
+    {
+        ps_op->u1_ccv_persistence_flag = ps_sei_ccv->u1_ccv_persistence_flag;
+        ps_op->u1_ccv_primaries_present_flag = ps_sei_ccv->u1_ccv_primaries_present_flag;
+        ps_op->u1_ccv_min_luminance_value_present_flag =
+                    ps_sei_ccv->u1_ccv_min_luminance_value_present_flag;
+        ps_op->u1_ccv_max_luminance_value_present_flag =
+                    ps_sei_ccv->u1_ccv_max_luminance_value_present_flag;
+        ps_op->u1_ccv_avg_luminance_value_present_flag =
+                    ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag;
+        ps_op->u1_ccv_reserved_zero_2bits = ps_sei_ccv->u1_ccv_reserved_zero_2bits;
+
+        if(1 == ps_sei_ccv->u1_ccv_primaries_present_flag)
+        {
+            for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
+            {
+                ps_op->ai4_ccv_primaries_x[i4_count] = ps_sei_ccv->ai4_ccv_primaries_x[i4_count];
+                ps_op->ai4_ccv_primaries_y[i4_count] = ps_sei_ccv->ai4_ccv_primaries_y[i4_count];
+            }
+        }
+
+        if(1 == ps_sei_ccv->u1_ccv_min_luminance_value_present_flag)
+        {
+            ps_op->u4_ccv_min_luminance_value = ps_sei_ccv->u4_ccv_min_luminance_value;
+        }
+        if(1 == ps_sei_ccv->u1_ccv_max_luminance_value_present_flag)
+        {
+            ps_op->u4_ccv_max_luminance_value = ps_sei_ccv->u4_ccv_max_luminance_value;
+        }
+        if(1 == ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag)
+        {
+            ps_op->u4_ccv_avg_luminance_value = ps_sei_ccv->u4_ccv_avg_luminance_value;
+        }
+    }
+
+    return IV_SUCCESS;
+}
 
 WORD32 ih264d_set_num_cores(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
 {
@@ -3692,6 +4104,8 @@
     ps_dec_op->e4_fld_type = ps_dec->s_disp_op.e4_fld_type;
     ps_dec_op->u4_ts = ps_dec->s_disp_op.u4_ts;
     ps_dec_op->u4_disp_buf_id = ps_dec->s_disp_op.u4_disp_buf_id;
+
+    ih264d_export_sei_params(&ps_dec_op->s_sei_decode_op, ps_dec);
 }
 
 /*****************************************************************************/
diff --git a/decoder/ih264d_defs.h b/decoder/ih264d_defs.h
index 94d0d61..2758a59 100644
--- a/decoder/ih264d_defs.h
+++ b/decoder/ih264d_defs.h
@@ -608,6 +608,38 @@
 #define NUM_COEFFS_IN_4x4BLK 16
 #define CABAC_BITS_TO_READ 23
 
+#define DISPLAY_PRIMARIES_X_UPPER_LIMIT                37000
+#define DISPLAY_PRIMARIES_X_LOWER_LIMIT                5
+#define DISPLAY_PRIMARIES_X_DIVISION_FACTOR            5
+
+#define DISPLAY_PRIMARIES_Y_UPPER_LIMIT                42000
+#define DISPLAY_PRIMARIES_Y_LOWER_LIMIT                5
+#define DISPLAY_PRIMARIES_Y_DIVISION_FACTOR            5
+
+#define WHITE_POINT_X_UPPER_LIMIT                      37000
+#define WHITE_POINT_X_LOWER_LIMIT                      5
+#define WHITE_POINT_X_DIVISION_FACTOR                  5
+
+#define WHITE_POINT_Y_UPPER_LIMIT                      42000
+#define WHITE_POINT_Y_LOWER_LIMIT                      5
+#define WHITE_POINT_Y_DIVISION_FACTOR                  5
+
+#define MAX_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT        100000000
+#define MAX_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT        50000
+#define MAX_DISPLAY_MASTERING_LUMINANCE_DIVISION_FACTOR    10000
+
+#define MIN_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT        50000
+#define MIN_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT        1
+
+#define AMBIENT_LIGHT_X_UPPER_LIMIT        50000
+#define AMBIENT_LIGHT_Y_UPPER_LIMIT        50000
+
+#define CCV_PRIMARIES_X_UPPER_LIMIT        5000000
+#define CCV_PRIMARIES_X_LOWER_LIMIT        -5000000
+#define CCV_PRIMARIES_Y_UPPER_LIMIT        5000000
+#define CCV_PRIMARIES_Y_LOWER_LIMIT        -5000000
+
+
 #define MEMSET_16BYTES(pu4_start,value)                         \
 {                                                               \
     memset(pu4_start,value,16);                                 \
diff --git a/decoder/ih264d_dpb_mgr.c b/decoder/ih264d_dpb_mgr.c
index af414a5..0b8426b 100644
--- a/decoder/ih264d_dpb_mgr.c
+++ b/decoder/ih264d_dpb_mgr.c
@@ -1176,10 +1176,16 @@
 
                     {
                         UWORD32 i4_cur_pic_num = u4_cur_pic_num;
+                        WORD64 i8_pic_num;
                         u4_diff_pic_num = ps_mmc_params->u4_diff_pic_num; //Get absDiffPicnumMinus1
                         if(u1_fld_pic_flag)
                             i4_cur_pic_num = i4_cur_pic_num * 2 + 1;
-                        i4_pic_num = ((WORD32)i4_cur_pic_num - ((WORD32)u4_diff_pic_num + 1));
+                        i8_pic_num = ((WORD64)i4_cur_pic_num - ((WORD64)u4_diff_pic_num + 1));
+                        if(IS_OUT_OF_RANGE_S32(i8_pic_num))
+                        {
+                            return ERROR_DBP_MANAGER_T;
+                        }
+                        i4_pic_num = i8_pic_num;
                     }
 
                     if(ps_dpb_mgr->u1_num_st_ref_bufs > 0)
@@ -1223,11 +1229,17 @@
                 {
                     {
                         UWORD32 i4_cur_pic_num = u4_cur_pic_num;
+                        WORD64 i8_pic_num;
                         u4_diff_pic_num = ps_mmc_params->u4_diff_pic_num; //Get absDiffPicnumMinus1
                         if(u1_fld_pic_flag)
                             i4_cur_pic_num = i4_cur_pic_num * 2 + 1;
 
-                        i4_pic_num = (WORD32)i4_cur_pic_num - ((WORD32)u4_diff_pic_num + 1);
+                        i8_pic_num = (WORD64)i4_cur_pic_num - ((WORD64)u4_diff_pic_num + 1);
+                        if(IS_OUT_OF_RANGE_S32(i8_pic_num))
+                        {
+                            return ERROR_DBP_MANAGER_T;
+                        }
+                        i4_pic_num = i8_pic_num;
                     }
 
                     u4_lt_idx = ps_mmc_params->u4_lt_idx; //Get long term index
diff --git a/decoder/ih264d_error_handler.h b/decoder/ih264d_error_handler.h
index a3764c6..6cdbc81 100644
--- a/decoder/ih264d_error_handler.h
+++ b/decoder/ih264d_error_handler.h
@@ -114,7 +114,15 @@
     ERROR_NEW_FRAME_EXPECTED = 0x94,
     ERROR_INCOMPLETE_FRAME = 0x95,
     ERROR_VUI_PARAMS_NOT_FOUND = 0x96,
-    ERROR_INV_POC = 0x97
+    ERROR_INV_POC = 0x97,
+    ERROR_SEI_MDCV_PARAMS_NOT_FOUND = 0x98,
+    ERROR_SEI_CLL_PARAMS_NOT_FOUND = 0x99,
+    ERROR_SEI_AVE_PARAMS_NOT_FOUND = 0x9A,
+    ERROR_SEI_CCV_PARAMS_NOT_FOUND = 0x9B,
+    ERROR_INV_SEI_MDCV_PARAMS = 0x9C,
+    ERROR_INV_SEI_CLL_PARAMS = 0x9D,
+    ERROR_INV_SEI_AVE_PARAMS = 0x9E,
+    ERROR_INV_SEI_CCV_PARAMS = 0x9F
 
 } h264_decoder_error_code_t;
 
diff --git a/decoder/ih264d_parse_headers.c b/decoder/ih264d_parse_headers.c
index 03b423c..f286e29 100644
--- a/decoder/ih264d_parse_headers.c
+++ b/decoder/ih264d_parse_headers.c
@@ -62,6 +62,83 @@
 
 /*****************************************************************************/
 /*                                                                           */
+/*  Function Name : ih264d_get_pre_sei_params                                */
+/*                                                                           */
+/*  Description   : Gets valid pre-sei params in decoder struct from parse   */
+/*                  struct.                                                  */
+/*  Inputs        : u1_nal_unit_type slice type                              */
+/*                  ps_dec    Decoder parameters                             */
+/*  Globals       : None                                                     */
+/*  Outputs       : None                                                     */
+/*  Returns       : None                                                     */
+/*                                                                           */
+/*  Issues        : None                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                          Draft                            */
+/*                                                                           */
+/*****************************************************************************/
+
+void ih264d_get_pre_sei_params(dec_struct_t *ps_dec, UWORD8 u1_nal_unit_type)
+{
+    if((NULL != ps_dec->ps_sei) &&
+        ((0 == ps_dec->ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag) &&
+        (0 == ps_dec->ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag)))
+    {
+        ps_dec->ps_sei->u1_sei_ccv_params_present_flag = 0;
+        memset(&ps_dec->ps_sei->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
+    }
+
+    if((NULL != ps_dec->ps_cur_sps) &&
+        ((1 == ps_dec->ps_cur_sps->u1_vui_parameters_present_flag) &&
+        ((2 != ps_dec->ps_cur_sps->s_vui.u1_colour_primaries) &&
+        (2 != ps_dec->ps_cur_sps->s_vui.u1_matrix_coeffs) &&
+        (2 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars) &&
+        (4 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars) &&
+        (5 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars))))
+    {
+        if((1 == ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag) ||
+            (IDR_SLICE_NAL == u1_nal_unit_type))
+        {
+            ps_dec->ps_sei->u1_sei_ccv_params_present_flag =
+                        ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag;
+            ps_dec->ps_sei->s_sei_ccv_params = ps_dec->ps_sei_parse->s_sei_ccv_params;
+        }
+    }
+    else
+    {
+        ps_dec->ps_sei->u1_sei_ccv_params_present_flag = 0;
+        memset(&ps_dec->ps_sei->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
+    }
+
+    if(IDR_SLICE_NAL == u1_nal_unit_type)
+    {
+        ps_dec->ps_sei->u1_sei_mdcv_params_present_flag =
+                        ps_dec->ps_sei_parse->u1_sei_mdcv_params_present_flag;
+        ps_dec->ps_sei->s_sei_mdcv_params = ps_dec->ps_sei_parse->s_sei_mdcv_params;
+        ps_dec->ps_sei->u1_sei_cll_params_present_flag =
+                        ps_dec->ps_sei_parse->u1_sei_cll_params_present_flag;
+        ps_dec->ps_sei->s_sei_cll_params = ps_dec->ps_sei_parse->s_sei_cll_params;
+        ps_dec->ps_sei->u1_sei_ave_params_present_flag =
+                        ps_dec->ps_sei_parse->u1_sei_ave_params_present_flag;
+        ps_dec->ps_sei->s_sei_ave_params = ps_dec->ps_sei_parse->s_sei_ave_params;
+    }
+
+    ps_dec->ps_sei_parse->u1_sei_mdcv_params_present_flag = 0;
+    memset(&ps_dec->ps_sei_parse->s_sei_mdcv_params, 0, sizeof(sei_mdcv_params_t));
+    ps_dec->ps_sei_parse->u1_sei_cll_params_present_flag = 0;
+    memset(&ps_dec->ps_sei_parse->s_sei_cll_params, 0, sizeof(sei_cll_params_t));
+    ps_dec->ps_sei_parse->u1_sei_ave_params_present_flag = 0;
+    memset(&ps_dec->ps_sei_parse->s_sei_ave_params, 0, sizeof(sei_ave_params_t));
+    ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag = 0;
+    memset(&ps_dec->ps_sei_parse->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
+
+}
+
+/*****************************************************************************/
+/*                                                                           */
 /*  Function Name : ih264d_parse_slice_partition                                     */
 /*                                                                           */
 /*  Description   : This function is intended to parse and decode slice part */
@@ -348,9 +425,10 @@
 
                 if(ps_pps->u1_pic_scaling_list_present_flag[i4_i])
                 {
+                    WORD32 ret;
                     if(i4_i < 6)
                     {
-                        ih264d_scaling_list(
+                        ret = ih264d_scaling_list(
                                         ps_pps->i2_pic_scalinglist4x4[i4_i],
                                         16,
                                         &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
@@ -358,12 +436,17 @@
                     }
                     else
                     {
-                        ih264d_scaling_list(
+                        ret = ih264d_scaling_list(
                                         ps_pps->i2_pic_scalinglist8x8[i4_i - 6],
                                         64,
                                         &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
                                         ps_bitstrm);
                     }
+
+                    if(ret != OK)
+                    {
+                        return ret;
+                    }
                 }
             }
         }
@@ -663,7 +746,7 @@
                 {
                     if(i4_i < 6)
                     {
-                        ih264d_scaling_list(
+                        ret = ih264d_scaling_list(
                                         ps_seq->i2_scalinglist4x4[i4_i],
                                         16,
                                         &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
@@ -671,12 +754,16 @@
                     }
                     else
                     {
-                        ih264d_scaling_list(
+                        ret = ih264d_scaling_list(
                                         ps_seq->i2_scalinglist8x8[i4_i - 6],
                                         64,
                                         &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
                                         ps_bitstrm);
                     }
+                    if(ret != OK)
+                    {
+                        return ret;
+                    }
                 }
             }
         }
@@ -1169,6 +1256,7 @@
                     {
                         if(ps_dec->i4_header_decoded == 3)
                         {
+                            ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
                             /* ! */
                             ps_dec->u4_slice_start_code_found = 1;
 
diff --git a/decoder/ih264d_parse_slice.c b/decoder/ih264d_parse_slice.c
index 0f5598f..cc1d90f 100644
--- a/decoder/ih264d_parse_slice.c
+++ b/decoder/ih264d_parse_slice.c
@@ -431,7 +431,7 @@
         ps_dec->ps_cur_pic = ps_cur_pic;
         ps_dec->u1_pic_buf_id = cur_pic_buf_id;
         ps_cur_pic->u4_ts = ps_dec->u4_ts;
-
+        memcpy(&ps_cur_pic->s_sei_pic, ps_dec->ps_sei, sizeof(sei));
 
         ps_cur_pic->u1_mv_buf_id = cur_mv_buf_id;
         ps_dec->au1_pic_buf_id_mv_buf_id_map[cur_pic_buf_id] = cur_mv_buf_id;
@@ -825,7 +825,15 @@
             ps_cur_pic->u2_crop_offset_y = ps_dec->u2_crop_offset_y;
             ps_cur_pic->u2_crop_offset_uv = ps_dec->u2_crop_offset_uv;
             ps_cur_pic->u1_pic_type = 0;
-
+            {
+                UWORD64 i8_display_poc;
+                i8_display_poc = (UWORD64)ps_dec->i4_prev_max_display_seq +
+                            ps_dec->ps_cur_pic->i4_poc;
+                if(IS_OUT_OF_RANGE_S32(i8_display_poc))
+                {
+                    ps_dec->i4_prev_max_display_seq = 0;
+                }
+            }
             ret = ih264d_insert_pic_in_display_list(
                             ps_dec->ps_dpb_mgr,
                             ps_dec->u1_pic_buf_id,
diff --git a/decoder/ih264d_process_bslice.c b/decoder/ih264d_process_bslice.c
index 3ff15df..5dfba33 100644
--- a/decoder/ih264d_process_bslice.c
+++ b/decoder/ih264d_process_bslice.c
@@ -1193,6 +1193,23 @@
         }
     }
 }
+static int poc_compare(const void *pv_pic1, const void *pv_pic2)
+{
+    struct pic_buffer_t *ps_pic1 = *(struct pic_buffer_t **) pv_pic1;
+    struct pic_buffer_t *ps_pic2 = *(struct pic_buffer_t **) pv_pic2;
+    if (ps_pic1->i4_poc < ps_pic2->i4_poc)
+    {
+        return -1;
+    }
+    else if (ps_pic1->i4_poc > ps_pic2->i4_poc)
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
 /*!
  **************************************************************************
  * \if Function name : ih264d_init_ref_idx_lx_b \endif
@@ -1211,15 +1228,16 @@
     dpb_manager_t *ps_dpb_mgr;
     struct dpb_info_t *ps_next_dpb;
     WORD32 i_cur_poc, i_max_st_poc, i_min_st_poc, i_ref_poc, i_temp_poc;
-    WORD8 i;
+    WORD8 i, j;
     UWORD8 u1_max_lt_index, u1_min_lt_index;
     UWORD32 u4_lt_index;
+    WORD32 i_cur_idx;
     UWORD8 u1_field_pic_flag;
     dec_slice_params_t *ps_cur_slice;
     UWORD8 u1_L0, u1_L1;
     UWORD8 u1_num_short_term_bufs;
     UWORD8 u1_max_ref_idx_l0, u1_max_ref_idx_l1;
-
+    struct pic_buffer_t *aps_st_pic_bufs[2 * MAX_REF_BUFS] = {NULL};
     ps_cur_slice = ps_dec->ps_cur_slice;
     u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
     u1_max_ref_idx_l0 = ps_cur_slice->u1_num_ref_idx_lx_active[0]
@@ -1256,6 +1274,16 @@
         ps_next_dpb = ps_next_dpb->ps_prev_short;
     }
 
+    /* Sort ST ref pocs in ascending order */
+    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
+    for (j = 0; j < ps_dpb_mgr->u1_num_st_ref_bufs; j++)
+    {
+        aps_st_pic_bufs[j] = ps_next_dpb->ps_pic_buf;
+        ps_next_dpb = ps_next_dpb->ps_prev_short;
+    }
+    qsort(aps_st_pic_bufs, ps_dpb_mgr->u1_num_st_ref_bufs,
+        sizeof(aps_st_pic_bufs[0]), poc_compare);
+
     /* Start from LT head */
     ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
     if(ps_next_dpb)
@@ -1275,58 +1303,57 @@
 
     /* 1. Initialize refIdxL0 */
     u1_L0 = 0;
+    i_temp_poc = i_cur_poc;
     if(u1_field_pic_flag)
     {
         ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
         ps_ref_pic_buf_lx += MAX_REF_BUFS;
-        i_temp_poc = i_cur_poc;
     }
     else
     {
         ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
-        i_temp_poc = i_cur_poc - 1;
+        /* Avoid integer overflow while decrementing by one */
+        if (i_temp_poc > INT32_MIN)
+            i_temp_poc--;
+    }
+
+    i_cur_idx = -1;
+    for(j = 0; j < ps_dpb_mgr->u1_num_st_ref_bufs; j++)
+    {
+        if (NULL == aps_st_pic_bufs[j])
+        {
+            break;
+        }
+        if (aps_st_pic_bufs[j]->i4_poc <= i_temp_poc)
+        {
+            i_cur_idx = j;
+        }
     }
     /* Arrange all short term buffers in output order as given by POC */
     /* 1.1 Arrange POC's less than CurrPOC in the descending POC order starting
      from (CurrPOC - 1)*/
-    for(; i_temp_poc >= i_min_st_poc; i_temp_poc--)
+    for(j = i_cur_idx; j >= 0; j--)
     {
-        /* Start from ST head */
-        ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
-        for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
+        if(aps_st_pic_bufs[j])
         {
-            if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc)
-            {
-                /* Copy info in pic buffer */
-                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
-                                                   ps_next_dpb->ps_pic_buf);
-                ps_ref_pic_buf_lx++;
-                u1_L0++;
-                break;
-            }
-            ps_next_dpb = ps_next_dpb->ps_prev_short;
+            /* Copy info in pic buffer */
+            ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
+                                               aps_st_pic_bufs[j]);
+            ps_ref_pic_buf_lx++;
+            u1_L0++;
         }
     }
 
+    /* 1.2. Arrange POC's more than CurrPOC in the ascending POC order starting
+     from (CurrPOC + 1)*/
+    for(j = i_cur_idx + 1; j < ps_dpb_mgr->u1_num_st_ref_bufs; j++)
     {
-        /* 1.2. Arrange POC's more than CurrPOC in the ascending POC order starting
-         from (CurrPOC + 1)*/
-        for(i_temp_poc = i_cur_poc + 1; i_temp_poc <= i_max_st_poc; i_temp_poc++)
+        if(aps_st_pic_bufs[j])
         {
-            /* Start from ST head */
-            ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
-            for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
-            {
-                if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc)
-                {
-                    ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
-                                                       ps_next_dpb->ps_pic_buf);
-                    ps_ref_pic_buf_lx++;
-                    u1_L0++;
-                    break;
-                }
-                ps_next_dpb = ps_next_dpb->ps_prev_short;
-            }
+            ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
+                                               aps_st_pic_bufs[j]);
+            ps_ref_pic_buf_lx++;
+            u1_L0++;
         }
     }
 
@@ -1360,17 +1387,17 @@
         /* reference list to handle of errors        */
         {
             UWORD8 u1_i;
-            pic_buffer_t *ps_ref_pic;
+            pic_buffer_t ref_pic;
 
-            ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS;
+            ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS);
 
-            if(NULL == ps_ref_pic->pu1_buf1)
+            if(NULL == ref_pic.pu1_buf1)
             {
-                ps_ref_pic = ps_dec->ps_cur_pic;
+                ref_pic = *ps_dec->ps_cur_pic;
             }
             for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
             {
-                *ps_ref_pic_buf_lx = *ps_ref_pic;
+                *ps_ref_pic_buf_lx = ref_pic;
                 ps_ref_pic_buf_lx++;
             }
         }
@@ -1387,17 +1414,17 @@
     /* reference list to handle of errors        */
     {
         UWORD8 u1_i;
-        pic_buffer_t *ps_ref_pic;
+        pic_buffer_t ref_pic;
 
-        ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0];
+        ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0]);
 
-        if(NULL == ps_ref_pic->pu1_buf1)
+        if(NULL == ref_pic.pu1_buf1)
         {
-            ps_ref_pic = ps_dec->ps_cur_pic;
+            ref_pic = *ps_dec->ps_cur_pic;
         }
         for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
         {
-            *ps_ref_pic_buf_lx = *ps_ref_pic;
+            *ps_ref_pic_buf_lx = ref_pic;
             ps_ref_pic_buf_lx++;
         }
     }
@@ -1415,51 +1442,29 @@
 
         /* 2.1. Arrange POC's more than CurrPOC in the ascending POC order starting
          from (CurrPOC + 1)*/
-        for(i_temp_poc = i_cur_poc + 1; i_temp_poc <= i_max_st_poc; i_temp_poc++)
+        for(j = i_cur_idx + 1; j < ps_dpb_mgr->u1_num_st_ref_bufs; j++)
         {
-            /* Start from ST head */
-            ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
-            for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
+            if(aps_st_pic_bufs[j])
             {
-                if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc)
-                {
-                    ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
-                                                       ps_next_dpb->ps_pic_buf);
-                    ps_ref_pic_buf_lx++;
-                    u1_L1++;
-                    break;
-                }
-                ps_next_dpb = ps_next_dpb->ps_prev_short;
+                /* Start from ST head */
+                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
+                                                   aps_st_pic_bufs[j]);
+                ps_ref_pic_buf_lx++;
+                u1_L1++;
             }
         }
 
-        if(u1_field_pic_flag)
-        {
-            i_temp_poc = i_cur_poc;
-        }
-        else
-        {
-            i_temp_poc = i_cur_poc - 1;
-        }
-
         /* Arrange all short term buffers in output order as given by POC */
         /* 2.2 Arrange POC's less than CurrPOC in the descending POC order starting
          from (CurrPOC - 1)*/
-        for(; i_temp_poc >= i_min_st_poc; i_temp_poc--)
+        for(j = i_cur_idx; j >= 0; j--)
         {
-            /* Start from ST head */
-            ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
-            for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
+            if(aps_st_pic_bufs[j])
             {
-                if((WORD32)ps_next_dpb->ps_pic_buf->i4_poc == i_temp_poc)
-                {
-                    ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
-                                                       ps_next_dpb->ps_pic_buf);
-                    ps_ref_pic_buf_lx++;
-                    u1_L1++;
-                    break;
-                }
-                ps_next_dpb = ps_next_dpb->ps_prev_short;
+                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
+                                                   aps_st_pic_bufs[j]);
+                ps_ref_pic_buf_lx++;
+                u1_L1++;
             }
         }
 
@@ -1493,17 +1498,17 @@
             /* reference list to handle of errors        */
             {
                 UWORD8 u1_i;
-                pic_buffer_t *ps_ref_pic;
+                pic_buffer_t ref_pic;
 
-                ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS;
+                ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS);
 
-                if(NULL == ps_ref_pic->pu1_buf1)
+                if(NULL == ref_pic.pu1_buf1)
                 {
-                    ps_ref_pic = ps_dec->ps_cur_pic;
+                    ref_pic = *ps_dec->ps_cur_pic;
                 }
                 for(u1_i = u1_L1; u1_i < u1_max_ref_idx_l1; u1_i++)
                 {
-                    *ps_ref_pic_buf_lx = *ps_ref_pic;
+                    *ps_ref_pic_buf_lx = ref_pic;
                     ps_ref_pic_buf_lx++;
                 }
             }
@@ -1520,17 +1525,17 @@
         /* reference list to handle of errors        */
         {
             UWORD8 u1_i;
-            pic_buffer_t *ps_ref_pic;
+            pic_buffer_t ref_pic;
 
-            ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0];
+            ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0]);
 
-            if(NULL == ps_ref_pic->pu1_buf1)
+            if(NULL == ref_pic.pu1_buf1)
             {
-                ps_ref_pic = ps_dec->ps_cur_pic;
+                ref_pic = *ps_dec->ps_cur_pic;
             }
             for(u1_i = u1_L1; u1_i < u1_max_ref_idx_l1; u1_i++)
             {
-                *ps_ref_pic_buf_lx = *ps_ref_pic;
+                *ps_ref_pic_buf_lx = ref_pic;
                 ps_ref_pic_buf_lx++;
             }
         }
diff --git a/decoder/ih264d_process_pslice.c b/decoder/ih264d_process_pslice.c
index efda5cf..7c24383 100644
--- a/decoder/ih264d_process_pslice.c
+++ b/decoder/ih264d_process_pslice.c
@@ -940,7 +940,23 @@
     return OK;
 }
 
-
+static int pic_num_compare(const void *pv_pic1, const void *pv_pic2)
+{
+    struct pic_buffer_t *ps_pic1 = *(struct pic_buffer_t **) pv_pic1;
+    struct pic_buffer_t *ps_pic2 = *(struct pic_buffer_t **) pv_pic2;
+    if (ps_pic1->i4_pic_num < ps_pic2->i4_pic_num)
+    {
+        return -1;
+    }
+    else if (ps_pic1->i4_pic_num > ps_pic2->i4_pic_num)
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
 /*****************************************************************************/
 /*                                                                           */
 /*  Function Name : ih264d_init_ref_idx_lx_p                                        */
@@ -970,7 +986,7 @@
     struct pic_buffer_t *ps_ref_pic_buf_lx;
     dpb_manager_t *ps_dpb_mgr;
     struct dpb_info_t *ps_next_dpb;
-    WORD8 i;
+    WORD8 i, j;
     UWORD8 u1_max_lt_index, u1_min_lt_index;
     UWORD32 u4_lt_index;
     UWORD8 u1_field_pic_flag;
@@ -980,6 +996,7 @@
     WORD32 i4_temp_pic_num, i4_ref_pic_num;
     UWORD8 u1_num_short_term_bufs;
     UWORD8 u1_max_ref_idx_l0;
+    struct pic_buffer_t *aps_st_pic_bufs[2 * MAX_REF_BUFS] = {NULL};
 
     ps_cur_slice = ps_dec->ps_cur_slice;
     u1_field_pic_flag = ps_cur_slice->u1_field_pic_flag;
@@ -1010,6 +1027,16 @@
         ps_next_dpb = ps_next_dpb->ps_prev_short;
     }
 
+    /* Sort ST ref pocs in ascending order */
+    ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
+    for (j = 0; j < ps_dpb_mgr->u1_num_st_ref_bufs; j++)
+    {
+        aps_st_pic_bufs[j] = ps_next_dpb->ps_pic_buf;
+        ps_next_dpb = ps_next_dpb->ps_prev_short;
+    }
+    qsort(aps_st_pic_bufs, ps_dpb_mgr->u1_num_st_ref_bufs,
+        sizeof(aps_st_pic_bufs[0]), pic_num_compare);
+
     /* Start from LT head */
     ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
     if(ps_next_dpb)
@@ -1040,26 +1067,18 @@
         ps_ref_pic_buf_lx = ps_dpb_mgr->ps_init_dpb[0][0];
         i4_temp_pic_num = i4_cur_pic_num;
     }
-
     /* Arrange all short term buffers in output order as given by pic_num */
     /* Arrange pic_num's less than Curr pic_num in the descending pic_num */
     /* order starting from (Curr pic_num - 1)                             */
-    for(; i4_temp_pic_num >= i4_min_st_pic_num; i4_temp_pic_num--)
+    for(j = ps_dpb_mgr->u1_num_st_ref_bufs - 1; j >= 0; j--)
     {
-        /* Start from ST head */
-        ps_next_dpb = ps_dpb_mgr->ps_dpb_st_head;
-        for(i = 0; i < ps_dpb_mgr->u1_num_st_ref_bufs; i++)
+        if(aps_st_pic_bufs[j])
         {
-            if((WORD32)ps_next_dpb->ps_pic_buf->i4_pic_num == i4_temp_pic_num)
-            {
-                /* Copy info in pic buffer */
-                ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
-                                                   ps_next_dpb->ps_pic_buf);
-                ps_ref_pic_buf_lx++;
-                u1_L0++;
-                break;
-            }
-            ps_next_dpb = ps_next_dpb->ps_prev_short;
+            /* Copy info in pic buffer */
+            ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
+                                               aps_st_pic_bufs[j]);
+            ps_ref_pic_buf_lx++;
+            u1_L0++;
         }
     }
 
@@ -1093,17 +1112,17 @@
         /* reference list to handle of errors        */
         {
             UWORD8 u1_i;
-            pic_buffer_t *ps_ref_pic;
+            pic_buffer_t ref_pic;
 
-            ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS;
+            ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0] + MAX_REF_BUFS);
 
-            if(NULL == ps_ref_pic->pu1_buf1)
+            if(NULL == ref_pic.pu1_buf1)
             {
-                ps_ref_pic = ps_dec->ps_cur_pic;
+                ref_pic = *ps_dec->ps_cur_pic;
             }
             for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
             {
-                *ps_ref_pic_buf_lx = *ps_ref_pic;
+                *ps_ref_pic_buf_lx = ref_pic;
                 ps_ref_pic_buf_lx++;
             }
         }
@@ -1119,17 +1138,17 @@
     /* reference list to handle of errors        */
     {
         UWORD8 u1_i;
-        pic_buffer_t *ps_ref_pic;
+        pic_buffer_t ref_pic;
 
-        ps_ref_pic = ps_dpb_mgr->ps_init_dpb[0][0];
+        ref_pic = *(ps_dpb_mgr->ps_init_dpb[0][0]);
 
-        if(NULL == ps_ref_pic->pu1_buf1)
+        if(NULL == ref_pic.pu1_buf1)
         {
-            ps_ref_pic = ps_dec->ps_cur_pic;
+            ref_pic = *ps_dec->ps_cur_pic;
         }
         for(u1_i = u1_L0; u1_i < u1_max_ref_idx_l0; u1_i++)
         {
-            *ps_ref_pic_buf_lx = *ps_ref_pic;
+            *ps_ref_pic_buf_lx = ref_pic;
             ps_ref_pic_buf_lx++;
         }
     }
diff --git a/decoder/ih264d_quant_scaling.c b/decoder/ih264d_quant_scaling.c
index 1d48907..4e5c58d 100644
--- a/decoder/ih264d_quant_scaling.c
+++ b/decoder/ih264d_quant_scaling.c
@@ -20,6 +20,7 @@
 #include "ih264_typedefs.h"
 #include "ih264_macros.h"
 #include "ih264_platform_macros.h"
+#include "ih264_defs.h"
 #include "ih264d_bitstrm.h"
 #include "ih264d_structs.h"
 #include "ih264d_parse_cavlc.h"
@@ -44,7 +45,7 @@
 
 #define IDCT_BLOCK_WIDTH8X8  8
 
-void ih264d_scaling_list(WORD16 *pi2_scaling_list,
+WORD32 ih264d_scaling_list(WORD16 *pi2_scaling_list,
                          WORD32 i4_size_of_scalinglist,
                          UWORD8 *pu1_use_default_scaling_matrix_flag,
                          dec_bit_stream_t *ps_bitstrm)
@@ -62,6 +63,11 @@
             i4_delta_scale = ih264d_sev(pu4_bitstrm_ofst,
                                         pu4_bitstrm_buf);
 
+            if(i4_delta_scale < MIN_H264_DELTA_SCALE ||
+                        i4_delta_scale > MAX_H264_DELTA_SCALE)
+            {
+                return ERROR_INV_RANGE_QP_T;
+            }
             i4_nextScale = ((i4_lastScale + i4_delta_scale + 256) & 0xff);
 
             *pu1_use_default_scaling_matrix_flag = ((i4_j == 0)
@@ -72,6 +78,7 @@
                         (i4_nextScale == 0) ? (i4_lastScale) : (i4_nextScale);
         i4_lastScale = pi2_scaling_list[i4_j];
     }
+    return OK;
 }
 
 WORD32 ih264d_form_default_scaling_matrix(dec_struct_t *ps_dec)
diff --git a/decoder/ih264d_quant_scaling.h b/decoder/ih264d_quant_scaling.h
index c714c34..1a9b7d1 100644
--- a/decoder/ih264d_quant_scaling.h
+++ b/decoder/ih264d_quant_scaling.h
@@ -19,7 +19,7 @@
 */
 #ifndef _IH264D_QUANT_SCALING_H_
 #define _IH264D_QUANT_SCALING_H_
-void ih264d_scaling_list(WORD16 *pi2_scaling_list,
+WORD32 ih264d_scaling_list(WORD16 *pi2_scaling_list,
                   WORD32 i4_size_of_scalinglist,
                   UWORD8 *pu1_use_default_scaling_matrix_flag,
                   dec_bit_stream_t *ps_bitstrm);
diff --git a/decoder/ih264d_sei.c b/decoder/ih264d_sei.c
index 39be782..4375671 100644
--- a/decoder/ih264d_sei.c
+++ b/decoder/ih264d_sei.c
@@ -20,7 +20,7 @@
 
 /*****************************************************************************/
 /*                                                                           */
-/*  File Name         : ih264d_sei.c                                                */
+/*  File Name         : ih264d_sei.c                                         */
 /*                                                                           */
 /*  Description       : This file contains routines to parse SEI NAL's       */
 /*                                                                           */
@@ -35,10 +35,11 @@
 /*                                                                           */
 /*****************************************************************************/
 
+#include <string.h>
+
 #include "ih264_typedefs.h"
 #include "ih264_macros.h"
 #include "ih264_platform_macros.h"
-#include "ih264d_sei.h"
 #include "ih264d_bitstrm.h"
 #include "ih264d_structs.h"
 #include "ih264d_error_handler.h"
@@ -48,15 +49,15 @@
 
 /*****************************************************************************/
 /*                                                                           */
-/*  Function Name : ih264d_parse_buffering_period                                   */
+/*  Function Name : ih264d_parse_buffering_period                            */
 /*                                                                           */
 /*  Description   : This function parses SEI message buffering_period        */
-/*  Inputs        : ps_buf_prd pointer to struct buf_period_t                  */
-/*                  ps_bitstrm    Bitstream                                */
+/*  Inputs        : ps_buf_prd pointer to struct buf_period_t                */
+/*                  ps_bitstrm    Bitstream                                  */
 /*  Globals       : None                                                     */
 /*  Processing    : Parses SEI payload buffering period.                     */
 /*  Outputs       : None                                                     */
-/*  Returns       : None                                                     */
+/*  Return        : 0 for successfull parsing, else error message            */
 /*                                                                           */
 /*  Issues        : Not implemented fully                                    */
 /*                                                                           */
@@ -84,7 +85,7 @@
         return ERROR_INVALID_SEQ_PARAM;
     ps_seq = &ps_dec->ps_sps[u1_seq_parameter_set_id];
     if(TRUE != ps_seq->u1_is_valid)
-        return (-1);
+        return ERROR_INVALID_SEQ_PARAM;
 
     ps_dec->ps_sei->u1_seq_param_set_id = u1_seq_parameter_set_id;
     ps_dec->ps_cur_sps = ps_seq;
@@ -120,21 +121,21 @@
             }
         }
     }
-    return OK;
+    return (OK);
 }
 
 /*****************************************************************************/
 /*                                                                           */
-/*  Function Name : ih264d_parse_pic_timing                                         */
+/*  Function Name : ih264d_parse_pic_timing                                  */
 /*                                                                           */
 /*  Description   : This function parses SEI message pic_timing              */
-/*  Inputs        : ps_bitstrm    Bitstream                                */
+/*  Inputs        : ps_bitstrm    Bitstream                                  */
 /*                  ps_dec          Poniter decoder context                  */
-/*                  ui4_payload_size pay load i4_size                           */
+/*                  ui4_payload_size pay load i4_size                        */
 /*  Globals       : None                                                     */
 /*  Processing    : Parses SEI payload picture timing                        */
 /*  Outputs       : None                                                     */
-/*  Returns       : None                                                     */
+/*  Return        : 0                                                        */
 /*                                                                           */
 /*  Issues        : Not implemented fully                                    */
 /*                                                                           */
@@ -204,21 +205,21 @@
     ih264d_flush_bits_h264(ps_bitstrm,
                            (ui4_payload_size << 3) - u4_bits_consumed);
 
-    return (0);
+    return (OK);
 }
 
 /*****************************************************************************/
 /*                                                                           */
-/*  Function Name : ih264d_parse_recovery_point                                     */
+/*  Function Name : ih264d_parse_recovery_point                              */
 /*                                                                           */
 /*  Description   : This function parses SEI message recovery point          */
-/*  Inputs        : ps_bitstrm    Bitstream                                */
+/*  Inputs        : ps_bitstrm    Bitstream                                  */
 /*                  ps_dec          Poniter decoder context                  */
-/*                  ui4_payload_size pay load i4_size                           */
+/*                  ui4_payload_size pay load i4_size                        */
 /*  Globals       : None                                                     */
 /*  Processing    : Parses SEI payload picture timing                        */
 /*  Outputs       : None                                                     */
-/*  Returns       : None                                                     */
+/*  Return        : 0                                                        */
 /*                                                                           */
 /*  Issues        : Not implemented fully                                    */
 /*                                                                           */
@@ -245,22 +246,415 @@
     ps_sei->u1_broken_link_flag = ih264d_get_bit_h264(ps_bitstrm);
     ps_sei->u1_changing_slice_grp_idc = ih264d_get_bits_h264(ps_bitstrm, 2);
 
-    return (0);
+    return (OK);
 }
 
 /*****************************************************************************/
 /*                                                                           */
-/*  Function Name : ih264d_parse_sei_payload                                        */
+/*  Function Name : ih264d_parse_mdcv                                        */
+/*                                                                           */
+/*  Description   : This function parses SEI message mdcv                    */
+/*  Inputs        : ps_bitstrm    Bitstream                                  */
+/*                  ps_dec          Poniter decoder context                  */
+/*                  ui4_payload_size pay load i4_size                        */
+/*  Globals       : None                                                     */
+/*  Processing    :                                                          */
+/*  Outputs       : None                                                     */
+/*  Return        : 0 for successfull parsing, else -1                       */
+/*                                                                           */
+/*  Issues        :                                                          */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                         Draft                             */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_parse_mdcv(dec_bit_stream_t *ps_bitstrm,
+                         dec_struct_t *ps_dec,
+                         UWORD32 ui4_payload_size)
+{
+    sei *ps_sei = ps_dec->ps_sei_parse;
+    dec_err_status_t *ps_err = ps_dec->ps_dec_err_status;
+    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
+    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
+    UWORD32 u4_count;
+    UNUSED(ui4_payload_size);
+
+    if((ps_dec == NULL) || (ps_sei == NULL))
+    {
+        return NOT_OK;
+    }
+
+    ps_sei->u1_sei_mdcv_params_present_flag = 1;
+
+    /* display primaries x */
+    for(u4_count = 0; u4_count < NUM_SEI_MDCV_PRIMARIES; u4_count++)
+    {
+        ps_sei->s_sei_mdcv_params.au2_display_primaries_x[u4_count] =
+                                    (UWORD16)ih264d_get_bits_h264(ps_bitstrm, 16);
+
+        if((ps_sei->s_sei_mdcv_params.au2_display_primaries_x[u4_count] >
+                                                DISPLAY_PRIMARIES_X_UPPER_LIMIT) ||
+           (ps_sei->s_sei_mdcv_params.au2_display_primaries_x[u4_count] <
+                                                DISPLAY_PRIMARIES_X_LOWER_LIMIT) ||
+           ((ps_sei->s_sei_mdcv_params.au2_display_primaries_x[u4_count] %
+                                               DISPLAY_PRIMARIES_X_DIVISION_FACTOR) != 0))
+        {
+            ps_sei->u1_sei_mdcv_params_present_flag = 0;
+            return ERROR_INV_SEI_MDCV_PARAMS;
+        }
+
+        ps_sei->s_sei_mdcv_params.au2_display_primaries_y[u4_count] =
+                                    (UWORD16)ih264d_get_bits_h264(ps_bitstrm, 16);
+
+        if((ps_sei->s_sei_mdcv_params.au2_display_primaries_y[u4_count] >
+                                                DISPLAY_PRIMARIES_Y_UPPER_LIMIT) ||
+           (ps_sei->s_sei_mdcv_params.au2_display_primaries_y[u4_count] <
+                                               DISPLAY_PRIMARIES_Y_LOWER_LIMIT) ||
+           ((ps_sei->s_sei_mdcv_params.au2_display_primaries_y[u4_count] %
+                                              DISPLAY_PRIMARIES_Y_DIVISION_FACTOR) != 0))
+        {
+            ps_sei->u1_sei_mdcv_params_present_flag = 0;
+            return ERROR_INV_SEI_MDCV_PARAMS;
+        }
+    }
+
+    /* white point x */
+    ps_sei->s_sei_mdcv_params.u2_white_point_x = (UWORD16)ih264d_get_bits_h264(ps_bitstrm, 16);
+
+    if((ps_sei->s_sei_mdcv_params.u2_white_point_x > WHITE_POINT_X_UPPER_LIMIT) ||
+       (ps_sei->s_sei_mdcv_params.u2_white_point_x < WHITE_POINT_X_LOWER_LIMIT) ||
+       ((ps_sei->s_sei_mdcv_params.u2_white_point_x % WHITE_POINT_X_DIVISION_FACTOR) != 0))
+    {
+        ps_sei->u1_sei_mdcv_params_present_flag = 0;
+        return ERROR_INV_SEI_MDCV_PARAMS;
+    }
+    /* white point y */
+    ps_sei->s_sei_mdcv_params.u2_white_point_y = (UWORD16)ih264d_get_bits_h264(ps_bitstrm, 16);
+
+    if((ps_sei->s_sei_mdcv_params.u2_white_point_y > WHITE_POINT_Y_UPPER_LIMIT) ||
+       (ps_sei->s_sei_mdcv_params.u2_white_point_y < WHITE_POINT_Y_LOWER_LIMIT) ||
+       ((ps_sei->s_sei_mdcv_params.u2_white_point_y % WHITE_POINT_Y_DIVISION_FACTOR) != 0))
+    {
+        ps_sei->u1_sei_mdcv_params_present_flag = 0;
+        return ERROR_INV_SEI_MDCV_PARAMS;
+    }
+    /* max display mastering luminance */
+    ps_sei->s_sei_mdcv_params.u4_max_display_mastering_luminance =
+                                    (UWORD32)ih264d_get_bits_h264(ps_bitstrm, 32);
+
+    if((ps_sei->s_sei_mdcv_params.u4_max_display_mastering_luminance >
+                                            MAX_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT) ||
+       (ps_sei->s_sei_mdcv_params.u4_max_display_mastering_luminance <
+                                            MAX_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT) ||
+       ((ps_sei->s_sei_mdcv_params.u4_max_display_mastering_luminance %
+                                        MAX_DISPLAY_MASTERING_LUMINANCE_DIVISION_FACTOR) != 0))
+    {
+        ps_sei->u1_sei_mdcv_params_present_flag = 0;
+        return ERROR_INV_SEI_MDCV_PARAMS;
+    }
+    /* min display mastering luminance */
+    ps_sei->s_sei_mdcv_params.u4_min_display_mastering_luminance =
+                                    (UWORD32)ih264d_get_bits_h264(ps_bitstrm, 32);
+
+    if((ps_sei->s_sei_mdcv_params.u4_min_display_mastering_luminance >
+                                            MIN_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT) ||
+        (ps_sei->s_sei_mdcv_params.u4_min_display_mastering_luminance <
+                                            MIN_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT))
+    {
+        ps_sei->u1_sei_mdcv_params_present_flag = 0;
+        return ERROR_INV_SEI_MDCV_PARAMS;
+    }
+    if(ps_sei->s_sei_mdcv_params.u4_max_display_mastering_luminance <=
+            ps_sei->s_sei_mdcv_params.u4_min_display_mastering_luminance)
+    {
+        ps_sei->u1_sei_mdcv_params_present_flag = 0;
+        return ERROR_INV_SEI_MDCV_PARAMS;
+    }
+    return (OK);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_parse_cll                                         */
+/*                                                                           */
+/*  Description   : This function parses SEI message cll                     */
+/*  Inputs        : ps_bitstrm    Bitstream                                  */
+/*                  ps_dec          Poniter decoder context                  */
+/*                  ui4_payload_size pay load i4_size                        */
+/*  Globals       : None                                                     */
+/*  Processing    :                                                          */
+/*  Outputs       : None                                                     */
+/*  Return        : 0 for successfull parsing, else -1                       */
+/*                                                                           */
+/*  Issues        :                                                          */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                         Draft                             */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_parse_cll(dec_bit_stream_t *ps_bitstrm,
+                        dec_struct_t *ps_dec,
+                        UWORD32 ui4_payload_size)
+{
+    sei *ps_sei = ps_dec->ps_sei_parse;
+    dec_err_status_t *ps_err = ps_dec->ps_dec_err_status;
+    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
+    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
+    UNUSED(ui4_payload_size);
+
+    if((ps_dec == NULL) || (ps_sei == NULL))
+    {
+        return NOT_OK;
+    }
+
+    ps_sei->u1_sei_cll_params_present_flag = 1;
+
+    ps_sei->s_sei_cll_params.u2_max_content_light_level =
+                        (UWORD16)ih264d_get_bits_h264(ps_bitstrm, 16);
+    ps_sei->s_sei_cll_params.u2_max_pic_average_light_level =
+                        (UWORD16)ih264d_get_bits_h264(ps_bitstrm, 16);
+    /*No any sanity checks done for CLL params*/
+
+    return (OK);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_parse_ave                                         */
+/*                                                                           */
+/*  Description   : This function parses SEI message ave                     */
+/*  Inputs        : ps_bitstrm    Bitstream                                  */
+/*                  ps_dec          Poniter decoder context                  */
+/*                  ui4_payload_size pay load i4_size                        */
+/*  Globals       : None                                                     */
+/*  Processing    :                                                          */
+/*  Outputs       : None                                                     */
+/*  Return        : 0 for successfull parsing, else -1                       */
+/*                                                                           */
+/*  Issues        :                                                          */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                         Draft                             */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_parse_ave(dec_bit_stream_t *ps_bitstrm,
+                        dec_struct_t *ps_dec,
+                        UWORD32 ui4_payload_size)
+{
+    sei *ps_sei = ps_dec->ps_sei_parse;
+    dec_err_status_t *ps_err = ps_dec->ps_dec_err_status;
+    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
+    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
+    UNUSED(ui4_payload_size);
+
+    if((ps_dec == NULL) || (ps_sei == NULL))
+    {
+        return NOT_OK;
+    }
+
+    ps_sei->u1_sei_ave_params_present_flag = 1;
+
+    ps_sei->s_sei_ave_params.u4_ambient_illuminance = (UWORD32)ih264d_get_bits_h264(ps_bitstrm, 32);
+    if(0 == ps_sei->s_sei_ave_params.u4_ambient_illuminance)
+    {
+        ps_sei->u1_sei_ave_params_present_flag = 0;
+        return ERROR_INV_SEI_AVE_PARAMS;
+    }
+
+    ps_sei->s_sei_ave_params.u2_ambient_light_x = (UWORD16)ih264d_get_bits_h264(ps_bitstrm, 16);
+    if(ps_sei->s_sei_ave_params.u2_ambient_light_x > AMBIENT_LIGHT_X_UPPER_LIMIT)
+    {
+        ps_sei->u1_sei_ave_params_present_flag = 0;
+        return ERROR_INV_SEI_AVE_PARAMS;
+    }
+
+    ps_sei->s_sei_ave_params.u2_ambient_light_y = (UWORD16)ih264d_get_bits_h264(ps_bitstrm, 16);
+    if(ps_sei->s_sei_ave_params.u2_ambient_light_y > AMBIENT_LIGHT_Y_UPPER_LIMIT)
+    {
+        ps_sei->u1_sei_ave_params_present_flag = 0;
+        return ERROR_INV_SEI_AVE_PARAMS;
+    }
+    return (OK);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_parse_ccv                                         */
+/*                                                                           */
+/*  Description   : This function parses SEI message ccv                     */
+/*  Inputs        : ps_bitstrm    Bitstream                                  */
+/*                  ps_dec          Poniter decoder context                  */
+/*                  ui4_payload_size pay load i4_size                        */
+/*  Globals       : None                                                     */
+/*  Processing    :                                                          */
+/*  Outputs       : None                                                     */
+/*  Return        : 0 for successfull parsing, else -1                       */
+/*                                                                           */
+/*  Issues        :                                                          */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                         Draft                                             */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_parse_ccv(dec_bit_stream_t *ps_bitstrm,
+                        dec_struct_t *ps_dec,
+                        UWORD32 ui4_payload_size)
+{
+    sei *ps_sei = ps_dec->ps_sei_parse;
+    dec_err_status_t *ps_err = ps_dec->ps_dec_err_status;
+    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
+    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
+    UWORD32 u4_count;
+    UNUSED(ui4_payload_size);
+
+    if((ps_dec == NULL) || (ps_sei == NULL))
+    {
+        return NOT_OK;
+    }
+
+    ps_sei->u1_sei_ccv_params_present_flag = 0;
+
+    ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag = (UWORD8)ih264d_get_bit_h264(ps_bitstrm);
+
+    if(ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag > 1)
+    {
+        return ERROR_INV_SEI_CCV_PARAMS;
+    }
+    if(0 == ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag)
+    {
+        ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag =
+                                                (UWORD8)ih264d_get_bit_h264(ps_bitstrm);
+        if(ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag > 1)
+        {
+            return ERROR_INV_SEI_CCV_PARAMS;
+        }
+        ps_sei->s_sei_ccv_params.u1_ccv_primaries_present_flag =
+                                                (UWORD8)ih264d_get_bit_h264(ps_bitstrm);
+        if(ps_sei->s_sei_ccv_params.u1_ccv_primaries_present_flag > 1)
+        {
+            return ERROR_INV_SEI_CCV_PARAMS;
+        }
+        ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag =
+                                                (UWORD8)ih264d_get_bit_h264(ps_bitstrm);
+        if(ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag > 1)
+        {
+            return ERROR_INV_SEI_CCV_PARAMS;
+        }
+        ps_sei->s_sei_ccv_params.u1_ccv_max_luminance_value_present_flag =
+                                                (UWORD8)ih264d_get_bit_h264(ps_bitstrm);
+        if(ps_sei->s_sei_ccv_params.u1_ccv_max_luminance_value_present_flag > 1)
+        {
+            return ERROR_INV_SEI_CCV_PARAMS;
+        }
+        ps_sei->s_sei_ccv_params.u1_ccv_avg_luminance_value_present_flag =
+                                                (UWORD8)ih264d_get_bit_h264(ps_bitstrm);
+        if(ps_sei->s_sei_ccv_params.u1_ccv_avg_luminance_value_present_flag > 1)
+        {
+            return ERROR_INV_SEI_CCV_PARAMS;
+        }
+
+        if((ps_sei->s_sei_ccv_params.u1_ccv_primaries_present_flag == 0) &&
+           (ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag == 0) &&
+           (ps_sei->s_sei_ccv_params.u1_ccv_max_luminance_value_present_flag == 0) &&
+           (ps_sei->s_sei_ccv_params.u1_ccv_avg_luminance_value_present_flag == 0))
+        {
+            return ERROR_INV_SEI_CCV_PARAMS;
+	 }
+
+        ps_sei->s_sei_ccv_params.u1_ccv_reserved_zero_2bits =
+                                                (UWORD8)ih264d_get_bits_h264(ps_bitstrm, 2);
+        if((ps_sei->s_sei_ccv_params.u1_ccv_reserved_zero_2bits != 0))
+        {
+            return ERROR_INV_SEI_CCV_PARAMS;
+        }
+
+        /* ccv primaries */
+        if(1 == ps_sei->s_sei_ccv_params.u1_ccv_primaries_present_flag)
+        {
+            for(u4_count = 0; u4_count < NUM_SEI_CCV_PRIMARIES; u4_count++)
+            {
+                ps_sei->s_sei_ccv_params.ai4_ccv_primaries_x[u4_count] =
+                                                (WORD32)ih264d_get_bits_h264(ps_bitstrm, 32);
+                if((ps_sei->s_sei_ccv_params.ai4_ccv_primaries_x[u4_count] >
+                                                        CCV_PRIMARIES_X_UPPER_LIMIT) ||
+                   (ps_sei->s_sei_ccv_params.ai4_ccv_primaries_x[u4_count] <
+                                                        CCV_PRIMARIES_X_LOWER_LIMIT))
+                {
+                    return ERROR_INV_SEI_CCV_PARAMS;
+                }
+
+                ps_sei->s_sei_ccv_params.ai4_ccv_primaries_y[u4_count] =
+                                                (WORD32)ih264d_get_bits_h264(ps_bitstrm, 32);
+                if((ps_sei->s_sei_ccv_params.ai4_ccv_primaries_y[u4_count] >
+                                                        CCV_PRIMARIES_Y_UPPER_LIMIT) ||
+                   (ps_sei->s_sei_ccv_params.ai4_ccv_primaries_y[u4_count] <
+                                                        CCV_PRIMARIES_Y_LOWER_LIMIT))
+                {
+                    return ERROR_INV_SEI_CCV_PARAMS;
+                }
+            }
+        }
+
+        if(1 == ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag)
+        {
+            ps_sei->s_sei_ccv_params.u4_ccv_min_luminance_value =
+                                                (UWORD32)ih264d_get_bits_h264(ps_bitstrm, 32);
+        }
+
+        if(1 == ps_sei->s_sei_ccv_params.u1_ccv_max_luminance_value_present_flag)
+        {
+            ps_sei->s_sei_ccv_params.u4_ccv_max_luminance_value =
+                                                (UWORD32)ih264d_get_bits_h264(ps_bitstrm, 32);
+            if((1 == ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag) &&
+                (ps_sei->s_sei_ccv_params.u4_ccv_max_luminance_value <
+                                                ps_sei->s_sei_ccv_params.u4_ccv_min_luminance_value))
+            {
+                return ERROR_INV_SEI_CCV_PARAMS;
+            }
+        }
+        if(1 == ps_sei->s_sei_ccv_params.u1_ccv_avg_luminance_value_present_flag)
+        {
+            ps_sei->s_sei_ccv_params.u4_ccv_avg_luminance_value =
+                                                (UWORD32)ih264d_get_bits_h264(ps_bitstrm, 32);
+            if((1 == ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag) &&
+                (ps_sei->s_sei_ccv_params.u4_ccv_avg_luminance_value <
+                                                ps_sei->s_sei_ccv_params.u4_ccv_min_luminance_value))
+            {
+                return ERROR_INV_SEI_CCV_PARAMS;
+            }
+            if((1 == ps_sei->s_sei_ccv_params.u1_ccv_max_luminance_value_present_flag) &&
+                (ps_sei->s_sei_ccv_params.u4_ccv_max_luminance_value <
+                                                ps_sei->s_sei_ccv_params.u4_ccv_avg_luminance_value))
+            {
+                return ERROR_INV_SEI_CCV_PARAMS;
+            }
+        }
+    }
+    ps_sei->u1_sei_ccv_params_present_flag = 1;
+    return (OK);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_parse_sei_payload                                 */
 /*                                                                           */
 /*  Description   : This function parses SEI pay loads. Currently it's       */
 /*                  implemented partially.                                   */
-/*  Inputs        : ps_bitstrm    Bitstream                                */
+/*  Inputs        : ps_bitstrm    Bitstream                                  */
 /*                  ui4_payload_type  SEI payload type                       */
-/*                  ui4_payload_size  SEI payload i4_size                       */
+/*                  ui4_payload_size  SEI payload i4_size                    */
 /*  Globals       : None                                                     */
 /*  Processing    : Parses SEI payloads units and stores the info            */
 /*  Outputs       : None                                                     */
-/*  Returns       : None                                                     */
+/*  Return        : status for successful parsing, else -1                   */
 /*                                                                           */
 /*  Issues        : Not implemented fully                                    */
 /*                                                                           */
@@ -278,10 +672,14 @@
 {
     sei *ps_sei;
     WORD32 i4_status = 0;
-    ps_sei = (sei *)ps_dec->ps_sei;
+    ps_sei = (sei *)ps_dec->ps_sei_parse;
 
     if(ui4_payload_size == 0)
         return -1;
+    if(NULL == ps_bitstrm)
+    {
+        return NOT_OK;
+    }
 
     switch(ui4_payload_type)
     {
@@ -301,6 +699,26 @@
             i4_status = ih264d_parse_recovery_point(ps_bitstrm, ps_dec,
                                         ui4_payload_size);
             break;
+        case SEI_MASTERING_DISP_COL_VOL:
+
+            i4_status = ih264d_parse_mdcv(ps_bitstrm, ps_dec,
+                                          ui4_payload_size);
+            break;
+        case SEI_CONTENT_LIGHT_LEVEL_DATA:
+
+            i4_status = ih264d_parse_cll(ps_bitstrm, ps_dec,
+                                         ui4_payload_size);
+            break;
+        case SEI_AMBIENT_VIEWING_ENVIRONMENT:
+
+            i4_status = ih264d_parse_ave(ps_bitstrm, ps_dec,
+                                         ui4_payload_size);
+            break;
+        case SEI_CONTENT_COLOR_VOLUME:
+
+            i4_status = ih264d_parse_ccv(ps_bitstrm, ps_dec,
+                                         ui4_payload_size);
+            break;
         default:
             i4_status = ih264d_flush_bits_h264(ps_bitstrm, (ui4_payload_size << 3));
             break;
@@ -385,3 +803,173 @@
     return (i4_status);
 }
 
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_export_sei_mdcv_params                            */
+/*                                                                           */
+/*  Description   : This function populates SEI mdcv message in              */
+/*                     output structure                                      */
+/*  Inputs        : ps_sei_mdcv_op pointer to sei mdcv o\p struct            */
+/*                : ps_sei pointer to decoded sei params                     */
+/*  Outputs       :                                                          */
+/*  Returns       : returns 0 for success; -1 for failure                    */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                                                           */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_export_sei_mdcv_params(ivd_sei_decode_op_t *ps_sei_decode_op,
+                                     sei *ps_sei, sei *ps_sei_export)
+{
+    if((ps_sei_export == NULL) || (ps_sei == NULL))
+    {
+        return NOT_OK;
+    }
+
+    ps_sei_export->u1_sei_mdcv_params_present_flag = ps_sei->u1_sei_mdcv_params_present_flag;
+    ps_sei_decode_op->u1_sei_mdcv_params_present_flag = ps_sei->u1_sei_mdcv_params_present_flag;
+
+    if(0 == ps_sei_export->u1_sei_mdcv_params_present_flag)
+    {
+        memset(&ps_sei_export->s_sei_mdcv_params, 0, sizeof(sei_mdcv_params_t));
+    }
+    else
+    {
+        memcpy(&ps_sei_export->s_sei_mdcv_params, &ps_sei->s_sei_mdcv_params,
+                                                    sizeof(sei_mdcv_params_t));
+    }
+
+    return (OK);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_export_sei_cll_params                             */
+/*                                                                           */
+/*  Description   : This function populates SEI cll message in               */
+/*                     output structure                                      */
+/*  Inputs        : ps_sei_cll_op pointer to sei cll o\p struct              */
+/*                : ps_sei pointer to decoded sei params                     */
+/*  Outputs       :                                                          */
+/*  Returns       : returns 0 for success; -1 for failure                    */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                                                           */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_export_sei_cll_params(ivd_sei_decode_op_t *ps_sei_decode_op,
+                                    sei *ps_sei, sei *ps_sei_export)
+{
+    if((ps_sei_export == NULL) || (ps_sei == NULL))
+    {
+        return NOT_OK;
+    }
+
+    ps_sei_export->u1_sei_cll_params_present_flag = ps_sei->u1_sei_cll_params_present_flag;
+    ps_sei_decode_op->u1_sei_cll_params_present_flag = ps_sei->u1_sei_cll_params_present_flag;
+
+    if(0 == ps_sei_export->u1_sei_cll_params_present_flag)
+    {
+        memset(&ps_sei_export->s_sei_cll_params, 0, sizeof(sei_cll_params_t));
+    }
+    else
+    {
+        memcpy(&ps_sei_export->s_sei_cll_params, &ps_sei->s_sei_cll_params,
+                                                    sizeof(sei_cll_params_t));
+    }
+    return (OK);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_export_sei_ave_params                             */
+/*                                                                           */
+/*  Description   : This function populates SEI ave message in               */
+/*                     output structure                                      */
+/*  Inputs        : ps_sei_ave_op pointer to sei ave o\p struct              */
+/*                : ps_sei pointer to decoded sei params                     */
+/*  Outputs       :                                                          */
+/*  Returns       : returns 0 for success; -1 for failure                    */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                                                           */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_export_sei_ave_params(ivd_sei_decode_op_t *ps_sei_decode_op,
+                                    sei *ps_sei, sei *ps_sei_export)
+{
+    if((ps_sei_export == NULL) || (ps_sei == NULL))
+    {
+        return NOT_OK;
+    }
+
+    ps_sei_export->u1_sei_ave_params_present_flag = ps_sei->u1_sei_ave_params_present_flag;
+    ps_sei_decode_op->u1_sei_ave_params_present_flag = ps_sei->u1_sei_ave_params_present_flag;
+
+    if(0 == ps_sei_export->u1_sei_ave_params_present_flag)
+    {
+        memset(&ps_sei_export->s_sei_ave_params, 0, sizeof(sei_ave_params_t));
+    }
+    else
+    {
+        memcpy(&ps_sei_export->s_sei_ave_params, &ps_sei->s_sei_ave_params,
+                                                    sizeof(sei_ave_params_t));
+    }
+
+    return (OK);
+}
+
+/*****************************************************************************/
+/*                                                                           */
+/*  Function Name : ih264d_export_sei_ccv_params                             */
+/*                                                                           */
+/*  Description   : This function populates SEI ccv message in               */
+/*                     output structure                                      */
+/*  Inputs        : ps_sei_ccv_op pointer to sei ccv o\p struct              */
+/*                : ps_sei pointer to decoded sei params                     */
+/*  Outputs       :                                                          */
+/*  Returns       : returns 0 for success; -1 for failure                    */
+/*                                                                           */
+/*  Issues        : none                                                     */
+/*                                                                           */
+/*  Revision History:                                                        */
+/*                                                                           */
+/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
+/*                                                                           */
+/*                                                                           */
+/*****************************************************************************/
+WORD32 ih264d_export_sei_ccv_params(ivd_sei_decode_op_t *ps_sei_decode_op,
+                                    sei *ps_sei, sei *ps_sei_export)
+{
+    if((ps_sei_export == NULL) || (ps_sei == NULL))
+    {
+        return NOT_OK;
+    }
+
+    ps_sei_export->u1_sei_ccv_params_present_flag = ps_sei->u1_sei_ccv_params_present_flag;
+    ps_sei_decode_op->u1_sei_ccv_params_present_flag = ps_sei->u1_sei_ccv_params_present_flag;
+
+    if(0 == ps_sei_export->u1_sei_ccv_params_present_flag)
+    {
+        memset(&ps_sei_export->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
+    }
+    else
+    {
+        memcpy(&ps_sei_export->s_sei_ccv_params, &ps_sei->s_sei_ccv_params,
+                                                    sizeof(sei_ccv_params_t));
+    }
+    return (OK);
+}
+
diff --git a/decoder/ih264d_sei.h b/decoder/ih264d_sei.h
index 5033740..af143ac 100644
--- a/decoder/ih264d_sei.h
+++ b/decoder/ih264d_sei.h
@@ -43,6 +43,7 @@
 #include "ih264_platform_macros.h"
 #include "ih264d_bitstrm.h"
 #include "ih264d_structs.h"
+#include "ih264d.h"
 
 #define SEI_BUF_PERIOD      0
 #define SEI_PIC_TIMING      1
@@ -63,6 +64,11 @@
 #define SEI_PROG_REF_SEGMENT_START  16
 #define SEI_PROG_REF_SEGMENT_END    17
 #define SEI_MOT_CON_SLICE_GRP_SET   18
+#define SEI_MASTERING_DISP_COL_VOL       137
+#define SEI_CONTENT_LIGHT_LEVEL_DATA     144
+#define SEI_AMBIENT_VIEWING_ENVIRONMENT  148
+#define SEI_CONTENT_COLOR_VOLUME         149
+
 /* Declaration of dec_struct_t to avoid CCS compilation Error */
 struct _DecStruct;
 WORD32 ih264d_parse_sei_message(struct _DecStruct *ps_dec,
@@ -75,6 +81,159 @@
 
 } buf_period_t;
 
+/**
+ * Structure to hold Mastering Display Color Volume SEI
+ */
+typedef struct
+{
+    /**
+     * Array to store the display_primaries_x values
+     */
+    UWORD16 au2_display_primaries_x[NUM_SEI_MDCV_PRIMARIES];
+
+    /**
+     * Array to store the display_primaries_y values
+     */
+    UWORD16 au2_display_primaries_y[NUM_SEI_MDCV_PRIMARIES];
+
+    /**
+     * Variable to store the white point x value
+     */
+    UWORD16 u2_white_point_x;
+
+    /**
+     * Variable to store the white point y value
+     */
+    UWORD16 u2_white_point_y;
+
+    /**
+     * Variable to store the max display mastering luminance value
+     */
+    UWORD32 u4_max_display_mastering_luminance;
+
+    /**
+     * Variable to store the min display mastering luminance value
+     */
+    UWORD32 u4_min_display_mastering_luminance;
+
+}sei_mdcv_params_t;
+
+
+/**
+ * Structure for Content Light Level Info
+ *
+ */
+typedef struct
+{
+    /**
+     * The maximum pixel intensity of all samples
+     */
+    UWORD16 u2_max_content_light_level;
+
+    /**
+     * The average pixel intensity of all samples
+     */
+    UWORD16 u2_max_pic_average_light_level;
+
+}sei_cll_params_t;
+
+
+/**
+ * Structure to hold Ambient viewing environment SEI
+ */
+typedef struct
+{
+
+    /**
+     * specifies the environmental illuminance of the ambient viewing environment
+     */
+    UWORD32 u4_ambient_illuminance;
+
+    /*
+     * specify the normalized x chromaticity coordinates of the
+     * environmental ambient light in the nominal viewing environment
+     */
+    UWORD16 u2_ambient_light_x;
+
+    /*
+    * specify the normalized y chromaticity coordinates of the
+    * environmental ambient light in the nominal viewing environment
+    */
+    UWORD16 u2_ambient_light_y;
+
+}sei_ave_params_t;
+
+
+/**
+ * Structure to hold Content color volume SEI
+ */
+typedef struct
+{
+    /*
+     * Flag used to control persistence of CCV SEI messages
+     */
+    UWORD8 u1_ccv_cancel_flag;
+
+    /*
+     * specifies the persistence of the CCV SEI message for the current layer
+     */
+    UWORD8 u1_ccv_persistence_flag;
+
+    /*
+     * specifies the presence of syntax elements ccv_primaries_x and ccv_primaries_y
+     */
+    UWORD8 u1_ccv_primaries_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_min_luminance_value is present
+     */
+    UWORD8 u1_ccv_min_luminance_value_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_max_luminance_value is present
+     */
+    UWORD8 u1_ccv_max_luminance_value_present_flag;
+
+    /*
+     * specifies that the syntax element ccv_avg_luminance_value is present
+     */
+    UWORD8 u1_ccv_avg_luminance_value_present_flag;
+
+    /*
+     * shall be equal to 0 in bitstreams conforming to this version. Other values
+     * for reserved_zero_2bits are reserved for future use
+     */
+    UWORD8 u1_ccv_reserved_zero_2bits;
+
+    /*
+     * specify the normalized x chromaticity coordinates of the colour
+     * primary component c of the nominal content colour volume
+     */
+    WORD32 ai4_ccv_primaries_x[NUM_SEI_CCV_PRIMARIES];
+
+    /*
+     * specify the normalized y chromaticity coordinates of the colour
+     * primary component c of the nominal content colour volume
+     */
+    WORD32 ai4_ccv_primaries_y[NUM_SEI_CCV_PRIMARIES];
+
+    /*
+     * specifies the normalized minimum luminance value
+     */
+    UWORD32 u4_ccv_min_luminance_value;
+
+    /*
+     * specifies the normalized maximum luminance value
+     */
+    UWORD32 u4_ccv_max_luminance_value;
+
+    /*
+     * specifies the normalized average luminance value
+     */
+    UWORD32 u4_ccv_avg_luminance_value;
+
+}sei_ccv_params_t;
+
 struct _sei
 {
     UWORD8 u1_seq_param_set_id;
@@ -85,7 +244,61 @@
     UWORD8 u1_broken_link_flag;
     UWORD8 u1_changing_slice_grp_idc;
     UWORD8 u1_is_valid;
+
+    /**
+     *  mastering display color volume info present flag
+     */
+    UWORD8 u1_sei_mdcv_params_present_flag;
+
+    /*
+     * MDCV parameters
+     */
+    sei_mdcv_params_t s_sei_mdcv_params;
+
+    /**
+     * content light level info present flag
+     */
+    UWORD8 u1_sei_cll_params_present_flag;
+
+    /*
+     * CLL parameters
+     */
+    sei_cll_params_t s_sei_cll_params;
+
+    /**
+     * ambient viewing environment info present flag
+     */
+    UWORD8 u1_sei_ave_params_present_flag;
+
+    /*
+     * AVE parameters
+     */
+    sei_ave_params_t s_sei_ave_params;
+
+    /**
+     * content color volume info present flag
+     */
+    UWORD8 u1_sei_ccv_params_present_flag;
+
+    /*
+     * CCV parameters
+     */
+    sei_ccv_params_t s_sei_ccv_params;
+
 };
 typedef struct _sei sei;
+
+WORD32 ih264d_export_sei_mdcv_params(ivd_sei_decode_op_t *ps_sei_decode_op,
+                                     sei *ps_sei, sei *ps_sei_export);
+
+WORD32 ih264d_export_sei_cll_params(ivd_sei_decode_op_t *ps_sei_decode_op,
+                                    sei *ps_sei, sei *ps_sei_export);
+
+WORD32 ih264d_export_sei_ave_params(ivd_sei_decode_op_t *ps_sei_decode_op,
+                                    sei *ps_sei, sei *ps_sei_export);
+
+WORD32 ih264d_export_sei_ccv_params(ivd_sei_decode_op_t *ps_sei_decode_op,
+                                    sei *ps_sei, sei *ps_sei_export);
+
 #endif /* _IH264D_SEI_H_ */
 
diff --git a/decoder/ih264d_structs.h b/decoder/ih264d_structs.h
index 41cc885..fdfbada 100644
--- a/decoder/ih264d_structs.h
+++ b/decoder/ih264d_structs.h
@@ -190,6 +190,7 @@
     /* ! */
     UWORD32 u4_ts;
     UWORD8 u1_pic_struct;/* Refer to SEI table D-1 */
+    sei s_sei_pic;
 
 } pic_buffer_t;
 
@@ -1005,6 +1006,11 @@
     UWORD8 *pu1_temp_mc_buffer;
 
     struct _sei *ps_sei;
+    struct _sei *ps_sei_parse;
+    struct _sei s_sei_export;
+
+    void *pv_disp_sei_params;
+
     UWORD8 u1_pic_struct_copy;
     /* Variables required for cropping */
     UWORD16 u2_disp_width;
diff --git a/decoder/ih264d_utils.c b/decoder/ih264d_utils.c
index 28d8db0..35cd7b9 100644
--- a/decoder/ih264d_utils.c
+++ b/decoder/ih264d_utils.c
@@ -324,7 +324,7 @@
 
             if(u1_nal_ref_idc == 0)
             {
-                i8_result = expected_poc
+                i8_result = (WORD64)expected_poc
                                 + ps_seq->i4_ofst_for_non_ref_pic;
 
                 if(IS_OUT_OF_RANGE_S32(i8_result))
@@ -336,14 +336,14 @@
             /* 6. TopFieldOrderCnt or BottomFieldOrderCnt are derived as */
             if(!u1_field_pic_flag)
             {
-                i8_result = expected_poc
+                i8_result = (WORD64)expected_poc
                                 + ps_cur_poc->i4_delta_pic_order_cnt[0];
 
                 if(IS_OUT_OF_RANGE_S32(i8_result))
                     return ERROR_INV_POC;
                 i4_top_field_order_cnt = (WORD32)i8_result;
 
-                i8_result = i4_top_field_order_cnt
+                i8_result = (WORD64)i4_top_field_order_cnt
                                 + ps_seq->i4_ofst_for_top_to_bottom_field
                                 + ps_cur_poc->i4_delta_pic_order_cnt[1];
 
@@ -353,7 +353,7 @@
             }
             else if(!u1_bottom_field_flag)
             {
-                i8_result = expected_poc
+                i8_result = (WORD64)expected_poc
                                 + ps_cur_poc->i4_delta_pic_order_cnt[0];
 
                 if(IS_OUT_OF_RANGE_S32(i8_result))
@@ -362,7 +362,7 @@
             }
             else
             {
-                i8_result = expected_poc
+                i8_result = (WORD64)expected_poc
                                 + ps_seq->i4_ofst_for_top_to_bottom_field
                                 + ps_cur_poc->i4_delta_pic_order_cnt[0];
 
@@ -949,6 +949,7 @@
     ps_dec->i4_display_index  = DEFAULT_POC;
     if(pic_buf != NULL)
     {
+        ps_dec->pv_disp_sei_params = &pic_buf->s_sei_pic;
         pv_disp_op->e4_fld_type = 0;
         pv_disp_op->u4_disp_buf_id = i4_disp_buf_id;
 
@@ -1645,6 +1646,15 @@
                 return ret;
         }
 
+        {
+            UWORD64 i8_display_poc;
+            i8_display_poc = (UWORD64)ps_dec->i4_prev_max_display_seq +
+                        i4_poc;
+            if(IS_OUT_OF_RANGE_S32(i8_display_poc))
+            {
+                ps_dec->i4_prev_max_display_seq = 0;
+            }
+        }
         ret = ih264d_insert_pic_in_display_list(
                         ps_dec->ps_dpb_mgr, (WORD8) DO_NOT_DISP,
                         (WORD32)(ps_dec->i4_prev_max_display_seq + i4_poc),
diff --git a/decoder/ivd.h b/decoder/ivd.h
index f3a9f62..bac5847 100644
--- a/decoder/ivd.h
+++ b/decoder/ivd.h
@@ -43,6 +43,18 @@
 /* Constant Macros                                                           */
 /*****************************************************************************/
 #define IVD_VIDDEC_MAX_IO_BUFFERS 64
+
+/** SEI macros */
+/*
+ * @brief  specifies the number of colour primary components of the mastering display
+ */
+#define NUM_SEI_MDCV_PRIMARIES        3
+
+/*
+ * @brief  specifies the number of colour primary components of the nominal content colour volume
+ */
+#define NUM_SEI_CCV_PRIMARIES         3
+
 /*****************************************************************************/
 /* Typedefs                                                                  */
 /*****************************************************************************/
@@ -368,6 +380,17 @@
 /*   Video Decode                                                            */
 /*****************************************************************************/
 
+/* SEI params deocde */
+typedef struct {
+    UWORD8                                         u1_sei_mdcv_params_present_flag;
+
+    UWORD8                                         u1_sei_cll_params_present_flag;
+
+    UWORD8                                         u1_sei_ave_params_present_flag;
+
+    UWORD8                                         u1_sei_ccv_params_present_flag;
+
+}ivd_sei_decode_op_t;
 
 /* IVD_API_COMMAND_TYPE_T::e_cmd = IVD_CMD_VIDEO_DECODE                      */
 
@@ -473,6 +496,11 @@
     iv_yuv_buf_t                            s_disp_frm_buf;
 
     /**
+     * sei params o/p struct
+     */
+    ivd_sei_decode_op_t                     s_sei_decode_op;
+
+    /**
      * fld_type
      */
     IV_FLD_TYPE_T                           e4_fld_type;
diff --git a/encoder/ih264e.h b/encoder/ih264e.h
index 4de0b17..c736d9b 100644
--- a/encoder/ih264e.h
+++ b/encoder/ih264e.h
@@ -47,11 +47,6 @@
 #include "iv2.h"
 #include "ive2.h"
 /*****************************************************************************/
-/* Constant Macros                                                           */
-/*****************************************************************************/
-
-
-/*****************************************************************************/
 /* API Function Prototype                                                    */
 /*****************************************************************************/
 IV_STATUS_T ih264e_api_function(iv_obj_t *ps_handle, void *pv_api_ip,void *pv_api_op);
@@ -614,6 +609,234 @@
     UWORD32                                     u4_error_code;
 }ih264e_vui_op_t;
 
+/*****************************************************************************/
+/*    Video control  Set SEI MDCV params                                     */
+/*****************************************************************************/
+typedef struct
+{
+    /** size of the structure                                             */
+    UWORD32                                     u4_size;
+
+    /** Command type : IVE_CMD_VIDEO_CTL                                  */
+    IVE_API_COMMAND_TYPE_T                      e_cmd;
+
+    /** Sub command type : IVE_CMD_CTL_SET_SEI_MDCV_PARAMS                */
+    IVE_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+
+    /** mastering display color volume info present flag                  */
+    UWORD8                                      u1_sei_mdcv_params_present_flag;
+
+    /** Array to store the display_primaries_x values                     */
+    UWORD16                                     au2_display_primaries_x[3];
+
+    /** Array to store the display_primaries_y values                     */
+    UWORD16                                     au2_display_primaries_y[3];
+
+    /** Variable to store the white point x value                         */
+    UWORD16                                     u2_white_point_x;
+
+    /** Variable to store the white point y value                         */
+    UWORD16                                     u2_white_point_y;
+
+    /** Variable to store the max display mastering luminance value       */
+    UWORD32                                     u4_max_display_mastering_luminance;
+
+    /** Variable to store the min display mastering luminance value       */
+    UWORD32                                     u4_min_display_mastering_luminance;
+
+    /** Lower 32bits of time stamp corresponding to input buffer,
+     * from which this command takes effect                               */
+    UWORD32                                     u4_timestamp_low;
+
+    /** Upper 32bits of time stamp corresponding to input buffer,
+     * from which this command takes effect                               */
+    UWORD32                                     u4_timestamp_high;
+
+}ih264e_ctl_set_sei_mdcv_params_ip_t;
+
+typedef struct
+{
+    /** size of the structure                                           */
+    UWORD32                                     u4_size;
+
+    /** Return error code                                               */
+    UWORD32                                     u4_error_code;
+
+}ih264e_ctl_set_sei_mdcv_params_op_t;
+
+/*****************************************************************************/
+/*    Video control  Set SEI CLL params                                      */
+/*****************************************************************************/
+typedef struct
+{
+    /** size of the structure                                             */
+    UWORD32                                     u4_size;
+
+    /** Command type : IVE_CMD_VIDEO_CTL                                  */
+    IVE_API_COMMAND_TYPE_T                      e_cmd;
+
+    /** Sub command type : IVE_CMD_CTL_SET_SEI_CLL_PARAMS                 */
+    IVE_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+
+    /** content light level info present flag                             */
+    UWORD8                                      u1_sei_cll_params_present_flag;
+
+    /** The maximum pixel intensity of all samples                        */
+    UWORD16                                     u2_max_content_light_level;
+
+    /** The average pixel intensity of all samples                        */
+    UWORD16                                     u2_max_pic_average_light_level;
+
+    /** Lower 32bits of time stamp corresponding to input buffer,
+     * from which this command takes effect                               */
+    UWORD32                                     u4_timestamp_low;
+
+    /** Upper 32bits of time stamp corresponding to input buffer,
+     * from which this command takes effect                               */
+    UWORD32                                     u4_timestamp_high;
+
+}ih264e_ctl_set_sei_cll_params_ip_t;
+
+typedef struct
+{
+    /** size of the structure                                             */
+    UWORD32                                     u4_size;
+
+    /** Return error code                                                 */
+    UWORD32                                     u4_error_code;
+
+}ih264e_ctl_set_sei_cll_params_op_t;
+
+/*****************************************************************************/
+/*    Video control  Set SEI AVE params                                      */
+/*****************************************************************************/
+typedef struct
+{
+    /** size of the structure                                             */
+    UWORD32                                     u4_size;
+
+    /** Command type : IVE_CMD_VIDEO_CTL                                  */
+    IVE_API_COMMAND_TYPE_T                      e_cmd;
+
+    /** Sub command type : IVE_CMD_CTL_SET_SEI_AVE_PARAMS                 */
+    IVE_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+
+    /** ambient viewing environment info present flag                     */
+    UWORD8                                      u1_sei_ave_params_present_flag;
+
+    /** specifies the environmental illluminance of the ambient viewing
+     * environment                                                        */
+    UWORD32                                     u4_ambient_illuminance;
+
+    /** specify the normalized x chromaticity coordinates of the
+     * environmental ambient light in the nominal viewing environment     */
+    UWORD16                                     u2_ambient_light_x;
+
+    /** specify the normalized y chromaticity coordinates of the
+     * environmental ambient light in the nominal viewing environment     */
+    UWORD16                                     u2_ambient_light_y;
+
+    /** Lower 32bits of time stamp corresponding to input buffer,
+     * from which this command takes effect                               */
+    UWORD32                                     u4_timestamp_low;
+
+    /** Upper 32bits of time stamp corresponding to input buffer,
+     * from which this command takes effect                               */
+    UWORD32                                     u4_timestamp_high;
+
+}ih264e_ctl_set_sei_ave_params_ip_t;
+
+typedef struct
+{
+    /** size of the structure                                             */
+    UWORD32                                     u4_size;
+
+    /** Return error code                                                 */
+    UWORD32                                     u4_error_code;
+
+}ih264e_ctl_set_sei_ave_params_op_t;
+
+/*****************************************************************************/
+/*    Video control  Set SEI CCV params                                      */
+/*****************************************************************************/
+typedef struct
+{
+    /** size of the structure                                             */
+    UWORD32                                     u4_size;
+
+    /** Command type : IVE_CMD_VIDEO_CTL                                  */
+    IVE_API_COMMAND_TYPE_T                      e_cmd;
+
+    /** Sub command type : IVE_CMD_CTL_SET_SEI_CCV_PARAMS                 */
+    IVE_CONTROL_API_COMMAND_TYPE_T              e_sub_cmd;
+
+    /** content color volume info present flag                            */
+    UWORD8                                      u1_sei_ccv_params_present_flag;
+
+    /** Flag used to control persistence of CCV SEI messages              */
+    UWORD8                                      u1_ccv_cancel_flag;
+
+    /** specifies the persistence of the CCV SEI message for the
+     * current layer                                                      */
+    UWORD8                                      u1_ccv_persistence_flag;
+
+    /** specifies the presence of syntax elements ccv_primaries_x
+     * and ccv_primaries_y                                                */
+    UWORD8                                      u1_ccv_primaries_present_flag;
+
+    /** specifies that the syntax element ccv_min_luminance_value
+     * is present                                                         */
+    UWORD8                                      u1_ccv_min_luminance_value_present_flag;
+
+    /** specifies that the syntax element ccv_max_luminance_value
+     *  is present                                                        */
+    UWORD8                                      u1_ccv_max_luminance_value_present_flag;
+
+    /** specifies that the syntax element ccv_avg_luminance_value
+     *  is present                                                        */
+    UWORD8                                      u1_ccv_avg_luminance_value_present_flag;
+
+    /** shall be equal to 0 in bitstreams conforming to this version.
+     * Other values for reserved_zero_2bits are reserved for future use   */
+    UWORD8                                      u1_ccv_reserved_zero_2bits;
+
+    /** specify the normalized x chromaticity coordinates of the colour
+     * primary component c of the nominal content colour volume           */
+    WORD32                                      ai4_ccv_primaries_x[3];
+
+    /** specify the normalized y chromaticity coordinates of the colour
+     * primary component c of the nominal content colour volume           */
+    WORD32                                      ai4_ccv_primaries_y[3];
+
+    /** specifies the normalized minimum luminance value                  */
+    UWORD32                                     u4_ccv_min_luminance_value;
+
+    /** specifies the normalized maximum luminance value                  */
+    UWORD32                                     u4_ccv_max_luminance_value;
+
+    /** specifies the normalized average luminance value                  */
+    UWORD32                                     u4_ccv_avg_luminance_value;
+
+    /** Lower 32bits of time stamp corresponding to input buffer,
+     * from which this command takes effect                               */
+    UWORD32                                     u4_timestamp_low;
+
+    /** Upper 32bits of time stamp corresponding to input buffer,
+     * from which this command takes effect                               */
+    UWORD32                                     u4_timestamp_high;
+
+}ih264e_ctl_set_sei_ccv_params_ip_t;
+
+typedef struct
+{
+    /** size of the structure                                             */
+    UWORD32                                     u4_size;
+
+    /** Return error code                                                 */
+    UWORD32                                     u4_error_code;
+
+}ih264e_ctl_set_sei_ccv_params_op_t;
+
 
 /* The enum values should not have greater than 8 bits as this is assigned to WORD8 */
 typedef enum
diff --git a/encoder/ih264e_api.c b/encoder/ih264e_api.c
index a996303..61ef6b5 100644
--- a/encoder/ih264e_api.c
+++ b/encoder/ih264e_api.c
@@ -1651,6 +1651,388 @@
                     break;
                 }
 
+                case IVE_CMD_CTL_SET_SEI_MDCV_PARAMS:
+                {
+                    ih264e_ctl_set_sei_mdcv_params_ip_t *ps_ip = pv_api_ip;
+                    ih264e_ctl_set_sei_mdcv_params_op_t *ps_op = pv_api_op;
+
+                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_mdcv_params_ip_t))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IVE_ERR_IP_CTL_SET_SEI_MDCV_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+
+                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_mdcv_params_op_t))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IVE_ERR_OP_CTL_SET_SEI_MDCV_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+
+                    if((ps_ip->u1_sei_mdcv_params_present_flag != 0)
+                            && (ps_ip->u1_sei_mdcv_params_present_flag) != 1)
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IH264E_INVALID_SEI_MDCV_PARAMS;
+                        return IV_FAIL;
+                    }
+
+                    if(1 == ps_ip->u1_sei_mdcv_params_present_flag)
+                    {
+                        /* Check values for u2_display_primaries_x and u2_display_primaries_y */
+                        for(i = 0; i < 3; i++)
+                        {
+                            if((ps_ip->au2_display_primaries_x[i] >
+                                                    DISPLAY_PRIMARIES_X_UPPER_LIMIT) ||
+                               (ps_ip->au2_display_primaries_x[i] <
+                                                    DISPLAY_PRIMARIES_X_LOWER_LIMIT) ||
+                               ((ps_ip->au2_display_primaries_x[i] %
+                                                    DISPLAY_PRIMARIES_X_DIVISION_FACTOR) != 0))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_MDCV_PARAMS;
+                                return IV_FAIL;
+                            }
+
+                            if((ps_ip->au2_display_primaries_y[i] >
+                                                    DISPLAY_PRIMARIES_Y_UPPER_LIMIT) ||
+                               (ps_ip->au2_display_primaries_y[i] <
+                                                    DISPLAY_PRIMARIES_Y_LOWER_LIMIT) ||
+                               ((ps_ip->au2_display_primaries_y[i] %
+                                                    DISPLAY_PRIMARIES_Y_DIVISION_FACTOR) != 0))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_MDCV_PARAMS;
+                                return IV_FAIL;
+                            }
+                        }
+
+                        if((ps_ip->u2_white_point_x > WHITE_POINT_X_UPPER_LIMIT) ||
+                           (ps_ip->u2_white_point_x < WHITE_POINT_X_LOWER_LIMIT) ||
+                           ((ps_ip->u2_white_point_x % WHITE_POINT_X_DIVISION_FACTOR) != 0))
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_MDCV_PARAMS;
+                            return IV_FAIL;
+                        }
+
+                        if((ps_ip->u2_white_point_y > WHITE_POINT_Y_UPPER_LIMIT) ||
+                           (ps_ip->u2_white_point_y < WHITE_POINT_Y_LOWER_LIMIT) ||
+                           ((ps_ip->u2_white_point_y % WHITE_POINT_Y_DIVISION_FACTOR) != 0))
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_MDCV_PARAMS;
+                            return IV_FAIL;
+                        }
+
+                        if((ps_ip->u4_max_display_mastering_luminance >
+                                        MAX_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT) ||
+                           (ps_ip->u4_max_display_mastering_luminance <
+                                        MAX_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT) ||
+                           ((ps_ip->u4_max_display_mastering_luminance %
+                                        MAX_DISPLAY_MASTERING_LUMINANCE_DIVISION_FACTOR) != 0))
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_MDCV_PARAMS;
+                            return IV_FAIL;
+                        }
+
+                        if((ps_ip->u4_min_display_mastering_luminance >
+                                        MIN_DISPLAY_MASTERING_LUMINANCE_UPPER_LIMIT ) ||
+                           (ps_ip->u4_min_display_mastering_luminance <
+                                        MIN_DISPLAY_MASTERING_LUMINANCE_LOWER_LIMIT))
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_MDCV_PARAMS;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_ip->u4_max_display_mastering_luminance <=
+                                ps_ip->u4_min_display_mastering_luminance)
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_MDCV_PARAMS;
+                            return IV_FAIL;
+                        }
+                    }
+                    break;
+                }
+
+                case IVE_CMD_CTL_SET_SEI_CLL_PARAMS:
+                {
+                    ih264e_ctl_set_sei_cll_params_ip_t *ps_ip = pv_api_ip;
+                    ih264e_ctl_set_sei_cll_params_op_t *ps_op = pv_api_op;
+
+                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_cll_params_ip_t))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IVE_ERR_IP_CTL_SET_SEI_CLL_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+
+                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_cll_params_op_t))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IVE_ERR_OP_CTL_SET_SEI_CLL_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+
+                    if((ps_ip->u1_sei_cll_params_present_flag != 0)
+                            && (ps_ip->u1_sei_cll_params_present_flag != 1))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IH264E_INVALID_SEI_CLL_PARAMS;
+                        return IV_FAIL;
+                    }
+                    break;
+                }
+
+                case IVE_CMD_CTL_SET_SEI_AVE_PARAMS:
+                {
+                    ih264e_ctl_set_sei_ave_params_ip_t *ps_ip = pv_api_ip;
+                    ih264e_ctl_set_sei_ave_params_op_t *ps_op = pv_api_op;
+
+                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_ave_params_ip_t))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IVE_ERR_IP_CTL_SET_SEI_AVE_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+
+                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_ave_params_op_t))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IVE_ERR_OP_CTL_SET_SEI_AVE_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+
+                    if((ps_ip->u1_sei_ave_params_present_flag != 0)
+                            && (ps_ip->u1_sei_ave_params_present_flag != 1))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IH264E_INVALID_SEI_AVE_PARAMS;
+                        return IV_FAIL;
+                    }
+
+                    if(1 == ps_ip->u1_sei_ave_params_present_flag)
+                    {
+                        if((0 == ps_ip->u4_ambient_illuminance))
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_AVE_PARAMS;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_ip->u2_ambient_light_x > AMBIENT_LIGHT_X_UPPER_LIMIT)
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_AVE_PARAMS;
+                            return IV_FAIL;
+                        }
+
+                        if(ps_ip->u2_ambient_light_y > AMBIENT_LIGHT_Y_UPPER_LIMIT)
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_AVE_PARAMS;
+                            return IV_FAIL;
+                        }
+                    }
+                    break;
+                }
+
+                case IVE_CMD_CTL_SET_SEI_CCV_PARAMS:
+                {
+                    ih264e_ctl_set_sei_ccv_params_ip_t *ps_ip = pv_api_ip;
+                    ih264e_ctl_set_sei_ccv_params_op_t *ps_op = pv_api_op;
+
+                    if(ps_ip->u4_size != sizeof(ih264e_ctl_set_sei_ccv_params_ip_t))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IVE_ERR_IP_CTL_SET_SEI_CCV_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+
+                    if(ps_op->u4_size != sizeof(ih264e_ctl_set_sei_ccv_params_op_t))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IVE_ERR_OP_CTL_SET_SEI_CCV_STRUCT_SIZE_INCORRECT;
+                        return IV_FAIL;
+                    }
+
+                    if((ps_ip->u1_sei_ccv_params_present_flag != 0)
+                            && (ps_ip->u1_sei_ccv_params_present_flag != 1))
+                    {
+                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                        ps_op->u4_error_code |=
+                                IH264E_INVALID_SEI_CCV_PARAMS;
+                        return IV_FAIL;
+                    }
+
+
+                    if(1 == ps_ip->u1_sei_ccv_params_present_flag)
+                    {
+                        if((ps_ip->u1_ccv_cancel_flag != 0)
+                                && (ps_ip->u1_ccv_cancel_flag != 1))
+                        {
+                            ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                            ps_op->u4_error_code |=
+                                    IH264E_INVALID_SEI_CCV_PARAMS;
+                            return IV_FAIL;
+                        }
+
+                        if(0 == ps_ip->u1_ccv_cancel_flag)
+                        {
+                            if((ps_ip->u1_ccv_persistence_flag != 0)
+                                    && (ps_ip->u1_ccv_persistence_flag != 1))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_CCV_PARAMS;
+                                return IV_FAIL;
+                            }
+                            if((ps_ip->u1_ccv_primaries_present_flag != 0)
+                                    && (ps_ip->u1_ccv_primaries_present_flag != 1))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_CCV_PARAMS;
+                                return IV_FAIL;
+                            }
+                            if((ps_ip->u1_ccv_min_luminance_value_present_flag != 0)
+                                    && (ps_ip->u1_ccv_min_luminance_value_present_flag != 1))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_CCV_PARAMS;
+                                return IV_FAIL;
+                            }
+                            if((ps_ip->u1_ccv_max_luminance_value_present_flag != 0)
+                                    && (ps_ip->u1_ccv_max_luminance_value_present_flag != 1))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_CCV_PARAMS;
+                                return IV_FAIL;
+                            }
+                            if((ps_ip->u1_ccv_avg_luminance_value_present_flag != 0)
+                                    && (ps_ip->u1_ccv_avg_luminance_value_present_flag != 1))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_CCV_PARAMS;
+                                return IV_FAIL;
+                            }
+                            if((ps_ip->u1_ccv_primaries_present_flag == 0)
+                                    && (ps_ip->u1_ccv_min_luminance_value_present_flag == 0)
+                                    && (ps_ip->u1_ccv_max_luminance_value_present_flag == 0)
+                                    && (ps_ip->u1_ccv_avg_luminance_value_present_flag == 0))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_CCV_PARAMS;
+                                return IV_FAIL;
+                            }
+
+                            if((ps_ip->u1_ccv_reserved_zero_2bits != 0))
+                            {
+                                ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                ps_op->u4_error_code |=
+                                        IH264E_INVALID_SEI_CCV_PARAMS;
+                                return IV_FAIL;
+                            }
+
+                            if(1 == ps_ip->u1_ccv_primaries_present_flag)
+                            {
+                                for(i = 0; i < 3; i++)
+                                {
+                                    if((ps_ip->ai4_ccv_primaries_x[i] >
+                                                        CCV_PRIMARIES_X_UPPER_LIMIT) ||
+                                       (ps_ip->ai4_ccv_primaries_x[i] <
+                                                        CCV_PRIMARIES_X_LOWER_LIMIT))
+                                    {
+                                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                        ps_op->u4_error_code |=
+                                                IH264E_INVALID_SEI_CCV_PARAMS;
+                                        return IV_FAIL;
+                                    }
+
+                                    if((ps_ip->ai4_ccv_primaries_y[i] >
+                                                        CCV_PRIMARIES_Y_UPPER_LIMIT) ||
+                                       (ps_ip->ai4_ccv_primaries_y[i] <
+                                                        CCV_PRIMARIES_Y_LOWER_LIMIT))
+                                    {
+                                        ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                        ps_op->u4_error_code |=
+                                                IH264E_INVALID_SEI_CCV_PARAMS;
+                                        return IV_FAIL;
+                                    }
+                                }
+                            }
+
+                            if((1 == ps_ip->u1_ccv_min_luminance_value_present_flag) &&
+                                    (1 == ps_ip->u1_ccv_avg_luminance_value_present_flag))
+                            {
+                                if((ps_ip->u4_ccv_avg_luminance_value <
+                                                    ps_ip->u4_ccv_min_luminance_value))
+                                {
+                                    ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                    ps_op->u4_error_code |=
+                                            IH264E_INVALID_SEI_CCV_PARAMS;
+                                    return IV_FAIL;
+                                }
+                            }
+
+                            if((1 == ps_ip->u1_ccv_min_luminance_value_present_flag) &&
+                                    (1 == ps_ip->u1_ccv_max_luminance_value_present_flag))
+                            {
+                                if((ps_ip->u4_ccv_max_luminance_value <
+                                                    ps_ip->u4_ccv_min_luminance_value))
+                                {
+                                    ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                    ps_op->u4_error_code |=
+                                            IH264E_INVALID_SEI_CCV_PARAMS;
+                                    return IV_FAIL;
+                                }
+                            }
+                            if((1 == ps_ip->u1_ccv_avg_luminance_value_present_flag) &&
+                                    (1 == ps_ip->u1_ccv_max_luminance_value_present_flag))
+                            {
+                                if((ps_ip->u4_ccv_max_luminance_value <
+                                                    ps_ip->u4_ccv_avg_luminance_value))
+                                {
+                                    ps_op->u4_error_code |= 1 << IVE_UNSUPPORTEDPARAM;
+                                    ps_op->u4_error_code |=
+                                            IH264E_INVALID_SEI_CCV_PARAMS;
+                                    return IV_FAIL;
+                                }
+                            }
+                        }
+                    }
+                    break;
+                }
+
                 case IVE_CMD_CTL_SET_ENC_MODE:
                 {
                     ih264e_ctl_set_enc_mode_ip_t *ps_ip = pv_api_ip;
@@ -2256,6 +2638,32 @@
     {
         ps_codec->s_cfg.s_vui = ps_cfg->s_vui;
     }
+
+    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_MDCV_PARAMS)
+    {
+        ps_codec->s_cfg.s_sei.u1_sei_mdcv_params_present_flag =
+                                                ps_cfg->s_sei.u1_sei_mdcv_params_present_flag;
+        ps_codec->s_cfg.s_sei.s_sei_mdcv_params = ps_cfg->s_sei.s_sei_mdcv_params;
+    }
+    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_CLL_PARAMS)
+    {
+        ps_codec->s_cfg.s_sei.u1_sei_cll_params_present_flag =
+                                                ps_cfg->s_sei.u1_sei_cll_params_present_flag;
+        ps_codec->s_cfg.s_sei.s_sei_cll_params = ps_cfg->s_sei.s_sei_cll_params;
+    }
+    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_AVE_PARAMS)
+    {
+        ps_codec->s_cfg.s_sei.u1_sei_ave_params_present_flag =
+                                                ps_cfg->s_sei.u1_sei_ave_params_present_flag;
+        ps_codec->s_cfg.s_sei.s_sei_ave_params = ps_cfg->s_sei.s_sei_ave_params;
+    }
+    else if (ps_cfg->e_cmd == IVE_CMD_CTL_SET_SEI_CCV_PARAMS)
+    {
+        ps_codec->s_cfg.s_sei.u1_sei_ccv_params_present_flag =
+                                                ps_cfg->s_sei.u1_sei_ccv_params_present_flag;
+        ps_codec->s_cfg.s_sei.s_sei_ccv_params = ps_cfg->s_sei.s_sei_ccv_params;
+    }
+
     /* reset RC model */
     if (u4_init_rc)
     {
@@ -2425,6 +2833,8 @@
     ps_cfg->u4_constrained_intra_pred = 0;
     ps_cfg->u4_pic_info_type = 0;
     ps_cfg->u4_mb_info_type = 0;
+    ps_cfg->s_vui.u1_video_signal_type_present_flag = 1;
+    ps_cfg->s_vui.u1_colour_description_present_flag = 1;
 
     return ret;
 }
@@ -5346,6 +5756,228 @@
 
     return IV_SUCCESS;
 }
+
+/**
+ *******************************************************************************
+ *
+ * @brief
+ *  Sets Mastering display color volume sei params
+ *
+ * @par Description:
+ *  Supplemental enhancement information
+ *
+ * @param[in] pv_api_ip
+ *  Pointer to input argument structure
+ *
+ * @param[out] pv_api_op
+ *  Pointer to output argument structure
+ *
+ * @param[out] ps_cfg
+ *  Pointer to config structure to be updated
+ *
+ * @return error status
+ *
+ * @remarks none
+ *
+ *******************************************************************************
+ */
+static WORD32 ih264e_set_sei_mdcv_params(void *pv_api_ip,
+                                         void *pv_api_op,
+                                         cfg_params_t *ps_cfg)
+{
+    WORD32 i4_count;
+    /* ctrl call I/O structures */
+    ih264e_ctl_set_sei_mdcv_params_ip_t *ps_ip = pv_api_ip;
+    ih264e_ctl_set_sei_mdcv_params_op_t *ps_op = pv_api_op;
+    sei_params_t *ps_sei = &ps_cfg->s_sei;
+
+    ps_op->u4_error_code = 0;
+
+    ps_sei->u1_sei_mdcv_params_present_flag = ps_ip->u1_sei_mdcv_params_present_flag;
+    for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
+    {
+        ps_sei->s_sei_mdcv_params.au2_display_primaries_x[i4_count] =
+                                                ps_ip->au2_display_primaries_x[i4_count];
+        ps_sei->s_sei_mdcv_params.au2_display_primaries_y[i4_count] =
+                                                ps_ip->au2_display_primaries_y[i4_count];
+    }
+
+    ps_sei->s_sei_mdcv_params.u2_white_point_x = ps_ip->u2_white_point_x;
+    ps_sei->s_sei_mdcv_params.u2_white_point_y = ps_ip->u2_white_point_y;
+    ps_sei->s_sei_mdcv_params.u4_max_display_mastering_luminance =
+                                                ps_ip->u4_max_display_mastering_luminance;
+    ps_sei->s_sei_mdcv_params.u4_min_display_mastering_luminance =
+                                                ps_ip->u4_min_display_mastering_luminance;
+
+    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
+    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
+
+    return IV_SUCCESS;
+}
+
+/**
+ *******************************************************************************
+ *
+ * @brief
+ *  Sets content light level sei params
+ *
+ * @par Description:
+ *  Supplemental enhancement information
+ *
+ * @param[in] pv_api_ip
+ *  Pointer to input argument structure
+ *
+ * @param[out] pv_api_op
+ *  Pointer to output argument structure
+ *
+ * @param[out] ps_cfg
+ *  Pointer to config structure to be updated
+ *
+ * @return error status
+ *
+ * @remarks none
+ *
+ *******************************************************************************
+ */
+static WORD32 ih264e_set_sei_cll_params(void *pv_api_ip,
+                                        void *pv_api_op,
+                                        cfg_params_t *ps_cfg)
+{
+    /* ctrl call I/O structures */
+    ih264e_ctl_set_sei_cll_params_ip_t *ps_ip = pv_api_ip;
+    ih264e_ctl_set_sei_cll_params_op_t *ps_op = pv_api_op;
+    sei_params_t *ps_sei = &ps_cfg->s_sei;
+
+    ps_op->u4_error_code = 0;
+
+    ps_sei->u1_sei_cll_params_present_flag = ps_ip->u1_sei_cll_params_present_flag;
+
+    ps_sei->s_sei_cll_params.u2_max_content_light_level = ps_ip->u2_max_content_light_level;
+    ps_sei->s_sei_cll_params.u2_max_pic_average_light_level =
+                                                ps_ip->u2_max_pic_average_light_level;
+
+    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
+    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
+
+    return IV_SUCCESS;
+}
+
+/**
+ *******************************************************************************
+ *
+ * @brief
+ *  Sets ambient viewing environment sei params
+ *
+ * @par Description:
+ *  Supplemental enhancement information
+ *
+ * @param[in] pv_api_ip
+ *  Pointer to input argument structure
+ *
+ * @param[out] pv_api_op
+ *  Pointer to output argument structure
+ *
+ * @param[out] ps_cfg
+ *  Pointer to config structure to be updated
+ *
+ * @return error status
+ *
+ * @remarks none
+ *
+ *******************************************************************************
+ */
+static WORD32 ih264e_set_sei_ave_params(void *pv_api_ip,
+                                        void *pv_api_op,
+                                        cfg_params_t *ps_cfg)
+{
+    /* ctrl call I/O structures */
+    ih264e_ctl_set_sei_ave_params_ip_t *ps_ip = pv_api_ip;
+    ih264e_ctl_set_sei_ave_params_op_t *ps_op = pv_api_op;
+    sei_params_t *ps_sei = &ps_cfg->s_sei;
+
+    ps_op->u4_error_code = 0;
+
+    ps_sei->u1_sei_ave_params_present_flag = ps_ip->u1_sei_ave_params_present_flag;
+
+    ps_sei->s_sei_ave_params.u4_ambient_illuminance = ps_ip->u4_ambient_illuminance;
+    ps_sei->s_sei_ave_params.u2_ambient_light_x = ps_ip->u2_ambient_light_x;
+    ps_sei->s_sei_ave_params.u2_ambient_light_y = ps_ip->u2_ambient_light_y;
+
+    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
+    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
+
+    return IV_SUCCESS;
+}
+
+/**
+ *******************************************************************************
+ *
+ * @brief
+ *  Sets content color volume sei params
+ *
+ * @par Description:
+ *  Supplemental enhancement information
+ *
+ * @param[in] pv_api_ip
+ *  Pointer to input argument structure
+ *
+ * @param[out] pv_api_op
+ *  Pointer to output argument structure
+ *
+ * @param[out] ps_cfg
+ *  Pointer to config structure to be updated
+ *
+ * @return error status
+ *
+ * @remarks none
+ *
+ *******************************************************************************
+ */
+static WORD32 ih264e_set_sei_ccv_params(void *pv_api_ip,
+                                        void *pv_api_op,
+                                        cfg_params_t *ps_cfg)
+{
+    WORD32 i4_count;
+    /* ctrl call I/O structures */
+    ih264e_ctl_set_sei_ccv_params_ip_t *ps_ip = pv_api_ip;
+    ih264e_ctl_set_sei_ccv_params_op_t *ps_op = pv_api_op;
+    sei_params_t *ps_sei = &ps_cfg->s_sei;
+
+    ps_op->u4_error_code = 0;
+
+    ps_sei->u1_sei_ccv_params_present_flag = ps_ip->u1_sei_ccv_params_present_flag;
+
+    ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag = ps_ip->u1_ccv_cancel_flag;
+    ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag = ps_ip->u1_ccv_persistence_flag;
+    ps_sei->s_sei_ccv_params.u1_ccv_primaries_present_flag =
+                                                ps_ip->u1_ccv_primaries_present_flag;
+    ps_sei->s_sei_ccv_params.u1_ccv_min_luminance_value_present_flag =
+                                                ps_ip->u1_ccv_min_luminance_value_present_flag;
+    ps_sei->s_sei_ccv_params.u1_ccv_max_luminance_value_present_flag =
+                                                ps_ip->u1_ccv_max_luminance_value_present_flag;
+    ps_sei->s_sei_ccv_params.u1_ccv_avg_luminance_value_present_flag =
+                                                ps_ip->u1_ccv_avg_luminance_value_present_flag;
+    ps_sei->s_sei_ccv_params.u1_ccv_reserved_zero_2bits =
+                                                ps_ip->u1_ccv_reserved_zero_2bits;
+
+    for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
+    {
+        ps_sei->s_sei_ccv_params.ai4_ccv_primaries_x[i4_count] =
+                                                ps_ip->ai4_ccv_primaries_x[i4_count];
+        ps_sei->s_sei_ccv_params.ai4_ccv_primaries_y[i4_count] =
+                                                ps_ip->ai4_ccv_primaries_y[i4_count];
+    }
+
+    ps_sei->s_sei_ccv_params.u4_ccv_min_luminance_value = ps_ip->u4_ccv_min_luminance_value;
+    ps_sei->s_sei_ccv_params.u4_ccv_max_luminance_value = ps_ip->u4_ccv_max_luminance_value;
+    ps_sei->s_sei_ccv_params.u4_ccv_avg_luminance_value = ps_ip->u4_ccv_avg_luminance_value;
+
+    ps_cfg->u4_timestamp_high = ps_ip->u4_timestamp_high;
+    ps_cfg->u4_timestamp_low = ps_ip->u4_timestamp_low;
+
+    return IV_SUCCESS;
+}
+
 /**
 *******************************************************************************
 *
@@ -5573,6 +6205,22 @@
             ret = ih264e_set_vui_params(pv_api_ip, pv_api_op, ps_cfg);
             break;
 
+        case IVE_CMD_CTL_SET_SEI_MDCV_PARAMS:
+            ret = ih264e_set_sei_mdcv_params(pv_api_ip, pv_api_op, ps_cfg);
+            break;
+
+        case IVE_CMD_CTL_SET_SEI_CLL_PARAMS:
+            ret = ih264e_set_sei_cll_params(pv_api_ip, pv_api_op, ps_cfg);
+            break;
+
+        case IVE_CMD_CTL_SET_SEI_AVE_PARAMS:
+            ret = ih264e_set_sei_ave_params(pv_api_ip, pv_api_op, ps_cfg);
+            break;
+
+        case IVE_CMD_CTL_SET_SEI_CCV_PARAMS:
+            ret = ih264e_set_sei_ccv_params(pv_api_ip, pv_api_op, ps_cfg);
+            break;
+
         case IVE_CMD_CTL_RESET:
 
             /* invalidate config param struct as it is being served right away */
diff --git a/encoder/ih264e_encode.c b/encoder/ih264e_encode.c
index c7e3717..fe23841 100644
--- a/encoder/ih264e_encode.c
+++ b/encoder/ih264e_encode.c
@@ -96,6 +96,9 @@
 #include "ih264e_ittiam_logo.h"
 #endif
 
+
+#define SEI_BASED_FORCE_IDR 1
+
 /*****************************************************************************/
 /* Function Definitions                                                      */
 /*****************************************************************************/
@@ -232,7 +235,7 @@
     /* Check for output memory allocation size */
     if (ps_video_encode_ip->s_ive_ip.s_out_buf.u4_bufsize < MIN_STREAM_SIZE)
     {
-        error_status |= IH264E_INSUFFICIENT_OUTPUT_BUFFER;
+        error_status = IH264E_INSUFFICIENT_OUTPUT_BUFFER;
         SET_ERROR_ON_RETURN(error_status,
                             IVE_UNSUPPORTEDPARAM,
                             ps_video_encode_op->s_ive_op.u4_error_code,
@@ -277,7 +280,7 @@
                             ((WORD32)ps_cfg->u4_timestamp_high == -1) ||
                             ((WORD32)ps_cfg->u4_timestamp_low == -1) )
             {
-                error_status |= ih264e_codec_update_config(ps_codec, ps_cfg);
+                error_status = ih264e_codec_update_config(ps_codec, ps_cfg);
                 SET_ERROR_ON_RETURN(error_status,
                                     IVE_UNSUPPORTEDPARAM,
                                     ps_video_encode_op->s_ive_op.u4_error_code,
@@ -287,7 +290,84 @@
             }
         }
     }
+    /* Force IDR based on SEI params */
+#if SEI_BASED_FORCE_IDR
+    {
+        sei_mdcv_params_t *ps_sei_mdcv_params = &ps_codec->s_sei.s_sei_mdcv_params;
+        sei_mdcv_params_t *ps_cfg_sei_mdcv_params =
+                                &ps_codec->s_cfg.s_sei.s_sei_mdcv_params;
+        sei_cll_params_t *ps_sei_cll_params = &ps_codec->s_sei.s_sei_cll_params;
+        sei_cll_params_t *ps_cfg_sei_cll_params =
+                                &ps_codec->s_cfg.s_sei.s_sei_cll_params;
+        sei_ave_params_t *ps_sei_ave_params = &ps_codec->s_sei.s_sei_ave_params;
+        sei_ave_params_t *ps_cfg_sei_ave_params =
+                                &ps_codec->s_cfg.s_sei.s_sei_ave_params;
 
+        if((ps_sei_mdcv_params->au2_display_primaries_x[0]!=
+                                ps_cfg_sei_mdcv_params->au2_display_primaries_x[0]) ||
+            (ps_sei_mdcv_params->au2_display_primaries_x[1] !=
+                                ps_cfg_sei_mdcv_params->au2_display_primaries_x[1]) ||
+            (ps_sei_mdcv_params->au2_display_primaries_x[2] !=
+                                ps_cfg_sei_mdcv_params->au2_display_primaries_x[2]) ||
+            (ps_sei_mdcv_params->au2_display_primaries_y[0] !=
+                                ps_cfg_sei_mdcv_params->au2_display_primaries_y[0]) ||
+            (ps_sei_mdcv_params->au2_display_primaries_y[1] !=
+                                ps_cfg_sei_mdcv_params->au2_display_primaries_y[1]) ||
+            (ps_sei_mdcv_params->au2_display_primaries_y[2] !=
+                                ps_cfg_sei_mdcv_params->au2_display_primaries_y[2]) ||
+            (ps_sei_mdcv_params->u2_white_point_x !=
+                                ps_cfg_sei_mdcv_params->u2_white_point_x) ||
+            (ps_sei_mdcv_params->u2_white_point_y !=
+                                ps_cfg_sei_mdcv_params->u2_white_point_y) ||
+            (ps_sei_mdcv_params->u4_max_display_mastering_luminance !=
+                                ps_cfg_sei_mdcv_params->u4_max_display_mastering_luminance) ||
+            (ps_sei_mdcv_params->u4_min_display_mastering_luminance !=
+                                ps_cfg_sei_mdcv_params->u4_min_display_mastering_luminance))
+        {
+            ps_codec->s_sei.s_sei_mdcv_params = ps_codec->s_cfg.s_sei.s_sei_mdcv_params;
+            ps_codec->s_sei.u1_sei_mdcv_params_present_flag = 1;
+        }
+        else
+        {
+            ps_codec->s_sei.u1_sei_mdcv_params_present_flag = 0;
+        }
+
+        if((ps_sei_cll_params->u2_max_content_light_level !=
+                                ps_cfg_sei_cll_params->u2_max_content_light_level) ||
+                (ps_sei_cll_params->u2_max_pic_average_light_level !=
+                                ps_cfg_sei_cll_params->u2_max_pic_average_light_level))
+        {
+            ps_codec->s_sei.s_sei_cll_params = ps_codec->s_cfg.s_sei.s_sei_cll_params;
+            ps_codec->s_sei.u1_sei_cll_params_present_flag = 1;
+        }
+        else
+        {
+            ps_codec->s_sei.u1_sei_cll_params_present_flag = 0;
+        }
+
+        if((ps_sei_ave_params->u4_ambient_illuminance !=
+                                ps_cfg_sei_ave_params->u4_ambient_illuminance) ||
+                (ps_sei_ave_params->u2_ambient_light_x !=
+                                ps_cfg_sei_ave_params->u2_ambient_light_x) ||
+                (ps_sei_ave_params->u2_ambient_light_y !=
+                                ps_cfg_sei_ave_params->u2_ambient_light_y))
+        {
+            ps_codec->s_sei.s_sei_ave_params = ps_codec->s_cfg.s_sei.s_sei_ave_params;
+            ps_codec->s_sei.u1_sei_ave_params_present_flag = 1;
+        }
+        else
+        {
+            ps_codec->s_sei.u1_sei_ave_params_present_flag = 0;
+        }
+
+        if((1 == ps_codec->s_sei.u1_sei_mdcv_params_present_flag) ||
+                (1 == ps_codec->s_sei.u1_sei_cll_params_present_flag) ||
+                (1 == ps_codec->s_sei.u1_sei_ave_params_present_flag))
+        {
+            ps_codec->force_curr_frame_type = IV_IDR_FRAME;
+        }
+    }
+#endif
     /******************************************************************
      * INSERT LOGO
      *****************************************************************/
@@ -324,14 +404,14 @@
         /********************************************************************/
 
         /* initialize mv bank buffer manager */
-        error_status |= ih264e_mv_buf_mgr_add_bufs(ps_codec);
+        error_status = ih264e_mv_buf_mgr_add_bufs(ps_codec);
         SET_ERROR_ON_RETURN(error_status,
                             IVE_FATALERROR,
                             ps_video_encode_op->s_ive_op.u4_error_code,
                             IV_FAIL);
 
         /* initialize ref bank buffer manager */
-        error_status |= ih264e_pic_buf_mgr_add_bufs(ps_codec);
+        error_status = ih264e_pic_buf_mgr_add_bufs(ps_codec);
         SET_ERROR_ON_RETURN(error_status,
                             IVE_FATALERROR,
                             ps_video_encode_op->s_ive_op.u4_error_code,
@@ -354,14 +434,7 @@
         ps_codec->force_curr_frame_type = IV_IDR_FRAME;
 
         /* generate header */
-        error_status |= ih264e_generate_sps_pps(ps_codec);
-
-        /* api call cnt */
-        ps_codec->i4_encode_api_call_cnt --;
-
-        /* header mode tag is not sticky */
-        ps_codec->i4_header_mode = 0;
-        ps_codec->i4_gen_header = 0;
+        error_status = ih264e_generate_sps_pps(ps_codec);
 
         /* send the input to app */
         ps_video_encode_op->s_ive_op.s_inp_buf = ps_video_encode_ip->s_ive_ip.s_inp_buf;
@@ -384,6 +457,13 @@
         /* indicates that header has been generated previously */
         ps_codec->u4_header_generated = 1;
 
+        /* api call cnt */
+        ps_codec->i4_encode_api_call_cnt --;
+
+        /* header mode tag is not sticky */
+        ps_codec->i4_header_mode = 0;
+        ps_codec->i4_gen_header = 0;
+
         return IV_SUCCESS;
     }
 
@@ -418,7 +498,7 @@
         ps_codec->ai4_pic_cnt[ctxt_sel] = ps_codec->i4_pic_cnt;
 
         /* initialize all relevant process ctxts */
-        error_status |= ih264e_pic_init(ps_codec, &s_inp_buf);
+        error_status = ih264e_pic_init(ps_codec, &s_inp_buf);
         SET_ERROR_ON_RETURN(error_status,
                             IVE_FATALERROR,
                             ps_video_encode_op->s_ive_op.u4_error_code,
@@ -691,12 +771,12 @@
 
         for (i = 0; i < (WORD32)ps_codec->s_cfg.u4_num_cores; i++)
         {
-            error_status |= ps_codec->as_process[ctxt_sel + i].i4_error_code;
+            error_status = ps_codec->as_process[ctxt_sel + i].i4_error_code;
+            SET_ERROR_ON_RETURN(error_status,
+                                IVE_FATALERROR,
+                                ps_video_encode_op->s_ive_op.u4_error_code,
+                                IV_FAIL);
         }
-        SET_ERROR_ON_RETURN(error_status,
-                            IVE_FATALERROR,
-                            ps_video_encode_op->s_ive_op.u4_error_code,
-                            IV_FAIL);
     }
     else
     {
diff --git a/encoder/ih264e_encode_header.c b/encoder/ih264e_encode_header.c
index 3626a63..16cf28e 100644
--- a/encoder/ih264e_encode_header.c
+++ b/encoder/ih264e_encode_header.c
@@ -33,6 +33,7 @@
 *  - ih264e_generate_nal_unit_header()
 *  - ih264e_generate_sps()
 *  - ih264e_generate_pps()
+*  - ih264e_generate_sei()
 *  - ih264e_generate_slice_header()
 *  - ih264e_get_level()
 *  - ih264e_populate_sps()
@@ -87,6 +88,7 @@
 #include "ih264e_rate_control.h"
 #include "ih264e_cabac_structs.h"
 #include "ih264e_structs.h"
+#include "ih264e_sei.h"
 #include "ih264e_encode_header.h"
 #include "ih264_common_tables.h"
 #include "ih264_macros.h"
@@ -443,11 +445,17 @@
     WORD8  i1_nal_ref_idc = 3;
 
     /* Insert Start Code */
-    return_status |= ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
-
+    return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
+    if(return_status != IH264E_SUCCESS)
+    {
+        return return_status;
+    }
     /* Insert Nal Unit Header */
-    return_status |= ih264e_generate_nal_unit_header(ps_bitstrm, i1_nal_unit_type, i1_nal_ref_idc);
-
+    return_status = ih264e_generate_nal_unit_header(ps_bitstrm, i1_nal_unit_type, i1_nal_ref_idc);
+    if(return_status != IH264E_SUCCESS)
+    {
+        return return_status;
+    }
     /* profile_idc */
     PUT_BITS(ps_bitstrm, ps_sps->u1_profile_idc, 8, return_status, "profile_idc");
 
@@ -577,11 +585,15 @@
     if (ps_sps->i1_vui_parameters_present_flag)
     {
         /* Add vui parameters to the bitstream */;
-        return_status |= ih264e_generate_vui(ps_bitstrm, ps_vui);
+        return_status = ih264e_generate_vui(ps_bitstrm, ps_vui);
+        if(return_status != IH264E_SUCCESS)
+        {
+            return return_status;
+        }
     }
 
     /* rbsp trailing bits */
-    return_status |= ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+    return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
 
     return return_status;
 }
@@ -609,7 +621,11 @@
     WORD32 return_status = IH264E_SUCCESS;
 
     /* Insert the NAL start code */
-    return_status |= ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
+    return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
+    if(return_status != IH264E_SUCCESS)
+    {
+        return return_status;
+    }
 
     /* Insert Nal Unit Header */
     PUT_BITS(ps_bitstrm, NAL_PPS_FIRST_BYTE, 8, return_status, "pps_header");
@@ -682,7 +698,96 @@
         PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_second_chroma_qp_index_offset, return_status, "Second chroma QP offset");
     }
 
-    return_status |= ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+    return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+
+    return return_status;
+}
+
+/**
+******************************************************************************
+*
+* @brief Generates SEI (Supplemental Enhancement Information)
+*
+* @par   Description
+*  This function generates Supplemental Enhancement Information header as per the spec
+*
+* @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+* @param[in]   ps_sei
+*  pointer to structure containing SEI data
+*
+* @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_generate_sei(bitstrm_t *ps_bitstrm, sei_params_t *ps_sei,
+                                                        UWORD32 u4_insert_per_idr)
+{
+    WORD32 return_status = IH264E_SUCCESS;
+    WORD8  i1_nal_unit_type = NAL_SEI;
+    WORD8  i1_nal_ref_idc = 0;
+
+    /* Insert Start Code */
+    return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
+    if(return_status != IH264E_SUCCESS)
+    {
+        return return_status;
+    }
+
+    /* Insert Nal Unit Header */
+    return_status = ih264e_generate_nal_unit_header(ps_bitstrm,
+                                                    i1_nal_unit_type, i1_nal_ref_idc);
+    if(return_status != IH264E_SUCCESS)
+    {
+        return return_status;
+    }
+    /* Mastering Display Color SEI */
+    if(1 == ps_sei->u1_sei_mdcv_params_present_flag && u4_insert_per_idr)
+    {
+        return_status = ih264e_put_sei_msg(IH264_SEI_MASTERING_DISP_COL_VOL,
+                                            ps_sei, ps_bitstrm);
+        if(return_status != IH264E_SUCCESS)
+        {
+            return return_status;
+        }
+    }
+
+    /* Content Light Level Information*/
+    if(1 == ps_sei->u1_sei_cll_params_present_flag && u4_insert_per_idr)
+    {
+        return_status = ih264e_put_sei_msg(IH264_SEI_CONTENT_LIGHT_LEVEL_DATA,
+                                            ps_sei, ps_bitstrm);
+        if(return_status != IH264E_SUCCESS)
+        {
+            return return_status;
+        }
+    }
+
+    /* Ambient viewing environment SEI */
+    if(1 == ps_sei->u1_sei_ave_params_present_flag && u4_insert_per_idr)
+    {
+        return_status = ih264e_put_sei_msg(IH264_SEI_AMBIENT_VIEWING_ENVIRONMENT,
+                                            ps_sei, ps_bitstrm);
+        if(return_status != IH264E_SUCCESS)
+        {
+            return return_status;
+        }
+    }
+
+    /* Content color volume Information*/
+    if(1 == ps_sei->u1_sei_ccv_params_present_flag)
+    {
+        return_status = ih264e_put_sei_msg(IH264_SEI_CONTENT_COLOR_VOLUME,
+                                            ps_sei, ps_bitstrm);
+        if(return_status != IH264E_SUCCESS)
+        {
+            return return_status;
+        }
+    }
+
+    /* rbsp trailing bits */
+    return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
 
     return return_status;
 }
@@ -726,11 +831,17 @@
     WORD32 return_status = IH264E_SUCCESS;
 
     /* Insert start code */
-    return_status |= ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
-
+    return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
+    if(return_status != IH264E_SUCCESS)
+    {
+        return return_status;
+    }
     /* Insert Nal Unit Header */
-    return_status |= ih264e_generate_nal_unit_header(ps_bitstrm, ps_slice_hdr->i1_nal_unit_type, ps_slice_hdr->i1_nal_unit_idc);
-
+    return_status = ih264e_generate_nal_unit_header(ps_bitstrm, ps_slice_hdr->i1_nal_unit_type, ps_slice_hdr->i1_nal_unit_idc);
+    if(return_status != IH264E_SUCCESS)
+    {
+        return return_status;
+    }
     /* first_mb_in_slice */
     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u2_first_mb_in_slice, return_status, "first_mb_in_slice");
 
@@ -1507,7 +1618,11 @@
     IH264E_ERROR_T return_status = IH264E_SUCCESS;
 
     /* Insert the NAL start code */
-    return_status |= ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
+    return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
+    if(return_status != IH264E_SUCCESS)
+    {
+        return return_status;
+    }
 
     if (ps_bitstrm->u4_strm_buf_offset + insert_fill_bytes >= ps_bitstrm->u4_max_strm_size)
     {
@@ -1543,7 +1658,7 @@
         i4_num_words_to_fill-- ;
     }
 
-    return_status |= ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+    return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
 
     return return_status;
 }
diff --git a/encoder/ih264e_encode_header.h b/encoder/ih264e_encode_header.h
index c379d5e..a028930 100644
--- a/encoder/ih264e_encode_header.h
+++ b/encoder/ih264e_encode_header.h
@@ -49,9 +49,15 @@
  *           bitstream
 ******************************************************************************
  */
-#define PUT_BITS(ps_bitstrm, code_val, code_len, ret_val, syntax_string) \
-         ENTROPY_TRACE(syntax_string, code_val);\
-        ret_val |= ih264e_put_bits((ps_bitstrm), (code_val), (code_len))
+#define PUT_BITS(ps_bitstrm, code_val, code_len, ret_val, syntax_string)     \
+        {                                                                    \
+            ENTROPY_TRACE(syntax_string, code_val);                          \
+            ret_val = ih264e_put_bits((ps_bitstrm), (code_val), (code_len)); \
+            if(ret_val != IH264E_SUCCESS)                                    \
+            {                                                                \
+                return ret_val;                                              \
+            }                                                                \
+        }
 
 /**
 ******************************************************************************
@@ -60,10 +66,15 @@
  *           signed numbers
 ******************************************************************************
  */
-#define PUT_BITS_UEV(ps_bitstrm, code_val, ret_val, syntax_string) \
-        ENTROPY_TRACE(syntax_string, code_val);\
-        ret_val |= ih264e_put_uev((ps_bitstrm), (code_val))
-
+#define PUT_BITS_UEV(ps_bitstrm, code_val, ret_val, syntax_string)           \
+        {                                                                    \
+            ENTROPY_TRACE(syntax_string, code_val);                          \
+            ret_val = ih264e_put_uev((ps_bitstrm), (code_val));              \
+            if(ret_val != IH264E_SUCCESS)                                    \
+            {                                                                \
+                return ret_val;                                              \
+            }                                                                \
+        }
 /**
 ******************************************************************************
  *  @brief   Macro to put a code with specified number of bits into the
@@ -71,10 +82,29 @@
  *           signed numbers
 ******************************************************************************
  */
-#define PUT_BITS_SEV(ps_bitstrm, code_val, ret_val, syntax_string) \
-        ENTROPY_TRACE(syntax_string, code_val);\
-        ret_val |= ih264e_put_sev((ps_bitstrm), (code_val))
+#define PUT_BITS_SEV(ps_bitstrm, code_val, ret_val, syntax_string)           \
+        {                                                                    \
+            ENTROPY_TRACE(syntax_string, code_val);                          \
+            ret_val = ih264e_put_sev((ps_bitstrm), (code_val));              \
+            if(ret_val != IH264E_SUCCESS)                                    \
+            {                                                                \
+                return ret_val;                                              \
+            }                                                                \
+        }
 
+/**
+******************************************************************************
+ *  @brief   Macro to set active entropy threads to zero and return
+ *           in case of errors
+******************************************************************************
+ */
+#define RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel)              \
+        if(ps_entropy->i4_error_code != IH264E_SUCCESS)                      \
+        {                                                                    \
+            DATA_SYNC();                                                     \
+            ps_codec->au4_entropy_thread_active[ctxt_sel] = 0;               \
+            return ps_entropy->i4_error_code;                                \
+        }
 
 /*****************************************************************************/
 /* Extern Function Declarations                                              */
@@ -133,6 +163,31 @@
 /**
 ******************************************************************************
 *
+* @brief Generates SEI (Supplemental Enhancement Information)
+*
+* @par   Description
+*  This function generates Supplemental Enhancement Information header as per the spec
+*
+* @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+* @param[in]   ps_sei
+*  pointer to structure containing SEI data
+*
+* @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T      ih264e_generate_sei
+    (
+        bitstrm_t     *ps_bitstrm,
+        sei_params_t  *ps_sei,
+        UWORD32        u4_insert_per_idr
+    );
+
+/**
+******************************************************************************
+*
 * @brief Generates Slice Header
 *
 * @par   Description
diff --git a/encoder/ih264e_error.h b/encoder/ih264e_error.h
index ba489c9..c11d857 100644
--- a/encoder/ih264e_error.h
+++ b/encoder/ih264e_error.h
@@ -229,6 +229,18 @@
     /**Invalid Constrained Intra prediction mode */
     IH264E_INVALID_CONSTRAINED_INTRA_PREDICTION_MODE                = IH264E_CODEC_ERROR_START + 0x32,
 
+    /**Invalid mastering display color volume sei params */
+    IH264E_INVALID_SEI_MDCV_PARAMS                                  = IH264E_CODEC_ERROR_START + 0x33,
+
+    /**Invalid content light level sei params */
+    IH264E_INVALID_SEI_CLL_PARAMS                                   = IH264E_CODEC_ERROR_START + 0x34,
+
+    /**Invalid ambient viewing environment sei params */
+    IH264E_INVALID_SEI_AVE_PARAMS                                   = IH264E_CODEC_ERROR_START + 0x35,
+
+    /**Invalid content color volume sei params */
+    IH264E_INVALID_SEI_CCV_PARAMS                                   = IH264E_CODEC_ERROR_START + 0x36,
+
     /**max failure error code to ensure enum is 32 bits wide */
     IH264E_FAIL                                                     = -1,
 
diff --git a/encoder/ih264e_process.c b/encoder/ih264e_process.c
index 5425938..289053f 100644
--- a/encoder/ih264e_process.c
+++ b/encoder/ih264e_process.c
@@ -181,11 +181,14 @@
     ps_entropy->i4_error_code = IH264E_SUCCESS;
 
     /* generate sps */
-    ps_entropy->i4_error_code |= ih264e_generate_sps(ps_bitstrm, ps_sps,
+    ps_entropy->i4_error_code = ih264e_generate_sps(ps_bitstrm, ps_sps,
                                                      &ps_codec->s_cfg.s_vui);
-
+    if(ps_entropy->i4_error_code != IH264E_SUCCESS)
+    {
+        return ps_entropy->i4_error_code;
+    }
     /* generate pps */
-    ps_entropy->i4_error_code |= ih264e_generate_pps(ps_bitstrm, ps_pps, ps_sps);
+    ps_entropy->i4_error_code = ih264e_generate_pps(ps_bitstrm, ps_pps, ps_sps);
 
     /* queue output buffer */
     ps_out_buf->s_bits_buf.u4_bytes = ps_bitstrm->u4_strm_buf_offset;
@@ -302,6 +305,9 @@
     /* output buff */
     out_buf_t s_out_buf;
 
+    /* sei params */
+    sei_params_t s_sei;
+
     /* proc map */
     UWORD8  *pu1_proc_map;
 
@@ -313,7 +319,7 @@
 
     /* temp var */
     WORD32 i4_wd_mbs, i4_ht_mbs;
-    UWORD32 u4_mb_cnt, u4_mb_idx, u4_mb_end_idx;
+    UWORD32 u4_mb_cnt, u4_mb_idx, u4_mb_end_idx, u4_insert_per_idr;
     WORD32 bitstream_start_offset, bitstream_end_offset;
     /********************************************************************/
     /*                            BEGIN INIT                            */
@@ -372,10 +378,12 @@
         if (1 == ps_entropy->i4_gen_header)
         {
             /* generate sps */
-            ps_entropy->i4_error_code |= ih264e_generate_sps(ps_bitstrm, ps_sps,
+            ps_entropy->i4_error_code = ih264e_generate_sps(ps_bitstrm, ps_sps,
                                                              &ps_codec->s_cfg.s_vui);
+            RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
             /* generate pps */
-            ps_entropy->i4_error_code |= ih264e_generate_pps(ps_bitstrm, ps_pps, ps_sps);
+            ps_entropy->i4_error_code = ih264e_generate_pps(ps_bitstrm, ps_pps, ps_sps);
+            RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
 
             /* reset i4_gen_header */
             ps_entropy->i4_gen_header = 0;
@@ -384,10 +392,51 @@
         /* populate slice header */
         ih264e_populate_slice_header(ps_proc, ps_slice_hdr, ps_pps, ps_sps);
 
-        /* generate slice header */
-        ps_entropy->i4_error_code |= ih264e_generate_slice_header(ps_bitstrm, ps_slice_hdr,
-                                                                  ps_pps, ps_sps);
+        /* generate sei */
+        u4_insert_per_idr = (NAL_SLICE_IDR == ps_slice_hdr->i1_nal_unit_type);
 
+        memset(&s_sei, 0, sizeof(sei_params_t));
+        s_sei.u1_sei_mdcv_params_present_flag =
+                    ps_codec->s_cfg.s_sei.u1_sei_mdcv_params_present_flag;
+        s_sei.s_sei_mdcv_params = ps_codec->s_cfg.s_sei.s_sei_mdcv_params;
+        s_sei.u1_sei_cll_params_present_flag =
+                    ps_codec->s_cfg.s_sei.u1_sei_cll_params_present_flag;
+        s_sei.s_sei_cll_params = ps_codec->s_cfg.s_sei.s_sei_cll_params;
+        s_sei.u1_sei_ave_params_present_flag =
+                    ps_codec->s_cfg.s_sei.u1_sei_ave_params_present_flag;
+        s_sei.s_sei_ave_params = ps_codec->s_cfg.s_sei.s_sei_ave_params;
+        s_sei.u1_sei_ccv_params_present_flag = 0;
+        s_sei.s_sei_ccv_params =
+                    ps_codec->as_inp_list[ps_codec->i4_poc % MAX_NUM_BFRAMES].s_sei_ccv;
+
+        if((1 == ps_sps->i1_vui_parameters_present_flag) &&
+           (1 == ps_codec->s_cfg.s_vui.u1_video_signal_type_present_flag) &&
+           (1 == ps_codec->s_cfg.s_vui.u1_colour_description_present_flag) &&
+           (2 != ps_codec->s_cfg.s_vui.u1_colour_primaries) &&
+           (2 != ps_codec->s_cfg.s_vui.u1_matrix_coefficients) &&
+           (2 != ps_codec->s_cfg.s_vui.u1_transfer_characteristics) &&
+           (4 != ps_codec->s_cfg.s_vui.u1_transfer_characteristics) &&
+           (5 != ps_codec->s_cfg.s_vui.u1_transfer_characteristics))
+        {
+            s_sei.u1_sei_ccv_params_present_flag =
+            ps_codec->as_inp_list[ps_codec->i4_poc % MAX_NUM_BFRAMES].u1_sei_ccv_params_present_flag;
+        }
+
+        if((1 == s_sei.u1_sei_mdcv_params_present_flag && u4_insert_per_idr) ||
+           (1 == s_sei.u1_sei_cll_params_present_flag && u4_insert_per_idr) ||
+           (1 == s_sei.u1_sei_ave_params_present_flag && u4_insert_per_idr) ||
+           (1 == s_sei.u1_sei_ccv_params_present_flag))
+        {
+            ps_entropy->i4_error_code =
+                    ih264e_generate_sei(ps_bitstrm, &s_sei, u4_insert_per_idr);
+            RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
+        }
+        ps_codec->as_inp_list[ps_codec->i4_poc % MAX_NUM_BFRAMES].u1_sei_ccv_params_present_flag = 0;
+
+        /* generate slice header */
+        ps_entropy->i4_error_code = ih264e_generate_slice_header(ps_bitstrm, ps_slice_hdr,
+                                                                  ps_pps, ps_sps);
+        RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
         /* once start of frame / slice is done, you can reset it */
         /* it is the responsibility of the caller to set this flag */
         ps_entropy->i4_sof = 0;
@@ -445,7 +494,10 @@
 
 
         /* write mb layer */
-        ps_entropy->i4_error_code |= ps_codec->pf_write_mb_syntax_layer[ps_entropy->u1_entropy_coding_mode_flag][i4_slice_type](ps_entropy);
+        ps_entropy->i4_error_code = ps_codec->pf_write_mb_syntax_layer
+                        [ps_entropy->u1_entropy_coding_mode_flag][i4_slice_type](ps_entropy);
+        RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
+
         /* Starting bitstream offset for header in bits */
         bitstream_start_offset = GET_NUM_BITS(ps_bitstrm);
 
@@ -487,12 +539,15 @@
                         {
                             if (*ps_entropy->pi4_mb_skip_run)
                             {
-                            PUT_BITS_UEV(ps_bitstrm, *ps_entropy->pi4_mb_skip_run, ps_entropy->i4_error_code, "mb skip run");
+                                PUT_BITS_UEV(ps_bitstrm, *ps_entropy->pi4_mb_skip_run,
+                                            ps_entropy->i4_error_code, "mb skip run");
                                 *ps_entropy->pi4_mb_skip_run = 0;
+                                RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
                             }
                         }
                         /* put rbsp trailing bits for the previous slice */
-                                 ps_entropy->i4_error_code |= ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+                        ps_entropy->i4_error_code = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+                        RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
                     }
                     else
                     {
@@ -510,8 +565,9 @@
                                                  ps_sps);
 
                     /* generate slice header */
-                    ps_entropy->i4_error_code |= ih264e_generate_slice_header(
+                    ps_entropy->i4_error_code = ih264e_generate_slice_header(
                                     ps_bitstrm, ps_slice_hdr, ps_pps, ps_sps);
+                    RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
                     if (CABAC == ps_entropy->u1_entropy_coding_mode_flag)
                     {
                         BITSTREAM_BYTE_ALIGN(ps_bitstrm);
@@ -528,8 +584,6 @@
                     }
                 }
             }
-            /* Dont execute any further instructions until store synchronization took place */
-            DATA_SYNC();
         }
 
         /* Ending bitstream offset for header in bits */
@@ -566,10 +620,12 @@
                     PUT_BITS_UEV(ps_bitstrm, *ps_entropy->pi4_mb_skip_run,
                                  ps_entropy->i4_error_code, "mb skip run");
                     *ps_entropy->pi4_mb_skip_run = 0;
+                    RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
                 }
             }
             /* put rbsp trailing bits */
-             ps_entropy->i4_error_code |= ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+             ps_entropy->i4_error_code = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+             RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
         }
         else
         {
@@ -589,12 +645,13 @@
             /* cbr rc - house keeping */
             if (ps_codec->s_rate_control.post_encode_skip[ctxt_sel])
             {
-                ps_entropy->ps_bitstrm->u4_strm_buf_offset = 0;
+                 ps_entropy->ps_bitstrm->u4_strm_buf_offset = 0;
             }
             else if (i4_stuff_bytes)
             {
                 /* add filler nal units */
-                ps_entropy->i4_error_code |= ih264e_add_filler_nal_unit(ps_bitstrm, i4_stuff_bytes);
+                 ps_entropy->i4_error_code = ih264e_add_filler_nal_unit(ps_bitstrm, i4_stuff_bytes);
+                 RETURN_ENTROPY_IF_ERROR(ps_codec, ps_entropy, ctxt_sel);
             }
         }
 
@@ -617,6 +674,9 @@
         DEBUG("entropy status %x", ps_entropy->i4_error_code);
     }
 
+    /* Dont execute any further instructions until store synchronization took place */
+    DATA_SYNC();
+
     /* allow threads to dequeue entropy jobs */
     ps_codec->au4_entropy_thread_active[ctxt_sel] = 0;
 
@@ -1048,8 +1108,11 @@
         s_job.i2_proc_base_idx = (ps_codec->i4_encode_api_call_cnt % MAX_CTXT_SETS) ? (MAX_PROCESS_CTXT / 2) : 0;
 
         /* queue the job */
-        error_status |= ih264_list_queue(ps_proc->pv_entropy_jobq, &s_job, 1);
-
+        error_status = ih264_list_queue(ps_proc->pv_entropy_jobq, &s_job, 1);
+        if(error_status != IH264_SUCCESS)
+        {
+            return error_status;
+        }
         if(ps_proc->i4_mb_y == (i4_ht_mbs - 1))
             ih264_list_terminate(ps_codec->pv_entropy_jobq);
     }
@@ -2249,8 +2312,11 @@
         }
 
         /* update the context after for coding next mb */
-        error_status |= ih264e_update_proc_ctxt(ps_proc);
-
+        error_status = ih264e_update_proc_ctxt(ps_proc);
+        if(error_status != IH264E_SUCCESS)
+        {
+            return error_status;
+        }
         /* Once the last row is processed, mark the buffer status appropriately */
         if (ps_proc->i4_ht_mbs == ps_proc->i4_mb_y)
         {
@@ -2273,10 +2339,18 @@
             /* hence the slice map should be of no significance to perform debloc */
             /* king                                                               */
             /**********************************************************************/
-            error_status |= ih264_buf_mgr_release(ps_codec->pv_mv_buf_mgr, ps_cur_mv_buf->i4_buf_id , BUF_MGR_CODEC);
-
-            error_status |= ih264_buf_mgr_release(ps_codec->pv_ref_buf_mgr, ps_cur_pic->i4_buf_id , BUF_MGR_CODEC);
-
+            error_status = ih264_buf_mgr_release(ps_codec->pv_mv_buf_mgr,
+                                                ps_cur_mv_buf->i4_buf_id , BUF_MGR_CODEC);
+            if(error_status != IH264E_SUCCESS)
+            {
+                return error_status;
+            }
+            error_status = ih264_buf_mgr_release(ps_codec->pv_ref_buf_mgr,
+                                                ps_cur_pic->i4_buf_id , BUF_MGR_CODEC);
+            if(error_status != IH264E_SUCCESS)
+            {
+                return error_status;
+            }
             if (ps_codec->s_cfg.u4_enable_recon)
             {
                 /* pic cnt */
@@ -2459,6 +2533,7 @@
     /* set affinity */
     ithread_set_affinity(ps_proc->i4_id);
 
+    ps_proc->i4_error_code = IH264_SUCCESS;
     while(1)
     {
         /* dequeue a job from the entropy queue */
@@ -2521,7 +2596,12 @@
                 ih264e_init_proc_ctxt(ps_proc);
 
                 /* core code all mbs enlisted under the current job */
-                error_status |= ih264e_process(ps_proc);
+                error_status = ih264e_process(ps_proc);
+                if(error_status !=IH264_SUCCESS)
+                {
+                    ps_proc->i4_error_code = error_status;
+                    return ret;
+                }
                 break;
 
             case CMD_ENTROPY:
@@ -2533,16 +2613,19 @@
                 ih264e_init_entropy_ctxt(ps_proc);
 
                 /* entropy code all mbs enlisted under the current job */
-                error_status |= ih264e_entropy(ps_proc);
+                error_status = ih264e_entropy(ps_proc);
+                if(error_status !=IH264_SUCCESS)
+                {
+                    ps_proc->i4_error_code = error_status;
+                    return ret;
+                }
                 break;
 
             default:
-                error_status |= IH264_FAIL;
-                break;
+                ps_proc->i4_error_code = IH264_FAIL;
+                return ret;
         }
     }
 
-    /* send error code */
-    ps_proc->i4_error_code = error_status;
     return ret;
 }
diff --git a/encoder/ih264e_sei.c b/encoder/ih264e_sei.c
new file mode 100644
index 0000000..bffdeb2
--- /dev/null
+++ b/encoder/ih264e_sei.c
@@ -0,0 +1,447 @@
+/******************************************************************************
+ *
+ * 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
+*  ih264e_sei.c
+*
+* @brief
+*  This file contains function definitions related to SEI NAL's header encoding
+*
+* @author
+*  ittiam
+*
+* @par List of Functions:
+*  - ih264e_put_sei_mdcv_params
+*  - ih264e_put_sei_cll_params
+*  - ih264e_put_sei_ave_params
+*  - ih264e_put_sei_ccv_params
+*  - ih264e_put_sei_msg
+*
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+
+/*****************************************************************************/
+/* File Includes                                                             */
+/*****************************************************************************/
+
+/* System include files */
+#include <stdio.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+/* User include files */
+#include "ih264_typedefs.h"
+#include "iv2.h"
+#include "ive2.h"
+#include "ih264_macros.h"
+#include "ih264_platform_macros.h"
+#include "ih264e_trace.h"
+#include "ih264e_error.h"
+#include "ih264e_bitstream.h"
+#include "ih264_defs.h"
+#include "ih264_structs.h"
+#include "ih264_cabac_tables.h"
+#include "ih264e_cabac_structs.h"
+#include "irc_cntrl_param.h"
+#include "ime_distortion_metrics.h"
+#include "ime_defs.h"
+#include "ime_structs.h"
+#include "ih264e_defs.h"
+#include "irc_cntrl_param.h"
+#include "irc_frame_info_collector.h"
+#include "ih264_trans_quant_itrans_iquant.h"
+#include "ih264_inter_pred_filters.h"
+#include "ih264_deblk_edge_filters.h"
+#include "ih264e_structs.h"
+#include "ih264e_encode_header.h"
+#include "ih264e_sei.h"
+
+/*****************************************************************************/
+/* Function Definitions                                                      */
+/*****************************************************************************/
+
+/**
+******************************************************************************
+*
+*  @brief Generates Mastering Display Color Volume (Supplemental Enhancement Information )
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @param[in]   ps_sei_mdcv
+*  pointer to structure containing mdcv SEI data
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_mdcv_params(sei_mdcv_params_t *ps_sei_mdcv,
+                                 bitstrm_t *ps_bitstrm)
+{
+    WORD32 return_status = IH264E_SUCCESS;
+    UWORD8 u1_payload_size = 0;
+    UWORD32 u4_count;
+
+    if(ps_sei_mdcv == NULL)
+    {
+        return IH264E_FAIL;
+    }
+
+    u1_payload_size += (NUM_SEI_MDCV_PRIMARIES * 2); /* display primaries x */
+    u1_payload_size += (NUM_SEI_MDCV_PRIMARIES * 2); /* display primaries y */
+    u1_payload_size += 2; /* white point x */
+    u1_payload_size += 2; /* white point y */
+    u1_payload_size += 4; /* max display mastering luminance */
+    u1_payload_size += 4; /* min display mastering luminance */
+
+    /************************************************************************/
+    /* PayloadSize : This is the size of the payload in bytes               */
+    /************************************************************************/
+    PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status, "u1_payload_size");
+
+    /*******************************************************************************/
+    /* Put the mastering display color volume SEI parameters into the bitstream.   */
+    /*******************************************************************************/
+
+    /* display primaries x */
+    for(u4_count = 0; u4_count < NUM_SEI_MDCV_PRIMARIES; u4_count++)
+    {
+        PUT_BITS(ps_bitstrm, ps_sei_mdcv->au2_display_primaries_x[u4_count], 16,
+                                return_status, "u2_display_primaries_x");
+
+        PUT_BITS(ps_bitstrm, ps_sei_mdcv->au2_display_primaries_y[u4_count], 16,
+                                return_status, "u2_display_primaries_y");
+    }
+
+    /* white point x */
+    PUT_BITS(ps_bitstrm, ps_sei_mdcv->u2_white_point_x, 16, return_status, "u2_white point x");
+
+    /* white point y */
+    PUT_BITS(ps_bitstrm, ps_sei_mdcv->u2_white_point_y, 16, return_status, "u2_white point y");
+
+    /* max display mastering luminance */
+    PUT_BITS(ps_bitstrm, ps_sei_mdcv->u4_max_display_mastering_luminance, 32,
+                                return_status, "u4_max_display_mastering_luminance");
+
+    /* min display mastering luminance */
+    PUT_BITS(ps_bitstrm, ps_sei_mdcv->u4_min_display_mastering_luminance, 32,
+                                return_status, "u4_max_display_mastering_luminance");
+
+    return (return_status);
+}
+
+/**
+******************************************************************************
+*
+*  @brief Stores content light level info in bitstream
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @param[in]   ps_sei_cll
+*  Pinter to structure containing cll sei params
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_cll_params(sei_cll_params_t *ps_sei_cll,
+                                bitstrm_t *ps_bitstrm)
+{
+    WORD32 return_status = IH264E_SUCCESS;
+    UWORD8 u1_payload_size = 0;
+
+    if(ps_sei_cll == NULL)
+    {
+        return IH264E_FAIL;
+    }
+
+    u1_payload_size += 2; /* max pic average light level */
+    u1_payload_size += 2; /* max content light level */
+
+    /************************************************************************/
+    /* PayloadSize : This is the size of the payload in bytes               */
+    /************************************************************************/
+    PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status, "u1_payload_size");
+
+    PUT_BITS(ps_bitstrm, ps_sei_cll->u2_max_content_light_level, 16,
+                                return_status, "u2_max_content_light_level");
+    PUT_BITS(ps_bitstrm, ps_sei_cll->u2_max_pic_average_light_level, 16,
+                                return_status, "u2_max_pic_average_light_level");
+
+    return (return_status);
+}
+
+/**
+******************************************************************************
+*
+*  @brief Stores ambient viewing environment info in bitstream
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @param[in]   ps_sei_ave
+*  pointer to ambient viewing environment info
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_ave_params(sei_ave_params_t *ps_sei_ave,
+                                bitstrm_t *ps_bitstrm)
+{
+    WORD32 return_status = IH264E_SUCCESS;
+    UWORD8 u1_payload_size = 0;
+
+    if(ps_sei_ave == NULL)
+    {
+        return IH264E_FAIL;
+    }
+
+    u1_payload_size += 4; /* ambient illuminance */
+    u1_payload_size += 2; /* ambient light x */
+    u1_payload_size += 2; /* ambient light y */
+
+    /************************************************************************/
+    /* PayloadSize : This is the size of the payload in bytes               */
+    /************************************************************************/
+    PUT_BITS(ps_bitstrm, u1_payload_size, 8, return_status, "u1_payload_size");
+
+    PUT_BITS(ps_bitstrm, ps_sei_ave->u4_ambient_illuminance, 32,
+                                return_status, "u4_ambient_illuminance");
+    PUT_BITS(ps_bitstrm, ps_sei_ave->u2_ambient_light_x, 16,
+                                return_status, "u2_ambient_light_x");
+    PUT_BITS(ps_bitstrm, ps_sei_ave->u2_ambient_light_y, 16,
+                                return_status, "u2_ambient_light_y");
+
+    return (return_status);
+}
+
+/**
+******************************************************************************
+*
+*  @brief Generates Content Color Volume info (Supplemental Enhancement Information )
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @param[in]   ps_sei_ccv
+*  pointer to structure containing CCV SEI data
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_ccv_params(sei_ccv_params_t *ps_sei_ccv,
+                                bitstrm_t *ps_bitstrm)
+{
+    WORD32 return_status = IH264E_SUCCESS;
+    UWORD16 u2_payload_bits = 0;
+    UWORD8  u1_payload_bytes = 0;
+    UWORD32 u4_count;
+
+    if(ps_sei_ccv == NULL)
+    {
+        return IH264E_FAIL;
+    }
+
+    u2_payload_bits += 1;   /* ccv cancel flag */
+    if(0 == (UWORD32)ps_sei_ccv->u1_ccv_cancel_flag)
+    {
+        u2_payload_bits += 1;   /* ccv persistence flag */
+        u2_payload_bits += 1;   /* ccv primaries present flag */
+        u2_payload_bits += 1;   /* ccv min luminance value present flag */
+        u2_payload_bits += 1;   /* ccv max luminance value present flag */
+        u2_payload_bits += 1;   /* ccv avg luminance value present flag */
+        u2_payload_bits += 2;   /* ccv reserved zero 2bits */
+        if(1 == ps_sei_ccv->u1_ccv_primaries_present_flag)
+        {
+            u2_payload_bits += (NUM_SEI_CCV_PRIMARIES * 32);  /* ccv primaries x[ c ] */
+            u2_payload_bits += (NUM_SEI_CCV_PRIMARIES * 32);  /* ccv primaries y[ c ] */
+        }
+        if(1 == ps_sei_ccv->u1_ccv_min_luminance_value_present_flag)
+        {
+            u2_payload_bits += 32;  /* ccv min luminance value */
+        }
+        if(1 == ps_sei_ccv->u1_ccv_max_luminance_value_present_flag)
+        {
+            u2_payload_bits += 32;  /* ccv max luminance value */
+        }
+        if(1 == ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag)
+        {
+            u2_payload_bits += 32;  /* ccv avg luminance value */
+        }
+    }
+
+    u1_payload_bytes = (UWORD8)((u2_payload_bits + 7) >> 3);
+    /************************************************************************/
+    /* PayloadSize : This is the size of the payload in bytes               */
+    /************************************************************************/
+    PUT_BITS(ps_bitstrm, u1_payload_bytes, 8, return_status, "u1_payload_bytes");
+
+    /*******************************************************************************/
+    /* Put the Content Color Volume SEI parameters into the bitstream.  */
+    /*******************************************************************************/
+
+    PUT_BITS(ps_bitstrm, ps_sei_ccv->u1_ccv_cancel_flag, 1,
+                            return_status, "u1_ccv_cancel_flag");
+
+    if(0 == ps_sei_ccv->u1_ccv_cancel_flag)
+    {
+        PUT_BITS(ps_bitstrm, ps_sei_ccv->u1_ccv_persistence_flag, 1,
+                                return_status, "u1_ccv_persistence_flag");
+        PUT_BITS(ps_bitstrm, ps_sei_ccv->u1_ccv_primaries_present_flag, 1,
+                                return_status, "u1_ccv_primaries_present_flag");
+        PUT_BITS(ps_bitstrm, ps_sei_ccv->u1_ccv_min_luminance_value_present_flag, 1,
+                                return_status, "u1_ccv_min_luminance_value_present_flag");
+        PUT_BITS(ps_bitstrm, ps_sei_ccv->u1_ccv_max_luminance_value_present_flag, 1,
+                                return_status, "u1_ccv_max_luminance_value_present_flag");
+        PUT_BITS(ps_bitstrm, ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag, 1,
+                                return_status, "u1_ccv_avg_luminance_value_present_flag");
+        PUT_BITS(ps_bitstrm, ps_sei_ccv->u1_ccv_reserved_zero_2bits, 2,
+                                return_status, "u1_ccv_reserved_zero_2bits");
+
+        /* ccv primaries */
+        if(1 == ps_sei_ccv->u1_ccv_primaries_present_flag)
+        {
+            for(u4_count = 0; u4_count < NUM_SEI_CCV_PRIMARIES; u4_count++)
+            {
+                PUT_BITS(ps_bitstrm, ps_sei_ccv->ai4_ccv_primaries_x[u4_count], 32,
+                                return_status, "i4_ccv_primaries_x");
+                PUT_BITS(ps_bitstrm, ps_sei_ccv->ai4_ccv_primaries_y[u4_count], 32,
+                                return_status, "i4_ccv_primaries_y");
+            }
+        }
+
+        if(1 == ps_sei_ccv->u1_ccv_min_luminance_value_present_flag)
+        {
+            PUT_BITS(ps_bitstrm, ps_sei_ccv->u4_ccv_min_luminance_value, 32,
+                                return_status, "u4_ccv_min_luminance_value");
+        }
+        if(1 == ps_sei_ccv->u1_ccv_max_luminance_value_present_flag)
+        {
+            PUT_BITS(ps_bitstrm, ps_sei_ccv->u4_ccv_max_luminance_value, 32,
+                                return_status, "u4_ccv_max_luminance_value");
+        }
+        if(1 == ps_sei_ccv->u1_ccv_avg_luminance_value_present_flag)
+        {
+            PUT_BITS(ps_bitstrm, ps_sei_ccv->u4_ccv_avg_luminance_value, 32,
+                                return_status, "u4_ccv_avg_luminance_value");
+        }
+    }
+
+    return (return_status);
+}
+
+/**
+******************************************************************************
+*
+*  @brief Generates SEI (Supplemental Enhancement Information )
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   e_payload_type
+*  Determines the type of SEI msg
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @param[in]   ps_sei_params
+*  pointer to structure containing SEI data
+*               buffer period, recovery point, picture timing
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_msg(IH264_SEI_TYPE e_payload_type,
+                         sei_params_t *ps_sei_params,
+                         bitstrm_t *ps_bitstrm)
+{
+    WORD32 return_status = IH264E_SUCCESS;
+
+    /************************************************************************/
+    /* PayloadType : Send in the SEI type in the stream                     */
+    /************************************************************************/
+
+    UWORD32 u4_payload_type = e_payload_type;
+
+    while(u4_payload_type > 0xFF)
+    {
+        PUT_BITS(ps_bitstrm, 0xFF, 8, return_status, "payload");
+        u4_payload_type -= 0xFF;
+    }
+
+    PUT_BITS(ps_bitstrm, (UWORD32)u4_payload_type, 8, return_status, "e_payload_type");
+
+    switch(e_payload_type)
+    {
+    case IH264_SEI_MASTERING_DISP_COL_VOL :
+        return_status = ih264e_put_sei_mdcv_params(&(ps_sei_params->s_sei_mdcv_params),
+                                                    ps_bitstrm);
+        break;
+
+    case IH264_SEI_CONTENT_LIGHT_LEVEL_DATA :
+        return_status = ih264e_put_sei_cll_params(&(ps_sei_params->s_sei_cll_params),
+                                                    ps_bitstrm);
+        break;
+
+    case IH264_SEI_AMBIENT_VIEWING_ENVIRONMENT :
+        return_status = ih264e_put_sei_ave_params(&(ps_sei_params->s_sei_ave_params),
+                                                    ps_bitstrm);
+        break;
+
+    case IH264_SEI_CONTENT_COLOR_VOLUME :
+         return_status = ih264e_put_sei_ccv_params(&(ps_sei_params->s_sei_ccv_params),
+                                                    ps_bitstrm);
+         break;
+
+    default :
+        return_status = IH264E_FAIL;
+    }
+
+    /* rbsp trailing bits */
+    if((IH264E_SUCCESS == return_status) && (ps_bitstrm->i4_bits_left_in_cw & 0x7))
+        return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
+
+    return(return_status);
+}
+
+
diff --git a/encoder/ih264e_sei.h b/encoder/ih264e_sei.h
new file mode 100644
index 0000000..a5b1d9d
--- /dev/null
+++ b/encoder/ih264e_sei.h
@@ -0,0 +1,170 @@
+/******************************************************************************
+ *
+ * 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
+*  ih264e_sei.h
+*
+* @brief
+*  This file contains function declarations for sei message encoding
+*
+* @author
+*
+*
+* @remarks
+*  None
+*
+*******************************************************************************
+*/
+
+#ifndef ENCODER_IH264E_SEI_H_
+#define ENCODER_IH264E_SEI_H_
+
+
+/*****************************************************************************/
+/* INTERFACE STRUCTURE DEFINITIONS                                           */
+/*****************************************************************************/
+typedef enum
+{
+    /* SEI PREFIX */
+
+    IH264_SEI_MASTERING_DISP_COL_VOL       = 137,
+    IH264_SEI_CONTENT_LIGHT_LEVEL_DATA     = 144,
+    IH264_SEI_AMBIENT_VIEWING_ENVIRONMENT  = 148,
+    IH264_SEI_CONTENT_COLOR_VOLUME         = 149
+
+}IH264_SEI_TYPE;
+
+/*****************************************************************************/
+/* Function Declarations                                              */
+/*****************************************************************************/
+
+/**
+******************************************************************************
+*
+*  @brief Generates Mastering Display Color Volume (Supplemental Enhancement Information )
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   ps_sei_mdcl
+*  pointer to structure containing mdcv SEI data
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_mdcv_params(sei_mdcv_params_t *ps_sei_mdcv,
+                                 bitstrm_t *ps_bitstrm);
+
+/**
+******************************************************************************
+*
+*  @brief Stores content light level info in bitstream
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   ps_sei_cll
+*  pointer to structure containing cll sei data
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_cll_params(sei_cll_params_t *ps_sei_cll,
+                                bitstrm_t *ps_bitstrm);
+
+/**
+******************************************************************************
+*
+*  @brief Stores ambient viewing environment info in bitstream
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @param[in]   ps_sei_ave
+*  pointer to ambient viewing environment info
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_ave_params(sei_ave_params_t *ps_sei_ave,
+                                bitstrm_t *ps_bitstrm);
+
+/**
+******************************************************************************
+*
+*  @brief Generates Content Color Volume info (Supplemental Enhancement Information )
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @param[in]   ps_sei_ccv
+*  pointer to structure containing ccv SEI data
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_ccv_params(sei_ccv_params_t *ps_sei_ccv,
+                                bitstrm_t *ps_bitstrm);
+
+/**
+******************************************************************************
+*
+*  @brief Generates SEI (Supplemental Enhancement Information )
+*
+*  @par   Description
+*  Parse Supplemental Enhancement Information
+*
+*  @param[in]   e_payload_type
+*  Determines the type of SEI msg
+*
+*  @param[in]   ps_bitstrm
+*  pointer to bitstream context (handle)
+*
+*  @param[in]   ps_sei
+*  pointer to structure containing SEI data
+*
+*  @return      success or failure error code
+*
+******************************************************************************
+*/
+IH264E_ERROR_T ih264e_put_sei_msg(IH264_SEI_TYPE e_payload_type,
+                         sei_params_t *ps_sei_params,
+                         bitstrm_t *ps_bitstrm);
+
+
+#endif /* ENCODER_IH264E_SEI_H_ */
diff --git a/encoder/ih264e_structs.h b/encoder/ih264e_structs.h
index c2e3b89..8674470 100644
--- a/encoder/ih264e_structs.h
+++ b/encoder/ih264e_structs.h
@@ -306,6 +306,12 @@
     /** Buffer containing pic info if mb_info_type is non-zero           */
     void                                    *pv_pic_info;
 
+    /** SEI CCV params flag                                              */
+    UWORD8                                  u1_sei_ccv_params_present_flag;
+
+    /** SEI CCV params info                                              */
+    sei_ccv_params_t                        s_sei_ccv;
+
 }inp_buf_t;
 
 typedef struct
@@ -566,6 +572,9 @@
     /** VUI structure                                                         */
     vui_t                                       s_vui;
 
+    /** SEI structure                                                         */
+    sei_params_t                                s_sei;
+
 }cfg_params_t;
 
 
@@ -2768,13 +2777,13 @@
     pf_sixtap_filter_2dvh_vert pf_ih264e_sixtap_filter_2dvh_vert;
 
     /**
-     * color space conversion form YUV 420P to YUV 420Sp
+     * color space conversion from YUV 420P to YUV 420Sp
      */
     pf_fmt_conv_420p_to_420sp pf_ih264e_conv_420p_to_420sp;
 
 
     /**
-     * color space conversion form YUV 420P to YUV 420Sp
+     * color space conversion from YUV 420P to YUV 420Sp
      */
     pf_fmt_conv_422ile_to_420sp pf_ih264e_fmt_conv_422i_to_420sp;
 
@@ -2808,11 +2817,16 @@
      */
     WORD32 i4_pending_idr_flag;
 
-    /*
+    /**
     *Flag to indicate if we have recived the last input frame
     */
     WORD32 i4_last_inp_buff_received;
 
+    /**
+     * backup sei params for comparison
+     */
+    sei_params_t s_sei;
+
 };
 
 #endif /* IH264E_STRUCTS_H_ */
diff --git a/encoder/ih264e_utils.c b/encoder/ih264e_utils.c
index c813f57..2196a64 100644
--- a/encoder/ih264e_utils.c
+++ b/encoder/ih264e_utils.c
@@ -247,6 +247,10 @@
     ps_inp_buf->pv_pic_info = ps_ive_ip->pv_pic_info;
     ps_inp_buf->u4_pic_info_type = ps_ive_ip->u4_pic_info_type;
 
+    ps_inp_buf->u1_sei_ccv_params_present_flag =
+                ps_codec->s_cfg.s_sei.u1_sei_ccv_params_present_flag;
+    ps_inp_buf->s_sei_ccv = ps_codec->s_cfg.s_sei.s_sei_ccv_params;
+
     /***************************************************************************
      * Now we should add the picture to RC stack here
      **************************************************************************/
@@ -354,6 +358,9 @@
     ps_enc_buff->pv_pic_info = ps_inp_buf->pv_pic_info;
     ps_enc_buff->u4_pic_info_type = ps_inp_buf->u4_pic_info_type;
 
+    ps_enc_buff->u1_sei_ccv_params_present_flag = ps_inp_buf->u1_sei_ccv_params_present_flag;
+    ps_enc_buff->s_sei_ccv = ps_inp_buf->s_sei_ccv;
+
     /* Special case for encoding trailing B frames
      *
      * In encoding streams with B frames it may happen that we have a B frame
diff --git a/encoder/ih264e_version.c b/encoder/ih264e_version.c
index e66e1ad..a8b0db0 100644
--- a/encoder/ih264e_version.c
+++ b/encoder/ih264e_version.c
@@ -85,7 +85,7 @@
 * Concatenates various strings to form a version string
 *******************************************************************************
 */
-#ifdef __ANDROID__
+#ifdef ANDROID
 #define VERSION(version_string, codec_name, codec_release_type, codec_release_ver, codec_vendor)    \
     snprintf(version_string, MAX_STRLEN,                                                            \
              "@(#)Id:%s_%s Ver:%s Released by %s",                                                  \
diff --git a/encoder/ive2.h b/encoder/ive2.h
index b2c00d5..f3f1bd9 100644
--- a/encoder/ive2.h
+++ b/encoder/ive2.h
@@ -145,6 +145,10 @@
     IVE_CMD_CTL_FLUSH                       = 0xB0,
     IVE_CMD_CTL_GETBUFINFO                  = 0xC0,
     IVE_CMD_CTL_GETVERSION                  = 0xC1,
+    IVE_CMD_CTL_SET_SEI_MDCV_PARAMS         = 0xD0,
+    IVE_CMD_CTL_SET_SEI_CLL_PARAMS          = 0xD1,
+    IVE_CMD_CTL_SET_SEI_AVE_PARAMS          = 0xD2,
+    IVE_CMD_CTL_SET_SEI_CCV_PARAMS          = 0xD3,
     IVE_CMD_CTL_CODEC_SUBCMD_START          = 0x100,
 }IVE_CONTROL_API_COMMAND_TYPE_T;
 
@@ -238,6 +242,14 @@
     IVE_ERR_OP_CTL_SETPROFILE_API_STRUCT_SIZE_INCORRECT         = 0x3F,
     IVE_ERR_IP_CTL_SET_VUI_STRUCT_SIZE_INCORRECT                = 0x40,
     IVE_ERR_OP_CTL_SET_VUI_STRUCT_SIZE_INCORRECT                = 0x41,
+    IVE_ERR_IP_CTL_SET_SEI_MDCV_STRUCT_SIZE_INCORRECT           = 0x42,
+    IVE_ERR_OP_CTL_SET_SEI_MDCV_STRUCT_SIZE_INCORRECT           = 0x43,
+    IVE_ERR_IP_CTL_SET_SEI_CLL_STRUCT_SIZE_INCORRECT            = 0x44,
+    IVE_ERR_OP_CTL_SET_SEI_CLL_STRUCT_SIZE_INCORRECT            = 0x45,
+    IVE_ERR_IP_CTL_SET_SEI_AVE_STRUCT_SIZE_INCORRECT            = 0x46,
+    IVE_ERR_OP_CTL_SET_SEI_AVE_STRUCT_SIZE_INCORRECT            = 0x47,
+    IVE_ERR_IP_CTL_SET_SEI_CCV_STRUCT_SIZE_INCORRECT            = 0x48,
+    IVE_ERR_OP_CTL_SET_SEI_CCV_STRUCT_SIZE_INCORRECT            = 0x49,
 }IVE_ERROR_CODES_T;
 
 
diff --git a/fuzzer/Android.bp b/fuzzer/Android.bp
new file mode 100644
index 0000000..8540107
--- /dev/null
+++ b/fuzzer/Android.bp
@@ -0,0 +1,16 @@
+cc_fuzz {
+    name: "avc_dec_fuzzer",
+    host_supported: true,
+    srcs: [
+        "avc_dec_fuzzer.cpp",
+    ],
+    static_libs: [
+        "libavcdec",
+        "liblog",
+    ],
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
+}
diff --git a/fuzzer/README.md b/fuzzer/README.md
new file mode 100644
index 0000000..a42e8b5
--- /dev/null
+++ b/fuzzer/README.md
@@ -0,0 +1,69 @@
+# Fuzzer for libavc decoder
+
+This describes steps to build avc_dec_fuzzer binary.
+
+## Linux x86/x64
+
+###  Requirements
+- cmake (3.5 or above)
+- make
+- clang (6.0 or above)
+  needs to support -fsanitize=fuzzer, -fsanitize=fuzzer-no-link
+
+### Steps to build
+Clone libavc repository
+```
+$ git clone https://android.googlesource.com/platform/external/libavc
+```
+Create a directory inside libavc and change directory
+```
+ $ cd libavc
+ $ mkdir build
+ $ cd build
+```
+Build libavc using cmake
+```
+ $ CC=clang CXX=clang++ cmake ../ \
+   -DSANITIZE=fuzzer-no-link,address,signed-integer-overflow
+ $ make
+ ```
+Build the fuzzer
+```
+ $ clang++ -std=c++11 -fsanitize=fuzzer,address -I.  -I../  -I../common \
+   -I../decoder -Wl,--start-group ../fuzzer/avc_dec_fuzzer.cpp \
+   -o ./avc_dec_fuzzer ./libavcdec.a -Wl,--end-group
+```
+
+### Steps to run
+Create a directory CORPUS_DIR and copy some elementary h264 files to that folder
+To run the fuzzer
+```
+$ ./avc_dec_fuzzer CORPUS_DIR
+```
+
+## Android
+
+### Steps to build
+Build the fuzzer
+```
+  $ SANITIZE_TARGET=address SANITIZE_HOST=address mmma -j$(nproc) \
+    external/libavc/fuzzer
+```
+
+### Steps to run
+Create a directory CORPUS_DIR and copy some elementary h264 files to that folder
+Push this directory to device.
+
+To run on device
+```
+  $ adb sync data
+  $ adb shell /data/fuzz/avc_dec_fuzzer CORPUS_DIR
+```
+To run on host
+```
+  $ $ANDROID_HOST_OUT/fuzz/avc_dec_fuzzer CORPUS_DIR
+```
+
+## References:
+ * http://llvm.org/docs/LibFuzzer.html
+ * https://github.com/google/oss-fuzz
diff --git a/fuzzer/avc_dec_fuzzer.cpp b/fuzzer/avc_dec_fuzzer.cpp
new file mode 100644
index 0000000..c292298
--- /dev/null
+++ b/fuzzer/avc_dec_fuzzer.cpp
@@ -0,0 +1,374 @@
+/******************************************************************************
+ *
+ * Copyright (C) 2019 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 <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <algorithm>
+#include <memory>
+
+#include "ih264_typedefs.h"
+#include "ih264d.h"
+#include "iv.h"
+#include "ivd.h"
+
+#define NELEMENTS(x) (sizeof(x) / sizeof(x[0]))
+#define ivd_api_function ih264d_api_function
+const IV_COLOR_FORMAT_T supportedColorFormats[] = {
+    IV_YUV_420P,   IV_YUV_420SP_UV, IV_YUV_420SP_VU,
+    IV_YUV_422ILE, IV_RGB_565,      IV_RGBA_8888};
+
+/* Decoder ignores invalid arch, i.e. for arm build, if SSSE3 is requested,
+ * decoder defaults to a supported configuration. So same set of supported
+ * architectures can be used in arm/arm64/x86 builds */
+const IVD_ARCH_T supportedArchitectures[] = {
+    ARCH_ARM_NONEON,  ARCH_ARM_A9Q,   ARCH_ARM_NEONINTR, ARCH_ARMV8_GENERIC,
+    ARCH_X86_GENERIC, ARCH_X86_SSSE3, ARCH_X86_SSE42};
+
+enum {
+  OFFSET_COLOR_FORMAT = 6,
+  OFFSET_NUM_CORES,
+  OFFSET_ARCH,
+  /* Should be the last entry */
+  OFFSET_MAX,
+};
+
+const static int kMaxNumDecodeCalls = 100;
+const static int kSupportedColorFormats = NELEMENTS(supportedColorFormats);
+const static int kSupportedArchitectures = NELEMENTS(supportedArchitectures);
+const static int kMaxCores = 4;
+void *iv_aligned_malloc(void *ctxt, WORD32 alignment, WORD32 size) {
+  void *buf = NULL;
+  (void)ctxt;
+  if (0 != posix_memalign(&buf, alignment, size)) {
+      return NULL;
+  }
+  return buf;
+}
+
+void iv_aligned_free(void *ctxt, void *buf) {
+  (void)ctxt;
+  free(buf);
+}
+
+class Codec {
+ public:
+  Codec(IV_COLOR_FORMAT_T colorFormat, size_t numCores);
+  ~Codec();
+
+  void createCodec();
+  void deleteCodec();
+  void resetCodec();
+  void setCores();
+  void allocFrame();
+  void freeFrame();
+  void decodeHeader(const uint8_t *data, size_t size);
+  IV_API_CALL_STATUS_T decodeFrame(const uint8_t *data, size_t size,
+                                   size_t *bytesConsumed);
+  void setParams(IVD_VIDEO_DECODE_MODE_T mode);
+  void setArchitecture(IVD_ARCH_T arch);
+
+ private:
+  IV_COLOR_FORMAT_T mColorFormat;
+  size_t mNumCores;
+  iv_obj_t *mCodec;
+  ivd_out_bufdesc_t mOutBufHandle;
+  uint32_t mWidth;
+  uint32_t mHeight;
+};
+
+Codec::Codec(IV_COLOR_FORMAT_T colorFormat, size_t numCores) {
+  mColorFormat = colorFormat;
+  mNumCores = numCores;
+  mCodec = nullptr;
+  mWidth = 0;
+  mHeight = 0;
+
+  memset(&mOutBufHandle, 0, sizeof(mOutBufHandle));
+}
+Codec::~Codec() {}
+void Codec::createCodec() {
+  IV_API_CALL_STATUS_T ret;
+  ih264d_create_ip_t create_ip;
+  ih264d_create_op_t create_op;
+  void *fxns = (void *)&ivd_api_function;
+
+  create_ip.s_ivd_create_ip_t.e_cmd = IVD_CMD_CREATE;
+  create_ip.s_ivd_create_ip_t.u4_share_disp_buf = 0;
+  create_ip.s_ivd_create_ip_t.e_output_format = mColorFormat;
+  create_ip.s_ivd_create_ip_t.pf_aligned_alloc = iv_aligned_malloc;
+  create_ip.s_ivd_create_ip_t.pf_aligned_free = iv_aligned_free;
+  create_ip.s_ivd_create_ip_t.pv_mem_ctxt = NULL;
+  create_ip.s_ivd_create_ip_t.u4_size = sizeof(ih264d_create_ip_t);
+  create_op.s_ivd_create_op_t.u4_size = sizeof(ih264d_create_op_t);
+
+  ret = ivd_api_function(NULL, (void *)&create_ip, (void *)&create_op);
+  if (ret != IV_SUCCESS) {
+    return;
+  }
+  mCodec = (iv_obj_t *)create_op.s_ivd_create_op_t.pv_handle;
+  mCodec->pv_fxns = fxns;
+  mCodec->u4_size = sizeof(iv_obj_t);
+}
+
+void Codec::deleteCodec() {
+  ivd_delete_ip_t delete_ip;
+  ivd_delete_op_t delete_op;
+
+  delete_ip.e_cmd = IVD_CMD_DELETE;
+  delete_ip.u4_size = sizeof(ivd_delete_ip_t);
+  delete_op.u4_size = sizeof(ivd_delete_op_t);
+
+  ivd_api_function(mCodec, (void *)&delete_ip, (void *)&delete_op);
+}
+void Codec::resetCodec() {
+  ivd_ctl_reset_ip_t s_ctl_ip;
+  ivd_ctl_reset_op_t s_ctl_op;
+
+  s_ctl_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+  s_ctl_ip.e_sub_cmd = IVD_CMD_CTL_RESET;
+  s_ctl_ip.u4_size = sizeof(ivd_ctl_reset_ip_t);
+  s_ctl_op.u4_size = sizeof(ivd_ctl_reset_op_t);
+
+  ivd_api_function(mCodec, (void *)&s_ctl_ip, (void *)&s_ctl_op);
+}
+
+void Codec::setCores() {
+  ih264d_ctl_set_num_cores_ip_t s_ctl_ip;
+  ih264d_ctl_set_num_cores_op_t s_ctl_op;
+
+  s_ctl_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+  s_ctl_ip.e_sub_cmd =
+      (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_SET_NUM_CORES;
+  s_ctl_ip.u4_num_cores = mNumCores;
+  s_ctl_ip.u4_size = sizeof(ih264d_ctl_set_num_cores_ip_t);
+  s_ctl_op.u4_size = sizeof(ih264d_ctl_set_num_cores_op_t);
+
+  ivd_api_function(mCodec, (void *)&s_ctl_ip, (void *)&s_ctl_op);
+}
+
+void Codec::setParams(IVD_VIDEO_DECODE_MODE_T mode) {
+  ivd_ctl_set_config_ip_t s_ctl_ip;
+  ivd_ctl_set_config_op_t s_ctl_op;
+
+  s_ctl_ip.u4_disp_wd = 0;
+  s_ctl_ip.e_frm_skip_mode = IVD_SKIP_NONE;
+  s_ctl_ip.e_frm_out_mode = IVD_DISPLAY_FRAME_OUT;
+  s_ctl_ip.e_vid_dec_mode = mode;
+  s_ctl_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+  s_ctl_ip.e_sub_cmd = IVD_CMD_CTL_SETPARAMS;
+  s_ctl_ip.u4_size = sizeof(ivd_ctl_set_config_ip_t);
+  s_ctl_op.u4_size = sizeof(ivd_ctl_set_config_op_t);
+
+  ivd_api_function(mCodec, (void *)&s_ctl_ip, (void *)&s_ctl_op);
+}
+
+void Codec::setArchitecture(IVD_ARCH_T arch) {
+  ih264d_ctl_set_processor_ip_t s_ctl_ip;
+  ih264d_ctl_set_processor_op_t s_ctl_op;
+
+  s_ctl_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+  s_ctl_ip.e_sub_cmd =
+      (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_SET_PROCESSOR;
+  s_ctl_ip.u4_arch = arch;
+  s_ctl_ip.u4_soc = SOC_GENERIC;
+  s_ctl_ip.u4_size = sizeof(ih264d_ctl_set_processor_ip_t);
+  s_ctl_op.u4_size = sizeof(ih264d_ctl_set_processor_op_t);
+
+  ivd_api_function(mCodec, (void *)&s_ctl_ip, (void *)&s_ctl_op);
+}
+void Codec::freeFrame() {
+  for (int i = 0; i < mOutBufHandle.u4_num_bufs; i++) {
+    if (mOutBufHandle.pu1_bufs[i]) {
+      free(mOutBufHandle.pu1_bufs[i]);
+      mOutBufHandle.pu1_bufs[i] = nullptr;
+    }
+  }
+}
+void Codec::allocFrame() {
+  size_t sizes[4] = {0};
+  size_t num_bufs = 0;
+
+  freeFrame();
+
+  memset(&mOutBufHandle, 0, sizeof(mOutBufHandle));
+
+  switch (mColorFormat) {
+    case IV_YUV_420SP_UV:
+      [[fallthrough]];
+    case IV_YUV_420SP_VU:
+      sizes[0] = mWidth * mHeight;
+      sizes[1] = mWidth * mHeight >> 1;
+      num_bufs = 2;
+      break;
+    case IV_YUV_422ILE:
+      sizes[0] = mWidth * mHeight * 2;
+      num_bufs = 1;
+      break;
+    case IV_RGB_565:
+      sizes[0] = mWidth * mHeight * 2;
+      num_bufs = 1;
+      break;
+    case IV_RGBA_8888:
+      sizes[0] = mWidth * mHeight * 4;
+      num_bufs = 1;
+      break;
+    case IV_YUV_420P:
+      [[fallthrough]];
+    default:
+      sizes[0] = mWidth * mHeight;
+      sizes[1] = mWidth * mHeight >> 2;
+      sizes[2] = mWidth * mHeight >> 2;
+      num_bufs = 3;
+      break;
+  }
+  mOutBufHandle.u4_num_bufs = num_bufs;
+  for (int i = 0; i < num_bufs; i++) {
+    mOutBufHandle.u4_min_out_buf_size[i] = sizes[i];
+    mOutBufHandle.pu1_bufs[i] = (UWORD8 *)iv_aligned_malloc(NULL, 16, sizes[i]);
+  }
+}
+void Codec::decodeHeader(const uint8_t *data, size_t size) {
+  setParams(IVD_DECODE_HEADER);
+
+  while (size > 0) {
+    IV_API_CALL_STATUS_T ret;
+    ivd_video_decode_ip_t dec_ip;
+    ivd_video_decode_op_t dec_op;
+    size_t bytes_consumed;
+
+    memset(&dec_ip, 0, sizeof(dec_ip));
+    memset(&dec_op, 0, sizeof(dec_op));
+
+    dec_ip.e_cmd = IVD_CMD_VIDEO_DECODE;
+    dec_ip.u4_ts = 0;
+    dec_ip.pv_stream_buffer = (void *)data;
+    dec_ip.u4_num_Bytes = size;
+    dec_ip.u4_size = sizeof(ivd_video_decode_ip_t);
+    dec_op.u4_size = sizeof(ivd_video_decode_op_t);
+
+    ret = ivd_api_function(mCodec, (void *)&dec_ip, (void *)&dec_op);
+
+    bytes_consumed = dec_op.u4_num_bytes_consumed;
+    /* If no bytes are consumed, then consume 4 bytes to ensure fuzzer proceeds
+     * to feed next data */
+    if (!bytes_consumed) bytes_consumed = 4;
+
+    bytes_consumed = std::min(size, bytes_consumed);
+
+    data += bytes_consumed;
+    size -= bytes_consumed;
+
+    mWidth = std::min(dec_op.u4_pic_wd, (UWORD32)10240);
+    mHeight = std::min(dec_op.u4_pic_ht, (UWORD32)10240);
+
+    /* Break after successful header decode */
+    if (mWidth && mHeight) {
+      break;
+    }
+  }
+  /* if width / height are invalid, set them to defaults */
+  if (!mWidth) mWidth = 1920;
+  if (!mHeight) mHeight = 1088;
+}
+
+IV_API_CALL_STATUS_T Codec::decodeFrame(const uint8_t *data, size_t size,
+                                        size_t *bytesConsumed) {
+  IV_API_CALL_STATUS_T ret;
+  ivd_video_decode_ip_t dec_ip;
+  ivd_video_decode_op_t dec_op;
+
+  memset(&dec_ip, 0, sizeof(dec_ip));
+  memset(&dec_op, 0, sizeof(dec_op));
+
+  dec_ip.e_cmd = IVD_CMD_VIDEO_DECODE;
+  dec_ip.u4_ts = 0;
+  dec_ip.pv_stream_buffer = (void *)data;
+  dec_ip.u4_num_Bytes = size;
+  dec_ip.u4_size = sizeof(ivd_video_decode_ip_t);
+  dec_ip.s_out_buffer = mOutBufHandle;
+
+  dec_op.u4_size = sizeof(ivd_video_decode_op_t);
+
+  ret = ivd_api_function(mCodec, (void *)&dec_ip, (void *)&dec_op);
+
+  /* In case of change in resolution, reset codec and feed the same data again
+   */
+  if (IVD_RES_CHANGED == (dec_op.u4_error_code & 0xFF)) {
+    resetCodec();
+    ret = ivd_api_function(mCodec, (void *)&dec_ip, (void *)&dec_op);
+  }
+  *bytesConsumed = dec_op.u4_num_bytes_consumed;
+
+  /* If no bytes are consumed, then consume 4 bytes to ensure fuzzer proceeds
+   * to feed next data */
+  if (!*bytesConsumed) *bytesConsumed = 4;
+
+  if (dec_op.u4_pic_wd && dec_op.u4_pic_ht &&
+      (mWidth != dec_op.u4_pic_wd || mHeight != dec_op.u4_pic_ht)) {
+    mWidth = std::min(dec_op.u4_pic_wd, (UWORD32)10240);
+    mHeight = std::min(dec_op.u4_pic_ht, (UWORD32)10240);
+    allocFrame();
+  }
+
+  return ret;
+}
+
+extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+  if (size < 1) {
+    return 0;
+  }
+  size_t colorFormatOfst = std::min((size_t)OFFSET_COLOR_FORMAT, size - 1);
+  size_t numCoresOfst = std::min((size_t)OFFSET_NUM_CORES, size - 1);
+  size_t architectureOfst = std::min((size_t)OFFSET_ARCH, size - 1);
+  size_t architectureIdx = data[architectureOfst] % kSupportedArchitectures;
+  IVD_ARCH_T arch = (IVD_ARCH_T)supportedArchitectures[architectureIdx];
+  size_t colorFormatIdx = data[colorFormatOfst] % kSupportedColorFormats;
+  IV_COLOR_FORMAT_T colorFormat =
+      (IV_COLOR_FORMAT_T)(supportedColorFormats[colorFormatIdx]);
+  uint32_t numCores = (data[numCoresOfst] % kMaxCores) + 1;
+  size_t numDecodeCalls = 0;
+  Codec *codec = new Codec(colorFormat, numCores);
+  codec->createCodec();
+  codec->setArchitecture(arch);
+  codec->setCores();
+  codec->decodeHeader(data, size);
+  codec->setParams(IVD_DECODE_FRAME);
+  codec->allocFrame();
+
+  while (size > 0 && numDecodeCalls < kMaxNumDecodeCalls) {
+    IV_API_CALL_STATUS_T ret;
+    size_t bytesConsumed;
+    ret = codec->decodeFrame(data, size, &bytesConsumed);
+
+    bytesConsumed = std::min(size, bytesConsumed);
+    data += bytesConsumed;
+    size -= bytesConsumed;
+    numDecodeCalls++;
+  }
+
+  codec->freeFrame();
+  codec->deleteCodec();
+  delete codec;
+  return 0;
+}
diff --git a/fuzzer/avc_dec_fuzzer.dict b/fuzzer/avc_dec_fuzzer.dict
new file mode 100644
index 0000000..f436f20
--- /dev/null
+++ b/fuzzer/avc_dec_fuzzer.dict
@@ -0,0 +1,2 @@
+# Start code (bytes 0-3)
+kw1="\x00\x00\x00\x01"
diff --git a/fuzzer/ossfuzz.sh b/fuzzer/ossfuzz.sh
new file mode 100755
index 0000000..e5bed08
--- /dev/null
+++ b/fuzzer/ossfuzz.sh
@@ -0,0 +1,44 @@
+#!/bin/bash -eu
+#
+# 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.
+#
+################################################################################
+# Ensure SRC and WORK are set
+test "${SRC}" != "" || exit 1
+test "${WORK}" != "" || exit 1
+test "${OUT}" != "" || exit 1
+
+# Build libavc
+build_dir=$WORK/build
+rm -rf ${build_dir}
+mkdir -p ${build_dir}
+pushd ${build_dir}
+
+cmake $SRC/libavc
+make -j$(nproc)
+popd
+
+# build fuzzers
+$CXX $CXXFLAGS -std=c++11 \
+    -I$SRC/libavc \
+    -I$SRC/libavc/common \
+    -I$SRC/libavc/decoder \
+    -I${build_dir} \
+    -Wl,--start-group \
+    $LIB_FUZZING_ENGINE \
+    $SRC/libavc/fuzzer/avc_dec_fuzzer.cpp -o $OUT/avc_dec_fuzzer \
+    ${build_dir}/libavcdec.a \
+    -Wl,--end-group
+
+cp $SRC/avc_dec_fuzzer_seed_corpus.zip $OUT/avc_dec_fuzzer_seed_corpus.zip
+cp $SRC/libavc/fuzzer/avc_dec_fuzzer.dict $OUT/avcdec_fuzzer.dict
diff --git a/test/Android.bp b/test/Android.bp
index 2a5b6c7..a62b56c 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -1,7 +1,7 @@
 cc_test {
     name: "avcdec",
     gtest: false,
-
+    host_supported:true,
     cflags: [
         "-DPROFILE_ENABLE",
         "-DARM",
@@ -16,11 +16,17 @@
     srcs: ["decoder/main.c"],
     static_libs: ["libavcdec"],
     shared_libs: ["liblog"],
+    target: {
+        darwin: {
+            enabled: false,
+        },
+    },
 }
 
 cc_test {
     name: "avcenc",
     gtest: false,
+    host_supported: true,
 
     cflags: [
         "-DPROFILE_ENABLE",
diff --git a/test/decoder/main.c b/test/decoder/main.c
index ea7fca3..533f72a 100644
--- a/test/decoder/main.c
+++ b/test/decoder/main.c
@@ -44,9 +44,6 @@
 #include <signal.h>
 #endif
 
-#ifndef IOS
-#include <malloc.h>
-#endif
 #ifdef IOS_DISPLAY
 #include "cast_types.h"
 #else
@@ -447,8 +444,13 @@
 #if (!defined(IOS)) && (!defined(_WIN32))
 void * ih264a_aligned_malloc(void *pv_ctxt, WORD32 alignment, WORD32 i4_size)
 {
-   (void)pv_ctxt;
-    return memalign(alignment, i4_size);
+    void *buf = NULL;
+    (void)pv_ctxt;
+    if (0 != posix_memalign(&buf, alignment, i4_size))
+    {
+        return NULL;
+    }
+    return buf;
 }
 
 void ih264a_aligned_free(void *pv_ctxt, void *pv_buf)
@@ -1695,6 +1697,132 @@
                  * dumping all the frames in one common file. Also, the number of dumped frames
                  * at any given instance of time cannot exceed 'frame_memory'
                  */
+
+                /*************************************************************************/
+                /* Get SEI MDCV parameters                                               */
+                /*************************************************************************/
+                if(1 == s_video_decode_op.s_sei_decode_op.u1_sei_mdcv_params_present_flag)
+                {
+                    ih264d_ctl_get_sei_mdcv_params_ip_t s_ctl_get_sei_mdcv_params_ip;
+                    ih264d_ctl_get_sei_mdcv_params_op_t s_ctl_get_sei_mdcv_params_op;
+
+                    memset(&s_ctl_get_sei_mdcv_params_ip, 0,
+                                        sizeof(ih264d_ctl_get_sei_mdcv_params_ip_t));
+                    memset(&s_ctl_get_sei_mdcv_params_op, 0,
+                                        sizeof(ih264d_ctl_get_sei_mdcv_params_op_t));
+
+                    s_ctl_get_sei_mdcv_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+                    s_ctl_get_sei_mdcv_params_ip.e_sub_cmd =
+                            (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS;
+                    s_ctl_get_sei_mdcv_params_ip.u4_size =
+                            sizeof(ih264d_ctl_get_sei_mdcv_params_ip_t);
+                    s_ctl_get_sei_mdcv_params_op.u4_size =
+                            sizeof(ih264d_ctl_get_sei_mdcv_params_op_t);
+
+                    ret = ivd_api_function((iv_obj_t *)codec_obj,
+                                            (void *)&s_ctl_get_sei_mdcv_params_ip,
+                                            (void *)&s_ctl_get_sei_mdcv_params_op);
+
+                    if(IV_SUCCESS != ret)
+                    {
+                        printf("MDCV SEI params not present : Error %x\n",
+                                 s_ctl_get_sei_mdcv_params_op.u4_error_code);
+                    }
+                }
+                /*************************************************************************/
+                /* Get SEI CLL parameters                                                */
+                /*************************************************************************/
+                if(1 == s_video_decode_op.s_sei_decode_op.u1_sei_cll_params_present_flag)
+                {
+                    ih264d_ctl_get_sei_cll_params_ip_t s_ctl_get_sei_cll_params_ip;
+                    ih264d_ctl_get_sei_cll_params_op_t s_ctl_get_sei_cll_params_op;
+
+                    memset(&s_ctl_get_sei_cll_params_ip, 0,
+                                        sizeof(ih264d_ctl_get_sei_cll_params_ip_t));
+                    memset(&s_ctl_get_sei_cll_params_op, 0,
+                                        sizeof(ih264d_ctl_get_sei_cll_params_op_t));
+
+                    s_ctl_get_sei_cll_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+                    s_ctl_get_sei_cll_params_ip.e_sub_cmd =
+                            (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_SEI_CLL_PARAMS;
+                    s_ctl_get_sei_cll_params_ip.u4_size =
+                            sizeof(ih264d_ctl_get_sei_cll_params_ip_t);
+                    s_ctl_get_sei_cll_params_op.u4_size =
+                            sizeof(ih264d_ctl_get_sei_cll_params_op_t);
+
+                    ret = ivd_api_function((iv_obj_t *)codec_obj,
+                                            (void *)&s_ctl_get_sei_cll_params_ip,
+                                            (void *)&s_ctl_get_sei_cll_params_op);
+
+                    if(IV_SUCCESS != ret)
+                    {
+                        printf("CLL SEI params not present : Error %x\n",
+                                s_ctl_get_sei_cll_params_op.u4_error_code);
+                    }
+                }
+                /*************************************************************************/
+                /* Get SEI AVE parameters                                                */
+                /*************************************************************************/
+                if(1 == s_video_decode_op.s_sei_decode_op.u1_sei_ave_params_present_flag)
+                {
+                    ih264d_ctl_get_sei_ave_params_ip_t s_ctl_get_sei_ave_params_ip;
+                    ih264d_ctl_get_sei_ave_params_op_t s_ctl_get_sei_ave_params_op;
+
+                    memset(&s_ctl_get_sei_ave_params_ip, 0,
+                                        sizeof(ih264d_ctl_get_sei_ave_params_ip_t));
+                    memset(&s_ctl_get_sei_ave_params_op, 0,
+                                        sizeof(ih264d_ctl_get_sei_ave_params_op_t));
+
+                    s_ctl_get_sei_ave_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+                    s_ctl_get_sei_ave_params_ip.e_sub_cmd =
+                            (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_SEI_AVE_PARAMS;
+                    s_ctl_get_sei_ave_params_ip.u4_size =
+                            sizeof(ih264d_ctl_get_sei_ave_params_ip_t);
+                    s_ctl_get_sei_ave_params_op.u4_size =
+                            sizeof(ih264d_ctl_get_sei_ave_params_op_t);
+
+                    ret = ivd_api_function((iv_obj_t *)codec_obj,
+                                            (void *)&s_ctl_get_sei_ave_params_ip,
+                                            (void *)&s_ctl_get_sei_ave_params_op);
+
+                    if(IV_SUCCESS != ret)
+                    {
+                        printf("AVE SEI params not present : Error %x\n",
+                                s_ctl_get_sei_ave_params_op.u4_error_code);
+                    }
+                }
+                /*************************************************************************/
+                /* Get SEI CCV parameters                                                */
+                /*************************************************************************/
+                if(1 == s_video_decode_op.s_sei_decode_op.u1_sei_ccv_params_present_flag)
+                {
+                    ih264d_ctl_get_sei_ccv_params_ip_t s_ctl_get_sei_ccv_params_ip;
+                    ih264d_ctl_get_sei_ccv_params_op_t s_ctl_get_sei_ccv_params_op;
+
+                    memset(&s_ctl_get_sei_ccv_params_ip, 0,
+                                        sizeof(ih264d_ctl_get_sei_ccv_params_ip_t));
+                    memset(&s_ctl_get_sei_ccv_params_op, 0,
+                                        sizeof(ih264d_ctl_get_sei_ccv_params_op_t));
+
+                    s_ctl_get_sei_ccv_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+                    s_ctl_get_sei_ccv_params_ip.e_sub_cmd =
+                            (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_SEI_CCV_PARAMS;
+                    s_ctl_get_sei_ccv_params_ip.u4_size =
+                            sizeof(ih264d_ctl_get_sei_ccv_params_ip_t);
+                    s_ctl_get_sei_ccv_params_op.u4_size =
+                            sizeof(ih264d_ctl_get_sei_ccv_params_op_t);
+
+                    ret = ivd_api_function((iv_obj_t *)codec_obj,
+                                            (void *)&s_ctl_get_sei_ccv_params_ip,
+                                            (void *)&s_ctl_get_sei_ccv_params_op);
+
+                    if(IV_SUCCESS != ret)
+                    {
+                        printf("CCV SEI params not present : Error %x\n",
+                                s_ctl_get_sei_ccv_params_op.u4_error_code);
+                    }
+                }
+
                 if(ps_app_ctx->u4_file_save_flag)
                 {
                     /* Locate the position of extension yuv */
@@ -1898,6 +2026,7 @@
     s_app_ctx.quit          = 0;
     s_app_ctx.paused        = 0;
     //s_app_ctx.u4_output_present = 0;
+    s_app_ctx.u4_chksum_save_flag = 0;
 
     s_app_ctx.get_stride = &default_get_stride;
 
@@ -2997,6 +3126,131 @@
                 }
             }
 
+            /*************************************************************************/
+            /* Get SEI MDCV parameters                                               */
+            /*************************************************************************/
+            if(1 == s_video_decode_op.s_sei_decode_op.u1_sei_mdcv_params_present_flag)
+            {
+                ih264d_ctl_get_sei_mdcv_params_ip_t s_ctl_get_sei_mdcv_params_ip;
+                ih264d_ctl_get_sei_mdcv_params_op_t s_ctl_get_sei_mdcv_params_op;
+
+                memset(&s_ctl_get_sei_mdcv_params_ip, 0,
+                                        sizeof(ih264d_ctl_get_sei_mdcv_params_ip_t));
+                memset(&s_ctl_get_sei_mdcv_params_op, 0,
+                                        sizeof(ih264d_ctl_get_sei_mdcv_params_op_t));
+
+                s_ctl_get_sei_mdcv_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+                s_ctl_get_sei_mdcv_params_ip.e_sub_cmd =
+                        (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_SEI_MDCV_PARAMS;
+                s_ctl_get_sei_mdcv_params_ip.u4_size =
+                        sizeof(ih264d_ctl_get_sei_mdcv_params_ip_t);
+                s_ctl_get_sei_mdcv_params_op.u4_size =
+                        sizeof(ih264d_ctl_get_sei_mdcv_params_op_t);
+
+                ret = ivd_api_function((iv_obj_t *)codec_obj,
+                                        (void *)&s_ctl_get_sei_mdcv_params_ip,
+                                        (void *)&s_ctl_get_sei_mdcv_params_op);
+
+                if(IV_SUCCESS != ret)
+                {
+                     printf("MDCV SEI params not present : Error %x\n",
+                             s_ctl_get_sei_mdcv_params_op.u4_error_code);
+                }
+            }
+            /*************************************************************************/
+            /* Get SEI CLL parameters                                                */
+            /*************************************************************************/
+            if(1 == s_video_decode_op.s_sei_decode_op.u1_sei_cll_params_present_flag)
+            {
+
+                ih264d_ctl_get_sei_cll_params_ip_t s_ctl_get_sei_cll_params_ip;
+                ih264d_ctl_get_sei_cll_params_op_t s_ctl_get_sei_cll_params_op;
+
+                memset(&s_ctl_get_sei_cll_params_ip, 0,
+                                        sizeof(ih264d_ctl_get_sei_cll_params_ip_t));
+                memset(&s_ctl_get_sei_cll_params_op, 0,
+                                        sizeof(ih264d_ctl_get_sei_cll_params_op_t));
+
+                s_ctl_get_sei_cll_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+                s_ctl_get_sei_cll_params_ip.e_sub_cmd =
+                        (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_SEI_CLL_PARAMS;
+                s_ctl_get_sei_cll_params_ip.u4_size =
+                        sizeof(ih264d_ctl_get_sei_cll_params_ip_t);
+                s_ctl_get_sei_cll_params_op.u4_size =
+                        sizeof(ih264d_ctl_get_sei_cll_params_op_t);
+
+                ret = ivd_api_function((iv_obj_t *)codec_obj,
+                                        (void *)&s_ctl_get_sei_cll_params_ip,
+                                        (void *)&s_ctl_get_sei_cll_params_op);
+
+                if(IV_SUCCESS != ret)
+                {
+                    printf("CLL SEI params not present : Error %x\n",
+                            s_ctl_get_sei_cll_params_op.u4_error_code);
+                }
+            }
+            /*************************************************************************/
+            /* Get SEI AVE parameters                                                */
+            /*************************************************************************/
+            if(1 == s_video_decode_op.s_sei_decode_op.u1_sei_ave_params_present_flag)
+            {
+                ih264d_ctl_get_sei_ave_params_ip_t s_ctl_get_sei_ave_params_ip;
+                ih264d_ctl_get_sei_ave_params_op_t s_ctl_get_sei_ave_params_op;
+
+                memset(&s_ctl_get_sei_ave_params_ip, 0,
+                                        sizeof(ih264d_ctl_get_sei_ave_params_ip_t));
+                memset(&s_ctl_get_sei_ave_params_op, 0,
+                                        sizeof(ih264d_ctl_get_sei_ave_params_op_t));
+
+                s_ctl_get_sei_ave_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+                s_ctl_get_sei_ave_params_ip.e_sub_cmd =
+                        (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_SEI_AVE_PARAMS;
+                s_ctl_get_sei_ave_params_ip.u4_size =
+                        sizeof(ih264d_ctl_get_sei_ave_params_ip_t);
+                s_ctl_get_sei_ave_params_op.u4_size =
+                        sizeof(ih264d_ctl_get_sei_ave_params_op_t);
+
+                ret = ivd_api_function((iv_obj_t *)codec_obj,
+                                        (void *)&s_ctl_get_sei_ave_params_ip,
+                                        (void *)&s_ctl_get_sei_ave_params_op);
+
+                if(IV_SUCCESS != ret)
+                {
+                    printf("AVE SEI params not present : Error %x\n",
+                            s_ctl_get_sei_ave_params_op.u4_error_code);
+                }
+            }
+            /*************************************************************************/
+            /* Get SEI CCV parameters                                                */
+            /*************************************************************************/
+            if(1 == s_video_decode_op.s_sei_decode_op.u1_sei_ccv_params_present_flag)
+            {
+                ih264d_ctl_get_sei_ccv_params_ip_t s_ctl_get_sei_ccv_params_ip;
+                ih264d_ctl_get_sei_ccv_params_op_t s_ctl_get_sei_ccv_params_op;
+
+                memset(&s_ctl_get_sei_ccv_params_ip, 0,
+                                        sizeof(ih264d_ctl_get_sei_ccv_params_ip_t));
+                memset(&s_ctl_get_sei_ccv_params_op, 0,
+                                        sizeof(ih264d_ctl_get_sei_ccv_params_op_t));
+
+                s_ctl_get_sei_ccv_params_ip.e_cmd = IVD_CMD_VIDEO_CTL;
+                s_ctl_get_sei_ccv_params_ip.e_sub_cmd =
+                        (IVD_CONTROL_API_COMMAND_TYPE_T)IH264D_CMD_CTL_GET_SEI_CCV_PARAMS;
+                s_ctl_get_sei_ccv_params_ip.u4_size =
+                        sizeof(ih264d_ctl_get_sei_ccv_params_ip_t);
+                s_ctl_get_sei_ccv_params_op.u4_size =
+                        sizeof(ih264d_ctl_get_sei_ccv_params_op_t);
+
+                ret = ivd_api_function((iv_obj_t *)codec_obj,
+                                        (void *)&s_ctl_get_sei_ccv_params_ip,
+                                        (void *)&s_ctl_get_sei_ccv_params_op);
+
+                if(IV_SUCCESS != ret)
+                {
+                    printf("CCV SEI params not present : Error %x\n",
+                            s_ctl_get_sei_ccv_params_op.u4_error_code);
+                }
+            }
 
             if((1 == s_app_ctx.display) &&
                             (1 == s_video_decode_op.u4_output_present))
diff --git a/test/encoder/app.h b/test/encoder/app.h
index 8a2fb0a..232a59b 100644
--- a/test/encoder/app.h
+++ b/test/encoder/app.h
@@ -133,6 +133,9 @@
 #define DEFAULT_SLICE_PARAM         256
 #define DEFAULT_ENTROPY_CODING_MODE 0
 
+#define DEFAULT_MAX_DISPLAY_MASTERING_LUMINANCE 50000
+#define DEFAULT_MIN_DISPLAY_MASTERING_LUMINANCE 1
+
 #define STRLENGTH               500
 
 
@@ -320,6 +323,40 @@
     TIMER   enc_last_time;
     WORD32  avg_time;
 
+    UWORD32 u4_sei_mdcv_params_present_flag;
+    UWORD32 au4_display_primaries_x[NUM_SEI_MDCV_PRIMARIES];
+    UWORD32 au4_display_primaries_y[NUM_SEI_MDCV_PRIMARIES];
+    UWORD32 u4_white_point_x;
+    UWORD32 u4_white_point_y;
+    UWORD32 u4_max_display_mastering_luminance;
+    UWORD32 u4_min_display_mastering_luminance;
+
+    UWORD32 u4_sei_cll_params_present_flag;
+    UWORD32 u4_max_content_light_level;
+    UWORD32 u4_max_pic_average_light_level;
+
+    UWORD32 u4_sei_ave_params_present_flag;
+    UWORD32 u4_ambient_illuminance;
+    UWORD32 u4_ambient_light_x;
+    UWORD32 u4_ambient_light_y;
+
+    UWORD32 u4_sei_ccv_params_present_flag;
+    UWORD32 u4_ccv_cancel_flag;
+    UWORD32 u4_ccv_persistence_flag;
+    UWORD32 u4_ccv_primaries_present_flag;
+    UWORD32 u4_ccv_min_luminance_value_present_flag;
+    UWORD32 u4_ccv_max_luminance_value_present_flag;
+    UWORD32 u4_ccv_avg_luminance_value_present_flag;
+    UWORD32 u4_ccv_reserved_zero_2bits;
+    WORD32  ai4_ccv_primaries_x[NUM_SEI_CCV_PRIMARIES];
+    WORD32  ai4_ccv_primaries_y[NUM_SEI_CCV_PRIMARIES];
+    UWORD32 u4_ccv_min_luminance_value;
+    UWORD32 u4_ccv_max_luminance_value;
+    UWORD32 u4_ccv_avg_luminance_value;
+
+    ih264e_ctl_set_sei_mdcv_params_ip_t s_sei_mdcv_params;
+    ih264e_ctl_set_sei_cll_params_ip_t s_sei_cll_params;
+    ih264e_ctl_set_sei_ave_params_ip_t s_sei_ave_params;
 
 } app_ctxt_t;
 
diff --git a/test/encoder/input.c b/test/encoder/input.c
index 1d40eb0..77b1090 100644
--- a/test/encoder/input.c
+++ b/test/encoder/input.c
@@ -30,6 +30,7 @@
 
 /* User include files */
 #include "ih264_typedefs.h"
+#include "ih264_defs.h"
 #include "iv2.h"
 #include "ive2.h"
 #include "ih264e.h"
diff --git a/test/encoder/main.c b/test/encoder/main.c
index bc25e8d..fc84ad2 100644
--- a/test/encoder/main.c
+++ b/test/encoder/main.c
@@ -29,10 +29,6 @@
 #include <assert.h>
 #include <string.h>
 
-#ifndef IOS
-#include <malloc.h>
-#endif
-
 #ifdef WINDOWS_TIMER
 #include "windows.h"
 #else
@@ -40,6 +36,7 @@
 #endif
 /* User include files */
 #include "ih264_typedefs.h"
+#include "ih264_defs.h"
 #include "iv2.h"
 #include "ive2.h"
 #include "ih264e.h"
@@ -277,7 +274,12 @@
 
 void * ih264a_aligned_malloc(WORD32 alignment, WORD32 size)
 {
-    return memalign(alignment, size);
+    void *buf = NULL;
+    if (0 != posix_memalign(&buf, alignment, size))
+    {
+        return NULL;
+    }
+    return buf;
 }
 
 void ih264a_aligned_free(void *pv_buf)
@@ -846,12 +848,14 @@
 
     while(0 == (feof(fp_cfg)))
     {
+        int ret;
         line[0] = '\0';
-        fgets(line, STRLENGTH, fp_cfg);
+        if(NULL == fgets(line, sizeof(line), fp_cfg))
+            break;
         argument[0] = '\0';
         /* Reading Input File Name */
-        sscanf(line, "%s %s %s", argument, value, description);
-        if(argument[0] == '\0')
+        ret = sscanf(line, "%s %s %s", argument, value, description);
+        if(ret < 2)
             continue;
 
         parse_argument(ps_app_ctxt, argument, value);
@@ -1462,10 +1466,10 @@
     s_vui_params_ip.u2_sar_height = 0;
     s_vui_params_ip.u1_overscan_info_present_flag = 0;
     s_vui_params_ip.u1_overscan_appropriate_flag = 0;
-    s_vui_params_ip.u1_video_signal_type_present_flag = 0;
+    s_vui_params_ip.u1_video_signal_type_present_flag = 1;
     s_vui_params_ip.u1_video_format = 0;
     s_vui_params_ip.u1_video_full_range_flag = 0;
-    s_vui_params_ip.u1_colour_description_present_flag = 0;
+    s_vui_params_ip.u1_colour_description_present_flag = 1;
     s_vui_params_ip.u1_colour_primaries = 0;
     s_vui_params_ip.u1_transfer_characteristics = 0;
     s_vui_params_ip.u1_matrix_coefficients = 0;
@@ -1504,6 +1508,222 @@
     }
     return;
 }
+
+void set_sei_mdcv_params(app_ctxt_t *ps_app_ctxt,
+                         UWORD32 u4_timestamp_low,
+                         UWORD32 u4_timestamp_high)
+{
+    WORD32 i4_count;
+    IV_STATUS_T status;
+
+    ih264e_ctl_set_sei_mdcv_params_ip_t s_sei_mdcv_params_ip;
+    ih264e_ctl_set_sei_mdcv_params_op_t s_sei_mdcv_params_op;
+
+    s_sei_mdcv_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
+    s_sei_mdcv_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_MDCV_PARAMS;
+
+    s_sei_mdcv_params_ip.u1_sei_mdcv_params_present_flag =
+                                (UWORD8)ps_app_ctxt->u4_sei_mdcv_params_present_flag;
+
+    for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
+    {
+        s_sei_mdcv_params_ip.au2_display_primaries_x[i4_count] =
+                                (UWORD16)ps_app_ctxt->au4_display_primaries_x[i4_count];
+        s_sei_mdcv_params_ip.au2_display_primaries_y[i4_count] =
+                                (UWORD16)ps_app_ctxt->au4_display_primaries_y[i4_count];
+    }
+
+    s_sei_mdcv_params_ip.u2_white_point_x = (UWORD16)ps_app_ctxt->u4_white_point_x;
+    s_sei_mdcv_params_ip.u2_white_point_y = (UWORD16)ps_app_ctxt->u4_white_point_y;
+    s_sei_mdcv_params_ip.u4_max_display_mastering_luminance =
+                                ps_app_ctxt->u4_max_display_mastering_luminance;
+    s_sei_mdcv_params_ip.u4_min_display_mastering_luminance =
+                                ps_app_ctxt->u4_min_display_mastering_luminance;
+
+    s_sei_mdcv_params_ip.u4_timestamp_high  =   u4_timestamp_high;
+    s_sei_mdcv_params_ip.u4_timestamp_low   =   u4_timestamp_low;
+
+    s_sei_mdcv_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_mdcv_params_ip_t);
+    s_sei_mdcv_params_op.u4_size = sizeof(ih264e_ctl_set_sei_mdcv_params_op_t);
+
+    if((ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_x[0] !=
+                                s_sei_mdcv_params_ip.au2_display_primaries_x[0]) ||
+            (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_x[1] !=
+                                s_sei_mdcv_params_ip.au2_display_primaries_x[1]) ||
+            (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_x[2] !=
+                                s_sei_mdcv_params_ip.au2_display_primaries_x[2]) ||
+            (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_y[0] !=
+                                s_sei_mdcv_params_ip.au2_display_primaries_y[0]) ||
+            (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_y[1] !=
+                                s_sei_mdcv_params_ip.au2_display_primaries_y[1]) ||
+            (ps_app_ctxt->s_sei_mdcv_params.au2_display_primaries_y[2] !=
+                                s_sei_mdcv_params_ip.au2_display_primaries_y[2]) ||
+            (ps_app_ctxt->s_sei_mdcv_params.u2_white_point_x !=
+                                s_sei_mdcv_params_ip.u2_white_point_x) ||
+            (ps_app_ctxt->s_sei_mdcv_params.u2_white_point_y !=
+                                s_sei_mdcv_params_ip.u2_white_point_x) ||
+            (ps_app_ctxt->s_sei_mdcv_params.u4_max_display_mastering_luminance !=
+                                s_sei_mdcv_params_ip.u4_max_display_mastering_luminance) ||
+            (ps_app_ctxt->s_sei_mdcv_params.u4_min_display_mastering_luminance !=
+                                s_sei_mdcv_params_ip.u4_min_display_mastering_luminance))
+    {
+        status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_mdcv_params_ip,
+                                     &s_sei_mdcv_params_op);
+        if(status != IV_SUCCESS)
+        {
+            printf("Unable to set sei mdcv params = 0x%x\n",
+                    s_sei_mdcv_params_op.u4_error_code);
+        }
+        ps_app_ctxt->s_sei_mdcv_params = s_sei_mdcv_params_ip;
+    }
+    return;
+}
+
+void set_sei_cll_params(app_ctxt_t *ps_app_ctxt,
+                        UWORD32 u4_timestamp_low,
+                        UWORD32 u4_timestamp_high)
+{
+    IV_STATUS_T status;
+
+    ih264e_ctl_set_sei_cll_params_ip_t s_sei_cll_params_ip;
+    ih264e_ctl_set_sei_cll_params_op_t s_sei_cll_params_op;
+
+    s_sei_cll_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
+    s_sei_cll_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_CLL_PARAMS;
+
+    s_sei_cll_params_ip.u1_sei_cll_params_present_flag =
+                                (UWORD8)ps_app_ctxt->u4_sei_cll_params_present_flag;
+
+    s_sei_cll_params_ip.u2_max_content_light_level =
+                                (UWORD16)ps_app_ctxt->u4_max_content_light_level;
+    s_sei_cll_params_ip.u2_max_pic_average_light_level =
+                                (UWORD16)ps_app_ctxt->u4_max_pic_average_light_level;
+
+    s_sei_cll_params_ip.u4_timestamp_high  = u4_timestamp_high;
+    s_sei_cll_params_ip.u4_timestamp_low   = u4_timestamp_low;
+
+    s_sei_cll_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_cll_params_ip_t);
+    s_sei_cll_params_op.u4_size = sizeof(ih264e_ctl_set_sei_cll_params_op_t);
+
+    if((ps_app_ctxt->s_sei_cll_params.u2_max_content_light_level !=
+                                s_sei_cll_params_ip.u2_max_content_light_level) ||
+            (ps_app_ctxt->s_sei_cll_params.u2_max_pic_average_light_level !=
+                                s_sei_cll_params_ip.u2_max_pic_average_light_level))
+    {
+        status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_cll_params_ip,
+                                     &s_sei_cll_params_op);
+        if(status != IV_SUCCESS)
+        {
+            printf("Unable to set sei cll params = 0x%x\n",
+                    s_sei_cll_params_op.u4_error_code);
+        }
+        ps_app_ctxt->s_sei_cll_params = s_sei_cll_params_ip;
+    }
+    return;
+}
+
+void set_sei_ave_params(app_ctxt_t *ps_app_ctxt,
+                        UWORD32 u4_timestamp_low,
+                        UWORD32 u4_timestamp_high)
+{
+    IV_STATUS_T status;
+
+    ih264e_ctl_set_sei_ave_params_ip_t s_sei_ave_params_ip;
+    ih264e_ctl_set_sei_ave_params_op_t s_sei_ave_params_op;
+
+    s_sei_ave_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
+    s_sei_ave_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_AVE_PARAMS;
+
+    s_sei_ave_params_ip.u1_sei_ave_params_present_flag =
+                                (UWORD8)ps_app_ctxt->u4_sei_ave_params_present_flag;
+
+    s_sei_ave_params_ip.u4_ambient_illuminance = ps_app_ctxt->u4_ambient_illuminance;
+    s_sei_ave_params_ip.u2_ambient_light_x = (UWORD16)ps_app_ctxt->u4_ambient_light_x;
+    s_sei_ave_params_ip.u2_ambient_light_y = (UWORD16)ps_app_ctxt->u4_ambient_light_y;
+
+    s_sei_ave_params_ip.u4_timestamp_high  =   u4_timestamp_high;
+    s_sei_ave_params_ip.u4_timestamp_low   =   u4_timestamp_low;
+
+    s_sei_ave_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_ave_params_ip_t);
+    s_sei_ave_params_op.u4_size = sizeof(ih264e_ctl_set_sei_ave_params_op_t);
+
+    if((ps_app_ctxt->s_sei_ave_params.u4_ambient_illuminance !=
+                                s_sei_ave_params_ip.u4_ambient_illuminance) ||
+            (ps_app_ctxt->s_sei_ave_params.u2_ambient_light_x !=
+                                s_sei_ave_params_ip.u2_ambient_light_x) ||
+            (ps_app_ctxt->s_sei_ave_params.u2_ambient_light_y !=
+                                s_sei_ave_params_ip.u2_ambient_light_y))
+    {
+        status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_ave_params_ip,
+                                 &s_sei_ave_params_op);
+        if(status != IV_SUCCESS)
+        {
+            printf("Unable to set sei ave params = 0x%x\n",
+                    s_sei_ave_params_op.u4_error_code);
+        }
+        ps_app_ctxt->s_sei_ave_params = s_sei_ave_params_ip;
+    }
+    return;
+}
+
+void set_sei_ccv_params(app_ctxt_t *ps_app_ctxt,
+                        UWORD32 u4_timestamp_low,
+                        UWORD32 u4_timestamp_high)
+{
+    WORD32 i4_count;
+    IV_STATUS_T status;
+
+    ih264e_ctl_set_sei_ccv_params_ip_t s_sei_ccv_params_ip;
+    ih264e_ctl_set_sei_ccv_params_op_t s_sei_ccv_params_op;
+
+    s_sei_ccv_params_ip.e_cmd = IVE_CMD_VIDEO_CTL;
+    s_sei_ccv_params_ip.e_sub_cmd = IVE_CMD_CTL_SET_SEI_CCV_PARAMS;
+
+    s_sei_ccv_params_ip.u1_sei_ccv_params_present_flag =
+                            (UWORD8)ps_app_ctxt->u4_sei_ccv_params_present_flag;
+
+    s_sei_ccv_params_ip.u1_ccv_cancel_flag = (UWORD8)ps_app_ctxt->u4_ccv_cancel_flag;
+    s_sei_ccv_params_ip.u1_ccv_persistence_flag =
+                            (UWORD8)ps_app_ctxt->u4_ccv_persistence_flag;
+    s_sei_ccv_params_ip.u1_ccv_primaries_present_flag =
+                            (UWORD8)ps_app_ctxt->u4_ccv_primaries_present_flag;
+    s_sei_ccv_params_ip.u1_ccv_min_luminance_value_present_flag =
+                            (UWORD8)ps_app_ctxt->u4_ccv_min_luminance_value_present_flag;
+    s_sei_ccv_params_ip.u1_ccv_max_luminance_value_present_flag =
+                            (UWORD8)ps_app_ctxt->u4_ccv_max_luminance_value_present_flag;
+    s_sei_ccv_params_ip.u1_ccv_avg_luminance_value_present_flag =
+                            (UWORD8)ps_app_ctxt->u4_ccv_avg_luminance_value_present_flag;
+    s_sei_ccv_params_ip.u1_ccv_reserved_zero_2bits =
+                            (UWORD8)ps_app_ctxt->u4_ccv_reserved_zero_2bits;
+
+    for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
+    {
+        s_sei_ccv_params_ip.ai4_ccv_primaries_x[i4_count] =
+                            ps_app_ctxt->ai4_ccv_primaries_x[i4_count];
+        s_sei_ccv_params_ip.ai4_ccv_primaries_y[i4_count] =
+                            ps_app_ctxt->ai4_ccv_primaries_y[i4_count];
+    }
+
+    s_sei_ccv_params_ip.u4_ccv_min_luminance_value = ps_app_ctxt->u4_ccv_min_luminance_value;
+    s_sei_ccv_params_ip.u4_ccv_max_luminance_value = ps_app_ctxt->u4_ccv_max_luminance_value;
+    s_sei_ccv_params_ip.u4_ccv_avg_luminance_value = ps_app_ctxt->u4_ccv_avg_luminance_value;
+
+    s_sei_ccv_params_ip.u4_timestamp_high  =   u4_timestamp_high;
+    s_sei_ccv_params_ip.u4_timestamp_low   =   u4_timestamp_low;
+
+    s_sei_ccv_params_ip.u4_size = sizeof(ih264e_ctl_set_sei_ccv_params_ip_t);
+    s_sei_ccv_params_op.u4_size = sizeof(ih264e_ctl_set_sei_ccv_params_op_t);
+
+    status = ih264e_api_function(ps_app_ctxt->ps_enc, &s_sei_ccv_params_ip,
+                                 &s_sei_ccv_params_op);
+    if(status != IV_SUCCESS)
+    {
+        printf("Unable to set sei ccv params = 0x%x\n",
+                s_sei_ccv_params_op.u4_error_code);
+    }
+    return;
+}
+
 #define PEAK_WINDOW_SIZE    8
 
 void synchronous_encode(iv_obj_t *ps_enc, app_ctxt_t *ps_app_ctxt)
@@ -1621,6 +1841,62 @@
 
     while(1)
     {
+        IV_PICTURE_CODING_TYPE_T  e_frame_type;
+        WORD32 i4_count;
+
+        /* Default sei params values*/
+        ps_app_ctxt->u4_sei_mdcv_params_present_flag = 1;
+        if(1 == ps_app_ctxt->u4_sei_mdcv_params_present_flag)
+        {
+            for(i4_count = 0; i4_count < NUM_SEI_MDCV_PRIMARIES; i4_count++)
+            {
+                ps_app_ctxt->au4_display_primaries_x[i4_count] = 0;
+                ps_app_ctxt->au4_display_primaries_y[i4_count] = 0;
+            }
+            ps_app_ctxt->u4_white_point_x = 0;
+            ps_app_ctxt->u4_white_point_y = 0;
+            ps_app_ctxt->u4_max_display_mastering_luminance = DEFAULT_MAX_DISPLAY_MASTERING_LUMINANCE;
+            ps_app_ctxt->u4_min_display_mastering_luminance = DEFAULT_MIN_DISPLAY_MASTERING_LUMINANCE;
+            set_sei_mdcv_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
+        }
+
+        ps_app_ctxt->u4_sei_cll_params_present_flag = 1;
+        if(1 == ps_app_ctxt->u4_sei_cll_params_present_flag)
+        {
+            ps_app_ctxt->u4_max_content_light_level = 0;
+            ps_app_ctxt->u4_max_pic_average_light_level = 0;
+            set_sei_cll_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
+        }
+
+        ps_app_ctxt->u4_sei_ave_params_present_flag = 1;
+        if(1 == ps_app_ctxt->u4_sei_ave_params_present_flag)
+        {
+            ps_app_ctxt->u4_ambient_illuminance = 1;
+            ps_app_ctxt->u4_ambient_light_x = 0;
+            ps_app_ctxt->u4_ambient_light_y = 0;
+            set_sei_ave_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
+        }
+
+        ps_app_ctxt->u4_sei_ccv_params_present_flag = 1;
+        if(1 == ps_app_ctxt->u4_sei_ccv_params_present_flag)
+        {
+            ps_app_ctxt->u4_ccv_cancel_flag = 0;
+            ps_app_ctxt->u4_ccv_persistence_flag = 1;
+            ps_app_ctxt->u4_ccv_primaries_present_flag = 1;
+            ps_app_ctxt->u4_ccv_min_luminance_value_present_flag = 1;
+            ps_app_ctxt->u4_ccv_max_luminance_value_present_flag = 1;
+            ps_app_ctxt->u4_ccv_avg_luminance_value_present_flag = 1;
+            ps_app_ctxt->u4_ccv_reserved_zero_2bits = 0;
+            for(i4_count = 0; i4_count < NUM_SEI_CCV_PRIMARIES; i4_count++)
+            {
+                ps_app_ctxt->ai4_ccv_primaries_x[i4_count] = 1;
+                ps_app_ctxt->ai4_ccv_primaries_y[i4_count] = 1;
+            }
+            ps_app_ctxt->u4_ccv_min_luminance_value = 1;
+            ps_app_ctxt->u4_ccv_max_luminance_value = 1;
+            ps_app_ctxt->u4_ccv_avg_luminance_value = 1;
+            set_sei_ccv_params(ps_app_ctxt, u4_timestamp_low, u4_timestamp_high);
+        }
 
         /******************************************************************************/
         /****************** Input Initialization **************************************/
diff --git a/test/encoder/output.c b/test/encoder/output.c
index 8438869..8d16400 100644
--- a/test/encoder/output.c
+++ b/test/encoder/output.c
@@ -31,6 +31,7 @@
 /* User include files */
 
 #include "ih264_typedefs.h"
+#include "ih264_defs.h"
 #include "iv2.h"
 #include "ive2.h"
 #include "ih264e.h"
diff --git a/test/encoder/psnr.c b/test/encoder/psnr.c
index 6913cb3..d5a953c 100644
--- a/test/encoder/psnr.c
+++ b/test/encoder/psnr.c
@@ -29,6 +29,7 @@
 
 /* User include files */
 #include "ih264_typedefs.h"
+#include "ih264_defs.h"
 #include "iv2.h"
 #include "ive2.h"
 #include "ih264e.h"
diff --git a/test/encoder/recon.c b/test/encoder/recon.c
index d177a62..89cfe40 100644
--- a/test/encoder/recon.c
+++ b/test/encoder/recon.c
@@ -31,6 +31,7 @@
 /* User include files */
 
 #include "ih264_typedefs.h"
+#include "ih264_defs.h"
 #include "iv2.h"
 #include "ive2.h"
 #include "ih264e.h"