glib free and cpp based libmix

Change-Id: Id4bbc51c59145babb8088ad0973a3b628b4b11cd
Signed-off-by: Liu, Shuo <shuo.liu@intel.com>
diff --git a/Android.mk b/Android.mk
index 3b5ef37..135c4c4 100644
--- a/Android.mk
+++ b/Android.mk
@@ -3,8 +3,6 @@
 
 VENDORS_INTEL_MRST_LIBMIX_ROOT := $(LOCAL_PATH)
 
-GLIB_TOP := hardware/intel/glib
-
 include $(VENDORS_INTEL_MRST_LIBMIX_ROOT)/mix_common/src/Android.mk
 #include $(VENDORS_INTEL_MRST_LIBMIX_ROOT)/mix_audio/src/Android.mk
 include $(VENDORS_INTEL_MRST_LIBMIX_ROOT)/mix_video/src/Android.mk
diff --git a/mix_common/autogen.sh b/mix_common/autogen.sh
deleted file mode 100644
index e123d49..0000000
--- a/mix_common/autogen.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-package=MixCommon
-
-aclocal -I m4/ $ACLOCAL_FLAGS || exit 1
-libtoolize --copy --force || exit 1
-autoheader -v || exit 1
-autoconf -v || exit 1
-automake -a -c -v || exit 1
-#autoreconf -v --install
diff --git a/mix_common/src/Android.mk b/mix_common/src/Android.mk
index 4042f95..3dffe11 100644
--- a/mix_common/src/Android.mk
+++ b/mix_common/src/Android.mk
@@ -4,23 +4,28 @@
 LOCAL_SRC_FILES :=		\
 	mixlog.cpp		\
 	mixparams.cpp		\
-	mixdrmparams.cpp
+	mixdrmparams.cpp		\
+	j_slist.cpp		\
+	j_queue.cpp		\
+	j_hashtable.cpp
+
 
 LOCAL_C_INCLUDES :=		\
-	$(LOCAL_PATH)		\
-	$(GLIB_TOP)			\
-	$(GLIB_TOP)/android	\
-	$(GLIB_TOP)/glib
+	$(LOCAL_PATH)
+
+LOCAL_SHARED_LIBRARIES :=	\
+	libcutils
 
 LOCAL_CFLAGS := -DANDROID
 
-LOCAL_SHARED_LIBRARIES := 	\
-	libglib-2.0
-#	libgmodule-2.0
 
 LOCAL_COPY_HEADERS_TO := libmixcommon
 
 LOCAL_COPY_HEADERS :=		\
+	mixtypes.h		\
+	j_slist.h		\
+	j_queue.h		\
+	j_hashtable.h	\
 	mixlog.h		\
 	mixresult.h		\
 	mixparams.h		\
diff --git a/mix_common/src/mixdrmparams.cpp b/mix_common/src/mixdrmparams.cpp
index c75b184..ae0ec80 100644
--- a/mix_common/src/mixdrmparams.cpp
+++ b/mix_common/src/mixdrmparams.cpp
@@ -1,6 +1,6 @@
-/* 
+/*
  INTEL CONFIDENTIAL
- Copyright 2009 Intel Corporation All Rights Reserved. 
+ Copyright 2009 Intel Corporation All Rights Reserved.
  The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
 
  No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
@@ -23,22 +23,22 @@
 }
 
 MixDrmParams *mix_drmparams_new(void) {
-	return new MixDrmParams();
+    return new MixDrmParams();
 }
 
-MixDrmParams *mix_drmparams_ref(MixDrmParams *mix) { 
-	return (MixDrmParams*)mix_params_ref(MIX_PARAMS(mix)); 
+MixDrmParams *mix_drmparams_ref(MixDrmParams *mix) {
+    return (MixDrmParams*)mix_params_ref(MIX_PARAMS(mix));
 }
 
 MixParams * MixDrmParams::dup () const {
-	MixParams* dup = new MixDrmParams();
-	if (NULL != dup) {
-		if (FALSE == copy(dup)) {
-			dup->Unref();
-			dup = NULL;
-		}
-	}
-	return dup;
+    MixParams* dup = new MixDrmParams();
+    if (NULL != dup) {
+        if (FALSE == copy(dup)) {
+            dup->Unref();
+            dup = NULL;
+        }
+    }
+    return dup;
 }
 
 
diff --git a/mix_common/src/mixdrmparams.h b/mix_common/src/mixdrmparams.h
index 7dc7512..9bbb2d0 100644
--- a/mix_common/src/mixdrmparams.h
+++ b/mix_common/src/mixdrmparams.h
@@ -1,6 +1,6 @@
-/* 
+/*
  INTEL CONFIDENTIAL
- Copyright 2009 Intel Corporation All Rights Reserved. 
+ Copyright 2009 Intel Corporation All Rights Reserved.
  The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
 
  No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
@@ -21,7 +21,7 @@
 /**
  * MIX_IS_DRMPARAMS:
  * @obj: an object.
- * 
+ *
  * Checks if the given object is an instance of #MixParams
  */
 #define MIX_IS_DRMPARAMS(obj) (NULL != MIX_DRMPARAMS(obj))
@@ -33,15 +33,15 @@
  */
 class MixDrmParams : public MixParams {
 public:
-  MixDrmParams();
-  virtual ~MixDrmParams();
-  virtual MixParams * dup () const;
+    MixDrmParams();
+    virtual ~MixDrmParams();
+    virtual MixParams * dup () const;
 };
 
 /**
  * mix_drmparams_new:
  * @returns: A newly allocated instance of #MixDrmParams
- * 
+ *
  * Use this method to create new instance of #MixDrmParams
  */
 MixDrmParams *mix_drmparams_new(void);
@@ -50,7 +50,7 @@
  * mix_drmparams_ref:
  * @mix: object to add reference
  * @returns: the MixDrmParams instance where reference count has been increased.
- * 
+ *
  * Add reference count.
  */
 MixDrmParams *mix_drmparams_ref(MixDrmParams *mix);
@@ -58,7 +58,7 @@
 /**
  * mix_drmparams_unref:
  * @obj: object to unref.
- * 
+ *
  * Decrement reference count of the object.
  */
 #define mix_drmparams_unref(obj) mix_params_unref(MIX_PARAMS(obj))
diff --git a/mix_common/src/mixlog.cpp b/mix_common/src/mixlog.cpp
index bef6a24..cad5c5a 100644
--- a/mix_common/src/mixlog.cpp
+++ b/mix_common/src/mixlog.cpp
@@ -10,7 +10,9 @@
 #include "mixlog.h"
 
 #ifndef ANDROID
-#include <glib.h>
+#ifdef MIX_LOG_USE_HT
+#include "j_hashtable.h"
+#endif
 #endif
 
 #define MIX_DELOG_COMPS "MIX_DELOG_COMPS"
@@ -26,234 +28,239 @@
 static GStaticMutex g_mutex = G_STATIC_MUTEX_INIT;
 
 #ifdef MIX_LOG_USE_HT
-static GHashTable *g_defile_ht = NULL, *g_defunc_ht = NULL, *g_decom_ht = NULL;
-static gint g_mix_log_level = MIX_LOG_LEVEL_VERBOSE;
-static gint g_refcount = 0;
+static JHashTable *g_defile_ht = NULL, *g_defunc_ht = NULL, *g_decom_ht = NULL;
+static int g_mix_log_level = MIX_LOG_LEVEL_VERBOSE;
+static int g_refcount = 0;
 
-#define mix_log_destroy_ht(ht) if(ht) { g_hash_table_destroy(ht); ht = NULL; }
+#define mix_log_destroy_ht(ht) if(ht) { \
+	if (ht == NULL || ht->ref_count <= 0) return; \
+	j_hash_table_remove_all (ht); \
+	j_hash_table_unref (ht); \
+	ht = NULL; }
 
-void mix_log_get_ht(GHashTable **ht, const gchar *var) {
+void mix_log_get_ht(JHashTable **ht, const char *var) {
 
-	const char *delog_list = NULL;
-	char *item = NULL;
-	if (!ht || !var) {
-		return;
-	}
+    const char *delog_list = NULL;
+    char *item = NULL;
+    if (!ht || !var) {
+        return;
+    }
 
-	delog_list = g_getenv(var);
-	if (!delog_list) {
-		return;
-	}
+    delog_list = g_getenv(var);
+    if (!delog_list) {
+        return;
+    }
 
-	if (*ht == NULL) {
-		*ht = g_hash_table_new(g_str_hash, g_str_equal);
-		if (*ht == NULL) {
-			return;
-		}
-	}
+    if (*ht == NULL) {
+        *ht = j_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
+        if (*ht == NULL) {
+            return;
+        }
+    }
 
-	item = strtok((char *) delog_list, MIX_DELOG_DELIMITERS);
-	while (item != NULL) {
-		g_hash_table_insert(*ht, item, "true");
-		item = strtok(NULL, MIX_DELOG_DELIMITERS);
-	}
+    item = strtok((char *) delog_list, MIX_DELOG_DELIMITERS);
+    while (item != NULL) {
+        j_hash_table_insert(*ht, item, "true");
+        item = strtok(NULL, MIX_DELOG_DELIMITERS);
+    }
 }
 
 void mix_log_initialize_func() {
 
-	const gchar *mix_log_level = NULL;
-	g_static_mutex_lock(&g_mutex);
+    const char *mix_log_level = NULL;
+    g_static_mutex_lock(&g_mutex);
 
-	if (g_refcount == 0) {
+    if (g_refcount == 0) {
 
-		mix_log_level = g_getenv(MIX_LOG_LEVEL);
-		if (mix_log_level) {
-			g_mix_log_level = atoi(mix_log_level);
-		}
+        mix_log_level = g_getenv(MIX_LOG_LEVEL);
+        if (mix_log_level) {
+            g_mix_log_level = atoi(mix_log_level);
+        }
 
-		mix_log_get_ht(&g_decom_ht, MIX_DELOG_COMPS);
-		mix_log_get_ht(&g_defile_ht, MIX_DELOG_FILES);
-		mix_log_get_ht(&g_defunc_ht, MIX_DELOG_FUNCS);
-	}
+        mix_log_get_ht(&g_decom_ht, MIX_DELOG_COMPS);
+        mix_log_get_ht(&g_defile_ht, MIX_DELOG_FILES);
+        mix_log_get_ht(&g_defunc_ht, MIX_DELOG_FUNCS);
+    }
 
-	g_refcount++;
+    g_refcount++;
 
-	g_static_mutex_unlock(&g_mutex);
+    g_static_mutex_unlock(&g_mutex);
 }
 
 void mix_log_finalize_func() {
 
-	g_static_mutex_lock(&g_mutex);
+    g_static_mutex_lock(&g_mutex);
 
-	g_refcount--;
+    g_refcount--;
 
-	if (g_refcount == 0) {
-		mix_log_destroy_ht(g_decom_ht);
-		mix_log_destroy_ht(g_defile_ht);
-		mix_log_destroy_ht(g_defunc_ht);
+    if (g_refcount == 0) {
+        mix_log_destroy_ht(g_decom_ht);
+        mix_log_destroy_ht(g_defile_ht);
+        mix_log_destroy_ht(g_defunc_ht);
 
-		g_mix_log_level = MIX_LOG_LEVEL_VERBOSE;
-	}
+        g_mix_log_level = MIX_LOG_LEVEL_VERBOSE;
+    }
 
-	if (g_refcount < 0) {
-		g_refcount = 0;
-	}
+    if (g_refcount < 0) {
+        g_refcount = 0;
+    }
 
-	g_static_mutex_unlock(&g_mutex);
+    g_static_mutex_unlock(&g_mutex);
 }
 
-void mix_log_func(const gchar* comp, gint level, const gchar *file,
-		const gchar *func, gint line, const gchar *format, ...) {
+void mix_log_func(const char* comp, int level, const char *file,
+                  const char *func, int line, const char *format, ...) {
 
-	va_list args;
-	static gchar* loglevel[4] = {"**ERROR", "*WARNING", "INFO", "VERBOSE"};
+    va_list args;
+    static char* loglevel[4] = {"**ERROR", "*WARNING", "INFO", "VERBOSE"};
 
-	if (!format) {
-		return;
-	}
+    if (!format) {
+        return;
+    }
 
-	g_static_mutex_lock(&g_mutex);
+    g_static_mutex_lock(&g_mutex);
 
-	if (level > g_mix_log_level) {
-		goto exit;
-	}
+    if (level > g_mix_log_level) {
+        goto exit;
+    }
 
-	if (g_decom_ht) {
-		if (g_hash_table_lookup(g_decom_ht, comp)) {
-			goto exit;
-		}
-	}
+    if (g_decom_ht) {
+        if (j_hash_table_lookup(g_decom_ht, comp)) {
+            goto exit;
+        }
+    }
 
-	if (g_defile_ht) {
-		if (g_hash_table_lookup(g_defile_ht, file)) {
-			goto exit;
-		}
-	}
+    if (g_defile_ht) {
+        if (j_hash_table_lookup(g_defile_ht, file)) {
+            goto exit;
+        }
+    }
 
-	if (g_defunc_ht) {
-		if (g_hash_table_lookup(g_defunc_ht, func)) {
-			goto exit;
-		}
-	}
+    if (g_defunc_ht) {
+        if (j_hash_table_lookup(g_defunc_ht, func)) {
+            goto exit;
+        }
+    }
 
-	if(level > MIX_LOG_LEVEL_VERBOSE) {
-		level = MIX_LOG_LEVEL_VERBOSE;
-	}
-	if(level < MIX_LOG_LEVEL_ERROR) {
-		level = MIX_LOG_LEVEL_ERROR;
-	}
+    if (level > MIX_LOG_LEVEL_VERBOSE) {
+        level = MIX_LOG_LEVEL_VERBOSE;
+    }
+    if (level < MIX_LOG_LEVEL_ERROR) {
+        level = MIX_LOG_LEVEL_ERROR;
+    }
 
-	g_print("%s : %s : %s : ", loglevel[level - 1], file, func);
+    g_print("%s : %s : %s : ", loglevel[level - 1], file, func);
 
-	va_start(args, format);
-	g_vprintf(format, args);
-	va_end(args);
+    va_start(args, format);
+    g_vprintf(format, args);
+    va_end(args);
 
-	exit: g_static_mutex_unlock(&g_mutex);
+exit:
+    g_static_mutex_unlock(&g_mutex);
 }
 
 #else /* MIX_LOG_USE_HT */
 
-gboolean mix_shall_delog(const gchar *name, const gchar *var) {
+bool mix_shall_delog(const char *name, const char *var) {
 
-	const char *delog_list = NULL;
-	char *item = NULL;
-	gboolean delog = FALSE;
+    const char *delog_list = NULL;
+    char *item = NULL;
+    bool delog = FALSE;
 
-	if (!name || !var) {
-		return delog;
-	}
+    if (!name || !var) {
+        return delog;
+    }
 
-	delog_list = g_getenv(var);
-	if (!delog_list) {
-		return delog;
-	}
+    delog_list = g_getenv(var);
+    if (!delog_list) {
+        return delog;
+    }
 
-	item = strtok((char *) delog_list, MIX_DELOG_DELIMITERS);
-	while (item != NULL) {
-		if (strcmp(item, name) == 0) {
-			delog = TRUE;
-			break;
-		}
-		item = strtok(NULL, MIX_DELOG_DELIMITERS);
-	}
+    item = strtok((char *) delog_list, MIX_DELOG_DELIMITERS);
+    while (item != NULL) {
+        if (strcmp(item, name) == 0) {
+            delog = TRUE;
+            break;
+        }
+        item = strtok(NULL, MIX_DELOG_DELIMITERS);
+    }
 
-	return delog;
+    return delog;
 }
 
-gboolean mix_log_enabled() {
+bool mix_log_enabled() {
 
-	const char *value = NULL;
-	value = g_getenv(MIX_LOG_ENABLE);
-	if(!value) {
-		return FALSE;
-	}
-	
-	if(value[0] == '0') {
-		return FALSE;
-	}
-	return TRUE;
+    const char *value = NULL;
+    value = g_getenv(MIX_LOG_ENABLE);
+    if (!value) {
+        return FALSE;
+    }
+
+    if (value[0] == '0') {
+        return FALSE;
+    }
+    return TRUE;
 }
 
-void mix_log_func(const gchar* comp, gint level, const gchar *file,
-		const gchar *func, gint line, const gchar *format, ...) {
+void mix_log_func(const char* comp, int level, const char *file,
+                  const char *func, int line, const char *format, ...) {
 
-	va_list args;
-	static gchar* loglevel[4] = { "**ERROR", "*WARNING", "INFO", "VERBOSE" };
+    va_list args;
+    static char* loglevel[4] = { "**ERROR", "*WARNING", "INFO", "VERBOSE" };
 
-	const gchar *env_mix_log_level = NULL;
-	gint mix_log_level_threhold = MIX_LOG_LEVEL_VERBOSE;
+    const char *env_mix_log_level = NULL;
+    int mix_log_level_threhold = MIX_LOG_LEVEL_VERBOSE;
 
-	if(!mix_log_enabled()) {
-		return;
-	}
+    if (!mix_log_enabled()) {
+        return;
+    }
 
-	if (!format) {
-		return;
-	}
+    if (!format) {
+        return;
+    }
 
-	g_static_mutex_lock(&g_mutex);
+    g_static_mutex_lock(&g_mutex);
 
-	/* log level */
-	env_mix_log_level = g_getenv(MIX_LOG_LEVEL);
-	if (env_mix_log_level) {
-		mix_log_level_threhold = atoi(env_mix_log_level);
-	}
+    /* log level */
+    env_mix_log_level = g_getenv(MIX_LOG_LEVEL);
+    if (env_mix_log_level) {
+        mix_log_level_threhold = atoi(env_mix_log_level);
+    }
 
-	if (level > mix_log_level_threhold) {
-		goto exit;
-	}
+    if (level > mix_log_level_threhold) {
+        goto exit;
+    }
 
-	/* component */
-	if (mix_shall_delog(comp, MIX_DELOG_COMPS)) {
-		goto exit;
-	}
+    /* component */
+    if (mix_shall_delog(comp, MIX_DELOG_COMPS)) {
+        goto exit;
+    }
 
-	/* files */
-	if (mix_shall_delog(file, MIX_DELOG_FILES)) {
-		goto exit;
-	}
+    /* files */
+    if (mix_shall_delog(file, MIX_DELOG_FILES)) {
+        goto exit;
+    }
 
-	/* functions */
-	if (mix_shall_delog(func, MIX_DELOG_FUNCS)) {
-		goto exit;
-	}
+    /* functions */
+    if (mix_shall_delog(func, MIX_DELOG_FUNCS)) {
+        goto exit;
+    }
 
-	if (level > MIX_LOG_LEVEL_VERBOSE) {
-		level = MIX_LOG_LEVEL_VERBOSE;
-	}
-	if (level < MIX_LOG_LEVEL_ERROR) {
-		level = MIX_LOG_LEVEL_ERROR;
-	}
+    if (level > MIX_LOG_LEVEL_VERBOSE) {
+        level = MIX_LOG_LEVEL_VERBOSE;
+    }
+    if (level < MIX_LOG_LEVEL_ERROR) {
+        level = MIX_LOG_LEVEL_ERROR;
+    }
 
-	g_print("%s : %s : %s : ", loglevel[level - 1], file, func);
+    g_print("%s : %s : %s : ", loglevel[level - 1], file, func);
 
-	va_start(args, format);
-	g_vprintf(format, args);
-	va_end(args);
+    va_start(args, format);
+    g_vprintf(format, args);
+    va_end(args);
 
 exit:
-	g_static_mutex_unlock(&g_mutex);
+    g_static_mutex_unlock(&g_mutex);
 }
 
 
diff --git a/mix_common/src/mixlog.h b/mix_common/src/mixlog.h
index dd93046..bf298dc 100644
--- a/mix_common/src/mixlog.h
+++ b/mix_common/src/mixlog.h
@@ -6,14 +6,15 @@
  No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
  */
 
-#include <glib.h>
+#include "mixtypes.h"
 
 #ifndef __MIX_LOG_H__
 #define __MIX_LOG_H__
 
 /* Warning: don't call these functions */
-void mix_log_func(const gchar* comp, gint level, const gchar *file,
-		const gchar *func, gint line, const gchar *format, ...);
+void mix_log_func(
+    const char* comp, int level, const char *file,
+    const char *func, int line, const char *format, ...);
 
 /* Components */
 #define MIX_VIDEO_COMP 		"mixvideo"
diff --git a/mix_common/src/mixparams.cpp b/mix_common/src/mixparams.cpp
index 6489339..3fff640 100644
--- a/mix_common/src/mixparams.cpp
+++ b/mix_common/src/mixparams.cpp
@@ -1,6 +1,6 @@
-/* 
+/*
  INTEL CONFIDENTIAL
- Copyright 2009 Intel Corporation All Rights Reserved. 
+ Copyright 2009 Intel Corporation All Rights Reserved.
  The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
 
  No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
@@ -16,112 +16,111 @@
 #endif
 
 #include "mixparams.h"
+#include <cutils/atomic.h>
 
 
 #define DEBUG_REFCOUNT
 
 MixParams::MixParams()
-	:ref_count(1)
-	,_reserved(NULL) {
+        :ref_count(1)
+        ,_reserved(NULL) {
 }
 
 MixParams::~MixParams() {
-	finalize();
+    finalize();
 }
 
 MixParams* MixParams::Ref() {
-	this->ref_count++;
-	return this;
+    this->ref_count++;
+    return this;
 }
 
 void MixParams::Unref() {
-	this->ref_count--;
-	if (0 == this->ref_count) {
-		delete this;
-	}
+    this->ref_count--;
+    if (0 == this->ref_count) {
+        delete this;
+    }
 }
 
 MixParams* MixParams::dup() const {
-	MixParams *ret = new MixParams();
-	if (FALSE != copy(ret)) {
-		return ret;
-	}
-	return NULL;
+    MixParams *ret = new MixParams();
+    if (FALSE != copy(ret)) {
+        return ret;
+    }
+    return NULL;
 }
 
-gboolean MixParams::copy(MixParams* target) const {
-	gboolean ret =  FALSE;
-	if ( NULL != target) {
-		return TRUE;
-	}
-	return ret;
+bool MixParams::copy(MixParams* target) const {
+    bool ret =  FALSE;
+    if ( NULL != target) {
+        return TRUE;
+    }
+    return ret;
 }
 
 void MixParams::finalize() {
 }
 
-gboolean MixParams::equal(MixParams *obj) const {
-	gboolean ret =  FALSE;
-	if ( NULL != obj) {
-		return TRUE;
-	}
-	return ret;
+bool MixParams::equal(MixParams *obj) const {
+    bool ret =  FALSE;
+    if ( NULL != obj) {
+        return TRUE;
+    }
+    return ret;
 }
 
 MixParams* mix_params_new () {
-	/* we don't support dynamic types because they really aren't useful,*/
-	/* and could cause ref_count problems */
-	return new MixParams();
+    /* we don't support dynamic types because they really aren't useful,*/
+    /* and could cause ref_count problems */
+    return new MixParams();
 }
 
-gboolean mix_params_copy (MixParams *target, const MixParams *src) {
-	if ( NULL != target && NULL != src) {
-		return src->copy(target);
-	} else
-		return FALSE;
+bool mix_params_copy (MixParams *target, const MixParams *src) {
+    if ( NULL != target && NULL != src) {
+        return src->copy(target);
+    } else
+        return FALSE;
 }
 
 MixParams* mix_params_ref (MixParams *obj) {
-	if (NULL == obj)
-		return NULL;
-	return obj->Ref();
+    if (NULL == obj)
+        return NULL;
+    return obj->Ref();
 }
 
 void mix_params_unref(MixParams *obj) {
-	if (NULL != obj)
-		obj->Unref();
+    if (NULL != obj)
+        obj->Unref();
 }
 
 void mix_params_replace (MixParams **olddata, MixParams *newdata) {
-	if (NULL == olddata)
-		return;
-	MixParams *olddata_val =
-		reinterpret_cast<MixParams*>(g_atomic_pointer_get((gpointer *) olddata));
-	if (olddata_val == newdata)
-		return;
-	if (NULL != newdata)
-		newdata->Ref();
-	while (!g_atomic_pointer_compare_and_exchange ((gpointer *) olddata,
-		olddata_val, newdata)) {
-		olddata_val =
-			reinterpret_cast<MixParams*>(g_atomic_pointer_get ((gpointer *) olddata));
-	}
-	if (NULL != olddata_val)
-		olddata_val->Unref();
+    if (NULL == olddata)
+        return;
+    MixParams *olddata_val = *olddata;
+    if (olddata_val == newdata)
+        return;
+    if (NULL != newdata)
+        newdata->Ref();
+    while (!android_atomic_cmpxchg (
+                (int32_t)olddata_val,(int32_t)newdata, (int32_t *) (*olddata))) {
+        olddata_val = *olddata;
+    }
+    if (NULL != olddata_val)
+        olddata_val->Unref();
 }
 
 MixParams * mix_params_dup(const MixParams *obj) {
-	if (NULL != obj) {
-		return obj->dup();
-	} else {
-		return NULL;
-	}
+    if (NULL != obj) {
+        return obj->dup();
+    } else {
+        return NULL;
+    }
 }
 
-gboolean mix_params_equal (MixParams *first, MixParams *second) {
-	if (NULL != first && NULL != second)
-		return first->equal(second);
-	else
-		return FALSE;
+bool mix_params_equal (MixParams *first, MixParams *second) {
+    if (NULL != first && NULL != second)
+        return first->equal(second);
+    else
+        return FALSE;
 }
 
diff --git a/mix_common/src/mixparams.h b/mix_common/src/mixparams.h
index c1a19a5..f3395f4 100644
--- a/mix_common/src/mixparams.h
+++ b/mix_common/src/mixparams.h
@@ -1,6 +1,6 @@
-/* 
+/*
  INTEL CONFIDENTIAL
- Copyright 2009 Intel Corporation All Rights Reserved. 
+ Copyright 2009 Intel Corporation All Rights Reserved.
  The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
 
  No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
@@ -9,7 +9,7 @@
 #ifndef __MIX_PARAMS_H__
 #define __MIX_PARAMS_H__
 
-#include <glib-object.h>
+#include "mixtypes.h"
 
 #define MIX_PARAMS(obj)          (reinterpret_cast<MixParams*> ((obj)))
 #define MIX_PARAMS_CAST(obj)     ((MixParams*)(obj))
@@ -32,73 +32,69 @@
 class MixParams {
 
 public:
-	MixParams();
-	virtual ~MixParams();
-	MixParams* Ref();
-	void Unref();
-	gint GetRefCount() { return ref_count;}
-  
-public:
-	/**
-	* MixParamsDupFunction:
-	* @obj: Params to duplicate
-	* @returns: reference to cloned instance. 
-	*
-	* Virtual function prototype for methods to create duplicate of instance.
-	*
-	*/
-	virtual MixParams * dup () const;
-
-	/**
-	* MixParamsCopyFunction:
-	* @target: target of the copy
-	* @src: source of the copy
-	* @returns: boolean indicates if copy is successful.
-	*
-	* Virtual function prototype for methods to create copies of instance.
-	*
-	*/
-	virtual gboolean copy(MixParams* target) const;
-
-	/**
-	* MixParamsFinalizeFunction:
-	* @obj: Params to finalize
-	*
-	* Virtual function prototype for methods to free ressources used by
-	* object.
-	*/
-	virtual void finalize ();
-
-	/**
-	* MixParamsEqualsFunction:
-	* @first: first object in the comparison
-	* @second: second object in the comparison
-	*
-	* Virtual function prototype for methods to compare 2 objects and check if they are equal.
-	*/
-	virtual gboolean equal (MixParams *obj) const;
+    MixParams();
+    virtual ~MixParams();
+    MixParams* Ref();
+    void Unref();
+    int GetRefCount() {
+        return ref_count;
+    }
 
 public:
-	/*< public >*/
-	gint ref_count;
+    /**
+    * MixParamsDupFunction:
+    * @obj: Params to duplicate
+    * @returns: reference to cloned instance.
+    *
+    * Virtual function prototype for methods to create duplicate of instance.
+    *
+    */
+    virtual MixParams * dup () const;
 
-	/*< private >*/
-	gpointer _reserved; 
+    /**
+    * MixParamsCopyFunction:
+    * @target: target of the copy
+    * @src: source of the copy
+    * @returns: intean indicates if copy is successful.
+    *
+    * Virtual function prototype for methods to create copies of instance.
+    *
+    */
+    virtual bool copy(MixParams* target) const;
+
+    /**
+    * MixParamsFinalizeFunction:
+    * @obj: Params to finalize
+    *
+    * Virtual function prototype for methods to free ressources used by
+    * object.
+    */
+    virtual void finalize ();
+
+    /**
+    * MixParamsEqualsFunction:
+    * @first: first object in the comparison
+    * @second: second object in the comparison
+    *
+    * Virtual function prototype for methods to compare 2 objects and check if they are equal.
+    */
+    virtual bool equal (MixParams *obj) const;
+
+public:
+    /*< public >*/
+    int ref_count;
+
+    /*< private >*/
+    void* _reserved;
 
 };
 
-/**
- * mix_params_get_type:
- * @returns: type of this object.
- * 
- * Get type.
- */
-//GType mix_params_get_type(void);
+
 
 /**
  * mix_params_new:
  * @returns: return a newly allocated object.
- * 
+ *
  * Create new instance of the object.
  */
 MixParams* mix_params_new();
@@ -107,27 +103,27 @@
  * mix_params_copy:
  * @target: copy to target
  * @src: copy from source
- * @returns: boolean indicating if copy is successful.
- * 
+ * @returns: intean indicating if copy is successful.
+ *
  * Copy data from one instance to the other. This method internally invoked the #MixParams::copy method such that derived object will be copied correctly.
  */
-gboolean mix_params_copy(MixParams *target, const MixParams *src);
+bool mix_params_copy(MixParams *target, const MixParams *src);
 
 
-/** 
+/**
  * mix_params_ref:
  * @obj: a #MixParams object.
  * @returns: the object with reference count incremented.
- * 
+ *
  * Increment reference count.
  */
 MixParams* mix_params_ref(MixParams *obj);
 
 
-/** 
+/**
  * mix_params_unref:
  * @obj: a #MixParams object.
- * 
+ *
  * Decrement reference count.
  */
 void mix_params_unref  (MixParams *obj);
@@ -147,7 +143,7 @@
  * mix_params_dup:
  * @obj: #MixParams object to duplicate.
  * @returns: A newly allocated duplicate of the object, or NULL if failed.
- * 
+ *
  * Duplicate the given #MixParams and allocate a new instance. This method is chained up properly and derive object will be dupped properly.
  */
 MixParams *mix_params_dup(const MixParams *obj);
@@ -156,10 +152,10 @@
  * mix_params_equal:
  * @first: first object to compare
  * @second: second object to compare
- * @returns: boolean indicates if the 2 object contains same data.
- * 
+ * @returns: intean indicates if the 2 object contains same data.
+ *
  * Note that the parameter comparison compares the values that are hold inside the object, not for checking if the 2 pointers are of the same instance.
  */
-gboolean mix_params_equal(MixParams *first, MixParams *second);
+bool mix_params_equal(MixParams *first, MixParams *second);
 #endif
 
diff --git a/mix_common/src/mixresult.h b/mix_common/src/mixresult.h
index 0559bc2..e8325f7 100644
--- a/mix_common/src/mixresult.h
+++ b/mix_common/src/mixresult.h
@@ -1,18 +1,18 @@
 /*************************************************************************************
  * INTEL CONFIDENTIAL
- * Copyright 2008-2009 Intel Corporation All Rights Reserved. 
- * The source code contained or described herein and all documents related 
- * to the source code ("Material") are owned by Intel Corporation or its 
- * suppliers or licensors. Title to the Material remains with Intel 
- * Corporation or its suppliers and licensors. The Material contains trade 
- * secrets and proprietary and confidential information of Intel or its 
- * suppliers and licensors. The Material is protected by worldwide copyright 
- * and trade secret laws and treaty provisions. No part of the Material may 
- * be used, copied, reproduced, modified, published, uploaded, posted, 
- * transmitted, distributed, or disclosed in any way without Intel’s prior 
+ * Copyright 2008-2009 Intel Corporation All Rights Reserved.
+ * The source code contained or described herein and all documents related
+ * to the source code ("Material") are owned by Intel Corporation or its
+ * suppliers or licensors. Title to the Material remains with Intel
+ * Corporation or its suppliers and licensors. The Material contains trade
+ * secrets and proprietary and confidential information of Intel or its
+ * suppliers and licensors. The Material is protected by worldwide copyright
+ * and trade secret laws and treaty provisions. No part of the Material may
+ * be used, copied, reproduced, modified, published, uploaded, posted,
+ * transmitted, distributed, or disclosed in any way without Intel’s prior
  * express written permission.
  *
- * No license under any patent, copyright, trade secret or other intellectual 
+ * No license under any patent, copyright, trade secret or other intellectual
  * property right is granted to or conferred upon you by disclosure or delivery
  * of the Materials, either expressly, by implication, inducement, estoppel or
  * otherwise. Any license under such intellectual property rights must be express
@@ -22,69 +22,69 @@
 #ifndef MIX_RESULT_H
 #define MIX_RESULT_H
 
-#include <glib.h>
+#include "mixtypes.h"
 
-typedef gint32 MIX_RESULT;
+typedef int32 MIX_RESULT;
 
 #define MIX_SUCCEEDED(result_code) ((((MIX_RESULT)(result_code)) & 0x80000000) == 0)
 
 typedef enum {
-	/** General success */
-	MIX_RESULT_SUCCESS 				= 	(MIX_RESULT) 0x00000000,
-        MIX_RESULT_SUCCESS_CHG = (MIX_RESULT)0x00000001,
+    /** General success */
+    MIX_RESULT_SUCCESS 				= 	(MIX_RESULT) 0x00000000,
+    MIX_RESULT_SUCCESS_CHG = (MIX_RESULT)0x00000001,
 
-	/** Module specific success starting number */
+    /** Module specific success starting number */
 
-	/** Starting success number for Audio */
-	MIX_RESULT_SUCCESS_AUDIO_START			=	(MIX_RESULT) 0x00010000,
-	/** Starting success number for Video */
-	MIX_RESULT_SUCCESS_VIDEO_START			=	(MIX_RESULT) 0x00020000,
-	/** Starting success number for DRM */
-	MIX_RESULT_SUCCESS_DRM_START			= 	(MIX_RESULT) 0x00030000
+    /** Starting success number for Audio */
+    MIX_RESULT_SUCCESS_AUDIO_START			=	(MIX_RESULT) 0x00010000,
+    /** Starting success number for Video */
+    MIX_RESULT_SUCCESS_VIDEO_START			=	(MIX_RESULT) 0x00020000,
+    /** Starting success number for DRM */
+    MIX_RESULT_SUCCESS_DRM_START			= 	(MIX_RESULT) 0x00030000
 } MIX_SUCCESS_COMMON;
 
 typedef enum {
-	/** General failure */
-	MIX_RESULT_FAIL					= 	(MIX_RESULT) 0x80000000,
-	MIX_RESULT_NULL_PTR				=	(MIX_RESULT) 0x80000001,
-	MIX_RESULT_LPE_NOTAVAIL			= 	(MIX_RESULT) 0X80000002,
-	MIX_RESULT_DIRECT_NOTAVAIL		=	(MIX_RESULT) 0x80000003,
-	MIX_RESULT_NOT_SUPPORTED		=	(MIX_RESULT) 0x80000004,
-	MIX_RESULT_CONF_MISMATCH		=	(MIX_RESULT) 0x80000005,
-	MIX_RESULT_RESUME_NEEDED		=	(MIX_RESULT) 0x80000007,
-	MIX_RESULT_WRONGMODE			= 	(MIX_RESULT) 0x80000008,
-	MIX_RESULT_RESOURCES_NOTAVAIL = (MIX_RESULT)0x80000009,
-        MIX_RESULT_INVALID_PARAM = (MIX_RESULT)0x8000000a,
-        MIX_RESULT_ALREADY_INIT = (MIX_RESULT)0x8000000b,
-        MIX_RESULT_WRONG_STATE = (MIX_RESULT)0x8000000c,
-        MIX_RESULT_NOT_INIT = (MIX_RESULT)0x8000000d,
-        MIX_RESULT_NOT_CONFIGURED = (MIX_RESULT)0x8000000e,
-        MIX_RESULT_STREAM_NOTAVAIL = (MIX_RESULT)0x8000000f,
-        MIX_RESULT_CODEC_NOTAVAIL = (MIX_RESULT)0x80000010,
-        MIX_RESULT_CODEC_NOTSUPPORTED = (MIX_RESULT)0x80000011,
-        MIX_RESULT_INVALID_COUNT = (MIX_RESULT)0x80000012,
-        MIX_RESULT_NOT_ACP = (MIX_RESULT)0x80000013,
-	MIX_RESULT_INVALID_DECODE_MODE = (MIX_RESULT)0x80000014,
-        MIX_RESULT_INVALID_STREAM_NAME = (MIX_RESULT)0x80000015,
-        MIX_RESULT_NO_MEMORY = (MIX_RESULT)0x80000016,
-        MIX_RESULT_NEED_RETRY = (MIX_RESULT)0x80000017,
-        MIX_RESULT_SYSTEM_ERRNO = (MIX_RESULT)0x80000018,
-        MIX_RESULT_AM_REGISTER_FAIL = (MIX_RESULT)0x80000019,
-	MIX_RESULT_AM_UNREGISTER_FAIL = (MIX_RESULT)0x80000020,
-	MIX_RESULT_AM_NOTIFY_PAUSE_FAIL = (MIX_RESULT)0x80000021,
-	MIX_RESULT_AM_NOTIFY_RESUME_FAIL = (MIX_RESULT)0x80000022,
+    /** General failure */
+    MIX_RESULT_FAIL					= 	(MIX_RESULT) 0x80000000,
+    MIX_RESULT_NULL_PTR				=	(MIX_RESULT) 0x80000001,
+    MIX_RESULT_LPE_NOTAVAIL			= 	(MIX_RESULT) 0X80000002,
+    MIX_RESULT_DIRECT_NOTAVAIL		=	(MIX_RESULT) 0x80000003,
+    MIX_RESULT_NOT_SUPPORTED		=	(MIX_RESULT) 0x80000004,
+    MIX_RESULT_CONF_MISMATCH		=	(MIX_RESULT) 0x80000005,
+    MIX_RESULT_RESUME_NEEDED		=	(MIX_RESULT) 0x80000007,
+    MIX_RESULT_WRONGMODE			= 	(MIX_RESULT) 0x80000008,
+    MIX_RESULT_RESOURCES_NOTAVAIL = (MIX_RESULT)0x80000009,
+    MIX_RESULT_INVALID_PARAM = (MIX_RESULT)0x8000000a,
+    MIX_RESULT_ALREADY_INIT = (MIX_RESULT)0x8000000b,
+    MIX_RESULT_WRONG_STATE = (MIX_RESULT)0x8000000c,
+    MIX_RESULT_NOT_INIT = (MIX_RESULT)0x8000000d,
+    MIX_RESULT_NOT_CONFIGURED = (MIX_RESULT)0x8000000e,
+    MIX_RESULT_STREAM_NOTAVAIL = (MIX_RESULT)0x8000000f,
+    MIX_RESULT_CODEC_NOTAVAIL = (MIX_RESULT)0x80000010,
+    MIX_RESULT_CODEC_NOTSUPPORTED = (MIX_RESULT)0x80000011,
+    MIX_RESULT_INVALID_COUNT = (MIX_RESULT)0x80000012,
+    MIX_RESULT_NOT_ACP = (MIX_RESULT)0x80000013,
+    MIX_RESULT_INVALID_DECODE_MODE = (MIX_RESULT)0x80000014,
+    MIX_RESULT_INVALID_STREAM_NAME = (MIX_RESULT)0x80000015,
+    MIX_RESULT_NO_MEMORY = (MIX_RESULT)0x80000016,
+    MIX_RESULT_NEED_RETRY = (MIX_RESULT)0x80000017,
+    MIX_RESULT_SYSTEM_ERRNO = (MIX_RESULT)0x80000018,
+    MIX_RESULT_AM_REGISTER_FAIL = (MIX_RESULT)0x80000019,
+    MIX_RESULT_AM_UNREGISTER_FAIL = (MIX_RESULT)0x80000020,
+    MIX_RESULT_AM_NOTIFY_PAUSE_FAIL = (MIX_RESULT)0x80000021,
+    MIX_RESULT_AM_NOTIFY_RESUME_FAIL = (MIX_RESULT)0x80000022,
 
-	/** Module specific errors starting number */
+    /** Module specific errors starting number */
 
-	/** Starting error number for Audio */
-	MIX_RESULT_ERROR_AUDIO_START			=	(MIX_RESULT) 0x80010000,
-	/** Starting error number for Video */
-	MIX_RESULT_ERROR_VIDEO_START			=	(MIX_RESULT) 0x80020000,
-	/** Starting error number for DRM */
-	MIX_RESULT_ERROR_DRM_START				= 	(MIX_RESULT) 0x80030000
+    /** Starting error number for Audio */
+    MIX_RESULT_ERROR_AUDIO_START			=	(MIX_RESULT) 0x80010000,
+    /** Starting error number for Video */
+    MIX_RESULT_ERROR_VIDEO_START			=	(MIX_RESULT) 0x80020000,
+    /** Starting error number for DRM */
+    MIX_RESULT_ERROR_DRM_START				= 	(MIX_RESULT) 0x80030000
 } MIX_ERROR_COMMON;
 
-  /* New success code should be added just above this line */
+/* New success code should be added just above this line */
 //  MIX_RESULT_IAM_DISABLED,            /* 0x80000008 */
 //  MIX_RESULT_IAM_NOTAVAIL,            /* 0x80000009 */
 //  MIX_RESULT_IAM_REG_FAILED,          /* 0x8000000f */
diff --git a/mix_vbp/autogen.sh b/mix_vbp/autogen.sh
deleted file mode 100644
index ed2c536..0000000
--- a/mix_vbp/autogen.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#INTEL CONFIDENTIAL
-#Copyright 2009 Intel Corporation All Rights Reserved. 
-#The source code contained or described herein and all documents related to the source code ("Material") are owned by Intel Corporation or its suppliers or licensors. Title to the Material remains with Intel Corporation or its suppliers and licensors. The Material contains trade secrets and proprietary and confidential information of Intel or its suppliers and licensors. The Material is protected by worldwide copyright and trade secret laws and treaty provisions. No part of the Material may be used, copied, reproduced, modified, published, uploaded, posted, transmitted, distributed, or disclosed in any way without Intel’s prior express written permission.
-
-#No license under any patent, copyright, trade secret or other intellectual property right is granted to or conferred upon you by disclosure or delivery of the Materials, either expressly, by implication, inducement, estoppel or otherwise. Any license under such intellectual property rights must be express and approved by Intel in writing.
-#
-
-package=MIXVBP
-
-#Uncomment the follow line if building documentation using gtkdoc
-#gtkdocize --flavour no-tmpl || exit 1
-aclocal -I m4/ $ACLOCAL_FLAGS || exit 1
-libtoolize --copy --force || exit 1
-autoheader -v || exit 1
-autoconf -v || exit 1
-automake -a -c -v || exit 1
-
-echo "Now type ./configure to configure $package."
-exit 0
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/include/h264.h b/mix_vbp/viddec_fw/fw/codecs/h264/include/h264.h
index 4618532..1976567 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/include/h264.h
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/include/h264.h
@@ -60,7 +60,7 @@
 
 // Used to check whether the SEI RP is the only way for recovery (cisco contents)
 // This threshold will decide the interval of recovery even no error detected if no IDR during this time
-#define SEI_REC_CHECK_TH				8		
+#define SEI_REC_CHECK_TH				8
 
 //SPS
 #define MAX_NUM_SPS			32
@@ -69,7 +69,7 @@
 //PPS
 #define MAX_PIC_PARAMS		255
 #define MAX_NUM_REF_FRAMES	32
-#define MAX_QP				51 
+#define MAX_QP				51
 #define MAX_NUM_PPS			256
 
 #define PUT_FS_IDC_BITS(w)                                (w&0x1F)
@@ -115,14 +115,14 @@
 
 
 //// PIP
-typedef enum _pip_setting_t
-{
-  PIP_SCALER_DISABLED,
-  PIP_SCALE_FACTOR_1_BY_4,
-  PIP_SCALE_FACTOR_1_BY_2,
-  PIP_SCALER_INVALID,
+    typedef enum _pip_setting_t
+    {
+        PIP_SCALER_DISABLED,
+        PIP_SCALE_FACTOR_1_BY_4,
+        PIP_SCALE_FACTOR_1_BY_2,
+        PIP_SCALER_INVALID,
 
-} pip_setting_t;
+    } pip_setting_t;
 
 
 #ifdef VERBOSE
@@ -131,81 +131,81 @@
 //#define DEBUGGETBITS(args...)
 #endif
 
-/* status codes */
-typedef enum _h264_Status
-{
-    H264_STATUS_EOF          =  1,   // end of file
-    H264_STATUS_OK           =  0,   // no error
-    H264_STATUS_NO_MEM       =  2,   // out of memory
-    H264_STATUS_FILE_ERROR   =  3,   // file error
-    H264_STATUS_NOTSUPPORT   =  4,   // not supported mode
-    H264_STATUS_PARSE_ERROR  =  5,   // fail in parse MPEG-4 stream
-    H264_STATUS_ERROR        =  6,   // unknown/unspecified error
-    H264_NAL_ERROR,
-	H264_SPS_INVALID_PROFILE,
-	H264_SPS_INVALID_LEVEL,
-	H264_SPS_INVALID_SEQ_PARAM_ID,
-	H264_SPS_ERROR,
-	H264_PPS_INVALID_PIC_ID,
-	H264_PPS_INVALID_SEQ_ID,
-	H264_PPS_ERROR,
-	H264_SliceHeader_INVALID_MB,
-	H264_SliceHeader_ERROR,
-	H264_FRAME_DONE,
-	H264_SLICE_DONE,	
-	H264_STATUS_POLL_ONCE_ERROR,
-	H264_STATUS_DEC_MEMINIT_ERROR,	
-	H264_STATUS_NAL_UNIT_TYPE_ERROR,
-	H264_STATUS_SEI_ERROR,
-	H264_STATUS_SEI_DONE,
-} h264_Status;
+    /* status codes */
+    typedef enum _h264_Status
+    {
+        H264_STATUS_EOF          =  1,   // end of file
+        H264_STATUS_OK           =  0,   // no error
+        H264_STATUS_NO_MEM       =  2,   // out of memory
+        H264_STATUS_FILE_ERROR   =  3,   // file error
+        H264_STATUS_NOTSUPPORT   =  4,   // not supported mode
+        H264_STATUS_PARSE_ERROR  =  5,   // fail in parse MPEG-4 stream
+        H264_STATUS_ERROR        =  6,   // unknown/unspecified error
+        H264_NAL_ERROR,
+        H264_SPS_INVALID_PROFILE,
+        H264_SPS_INVALID_LEVEL,
+        H264_SPS_INVALID_SEQ_PARAM_ID,
+        H264_SPS_ERROR,
+        H264_PPS_INVALID_PIC_ID,
+        H264_PPS_INVALID_SEQ_ID,
+        H264_PPS_ERROR,
+        H264_SliceHeader_INVALID_MB,
+        H264_SliceHeader_ERROR,
+        H264_FRAME_DONE,
+        H264_SLICE_DONE,
+        H264_STATUS_POLL_ONCE_ERROR,
+        H264_STATUS_DEC_MEMINIT_ERROR,
+        H264_STATUS_NAL_UNIT_TYPE_ERROR,
+        H264_STATUS_SEI_ERROR,
+        H264_STATUS_SEI_DONE,
+    } h264_Status;
 
 
 
-typedef enum _picture_structure_t
-{
-   TOP_FIELD		= 1,
-   BOTTOM_FIELD		= 2,
-   FRAME			= 3,
-   INVALID			= 4
-} picture_structure_t;
+    typedef enum _picture_structure_t
+    {
+        TOP_FIELD		= 1,
+        BOTTOM_FIELD		= 2,
+        FRAME			= 3,
+        INVALID			= 4
+    } picture_structure_t;
 
 ///// Chorma format
 
-typedef enum _h264_chroma_format_t
-{
-	H264_CHROMA_MONOCHROME,
-	H264_CHROMA_420,
-	H264_CHROMA_422,
-	H264_CHROMA_444,
-}h264_chroma_format_t;
+    typedef enum _h264_chroma_format_t
+    {
+        H264_CHROMA_MONOCHROME,
+        H264_CHROMA_420,
+        H264_CHROMA_422,
+        H264_CHROMA_444,
+    } h264_chroma_format_t;
 
-/* H264 start code values */
-typedef enum _h264_nal_unit_type 
-{
-  	h264_NAL_UNIT_TYPE_unspecified = 0,
-	h264_NAL_UNIT_TYPE_SLICE,
-	h264_NAL_UNIT_TYPE_DPA,
-	h264_NAL_UNIT_TYPE_DPB,
-	h264_NAL_UNIT_TYPE_DPC,
-	h264_NAL_UNIT_TYPE_IDR,
-	h264_NAL_UNIT_TYPE_SEI,
-	h264_NAL_UNIT_TYPE_SPS,
-	h264_NAL_UNIT_TYPE_PPS,
-	h264_NAL_UNIT_TYPE_Acc_unit_delimiter,
-	h264_NAL_UNIT_TYPE_EOSeq,
-	h264_NAL_UNIT_TYPE_EOstream,
-	h264_NAL_UNIT_TYPE_filler_data,
-	h264_NAL_UNIT_TYPE_SPS_extension,
-	h264_NAL_UNIT_TYPE_Reserved1			=14,		/*14-18*/
-	h264_NAL_UNIT_TYPE_Reserved2			=15,		/*14-18*/
-	h264_NAL_UNIT_TYPE_Reserved3			=16,		/*14-18*/
-	h264_NAL_UNIT_TYPE_Reserved4			=17,		/*14-18*/
-	h264_NAL_UNIT_TYPE_Reserved5			=18,		/*14-18*/
-	h264_NAL_UNIT_TYPE_ACP				=19,
-	h264_NAL_UNIT_TYPE_Reserved6			=20,		/*20-23*/
-	h264_NAL_UNIT_TYPE_unspecified2		=24,		/*24-31*/
-} h264_nal_unit_type;
+    /* H264 start code values */
+    typedef enum _h264_nal_unit_type
+    {
+        h264_NAL_UNIT_TYPE_unspecified = 0,
+        h264_NAL_UNIT_TYPE_SLICE,
+        h264_NAL_UNIT_TYPE_DPA,
+        h264_NAL_UNIT_TYPE_DPB,
+        h264_NAL_UNIT_TYPE_DPC,
+        h264_NAL_UNIT_TYPE_IDR,
+        h264_NAL_UNIT_TYPE_SEI,
+        h264_NAL_UNIT_TYPE_SPS,
+        h264_NAL_UNIT_TYPE_PPS,
+        h264_NAL_UNIT_TYPE_Acc_unit_delimiter,
+        h264_NAL_UNIT_TYPE_EOSeq,
+        h264_NAL_UNIT_TYPE_EOstream,
+        h264_NAL_UNIT_TYPE_filler_data,
+        h264_NAL_UNIT_TYPE_SPS_extension,
+        h264_NAL_UNIT_TYPE_Reserved1			=14,		/*14-18*/
+        h264_NAL_UNIT_TYPE_Reserved2			=15,		/*14-18*/
+        h264_NAL_UNIT_TYPE_Reserved3			=16,		/*14-18*/
+        h264_NAL_UNIT_TYPE_Reserved4			=17,		/*14-18*/
+        h264_NAL_UNIT_TYPE_Reserved5			=18,		/*14-18*/
+        h264_NAL_UNIT_TYPE_ACP				=19,
+        h264_NAL_UNIT_TYPE_Reserved6			=20,		/*20-23*/
+        h264_NAL_UNIT_TYPE_unspecified2		=24,		/*24-31*/
+    } h264_nal_unit_type;
 
 #define h264_NAL_PRIORITY_HIGHEST     3
 #define h264_NAL_PRIORITY_HIGH        2
@@ -213,97 +213,97 @@
 #define h264_NAL_PRIORITY_DISPOSABLE  0
 
 
-typedef enum _h264_Profile
-{
-    h264_ProfileBaseline = 66,  	/** Baseline profile */
-    h264_ProfileMain = 77,        	/** Main profile */
-    h264_ProfileExtended = 88,    	/** Extended profile */
-    h264_ProfileHigh = 100 ,     		/** High profile */
-    h264_ProfileHigh10 = 110,			/** High 10 profile */
-    h264_ProfileHigh422 = 122,		/** High profile 4:2:2 */
-    h264_ProfileHigh444 = 144,		/** High profile 4:4:4 */
-} h264_Profile;
+    typedef enum _h264_Profile
+    {
+        h264_ProfileBaseline = 66,  	/** Baseline profile */
+        h264_ProfileMain = 77,        	/** Main profile */
+        h264_ProfileExtended = 88,    	/** Extended profile */
+        h264_ProfileHigh = 100 ,     		/** High profile */
+        h264_ProfileHigh10 = 110,			/** High 10 profile */
+        h264_ProfileHigh422 = 122,		/** High profile 4:2:2 */
+        h264_ProfileHigh444 = 144,		/** High profile 4:4:4 */
+    } h264_Profile;
 
 
-typedef enum _h264_Level
-{
-    h264_Level1b	= 9,		    /** Level 1b */
-    h264_Level1		= 10,			/** Level 1 */
-    h264_Level11	= 11, 		    /** Level 1.1 */
-	h264_Level12	= 12, 		    /** Level 1.2 */
-	h264_Level13	= 13, 		    /** Level 1.3 */
-	h264_Level2		= 20,			/** Level 2 */
-    h264_Level21 	= 21, 		    /** Level 2.1 */
-	h264_Level22	= 22, 		    /** Level 2.2 */
-	h264_Level3		= 30, 		    /** Level 3 */
-	h264_Level31	= 31, 		    /** Level 3.1 */
-	h264_Level32	= 32, 		    /** Level 3.2 */	
-	h264_Level4		= 40, 		    /** Level 4 */
-	h264_Level41	= 41, 		    /** Level 4.1 */
-	h264_Level42	= 42, 		    /** Level 4.2 */
-	h264_Level5		= 50, 		    /** Level 5 */
-	h264_Level51	= 51, 		    /** Level 5.1 */
-	h264_LevelReserved = 255  /** Unknown profile */
-} h264_Level;
+    typedef enum _h264_Level
+    {
+        h264_Level1b	= 9,		    /** Level 1b */
+        h264_Level1		= 10,			/** Level 1 */
+        h264_Level11	= 11, 		    /** Level 1.1 */
+        h264_Level12	= 12, 		    /** Level 1.2 */
+        h264_Level13	= 13, 		    /** Level 1.3 */
+        h264_Level2		= 20,			/** Level 2 */
+        h264_Level21 	= 21, 		    /** Level 2.1 */
+        h264_Level22	= 22, 		    /** Level 2.2 */
+        h264_Level3		= 30, 		    /** Level 3 */
+        h264_Level31	= 31, 		    /** Level 3.1 */
+        h264_Level32	= 32, 		    /** Level 3.2 */
+        h264_Level4		= 40, 		    /** Level 4 */
+        h264_Level41	= 41, 		    /** Level 4.1 */
+        h264_Level42	= 42, 		    /** Level 4.2 */
+        h264_Level5		= 50, 		    /** Level 5 */
+        h264_Level51	= 51, 		    /** Level 5.1 */
+        h264_LevelReserved = 255  /** Unknown profile */
+    } h264_Level;
 
 
-typedef enum _h264_video_format
-{
-	h264_Component	=0,
-	h264_PAL,
-	h264_NTSC,
-	h264_SECAM,
-	h264_MAC,
-	h264_unspecified,
-	h264_Reserved6,
-	h264_Reserved7	
-}h264_video_format;
+    typedef enum _h264_video_format
+    {
+        h264_Component	=0,
+        h264_PAL,
+        h264_NTSC,
+        h264_SECAM,
+        h264_MAC,
+        h264_unspecified,
+        h264_Reserved6,
+        h264_Reserved7
+    } h264_video_format;
 
 
-typedef enum _h264_fcm
-{
-    h264_ProgressiveFrame = 0,
-    h264_InterlacedFrame  = 1,
-    h264_InterlacedField  = 3,
-    h264_PictureFormatNone
-} h264_fcm;
+    typedef enum _h264_fcm
+    {
+        h264_ProgressiveFrame = 0,
+        h264_InterlacedFrame  = 1,
+        h264_InterlacedField  = 3,
+        h264_PictureFormatNone
+    } h264_fcm;
 
 
 ///// Define the picture types []
-typedef enum _h264_ptype_t
-{
-    h264_PtypeP = 0,
-    h264_PtypeB = 1,
-    h264_PtypeI = 2,
-    h264_PtypeSP = 3,
-    h264_PtypeSI = 4,
-    h264_Ptype_unspecified,
-} h264_ptype_t;
+    typedef enum _h264_ptype_t
+    {
+        h264_PtypeP = 0,
+        h264_PtypeB = 1,
+        h264_PtypeI = 2,
+        h264_PtypeSP = 3,
+        h264_PtypeSI = 4,
+        h264_Ptype_unspecified,
+    } h264_ptype_t;
 
 
 ///// Aspect ratio
-typedef enum _h264_aspect_ratio
-{
-	h264_AR_Unspecified = 0,
-	h264_AR_1_1 = 1,
-	h264_AR_12_11 = 2,
-	h264_AR_10_11 = 3,
-	h264_AR_16_11 = 4,
-	h264_AR_40_33 = 5,
-	h264_AR_24_11 = 6,
-	h264_AR_20_11 = 7,
-	h264_AR_32_11 = 8,
-	h264_AR_80_33 = 9,
-	h264_AR_18_11 = 10,
-	h264_AR_15_11 = 11,
-	h264_AR_64_33 = 12,
-	h264_AR_160_99 = 13,
-	h264_AR_4_3 = 14,
-	h264_AR_3_2 = 15,
-	h264_AR_2_1 = 16,
-	h264_AR_RESERVED = 17,
-	h264_AR_Extended_SAR = 255,
-}h264_aspect_ratio;
+    typedef enum _h264_aspect_ratio
+    {
+        h264_AR_Unspecified = 0,
+        h264_AR_1_1 = 1,
+        h264_AR_12_11 = 2,
+        h264_AR_10_11 = 3,
+        h264_AR_16_11 = 4,
+        h264_AR_40_33 = 5,
+        h264_AR_24_11 = 6,
+        h264_AR_20_11 = 7,
+        h264_AR_32_11 = 8,
+        h264_AR_80_33 = 9,
+        h264_AR_18_11 = 10,
+        h264_AR_15_11 = 11,
+        h264_AR_64_33 = 12,
+        h264_AR_160_99 = 13,
+        h264_AR_4_3 = 14,
+        h264_AR_3_2 = 15,
+        h264_AR_2_1 = 16,
+        h264_AR_RESERVED = 17,
+        h264_AR_Extended_SAR = 255,
+    } h264_aspect_ratio;
 
 
 //////////////////////////////////////////////
@@ -311,723 +311,723 @@
 //////////////////////////////////////////////
 // storable_picture
 
-/* Structure details 
-   If all members remain ints
-   Size = 11 ints, i.e. 44 bytes
-*/
+    /* Structure details
+       If all members remain ints
+       Size = 11 ints, i.e. 44 bytes
+    */
 
-typedef struct
-{
-  int32_t	poc;
-  int32_t	pic_num;
+    typedef struct
+    {
+        int32_t	poc;
+        int32_t	pic_num;
 
-  int32_t	long_term_pic_num;
-  
-  uint8_t	long_term_frame_idx;
-  uint8_t	is_long_term;
-  uint8_t	used_for_reference;
-  uint8_t	pad_flag;  		// Used to indicate the status
+        int32_t	long_term_pic_num;
 
-} storable_picture, *storable_picture_ptr;
+        uint8_t	long_term_frame_idx;
+        uint8_t	is_long_term;
+        uint8_t	used_for_reference;
+        uint8_t	pad_flag;  		// Used to indicate the status
+
+    } storable_picture, *storable_picture_ptr;
 
 //////////////////////////////////////////////
 // frame store
 
-/* Structure details 
-   If all members remain ints
-   Size = 46 ints, i.e. 184 bytes
-*/
+    /* Structure details
+       If all members remain ints
+       Size = 46 ints, i.e. 184 bytes
+    */
 
-typedef struct _frame_store
-{
-	storable_picture frame;
-	storable_picture top_field;
-	storable_picture bottom_field;
+    typedef struct _frame_store
+    {
+        storable_picture frame;
+        storable_picture top_field;
+        storable_picture bottom_field;
 
-	int32_t	frame_num;
-	
-	int32_t	frame_num_wrap;
-	
+        int32_t	frame_num;
 
-	uint8_t	fs_idc;
-	uint8_t	pic_type;            //bit7 structure: 1 frame , 0 field;  
-	                              //bit4,5,6 top field (frame) pic type,  00 IDR 01 I 10 P 11 B 100 INVALID
-	                              //bit1,2,3 bottom pic type,  00 IDR 01 I 10 P 11 B 100 INVALID
-   uint8_t	long_term_frame_idx; // No two frame stores may have the same long-term frame index	                              
-
-   #define viddec_h264_get_dec_structure(x)         h264_bitfields_extract( (x)->fs_flag_1, 0, 0x03)
-   #define viddec_h264_set_dec_structure(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 0, 0x03)
-   #define viddec_h264_get_is_used(x)         h264_bitfields_extract( (x)->fs_flag_1, 2, 0x03)
-   #define viddec_h264_set_is_frame_used(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 2, 0x03)
-   #define viddec_h264_set_is_top_used(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 2, 0x01)
-   #define viddec_h264_set_is_bottom_used(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 3, 0x01)
-   #define viddec_h264_get_is_skipped(x)         h264_bitfields_extract( (x)->fs_flag_1, 4, 0x03)
-   #define viddec_h264_set_is_frame_skipped(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 4, 0x03)
-   #define viddec_h264_set_is_top_skipped(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 4, 0x01)
-   #define viddec_h264_set_is_bottom_skipped(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 5, 0x01)
-   #define viddec_h264_get_is_long_term(x)         h264_bitfields_extract( (x)->fs_flag_1, 6, 0x03)
-   #define viddec_h264_set_is_frame_long_term(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 6, 0x03)
-   #define viddec_h264_set_is_top_long_term(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 6, 0x01)
-   #define viddec_h264_set_is_bottom_long_term(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 7, 0x01)
-   uint8_t  fs_flag_1;
+        int32_t	frame_num_wrap;
 
 
-   #define viddec_h264_get_is_non_existent(x)            h264_bitfields_extract( (x)->fs_flag_2, 0, 0x01)
-   #define viddec_h264_set_is_non_existent(x, val)       h264_bitfields_insert ( (x)->fs_flag_2, (val), 0, 0x01)
-   #define viddec_h264_get_is_output(x)                  h264_bitfields_extract( (x)->fs_flag_2, 1, 0x01)
-   #define viddec_h264_set_is_output(x, val)             h264_bitfields_insert ( (x)->fs_flag_2, (val), 1, 0x01)
-   #define viddec_h264_get_is_dangling(x)                h264_bitfields_extract( (x)->fs_flag_2, 2, 0x01)
-   #define viddec_h264_set_is_dangling(x, val)           h264_bitfields_insert ( (x)->fs_flag_2, (val), 2, 0x01)
-   #define viddec_h264_get_recovery_pt_picture(x)        h264_bitfields_extract( (x)->fs_flag_2, 3, 0x01)
-   #define viddec_h264_set_recovery_pt_picture(x, val)   h264_bitfields_insert ( (x)->fs_flag_2, (val), 3, 0x01)
-   #define viddec_h264_get_broken_link_picture(x)        h264_bitfields_extract( (x)->fs_flag_2, 4, 0x01)
-   #define viddec_h264_set_broken_link_picture(x, val)   h264_bitfields_insert ( (x)->fs_flag_2, (val), 4, 0x01)
-   #define viddec_h264_get_open_gop_entry(x)             h264_bitfields_extract( (x)->fs_flag_2, 5, 0x01)
-   #define viddec_h264_set_open_gop_entry(x, val)        h264_bitfields_insert ( (x)->fs_flag_2, (val), 5, 0x01)
-   #define viddec_h264_get_first_field_intra(x)          h264_bitfields_extract( (x)->fs_flag_2, 6, 0x01)
-   #define viddec_h264_set_first_field_intra(x, val)     h264_bitfields_insert ( (x)->fs_flag_2, (val), 6, 0x01)
-	uint8_t  fs_flag_2;   
+        uint8_t	fs_idc;
+        uint8_t	pic_type;            //bit7 structure: 1 frame , 0 field;
+        //bit4,5,6 top field (frame) pic type,  00 IDR 01 I 10 P 11 B 100 INVALID
+        //bit1,2,3 bottom pic type,  00 IDR 01 I 10 P 11 B 100 INVALID
+        uint8_t	long_term_frame_idx; // No two frame stores may have the same long-term frame index
 
-   uint8_t  fs_flag_reserve_1;
-   uint8_t  fs_flag_reserve_2;
-   uint8_t  fs_flag_reserve_3;
+#define viddec_h264_get_dec_structure(x)         h264_bitfields_extract( (x)->fs_flag_1, 0, 0x03)
+#define viddec_h264_set_dec_structure(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 0, 0x03)
+#define viddec_h264_get_is_used(x)         h264_bitfields_extract( (x)->fs_flag_1, 2, 0x03)
+#define viddec_h264_set_is_frame_used(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 2, 0x03)
+#define viddec_h264_set_is_top_used(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 2, 0x01)
+#define viddec_h264_set_is_bottom_used(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 3, 0x01)
+#define viddec_h264_get_is_skipped(x)         h264_bitfields_extract( (x)->fs_flag_1, 4, 0x03)
+#define viddec_h264_set_is_frame_skipped(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 4, 0x03)
+#define viddec_h264_set_is_top_skipped(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 4, 0x01)
+#define viddec_h264_set_is_bottom_skipped(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 5, 0x01)
+#define viddec_h264_get_is_long_term(x)         h264_bitfields_extract( (x)->fs_flag_1, 6, 0x03)
+#define viddec_h264_set_is_frame_long_term(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 6, 0x03)
+#define viddec_h264_set_is_top_long_term(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 6, 0x01)
+#define viddec_h264_set_is_bottom_long_term(x, val)    h264_bitfields_insert ( (x)->fs_flag_1, (val), 7, 0x01)
+        uint8_t  fs_flag_1;
 
-	// If non-reference, may have skipped pixel decode
-	//uint8_t	non_ref_skipped;
-} frame_store, *frame_param_ptr;
+
+#define viddec_h264_get_is_non_existent(x)            h264_bitfields_extract( (x)->fs_flag_2, 0, 0x01)
+#define viddec_h264_set_is_non_existent(x, val)       h264_bitfields_insert ( (x)->fs_flag_2, (val), 0, 0x01)
+#define viddec_h264_get_is_output(x)                  h264_bitfields_extract( (x)->fs_flag_2, 1, 0x01)
+#define viddec_h264_set_is_output(x, val)             h264_bitfields_insert ( (x)->fs_flag_2, (val), 1, 0x01)
+#define viddec_h264_get_is_dangling(x)                h264_bitfields_extract( (x)->fs_flag_2, 2, 0x01)
+#define viddec_h264_set_is_dangling(x, val)           h264_bitfields_insert ( (x)->fs_flag_2, (val), 2, 0x01)
+#define viddec_h264_get_recovery_pt_picture(x)        h264_bitfields_extract( (x)->fs_flag_2, 3, 0x01)
+#define viddec_h264_set_recovery_pt_picture(x, val)   h264_bitfields_insert ( (x)->fs_flag_2, (val), 3, 0x01)
+#define viddec_h264_get_broken_link_picture(x)        h264_bitfields_extract( (x)->fs_flag_2, 4, 0x01)
+#define viddec_h264_set_broken_link_picture(x, val)   h264_bitfields_insert ( (x)->fs_flag_2, (val), 4, 0x01)
+#define viddec_h264_get_open_gop_entry(x)             h264_bitfields_extract( (x)->fs_flag_2, 5, 0x01)
+#define viddec_h264_set_open_gop_entry(x, val)        h264_bitfields_insert ( (x)->fs_flag_2, (val), 5, 0x01)
+#define viddec_h264_get_first_field_intra(x)          h264_bitfields_extract( (x)->fs_flag_2, 6, 0x01)
+#define viddec_h264_set_first_field_intra(x, val)     h264_bitfields_insert ( (x)->fs_flag_2, (val), 6, 0x01)
+        uint8_t  fs_flag_2;
+
+        uint8_t  fs_flag_reserve_1;
+        uint8_t  fs_flag_reserve_2;
+        uint8_t  fs_flag_reserve_3;
+
+        // If non-reference, may have skipped pixel decode
+        //uint8_t	non_ref_skipped;
+    } frame_store, *frame_param_ptr;
 
 //! Decoded Picture Buffer
-typedef struct _h264_decoded_picture_buffer
-{
-	///
-	int32_t     last_output_poc;
-	int32_t     max_long_term_pic_idx;
+    typedef struct _h264_decoded_picture_buffer
+    {
+        ///
+        int32_t     last_output_poc;
+        int32_t     max_long_term_pic_idx;
 
-	//// Resolutions
-	int32_t		PicWidthInMbs;
-	int32_t		FrameHeightInMbs;
+        //// Resolutions
+        int32_t		PicWidthInMbs;
+        int32_t		FrameHeightInMbs;
 
-	frame_store	fs[NUM_DPB_FRAME_STORES];
+        frame_store	fs[NUM_DPB_FRAME_STORES];
 
-	uint8_t		fs_ref_idc[16];
-	uint8_t		fs_ltref_idc[16];
+        uint8_t		fs_ref_idc[16];
+        uint8_t		fs_ltref_idc[16];
 
-	uint8_t		fs_dpb_idc[NUM_DPB_FRAME_STORES+2];
+        uint8_t		fs_dpb_idc[NUM_DPB_FRAME_STORES+2];
 
-	uint8_t		listX_0[33+3];  // [bit5}:field_flag:0 for top, 1 for bottom, [bit4~0]:fs_idc
-	uint8_t		listX_1[33+3];
+        uint8_t		listX_0[33+3];  // [bit5}:field_flag:0 for top, 1 for bottom, [bit4~0]:fs_idc
+        uint8_t		listX_1[33+3];
 
-	uint8_t		listXsize[2]; // 1 to 32
-	uint8_t		nInitListSize[2];
+        uint8_t		listXsize[2]; // 1 to 32
+        uint8_t		nInitListSize[2];
 
-	//uint32_t	size;
-	uint8_t		fs_dec_idc;
-	uint8_t		fs_non_exist_idc;
-	uint8_t		BumpLevel;
-	uint8_t		used_size;
+        //uint32_t	size;
+        uint8_t		fs_dec_idc;
+        uint8_t		fs_non_exist_idc;
+        uint8_t		BumpLevel;
+        uint8_t		used_size;
 
-	uint8_t		OutputLevel;	
-	uint8_t		OutputLevelValid;
-	uint8_t		OutputCtrl;
-	uint8_t     num_ref_frames;
-	
-	uint8_t		ref_frames_in_buffer;
-	uint8_t		ltref_frames_in_buffer;
-	uint8_t		SuspendOutput;
-	uint8_t		WaitSeiRecovery; 
+        uint8_t		OutputLevel;
+        uint8_t		OutputLevelValid;
+        uint8_t		OutputCtrl;
+        uint8_t     num_ref_frames;
 
-   
-   uint8_t		frame_numbers_need_to_be_allocated;
-   uint8_t		frame_id_need_to_be_allocated;
-
-	//// frame list to release from dpb, need be displayed
-   uint8_t		frame_numbers_need_to_be_removed;
-   uint8_t		frame_id_need_to_be_removed[17];
-
-	//// frame list to removed from dpb but not display 
-   uint8_t		frame_numbers_need_to_be_dropped;
-   uint8_t		frame_id_need_to_be_dropped[17];
-
-	//// frame list to display (in display order) 
-   uint8_t		frame_numbers_need_to_be_displayed;
-   uint8_t		frame_id_need_to_be_displayed[17];   
+        uint8_t		ref_frames_in_buffer;
+        uint8_t		ltref_frames_in_buffer;
+        uint8_t		SuspendOutput;
+        uint8_t		WaitSeiRecovery;
 
 
-} h264_DecodedPictureBuffer;
+        uint8_t		frame_numbers_need_to_be_allocated;
+        uint8_t		frame_id_need_to_be_allocated;
+
+        //// frame list to release from dpb, need be displayed
+        uint8_t		frame_numbers_need_to_be_removed;
+        uint8_t		frame_id_need_to_be_removed[17];
+
+        //// frame list to removed from dpb but not display
+        uint8_t		frame_numbers_need_to_be_dropped;
+        uint8_t		frame_id_need_to_be_dropped[17];
+
+        //// frame list to display (in display order)
+        uint8_t		frame_numbers_need_to_be_displayed;
+        uint8_t		frame_id_need_to_be_displayed[17];
+
+
+    } h264_DecodedPictureBuffer;
 
 
 //////////////////////////////////////////////
 // qm_matrix_set
-typedef struct _qm_matrix_set
-{
- // uint8_t scaling_default_vector;
-  uint8_t scaling_list[56];            // 0 to 23 for qm 0 to 5 (4x4), 24 to 55 for qm 6 & 7 (8x8)
+    typedef struct _qm_matrix_set
+    {
+// uint8_t scaling_default_vector;
+        uint8_t scaling_list[56];            // 0 to 23 for qm 0 to 5 (4x4), 24 to 55 for qm 6 & 7 (8x8)
 
-} qm_matrix_set, *qm_matrix_set_ptr;
+    } qm_matrix_set, *qm_matrix_set_ptr;
 
-/*
-///////// Currently not enabled in parser fw///////////////////
-typedef struct _h264_SPS_Extension_RBSP {
-	int32_t 			seq_parameter_set_id;					//UE
-	int32_t				aux_format_idc;							//UE
-	int32_t				bit_depth_aux_minus8;					//UE
-	int32_t				alpha_incr_flag;						
-	int32_t				alpha_opaque_value;						
-	int32_t				alpha_transparent_value;
-	int32_t				additional_extension_flag;
-//	h264_rbsp_trail_set* rbsp_trail_ptr;
-}h264_SPS_Extension_RBSP_t;
-*/
+    /*
+    ///////// Currently not enabled in parser fw///////////////////
+    typedef struct _h264_SPS_Extension_RBSP {
+    	int32_t 			seq_parameter_set_id;					//UE
+    	int32_t				aux_format_idc;							//UE
+    	int32_t				bit_depth_aux_minus8;					//UE
+    	int32_t				alpha_incr_flag;
+    	int32_t				alpha_opaque_value;
+    	int32_t				alpha_transparent_value;
+    	int32_t				additional_extension_flag;
+    //	h264_rbsp_trail_set* rbsp_trail_ptr;
+    }h264_SPS_Extension_RBSP_t;
+    */
 
-typedef struct _h264_hrd_param_set {
-	int32_t				bit_rate_value_minus1[MAX_CPB_CNT];			// ue(v), 0 to (2^32)-2
-	int32_t				cpb_size_value_minus1[MAX_CPB_CNT];			// ue(v), 0 to (2^32)-2
+    typedef struct _h264_hrd_param_set {
+        int32_t				bit_rate_value_minus1[MAX_CPB_CNT];			// ue(v), 0 to (2^32)-2
+        int32_t				cpb_size_value_minus1[MAX_CPB_CNT];			// ue(v), 0 to (2^32)-2
 
-	uint8_t				cbr_flag[MAX_CPB_CNT];							// u(1) * 32
+        uint8_t				cbr_flag[MAX_CPB_CNT];							// u(1) * 32
 
-} h264_hrd_param_set, *h264_hrd_param_set_ptr;
+    } h264_hrd_param_set, *h264_hrd_param_set_ptr;
 
-typedef struct _vui_seq_parameters_t_used
-{
-	uint32_t	num_units_in_tick;                             // u(32)
-	uint32_t	time_scale;                                    // u(32)
+    typedef struct _vui_seq_parameters_t_used
+    {
+        uint32_t	num_units_in_tick;                             // u(32)
+        uint32_t	time_scale;                                    // u(32)
 
-	int32_t  num_reorder_frames;                               // ue(v), 0 to max_dec_frame_buffering
-	int32_t	max_dec_frame_buffering;                          // ue(v), 0 to MaxDpbSize, specified in subclause A.3
+        int32_t  num_reorder_frames;                               // ue(v), 0 to max_dec_frame_buffering
+        int32_t	max_dec_frame_buffering;                          // ue(v), 0 to MaxDpbSize, specified in subclause A.3
 
-	uint16_t	 sar_width;                                       // u(16)
-	uint16_t	 sar_height;                                      // u(16)
+        uint16_t	 sar_width;                                       // u(16)
+        uint16_t	 sar_height;                                      // u(16)
 
-	uint8_t   aspect_ratio_info_present_flag;                  // u(1)
-	uint8_t   aspect_ratio_idc;                                // u(8)	
-	uint8_t   video_signal_type_present_flag;                  // u(1)
-	uint8_t   video_format;                                    // u(3)
+        uint8_t   aspect_ratio_info_present_flag;                  // u(1)
+        uint8_t   aspect_ratio_idc;                                // u(8)
+        uint8_t   video_signal_type_present_flag;                  // u(1)
+        uint8_t   video_format;                                    // u(3)
 #ifdef VBP
-    uint8_t   video_full_range_flag;                           // u(1)
-    uint8_t   matrix_coefficients;                              // u(8) 
+        uint8_t   video_full_range_flag;                           // u(1)
+        uint8_t   matrix_coefficients;                              // u(8)
 #endif
-	
-	uint8_t   colour_description_present_flag;                 // u(1)	
-	uint8_t   colour_primaries;                                // u(8)	
-	uint8_t   transfer_characteristics;                        // u(8)
-	uint8_t   timing_info_present_flag;                        // u(1)
-	
-	uint8_t   fixed_frame_rate_flag;                           // u(1)
-	uint8_t   low_delay_hrd_flag;                              // u(1)
-	uint8_t   bitstream_restriction_flag;                      // u(1)
-	uint8_t   pic_struct_present_flag;
-   
-	uint8_t   nal_hrd_parameters_present_flag;                 // u(1)	
-	uint8_t 	 nal_hrd_cpb_removal_delay_length_minus1;				// u(5)
-	uint8_t   nal_hrd_dpb_output_delay_length_minus1;				// u(5)	
-	uint8_t   nal_hrd_time_offset_length;								// u(5)
-	
-	uint8_t   nal_hrd_cpb_cnt_minus1;									// ue(v), 0 to 31
-	uint8_t   nal_hrd_initial_cpb_removal_delay_length_minus1;	// u(5)   
-   uint8_t   vcl_hrd_parameters_present_flag;                 // u(1)
-	uint8_t 	 vcl_hrd_cpb_removal_delay_length_minus1;				// u(5)
-	
-	uint8_t   vcl_hrd_dpb_output_delay_length_minus1;				// u(5)	
-	uint8_t   vcl_hrd_time_offset_length;								// u(5)	
-	uint8_t   vcl_hrd_cpb_cnt_minus1;									// ue(v), 0 to 31
-	uint8_t   vcl_hrd_initial_cpb_removal_delay_length_minus1;	// u(5) 
 
-	/////// Here should be kept as 32-bits aligned for next structures
-	/// 2 structures for NAL&VCL HRD
-	
-	
-} vui_seq_parameters_t_used;
+        uint8_t   colour_description_present_flag;                 // u(1)
+        uint8_t   colour_primaries;                                // u(8)
+        uint8_t   transfer_characteristics;                        // u(8)
+        uint8_t   timing_info_present_flag;                        // u(1)
+
+        uint8_t   fixed_frame_rate_flag;                           // u(1)
+        uint8_t   low_delay_hrd_flag;                              // u(1)
+        uint8_t   bitstream_restriction_flag;                      // u(1)
+        uint8_t   pic_struct_present_flag;
+
+        uint8_t   nal_hrd_parameters_present_flag;                 // u(1)
+        uint8_t 	 nal_hrd_cpb_removal_delay_length_minus1;				// u(5)
+        uint8_t   nal_hrd_dpb_output_delay_length_minus1;				// u(5)
+        uint8_t   nal_hrd_time_offset_length;								// u(5)
+
+        uint8_t   nal_hrd_cpb_cnt_minus1;									// ue(v), 0 to 31
+        uint8_t   nal_hrd_initial_cpb_removal_delay_length_minus1;	// u(5)
+        uint8_t   vcl_hrd_parameters_present_flag;                 // u(1)
+        uint8_t 	 vcl_hrd_cpb_removal_delay_length_minus1;				// u(5)
+
+        uint8_t   vcl_hrd_dpb_output_delay_length_minus1;				// u(5)
+        uint8_t   vcl_hrd_time_offset_length;								// u(5)
+        uint8_t   vcl_hrd_cpb_cnt_minus1;									// ue(v), 0 to 31
+        uint8_t   vcl_hrd_initial_cpb_removal_delay_length_minus1;	// u(5)
+
+        /////// Here should be kept as 32-bits aligned for next structures
+        /// 2 structures for NAL&VCL HRD
 
 
-typedef struct _vui_seq_parameters_t_not_used
-{
-	int16_t  chroma_sample_loc_type_top_field;                // ue(v)
-	int16_t  chroma_sample_loc_type_bottom_field;             // ue(v)
-	
-	uint8_t   overscan_info_present_flag;                      // u(1)
-	uint8_t   overscan_appropriate_flag;                       // u(1)
+    } vui_seq_parameters_t_used;
 
-   uint8_t   video_full_range_flag;                           // u(1)
-	uint8_t   matrix_coefficients;                             // u(8)	    
 
-   uint8_t   chroma_location_info_present_flag;               // u(1)
-	uint8_t   max_bytes_per_pic_denom;                          // ue(v), 0 to 16
-	uint8_t   max_bits_per_mb_denom;                            // ue(v), 0 to 16
-	uint8_t   log2_max_mv_length_vertical;                      // ue(v), 0 to 16, default to 16
-	uint8_t   log2_max_mv_length_horizontal;                    // ue(v), 0 to 16, default to 16
+    typedef struct _vui_seq_parameters_t_not_used
+    {
+        int16_t  chroma_sample_loc_type_top_field;                // ue(v)
+        int16_t  chroma_sample_loc_type_bottom_field;             // ue(v)
 
-	uint8_t   motion_vectors_over_pic_boundaries_flag;          // u(1)
+        uint8_t   overscan_info_present_flag;                      // u(1)
+        uint8_t   overscan_appropriate_flag;                       // u(1)
 
-   uint8_t   nal_hrd_bit_rate_scale;									// u(4)
-	uint8_t   nal_hrd_cpb_size_scale;									// u(4)
+        uint8_t   video_full_range_flag;                           // u(1)
+        uint8_t   matrix_coefficients;                             // u(8)
 
-   uint8_t   vcl_hrd_bit_rate_scale;									// u(4)
-	uint8_t   vcl_hrd_cpb_size_scale;									// u(4)   
+        uint8_t   chroma_location_info_present_flag;               // u(1)
+        uint8_t   max_bytes_per_pic_denom;                          // ue(v), 0 to 16
+        uint8_t   max_bits_per_mb_denom;                            // ue(v), 0 to 16
+        uint8_t   log2_max_mv_length_vertical;                      // ue(v), 0 to 16, default to 16
+        uint8_t   log2_max_mv_length_horizontal;                    // ue(v), 0 to 16, default to 16
 
-   h264_hrd_param_set nal_hrd_parameters;
-   h264_hrd_param_set vcl_hrd_parameters; 
+        uint8_t   motion_vectors_over_pic_boundaries_flag;          // u(1)
 
-	
-} vui_seq_parameters_t_not_used, *vui_seq_parameters_t_not_used_ptr;
+        uint8_t   nal_hrd_bit_rate_scale;									// u(4)
+        uint8_t   nal_hrd_cpb_size_scale;									// u(4)
+
+        uint8_t   vcl_hrd_bit_rate_scale;									// u(4)
+        uint8_t   vcl_hrd_cpb_size_scale;									// u(4)
+
+        h264_hrd_param_set nal_hrd_parameters;
+        h264_hrd_param_set vcl_hrd_parameters;
+
+
+    } vui_seq_parameters_t_not_used, *vui_seq_parameters_t_not_used_ptr;
 
 
 //////////////////////////////////////////////
 // picture parameter set
 
-typedef struct _PPS_PAR
-{
-	//int32_t DOUBLE_ALIGN valid;                          // indicates the parameter set is valid
+    typedef struct _PPS_PAR
+    {
+        //int32_t DOUBLE_ALIGN valid;                          // indicates the parameter set is valid
 
-	int32_t pic_init_qp_minus26;                             // se(v), -26 to +25
-	int32_t pic_init_qs_minus26;                             // se(v), -26 to +25
-	int32_t chroma_qp_index_offset;                          // se(v), -12 to +12
-	int32_t second_chroma_qp_index_offset;
+        int32_t pic_init_qp_minus26;                             // se(v), -26 to +25
+        int32_t pic_init_qs_minus26;                             // se(v), -26 to +25
+        int32_t chroma_qp_index_offset;                          // se(v), -12 to +12
+        int32_t second_chroma_qp_index_offset;
 
-	uint8_t pic_parameter_set_id;                            // ue(v), 0 to 255, restricted to 0 to 127 by MPD_CTRL_MAXPPS = 128
-	uint8_t seq_parameter_set_id;                            // ue(v), 0 to 31
-	uint8_t entropy_coding_mode_flag;                        // u(1)
-	uint8_t pic_order_present_flag;                          // u(1)
-	
-	uint8_t num_slice_groups_minus1;                         // ue(v), shall be 0 for MP
-	// Below are not relevant for main profile...
-	uint8_t slice_group_map_type;                            // ue(v), 0 to 6
-	uint8_t num_ref_idx_l0_active;							// ue(v), 0 to 31
-	uint8_t num_ref_idx_l1_active;							// ue(v), 0 to 31
+        uint8_t pic_parameter_set_id;                            // ue(v), 0 to 255, restricted to 0 to 127 by MPD_CTRL_MAXPPS = 128
+        uint8_t seq_parameter_set_id;                            // ue(v), 0 to 31
+        uint8_t entropy_coding_mode_flag;                        // u(1)
+        uint8_t pic_order_present_flag;                          // u(1)
 
-	uint8_t weighted_pred_flag;                              // u(1)
-	uint8_t weighted_bipred_idc;                             // u(2)
-	uint8_t deblocking_filter_control_present_flag;          // u(1)
-	uint8_t constrained_intra_pred_flag;                     // u(1)
+        uint8_t num_slice_groups_minus1;                         // ue(v), shall be 0 for MP
+        // Below are not relevant for main profile...
+        uint8_t slice_group_map_type;                            // ue(v), 0 to 6
+        uint8_t num_ref_idx_l0_active;							// ue(v), 0 to 31
+        uint8_t num_ref_idx_l1_active;							// ue(v), 0 to 31
 
-	uint8_t redundant_pic_cnt_present_flag;                  // u(1)
-	uint8_t transform_8x8_mode_flag;
-	uint8_t pic_scaling_matrix_present_flag;
-	uint8_t pps_status_flag;
+        uint8_t weighted_pred_flag;                              // u(1)
+        uint8_t weighted_bipred_idc;                             // u(2)
+        uint8_t deblocking_filter_control_present_flag;          // u(1)
+        uint8_t constrained_intra_pred_flag;                     // u(1)
 
-	//// Keep here with 32-bits aligned
-	uint8_t	pic_scaling_list_present_flag[MAX_PIC_LIST_NUM];
+        uint8_t redundant_pic_cnt_present_flag;                  // u(1)
+        uint8_t transform_8x8_mode_flag;
+        uint8_t pic_scaling_matrix_present_flag;
+        uint8_t pps_status_flag;
 
-	qm_matrix_set	pps_qm;
+        //// Keep here with 32-bits aligned
+        uint8_t	pic_scaling_list_present_flag[MAX_PIC_LIST_NUM];
 
-	uint8_t 		ScalingList4x4[6][16];
-	uint8_t 		ScalingList8x8[2][64];
-	uint8_t   	UseDefaultScalingMatrix4x4Flag[6+2];
-	uint8_t		UseDefaultScalingMatrix8x8Flag[6+2];
-	
-} pic_param_set, *pic_param_set_ptr, h264_PicParameterSet_t;
+        qm_matrix_set	pps_qm;
 
-typedef union _list_reordering_num_t
-{
-	int32_t abs_diff_pic_num_minus1;
-	int32_t long_term_pic_num;
-} list_reordering_num_t;
+        uint8_t 		ScalingList4x4[6][16];
+        uint8_t 		ScalingList8x8[2][64];
+        uint8_t   	UseDefaultScalingMatrix4x4Flag[6+2];
+        uint8_t		UseDefaultScalingMatrix8x8Flag[6+2];
 
-typedef struct _h264_Ref_Pic_List_Reordering				////size = 8*33+ 1 + 33
-{
-	list_reordering_num_t list_reordering_num[MAX_NUM_REF_FRAMES+1];
+    } pic_param_set, *pic_param_set_ptr, h264_PicParameterSet_t;
 
-	uint8_t			ref_pic_list_reordering_flag;			
-	uint8_t			reordering_of_pic_nums_idc[MAX_NUM_REF_FRAMES+1];							//UE
-	
-}h264_Ref_Pic_List_Reordering_t;
+    typedef union _list_reordering_num_t
+    {
+        int32_t abs_diff_pic_num_minus1;
+        int32_t long_term_pic_num;
+    } list_reordering_num_t;
 
-typedef enum _H264_DANGLING_TYPE
-{
-	DANGLING_TYPE_LAST_FIELD,
-	DANGLING_TYPE_DPB_RESET,
-	DANGLING_TYPE_FIELD,
-	DANGLING_TYPE_FRAME,
-	DANGLING_TYPE_GAP_IN_FRAME
+    typedef struct _h264_Ref_Pic_List_Reordering				////size = 8*33+ 1 + 33
+    {
+        list_reordering_num_t list_reordering_num[MAX_NUM_REF_FRAMES+1];
 
-} H264_DANGLING_TYPE;
+        uint8_t			ref_pic_list_reordering_flag;
+        uint8_t			reordering_of_pic_nums_idc[MAX_NUM_REF_FRAMES+1];							//UE
+
+    } h264_Ref_Pic_List_Reordering_t;
+
+    typedef enum _H264_DANGLING_TYPE
+    {
+        DANGLING_TYPE_LAST_FIELD,
+        DANGLING_TYPE_DPB_RESET,
+        DANGLING_TYPE_FIELD,
+        DANGLING_TYPE_FRAME,
+        DANGLING_TYPE_GAP_IN_FRAME
+
+    } H264_DANGLING_TYPE;
 
 
-typedef struct _h264_Dec_Ref_Pic_Marking			//size = 17*4*2 + 17*3 + 4 + 1
-{
-	int32_t		difference_of_pic_num_minus1[NUM_MMCO_OPERATIONS];
-	int32_t		long_term_pic_num[NUM_MMCO_OPERATIONS]; 
+    typedef struct _h264_Dec_Ref_Pic_Marking			//size = 17*4*2 + 17*3 + 4 + 1
+    {
+        int32_t		difference_of_pic_num_minus1[NUM_MMCO_OPERATIONS];
+        int32_t		long_term_pic_num[NUM_MMCO_OPERATIONS];
 
-	/// MMCO
-	uint8_t		memory_management_control_operation[NUM_MMCO_OPERATIONS];
-	uint8_t		max_long_term_frame_idx_plus1[NUM_MMCO_OPERATIONS];
-	uint8_t		long_term_frame_idx[NUM_MMCO_OPERATIONS];
-	uint8_t		long_term_reference_flag;
+        /// MMCO
+        uint8_t		memory_management_control_operation[NUM_MMCO_OPERATIONS];
+        uint8_t		max_long_term_frame_idx_plus1[NUM_MMCO_OPERATIONS];
+        uint8_t		long_term_frame_idx[NUM_MMCO_OPERATIONS];
+        uint8_t		long_term_reference_flag;
 
-	uint8_t		adaptive_ref_pic_marking_mode_flag;
-	uint8_t		dec_ref_pic_marking_count;
-	uint8_t		no_output_of_prior_pics_flag;
+        uint8_t		adaptive_ref_pic_marking_mode_flag;
+        uint8_t		dec_ref_pic_marking_count;
+        uint8_t		no_output_of_prior_pics_flag;
 
-	uint8_t		pad;
-}h264_Dec_Ref_Pic_Marking_t;
+        uint8_t		pad;
+    } h264_Dec_Ref_Pic_Marking_t;
 
 
 
-typedef struct old_slice_par
-{
-	int32_t		frame_num;
-	int32_t		pic_order_cnt_lsb;
-	int32_t		delta_pic_order_cnt_bottom;
-	int32_t		delta_pic_order_cnt[2];
+    typedef struct old_slice_par
+    {
+        int32_t		frame_num;
+        int32_t		pic_order_cnt_lsb;
+        int32_t		delta_pic_order_cnt_bottom;
+        int32_t		delta_pic_order_cnt[2];
 
-	uint8_t		field_pic_flag;
-	uint8_t		bottom_field_flag;
-	uint8_t		nal_ref_idc;
-	uint8_t		structure;
-	
-	uint8_t		idr_flag;
-	uint8_t		idr_pic_id;
-	uint8_t		pic_parameter_id;
-	uint8_t		status;
-} OldSliceParams;
+        uint8_t		field_pic_flag;
+        uint8_t		bottom_field_flag;
+        uint8_t		nal_ref_idc;
+        uint8_t		structure;
+
+        uint8_t		idr_flag;
+        uint8_t		idr_pic_id;
+        uint8_t		pic_parameter_id;
+        uint8_t		status;
+    } OldSliceParams;
 
 #ifdef VBP
-typedef struct _h264__pred_weight_table
-{
-  uint8_t luma_log2_weight_denom;
-  uint8_t chroma_log2_weight_denom;
-  uint8_t luma_weight_l0_flag;
-  int16_t luma_weight_l0[32];
-  int8_t luma_offset_l0[32];
-  uint8_t chroma_weight_l0_flag;
-  int16_t chroma_weight_l0[32][2];
-  int8_t chroma_offset_l0[32][2];
-  
-  uint8_t luma_weight_l1_flag;
-  int16_t luma_weight_l1[32];
-  int8_t luma_offset_l1[32];
-  uint8_t chroma_weight_l1_flag;
-  int16_t chroma_weight_l1[32][2];
-  int8_t chroma_offset_l1[32][2];
-} h264_pred_weight_table;
+    typedef struct _h264__pred_weight_table
+    {
+        uint8_t luma_log2_weight_denom;
+        uint8_t chroma_log2_weight_denom;
+        uint8_t luma_weight_l0_flag;
+        int16_t luma_weight_l0[32];
+        int8_t luma_offset_l0[32];
+        uint8_t chroma_weight_l0_flag;
+        int16_t chroma_weight_l0[32][2];
+        int8_t chroma_offset_l0[32][2];
+
+        uint8_t luma_weight_l1_flag;
+        int16_t luma_weight_l1[32];
+        int8_t luma_offset_l1[32];
+        uint8_t chroma_weight_l1_flag;
+        int16_t chroma_weight_l1[32][2];
+        int8_t chroma_offset_l1[32][2];
+    } h264_pred_weight_table;
 #endif
 
-typedef struct _h264_Slice_Header
-{
-	int32_t 		first_mb_in_slice;								//UE
-	int32_t		frame_num;											//UV
-	int32_t		pic_order_cnt_lsb;								//UV
-	int32_t		delta_pic_order_cnt_bottom;					//SE
-	int32_t		delta_pic_order_cnt[2];								//SE
-	int32_t		redundant_pic_cnt;									//UE
-	
-	uint32_t		num_ref_idx_l0_active;								//UE
-	uint32_t		num_ref_idx_l1_active;								//UE
+    typedef struct _h264_Slice_Header
+    {
+        int32_t 		first_mb_in_slice;								//UE
+        int32_t		frame_num;											//UV
+        int32_t		pic_order_cnt_lsb;								//UV
+        int32_t		delta_pic_order_cnt_bottom;					//SE
+        int32_t		delta_pic_order_cnt[2];								//SE
+        int32_t		redundant_pic_cnt;									//UE
 
-	int32_t		slice_qp_delta;										//SE
-	int32_t		slice_qs_delta;										//SE
-	int32_t		slice_alpha_c0_offset_div2;						//SE
-	int32_t		slice_beta_offset_div2;								//SE
-	int32_t		slice_group_change_cycle;							//UV
+        uint32_t		num_ref_idx_l0_active;								//UE
+        uint32_t		num_ref_idx_l1_active;								//UE
+
+        int32_t		slice_qp_delta;										//SE
+        int32_t		slice_qs_delta;										//SE
+        int32_t		slice_alpha_c0_offset_div2;						//SE
+        int32_t		slice_beta_offset_div2;								//SE
+        int32_t		slice_group_change_cycle;							//UV
 
 #ifdef VBP
-  h264_pred_weight_table  sh_predwttbl;
+        h264_pred_weight_table  sh_predwttbl;
 #endif
-    
-	///// Flags or IDs
-	//h264_ptype_t	slice_type;											//UE
-	uint8_t			slice_type; 
-	uint8_t 			nal_ref_idc;
-	uint8_t			structure;
-	uint8_t 			pic_parameter_id;									//UE
 
-	uint8_t			field_pic_flag;
-	uint8_t			bottom_field_flag;
-	uint8_t			idr_flag;											//UE
-	uint8_t			idr_pic_id;											//UE
+        ///// Flags or IDs
+        //h264_ptype_t	slice_type;											//UE
+        uint8_t			slice_type;
+        uint8_t 			nal_ref_idc;
+        uint8_t			structure;
+        uint8_t 			pic_parameter_id;									//UE
 
-	uint8_t 			sh_error;	
-	uint8_t			cabac_init_idc;										//UE
-	uint8_t			sp_for_switch_flag;					
-	uint8_t			disable_deblocking_filter_idc;						//UE
-	
-	uint8_t			direct_spatial_mv_pred_flag;						
-	uint8_t			num_ref_idx_active_override_flag;
-	int16_t			current_slice_nr;
+        uint8_t			field_pic_flag;
+        uint8_t			bottom_field_flag;
+        uint8_t			idr_flag;											//UE
+        uint8_t			idr_pic_id;											//UE
 
-	//// For Ref list reordering
-	h264_Dec_Ref_Pic_Marking_t sh_dec_refpic;
-	h264_Ref_Pic_List_Reordering_t sh_refpic_l0;
-	h264_Ref_Pic_List_Reordering_t sh_refpic_l1;
-	
-} h264_Slice_Header_t;
+        uint8_t 			sh_error;
+        uint8_t			cabac_init_idc;										//UE
+        uint8_t			sp_for_switch_flag;
+        uint8_t			disable_deblocking_filter_idc;						//UE
+
+        uint8_t			direct_spatial_mv_pred_flag;
+        uint8_t			num_ref_idx_active_override_flag;
+        int16_t			current_slice_nr;
+
+        //// For Ref list reordering
+        h264_Dec_Ref_Pic_Marking_t sh_dec_refpic;
+        h264_Ref_Pic_List_Reordering_t sh_refpic_l0;
+        h264_Ref_Pic_List_Reordering_t sh_refpic_l1;
+
+    } h264_Slice_Header_t;
 
 
 #define   MAX_USER_DATA_SIZE              1024
-typedef struct _h264_user_data_t
-{
-	h264_sei_payloadtype    user_data_type;
-	
-  	int32_t    user_data_id;
-  	int32_t    dsn;
-  	int32_t    user_data_size;
-  	int32_t    user_data[MAX_USER_DATA_SIZE>>2];
-} h264_user_data_t;
+    typedef struct _h264_user_data_t
+    {
+        h264_sei_payloadtype    user_data_type;
+
+        int32_t    user_data_id;
+        int32_t    dsn;
+        int32_t    user_data_size;
+        int32_t    user_data[MAX_USER_DATA_SIZE>>2];
+    } h264_user_data_t;
 
 // SPS DISPLAY parameters: seq_param_set_disp, *seq_param_set_disp_ptr;
-typedef struct _SPS_DISP
-{
-	///// VUI info
-	vui_seq_parameters_t_used vui_seq_parameters;    //size =           
+    typedef struct _SPS_DISP
+    {
+        ///// VUI info
+        vui_seq_parameters_t_used vui_seq_parameters;    //size =
 
-	///// Resolution
-	int16_t pic_width_in_mbs_minus1;                          
-	int16_t pic_height_in_map_units_minus1;                   
+        ///// Resolution
+        int16_t pic_width_in_mbs_minus1;
+        int16_t pic_height_in_map_units_minus1;
 
-	///// Cropping
-	int16_t frame_crop_rect_left_offset;                  
-	int16_t frame_crop_rect_right_offset;                 
+        ///// Cropping
+        int16_t frame_crop_rect_left_offset;
+        int16_t frame_crop_rect_right_offset;
 
-	int16_t frame_crop_rect_top_offset;                   
-	int16_t frame_crop_rect_bottom_offset;                
+        int16_t frame_crop_rect_top_offset;
+        int16_t frame_crop_rect_bottom_offset;
 
-	///// Flags
-	uint8_t frame_mbs_only_flag;                              
-	uint8_t mb_adaptive_frame_field_flag;
-	uint8_t direct_8x8_inference_flag;                        
-	uint8_t frame_cropping_flag;         
-	
-	uint16_t vui_parameters_present_flag;                      
-	uint16_t chroma_format_idc;
-} seq_param_set_disp, *seq_param_set_disp_ptr;
+        ///// Flags
+        uint8_t frame_mbs_only_flag;
+        uint8_t mb_adaptive_frame_field_flag;
+        uint8_t direct_8x8_inference_flag;
+        uint8_t frame_cropping_flag;
+
+        uint16_t vui_parameters_present_flag;
+        uint16_t chroma_format_idc;
+    } seq_param_set_disp, *seq_param_set_disp_ptr;
 
 
 ////SPS: seq_param_set, *seq_param_set_ptr;
 
-typedef struct _SPS_PAR_USED
-{
-   uint32_t    is_updated;
+    typedef struct _SPS_PAR_USED
+    {
+        uint32_t    is_updated;
 
-	/////////// Required for display section //////////////////////////
-	seq_param_set_disp sps_disp;
-	
-	int32_t		expectedDeltaPerPOCCycle; 
-	int32_t 		offset_for_non_ref_pic;                           // se(v), -2^31 to (2^31)-1, 32-bit integer
-	int32_t 		offset_for_top_to_bottom_field;                   // se(v), -2^31 to (2^31)-1, 32-bit integer
+        /////////// Required for display section //////////////////////////
+        seq_param_set_disp sps_disp;
 
-	/////////// IDC 
-	uint8_t 		profile_idc;                                      // u(8), 0x77 for MP
-	uint8_t 		constraint_set_flags;                             // bit 0 to 3 for set0 to set3                          
-	uint8_t 		level_idc;                                        // u(8)	    
-	uint8_t 		seq_parameter_set_id;                             // ue(v), 0 to 31
-	
+        int32_t		expectedDeltaPerPOCCycle;
+        int32_t 		offset_for_non_ref_pic;                           // se(v), -2^31 to (2^31)-1, 32-bit integer
+        int32_t 		offset_for_top_to_bottom_field;                   // se(v), -2^31 to (2^31)-1, 32-bit integer
 
-	uint8_t 		pic_order_cnt_type;                               // ue(v), 0 to 2
-	uint8_t 		log2_max_frame_num_minus4;                        // ue(v), 0 to 12
-	uint8_t 		log2_max_pic_order_cnt_lsb_minus4;                // ue(v), 0 to 12
-	uint8_t 		num_ref_frames_in_pic_order_cnt_cycle;            // ue(v), 0 to 255
-	    
-	//int32_t offset_for_ref_frame[MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE];   // se(v), -2^31 to (2^31)-1, 32-bit integer
-	uint8_t 		num_ref_frames;                                   // ue(v), 0 to 16, 
-	uint8_t 		gaps_in_frame_num_value_allowed_flag;             // u(1)
-	// This is my addition, we should calculate this once and leave it with the sps
-	// as opposed to calculating it each time in h264_hdr_decoding_POC()
-
-	uint8_t 		delta_pic_order_always_zero_flag;                 // u(1)
-	uint8_t		residual_colour_transform_flag;
-	
-	uint8_t		bit_depth_luma_minus8;
-	uint8_t		bit_depth_chroma_minus8;
-	uint8_t		lossless_qpprime_y_zero_flag;
-	uint8_t		seq_scaling_matrix_present_flag;
-	
-	uint8_t		seq_scaling_list_present_flag[MAX_PIC_LIST_NUM];			//0-7 
-
-	//// Combine the scaling matrix to word ( 24 + 32)
-	uint8_t 		ScalingList4x4[6][16];
-	uint8_t 		ScalingList8x8[2][64];
-	uint8_t		UseDefaultScalingMatrix4x4Flag[6];
-	uint8_t		UseDefaultScalingMatrix8x8Flag[6];
-
-} seq_param_set_used, *seq_param_set_used_ptr;
+        /////////// IDC
+        uint8_t 		profile_idc;                                      // u(8), 0x77 for MP
+        uint8_t 		constraint_set_flags;                             // bit 0 to 3 for set0 to set3
+        uint8_t 		level_idc;                                        // u(8)
+        uint8_t 		seq_parameter_set_id;                             // ue(v), 0 to 31
 
 
-typedef struct _SPS_PAR_ALL
-{
+        uint8_t 		pic_order_cnt_type;                               // ue(v), 0 to 2
+        uint8_t 		log2_max_frame_num_minus4;                        // ue(v), 0 to 12
+        uint8_t 		log2_max_pic_order_cnt_lsb_minus4;                // ue(v), 0 to 12
+        uint8_t 		num_ref_frames_in_pic_order_cnt_cycle;            // ue(v), 0 to 255
 
-    seq_param_set_used  sps_par_used;
-    vui_seq_parameters_t_not_used sps_vui_par_not_used;
+        //int32_t offset_for_ref_frame[MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE];   // se(v), -2^31 to (2^31)-1, 32-bit integer
+        uint8_t 		num_ref_frames;                                   // ue(v), 0 to 16,
+        uint8_t 		gaps_in_frame_num_value_allowed_flag;             // u(1)
+        // This is my addition, we should calculate this once and leave it with the sps
+        // as opposed to calculating it each time in h264_hdr_decoding_POC()
 
-}seq_param_set_all, *seq_param_set_all_ptr;
+        uint8_t 		delta_pic_order_always_zero_flag;                 // u(1)
+        uint8_t		residual_colour_transform_flag;
+
+        uint8_t		bit_depth_luma_minus8;
+        uint8_t		bit_depth_chroma_minus8;
+        uint8_t		lossless_qpprime_y_zero_flag;
+        uint8_t		seq_scaling_matrix_present_flag;
+
+        uint8_t		seq_scaling_list_present_flag[MAX_PIC_LIST_NUM];			//0-7
+
+        //// Combine the scaling matrix to word ( 24 + 32)
+        uint8_t 		ScalingList4x4[6][16];
+        uint8_t 		ScalingList8x8[2][64];
+        uint8_t		UseDefaultScalingMatrix4x4Flag[6];
+        uint8_t		UseDefaultScalingMatrix8x8Flag[6];
+
+    } seq_param_set_used, *seq_param_set_used_ptr;
+
+
+    typedef struct _SPS_PAR_ALL
+    {
+
+        seq_param_set_used  sps_par_used;
+        vui_seq_parameters_t_not_used sps_vui_par_not_used;
+
+    } seq_param_set_all, *seq_param_set_all_ptr;
 
 
 ///// Image control parameter////////////
-typedef struct _h264_img_par
-{
-	int32_t frame_num;				// decoding num of current frame
-	int32_t frame_count;				// count of decoded frames
-	int32_t current_slice_num;
-	int32_t gaps_in_frame_num;
+    typedef struct _h264_img_par
+    {
+        int32_t frame_num;				// decoding num of current frame
+        int32_t frame_count;				// count of decoded frames
+        int32_t current_slice_num;
+        int32_t gaps_in_frame_num;
 
-	// POC decoding 
-	int32_t num_ref_frames_in_pic_order_cnt_cycle;
-	int32_t delta_pic_order_always_zero_flag;
-	int32_t offset_for_non_ref_pic;
-	int32_t offset_for_top_to_bottom_field;
+        // POC decoding
+        int32_t num_ref_frames_in_pic_order_cnt_cycle;
+        int32_t delta_pic_order_always_zero_flag;
+        int32_t offset_for_non_ref_pic;
+        int32_t offset_for_top_to_bottom_field;
 
-	int32_t pic_order_cnt_lsb;
-	int32_t pic_order_cnt_msb;
-	int32_t delta_pic_order_cnt_bottom;
-	int32_t delta_pic_order_cnt[2];
+        int32_t pic_order_cnt_lsb;
+        int32_t pic_order_cnt_msb;
+        int32_t delta_pic_order_cnt_bottom;
+        int32_t delta_pic_order_cnt[2];
 
-	int32_t PicOrderCntMsb;
-	int32_t CurrPicOrderCntMsb;
-	int32_t PrevPicOrderCntLsb;
+        int32_t PicOrderCntMsb;
+        int32_t CurrPicOrderCntMsb;
+        int32_t PrevPicOrderCntLsb;
 
-	int32_t FrameNumOffset;
+        int32_t FrameNumOffset;
 
-	int32_t PreviousFrameNum;
-	int32_t PreviousFrameNumOffset;
+        int32_t PreviousFrameNum;
+        int32_t PreviousFrameNumOffset;
 
-	int32_t toppoc;
-	int32_t bottompoc;
-	int32_t framepoc;
-	int32_t ThisPOC;
+        int32_t toppoc;
+        int32_t bottompoc;
+        int32_t framepoc;
+        int32_t ThisPOC;
 
-	//int32_t sei_freeze_this_image;
+        //int32_t sei_freeze_this_image;
 
-	///////////////////// Resolutions
-	int32_t PicWidthInMbs;
-	int32_t FrameHeightInMbs;
+        ///////////////////// Resolutions
+        int32_t PicWidthInMbs;
+        int32_t FrameHeightInMbs;
 
-	///////////////////// MMCO
-	uint8_t last_has_mmco_5;
-	uint8_t curr_has_mmco_5;
+        ///////////////////// MMCO
+        uint8_t last_has_mmco_5;
+        uint8_t curr_has_mmco_5;
 
-	/////////////////// Flags
-	uint8_t g_new_frame;                   
-	uint8_t g_new_pic;
-	
-	uint8_t structure;
-	uint8_t second_field;           // Set to one if this is the second field of a set of paired fields...
-	uint8_t field_pic_flag;
-	uint8_t last_pic_bottom_field;
-	
-	uint8_t bottom_field_flag;
-	uint8_t MbaffFrameFlag;
-	uint8_t no_output_of_prior_pics_flag;
-	uint8_t long_term_reference_flag;
-	
-	uint8_t skip_this_pic;
-	uint8_t pic_order_cnt_type;
-	// Recovery
-	uint8_t recovery_point_found;
-	uint8_t used_for_reference;	
-} h264_img_par;
+        /////////////////// Flags
+        uint8_t g_new_frame;
+        uint8_t g_new_pic;
+
+        uint8_t structure;
+        uint8_t second_field;           // Set to one if this is the second field of a set of paired fields...
+        uint8_t field_pic_flag;
+        uint8_t last_pic_bottom_field;
+
+        uint8_t bottom_field_flag;
+        uint8_t MbaffFrameFlag;
+        uint8_t no_output_of_prior_pics_flag;
+        uint8_t long_term_reference_flag;
+
+        uint8_t skip_this_pic;
+        uint8_t pic_order_cnt_type;
+        // Recovery
+        uint8_t recovery_point_found;
+        uint8_t used_for_reference;
+    } h264_img_par;
 
 
-typedef struct  _h264_slice_reg_data
-{         
-	uint32_t h264_bsd_slice_p1;      // 0x150  
-	//uint32_t h264_mpr_list0[8];       // from 0x380 to 0x3BC 
-	uint32_t h264_bsd_slice_p2;      // 0x154 
-	uint32_t h264_bsd_slice_start;   // 0x158      
+    typedef struct  _h264_slice_reg_data
+    {
+        uint32_t h264_bsd_slice_p1;      // 0x150
+        //uint32_t h264_mpr_list0[8];       // from 0x380 to 0x3BC
+        uint32_t h264_bsd_slice_p2;      // 0x154
+        uint32_t h264_bsd_slice_start;   // 0x158
 
-} h264_slice_data;
+    } h264_slice_data;
 
 
-typedef struct  _h264_pic_data
-{
-	uint32_t h264_dpb_init;          // 0x40         
-	//info For current pic
-	uint32_t h264_cur_bsd_img_init;      // 0x140 
-	uint32_t h264_cur_mpr_tf_poc;        // 0x300 
-	uint32_t h264_cur_mpr_bf_poc;        // 0x304         
+    typedef struct  _h264_pic_data
+    {
+        uint32_t h264_dpb_init;          // 0x40
+        //info For current pic
+        uint32_t h264_cur_bsd_img_init;      // 0x140
+        uint32_t h264_cur_mpr_tf_poc;        // 0x300
+        uint32_t h264_cur_mpr_bf_poc;        // 0x304
 
-	//info For framess in DPB
-	//uint32_t h264_dpb_bsd_img_init[16];      //0x140
-	//uint32_t h264_dpb_mpr_tf_poc[16];        // 0x300 
-	//uint32_t h264_dpb_mpr_bf_poc[16];        // 0x304   
-} h264_pic_data;
+        //info For framess in DPB
+        //uint32_t h264_dpb_bsd_img_init[16];      //0x140
+        //uint32_t h264_dpb_mpr_tf_poc[16];        // 0x300
+        //uint32_t h264_dpb_mpr_bf_poc[16];        // 0x304
+    } h264_pic_data;
 
-enum h264_workload_item_type
-{
-   VIDDEC_WORKLOAD_H264_SLICE_REG = VIDDEC_WORKLOAD_DECODER_SPECIFIC,
-   VIDDEC_WORKLOAD_H264_PIC_REG,
-   VIDDEC_WORKLOAD_H264_DPB_FRAME_POC,
-   VIDDEC_WORKLOAD_H264_SH_BITS_OFFSET,
-   VIDDEC_WORKLOAD_H264_PWT_BITS_OFFSET,
-   VIDDEC_WORKLOAD_H264_PWT_ES_BYTES,
-   VIDDEC_WORKLOAD_H264_SCALING_MATRIX,   
-   VIDDEC_WORKLOAD_H264_DEBUG
-};
+    enum h264_workload_item_type
+    {
+        VIDDEC_WORKLOAD_H264_SLICE_REG = VIDDEC_WORKLOAD_DECODER_SPECIFIC,
+        VIDDEC_WORKLOAD_H264_PIC_REG,
+        VIDDEC_WORKLOAD_H264_DPB_FRAME_POC,
+        VIDDEC_WORKLOAD_H264_SH_BITS_OFFSET,
+        VIDDEC_WORKLOAD_H264_PWT_BITS_OFFSET,
+        VIDDEC_WORKLOAD_H264_PWT_ES_BYTES,
+        VIDDEC_WORKLOAD_H264_SCALING_MATRIX,
+        VIDDEC_WORKLOAD_H264_DEBUG
+    };
 
 
 
 ////////////////////////////////////////////
-/* Full Info set*/
+    /* Full Info set*/
 ////////////////////////////////////////////
-typedef struct _h264_Info 
-{
+    typedef struct _h264_Info
+    {
 
-   h264_DecodedPictureBuffer           dpb;
+        h264_DecodedPictureBuffer           dpb;
 
-   //// Structures
-   //// need to gurantee active_SPS and active_PPS start from 4-bytes alignment address
-   seq_param_set_used	active_SPS;
-   pic_param_set			active_PPS;
-
-	
-   h264_Slice_Header_t  SliceHeader;
-   OldSliceParams       old_slice;
-   sei_info             sei_information;
-
-   h264_img_par      img;
-
-   uint32_t          SPS_PADDR_GL;
-   uint32_t          PPS_PADDR_GL;
-   uint32_t          OFFSET_REF_FRAME_PADDR_GL;
-	uint32_t				TMP_OFFSET_REFFRM_PADDR_GL;
-
-   uint32_t          h264_list_replacement;
-
-   uint32_t          h264_pwt_start_byte_offset;
-   uint32_t          h264_pwt_start_bit_offset;
-   uint32_t          h264_pwt_end_byte_offset;
-   uint32_t          h264_pwt_end_bit_offset;
-   uint32_t          h264_pwt_enabled;   
-
-	uint32_t          sps_valid;
-
-   uint8_t           slice_ref_list0[32];
-   uint8_t           slice_ref_list1[32];
+        //// Structures
+        //// need to gurantee active_SPS and active_PPS start from 4-bytes alignment address
+        seq_param_set_used	active_SPS;
+        pic_param_set			active_PPS;
 
 
-   uint8_t           qm_present_list;
-   //h264_NAL_Unit_t	
-   uint8_t           nal_unit_type;
-   uint8_t           old_nal_unit_type;
-   uint8_t    			got_start;   
+        h264_Slice_Header_t  SliceHeader;
+        OldSliceParams       old_slice;
+        sei_info             sei_information;
 
-   //workload
-   uint8_t           push_to_cur;
-   uint8_t           Is_first_frame_in_stream;
-   uint8_t           Is_SPS_updated;
-   uint8_t           number_of_first_au_info_nal_before_first_slice;
+        h264_img_par      img;
 
-   uint8_t           is_frame_boundary_detected_by_non_slice_nal;
-   uint8_t           is_frame_boundary_detected_by_slice_nal;
-   uint8_t           is_current_workload_done;
-   uint8_t			 primary_pic_type_plus_one;	  //AUD---[0,7]    
+        uint32_t          SPS_PADDR_GL;
+        uint32_t          PPS_PADDR_GL;
+        uint32_t          OFFSET_REF_FRAME_PADDR_GL;
+        uint32_t				TMP_OFFSET_REFFRM_PADDR_GL;
 
-	//Error handling
-	uint8_t			sei_rp_received;		
-	uint8_t			last_I_frame_idc;		
-	uint8_t			sei_b_state_ready;
-	uint8_t			gop_err_flag;
-	
+        uint32_t          h264_list_replacement;
 
-	uint32_t		wl_err_curr;
-	uint32_t		wl_err_next;	
+        uint32_t          h264_pwt_start_byte_offset;
+        uint32_t          h264_pwt_start_bit_offset;
+        uint32_t          h264_pwt_end_byte_offset;
+        uint32_t          h264_pwt_end_bit_offset;
+        uint32_t          h264_pwt_enabled;
 
-} h264_Info;
+        uint32_t          sps_valid;
+
+        uint8_t           slice_ref_list0[32];
+        uint8_t           slice_ref_list1[32];
+
+
+        uint8_t           qm_present_list;
+        //h264_NAL_Unit_t
+        uint8_t           nal_unit_type;
+        uint8_t           old_nal_unit_type;
+        uint8_t    			got_start;
+
+        //workload
+        uint8_t           push_to_cur;
+        uint8_t           Is_first_frame_in_stream;
+        uint8_t           Is_SPS_updated;
+        uint8_t           number_of_first_au_info_nal_before_first_slice;
+
+        uint8_t           is_frame_boundary_detected_by_non_slice_nal;
+        uint8_t           is_frame_boundary_detected_by_slice_nal;
+        uint8_t           is_current_workload_done;
+        uint8_t			 primary_pic_type_plus_one;	  //AUD---[0,7]
+
+        //Error handling
+        uint8_t			sei_rp_received;
+        uint8_t			last_I_frame_idc;
+        uint8_t			sei_b_state_ready;
+        uint8_t			gop_err_flag;
+
+
+        uint32_t		wl_err_curr;
+        uint32_t		wl_err_next;
+
+    } h264_Info;
 
 
 
-struct h264_viddec_parser
-{
-   uint32_t     sps_pps_ddr_paddr;
-   h264_Info    info;
-};
+    struct h264_viddec_parser
+    {
+        uint32_t     sps_pps_ddr_paddr;
+        h264_Info    info;
+    };
 
 #ifdef __cplusplus
 }
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse.h b/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse.h
index 88db5de..2e7b817 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse.h
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse.h
@@ -17,43 +17,43 @@
 #endif
 
 
-enum h264_debug_point_id
-{
-   WARNING_H264_GENERAL = 0xff000000,
-	WARNING_H264_DPB,
-   WARNING_H264_REFLIST,
-   WARNING_H264_SPS,   
-   WARNING_H264_PPS,
-   WARNING_H264_SEI,
-   WARNING_H264_VCL,
-   
-   ERROR_H264_GENERAL = 0xffff0000,
-	ERROR_H264_DPB,	
-	ERROR_H264_REFLIST,
-	ERROR_H264_SPS,   
-	ERROR_H264_PPS,
-	ERROR_H264_SEI,
-	ERROR_H264_VCL
-};
+    enum h264_debug_point_id
+    {
+        WARNING_H264_GENERAL = 0xff000000,
+        WARNING_H264_DPB,
+        WARNING_H264_REFLIST,
+        WARNING_H264_SPS,
+        WARNING_H264_PPS,
+        WARNING_H264_SEI,
+        WARNING_H264_VCL,
 
-static inline void MFD_PARSER_DEBUG(int debug_point_id)
-{
+        ERROR_H264_GENERAL = 0xffff0000,
+        ERROR_H264_DPB,
+        ERROR_H264_REFLIST,
+        ERROR_H264_SPS,
+        ERROR_H264_PPS,
+        ERROR_H264_SEI,
+        ERROR_H264_VCL
+    };
+
+    static inline void MFD_PARSER_DEBUG(int debug_point_id)
+    {
 #ifdef H264_MFD_DEBUG
 
-	int p1,p2,p3,p4,p5,p6;
+        int p1,p2,p3,p4,p5,p6;
 
-	p1 = 0x0BAD;
-	p2 = 0xC0DE;
-	p3 = debug_point_id;
-	p4=p5=p6 = 0;
-	
-	DEBUG_WRITE(p1,p2,p3,p4,p5,p6);
-#endif	
+        p1 = 0x0BAD;
+        p2 = 0xC0DE;
+        p3 = debug_point_id;
+        p4=p5=p6 = 0;
 
-	debug_point_id = debug_point_id;
+        DEBUG_WRITE(p1,p2,p3,p4,p5,p6);
+#endif
 
-	return;
-}
+        debug_point_id = debug_point_id;
+
+        return;
+    }
 
 
 
@@ -61,27 +61,27 @@
 ////////////////////////////////////////////////////////////////////
 ///////////////////////////// Init functions
 ////////////////////////////////////////////////////////////////////
-extern void h264_init_old_slice(h264_Info* pInfo);
-extern void h264_init_img(h264_Info* pInfo);
-extern void h264_init_Info(h264_Info* pInfo);
-extern void h264_init_Info_under_sps_pps_level(h264_Info* pInfo);
-extern void h264_init_sps_pps(struct h264_viddec_parser* parser, uint32_t *persist_mem);
+    extern void h264_init_old_slice(h264_Info* pInfo);
+    extern void h264_init_img(h264_Info* pInfo);
+    extern void h264_init_Info(h264_Info* pInfo);
+    extern void h264_init_Info_under_sps_pps_level(h264_Info* pInfo);
+    extern void h264_init_sps_pps(struct h264_viddec_parser* parser, uint32_t *persist_mem);
 
-extern void h264_update_old_slice(h264_Info * pInfo,h264_Slice_Header_t next_SliceHeader);
-extern void h264_sei_stream_initialise (h264_Info* pInfo);
-extern void h264_update_img_info(h264_Info * pInfo );
-extern void h264_update_frame_type(h264_Info * pInfo );
+    extern void h264_update_old_slice(h264_Info * pInfo,h264_Slice_Header_t next_SliceHeader);
+    extern void h264_sei_stream_initialise (h264_Info* pInfo);
+    extern void h264_update_img_info(h264_Info * pInfo );
+    extern void h264_update_frame_type(h264_Info * pInfo );
 
-extern int32_t h264_check_previous_frame_end(h264_Info * pInfo);
+    extern int32_t h264_check_previous_frame_end(h264_Info * pInfo);
 
 
 ////////////////////////////////////////////////////////////////////
 ///////////////////////////// bsd functions
 ////////////////////////////////////////////////////////////////////
-extern uint8_t h264_More_RBSP_Data(void *parent, h264_Info * pInfo);
+    extern uint8_t h264_More_RBSP_Data(void *parent, h264_Info * pInfo);
 ////// VLE and bit operation
-extern uint32_t h264_get_codeNum(void *parent,h264_Info* pInfo);
-extern int32_t h264_GetVLCElement(void *parent,h264_Info* pInfo, uint8_t bIsSigned);
+    extern uint32_t h264_get_codeNum(void *parent,h264_Info* pInfo);
+    extern int32_t h264_GetVLCElement(void *parent,h264_Info* pInfo, uint8_t bIsSigned);
 
 
 
@@ -90,58 +90,58 @@
 ////////////////////////////////////////////////////////////////////
 
 //NAL
-extern h264_Status h264_Parse_NAL_Unit(void *parent, h264_Info* pInfo, uint8_t *nal_ref_idc);
+    extern h264_Status h264_Parse_NAL_Unit(void *parent, h264_Info* pInfo, uint8_t *nal_ref_idc);
 
 ////// Slice header
-extern h264_Status h264_Parse_Slice_Layer_Without_Partitioning_RBSP(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader);
-extern h264_Status h264_Parse_Slice_Header_1(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader);
-extern h264_Status h264_Parse_Slice_Header_2(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader);
-extern h264_Status h264_Parse_Slice_Header_3(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader);
+    extern h264_Status h264_Parse_Slice_Layer_Without_Partitioning_RBSP(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader);
+    extern h264_Status h264_Parse_Slice_Header_1(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader);
+    extern h264_Status h264_Parse_Slice_Header_2(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader);
+    extern h264_Status h264_Parse_Slice_Header_3(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader);
 
 
 ////// SPS
-extern h264_Status h264_Parse_SeqParameterSet(void *parent, h264_Info * pInfo,seq_param_set_used_ptr SPS, vui_seq_parameters_t_not_used_ptr pVUI_Seq_Not_Used, int32_t* pOffset_ref_frame);
+    extern h264_Status h264_Parse_SeqParameterSet(void *parent, h264_Info * pInfo,seq_param_set_used_ptr SPS, vui_seq_parameters_t_not_used_ptr pVUI_Seq_Not_Used, int32_t* pOffset_ref_frame);
 //extern h264_Status h264_Parse_SeqParameterSet_Extension(void *parent, h264_Info * pInfo);
-extern h264_Status h264_Parse_PicParameterSet(void *parent, h264_Info * pInfo,h264_PicParameterSet_t* PictureParameterSet);
+    extern h264_Status h264_Parse_PicParameterSet(void *parent, h264_Info * pInfo,h264_PicParameterSet_t* PictureParameterSet);
 
 ////// SEI functions
-h264_Status h264_Parse_Supplemental_Enhancement_Information_Message(void *parent,h264_Info* pInfo);
-h264_Status h264_SEI_payload(void *parent, h264_Info* pInfo, h264_sei_payloadtype payloadType, int32_t payloadSize);
+    h264_Status h264_Parse_Supplemental_Enhancement_Information_Message(void *parent,h264_Info* pInfo);
+    h264_Status h264_SEI_payload(void *parent, h264_Info* pInfo, h264_sei_payloadtype payloadType, int32_t payloadSize);
 
 //////
-extern h264_Status h264_Scaling_List(void *parent, uint8_t *scalingList, int32_t sizeOfScalingList, uint8_t  *UseDefaultScalingMatrix, h264_Info* pInfo);
-extern h264_Status h264_Parse_Ref_Pic_List_Reordering(void *parent,h264_Info* pInfo,h264_Slice_Header_t *SliceHeader);
-extern h264_Status h264_Parse_Pred_Weight_Table(void *parent,h264_Info* pInfo,h264_Slice_Header_t *SliceHeader);
-extern h264_Status h264_Parse_Dec_Ref_Pic_Marking(void *parent,h264_Info* pInfo,h264_Slice_Header_t *SliceHeader);
+    extern h264_Status h264_Scaling_List(void *parent, uint8_t *scalingList, int32_t sizeOfScalingList, uint8_t  *UseDefaultScalingMatrix, h264_Info* pInfo);
+    extern h264_Status h264_Parse_Ref_Pic_List_Reordering(void *parent,h264_Info* pInfo,h264_Slice_Header_t *SliceHeader);
+    extern h264_Status h264_Parse_Pred_Weight_Table(void *parent,h264_Info* pInfo,h264_Slice_Header_t *SliceHeader);
+    extern h264_Status h264_Parse_Dec_Ref_Pic_Marking(void *parent,h264_Info* pInfo,h264_Slice_Header_t *SliceHeader);
 
 
 
 ///// Mem functions
-extern void* h264_memset( void* buf, uint32_t c, uint32_t num );
-extern void* h264_memcpy( void* dest, void* src, uint32_t num );
+    extern void* h264_memset( void* buf, uint32_t c, uint32_t num );
+    extern void* h264_memcpy( void* dest, void* src, uint32_t num );
 
-extern void h264_Parse_Copy_Sps_To_DDR(h264_Info* pInfo, seq_param_set_used_ptr SPS, uint32_t nSPSId);
-extern void h264_Parse_Copy_Sps_From_DDR(h264_Info* pInfo, seq_param_set_used_ptr SPS, uint32_t nSPSId);
+    extern void h264_Parse_Copy_Sps_To_DDR(h264_Info* pInfo, seq_param_set_used_ptr SPS, uint32_t nSPSId);
+    extern void h264_Parse_Copy_Sps_From_DDR(h264_Info* pInfo, seq_param_set_used_ptr SPS, uint32_t nSPSId);
 
-extern void h264_Parse_Copy_Pps_To_DDR(h264_Info* pInfo, pic_param_set_ptr PPS, uint32_t nPPSId);
-extern void h264_Parse_Copy_Pps_From_DDR(h264_Info* pInfo, pic_param_set_ptr PPS, uint32_t nPPSId);
+    extern void h264_Parse_Copy_Pps_To_DDR(h264_Info* pInfo, pic_param_set_ptr PPS, uint32_t nPPSId);
+    extern void h264_Parse_Copy_Pps_From_DDR(h264_Info* pInfo, pic_param_set_ptr PPS, uint32_t nPPSId);
 
-extern void h264_Parse_Copy_Offset_Ref_Frames_To_DDR(h264_Info* pInfo, int32_t* pOffset_ref_frames, uint32_t nSPSId);
-extern void h264_Parse_Copy_Offset_Ref_Frames_From_DDR(h264_Info* pInfo, int32_t* pOffset_ref_frames, uint32_t nSPSId);
-extern uint32_t h264_Parse_Check_Sps_Updated_Flag(h264_Info* pInfo, uint32_t nSPSId);
-extern void h264_Parse_Clear_Sps_Updated_Flag(h264_Info* pInfo, uint32_t nSPSId);
+    extern void h264_Parse_Copy_Offset_Ref_Frames_To_DDR(h264_Info* pInfo, int32_t* pOffset_ref_frames, uint32_t nSPSId);
+    extern void h264_Parse_Copy_Offset_Ref_Frames_From_DDR(h264_Info* pInfo, int32_t* pOffset_ref_frames, uint32_t nSPSId);
+    extern uint32_t h264_Parse_Check_Sps_Updated_Flag(h264_Info* pInfo, uint32_t nSPSId);
+    extern void h264_Parse_Clear_Sps_Updated_Flag(h264_Info* pInfo, uint32_t nSPSId);
 
 
 ////////////////////////////////////////////////////////////////////
 ///////////////////////////// workload functions
 ////////////////////////////////////////////////////////////////////
 
-extern void h264_parse_emit_current_slice( void *parent, h264_Info *pInfo );
+    extern void h264_parse_emit_current_slice( void *parent, h264_Info *pInfo );
 
-extern void h264_parse_emit_current_pic( void *parent, h264_Info *pInfo );
+    extern void h264_parse_emit_current_pic( void *parent, h264_Info *pInfo );
 
-extern void h264_parse_emit_start_new_frame( void *parent, h264_Info *pInfo );
-extern void h264_parse_emit_eos( void *parent, h264_Info *pInfo );
+    extern void h264_parse_emit_start_new_frame( void *parent, h264_Info *pInfo );
+    extern void h264_parse_emit_eos( void *parent, h264_Info *pInfo );
 #ifdef __cplusplus
 }
 #endif
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse_dpb.h b/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse_dpb.h
index 8b4deb4..002818b 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse_dpb.h
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse_dpb.h
@@ -26,79 +26,79 @@
 ////////////////////////////////////////////////////////////////////
 
 ///// Reference list
-extern void h264_dpb_update_ref_lists(h264_Info * pInfo);
-extern void h264_dpb_reorder_lists(h264_Info * pInfo);
+    extern void h264_dpb_update_ref_lists(h264_Info * pInfo);
+    extern void h264_dpb_reorder_lists(h264_Info * pInfo);
 
-extern void h264_dpb_insert_ref_lists(h264_DecodedPictureBuffer * p_dpb,int32_t NonExisting);
+    extern void h264_dpb_insert_ref_lists(h264_DecodedPictureBuffer * p_dpb,int32_t NonExisting);
 
-///// POC 
-extern void h264_hdr_decoding_poc (h264_Info * pInfo,int32_t NonExisting, int32_t frame_num);
-extern void h264_hdr_post_poc(h264_Info* pInfo,int32_t NonExisting, int32_t frame_num, int32_t use_old);
+///// POC
+    extern void h264_hdr_decoding_poc (h264_Info * pInfo,int32_t NonExisting, int32_t frame_num);
+    extern void h264_hdr_post_poc(h264_Info* pInfo,int32_t NonExisting, int32_t frame_num, int32_t use_old);
 
 ///// DPB buffer mangement
-extern void h264_init_dpb(h264_DecodedPictureBuffer * p_dpb);
+    extern void h264_init_dpb(h264_DecodedPictureBuffer * p_dpb);
 
-extern void h264_dpb_unmark_for_reference(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc);
-extern void h264_dpb_unmark_for_long_term_reference(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc);
-extern void h264_dpb_unmark_long_term_frame_for_reference_by_frame_idx(h264_DecodedPictureBuffer *p_dpb, int32_t long_term_frame_idx);
-extern void h264_dpb_unmark_long_term_field_for_reference_by_frame_idx(h264_DecodedPictureBuffer *p_dpb, int32_t long_term_frame_idx, int32_t fs_idc, int32_t polarity);
-extern void h264_dpb_mark_pic_long_term(h264_Info * pInfo, int32_t long_term_frame_idx, int32_t picNumX);
-extern void h264_dpb_mark_dangling_field(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc);
+    extern void h264_dpb_unmark_for_reference(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc);
+    extern void h264_dpb_unmark_for_long_term_reference(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc);
+    extern void h264_dpb_unmark_long_term_frame_for_reference_by_frame_idx(h264_DecodedPictureBuffer *p_dpb, int32_t long_term_frame_idx);
+    extern void h264_dpb_unmark_long_term_field_for_reference_by_frame_idx(h264_DecodedPictureBuffer *p_dpb, int32_t long_term_frame_idx, int32_t fs_idc, int32_t polarity);
+    extern void h264_dpb_mark_pic_long_term(h264_Info * pInfo, int32_t long_term_frame_idx, int32_t picNumX);
+    extern void h264_dpb_mark_dangling_field(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc);
 
-extern void h264_dpb_update_queue_dangling_field(h264_Info * pInfo);
-extern void h264_dpb_is_used_for_reference(int32_t * flag);
+    extern void h264_dpb_update_queue_dangling_field(h264_Info * pInfo);
+    extern void h264_dpb_is_used_for_reference(int32_t * flag);
 
 
-extern void h264_dpb_set_active_fs(h264_DecodedPictureBuffer * p_dpb,int32_t index);
-extern void h264_dpb_flush_dpb (h264_Info * pInfo,int32_t output_all, int32_t keep_complement, int32_t num_ref_frames);
+    extern void h264_dpb_set_active_fs(h264_DecodedPictureBuffer * p_dpb,int32_t index);
+    extern void h264_dpb_flush_dpb (h264_Info * pInfo,int32_t output_all, int32_t keep_complement, int32_t num_ref_frames);
 
-extern void h264_dpb_idr_memory_management (h264_Info * pInfo,
-											seq_param_set_used_ptr active_sps,
-											int32_t no_output_of_prior_pics_flag);
+    extern void h264_dpb_idr_memory_management (h264_Info * pInfo,
+            seq_param_set_used_ptr active_sps,
+            int32_t no_output_of_prior_pics_flag);
 
-extern void h264_dpb_init_frame_store(h264_Info * pInfo);
-extern void h264_dpb_reset_dpb(h264_Info * pInfo,int32_t PicWidthInMbs, int32_t FrameHeightInMbs, 
-							   int32_t SizeChange, int32_t no_output_of_prior_pics_flag);
+    extern void h264_dpb_init_frame_store(h264_Info * pInfo);
+    extern void h264_dpb_reset_dpb(h264_Info * pInfo,int32_t PicWidthInMbs, int32_t FrameHeightInMbs,
+                                   int32_t SizeChange, int32_t no_output_of_prior_pics_flag);
 
-extern void h264_dpb_gaps_in_frame_num_mem_management(h264_Info * pInfo);
+    extern void h264_dpb_gaps_in_frame_num_mem_management(h264_Info * pInfo);
 
-extern int32_t h264_dpb_assign_frame_store(h264_Info * pInfo, int32_t NonExisting);
+    extern int32_t h264_dpb_assign_frame_store(h264_Info * pInfo, int32_t NonExisting);
 
-extern void h264_dpb_get_smallest_poc(h264_DecodedPictureBuffer *p_dpb, int32_t *poc, int32_t *pos);
-extern void h264_dpb_remove_unused_frame_from_dpb(h264_DecodedPictureBuffer *p_dpb, int32_t * flag);
+    extern void h264_dpb_get_smallest_poc(h264_DecodedPictureBuffer *p_dpb, int32_t *poc, int32_t *pos);
+    extern void h264_dpb_remove_unused_frame_from_dpb(h264_DecodedPictureBuffer *p_dpb, int32_t * flag);
 
-extern void h264_dpb_sliding_window_memory_management(h264_DecodedPictureBuffer *p_dpb,
-													  int32_t NonExisting, 
-													  int32_t num_ref_frames);
-extern int32_t h264_dpb_queue_update(h264_Info * pInfo,
-									 int32_t push, 
-									 int32_t direct, 
-									 int32_t frame_request, 
-									 int32_t num_ref_frames);
+    extern void h264_dpb_sliding_window_memory_management(h264_DecodedPictureBuffer *p_dpb,
+            int32_t NonExisting,
+            int32_t num_ref_frames);
+    extern int32_t h264_dpb_queue_update(h264_Info * pInfo,
+                                         int32_t push,
+                                         int32_t direct,
+                                         int32_t frame_request,
+                                         int32_t num_ref_frames);
 
-extern void h264_dpb_split_field (h264_Info * pInfo);
-extern void h264_dpb_combine_field(int32_t use_old);
+    extern void h264_dpb_split_field (h264_Info * pInfo);
+    extern void h264_dpb_combine_field(int32_t use_old);
 
-extern void h264_dpb_insert_picture_in_dpb(h264_Info * pInfo,
-										   int32_t used_for_reference, 
-										   int32_t add2dpb, 
-										   int32_t NonExisting, 
-										   int32_t use_old);
+    extern void h264_dpb_insert_picture_in_dpb(h264_Info * pInfo,
+            int32_t used_for_reference,
+            int32_t add2dpb,
+            int32_t NonExisting,
+            int32_t use_old);
 
-extern void h264_dpb_store_previous_picture_in_dpb(h264_Info * pInfo,
-											int32_t NonExisting, 
-											int32_t use_old);
+    extern void h264_dpb_store_previous_picture_in_dpb(h264_Info * pInfo,
+            int32_t NonExisting,
+            int32_t use_old);
 
-extern void h264_dpb_adaptive_memory_management (h264_Info * pInfo);
+    extern void h264_dpb_adaptive_memory_management (h264_Info * pInfo);
 
-extern int32_t h264_dpb_output_one_frame_from_dpb(h264_Info* pInfo,
-			int32_t direct, int32_t request, int32_t num_ref_frames);
+    extern int32_t h264_dpb_output_one_frame_from_dpb(h264_Info* pInfo,
+            int32_t direct, int32_t request, int32_t num_ref_frames);
 
-extern void h264_dpb_remove_frame_from_dpb(h264_DecodedPictureBuffer *p_dpb, int32_t idx);
-extern void h264_dpb_frame_output(h264_Info * pInfo,int32_t fs_idc, int32_t direct, int32_t * existing);
+    extern void h264_dpb_remove_frame_from_dpb(h264_DecodedPictureBuffer *p_dpb, int32_t idx);
+    extern void h264_dpb_frame_output(h264_Info * pInfo,int32_t fs_idc, int32_t direct, int32_t * existing);
 
 //////////////////////////////////////////////////////////// Globals
-extern frame_store *active_fs;
+    extern frame_store *active_fs;
 
 
 #ifdef __cplusplus
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse_sei.h b/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse_sei.h
index e5903cd..f0a591d 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse_sei.h
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/include/h264parse_sei.h
@@ -31,53 +31,53 @@
 #define SEI_SCAN_FORMAT_INTERLACED      0x1
 #define SEI_SCAN_FORMAT_PROGRESSIVE     0x3
 #define SEI_SCAN_FORMAT_VALID(r)        (r&0x1)
-#define SEI_SCAN_FORMAT(r)              ((r&0x2)>>1)        
+#define SEI_SCAN_FORMAT(r)              ((r&0x2)>>1)
 
-typedef enum 
+typedef enum
 {
-	SEI_BUF_PERIOD = 0,
-	SEI_PIC_TIMING,
-	SEI_PAN_SCAN,
-	SEI_FILLER_PAYLOAD,
-	SEI_REG_USERDATA,
-	SEI_UNREG_USERDATA,
-	SEI_RECOVERY_POINT,
-	SEI_DEC_REF_PIC_MARKING_REP,
-	SEI_SPARE_PIC,
-	SEI_SCENE_INFO,
-	SEI_SUB_SEQ_INFO,
-	SEI_SUB_SEQ_LAYER,
-	SEI_SUB_SEQ,
-	SEI_FULL_FRAME_FREEZE,
-	SEI_FULL_FRAME_FREEZE_RELEASE,
-	SEI_FULL_FRAME_SNAPSHOT,
-	SEI_PROGRESSIVE_SEGMENT_START,
-	SEI_PROGRESSIVE_SEGMENT_END,
-	SEI_MOTION_CONSTRAINED_SLICE_GRP_SET,
-	SEI_FILM_GRAIN_CHARACTERISTICS,
-	SEI_DEBLK_FILTER_DISPLAY_PREFERENCE,
-	SEI_STEREO_VIDEO_INFO,
-	SEI_RESERVED,
-}h264_sei_payloadtype;
+    SEI_BUF_PERIOD = 0,
+    SEI_PIC_TIMING,
+    SEI_PAN_SCAN,
+    SEI_FILLER_PAYLOAD,
+    SEI_REG_USERDATA,
+    SEI_UNREG_USERDATA,
+    SEI_RECOVERY_POINT,
+    SEI_DEC_REF_PIC_MARKING_REP,
+    SEI_SPARE_PIC,
+    SEI_SCENE_INFO,
+    SEI_SUB_SEQ_INFO,
+    SEI_SUB_SEQ_LAYER,
+    SEI_SUB_SEQ,
+    SEI_FULL_FRAME_FREEZE,
+    SEI_FULL_FRAME_FREEZE_RELEASE,
+    SEI_FULL_FRAME_SNAPSHOT,
+    SEI_PROGRESSIVE_SEGMENT_START,
+    SEI_PROGRESSIVE_SEGMENT_END,
+    SEI_MOTION_CONSTRAINED_SLICE_GRP_SET,
+    SEI_FILM_GRAIN_CHARACTERISTICS,
+    SEI_DEBLK_FILTER_DISPLAY_PREFERENCE,
+    SEI_STEREO_VIDEO_INFO,
+    SEI_RESERVED,
+} h264_sei_payloadtype;
 
 
 
 typedef struct _h264_SEI_buffering_period
 {
-  	int32_t seq_param_set_id;
-   int32_t initial_cpb_removal_delay_nal;
-   int32_t initial_cpb_removal_delay_offset_nal; 
-   int32_t initial_cpb_removal_delay_vcl;
-   int32_t initial_cpb_removal_delay_offset_vcl; 
+    int32_t seq_param_set_id;
+    int32_t initial_cpb_removal_delay_nal;
+    int32_t initial_cpb_removal_delay_offset_nal;
+    int32_t initial_cpb_removal_delay_vcl;
+    int32_t initial_cpb_removal_delay_offset_vcl;
 
-}h264_SEI_buffering_period_t;
+} h264_SEI_buffering_period_t;
 
 typedef struct _h264_SEI_pic_timing
 {
-	int32_t cpb_removal_delay;
-	int32_t dpb_output_delay;
-	int32_t pic_struct;
-}h264_SEI_pic_timing_t;
+    int32_t cpb_removal_delay;
+    int32_t dpb_output_delay;
+    int32_t pic_struct;
+} h264_SEI_pic_timing_t;
 
 #if 0
 int32_t clock_timestamp_flag[MAX_NUM_CLOCK_TS];
@@ -96,191 +96,191 @@
 int32_t hours_flag[MAX_NUM_CLOCK_TS];
 int32_t time_offset[MAX_NUM_CLOCK_TS];
 
-#endif 
+#endif
 
 typedef struct _h264_SEI_pan_scan_rectangle
 {
-	int32_t pan_scan_rect_id;
-	int32_t pan_scan_rect_cancel_flag;
-	int32_t pan_scan_cnt_minus1;
-	int32_t pan_scan_rect_left_offset[MAX_PAN_SCAN_CNT];
-	int32_t pan_scan_rect_right_offset[MAX_PAN_SCAN_CNT];
-	int32_t pan_scan_rect_top_offset[MAX_PAN_SCAN_CNT];
-	int32_t pan_scan_rect_bottom_offset[MAX_PAN_SCAN_CNT];
-	int32_t pan_scan_rect_repetition_period;
-}h264_SEI_pan_scan_rectangle_t;
+    int32_t pan_scan_rect_id;
+    int32_t pan_scan_rect_cancel_flag;
+    int32_t pan_scan_cnt_minus1;
+    int32_t pan_scan_rect_left_offset[MAX_PAN_SCAN_CNT];
+    int32_t pan_scan_rect_right_offset[MAX_PAN_SCAN_CNT];
+    int32_t pan_scan_rect_top_offset[MAX_PAN_SCAN_CNT];
+    int32_t pan_scan_rect_bottom_offset[MAX_PAN_SCAN_CNT];
+    int32_t pan_scan_rect_repetition_period;
+} h264_SEI_pan_scan_rectangle_t;
 
 typedef struct _h264_SEI_filler_payload
 {
-	int32_t ff_byte;
-}h264_SEI_filler_payload_t;
+    int32_t ff_byte;
+} h264_SEI_filler_payload_t;
 
 typedef struct _h264_SEI_userdata_registered
 {
-	int32_t itu_t_t35_country_code;
-	int32_t itu_t_t35_country_code_extension_byte;
-	int32_t itu_t_t35_payload_byte;
-}h264_SEI_userdata_registered_t;
+    int32_t itu_t_t35_country_code;
+    int32_t itu_t_t35_country_code_extension_byte;
+    int32_t itu_t_t35_payload_byte;
+} h264_SEI_userdata_registered_t;
 
 typedef struct _h264_SEI_userdata_unregistered
 {
-	int32_t uuid_iso_iec_11578[4];
-	int32_t user_data_payload_byte;
-}h264_SEI_userdata_unregistered_t;
+    int32_t uuid_iso_iec_11578[4];
+    int32_t user_data_payload_byte;
+} h264_SEI_userdata_unregistered_t;
 
 typedef struct _h264_SEI_recovery_point
 {
-	int32_t recovery_frame_cnt;
-	int32_t exact_match_flag;
-	int32_t broken_link_flag;
-	int32_t changing_slice_group_idc;
-}h264_SEI_recovery_point_t;
+    int32_t recovery_frame_cnt;
+    int32_t exact_match_flag;
+    int32_t broken_link_flag;
+    int32_t changing_slice_group_idc;
+} h264_SEI_recovery_point_t;
 
 typedef struct _h264_SEI_decoded_ref_pic_marking_repetition
 {
-	int32_t original_idr_flag;
-	int32_t original_frame_num;
-	int32_t orignal_field_pic_flag;
-	int32_t original_bottom_field_pic_flag;
-	int32_t no_output_of_prior_pics_flag;
-	int32_t long_term_reference_flag;
-	int32_t adaptive_ref_pic_marking_mode_flag;
-	int32_t memory_management_control_operation;				//UE
-	int32_t difference_of_pics_num_minus1;						//UE
-	int32_t long_term_pic_num;									//UE
-	int32_t long_term_frame_idx;								//UE
-	int32_t max_long_term_frame_idx_plus1;						//UE
-}h264_SEI_decoded_ref_pic_marking_repetition_t;
+    int32_t original_idr_flag;
+    int32_t original_frame_num;
+    int32_t orignal_field_pic_flag;
+    int32_t original_bottom_field_pic_flag;
+    int32_t no_output_of_prior_pics_flag;
+    int32_t long_term_reference_flag;
+    int32_t adaptive_ref_pic_marking_mode_flag;
+    int32_t memory_management_control_operation;				//UE
+    int32_t difference_of_pics_num_minus1;						//UE
+    int32_t long_term_pic_num;									//UE
+    int32_t long_term_frame_idx;								//UE
+    int32_t max_long_term_frame_idx_plus1;						//UE
+} h264_SEI_decoded_ref_pic_marking_repetition_t;
 
 typedef struct _h264_SEI_spare_picture
 {
-	int32_t target_frame_num;
-	int32_t spare_field_flag;
-	int32_t target_bottom_field_flag;
-	int32_t num_spare_pics_minus1;
-	int32_t delta_spare_frame_num[MAX_NUM_SPARE_PICS];
-	int32_t spare_bottom_field_flag[MAX_NUM_SPARE_PICS];
-	int32_t spare_area_idc[MAX_NUM_SPARE_PICS];				// not complete
-}h264_SEI_spare_picture_t;
+    int32_t target_frame_num;
+    int32_t spare_field_flag;
+    int32_t target_bottom_field_flag;
+    int32_t num_spare_pics_minus1;
+    int32_t delta_spare_frame_num[MAX_NUM_SPARE_PICS];
+    int32_t spare_bottom_field_flag[MAX_NUM_SPARE_PICS];
+    int32_t spare_area_idc[MAX_NUM_SPARE_PICS];				// not complete
+} h264_SEI_spare_picture_t;
 
 typedef struct _h264_SEI_scene_info
 {
-	int32_t scene_info_present_flag;
-	int32_t scene_id;
-	int32_t scene_transitioning_type;
-	int32_t second_scene_id;
-}h264_SEI_scene_info_t;
+    int32_t scene_info_present_flag;
+    int32_t scene_id;
+    int32_t scene_transitioning_type;
+    int32_t second_scene_id;
+} h264_SEI_scene_info_t;
 
 typedef struct _h264_SEI_sub_sequence_info
 {
-	int32_t sub_seq_layer_num;
-	int32_t sub_seq_id;
-	int32_t first_ref_pic_flag;
-	int32_t leading_non_ref_pic_flag;
-	int32_t last_pic_flag;
-	int32_t sub_seq_frame_num_flag;
-	int32_t sub_seq_frame_num;
-}h264_SEI_sub_sequence_info_t;
+    int32_t sub_seq_layer_num;
+    int32_t sub_seq_id;
+    int32_t first_ref_pic_flag;
+    int32_t leading_non_ref_pic_flag;
+    int32_t last_pic_flag;
+    int32_t sub_seq_frame_num_flag;
+    int32_t sub_seq_frame_num;
+} h264_SEI_sub_sequence_info_t;
 
 typedef struct _h264_SEI_sub_sequence_layer
 {
-	int32_t num_sub_seq_layers_minus1;
-	int32_t accurate_statistics_flag[MAX_SUB_SEQ_LAYERS];
-	int32_t average_bit_rate[MAX_SUB_SEQ_LAYERS];
-	int32_t average_frame_rate[MAX_SUB_SEQ_LAYERS];
-}h264_SEI_sub_sequence_layer_t;
+    int32_t num_sub_seq_layers_minus1;
+    int32_t accurate_statistics_flag[MAX_SUB_SEQ_LAYERS];
+    int32_t average_bit_rate[MAX_SUB_SEQ_LAYERS];
+    int32_t average_frame_rate[MAX_SUB_SEQ_LAYERS];
+} h264_SEI_sub_sequence_layer_t;
 
 typedef struct _h264_SEI_sub_sequence
 {
-	int32_t sub_seq_layer_num;
-	int32_t sub_seq_id;
-	int32_t duration_flag;
-	int32_t sub_seq_duration;
-	int32_t average_rate_flag;
-	int32_t average_statistics_flag;
-	int32_t average_bit_rate;
-	int32_t average_frame_rate;
-	int32_t num_referenced_subseqs;
-	int32_t ref_sub_seq_layer_num;
-	int32_t ref_sub_seq_id;
-	int32_t ref_sub_seq_direction;
-}h264_SEI_sub_sequence_t;
+    int32_t sub_seq_layer_num;
+    int32_t sub_seq_id;
+    int32_t duration_flag;
+    int32_t sub_seq_duration;
+    int32_t average_rate_flag;
+    int32_t average_statistics_flag;
+    int32_t average_bit_rate;
+    int32_t average_frame_rate;
+    int32_t num_referenced_subseqs;
+    int32_t ref_sub_seq_layer_num;
+    int32_t ref_sub_seq_id;
+    int32_t ref_sub_seq_direction;
+} h264_SEI_sub_sequence_t;
 
 typedef struct _h264_SEI_full_frame_freeze
 {
-	int32_t full_frame_freeze_repetition_period;
-}h264_SEI_full_frame_freeze_t;
+    int32_t full_frame_freeze_repetition_period;
+} h264_SEI_full_frame_freeze_t;
 
 typedef struct _h264_SEI_full_frame_snapshot
 {
-	int32_t snapshot_id;
-}h264_SEI_full_frame_snapshot_t;
+    int32_t snapshot_id;
+} h264_SEI_full_frame_snapshot_t;
 
 typedef struct _h264_SEI_progressive_segment_start
 {
-	int32_t progressive_refinement_id;
-	int32_t num_refinement_steps_minus1;
-}h264_SEI_progressive_segment_start_t;
+    int32_t progressive_refinement_id;
+    int32_t num_refinement_steps_minus1;
+} h264_SEI_progressive_segment_start_t;
 
 typedef struct _h264_SEI_progressive_segment_end
 {
-	int32_t progressive_refinement_id;
-}h264_SEI_progressive_segment_end_t;
+    int32_t progressive_refinement_id;
+} h264_SEI_progressive_segment_end_t;
 
 typedef struct _h264_SEI_motion_constrained_slice_group
 {
-	int32_t num_slice_groups_in_set_minus1;
-	int32_t slice_group_id[MAX_SLICE_GRPS];
-	int32_t exact_sample_value_match_flag;
-	int32_t pan_scan_rect_flag;
-	int32_t pan_scan_rect_id;
-}h264_SEI_motion_constrained_slice_group_t;
+    int32_t num_slice_groups_in_set_minus1;
+    int32_t slice_group_id[MAX_SLICE_GRPS];
+    int32_t exact_sample_value_match_flag;
+    int32_t pan_scan_rect_flag;
+    int32_t pan_scan_rect_id;
+} h264_SEI_motion_constrained_slice_group_t;
 
 typedef struct _h264_SEI_deblocking_filter_display_pref
 {
-	int32_t devlocking_display_preference_cancel_flag;
-	int32_t display_prior_to_deblocking_preferred_flag;
-	int32_t dec_frame_buffering_constraint_flag;
-	int32_t deblocking_display_preference_repetition_period;
-}h264_SEI_deblocking_filter_display_pref_t;
+    int32_t devlocking_display_preference_cancel_flag;
+    int32_t display_prior_to_deblocking_preferred_flag;
+    int32_t dec_frame_buffering_constraint_flag;
+    int32_t deblocking_display_preference_repetition_period;
+} h264_SEI_deblocking_filter_display_pref_t;
 
 typedef struct _h264_SEI_stereo_video_info
 {
-	int32_t field_views_flag;
-	int32_t top_field_is_left_view_flag;
-	int32_t curent_frame_is_left_view_flag;
-	int32_t next_frame_is_second_view_flag;
-	int32_t left_view_self_contained_flag;
-	int32_t right_view_self_contained_flag;
-}h264_SEI_stereo_video_info_t;
+    int32_t field_views_flag;
+    int32_t top_field_is_left_view_flag;
+    int32_t curent_frame_is_left_view_flag;
+    int32_t next_frame_is_second_view_flag;
+    int32_t left_view_self_contained_flag;
+    int32_t right_view_self_contained_flag;
+} h264_SEI_stereo_video_info_t;
 
 typedef struct _h264_SEI_reserved
 {
-	int32_t reserved_sei_message_payload_byte;
-}h264_SEI_reserved_t;
+    int32_t reserved_sei_message_payload_byte;
+} h264_SEI_reserved_t;
 
 
 ////////////////////////////
 // SEI Info
-///////////////////////////// 
+/////////////////////////////
 
 typedef struct sei_info
 {
-	int32_t recovery_point;
-	int32_t recovery_frame_num;
+    int32_t recovery_point;
+    int32_t recovery_frame_num;
 
-	int32_t capture_POC;
-	int32_t freeze_POC;
-	int32_t release_POC;        // The POC which when reached will allow display update to re-commence
-	int32_t disp_frozen;        // Indicates display is currently frozen
-	int32_t freeze_rep_period;
-	int32_t recovery_frame_cnt;
-	int32_t capture_fn;
-	int32_t recovery_fn;
-	int32_t broken_link;
-	int32_t scan_format;
-	int32_t broken_link_pic;
-}sei_info, *sei_info_ptr;
+    int32_t capture_POC;
+    int32_t freeze_POC;
+    int32_t release_POC;        // The POC which when reached will allow display update to re-commence
+    int32_t disp_frozen;        // Indicates display is currently frozen
+    int32_t freeze_rep_period;
+    int32_t recovery_frame_cnt;
+    int32_t capture_fn;
+    int32_t recovery_fn;
+    int32_t broken_link;
+    int32_t scan_format;
+    int32_t broken_link_pic;
+} sei_info, *sei_info_ptr;
 
 /*typedef struct _h264_SEI
 {
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/Android.mk b/mix_vbp/viddec_fw/fw/codecs/h264/parser/Android.mk
index 70f1388..d3e4910 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/Android.mk
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/Android.mk
@@ -18,9 +18,6 @@
 LOCAL_CFLAGS := -DVBP -DHOST_ONLY
 
 LOCAL_C_INCLUDES :=							   \
-	$(GLIB_TOP)							   \
-	$(GLIB_TOP)/android						   \
-	$(GLIB_TOP)/glib						   \
 	$(VENDORS_INTEL_MRST_MIXVBP_ROOT)/viddec_fw/include		   \
 	$(VENDORS_INTEL_MRST_MIXVBP_ROOT)/viddec_fw/fw/include		   \
 	$(VENDORS_INTEL_MRST_MIXVBP_ROOT)/viddec_fw/fw/parser/include	   \
@@ -30,7 +27,6 @@
 LOCAL_MODULE := libmixvbp_h264
 
 LOCAL_SHARED_LIBRARIES :=		\
-	libglib-2.0			\
 	libmixvbp
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse.c
index 180e7b6..e7dd6a7 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse.c
@@ -24,43 +24,43 @@
 
 h264_Status h264_Scaling_List(void *parent, uint8_t *scalingList, int32_t sizeOfScalingList, uint8_t *UseDefaultScalingMatrix, h264_Info* pInfo)
 {
-	int32_t j, scanj;
-	int32_t delta_scale, lastScale, nextScale;
+    int32_t j, scanj;
+    int32_t delta_scale, lastScale, nextScale;
 
 #if 0
-	const uint8_t ZZ_SCAN[16]  =
-	{  0,  1,  4,  8,  5,  2,  3,  6,  9, 12, 13, 10,  7, 11, 14, 15
-	};
+    const uint8_t ZZ_SCAN[16]  =
+        {  0,  1,  4,  8,  5,  2,  3,  6,  9, 12, 13, 10,  7, 11, 14, 15
+        };
 
-	const uint8_t ZZ_SCAN8[64] =
-	{  0,  1,  8, 16,  9,  2,  3, 10, 17, 24, 32, 25, 18, 11,  4,  5,
-		12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13,  6,  7, 14, 21, 28,
-		35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
-		58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
-	};
+    const uint8_t ZZ_SCAN8[64] =
+        {  0,  1,  8, 16,  9,  2,  3, 10, 17, 24, 32, 25, 18, 11,  4,  5,
+           12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13,  6,  7, 14, 21, 28,
+           35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
+           58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
+        };
 #endif
 
-	lastScale      = 8;
-	nextScale      = 8;
-   scanj = 0;
+    lastScale      = 8;
+    nextScale      = 8;
+    scanj = 0;
 
-	for(j=0; j<sizeOfScalingList; j++)
-	{
-		//scanj = (sizeOfScalingList==16)?ZZ_SCAN[j]:ZZ_SCAN8[j];
+    for (j=0; j<sizeOfScalingList; j++)
+    {
+        //scanj = (sizeOfScalingList==16)?ZZ_SCAN[j]:ZZ_SCAN8[j];
 
-		if(nextScale!=0)
-		{
-		  delta_scale = h264_GetVLCElement(parent, pInfo, true);
-		  nextScale = (lastScale + delta_scale + 256) % 256;
-		  *UseDefaultScalingMatrix = (uint8_t) (scanj==0 && nextScale==0);
-		}
+        if (nextScale!=0)
+        {
+            delta_scale = h264_GetVLCElement(parent, pInfo, true);
+            nextScale = (lastScale + delta_scale + 256) % 256;
+            *UseDefaultScalingMatrix = (uint8_t) (scanj==0 && nextScale==0);
+        }
 
-		scalingList[scanj] = (nextScale==0) ? lastScale:nextScale;
-		lastScale = scalingList[scanj];
-      scanj ++;
-	}
+        scalingList[scanj] = (nextScale==0) ? lastScale:nextScale;
+        lastScale = scalingList[scanj];
+        scanj ++;
+    }
 
-	return H264_STATUS_OK;
+    return H264_STATUS_OK;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -69,65 +69,65 @@
 
 h264_Status h264_active_par_set(h264_Info*pInfo,h264_Slice_Header_t* SliceHeader)
 {
-	//h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader;
+    //h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader;
 
-	///////////////////////////////////////////////////
-	// Reload SPS/PPS while
-	// 1) Start of Frame (in case of context switch)
-	// 2) PPS id changed
-	///////////////////////////////////////////////////
-	if((SliceHeader->first_mb_in_slice == 0) || (SliceHeader->pic_parameter_id != pInfo->active_PPS.pic_parameter_set_id)) 
-	{
+    ///////////////////////////////////////////////////
+    // Reload SPS/PPS while
+    // 1) Start of Frame (in case of context switch)
+    // 2) PPS id changed
+    ///////////////////////////////////////////////////
+    if ((SliceHeader->first_mb_in_slice == 0) || (SliceHeader->pic_parameter_id != pInfo->active_PPS.pic_parameter_set_id))
+    {
 #ifndef WIN32
-		h264_Parse_Copy_Pps_From_DDR(pInfo, &pInfo->active_PPS, SliceHeader->pic_parameter_id);
+        h264_Parse_Copy_Pps_From_DDR(pInfo, &pInfo->active_PPS, SliceHeader->pic_parameter_id);
 
-		if(pInfo->active_PPS.seq_parameter_set_id >= MAX_NUM_SPS) 
-		{
-			return H264_PPS_INVALID_PIC_ID;			/// Invalid PPS detected
-		} 
+        if (pInfo->active_PPS.seq_parameter_set_id >= MAX_NUM_SPS)
+        {
+            return H264_PPS_INVALID_PIC_ID;			/// Invalid PPS detected
+        }
 
-      if(pInfo->active_PPS.seq_parameter_set_id != pInfo->active_SPS.seq_parameter_set_id)
-      {         
-         pInfo->Is_SPS_updated =1;
-		 h264_Parse_Copy_Sps_From_DDR(pInfo, &pInfo->active_SPS, pInfo->active_PPS.seq_parameter_set_id);
-		 h264_Parse_Clear_Sps_Updated_Flag(pInfo, pInfo->active_PPS.seq_parameter_set_id);
-      }
-	  else
-	  {
-	     if(h264_Parse_Check_Sps_Updated_Flag(pInfo, pInfo->active_PPS.seq_parameter_set_id))
-	     {
-	        pInfo->Is_SPS_updated =1;
-		    h264_Parse_Copy_Sps_From_DDR(pInfo, &pInfo->active_SPS, pInfo->active_PPS.seq_parameter_set_id);
-			h264_Parse_Clear_Sps_Updated_Flag(pInfo, pInfo->active_PPS.seq_parameter_set_id);
-	     }
-	  }
-		
-#else	
-		pInfo->active_PPS = PPS_GL[SliceHeader->pic_parameter_id];
-		pInfo->active_SPS = SPS_GL[pInfo->active_PPS.seq_parameter_set_id];			
+        if (pInfo->active_PPS.seq_parameter_set_id != pInfo->active_SPS.seq_parameter_set_id)
+        {
+            pInfo->Is_SPS_updated =1;
+            h264_Parse_Copy_Sps_From_DDR(pInfo, &pInfo->active_SPS, pInfo->active_PPS.seq_parameter_set_id);
+            h264_Parse_Clear_Sps_Updated_Flag(pInfo, pInfo->active_PPS.seq_parameter_set_id);
+        }
+        else
+        {
+            if (h264_Parse_Check_Sps_Updated_Flag(pInfo, pInfo->active_PPS.seq_parameter_set_id))
+            {
+                pInfo->Is_SPS_updated =1;
+                h264_Parse_Copy_Sps_From_DDR(pInfo, &pInfo->active_SPS, pInfo->active_PPS.seq_parameter_set_id);
+                h264_Parse_Clear_Sps_Updated_Flag(pInfo, pInfo->active_PPS.seq_parameter_set_id);
+            }
+        }
+
+#else
+        pInfo->active_PPS = PPS_GL[SliceHeader->pic_parameter_id];
+        pInfo->active_SPS = SPS_GL[pInfo->active_PPS.seq_parameter_set_id];
 #endif
-	
-		if(pInfo->active_SPS.seq_parameter_set_id >= MAX_NUM_SPS) 
-		{
-			return H264_PPS_INVALID_PIC_ID;			//// Invalid SPS detected
-		} 
-	}
-	else {
-		if((pInfo->active_PPS.seq_parameter_set_id >= MAX_NUM_SPS)  || (pInfo->active_SPS.seq_parameter_set_id >= MAX_NUM_SPS))
-		{
-			return H264_PPS_INVALID_PIC_ID;			/// Invalid PPS detected
-		} 
-	}
+
+        if (pInfo->active_SPS.seq_parameter_set_id >= MAX_NUM_SPS)
+        {
+            return H264_PPS_INVALID_PIC_ID;			//// Invalid SPS detected
+        }
+    }
+    else {
+        if ((pInfo->active_PPS.seq_parameter_set_id >= MAX_NUM_SPS)  || (pInfo->active_SPS.seq_parameter_set_id >= MAX_NUM_SPS))
+        {
+            return H264_PPS_INVALID_PIC_ID;			/// Invalid PPS detected
+        }
+    }
 
 
-	pInfo->img.PicWidthInMbs    = (pInfo->active_SPS.sps_disp.pic_width_in_mbs_minus1 + 1);
-	//pInfo->img.PicHeightInMapUnits = (pInfo->active_SPS.sps_disp.pic_height_in_map_units_minus1 + 1);
-	pInfo->img.FrameHeightInMbs = pInfo->active_SPS.sps_disp.frame_mbs_only_flag?				\
-								(pInfo->active_SPS.sps_disp.pic_height_in_map_units_minus1 + 1):	\
-								((pInfo->active_SPS.sps_disp.pic_height_in_map_units_minus1 + 1)<<1);
+    pInfo->img.PicWidthInMbs    = (pInfo->active_SPS.sps_disp.pic_width_in_mbs_minus1 + 1);
+    //pInfo->img.PicHeightInMapUnits = (pInfo->active_SPS.sps_disp.pic_height_in_map_units_minus1 + 1);
+    pInfo->img.FrameHeightInMbs = pInfo->active_SPS.sps_disp.frame_mbs_only_flag?				\
+                                  (pInfo->active_SPS.sps_disp.pic_height_in_map_units_minus1 + 1):	\
+                                  ((pInfo->active_SPS.sps_disp.pic_height_in_map_units_minus1 + 1)<<1);
 
 
-	return H264_STATUS_OK;
+    return H264_STATUS_OK;
 };   //// End of h264_active_par_set
 
 /* ------------------------------------------------------------------------------------------ */
@@ -135,76 +135,76 @@
 /* ------------------------------------------------------------------------------------------ */
 
 //////////////////////////////////////////////////
-// Parse slice header info 
+// Parse slice header info
 //////////////////////////////////////////////////
 h264_Status h264_Parse_Slice_Layer_Without_Partitioning_RBSP(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader)
 {
-	h264_Status retStatus = H264_STATUS_ERROR;
+    h264_Status retStatus = H264_STATUS_ERROR;
 
-	////////////////////////////////////////////////////
-	//// Parse slice header info 
-	//// Part1: not depend on the active PPS/SPS
-	//// Part2/3: depend on the active parset
-	//////////////////////////////////////////////////
+    ////////////////////////////////////////////////////
+    //// Parse slice header info
+    //// Part1: not depend on the active PPS/SPS
+    //// Part2/3: depend on the active parset
+    //////////////////////////////////////////////////
 
-	//retStatus = h264_Parse_Slice_Header_1(pInfo);
+    //retStatus = h264_Parse_Slice_Header_1(pInfo);
 
-	SliceHeader->sh_error = 0;
-	
-	if(h264_Parse_Slice_Header_1(parent, pInfo, SliceHeader) == H264_STATUS_OK)
-	{
-		//////////////////////////////////////////
-		//// Active parameter set for this slice
-		//////////////////////////////////////////
-		retStatus = h264_active_par_set(pInfo, SliceHeader);		
-	} 
+    SliceHeader->sh_error = 0;
 
-	if(retStatus == H264_STATUS_OK) {
-		switch(pInfo->active_SPS.profile_idc)
-		{
-			case h264_ProfileBaseline:
-			case h264_ProfileMain:
-			case h264_ProfileExtended:
-				pInfo->active_PPS.transform_8x8_mode_flag=0;
-				pInfo->active_PPS.pic_scaling_matrix_present_flag =0;
-				pInfo->active_PPS.second_chroma_qp_index_offset = pInfo->active_PPS.chroma_qp_index_offset;
-			
-			default:				
-				break;
-		}
-		
-		if( h264_Parse_Slice_Header_2(parent, pInfo, SliceHeader) != H264_STATUS_OK) 
-		{
-			SliceHeader->sh_error |= 2;			
-		} 
-		else	if( h264_Parse_Slice_Header_3(parent, pInfo, SliceHeader) != H264_STATUS_OK) 
-		{
-			SliceHeader->sh_error |= 4;
-		}
+    if (h264_Parse_Slice_Header_1(parent, pInfo, SliceHeader) == H264_STATUS_OK)
+    {
+        //////////////////////////////////////////
+        //// Active parameter set for this slice
+        //////////////////////////////////////////
+        retStatus = h264_active_par_set(pInfo, SliceHeader);
+    }
 
-	} else 	{
-		SliceHeader->sh_error |= 1;
-	}
+    if (retStatus == H264_STATUS_OK) {
+        switch (pInfo->active_SPS.profile_idc)
+        {
+        case h264_ProfileBaseline:
+        case h264_ProfileMain:
+        case h264_ProfileExtended:
+            pInfo->active_PPS.transform_8x8_mode_flag=0;
+            pInfo->active_PPS.pic_scaling_matrix_present_flag =0;
+            pInfo->active_PPS.second_chroma_qp_index_offset = pInfo->active_PPS.chroma_qp_index_offset;
+
+        default:
+            break;
+        }
+
+        if ( h264_Parse_Slice_Header_2(parent, pInfo, SliceHeader) != H264_STATUS_OK)
+        {
+            SliceHeader->sh_error |= 2;
+        }
+        else	if ( h264_Parse_Slice_Header_3(parent, pInfo, SliceHeader) != H264_STATUS_OK)
+        {
+            SliceHeader->sh_error |= 4;
+        }
+
+    } else 	{
+        SliceHeader->sh_error |= 1;
+    }
 
 
-	//if(SliceHeader->sh_error) {
-		//pInfo->wl_err_flag |= VIDDEC_FW_WORKLOAD_ERR_NOTDECODABLE;
-	//}
+    //if(SliceHeader->sh_error) {
+    //pInfo->wl_err_flag |= VIDDEC_FW_WORKLOAD_ERR_NOTDECODABLE;
+    //}
 
 
 
-	//////////////////////////////////
-	//// Parse slice data (MB loop)
-	//////////////////////////////////
-	//retStatus = h264_Parse_Slice_Data(pInfo);
-	{
-		//uint32_t data = 0; 
-		//if( viddec_pm_peek_bits(parent, &data, 32) == -1)
-			//retStatus = H264_STATUS_ERROR;
-	}
-	//h264_Parse_rbsp_trailing_bits(pInfo);
+    //////////////////////////////////
+    //// Parse slice data (MB loop)
+    //////////////////////////////////
+    //retStatus = h264_Parse_Slice_Data(pInfo);
+    {
+        //uint32_t data = 0;
+        //if( viddec_pm_peek_bits(parent, &data, 32) == -1)
+        //retStatus = H264_STATUS_ERROR;
+    }
+    //h264_Parse_rbsp_trailing_bits(pInfo);
 
-	return retStatus;
+    return retStatus;
 }
 
 
@@ -215,34 +215,34 @@
 
 h264_Status h264_Parse_NAL_Unit(void *parent, h264_Info* pInfo, uint8_t *nal_ref_idc)
 {
-	h264_Status ret = H264_STATUS_ERROR;
+    h264_Status ret = H264_STATUS_ERROR;
 
-	//h264_NAL_Unit_t* NAL = &pInfo->NAL;
-	uint32_t code;
+    //h264_NAL_Unit_t* NAL = &pInfo->NAL;
+    uint32_t code;
 #if 0
-	viddec_pm_get_bits(void * parent,uint32_t * data,uint32_t num_bits)(parent, &code, 24);
-	viddec_pm_get_bits(parent, &code, 1);   //forbidden_zero_bit
+    viddec_pm_get_bits(void * parent,uint32_t * data,uint32_t num_bits)(parent, &code, 24);
+    viddec_pm_get_bits(parent, &code, 1);   //forbidden_zero_bit
 
-	viddec_pm_get_bits(parent, &code, 2);
-	SliceHeader->nal_ref_idc = (uint8_t)code;
+    viddec_pm_get_bits(parent, &code, 2);
+    SliceHeader->nal_ref_idc = (uint8_t)code;
 
-	viddec_pm_get_bits(parent, &code, 5);
-	pInfo->nal_unit_type = (uint8_t)code;
+    viddec_pm_get_bits(parent, &code, 5);
+    pInfo->nal_unit_type = (uint8_t)code;
 #else
-#ifdef VBP	
-	if( viddec_pm_get_bits(parent, &code, 8) != -1) 
+#ifdef VBP
+    if ( viddec_pm_get_bits(parent, &code, 8) != -1)
 #else
-	//// 24bit SC, 1 bit: forbidden_zero_bit, 2 bitrs: nal_ref_idc, 5 bits: nal_unit_type	
-	if( viddec_pm_get_bits(parent, &code, 32) != -1) 
-#endif	
-	{
-		*nal_ref_idc = (uint8_t)((code>>5)&0x3);
-		pInfo->nal_unit_type = (uint8_t)((code>>0)&0x1f);
-		ret = H264_STATUS_OK;
-	}
+    //// 24bit SC, 1 bit: forbidden_zero_bit, 2 bitrs: nal_ref_idc, 5 bits: nal_unit_type
+    if ( viddec_pm_get_bits(parent, &code, 32) != -1)
+#endif
+    {
+        *nal_ref_idc = (uint8_t)((code>>5)&0x3);
+        pInfo->nal_unit_type = (uint8_t)((code>>0)&0x1f);
+        ret = H264_STATUS_OK;
+    }
 #endif
 
-	return ret;
+    return ret;
 }
 
 
@@ -267,61 +267,61 @@
 
 void h264_init_old_slice(h264_Info* pInfo)
 {
-	pInfo->SliceHeader.field_pic_flag = 0;
+    pInfo->SliceHeader.field_pic_flag = 0;
 
-	pInfo->SliceHeader.pic_parameter_id = 0xFF;
+    pInfo->SliceHeader.pic_parameter_id = 0xFF;
 
-	pInfo->SliceHeader.frame_num = INT_MAX;
+    pInfo->SliceHeader.frame_num = INT_MAX;
 
-	pInfo->SliceHeader.nal_ref_idc = 0xFF;
+    pInfo->SliceHeader.nal_ref_idc = 0xFF;
 
-	pInfo->SliceHeader.idr_flag = 0;
+    pInfo->SliceHeader.idr_flag = 0;
 
-	pInfo->SliceHeader.pic_order_cnt_lsb          = UINT_MAX;
-	pInfo->SliceHeader.delta_pic_order_cnt_bottom = INT_MAX;
+    pInfo->SliceHeader.pic_order_cnt_lsb          = UINT_MAX;
+    pInfo->SliceHeader.delta_pic_order_cnt_bottom = INT_MAX;
 
-	pInfo->SliceHeader.delta_pic_order_cnt[0] = INT_MAX;
-	pInfo->SliceHeader.delta_pic_order_cnt[1] = INT_MAX;
+    pInfo->SliceHeader.delta_pic_order_cnt[0] = INT_MAX;
+    pInfo->SliceHeader.delta_pic_order_cnt[1] = INT_MAX;
 
-	return;
+    return;
 }
 
 
 void h264_init_img(h264_Info* pInfo)
 {
-   h264_memset(&(pInfo->img), 0x0, sizeof(h264_img_par) );
+    h264_memset(&(pInfo->img), 0x0, sizeof(h264_img_par) );
 
- 
-   return;
+
+    return;
 }
 
 
 void h264_init_sps_pps(struct h264_viddec_parser* parser, uint32_t *persist_mem)
 {
     int32_t i;
-    
+
     h264_Info * pInfo = &(parser->info);
-    
+
     parser->sps_pps_ddr_paddr = (uint32_t)persist_mem;
-    
-    pInfo->SPS_PADDR_GL = parser->sps_pps_ddr_paddr;   
-    pInfo->PPS_PADDR_GL = pInfo->SPS_PADDR_GL + MAX_NUM_SPS * sizeof(seq_param_set_all);   
+
+    pInfo->SPS_PADDR_GL = parser->sps_pps_ddr_paddr;
+    pInfo->PPS_PADDR_GL = pInfo->SPS_PADDR_GL + MAX_NUM_SPS * sizeof(seq_param_set_all);
     pInfo->OFFSET_REF_FRAME_PADDR_GL = pInfo->PPS_PADDR_GL + MAX_NUM_PPS * sizeof(pic_param_set);
-    pInfo->TMP_OFFSET_REFFRM_PADDR_GL = pInfo->OFFSET_REF_FRAME_PADDR_GL + 
-        MAX_NUM_SPS * sizeof(int32_t) * MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE;
+    pInfo->TMP_OFFSET_REFFRM_PADDR_GL = pInfo->OFFSET_REF_FRAME_PADDR_GL +
+                                        MAX_NUM_SPS * sizeof(int32_t) * MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE;
 
     h264_memset( &(pInfo->active_SPS), 0x0, sizeof(seq_param_set_used) );
     h264_memset( &(pInfo->active_PPS), 0x0, sizeof(pic_param_set) );
 
     /* Global for SPS   & PPS */
-    for(i=0;i<MAX_NUM_SPS;i++)   
+    for (i=0; i<MAX_NUM_SPS; i++)
     {
-        pInfo->active_SPS.seq_parameter_set_id = 0xff; 
+        pInfo->active_SPS.seq_parameter_set_id = 0xff;
         h264_Parse_Copy_Sps_To_DDR (pInfo, &(pInfo->active_SPS), i);
     }
-    for(i=0;i<MAX_NUM_PPS;i++)   
+    for (i=0; i<MAX_NUM_PPS; i++)
     {
-        pInfo->active_PPS.seq_parameter_set_id = 0xff; 
+        pInfo->active_PPS.seq_parameter_set_id = 0xff;
         h264_Parse_Copy_Pps_To_DDR (pInfo, &(pInfo->active_PPS), i);
     }
 
@@ -344,14 +344,14 @@
     h264_memset( &(pInfo->img), 0x0, sizeof(h264_img_par) );
 
     pInfo->h264_list_replacement = 0;
-	
+
     pInfo->h264_pwt_start_byte_offset = 0;
     pInfo->h264_pwt_start_bit_offset = 0;
     pInfo->h264_pwt_end_byte_offset = 0;
     pInfo->h264_pwt_end_bit_offset = 0;
     pInfo->h264_pwt_enabled = 0;
 
-    for(i=0;i<32;i++)   
+    for (i=0; i<32; i++)
     {
         pInfo->slice_ref_list0[i] = 0;
         pInfo->slice_ref_list1[i] = 0;
@@ -370,20 +370,20 @@
     pInfo->is_frame_boundary_detected_by_non_slice_nal = 0;
     pInfo->is_frame_boundary_detected_by_slice_nal = 0;
     pInfo->is_current_workload_done = 0;
-	
+
     pInfo->sei_rp_received = 0;
     pInfo->last_I_frame_idc = 255;
     pInfo->wl_err_curr = 0;
     pInfo->wl_err_next = 0;
 
     pInfo->primary_pic_type_plus_one = 0;
-	pInfo->sei_b_state_ready = 0;				
-	
+    pInfo->sei_b_state_ready = 0;
+
     /* Init old slice structure  */
-    h264_init_old_slice(pInfo);		
+    h264_init_old_slice(pInfo);
 
     /* init_dpb */
-    h264_init_dpb(&(pInfo->dpb)); 	
+    h264_init_dpb(&(pInfo->dpb));
 
     /* init_sei	*/
     h264_sei_stream_initialise(pInfo);
@@ -391,73 +391,73 @@
 }
 
 void h264_init_Info(h264_Info* pInfo)
-{   
-    h264_memset(pInfo, 0x0, sizeof(h264_Info));  
+{
+    h264_memset(pInfo, 0x0, sizeof(h264_Info));
 
     pInfo->old_nal_unit_type = 0xff;
 
     pInfo->Is_first_frame_in_stream =1;
-    pInfo->img.frame_count = 0;    
-    pInfo->last_I_frame_idc = 255;	
-    
+    pInfo->img.frame_count = 0;
+    pInfo->last_I_frame_idc = 255;
+
     return;
 }
- 
- /* ------------------------------------------------------------------------------------------ */
+
+/* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 
 /////////////////////////////////////////////////////
 //
-// Judge whether it is the first VCL of a new picture 
+// Judge whether it is the first VCL of a new picture
 //
 /////////////////////////////////////////////////////
- int32_t h264_is_second_field(h264_Info * pInfo)
- {
+int32_t h264_is_second_field(h264_Info * pInfo)
+{
     h264_Slice_Header_t cur_slice = pInfo->SliceHeader;
     OldSliceParams old_slice = pInfo->old_slice;
- 
+
     int result = 0;
- 
+
     //pInfo->img.second_field = 0;
- 
+
     /// is it second field?
- 
+
     //OS_INFO( "xxx is_used = %d\n", pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].is_used);
- 
-    if (cur_slice.structure != FRAME) 
+
+    if (cur_slice.structure != FRAME)
     {
-       if( ( MPD_DPB_FS_NULL_IDC != pInfo->dpb.fs_dec_idc)&&(3 != viddec_h264_get_is_used(&(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc])) )
-         &&(0 != viddec_h264_get_is_used(&(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc])) ))
-       {
-          if ((cur_slice.frame_num == old_slice.frame_num)||(cur_slice.idr_flag)) 
-          {
- 
-             if(old_slice.structure != cur_slice.structure) 
-             {
- 
-                if (((cur_slice.structure == TOP_FIELD &&old_slice.structure == BOTTOM_FIELD) || // Condition 1:
-                      (old_slice.structure == TOP_FIELD && cur_slice.structure == BOTTOM_FIELD)) &&    \
-                   ((old_slice.nal_ref_idc ==0 && cur_slice.nal_ref_idc == 0)              || // Condition 2:
-                      (old_slice.nal_ref_idc !=0 &&cur_slice.nal_ref_idc != 0))) 
+        if ( ( MPD_DPB_FS_NULL_IDC != pInfo->dpb.fs_dec_idc)&&(3 != viddec_h264_get_is_used(&(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc])) )
+                &&(0 != viddec_h264_get_is_used(&(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc])) ))
+        {
+            if ((cur_slice.frame_num == old_slice.frame_num)||(cur_slice.idr_flag))
+            {
+
+                if (old_slice.structure != cur_slice.structure)
                 {
-                   //pInfo->img.second_field = 1;
-                   result = 1;
-                }            
-             }
-          }
- 
- 
-       }
-          
- 
+
+                    if (((cur_slice.structure == TOP_FIELD &&old_slice.structure == BOTTOM_FIELD) || // Condition 1:
+                            (old_slice.structure == TOP_FIELD && cur_slice.structure == BOTTOM_FIELD)) &&    \
+                            ((old_slice.nal_ref_idc ==0 && cur_slice.nal_ref_idc == 0)              || // Condition 2:
+                             (old_slice.nal_ref_idc !=0 &&cur_slice.nal_ref_idc != 0)))
+                    {
+                        //pInfo->img.second_field = 1;
+                        result = 1;
+                    }
+                }
+            }
+
+
+        }
+
+
     }
-    
-    
-    
+
+
+
     return result;
- 
- } //// End of h264_is_second_field
+
+} //// End of h264_is_second_field
 
 
 
@@ -467,86 +467,86 @@
 
 int32_t h264_is_new_picture_start(h264_Info * pInfo, h264_Slice_Header_t cur_slice, h264_Slice_Header_t old_slice)
 {
-	int result = 0;
+    int result = 0;
 
-    if(pInfo->number_of_first_au_info_nal_before_first_slice)
+    if (pInfo->number_of_first_au_info_nal_before_first_slice)
     {
-       pInfo->number_of_first_au_info_nal_before_first_slice = 0;
-       return 1;
+        pInfo->number_of_first_au_info_nal_before_first_slice = 0;
+        return 1;
     }
 
-	
 
-	result |= (old_slice.pic_parameter_id != cur_slice.pic_parameter_id);
-	result |= (old_slice.frame_num != cur_slice.frame_num);
-	result |= (old_slice.field_pic_flag != cur_slice.field_pic_flag);
-	if(cur_slice.field_pic_flag && old_slice.field_pic_flag)
-	{
-		result |= (old_slice.bottom_field_flag != cur_slice.bottom_field_flag);
-	}
 
-	result |= (old_slice.nal_ref_idc != cur_slice.nal_ref_idc) && \
-			 ((old_slice.nal_ref_idc == 0) || (cur_slice.nal_ref_idc == 0));
-	result |= ( old_slice.idr_flag != cur_slice.idr_flag);
+    result |= (old_slice.pic_parameter_id != cur_slice.pic_parameter_id);
+    result |= (old_slice.frame_num != cur_slice.frame_num);
+    result |= (old_slice.field_pic_flag != cur_slice.field_pic_flag);
+    if (cur_slice.field_pic_flag && old_slice.field_pic_flag)
+    {
+        result |= (old_slice.bottom_field_flag != cur_slice.bottom_field_flag);
+    }
 
-	if (cur_slice.idr_flag && old_slice.idr_flag)
-	{
-		result |= (old_slice.idr_pic_id != cur_slice.idr_pic_id);
-	}
+    result |= (old_slice.nal_ref_idc != cur_slice.nal_ref_idc) && \
+              ((old_slice.nal_ref_idc == 0) || (cur_slice.nal_ref_idc == 0));
+    result |= ( old_slice.idr_flag != cur_slice.idr_flag);
 
-	if (pInfo->active_SPS.pic_order_cnt_type == 0)
-	{
-		result |=  (old_slice.pic_order_cnt_lsb          != cur_slice.pic_order_cnt_lsb);
-		result |=  (old_slice.delta_pic_order_cnt_bottom != cur_slice.delta_pic_order_cnt_bottom);
-	}
+    if (cur_slice.idr_flag && old_slice.idr_flag)
+    {
+        result |= (old_slice.idr_pic_id != cur_slice.idr_pic_id);
+    }
 
-	if (pInfo->active_SPS.pic_order_cnt_type == 1)
-	{
-		result |= (old_slice.delta_pic_order_cnt[0] != cur_slice.delta_pic_order_cnt[0]);
-		result |= (old_slice.delta_pic_order_cnt[1] != cur_slice.delta_pic_order_cnt[1]);
-	}
+    if (pInfo->active_SPS.pic_order_cnt_type == 0)
+    {
+        result |=  (old_slice.pic_order_cnt_lsb          != cur_slice.pic_order_cnt_lsb);
+        result |=  (old_slice.delta_pic_order_cnt_bottom != cur_slice.delta_pic_order_cnt_bottom);
+    }
 
-   return result;
+    if (pInfo->active_SPS.pic_order_cnt_type == 1)
+    {
+        result |= (old_slice.delta_pic_order_cnt[0] != cur_slice.delta_pic_order_cnt[0]);
+        result |= (old_slice.delta_pic_order_cnt[1] != cur_slice.delta_pic_order_cnt[1]);
+    }
+
+    return result;
 }
 
 
 int32_t h264_check_previous_frame_end(h264_Info * pInfo)
 {
-	int result = 0;
+    int result = 0;
 
-	if( (h264_NAL_UNIT_TYPE_SLICE==pInfo->old_nal_unit_type)||(h264_NAL_UNIT_TYPE_IDR==pInfo->old_nal_unit_type) )
-	{
+    if ( (h264_NAL_UNIT_TYPE_SLICE==pInfo->old_nal_unit_type)||(h264_NAL_UNIT_TYPE_IDR==pInfo->old_nal_unit_type) )
+    {
 
-		switch ( pInfo->nal_unit_type )
-		{	
-			case h264_NAL_UNIT_TYPE_Acc_unit_delimiter:
-			case h264_NAL_UNIT_TYPE_SPS:
-			case h264_NAL_UNIT_TYPE_PPS:
-			case h264_NAL_UNIT_TYPE_SEI:
-			case h264_NAL_UNIT_TYPE_EOSeq:
-			case h264_NAL_UNIT_TYPE_EOstream:
-			case h264_NAL_UNIT_TYPE_Reserved1:
-			case h264_NAL_UNIT_TYPE_Reserved2:
-			case h264_NAL_UNIT_TYPE_Reserved3: 			
-			case h264_NAL_UNIT_TYPE_Reserved4:
-			case h264_NAL_UNIT_TYPE_Reserved5:
-			{
-				pInfo->img.current_slice_num = 0;
-				
-				if((pInfo->img.structure == FRAME) || (pInfo->img.second_field)) {					
-					pInfo->is_frame_boundary_detected_by_non_slice_nal =1;
-					pInfo->is_current_workload_done=1;
-					result=1;
-				} 
-				break;
-			}
-			default:	
-				break;
-		}
+        switch ( pInfo->nal_unit_type )
+        {
+        case h264_NAL_UNIT_TYPE_Acc_unit_delimiter:
+        case h264_NAL_UNIT_TYPE_SPS:
+        case h264_NAL_UNIT_TYPE_PPS:
+        case h264_NAL_UNIT_TYPE_SEI:
+        case h264_NAL_UNIT_TYPE_EOSeq:
+        case h264_NAL_UNIT_TYPE_EOstream:
+        case h264_NAL_UNIT_TYPE_Reserved1:
+        case h264_NAL_UNIT_TYPE_Reserved2:
+        case h264_NAL_UNIT_TYPE_Reserved3:
+        case h264_NAL_UNIT_TYPE_Reserved4:
+        case h264_NAL_UNIT_TYPE_Reserved5:
+        {
+            pInfo->img.current_slice_num = 0;
 
-	}
+            if ((pInfo->img.structure == FRAME) || (pInfo->img.second_field)) {
+                pInfo->is_frame_boundary_detected_by_non_slice_nal =1;
+                pInfo->is_current_workload_done=1;
+                result=1;
+            }
+            break;
+        }
+        default:
+            break;
+        }
 
-	return result;
+    }
+
+    return result;
 
 }
 
@@ -562,43 +562,43 @@
 //////////////////////////////////////////////////////////////
 void h264_update_old_slice(h264_Info * pInfo,h264_Slice_Header_t next_SliceHeader)
 {
-	pInfo->old_slice.pic_parameter_id = pInfo->SliceHeader.pic_parameter_id;
+    pInfo->old_slice.pic_parameter_id = pInfo->SliceHeader.pic_parameter_id;
 
-	pInfo->old_slice.frame_num = pInfo->SliceHeader.frame_num;
+    pInfo->old_slice.frame_num = pInfo->SliceHeader.frame_num;
 
-	pInfo->old_slice.field_pic_flag = pInfo->SliceHeader.field_pic_flag;
+    pInfo->old_slice.field_pic_flag = pInfo->SliceHeader.field_pic_flag;
 
-	if(pInfo->SliceHeader.field_pic_flag)
-	{
-		pInfo->old_slice.bottom_field_flag = pInfo->SliceHeader.bottom_field_flag;
-	}
+    if (pInfo->SliceHeader.field_pic_flag)
+    {
+        pInfo->old_slice.bottom_field_flag = pInfo->SliceHeader.bottom_field_flag;
+    }
 
-	pInfo->old_slice.nal_ref_idc   = pInfo->SliceHeader.nal_ref_idc;
+    pInfo->old_slice.nal_ref_idc   = pInfo->SliceHeader.nal_ref_idc;
 
-	pInfo->old_slice.structure = pInfo->SliceHeader.structure;
+    pInfo->old_slice.structure = pInfo->SliceHeader.structure;
 
-	pInfo->old_slice.idr_flag = pInfo->SliceHeader.idr_flag;
-	if (pInfo->SliceHeader.idr_flag)
-	{
-		pInfo->old_slice.idr_pic_id = pInfo->SliceHeader.idr_pic_id;
-	}
+    pInfo->old_slice.idr_flag = pInfo->SliceHeader.idr_flag;
+    if (pInfo->SliceHeader.idr_flag)
+    {
+        pInfo->old_slice.idr_pic_id = pInfo->SliceHeader.idr_pic_id;
+    }
 
-	if (pInfo->active_SPS.pic_order_cnt_type == 0)
-	{
-		pInfo->old_slice.pic_order_cnt_lsb          = pInfo->SliceHeader.pic_order_cnt_lsb;
-		pInfo->old_slice.delta_pic_order_cnt_bottom = pInfo->SliceHeader.delta_pic_order_cnt_bottom;
-	}
+    if (pInfo->active_SPS.pic_order_cnt_type == 0)
+    {
+        pInfo->old_slice.pic_order_cnt_lsb          = pInfo->SliceHeader.pic_order_cnt_lsb;
+        pInfo->old_slice.delta_pic_order_cnt_bottom = pInfo->SliceHeader.delta_pic_order_cnt_bottom;
+    }
 
-	if (pInfo->active_SPS.pic_order_cnt_type == 1)
-	{
-		pInfo->old_slice.delta_pic_order_cnt[0] = pInfo->SliceHeader.delta_pic_order_cnt[0];
-		pInfo->old_slice.delta_pic_order_cnt[1] = pInfo->SliceHeader.delta_pic_order_cnt[1];
-	}	
+    if (pInfo->active_SPS.pic_order_cnt_type == 1)
+    {
+        pInfo->old_slice.delta_pic_order_cnt[0] = pInfo->SliceHeader.delta_pic_order_cnt[0];
+        pInfo->old_slice.delta_pic_order_cnt[1] = pInfo->SliceHeader.delta_pic_order_cnt[1];
+    }
 
-	////////////////////////////// Next to current
-	memcpy(&pInfo->SliceHeader, &next_SliceHeader, sizeof(h264_Slice_Header_t));	
+    ////////////////////////////// Next to current
+    memcpy(&pInfo->SliceHeader, &next_SliceHeader, sizeof(h264_Slice_Header_t));
 
-	return;
+    return;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -610,59 +610,59 @@
 //////////////////////////////////////////////////////////////////////////////
 void h264_update_img_info(h264_Info * pInfo )
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	pInfo->img.frame_num = pInfo->SliceHeader.frame_num;
-	pInfo->img.structure = pInfo->SliceHeader.structure;
+    pInfo->img.frame_num = pInfo->SliceHeader.frame_num;
+    pInfo->img.structure = pInfo->SliceHeader.structure;
 
-	pInfo->img.field_pic_flag = pInfo->SliceHeader.field_pic_flag;
-	pInfo->img.bottom_field_flag = pInfo->SliceHeader.bottom_field_flag;
-	
-	pInfo->img.MbaffFrameFlag  = pInfo->active_SPS.sps_disp.mb_adaptive_frame_field_flag & (!(pInfo->SliceHeader.field_pic_flag));
-	pInfo->img.pic_order_cnt_type = pInfo->active_SPS.pic_order_cnt_type;
+    pInfo->img.field_pic_flag = pInfo->SliceHeader.field_pic_flag;
+    pInfo->img.bottom_field_flag = pInfo->SliceHeader.bottom_field_flag;
 
-	if(pInfo->img.pic_order_cnt_type == 1) {
-		pInfo->img.num_ref_frames_in_pic_order_cnt_cycle = pInfo->active_SPS.num_ref_frames_in_pic_order_cnt_cycle;
-		pInfo->img.delta_pic_order_always_zero_flag = pInfo->active_SPS.delta_pic_order_always_zero_flag;
-		pInfo->img.offset_for_non_ref_pic = pInfo->active_SPS.offset_for_non_ref_pic;
-		pInfo->img.offset_for_top_to_bottom_field = pInfo->active_SPS.offset_for_top_to_bottom_field;
-	}
+    pInfo->img.MbaffFrameFlag  = pInfo->active_SPS.sps_disp.mb_adaptive_frame_field_flag & (!(pInfo->SliceHeader.field_pic_flag));
+    pInfo->img.pic_order_cnt_type = pInfo->active_SPS.pic_order_cnt_type;
 
-	pInfo->img.pic_order_cnt_lsb = pInfo->SliceHeader.pic_order_cnt_lsb;
-	//pInfo->img.pic_order_cnt_msb = pInfo->SliceHeader.pic_order_cnt_msb;
-	pInfo->img.delta_pic_order_cnt_bottom = pInfo->SliceHeader.delta_pic_order_cnt_bottom;
-	pInfo->img.delta_pic_order_cnt[0] = pInfo->SliceHeader.delta_pic_order_cnt[0];
-	pInfo->img.delta_pic_order_cnt[1] = pInfo->SliceHeader.delta_pic_order_cnt[1];
+    if (pInfo->img.pic_order_cnt_type == 1) {
+        pInfo->img.num_ref_frames_in_pic_order_cnt_cycle = pInfo->active_SPS.num_ref_frames_in_pic_order_cnt_cycle;
+        pInfo->img.delta_pic_order_always_zero_flag = pInfo->active_SPS.delta_pic_order_always_zero_flag;
+        pInfo->img.offset_for_non_ref_pic = pInfo->active_SPS.offset_for_non_ref_pic;
+        pInfo->img.offset_for_top_to_bottom_field = pInfo->active_SPS.offset_for_top_to_bottom_field;
+    }
+
+    pInfo->img.pic_order_cnt_lsb = pInfo->SliceHeader.pic_order_cnt_lsb;
+    //pInfo->img.pic_order_cnt_msb = pInfo->SliceHeader.pic_order_cnt_msb;
+    pInfo->img.delta_pic_order_cnt_bottom = pInfo->SliceHeader.delta_pic_order_cnt_bottom;
+    pInfo->img.delta_pic_order_cnt[0] = pInfo->SliceHeader.delta_pic_order_cnt[0];
+    pInfo->img.delta_pic_order_cnt[1] = pInfo->SliceHeader.delta_pic_order_cnt[1];
 
 
-	pInfo->img.PreviousFrameNum = pInfo->old_slice.frame_num;
+    pInfo->img.PreviousFrameNum = pInfo->old_slice.frame_num;
 
-	pInfo->img.no_output_of_prior_pics_flag = pInfo->SliceHeader.sh_dec_refpic.no_output_of_prior_pics_flag;
+    pInfo->img.no_output_of_prior_pics_flag = pInfo->SliceHeader.sh_dec_refpic.no_output_of_prior_pics_flag;
 
-	////////////////////////////////////////////////// Check SEI recovery point
-	if (pInfo->sei_information.recovery_point) {
-		int32_t MaxFrameNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4); 
-		pInfo->sei_information.recovery_frame_num = (pInfo->img.frame_num + pInfo->sei_information.recovery_frame_cnt) % MaxFrameNum;
-	}
+    ////////////////////////////////////////////////// Check SEI recovery point
+    if (pInfo->sei_information.recovery_point) {
+        int32_t MaxFrameNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
+        pInfo->sei_information.recovery_frame_num = (pInfo->img.frame_num + pInfo->sei_information.recovery_frame_cnt) % MaxFrameNum;
+    }
 
-	if (pInfo->SliceHeader.idr_flag)
-		pInfo->sei_information.recovery_frame_num = pInfo->img.frame_num;
+    if (pInfo->SliceHeader.idr_flag)
+        pInfo->sei_information.recovery_frame_num = pInfo->img.frame_num;
 
-     
-	
-	/////////////////////////////////////////////////Resolution Change
-	pInfo->img.curr_has_mmco_5 = 0;
 
-	if ( (pInfo->img.PicWidthInMbs != p_dpb->PicWidthInMbs)||
-	   (pInfo->img.FrameHeightInMbs != p_dpb->FrameHeightInMbs) )
-	{
-		int32_t no_output_old_pics = (pInfo->SliceHeader.idr_flag)? pInfo->img.no_output_of_prior_pics_flag : 0;
 
-		// If resolution changed, reset the soft DPB here
-		h264_dpb_reset_dpb(pInfo, pInfo->img.PicWidthInMbs, pInfo->img.FrameHeightInMbs, 1, no_output_old_pics);
-	}
+    /////////////////////////////////////////////////Resolution Change
+    pInfo->img.curr_has_mmco_5 = 0;
 
-	return;
+    if ( (pInfo->img.PicWidthInMbs != p_dpb->PicWidthInMbs)||
+            (pInfo->img.FrameHeightInMbs != p_dpb->FrameHeightInMbs) )
+    {
+        int32_t no_output_old_pics = (pInfo->SliceHeader.idr_flag)? pInfo->img.no_output_of_prior_pics_flag : 0;
+
+        // If resolution changed, reset the soft DPB here
+        h264_dpb_reset_dpb(pInfo, pInfo->img.PicWidthInMbs, pInfo->img.FrameHeightInMbs, 1, no_output_old_pics);
+    }
+
+    return;
 
 } ///// End of init new frame
 
@@ -670,124 +670,124 @@
 void h264_update_frame_type(h264_Info * pInfo )
 {
 
-//update frame type 
-   if(pInfo->img.structure == FRAME)
-   {
-      if(pInfo->nal_unit_type == h264_NAL_UNIT_TYPE_IDR)
-      {
-         pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (0x1 << FRAME_TYPE_STRUCTRUE_OFFSET)|(FRAME_TYPE_IDR << FRAME_TYPE_FRAME_OFFSET);
-         //pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = 0xff;
-         //pInfo->dpb.fs[0].pic_type = pInfo->dpb.fs_dec_idc;
-         
-      }
-      else 
-      {
-      #if 1
-         switch(pInfo->SliceHeader.slice_type)
-         { 
-            case h264_PtypeB:
-               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (0x1 << FRAME_TYPE_STRUCTRUE_OFFSET)|(FRAME_TYPE_B << FRAME_TYPE_FRAME_OFFSET);
-            	break;
-            case h264_PtypeSP:
-            case h264_PtypeP:
-	            if( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_FRAME_OFFSET))>>FRAME_TYPE_FRAME_OFFSET != FRAME_TYPE_B)
-	               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (0x1 << FRAME_TYPE_STRUCTRUE_OFFSET)|(FRAME_TYPE_P << FRAME_TYPE_FRAME_OFFSET);
-	            break;
-            case h264_PtypeI:
-            case h264_PtypeSI:
-	            if( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_FRAME_OFFSET))>>FRAME_TYPE_FRAME_OFFSET == FRAME_TYPE_INVALID)
-	            {
-	               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (0x1 << FRAME_TYPE_STRUCTRUE_OFFSET)|(FRAME_TYPE_I << FRAME_TYPE_FRAME_OFFSET);
-	            }
-				   pInfo->last_I_frame_idc = pInfo->dpb.fs_dec_idc;
-				
-	            break;
-            default:
-            	break;
+//update frame type
+    if (pInfo->img.structure == FRAME)
+    {
+        if (pInfo->nal_unit_type == h264_NAL_UNIT_TYPE_IDR)
+        {
+            pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (0x1 << FRAME_TYPE_STRUCTRUE_OFFSET)|(FRAME_TYPE_IDR << FRAME_TYPE_FRAME_OFFSET);
+            //pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = 0xff;
+            //pInfo->dpb.fs[0].pic_type = pInfo->dpb.fs_dec_idc;
 
-         }
-      #endif
-         
-      }      
-
-   }
-   else if(pInfo->img.structure == TOP_FIELD)
-   {
-      if(pInfo->nal_unit_type == h264_NAL_UNIT_TYPE_IDR)
-      {
-         pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_IDR << FRAME_TYPE_TOP_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_BOTTOM_OFFSET));;
-      }
-      else 
-      {
-         switch(pInfo->SliceHeader.slice_type)
-         { 
-            case h264_PtypeB:
-               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_B << FRAME_TYPE_TOP_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_BOTTOM_OFFSET));
-            break;
-            case h264_PtypeSP:
-            case h264_PtypeP:
-            if( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_TOP_OFFSET))>>FRAME_TYPE_TOP_OFFSET != FRAME_TYPE_B)
-               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_P << FRAME_TYPE_TOP_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_BOTTOM_OFFSET));
-            break;
-            case h264_PtypeI:
-            case h264_PtypeSI:
-            if( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_TOP_OFFSET))>>FRAME_TYPE_TOP_OFFSET == FRAME_TYPE_INVALID)
+        }
+        else
+        {
+#if 1
+            switch (pInfo->SliceHeader.slice_type)
             {
-               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_I << FRAME_TYPE_TOP_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_BOTTOM_OFFSET));
-            }
-            if (pInfo->sei_rp_received)
-               pInfo->last_I_frame_idc = pInfo->dpb.fs_dec_idc;
-            else
-               pInfo->last_I_frame_idc = 255;
-            break;
-            default:
-            break;
-
-         }
-         
-      }      
-      
-
-   }else if(pInfo->img.structure == BOTTOM_FIELD)
-   {
-      if(pInfo->nal_unit_type == h264_NAL_UNIT_TYPE_IDR)
-      {
-         pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_IDR << FRAME_TYPE_BOTTOM_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_TOP_OFFSET));;
-      }
-      else 
-      {
-         switch(pInfo->SliceHeader.slice_type)
-         { 
             case h264_PtypeB:
-               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_B << FRAME_TYPE_BOTTOM_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_TOP_OFFSET));
-            break;
+                pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (0x1 << FRAME_TYPE_STRUCTRUE_OFFSET)|(FRAME_TYPE_B << FRAME_TYPE_FRAME_OFFSET);
+                break;
             case h264_PtypeSP:
             case h264_PtypeP:
-            if( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_BOTTOM_OFFSET))>>FRAME_TYPE_BOTTOM_OFFSET != FRAME_TYPE_B)
-               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_P << FRAME_TYPE_BOTTOM_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_TOP_OFFSET));
-            break;
+                if ( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_FRAME_OFFSET))>>FRAME_TYPE_FRAME_OFFSET != FRAME_TYPE_B)
+                    pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (0x1 << FRAME_TYPE_STRUCTRUE_OFFSET)|(FRAME_TYPE_P << FRAME_TYPE_FRAME_OFFSET);
+                break;
             case h264_PtypeI:
             case h264_PtypeSI:
-            if( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_BOTTOM_OFFSET))>>FRAME_TYPE_BOTTOM_OFFSET == FRAME_TYPE_INVALID)
-            {
-               pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_I << FRAME_TYPE_BOTTOM_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_TOP_OFFSET));
-            }
-            if (pInfo->sei_rp_received)
-               pInfo->last_I_frame_idc = pInfo->dpb.fs_dec_idc + PUT_LIST_INDEX_FIELD_BIT(1);
-            else
-               pInfo->last_I_frame_idc = 255;
+                if ( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_FRAME_OFFSET))>>FRAME_TYPE_FRAME_OFFSET == FRAME_TYPE_INVALID)
+                {
+                    pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (0x1 << FRAME_TYPE_STRUCTRUE_OFFSET)|(FRAME_TYPE_I << FRAME_TYPE_FRAME_OFFSET);
+                }
+                pInfo->last_I_frame_idc = pInfo->dpb.fs_dec_idc;
 
-            break;
+                break;
             default:
-            break;
+                break;
 
-         }
-         
-      }            
-      
-   }
-   return;
-   
+            }
+#endif
+
+        }
+
+    }
+    else if (pInfo->img.structure == TOP_FIELD)
+    {
+        if (pInfo->nal_unit_type == h264_NAL_UNIT_TYPE_IDR)
+        {
+            pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_IDR << FRAME_TYPE_TOP_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_BOTTOM_OFFSET));;
+        }
+        else
+        {
+            switch (pInfo->SliceHeader.slice_type)
+            {
+            case h264_PtypeB:
+                pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_B << FRAME_TYPE_TOP_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_BOTTOM_OFFSET));
+                break;
+            case h264_PtypeSP:
+            case h264_PtypeP:
+                if ( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_TOP_OFFSET))>>FRAME_TYPE_TOP_OFFSET != FRAME_TYPE_B)
+                    pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_P << FRAME_TYPE_TOP_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_BOTTOM_OFFSET));
+                break;
+            case h264_PtypeI:
+            case h264_PtypeSI:
+                if ( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_TOP_OFFSET))>>FRAME_TYPE_TOP_OFFSET == FRAME_TYPE_INVALID)
+                {
+                    pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_I << FRAME_TYPE_TOP_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_BOTTOM_OFFSET));
+                }
+                if (pInfo->sei_rp_received)
+                    pInfo->last_I_frame_idc = pInfo->dpb.fs_dec_idc;
+                else
+                    pInfo->last_I_frame_idc = 255;
+                break;
+            default:
+                break;
+
+            }
+
+        }
+
+
+    } else if (pInfo->img.structure == BOTTOM_FIELD)
+    {
+        if (pInfo->nal_unit_type == h264_NAL_UNIT_TYPE_IDR)
+        {
+            pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_IDR << FRAME_TYPE_BOTTOM_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_TOP_OFFSET));;
+        }
+        else
+        {
+            switch (pInfo->SliceHeader.slice_type)
+            {
+            case h264_PtypeB:
+                pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_B << FRAME_TYPE_BOTTOM_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_TOP_OFFSET));
+                break;
+            case h264_PtypeSP:
+            case h264_PtypeP:
+                if ( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_BOTTOM_OFFSET))>>FRAME_TYPE_BOTTOM_OFFSET != FRAME_TYPE_B)
+                    pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_P << FRAME_TYPE_BOTTOM_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_TOP_OFFSET));
+                break;
+            case h264_PtypeI:
+            case h264_PtypeSI:
+                if ( ((pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type) & (0x7 << FRAME_TYPE_BOTTOM_OFFSET))>>FRAME_TYPE_BOTTOM_OFFSET == FRAME_TYPE_INVALID)
+                {
+                    pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type = (FRAME_TYPE_I << FRAME_TYPE_BOTTOM_OFFSET)|(pInfo->dpb.fs[pInfo->dpb.fs_dec_idc].pic_type & (0x7 << FRAME_TYPE_TOP_OFFSET));
+                }
+                if (pInfo->sei_rp_received)
+                    pInfo->last_I_frame_idc = pInfo->dpb.fs_dec_idc + PUT_LIST_INDEX_FIELD_BIT(1);
+                else
+                    pInfo->last_I_frame_idc = 255;
+
+                break;
+            default:
+                break;
+
+            }
+
+        }
+
+    }
+    return;
+
 }
 
 
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_bsd.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_bsd.c
index dbbe5c6..40c7559 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_bsd.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_bsd.c
@@ -24,7 +24,7 @@
    @param      cxt : Buffer adress & size are part inputs, the cxt is updated
                      with codeNum & sign on sucess.
                      Assumption: codeNum is a max of 32 bits
-                     
+
    @retval       1 : Sucessfuly found a code num, cxt is updated with codeNum, sign, and size of code.
    @retval       0 : Couldn't find a code in the current buffer.
    be freed.
@@ -32,131 +32,131 @@
 
 uint32_t h264_get_codeNum(void *parent, h264_Info* pInfo)
 {
-   int32_t    leadingZeroBits= 0;
-   uint32_t    temp = 0, match = 0, noOfBits = 0, count = 0;
-   uint32_t   codeNum =0;
-   uint32_t   bits_offset =0, byte_offset =0;
-   uint8_t    is_emul =0;
-   uint8_t    is_first_byte = 1;
-   uint32_t   length =0;
-   uint32_t   bits_need_add_in_first_byte =0;
-   int32_t    bits_operation_result=0;
+    int32_t    leadingZeroBits= 0;
+    uint32_t    temp = 0, match = 0, noOfBits = 0, count = 0;
+    uint32_t   codeNum =0;
+    uint32_t   bits_offset =0, byte_offset =0;
+    uint8_t    is_emul =0;
+    uint8_t    is_first_byte = 1;
+    uint32_t   length =0;
+    uint32_t   bits_need_add_in_first_byte =0;
+    int32_t    bits_operation_result=0;
 
-   //remove warning
-   pInfo = pInfo;   
+    //remove warning
+    pInfo = pInfo;
 
-   ////// Step 1: parse through zero bits until we find a bit with value 1.
-   viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
-
- 
-   while(!match)
-   {
-       if ((bits_offset != 0) && ( is_first_byte == 1))
-       {
-           //we handle byte at a time, if we have offset then for first
-           //   byte handle only 8 - offset bits 
-           noOfBits = (uint8_t)(8 - bits_offset);
-           bits_operation_result = viddec_pm_peek_bits(parent, &temp, noOfBits); 
-
-             
-           temp = (temp << bits_offset);
-           if(temp!=0)
-           {
-              bits_need_add_in_first_byte = bits_offset;
-           }          
-           is_first_byte =0;            
-       }
-       else
-       {
-           noOfBits = 8;/* always 8 bits as we read a byte at a time */
-           bits_operation_result = viddec_pm_peek_bits(parent, &temp, 8); 
-  
-       }
-
-	   if(-1==bits_operation_result)
-	   {
-	      return MAX_INT32_VALUE;      
-	   }
-
-       if(temp != 0)    
-       {
-           // if byte!=0 we have at least one bit with value 1.
-           count=1;
-           while(((temp & 0x80) != 0x80) && (count <= noOfBits))
-           {
-               count++;
-               temp = temp <<1;
-           }
-           //At this point we get the bit position of 1 in current byte(count).
-            
-           match = 1;
-           leadingZeroBits += count;            
-       }
-       else
-       {
-           // we don't have a 1 in current byte 
-           leadingZeroBits += noOfBits;            
-       }
-
-       if(!match)
-       {
-           //actually move the bitoff by viddec_pm_get_bits
-           viddec_pm_get_bits(parent, &temp, noOfBits);           
-       }
-       else
-       {
-           //actually move the bitoff by viddec_pm_get_bits
-           viddec_pm_get_bits(parent, &temp, count);            
-       }        
-
-   }
-   ////// step 2: Now read the next (leadingZeroBits-1) bits to get the encoded value.
+    ////// Step 1: parse through zero bits until we find a bit with value 1.
+    viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
 
 
-   if(match)
-   {
+    while (!match)
+    {
+        if ((bits_offset != 0) && ( is_first_byte == 1))
+        {
+            //we handle byte at a time, if we have offset then for first
+            //   byte handle only 8 - offset bits
+            noOfBits = (uint8_t)(8 - bits_offset);
+            bits_operation_result = viddec_pm_peek_bits(parent, &temp, noOfBits);
 
-       viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
-       /* bit position in current byte */
-       //count = (uint8_t)((leadingZeroBits + bits_offset)& 0x7);        
-       count = ((count + bits_need_add_in_first_byte)& 0x7);   
-        
-       leadingZeroBits --;
-       length =  leadingZeroBits;
-       codeNum = 0;
-       noOfBits = 8 - count;    
 
-        
-       while(leadingZeroBits > 0)
-       {
-           if(noOfBits < (uint32_t)leadingZeroBits)
-           {
-               viddec_pm_get_bits(parent, &temp, noOfBits);
+            temp = (temp << bits_offset);
+            if (temp!=0)
+            {
+                bits_need_add_in_first_byte = bits_offset;
+            }
+            is_first_byte =0;
+        }
+        else
+        {
+            noOfBits = 8;/* always 8 bits as we read a byte at a time */
+            bits_operation_result = viddec_pm_peek_bits(parent, &temp, 8);
 
-                  
-               codeNum = (codeNum << noOfBits) | temp;
-               leadingZeroBits -= noOfBits;
-           }
-           else
-           {
-               viddec_pm_get_bits(parent, &temp, leadingZeroBits);
-                
-               codeNum = (codeNum << leadingZeroBits) | temp;
-               leadingZeroBits = 0;
-           }
-    
+        }
 
-           noOfBits = 8;
-       }
-       // update codeNum = 2 ** (leadingZeroBits) -1 + read_bits(leadingZeroBits). 
-       codeNum = codeNum + (1 << length) -1;         
+        if (-1==bits_operation_result)
+        {
+            return MAX_INT32_VALUE;
+        }
+
+        if (temp != 0)
+        {
+            // if byte!=0 we have at least one bit with value 1.
+            count=1;
+            while (((temp & 0x80) != 0x80) && (count <= noOfBits))
+            {
+                count++;
+                temp = temp <<1;
+            }
+            //At this point we get the bit position of 1 in current byte(count).
+
+            match = 1;
+            leadingZeroBits += count;
+        }
+        else
+        {
+            // we don't have a 1 in current byte
+            leadingZeroBits += noOfBits;
+        }
+
+        if (!match)
+        {
+            //actually move the bitoff by viddec_pm_get_bits
+            viddec_pm_get_bits(parent, &temp, noOfBits);
+        }
+        else
+        {
+            //actually move the bitoff by viddec_pm_get_bits
+            viddec_pm_get_bits(parent, &temp, count);
+        }
+
+    }
+    ////// step 2: Now read the next (leadingZeroBits-1) bits to get the encoded value.
+
+
+    if (match)
+    {
+
+        viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
+        /* bit position in current byte */
+        //count = (uint8_t)((leadingZeroBits + bits_offset)& 0x7);
+        count = ((count + bits_need_add_in_first_byte)& 0x7);
+
+        leadingZeroBits --;
+        length =  leadingZeroBits;
+        codeNum = 0;
+        noOfBits = 8 - count;
+
+
+        while (leadingZeroBits > 0)
+        {
+            if (noOfBits < (uint32_t)leadingZeroBits)
+            {
+                viddec_pm_get_bits(parent, &temp, noOfBits);
+
+
+                codeNum = (codeNum << noOfBits) | temp;
+                leadingZeroBits -= noOfBits;
+            }
+            else
+            {
+                viddec_pm_get_bits(parent, &temp, leadingZeroBits);
+
+                codeNum = (codeNum << leadingZeroBits) | temp;
+                leadingZeroBits = 0;
+            }
+
+
+            noOfBits = 8;
+        }
+        // update codeNum = 2 ** (leadingZeroBits) -1 + read_bits(leadingZeroBits).
+        codeNum = codeNum + (1 << length) -1;
 
     }
 
     viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
-    if(bits_offset!=0)
+    if (bits_offset!=0)
     {
-      viddec_pm_peek_bits(parent, &temp, 8-bits_offset); 
+        viddec_pm_peek_bits(parent, &temp, 8-bits_offset);
     }
 
     return codeNum;
@@ -167,19 +167,19 @@
 /*---------------------------------------*/
 int32_t h264_GetVLCElement(void *parent, h264_Info* pInfo, uint8_t bIsSigned)
 {
-	int32_t sval = 0;
-	signed char sign;
+    int32_t sval = 0;
+    signed char sign;
 
-	sval = h264_get_codeNum(parent , pInfo);
+    sval = h264_get_codeNum(parent , pInfo);
 
- 	if(bIsSigned)  //get signed integer golomb code else the value is unsigned
-	{
-	  sign = (sval & 0x1)?1:-1;
-	  sval = (sval +1) >> 1;
-	  sval = sval * sign;
-	}
+    if (bIsSigned) //get signed integer golomb code else the value is unsigned
+    {
+        sign = (sval & 0x1)?1:-1;
+        sval = (sval +1) >> 1;
+        sval = sval * sign;
+    }
 
-	return sval;
+    return sval;
 } // Ipp32s H264Bitstream::GetVLCElement(bool bIsSigned)
 
 ///
@@ -187,39 +187,39 @@
 ///
 uint8_t h264_More_RBSP_Data(void *parent, h264_Info * pInfo)
 {
-	uint8_t cnt = 0;  
+    uint8_t cnt = 0;
 
-	uint8_t  is_emul =0; 
-	uint8_t 	cur_byte = 0;
-	int32_t  shift_bits =0;
-	uint32_t ctr_bit = 0;
-	uint32_t bits_offset =0, byte_offset =0;
+    uint8_t  is_emul =0;
+    uint8_t 	cur_byte = 0;
+    int32_t  shift_bits =0;
+    uint32_t ctr_bit = 0;
+    uint32_t bits_offset =0, byte_offset =0;
 
-   //remove warning
-   pInfo = pInfo; 
+    //remove warning
+    pInfo = pInfo;
 
-	if (!viddec_pm_is_nomoredata(parent)) 
-		return 1;
+    if (!viddec_pm_is_nomoredata(parent))
+        return 1;
 
-	viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
+    viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
 
-	shift_bits = 7-bits_offset; 
+    shift_bits = 7-bits_offset;
 
-	// read one byte
-	viddec_pm_get_cur_byte(parent, &cur_byte); 
+    // read one byte
+    viddec_pm_get_cur_byte(parent, &cur_byte);
 
-	ctr_bit = ((cur_byte)>> (shift_bits--)) & 0x01;
+    ctr_bit = ((cur_byte)>> (shift_bits--)) & 0x01;
 
-	// a stop bit has to be one
-	if (ctr_bit==0) 
-		return 1;  
+    // a stop bit has to be one
+    if (ctr_bit==0)
+        return 1;
 
-	while (shift_bits>=0 && !cnt)
-	{
-		cnt |= (((cur_byte)>> (shift_bits--)) & 0x01);   // set up control bit
-	} 
+    while (shift_bits>=0 && !cnt)
+    {
+        cnt |= (((cur_byte)>> (shift_bits--)) & 0x01);   // set up control bit
+    }
 
-   return (cnt);  
+    return (cnt);
 }
 
 
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_dpb.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_dpb.c
index 3a111c4..25ca059 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_dpb.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_dpb.c
@@ -41,22 +41,22 @@
 
 void h264_init_dpb(h264_DecodedPictureBuffer * p_dpb)
 {
-	int32_t i;
+    int32_t i;
 
-	//// Init DPB to zero
-	//h264_memset(p_dpb, 0x0, sizeof(h264_DecodedPictureBuffer) );
+    //// Init DPB to zero
+    //h264_memset(p_dpb, 0x0, sizeof(h264_DecodedPictureBuffer) );
 
 
-	for(i=0;i<NUM_DPB_FRAME_STORES;i++) 
-	{
-		p_dpb->fs[i].fs_idc = MPD_DPB_FS_NULL_IDC;
-		p_dpb->fs_dpb_idc[i] = MPD_DPB_FS_NULL_IDC;
-	}
-	p_dpb->used_size = 0;
-	p_dpb->fs_dec_idc = MPD_DPB_FS_NULL_IDC;
-	p_dpb->fs_non_exist_idc = MPD_DPB_FS_NULL_IDC;
+    for (i=0; i<NUM_DPB_FRAME_STORES; i++)
+    {
+        p_dpb->fs[i].fs_idc = MPD_DPB_FS_NULL_IDC;
+        p_dpb->fs_dpb_idc[i] = MPD_DPB_FS_NULL_IDC;
+    }
+    p_dpb->used_size = 0;
+    p_dpb->fs_dec_idc = MPD_DPB_FS_NULL_IDC;
+    p_dpb->fs_non_exist_idc = MPD_DPB_FS_NULL_IDC;
 
-	return;
+    return;
 }
 
 
@@ -72,8 +72,8 @@
 //////////////////////////////////////////////////////////////////////////////
 void h264_dpb_add_ref_list(h264_DecodedPictureBuffer * p_dpb, int32_t ref_idc)
 {
-	p_dpb->fs_ref_idc[p_dpb->ref_frames_in_buffer] = ref_idc;
-	p_dpb->ref_frames_in_buffer++;
+    p_dpb->fs_ref_idc[p_dpb->ref_frames_in_buffer] = ref_idc;
+    p_dpb->ref_frames_in_buffer++;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -85,8 +85,8 @@
 //////////////////////////////////////////////////////////////////////////////
 void h264_dpb_add_ltref_list(h264_DecodedPictureBuffer * p_dpb, int32_t ref_idc)
 {
-	p_dpb->fs_ltref_idc[p_dpb->ltref_frames_in_buffer] = ref_idc;
-	p_dpb->ltref_frames_in_buffer++;
+    p_dpb->fs_ltref_idc[p_dpb->ltref_frames_in_buffer] = ref_idc;
+    p_dpb->ltref_frames_in_buffer++;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -96,54 +96,54 @@
 //
 // Decide whether the current picture needs to be added to the reference lists
 // active_fs should be set-up prior to calling this function
-// 
-// Check if we need to search the lists here 
+//
+// Check if we need to search the lists here
 // or can we go straight to adding to ref lists..
 //////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_insert_ref_lists(h264_DecodedPictureBuffer * p_dpb, int32_t NonExisting)
 {
-	if(NonExisting) 
-		h264_dpb_set_active_fs(p_dpb,p_dpb->fs_non_exist_idc);
-	else
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+    if (NonExisting)
+        h264_dpb_set_active_fs(p_dpb,p_dpb->fs_non_exist_idc);
+    else
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
 
-	//if(active_fs->is_reference)
-	if(active_fs->frame.used_for_reference)
-	{
-		if(viddec_h264_get_is_long_term(active_fs))
-		{
-			if(viddec_h264_get_dec_structure(active_fs) == FRAME) 
-				h264_dpb_add_ltref_list(p_dpb, active_fs->fs_idc);
-			else
-			{
-				uint32_t found_in_list = 0, i = 0;
-				for (i = 0; (i < p_dpb->ltref_frames_in_buffer) && (found_in_list == 0); i++) {
-				  if(p_dpb->fs_ltref_idc[i] == active_fs->fs_idc) found_in_list = 1;
-				}
+    //if(active_fs->is_reference)
+    if (active_fs->frame.used_for_reference)
+    {
+        if (viddec_h264_get_is_long_term(active_fs))
+        {
+            if (viddec_h264_get_dec_structure(active_fs) == FRAME)
+                h264_dpb_add_ltref_list(p_dpb, active_fs->fs_idc);
+            else
+            {
+                uint32_t found_in_list = 0, i = 0;
+                for (i = 0; (i < p_dpb->ltref_frames_in_buffer) && (found_in_list == 0); i++) {
+                    if (p_dpb->fs_ltref_idc[i] == active_fs->fs_idc) found_in_list = 1;
+                }
 
-				if(found_in_list == 0) h264_dpb_add_ltref_list(p_dpb, active_fs->fs_idc);
-			}
-		}
-		else
-		{
-			if(viddec_h264_get_dec_structure(active_fs) == FRAME) {
-				h264_dpb_add_ref_list(p_dpb, active_fs->fs_idc);
-			} else
-			{
-				uint32_t found_in_list = 0, i = 0;
+                if (found_in_list == 0) h264_dpb_add_ltref_list(p_dpb, active_fs->fs_idc);
+            }
+        }
+        else
+        {
+            if (viddec_h264_get_dec_structure(active_fs) == FRAME) {
+                h264_dpb_add_ref_list(p_dpb, active_fs->fs_idc);
+            } else
+            {
+                uint32_t found_in_list = 0, i = 0;
 
-				for (i = 0; (i < p_dpb->ref_frames_in_buffer) && (found_in_list == 0); i++) 
-				{
-				  if(p_dpb->fs_ref_idc[i] == active_fs->fs_idc) found_in_list = 1;
-				}
+                for (i = 0; (i < p_dpb->ref_frames_in_buffer) && (found_in_list == 0); i++)
+                {
+                    if (p_dpb->fs_ref_idc[i] == active_fs->fs_idc) found_in_list = 1;
+                }
 
-				if(found_in_list == 0) h264_dpb_add_ref_list(p_dpb, active_fs->fs_idc);
-			}
-		}
-	}
+                if (found_in_list == 0) h264_dpb_add_ref_list(p_dpb, active_fs->fs_idc);
+            }
+        }
+    }
 
-	return;
+    return;
 
 }
 
@@ -156,8 +156,8 @@
 
 void h264_dpb_set_active_fs(h264_DecodedPictureBuffer * p_dpb, int32_t index)
 {
-  active_fs = &p_dpb->fs[index];
-} 
+    active_fs = &p_dpb->fs[index];
+}
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -167,26 +167,26 @@
 
 void h264_list_sort(uint8_t *list, int32_t *sort_indices, int32_t size, int32_t desc)
 {
-	int32_t j, k, temp, idc;
+    int32_t j, k, temp, idc;
 
-  // Dodgy looking for embedded code here...
-	if(size > 1)
-	{
-		for (j = 0; j < size-1; j = j + 1) {
-			for (k = j + 1; k < size; k = k + 1) {
-				if ((desc & (sort_indices[j] < sort_indices[k]))|
-					(~desc & (sort_indices[j] > sort_indices[k])) ) 
-				{
-					temp = sort_indices[k];
-					sort_indices[k] = sort_indices[j];
-					sort_indices[j] = temp;
-					idc = list[k];
-					list[k] = list[j];
-					list[j] = idc;
-				}		
-			}
-		}
-	}		
+    // Dodgy looking for embedded code here...
+    if (size > 1)
+    {
+        for (j = 0; j < size-1; j = j + 1) {
+            for (k = j + 1; k < size; k = k + 1) {
+                if ((desc & (sort_indices[j] < sort_indices[k]))|
+                        (~desc & (sort_indices[j] > sort_indices[k])) )
+                {
+                    temp = sort_indices[k];
+                    sort_indices[k] = sort_indices[j];
+                    sort_indices[j] = temp;
+                    idc = list[k];
+                    list[k] = list[j];
+                    list[j] = idc;
+                }
+            }
+        }
+    }
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -200,11 +200,11 @@
 
 int32_t h264_dpb_pic_is_bottom_field_ref(int32_t long_term)
 {
-	int32_t temp;	
-	if(long_term) temp = ((active_fs->bottom_field.used_for_reference) && (active_fs->bottom_field.is_long_term))  ? 1 : 0;
-	else          temp = ((active_fs->bottom_field.used_for_reference) && !(active_fs->bottom_field.is_long_term)) ? 1 : 0;
-	
-	return temp;
+    int32_t temp;
+    if (long_term) temp = ((active_fs->bottom_field.used_for_reference) && (active_fs->bottom_field.is_long_term))  ? 1 : 0;
+    else          temp = ((active_fs->bottom_field.used_for_reference) && !(active_fs->bottom_field.is_long_term)) ? 1 : 0;
+
+    return temp;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -217,13 +217,13 @@
 
 int32_t h264_dpb_pic_is_top_field_ref(int32_t long_term)
 {
-	int32_t temp;	
-	if(long_term) 
-		temp = ((active_fs->top_field.used_for_reference) && (active_fs->top_field.is_long_term))  ? 1 : 0;
-	else
-		temp = ((active_fs->top_field.used_for_reference) && !(active_fs->top_field.is_long_term)) ? 1 : 0;
-	
-	return temp;
+    int32_t temp;
+    if (long_term)
+        temp = ((active_fs->top_field.used_for_reference) && (active_fs->top_field.is_long_term))  ? 1 : 0;
+    else
+        temp = ((active_fs->top_field.used_for_reference) && !(active_fs->top_field.is_long_term)) ? 1 : 0;
+
+    return temp;
 }
 
 
@@ -238,97 +238,97 @@
 
 int32_t h264_dpb_gen_pic_list_from_frame_list(h264_DecodedPictureBuffer *p_dpb, uint8_t *pic_list, uint8_t *frame_list, int32_t currPicStructure, int32_t list_size, int32_t long_term)
 {
-	int32_t top_idx, bot_idx, got_pic, list_idx;		
-	int32_t lterm;
+    int32_t top_idx, bot_idx, got_pic, list_idx;
+    int32_t lterm;
 
-	list_idx = 0;
-	lterm = (long_term)? 1:0;
+    list_idx = 0;
+    lterm = (long_term)? 1:0;
 
-	if(list_size){
-		
+    if (list_size) {
 
-		top_idx = 0;
-		bot_idx = 0;
 
-		if (currPicStructure == TOP_FIELD) {
-			while ((top_idx < list_size)||(bot_idx < list_size))
-			{
-				/////////////////////////////////////////// ref Top Field
-				got_pic = 0;
-				while ((top_idx < list_size) & ~got_pic)
-				{
-					h264_dpb_set_active_fs(p_dpb, frame_list[top_idx]);
-					if ((viddec_h264_get_is_used(active_fs))&0x1)
-					{
-						if(h264_dpb_pic_is_top_field_ref(long_term))
-						{
-							pic_list[list_idx] = PUT_LIST_LONG_TERM_BITS(lterm) + frame_list[top_idx] + PUT_LIST_INDEX_FIELD_BIT(0);  // top_field
-							list_idx++;
-							got_pic = 1;
-						}
-					}
-					top_idx++;
-				}
+        top_idx = 0;
+        bot_idx = 0;
 
-				/////////////////////////////////////////// ref Bottom Field
-				got_pic = 0;
-				while ((bot_idx < list_size) & ~got_pic)
-				{
-					h264_dpb_set_active_fs(p_dpb, frame_list[bot_idx]);
-					if ((viddec_h264_get_is_used(active_fs))&0x2)
-					{
-						if(h264_dpb_pic_is_bottom_field_ref(long_term))
-						{
-							pic_list[list_idx] = PUT_LIST_LONG_TERM_BITS(lterm) + frame_list[bot_idx] + PUT_LIST_INDEX_FIELD_BIT(1);  // bottom_field
-							list_idx++;
-							got_pic = 1;
-						}
-					}
-					bot_idx++;
-				}
-			}    
-		}      
-		  
-		/////////////////////////////////////////////// current Bottom Field
-		if (currPicStructure == BOTTOM_FIELD)	{
-			while ((top_idx < list_size)||(bot_idx < list_size))
-			{
-				/////////////////////////////////////////// ref Top Field
-				got_pic = 0;
-				while ((bot_idx < list_size) && (!(got_pic)))
-				{
-					h264_dpb_set_active_fs(p_dpb, frame_list[bot_idx]);
-					if ((viddec_h264_get_is_used(active_fs))&0x2) {
-						if(h264_dpb_pic_is_bottom_field_ref(long_term)) {
-							// short term ref pic
-						  pic_list[list_idx] = PUT_LIST_LONG_TERM_BITS(lterm) + frame_list[bot_idx] + PUT_LIST_INDEX_FIELD_BIT(1);  // bottom_field
-						  list_idx++;
-						  got_pic = 1;
-						}
-					}
-					bot_idx++;
-				}
+        if (currPicStructure == TOP_FIELD) {
+            while ((top_idx < list_size)||(bot_idx < list_size))
+            {
+                /////////////////////////////////////////// ref Top Field
+                got_pic = 0;
+                while ((top_idx < list_size) & ~got_pic)
+                {
+                    h264_dpb_set_active_fs(p_dpb, frame_list[top_idx]);
+                    if ((viddec_h264_get_is_used(active_fs))&0x1)
+                    {
+                        if (h264_dpb_pic_is_top_field_ref(long_term))
+                        {
+                            pic_list[list_idx] = PUT_LIST_LONG_TERM_BITS(lterm) + frame_list[top_idx] + PUT_LIST_INDEX_FIELD_BIT(0);  // top_field
+                            list_idx++;
+                            got_pic = 1;
+                        }
+                    }
+                    top_idx++;
+                }
 
-				/////////////////////////////////////////// ref Bottom Field
-				got_pic = 0;
-				while ((top_idx < list_size) && (!(got_pic)))
-				{
-					h264_dpb_set_active_fs(p_dpb, frame_list[top_idx]);
-					if ((viddec_h264_get_is_used(active_fs))&0x1) {
-						if(h264_dpb_pic_is_top_field_ref(long_term)){
-							// short term ref pic
-						  pic_list[list_idx] = PUT_LIST_LONG_TERM_BITS(lterm) + frame_list[top_idx] + PUT_LIST_INDEX_FIELD_BIT(0);  // top_field
-						  list_idx++;
-						  got_pic = 1;
-						}
-					}
-					top_idx++;
-				}
-			}    
-		}
-	}
-	  
-	return list_idx;
+                /////////////////////////////////////////// ref Bottom Field
+                got_pic = 0;
+                while ((bot_idx < list_size) & ~got_pic)
+                {
+                    h264_dpb_set_active_fs(p_dpb, frame_list[bot_idx]);
+                    if ((viddec_h264_get_is_used(active_fs))&0x2)
+                    {
+                        if (h264_dpb_pic_is_bottom_field_ref(long_term))
+                        {
+                            pic_list[list_idx] = PUT_LIST_LONG_TERM_BITS(lterm) + frame_list[bot_idx] + PUT_LIST_INDEX_FIELD_BIT(1);  // bottom_field
+                            list_idx++;
+                            got_pic = 1;
+                        }
+                    }
+                    bot_idx++;
+                }
+            }
+        }
+
+        /////////////////////////////////////////////// current Bottom Field
+        if (currPicStructure == BOTTOM_FIELD)	{
+            while ((top_idx < list_size)||(bot_idx < list_size))
+            {
+                /////////////////////////////////////////// ref Top Field
+                got_pic = 0;
+                while ((bot_idx < list_size) && (!(got_pic)))
+                {
+                    h264_dpb_set_active_fs(p_dpb, frame_list[bot_idx]);
+                    if ((viddec_h264_get_is_used(active_fs))&0x2) {
+                        if (h264_dpb_pic_is_bottom_field_ref(long_term)) {
+                            // short term ref pic
+                            pic_list[list_idx] = PUT_LIST_LONG_TERM_BITS(lterm) + frame_list[bot_idx] + PUT_LIST_INDEX_FIELD_BIT(1);  // bottom_field
+                            list_idx++;
+                            got_pic = 1;
+                        }
+                    }
+                    bot_idx++;
+                }
+
+                /////////////////////////////////////////// ref Bottom Field
+                got_pic = 0;
+                while ((top_idx < list_size) && (!(got_pic)))
+                {
+                    h264_dpb_set_active_fs(p_dpb, frame_list[top_idx]);
+                    if ((viddec_h264_get_is_used(active_fs))&0x1) {
+                        if (h264_dpb_pic_is_top_field_ref(long_term)) {
+                            // short term ref pic
+                            pic_list[list_idx] = PUT_LIST_LONG_TERM_BITS(lterm) + frame_list[top_idx] + PUT_LIST_INDEX_FIELD_BIT(0);  // top_field
+                            list_idx++;
+                            got_pic = 1;
+                        }
+                    }
+                    top_idx++;
+                }
+            }
+        }
+    }
+
+    return list_idx;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -342,30 +342,30 @@
 
 void h264_dpb_remove_ref_list(h264_DecodedPictureBuffer * p_dpb, int32_t ref_idc)
 {
-	uint8_t idx   = 0;
-	int32_t Found = 0;
+    uint8_t idx   = 0;
+    int32_t Found = 0;
 
-	while ((idx < p_dpb->ref_frames_in_buffer) && (!(Found)))
-	{
-		if (p_dpb->fs_ref_idc[idx] == ref_idc) 
-			Found = 1;
-		else 
-			idx++;
-	}
+    while ((idx < p_dpb->ref_frames_in_buffer) && (!(Found)))
+    {
+        if (p_dpb->fs_ref_idc[idx] == ref_idc)
+            Found = 1;
+        else
+            idx++;
+    }
 
-	if (Found)
-	{
-		// Move the remainder of the list up one
-		while(idx < p_dpb->ref_frames_in_buffer - 1) {
-			p_dpb->fs_ref_idc[idx] = p_dpb->fs_ref_idc[idx + 1];
-			idx ++;
-		}
+    if (Found)
+    {
+        // Move the remainder of the list up one
+        while (idx < p_dpb->ref_frames_in_buffer - 1) {
+            p_dpb->fs_ref_idc[idx] = p_dpb->fs_ref_idc[idx + 1];
+            idx ++;
+        }
 
-		p_dpb->fs_ref_idc[idx] = MPD_DPB_FS_NULL_IDC; // Clear the last one
-		p_dpb->ref_frames_in_buffer--;
-	}
+        p_dpb->fs_ref_idc[idx] = MPD_DPB_FS_NULL_IDC; // Clear the last one
+        p_dpb->ref_frames_in_buffer--;
+    }
 
-  return;
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -378,29 +378,29 @@
 
 void h264_dpb_remove_ltref_list(h264_DecodedPictureBuffer * p_dpb,int32_t ref_idc)
 {
-	uint8_t idx   = 0;
-	int32_t Found = 0;
+    uint8_t idx   = 0;
+    int32_t Found = 0;
 
-	while ((idx < p_dpb->ltref_frames_in_buffer) && (!(Found)))
-	{
-		if (p_dpb->fs_ltref_idc[idx] == ref_idc) Found = 1;
-		else idx++;
-	}
+    while ((idx < p_dpb->ltref_frames_in_buffer) && (!(Found)))
+    {
+        if (p_dpb->fs_ltref_idc[idx] == ref_idc) Found = 1;
+        else idx++;
+    }
 
-	if (Found)
-	{
-		// Move the remainder of the list up one
-		while(idx <(uint8_t)(p_dpb->ltref_frames_in_buffer - 1))
-		{
-			p_dpb->fs_ltref_idc[idx] = p_dpb->fs_ltref_idc[idx + 1];
-			idx ++;
-		}
-		p_dpb->fs_ltref_idc[idx] = MPD_DPB_FS_NULL_IDC;		// Clear the last one
+    if (Found)
+    {
+        // Move the remainder of the list up one
+        while (idx <(uint8_t)(p_dpb->ltref_frames_in_buffer - 1))
+        {
+            p_dpb->fs_ltref_idc[idx] = p_dpb->fs_ltref_idc[idx + 1];
+            idx ++;
+        }
+        p_dpb->fs_ltref_idc[idx] = MPD_DPB_FS_NULL_IDC;		// Clear the last one
 
-		p_dpb->ltref_frames_in_buffer--;
-	}
+        p_dpb->ltref_frames_in_buffer--;
+    }
 
-	return;
+    return;
 }
 
 
@@ -415,474 +415,474 @@
 //////////////////////////////////////////////////////////////////////////////
 void h264_dpb_update_ref_lists(h264_Info * pInfo)
 {
-	h264_DecodedPictureBuffer * p_dpb = &pInfo->dpb;
+    h264_DecodedPictureBuffer * p_dpb = &pInfo->dpb;
 
-	int32_t MaxFrameNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
+    int32_t MaxFrameNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
 
-	uint8_t list0idx, list0idx_1, listltidx;
-	uint8_t idx;
+    uint8_t list0idx, list0idx_1, listltidx;
+    uint8_t idx;
 
-	uint8_t add_top, add_bottom, diff;
-	uint8_t list_idc;
-	uint8_t check_non_existing, skip_picture;
+    uint8_t add_top, add_bottom, diff;
+    uint8_t list_idc;
+    uint8_t check_non_existing, skip_picture;
 
 
-	uint8_t gen_pic_fs_list0[16];
-	uint8_t gen_pic_fs_list1[16];
-	uint8_t gen_pic_fs_listlt[16];
-	uint8_t gen_pic_pic_list[32];  // check out these sizes...
+    uint8_t gen_pic_fs_list0[16];
+    uint8_t gen_pic_fs_list1[16];
+    uint8_t gen_pic_fs_listlt[16];
+    uint8_t gen_pic_pic_list[32];  // check out these sizes...
 
-	uint8_t sort_fs_idc[16];
-	int32_t list_sort_number[16];
+    uint8_t sort_fs_idc[16];
+    int32_t list_sort_number[16];
 
 #ifdef DUMP_HEADER_INFO
-	static int cc1 = 0;
-	//OS_INFO("-------------cc1= %d\n",cc1);    /////// DEBUG info
-	if(cc1 == 255) 
-		idx = 0;
+    static int cc1 = 0;
+    //OS_INFO("-------------cc1= %d\n",cc1);    /////// DEBUG info
+    if (cc1 == 255)
+        idx = 0;
 #endif
 
-	list0idx = list0idx_1 = listltidx = 0;
+    list0idx = list0idx_1 = listltidx = 0;
 
-	if (pInfo->SliceHeader.structure == FRAME) 
-	{
-		////////////////////////////////////////////////// short term handling
-		for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
-		{
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
+    if (pInfo->SliceHeader.structure == FRAME)
+    {
+        ////////////////////////////////////////////////// short term handling
+        for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
 
-			if((viddec_h264_get_is_used(active_fs) == 3)&&(active_fs->frame.used_for_reference == 3))
-			{
-				if (active_fs->frame_num > pInfo->img.frame_num) 
-				   active_fs->frame_num_wrap = active_fs->frame_num - MaxFrameNum;
-				else                                      
-				   active_fs->frame_num_wrap = active_fs->frame_num;
+            if ((viddec_h264_get_is_used(active_fs) == 3)&&(active_fs->frame.used_for_reference == 3))
+            {
+                if (active_fs->frame_num > pInfo->img.frame_num)
+                    active_fs->frame_num_wrap = active_fs->frame_num - MaxFrameNum;
+                else
+                    active_fs->frame_num_wrap = active_fs->frame_num;
 
-				active_fs->frame.pic_num     = active_fs->frame_num_wrap;
+                active_fs->frame.pic_num     = active_fs->frame_num_wrap;
 
-				// Use this opportunity to sort list for a p-frame
-				if(pInfo->SliceHeader.slice_type == h264_PtypeP)
-				{
-				  sort_fs_idc[list0idx]      = p_dpb->fs_ref_idc[idx];
-				  list_sort_number[list0idx] = active_fs->frame.pic_num;
-				  list0idx++;          	
-				}
-			}
-		}
+                // Use this opportunity to sort list for a p-frame
+                if (pInfo->SliceHeader.slice_type == h264_PtypeP)
+                {
+                    sort_fs_idc[list0idx]      = p_dpb->fs_ref_idc[idx];
+                    list_sort_number[list0idx] = active_fs->frame.pic_num;
+                    list0idx++;
+                }
+            }
+        }
 
-		if(pInfo->SliceHeader.slice_type == h264_PtypeP)
-		{
-			h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 1);
-			for (idx = 0; idx < list0idx; idx++)
-				p_dpb->listX_0[idx] = (sort_fs_idc[idx]);  // frame
+        if (pInfo->SliceHeader.slice_type == h264_PtypeP)
+        {
+            h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 1);
+            for (idx = 0; idx < list0idx; idx++)
+                p_dpb->listX_0[idx] = (sort_fs_idc[idx]);  // frame
 
-			p_dpb->listXsize[0] = list0idx;
-		}
+            p_dpb->listXsize[0] = list0idx;
+        }
 
-		////////////////////////////////////////////////// long term handling
-		for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
-		{
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
-			if ((viddec_h264_get_is_used(active_fs) == 3) && (viddec_h264_get_is_long_term(active_fs) == 3) && (active_fs->frame.used_for_reference == 3))
-			{
-				active_fs->frame.long_term_pic_num = active_fs->frame.long_term_frame_idx;
+        ////////////////////////////////////////////////// long term handling
+        for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
+            if ((viddec_h264_get_is_used(active_fs) == 3) && (viddec_h264_get_is_long_term(active_fs) == 3) && (active_fs->frame.used_for_reference == 3))
+            {
+                active_fs->frame.long_term_pic_num = active_fs->frame.long_term_frame_idx;
 
-				if(pInfo->SliceHeader.slice_type == h264_PtypeP)
-				{
-				  sort_fs_idc[list0idx-p_dpb->listXsize[0]]       = p_dpb->fs_ltref_idc[idx];
-				  list_sort_number[list0idx-p_dpb->listXsize[0]]  = active_fs->frame.long_term_pic_num;
-				  list0idx++;
-				}
-			}
-		}
+                if (pInfo->SliceHeader.slice_type == h264_PtypeP)
+                {
+                    sort_fs_idc[list0idx-p_dpb->listXsize[0]]       = p_dpb->fs_ltref_idc[idx];
+                    list_sort_number[list0idx-p_dpb->listXsize[0]]  = active_fs->frame.long_term_pic_num;
+                    list0idx++;
+                }
+            }
+        }
 
-		if(pInfo->SliceHeader.slice_type == h264_PtypeP)
-		{
-			h264_list_sort(sort_fs_idc, list_sort_number, list0idx-p_dpb->listXsize[0], 0);	
-			for (idx = p_dpb->listXsize[0]; idx < list0idx; idx++) {
-				p_dpb->listX_0[idx] = (1<<6) + sort_fs_idc[idx-p_dpb->listXsize[0]];
-			}
-			p_dpb->listXsize[0] = list0idx;
-		}
-	}  
-	else   /// Field base
-	{
-		if (pInfo->SliceHeader.structure == TOP_FIELD)
-		{
-			add_top    = 1; 
-			add_bottom = 0; 
-		}
-		else
-		{
-			add_top    = 0; 
-			add_bottom = 1; 
-		}
+        if (pInfo->SliceHeader.slice_type == h264_PtypeP)
+        {
+            h264_list_sort(sort_fs_idc, list_sort_number, list0idx-p_dpb->listXsize[0], 0);
+            for (idx = p_dpb->listXsize[0]; idx < list0idx; idx++) {
+                p_dpb->listX_0[idx] = (1<<6) + sort_fs_idc[idx-p_dpb->listXsize[0]];
+            }
+            p_dpb->listXsize[0] = list0idx;
+        }
+    }
+    else   /// Field base
+    {
+        if (pInfo->SliceHeader.structure == TOP_FIELD)
+        {
+            add_top    = 1;
+            add_bottom = 0;
+        }
+        else
+        {
+            add_top    = 0;
+            add_bottom = 1;
+        }
 
-		////////////////////////////////////////////P0: Short term handling
-		for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
-		{
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
-			if (active_fs->frame.used_for_reference)
-			{
-				if(active_fs->frame_num > pInfo->SliceHeader.frame_num) {
-					active_fs->frame_num_wrap = active_fs->frame_num - MaxFrameNum;
-				} else {
-					active_fs->frame_num_wrap = active_fs->frame_num;
-				}
+        ////////////////////////////////////////////P0: Short term handling
+        for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
+            if (active_fs->frame.used_for_reference)
+            {
+                if (active_fs->frame_num > pInfo->SliceHeader.frame_num) {
+                    active_fs->frame_num_wrap = active_fs->frame_num - MaxFrameNum;
+                } else {
+                    active_fs->frame_num_wrap = active_fs->frame_num;
+                }
 
-				if ((active_fs->frame.used_for_reference)&0x1) {
-					active_fs->top_field.pic_num    = (active_fs->frame_num_wrap << 1) + add_top;
-				}
+                if ((active_fs->frame.used_for_reference)&0x1) {
+                    active_fs->top_field.pic_num    = (active_fs->frame_num_wrap << 1) + add_top;
+                }
 
-				if ((active_fs->frame.used_for_reference)&0x2) {
-					active_fs->bottom_field.pic_num = (active_fs->frame_num_wrap << 1) + add_bottom;
-				}
+                if ((active_fs->frame.used_for_reference)&0x2) {
+                    active_fs->bottom_field.pic_num = (active_fs->frame_num_wrap << 1) + add_bottom;
+                }
 
-				if(pInfo->SliceHeader.slice_type == h264_PtypeP) { 
-					sort_fs_idc[list0idx]      = p_dpb->fs_ref_idc[idx];
-					list_sort_number[list0idx] = active_fs->frame_num_wrap;
-					list0idx++;
-				}
-			}
-		}
+                if (pInfo->SliceHeader.slice_type == h264_PtypeP) {
+                    sort_fs_idc[list0idx]      = p_dpb->fs_ref_idc[idx];
+                    list_sort_number[list0idx] = active_fs->frame_num_wrap;
+                    list0idx++;
+                }
+            }
+        }
 
-		if(pInfo->SliceHeader.slice_type == h264_PtypeP)
-		{
-			h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 1);	
-			for (idx = 0; idx < list0idx; idx++) {
-				gen_pic_fs_list0[idx] = sort_fs_idc[idx];
-			}
+        if (pInfo->SliceHeader.slice_type == h264_PtypeP)
+        {
+            h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 1);
+            for (idx = 0; idx < list0idx; idx++) {
+                gen_pic_fs_list0[idx] = sort_fs_idc[idx];
+            }
 
-			p_dpb->listXsize[0] = 0;
-			p_dpb->listXsize[0] = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_list0, pInfo->img.structure, list0idx, 0);
+            p_dpb->listXsize[0] = 0;
+            p_dpb->listXsize[0] = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_list0, pInfo->img.structure, list0idx, 0);
 
-			for (idx = 0; idx < p_dpb->listXsize[0]; idx++)
-			{
-				p_dpb->listX_0[idx] = gen_pic_pic_list[idx];
-			}
-		}
+            for (idx = 0; idx < p_dpb->listXsize[0]; idx++)
+            {
+                p_dpb->listX_0[idx] = gen_pic_pic_list[idx];
+            }
+        }
 
-		////////////////////////////////////////////P0: long term handling
-		for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
-		{
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
+        ////////////////////////////////////////////P0: long term handling
+        for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
 
-			if (viddec_h264_get_is_long_term(active_fs)&0x1) {
-				active_fs->top_field.long_term_pic_num    = (active_fs->top_field.long_term_frame_idx << 1) + add_top;
-			}
+            if (viddec_h264_get_is_long_term(active_fs)&0x1) {
+                active_fs->top_field.long_term_pic_num    = (active_fs->top_field.long_term_frame_idx << 1) + add_top;
+            }
 
-			if (viddec_h264_get_is_long_term(active_fs)&0x2) {
-				active_fs->bottom_field.long_term_pic_num = (active_fs->bottom_field.long_term_frame_idx << 1) + add_bottom;
-			}
-			  
-			if(pInfo->SliceHeader.slice_type == h264_PtypeP)
-			{
-				sort_fs_idc[listltidx]      = p_dpb->fs_ltref_idc[idx];
-				list_sort_number[listltidx] = active_fs->long_term_frame_idx;
-				listltidx++;
-			}      
-		}
+            if (viddec_h264_get_is_long_term(active_fs)&0x2) {
+                active_fs->bottom_field.long_term_pic_num = (active_fs->bottom_field.long_term_frame_idx << 1) + add_bottom;
+            }
 
-		if(pInfo->SliceHeader.slice_type == h264_PtypeP)
-		{
-			h264_list_sort(sort_fs_idc, list_sort_number, listltidx, 0);    
-			for (idx = 0; idx < listltidx; idx++) {
-				gen_pic_fs_listlt[idx] = sort_fs_idc[idx];
-			}
-			list0idx_1 = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_listlt, pInfo->img.structure, listltidx, 1);
+            if (pInfo->SliceHeader.slice_type == h264_PtypeP)
+            {
+                sort_fs_idc[listltidx]      = p_dpb->fs_ltref_idc[idx];
+                list_sort_number[listltidx] = active_fs->long_term_frame_idx;
+                listltidx++;
+            }
+        }
 
-			for (idx = 0; idx < list0idx_1; idx++) {
-				p_dpb->listX_0[p_dpb->listXsize[0]+idx] = gen_pic_pic_list[idx];
-			}
-			p_dpb->listXsize[0] += list0idx_1;
-		}
-	}
+        if (pInfo->SliceHeader.slice_type == h264_PtypeP)
+        {
+            h264_list_sort(sort_fs_idc, list_sort_number, listltidx, 0);
+            for (idx = 0; idx < listltidx; idx++) {
+                gen_pic_fs_listlt[idx] = sort_fs_idc[idx];
+            }
+            list0idx_1 = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_listlt, pInfo->img.structure, listltidx, 1);
+
+            for (idx = 0; idx < list0idx_1; idx++) {
+                p_dpb->listX_0[p_dpb->listXsize[0]+idx] = gen_pic_pic_list[idx];
+            }
+            p_dpb->listXsize[0] += list0idx_1;
+        }
+    }
 
 
-	if (pInfo->SliceHeader.slice_type == h264_PtypeI)
-	{
-		p_dpb->listXsize[0] = 0;
-		p_dpb->listXsize[1] = 0;
-		return;
-	}
+    if (pInfo->SliceHeader.slice_type == h264_PtypeI)
+    {
+        p_dpb->listXsize[0] = 0;
+        p_dpb->listXsize[1] = 0;
+        return;
+    }
 
-	if(pInfo->SliceHeader.slice_type == h264_PtypeP) 
-	{
-		//// Forward done above
-		p_dpb->listXsize[1] = 0;
-	}
-
-	  
-	// B-Slice
-	// Do not include non-existing frames for B-pictures when cnt_type is zero
-
-	if(pInfo->SliceHeader.slice_type == h264_PtypeB)
-	{
-		list0idx = list0idx_1 = listltidx = 0;
-		skip_picture = 0;
-
-		if(pInfo->active_SPS.pic_order_cnt_type == 0)
-		  check_non_existing = 1;
-		else
-		  check_non_existing = 0;
-
-		if (pInfo->SliceHeader.structure == FRAME)  
-		{
-		  for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
-		  {
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
-			if (viddec_h264_get_is_used(active_fs) == 3)
-			{
-				if(check_non_existing)
-				{
-					if(viddec_h264_get_is_non_existent(active_fs)) skip_picture = 1;
-					else                           skip_picture = 0;  
-				}
-			      
-				if(skip_picture == 0)
-				{
-					if ((active_fs->frame.used_for_reference==3) && (!(active_fs->frame.is_long_term)))
-					{
-						if (pInfo->img.framepoc >= active_fs->frame.poc)
-						{
-							sort_fs_idc[list0idx]      = p_dpb->fs_ref_idc[idx];
-							list_sort_number[list0idx] = active_fs->frame.poc;
-							list0idx++;
-						}
-					}
-				}
-			}
-		  }
-		     	
-		  h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 1);
-		  for (idx = 0; idx < list0idx; idx++) {
-			p_dpb->listX_0[idx] = sort_fs_idc[idx];
-		  }
-
-		  list0idx_1 = list0idx;
-		  
-		  /////////////////////////////////////////B0:  Short term handling
-		  for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
-		  {
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
-
-			if (viddec_h264_get_is_used(active_fs) == 3)
-			{
-				if(check_non_existing)
-				{
-					if(viddec_h264_get_is_non_existent(active_fs))	skip_picture = 1;
-					else							skip_picture = 0;  
-				}
-
-				if(skip_picture == 0)
-				{
-					if ((active_fs->frame.used_for_reference) && (!(active_fs->frame.is_long_term)))
-					{
-					  if (pInfo->img.framepoc < active_fs->frame.poc)
-					  {
-						sort_fs_idc[list0idx-list0idx_1]      = p_dpb->fs_ref_idc[idx];
-						list_sort_number[list0idx-list0idx_1] = active_fs->frame.poc;
-						list0idx++;
-					  }
-					}
-				}
-			}
-		  }
-		  
-		  h264_list_sort(sort_fs_idc, list_sort_number, list0idx-list0idx_1, 0);
-		  for (idx = list0idx_1; idx < list0idx; idx++) {
-			p_dpb->listX_0[idx] = sort_fs_idc[idx-list0idx_1];
-		  }
-
-		  for (idx = 0; idx < list0idx_1; idx++) {
-			p_dpb->listX_1[list0idx-list0idx_1+idx] = p_dpb->listX_0[idx];
-		  }
-
-		  for (idx = list0idx_1; idx < list0idx; idx++) {
-			p_dpb->listX_1[idx-list0idx_1] = p_dpb->listX_0[idx];
-		  }
-
-		  p_dpb->listXsize[0] = list0idx;
-		  p_dpb->listXsize[1] = list0idx;
-
-		  /////////////////////////////////////////B0:  long term handling
-		  list0idx = 0;
-
-		  // Can non-existent pics be set as long term??
-		  for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
-		  {
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
-		    
-			if ((viddec_h264_get_is_used(active_fs) == 3) && (viddec_h264_get_is_long_term(active_fs) == 3))
-			{
-				// if we have two fields, both must be long-term
-			  sort_fs_idc[list0idx]      = p_dpb->fs_ltref_idc[idx];
-			  list_sort_number[list0idx] = active_fs->frame.long_term_pic_num;
-			  list0idx++;
-			}
-		  }
-		  
-		  h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 0);
-		  for (idx = p_dpb->listXsize[0]; idx < (p_dpb->listXsize[0]+list0idx); idx = idx + 1)
-		  {
-			p_dpb->listX_0[idx] = (1<<6) + sort_fs_idc[idx-p_dpb->listXsize[0]];
-			p_dpb->listX_1[idx] = (1<<6) + sort_fs_idc[idx-p_dpb->listXsize[0]];
-		  }
-		    
-		  p_dpb->listXsize[0] += list0idx;
-		  p_dpb->listXsize[1] += list0idx;
-		}
-		else  // Field
-		{
-		  for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
-		  {
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
-
-			if (viddec_h264_get_is_used(active_fs))	{
-				if(check_non_existing) {
-					if(viddec_h264_get_is_non_existent(active_fs)) 
-						skip_picture = 1;
-					else
-						skip_picture = 0;  
-				}
-
-				if(skip_picture == 0)  {
-					if (pInfo->img.ThisPOC >= active_fs->frame.poc) {
-					  sort_fs_idc[list0idx]      = p_dpb->fs_ref_idc[idx];
-					  list_sort_number[list0idx] = active_fs->frame.poc; 
-					  list0idx++;
-					}
-				}
-			}
-		  }
-		  
-		  h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 1);      
-		  for (idx = 0; idx < list0idx; idx = idx + 1) {
-			gen_pic_fs_list0[idx] = sort_fs_idc[idx];
-		  }
-		    
-		  list0idx_1 = list0idx;
-
-		  ///////////////////////////////////////////// B1: Short term handling
-		  for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
-		  {
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
-			if (viddec_h264_get_is_used(active_fs))
-			{
-				if(check_non_existing) {
-					if(viddec_h264_get_is_non_existent(active_fs)) 
-						skip_picture = 1;
-					else 
-						skip_picture = 0;  
-				}
-
-				if(skip_picture == 0) {
-					if (pInfo->img.ThisPOC < active_fs->frame.poc) {
-						sort_fs_idc[list0idx-list0idx_1]      = p_dpb->fs_ref_idc[idx];
-						list_sort_number[list0idx-list0idx_1] = active_fs->frame.poc; 
-						list0idx++;
-					}
-				}
-			}
-		  }
-		  
-		  ///// Generate frame list from sorted fs
-		  /////
-		  h264_list_sort(sort_fs_idc, list_sort_number, list0idx-list0idx_1, 0);            
-		  for (idx = list0idx_1; idx < list0idx; idx++)
-			gen_pic_fs_list0[idx] = sort_fs_idc[idx-list0idx_1];
-		    
-		  for (idx = 0; idx < list0idx_1; idx++)
-			gen_pic_fs_list1[list0idx-list0idx_1+idx] = gen_pic_fs_list0[idx];
-
-		  for (idx = list0idx_1; idx < list0idx; idx++)
-			gen_pic_fs_list1[idx-list0idx_1] = gen_pic_fs_list0[idx];    
-
-		  ///// Generate List_X0
-		  /////
-		  p_dpb->listXsize[0] = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_list0, pInfo->img.structure, list0idx, 0);
-
-		  for (idx = 0; idx < p_dpb->listXsize[0]; idx++)
-			p_dpb->listX_0[idx] = gen_pic_pic_list[idx];
-
-		  //// Generate List X1
-		  ////
-		  p_dpb->listXsize[1] = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_list1, pInfo->img.structure, list0idx, 0);
-
-		  for (idx = 0; idx < p_dpb->listXsize[1]; idx++)
-			p_dpb->listX_1[idx] = gen_pic_pic_list[idx];
-
-		  ///////////////////////////////////////////// B1: long term handling
-		  for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
-		  {
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
-			sort_fs_idc[listltidx]      = p_dpb->fs_ltref_idc[idx];
-			list_sort_number[listltidx] = active_fs->long_term_frame_idx;
-			listltidx++;
-		  }
-
-		  h264_list_sort(sort_fs_idc, list_sort_number, listltidx, 0);      
-		  for (idx = 0; idx < listltidx; idx++) 
-			gen_pic_fs_listlt[idx] = sort_fs_idc[idx];
-
-		  list0idx_1 = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_listlt, pInfo->img.structure, listltidx, 1);
-
-		  for (idx = 0; idx < list0idx_1; idx++)
-		  {
-			p_dpb->listX_0[p_dpb->listXsize[0]+idx] = gen_pic_pic_list[idx];
-			p_dpb->listX_1[p_dpb->listXsize[1]+idx] = gen_pic_pic_list[idx];
-		  }
-		    
-		  p_dpb->listXsize[0] += list0idx_1;
-		  p_dpb->listXsize[1] += list0idx_1;
-		}
-	}
-
-	// Setup initial list sizes at this point  
-	p_dpb->nInitListSize[0] = p_dpb->listXsize[0];  
-	p_dpb->nInitListSize[1] = p_dpb->listXsize[1];
-	if(pInfo->SliceHeader.slice_type != h264_PtypeI)
-	{
-		if ((p_dpb->listXsize[0]==p_dpb->listXsize[1]) && (p_dpb->listXsize[0] > 1))
-		{
-			// check if lists are identical, if yes swap first two elements of listX[1]
-			diff = 0;
-			for (idx = 0; idx < p_dpb->listXsize[0]; idx = idx + 1) 
-			{
-				if (p_dpb->listX_0[idx] != p_dpb->listX_1[idx]) diff = 1;
-			}
+    if (pInfo->SliceHeader.slice_type == h264_PtypeP)
+    {
+        //// Forward done above
+        p_dpb->listXsize[1] = 0;
+    }
 
 
-			if (!(diff))
-			{ 
-				list_idc       = p_dpb->listX_1[0];
-				p_dpb->listX_1[0] = p_dpb->listX_1[1];
-				p_dpb->listX_1[1] = list_idc;
-			}
-		}
+    // B-Slice
+    // Do not include non-existing frames for B-pictures when cnt_type is zero
 
-		// set max size
-      if (p_dpb->listXsize[0] > pInfo->SliceHeader.num_ref_idx_l0_active) 
-      {
-         p_dpb->listXsize[0] = pInfo->SliceHeader.num_ref_idx_l0_active;
-      }
+    if (pInfo->SliceHeader.slice_type == h264_PtypeB)
+    {
+        list0idx = list0idx_1 = listltidx = 0;
+        skip_picture = 0;
+
+        if (pInfo->active_SPS.pic_order_cnt_type == 0)
+            check_non_existing = 1;
+        else
+            check_non_existing = 0;
+
+        if (pInfo->SliceHeader.structure == FRAME)
+        {
+            for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
+            {
+                h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
+                if (viddec_h264_get_is_used(active_fs) == 3)
+                {
+                    if (check_non_existing)
+                    {
+                        if (viddec_h264_get_is_non_existent(active_fs)) skip_picture = 1;
+                        else                           skip_picture = 0;
+                    }
+
+                    if (skip_picture == 0)
+                    {
+                        if ((active_fs->frame.used_for_reference==3) && (!(active_fs->frame.is_long_term)))
+                        {
+                            if (pInfo->img.framepoc >= active_fs->frame.poc)
+                            {
+                                sort_fs_idc[list0idx]      = p_dpb->fs_ref_idc[idx];
+                                list_sort_number[list0idx] = active_fs->frame.poc;
+                                list0idx++;
+                            }
+                        }
+                    }
+                }
+            }
+
+            h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 1);
+            for (idx = 0; idx < list0idx; idx++) {
+                p_dpb->listX_0[idx] = sort_fs_idc[idx];
+            }
+
+            list0idx_1 = list0idx;
+
+            /////////////////////////////////////////B0:  Short term handling
+            for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
+            {
+                h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
+
+                if (viddec_h264_get_is_used(active_fs) == 3)
+                {
+                    if (check_non_existing)
+                    {
+                        if (viddec_h264_get_is_non_existent(active_fs))	skip_picture = 1;
+                        else							skip_picture = 0;
+                    }
+
+                    if (skip_picture == 0)
+                    {
+                        if ((active_fs->frame.used_for_reference) && (!(active_fs->frame.is_long_term)))
+                        {
+                            if (pInfo->img.framepoc < active_fs->frame.poc)
+                            {
+                                sort_fs_idc[list0idx-list0idx_1]      = p_dpb->fs_ref_idc[idx];
+                                list_sort_number[list0idx-list0idx_1] = active_fs->frame.poc;
+                                list0idx++;
+                            }
+                        }
+                    }
+                }
+            }
+
+            h264_list_sort(sort_fs_idc, list_sort_number, list0idx-list0idx_1, 0);
+            for (idx = list0idx_1; idx < list0idx; idx++) {
+                p_dpb->listX_0[idx] = sort_fs_idc[idx-list0idx_1];
+            }
+
+            for (idx = 0; idx < list0idx_1; idx++) {
+                p_dpb->listX_1[list0idx-list0idx_1+idx] = p_dpb->listX_0[idx];
+            }
+
+            for (idx = list0idx_1; idx < list0idx; idx++) {
+                p_dpb->listX_1[idx-list0idx_1] = p_dpb->listX_0[idx];
+            }
+
+            p_dpb->listXsize[0] = list0idx;
+            p_dpb->listXsize[1] = list0idx;
+
+            /////////////////////////////////////////B0:  long term handling
+            list0idx = 0;
+
+            // Can non-existent pics be set as long term??
+            for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
+            {
+                h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
+
+                if ((viddec_h264_get_is_used(active_fs) == 3) && (viddec_h264_get_is_long_term(active_fs) == 3))
+                {
+                    // if we have two fields, both must be long-term
+                    sort_fs_idc[list0idx]      = p_dpb->fs_ltref_idc[idx];
+                    list_sort_number[list0idx] = active_fs->frame.long_term_pic_num;
+                    list0idx++;
+                }
+            }
+
+            h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 0);
+            for (idx = p_dpb->listXsize[0]; idx < (p_dpb->listXsize[0]+list0idx); idx = idx + 1)
+            {
+                p_dpb->listX_0[idx] = (1<<6) + sort_fs_idc[idx-p_dpb->listXsize[0]];
+                p_dpb->listX_1[idx] = (1<<6) + sort_fs_idc[idx-p_dpb->listXsize[0]];
+            }
+
+            p_dpb->listXsize[0] += list0idx;
+            p_dpb->listXsize[1] += list0idx;
+        }
+        else  // Field
+        {
+            for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
+            {
+                h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
+
+                if (viddec_h264_get_is_used(active_fs))	{
+                    if (check_non_existing) {
+                        if (viddec_h264_get_is_non_existent(active_fs))
+                            skip_picture = 1;
+                        else
+                            skip_picture = 0;
+                    }
+
+                    if (skip_picture == 0)  {
+                        if (pInfo->img.ThisPOC >= active_fs->frame.poc) {
+                            sort_fs_idc[list0idx]      = p_dpb->fs_ref_idc[idx];
+                            list_sort_number[list0idx] = active_fs->frame.poc;
+                            list0idx++;
+                        }
+                    }
+                }
+            }
+
+            h264_list_sort(sort_fs_idc, list_sort_number, list0idx, 1);
+            for (idx = 0; idx < list0idx; idx = idx + 1) {
+                gen_pic_fs_list0[idx] = sort_fs_idc[idx];
+            }
+
+            list0idx_1 = list0idx;
+
+            ///////////////////////////////////////////// B1: Short term handling
+            for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
+            {
+                h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
+                if (viddec_h264_get_is_used(active_fs))
+                {
+                    if (check_non_existing) {
+                        if (viddec_h264_get_is_non_existent(active_fs))
+                            skip_picture = 1;
+                        else
+                            skip_picture = 0;
+                    }
+
+                    if (skip_picture == 0) {
+                        if (pInfo->img.ThisPOC < active_fs->frame.poc) {
+                            sort_fs_idc[list0idx-list0idx_1]      = p_dpb->fs_ref_idc[idx];
+                            list_sort_number[list0idx-list0idx_1] = active_fs->frame.poc;
+                            list0idx++;
+                        }
+                    }
+                }
+            }
+
+            ///// Generate frame list from sorted fs
+            /////
+            h264_list_sort(sort_fs_idc, list_sort_number, list0idx-list0idx_1, 0);
+            for (idx = list0idx_1; idx < list0idx; idx++)
+                gen_pic_fs_list0[idx] = sort_fs_idc[idx-list0idx_1];
+
+            for (idx = 0; idx < list0idx_1; idx++)
+                gen_pic_fs_list1[list0idx-list0idx_1+idx] = gen_pic_fs_list0[idx];
+
+            for (idx = list0idx_1; idx < list0idx; idx++)
+                gen_pic_fs_list1[idx-list0idx_1] = gen_pic_fs_list0[idx];
+
+            ///// Generate List_X0
+            /////
+            p_dpb->listXsize[0] = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_list0, pInfo->img.structure, list0idx, 0);
+
+            for (idx = 0; idx < p_dpb->listXsize[0]; idx++)
+                p_dpb->listX_0[idx] = gen_pic_pic_list[idx];
+
+            //// Generate List X1
+            ////
+            p_dpb->listXsize[1] = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_list1, pInfo->img.structure, list0idx, 0);
+
+            for (idx = 0; idx < p_dpb->listXsize[1]; idx++)
+                p_dpb->listX_1[idx] = gen_pic_pic_list[idx];
+
+            ///////////////////////////////////////////// B1: long term handling
+            for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
+            {
+                h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
+                sort_fs_idc[listltidx]      = p_dpb->fs_ltref_idc[idx];
+                list_sort_number[listltidx] = active_fs->long_term_frame_idx;
+                listltidx++;
+            }
+
+            h264_list_sort(sort_fs_idc, list_sort_number, listltidx, 0);
+            for (idx = 0; idx < listltidx; idx++)
+                gen_pic_fs_listlt[idx] = sort_fs_idc[idx];
+
+            list0idx_1 = h264_dpb_gen_pic_list_from_frame_list(p_dpb, gen_pic_pic_list, gen_pic_fs_listlt, pInfo->img.structure, listltidx, 1);
+
+            for (idx = 0; idx < list0idx_1; idx++)
+            {
+                p_dpb->listX_0[p_dpb->listXsize[0]+idx] = gen_pic_pic_list[idx];
+                p_dpb->listX_1[p_dpb->listXsize[1]+idx] = gen_pic_pic_list[idx];
+            }
+
+            p_dpb->listXsize[0] += list0idx_1;
+            p_dpb->listXsize[1] += list0idx_1;
+        }
+    }
+
+    // Setup initial list sizes at this point
+    p_dpb->nInitListSize[0] = p_dpb->listXsize[0];
+    p_dpb->nInitListSize[1] = p_dpb->listXsize[1];
+    if (pInfo->SliceHeader.slice_type != h264_PtypeI)
+    {
+        if ((p_dpb->listXsize[0]==p_dpb->listXsize[1]) && (p_dpb->listXsize[0] > 1))
+        {
+            // check if lists are identical, if yes swap first two elements of listX[1]
+            diff = 0;
+            for (idx = 0; idx < p_dpb->listXsize[0]; idx = idx + 1)
+            {
+                if (p_dpb->listX_0[idx] != p_dpb->listX_1[idx]) diff = 1;
+            }
 
 
-      if (p_dpb->listXsize[1] > pInfo->SliceHeader.num_ref_idx_l1_active) 
-      {
-         p_dpb->listXsize[1] = pInfo->SliceHeader.num_ref_idx_l1_active;
-      }
+            if (!(diff))
+            {
+                list_idc       = p_dpb->listX_1[0];
+                p_dpb->listX_1[0] = p_dpb->listX_1[1];
+                p_dpb->listX_1[1] = list_idc;
+            }
+        }
+
+        // set max size
+        if (p_dpb->listXsize[0] > pInfo->SliceHeader.num_ref_idx_l0_active)
+        {
+            p_dpb->listXsize[0] = pInfo->SliceHeader.num_ref_idx_l0_active;
+        }
+
+
+        if (p_dpb->listXsize[1] > pInfo->SliceHeader.num_ref_idx_l1_active)
+        {
+            p_dpb->listXsize[1] = pInfo->SliceHeader.num_ref_idx_l1_active;
+        }
 
 
 
-	}
+    }
 
 
 
-	/// DPB reorder list
-	h264_dpb_reorder_lists(pInfo);	
+    /// DPB reorder list
+    h264_dpb_reorder_lists(pInfo);
 
-	return;
+    return;
 }   //// End of init_dpb_list
 
 
@@ -898,40 +898,40 @@
 //
 static frame_param_ptr h264_dpb_get_short_term_pic(h264_Info * pInfo,int32_t pic_num, int32_t *bottom_field_bit)
 {
-	register uint32_t idx;
-	register frame_param_ptr temp_fs;
-	
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    register uint32_t idx;
+    register frame_param_ptr temp_fs;
 
-	*bottom_field_bit = 0;
-	for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
-	{
-		temp_fs = &p_dpb->fs[p_dpb->fs_ref_idc[idx]];    	
-		if (pInfo->SliceHeader.structure == FRAME)
-		{
-			if(temp_fs->frame.used_for_reference == 3) 
-			  if (!(temp_fs->frame.is_long_term))
-				if (temp_fs->frame.pic_num == pic_num) return temp_fs;
-		  }
-		  else // current picture is a field
-		  {
-		  if (temp_fs->frame.used_for_reference&0x1)
-			if (!(temp_fs->top_field.is_long_term))
-			  if (temp_fs->top_field.pic_num == pic_num)
-			  {
-				return temp_fs;
-			  } 
-		   
-		  if (temp_fs->frame.used_for_reference&0x2)
-  			if (!(temp_fs->bottom_field.is_long_term))
-  			  if (temp_fs->bottom_field.pic_num == pic_num)
-  			  {
-      			*bottom_field_bit = PUT_LIST_INDEX_FIELD_BIT(1);
-				return temp_fs;
-			  }  
-		}  
-	}  
-	return NULL;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+
+    *bottom_field_bit = 0;
+    for (idx = 0; idx < p_dpb->ref_frames_in_buffer; idx++)
+    {
+        temp_fs = &p_dpb->fs[p_dpb->fs_ref_idc[idx]];
+        if (pInfo->SliceHeader.structure == FRAME)
+        {
+            if (temp_fs->frame.used_for_reference == 3)
+                if (!(temp_fs->frame.is_long_term))
+                    if (temp_fs->frame.pic_num == pic_num) return temp_fs;
+        }
+        else // current picture is a field
+        {
+            if (temp_fs->frame.used_for_reference&0x1)
+                if (!(temp_fs->top_field.is_long_term))
+                    if (temp_fs->top_field.pic_num == pic_num)
+                    {
+                        return temp_fs;
+                    }
+
+            if (temp_fs->frame.used_for_reference&0x2)
+                if (!(temp_fs->bottom_field.is_long_term))
+                    if (temp_fs->bottom_field.pic_num == pic_num)
+                    {
+                        *bottom_field_bit = PUT_LIST_INDEX_FIELD_BIT(1);
+                        return temp_fs;
+                    }
+        }
+    }
+    return NULL;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -945,38 +945,38 @@
 
 static frame_param_ptr h264_dpb_get_long_term_pic(h264_Info * pInfo,int32_t long_term_pic_num, int32_t *bottom_field_bit)
 {
-	register uint32_t idx;
-	register frame_param_ptr temp_fs;
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    register uint32_t idx;
+    register frame_param_ptr temp_fs;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	*bottom_field_bit = 0;
-	for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
-	{
-		temp_fs = &p_dpb->fs[p_dpb->fs_ltref_idc[idx]];  
-		if (pInfo->SliceHeader.structure == FRAME)
-		{
-			if (temp_fs->frame.used_for_reference == 3)
-			  if (temp_fs->frame.is_long_term)
-				if (temp_fs->frame.long_term_pic_num == long_term_pic_num) 
-					return temp_fs;
-		}
-		else
-		{
-		  if (temp_fs->frame.used_for_reference&0x1)
-			if (temp_fs->top_field.is_long_term)
-			  if (temp_fs->top_field.long_term_pic_num == long_term_pic_num) 
-				  return temp_fs;
+    *bottom_field_bit = 0;
+    for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
+    {
+        temp_fs = &p_dpb->fs[p_dpb->fs_ltref_idc[idx]];
+        if (pInfo->SliceHeader.structure == FRAME)
+        {
+            if (temp_fs->frame.used_for_reference == 3)
+                if (temp_fs->frame.is_long_term)
+                    if (temp_fs->frame.long_term_pic_num == long_term_pic_num)
+                        return temp_fs;
+        }
+        else
+        {
+            if (temp_fs->frame.used_for_reference&0x1)
+                if (temp_fs->top_field.is_long_term)
+                    if (temp_fs->top_field.long_term_pic_num == long_term_pic_num)
+                        return temp_fs;
 
-		  if (temp_fs->frame.used_for_reference&0x2)
-  			if (temp_fs->bottom_field.is_long_term)
-  			  if (temp_fs->bottom_field.long_term_pic_num == long_term_pic_num)
-  			  {
-      			*bottom_field_bit = PUT_LIST_INDEX_FIELD_BIT(1);
-      			return temp_fs;
-			  } 
-		}  
-	}  
-	return NULL;
+            if (temp_fs->frame.used_for_reference&0x2)
+                if (temp_fs->bottom_field.is_long_term)
+                    if (temp_fs->bottom_field.long_term_pic_num == long_term_pic_num)
+                    {
+                        *bottom_field_bit = PUT_LIST_INDEX_FIELD_BIT(1);
+                        return temp_fs;
+                    }
+        }
+    }
+    return NULL;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -988,368 +988,368 @@
 // Used to sort a list based on a corresponding sort indices
 //
 
-struct list_value_t 
+struct list_value_t
 {
-	int32_t value;
-	struct list_value_t *next;     
+    int32_t value;
+    struct list_value_t *next;
 };
 
 struct linked_list_t
 {
-	struct list_value_t *begin;
-	struct list_value_t *end;
-	struct list_value_t *entry;
-	struct list_value_t *prev_entry;
-	struct list_value_t list[32];
+    struct list_value_t *begin;
+    struct list_value_t *end;
+    struct list_value_t *entry;
+    struct list_value_t *prev_entry;
+    struct list_value_t list[32];
 };
 
 static void linked_list_initialize (struct linked_list_t *lp, uint8_t *vp, int32_t size)
 {
-	struct list_value_t *lvp;
+    struct list_value_t *lvp;
 
-	lvp            = lp->list;
-	lp->begin      = lvp;
-	lp->entry      = lvp;
-	lp->end        = lvp + (size-1);
-	lp->prev_entry = NULL;
+    lvp            = lp->list;
+    lp->begin      = lvp;
+    lp->entry      = lvp;
+    lp->end        = lvp + (size-1);
+    lp->prev_entry = NULL;
 
-	while (lvp <= lp->end) 
-	{ 
-		lvp->value = *(vp++); 
-		lvp->next  = lvp + 1;
-		lvp++;
-	}
-	lp->end->next = NULL;
-	return;
+    while (lvp <= lp->end)
+    {
+        lvp->value = *(vp++);
+        lvp->next  = lvp + 1;
+        lvp++;
+    }
+    lp->end->next = NULL;
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 static void linked_list_reorder (struct linked_list_t *lp, int32_t list_value)
 {
-	register struct list_value_t *lvp = lp->entry;
-	register struct list_value_t *lvp_prev;
+    register struct list_value_t *lvp = lp->entry;
+    register struct list_value_t *lvp_prev;
 
-	if (lvp == NULL) {
-		lp->end->value = list_value;  // replace the end entry
-	} else if ((lp->begin==lp->end)||(lvp==lp->end))  // replece the begin/end entry and set the entry to NULL
-	{
-		lp->entry->value = list_value;
-		lp->prev_entry   = lp->entry;
-		lp->entry        = NULL;
-	}
-	else if (lvp->value==list_value)  // the entry point matches
-	{
-		lp->prev_entry = lvp;
-		lp->entry      = lvp->next;
-	}
-	else if (lvp->next == lp->end) // the entry is just before the end
-	{
-		// replace the end and swap the end and entry points
-		//                  lvp
-		//  prev_entry  => entry                    => old_end
-		//                 old_end & new_prev_entry => new_end & entry
-		lp->end->value = list_value;
+    if (lvp == NULL) {
+        lp->end->value = list_value;  // replace the end entry
+    } else if ((lp->begin==lp->end)||(lvp==lp->end))  // replece the begin/end entry and set the entry to NULL
+    {
+        lp->entry->value = list_value;
+        lp->prev_entry   = lp->entry;
+        lp->entry        = NULL;
+    }
+    else if (lvp->value==list_value)  // the entry point matches
+    {
+        lp->prev_entry = lvp;
+        lp->entry      = lvp->next;
+    }
+    else if (lvp->next == lp->end) // the entry is just before the end
+    {
+        // replace the end and swap the end and entry points
+        //                  lvp
+        //  prev_entry  => entry                    => old_end
+        //                 old_end & new_prev_entry => new_end & entry
+        lp->end->value = list_value;
 
-		if (lp->prev_entry)
-			lp->prev_entry->next = lp->end; 
-		else
-			lp->begin            = lp->end;
+        if (lp->prev_entry)
+            lp->prev_entry->next = lp->end;
+        else
+            lp->begin            = lp->end;
 
-		lp->prev_entry = lp->end;
-		lp->end->next  = lvp;
-		lp->end        = lvp;
-		lvp->next      = NULL;
-	}
-	else
-	{
-		lvp_prev = NULL;
-		while (lvp->next) // do not check the end but we'll be in the loop at least once
-		{
-			if (lvp->value == list_value) break;
-			lvp_prev = lvp;
-			lvp = lvp->next;
-		}
-		lvp->value = list_value;   // force end matches
+        lp->prev_entry = lp->end;
+        lp->end->next  = lvp;
+        lp->end        = lvp;
+        lvp->next      = NULL;
+    }
+    else
+    {
+        lvp_prev = NULL;
+        while (lvp->next) // do not check the end but we'll be in the loop at least once
+        {
+            if (lvp->value == list_value) break;
+            lvp_prev = lvp;
+            lvp = lvp->next;
+        }
+        lvp->value = list_value;   // force end matches
 
-		// remove lvp from the list
-		lvp_prev->next = lvp->next;
-		if (lvp==lp->end) lp->end = lvp_prev;
+        // remove lvp from the list
+        lvp_prev->next = lvp->next;
+        if (lvp==lp->end) lp->end = lvp_prev;
 
-		// insert lvp in front of lp->entry
-		if (lp->entry==lp->begin) 
-		{
-			lvp->next = lp->begin;
-			lp->begin = lvp;
-		}
-		else
-		{
-			lvp->next = lp->entry;
-			lp->prev_entry->next = lvp;
-		}
-		lp->prev_entry = lvp;
-	}
-	return;
+        // insert lvp in front of lp->entry
+        if (lp->entry==lp->begin)
+        {
+            lvp->next = lp->begin;
+            lp->begin = lvp;
+        }
+        else
+        {
+            lvp->next = lp->entry;
+            lp->prev_entry->next = lvp;
+        }
+        lp->prev_entry = lvp;
+    }
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 static void linked_list_output (struct linked_list_t *lp, int32_t *vp)
 {
-	register int32_t *ip1;
-	register struct list_value_t *lvp;
+    register int32_t *ip1;
+    register struct list_value_t *lvp;
 
-	lvp  = lp->begin;
-	ip1  = vp;
-	while (lvp)
-	{
-		*(ip1++) = lvp->value;
-		lvp = lvp->next;
-	}
-	return;	
+    lvp  = lp->begin;
+    ip1  = vp;
+    while (lvp)
+    {
+        *(ip1++) = lvp->value;
+        lvp = lvp->next;
+    }
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 int32_t h264_dpb_reorder_ref_pic_list(h264_Info * pInfo,int32_t list_num, int32_t num_ref_idx_active)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
-	uint8_t                   *remapping_of_pic_nums_idc;
-	list_reordering_num_t		*list_reordering_num;
-	int32_t                    bottom_field_bit;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    uint8_t                   *remapping_of_pic_nums_idc;
+    list_reordering_num_t		*list_reordering_num;
+    int32_t                    bottom_field_bit;
 
-	int32_t  maxPicNum, currPicNum, picNumLXNoWrap, picNumLXPred, pic_num;
-	int32_t  refIdxLX;
-	int32_t  i;
+    int32_t  maxPicNum, currPicNum, picNumLXNoWrap, picNumLXPred, pic_num;
+    int32_t  refIdxLX;
+    int32_t  i;
 
-	int32_t    PicList[32] = {0};
-	struct linked_list_t ll;
-	struct linked_list_t *lp = &ll;     // should consider use the scratch space
+    int32_t    PicList[32] = {0};
+    struct linked_list_t ll;
+    struct linked_list_t *lp = &ll;     // should consider use the scratch space
 
-	// declare these below as registers gave me 23 cy/MB for the worst frames in Allegro_Combined_CABAC_07_HD, YHu
-	register frame_param_ptr temp_fs;
-	register int32_t temp;
-	register uint8_t  *ip1;
+    // declare these below as registers gave me 23 cy/MB for the worst frames in Allegro_Combined_CABAC_07_HD, YHu
+    register frame_param_ptr temp_fs;
+    register int32_t temp;
+    register uint8_t  *ip1;
 
-	maxPicNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
+    maxPicNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
 
 
-	if (list_num == 0) // i.e list 0
-	{
-		ip1 = p_dpb->listX_0;
-		remapping_of_pic_nums_idc = pInfo->SliceHeader.sh_refpic_l0.reordering_of_pic_nums_idc;
-		list_reordering_num       = pInfo->SliceHeader.sh_refpic_l0.list_reordering_num;
-	}
-	else
-	{
-		ip1 = p_dpb->listX_1;
-		remapping_of_pic_nums_idc = pInfo->SliceHeader.sh_refpic_l1.reordering_of_pic_nums_idc;
-		list_reordering_num       = pInfo->SliceHeader.sh_refpic_l1.list_reordering_num;
-	}
+    if (list_num == 0) // i.e list 0
+    {
+        ip1 = p_dpb->listX_0;
+        remapping_of_pic_nums_idc = pInfo->SliceHeader.sh_refpic_l0.reordering_of_pic_nums_idc;
+        list_reordering_num       = pInfo->SliceHeader.sh_refpic_l0.list_reordering_num;
+    }
+    else
+    {
+        ip1 = p_dpb->listX_1;
+        remapping_of_pic_nums_idc = pInfo->SliceHeader.sh_refpic_l1.reordering_of_pic_nums_idc;
+        list_reordering_num       = pInfo->SliceHeader.sh_refpic_l1.list_reordering_num;
+    }
 
 
-	linked_list_initialize (lp, ip1, num_ref_idx_active);
+    linked_list_initialize (lp, ip1, num_ref_idx_active);
 
-	currPicNum = pInfo->SliceHeader.frame_num;
-	if (pInfo->SliceHeader.structure != FRAME)
-	{
+    currPicNum = pInfo->SliceHeader.frame_num;
+    if (pInfo->SliceHeader.structure != FRAME)
+    {
 
-	/* The reason it is + 1 I think, is because the list is based on polarity
-	   expand later...
-	*/    
-	maxPicNum  <<= 1;
-	currPicNum <<= 1;
-	currPicNum++;
-	}
+        /* The reason it is + 1 I think, is because the list is based on polarity
+           expand later...
+        */
+        maxPicNum  <<= 1;
+        currPicNum <<= 1;
+        currPicNum++;
+    }
 
-	picNumLXPred = currPicNum;
-	refIdxLX = 0;
+    picNumLXPred = currPicNum;
+    refIdxLX = 0;
 
-	for (i = 0; remapping_of_pic_nums_idc[i] != 3; i++)
-	{
-		if(i > MAX_NUM_REF_FRAMES) 
-		{
-				break;
-		}
-		
-		if (remapping_of_pic_nums_idc[i] < 2) // - short-term re-ordering
-		{
-			temp = (list_reordering_num[i].abs_diff_pic_num_minus1 + 1);
-			if (remapping_of_pic_nums_idc[i] == 0)
-			{
-				temp = picNumLXPred - temp;
-				if (temp < 0 ) picNumLXNoWrap = temp + maxPicNum;
-				else           picNumLXNoWrap = temp;
-			}
-			else // (remapping_of_pic_nums_idc[i] == 1) 
-			{
-				temp += picNumLXPred;
-				if (temp  >=  maxPicNum) picNumLXNoWrap = temp - maxPicNum;
-				else                     picNumLXNoWrap = temp;
-			}
+    for (i = 0; remapping_of_pic_nums_idc[i] != 3; i++)
+    {
+        if (i > MAX_NUM_REF_FRAMES)
+        {
+            break;
+        }
 
-			// Updates for next iteration of the loop
-			picNumLXPred = picNumLXNoWrap;
+        if (remapping_of_pic_nums_idc[i] < 2) // - short-term re-ordering
+        {
+            temp = (list_reordering_num[i].abs_diff_pic_num_minus1 + 1);
+            if (remapping_of_pic_nums_idc[i] == 0)
+            {
+                temp = picNumLXPred - temp;
+                if (temp < 0 ) picNumLXNoWrap = temp + maxPicNum;
+                else           picNumLXNoWrap = temp;
+            }
+            else // (remapping_of_pic_nums_idc[i] == 1)
+            {
+                temp += picNumLXPred;
+                if (temp  >=  maxPicNum) picNumLXNoWrap = temp - maxPicNum;
+                else                     picNumLXNoWrap = temp;
+            }
 
-			if (picNumLXNoWrap > currPicNum ) pic_num = picNumLXNoWrap - maxPicNum;
-			else                              pic_num = picNumLXNoWrap;
+            // Updates for next iteration of the loop
+            picNumLXPred = picNumLXNoWrap;
 
-			temp_fs = h264_dpb_get_short_term_pic(pInfo, pic_num, &bottom_field_bit);
-			if (temp_fs)
-			{
-				temp = bottom_field_bit + PUT_FS_IDC_BITS(temp_fs->fs_idc);
-				linked_list_reorder (lp, temp);
-			}
-		}
-		else //(remapping_of_pic_nums_idc[i] == 2) long-term re-ordering
-		{
-			pic_num = list_reordering_num[i].long_term_pic_num;
+            if (picNumLXNoWrap > currPicNum ) pic_num = picNumLXNoWrap - maxPicNum;
+            else                              pic_num = picNumLXNoWrap;
 
-			temp_fs = h264_dpb_get_long_term_pic(pInfo, pic_num, &bottom_field_bit);
-			if (temp_fs)
-			{
-				temp = PUT_LIST_LONG_TERM_BITS(1) + bottom_field_bit + PUT_FS_IDC_BITS(temp_fs->fs_idc);
-				linked_list_reorder (lp, temp);		  	
-			}
-		}
-	}
+            temp_fs = h264_dpb_get_short_term_pic(pInfo, pic_num, &bottom_field_bit);
+            if (temp_fs)
+            {
+                temp = bottom_field_bit + PUT_FS_IDC_BITS(temp_fs->fs_idc);
+                linked_list_reorder (lp, temp);
+            }
+        }
+        else //(remapping_of_pic_nums_idc[i] == 2) long-term re-ordering
+        {
+            pic_num = list_reordering_num[i].long_term_pic_num;
 
-	linked_list_output (lp, PicList);
+            temp_fs = h264_dpb_get_long_term_pic(pInfo, pic_num, &bottom_field_bit);
+            if (temp_fs)
+            {
+                temp = PUT_LIST_LONG_TERM_BITS(1) + bottom_field_bit + PUT_FS_IDC_BITS(temp_fs->fs_idc);
+                linked_list_reorder (lp, temp);
+            }
+        }
+    }
 
-   if(0 == list_num )
-   {
-      for(i=0; i<num_ref_idx_active; i++)
-      {
-         pInfo->slice_ref_list0[i]=(uint8_t)PicList[i];        
-      }         
-   }
-   else
-   {
-      for(i=0; i<num_ref_idx_active; i++)
-      {
-         pInfo->slice_ref_list1[i]=(uint8_t)PicList[i];        
-      }              
-   }
+    linked_list_output (lp, PicList);
+
+    if (0 == list_num )
+    {
+        for (i=0; i<num_ref_idx_active; i++)
+        {
+            pInfo->slice_ref_list0[i]=(uint8_t)PicList[i];
+        }
+    }
+    else
+    {
+        for (i=0; i<num_ref_idx_active; i++)
+        {
+            pInfo->slice_ref_list1[i]=(uint8_t)PicList[i];
+        }
+    }
 
 
-	// Instead of updating the now reordered list here, just write it down...
-	// This way, we can continue to hold the initialised list in p_dpb->listX_0
-	// and therefore not need to update it every slice
+    // Instead of updating the now reordered list here, just write it down...
+    // This way, we can continue to hold the initialised list in p_dpb->listX_0
+    // and therefore not need to update it every slice
 
-	//h264_dpb_write_list(list_num, PicList, num_ref_idx_active);
+    //h264_dpb_write_list(list_num, PicList, num_ref_idx_active);
 
-	return num_ref_idx_active;
-} 
+    return num_ref_idx_active;
+}
 
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
-	
+
 
 void h264_dpb_RP_check_list (h264_Info * pInfo)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
-	 uint8_t    *p_list = pInfo->slice_ref_list0;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    uint8_t    *p_list = pInfo->slice_ref_list0;
 
-	//
-	// If the decoding start from RP and without exact point, all B frames belong to previous GOP should be throw away!
-	//
-	
-	if((pInfo->SliceHeader.slice_type == h264_PtypeB)&&(pInfo->sei_b_state_ready ==0) && pInfo->sei_rp_received) {
-		pInfo->wl_err_curr |= VIDDEC_FW_WORKLOAD_ERR_NOTDECODABLE;
-		pInfo->wl_err_curr |= (FRAME << FIELD_ERR_OFFSET); 				
-	}
+    //
+    // If the decoding start from RP and without exact point, all B frames belong to previous GOP should be throw away!
+    //
+
+    if ((pInfo->SliceHeader.slice_type == h264_PtypeB)&&(pInfo->sei_b_state_ready ==0) && pInfo->sei_rp_received) {
+        pInfo->wl_err_curr |= VIDDEC_FW_WORKLOAD_ERR_NOTDECODABLE;
+        pInfo->wl_err_curr |= (FRAME << FIELD_ERR_OFFSET);
+    }
 
 
-	//
-	// Repare Ref list if it damaged with RP recovery only
-	//
-	if((pInfo->SliceHeader.slice_type == h264_PtypeP) && pInfo->sei_rp_received)
-	{
+    //
+    // Repare Ref list if it damaged with RP recovery only
+    //
+    if ((pInfo->SliceHeader.slice_type == h264_PtypeP) && pInfo->sei_rp_received)
+    {
 
-		int32_t idx, rp_found = 0;
+        int32_t idx, rp_found = 0;
 
-		if( ((pInfo->SliceHeader.num_ref_idx_l0_active == 1)&&(pInfo->SliceHeader.structure == FRAME)) ||
-         ((pInfo->SliceHeader.num_ref_idx_l0_active == 2)&&(pInfo->SliceHeader.structure != FRAME)) )
-		{
-	         if(pInfo->SliceHeader.sh_refpic_l0.ref_pic_list_reordering_flag)
-	         {
-	            p_list = pInfo->slice_ref_list0;      
-	         }
-	         else
-	         {
-	            p_list = pInfo->dpb.listX_0;
-				//pInfo->sei_rp_received = 0;
-				//return;
-	         }				
-	
+        if ( ((pInfo->SliceHeader.num_ref_idx_l0_active == 1)&&(pInfo->SliceHeader.structure == FRAME)) ||
+                ((pInfo->SliceHeader.num_ref_idx_l0_active == 2)&&(pInfo->SliceHeader.structure != FRAME)) )
+        {
+            if (pInfo->SliceHeader.sh_refpic_l0.ref_pic_list_reordering_flag)
+            {
+                p_list = pInfo->slice_ref_list0;
+            }
+            else
+            {
+                p_list = pInfo->dpb.listX_0;
+                //pInfo->sei_rp_received = 0;
+                //return;
+            }
 
-			for(idx = 0; idx < p_dpb->used_size; idx++) {
-				if(p_dpb->fs_dpb_idc[idx] == pInfo->last_I_frame_idc) {
-					rp_found = 1;
-					break;
-				}
-			}
-			if(rp_found) {
-#if 0				
-				int32_t poc;
 
-				///// Clear long-term ref list
-				for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
-				{
-					h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_ltref_idc[0]);
-					h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[0]);
-				}	
+            for (idx = 0; idx < p_dpb->used_size; idx++) {
+                if (p_dpb->fs_dpb_idc[idx] == pInfo->last_I_frame_idc) {
+                    rp_found = 1;
+                    break;
+                }
+            }
+            if (rp_found) {
+#if 0
+                int32_t poc;
 
-				///// Clear short-term ref list
-				//while(p_dpb->used_size>1) 
-				for(idx = 0; idx < p_dpb->used_size; idx++)
-				{			
-					int32_t idx_pos;
-					//// find smallest non-output POC			
-					h264_dpb_get_smallest_poc(p_dpb, &poc, &idx_pos);	
-					
-					//// Remove all frames in previous GOP
-					if ((idx_pos != MPD_DPB_FS_NULL_IDC) && (p_dpb->fs_dpb_idc[idx_pos] != pInfo->last_I_frame_idc))
-					{							
-						// Remove from ref-list				
-						h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_dpb_idc[idx_pos]);
-						h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_dpb_idc[idx_pos]);
+                ///// Clear long-term ref list
+                for (idx = 0; idx < p_dpb->ltref_frames_in_buffer; idx++)
+                {
+                    h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_ltref_idc[0]);
+                    h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[0]);
+                }
 
-						// Output from DPB
-						//h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
-						//if((active_fs->is_output == 0) && (active_fs->is_non_existent == 0))
-						{
-							//int32_t existing;									
-							//h264_dpb_frame_output(pInfo, p_dpb->fs_dpb_idc[idx], 0, &existing);				
-							//p_dpb->last_output_poc = poc; 				
-						}
-						//h264_dpb_remove_frame_from_dpb(p_dpb, idx);		// Remove dpb.fs_dpb_idc[pos] 					
+                ///// Clear short-term ref list
+                //while(p_dpb->used_size>1)
+                for (idx = 0; idx < p_dpb->used_size; idx++)
+                {
+                    int32_t idx_pos;
+                    //// find smallest non-output POC
+                    h264_dpb_get_smallest_poc(p_dpb, &poc, &idx_pos);
 
-					} 
-				}
+                    //// Remove all frames in previous GOP
+                    if ((idx_pos != MPD_DPB_FS_NULL_IDC) && (p_dpb->fs_dpb_idc[idx_pos] != pInfo->last_I_frame_idc))
+                    {
+                        // Remove from ref-list
+                        h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_dpb_idc[idx_pos]);
+                        h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_dpb_idc[idx_pos]);
+
+                        // Output from DPB
+                        //h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
+                        //if((active_fs->is_output == 0) && (active_fs->is_non_existent == 0))
+                        {
+                            //int32_t existing;
+                            //h264_dpb_frame_output(pInfo, p_dpb->fs_dpb_idc[idx], 0, &existing);
+                            //p_dpb->last_output_poc = poc;
+                        }
+                        //h264_dpb_remove_frame_from_dpb(p_dpb, idx);		// Remove dpb.fs_dpb_idc[pos]
+
+                    }
+                }
 #endif
 
-				///// Set the reference to last I frame
-				if( (pInfo->last_I_frame_idc!=255)&&(pInfo->last_I_frame_idc!=p_list[0])) 
-				{
-					/// Repaire the reference list now						
-					h264_dpb_unmark_for_reference(p_dpb, p_list[0]);
-					h264_dpb_remove_ref_list(p_dpb, p_list[0]);
-					p_list[0] = pInfo->last_I_frame_idc;
-               if (pInfo->SliceHeader.structure != FRAME)
-                  p_list[1] = (pInfo->last_I_frame_idc ^ 0x20);
-				}
-			}
-		}
-		
-		pInfo->sei_rp_received = 0;
-		pInfo->sei_b_state_ready = 1;
+                ///// Set the reference to last I frame
+                if ( (pInfo->last_I_frame_idc!=255)&&(pInfo->last_I_frame_idc!=p_list[0]))
+                {
+                    /// Repaire the reference list now
+                    h264_dpb_unmark_for_reference(p_dpb, p_list[0]);
+                    h264_dpb_remove_ref_list(p_dpb, p_list[0]);
+                    p_list[0] = pInfo->last_I_frame_idc;
+                    if (pInfo->SliceHeader.structure != FRAME)
+                        p_list[1] = (pInfo->last_I_frame_idc ^ 0x20);
+                }
+            }
+        }
 
-	}
+        pInfo->sei_rp_received = 0;
+        pInfo->sei_b_state_ready = 1;
+
+    }
 
 
-	return;
+    return;
 }
 
 
@@ -1361,53 +1361,53 @@
 //
 // Used to sort a list based on a corresponding sort indices
 //
-  
+
 void h264_dpb_reorder_lists(h264_Info * pInfo)
 {
-	int32_t currSliceType = pInfo->SliceHeader.slice_type;
+    int32_t currSliceType = pInfo->SliceHeader.slice_type;
 
-	if (currSliceType == h264_PtypeP )				
-	{
-		/////////////////////////////////////////////// Reordering reference list for P slice
-		/// Forward reordering
-		if (pInfo->SliceHeader.sh_refpic_l0.ref_pic_list_reordering_flag)
-			h264_dpb_reorder_ref_pic_list(pInfo, 0, pInfo->SliceHeader.num_ref_idx_l0_active);
-		else
-		{
-			
-		}
-		pInfo->dpb.listXsize[0]=pInfo->SliceHeader.num_ref_idx_l0_active;
-	} else if (currSliceType == h264_PtypeB)		
-	{
-		/////////////////////////////////////////////// Reordering reference list for B slice
-		/// Forward reordering
-		if (pInfo->SliceHeader.sh_refpic_l0.ref_pic_list_reordering_flag)
-			h264_dpb_reorder_ref_pic_list(pInfo, 0, pInfo->SliceHeader.num_ref_idx_l0_active);
-		else
-		{
-  			
-		}
-		pInfo->dpb.listXsize[0]=pInfo->SliceHeader.num_ref_idx_l0_active;
+    if (currSliceType == h264_PtypeP )
+    {
+        /////////////////////////////////////////////// Reordering reference list for P slice
+        /// Forward reordering
+        if (pInfo->SliceHeader.sh_refpic_l0.ref_pic_list_reordering_flag)
+            h264_dpb_reorder_ref_pic_list(pInfo, 0, pInfo->SliceHeader.num_ref_idx_l0_active);
+        else
+        {
 
-		/// Backward reordering
-		if (pInfo->SliceHeader.sh_refpic_l1.ref_pic_list_reordering_flag)
-		  h264_dpb_reorder_ref_pic_list(pInfo, 1, pInfo->SliceHeader.num_ref_idx_l1_active);
-		else
-		{
-  			
-		}
-		pInfo->dpb.listXsize[1]=pInfo->SliceHeader.num_ref_idx_l1_active;
-	}
+        }
+        pInfo->dpb.listXsize[0]=pInfo->SliceHeader.num_ref_idx_l0_active;
+    } else if (currSliceType == h264_PtypeB)
+    {
+        /////////////////////////////////////////////// Reordering reference list for B slice
+        /// Forward reordering
+        if (pInfo->SliceHeader.sh_refpic_l0.ref_pic_list_reordering_flag)
+            h264_dpb_reorder_ref_pic_list(pInfo, 0, pInfo->SliceHeader.num_ref_idx_l0_active);
+        else
+        {
 
-	//// Check if need recover reference list with previous recovery point
-	if(!pInfo->img.second_field)
-   {  
-	   h264_dpb_RP_check_list(pInfo);
-   }
+        }
+        pInfo->dpb.listXsize[0]=pInfo->SliceHeader.num_ref_idx_l0_active;
+
+        /// Backward reordering
+        if (pInfo->SliceHeader.sh_refpic_l1.ref_pic_list_reordering_flag)
+            h264_dpb_reorder_ref_pic_list(pInfo, 1, pInfo->SliceHeader.num_ref_idx_l1_active);
+        else
+        {
+
+        }
+        pInfo->dpb.listXsize[1]=pInfo->SliceHeader.num_ref_idx_l1_active;
+    }
+
+    //// Check if need recover reference list with previous recovery point
+    if (!pInfo->img.second_field)
+    {
+        h264_dpb_RP_check_list(pInfo);
+    }
 
 
-	return;
-}  
+    return;
+}
 
 ////////////////////////////////////////// DPB management //////////////////////
 
@@ -1418,21 +1418,21 @@
 //
 static int32_t avc_dpb_get_non_output_frame_number(h264_Info * pInfo)
 {
-   int32_t idx; 
-   int32_t number=0;
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    int32_t idx;
+    int32_t number=0;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-   for (idx = 0; idx < p_dpb->used_size; idx++)
-   {
-      h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
-   
-      if (viddec_h264_get_is_output(active_fs) == 0) 
-      {
-         (number)++;   
-      }
-   }
+    for (idx = 0; idx < p_dpb->used_size; idx++)
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
 
-	return number;
+        if (viddec_h264_get_is_output(active_fs) == 0)
+        {
+            (number)++;
+        }
+    }
+
+    return number;
 }
 
 
@@ -1443,221 +1443,224 @@
 
 void h264_dpb_store_previous_picture_in_dpb(h264_Info * pInfo,int32_t NonExisting, int32_t use_old)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	int32_t used_for_reference;
-	int32_t is_direct_output;
-	int32_t second_field_stored = 0;
-	int32_t poc;
-	int32_t pos;
-	int32_t flag;
-	int32_t first_field_non_ref = 0;
-	int32_t idr_flag;
+    int32_t used_for_reference;
+    int32_t is_direct_output;
+    int32_t second_field_stored = 0;
+    int32_t poc;
+    int32_t pos;
+    int32_t flag;
+    int32_t first_field_non_ref = 0;
+    int32_t idr_flag;
 
-	if(NonExisting) {
-		if(p_dpb->fs_non_exist_idc == MPD_DPB_FS_NULL_IDC) 
-			return;
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_non_exist_idc);
-	} else {
-		if(p_dpb->fs_dec_idc == MPD_DPB_FS_NULL_IDC) 
-			return;
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
-	}
+    if (NonExisting) {
+        if (p_dpb->fs_non_exist_idc == MPD_DPB_FS_NULL_IDC)
+            return;
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_non_exist_idc);
+    } else {
+        if (p_dpb->fs_dec_idc == MPD_DPB_FS_NULL_IDC)
+            return;
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+    }
 
-	if(NonExisting == 0)
-	{
-		//active_fs->sps_disp_index = (next_sps_disp_entry == 0)? 7 : next_sps_disp_entry - 1;
-		pInfo->img.last_has_mmco_5       = 0;
-		pInfo->img.last_pic_bottom_field = pInfo->img.bottom_field_flag;
+    if (NonExisting == 0)
+    {
+        //active_fs->sps_disp_index = (next_sps_disp_entry == 0)? 7 : next_sps_disp_entry - 1;
+        pInfo->img.last_has_mmco_5       = 0;
+        pInfo->img.last_pic_bottom_field = pInfo->img.bottom_field_flag;
 
-		//used_for_reference = (use_old) ? !(old_pInfo->img.old_disposable_flag) : !(pInfo->img.disposable_flag);
-		used_for_reference = (use_old) ? !(pInfo->old_slice.nal_ref_idc==0) : !(pInfo->SliceHeader.nal_ref_idc==0);
+        //used_for_reference = (use_old) ? !(old_pInfo->img.old_disposable_flag) : !(pInfo->img.disposable_flag);
+        used_for_reference = (use_old) ? !(pInfo->old_slice.nal_ref_idc==0) : !(pInfo->SliceHeader.nal_ref_idc==0);
 
-		switch (viddec_h264_get_dec_structure(active_fs))
-		{
-		case(TOP_FIELD)   : {
-				active_fs->top_field.used_for_reference = used_for_reference;
-				viddec_h264_set_is_top_used(active_fs, 1);
-				//active_fs->crc_field_coded     = 1;
-			}break;
-		case(BOTTOM_FIELD): {
-				active_fs->bottom_field.used_for_reference = used_for_reference << 1;
-				viddec_h264_set_is_bottom_used(active_fs, 1);
-				//active_fs->crc_field_coded     = 1;
-			}break;
-		default: {
-			active_fs->frame.used_for_reference = used_for_reference?3:0;
-				viddec_h264_set_is_frame_used(active_fs, 3);
-				//if(pInfo->img.MbaffFrameFlag) active_fs->crc_field_coded  = 1;
+        switch (viddec_h264_get_dec_structure(active_fs))
+        {
+        case(TOP_FIELD)   : {
+            active_fs->top_field.used_for_reference = used_for_reference;
+            viddec_h264_set_is_top_used(active_fs, 1);
+            //active_fs->crc_field_coded     = 1;
+        }
+        break;
+        case(BOTTOM_FIELD): {
+            active_fs->bottom_field.used_for_reference = used_for_reference << 1;
+            viddec_h264_set_is_bottom_used(active_fs, 1);
+            //active_fs->crc_field_coded     = 1;
+        }
+        break;
+        default: {
+            active_fs->frame.used_for_reference = used_for_reference?3:0;
+            viddec_h264_set_is_frame_used(active_fs, 3);
+            //if(pInfo->img.MbaffFrameFlag) active_fs->crc_field_coded  = 1;
 
-			}break;
-		}
+        }
+        break;
+        }
 
-		//freeze_assert = use_old ? old_pInfo->img.sei_freeze_this_image : pInfo->img.sei_freeze_this_image;
-		//if (freeze_assert)  sei_information.disp_frozen = 1;
+        //freeze_assert = use_old ? old_pInfo->img.sei_freeze_this_image : pInfo->img.sei_freeze_this_image;
+        //if (freeze_assert)  sei_information.disp_frozen = 1;
 
-		idr_flag = use_old ? pInfo->old_slice.idr_flag : pInfo->SliceHeader.idr_flag;
-		if (idr_flag) {
-			h264_dpb_idr_memory_management (pInfo, &pInfo->active_SPS, pInfo->img.no_output_of_prior_pics_flag);
-		} else {
-		  // adaptive memory management			
-			if (used_for_reference & pInfo->SliceHeader.sh_dec_refpic.adaptive_ref_pic_marking_mode_flag) {
-				h264_dpb_adaptive_memory_management(pInfo);
-			}
-		}
-		// Reset the active frame store - could have changed in mem management ftns
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+        idr_flag = use_old ? pInfo->old_slice.idr_flag : pInfo->SliceHeader.idr_flag;
+        if (idr_flag) {
+            h264_dpb_idr_memory_management (pInfo, &pInfo->active_SPS, pInfo->img.no_output_of_prior_pics_flag);
+        } else {
+            // adaptive memory management
+            if (used_for_reference & pInfo->SliceHeader.sh_dec_refpic.adaptive_ref_pic_marking_mode_flag) {
+                h264_dpb_adaptive_memory_management(pInfo);
+            }
+        }
+        // Reset the active frame store - could have changed in mem management ftns
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
 
-		if ((viddec_h264_get_dec_structure(active_fs) == TOP_FIELD)||(viddec_h264_get_dec_structure(active_fs) == BOTTOM_FIELD))
-		{
-		  // check for frame store with same pic_number -- always true in my case, YH
-		  // when we allocate frame store for the second field, we make sure the frame store for the second 
-		  // field is the one that contains the first field of the frame- see h264_dpb_init_frame_store()
-		  // This is different from JM model. 
-		  // In this way we don't need to move image data around and can reduce memory bandwidth.   
-		  // simply check if the check if the other field has been decoded or not
-		  
-		  if (viddec_h264_get_is_used(active_fs) != 0)
-		  {
-			if(pInfo->img.second_field)
-			{
-			  h264_dpb_insert_picture_in_dpb(pInfo, used_for_reference, 0, NonExisting, use_old);
-			  second_field_stored = 1;
-			}
-		  }
-		}   
-	}
-	else
-	{ // Set up locals for non-existing frames
-		used_for_reference = 1;
-		
-		active_fs->frame.used_for_reference = used_for_reference?3:0;
-		viddec_h264_set_is_frame_used(active_fs, 3);
-		viddec_h264_set_dec_structure(active_fs, FRAME);		
-		pInfo->img.structure = FRAME;
-	}
+        if ((viddec_h264_get_dec_structure(active_fs) == TOP_FIELD)||(viddec_h264_get_dec_structure(active_fs) == BOTTOM_FIELD))
+        {
+            // check for frame store with same pic_number -- always true in my case, YH
+            // when we allocate frame store for the second field, we make sure the frame store for the second
+            // field is the one that contains the first field of the frame- see h264_dpb_init_frame_store()
+            // This is different from JM model.
+            // In this way we don't need to move image data around and can reduce memory bandwidth.
+            // simply check if the check if the other field has been decoded or not
 
-	is_direct_output = 0;
-	if (NonExisting == 0)
-	{
-		if(p_dpb->used_size >= p_dpb->BumpLevel) 
-		{
-		  // non-reference frames may be output directly
-		  h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
-		    
-		  if ((used_for_reference == 0) && (viddec_h264_get_is_used(active_fs) == 3))
-		  {
-			h264_dpb_get_smallest_poc (p_dpb, &poc, &pos);
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
-			if ((pos == MPD_DPB_FS_NULL_IDC) || (pInfo->img.ThisPOC < poc))
-			{
-			  is_direct_output = 1;
-			}
-		  }
-		}
-	}
+            if (viddec_h264_get_is_used(active_fs) != 0)
+            {
+                if (pInfo->img.second_field)
+                {
+                    h264_dpb_insert_picture_in_dpb(pInfo, used_for_reference, 0, NonExisting, use_old);
+                    second_field_stored = 1;
+                }
+            }
+        }
+    }
+    else
+    { // Set up locals for non-existing frames
+        used_for_reference = 1;
 
-	if (NonExisting) {
-		h264_dpb_sliding_window_memory_management(p_dpb, NonExisting, pInfo->active_SPS.num_ref_frames);
-	} else if(pInfo->SliceHeader.idr_flag == 0) {
-		if(used_for_reference){
-			if(pInfo->img.second_field == 0) {
-				if (pInfo->SliceHeader.sh_dec_refpic.adaptive_ref_pic_marking_mode_flag == 0) {
-					h264_dpb_sliding_window_memory_management(p_dpb, NonExisting, pInfo->active_SPS.num_ref_frames);
-				}
-			}
-		}
-	}
+        active_fs->frame.used_for_reference = used_for_reference?3:0;
+        viddec_h264_set_is_frame_used(active_fs, 3);
+        viddec_h264_set_dec_structure(active_fs, FRAME);
+        pInfo->img.structure = FRAME;
+    }
 
-	h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
+    is_direct_output = 0;
+    if (NonExisting == 0)
+    {
+        if (p_dpb->used_size >= p_dpb->BumpLevel)
+        {
+            // non-reference frames may be output directly
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
 
-	//if (is_direct_output == 0)
-	{
-		if ((pInfo->img.second_field == 0) || (NonExisting))
-		{
-		  h264_dpb_insert_picture_in_dpb(pInfo, used_for_reference, 1, NonExisting, use_old); 
-		}
+            if ((used_for_reference == 0) && (viddec_h264_get_is_used(active_fs) == 3))
+            {
+                h264_dpb_get_smallest_poc (p_dpb, &poc, &pos);
+                h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+                if ((pos == MPD_DPB_FS_NULL_IDC) || (pInfo->img.ThisPOC < poc))
+                {
+                    is_direct_output = 1;
+                }
+            }
+        }
+    }
 
-		// In an errored stream we saw a condition where 
-		// p_dpb->ref_frames_in_buffer + p_dpb->ltref_frames_in_buffer > p_dpb->BumpLevel,
-		// which in itself is an error, but this means first_field_non_ref will
-		// not get set and causes problems for h264_dpb_queue_update()
-		if((pInfo->img.structure != FRAME) && (pInfo->img.second_field == 0)) {
-		  if(used_for_reference ==	0)
-			if(p_dpb->ref_frames_in_buffer + p_dpb->ltref_frames_in_buffer == p_dpb->BumpLevel)
-			  first_field_non_ref = 1;
-		}
+    if (NonExisting) {
+        h264_dpb_sliding_window_memory_management(p_dpb, NonExisting, pInfo->active_SPS.num_ref_frames);
+    } else if (pInfo->SliceHeader.idr_flag == 0) {
+        if (used_for_reference) {
+            if (pInfo->img.second_field == 0) {
+                if (pInfo->SliceHeader.sh_dec_refpic.adaptive_ref_pic_marking_mode_flag == 0) {
+                    h264_dpb_sliding_window_memory_management(p_dpb, NonExisting, pInfo->active_SPS.num_ref_frames);
+                }
+            }
+        }
+    }
 
-	}
+    h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
 
-	if(NonExisting) 
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_non_exist_idc);
-	else
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+    //if (is_direct_output == 0)
+    {
+        if ((pInfo->img.second_field == 0) || (NonExisting))
+        {
+            h264_dpb_insert_picture_in_dpb(pInfo, used_for_reference, 1, NonExisting, use_old);
+        }
 
-	if(NonExisting == 0)
-	{
-		if((pInfo->img.second_field == 1) || (pInfo->img.structure == FRAME))
-		{
-			//h264_send_new_decoded_frame();
-			if((p_dpb->OutputCtrl) && (is_direct_output == 0)) 
-				h264_dpb_output_one_frame_from_dpb(pInfo, 0, 0,pInfo->active_SPS.num_ref_frames); 
+        // In an errored stream we saw a condition where
+        // p_dpb->ref_frames_in_buffer + p_dpb->ltref_frames_in_buffer > p_dpb->BumpLevel,
+        // which in itself is an error, but this means first_field_non_ref will
+        // not get set and causes problems for h264_dpb_queue_update()
+        if ((pInfo->img.structure != FRAME) && (pInfo->img.second_field == 0)) {
+            if (used_for_reference ==	0)
+                if (p_dpb->ref_frames_in_buffer + p_dpb->ltref_frames_in_buffer == p_dpb->BumpLevel)
+                    first_field_non_ref = 1;
+        }
 
-			// Pictures inserted by this point - check if we have reached the specified output 
-			// level (if one has been specified) so we can begin on next call
+    }
 
-			/* 
-			Fixed HSD 212625---------------should compare OutputLevel with non-output frame number in dpb, not the used number in dpb
-			if((p_dpb->OutputLevelValid)&&(p_dpb->OutputCtrl == 0))
-			{
-				if(p_dpb->used_size == p_dpb->OutputLevel)  
-				p_dpb->OutputCtrl = 1;
-			}
-			*/
+    if (NonExisting)
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_non_exist_idc);
+    else
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
 
-			if(p_dpb->OutputLevelValid)
-			{
-				 int32_t non_output_frame_number=0;
-				 non_output_frame_number = avc_dpb_get_non_output_frame_number(pInfo);
-			
-				 if(non_output_frame_number == p_dpb->OutputLevel)  
-					 p_dpb->OutputCtrl = 1;
-				 else
-					 p_dpb->OutputCtrl = 0;
-			}
-			else {
-				 p_dpb->OutputCtrl = 0;  
-			}
-		}
-	}
+    if (NonExisting == 0)
+    {
+        if ((pInfo->img.second_field == 1) || (pInfo->img.structure == FRAME))
+        {
+            //h264_send_new_decoded_frame();
+            if ((p_dpb->OutputCtrl) && (is_direct_output == 0))
+                h264_dpb_output_one_frame_from_dpb(pInfo, 0, 0,pInfo->active_SPS.num_ref_frames);
 
-	while(p_dpb->used_size > (p_dpb->BumpLevel + first_field_non_ref)) 
-	//while(p_dpb->used_size > p_dpb->BumpLevel) 
-	{
-		h264_dpb_queue_update(pInfo, 1, 0, 0,pInfo->active_SPS.num_ref_frames); // flush a frame
-		//h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
-	}
+            // Pictures inserted by this point - check if we have reached the specified output
+            // level (if one has been specified) so we can begin on next call
 
-	//
-	// Do not output "direct output" pictures until the sempahore has been set that the pic is 
-	// decoded!!
-	//
-	if(is_direct_output) {  
-		h264_dpb_queue_update(pInfo, 1, 1, 0,pInfo->active_SPS.num_ref_frames);
-		//h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
-	}
+            /*
+            Fixed HSD 212625---------------should compare OutputLevel with non-output frame number in dpb, not the used number in dpb
+            if((p_dpb->OutputLevelValid)&&(p_dpb->OutputCtrl == 0))
+            {
+            	if(p_dpb->used_size == p_dpb->OutputLevel)
+            	p_dpb->OutputCtrl = 1;
+            }
+            */
 
-	//
-	// Add reference pictures into Reference list 
-	//
-	if(used_for_reference) {
-		h264_dpb_insert_ref_lists(&pInfo->dpb, NonExisting);
-	}
+            if (p_dpb->OutputLevelValid)
+            {
+                int32_t non_output_frame_number=0;
+                non_output_frame_number = avc_dpb_get_non_output_frame_number(pInfo);
 
-	h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
+                if (non_output_frame_number == p_dpb->OutputLevel)
+                    p_dpb->OutputCtrl = 1;
+                else
+                    p_dpb->OutputCtrl = 0;
+            }
+            else {
+                p_dpb->OutputCtrl = 0;
+            }
+        }
+    }
+
+    while (p_dpb->used_size > (p_dpb->BumpLevel + first_field_non_ref))
+        //while(p_dpb->used_size > p_dpb->BumpLevel)
+    {
+        h264_dpb_queue_update(pInfo, 1, 0, 0,pInfo->active_SPS.num_ref_frames); // flush a frame
+        //h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
+    }
+
+    //
+    // Do not output "direct output" pictures until the sempahore has been set that the pic is
+    // decoded!!
+    //
+    if (is_direct_output) {
+        h264_dpb_queue_update(pInfo, 1, 1, 0,pInfo->active_SPS.num_ref_frames);
+        //h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
+    }
+
+    //
+    // Add reference pictures into Reference list
+    //
+    if (used_for_reference) {
+        h264_dpb_insert_ref_lists(&pInfo->dpb, NonExisting);
+    }
+
+    h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
 
 
-	return;
+    return;
 } ////////////// End of DPB store pic
 
 
@@ -1681,93 +1684,96 @@
 
 void h264_dpb_insert_picture_in_dpb(h264_Info * pInfo,int32_t used_for_reference, int32_t add2dpb, int32_t NonExisting, int32_t use_old)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	if(NonExisting == 0) {	
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
-		active_fs->frame_num = (use_old) ? pInfo->old_slice.frame_num : pInfo->SliceHeader.frame_num;
-	}
-	else {
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_non_exist_idc);
-		active_fs->frame_num = active_fs->frame.pic_num;
-	}
+    if (NonExisting == 0) {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+        active_fs->frame_num = (use_old) ? pInfo->old_slice.frame_num : pInfo->SliceHeader.frame_num;
+    }
+    else {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_non_exist_idc);
+        active_fs->frame_num = active_fs->frame.pic_num;
+    }
 
-	if (add2dpb) {
-		p_dpb->fs_dpb_idc[p_dpb->used_size] = active_fs->fs_idc;  
-		p_dpb->used_size++;
-	}
+    if (add2dpb) {
+        p_dpb->fs_dpb_idc[p_dpb->used_size] = active_fs->fs_idc;
+        p_dpb->used_size++;
+    }
 
 
-	switch (viddec_h264_get_dec_structure(active_fs))
-	{
-	case FRAME :{
-		 viddec_h264_set_is_frame_used(active_fs, 3);
-		 active_fs->frame.used_for_reference = used_for_reference?3:0;
-		 if (used_for_reference)
-		 {
-		   active_fs->frame.used_for_reference = 3;
-		   if (active_fs->frame.is_long_term) 
-			   viddec_h264_set_is_frame_long_term(active_fs, 3);
-		 }
-		 // Split frame to 2 fields for prediction
-		 h264_dpb_split_field(pInfo);
+    switch (viddec_h264_get_dec_structure(active_fs))
+    {
+    case FRAME : {
+        viddec_h264_set_is_frame_used(active_fs, 3);
+        active_fs->frame.used_for_reference = used_for_reference?3:0;
+        if (used_for_reference)
+        {
+            active_fs->frame.used_for_reference = 3;
+            if (active_fs->frame.is_long_term)
+                viddec_h264_set_is_frame_long_term(active_fs, 3);
+        }
+        // Split frame to 2 fields for prediction
+        h264_dpb_split_field(pInfo);
 
-		}break;
-	case TOP_FIELD :{
-		viddec_h264_set_is_top_used(active_fs, 1);
+    }
+    break;
+    case TOP_FIELD : {
+        viddec_h264_set_is_top_used(active_fs, 1);
 
-		active_fs->top_field.used_for_reference = used_for_reference;
-		if (used_for_reference)
-		{
-			active_fs->frame.used_for_reference |= 0x1;
-			if (active_fs->top_field.is_long_term)
-			{
-			 viddec_h264_set_is_top_long_term(active_fs, 1);
-			 active_fs->long_term_frame_idx = active_fs->top_field.long_term_frame_idx;
-			}
-		}
-		if (viddec_h264_get_is_used(active_fs) == 3) {
-			h264_dpb_combine_field(use_old); // generate frame view
-		}
-		else
-		{
-			active_fs->frame.poc      = active_fs->top_field.poc;
-		}
+        active_fs->top_field.used_for_reference = used_for_reference;
+        if (used_for_reference)
+        {
+            active_fs->frame.used_for_reference |= 0x1;
+            if (active_fs->top_field.is_long_term)
+            {
+                viddec_h264_set_is_top_long_term(active_fs, 1);
+                active_fs->long_term_frame_idx = active_fs->top_field.long_term_frame_idx;
+            }
+        }
+        if (viddec_h264_get_is_used(active_fs) == 3) {
+            h264_dpb_combine_field(use_old); // generate frame view
+        }
+        else
+        {
+            active_fs->frame.poc      = active_fs->top_field.poc;
+        }
 
-		}break;
-	case BOTTOM_FIELD :{
-		 viddec_h264_set_is_bottom_used(active_fs, 1);
+    }
+    break;
+    case BOTTOM_FIELD : {
+        viddec_h264_set_is_bottom_used(active_fs, 1);
 
-		 active_fs->bottom_field.used_for_reference = (used_for_reference<<1);
-		 if (used_for_reference)
-		 {
-		   active_fs->frame.used_for_reference |= 0x2; 
-		   if (active_fs->bottom_field.is_long_term)
-		   {
-			 viddec_h264_set_is_bottom_long_term(active_fs, 1); 
-			 active_fs->long_term_frame_idx = active_fs->bottom_field.long_term_frame_idx;
-		   }
-		 }
-		 if (viddec_h264_get_is_used(active_fs) == 3) {
-			 h264_dpb_combine_field(use_old); // generate frame view
-		 }
-		 else 
-		 {
-		   active_fs->frame.poc = active_fs->bottom_field.poc;
-		 }
+        active_fs->bottom_field.used_for_reference = (used_for_reference<<1);
+        if (used_for_reference)
+        {
+            active_fs->frame.used_for_reference |= 0x2;
+            if (active_fs->bottom_field.is_long_term)
+            {
+                viddec_h264_set_is_bottom_long_term(active_fs, 1);
+                active_fs->long_term_frame_idx = active_fs->bottom_field.long_term_frame_idx;
+            }
+        }
+        if (viddec_h264_get_is_used(active_fs) == 3) {
+            h264_dpb_combine_field(use_old); // generate frame view
+        }
+        else
+        {
+            active_fs->frame.poc = active_fs->bottom_field.poc;
+        }
 
-		}break;
-	}
-/*
-	if ( gRestartMode.LastRestartType  == RESTART_SEI )
-	{
-		if ( active_fs->open_gop_entry ) dpb.WaitSeiRecovery = 1;
-	}
+    }
+    break;
+    }
+    /*
+    	if ( gRestartMode.LastRestartType  == RESTART_SEI )
+    	{
+    		if ( active_fs->open_gop_entry ) dpb.WaitSeiRecovery = 1;
+    	}
 
-	gRestartMode.LastRestartType = 0xFFFF;
-*/
+    	gRestartMode.LastRestartType = 0xFFFF;
+    */
 
-	return;
+    return;
 } ////// End of insert picture in DPB
 
 /* ------------------------------------------------------------------------------------------ */
@@ -1781,80 +1787,80 @@
 
 void h264_dpb_mm_unmark_short_term_for_reference(h264_Info * pInfo, int32_t difference_of_pic_nums_minus1)
 {
-	int32_t picNumX;
-	int32_t currPicNum;
-	uint32_t idx;
-	int32_t unmark_done;
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    int32_t picNumX;
+    int32_t currPicNum;
+    uint32_t idx;
+    int32_t unmark_done;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	if (pInfo->img.structure == FRAME) 
-		currPicNum = pInfo->img.frame_num;
-	else
-		currPicNum = (pInfo->img.frame_num << 1) + 1;
+    if (pInfo->img.structure == FRAME)
+        currPicNum = pInfo->img.frame_num;
+    else
+        currPicNum = (pInfo->img.frame_num << 1) + 1;
 
-	picNumX = currPicNum - (difference_of_pic_nums_minus1 + 1);
+    picNumX = currPicNum - (difference_of_pic_nums_minus1 + 1);
 
-	unmark_done = 0;
+    unmark_done = 0;
 
-	for (idx =0; (idx < p_dpb->ref_frames_in_buffer) && (!(unmark_done)); idx++)
-	{
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
+    for (idx =0; (idx < p_dpb->ref_frames_in_buffer) && (!(unmark_done)); idx++)
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
 
-		if (pInfo->img.structure == FRAME)
-		{    	
-		  /* If all pic numbers in the list are different (and they should be)
-			 we should terminate the for loop the moment we match pic numbers, 
-			 no need to continue to check - hence set unmark_done
-		  */
+        if (pInfo->img.structure == FRAME)
+        {
+            /* If all pic numbers in the list are different (and they should be)
+               we should terminate the for loop the moment we match pic numbers,
+               no need to continue to check - hence set unmark_done
+            */
 
-		  if ((active_fs->frame.used_for_reference == 3) && (viddec_h264_get_is_long_term(active_fs) == 0) &&
-			  (active_fs->frame.pic_num == picNumX))
-		  {
-			h264_dpb_unmark_for_reference(p_dpb, active_fs->fs_idc);
-			h264_dpb_remove_ref_list(p_dpb, active_fs->fs_idc);
-			unmark_done = 1;
-		  }
-		}
-		else
-		{
-		  /* 
-			 If we wish to unmark a short-term picture by picture number when the current picture
-			 is a field, we have to unmark the corresponding field as unused for reference,
-			 and also if it was part of a frame or complementary reference field pair, the
-			 frame is to be marked as unused. However the opposite field may still be used as a
-			 reference for future fields
+            if ((active_fs->frame.used_for_reference == 3) && (viddec_h264_get_is_long_term(active_fs) == 0) &&
+                    (active_fs->frame.pic_num == picNumX))
+            {
+                h264_dpb_unmark_for_reference(p_dpb, active_fs->fs_idc);
+                h264_dpb_remove_ref_list(p_dpb, active_fs->fs_idc);
+                unmark_done = 1;
+            }
+        }
+        else
+        {
+            /*
+               If we wish to unmark a short-term picture by picture number when the current picture
+               is a field, we have to unmark the corresponding field as unused for reference,
+               and also if it was part of a frame or complementary reference field pair, the
+               frame is to be marked as unused. However the opposite field may still be used as a
+               reference for future fields
 
-			 How will this affect the reference list update ftn coming after??
+               How will this affect the reference list update ftn coming after??
 
-		  */
-		  if ((active_fs->frame.used_for_reference&0x1) && (!(viddec_h264_get_is_long_term(active_fs)&0x01))&&
-			  (active_fs->top_field.pic_num == picNumX) )
-		  {
-			active_fs->top_field.used_for_reference = 0;
-			active_fs->frame.used_for_reference &= 2;
+            */
+            if ((active_fs->frame.used_for_reference&0x1) && (!(viddec_h264_get_is_long_term(active_fs)&0x01))&&
+                    (active_fs->top_field.pic_num == picNumX) )
+            {
+                active_fs->top_field.used_for_reference = 0;
+                active_fs->frame.used_for_reference &= 2;
 
-			unmark_done = 1;
+                unmark_done = 1;
 
-			//Check if other field is used for short-term reference, if not remove from list...
-			if(active_fs->bottom_field.used_for_reference == 0) 
-				h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[idx]);
-		  }
-		  if ((active_fs->frame.used_for_reference&0x2) && (!(viddec_h264_get_is_long_term(active_fs)&0x2)) &&
-			  (active_fs->bottom_field.pic_num == picNumX) )
-		  {
-			active_fs->bottom_field.used_for_reference = 0;
-			active_fs->frame.used_for_reference &= 1;
+                //Check if other field is used for short-term reference, if not remove from list...
+                if (active_fs->bottom_field.used_for_reference == 0)
+                    h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[idx]);
+            }
+            if ((active_fs->frame.used_for_reference&0x2) && (!(viddec_h264_get_is_long_term(active_fs)&0x2)) &&
+                    (active_fs->bottom_field.pic_num == picNumX) )
+            {
+                active_fs->bottom_field.used_for_reference = 0;
+                active_fs->frame.used_for_reference &= 1;
 
-			unmark_done = 1;
+                unmark_done = 1;
 
-			//Check if other field is used for reference, if not remove from list...
-			if(active_fs->top_field.used_for_reference == 0) 
-				h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[idx]);
-		  }
-		}
-	}
+                //Check if other field is used for reference, if not remove from list...
+                if (active_fs->top_field.used_for_reference == 0)
+                    h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[idx]);
+            }
+        }
+    }
 
-	return;
+    return;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -1868,72 +1874,72 @@
 // In a frame situation the long_term_pic_num will refer to another frame.
 // Thus we can call h264_dpb_unmark_for_long_term_reference() and then remove the picture
 // from the list
-// 
+//
 // If the current picture is a field, long_term_pic_num will refer to another field
 // It is also the case that each individual field should have a unique picture number
-// 8.2.5.4.2 suggests that when curr pic is a field, an mmco == 2 operation 
+// 8.2.5.4.2 suggests that when curr pic is a field, an mmco == 2 operation
 // should be accompanied by a second op to unmark the other field as being unused
 ///////////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_mm_unmark_long_term_for_reference (h264_Info * pInfo, int32_t long_term_pic_num)
 {
-	uint32_t idx;
-	int32_t unmark_done;
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    uint32_t idx;
+    int32_t unmark_done;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	unmark_done = 0;
-	for (idx = 0; (idx < p_dpb->ltref_frames_in_buffer) && (!(unmark_done)); idx++)
-	{
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
+    unmark_done = 0;
+    for (idx = 0; (idx < p_dpb->ltref_frames_in_buffer) && (!(unmark_done)); idx++)
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
 
-		if (pInfo->img.structure == FRAME)
-		{
-		  if ((active_fs->frame.used_for_reference==3) && (viddec_h264_get_is_long_term(active_fs)==3) &&
-			  (active_fs->frame.long_term_pic_num == long_term_pic_num))
-		  {
-			h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[idx]);
-			h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx]);
-			unmark_done = 1;
-		  }
-		}
-		else
-		{
-			/// Check top field
-			if ((active_fs->frame.used_for_reference&0x1) && (viddec_h264_get_is_long_term(active_fs)&0x1) &&
-			  (active_fs->top_field.long_term_pic_num == long_term_pic_num) )
-			{
-				active_fs->top_field.used_for_reference = 0;
-				active_fs->top_field.is_long_term = 0;
-				active_fs->frame.used_for_reference &= 2;
-				viddec_h264_set_is_frame_long_term(active_fs, 2);
+        if (pInfo->img.structure == FRAME)
+        {
+            if ((active_fs->frame.used_for_reference==3) && (viddec_h264_get_is_long_term(active_fs)==3) &&
+                    (active_fs->frame.long_term_pic_num == long_term_pic_num))
+            {
+                h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[idx]);
+                h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx]);
+                unmark_done = 1;
+            }
+        }
+        else
+        {
+            /// Check top field
+            if ((active_fs->frame.used_for_reference&0x1) && (viddec_h264_get_is_long_term(active_fs)&0x1) &&
+                    (active_fs->top_field.long_term_pic_num == long_term_pic_num) )
+            {
+                active_fs->top_field.used_for_reference = 0;
+                active_fs->top_field.is_long_term = 0;
+                active_fs->frame.used_for_reference &= 2;
+                viddec_h264_set_is_frame_long_term(active_fs, 2);
 
-				unmark_done = 1;
+                unmark_done = 1;
 
-				//Check if other field is used for long term reference, if not remove from list...
-				if ((active_fs->bottom_field.used_for_reference == 0) || (active_fs->bottom_field.is_long_term == 0))
-					 h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx]);
-			}
+                //Check if other field is used for long term reference, if not remove from list...
+                if ((active_fs->bottom_field.used_for_reference == 0) || (active_fs->bottom_field.is_long_term == 0))
+                    h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx]);
+            }
 
-			/// Check Bottom field
-			if ((active_fs->frame.used_for_reference&0x2) && (viddec_h264_get_is_long_term(active_fs)&0x2) &&
-			  (active_fs->bottom_field.long_term_pic_num == long_term_pic_num) )
-			{
-				active_fs->bottom_field.used_for_reference = 0;
-				active_fs->bottom_field.is_long_term = 0;
-				active_fs->frame.used_for_reference &= 1;
-				viddec_h264_set_is_frame_long_term(active_fs, 1);
+            /// Check Bottom field
+            if ((active_fs->frame.used_for_reference&0x2) && (viddec_h264_get_is_long_term(active_fs)&0x2) &&
+                    (active_fs->bottom_field.long_term_pic_num == long_term_pic_num) )
+            {
+                active_fs->bottom_field.used_for_reference = 0;
+                active_fs->bottom_field.is_long_term = 0;
+                active_fs->frame.used_for_reference &= 1;
+                viddec_h264_set_is_frame_long_term(active_fs, 1);
 
-				unmark_done = 1;
-				//Check if other field is used for long term reference, if not remove from list...
-				if ((active_fs->top_field.used_for_reference == 0) || (active_fs->top_field.is_long_term == 0))
-				{
-				  h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx]);			
-				}
-			}
-		} // field structure
-	} //for(idx)
+                unmark_done = 1;
+                //Check if other field is used for long term reference, if not remove from list...
+                if ((active_fs->top_field.used_for_reference == 0) || (active_fs->top_field.is_long_term == 0))
+                {
+                    h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx]);
+                }
+            }
+        } // field structure
+    } //for(idx)
 
-	return;
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -1947,31 +1953,31 @@
 
 int32_t h264_dpb_get_pic_struct_by_pic_num(h264_DecodedPictureBuffer *p_dpb, int32_t picNumX)
 {
-	uint32_t idx;
-	int32_t pic_struct = INVALID;
-	int32_t found = 0;
+    uint32_t idx;
+    int32_t pic_struct = INVALID;
+    int32_t found = 0;
 
-	for (idx =0; (idx < p_dpb->ref_frames_in_buffer) && (!(found)); idx++)
-	{
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
+    for (idx =0; (idx < p_dpb->ref_frames_in_buffer) && (!(found)); idx++)
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
 
-		if ((active_fs->frame.used_for_reference&0x1) && (!(viddec_h264_get_is_long_term(active_fs)&0x01))&&
-			(active_fs->top_field.pic_num == picNumX) )
-		{
-			found = 1;
-			pic_struct = TOP_FIELD;
-		  
-		}
-		if ((active_fs->frame.used_for_reference&0x2) && (!(viddec_h264_get_is_long_term(active_fs)&0x2)) &&
-			(active_fs->bottom_field.pic_num == picNumX) )
-		{
-			found = 1;
-			pic_struct = BOTTOM_FIELD;
-		  
-		}
-	}
+        if ((active_fs->frame.used_for_reference&0x1) && (!(viddec_h264_get_is_long_term(active_fs)&0x01))&&
+                (active_fs->top_field.pic_num == picNumX) )
+        {
+            found = 1;
+            pic_struct = TOP_FIELD;
 
-	return pic_struct;
+        }
+        if ((active_fs->frame.used_for_reference&0x2) && (!(viddec_h264_get_is_long_term(active_fs)&0x2)) &&
+                (active_fs->bottom_field.pic_num == picNumX) )
+        {
+            found = 1;
+            pic_struct = BOTTOM_FIELD;
+
+        }
+    }
+
+    return pic_struct;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -1985,32 +1991,32 @@
 
 void h264_dpb_mm_assign_long_term_frame_idx(h264_Info * pInfo, int32_t difference_of_pic_nums_minus1, int32_t long_term_frame_idx)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
-	int32_t picNumX;
-	int32_t currPicNum;
-	int32_t polarity = 0;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    int32_t picNumX;
+    int32_t currPicNum;
+    int32_t polarity = 0;
 
-	if (pInfo->img.structure == FRAME) {
-		currPicNum = pInfo->img.frame_num;
-	} else {
-		currPicNum = (pInfo->img.frame_num << 1) + 1;
-	}
+    if (pInfo->img.structure == FRAME) {
+        currPicNum = pInfo->img.frame_num;
+    } else {
+        currPicNum = (pInfo->img.frame_num << 1) + 1;
+    }
 
-	picNumX = currPicNum - (difference_of_pic_nums_minus1 + 1);
+    picNumX = currPicNum - (difference_of_pic_nums_minus1 + 1);
 
-	// remove frames / fields with same long_term_frame_idx
-	if (pInfo->img.structure == FRAME) {
-		h264_dpb_unmark_long_term_frame_for_reference_by_frame_idx(p_dpb, long_term_frame_idx);
-	} else {
-		polarity = h264_dpb_get_pic_struct_by_pic_num(p_dpb, picNumX);
+    // remove frames / fields with same long_term_frame_idx
+    if (pInfo->img.structure == FRAME) {
+        h264_dpb_unmark_long_term_frame_for_reference_by_frame_idx(p_dpb, long_term_frame_idx);
+    } else {
+        polarity = h264_dpb_get_pic_struct_by_pic_num(p_dpb, picNumX);
 
-		if(polarity != INVALID)
-		  h264_dpb_unmark_long_term_field_for_reference_by_frame_idx(p_dpb, long_term_frame_idx, active_fs->fs_idc, polarity);
-	}
+        if (polarity != INVALID)
+            h264_dpb_unmark_long_term_field_for_reference_by_frame_idx(p_dpb, long_term_frame_idx, active_fs->fs_idc, polarity);
+    }
 
-	h264_dpb_mark_pic_long_term(pInfo, long_term_frame_idx, picNumX);
+    h264_dpb_mark_pic_long_term(pInfo, long_term_frame_idx, picNumX);
 
-	return;
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -2023,31 +2029,31 @@
 
 void h264_dpb_mm_update_max_long_term_frame_idx(h264_DecodedPictureBuffer *p_dpb,int32_t max_long_term_frame_idx_plus1)
 {
-	//h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
-	int32_t idx;
-	int32_t temp;
-	int32_t removed_count;
-	int32_t idx2 = 0;
+    //h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    int32_t idx;
+    int32_t temp;
+    int32_t removed_count;
+    int32_t idx2 = 0;
 
-	p_dpb->max_long_term_pic_idx = max_long_term_frame_idx_plus1 - 1;
+    p_dpb->max_long_term_pic_idx = max_long_term_frame_idx_plus1 - 1;
 
-	temp = p_dpb->ltref_frames_in_buffer;
-	removed_count = 0;
+    temp = p_dpb->ltref_frames_in_buffer;
+    removed_count = 0;
 
-	// check for invalid frames
-	for (idx = 0; idx < temp; idx++)
-	{
-		idx2 = idx - removed_count;
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx2]);
+    // check for invalid frames
+    for (idx = 0; idx < temp; idx++)
+    {
+        idx2 = idx - removed_count;
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx2]);
 
-		if (active_fs->long_term_frame_idx > p_dpb->max_long_term_pic_idx)
-		{
-			removed_count++;
-			h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[idx2]);
-			h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx2]);
-		}
-	}
-	return;
+        if (active_fs->long_term_frame_idx > p_dpb->max_long_term_pic_idx)
+        {
+            removed_count++;
+            h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[idx2]);
+            h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx2]);
+        }
+    }
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -2060,15 +2066,15 @@
 
 void h264_dpb_mm_unmark_all_short_term_for_reference (h264_DecodedPictureBuffer *p_dpb)
 {
-	int32_t idx;
-	int32_t temp = p_dpb->ref_frames_in_buffer;
+    int32_t idx;
+    int32_t temp = p_dpb->ref_frames_in_buffer;
 
-	for (idx = 0; idx < temp; idx++)
-	{
-		h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_ref_idc[0]);
-		h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[0]);
-	}
-	return;
+    for (idx = 0; idx < temp; idx++)
+    {
+        h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_ref_idc[0]);
+        h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[0]);
+    }
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -2082,44 +2088,44 @@
 
 void h264_dpb_mm_mark_current_picture_long_term(h264_DecodedPictureBuffer *p_dpb, int32_t long_term_frame_idx)
 {
-	int32_t picNumX;
-	h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+    int32_t picNumX;
+    h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
 
-	if (viddec_h264_get_dec_structure(active_fs) == FRAME)
-	{
-		h264_dpb_unmark_long_term_frame_for_reference_by_frame_idx(p_dpb, long_term_frame_idx);
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
-		active_fs->frame.is_long_term        = 1;
-		active_fs->frame.long_term_frame_idx = long_term_frame_idx;
-		active_fs->frame.long_term_pic_num   = long_term_frame_idx;
-	}
-	else
-	{
-		if(viddec_h264_get_dec_structure(active_fs) == TOP_FIELD)
-		{
-		  picNumX = (active_fs->top_field.pic_num << 1) + 1;
-		  active_fs->top_field.is_long_term        = 1;
-		  active_fs->top_field.long_term_frame_idx = long_term_frame_idx;
+    if (viddec_h264_get_dec_structure(active_fs) == FRAME)
+    {
+        h264_dpb_unmark_long_term_frame_for_reference_by_frame_idx(p_dpb, long_term_frame_idx);
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+        active_fs->frame.is_long_term        = 1;
+        active_fs->frame.long_term_frame_idx = long_term_frame_idx;
+        active_fs->frame.long_term_pic_num   = long_term_frame_idx;
+    }
+    else
+    {
+        if (viddec_h264_get_dec_structure(active_fs) == TOP_FIELD)
+        {
+            picNumX = (active_fs->top_field.pic_num << 1) + 1;
+            active_fs->top_field.is_long_term        = 1;
+            active_fs->top_field.long_term_frame_idx = long_term_frame_idx;
 
-		  // Assign long-term pic num
-		  active_fs->top_field.long_term_pic_num   = (long_term_frame_idx << 1) + 1;
-		}
-		else
-		{
-		  picNumX = (active_fs->bottom_field.pic_num << 1) + 1;
-		  active_fs->bottom_field.is_long_term        = 1;
-		  active_fs->bottom_field.long_term_frame_idx = long_term_frame_idx;
+            // Assign long-term pic num
+            active_fs->top_field.long_term_pic_num   = (long_term_frame_idx << 1) + 1;
+        }
+        else
+        {
+            picNumX = (active_fs->bottom_field.pic_num << 1) + 1;
+            active_fs->bottom_field.is_long_term        = 1;
+            active_fs->bottom_field.long_term_frame_idx = long_term_frame_idx;
 
-		  // Assign long-term pic num
-		  active_fs->bottom_field.long_term_pic_num   = (long_term_frame_idx << 1) + 1;
+            // Assign long-term pic num
+            active_fs->bottom_field.long_term_pic_num   = (long_term_frame_idx << 1) + 1;
 
-		}
-		h264_dpb_unmark_long_term_field_for_reference_by_frame_idx(p_dpb, long_term_frame_idx, p_dpb->fs_dec_idc, viddec_h264_get_dec_structure(active_fs));
-	}
-	// Add to long term list
-	//h264_dpb_add_ltref_list(p_dpb->fs_dec_idc);
+        }
+        h264_dpb_unmark_long_term_field_for_reference_by_frame_idx(p_dpb, long_term_frame_idx, p_dpb->fs_dec_idc, viddec_h264_get_dec_structure(active_fs));
+    }
+    // Add to long term list
+    //h264_dpb_add_ltref_list(p_dpb->fs_dec_idc);
 
-	return;
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -2133,18 +2139,18 @@
 
 void h264_dpb_unmark_long_term_frame_for_reference_by_frame_idx(h264_DecodedPictureBuffer *p_dpb, int32_t long_term_frame_idx)
 {
-	uint32_t idx;
-	for(idx =0; idx < p_dpb->ltref_frames_in_buffer; idx++)
-	{
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
+    uint32_t idx;
+    for (idx =0; idx < p_dpb->ltref_frames_in_buffer; idx++)
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
 
-		if (active_fs->long_term_frame_idx == long_term_frame_idx) 
-		{
-		  h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[idx]);
-		  h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx]);
-		}
-	}
-	return;
+        if (active_fs->long_term_frame_idx == long_term_frame_idx)
+        {
+            h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[idx]);
+            h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx]);
+        }
+    }
+    return;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -2153,43 +2159,43 @@
 //////////////////////////////////////////////////////////////////////////////
 // h264_dpb_unmark_long_term_field_for_reference_by_frame_idx ()
 //
-// Mark a long-term reference field unused for reference. However if it is the 
-// complementary field (opposite polarity) of the picture stored in fs_idc, 
+// Mark a long-term reference field unused for reference. However if it is the
+// complementary field (opposite polarity) of the picture stored in fs_idc,
 // we do not unmark it
 //////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_unmark_long_term_field_for_reference_by_frame_idx(h264_DecodedPictureBuffer *p_dpb, int32_t long_term_frame_idx, int32_t fs_idc, int32_t polarity)
 {
-	uint32_t idx;
-	int32_t found = 0;
-	int32_t is_complement = 0;
+    uint32_t idx;
+    int32_t found = 0;
+    int32_t is_complement = 0;
 
-	for (idx = 0; (idx < p_dpb->ltref_frames_in_buffer) && (found == 0); idx++)
-	{
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
-		if (active_fs->long_term_frame_idx == long_term_frame_idx)
-		{
-		  if(active_fs->fs_idc == fs_idc)
-		  {
-			// Again these seem like redundant checks but for safety while until JM is updated
-			if (polarity == TOP_FIELD)    
-				is_complement = (active_fs->bottom_field.is_long_term)? 1:0;
-			else if(polarity == BOTTOM_FIELD) 
-				is_complement = (active_fs->top_field.is_long_term)   ? 1:0;
-		  }
-		  found = 1;        
-		}
-	}
+    for (idx = 0; (idx < p_dpb->ltref_frames_in_buffer) && (found == 0); idx++)
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ltref_idc[idx]);
+        if (active_fs->long_term_frame_idx == long_term_frame_idx)
+        {
+            if (active_fs->fs_idc == fs_idc)
+            {
+                // Again these seem like redundant checks but for safety while until JM is updated
+                if (polarity == TOP_FIELD)
+                    is_complement = (active_fs->bottom_field.is_long_term)? 1:0;
+                else if (polarity == BOTTOM_FIELD)
+                    is_complement = (active_fs->top_field.is_long_term)   ? 1:0;
+            }
+            found = 1;
+        }
+    }
 
-	if(found) {
-		if(is_complement == 0)
-		{
-		  h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[idx-1]);
-		  h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx-1]);
-		}
-	}
+    if (found) {
+        if (is_complement == 0)
+        {
+            h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[idx-1]);
+            h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[idx-1]);
+        }
+    }
 
-	return;
+    return;
 }
 
 
@@ -2202,7 +2208,7 @@
 // This is used on a picture already in the dpb - i.e. not for the current picture
 // dpb_split / dpb_combine field will perform ftnality in that case
 //
-// Marks a picture as used for long-term reference. Adds it to the long-term 
+// Marks a picture as used for long-term reference. Adds it to the long-term
 // reference list. Also removes it from the short term reference list if required
 //
 // Note: if the current picture is a frame, the picture to be marked will be a
@@ -2212,102 +2218,102 @@
 // assigned to be equal to long_term_frame_idx
 //
 // If the current picture is a field, the picture to be marked will be a
-// short-term reference field. We use the pic_nums assigned to the field parts of 
+// short-term reference field. We use the pic_nums assigned to the field parts of
 // the structure to identify the appropriate field. We assign the long_term_frame_idx
-// of the field equal to long_term_frame_idx. 
+// of the field equal to long_term_frame_idx.
 //
-// We also check to see if this marking has resulted in both fields of the frame 
-// becoming long_term. If it has, we update the frame part of the structure by 
+// We also check to see if this marking has resulted in both fields of the frame
+// becoming long_term. If it has, we update the frame part of the structure by
 // setting its long_term_frame_idx
 //////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_mark_pic_long_term(h264_Info * pInfo, int32_t long_term_frame_idx, int32_t picNumX)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
-	uint32_t idx;
-	int32_t mark_done;
-	int32_t polarity = 0;  
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    uint32_t idx;
+    int32_t mark_done;
+    int32_t polarity = 0;
 
-	mark_done = 0;
+    mark_done = 0;
 
-	if (pInfo->img.structure == FRAME)
-	{
-		for (idx = 0; (idx < p_dpb->ref_frames_in_buffer) && (!(mark_done)); idx++)
-		{
-		  h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
-			
-		  if (active_fs->frame.used_for_reference == 3)
-		  {
-			if ((!(active_fs->frame.is_long_term))&&(active_fs->frame.pic_num == picNumX))
-			{
-			  active_fs->long_term_frame_idx = long_term_frame_idx;
-			  active_fs->frame.long_term_frame_idx = long_term_frame_idx;
-			  active_fs->top_field.long_term_frame_idx = long_term_frame_idx;
-			  active_fs->bottom_field.long_term_frame_idx = long_term_frame_idx;
-		      
-			  active_fs->frame.is_long_term = 1;
-			  active_fs->top_field.is_long_term = 1;
-			  active_fs->bottom_field.is_long_term = 1;
-		      
-			  viddec_h264_set_is_frame_long_term(active_fs, 3);
-			  mark_done = 1;
+    if (pInfo->img.structure == FRAME)
+    {
+        for (idx = 0; (idx < p_dpb->ref_frames_in_buffer) && (!(mark_done)); idx++)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_ref_idc[idx]);
 
-			  // Assign long-term pic num
-			  active_fs->frame.long_term_pic_num   = long_term_frame_idx;
-			  active_fs->top_field.long_term_pic_num    = long_term_frame_idx;
-			  active_fs->bottom_field.long_term_pic_num = long_term_frame_idx;
-			  // Add to long term list
-			  h264_dpb_add_ltref_list(p_dpb, p_dpb->fs_ref_idc[idx]);
-			  // Remove from short-term list
-			  h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[idx]);
-			}
-		  }
-		}
-	}
-	else
-	{
-		polarity = h264_dpb_get_pic_struct_by_pic_num(p_dpb, picNumX);
-		active_fs->long_term_frame_idx = long_term_frame_idx;         /////BUG
+            if (active_fs->frame.used_for_reference == 3)
+            {
+                if ((!(active_fs->frame.is_long_term))&&(active_fs->frame.pic_num == picNumX))
+                {
+                    active_fs->long_term_frame_idx = long_term_frame_idx;
+                    active_fs->frame.long_term_frame_idx = long_term_frame_idx;
+                    active_fs->top_field.long_term_frame_idx = long_term_frame_idx;
+                    active_fs->bottom_field.long_term_frame_idx = long_term_frame_idx;
 
-		if(polarity == TOP_FIELD)
-		{
-			active_fs->top_field.long_term_frame_idx = long_term_frame_idx;
-			active_fs->top_field.is_long_term        = 1;
-			viddec_h264_set_is_top_long_term(active_fs, 1);
+                    active_fs->frame.is_long_term = 1;
+                    active_fs->top_field.is_long_term = 1;
+                    active_fs->bottom_field.is_long_term = 1;
 
-			// Assign long-term pic num
-			active_fs->top_field.long_term_pic_num   = (long_term_frame_idx << 1) + ((pInfo->img.structure == TOP_FIELD) ? 1 : 0);
-		  
-		}
-		else if (polarity == BOTTOM_FIELD)
-		{
-			active_fs->bottom_field.long_term_frame_idx = long_term_frame_idx;
-			active_fs->bottom_field.is_long_term        = 1;
-			viddec_h264_set_is_bottom_long_term(active_fs, 1);
+                    viddec_h264_set_is_frame_long_term(active_fs, 3);
+                    mark_done = 1;
 
-			// Assign long-term pic num
-			active_fs->bottom_field.long_term_pic_num   = (long_term_frame_idx << 1) + ((pInfo->img.structure == BOTTOM_FIELD) ? 1 : 0);
-		}
+                    // Assign long-term pic num
+                    active_fs->frame.long_term_pic_num   = long_term_frame_idx;
+                    active_fs->top_field.long_term_pic_num    = long_term_frame_idx;
+                    active_fs->bottom_field.long_term_pic_num = long_term_frame_idx;
+                    // Add to long term list
+                    h264_dpb_add_ltref_list(p_dpb, p_dpb->fs_ref_idc[idx]);
+                    // Remove from short-term list
+                    h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[idx]);
+                }
+            }
+        }
+    }
+    else
+    {
+        polarity = h264_dpb_get_pic_struct_by_pic_num(p_dpb, picNumX);
+        active_fs->long_term_frame_idx = long_term_frame_idx;         /////BUG
 
-		if (viddec_h264_get_is_long_term(active_fs) == 3)
-		{
-			active_fs->frame.is_long_term = 1;
-			active_fs->frame.long_term_frame_idx = long_term_frame_idx;
-			h264_dpb_remove_ref_list(p_dpb, active_fs->fs_idc);
-		}
-		else
-		{
-			// We need to add this idc to the long term ref list...
-			h264_dpb_add_ltref_list(p_dpb, active_fs->fs_idc);
-			    
-			// If the opposite field is not a short term reference, remove it from the 
-			// short term list. Since we know top field is a reference but both are not long term
-			// we can simply check that both fields are not references...
-			if(active_fs->frame.used_for_reference != 3)
-				h264_dpb_remove_ref_list(p_dpb, active_fs->fs_idc);
-		}
-	}
-	return;
+        if (polarity == TOP_FIELD)
+        {
+            active_fs->top_field.long_term_frame_idx = long_term_frame_idx;
+            active_fs->top_field.is_long_term        = 1;
+            viddec_h264_set_is_top_long_term(active_fs, 1);
+
+            // Assign long-term pic num
+            active_fs->top_field.long_term_pic_num   = (long_term_frame_idx << 1) + ((pInfo->img.structure == TOP_FIELD) ? 1 : 0);
+
+        }
+        else if (polarity == BOTTOM_FIELD)
+        {
+            active_fs->bottom_field.long_term_frame_idx = long_term_frame_idx;
+            active_fs->bottom_field.is_long_term        = 1;
+            viddec_h264_set_is_bottom_long_term(active_fs, 1);
+
+            // Assign long-term pic num
+            active_fs->bottom_field.long_term_pic_num   = (long_term_frame_idx << 1) + ((pInfo->img.structure == BOTTOM_FIELD) ? 1 : 0);
+        }
+
+        if (viddec_h264_get_is_long_term(active_fs) == 3)
+        {
+            active_fs->frame.is_long_term = 1;
+            active_fs->frame.long_term_frame_idx = long_term_frame_idx;
+            h264_dpb_remove_ref_list(p_dpb, active_fs->fs_idc);
+        }
+        else
+        {
+            // We need to add this idc to the long term ref list...
+            h264_dpb_add_ltref_list(p_dpb, active_fs->fs_idc);
+
+            // If the opposite field is not a short term reference, remove it from the
+            // short term list. Since we know top field is a reference but both are not long term
+            // we can simply check that both fields are not references...
+            if (active_fs->frame.used_for_reference != 3)
+                h264_dpb_remove_ref_list(p_dpb, active_fs->fs_idc);
+        }
+    }
+    return;
 } ///// End of mark pic long term
 
 
@@ -2322,83 +2328,89 @@
 
 void h264_dpb_adaptive_memory_management (h264_Info * pInfo)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
-	int32_t idx;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    int32_t idx;
 
-	idx = 0;
-	
-	while (idx < pInfo->SliceHeader.sh_dec_refpic.dec_ref_pic_marking_count)
-	{
-		switch(pInfo->SliceHeader.sh_dec_refpic.memory_management_control_operation[idx])  	
-		{
-		  case   1:{	//Mark a short-term reference picture as	�unused for reference?				
-			h264_dpb_mm_unmark_short_term_for_reference(pInfo,	
-												pInfo->SliceHeader.sh_dec_refpic.difference_of_pic_num_minus1[idx]);
-			} break;
-		  case   2:{	//Mark a long-term reference picture as 	�unused for reference?				
-			h264_dpb_mm_unmark_long_term_for_reference(pInfo, 
-												pInfo->SliceHeader.sh_dec_refpic.long_term_pic_num[idx]);
-			}break;
-		  case  3:{		//Mark a short-term reference picture as	"used for long-term reference" and assign a long-term frame index to it
-			h264_dpb_mm_assign_long_term_frame_idx(pInfo, 
-												pInfo->SliceHeader.sh_dec_refpic.difference_of_pic_num_minus1[idx], 
-												pInfo->SliceHeader.sh_dec_refpic.long_term_frame_idx[idx]);
-			}break;
-		  case  4:{	//Specify the maximum long-term frame index and 
-		  				//mark all long-term reference pictureshaving long-term frame indices greater than
-		  				//the maximum value as "unused for reference"
-			h264_dpb_mm_update_max_long_term_frame_idx (&pInfo->dpb, 
-												pInfo->SliceHeader.sh_dec_refpic.max_long_term_frame_idx_plus1[idx]);
-			}break;
-		  case  5:{		//Mark all reference pictures as	"unused for reference" and set the MaxLongTermFrameIdx variable to
-						// "no long-term frame indices"
-			h264_dpb_mm_unmark_all_short_term_for_reference(&pInfo->dpb);
-			h264_dpb_mm_update_max_long_term_frame_idx(&pInfo->dpb, 0);
-			pInfo->img.last_has_mmco_5 = 1;
-			}break;
-		  case   6:{	//Mark the current picture as	"used for long-term reference" and assign a long-term frame index to it
-			h264_dpb_mm_mark_current_picture_long_term(&pInfo->dpb, 
-												pInfo->SliceHeader.sh_dec_refpic.long_term_frame_idx[idx]);    
-			}break;
-		}
-		idx++;
-	}
+    idx = 0;
+
+    while (idx < pInfo->SliceHeader.sh_dec_refpic.dec_ref_pic_marking_count)
+    {
+        switch (pInfo->SliceHeader.sh_dec_refpic.memory_management_control_operation[idx])
+        {
+        case   1: {	//Mark a short-term reference picture as	�unused for reference?
+            h264_dpb_mm_unmark_short_term_for_reference(pInfo,
+                    pInfo->SliceHeader.sh_dec_refpic.difference_of_pic_num_minus1[idx]);
+        }
+        break;
+        case   2: {	//Mark a long-term reference picture as 	�unused for reference?
+            h264_dpb_mm_unmark_long_term_for_reference(pInfo,
+                    pInfo->SliceHeader.sh_dec_refpic.long_term_pic_num[idx]);
+        }
+        break;
+        case  3: {		//Mark a short-term reference picture as	"used for long-term reference" and assign a long-term frame index to it
+            h264_dpb_mm_assign_long_term_frame_idx(pInfo,
+                                                   pInfo->SliceHeader.sh_dec_refpic.difference_of_pic_num_minus1[idx],
+                                                   pInfo->SliceHeader.sh_dec_refpic.long_term_frame_idx[idx]);
+        }
+        break;
+        case  4: {	//Specify the maximum long-term frame index and
+            //mark all long-term reference pictureshaving long-term frame indices greater than
+            //the maximum value as "unused for reference"
+            h264_dpb_mm_update_max_long_term_frame_idx (&pInfo->dpb,
+                    pInfo->SliceHeader.sh_dec_refpic.max_long_term_frame_idx_plus1[idx]);
+        }
+        break;
+        case  5: {		//Mark all reference pictures as	"unused for reference" and set the MaxLongTermFrameIdx variable to
+            // "no long-term frame indices"
+            h264_dpb_mm_unmark_all_short_term_for_reference(&pInfo->dpb);
+            h264_dpb_mm_update_max_long_term_frame_idx(&pInfo->dpb, 0);
+            pInfo->img.last_has_mmco_5 = 1;
+        }
+        break;
+        case   6: {	//Mark the current picture as	"used for long-term reference" and assign a long-term frame index to it
+            h264_dpb_mm_mark_current_picture_long_term(&pInfo->dpb,
+                    pInfo->SliceHeader.sh_dec_refpic.long_term_frame_idx[idx]);
+        }
+        break;
+        }
+        idx++;
+    }
 
 
-	if (pInfo->img.last_has_mmco_5)
-	{
-		pInfo->img.frame_num = 0;
-		pInfo->SliceHeader.frame_num=0;
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+    if (pInfo->img.last_has_mmco_5)
+    {
+        pInfo->img.frame_num = 0;
+        pInfo->SliceHeader.frame_num=0;
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
 
-		if (viddec_h264_get_dec_structure(active_fs) == FRAME)
-		{
-			pInfo->img.bottompoc -= active_fs->frame.poc;
-			pInfo->img.toppoc    -= active_fs->frame.poc;      
+        if (viddec_h264_get_dec_structure(active_fs) == FRAME)
+        {
+            pInfo->img.bottompoc -= active_fs->frame.poc;
+            pInfo->img.toppoc    -= active_fs->frame.poc;
 
 
-			active_fs->frame.poc = 0;
-			active_fs->frame.pic_num = 0;
-			active_fs->frame_num = 0;			
-		}
+            active_fs->frame.poc = 0;
+            active_fs->frame.pic_num = 0;
+            active_fs->frame_num = 0;
+        }
 
-		else if (viddec_h264_get_dec_structure(active_fs) == TOP_FIELD)
-		{
-			active_fs->top_field.poc = active_fs->top_field.pic_num = 0;
-			pInfo->img.toppoc = active_fs->top_field.poc;
-		}
-		else if (viddec_h264_get_dec_structure(active_fs) == BOTTOM_FIELD)
-		{
-			active_fs->bottom_field.poc = active_fs->bottom_field.pic_num = 0;
-			pInfo->img.bottompoc = 0;
-		}
+        else if (viddec_h264_get_dec_structure(active_fs) == TOP_FIELD)
+        {
+            active_fs->top_field.poc = active_fs->top_field.pic_num = 0;
+            pInfo->img.toppoc = active_fs->top_field.poc;
+        }
+        else if (viddec_h264_get_dec_structure(active_fs) == BOTTOM_FIELD)
+        {
+            active_fs->bottom_field.poc = active_fs->bottom_field.pic_num = 0;
+            pInfo->img.bottompoc = 0;
+        }
 
-		h264_dpb_flush_dpb(pInfo, 1, pInfo->img.second_field,pInfo->active_SPS.num_ref_frames);
-	}
-	// Reset the marking count operations for the current picture...
-	pInfo->SliceHeader.sh_dec_refpic.dec_ref_pic_marking_count = 0;
+        h264_dpb_flush_dpb(pInfo, 1, pInfo->img.second_field,pInfo->active_SPS.num_ref_frames);
+    }
+    // Reset the marking count operations for the current picture...
+    pInfo->SliceHeader.sh_dec_refpic.dec_ref_pic_marking_count = 0;
 
-	return;
+    return;
 } ////// End of adaptive memory management
 
 /* ------------------------------------------------------------------------------------------ */
@@ -2408,132 +2420,132 @@
 // h264_dpb_gaps_in_frame_num_mem_management ()
 //
 // Produces a set of frame_nums pertaining to "non-existing" pictures
-// Calls h264_dpb_store_picture_in_dpb 
-////////////////////////////////////////////////////////////////////////////// 
+// Calls h264_dpb_store_picture_in_dpb
+//////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_gaps_in_frame_num_mem_management(h264_Info * pInfo)
 {
-	int32_t		temp_frame_num = 0;
-	int32_t		idx, prev_idc;
-	int32_t 	prev_frame_num_plus1_wrap;
-	uint32_t	temp;
-	int32_t MaxFrameNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
-	seq_param_set_used_ptr  active_sps = &pInfo->active_SPS;
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    int32_t		temp_frame_num = 0;
+    int32_t		idx, prev_idc;
+    int32_t 	prev_frame_num_plus1_wrap;
+    uint32_t	temp;
+    int32_t MaxFrameNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
+    seq_param_set_used_ptr  active_sps = &pInfo->active_SPS;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	pInfo->img.gaps_in_frame_num = 0;
+    pInfo->img.gaps_in_frame_num = 0;
 
-	// pInfo->img.last_has_mmco_5 set thru store_picture_in_dpb
-	if (pInfo->img.last_has_mmco_5)
-	{
-		// If the previous picture was an unpaired field, mark it as a dangler                                                                                  
-		if(p_dpb->used_size)                                                                                                                                       
-		{                                                                                                                                                       
-			idx = p_dpb->used_size-1;                                                                                                                                
-			prev_idc = p_dpb->fs_dpb_idc[idx];                                                                                                                       
-			if (prev_idc != MPD_DPB_FS_NULL_IDC)                                                                                                                  
-			{                                                                                                                                                     
-				h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]); 
-				active_fs->frame_num =0;
-			}                                                                                                                                                     
-		}
-		pInfo->img.PreviousFrameNumOffset = 0;
-		//CONFORMANCE_ISSUE
-		pInfo->img.PreviousFrameNum = 0;
+    // pInfo->img.last_has_mmco_5 set thru store_picture_in_dpb
+    if (pInfo->img.last_has_mmco_5)
+    {
+        // If the previous picture was an unpaired field, mark it as a dangler
+        if (p_dpb->used_size)
+        {
+            idx = p_dpb->used_size-1;
+            prev_idc = p_dpb->fs_dpb_idc[idx];
+            if (prev_idc != MPD_DPB_FS_NULL_IDC)
+            {
+                h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
+                active_fs->frame_num =0;
+            }
+        }
+        pInfo->img.PreviousFrameNumOffset = 0;
+        //CONFORMANCE_ISSUE
+        pInfo->img.PreviousFrameNum = 0;
 
-	}
+    }
 
-	// Check for gaps in frame_num
-	if(pInfo->SliceHeader.idr_flag) {
-		pInfo->img.PreviousFrameNum = pInfo->img.frame_num;
-	}
-	// Have we re-started following a recovery point message? 
-/*
-	else if(got_sei_recovery || aud_got_restart){
-		pInfo->img.PreviousFrameNum = pInfo->img.frame_num;
-		//got_sei_recovery = 0;
-		//aud_got_restart  = 0;
-	}
-*/
-	else if(pInfo->img.frame_num != pInfo->img.PreviousFrameNum)
-	{
-	    if (MaxFrameNum) 
-			ldiv_mod_u((uint32_t)(pInfo->img.PreviousFrameNum + 1), (uint32_t)MaxFrameNum, &temp);
+    // Check for gaps in frame_num
+    if (pInfo->SliceHeader.idr_flag) {
+        pInfo->img.PreviousFrameNum = pInfo->img.frame_num;
+    }
+    // Have we re-started following a recovery point message?
+    /*
+    	else if(got_sei_recovery || aud_got_restart){
+    		pInfo->img.PreviousFrameNum = pInfo->img.frame_num;
+    		//got_sei_recovery = 0;
+    		//aud_got_restart  = 0;
+    	}
+    */
+    else if (pInfo->img.frame_num != pInfo->img.PreviousFrameNum)
+    {
+        if (MaxFrameNum)
+            ldiv_mod_u((uint32_t)(pInfo->img.PreviousFrameNum + 1), (uint32_t)MaxFrameNum, &temp);
 
-		prev_frame_num_plus1_wrap = temp;
-		if(pInfo->img.frame_num != prev_frame_num_plus1_wrap)
-		{
-			pInfo->img.gaps_in_frame_num = (pInfo->img.frame_num < pInfo->img.PreviousFrameNum)? ((MaxFrameNum + pInfo->img.frame_num -1) - pInfo->img.PreviousFrameNum): (pInfo->img.frame_num - pInfo->img.PreviousFrameNum - 1);
-			// We should test for an error here - should infer an unintentional loss of pictures
-		}
-	}
+        prev_frame_num_plus1_wrap = temp;
+        if (pInfo->img.frame_num != prev_frame_num_plus1_wrap)
+        {
+            pInfo->img.gaps_in_frame_num = (pInfo->img.frame_num < pInfo->img.PreviousFrameNum)? ((MaxFrameNum + pInfo->img.frame_num -1) - pInfo->img.PreviousFrameNum): (pInfo->img.frame_num - pInfo->img.PreviousFrameNum - 1);
+            // We should test for an error here - should infer an unintentional loss of pictures
+        }
+    }
 
-  
-	//if(active_sps->gaps_in_frame_num_value_allowed_flag == 0) {
-	if(pInfo->img.gaps_in_frame_num && (active_sps->gaps_in_frame_num_value_allowed_flag == 0)) {
-		// infer an unintentional loss of pictures
-		// only invoke following process for a conforming bitstream 
-		// when gaps_in_frame_num_value_allowed_flag is equal to 1
-		pInfo->img.gaps_in_frame_num = 0;
 
-		//mfd_printf("ERROR STREAM??\n");
-		////// Error handling here----
-	} 
-	
-	/////// Removed following OLO source (Sodaville H.D)
-	//else if (pInfo->img.gaps_in_frame_num  > active_sps->num_ref_frames) {
-	//	// No need to produce any more non-existent frames than the amount required to flush the dpb
-	//	pInfo->img.gaps_in_frame_num = active_sps->num_ref_frames;
-		//mfd_printf("gaps in frame: %d\n", gaps_in_frame_num);
-	//}
+    //if(active_sps->gaps_in_frame_num_value_allowed_flag == 0) {
+    if (pInfo->img.gaps_in_frame_num && (active_sps->gaps_in_frame_num_value_allowed_flag == 0)) {
+        // infer an unintentional loss of pictures
+        // only invoke following process for a conforming bitstream
+        // when gaps_in_frame_num_value_allowed_flag is equal to 1
+        pInfo->img.gaps_in_frame_num = 0;
 
-	// If the previous picture was an unpaired field, mark it as a dangler                                                                                  
-	if(p_dpb->used_size)                                                                                                                                       
-	{                                                                                                                                                       
-		idx = p_dpb->used_size-1;                                                                                                                                
-		prev_idc = p_dpb->fs_dpb_idc[idx];                                                                                                                       
-		if (prev_idc != MPD_DPB_FS_NULL_IDC)                                                                                                                  
-		{                                                                                                                                                     
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);                                                                                                          
-			if(viddec_h264_get_is_used(active_fs) != 3) {                                                                                          
-				h264_dpb_mark_dangling_field(p_dpb, active_fs->fs_idc);  //, DANGLING_TYPE_GAP_IN_FRAME
-			}
-		}                                                                                                                                                     
-	}                                                                                                                                                       
+        //mfd_printf("ERROR STREAM??\n");
+        ////// Error handling here----
+    }
 
-	while(temp_frame_num < pInfo->img.gaps_in_frame_num)
-	{
-		h264_dpb_assign_frame_store(pInfo, 1);
+    /////// Removed following OLO source (Sodaville H.D)
+    //else if (pInfo->img.gaps_in_frame_num  > active_sps->num_ref_frames) {
+    //	// No need to produce any more non-existent frames than the amount required to flush the dpb
+    //	pInfo->img.gaps_in_frame_num = active_sps->num_ref_frames;
+    //mfd_printf("gaps in frame: %d\n", gaps_in_frame_num);
+    //}
 
-		// Set up initial markings - not sure if all are needed
-		viddec_h264_set_dec_structure(active_fs, FRAME);
+    // If the previous picture was an unpaired field, mark it as a dangler
+    if (p_dpb->used_size)
+    {
+        idx = p_dpb->used_size-1;
+        prev_idc = p_dpb->fs_dpb_idc[idx];
+        if (prev_idc != MPD_DPB_FS_NULL_IDC)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
+            if (viddec_h264_get_is_used(active_fs) != 3) {
+                h264_dpb_mark_dangling_field(p_dpb, active_fs->fs_idc);  //, DANGLING_TYPE_GAP_IN_FRAME
+            }
+        }
+    }
 
-	    if(MaxFrameNum) 
-			ldiv_mod_u((uint32_t)(pInfo->img.PreviousFrameNum + 1), (uint32_t)MaxFrameNum, &temp);
+    while (temp_frame_num < pInfo->img.gaps_in_frame_num)
+    {
+        h264_dpb_assign_frame_store(pInfo, 1);
 
-		active_fs->frame.pic_num = temp;
-		active_fs->long_term_frame_idx        = 0;
-		active_fs->frame.long_term_pic_num    = 0;
-		viddec_h264_set_is_frame_long_term(active_fs, 0);
+        // Set up initial markings - not sure if all are needed
+        viddec_h264_set_dec_structure(active_fs, FRAME);
 
-		// Note the call below will overwrite some aspects of the img structure with info relating to the
-		// non-existent picture
-		// However, since this is called before h264_hdr_decoding_poc() for the current existing picture
-		// it should be o.k.
-		if(pInfo->img.pic_order_cnt_type)
-		  h264_hdr_decoding_poc(pInfo, 1, temp);
+        if (MaxFrameNum)
+            ldiv_mod_u((uint32_t)(pInfo->img.PreviousFrameNum + 1), (uint32_t)MaxFrameNum, &temp);
 
-		pInfo->img.structure = FRAME;
-		active_fs->frame.poc = pInfo->img.framepoc;
+        active_fs->frame.pic_num = temp;
+        active_fs->long_term_frame_idx        = 0;
+        active_fs->frame.long_term_pic_num    = 0;
+        viddec_h264_set_is_frame_long_term(active_fs, 0);
 
-		// call store_picture_in_dpb 
-		
-		h264_dpb_store_previous_picture_in_dpb(pInfo, 1, 0);
+        // Note the call below will overwrite some aspects of the img structure with info relating to the
+        // non-existent picture
+        // However, since this is called before h264_hdr_decoding_poc() for the current existing picture
+        // it should be o.k.
+        if (pInfo->img.pic_order_cnt_type)
+            h264_hdr_decoding_poc(pInfo, 1, temp);
 
-		h264_hdr_post_poc(pInfo, 1, temp, 0);
+        pInfo->img.structure = FRAME;
+        active_fs->frame.poc = pInfo->img.framepoc;
 
-		temp_frame_num++;
-	}
+        // call store_picture_in_dpb
+
+        h264_dpb_store_previous_picture_in_dpb(pInfo, 1, 0);
+
+        h264_hdr_post_poc(pInfo, 1, temp, 0);
+
+        temp_frame_num++;
+    }
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -2548,14 +2560,14 @@
 
 void h264_dpb_unmark_for_reference(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc)
 {
-	h264_dpb_set_active_fs(p_dpb, fs_idc);
+    h264_dpb_set_active_fs(p_dpb, fs_idc);
 
-	if (viddec_h264_get_is_used(active_fs)&0x1)  active_fs->top_field.used_for_reference = 0;
-	if (viddec_h264_get_is_used(active_fs)&0x2)  active_fs->bottom_field.used_for_reference = 0;
-	if (viddec_h264_get_is_used(active_fs) == 3) active_fs->frame.used_for_reference = 0;
+    if (viddec_h264_get_is_used(active_fs)&0x1)  active_fs->top_field.used_for_reference = 0;
+    if (viddec_h264_get_is_used(active_fs)&0x2)  active_fs->bottom_field.used_for_reference = 0;
+    if (viddec_h264_get_is_used(active_fs) == 3) active_fs->frame.used_for_reference = 0;
 
-	active_fs->frame.used_for_reference = 0;
-	return;
+    active_fs->frame.used_for_reference = 0;
+    return;
 }
 
 
@@ -2571,29 +2583,29 @@
 
 void h264_dpb_unmark_for_long_term_reference(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc)
 {
-	h264_dpb_set_active_fs(p_dpb, fs_idc);
+    h264_dpb_set_active_fs(p_dpb, fs_idc);
 
-	if (viddec_h264_get_is_used(active_fs)&0x1)
-	{
-		active_fs->top_field.used_for_reference = 0;
-		active_fs->top_field.is_long_term = 0;
-	}
+    if (viddec_h264_get_is_used(active_fs)&0x1)
+    {
+        active_fs->top_field.used_for_reference = 0;
+        active_fs->top_field.is_long_term = 0;
+    }
 
-	if (viddec_h264_get_is_used(active_fs)&0x2)
-	{
-		active_fs->bottom_field.used_for_reference = 0;
-		active_fs->bottom_field.is_long_term = 0;
-	}
-	if (viddec_h264_get_is_used(active_fs) == 3)
-	{
-		active_fs->frame.used_for_reference = 0;
-		active_fs->frame.is_long_term = 0;
-	}
+    if (viddec_h264_get_is_used(active_fs)&0x2)
+    {
+        active_fs->bottom_field.used_for_reference = 0;
+        active_fs->bottom_field.is_long_term = 0;
+    }
+    if (viddec_h264_get_is_used(active_fs) == 3)
+    {
+        active_fs->frame.used_for_reference = 0;
+        active_fs->frame.is_long_term = 0;
+    }
 
-	active_fs->frame.used_for_reference = 0;
-	viddec_h264_set_is_frame_long_term(active_fs, 0);
+    active_fs->frame.used_for_reference = 0;
+    viddec_h264_set_is_frame_long_term(active_fs, 0);
 
-	return;
+    return;
 }
 
 
@@ -2611,39 +2623,39 @@
 void h264_dpb_mark_dangling_field(h264_DecodedPictureBuffer *p_dpb, int32_t fs_idc)
 {
 
-	h264_dpb_set_active_fs(p_dpb, fs_idc);
+    h264_dpb_set_active_fs(p_dpb, fs_idc);
 
-	//PRINTF(MFD_NONE, " fs_idc = %d DANGLING_TYPE = %d \n", fs_idc,  reason);
-	/*
-	Make the check that it has not already been marked
-	This covers the situation of a dangling field followed by a 
-	frame which is direct output (i.e. never entered into the dpb).
-	In this case we could attempt  to mark the prev unpaired field 
-	as a dangler twice which would upset the HW dpb_disp_q count
-	*/
+    //PRINTF(MFD_NONE, " fs_idc = %d DANGLING_TYPE = %d \n", fs_idc,  reason);
+    /*
+    Make the check that it has not already been marked
+    This covers the situation of a dangling field followed by a
+    frame which is direct output (i.e. never entered into the dpb).
+    In this case we could attempt  to mark the prev unpaired field
+    as a dangler twice which would upset the HW dpb_disp_q count
+    */
 
-	if(viddec_h264_get_is_dangling(active_fs) == 0)
-	{
-		switch(viddec_h264_get_dec_structure(active_fs))
-		{
-			case TOP_FIELD:
-				viddec_h264_set_is_dangling(active_fs, 1);
-				//PRINTF(MFD_NONE,  "FN:%d  fs_idc=%d  FRAME_FLAG_DANGLING_TOP_FIELD\n ", (h264_frame_number+1), active_fs->fs_idc);
-				break;
-			case BOTTOM_FIELD:
-				 //PRINTF(MFD_NONE,  " FN:%d  fs_idc=%d  FRAME_FLAG_DANGLING_BOTTOM_FIELD \n ", (h264_frame_number+1), active_fs->fs_idc);
-				 viddec_h264_set_is_dangling(active_fs, 1);
-				break;
-			default:
-				 //PRINTF(MFD_NONE,  "FN:%d  fs_idc=%d  DANGLING: FATAL_ERROR\n ", (h264_frame_number+1), active_fs->fs_idc);
-				 break;
-		}
+    if (viddec_h264_get_is_dangling(active_fs) == 0)
+    {
+        switch (viddec_h264_get_dec_structure(active_fs))
+        {
+        case TOP_FIELD:
+            viddec_h264_set_is_dangling(active_fs, 1);
+            //PRINTF(MFD_NONE,  "FN:%d  fs_idc=%d  FRAME_FLAG_DANGLING_TOP_FIELD\n ", (h264_frame_number+1), active_fs->fs_idc);
+            break;
+        case BOTTOM_FIELD:
+            //PRINTF(MFD_NONE,  " FN:%d  fs_idc=%d  FRAME_FLAG_DANGLING_BOTTOM_FIELD \n ", (h264_frame_number+1), active_fs->fs_idc);
+            viddec_h264_set_is_dangling(active_fs, 1);
+            break;
+        default:
+            //PRINTF(MFD_NONE,  "FN:%d  fs_idc=%d  DANGLING: FATAL_ERROR\n ", (h264_frame_number+1), active_fs->fs_idc);
+            break;
+        }
 
-		//h264_send_new_decoded_frame();
-	}
-	return;
+        //h264_send_new_decoded_frame();
+    }
+    return;
 }
-   
+
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -2657,19 +2669,19 @@
 void h264_dpb_is_used_for_reference(int32_t * flag)
 {
 
-	/* Check out below for embedded */ 
-	*flag = 0;
-	if (active_fs->frame.used_for_reference)
-		*flag = 1;
-	else if (viddec_h264_get_is_used(active_fs) ==3) // frame
-		*flag = active_fs->frame.used_for_reference;
-	else
-	{
-		if (viddec_h264_get_is_used(active_fs)&0x1) // top field
-			*flag = active_fs->top_field.used_for_reference;
-		if (viddec_h264_get_is_used(active_fs)&0x2) // bottom field
-			*flag = *flag ||  active_fs->bottom_field.used_for_reference;
-	}
+    /* Check out below for embedded */
+    *flag = 0;
+    if (active_fs->frame.used_for_reference)
+        *flag = 1;
+    else if (viddec_h264_get_is_used(active_fs) ==3) // frame
+        *flag = active_fs->frame.used_for_reference;
+    else
+    {
+        if (viddec_h264_get_is_used(active_fs)&0x1) // top field
+            *flag = active_fs->top_field.used_for_reference;
+        if (viddec_h264_get_is_used(active_fs)&0x2) // bottom field
+            *flag = *flag ||  active_fs->bottom_field.used_for_reference;
+    }
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -2683,226 +2695,231 @@
 
 void h264_dpb_idr_memory_management (h264_Info * pInfo,seq_param_set_used_ptr active_sps, int32_t no_output_of_prior_pics_flag)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
-	uint32_t	idx;
-	uint32_t	i;
-	int32_t		DPB_size;
-	int32_t		FrameSizeInBytes, FrameSizeInMbs;  
-	uint32_t	data;
-	int32_t		num_ref_frames = active_sps->num_ref_frames;
-	int32_t		level_idc = active_sps->level_idc;
-   uint32_t    temp_bump_level=0;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    uint32_t	idx;
+    uint32_t	i;
+    int32_t		DPB_size;
+    int32_t		FrameSizeInBytes, FrameSizeInMbs;
+    uint32_t	data;
+    int32_t		num_ref_frames = active_sps->num_ref_frames;
+    int32_t		level_idc = active_sps->level_idc;
+    uint32_t    temp_bump_level=0;
 
 
-	/// H.D-----
-	/// There are 2 kinds of dpb flush defined, one is with display, the other is without display
-	/// The function name dpb_flush actually is just the first, and the 2nd one is for error case or no_prior_output 
-	/// We will rewrite the code below to make it clean and clear
-	///
-	if (no_output_of_prior_pics_flag)
-	{
-	
-		// free all stored pictures
-		for (idx = 0; idx < p_dpb->used_size; idx = idx + 1)
-		{
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
+    /// H.D-----
+    /// There are 2 kinds of dpb flush defined, one is with display, the other is without display
+    /// The function name dpb_flush actually is just the first, and the 2nd one is for error case or no_prior_output
+    /// We will rewrite the code below to make it clean and clear
+    ///
+    if (no_output_of_prior_pics_flag)
+    {
 
-			//mfd_printf(" directly freeing fs_idc = %d DSN = 0x%x \n",active_fs->fs_idc, active_fs->first_dsn);
-			viddec_h264_set_is_frame_used(active_fs, 0);
-			//if( (active_fs->frame_sent == 0x01) && (active_fs->is_output == 0x0)) 
-			{
-				//DECODED_FRAME sent but not DISPLAY_FRAME
-				h264_dpb_unmark_for_reference(p_dpb, active_fs->fs_idc);
-				h264_dpb_remove_ref_list(p_dpb, active_fs->fs_idc);
-				//h264_send_new_display_frame(0x01); //send ignore_frame signal to Host
+        // free all stored pictures
+        for (idx = 0; idx < p_dpb->used_size; idx = idx + 1)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
 
-				///  Add into drop-out list for all frms in dpb without display
-				if(!(viddec_h264_get_is_non_existent(active_fs)))   {      
-					if( viddec_h264_get_is_output(&(p_dpb->fs[p_dpb->fs_dpb_idc[idx]])) ) {			//// This frame has been displayed but not released
-						p_dpb->frame_id_need_to_be_removed[p_dpb->frame_numbers_need_to_be_removed] = p_dpb->fs_dpb_idc[idx];      
-						p_dpb->frame_numbers_need_to_be_removed ++;   
-					} else {																		//// This frame will be removed without display
-						p_dpb->frame_id_need_to_be_dropped[p_dpb->frame_numbers_need_to_be_dropped] = p_dpb->fs_dpb_idc[idx];      
-						p_dpb->frame_numbers_need_to_be_dropped ++;   
-					}   
-				}
-			}
-		  
-		}
+            //mfd_printf(" directly freeing fs_idc = %d DSN = 0x%x \n",active_fs->fs_idc, active_fs->first_dsn);
+            viddec_h264_set_is_frame_used(active_fs, 0);
+            //if( (active_fs->frame_sent == 0x01) && (active_fs->is_output == 0x0))
+            {
+                //DECODED_FRAME sent but not DISPLAY_FRAME
+                h264_dpb_unmark_for_reference(p_dpb, active_fs->fs_idc);
+                h264_dpb_remove_ref_list(p_dpb, active_fs->fs_idc);
+                //h264_send_new_display_frame(0x01); //send ignore_frame signal to Host
 
-		////////////////////////////////////////// Reset Reference list
-		for (i = 0; i < p_dpb->ref_frames_in_buffer; i++)
-		  p_dpb->fs_ref_idc[i] = MPD_DPB_FS_NULL_IDC;
+                ///  Add into drop-out list for all frms in dpb without display
+                if (!(viddec_h264_get_is_non_existent(active_fs)))   {
+                    if ( viddec_h264_get_is_output(&(p_dpb->fs[p_dpb->fs_dpb_idc[idx]])) ) {			//// This frame has been displayed but not released
+                        p_dpb->frame_id_need_to_be_removed[p_dpb->frame_numbers_need_to_be_removed] = p_dpb->fs_dpb_idc[idx];
+                        p_dpb->frame_numbers_need_to_be_removed ++;
+                    } else {																		//// This frame will be removed without display
+                        p_dpb->frame_id_need_to_be_dropped[p_dpb->frame_numbers_need_to_be_dropped] = p_dpb->fs_dpb_idc[idx];
+                        p_dpb->frame_numbers_need_to_be_dropped ++;
+                    }
+                }
+            }
 
-		for (i = 0; i < p_dpb->ltref_frames_in_buffer; i++)
-		  p_dpb->fs_ltref_idc[i] = MPD_DPB_FS_NULL_IDC;
+        }
 
-		////////////////////////////////////////// Reset DPB and dpb list
-		for (i = 0; i < p_dpb->used_size; i++) {
-			p_dpb->fs[p_dpb->fs_dpb_idc[i]].fs_idc = MPD_DPB_FS_NULL_IDC;
-			p_dpb->fs_dpb_idc[i] = MPD_DPB_FS_NULL_IDC;
-		}
+        ////////////////////////////////////////// Reset Reference list
+        for (i = 0; i < p_dpb->ref_frames_in_buffer; i++)
+            p_dpb->fs_ref_idc[i] = MPD_DPB_FS_NULL_IDC;
 
-		p_dpb->used_size = 0;
-		p_dpb->ref_frames_in_buffer   = 0;
-		p_dpb->ltref_frames_in_buffer = 0;
+        for (i = 0; i < p_dpb->ltref_frames_in_buffer; i++)
+            p_dpb->fs_ltref_idc[i] = MPD_DPB_FS_NULL_IDC;
 
-		p_dpb->last_output_poc = 0x80000000;
-	}
-	else {
-		h264_dpb_flush_dpb(pInfo, 1, pInfo->img.second_field, num_ref_frames);
-	}
+        ////////////////////////////////////////// Reset DPB and dpb list
+        for (i = 0; i < p_dpb->used_size; i++) {
+            p_dpb->fs[p_dpb->fs_dpb_idc[i]].fs_idc = MPD_DPB_FS_NULL_IDC;
+            p_dpb->fs_dpb_idc[i] = MPD_DPB_FS_NULL_IDC;
+        }
 
-	if (p_dpb->fs_dec_idc != MPD_DPB_FS_NULL_IDC) // added condition for use of DPB initialization
-	{
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
-		if (pInfo->img.long_term_reference_flag)
-		{
-		  p_dpb->max_long_term_pic_idx      = 0;
-		  switch (viddec_h264_get_dec_structure(active_fs))
-		  {
-			case FRAME        : active_fs->frame.is_long_term = 1;
-			case TOP_FIELD    : active_fs->top_field.is_long_term = 1;
-			case BOTTOM_FIELD : active_fs->bottom_field.is_long_term = 1;
-		  }
-		  active_fs->long_term_frame_idx = 0;
-		}
-		else
-		{
-		  p_dpb->max_long_term_pic_idx = MPD_DPB_FS_NULL_IDC;
-		  viddec_h264_set_is_frame_long_term(active_fs, 0);
-		}
-	}
+        p_dpb->used_size = 0;
+        p_dpb->ref_frames_in_buffer   = 0;
+        p_dpb->ltref_frames_in_buffer = 0;
 
-	p_dpb->OutputLevel      = 0;
-	p_dpb->OutputLevelValid = 0;
-	p_dpb->OutputCtrl = 0;
+        p_dpb->last_output_poc = 0x80000000;
+    }
+    else {
+        h264_dpb_flush_dpb(pInfo, 1, pInfo->img.second_field, num_ref_frames);
+    }
+
+    if (p_dpb->fs_dec_idc != MPD_DPB_FS_NULL_IDC) // added condition for use of DPB initialization
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+        if (pInfo->img.long_term_reference_flag)
+        {
+            p_dpb->max_long_term_pic_idx      = 0;
+            switch (viddec_h264_get_dec_structure(active_fs))
+            {
+            case FRAME        :
+                active_fs->frame.is_long_term = 1;
+            case TOP_FIELD    :
+                active_fs->top_field.is_long_term = 1;
+            case BOTTOM_FIELD :
+                active_fs->bottom_field.is_long_term = 1;
+            }
+            active_fs->long_term_frame_idx = 0;
+        }
+        else
+        {
+            p_dpb->max_long_term_pic_idx = MPD_DPB_FS_NULL_IDC;
+            viddec_h264_set_is_frame_long_term(active_fs, 0);
+        }
+    }
+
+    p_dpb->OutputLevel      = 0;
+    p_dpb->OutputLevelValid = 0;
+    p_dpb->OutputCtrl = 0;
 
 
-	// Set up bumping level - do this every time a parameters set is activated...
-	if(active_sps->sps_disp.vui_parameters_present_flag)
-	{
-		if(active_sps->sps_disp.vui_seq_parameters.bitstream_restriction_flag)
-		{
-		  //p_dpb->OutputLevel      = active_sps->sps_disp.vui_seq_parameters.num_reorder_frames;
-		  //p_dpb->OutputLevelValid = 1;
-		}
-	}
+    // Set up bumping level - do this every time a parameters set is activated...
+    if (active_sps->sps_disp.vui_parameters_present_flag)
+    {
+        if (active_sps->sps_disp.vui_seq_parameters.bitstream_restriction_flag)
+        {
+            //p_dpb->OutputLevel      = active_sps->sps_disp.vui_seq_parameters.num_reorder_frames;
+            //p_dpb->OutputLevelValid = 1;
+        }
+    }
 
-	// Set up bumping level - do this every time a parameters set is activated...
-	switch(level_idc)
-	{
-       case h264_Level1b:
-       case h264_Level1:
-       {
-		   if ((active_sps->profile_idc < 100) && ((active_sps->constraint_set_flags & 0x1) == 0)) {
-				  DPB_size =	 338;
-		   }
-		   else {
-				  DPB_size =	 149;
-		   }  
+    // Set up bumping level - do this every time a parameters set is activated...
+    switch (level_idc)
+    {
+    case h264_Level1b:
+    case h264_Level1:
+    {
+        if ((active_sps->profile_idc < 100) && ((active_sps->constraint_set_flags & 0x1) == 0)) {
+            DPB_size =	 338;
+        }
+        else {
+            DPB_size =	 149;
+        }
 
-           break;
-       }
-       case h264_Level11:
-       {
-           DPB_size = 338;
-           break;
-       }
-       case h264_Level12:
-       case h264_Level13:
-       case h264_Level2:
-       {
-           DPB_size = 891;
-           break;
-       }
-       case h264_Level21:
-       {
-           DPB_size = 1782;
-           break;
-       }
-       case h264_Level22:
-       case h264_Level3:
-       {
-           DPB_size = 3038;
-           break;
-       }
-       case h264_Level31:
-       {
-           DPB_size = 6750;
-           break;
-       }
-       case h264_Level32:
-       {
-           DPB_size = 7680;
-           break;
-       }
-       case h264_Level4:
-       case h264_Level41:
-       {
-           DPB_size = 12288;
-           break;
-       }
-       case h264_Level42:
-       {
-           DPB_size = 13056;
-           break;
-       }
-       case h264_Level5:
-       {
-           DPB_size = 41400;
-           break;
-       }
-       case h264_Level51:
-       {
-           DPB_size = 69120;
-          break;
-       }
-		 default  : DPB_size =   69120; break;
-	}
+        break;
+    }
+    case h264_Level11:
+    {
+        DPB_size = 338;
+        break;
+    }
+    case h264_Level12:
+    case h264_Level13:
+    case h264_Level2:
+    {
+        DPB_size = 891;
+        break;
+    }
+    case h264_Level21:
+    {
+        DPB_size = 1782;
+        break;
+    }
+    case h264_Level22:
+    case h264_Level3:
+    {
+        DPB_size = 3038;
+        break;
+    }
+    case h264_Level31:
+    {
+        DPB_size = 6750;
+        break;
+    }
+    case h264_Level32:
+    {
+        DPB_size = 7680;
+        break;
+    }
+    case h264_Level4:
+    case h264_Level41:
+    {
+        DPB_size = 12288;
+        break;
+    }
+    case h264_Level42:
+    {
+        DPB_size = 13056;
+        break;
+    }
+    case h264_Level5:
+    {
+        DPB_size = 41400;
+        break;
+    }
+    case h264_Level51:
+    {
+        DPB_size = 69120;
+        break;
+    }
+    default  :
+        DPB_size =   69120;
+        break;
+    }
 
-	FrameSizeInMbs = pInfo->img.PicWidthInMbs * pInfo->img.FrameHeightInMbs;
-	FrameSizeInBytes = (FrameSizeInMbs << 8) + (FrameSizeInMbs << 7);
+    FrameSizeInMbs = pInfo->img.PicWidthInMbs * pInfo->img.FrameHeightInMbs;
+    FrameSizeInBytes = (FrameSizeInMbs << 8) + (FrameSizeInMbs << 7);
 
-	if(FrameSizeInBytes) 
-   {
+    if (FrameSizeInBytes)
+    {
 
-      temp_bump_level = ldiv_mod_u((DPB_size << 10), FrameSizeInBytes, &data);
+        temp_bump_level = ldiv_mod_u((DPB_size << 10), FrameSizeInBytes, &data);
 
-      if(temp_bump_level > 255)
-      {
-         p_dpb->BumpLevel = 255;
-      }
-      else
-      {
-         p_dpb->BumpLevel = (uint8_t)temp_bump_level;
-      }
-   }
+        if (temp_bump_level > 255)
+        {
+            p_dpb->BumpLevel = 255;
+        }
+        else
+        {
+            p_dpb->BumpLevel = (uint8_t)temp_bump_level;
+        }
+    }
 
-	if (p_dpb->BumpLevel == 0) 
-		p_dpb->BumpLevel = active_sps->num_ref_frames + 1;
+    if (p_dpb->BumpLevel == 0)
+        p_dpb->BumpLevel = active_sps->num_ref_frames + 1;
 
-	if (p_dpb->BumpLevel > 16) 
-		p_dpb->BumpLevel = 16;
-
-	
-	if(active_sps->sps_disp.vui_parameters_present_flag && active_sps->sps_disp.vui_seq_parameters.bitstream_restriction_flag) {
-	  
-		if (active_sps->sps_disp.vui_seq_parameters.max_dec_frame_buffering > p_dpb->BumpLevel) {
-			//MFD_PARSER_DEBUG(ERROR_H264_DPB);
-			//// err handling here
-		}
-		else {
-			p_dpb->BumpLevel = (active_sps->sps_disp.vui_seq_parameters.max_dec_frame_buffering > 1) ? 
-								 (active_sps->sps_disp.vui_seq_parameters.max_dec_frame_buffering) : 1;
-		}
-	}
+    if (p_dpb->BumpLevel > 16)
+        p_dpb->BumpLevel = 16;
 
 
-	// A new sequence means automatic frame release
-	//sei_information.disp_frozen = 0;
+    if (active_sps->sps_disp.vui_parameters_present_flag && active_sps->sps_disp.vui_seq_parameters.bitstream_restriction_flag) {
 
-	return;
+        if (active_sps->sps_disp.vui_seq_parameters.max_dec_frame_buffering > p_dpb->BumpLevel) {
+            //MFD_PARSER_DEBUG(ERROR_H264_DPB);
+            //// err handling here
+        }
+        else {
+            p_dpb->BumpLevel = (active_sps->sps_disp.vui_seq_parameters.max_dec_frame_buffering > 1) ?
+                               (active_sps->sps_disp.vui_seq_parameters.max_dec_frame_buffering) : 1;
+        }
+    }
+
+
+    // A new sequence means automatic frame release
+    //sei_information.disp_frozen = 0;
+
+    return;
 } //// End --- dpb_idr_memory_management
 
 /* ------------------------------------------------------------------------------------------ */
@@ -2912,43 +2929,43 @@
 // h264_dpb_remove_frame_from_dpb ()
 //
 // remove one frame from DPB
-// The parameter index, is the location of the frame to be removed in the 
+// The parameter index, is the location of the frame to be removed in the
 // fs_dpb_idc list. The used size is decremented by one
 //////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_remove_frame_from_dpb(h264_DecodedPictureBuffer *p_dpb, int32_t idx)
 {
-	int32_t fs_idc;
-	uint32_t i;
+    int32_t fs_idc;
+    uint32_t i;
 
-	fs_idc = p_dpb->fs_dpb_idc[idx];
-	
-	h264_dpb_set_active_fs(p_dpb, fs_idc);
-	viddec_h264_set_is_frame_used(active_fs, 0);
+    fs_idc = p_dpb->fs_dpb_idc[idx];
 
-   //add to support frame relocation interface to host
-   if(!(viddec_h264_get_is_non_existent(active_fs)))
-   {
-      p_dpb->frame_id_need_to_be_removed[p_dpb->frame_numbers_need_to_be_removed] = p_dpb->fs[fs_idc].fs_idc;
-      p_dpb->frame_numbers_need_to_be_removed ++;
-   }
+    h264_dpb_set_active_fs(p_dpb, fs_idc);
+    viddec_h264_set_is_frame_used(active_fs, 0);
 
-	///////////////////////////////////////// Reset FS
-	p_dpb->fs[fs_idc].fs_idc = MPD_DPB_FS_NULL_IDC;
+    //add to support frame relocation interface to host
+    if (!(viddec_h264_get_is_non_existent(active_fs)))
+    {
+        p_dpb->frame_id_need_to_be_removed[p_dpb->frame_numbers_need_to_be_removed] = p_dpb->fs[fs_idc].fs_idc;
+        p_dpb->frame_numbers_need_to_be_removed ++;
+    }
 
-	/////Remove unused frame from dpb-list
-	i = idx;
-	while( (i + 1)< p_dpb->used_size)
-	{
-		p_dpb->fs_dpb_idc[i] = p_dpb->fs_dpb_idc[i + 1];
-		i ++;
-	}
-	p_dpb->fs_dpb_idc[i] = MPD_DPB_FS_NULL_IDC;
+    ///////////////////////////////////////// Reset FS
+    p_dpb->fs[fs_idc].fs_idc = MPD_DPB_FS_NULL_IDC;
 
-	//////////////////////////// 
-	p_dpb->used_size--;
+    /////Remove unused frame from dpb-list
+    i = idx;
+    while ( (i + 1)< p_dpb->used_size)
+    {
+        p_dpb->fs_dpb_idc[i] = p_dpb->fs_dpb_idc[i + 1];
+        i ++;
+    }
+    p_dpb->fs_dpb_idc[i] = MPD_DPB_FS_NULL_IDC;
 
-	return;
+    ////////////////////////////
+    p_dpb->used_size--;
+
+    return;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -2960,53 +2977,53 @@
 //
 // Remove a picture from DPB which is no longer needed.
 // Search for a frame which is not used for reference and has previously been placed
-// in the output queue - if find one call h264_dpb_remove_frame_from_dpb() and 
+// in the output queue - if find one call h264_dpb_remove_frame_from_dpb() and
 // set flag 1
 //////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_remove_unused_frame_from_dpb(h264_DecodedPictureBuffer *p_dpb, int32_t * flag)
 {
-	uint32_t idx;
-	int32_t first_non_exist_valid, non_exist_idx;
-	int32_t used_for_reference = 0;
+    uint32_t idx;
+    int32_t first_non_exist_valid, non_exist_idx;
+    int32_t used_for_reference = 0;
 
-	*flag = 0;
-	first_non_exist_valid = 0x0;
-	non_exist_idx = 0x0;
+    *flag = 0;
+    first_non_exist_valid = 0x0;
+    non_exist_idx = 0x0;
 
-	for (idx = 0; (idx < p_dpb->used_size) && (*flag == 0); idx++)
-	{
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
-		h264_dpb_is_used_for_reference(&used_for_reference);
+    for (idx = 0; (idx < p_dpb->used_size) && (*flag == 0); idx++)
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
+        h264_dpb_is_used_for_reference(&used_for_reference);
 
-		//if( (used_for_reference == 0x0 ) && active_fs->is_output &&  active_fs->is_non_existent == 0x0)
-		//{
-			//PRINTF(MFD_NONE, " requesting to send FREE: fs_idc = %d fb_id = %d \n", active_fs->fs_idc, active_fs->fb_id);
-			//dpb_release_fb(&h264_dpb, active_fs->fb_id, 1);
-		//}
+        //if( (used_for_reference == 0x0 ) && active_fs->is_output &&  active_fs->is_non_existent == 0x0)
+        //{
+        //PRINTF(MFD_NONE, " requesting to send FREE: fs_idc = %d fb_id = %d \n", active_fs->fs_idc, active_fs->fb_id);
+        //dpb_release_fb(&h264_dpb, active_fs->fb_id, 1);
+        //}
 
-		if (viddec_h264_get_is_output(active_fs) && (used_for_reference == 0))
-		{
-			h264_dpb_remove_frame_from_dpb(p_dpb, idx);
-			*flag = 1;
-		}
-/*
-/////// Removed following OLO source (Sodaville H.D)
-		else if ( (first_non_exist_valid == 0x0) && active_fs->is_non_existent )
-		{
-			first_non_exist_valid = 0x01;
-			non_exist_idx = idx;
-		}
-*/
-	}
-/*
-/////// Removed following OLO source (Sodaville H.D)
-	if ( *flag == 0x0  && first_non_exist_valid) {
-	   h264_dpb_remove_frame_from_dpb(p_dpb,non_exist_idx);
-	  *flag = 1;
-	}
-*/
-	return;
+        if (viddec_h264_get_is_output(active_fs) && (used_for_reference == 0))
+        {
+            h264_dpb_remove_frame_from_dpb(p_dpb, idx);
+            *flag = 1;
+        }
+        /*
+        /////// Removed following OLO source (Sodaville H.D)
+        		else if ( (first_non_exist_valid == 0x0) && active_fs->is_non_existent )
+        		{
+        			first_non_exist_valid = 0x01;
+        			non_exist_idx = idx;
+        		}
+        */
+    }
+    /*
+    /////// Removed following OLO source (Sodaville H.D)
+    	if ( *flag == 0x0  && first_non_exist_valid) {
+    	   h264_dpb_remove_frame_from_dpb(p_dpb,non_exist_idx);
+    	  *flag = 1;
+    	}
+    */
+    return;
 }	//// End of h264_dpb_remove_unused_frame_from_dpb
 
 
@@ -3022,47 +3039,47 @@
 //////////////////////////////////////////////////////////////////////////////
 void h264_dpb_get_smallest_poc(h264_DecodedPictureBuffer *p_dpb, int32_t *poc, int32_t *pos)
 {
-	int32_t poc_int;
-	uint32_t idx;
-	int32_t first_non_output = 1;
+    int32_t poc_int;
+    uint32_t idx;
+    int32_t first_non_output = 1;
 
-	*pos = MPD_DPB_FS_NULL_IDC;
+    *pos = MPD_DPB_FS_NULL_IDC;
 
-	h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[0]);
-	poc_int = active_fs->frame.poc;
+    h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[0]);
+    poc_int = active_fs->frame.poc;
 
-	for (idx = 0; idx < p_dpb->used_size; idx++)
-	{
-		h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
+    for (idx = 0; idx < p_dpb->used_size; idx++)
+    {
+        h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
 
-		if (viddec_h264_get_is_output(active_fs) == 0) 
-		{
-		  //PRINTF(MFD_NONE, " active_fs->fs_idc = %d active_fs->is_used = %d, active_fs->is_dangling = %d , active_fs->poc = %d \n", active_fs->fs_idc, active_fs->is_used, active_fs->is_dangling, active_fs->poc);		   
-		  if ((viddec_h264_get_is_used(active_fs) == 3) || (viddec_h264_get_is_dangling(active_fs)))
-		  {
-			if (first_non_output)
-			{
-			  *pos = idx;
-			  first_non_output = 0;
-			  poc_int = active_fs->frame.poc;
-			}
-			else if (poc_int > active_fs->frame.poc)
-			{
-			  poc_int = active_fs->frame.poc;
-			  *pos = idx;
-			}
-		  }
-		  else if (p_dpb->used_size == 1)
-		  {
-			poc_int = active_fs->frame.poc;
-			*pos = idx;
-		  }
-		}
-	}
+        if (viddec_h264_get_is_output(active_fs) == 0)
+        {
+            //PRINTF(MFD_NONE, " active_fs->fs_idc = %d active_fs->is_used = %d, active_fs->is_dangling = %d , active_fs->poc = %d \n", active_fs->fs_idc, active_fs->is_used, active_fs->is_dangling, active_fs->poc);
+            if ((viddec_h264_get_is_used(active_fs) == 3) || (viddec_h264_get_is_dangling(active_fs)))
+            {
+                if (first_non_output)
+                {
+                    *pos = idx;
+                    first_non_output = 0;
+                    poc_int = active_fs->frame.poc;
+                }
+                else if (poc_int > active_fs->frame.poc)
+                {
+                    poc_int = active_fs->frame.poc;
+                    *pos = idx;
+                }
+            }
+            else if (p_dpb->used_size == 1)
+            {
+                poc_int = active_fs->frame.poc;
+                *pos = idx;
+            }
+        }
+    }
 
-	*poc = poc_int;
+    *poc = poc_int;
 
-	return;
+    return;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -3076,29 +3093,29 @@
 
 void h264_dpb_split_field (h264_Info * pInfo)
 {
- 
-	//active_fs->frame.poc          = active_fs->frame.poc;
-	//  active_fs->top_field.poc     = active_fs->frame.poc;
-	// This line changed on 11/05/05 KMc 
-	active_fs->top_field.poc     = pInfo->img.toppoc;
-	active_fs->bottom_field.poc  = pInfo->img.bottompoc;
 
-	active_fs->top_field.used_for_reference    = active_fs->frame.used_for_reference & 1;
-	active_fs->bottom_field.used_for_reference = active_fs->frame.used_for_reference >> 1;
+    //active_fs->frame.poc          = active_fs->frame.poc;
+    //  active_fs->top_field.poc     = active_fs->frame.poc;
+    // This line changed on 11/05/05 KMc
+    active_fs->top_field.poc     = pInfo->img.toppoc;
+    active_fs->bottom_field.poc  = pInfo->img.bottompoc;
 
-	active_fs->top_field.is_long_term = active_fs->frame.is_long_term;
-	active_fs->bottom_field.is_long_term = active_fs->frame.is_long_term;
+    active_fs->top_field.used_for_reference    = active_fs->frame.used_for_reference & 1;
+    active_fs->bottom_field.used_for_reference = active_fs->frame.used_for_reference >> 1;
 
-	active_fs->long_term_frame_idx = active_fs->frame.long_term_frame_idx;
-	active_fs->top_field.long_term_frame_idx = active_fs->frame.long_term_frame_idx;
-	active_fs->bottom_field.long_term_frame_idx = active_fs->frame.long_term_frame_idx;
+    active_fs->top_field.is_long_term = active_fs->frame.is_long_term;
+    active_fs->bottom_field.is_long_term = active_fs->frame.is_long_term;
+
+    active_fs->long_term_frame_idx = active_fs->frame.long_term_frame_idx;
+    active_fs->top_field.long_term_frame_idx = active_fs->frame.long_term_frame_idx;
+    active_fs->bottom_field.long_term_frame_idx = active_fs->frame.long_term_frame_idx;
 
 
-	// Assign field mvs attached to MB-Frame buffer to the proper buffer
-	//! Generate field MVs from Frame MVs
-	// ...
-	// these will be done in RTL through using proper memory mapping
-	return;
+    // Assign field mvs attached to MB-Frame buffer to the proper buffer
+    //! Generate field MVs from Frame MVs
+    // ...
+    // these will be done in RTL through using proper memory mapping
+    return;
 }
 
 
@@ -3114,23 +3131,23 @@
 void h264_dpb_combine_field(int32_t use_old)
 {
 
-   //remove warning
-   use_old = use_old;
-  
-	active_fs->frame.poc = (active_fs->top_field.poc < active_fs->bottom_field.poc)? 
-					 active_fs->top_field.poc: active_fs->bottom_field.poc;
+    //remove warning
+    use_old = use_old;
 
-	//active_fs->frame.poc = active_fs->poc;
+    active_fs->frame.poc = (active_fs->top_field.poc < active_fs->bottom_field.poc)?
+                           active_fs->top_field.poc: active_fs->bottom_field.poc;
+
+    //active_fs->frame.poc = active_fs->poc;
 
 
-	active_fs->frame.used_for_reference = active_fs->top_field.used_for_reference |(active_fs->bottom_field.used_for_reference);
+    active_fs->frame.used_for_reference = active_fs->top_field.used_for_reference |(active_fs->bottom_field.used_for_reference);
 
-	active_fs->frame.is_long_term = active_fs->top_field.is_long_term |(active_fs->bottom_field.is_long_term <<1);
+    active_fs->frame.is_long_term = active_fs->top_field.is_long_term |(active_fs->bottom_field.is_long_term <<1);
 
-	if (active_fs->frame.is_long_term) 
-		active_fs->frame.long_term_frame_idx = active_fs->long_term_frame_idx;
+    if (active_fs->frame.is_long_term)
+        active_fs->frame.long_term_frame_idx = active_fs->long_term_frame_idx;
 
-	return;
+    return;
 
 }
 
@@ -3143,33 +3160,33 @@
 //
 // Perform Sliding window decoded reference picture marking process
 // It must be the reference frame, complementary reference field pair
-// or non-paired reference field that has the smallest value of 
-// FrameNumWrap which is marked as unused for reference. Note : We CANNOT 
-// simply use frame_num!!!! 
+// or non-paired reference field that has the smallest value of
+// FrameNumWrap which is marked as unused for reference. Note : We CANNOT
+// simply use frame_num!!!!
 //
-// Although we hold frame_num_wrap in SW, currently, this is not 
-// being updated for every picture (the b-picture parameter non-update 
-// phenomenon of the reference software)  
+// Although we hold frame_num_wrap in SW, currently, this is not
+// being updated for every picture (the b-picture parameter non-update
+// phenomenon of the reference software)
 //////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_sliding_window_memory_management(h264_DecodedPictureBuffer *p_dpb, int32_t NonExisting, int32_t num_ref_frames)
 {
-	// if this is a reference pic with sliding window, unmark first ref frame
-	// should this be (p_dpb->ref_frames_in_buffer + p_dpb->ltref_frames_in_buffer)
-	// Rem: adaptive marking can be on a slice by slice basis so we
-	// could have pictures merked as long term reference in adaptive marking and then
-	//  the marking mode changed back to sliding_window_memory_management
-	if (p_dpb->ref_frames_in_buffer >= (num_ref_frames - p_dpb->ltref_frames_in_buffer))
-	{
-		h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_ref_idc[0]);
-		h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[0]);
+    // if this is a reference pic with sliding window, unmark first ref frame
+    // should this be (p_dpb->ref_frames_in_buffer + p_dpb->ltref_frames_in_buffer)
+    // Rem: adaptive marking can be on a slice by slice basis so we
+    // could have pictures merked as long term reference in adaptive marking and then
+    //  the marking mode changed back to sliding_window_memory_management
+    if (p_dpb->ref_frames_in_buffer >= (num_ref_frames - p_dpb->ltref_frames_in_buffer))
+    {
+        h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_ref_idc[0]);
+        h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[0]);
 
-		if(NonExisting == 0)
-		{
-			h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
-			viddec_h264_set_is_frame_long_term(active_fs, 0);
-		}
-	}
+        if (NonExisting == 0)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dec_idc);
+            viddec_h264_set_is_frame_long_term(active_fs, 0);
+        }
+    }
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -3178,7 +3195,7 @@
 //////////////////////////////////////////////////////////////////////////////
 // h264_dpb_store_picture_in_dpb ()
 //
-// First we run the marking procedure. 
+// First we run the marking procedure.
 // Then, before we add the current frame_store to the list of refernce stores we run some checks
 // These include checking the number of existing reference frames
 // in DPB and if necessary, flushing frames.
@@ -3200,105 +3217,105 @@
 
 void h264_dpb_frame_output(h264_Info * pInfo,int32_t fs_idc, int32_t direct, int32_t * existing)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	h264_dpb_set_active_fs(p_dpb, fs_idc);
+    h264_dpb_set_active_fs(p_dpb, fs_idc);
 
-	//h264_dpb_push_output_queue();
-	if(pInfo->sei_information.disp_frozen)
-	{
-		// check pocs
-		if(active_fs->top_field.poc >= pInfo->sei_information.freeze_POC)
-		{
-		  if(active_fs->top_field.poc <  pInfo->sei_information.release_POC)
-		  {
-			viddec_h264_set_is_top_skipped(active_fs, 1);
-		  }
-		  else
-		  {
-			pInfo->sei_information.disp_frozen = 0;
-		  }
-		}
+    //h264_dpb_push_output_queue();
+    if (pInfo->sei_information.disp_frozen)
+    {
+        // check pocs
+        if (active_fs->top_field.poc >= pInfo->sei_information.freeze_POC)
+        {
+            if (active_fs->top_field.poc <  pInfo->sei_information.release_POC)
+            {
+                viddec_h264_set_is_top_skipped(active_fs, 1);
+            }
+            else
+            {
+                pInfo->sei_information.disp_frozen = 0;
+            }
+        }
 
-		if(active_fs->bottom_field.poc >=  pInfo->sei_information.freeze_POC)
-		{
-		  if(active_fs->bottom_field.poc <  pInfo->sei_information.release_POC)
-		  {
-			viddec_h264_set_is_bottom_skipped(active_fs, 1);
-		  }
-		  else
-		  {
-			pInfo->sei_information.disp_frozen = 0;
-		  }
-		}
-	}
+        if (active_fs->bottom_field.poc >=  pInfo->sei_information.freeze_POC)
+        {
+            if (active_fs->bottom_field.poc <  pInfo->sei_information.release_POC)
+            {
+                viddec_h264_set_is_bottom_skipped(active_fs, 1);
+            }
+            else
+            {
+                pInfo->sei_information.disp_frozen = 0;
+            }
+        }
+    }
 
-	if ( viddec_h264_get_broken_link_picture(active_fs) )
-		 pInfo->sei_information.broken_link = 1;
+    if ( viddec_h264_get_broken_link_picture(active_fs) )
+        pInfo->sei_information.broken_link = 1;
 
-	if( pInfo->sei_information.broken_link)
-	{
-		// Check if this was the recovery point picture - going to have recovery point on
-		// a frame basis
-		if(viddec_h264_get_recovery_pt_picture(active_fs))
-		{
-			 pInfo->sei_information.broken_link = 0;
-			// Also reset wait on sei recovery point picture
-			p_dpb->WaitSeiRecovery         = 0;
-		}
-		else
-		{
-			viddec_h264_set_is_frame_skipped(active_fs, 3);
-		}
-	}
-	else
-	{
-	// even if this is not a broken - link, we need to follow SEI recovery point rules 
-		// Did we use SEI recovery point for th elast restart?
-		if ( p_dpb->WaitSeiRecovery )
-		{
-		  if ( viddec_h264_get_recovery_pt_picture(active_fs) ) {
-			p_dpb->WaitSeiRecovery         = 0;
-		  } else {
-			viddec_h264_set_is_frame_skipped(active_fs, 3);
-		  }
-		}
-	}
+    if ( pInfo->sei_information.broken_link)
+    {
+        // Check if this was the recovery point picture - going to have recovery point on
+        // a frame basis
+        if (viddec_h264_get_recovery_pt_picture(active_fs))
+        {
+            pInfo->sei_information.broken_link = 0;
+            // Also reset wait on sei recovery point picture
+            p_dpb->WaitSeiRecovery         = 0;
+        }
+        else
+        {
+            viddec_h264_set_is_frame_skipped(active_fs, 3);
+        }
+    }
+    else
+    {
+        // even if this is not a broken - link, we need to follow SEI recovery point rules
+        // Did we use SEI recovery point for th elast restart?
+        if ( p_dpb->WaitSeiRecovery )
+        {
+            if ( viddec_h264_get_recovery_pt_picture(active_fs) ) {
+                p_dpb->WaitSeiRecovery         = 0;
+            } else {
+                viddec_h264_set_is_frame_skipped(active_fs, 3);
+            }
+        }
+    }
 
-	if ( p_dpb->SuspendOutput )
-	{
-		if ( viddec_h264_get_open_gop_entry(active_fs) ) {
-			p_dpb->SuspendOutput      = 0;
-		} else{
-			viddec_h264_set_is_frame_skipped(active_fs, 3);
-		}
-	}
+    if ( p_dpb->SuspendOutput )
+    {
+        if ( viddec_h264_get_open_gop_entry(active_fs) ) {
+            p_dpb->SuspendOutput      = 0;
+        } else {
+            viddec_h264_set_is_frame_skipped(active_fs, 3);
+        }
+    }
 
-	//h264_send_new_display_frame(0x0);
-	viddec_h264_set_is_output(active_fs, 1);
+    //h264_send_new_display_frame(0x0);
+    viddec_h264_set_is_output(active_fs, 1);
 
-	if(viddec_h264_get_is_non_existent(active_fs) == 0)
-	{    
-		*existing = 1;
-      p_dpb->frame_id_need_to_be_displayed[p_dpb->frame_numbers_need_to_be_displayed]=active_fs->fs_idc;
-      p_dpb->frame_numbers_need_to_be_displayed++;     
-		
-		//if(direct) 
-			//h264_dpb_remove_frame_from_dpb(p_dpb, active_fs->fs_idc);		// Remove dpb.fs_dpb_idc[pos]
-	}
-	else
-	{
-		*existing = 0;
-	}
+    if (viddec_h264_get_is_non_existent(active_fs) == 0)
+    {
+        *existing = 1;
+        p_dpb->frame_id_need_to_be_displayed[p_dpb->frame_numbers_need_to_be_displayed]=active_fs->fs_idc;
+        p_dpb->frame_numbers_need_to_be_displayed++;
 
-	if(direct) {
-		viddec_h264_set_is_frame_used(active_fs, 0);
-		active_fs->frame.used_for_reference = 0;		
-		active_fs->top_field.used_for_reference = 0;		
-		active_fs->bottom_field.used_for_reference = 0;		
-		active_fs->fs_idc = MPD_DPB_FS_NULL_IDC;
-	}	
-	return;
+        //if(direct)
+        //h264_dpb_remove_frame_from_dpb(p_dpb, active_fs->fs_idc);		// Remove dpb.fs_dpb_idc[pos]
+    }
+    else
+    {
+        *existing = 0;
+    }
+
+    if (direct) {
+        viddec_h264_set_is_frame_used(active_fs, 0);
+        active_fs->frame.used_for_reference = 0;
+        active_fs->top_field.used_for_reference = 0;
+        active_fs->bottom_field.used_for_reference = 0;
+        active_fs->fs_idc = MPD_DPB_FS_NULL_IDC;
+    }
+    return;
 } ///////// End of dpb frame output
 
 
@@ -3308,7 +3325,7 @@
 //////////////////////////////////////////////////////////////////////////////
 // h264_dpb_output_one_frame_from_dpb ()
 //
-// Output one frame stored in the DPB. Basiclly this results in its placment 
+// Output one frame stored in the DPB. Basiclly this results in its placment
 // in the fs_output_idc list.
 // Placement in the output queue should cause an automatic removal from the dpb
 // if the frame store is not being used as a reference
@@ -3316,88 +3333,88 @@
 //////////////////////////////////////////////////////////////////////////////
 int32_t h264_dpb_output_one_frame_from_dpb(h264_Info* pInfo,int32_t direct, int32_t request, int32_t num_ref_frames)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
-	int32_t poc;
-	int32_t pos;
-	int32_t used_for_reference;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    int32_t poc;
+    int32_t pos;
+    int32_t used_for_reference;
 
-	int32_t existing = 0;
-	int32_t is_refused = 0;
-	int32_t is_pushed = 0;
+    int32_t existing = 0;
+    int32_t is_refused = 0;
+    int32_t is_pushed = 0;
 
-   //remove warning
-   request = request;
+    //remove warning
+    request = request;
 
-	if(direct)
-	{
-	  h264_dpb_frame_output(pInfo, p_dpb->fs_dec_idc, 1, &existing);
-	}
-	else 
-	{  
-		if(p_dpb->used_size != 0)
-		{
-		  // Should this be dpb.not_as_yet_output_num > 0 ??
-		  // There should maybe be a is_refused == 0 condition instead...
-		  while ((p_dpb->used_size > 0) && (existing == 0) && (is_refused == 0))
-		  {
-			// find smallest non-output POC
-			h264_dpb_get_smallest_poc(p_dpb, &poc, &pos);
-			if (pos != MPD_DPB_FS_NULL_IDC)
-			{			
-				// put it into the output queue
-				h264_dpb_frame_output(pInfo, p_dpb->fs_dpb_idc[pos], 0, &existing);
+    if (direct)
+    {
+        h264_dpb_frame_output(pInfo, p_dpb->fs_dec_idc, 1, &existing);
+    }
+    else
+    {
+        if (p_dpb->used_size != 0)
+        {
+            // Should this be dpb.not_as_yet_output_num > 0 ??
+            // There should maybe be a is_refused == 0 condition instead...
+            while ((p_dpb->used_size > 0) && (existing == 0) && (is_refused == 0))
+            {
+                // find smallest non-output POC
+                h264_dpb_get_smallest_poc(p_dpb, &poc, &pos);
+                if (pos != MPD_DPB_FS_NULL_IDC)
+                {
+                    // put it into the output queue
+                    h264_dpb_frame_output(pInfo, p_dpb->fs_dpb_idc[pos], 0, &existing);
 
-				p_dpb->last_output_poc = poc;  
-				if (existing) is_pushed = 1;
-				// If non-reference, free frame store and move empty store to end of buffer
+                    p_dpb->last_output_poc = poc;
+                    if (existing) is_pushed = 1;
+                    // If non-reference, free frame store and move empty store to end of buffer
 
-				h264_dpb_is_used_for_reference(&used_for_reference);
-				if (!(used_for_reference)) 
-					h264_dpb_remove_frame_from_dpb(p_dpb, pos);		// Remove dpb.fs_dpb_idc[pos]
-			}
-			else
-			{
-			  int32_t flag;
-			  uint32_t idx;
+                    h264_dpb_is_used_for_reference(&used_for_reference);
+                    if (!(used_for_reference))
+                        h264_dpb_remove_frame_from_dpb(p_dpb, pos);		// Remove dpb.fs_dpb_idc[pos]
+                }
+                else
+                {
+                    int32_t flag;
+                    uint32_t idx;
 
-			  // This is basically an error condition caused by too many reference frames in the DPB.
-			  // It should only happen in errored streams, and can happen if this picture had an MMCO,
-			  // thus disabling h264_dpb_sliding_window_memory_management(), which would normally have
-			  // unmarked the oldest reference frame.
-			  h264_dpb_sliding_window_memory_management(p_dpb, 0,num_ref_frames);
-			  h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
+                    // This is basically an error condition caused by too many reference frames in the DPB.
+                    // It should only happen in errored streams, and can happen if this picture had an MMCO,
+                    // thus disabling h264_dpb_sliding_window_memory_management(), which would normally have
+                    // unmarked the oldest reference frame.
+                    h264_dpb_sliding_window_memory_management(p_dpb, 0,num_ref_frames);
+                    h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
 
-			  if (flag == 0) {
-				 for (idx = 0; idx < p_dpb->used_size; idx++)
-				 {
-				   h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
-				   h264_dpb_is_used_for_reference(&used_for_reference);
-		       
-				   if (used_for_reference) {
-					  break;
-				   }
-				 }          
+                    if (flag == 0) {
+                        for (idx = 0; idx < p_dpb->used_size; idx++)
+                        {
+                            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
+                            h264_dpb_is_used_for_reference(&used_for_reference);
 
-				if (idx < p_dpb->used_size) {
-					 // Short term
-					h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_dpb_idc[idx]);
-					h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_dpb_idc[idx]);
+                            if (used_for_reference) {
+                                break;
+                            }
+                        }
 
-					// Long term
-					h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_dpb_idc[idx]);
-					h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_dpb_idc[idx]);
+                        if (idx < p_dpb->used_size) {
+                            // Short term
+                            h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_dpb_idc[idx]);
+                            h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_dpb_idc[idx]);
 
-					// Remove from DPB
-					h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
-				}
-			  }
-			  return 1;
-			}
-		  }
-		}
-	}
-	
-	return is_pushed;
+                            // Long term
+                            h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_dpb_idc[idx]);
+                            h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_dpb_idc[idx]);
+
+                            // Remove from DPB
+                            h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
+                        }
+                    }
+                    return 1;
+                }
+            }
+        }
+    }
+
+    return is_pushed;
 }
 
 
@@ -3408,25 +3425,25 @@
 //////////////////////////////////////////////////////////////////////////////
 // h264_dpb_queue_update
 //
-// This should be called anytime the output queue might be changed 
+// This should be called anytime the output queue might be changed
 //////////////////////////////////////////////////////////////////////////////
 
 int32_t h264_dpb_queue_update(h264_Info* pInfo,int32_t push, int32_t direct, int32_t frame_request, int32_t num_ref_frames)
 {
 
-	int32_t frame_output = 0;
+    int32_t frame_output = 0;
 
-	if(push)
-	{
-		frame_output = h264_dpb_output_one_frame_from_dpb(pInfo, direct, 0, num_ref_frames);
-	}
-	else if(frame_request)
-	{
-		frame_output = h264_dpb_output_one_frame_from_dpb(pInfo, 0, 1,num_ref_frames);
-	}
+    if (push)
+    {
+        frame_output = h264_dpb_output_one_frame_from_dpb(pInfo, direct, 0, num_ref_frames);
+    }
+    else if (frame_request)
+    {
+        frame_output = h264_dpb_output_one_frame_from_dpb(pInfo, 0, 1,num_ref_frames);
+    }
 
 
-	return frame_output;
+    return frame_output;
 
 }
 
@@ -3439,47 +3456,47 @@
 //
 // Unmarks all reference pictures in the short-term and long term lists and
 // in doing so resets the lists.
-// 
+//
 // Flushing the dpb, adds all the current frames in the dpb, not already on the output list
-// to the output list and removes them from the dpb (they will all be marked as unused for 
+// to the output list and removes them from the dpb (they will all be marked as unused for
 // reference first)
 //////////////////////////////////////////////////////////////////////////////
 
 void h264_dpb_flush_dpb (h264_Info* pInfo,int32_t output_all, int32_t keep_complement, int32_t num_ref_frames)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	int32_t idx, flag;
-	int32_t ref_frames_in_buffer;
+    int32_t idx, flag;
+    int32_t ref_frames_in_buffer;
 
-	ref_frames_in_buffer = p_dpb->ref_frames_in_buffer;
+    ref_frames_in_buffer = p_dpb->ref_frames_in_buffer;
 
-	for (idx = 0; idx < ref_frames_in_buffer; idx++){
-		h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_ref_idc[0]);		
-		h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[0]);
-	}
+    for (idx = 0; idx < ref_frames_in_buffer; idx++) {
+        h264_dpb_unmark_for_reference(p_dpb, p_dpb->fs_ref_idc[0]);
+        h264_dpb_remove_ref_list(p_dpb, p_dpb->fs_ref_idc[0]);
+    }
 
-	ref_frames_in_buffer = p_dpb->ltref_frames_in_buffer;
+    ref_frames_in_buffer = p_dpb->ltref_frames_in_buffer;
 
-	for (idx = 0; idx < ref_frames_in_buffer; idx++)
-	{
-		h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[0]);
-		h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[0]);
-	}
+    for (idx = 0; idx < ref_frames_in_buffer; idx++)
+    {
+        h264_dpb_unmark_for_long_term_reference(p_dpb, p_dpb->fs_ltref_idc[0]);
+        h264_dpb_remove_ltref_list(p_dpb, p_dpb->fs_ltref_idc[0]);
+    }
 
-	// output frames in POC order
-	if (output_all) {
-		while (p_dpb->used_size - keep_complement) {
-			h264_dpb_queue_update(pInfo, 1, 0, 0,num_ref_frames);
-		}
-	}
-	
-	flag = 1;
-	while (flag) {
-		h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
-	}
+    // output frames in POC order
+    if (output_all) {
+        while (p_dpb->used_size - keep_complement) {
+            h264_dpb_queue_update(pInfo, 1, 0, 0,num_ref_frames);
+        }
+    }
 
-	return;
+    flag = 1;
+    while (flag) {
+        h264_dpb_remove_unused_frame_from_dpb(p_dpb, &flag);
+    }
+
+    return;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -3488,66 +3505,66 @@
 //////////////////////////////////////////////////////////////////////////////
 // h264_dpb_reset_dpb ()
 //
-// Used to reset the contents of dpb 
+// Used to reset the contents of dpb
 // Must calculate memory (aligned) pointers for each of the possible frame stores
 //
-// Also want to calculate possible max dpb size in terms of frames 
+// Also want to calculate possible max dpb size in terms of frames
 // We should have an active SPS when we call this ftn to calc bumping level
 //////////////////////////////////////////////////////////////////////////////
 void h264_dpb_reset_dpb(h264_Info * pInfo,int32_t PicWidthInMbs, int32_t FrameHeightInMbs, int32_t SizeChange, int32_t no_output_of_prior_pics_flag)
 {
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
-	int32_t num_ref_frames = pInfo->active_SPS.num_ref_frames;
+    int32_t num_ref_frames = pInfo->active_SPS.num_ref_frames;
 
 
-	// If half way through a frame then Frame in progress will still be high,
-	// so mark the previous field as a dangling field. This is also needed to 
-	// keep cs7050_sif_dpb_disp_numb_ptr correct. Better to reset instead?
-	if(p_dpb->used_size)                                                                                                                                       
-	{
-		int32_t idx;
-		idx = p_dpb->used_size-1;
-		if (p_dpb->fs_dpb_idc[idx] != MPD_DPB_FS_NULL_IDC)                                                                                                                  
-		{                                                                                                                                                     
-		  h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
+    // If half way through a frame then Frame in progress will still be high,
+    // so mark the previous field as a dangling field. This is also needed to
+    // keep cs7050_sif_dpb_disp_numb_ptr correct. Better to reset instead?
+    if (p_dpb->used_size)
+    {
+        int32_t idx;
+        idx = p_dpb->used_size-1;
+        if (p_dpb->fs_dpb_idc[idx] != MPD_DPB_FS_NULL_IDC)
+        {
+            h264_dpb_set_active_fs(p_dpb, p_dpb->fs_dpb_idc[idx]);
 
-		  if(viddec_h264_get_is_used(active_fs) != 3)
-			h264_dpb_mark_dangling_field(p_dpb, active_fs->fs_idc);       //, DANGLING_TYPE_DPB_RESET                                                                                             
-		}                                                                                                                                                      
-	}                                                                                                                                                       
+            if (viddec_h264_get_is_used(active_fs) != 3)
+                h264_dpb_mark_dangling_field(p_dpb, active_fs->fs_idc);       //, DANGLING_TYPE_DPB_RESET
+        }
+    }
 
-	// initialize software DPB
-	if(active_fs) {
-		viddec_h264_set_dec_structure(active_fs, INVALID);
-	}
-	h264_dpb_idr_memory_management(pInfo, &pInfo->active_SPS, no_output_of_prior_pics_flag);  // implied no_output_of_prior_pics_flag==1
+    // initialize software DPB
+    if (active_fs) {
+        viddec_h264_set_dec_structure(active_fs, INVALID);
+    }
+    h264_dpb_idr_memory_management(pInfo, &pInfo->active_SPS, no_output_of_prior_pics_flag);  // implied no_output_of_prior_pics_flag==1
 
 
-	// May always be a size change which calls this function now...
-	// could eliminate below branch
-	if(SizeChange) 
-	{
+    // May always be a size change which calls this function now...
+    // could eliminate below branch
+    if (SizeChange)
+    {
 
-		/***
-		Note : 21/03/2005 14:16
-		Danger asociated with resetting curr_alloc_mem as it would allow the FW top reallocate 
-		frame stores from 0 -> NUM_FRAME_STORES again - could lead to queue overflow and corruption
+        /***
+        Note : 21/03/2005 14:16
+        Danger asociated with resetting curr_alloc_mem as it would allow the FW top reallocate
+        frame stores from 0 -> NUM_FRAME_STORES again - could lead to queue overflow and corruption
 
-		Placed in size change condition in the hope that this will only ensure dpb is empty 
-		and thus this behaviour is valid before continuing again
-		***/
+        Placed in size change condition in the hope that this will only ensure dpb is empty
+        and thus this behaviour is valid before continuing again
+        ***/
 
 
-		p_dpb->PicWidthInMbs      = PicWidthInMbs;
-		p_dpb->FrameHeightInMbs   = FrameHeightInMbs;
+        p_dpb->PicWidthInMbs      = PicWidthInMbs;
+        p_dpb->FrameHeightInMbs   = FrameHeightInMbs;
 
-		p_dpb->fs_dec_idc = MPD_DPB_FS_NULL_IDC;
-		//Flush the current DPB.
-		h264_dpb_flush_dpb(pInfo, 1,0,num_ref_frames);
-	}
+        p_dpb->fs_dec_idc = MPD_DPB_FS_NULL_IDC;
+        //Flush the current DPB.
+        h264_dpb_flush_dpb(pInfo, 1,0,num_ref_frames);
+    }
 
-  return;
+    return;
 } ///// End of reset DPB
 
 /* ------------------------------------------------------------------------------------------ */
@@ -3564,29 +3581,29 @@
 // ---------------------------------------------------------------------------
 int32_t dpb_setup_free_fb( h264_DecodedPictureBuffer *p_dpb, uint8_t* fb_id, pip_setting_t* pip_setting )
 {
-	uint8_t  idx;
+    uint8_t  idx;
 
-   //remove warning
-   pip_setting = pip_setting;
+    //remove warning
+    pip_setting = pip_setting;
 
 
-	for (idx = 0; idx < NUM_DPB_FRAME_STORES; idx++)
-	{
-		if (p_dpb->fs[idx].fs_idc == MPD_DPB_FS_NULL_IDC) 
-		{
-		  *fb_id = idx;
-		  break;
-		}
-	}
+    for (idx = 0; idx < NUM_DPB_FRAME_STORES; idx++)
+    {
+        if (p_dpb->fs[idx].fs_idc == MPD_DPB_FS_NULL_IDC)
+        {
+            *fb_id = idx;
+            break;
+        }
+    }
 
-	if(idx == NUM_DPB_FRAME_STORES) 
-		return 1;
+    if (idx == NUM_DPB_FRAME_STORES)
+        return 1;
 
-	p_dpb->fs[idx].fs_idc = idx;
+    p_dpb->fs[idx].fs_idc = idx;
 
-	return 0;
-  
-} 
+    return 0;
+
+}
 
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
@@ -3595,71 +3612,71 @@
 // h264_dpb_assign_frame_store ()
 //
 // may need a non-existing option parameter
-// 
+//
 
 int32_t h264_dpb_assign_frame_store(h264_Info * pInfo, int32_t NonExisting)
 {
-	uint8_t idc = MPD_DPB_FS_NULL_IDC;
-	pip_setting_t pip_setting;
-	h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
+    uint8_t idc = MPD_DPB_FS_NULL_IDC;
+    pip_setting_t pip_setting;
+    h264_DecodedPictureBuffer *p_dpb = &pInfo->dpb;
 
 
-	while( dpb_setup_free_fb(p_dpb, &idc, &pip_setting)  != 0 ) {
-		///
-		/// Generally this is triggered a error case, no more frame buffer avaliable for next
-		/// What we do here is just remove one with min-POC before get more info
-		///
+    while ( dpb_setup_free_fb(p_dpb, &idc, &pip_setting)  != 0 ) {
+        ///
+        /// Generally this is triggered a error case, no more frame buffer avaliable for next
+        /// What we do here is just remove one with min-POC before get more info
+        ///
 
-		int32_t pos = 0, poc = 0, existing = 1;	 
-	
-		// find smallest non-output POC	 
-		h264_dpb_get_smallest_poc(p_dpb, &poc, &pos);		 
-		if (pos != MPD_DPB_FS_NULL_IDC)	 
-		{					
-			// put it into the output queue		 
-			h264_dpb_frame_output(pInfo, p_dpb->fs_dpb_idc[pos], 0, &existing);		 
-			p_dpb->last_output_poc = poc; 		 
-			h264_dpb_remove_frame_from_dpb(p_dpb, pos);	 // Remove dpb.fs_dpb_idc[pos]	 
-		}	
-	}
+        int32_t pos = 0, poc = 0, existing = 1;
 
-
-	if(NonExisting) {
-		p_dpb->fs_non_exist_idc = idc;
-	}else { 
-		p_dpb->fs_dec_idc = idc;
-	}
-
-    //add to support frame relocation interface to host
-    if(!NonExisting)
-    {
-      p_dpb->frame_numbers_need_to_be_allocated = 1;
-      p_dpb->frame_id_need_to_be_allocated = p_dpb->fs_dec_idc;
+        // find smallest non-output POC
+        h264_dpb_get_smallest_poc(p_dpb, &poc, &pos);
+        if (pos != MPD_DPB_FS_NULL_IDC)
+        {
+            // put it into the output queue
+            h264_dpb_frame_output(pInfo, p_dpb->fs_dpb_idc[pos], 0, &existing);
+            p_dpb->last_output_poc = poc;
+            h264_dpb_remove_frame_from_dpb(p_dpb, pos);	 // Remove dpb.fs_dpb_idc[pos]
+        }
     }
 
-    
-    ///////////////////////////////h264_dpb_reset_fs();    
-	h264_dpb_set_active_fs(p_dpb, idc);
-   active_fs->fs_flag_1 = 0;
-   active_fs->fs_flag_2 = 0;
-	viddec_h264_set_is_non_existent(active_fs, NonExisting);
-	viddec_h264_set_is_output(active_fs, (NonExisting?1:0));
-   
-	active_fs->pic_type = ((FRAME_TYPE_INVALID<<FRAME_TYPE_TOP_OFFSET)|(FRAME_TYPE_INVALID<<FRAME_TYPE_BOTTOM_OFFSET));			//----
 
-	// Only put members in here which will not be reset somewhere else
-	// and which could be used before they are overwritten again with
-	// new valid values
-	// eg ->is_used is reset on removal from dpb, no need for it here
-	//    ->poc would only be changed when we overwrite on insert_Picture_in_dpb()
-	//    but would be used by get_smallest_poc() 
-	//    ->top.poc would also not be overwritten until a new valid value comes along,
-	//    but I don't think it is used before then so no need to reset
-	//active_fs->is_long_term    = 0;
-	active_fs->frame.used_for_reference    = 0;
-	active_fs->frame.poc			= 0;		
-	
-	return 1;
+    if (NonExisting) {
+        p_dpb->fs_non_exist_idc = idc;
+    } else {
+        p_dpb->fs_dec_idc = idc;
+    }
+
+    //add to support frame relocation interface to host
+    if (!NonExisting)
+    {
+        p_dpb->frame_numbers_need_to_be_allocated = 1;
+        p_dpb->frame_id_need_to_be_allocated = p_dpb->fs_dec_idc;
+    }
+
+
+    ///////////////////////////////h264_dpb_reset_fs();
+    h264_dpb_set_active_fs(p_dpb, idc);
+    active_fs->fs_flag_1 = 0;
+    active_fs->fs_flag_2 = 0;
+    viddec_h264_set_is_non_existent(active_fs, NonExisting);
+    viddec_h264_set_is_output(active_fs, (NonExisting?1:0));
+
+    active_fs->pic_type = ((FRAME_TYPE_INVALID<<FRAME_TYPE_TOP_OFFSET)|(FRAME_TYPE_INVALID<<FRAME_TYPE_BOTTOM_OFFSET));			//----
+
+    // Only put members in here which will not be reset somewhere else
+    // and which could be used before they are overwritten again with
+    // new valid values
+    // eg ->is_used is reset on removal from dpb, no need for it here
+    //    ->poc would only be changed when we overwrite on insert_Picture_in_dpb()
+    //    but would be used by get_smallest_poc()
+    //    ->top.poc would also not be overwritten until a new valid value comes along,
+    //    but I don't think it is used before then so no need to reset
+    //active_fs->is_long_term    = 0;
+    active_fs->frame.used_for_reference    = 0;
+    active_fs->frame.poc			= 0;
+
+    return 1;
 }
 
 
@@ -3673,42 +3690,42 @@
 //
 void h264_dpb_update_queue_dangling_field(h264_Info * pInfo)
 {
-	h264_DecodedPictureBuffer *dpb_ptr = &pInfo->dpb;
-	int32_t prev_pic_unpaired_field = 0;
+    h264_DecodedPictureBuffer *dpb_ptr = &pInfo->dpb;
+    int32_t prev_pic_unpaired_field = 0;
 
-	if(dpb_ptr->used_size > dpb_ptr->BumpLevel)
-	{
-		if (dpb_ptr->fs_dpb_idc[dpb_ptr->used_size-1] != MPD_DPB_FS_NULL_IDC)
-		{
-			h264_dpb_set_active_fs(dpb_ptr, dpb_ptr->fs_dpb_idc[dpb_ptr->used_size-1]);
-			if(viddec_h264_get_is_used(active_fs) != 3) 
-			{
-				prev_pic_unpaired_field = 1;
-			}
-		}
+    if (dpb_ptr->used_size > dpb_ptr->BumpLevel)
+    {
+        if (dpb_ptr->fs_dpb_idc[dpb_ptr->used_size-1] != MPD_DPB_FS_NULL_IDC)
+        {
+            h264_dpb_set_active_fs(dpb_ptr, dpb_ptr->fs_dpb_idc[dpb_ptr->used_size-1]);
+            if (viddec_h264_get_is_used(active_fs) != 3)
+            {
+                prev_pic_unpaired_field = 1;
+            }
+        }
 
-		if (pInfo->img.structure != FRAME)
-		{
-			// To prove this is the second field, 
-			// 1) The previous picture is an (as yet) unpaired field
-			if(prev_pic_unpaired_field)
-			{			
-				// If we establish the previous pic was an unpaired field and this picture is not
-				// its complement, the previous picture was a dangling field
-				if(pInfo->img.second_field == 0) {
-					while(dpb_ptr->used_size > dpb_ptr->BumpLevel) 
-						h264_dpb_queue_update(pInfo, 1, 0, 0,pInfo->active_SPS.num_ref_frames); // flush a frame						
-				}
-			}
-		}
-		else if (prev_pic_unpaired_field) {
-			while(dpb_ptr->used_size > dpb_ptr->BumpLevel) 			
-				h264_dpb_queue_update(pInfo, 1, 0, 0,pInfo->active_SPS.num_ref_frames); // flush a frame		
-		}
-	}
+        if (pInfo->img.structure != FRAME)
+        {
+            // To prove this is the second field,
+            // 1) The previous picture is an (as yet) unpaired field
+            if (prev_pic_unpaired_field)
+            {
+                // If we establish the previous pic was an unpaired field and this picture is not
+                // its complement, the previous picture was a dangling field
+                if (pInfo->img.second_field == 0) {
+                    while (dpb_ptr->used_size > dpb_ptr->BumpLevel)
+                        h264_dpb_queue_update(pInfo, 1, 0, 0,pInfo->active_SPS.num_ref_frames); // flush a frame
+                }
+            }
+        }
+        else if (prev_pic_unpaired_field) {
+            while (dpb_ptr->used_size > dpb_ptr->BumpLevel)
+                h264_dpb_queue_update(pInfo, 1, 0, 0,pInfo->active_SPS.num_ref_frames); // flush a frame
+        }
+    }
 
 
-	return;
+    return;
 }	///// End of init Frame Store
 
 
@@ -3723,145 +3740,148 @@
 
 void h264_dpb_init_frame_store(h264_Info * pInfo)
 {
-	h264_DecodedPictureBuffer *dpb_ptr = &pInfo->dpb;
+    h264_DecodedPictureBuffer *dpb_ptr = &pInfo->dpb;
 
-	int32_t free_fs_found;
-	int32_t idx = 0;
-	int32_t prev_pic_unpaired_field = 0;
-	int32_t prev_idc = MPD_DPB_FS_NULL_IDC;
-	int32_t structure = pInfo->img.structure;
+    int32_t free_fs_found;
+    int32_t idx = 0;
+    int32_t prev_pic_unpaired_field = 0;
+    int32_t prev_idc = MPD_DPB_FS_NULL_IDC;
+    int32_t structure = pInfo->img.structure;
 
-	if(dpb_ptr->used_size)
-	{
-		idx = dpb_ptr->used_size-1;
-		prev_idc = dpb_ptr->fs_dpb_idc[idx];
-	}
+    if (dpb_ptr->used_size)
+    {
+        idx = dpb_ptr->used_size-1;
+        prev_idc = dpb_ptr->fs_dpb_idc[idx];
+    }
 
-	if (prev_idc != MPD_DPB_FS_NULL_IDC)
-	{
-		h264_dpb_set_active_fs(dpb_ptr, dpb_ptr->fs_dpb_idc[dpb_ptr->used_size-1]);
-		if(viddec_h264_get_is_used(active_fs) != 3) 
-		{
-			//PRINTF(MFD_NONE, " FN: %d active_fs->is_used = %d \n", (h264_frame_number+1), active_fs->is_used);
-			prev_pic_unpaired_field = 1;
-		}
-	}
+    if (prev_idc != MPD_DPB_FS_NULL_IDC)
+    {
+        h264_dpb_set_active_fs(dpb_ptr, dpb_ptr->fs_dpb_idc[dpb_ptr->used_size-1]);
+        if (viddec_h264_get_is_used(active_fs) != 3)
+        {
+            //PRINTF(MFD_NONE, " FN: %d active_fs->is_used = %d \n", (h264_frame_number+1), active_fs->is_used);
+            prev_pic_unpaired_field = 1;
+        }
+    }
 
-	//if ((pInfo->img.curr_has_mmco_5) || (pInfo->img.idr_flag))   curr_fld_not_prev_comp = 1;
+    //if ((pInfo->img.curr_has_mmco_5) || (pInfo->img.idr_flag))   curr_fld_not_prev_comp = 1;
 
-	if (structure != FRAME)
-	{
+    if (structure != FRAME)
+    {
 
-		// To prove this is the second field, 
-		// 1) The previous picture is an (as yet) unpaired field
-		if(prev_pic_unpaired_field)
-		{			
-			// If we establish the previous pic was an unpaired field and this picture is not
-			// its complement, the previous picture was a dangling field
-			if(pInfo->img.second_field == 0)
-				h264_dpb_mark_dangling_field(dpb_ptr, active_fs->fs_idc);  //, DANGLING_TYPE_FIELD
-		}
-	}
-	else if (prev_pic_unpaired_field) {
-		h264_dpb_mark_dangling_field(dpb_ptr, active_fs->fs_idc);		//, DANGLING_TYPE_FRAME
-	}
+        // To prove this is the second field,
+        // 1) The previous picture is an (as yet) unpaired field
+        if (prev_pic_unpaired_field)
+        {
+            // If we establish the previous pic was an unpaired field and this picture is not
+            // its complement, the previous picture was a dangling field
+            if (pInfo->img.second_field == 0)
+                h264_dpb_mark_dangling_field(dpb_ptr, active_fs->fs_idc);  //, DANGLING_TYPE_FIELD
+        }
+    }
+    else if (prev_pic_unpaired_field) {
+        h264_dpb_mark_dangling_field(dpb_ptr, active_fs->fs_idc);		//, DANGLING_TYPE_FRAME
+    }
 
-	free_fs_found = 0;
+    free_fs_found = 0;
 
-	// If this is not a second field, we must find a free space for the current picture
-	if (!(pInfo->img.second_field))
-	{
-		dpb_ptr->fs_dec_idc = MPD_DPB_FS_NULL_IDC;	
-		free_fs_found = h264_dpb_assign_frame_store(pInfo, 0);
-		//h264_frame_number++;
-		//PRINTF(MFD_NONE, " FN: %d (inc) fs_idc =  %d \n", (h264_frame_number+1), dpb.fs_dec_idc);
-	}
+    // If this is not a second field, we must find a free space for the current picture
+    if (!(pInfo->img.second_field))
+    {
+        dpb_ptr->fs_dec_idc = MPD_DPB_FS_NULL_IDC;
+        free_fs_found = h264_dpb_assign_frame_store(pInfo, 0);
+        //h264_frame_number++;
+        //PRINTF(MFD_NONE, " FN: %d (inc) fs_idc =  %d \n", (h264_frame_number+1), dpb.fs_dec_idc);
+    }
 
-	h264_dpb_set_active_fs(dpb_ptr, dpb_ptr->fs_dec_idc);
+    h264_dpb_set_active_fs(dpb_ptr, dpb_ptr->fs_dec_idc);
 
-	////////////// TODO: THe following init
+    ////////////// TODO: THe following init
 #if 1
-	if( pInfo->img.second_field) {
-		//active_fs->second_dsn = pInfo->img.dsn;
-		//active_fs->prev_dsn = pInfo->img.prev_dsn;
-		if (active_fs->pic_type == FRAME_TYPE_IDR ||
-		   active_fs->pic_type == FRAME_TYPE_I) {
+    if ( pInfo->img.second_field) {
+        //active_fs->second_dsn = pInfo->img.dsn;
+        //active_fs->prev_dsn = pInfo->img.prev_dsn;
+        if (active_fs->pic_type == FRAME_TYPE_IDR ||
+                active_fs->pic_type == FRAME_TYPE_I) {
 
-		   viddec_h264_set_first_field_intra(active_fs, 1);
-		} else {
-		   viddec_h264_set_first_field_intra(active_fs, 0);
-		}
-	    
-	} 
-	else {
-		//active_fs->first_dsn = pInfo->img.dsn;
-		//active_fs->prev_dsn = pInfo->img.prev_dsn;
-		viddec_h264_set_first_field_intra(active_fs, 0);	    
-	}
+            viddec_h264_set_first_field_intra(active_fs, 1);
+        } else {
+            viddec_h264_set_first_field_intra(active_fs, 0);
+        }
 
-	if (pInfo->img.structure == FRAME) {
-		//active_fs->second_dsn = 0x0;
-	}
+    }
+    else {
+        //active_fs->first_dsn = pInfo->img.dsn;
+        //active_fs->prev_dsn = pInfo->img.prev_dsn;
+        viddec_h264_set_first_field_intra(active_fs, 0);
+    }
 
-	if ( pInfo->sei_information.broken_link_pic )
-	{
-		viddec_h264_set_broken_link_picture(active_fs, 1);
-		pInfo->sei_information.broken_link_pic = 0;
-	}    
+    if (pInfo->img.structure == FRAME) {
+        //active_fs->second_dsn = 0x0;
+    }
 
-	if ((pInfo->img.frame_num == pInfo->sei_information.recovery_frame_num)&&(pInfo->SliceHeader.nal_ref_idc != 0))
-		viddec_h264_set_recovery_pt_picture(active_fs, 1);
+    if ( pInfo->sei_information.broken_link_pic )
+    {
+        viddec_h264_set_broken_link_picture(active_fs, 1);
+        pInfo->sei_information.broken_link_pic = 0;
+    }
 
-	//if ((( gRestartMode.aud ) || ( gRestartMode.sei )) && ( !gRestartMode.idr))
-	if(pInfo->img.recovery_point_found == 6)
-	{
-		viddec_h264_set_open_gop_entry(active_fs, 1);
-		pInfo->dpb.SuspendOutput         = 1;
-	}
+    if ((pInfo->img.frame_num == pInfo->sei_information.recovery_frame_num)&&(pInfo->SliceHeader.nal_ref_idc != 0))
+        viddec_h264_set_recovery_pt_picture(active_fs, 1);
+
+    //if ((( gRestartMode.aud ) || ( gRestartMode.sei )) && ( !gRestartMode.idr))
+    if (pInfo->img.recovery_point_found == 6)
+    {
+        viddec_h264_set_open_gop_entry(active_fs, 1);
+        pInfo->dpb.SuspendOutput         = 1;
+    }
 #endif
 
-	if ((pInfo->img.second_field) || (free_fs_found))
-	{
-		viddec_h264_set_dec_structure(active_fs, pInfo->img.structure);
-		viddec_h264_set_is_output(active_fs, 0);
+    if ((pInfo->img.second_field) || (free_fs_found))
+    {
+        viddec_h264_set_dec_structure(active_fs, pInfo->img.structure);
+        viddec_h264_set_is_output(active_fs, 0);
 
-		switch(pInfo->img.structure)
-		{
-		  case (FRAME)     :{
-								  active_fs->frame.pic_num = pInfo->img.frame_num;
-                      			  active_fs->frame.long_term_frame_idx = 0;
-                      			  active_fs->frame.long_term_pic_num = 0;
-                      			  active_fs->frame.used_for_reference = 0;
-                      			  active_fs->frame.is_long_term = 0;
-                      			  //active_fs->frame.structure = pInfo->img.structure;
-								  active_fs->frame.poc = pInfo->img.framepoc;
-								}break;
-		  case (TOP_FIELD) :{
-								  active_fs->top_field.pic_num = pInfo->img.frame_num;
-								  active_fs->top_field.long_term_frame_idx = 0;
-								  active_fs->top_field.long_term_pic_num = 0;
-								  active_fs->top_field.used_for_reference = 0;
-								  active_fs->top_field.is_long_term = 0;
-								  //active_fs->top_field.structure = pInfo->img.structure;
-								  active_fs->top_field.poc = pInfo->img.toppoc;
-								}break;
-		case(BOTTOM_FIELD) :{
-								  active_fs->bottom_field.pic_num = pInfo->img.frame_num;
-								  active_fs->bottom_field.long_term_frame_idx = 0;
-								  active_fs->bottom_field.long_term_pic_num = 0;
-								  active_fs->bottom_field.used_for_reference = 0;
-								  active_fs->bottom_field.is_long_term = 0;
-								  //active_fs->bottom_field.structure = pInfo->img.structure;
-								  active_fs->bottom_field.poc = pInfo->img.bottompoc;
-								}break;
-		}
-	}
-	else
-	{
-	 // Need to drop a frame or something here 
-	}
+        switch (pInfo->img.structure)
+        {
+        case (FRAME)     : {
+            active_fs->frame.pic_num = pInfo->img.frame_num;
+            active_fs->frame.long_term_frame_idx = 0;
+            active_fs->frame.long_term_pic_num = 0;
+            active_fs->frame.used_for_reference = 0;
+            active_fs->frame.is_long_term = 0;
+            //active_fs->frame.structure = pInfo->img.structure;
+            active_fs->frame.poc = pInfo->img.framepoc;
+        }
+        break;
+        case (TOP_FIELD) : {
+            active_fs->top_field.pic_num = pInfo->img.frame_num;
+            active_fs->top_field.long_term_frame_idx = 0;
+            active_fs->top_field.long_term_pic_num = 0;
+            active_fs->top_field.used_for_reference = 0;
+            active_fs->top_field.is_long_term = 0;
+            //active_fs->top_field.structure = pInfo->img.structure;
+            active_fs->top_field.poc = pInfo->img.toppoc;
+        }
+        break;
+        case(BOTTOM_FIELD) : {
+            active_fs->bottom_field.pic_num = pInfo->img.frame_num;
+            active_fs->bottom_field.long_term_frame_idx = 0;
+            active_fs->bottom_field.long_term_pic_num = 0;
+            active_fs->bottom_field.used_for_reference = 0;
+            active_fs->bottom_field.is_long_term = 0;
+            //active_fs->bottom_field.structure = pInfo->img.structure;
+            active_fs->bottom_field.poc = pInfo->img.bottompoc;
+        }
+        break;
+        }
+    }
+    else
+    {
+        // Need to drop a frame or something here
+    }
 
-	return;
+    return;
 }	///// End of init Frame Store
 
 
@@ -3876,254 +3896,254 @@
 
 void h264_hdr_decoding_poc (h264_Info * pInfo,int32_t NonExisting, int32_t frame_num)
 {
-	int32_t MaxPicOrderCntLsb = (1<<(pInfo->active_SPS.log2_max_pic_order_cnt_lsb_minus4+4));
-	int32_t delta_pic_order_count[2];
-	int32_t MaxFrameNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
+    int32_t MaxPicOrderCntLsb = (1<<(pInfo->active_SPS.log2_max_pic_order_cnt_lsb_minus4+4));
+    int32_t delta_pic_order_count[2];
+    int32_t MaxFrameNum = 1 << (pInfo->active_SPS.log2_max_frame_num_minus4 + 4);
 
-	int32_t AbsFrameNum =0;
-	int32_t ExpectedDeltaPerPicOrderCntCycle =0;
-	int32_t PicOrderCntCycleCnt = 0;
-	int32_t FrameNumInPicOrderCntCycle =0;
-	int32_t ExpectedPicOrderCnt =0;
-	
-	int32_t actual_frame_num =0;
+    int32_t AbsFrameNum =0;
+    int32_t ExpectedDeltaPerPicOrderCntCycle =0;
+    int32_t PicOrderCntCycleCnt = 0;
+    int32_t FrameNumInPicOrderCntCycle =0;
+    int32_t ExpectedPicOrderCnt =0;
 
-   
+    int32_t actual_frame_num =0;
 
-	if(NonExisting)    actual_frame_num = frame_num;
-	else               actual_frame_num = pInfo->img.frame_num;
 
-	switch (pInfo->active_SPS.pic_order_cnt_type)
-	{
-	case 0: 
-		if(NonExisting != 0) break;
 
-		if (pInfo->SliceHeader.idr_flag) 
+    if (NonExisting)    actual_frame_num = frame_num;
+    else               actual_frame_num = pInfo->img.frame_num;
+
+    switch (pInfo->active_SPS.pic_order_cnt_type)
+    {
+    case 0:
+        if (NonExisting != 0) break;
+
+        if (pInfo->SliceHeader.idr_flag)
         {
-			pInfo->img.PicOrderCntMsb = 0;
-			pInfo->img.PrevPicOrderCntLsb = 0;
+            pInfo->img.PicOrderCntMsb = 0;
+            pInfo->img.PrevPicOrderCntLsb = 0;
         }
-		else if (pInfo->img.last_has_mmco_5) 
-		{
-		  if (pInfo->img.last_pic_bottom_field)
-		  {
-			pInfo->img.PicOrderCntMsb     = 0;
-			pInfo->img.PrevPicOrderCntLsb = 0;
-		  }
-		  else
-		  {
-			pInfo->img.PicOrderCntMsb     = 0;
-			pInfo->img.PrevPicOrderCntLsb = pInfo->img.toppoc;
-		  }
-		}
+        else if (pInfo->img.last_has_mmco_5)
+        {
+            if (pInfo->img.last_pic_bottom_field)
+            {
+                pInfo->img.PicOrderCntMsb     = 0;
+                pInfo->img.PrevPicOrderCntLsb = 0;
+            }
+            else
+            {
+                pInfo->img.PicOrderCntMsb     = 0;
+                pInfo->img.PrevPicOrderCntLsb = pInfo->img.toppoc;
+            }
+        }
 
-		// Calculate the MSBs of current picture
-		if((pInfo->img.pic_order_cnt_lsb < pInfo->img.PrevPicOrderCntLsb)  &&  
-			((pInfo->img.PrevPicOrderCntLsb - pInfo->img.pic_order_cnt_lsb )>=(MaxPicOrderCntLsb>>1)) ) 
-		{
-			pInfo->img.CurrPicOrderCntMsb = pInfo->img.PicOrderCntMsb + MaxPicOrderCntLsb;
-		} else if ((pInfo->img.pic_order_cnt_lsb  >  pInfo->img.PrevPicOrderCntLsb)  &&
-			((pInfo->img.pic_order_cnt_lsb - pInfo->img.PrevPicOrderCntLsb ) > (MaxPicOrderCntLsb>>1)) ) 
-		{
-			pInfo->img.CurrPicOrderCntMsb = pInfo->img.PicOrderCntMsb - MaxPicOrderCntLsb;
-		} else 
-		{
-			pInfo->img.CurrPicOrderCntMsb = pInfo->img.PicOrderCntMsb;
-		}
+        // Calculate the MSBs of current picture
+        if ((pInfo->img.pic_order_cnt_lsb < pInfo->img.PrevPicOrderCntLsb)  &&
+                ((pInfo->img.PrevPicOrderCntLsb - pInfo->img.pic_order_cnt_lsb )>=(MaxPicOrderCntLsb>>1)) )
+        {
+            pInfo->img.CurrPicOrderCntMsb = pInfo->img.PicOrderCntMsb + MaxPicOrderCntLsb;
+        } else if ((pInfo->img.pic_order_cnt_lsb  >  pInfo->img.PrevPicOrderCntLsb)  &&
+                   ((pInfo->img.pic_order_cnt_lsb - pInfo->img.PrevPicOrderCntLsb ) > (MaxPicOrderCntLsb>>1)) )
+        {
+            pInfo->img.CurrPicOrderCntMsb = pInfo->img.PicOrderCntMsb - MaxPicOrderCntLsb;
+        } else
+        {
+            pInfo->img.CurrPicOrderCntMsb = pInfo->img.PicOrderCntMsb;
+        }
 
-		// 2nd
+        // 2nd
 
-		if(pInfo->img.field_pic_flag==0)
-		{           
-		  //frame pix
-		  pInfo->img.toppoc = pInfo->img.CurrPicOrderCntMsb + pInfo->img.pic_order_cnt_lsb;
-		  pInfo->img.bottompoc = pInfo->img.toppoc + pInfo->img.delta_pic_order_cnt_bottom;
-		  pInfo->img.ThisPOC = pInfo->img.framepoc = (pInfo->img.toppoc < pInfo->img.bottompoc)? pInfo->img.toppoc : pInfo->img.bottompoc; // POC200301
-		}
-		else if (pInfo->img.bottom_field_flag==0)
-		{  //top field
-		  pInfo->img.ThisPOC= pInfo->img.toppoc = pInfo->img.CurrPicOrderCntMsb + pInfo->img.pic_order_cnt_lsb;
-		}
-		else
-		{  //bottom field
-		  pInfo->img.ThisPOC= pInfo->img.bottompoc = pInfo->img.CurrPicOrderCntMsb + pInfo->img.pic_order_cnt_lsb;
-		}
-		pInfo->img.framepoc=pInfo->img.ThisPOC;
+        if (pInfo->img.field_pic_flag==0)
+        {
+            //frame pix
+            pInfo->img.toppoc = pInfo->img.CurrPicOrderCntMsb + pInfo->img.pic_order_cnt_lsb;
+            pInfo->img.bottompoc = pInfo->img.toppoc + pInfo->img.delta_pic_order_cnt_bottom;
+            pInfo->img.ThisPOC = pInfo->img.framepoc = (pInfo->img.toppoc < pInfo->img.bottompoc)? pInfo->img.toppoc : pInfo->img.bottompoc; // POC200301
+        }
+        else if (pInfo->img.bottom_field_flag==0)
+        {  //top field
+            pInfo->img.ThisPOC= pInfo->img.toppoc = pInfo->img.CurrPicOrderCntMsb + pInfo->img.pic_order_cnt_lsb;
+        }
+        else
+        {  //bottom field
+            pInfo->img.ThisPOC= pInfo->img.bottompoc = pInfo->img.CurrPicOrderCntMsb + pInfo->img.pic_order_cnt_lsb;
+        }
+        pInfo->img.framepoc=pInfo->img.ThisPOC;
 
-		if ( pInfo->img.frame_num != pInfo->old_slice.frame_num)
-		  pInfo->img.PreviousFrameNum = pInfo->img.frame_num;
+        if ( pInfo->img.frame_num != pInfo->old_slice.frame_num)
+            pInfo->img.PreviousFrameNum = pInfo->img.frame_num;
 
-		if(pInfo->SliceHeader.nal_ref_idc)
-		{
-		  pInfo->img.PrevPicOrderCntLsb = pInfo->img.pic_order_cnt_lsb;
-		  pInfo->img.PicOrderCntMsb = pInfo->img.CurrPicOrderCntMsb;
-		}
-              
-		break;
+        if (pInfo->SliceHeader.nal_ref_idc)
+        {
+            pInfo->img.PrevPicOrderCntLsb = pInfo->img.pic_order_cnt_lsb;
+            pInfo->img.PicOrderCntMsb = pInfo->img.CurrPicOrderCntMsb;
+        }
+
+        break;
     case 1: {
-		if(NonExisting)
-		{
-			delta_pic_order_count[0] = 0;
-			delta_pic_order_count[1] = 0;
-		}
-		else
-		{
-			delta_pic_order_count[0] = ( pInfo->img.delta_pic_order_always_zero_flag ) ? 0 : pInfo->img.delta_pic_order_cnt[0];
-			delta_pic_order_count[1] = ( pInfo->img.delta_pic_order_always_zero_flag ) ? 0 :    
-				( (!pInfo->active_PPS.pic_order_present_flag)  && (!(pInfo->img.field_pic_flag))) ? 0 :  
-														pInfo->img.delta_pic_order_cnt[1]; 
-		}
+        if (NonExisting)
+        {
+            delta_pic_order_count[0] = 0;
+            delta_pic_order_count[1] = 0;
+        }
+        else
+        {
+            delta_pic_order_count[0] = ( pInfo->img.delta_pic_order_always_zero_flag ) ? 0 : pInfo->img.delta_pic_order_cnt[0];
+            delta_pic_order_count[1] = ( pInfo->img.delta_pic_order_always_zero_flag ) ? 0 :
+                                       ( (!pInfo->active_PPS.pic_order_present_flag)  && (!(pInfo->img.field_pic_flag))) ? 0 :
+                                       pInfo->img.delta_pic_order_cnt[1];
+        }
 
-		// this if branch should not be taken during processing of a gap_in_frame_num pic since
-		// an IDR picture cannot produce non-existent frames...
-		if(pInfo->SliceHeader.idr_flag)
-		{
-			pInfo->img.FrameNumOffset         = 0;
-		}
-		else 
-		{
+        // this if branch should not be taken during processing of a gap_in_frame_num pic since
+        // an IDR picture cannot produce non-existent frames...
+        if (pInfo->SliceHeader.idr_flag)
+        {
+            pInfo->img.FrameNumOffset         = 0;
+        }
+        else
+        {
 
-			if (actual_frame_num < pInfo->img.PreviousFrameNum)
-			{             
-			  pInfo->img.FrameNumOffset = pInfo->img.PreviousFrameNumOffset + MaxFrameNum;
-			}
-			else 
-			{
-			  pInfo->img.FrameNumOffset = pInfo->img.PreviousFrameNumOffset;
-			}
-		}
+            if (actual_frame_num < pInfo->img.PreviousFrameNum)
+            {
+                pInfo->img.FrameNumOffset = pInfo->img.PreviousFrameNumOffset + MaxFrameNum;
+            }
+            else
+            {
+                pInfo->img.FrameNumOffset = pInfo->img.PreviousFrameNumOffset;
+            }
+        }
 
-		// pInfo->img.num_ref_frames_in_pic_order_cnt_cycle set from SPS 
-		// so constant between existent and non-existent frames
-		if (pInfo->img.num_ref_frames_in_pic_order_cnt_cycle) 
-		  AbsFrameNum = pInfo->img.FrameNumOffset + actual_frame_num;
-		else
-		  AbsFrameNum = 0;
+        // pInfo->img.num_ref_frames_in_pic_order_cnt_cycle set from SPS
+        // so constant between existent and non-existent frames
+        if (pInfo->img.num_ref_frames_in_pic_order_cnt_cycle)
+            AbsFrameNum = pInfo->img.FrameNumOffset + actual_frame_num;
+        else
+            AbsFrameNum = 0;
 
-		// pInfo->img.disposable_flag should never be true for a non-existent frame since these are always 
-		// references...
-		if ((pInfo->SliceHeader.nal_ref_idc == 0) && (AbsFrameNum > 0)) AbsFrameNum = AbsFrameNum - 1;
+        // pInfo->img.disposable_flag should never be true for a non-existent frame since these are always
+        // references...
+        if ((pInfo->SliceHeader.nal_ref_idc == 0) && (AbsFrameNum > 0)) AbsFrameNum = AbsFrameNum - 1;
 
-		// 3rd
-		ExpectedDeltaPerPicOrderCntCycle = pInfo->active_SPS.expectedDeltaPerPOCCycle;
+        // 3rd
+        ExpectedDeltaPerPicOrderCntCycle = pInfo->active_SPS.expectedDeltaPerPOCCycle;
 
-		if (AbsFrameNum)
-		{
-			// Rem: pInfo->img.num_ref_frames_in_pic_order_cnt_cycle takes max value of 255 (8 bit)
-			// Frame NUm may be 2^16 (17 bits)
-			// I guess we really have to treat AbsFrameNum as a 32 bit number
-			uint32_t temp = 0;
-			int32_t i=0;
-			int32_t offset_for_ref_frame[MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE];
+        if (AbsFrameNum)
+        {
+            // Rem: pInfo->img.num_ref_frames_in_pic_order_cnt_cycle takes max value of 255 (8 bit)
+            // Frame NUm may be 2^16 (17 bits)
+            // I guess we really have to treat AbsFrameNum as a 32 bit number
+            uint32_t temp = 0;
+            int32_t i=0;
+            int32_t offset_for_ref_frame[MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE];
 
-			if (pInfo->img.num_ref_frames_in_pic_order_cnt_cycle)
-				PicOrderCntCycleCnt = ldiv_mod_u((uint32_t)(AbsFrameNum-1), (uint32_t)pInfo->img.num_ref_frames_in_pic_order_cnt_cycle, &temp);
-			
-			ExpectedPicOrderCnt = mult_u((uint32_t)PicOrderCntCycleCnt, (uint32_t)ExpectedDeltaPerPicOrderCntCycle);
+            if (pInfo->img.num_ref_frames_in_pic_order_cnt_cycle)
+                PicOrderCntCycleCnt = ldiv_mod_u((uint32_t)(AbsFrameNum-1), (uint32_t)pInfo->img.num_ref_frames_in_pic_order_cnt_cycle, &temp);
 
-			FrameNumInPicOrderCntCycle = temp;
+            ExpectedPicOrderCnt = mult_u((uint32_t)PicOrderCntCycleCnt, (uint32_t)ExpectedDeltaPerPicOrderCntCycle);
 
-			//ExpectedPicOrderCnt +=pInfo->active_SPS.expectedDeltaPerPOCCycle;
-#ifndef USER_MODE			
-			h264_Parse_Copy_Offset_Ref_Frames_From_DDR(pInfo, offset_for_ref_frame, pInfo->active_SPS.seq_parameter_set_id);
-			for (i = 0; i <= FrameNumInPicOrderCntCycle; i++)
-				ExpectedPicOrderCnt += offset_for_ref_frame[i];
+            FrameNumInPicOrderCntCycle = temp;
+
+            //ExpectedPicOrderCnt +=pInfo->active_SPS.expectedDeltaPerPOCCycle;
+#ifndef USER_MODE
+            h264_Parse_Copy_Offset_Ref_Frames_From_DDR(pInfo, offset_for_ref_frame, pInfo->active_SPS.seq_parameter_set_id);
+            for (i = 0; i <= FrameNumInPicOrderCntCycle; i++)
+                ExpectedPicOrderCnt += offset_for_ref_frame[i];
 #else
-			for (i = 0; i <= FrameNumInPicOrderCntCycle; i++)
-				ExpectedPicOrderCnt += pInfo->active_SPS.offset_for_ref_frame[i];
+            for (i = 0; i <= FrameNumInPicOrderCntCycle; i++)
+                ExpectedPicOrderCnt += pInfo->active_SPS.offset_for_ref_frame[i];
 #endif
-		}
-		else { 
-			ExpectedPicOrderCnt = 0;
-		}
+        }
+        else {
+            ExpectedPicOrderCnt = 0;
+        }
 
-		if (pInfo->SliceHeader.nal_ref_idc == 0)
-			ExpectedPicOrderCnt += pInfo->img.offset_for_non_ref_pic;
+        if (pInfo->SliceHeader.nal_ref_idc == 0)
+            ExpectedPicOrderCnt += pInfo->img.offset_for_non_ref_pic;
 
-		if (!(pInfo->img.field_pic_flag))
-		{
-			pInfo->img.toppoc = ExpectedPicOrderCnt + delta_pic_order_count[0];
-			pInfo->img.bottompoc = pInfo->img.toppoc + pInfo->img.offset_for_top_to_bottom_field + delta_pic_order_count[1];
-			pInfo->img.framepoc = (pInfo->img.toppoc < pInfo->img.bottompoc)? pInfo->img.toppoc : pInfo->img.bottompoc; 
-			pInfo->img.ThisPOC = pInfo->img.framepoc;
-		}
-		else if (!(pInfo->img.bottom_field_flag))
-		{
-			//top field 
-			pInfo->img.toppoc = ExpectedPicOrderCnt + delta_pic_order_count[0];
-			pInfo->img.ThisPOC = pInfo->img.toppoc;
-			pInfo->img.bottompoc = 0;
-		}
-		else
-		{
-			//bottom field
-			pInfo->img.toppoc = 0;
-			pInfo->img.bottompoc = ExpectedPicOrderCnt + pInfo->img.offset_for_top_to_bottom_field + delta_pic_order_count[0];
-			pInfo->img.ThisPOC = pInfo->img.bottompoc;
-		}
+        if (!(pInfo->img.field_pic_flag))
+        {
+            pInfo->img.toppoc = ExpectedPicOrderCnt + delta_pic_order_count[0];
+            pInfo->img.bottompoc = pInfo->img.toppoc + pInfo->img.offset_for_top_to_bottom_field + delta_pic_order_count[1];
+            pInfo->img.framepoc = (pInfo->img.toppoc < pInfo->img.bottompoc)? pInfo->img.toppoc : pInfo->img.bottompoc;
+            pInfo->img.ThisPOC = pInfo->img.framepoc;
+        }
+        else if (!(pInfo->img.bottom_field_flag))
+        {
+            //top field
+            pInfo->img.toppoc = ExpectedPicOrderCnt + delta_pic_order_count[0];
+            pInfo->img.ThisPOC = pInfo->img.toppoc;
+            pInfo->img.bottompoc = 0;
+        }
+        else
+        {
+            //bottom field
+            pInfo->img.toppoc = 0;
+            pInfo->img.bottompoc = ExpectedPicOrderCnt + pInfo->img.offset_for_top_to_bottom_field + delta_pic_order_count[0];
+            pInfo->img.ThisPOC = pInfo->img.bottompoc;
+        }
 
-		//CONFORMANCE_ISSUE
-		pInfo->img.framepoc=pInfo->img.ThisPOC;
+        //CONFORMANCE_ISSUE
+        pInfo->img.framepoc=pInfo->img.ThisPOC;
 
-		//CONFORMANCE_ISSUE
-		pInfo->img.PreviousFrameNum=pInfo->img.frame_num;
-		pInfo->img.PreviousFrameNumOffset=pInfo->img.FrameNumOffset;
-		 
-		}
-		break;
+        //CONFORMANCE_ISSUE
+        pInfo->img.PreviousFrameNum=pInfo->img.frame_num;
+        pInfo->img.PreviousFrameNumOffset=pInfo->img.FrameNumOffset;
+
+    }
+    break;
     case 2: {     // POC MODE 2
-		if (pInfo->SliceHeader.idr_flag) 
-		{
-			pInfo->img.FrameNumOffset = 0;     
-			pInfo->img.framepoc = 0;
-			pInfo->img.toppoc = 0;
-			pInfo->img.bottompoc = 0;
-			pInfo->img.ThisPOC = 0;
-		}
-		else
-		{
-			if (pInfo->img.last_has_mmco_5)
-			{
-			  pInfo->img.PreviousFrameNum = 0;
-			  pInfo->img.PreviousFrameNumOffset = 0;
-			}
-			if (actual_frame_num < pInfo->img.PreviousFrameNum) 
-			  pInfo->img.FrameNumOffset = pInfo->img.PreviousFrameNumOffset + MaxFrameNum;
-			else
-			  pInfo->img.FrameNumOffset = pInfo->img.PreviousFrameNumOffset;
+        if (pInfo->SliceHeader.idr_flag)
+        {
+            pInfo->img.FrameNumOffset = 0;
+            pInfo->img.framepoc = 0;
+            pInfo->img.toppoc = 0;
+            pInfo->img.bottompoc = 0;
+            pInfo->img.ThisPOC = 0;
+        }
+        else
+        {
+            if (pInfo->img.last_has_mmco_5)
+            {
+                pInfo->img.PreviousFrameNum = 0;
+                pInfo->img.PreviousFrameNumOffset = 0;
+            }
+            if (actual_frame_num < pInfo->img.PreviousFrameNum)
+                pInfo->img.FrameNumOffset = pInfo->img.PreviousFrameNumOffset + MaxFrameNum;
+            else
+                pInfo->img.FrameNumOffset = pInfo->img.PreviousFrameNumOffset;
 
-			AbsFrameNum = pInfo->img.FrameNumOffset + actual_frame_num;
-			if (pInfo->SliceHeader.nal_ref_idc == 0) pInfo->img.ThisPOC = (AbsFrameNum<<1) - 1;
-			else                     pInfo->img.ThisPOC = (AbsFrameNum<<1);
+            AbsFrameNum = pInfo->img.FrameNumOffset + actual_frame_num;
+            if (pInfo->SliceHeader.nal_ref_idc == 0) pInfo->img.ThisPOC = (AbsFrameNum<<1) - 1;
+            else                     pInfo->img.ThisPOC = (AbsFrameNum<<1);
 
-			if (!(pInfo->img.field_pic_flag))
-			{
-			  pInfo->img.toppoc    = pInfo->img.ThisPOC;
-			  pInfo->img.bottompoc = pInfo->img.ThisPOC;
-			  pInfo->img.framepoc  = pInfo->img.ThisPOC;
-			}
-			else if (!(pInfo->img.bottom_field_flag))
-			{
-			  pInfo->img.toppoc   = pInfo->img.ThisPOC;
-			  pInfo->img.framepoc = pInfo->img.ThisPOC;
-			}
-			else
-			{
-			  pInfo->img.bottompoc = pInfo->img.ThisPOC;
-			  pInfo->img.framepoc  = pInfo->img.ThisPOC;
-			}
-		}
+            if (!(pInfo->img.field_pic_flag))
+            {
+                pInfo->img.toppoc    = pInfo->img.ThisPOC;
+                pInfo->img.bottompoc = pInfo->img.ThisPOC;
+                pInfo->img.framepoc  = pInfo->img.ThisPOC;
+            }
+            else if (!(pInfo->img.bottom_field_flag))
+            {
+                pInfo->img.toppoc   = pInfo->img.ThisPOC;
+                pInfo->img.framepoc = pInfo->img.ThisPOC;
+            }
+            else
+            {
+                pInfo->img.bottompoc = pInfo->img.ThisPOC;
+                pInfo->img.framepoc  = pInfo->img.ThisPOC;
+            }
+        }
 
-		//CONFORMANCE_ISSUE
-		pInfo->img.PreviousFrameNum = pInfo->img.frame_num;
-		pInfo->img.PreviousFrameNumOffset = pInfo->img.FrameNumOffset;
-		} 
-		break;
-	default:
-		break;
-  }      
+        //CONFORMANCE_ISSUE
+        pInfo->img.PreviousFrameNum = pInfo->img.frame_num;
+        pInfo->img.PreviousFrameNumOffset = pInfo->img.FrameNumOffset;
+    }
+    break;
+    default:
+        break;
+    }
 
-  return;
+    return;
 }  //// End of decoding_POC
 
 /* ------------------------------------------------------------------------------------------ */
@@ -4136,41 +4156,42 @@
 
 void h264_hdr_post_poc(h264_Info* pInfo, int32_t NonExisting, int32_t frame_num, int32_t use_old)
 {
-	int32_t actual_frame_num = (NonExisting)? frame_num : 
-								(use_old)?	pInfo->old_slice.frame_num :
-											pInfo->img.frame_num;
+    int32_t actual_frame_num = (NonExisting)? frame_num :
+                               (use_old)?	pInfo->old_slice.frame_num :
+                               pInfo->img.frame_num;
 
-	int32_t disposable_flag = (use_old)?(pInfo->old_slice.nal_ref_idc == 0) : 
-										(pInfo->SliceHeader.nal_ref_idc == 0);
+    int32_t disposable_flag = (use_old)?(pInfo->old_slice.nal_ref_idc == 0) :
+                              (pInfo->SliceHeader.nal_ref_idc == 0);
 
-	switch(pInfo->img.pic_order_cnt_type)
-	{
-	case  0: {
-			pInfo->img.PreviousFrameNum   = actual_frame_num;
-			if ((disposable_flag == 0) && (NonExisting == 0))
-			{
-			 pInfo->img.PrevPicOrderCntLsb = (use_old)? pInfo->old_slice.pic_order_cnt_lsb : 
-												 pInfo->SliceHeader.pic_order_cnt_lsb;
-			 pInfo->img.PicOrderCntMsb     = pInfo->img.CurrPicOrderCntMsb;
-			}
-		}
-		break;
-	case  1: {
-			pInfo->img.PreviousFrameNum       = actual_frame_num;
-			pInfo->img.PreviousFrameNumOffset = pInfo->img.FrameNumOffset;
-		}
-		break;
-	case  2: {
-			pInfo->img.PreviousFrameNum       = actual_frame_num;
-			pInfo->img.PreviousFrameNumOffset = pInfo->img.FrameNumOffset;
-	           
-		}break;
-	         
-	default: {
-		}break;
-	}
+    switch (pInfo->img.pic_order_cnt_type)
+    {
+    case  0: {
+        pInfo->img.PreviousFrameNum   = actual_frame_num;
+        if ((disposable_flag == 0) && (NonExisting == 0))
+        {
+            pInfo->img.PrevPicOrderCntLsb = (use_old)? pInfo->old_slice.pic_order_cnt_lsb :
+                                            pInfo->SliceHeader.pic_order_cnt_lsb;
+            pInfo->img.PicOrderCntMsb     = pInfo->img.CurrPicOrderCntMsb;
+        }
+    }
+    break;
+    case  1: {
+        pInfo->img.PreviousFrameNum       = actual_frame_num;
+        pInfo->img.PreviousFrameNumOffset = pInfo->img.FrameNumOffset;
+    }
+    break;
+    case  2: {
+        pInfo->img.PreviousFrameNum       = actual_frame_num;
+        pInfo->img.PreviousFrameNumOffset = pInfo->img.FrameNumOffset;
 
-	return;
+    }
+    break;
+
+    default: {
+    } break;
+    }
+
+    return;
 } ///// End of h264_hdr_post_poc
 
 
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_math.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_math.c
index 307a0da..ec48cc8 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_math.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_math.c
@@ -6,79 +6,79 @@
 uint32_t mult_u(register uint32_t var1, register uint32_t var2)
 {
 
-	  register unsigned long var_out = 0;
-	
-	  while (var2 > 0)
-	  {
+    register unsigned long var_out = 0;
 
-	  	if (var2 & 0x01) 
-		{
-			var_out += var1;
-		}
-		var2 >>= 1;
-		var1 <<= 1;
-  }
-	return var_out;
-	
+    while (var2 > 0)
+    {
+
+        if (var2 & 0x01)
+        {
+            var_out += var1;
+        }
+        var2 >>= 1;
+        var1 <<= 1;
+    }
+    return var_out;
+
 }// mult_u
 
 uint32_t ldiv_mod_u(uint32_t a, uint32_t b, uint32_t * mod)
 {
-	register unsigned long div = b;
-	register unsigned long res = 0;
-	register unsigned long bit = 0x1;
+    register unsigned long div = b;
+    register unsigned long res = 0;
+    register unsigned long bit = 0x1;
 
-	if (!div)
-	{
-		*mod = 0;
-		return 0xffffffff ; // Div by 0
-	}
+    if (!div)
+    {
+        *mod = 0;
+        return 0xffffffff ; // Div by 0
+    }
 
-	if (a < b)
-	{
-		*mod = a;
-		return 0; // It won't even go once
-	}
+    if (a < b)
+    {
+        *mod = a;
+        return 0; // It won't even go once
+    }
 
-	while(!(div & 0x80000000))
-	{
-		div <<= 1;
-		bit <<= 1;
-	}
+    while (!(div & 0x80000000))
+    {
+        div <<= 1;
+        bit <<= 1;
+    }
 
-	while (bit)
-	{
-		if (div <= a)
-    		{
-		      res |= bit;
-		      a -= div;
-		 }
-	    div >>= 1;
-	    bit >>= 1;
-	}
- 	 *mod = a;
-  	return res;
+    while (bit)
+    {
+        if (div <= a)
+        {
+            res |= bit;
+            a -= div;
+        }
+        div >>= 1;
+        bit >>= 1;
+    }
+    *mod = a;
+    return res;
 }// ldiv_mod_u
 
 
 unsigned ldiv_u(register unsigned a, register unsigned  b)
-{  
-	register unsigned div = b << 16;
-	register unsigned res = 0;
-	register unsigned bit = 0x10000;
-	
-	while (bit)
-  	{
-  		div >>= 1;
-		bit >>= 1;
-		if (div < a)
-		{
-			res |= bit;
-			a -= div;
-		}
-	} 
-	
-	return res;
+{
+    register unsigned div = b << 16;
+    register unsigned res = 0;
+    register unsigned bit = 0x10000;
+
+    while (bit)
+    {
+        div >>= 1;
+        bit >>= 1;
+        if (div < a)
+        {
+            res |= bit;
+            a -= div;
+        }
+    }
+
+    return res;
 }
 
 
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_mem.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_mem.c
index 38297dc..b5a0145 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_mem.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_mem.c
@@ -16,32 +16,32 @@
 // ---------------------------------------------------------------------------
 void* h264_memset( void* buf, uint32_t c, uint32_t num )
 {
-	uint32_t* buf32 = (uint32_t*)buf;
-	uint32_t  size32 = ( num >> 2 );
-	uint32_t  i;
+    uint32_t* buf32 = (uint32_t*)buf;
+    uint32_t  size32 = ( num >> 2 );
+    uint32_t  i;
 
-	for ( i = 0; i < size32; i++ )
-	{
-		*buf32++ = c;
-	}
+    for ( i = 0; i < size32; i++ )
+    {
+        *buf32++ = c;
+    }
 
-	return buf;
+    return buf;
 }
 
 
 void* h264_memcpy( void* dest, void* src, uint32_t num )
 {
-	int32_t*	dest32 = (int32_t*)dest;
-	int32_t*    src32 = (int32_t*)src;
-	uint32_t	size32 = ( num >> 2 );
-	uint32_t	i;
+    int32_t*	dest32 = (int32_t*)dest;
+    int32_t*    src32 = (int32_t*)src;
+    uint32_t	size32 = ( num >> 2 );
+    uint32_t	i;
 
-	for ( i = 0; i < size32; i++ )
-	{
-		*dest32++ = *src32++;
-	}
+    for ( i = 0; i < size32; i++ )
+    {
+        *dest32++ = *src32++;
+    }
 
-	return dest;
+    return dest;
 }
 
 
@@ -50,33 +50,33 @@
 //h264_Parse_Copy_Sps_To_DDR () copy local sps to ddr mem
 void h264_Parse_Copy_Pps_To_DDR(h264_Info* pInfo, pic_param_set_ptr PPS, uint32_t nPPSId)
 {
-   uint32_t  copy_size = sizeof(pic_param_set);
-   uint32_t  pps_entry_ptr = pInfo->PPS_PADDR_GL+nPPSId*copy_size;
+    uint32_t  copy_size = sizeof(pic_param_set);
+    uint32_t  pps_entry_ptr = pInfo->PPS_PADDR_GL+nPPSId*copy_size;
 
-   if(nPPSId < MAX_NUM_PPS)
-   {
-	   cp_using_dma(pps_entry_ptr, (uint32_t)PPS, copy_size, 1, 0);     
-   }
+    if (nPPSId < MAX_NUM_PPS)
+    {
+        cp_using_dma(pps_entry_ptr, (uint32_t)PPS, copy_size, 1, 0);
+    }
 
-  return;  
+    return;
 
 }
 //end of h264_Parse_Copy_Pps_To_DDR
 
 
-// h264_Parse_Copy_Pps_From_DDR copy a pps with nPPSId from ddr mem to local PPS 
+// h264_Parse_Copy_Pps_From_DDR copy a pps with nPPSId from ddr mem to local PPS
 void h264_Parse_Copy_Pps_From_DDR(h264_Info* pInfo, pic_param_set_ptr PPS, uint32_t nPPSId)
 {
 
-  uint32_t copy_size= sizeof(pic_param_set);
-  uint32_t pps_entry_ptr = pInfo->PPS_PADDR_GL+nPPSId*copy_size;	 
+    uint32_t copy_size= sizeof(pic_param_set);
+    uint32_t pps_entry_ptr = pInfo->PPS_PADDR_GL+nPPSId*copy_size;
 
-  if( nPPSId < MAX_NUM_PPS)
-  {
-      cp_using_dma(pps_entry_ptr, (uint32_t)PPS, copy_size, 0, 0);  
-  }
-  
-  return;
+    if ( nPPSId < MAX_NUM_PPS)
+    {
+        cp_using_dma(pps_entry_ptr, (uint32_t)PPS, copy_size, 0, 0);
+    }
+
+    return;
 }
 //end of h264_Parse_Copy_Pps_From_DDR
 
@@ -84,71 +84,71 @@
 //h264_Parse_Copy_Sps_To_DDR () copy local sps to ddr mem with nSPSId
 void h264_Parse_Copy_Sps_To_DDR(h264_Info* pInfo, seq_param_set_used_ptr SPS, uint32_t nSPSId)
 {
-   uint32_t  copy_size = sizeof(seq_param_set_used);
-   uint32_t  sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*sizeof(seq_param_set_all);
+    uint32_t  copy_size = sizeof(seq_param_set_used);
+    uint32_t  sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*sizeof(seq_param_set_all);
 
-   if(nSPSId < MAX_NUM_SPS)
-   {
-		cp_using_dma(sps_entry_ptr, (uint32_t)SPS, copy_size, 1, 0);	  
-   }
-    
-   //OS_INFO("SPS->seq_parameter_set_id = %d\n", SPS->seq_parameter_set_id);
-  
+    if (nSPSId < MAX_NUM_SPS)
+    {
+        cp_using_dma(sps_entry_ptr, (uint32_t)SPS, copy_size, 1, 0);
+    }
 
-   return; 
+    //OS_INFO("SPS->seq_parameter_set_id = %d\n", SPS->seq_parameter_set_id);
+
+
+    return;
 }
 
 //end of h264_Parse_Copy_Sps_To_DDR
 
 
-// h264_Parse_Copy_Sps_From_DDR copy a sps with nSPSId from ddr mem to local SPS 
+// h264_Parse_Copy_Sps_From_DDR copy a sps with nSPSId from ddr mem to local SPS
 void h264_Parse_Copy_Sps_From_DDR(h264_Info* pInfo, seq_param_set_used_ptr SPS, uint32_t nSPSId)
 {
-	uint32_t copy_size= sizeof(seq_param_set_used);
-	uint32_t sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*sizeof(seq_param_set_all); 	  
+    uint32_t copy_size= sizeof(seq_param_set_used);
+    uint32_t sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*sizeof(seq_param_set_all);
 
-   if(nSPSId < MAX_NUM_SPS)
-   {
-      cp_using_dma(sps_entry_ptr, (uint32_t)SPS, copy_size, 0, 0);  
-   }
+    if (nSPSId < MAX_NUM_SPS)
+    {
+        cp_using_dma(sps_entry_ptr, (uint32_t)SPS, copy_size, 0, 0);
+    }
 
-   return;
- 
+    return;
+
 }
 //end of h264_Parse_Copy_Sps_From_DDR
 
 //h264_Parse_Copy_Offset_Ref_Frames_To_DDR () copy local offset_ref_frames to ddr mem with nSPSId
 void h264_Parse_Copy_Offset_Ref_Frames_To_DDR(h264_Info* pInfo, int32_t* pOffset_ref_frames, uint32_t nSPSId)
 {
-   uint32_t  copy_size = sizeof(int32_t)*MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE;
-   uint32_t  offset_ref_frames_entry_ptr = pInfo->OFFSET_REF_FRAME_PADDR_GL+nSPSId*copy_size;
+    uint32_t  copy_size = sizeof(int32_t)*MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE;
+    uint32_t  offset_ref_frames_entry_ptr = pInfo->OFFSET_REF_FRAME_PADDR_GL+nSPSId*copy_size;
 
-   if(nSPSId < MAX_NUM_SPS)
-   {
-		//cp_using_dma(offset_ref_frames_entry_ptr, (uint32_t)pOffset_ref_frames, copy_size, 1, 0);	  
-		h264_memcpy((int32_t *)offset_ref_frames_entry_ptr,pOffset_ref_frames, copy_size);
-   }
-    
-   return; 
+    if (nSPSId < MAX_NUM_SPS)
+    {
+        //cp_using_dma(offset_ref_frames_entry_ptr, (uint32_t)pOffset_ref_frames, copy_size, 1, 0);
+        h264_memcpy((int32_t *)offset_ref_frames_entry_ptr,pOffset_ref_frames, copy_size);
+    }
+
+    return;
 }
 
 //end of h264_Parse_Copy_Offset_Ref_Frames_To_DDR
 
 
-// h264_Parse_Copy_Offset_Ref_Frames_From_DDR copy a offset_ref_frames with nSPSId from ddr mem to local offset_ref_frames 
+// h264_Parse_Copy_Offset_Ref_Frames_From_DDR copy a offset_ref_frames with nSPSId from ddr mem to local offset_ref_frames
 void h264_Parse_Copy_Offset_Ref_Frames_From_DDR(h264_Info* pInfo, int32_t* pOffset_ref_frames, uint32_t nSPSId)
 {
-	uint32_t copy_size= sizeof(int32_t)*MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE;
-	uint32_t offset_ref_frames_entry_ptr = pInfo->OFFSET_REF_FRAME_PADDR_GL+nSPSId*copy_size; 	  
+    uint32_t copy_size= sizeof(int32_t)*MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE;
+    uint32_t offset_ref_frames_entry_ptr = pInfo->OFFSET_REF_FRAME_PADDR_GL+nSPSId*copy_size;
 
-   if(nSPSId < MAX_NUM_SPS)
-   {
-      //cp_using_dma(offset_ref_frames_entry_ptr, (uint32_t)pOffset_ref_frames, copy_size, 0, 0);  
-		h264_memcpy(pOffset_ref_frames, (int32_t *)offset_ref_frames_entry_ptr, copy_size);
-   }
+    if (nSPSId < MAX_NUM_SPS)
+    {
+        //cp_using_dma(offset_ref_frames_entry_ptr, (uint32_t)pOffset_ref_frames, copy_size, 0, 0);
+        h264_memcpy(pOffset_ref_frames, (int32_t *)offset_ref_frames_entry_ptr, copy_size);
+    }
 
-   return;
- 
+    return;
+
 }
 //end of h264_Parse_Copy_Offset_Ref_Frames_From_DDR
 
@@ -156,39 +156,39 @@
 //h264_Parse_Check_Sps_Updated_Flag () copy local sps to ddr mem with nSPSId
 uint32_t h264_Parse_Check_Sps_Updated_Flag(h264_Info* pInfo, uint32_t nSPSId)
 {
-   uint32_t  is_updated=0;
-   uint32_t  copy_size = sizeof(uint32_t);
-   uint32_t  sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*copy_size;
-   
+    uint32_t  is_updated=0;
+    uint32_t  copy_size = sizeof(uint32_t);
+    uint32_t  sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*copy_size;
 
-   if(nSPSId < MAX_NUM_SPS)
-   {
-		cp_using_dma(sps_entry_ptr, (uint32_t)(&is_updated), copy_size, 1, 0);	  
-   }
-    
-   //OS_INFO("SPS->seq_parameter_set_id = %d\n", SPS->seq_parameter_set_id);
-  
 
-   return is_updated; 
+    if (nSPSId < MAX_NUM_SPS)
+    {
+        cp_using_dma(sps_entry_ptr, (uint32_t)(&is_updated), copy_size, 1, 0);
+    }
+
+    //OS_INFO("SPS->seq_parameter_set_id = %d\n", SPS->seq_parameter_set_id);
+
+
+    return is_updated;
 }
 
 //end of h264_Parse_Check_Sps_Updated_Flag
 
 
-// h264_Parse_Clear_Sps_Updated_Flag copy a sps with nSPSId from ddr mem to local SPS 
+// h264_Parse_Clear_Sps_Updated_Flag copy a sps with nSPSId from ddr mem to local SPS
 void h264_Parse_Clear_Sps_Updated_Flag(h264_Info* pInfo, uint32_t nSPSId)
 {
     uint32_t  is_updated=0;
-	uint32_t copy_size= sizeof(uint32_t);
-	uint32_t sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*copy_size; 	  
+    uint32_t copy_size= sizeof(uint32_t);
+    uint32_t sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*copy_size;
 
-   if(nSPSId < MAX_NUM_SPS)
-   {
-      cp_using_dma(sps_entry_ptr, (uint32_t)(&is_updated), copy_size, 0, 0);  
-   }
+    if (nSPSId < MAX_NUM_SPS)
+    {
+        cp_using_dma(sps_entry_ptr, (uint32_t)(&is_updated), copy_size, 0, 0);
+    }
 
-   return;
- 
+    return;
+
 }
 //end of h264_Parse_Clear_Sps_Updated_Flag
 
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_pps.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_pps.c
index a1281c2..1719a04 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_pps.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_pps.c
@@ -8,120 +8,120 @@
 /*---------------------------------------------*/
 h264_Status h264_Parse_PicParameterSet(void *parent,h264_Info * pInfo,h264_PicParameterSet_t* PictureParameterSet)
 {
-	h264_Status ret = H264_PPS_ERROR;
+    h264_Status ret = H264_PPS_ERROR;
 
-	//h264_PicParameterSet_t* PictureParameterSet = &pInfo->PictureParameterSet;
-	uint32_t code=0, i = 0;
+    //h264_PicParameterSet_t* PictureParameterSet = &pInfo->PictureParameterSet;
+    uint32_t code=0, i = 0;
 
-	do {
-		///// PPS par1: pic_parameter_set_id & seq_parameter_set_id
-	   code = h264_GetVLCElement(parent, pInfo, false);
-		if(code > MAX_PIC_PARAMS) {
-			break;
-		}	   
-		PictureParameterSet->pic_parameter_set_id = (uint8_t)code;
+    do {
+        ///// PPS par1: pic_parameter_set_id & seq_parameter_set_id
+        code = h264_GetVLCElement(parent, pInfo, false);
+        if (code > MAX_PIC_PARAMS) {
+            break;
+        }
+        PictureParameterSet->pic_parameter_set_id = (uint8_t)code;
 
-	   
-		code = h264_GetVLCElement(parent, pInfo, false);
-		if(code > MAX_NUM_SPS-1) {
-			break;
-		}
-	   PictureParameterSet->seq_parameter_set_id = (uint8_t)code;
-		
-		///// entropy_coding_mode_flag
-		viddec_pm_get_bits(parent, &code, 1);
-		PictureParameterSet->entropy_coding_mode_flag = (uint8_t)code;
-		///// pic_order_present_flag
-		viddec_pm_get_bits(parent, &code, 1);
-		PictureParameterSet->pic_order_present_flag = (uint8_t)code;
-		
-		PictureParameterSet->num_slice_groups_minus1 = h264_GetVLCElement(parent, pInfo, false);
-	  
-		//
-		// In main profile, FMO is excluded and num_slice_groups_minus1 should be 0
-		//
-		if(PictureParameterSet->num_slice_groups_minus1 > 0) //MAX_NUM_SLICE_GRPS)
-			break;
-		
-		PictureParameterSet->num_ref_idx_l0_active = h264_GetVLCElement(parent, pInfo, false)+1;
-		PictureParameterSet->num_ref_idx_l1_active = h264_GetVLCElement(parent, pInfo, false)+1;
 
-		//// PPS->num_ref_idx_l0_active --- [0,32]	
-		if(((PictureParameterSet->num_ref_idx_l0_active) > MAX_NUM_REF_FRAMES) || ((PictureParameterSet->num_ref_idx_l1_active) > MAX_NUM_REF_FRAMES))
-		{
-			break;
-		}
-		
-		//// weighting prediction
-		viddec_pm_get_bits(parent, &code, 1);
-		PictureParameterSet->weighted_pred_flag = (uint8_t)code;
+        code = h264_GetVLCElement(parent, pInfo, false);
+        if (code > MAX_NUM_SPS-1) {
+            break;
+        }
+        PictureParameterSet->seq_parameter_set_id = (uint8_t)code;
 
-		viddec_pm_get_bits(parent, &code, 2);
-		PictureParameterSet->weighted_bipred_idc = (uint8_t)code;
+        ///// entropy_coding_mode_flag
+        viddec_pm_get_bits(parent, &code, 1);
+        PictureParameterSet->entropy_coding_mode_flag = (uint8_t)code;
+        ///// pic_order_present_flag
+        viddec_pm_get_bits(parent, &code, 1);
+        PictureParameterSet->pic_order_present_flag = (uint8_t)code;
 
-		//// QP
-		PictureParameterSet->pic_init_qp_minus26 = h264_GetVLCElement(parent, pInfo, true);
-		PictureParameterSet->pic_init_qs_minus26 = h264_GetVLCElement(parent, pInfo, true);
-		if(((PictureParameterSet->pic_init_qp_minus26+26) > MAX_QP) || ((PictureParameterSet->pic_init_qs_minus26+26) > MAX_QP))
-			break;		
-		PictureParameterSet->chroma_qp_index_offset = h264_GetVLCElement(parent, pInfo, true);
+        PictureParameterSet->num_slice_groups_minus1 = h264_GetVLCElement(parent, pInfo, false);
 
-		//// Deblocking ctl parameters
-		viddec_pm_get_bits(parent, &code, 1);
-		PictureParameterSet->deblocking_filter_control_present_flag = (uint8_t)code;
+        //
+        // In main profile, FMO is excluded and num_slice_groups_minus1 should be 0
+        //
+        if (PictureParameterSet->num_slice_groups_minus1 > 0) //MAX_NUM_SLICE_GRPS)
+            break;
 
-		viddec_pm_get_bits(parent, &code, 1);
-		PictureParameterSet->constrained_intra_pred_flag = (uint8_t)code;
+        PictureParameterSet->num_ref_idx_l0_active = h264_GetVLCElement(parent, pInfo, false)+1;
+        PictureParameterSet->num_ref_idx_l1_active = h264_GetVLCElement(parent, pInfo, false)+1;
 
-		if( viddec_pm_get_bits(parent, &code, 1) == -1)
-			break;
-		PictureParameterSet->redundant_pic_cnt_present_flag = (uint8_t)code;
+        //// PPS->num_ref_idx_l0_active --- [0,32]
+        if (((PictureParameterSet->num_ref_idx_l0_active) > MAX_NUM_REF_FRAMES) || ((PictureParameterSet->num_ref_idx_l1_active) > MAX_NUM_REF_FRAMES))
+        {
+            break;
+        }
 
-		//// Check if have more RBSP Data for additional parameters
-		if(h264_More_RBSP_Data(parent, pInfo))
-		{
-			viddec_pm_get_bits(parent,  &code, 1);
-			PictureParameterSet->transform_8x8_mode_flag = (uint8_t)code; 
+        //// weighting prediction
+        viddec_pm_get_bits(parent, &code, 1);
+        PictureParameterSet->weighted_pred_flag = (uint8_t)code;
 
-			if( viddec_pm_get_bits(parent, &code, 1) == -1)
-				break;			
-			PictureParameterSet->pic_scaling_matrix_present_flag = (uint8_t)code;
+        viddec_pm_get_bits(parent, &code, 2);
+        PictureParameterSet->weighted_bipred_idc = (uint8_t)code;
 
-			if(PictureParameterSet->pic_scaling_matrix_present_flag)
-	    	{
-				uint32_t n_ScalingList = 6 + (PictureParameterSet->transform_8x8_mode_flag << 1);
-	      		for(i=0; i<n_ScalingList; i++)
-	      		{
-						if( viddec_pm_get_bits(parent, &code, 1) == -1)
-							break;	
-						PictureParameterSet->pic_scaling_list_present_flag[i] = (uint8_t)code;
+        //// QP
+        PictureParameterSet->pic_init_qp_minus26 = h264_GetVLCElement(parent, pInfo, true);
+        PictureParameterSet->pic_init_qs_minus26 = h264_GetVLCElement(parent, pInfo, true);
+        if (((PictureParameterSet->pic_init_qp_minus26+26) > MAX_QP) || ((PictureParameterSet->pic_init_qs_minus26+26) > MAX_QP))
+            break;
+        PictureParameterSet->chroma_qp_index_offset = h264_GetVLCElement(parent, pInfo, true);
 
-						if(PictureParameterSet->pic_scaling_list_present_flag[i])
-		        		{
-	          			if(i<6)
-				            h264_Scaling_List(parent, PictureParameterSet->ScalingList4x4[i], 16, &PictureParameterSet->UseDefaultScalingMatrix4x4Flag[i], pInfo);
-	          			else
-				            h264_Scaling_List(parent, PictureParameterSet->ScalingList8x8[i-6], 64, &PictureParameterSet->UseDefaultScalingMatrix8x8Flag[i-6], pInfo);
-		        		}
-	      		}
-	    	}
-			
-			PictureParameterSet->second_chroma_qp_index_offset = h264_GetVLCElement(parent, pInfo, true); //fix		
-			//if((PictureParameterSet->second_chroma_qp_index_offset>12) || (PictureParameterSet->second_chroma_qp_index_offset < -12))
-			//	break;
-		}
-	 	else
-		{
-			PictureParameterSet->transform_8x8_mode_flag = 0;
-			PictureParameterSet->pic_scaling_matrix_present_flag = 0;
-			PictureParameterSet->second_chroma_qp_index_offset = PictureParameterSet->chroma_qp_index_offset;
-		}
+        //// Deblocking ctl parameters
+        viddec_pm_get_bits(parent, &code, 1);
+        PictureParameterSet->deblocking_filter_control_present_flag = (uint8_t)code;
 
-		ret = H264_STATUS_OK;
-	}while(0);
-	
-	//h264_Parse_rbsp_trailing_bits(pInfo);
-	return ret;
+        viddec_pm_get_bits(parent, &code, 1);
+        PictureParameterSet->constrained_intra_pred_flag = (uint8_t)code;
+
+        if ( viddec_pm_get_bits(parent, &code, 1) == -1)
+            break;
+        PictureParameterSet->redundant_pic_cnt_present_flag = (uint8_t)code;
+
+        //// Check if have more RBSP Data for additional parameters
+        if (h264_More_RBSP_Data(parent, pInfo))
+        {
+            viddec_pm_get_bits(parent,  &code, 1);
+            PictureParameterSet->transform_8x8_mode_flag = (uint8_t)code;
+
+            if ( viddec_pm_get_bits(parent, &code, 1) == -1)
+                break;
+            PictureParameterSet->pic_scaling_matrix_present_flag = (uint8_t)code;
+
+            if (PictureParameterSet->pic_scaling_matrix_present_flag)
+            {
+                uint32_t n_ScalingList = 6 + (PictureParameterSet->transform_8x8_mode_flag << 1);
+                for (i=0; i<n_ScalingList; i++)
+                {
+                    if ( viddec_pm_get_bits(parent, &code, 1) == -1)
+                        break;
+                    PictureParameterSet->pic_scaling_list_present_flag[i] = (uint8_t)code;
+
+                    if (PictureParameterSet->pic_scaling_list_present_flag[i])
+                    {
+                        if (i<6)
+                            h264_Scaling_List(parent, PictureParameterSet->ScalingList4x4[i], 16, &PictureParameterSet->UseDefaultScalingMatrix4x4Flag[i], pInfo);
+                        else
+                            h264_Scaling_List(parent, PictureParameterSet->ScalingList8x8[i-6], 64, &PictureParameterSet->UseDefaultScalingMatrix8x8Flag[i-6], pInfo);
+                    }
+                }
+            }
+
+            PictureParameterSet->second_chroma_qp_index_offset = h264_GetVLCElement(parent, pInfo, true); //fix
+            //if((PictureParameterSet->second_chroma_qp_index_offset>12) || (PictureParameterSet->second_chroma_qp_index_offset < -12))
+            //	break;
+        }
+        else
+        {
+            PictureParameterSet->transform_8x8_mode_flag = 0;
+            PictureParameterSet->pic_scaling_matrix_present_flag = 0;
+            PictureParameterSet->second_chroma_qp_index_offset = PictureParameterSet->chroma_qp_index_offset;
+        }
+
+        ret = H264_STATUS_OK;
+    } while (0);
+
+    //h264_Parse_rbsp_trailing_bits(pInfo);
+    return ret;
 }
 
 ////////// EOF///////////////
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_sei.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_sei.c
index b330f86..43655dd 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_sei.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_sei.c
@@ -14,941 +14,941 @@
 //////////////////////////////////////////////////////////////////////////////
 // avc_sei_stream_initialise ()
 //
-// 
+//
 
 void h264_sei_stream_initialise (h264_Info* pInfo)
 {
-	pInfo->sei_information.capture_POC     = 0;
-	pInfo->sei_information.disp_frozen     = 0;
-	pInfo->sei_information.release_POC     = 0;
-	pInfo->sei_information.capture_fn      = 0;
-	pInfo->sei_information.recovery_fn     = 0xFFFFFFFF;
-	pInfo->sei_information.scan_format     = 0;
-	pInfo->sei_information.broken_link_pic = 0;
-	return;
+    pInfo->sei_information.capture_POC     = 0;
+    pInfo->sei_information.disp_frozen     = 0;
+    pInfo->sei_information.release_POC     = 0;
+    pInfo->sei_information.capture_fn      = 0;
+    pInfo->sei_information.recovery_fn     = 0xFFFFFFFF;
+    pInfo->sei_information.scan_format     = 0;
+    pInfo->sei_information.broken_link_pic = 0;
+    return;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_buffering_period(void *parent,h264_Info* pInfo)
 {
-	h264_Status ret = H264_STATUS_SEI_ERROR;
+    h264_Status ret = H264_STATUS_SEI_ERROR;
 
-	h264_SEI_buffering_period_t* sei_msg_ptr;
-   h264_SEI_buffering_period_t  sei_buffering_period;
-	int32_t SchedSelIdx;
-	int num_bits = 0;
-	
-	sei_msg_ptr = (h264_SEI_buffering_period_t *)(&sei_buffering_period);
-	
-	do{
-		if(pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag == 1)
-		{
-			num_bits = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_initial_cpb_removal_delay_length_minus1 + 1;
-		}
-		else if(pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag)
-		{
-			num_bits = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_initial_cpb_removal_delay_length_minus1 + 1;
-		}
+    h264_SEI_buffering_period_t* sei_msg_ptr;
+    h264_SEI_buffering_period_t  sei_buffering_period;
+    int32_t SchedSelIdx;
+    int num_bits = 0;
 
-		sei_msg_ptr->seq_param_set_id = h264_GetVLCElement(parent, pInfo, false);
-		if(sei_msg_ptr->seq_param_set_id >= NUM_SPS)
-			break;
+    sei_msg_ptr = (h264_SEI_buffering_period_t *)(&sei_buffering_period);
 
-		//check if this id is same as the id of the current SPS  //fix
-		
-		if(pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag == 1)
-		{
-			if(pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_cpb_cnt_minus1 >= MAX_CPB_CNT) 
-				break;
-			
-			for(SchedSelIdx = 0; SchedSelIdx <= pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_cpb_cnt_minus1; SchedSelIdx++)
-			{
-				viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->initial_cpb_removal_delay_nal, num_bits);
-				viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->initial_cpb_removal_delay_offset_nal, num_bits);
-			}
-		}
+    do {
+        if (pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag == 1)
+        {
+            num_bits = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_initial_cpb_removal_delay_length_minus1 + 1;
+        }
+        else if (pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag)
+        {
+            num_bits = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_initial_cpb_removal_delay_length_minus1 + 1;
+        }
 
-		if(pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag == 1)
-		{
-			if(pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_cpb_cnt_minus1 >= MAX_CPB_CNT) 
-				break;
-				
-			for(SchedSelIdx = 0; SchedSelIdx <= pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_cpb_cnt_minus1; SchedSelIdx++)
-			{
-				viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->initial_cpb_removal_delay_vcl, num_bits);
-				viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->initial_cpb_removal_delay_offset_vcl, num_bits);
-			}
-		}
+        sei_msg_ptr->seq_param_set_id = h264_GetVLCElement(parent, pInfo, false);
+        if (sei_msg_ptr->seq_param_set_id >= NUM_SPS)
+            break;
 
-		ret = H264_STATUS_OK;
-	} while (0);
+        //check if this id is same as the id of the current SPS  //fix
 
-	return H264_STATUS_OK;
+        if (pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag == 1)
+        {
+            if (pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_cpb_cnt_minus1 >= MAX_CPB_CNT)
+                break;
+
+            for (SchedSelIdx = 0; SchedSelIdx <= pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_cpb_cnt_minus1; SchedSelIdx++)
+            {
+                viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->initial_cpb_removal_delay_nal, num_bits);
+                viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->initial_cpb_removal_delay_offset_nal, num_bits);
+            }
+        }
+
+        if (pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag == 1)
+        {
+            if (pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_cpb_cnt_minus1 >= MAX_CPB_CNT)
+                break;
+
+            for (SchedSelIdx = 0; SchedSelIdx <= pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_cpb_cnt_minus1; SchedSelIdx++)
+            {
+                viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->initial_cpb_removal_delay_vcl, num_bits);
+                viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->initial_cpb_removal_delay_offset_vcl, num_bits);
+            }
+        }
+
+        ret = H264_STATUS_OK;
+    } while (0);
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_pic_timing(void *parent,h264_Info* pInfo)
 {
-	int32_t CpbDpbDelaysPresentFlag = 0;
-	h264_SEI_pic_timing_t* sei_msg_ptr;
-   h264_SEI_pic_timing_t  sei_pic_timing;
-	int32_t num_bits_cpb = 0, num_bits_dpb = 0, time_offset_length = 0;
-	uint32_t code;
-   uint32_t clock_timestamp_flag = 0;
-   uint32_t full_timestamp_flag = 0;
-   uint32_t seconds_flag = 0;
-   uint32_t minutes_flag = 0;
-   uint32_t hours_flag = 0;
-   uint32_t time_offset = 0;
-
-   
-   
-	
-	sei_msg_ptr = (h264_SEI_pic_timing_t *)(&sei_pic_timing);
-
-	if(pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag)
-	{
-		num_bits_cpb = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_cpb_removal_delay_length_minus1 +1;
-		num_bits_dpb = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_dpb_output_delay_length_minus1 + 1;
-		time_offset_length = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_time_offset_length;
-	}
-	else if(pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag)
-	{
-		num_bits_cpb = pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_cpb_removal_delay_length_minus1 +1;
-		num_bits_dpb = pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_dpb_output_delay_length_minus1 + 1;
-	}
+    int32_t CpbDpbDelaysPresentFlag = 0;
+    h264_SEI_pic_timing_t* sei_msg_ptr;
+    h264_SEI_pic_timing_t  sei_pic_timing;
+    int32_t num_bits_cpb = 0, num_bits_dpb = 0, time_offset_length = 0;
+    uint32_t code;
+    uint32_t clock_timestamp_flag = 0;
+    uint32_t full_timestamp_flag = 0;
+    uint32_t seconds_flag = 0;
+    uint32_t minutes_flag = 0;
+    uint32_t hours_flag = 0;
+    uint32_t time_offset = 0;
 
 
-	CpbDpbDelaysPresentFlag = 1;		// as per amphion code
-	if(CpbDpbDelaysPresentFlag)
-	{
-		viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->cpb_removal_delay, num_bits_cpb);
-		viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->dpb_output_delay, num_bits_dpb);		
-	}
 
-	if(pInfo->active_SPS.sps_disp.vui_seq_parameters.pic_struct_present_flag)
-	{
-		int32_t i = 0, NumClockTS = 0;
 
-		viddec_workload_item_t     wi;
+    sei_msg_ptr = (h264_SEI_pic_timing_t *)(&sei_pic_timing);
 
-		wi.vwi_payload[0] = wi.vwi_payload[1] = wi.vwi_payload[2] = 0;
-		viddec_pm_get_bits(parent, &code , 4);
-		sei_msg_ptr->pic_struct = (uint8_t)code;
+    if (pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_parameters_present_flag)
+    {
+        num_bits_cpb = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_cpb_removal_delay_length_minus1 +1;
+        num_bits_dpb = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_dpb_output_delay_length_minus1 + 1;
+        time_offset_length = pInfo->active_SPS.sps_disp.vui_seq_parameters.nal_hrd_time_offset_length;
+    }
+    else if (pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_parameters_present_flag)
+    {
+        num_bits_cpb = pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_cpb_removal_delay_length_minus1 +1;
+        num_bits_dpb = pInfo->active_SPS.sps_disp.vui_seq_parameters.vcl_hrd_dpb_output_delay_length_minus1 + 1;
+    }
 
-		
-		if((sei_msg_ptr->pic_struct == 0) || (sei_msg_ptr->pic_struct == 7) || (sei_msg_ptr->pic_struct == 8)) {
-			pInfo->sei_information.scan_format = SEI_SCAN_FORMAT_PROGRESSIVE;
-		} else {
-			pInfo->sei_information.scan_format = SEI_SCAN_FORMAT_INTERLACED;
-		}
 
-		wi.vwi_type = VIDDEC_WORKLOAD_SEI_PIC_TIMING;
-		wi.h264_sei_pic_timing.pic_struct = sei_msg_ptr->pic_struct;		
+    CpbDpbDelaysPresentFlag = 1;		// as per amphion code
+    if (CpbDpbDelaysPresentFlag)
+    {
+        viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->cpb_removal_delay, num_bits_cpb);
+        viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->dpb_output_delay, num_bits_dpb);
+    }
+
+    if (pInfo->active_SPS.sps_disp.vui_seq_parameters.pic_struct_present_flag)
+    {
+        int32_t i = 0, NumClockTS = 0;
+
+        viddec_workload_item_t     wi;
+
+        wi.vwi_payload[0] = wi.vwi_payload[1] = wi.vwi_payload[2] = 0;
+        viddec_pm_get_bits(parent, &code , 4);
+        sei_msg_ptr->pic_struct = (uint8_t)code;
+
+
+        if ((sei_msg_ptr->pic_struct == 0) || (sei_msg_ptr->pic_struct == 7) || (sei_msg_ptr->pic_struct == 8)) {
+            pInfo->sei_information.scan_format = SEI_SCAN_FORMAT_PROGRESSIVE;
+        } else {
+            pInfo->sei_information.scan_format = SEI_SCAN_FORMAT_INTERLACED;
+        }
+
+        wi.vwi_type = VIDDEC_WORKLOAD_SEI_PIC_TIMING;
+        wi.h264_sei_pic_timing.pic_struct = sei_msg_ptr->pic_struct;
 
 #ifndef VBP
-      //Push to current if we are in first frame, or we do not detect previous frame end
-      viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
-#endif		
+        //Push to current if we are in first frame, or we do not detect previous frame end
+        viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
+#endif
 
-		if(sei_msg_ptr->pic_struct < 3) {
-			NumClockTS = 1;
-		} else if((sei_msg_ptr->pic_struct < 5) || (sei_msg_ptr->pic_struct == 7)) {
-			NumClockTS = 2;
-		} else {
-			NumClockTS = 3;
-		}
+        if (sei_msg_ptr->pic_struct < 3) {
+            NumClockTS = 1;
+        } else if ((sei_msg_ptr->pic_struct < 5) || (sei_msg_ptr->pic_struct == 7)) {
+            NumClockTS = 2;
+        } else {
+            NumClockTS = 3;
+        }
 
-		for(i = 0; i < NumClockTS; i++)
-		{
-			viddec_pm_get_bits(parent, &code , 1);
-         clock_timestamp_flag = code;
-			//sei_msg_ptr->clock_timestamp_flag[i] = (uint8_t)code;
-			
-			if(clock_timestamp_flag)
-			{
-				viddec_pm_get_bits(parent, &code , 2);
-				//sei_msg_ptr->ct_type[i] = (uint8_t)code;
+        for (i = 0; i < NumClockTS; i++)
+        {
+            viddec_pm_get_bits(parent, &code , 1);
+            clock_timestamp_flag = code;
+            //sei_msg_ptr->clock_timestamp_flag[i] = (uint8_t)code;
 
-				viddec_pm_get_bits(parent, &code , 1);
-				//sei_msg_ptr->nuit_field_based_flag[i] = (uint8_t)code;
+            if (clock_timestamp_flag)
+            {
+                viddec_pm_get_bits(parent, &code , 2);
+                //sei_msg_ptr->ct_type[i] = (uint8_t)code;
 
-				viddec_pm_get_bits(parent, &code , 5);
-				//sei_msg_ptr->counting_type[i] = (uint8_t)code;
+                viddec_pm_get_bits(parent, &code , 1);
+                //sei_msg_ptr->nuit_field_based_flag[i] = (uint8_t)code;
 
-				viddec_pm_get_bits(parent, &code , 1);
-				//sei_msg_ptr->full_timestamp_flag[i] = (uint8_t)code;
-				full_timestamp_flag = code;
+                viddec_pm_get_bits(parent, &code , 5);
+                //sei_msg_ptr->counting_type[i] = (uint8_t)code;
 
-				viddec_pm_get_bits(parent, &code , 1);
-				//sei_msg_ptr->discontinuity_flag[i] = (uint8_t)code;
+                viddec_pm_get_bits(parent, &code , 1);
+                //sei_msg_ptr->full_timestamp_flag[i] = (uint8_t)code;
+                full_timestamp_flag = code;
 
-				viddec_pm_get_bits(parent, &code , 1);
-				//sei_msg_ptr->cnt_dropped_flag[i] = (uint8_t)code;
+                viddec_pm_get_bits(parent, &code , 1);
+                //sei_msg_ptr->discontinuity_flag[i] = (uint8_t)code;
 
-				viddec_pm_get_bits(parent, &code , 8);
-				//sei_msg_ptr->n_frames[i] = (uint8_t)code;
+                viddec_pm_get_bits(parent, &code , 1);
+                //sei_msg_ptr->cnt_dropped_flag[i] = (uint8_t)code;
+
+                viddec_pm_get_bits(parent, &code , 8);
+                //sei_msg_ptr->n_frames[i] = (uint8_t)code;
 
 
-				if(full_timestamp_flag)
-				{
-					viddec_pm_get_bits(parent, &code , 6);
-					//sei_msg_ptr->seconds_value[i] = (uint8_t)code;
+                if (full_timestamp_flag)
+                {
+                    viddec_pm_get_bits(parent, &code , 6);
+                    //sei_msg_ptr->seconds_value[i] = (uint8_t)code;
 
-					viddec_pm_get_bits(parent, &code , 6);
-					//sei_msg_ptr->minutes_value[i] = (uint8_t)code;
+                    viddec_pm_get_bits(parent, &code , 6);
+                    //sei_msg_ptr->minutes_value[i] = (uint8_t)code;
 
-					viddec_pm_get_bits(parent, &code , 5);
-					//sei_msg_ptr->hours_value[i] = (uint8_t)code;
-				}
-				else
-				{
-					viddec_pm_get_bits(parent, &code , 1);
-					//sei_msg_ptr->seconds_flag[i] = (uint8_t)code;
-					seconds_flag = code;
-					
-					if(seconds_flag)
-					{
-						viddec_pm_get_bits(parent, &code , 6);
-						//sei_msg_ptr->seconds_value[i] = (uint8_t)code;
+                    viddec_pm_get_bits(parent, &code , 5);
+                    //sei_msg_ptr->hours_value[i] = (uint8_t)code;
+                }
+                else
+                {
+                    viddec_pm_get_bits(parent, &code , 1);
+                    //sei_msg_ptr->seconds_flag[i] = (uint8_t)code;
+                    seconds_flag = code;
 
-						viddec_pm_get_bits(parent, &code , 1);
-						//sei_msg_ptr->minutes_flag[i] = (uint8_t)code;
-						minutes_flag = code;
+                    if (seconds_flag)
+                    {
+                        viddec_pm_get_bits(parent, &code , 6);
+                        //sei_msg_ptr->seconds_value[i] = (uint8_t)code;
 
-						if(minutes_flag)
-						{
-							viddec_pm_get_bits(parent, &code , 6);
-							//sei_msg_ptr->minutes_value[i] = (uint8_t)code;
+                        viddec_pm_get_bits(parent, &code , 1);
+                        //sei_msg_ptr->minutes_flag[i] = (uint8_t)code;
+                        minutes_flag = code;
 
-							viddec_pm_get_bits(parent, &code , 1);
-							//sei_msg_ptr->hours_flag[i] = (uint8_t)code;
-							hours_flag = code;
-							
-							if(hours_flag){
-								viddec_pm_get_bits(parent, &code , 6);
-								//sei_msg_ptr->hours_value[i] = (uint8_t)code;
-							}
-						}
-					}
-				}
-				
-				if(time_offset_length > 0)
-				{
-					viddec_pm_get_bits(parent, (uint32_t *)&time_offset, time_offset_length);		
-				}
-			}
-		}
-	}
-	
+                        if (minutes_flag)
+                        {
+                            viddec_pm_get_bits(parent, &code , 6);
+                            //sei_msg_ptr->minutes_value[i] = (uint8_t)code;
 
-	return H264_STATUS_OK;
+                            viddec_pm_get_bits(parent, &code , 1);
+                            //sei_msg_ptr->hours_flag[i] = (uint8_t)code;
+                            hours_flag = code;
+
+                            if (hours_flag) {
+                                viddec_pm_get_bits(parent, &code , 6);
+                                //sei_msg_ptr->hours_value[i] = (uint8_t)code;
+                            }
+                        }
+                    }
+                }
+
+                if (time_offset_length > 0)
+                {
+                    viddec_pm_get_bits(parent, (uint32_t *)&time_offset, time_offset_length);
+                }
+            }
+        }
+    }
+
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_pan_scan(void *parent,h264_Info* pInfo)
 {
-	h264_SEI_pan_scan_rectangle_t* sei_msg_ptr;
-   h264_SEI_pan_scan_rectangle_t  sei_pan_scan;
-	uint32_t code;
+    h264_SEI_pan_scan_rectangle_t* sei_msg_ptr;
+    h264_SEI_pan_scan_rectangle_t  sei_pan_scan;
+    uint32_t code;
 
-	viddec_workload_item_t     wi;
+    viddec_workload_item_t     wi;
 
-   h264_memset( &(sei_pan_scan), 0x0, sizeof(h264_SEI_pan_scan_rectangle_t) );
-	
-   viddec_fw_reset_workload_item(&wi);
-	wi.vwi_type = VIDDEC_WORKLOAD_H264_PAN_SCAN;
+    h264_memset( &(sei_pan_scan), 0x0, sizeof(h264_SEI_pan_scan_rectangle_t) );
 
-	sei_msg_ptr = (h264_SEI_pan_scan_rectangle_t *)(&sei_pan_scan);
+    viddec_fw_reset_workload_item(&wi);
+    wi.vwi_type = VIDDEC_WORKLOAD_H264_PAN_SCAN;
 
-	sei_msg_ptr->pan_scan_rect_id = h264_GetVLCElement(parent, pInfo, false);
+    sei_msg_ptr = (h264_SEI_pan_scan_rectangle_t *)(&sei_pan_scan);
 
-	wi.h264_sei_pan_scan.pan_scan_rect_id = sei_msg_ptr->pan_scan_rect_id;
+    sei_msg_ptr->pan_scan_rect_id = h264_GetVLCElement(parent, pInfo, false);
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->pan_scan_rect_cancel_flag = (uint8_t)code;
-   viddec_fw_h264_sei_pan_scan_set_cancel_flag(&(wi.h264_sei_pan_scan), sei_msg_ptr->pan_scan_rect_cancel_flag);
-	
-	if(!sei_msg_ptr->pan_scan_rect_cancel_flag)
-	{
-		int32_t i;
-		sei_msg_ptr->pan_scan_cnt_minus1 = h264_GetVLCElement(parent, pInfo, false);
+    wi.h264_sei_pan_scan.pan_scan_rect_id = sei_msg_ptr->pan_scan_rect_id;
 
-		viddec_fw_h264_sei_pan_scan_set_cnt_minus1(&(wi.h264_sei_pan_scan), sei_msg_ptr->pan_scan_cnt_minus1);
-		if(sei_msg_ptr->pan_scan_cnt_minus1 > MAX_PAN_SCAN_CNT -1) 
-		{
-			return H264_STATUS_SEI_ERROR;
-		}
-		for(i=0; i<= sei_msg_ptr->pan_scan_cnt_minus1; i++)
-		{
-			sei_msg_ptr->pan_scan_rect_left_offset[i] = h264_GetVLCElement(parent, pInfo, true);
-			sei_msg_ptr->pan_scan_rect_right_offset[i] = h264_GetVLCElement(parent, pInfo, true);
-			sei_msg_ptr->pan_scan_rect_top_offset[i] = h264_GetVLCElement(parent, pInfo, true);
-			sei_msg_ptr->pan_scan_rect_bottom_offset[i] = h264_GetVLCElement(parent, pInfo, true);
-		}
-		sei_msg_ptr->pan_scan_rect_repetition_period = h264_GetVLCElement(parent, pInfo, false);
-		wi.h264_sei_pan_scan.pan_scan_rect_repetition_period = sei_msg_ptr->pan_scan_rect_repetition_period;
-	}
-#ifndef VBP	
-   //cur is first frame
-   viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
-#endif   
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->pan_scan_rect_cancel_flag = (uint8_t)code;
+    viddec_fw_h264_sei_pan_scan_set_cancel_flag(&(wi.h264_sei_pan_scan), sei_msg_ptr->pan_scan_rect_cancel_flag);
 
-	if(!sei_msg_ptr->pan_scan_rect_cancel_flag)
-	{
-		int32_t i;
+    if (!sei_msg_ptr->pan_scan_rect_cancel_flag)
+    {
+        int32_t i;
+        sei_msg_ptr->pan_scan_cnt_minus1 = h264_GetVLCElement(parent, pInfo, false);
 
-      viddec_fw_reset_workload_item(&wi);
-		wi.vwi_type = VIDDEC_WORKLOAD_SEI_PAN_SCAN_RECT;
+        viddec_fw_h264_sei_pan_scan_set_cnt_minus1(&(wi.h264_sei_pan_scan), sei_msg_ptr->pan_scan_cnt_minus1);
+        if (sei_msg_ptr->pan_scan_cnt_minus1 > MAX_PAN_SCAN_CNT -1)
+        {
+            return H264_STATUS_SEI_ERROR;
+        }
+        for (i=0; i<= sei_msg_ptr->pan_scan_cnt_minus1; i++)
+        {
+            sei_msg_ptr->pan_scan_rect_left_offset[i] = h264_GetVLCElement(parent, pInfo, true);
+            sei_msg_ptr->pan_scan_rect_right_offset[i] = h264_GetVLCElement(parent, pInfo, true);
+            sei_msg_ptr->pan_scan_rect_top_offset[i] = h264_GetVLCElement(parent, pInfo, true);
+            sei_msg_ptr->pan_scan_rect_bottom_offset[i] = h264_GetVLCElement(parent, pInfo, true);
+        }
+        sei_msg_ptr->pan_scan_rect_repetition_period = h264_GetVLCElement(parent, pInfo, false);
+        wi.h264_sei_pan_scan.pan_scan_rect_repetition_period = sei_msg_ptr->pan_scan_rect_repetition_period;
+    }
+#ifndef VBP
+    //cur is first frame
+    viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
+#endif
 
-		for(i=0; i<= sei_msg_ptr->pan_scan_cnt_minus1; i++)
-		{
-         viddec_fw_h264_pan_scan_set_left(&(wi.h264_pan_scan_rect), sei_msg_ptr->pan_scan_rect_left_offset[i]);
-         viddec_fw_h264_pan_scan_set_right(&(wi.h264_pan_scan_rect), sei_msg_ptr->pan_scan_rect_right_offset[i]);
-         viddec_fw_h264_pan_scan_set_top(&(wi.h264_pan_scan_rect), sei_msg_ptr->pan_scan_rect_top_offset[i]);
-         viddec_fw_h264_pan_scan_set_bottom(&(wi.h264_pan_scan_rect), sei_msg_ptr->pan_scan_rect_bottom_offset[i]);
-#ifndef VBP         
-         //cur is first frame
-         viddec_pm_append_workitem( parent, &wi , !pInfo->Is_first_frame_in_stream);
-#endif         
-		}
-	}
+    if (!sei_msg_ptr->pan_scan_rect_cancel_flag)
+    {
+        int32_t i;
 
-	return H264_STATUS_OK;
+        viddec_fw_reset_workload_item(&wi);
+        wi.vwi_type = VIDDEC_WORKLOAD_SEI_PAN_SCAN_RECT;
+
+        for (i=0; i<= sei_msg_ptr->pan_scan_cnt_minus1; i++)
+        {
+            viddec_fw_h264_pan_scan_set_left(&(wi.h264_pan_scan_rect), sei_msg_ptr->pan_scan_rect_left_offset[i]);
+            viddec_fw_h264_pan_scan_set_right(&(wi.h264_pan_scan_rect), sei_msg_ptr->pan_scan_rect_right_offset[i]);
+            viddec_fw_h264_pan_scan_set_top(&(wi.h264_pan_scan_rect), sei_msg_ptr->pan_scan_rect_top_offset[i]);
+            viddec_fw_h264_pan_scan_set_bottom(&(wi.h264_pan_scan_rect), sei_msg_ptr->pan_scan_rect_bottom_offset[i]);
+#ifndef VBP
+            //cur is first frame
+            viddec_pm_append_workitem( parent, &wi , !pInfo->Is_first_frame_in_stream);
+#endif
+        }
+    }
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_filler_payload(void *parent,h264_Info* pInfo, uint32_t payload_size)
 {
-	
-	h264_SEI_filler_payload_t* sei_msg_ptr;
-   h264_SEI_filler_payload_t sei_filler_payload;
-	uint32_t k;
-	uint32_t code;
 
-   //remove warning
-   pInfo = pInfo; 
-	
-	sei_msg_ptr = (h264_SEI_filler_payload_t *)(&sei_filler_payload);
-	for(k=0; k < payload_size; k++)
-	{
-		viddec_pm_get_bits(parent, &code , 8);
-		sei_msg_ptr->ff_byte = (uint8_t)code;
-	}
+    h264_SEI_filler_payload_t* sei_msg_ptr;
+    h264_SEI_filler_payload_t sei_filler_payload;
+    uint32_t k;
+    uint32_t code;
 
-	return H264_STATUS_OK;
+    //remove warning
+    pInfo = pInfo;
+
+    sei_msg_ptr = (h264_SEI_filler_payload_t *)(&sei_filler_payload);
+    for (k=0; k < payload_size; k++)
+    {
+        viddec_pm_get_bits(parent, &code , 8);
+        sei_msg_ptr->ff_byte = (uint8_t)code;
+    }
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_userdata_reg(void *parent,h264_Info* pInfo, uint32_t payload_size)
 {
-	
-	h264_SEI_userdata_registered_t* sei_msg_ptr;
-   h264_SEI_userdata_registered_t  sei_userdata_registered;
-	uint32_t i;
-	int32_t byte = 0;
-	uint32_t code = 0;
-	viddec_workload_item_t     wi;
 
-	wi.vwi_type = VIDDEC_WORKLOAD_SEI_USER_DATA_REGISTERED;
+    h264_SEI_userdata_registered_t* sei_msg_ptr;
+    h264_SEI_userdata_registered_t  sei_userdata_registered;
+    uint32_t i;
+    int32_t byte = 0;
+    uint32_t code = 0;
+    viddec_workload_item_t     wi;
+
+    wi.vwi_type = VIDDEC_WORKLOAD_SEI_USER_DATA_REGISTERED;
     wi.vwi_payload[0] = wi.vwi_payload[1] = wi.vwi_payload[2] = 0;
-   //remove warning
-   pInfo = pInfo;    
-	
-	sei_msg_ptr = (h264_SEI_userdata_registered_t *)(&sei_userdata_registered);
+    //remove warning
+    pInfo = pInfo;
 
-	viddec_pm_get_bits(parent, &code , 8);
-	sei_msg_ptr->itu_t_t35_country_code = (uint8_t)code;
-	
-	if(sei_msg_ptr->itu_t_t35_country_code != 0xff)	{
-		i = 1;
-	} else {
-		viddec_pm_get_bits(parent, &code , 8);
-		sei_msg_ptr->itu_t_t35_country_code_extension_byte = (uint8_t)code;
-		i = 2;
-	}
+    sei_msg_ptr = (h264_SEI_userdata_registered_t *)(&sei_userdata_registered);
 
-	
-	wi.user_data.size =0;
-	do
-	{	
-		
-		viddec_pm_get_bits(parent, (uint32_t *)&byte, 8); 	
+    viddec_pm_get_bits(parent, &code , 8);
+    sei_msg_ptr->itu_t_t35_country_code = (uint8_t)code;
 
-      wi.user_data.data_payload[wi.user_data.size]=(uint8_t)byte;
-		wi.user_data.size++;
-    
-    	if(11 == wi.user_data.size)
-    	{  
-          viddec_pm_setup_userdata(&wi);
-#ifndef VBP          
-          //cur is first frame
-          viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
-#endif          
-          wi.user_data.size =0;    		
-    	}          
-    	
-    	i++;
-	}while(i < payload_size);
+    if (sei_msg_ptr->itu_t_t35_country_code != 0xff)	{
+        i = 1;
+    } else {
+        viddec_pm_get_bits(parent, &code , 8);
+        sei_msg_ptr->itu_t_t35_country_code_extension_byte = (uint8_t)code;
+        i = 2;
+    }
 
-	if(0!=wi.user_data.size)
-	{
-       viddec_pm_setup_userdata(&wi);
-#ifndef VBP       
-       //cur is first frame
-       viddec_pm_append_workitem( parent, &wi , !pInfo->Is_first_frame_in_stream);
-#endif       
-	}
-	
-	return H264_STATUS_OK;
+
+    wi.user_data.size =0;
+    do
+    {
+
+        viddec_pm_get_bits(parent, (uint32_t *)&byte, 8);
+
+        wi.user_data.data_payload[wi.user_data.size]=(uint8_t)byte;
+        wi.user_data.size++;
+
+        if (11 == wi.user_data.size)
+        {
+            viddec_pm_setup_userdata(&wi);
+#ifndef VBP
+            //cur is first frame
+            viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
+#endif
+            wi.user_data.size =0;
+        }
+
+        i++;
+    } while (i < payload_size);
+
+    if (0!=wi.user_data.size)
+    {
+        viddec_pm_setup_userdata(&wi);
+#ifndef VBP
+        //cur is first frame
+        viddec_pm_append_workitem( parent, &wi , !pInfo->Is_first_frame_in_stream);
+#endif
+    }
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_userdata_unreg(void *parent, h264_Info* pInfo, uint32_t payload_size)
 {
-	
-	h264_SEI_userdata_unregistered_t* sei_msg_ptr;
-   h264_SEI_userdata_unregistered_t  sei_userdata_unregistered;
-	uint32_t i;
-	int32_t byte = 0;
-	uint32_t code;
 
-	viddec_workload_item_t     wi;
+    h264_SEI_userdata_unregistered_t* sei_msg_ptr;
+    h264_SEI_userdata_unregistered_t  sei_userdata_unregistered;
+    uint32_t i;
+    int32_t byte = 0;
+    uint32_t code;
+
+    viddec_workload_item_t     wi;
 
     wi.vwi_type = VIDDEC_WORKLOAD_SEI_USER_DATA_UNREGISTERED;
 
     //remove warning
-    pInfo = pInfo; 
+    pInfo = pInfo;
 
-	sei_msg_ptr = (h264_SEI_userdata_unregistered_t *)(&sei_userdata_unregistered);
+    sei_msg_ptr = (h264_SEI_userdata_unregistered_t *)(&sei_userdata_unregistered);
 
-	for (i = 0; i < 4; i++) 
-  	{
-		viddec_pm_get_bits(parent, &code , 32);
-		sei_msg_ptr->uuid_iso_iec_11578[i] = (uint8_t)code;
-  	}
-  
-  	wi.user_data.size =0;
-  	for(i = 16; i < payload_size; i++) 
-  	{
-    	
-		viddec_pm_get_bits(parent, (uint32_t *)&byte, 8); 	
+    for (i = 0; i < 4; i++)
+    {
+        viddec_pm_get_bits(parent, &code , 32);
+        sei_msg_ptr->uuid_iso_iec_11578[i] = (uint8_t)code;
+    }
 
-		wi.user_data.data_payload[wi.user_data.size]=(uint8_t)byte;
-		wi.user_data.size++;
-    
-    	if(11 == wi.user_data.size)
-    	{  
-          viddec_pm_setup_userdata(&wi);
-#ifndef VBP          
-          //cur is first frame
-          viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
-#endif         
-          wi.user_data.size =0;     		
-    	}    	
-  	}
+    wi.user_data.size =0;
+    for (i = 16; i < payload_size; i++)
+    {
 
-	if(0!=wi.user_data.size)
-	{
-       viddec_pm_setup_userdata(&wi);
-#ifndef VBP       
-       //cur is first frame
-       viddec_pm_append_workitem( parent, &wi , !pInfo->Is_first_frame_in_stream);
-#endif       
-	}
-	
-	return H264_STATUS_OK;
+        viddec_pm_get_bits(parent, (uint32_t *)&byte, 8);
+
+        wi.user_data.data_payload[wi.user_data.size]=(uint8_t)byte;
+        wi.user_data.size++;
+
+        if (11 == wi.user_data.size)
+        {
+            viddec_pm_setup_userdata(&wi);
+#ifndef VBP
+            //cur is first frame
+            viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
+#endif
+            wi.user_data.size =0;
+        }
+    }
+
+    if (0!=wi.user_data.size)
+    {
+        viddec_pm_setup_userdata(&wi);
+#ifndef VBP
+        //cur is first frame
+        viddec_pm_append_workitem( parent, &wi , !pInfo->Is_first_frame_in_stream);
+#endif
+    }
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_recovery_point(void *parent, h264_Info* pInfo)
 {
-	
-	h264_SEI_recovery_point_t* sei_msg_ptr;
-   h264_SEI_recovery_point_t  sei_recovery_point;
-	uint32_t code;
-	viddec_workload_item_t     wi;
 
-	
-	sei_msg_ptr = (h264_SEI_recovery_point_t *)(&sei_recovery_point);
-	
-	sei_msg_ptr->recovery_frame_cnt = h264_GetVLCElement(parent, pInfo, false);
+    h264_SEI_recovery_point_t* sei_msg_ptr;
+    h264_SEI_recovery_point_t  sei_recovery_point;
+    uint32_t code;
+    viddec_workload_item_t     wi;
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->exact_match_flag = (uint8_t)code;
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->broken_link_flag = (uint8_t)code;
+    sei_msg_ptr = (h264_SEI_recovery_point_t *)(&sei_recovery_point);
 
-	viddec_pm_get_bits(parent, &code , 2);
-	sei_msg_ptr->changing_slice_group_idc = (uint8_t)code;
+    sei_msg_ptr->recovery_frame_cnt = h264_GetVLCElement(parent, pInfo, false);
 
-	pInfo->sei_information.recovery_point = 1;
-	pInfo->sei_information.recovery_frame_cnt = (int32_t) sei_msg_ptr->recovery_frame_cnt;
-	pInfo->sei_information.capture_fn         = 1;
-	pInfo->sei_information.broken_link_pic    = sei_msg_ptr->broken_link_flag;
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->exact_match_flag = (uint8_t)code;
 
-	if(pInfo->got_start)	{
-		pInfo->img.recovery_point_found |= 2;
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->broken_link_flag = (uint8_t)code;
 
-		//// Enable the RP recovery if no IDR ---Cisco
-		if((pInfo->img.recovery_point_found & 1)==0)
-			pInfo->sei_rp_received = 1;
-	}	
+    viddec_pm_get_bits(parent, &code , 2);
+    sei_msg_ptr->changing_slice_group_idc = (uint8_t)code;
 
-	//
-	/// Append workload for SEI
-	//
-   viddec_fw_reset_workload_item(&wi);
-   wi.vwi_type = VIDDEC_WORKLOAD_SEI_RECOVERY_POINT;
-	wi.h264_sei_recovery_point.recovery_frame_cnt = sei_msg_ptr->recovery_frame_cnt;
-   viddec_fw_h264_h264_sei_recovery_set_exact_match_flag(&(wi.h264_sei_recovery_point), sei_msg_ptr->exact_match_flag);
-   viddec_fw_h264_h264_sei_recovery_set_broken_link_flag(&(wi.h264_sei_recovery_point), sei_msg_ptr->broken_link_flag);
-	wi.h264_sei_recovery_point.changing_slice_group_idc = sei_msg_ptr->changing_slice_group_idc;
-#ifndef VBP	
-   //cur is first frame
-   viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
-#endif   
+    pInfo->sei_information.recovery_point = 1;
+    pInfo->sei_information.recovery_frame_cnt = (int32_t) sei_msg_ptr->recovery_frame_cnt;
+    pInfo->sei_information.capture_fn         = 1;
+    pInfo->sei_information.broken_link_pic    = sei_msg_ptr->broken_link_flag;
 
-	return H264_STATUS_OK;
+    if (pInfo->got_start)	{
+        pInfo->img.recovery_point_found |= 2;
+
+        //// Enable the RP recovery if no IDR ---Cisco
+        if ((pInfo->img.recovery_point_found & 1)==0)
+            pInfo->sei_rp_received = 1;
+    }
+
+    //
+    /// Append workload for SEI
+    //
+    viddec_fw_reset_workload_item(&wi);
+    wi.vwi_type = VIDDEC_WORKLOAD_SEI_RECOVERY_POINT;
+    wi.h264_sei_recovery_point.recovery_frame_cnt = sei_msg_ptr->recovery_frame_cnt;
+    viddec_fw_h264_h264_sei_recovery_set_exact_match_flag(&(wi.h264_sei_recovery_point), sei_msg_ptr->exact_match_flag);
+    viddec_fw_h264_h264_sei_recovery_set_broken_link_flag(&(wi.h264_sei_recovery_point), sei_msg_ptr->broken_link_flag);
+    wi.h264_sei_recovery_point.changing_slice_group_idc = sei_msg_ptr->changing_slice_group_idc;
+#ifndef VBP
+    //cur is first frame
+    viddec_pm_append_workitem( parent, &wi , !(pInfo->Is_first_frame_in_stream ||(!pInfo->is_current_workload_done)));
+#endif
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_dec_ref_pic_marking_rep(void *parent,h264_Info* pInfo)
 {
-	
-	h264_SEI_decoded_ref_pic_marking_repetition_t* sei_msg_ptr;
-   h264_SEI_decoded_ref_pic_marking_repetition_t  sei_ref_pic;
-	uint32_t code;
-	
-	sei_msg_ptr = (h264_SEI_decoded_ref_pic_marking_repetition_t *)(&sei_ref_pic);
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->original_idr_flag = (uint8_t)code;
-	
-	sei_msg_ptr->original_frame_num = h264_GetVLCElement(parent, pInfo, false);
+    h264_SEI_decoded_ref_pic_marking_repetition_t* sei_msg_ptr;
+    h264_SEI_decoded_ref_pic_marking_repetition_t  sei_ref_pic;
+    uint32_t code;
 
-	if(!(pInfo->active_SPS.sps_disp.frame_mbs_only_flag))
-	{
-		viddec_pm_get_bits(parent, &code , 1);
-		sei_msg_ptr->orignal_field_pic_flag = (uint8_t)code;
-	
-		if(sei_msg_ptr->orignal_field_pic_flag)
-		{
-			viddec_pm_get_bits(parent, &code , 1);
-			sei_msg_ptr->original_bottom_field_pic_flag = (uint8_t)code;
-		}
-	}
-	h264_Parse_Dec_Ref_Pic_Marking(parent, pInfo, &pInfo->SliceHeader);
-	return H264_STATUS_OK;
+    sei_msg_ptr = (h264_SEI_decoded_ref_pic_marking_repetition_t *)(&sei_ref_pic);
+
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->original_idr_flag = (uint8_t)code;
+
+    sei_msg_ptr->original_frame_num = h264_GetVLCElement(parent, pInfo, false);
+
+    if (!(pInfo->active_SPS.sps_disp.frame_mbs_only_flag))
+    {
+        viddec_pm_get_bits(parent, &code , 1);
+        sei_msg_ptr->orignal_field_pic_flag = (uint8_t)code;
+
+        if (sei_msg_ptr->orignal_field_pic_flag)
+        {
+            viddec_pm_get_bits(parent, &code , 1);
+            sei_msg_ptr->original_bottom_field_pic_flag = (uint8_t)code;
+        }
+    }
+    h264_Parse_Dec_Ref_Pic_Marking(parent, pInfo, &pInfo->SliceHeader);
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_spare_pic(void *parent,h264_Info* pInfo)
 {
-	
-	//h264_SEI_spare_picture_t* sei_msg_ptr;
 
-   //remove warning
-   pInfo = pInfo; 
-   parent = parent;
-	
-	//sei_msg_ptr = (h264_SEI_spare_picture_t *)(&user_data->user_data[0]);
+    //h264_SEI_spare_picture_t* sei_msg_ptr;
 
-	//OS_INFO("Not supported SEI\n");
-	return H264_STATUS_OK;
+    //remove warning
+    pInfo = pInfo;
+    parent = parent;
+
+    //sei_msg_ptr = (h264_SEI_spare_picture_t *)(&user_data->user_data[0]);
+
+    //OS_INFO("Not supported SEI\n");
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_scene_info(void *parent,h264_Info* pInfo)
 {
-	
-	h264_SEI_scene_info_t* sei_msg_ptr;
-   h264_SEI_scene_info_t  sei_scene_info;
-	uint32_t code;
-	
-	sei_msg_ptr = (h264_SEI_scene_info_t*)(&sei_scene_info);
-	
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->scene_info_present_flag = (uint8_t)code;
 
-	if(sei_msg_ptr->scene_info_present_flag)
-	{
-		sei_msg_ptr->scene_id = h264_GetVLCElement(parent, pInfo, false);
-		sei_msg_ptr->scene_transitioning_type= h264_GetVLCElement(parent, pInfo, false);
-		if(sei_msg_ptr->scene_transitioning_type > 3)
-		{
-			sei_msg_ptr->second_scene_id = h264_GetVLCElement(parent, pInfo, false);
-		}
-	}
-	
-	return H264_STATUS_OK;
+    h264_SEI_scene_info_t* sei_msg_ptr;
+    h264_SEI_scene_info_t  sei_scene_info;
+    uint32_t code;
+
+    sei_msg_ptr = (h264_SEI_scene_info_t*)(&sei_scene_info);
+
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->scene_info_present_flag = (uint8_t)code;
+
+    if (sei_msg_ptr->scene_info_present_flag)
+    {
+        sei_msg_ptr->scene_id = h264_GetVLCElement(parent, pInfo, false);
+        sei_msg_ptr->scene_transitioning_type= h264_GetVLCElement(parent, pInfo, false);
+        if (sei_msg_ptr->scene_transitioning_type > 3)
+        {
+            sei_msg_ptr->second_scene_id = h264_GetVLCElement(parent, pInfo, false);
+        }
+    }
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_sub_seq_info(void *parent,h264_Info* pInfo)
 {
-	
-	h264_SEI_sub_sequence_info_t* sei_msg_ptr;
-   h264_SEI_sub_sequence_info_t  sei_sub_sequence_info;
-	uint32_t code;
-	
-	sei_msg_ptr = (h264_SEI_sub_sequence_info_t *)(&sei_sub_sequence_info);
 
-	sei_msg_ptr->sub_seq_layer_num = h264_GetVLCElement(parent, pInfo,false);
-	sei_msg_ptr->sub_seq_id= h264_GetVLCElement(parent, pInfo,false);
+    h264_SEI_sub_sequence_info_t* sei_msg_ptr;
+    h264_SEI_sub_sequence_info_t  sei_sub_sequence_info;
+    uint32_t code;
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->first_ref_pic_flag = (uint8_t)code;
+    sei_msg_ptr = (h264_SEI_sub_sequence_info_t *)(&sei_sub_sequence_info);
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->leading_non_ref_pic_flag = (uint8_t)code;
+    sei_msg_ptr->sub_seq_layer_num = h264_GetVLCElement(parent, pInfo,false);
+    sei_msg_ptr->sub_seq_id= h264_GetVLCElement(parent, pInfo,false);
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->last_pic_flag = (uint8_t)code;
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->first_ref_pic_flag = (uint8_t)code;
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->sub_seq_frame_num_flag = (uint8_t)code;
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->leading_non_ref_pic_flag = (uint8_t)code;
 
-	
-	if(sei_msg_ptr->sub_seq_frame_num_flag)
-	{
-		sei_msg_ptr->sub_seq_frame_num = h264_GetVLCElement(parent, pInfo,false);	
-	}
-	return H264_STATUS_OK;
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->last_pic_flag = (uint8_t)code;
+
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->sub_seq_frame_num_flag = (uint8_t)code;
+
+
+    if (sei_msg_ptr->sub_seq_frame_num_flag)
+    {
+        sei_msg_ptr->sub_seq_frame_num = h264_GetVLCElement(parent, pInfo,false);
+    }
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_sub_seq_layer(void *parent,h264_Info* pInfo)
 {
-	
-	h264_SEI_sub_sequence_layer_t* sei_msg_ptr;
-   h264_SEI_sub_sequence_layer_t  sei_sub_sequence_layer;
-	int32_t layer;
-	uint32_t code;
-	
-	sei_msg_ptr = (h264_SEI_sub_sequence_layer_t *)(&sei_sub_sequence_layer);
-	sei_msg_ptr->num_sub_seq_layers_minus1 = h264_GetVLCElement(parent, pInfo,false);
 
-	if(sei_msg_ptr->num_sub_seq_layers_minus1 >= MAX_SUB_SEQ_LAYERS)
-	{
-		return H264_STATUS_SEI_ERROR;
-	}
-	
-	for(layer = 0;layer <= sei_msg_ptr->num_sub_seq_layers_minus1; layer++)
-	{
-		viddec_pm_get_bits(parent, &code , 1);
-		sei_msg_ptr->accurate_statistics_flag[layer] = (uint8_t)code;
+    h264_SEI_sub_sequence_layer_t* sei_msg_ptr;
+    h264_SEI_sub_sequence_layer_t  sei_sub_sequence_layer;
+    int32_t layer;
+    uint32_t code;
 
-		viddec_pm_get_bits(parent, &code , 16);
-		sei_msg_ptr->average_bit_rate[layer] = (uint16_t)code;
+    sei_msg_ptr = (h264_SEI_sub_sequence_layer_t *)(&sei_sub_sequence_layer);
+    sei_msg_ptr->num_sub_seq_layers_minus1 = h264_GetVLCElement(parent, pInfo,false);
 
-		viddec_pm_get_bits(parent, &code , 16);
-		sei_msg_ptr->average_frame_rate[layer] = (uint16_t)code;
+    if (sei_msg_ptr->num_sub_seq_layers_minus1 >= MAX_SUB_SEQ_LAYERS)
+    {
+        return H264_STATUS_SEI_ERROR;
+    }
 
-	}
-	
-	return H264_STATUS_OK;
+    for (layer = 0; layer <= sei_msg_ptr->num_sub_seq_layers_minus1; layer++)
+    {
+        viddec_pm_get_bits(parent, &code , 1);
+        sei_msg_ptr->accurate_statistics_flag[layer] = (uint8_t)code;
+
+        viddec_pm_get_bits(parent, &code , 16);
+        sei_msg_ptr->average_bit_rate[layer] = (uint16_t)code;
+
+        viddec_pm_get_bits(parent, &code , 16);
+        sei_msg_ptr->average_frame_rate[layer] = (uint16_t)code;
+
+    }
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_sub_seq(void *parent,h264_Info* pInfo)
 {
-	int32_t n;
-	uint32_t code;
+    int32_t n;
+    uint32_t code;
 
-	h264_SEI_sub_sequence_t* sei_msg_ptr;
-   h264_SEI_sub_sequence_t  sei_sub_sequence;
-	
-	sei_msg_ptr = (h264_SEI_sub_sequence_t *)(&sei_sub_sequence);
+    h264_SEI_sub_sequence_t* sei_msg_ptr;
+    h264_SEI_sub_sequence_t  sei_sub_sequence;
 
-	sei_msg_ptr->sub_seq_layer_num = h264_GetVLCElement(parent, pInfo, false);
-	sei_msg_ptr->sub_seq_id= h264_GetVLCElement(parent, pInfo, false);
-	
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->duration_flag = (uint8_t)code;
+    sei_msg_ptr = (h264_SEI_sub_sequence_t *)(&sei_sub_sequence);
 
-	if(sei_msg_ptr->duration_flag)
-	{
-		viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->sub_seq_duration, 32);
-	}
-	
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->average_rate_flag = (uint8_t)code;
+    sei_msg_ptr->sub_seq_layer_num = h264_GetVLCElement(parent, pInfo, false);
+    sei_msg_ptr->sub_seq_id= h264_GetVLCElement(parent, pInfo, false);
 
-	if(sei_msg_ptr->average_rate_flag)
-	{
-		viddec_pm_get_bits(parent, &code , 1);
-		sei_msg_ptr->average_statistics_flag = (uint8_t)code;
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->duration_flag = (uint8_t)code;
 
-		viddec_pm_get_bits(parent, &code , 16);
-		sei_msg_ptr->average_bit_rate = (uint8_t)code;
+    if (sei_msg_ptr->duration_flag)
+    {
+        viddec_pm_get_bits(parent, (uint32_t *)&sei_msg_ptr->sub_seq_duration, 32);
+    }
 
-		viddec_pm_get_bits(parent, &code , 16);
-		sei_msg_ptr->average_frame_rate = (uint8_t)code;
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->average_rate_flag = (uint8_t)code;
 
-	}
-	sei_msg_ptr->num_referenced_subseqs = h264_GetVLCElement(parent, pInfo, false);
-	if(sei_msg_ptr->num_referenced_subseqs >= MAX_NUM_REF_SUBSEQS)
-	{
-		return H264_STATUS_SEI_ERROR;
-	}
+    if (sei_msg_ptr->average_rate_flag)
+    {
+        viddec_pm_get_bits(parent, &code , 1);
+        sei_msg_ptr->average_statistics_flag = (uint8_t)code;
 
-	for(n = 0; n < sei_msg_ptr->num_referenced_subseqs; n++)
-	{
-		sei_msg_ptr->ref_sub_seq_layer_num= h264_GetVLCElement(parent, pInfo, false);
-		sei_msg_ptr->ref_sub_seq_id= h264_GetVLCElement(parent, pInfo, false);
-		
-		viddec_pm_get_bits(parent, &code , 1);
-		sei_msg_ptr->ref_sub_seq_direction = (uint8_t)code;
-	}
-	return H264_STATUS_OK;
+        viddec_pm_get_bits(parent, &code , 16);
+        sei_msg_ptr->average_bit_rate = (uint8_t)code;
+
+        viddec_pm_get_bits(parent, &code , 16);
+        sei_msg_ptr->average_frame_rate = (uint8_t)code;
+
+    }
+    sei_msg_ptr->num_referenced_subseqs = h264_GetVLCElement(parent, pInfo, false);
+    if (sei_msg_ptr->num_referenced_subseqs >= MAX_NUM_REF_SUBSEQS)
+    {
+        return H264_STATUS_SEI_ERROR;
+    }
+
+    for (n = 0; n < sei_msg_ptr->num_referenced_subseqs; n++)
+    {
+        sei_msg_ptr->ref_sub_seq_layer_num= h264_GetVLCElement(parent, pInfo, false);
+        sei_msg_ptr->ref_sub_seq_id= h264_GetVLCElement(parent, pInfo, false);
+
+        viddec_pm_get_bits(parent, &code , 1);
+        sei_msg_ptr->ref_sub_seq_direction = (uint8_t)code;
+    }
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_full_frame_freeze(void *parent,h264_Info* pInfo)
 {
-	
-	h264_SEI_full_frame_freeze_t* sei_msg_ptr;
-   h264_SEI_full_frame_freeze_t  sei_full_frame_freeze;
-	
-	sei_msg_ptr = (h264_SEI_full_frame_freeze_t *)(&sei_full_frame_freeze);
 
-	sei_msg_ptr->full_frame_freeze_repetition_period= h264_GetVLCElement(parent, pInfo, false);
-	
-	pInfo->sei_information.capture_POC        = 1;
-	pInfo->sei_information.freeze_rep_period  = sei_msg_ptr->full_frame_freeze_repetition_period;
-	//pInfo->img.sei_freeze_this_image          = 1;
-	
-	return H264_STATUS_OK;
+    h264_SEI_full_frame_freeze_t* sei_msg_ptr;
+    h264_SEI_full_frame_freeze_t  sei_full_frame_freeze;
+
+    sei_msg_ptr = (h264_SEI_full_frame_freeze_t *)(&sei_full_frame_freeze);
+
+    sei_msg_ptr->full_frame_freeze_repetition_period= h264_GetVLCElement(parent, pInfo, false);
+
+    pInfo->sei_information.capture_POC        = 1;
+    pInfo->sei_information.freeze_rep_period  = sei_msg_ptr->full_frame_freeze_repetition_period;
+    //pInfo->img.sei_freeze_this_image          = 1;
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_full_frame_freeze_release(void *parent,h264_Info* pInfo)
 {
-   //remove warning
-   parent = parent;
-   pInfo = pInfo;
+    //remove warning
+    parent = parent;
+    pInfo = pInfo;
 
-   
-	return H264_STATUS_OK;
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_full_frame_snapshot(void *parent,h264_Info* pInfo)
 {
-	
-	h264_SEI_full_frame_snapshot_t* sei_msg_ptr;
-   h264_SEI_full_frame_snapshot_t  sei_full_frame_snapshot;
-	
-	sei_msg_ptr = (h264_SEI_full_frame_snapshot_t *)(&sei_full_frame_snapshot);
 
-	sei_msg_ptr->snapshot_id = h264_GetVLCElement(parent, pInfo, false);
-	return H264_STATUS_OK;
+    h264_SEI_full_frame_snapshot_t* sei_msg_ptr;
+    h264_SEI_full_frame_snapshot_t  sei_full_frame_snapshot;
+
+    sei_msg_ptr = (h264_SEI_full_frame_snapshot_t *)(&sei_full_frame_snapshot);
+
+    sei_msg_ptr->snapshot_id = h264_GetVLCElement(parent, pInfo, false);
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_progressive_segement_start(void *parent,h264_Info* pInfo)
 {
-	
-	h264_SEI_progressive_segment_start_t* sei_msg_ptr;
-   h264_SEI_progressive_segment_start_t  sei_progressive_segment_start;
-	
-	sei_msg_ptr = (h264_SEI_progressive_segment_start_t *)(&sei_progressive_segment_start);
 
-	sei_msg_ptr->progressive_refinement_id= h264_GetVLCElement(parent, pInfo, false);
-	sei_msg_ptr->num_refinement_steps_minus1= h264_GetVLCElement(parent, pInfo, false);
-	return H264_STATUS_OK;
+    h264_SEI_progressive_segment_start_t* sei_msg_ptr;
+    h264_SEI_progressive_segment_start_t  sei_progressive_segment_start;
+
+    sei_msg_ptr = (h264_SEI_progressive_segment_start_t *)(&sei_progressive_segment_start);
+
+    sei_msg_ptr->progressive_refinement_id= h264_GetVLCElement(parent, pInfo, false);
+    sei_msg_ptr->num_refinement_steps_minus1= h264_GetVLCElement(parent, pInfo, false);
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_progressive_segment_end(void *parent,h264_Info* pInfo)
 {
-	
-	h264_SEI_progressive_segment_end_t* sei_msg_ptr;
-   h264_SEI_progressive_segment_end_t  sei_progressive_segment_end;
-	
-	sei_msg_ptr = (h264_SEI_progressive_segment_end_t *)(&sei_progressive_segment_end);
 
-	sei_msg_ptr->progressive_refinement_id = h264_GetVLCElement(parent, pInfo, false);
-	return H264_STATUS_OK;
+    h264_SEI_progressive_segment_end_t* sei_msg_ptr;
+    h264_SEI_progressive_segment_end_t  sei_progressive_segment_end;
+
+    sei_msg_ptr = (h264_SEI_progressive_segment_end_t *)(&sei_progressive_segment_end);
+
+    sei_msg_ptr->progressive_refinement_id = h264_GetVLCElement(parent, pInfo, false);
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_motion_constrained_slice_grp_set(void *parent, h264_Info* pInfo)
 {
-	int32_t i;
-	uint32_t code;
-	h264_SEI_motion_constrained_slice_group_t* sei_msg_ptr;
-   h264_SEI_motion_constrained_slice_group_t  sei_motion_constrained_slice_group;
-	
-	sei_msg_ptr = (h264_SEI_motion_constrained_slice_group_t *)(&sei_motion_constrained_slice_group);
+    int32_t i;
+    uint32_t code;
+    h264_SEI_motion_constrained_slice_group_t* sei_msg_ptr;
+    h264_SEI_motion_constrained_slice_group_t  sei_motion_constrained_slice_group;
 
-	sei_msg_ptr->num_slice_groups_in_set_minus1= h264_GetVLCElement(parent, pInfo, false);
-	if(sei_msg_ptr->num_slice_groups_in_set_minus1 >= MAX_NUM_SLICE_GRPS)
-	{
-		return H264_STATUS_SEI_ERROR;
-	}
-	
-	for(i=0; i<= sei_msg_ptr->num_slice_groups_in_set_minus1; i++)
-	{
-		viddec_pm_get_bits(parent, &code , 1);
-		sei_msg_ptr->slice_group_id[i] = (uint8_t)code;
-	}
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->exact_sample_value_match_flag = (uint8_t)code;
+    sei_msg_ptr = (h264_SEI_motion_constrained_slice_group_t *)(&sei_motion_constrained_slice_group);
 
-	viddec_pm_get_bits(parent, &code , 1);
-	sei_msg_ptr->pan_scan_rect_flag = (uint8_t)code;
+    sei_msg_ptr->num_slice_groups_in_set_minus1= h264_GetVLCElement(parent, pInfo, false);
+    if (sei_msg_ptr->num_slice_groups_in_set_minus1 >= MAX_NUM_SLICE_GRPS)
+    {
+        return H264_STATUS_SEI_ERROR;
+    }
 
-	
-	if(sei_msg_ptr->pan_scan_rect_flag)
-	{
-		sei_msg_ptr->pan_scan_rect_id= h264_GetVLCElement(parent, pInfo, false);
-	}
-	return H264_STATUS_OK;
+    for (i=0; i<= sei_msg_ptr->num_slice_groups_in_set_minus1; i++)
+    {
+        viddec_pm_get_bits(parent, &code , 1);
+        sei_msg_ptr->slice_group_id[i] = (uint8_t)code;
+    }
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->exact_sample_value_match_flag = (uint8_t)code;
+
+    viddec_pm_get_bits(parent, &code , 1);
+    sei_msg_ptr->pan_scan_rect_flag = (uint8_t)code;
+
+
+    if (sei_msg_ptr->pan_scan_rect_flag)
+    {
+        sei_msg_ptr->pan_scan_rect_id= h264_GetVLCElement(parent, pInfo, false);
+    }
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_film_grain_characteristics(void *parent,h264_Info* pInfo)
 {
-	//OS_INFO("Not supported SEI\n");
+    //OS_INFO("Not supported SEI\n");
 
-   //remove warning
-   parent = parent;
-   pInfo = pInfo; 
+    //remove warning
+    parent = parent;
+    pInfo = pInfo;
 
 
 
-   
-	return H264_STATUS_OK;
+
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_deblocking_filter_display_preferences(void *parent,h264_Info* pInfo)
 {
-	
-	//h264_SEI_deblocking_filter_display_pref_t* sei_msg_ptr;
 
-   //remove warning
-   parent = parent;
-   pInfo = pInfo;  
-	
-	//sei_msg_ptr = (h264_SEI_deblocking_filter_display_pref_t *)(&user_data->user_data[0]);
+    //h264_SEI_deblocking_filter_display_pref_t* sei_msg_ptr;
 
-	//OS_INFO("Not supported SEI\n");
-	return H264_STATUS_OK;
+    //remove warning
+    parent = parent;
+    pInfo = pInfo;
+
+    //sei_msg_ptr = (h264_SEI_deblocking_filter_display_pref_t *)(&user_data->user_data[0]);
+
+    //OS_INFO("Not supported SEI\n");
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_sei_stereo_video_info(void *parent,h264_Info* pInfo)
 {
-	
-	//h264_SEI_stereo_video_info_t* sei_msg_ptr;
 
-   //remove warning
-   parent = parent;
-   pInfo = pInfo;
-   
-	
-	//sei_msg_ptr = (h264_SEI_stereo_video_info_t *)(&user_data->user_data[0]);
+    //h264_SEI_stereo_video_info_t* sei_msg_ptr;
 
-	//OS_INFO("Not supported SEI\n");
-	return H264_STATUS_OK;
+    //remove warning
+    parent = parent;
+    pInfo = pInfo;
+
+
+    //sei_msg_ptr = (h264_SEI_stereo_video_info_t *)(&user_data->user_data[0]);
+
+    //OS_INFO("Not supported SEI\n");
+    return H264_STATUS_OK;
 }
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 /* ------------------------------------------------------------------------------------------ */
 uint32_t h264_sei_reserved_sei_message(void *parent, h264_Info* pInfo, uint32_t payload_size)
 {
-	int32_t k, byte_index, user_data_byte_index;
-   uint32_t i;
-	int32_t word, bits;
-   uint32_t user_data;
-	//h264_SEI_reserved_t* sei_msg_ptr;
-   //h264_SEI_reserved_t  sei_reserved;
+    int32_t k, byte_index, user_data_byte_index;
+    uint32_t i;
+    int32_t word, bits;
+    uint32_t user_data;
+    //h264_SEI_reserved_t* sei_msg_ptr;
+    //h264_SEI_reserved_t  sei_reserved;
 
-   //remove warning
-   pInfo = pInfo;   
-	
-	//sei_msg_ptr = (h264_SEI_reserved_t *)(&sei_reserved);
-	
-  	byte_index = 0;
-	word = 0;
-	user_data_byte_index = 0x0;
-	
-	for(i = 0, k = 0; i < payload_size; i++) 
-	{
-		if(byte_index == 0) word = 0;
-		viddec_pm_get_bits(parent, (uint32_t *)&bits, 8);
-		
-		switch (byte_index)
-		{
-			case 1: 
-			 	word = (bits << 8) | word; 
-				break;
-		  	case 2: 
-				word = (bits << 16) | word; 
-				break;
-		  	case 3: 
-				word = (bits << 24) | word; 
-				break;
-		  	default : 
-				word = bits; 
-				break;
-		} 
-		
-		if(byte_index == 3)
-		{  
-		  byte_index = 0;
-		  user_data = word;
-		  k++;
-		}		   
-		else
-		{
-			byte_index++;
-		}
-	
-		user_data_byte_index++;
-		if ( user_data_byte_index == MAX_USER_DATA_SIZE) 
-		{	  
-			//user_data->user_data_size = user_data_byte_index;
-			//sei_msg_ptr = (h264_SEI_reserved_t *)(&user_data->user_data[0]);
-		  	byte_index = 0;
-		  	word = 0;
-		  	user_data_byte_index = 0x0;
-		}
-	}
-	
-	if(byte_index)
-		user_data = word;
-	
-	//user_data->user_data_size = user_data_byte_index;
-	
-	return user_data_byte_index;
-	
+    //remove warning
+    pInfo = pInfo;
+
+    //sei_msg_ptr = (h264_SEI_reserved_t *)(&sei_reserved);
+
+    byte_index = 0;
+    word = 0;
+    user_data_byte_index = 0x0;
+
+    for (i = 0, k = 0; i < payload_size; i++)
+    {
+        if (byte_index == 0) word = 0;
+        viddec_pm_get_bits(parent, (uint32_t *)&bits, 8);
+
+        switch (byte_index)
+        {
+        case 1:
+            word = (bits << 8) | word;
+            break;
+        case 2:
+            word = (bits << 16) | word;
+            break;
+        case 3:
+            word = (bits << 24) | word;
+            break;
+        default :
+            word = bits;
+            break;
+        }
+
+        if (byte_index == 3)
+        {
+            byte_index = 0;
+            user_data = word;
+            k++;
+        }
+        else
+        {
+            byte_index++;
+        }
+
+        user_data_byte_index++;
+        if ( user_data_byte_index == MAX_USER_DATA_SIZE)
+        {
+            //user_data->user_data_size = user_data_byte_index;
+            //sei_msg_ptr = (h264_SEI_reserved_t *)(&user_data->user_data[0]);
+            byte_index = 0;
+            word = 0;
+            user_data_byte_index = 0x0;
+        }
+    }
+
+    if (byte_index)
+        user_data = word;
+
+    //user_data->user_data_size = user_data_byte_index;
+
+    return user_data_byte_index;
+
 //	return H264_STATUS_OK;
 }
 
@@ -958,97 +958,97 @@
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_SEI_payload(void *parent, h264_Info* pInfo, h264_sei_payloadtype payloadType, int32_t payloadSize)
 {
-	//int32_t bit_equal_to_zero;
-	h264_Status status = H264_STATUS_OK;
+    //int32_t bit_equal_to_zero;
+    h264_Status status = H264_STATUS_OK;
 
-   //removing warning
-   payloadSize = payloadSize;
+    //removing warning
+    payloadSize = payloadSize;
 
-	switch(payloadType)
-	{
-		case SEI_BUF_PERIOD:
-			status = h264_sei_buffering_period(parent, pInfo);
-			break;
-		case SEI_PIC_TIMING:
-			status = h264_sei_pic_timing(parent, pInfo);
-			break;
-		case SEI_PAN_SCAN:
-			status = h264_sei_pan_scan(parent, pInfo);
-			break;
-		case SEI_FILLER_PAYLOAD:
-			status = h264_sei_filler_payload(parent, pInfo, payloadSize);
-			break;
-		case SEI_REG_USERDATA:
-			status = h264_sei_userdata_reg(parent, pInfo, payloadSize);
-			break;
-		case SEI_UNREG_USERDATA:
-			status = h264_sei_userdata_unreg(parent, pInfo, payloadSize);
-			break;
-		case SEI_RECOVERY_POINT:
-			h264_sei_recovery_point(parent, pInfo);
-			break;
-		case SEI_DEC_REF_PIC_MARKING_REP:
-			status = h264_sei_dec_ref_pic_marking_rep(parent, pInfo);
-			break;
-		case SEI_SPARE_PIC:
-			status = h264_sei_spare_pic(parent, pInfo);
-			break;
-		case SEI_SCENE_INFO:
-			status = h264_sei_scene_info(parent, pInfo);
-			break;
-		case SEI_SUB_SEQ_INFO:
-			status = h264_sei_sub_seq_info(parent, pInfo);
-			break;
-		case SEI_SUB_SEQ_LAYER:
-			status = h264_sei_sub_seq_layer(parent, pInfo);
-			break;
-		case SEI_SUB_SEQ:
-			status = h264_sei_sub_seq(parent, pInfo);
-			break;
-		case SEI_FULL_FRAME_FREEZE:
-			status = h264_sei_full_frame_freeze(parent, pInfo);
-			break;
-		case SEI_FULL_FRAME_FREEZE_RELEASE:
-			h264_sei_full_frame_freeze_release(parent, pInfo);
-			break;
-		case SEI_FULL_FRAME_SNAPSHOT:
-			status = h264_sei_full_frame_snapshot(parent, pInfo);
-			break;
-		case SEI_PROGRESSIVE_SEGMENT_START:
-			status = h264_sei_progressive_segement_start(parent, pInfo);
-			break;
-		case SEI_PROGRESSIVE_SEGMENT_END:
-			status = h264_sei_progressive_segment_end(parent, pInfo);
-			break;
-		case SEI_MOTION_CONSTRAINED_SLICE_GRP_SET:
-			status = h264_sei_motion_constrained_slice_grp_set(parent, pInfo);
-			break;
-		case SEI_FILM_GRAIN_CHARACTERISTICS:
-			status = h264_sei_film_grain_characteristics(parent, pInfo);
-			break;
-		case SEI_DEBLK_FILTER_DISPLAY_PREFERENCE:
-			status = h264_sei_deblocking_filter_display_preferences(parent, pInfo);
-			break;
-		case SEI_STEREO_VIDEO_INFO:
-			status = h264_sei_stereo_video_info(parent, pInfo);
-			break;
-		default:
-			status = (h264_Status)h264_sei_reserved_sei_message(parent, pInfo, payloadSize);
-			break;
-	}
+    switch (payloadType)
+    {
+    case SEI_BUF_PERIOD:
+        status = h264_sei_buffering_period(parent, pInfo);
+        break;
+    case SEI_PIC_TIMING:
+        status = h264_sei_pic_timing(parent, pInfo);
+        break;
+    case SEI_PAN_SCAN:
+        status = h264_sei_pan_scan(parent, pInfo);
+        break;
+    case SEI_FILLER_PAYLOAD:
+        status = h264_sei_filler_payload(parent, pInfo, payloadSize);
+        break;
+    case SEI_REG_USERDATA:
+        status = h264_sei_userdata_reg(parent, pInfo, payloadSize);
+        break;
+    case SEI_UNREG_USERDATA:
+        status = h264_sei_userdata_unreg(parent, pInfo, payloadSize);
+        break;
+    case SEI_RECOVERY_POINT:
+        h264_sei_recovery_point(parent, pInfo);
+        break;
+    case SEI_DEC_REF_PIC_MARKING_REP:
+        status = h264_sei_dec_ref_pic_marking_rep(parent, pInfo);
+        break;
+    case SEI_SPARE_PIC:
+        status = h264_sei_spare_pic(parent, pInfo);
+        break;
+    case SEI_SCENE_INFO:
+        status = h264_sei_scene_info(parent, pInfo);
+        break;
+    case SEI_SUB_SEQ_INFO:
+        status = h264_sei_sub_seq_info(parent, pInfo);
+        break;
+    case SEI_SUB_SEQ_LAYER:
+        status = h264_sei_sub_seq_layer(parent, pInfo);
+        break;
+    case SEI_SUB_SEQ:
+        status = h264_sei_sub_seq(parent, pInfo);
+        break;
+    case SEI_FULL_FRAME_FREEZE:
+        status = h264_sei_full_frame_freeze(parent, pInfo);
+        break;
+    case SEI_FULL_FRAME_FREEZE_RELEASE:
+        h264_sei_full_frame_freeze_release(parent, pInfo);
+        break;
+    case SEI_FULL_FRAME_SNAPSHOT:
+        status = h264_sei_full_frame_snapshot(parent, pInfo);
+        break;
+    case SEI_PROGRESSIVE_SEGMENT_START:
+        status = h264_sei_progressive_segement_start(parent, pInfo);
+        break;
+    case SEI_PROGRESSIVE_SEGMENT_END:
+        status = h264_sei_progressive_segment_end(parent, pInfo);
+        break;
+    case SEI_MOTION_CONSTRAINED_SLICE_GRP_SET:
+        status = h264_sei_motion_constrained_slice_grp_set(parent, pInfo);
+        break;
+    case SEI_FILM_GRAIN_CHARACTERISTICS:
+        status = h264_sei_film_grain_characteristics(parent, pInfo);
+        break;
+    case SEI_DEBLK_FILTER_DISPLAY_PREFERENCE:
+        status = h264_sei_deblocking_filter_display_preferences(parent, pInfo);
+        break;
+    case SEI_STEREO_VIDEO_INFO:
+        status = h264_sei_stereo_video_info(parent, pInfo);
+        break;
+    default:
+        status = (h264_Status)h264_sei_reserved_sei_message(parent, pInfo, payloadSize);
+        break;
+    }
 
-/*
-	viddec_pm_get_bits(parent, (uint32_t *)&tmp, 1);
-	
-	if(tmp == 0x1)		// if byte is not aligned
-	{
-		while(pInfo->bitoff != 0)
-		{
-			viddec_pm_get_bits(parent, (uint32_t *)&bit_equal_to_zero, 1);
-		}
-	}
-*/
-	return status;
+    /*
+    	viddec_pm_get_bits(parent, (uint32_t *)&tmp, 1);
+
+    	if(tmp == 0x1)		// if byte is not aligned
+    	{
+    		while(pInfo->bitoff != 0)
+    		{
+    			viddec_pm_get_bits(parent, (uint32_t *)&bit_equal_to_zero, 1);
+    		}
+    	}
+    */
+    return status;
 }
 
 /* ------------------------------------------------------------------------------------------ */
@@ -1056,78 +1056,78 @@
 /* ------------------------------------------------------------------------------------------ */
 h264_Status h264_Parse_Supplemental_Enhancement_Information_Message(void *parent, h264_Info* pInfo)
 {
-	h264_Status status = H264_STATUS_OK;
-	int32_t  payload_type, payload_size;
-	uint32_t next_8_bits = 0,bits_offset=0,byte_offset = 0;
-	uint8_t  is_emul = 0; 
-	int32_t  bits_operation_result = 0;
-	
-	do {
-		//// payload_type
-		payload_type = 0;
-		viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);	
-		while (next_8_bits == 0xFF)
-		{
-			bits_operation_result = viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
-			if(-1 == bits_operation_result)
-			{
-			   status = H264_STATUS_SEI_ERROR;
-			   return status;
-			}
-		    payload_type += 255;
-			
-		}
-		//viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
-		payload_type += next_8_bits;
+    h264_Status status = H264_STATUS_OK;
+    int32_t  payload_type, payload_size;
+    uint32_t next_8_bits = 0,bits_offset=0,byte_offset = 0;
+    uint8_t  is_emul = 0;
+    int32_t  bits_operation_result = 0;
 
-		//// payload_size
-		payload_size = 0;
-		viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
-		while (next_8_bits == 0xFF)
-		{
-			payload_size += 255;
-			bits_operation_result = viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
-			if(-1 == bits_operation_result)
-			{
-			   status = H264_STATUS_SEI_ERROR;
-			   return status;
-			}
-		}
-		//viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
-		payload_size += next_8_bits;
+    do {
+        //// payload_type
+        payload_type = 0;
+        viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
+        while (next_8_bits == 0xFF)
+        {
+            bits_operation_result = viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
+            if (-1 == bits_operation_result)
+            {
+                status = H264_STATUS_SEI_ERROR;
+                return status;
+            }
+            payload_type += 255;
 
-		//PRINTF(MFD_NONE, " SEI: payload type = %d, payload size = %d \n", payload_type, payload_size);
+        }
+        //viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
+        payload_type += next_8_bits;
+
+        //// payload_size
+        payload_size = 0;
+        viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
+        while (next_8_bits == 0xFF)
+        {
+            payload_size += 255;
+            bits_operation_result = viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
+            if (-1 == bits_operation_result)
+            {
+                status = H264_STATUS_SEI_ERROR;
+                return status;
+            }
+        }
+        //viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8);
+        payload_size += next_8_bits;
+
+        //PRINTF(MFD_NONE, " SEI: payload type = %d, payload size = %d \n", payload_type, payload_size);
 
 
-		/////////////////////////////////
-		// Parse SEI payloads
-		/////////////////////////////////		
-		status = h264_SEI_payload(parent, pInfo, (h264_sei_payloadtype)payload_type, payload_size);
-		if(status != H264_STATUS_OK)
-			break;
+        /////////////////////////////////
+        // Parse SEI payloads
+        /////////////////////////////////
+        status = h264_SEI_payload(parent, pInfo, (h264_sei_payloadtype)payload_type, payload_size);
+        if (status != H264_STATUS_OK)
+            break;
 
-		viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
-		// OS_INFO("SEI byte_offset 3= %d, bits_offset=%d\n", byte_offset, bits_offset);
+        viddec_pm_get_au_pos(parent, &bits_offset, &byte_offset, &is_emul);
+        // OS_INFO("SEI byte_offset 3= %d, bits_offset=%d\n", byte_offset, bits_offset);
 
-		if(bits_offset!=0)
-		{
-		 viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8-bits_offset);         
-		}
+        if (bits_offset!=0)
+        {
+            viddec_pm_get_bits(parent, (uint32_t *)&next_8_bits, 8-bits_offset);
+        }
 
-		bits_operation_result = viddec_pm_peek_bits(parent, (uint32_t *)&next_8_bits, 8);     
-		if(-1 == bits_operation_result)
-		{
-		   status = H264_STATUS_SEI_ERROR;
-		   return status;		
-		}
+        bits_operation_result = viddec_pm_peek_bits(parent, (uint32_t *)&next_8_bits, 8);
+        if (-1 == bits_operation_result)
+        {
+            status = H264_STATUS_SEI_ERROR;
+            return status;
+        }
 
-		// OS_INFO("next_8_bits = %08x\n", next_8_bits);
+        // OS_INFO("next_8_bits = %08x\n", next_8_bits);
 
-	}while(next_8_bits != 0x80);
+    } while (next_8_bits != 0x80);
 
-	//} while (h264_More_RBSP_Data(parent, pInfo) && status == H264_STATUS_OK);
+    //} while (h264_More_RBSP_Data(parent, pInfo) && status == H264_STATUS_OK);
 
-	return status;
+    return status;
 }
 
 #endif
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_sh.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_sh.c
index 29340ac..de34811 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_sh.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/h264parse_sh.c
@@ -13,37 +13,37 @@
 /*-----------------------------------------------------------------------------------------*/
 h264_Status h264_Parse_Slice_Header_1(void *parent,h264_Info* pInfo, h264_Slice_Header_t *SliceHeader)
 {
-	h264_Status ret = H264_STATUS_ERROR;
+    h264_Status ret = H264_STATUS_ERROR;
 
-	//h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader;
-	int32_t slice_type =0;
-	uint32_t data =0;
+    //h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader;
+    int32_t slice_type =0;
+    uint32_t data =0;
 
-	do {
-		///// first_mb_in_slice
-		SliceHeader->first_mb_in_slice = h264_GetVLCElement(parent, pInfo, false);
+    do {
+        ///// first_mb_in_slice
+        SliceHeader->first_mb_in_slice = h264_GetVLCElement(parent, pInfo, false);
 
-		///// slice_type
-		slice_type = h264_GetVLCElement(parent, pInfo, false);
-		SliceHeader->slice_type = (slice_type%5);
-		
-		if(SliceHeader->slice_type > h264_PtypeI)	{
-			ret = H264_STATUS_NOTSUPPORT;			
-			break;
-		}
-		
+        ///// slice_type
+        slice_type = h264_GetVLCElement(parent, pInfo, false);
+        SliceHeader->slice_type = (slice_type%5);
 
-		////// pic_parameter_id
-		data = h264_GetVLCElement(parent, pInfo, false);
-		if(data > MAX_PIC_PARAMS) {
-			ret = H264_PPS_INVALID_PIC_ID;
-			break;
-		}
-		SliceHeader->pic_parameter_id  = (uint8_t)data;
-		ret = H264_STATUS_OK;
-	}while(0);
+        if (SliceHeader->slice_type > h264_PtypeI)	{
+            ret = H264_STATUS_NOTSUPPORT;
+            break;
+        }
 
-	return ret;
+
+        ////// pic_parameter_id
+        data = h264_GetVLCElement(parent, pInfo, false);
+        if (data > MAX_PIC_PARAMS) {
+            ret = H264_PPS_INVALID_PIC_ID;
+            break;
+        }
+        SliceHeader->pic_parameter_id  = (uint8_t)data;
+        ret = H264_STATUS_OK;
+    } while (0);
+
+    return ret;
 }
 
 /*-----------------------------------------------------------------------------------------*/
@@ -56,105 +56,105 @@
 
 h264_Status h264_Parse_Slice_Header_2(void *parent, h264_Info* pInfo, h264_Slice_Header_t *SliceHeader)
 {
-	h264_Status ret = H264_SliceHeader_ERROR;
+    h264_Status ret = H264_SliceHeader_ERROR;
 
-	//h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader;
-	uint32_t code;
-	int32_t max_mb_num=0;
-   
-	do {
-		//////////////////////////////////// Slice header part 2//////////////////
+    //h264_Slice_Header_t* SliceHeader = &pInfo->SliceHeader;
+    uint32_t code;
+    int32_t max_mb_num=0;
 
-		/// Frame_num
-		viddec_pm_get_bits(parent, &code, pInfo->active_SPS.log2_max_frame_num_minus4+4);
-		SliceHeader->frame_num = (int32_t)code;
+    do {
+        //////////////////////////////////// Slice header part 2//////////////////
 
-		/// Picture structure
-		SliceHeader->structure = FRAME;
-		SliceHeader->field_pic_flag = 0;
-		SliceHeader->bottom_field_flag = 0;
+        /// Frame_num
+        viddec_pm_get_bits(parent, &code, pInfo->active_SPS.log2_max_frame_num_minus4+4);
+        SliceHeader->frame_num = (int32_t)code;
 
-		if(!(pInfo->active_SPS.sps_disp.frame_mbs_only_flag))
-		{
-			/// field_pic_flag
-			viddec_pm_get_bits(parent, &code, 1);
-			SliceHeader->field_pic_flag = (uint8_t)code;
-			
-			if(SliceHeader->field_pic_flag)
-			{
-				viddec_pm_get_bits(parent, &code, 1);
-				SliceHeader->bottom_field_flag = (uint8_t)code;
-				
-				SliceHeader->structure = SliceHeader->bottom_field_flag? BOTTOM_FIELD: TOP_FIELD;
-			} 
-		}
+        /// Picture structure
+        SliceHeader->structure = FRAME;
+        SliceHeader->field_pic_flag = 0;
+        SliceHeader->bottom_field_flag = 0;
 
-		////// Check valid or not of first_mb_in_slice
-		if(SliceHeader->structure == FRAME) {
-			max_mb_num = pInfo->img.FrameHeightInMbs * pInfo->img.PicWidthInMbs;
-		} else {
-			max_mb_num = pInfo->img.FrameHeightInMbs * pInfo->img.PicWidthInMbs/2;
-		}
+        if (!(pInfo->active_SPS.sps_disp.frame_mbs_only_flag))
+        {
+            /// field_pic_flag
+            viddec_pm_get_bits(parent, &code, 1);
+            SliceHeader->field_pic_flag = (uint8_t)code;
+
+            if (SliceHe