Multiple video conferencing use case fixes.  Fixed IDR interval always falling to default value.  Fixes for HSD 3470714 (NAL delimiter API support), HSD 3470713 (Decoder freeze with packet loss), green screen startup issues, video corruption issues, frame manager fix.

Change-Id: Id180dce3e2cd827ed3d1f0d79eb7c4651c97a73c
diff --git a/mix_vbp/ChangeLog b/mix_vbp/ChangeLog
index 98a1ee8..5efdae9 100644
--- a/mix_vbp/ChangeLog
+++ b/mix_vbp/ChangeLog
@@ -1,4 +1,8 @@
-2010-09-15 Andy Qiu <tao.q.tao@intel.com>
+2010-09-29 Andy Qiu <junhai.qiu@intel.com>
+	* Enhanced H.264 bitstream parsing
+	* Changed version number to 0.1.18
+
+2010-09-15 Tao Tao  <tao.q.tao@intel.com>
 	* Merged changes for Android
 
 2010-09-02 Andy Qiu <junhai.qiu@intel.com>
diff --git a/mix_vbp/configure.ac b/mix_vbp/configure.ac
index 7b9edae..933f6ab 100644
--- a/mix_vbp/configure.ac
+++ b/mix_vbp/configure.ac
@@ -2,7 +2,7 @@
 
 AC_CONFIG_MACRO_DIR(m4)
 
-UMG_MIX_VERSION(mixvbp, MIXVBP, 0, 1, 17)
+UMG_MIX_VERSION(mixvbp, MIXVBP, 0, 1, 18)
 
 dnl AM_MAINTAINER_MODE provides the option to enable maintainer mode
 AM_MAINTAINER_MODE
diff --git a/mix_vbp/mixvbp.spec b/mix_vbp/mixvbp.spec
index 77445d3..d3ccd71 100644
--- a/mix_vbp/mixvbp.spec
+++ b/mix_vbp/mixvbp.spec
@@ -6,7 +6,7 @@
 
 Summary: MIX Video Bitstream Parser
 Name: mixvbp
-Version: 0.1.17
+Version: 0.1.18
 Release: 1
 Source0: %{name}-%{version}.tar.bz2
 NoSource: 0
@@ -29,25 +29,40 @@
 
 %prep
 %setup -q
+
 %build
 ./autogen.sh
 ./configure --prefix=%{_prefix}
 make
+
 %install
 make DESTDIR=$RPM_BUILD_ROOT install
 rm -f $RPM_BUILD_ROOT/%{_prefix}/lib/libmixvbp_mpeg2*
 
+%post -p /sbin/ldconfig
+%postun -p /sbin/ldconfig
+
 %clean
 rm -rf $RPM_BUILD_ROOT
 %files
 %defattr(-,root,root)
-%{_prefix}/lib/libmixvbp.so*
-%{_prefix}/lib/libmixvbp_vc1.so*
-%{_prefix}/lib/libmixvbp_h264.so*
-%{_prefix}/lib/libmixvbp_mpeg4.so*
+%{_prefix}/lib/libmixvbp.so.*
+%{_prefix}/lib/libmixvbp_vc1.so.*
+%{_prefix}/lib/libmixvbp_h264.so.*
+%{_prefix}/lib/libmixvbp_mpeg4.so.*
 
 %files devel
 %defattr(-,root,root)
-%{_prefix}/include
+%{_prefix}/include/mixvbp
 %{_prefix}/lib/*.la
 %{_prefix}/lib/pkgconfig/mixvbp.pc
+%{_prefix}/lib/libmixvbp.so
+%{_prefix}/lib/libmixvbp_vc1.so
+%{_prefix}/lib/libmixvbp_h264.so
+%{_prefix}/lib/libmixvbp_mpeg4.so
+
+
+%changelog
+* Mon Sep 13 2010 John Q Public <umg@intel.com> 0.0
+- Dummy changelog to satisfy rpmlint.
+
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 d174f12..3a111c4 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
@@ -1,10 +1,3 @@
-
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
-
 /*!
  ***********************************************************************
  *  \file: h264_dpb_ctl.c
diff --git a/mix_vbp/viddec_fw/fw/codecs/h264/parser/viddec_h264_parse.c b/mix_vbp/viddec_fw/fw/codecs/h264/parser/viddec_h264_parse.c
index c30167b..a763d00 100644
--- a/mix_vbp/viddec_fw/fw/codecs/h264/parser/viddec_h264_parse.c
+++ b/mix_vbp/viddec_fw/fw/codecs/h264/parser/viddec_h264_parse.c
@@ -1,8 +1,3 @@
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
 #include "viddec_fw_debug.h"
 #include "viddec_parser_ops.h"
 
diff --git a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_fw_mp4_workload.c b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_fw_mp4_workload.c
index 4a53b8b..6b44c7a 100644
--- a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_fw_mp4_workload.c
+++ b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_fw_mp4_workload.c
@@ -2,9 +2,6 @@
 #include "viddec_parser_ops.h"
 #include "viddec_fw_mp4.h"
 #include "viddec_mp4_parse.h"
-#ifdef ANDROID
-#include "viddec_types.h"
-#endif
 
 uint32_t viddec_fw_mp4_populate_attr(viddec_workload_t *wl, viddec_mp4_parser_t *parser)
 {
diff --git a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_parse.c b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_parse.c
index 6a4a8ac..d2722a2 100644
--- a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_parse.c
+++ b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_parse.c
@@ -6,9 +6,6 @@
 #include "viddec_mp4_videoobjectlayer.h"
 #include "viddec_mp4_videoobjectplane.h"
 #include "viddec_mp4_visualobject.h"
-#ifdef ANDROID
-#include "viddec_types.h"
-#endif
 
 extern uint32_t viddec_parse_sc_mp4(void *in, void *pcxt, void *sc_state);
 
diff --git a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_shortheader.c b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_shortheader.c
index 7603cd7..33cb1d7 100644
--- a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_shortheader.c
+++ b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_shortheader.c
@@ -1,7 +1,4 @@
 #include "viddec_mp4_shortheader.h"
-#ifdef ANDROID
-#include "viddec_types.h"
-#endif
 
 typedef struct
 {
diff --git a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_videoobjectlayer.c b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_videoobjectlayer.c
index e92a26d..31ac9d1 100644
--- a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_videoobjectlayer.c
+++ b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_videoobjectlayer.c
@@ -1,7 +1,4 @@
 #include "viddec_mp4_videoobjectlayer.h"
-#ifdef ANDROID
-#include "viddec_types.h"
-#endif
 
 const unsigned char mp4_DefaultIntraQuantMatrix[64] = {
     8, 17, 18, 19, 21, 23, 25, 27, 
diff --git a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_videoobjectplane.c b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_videoobjectplane.c
index 5d1ae0f..3fee166 100644
--- a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_videoobjectplane.c
+++ b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_videoobjectplane.c
@@ -1,7 +1,4 @@
 #include "viddec_mp4_videoobjectplane.h"
-#ifdef ANDROID
-#include "viddec_types.h"
-#endif
 
 mp4_Status_t mp4_Parse_GroupOfVideoObjectPlane(void *parent, viddec_mp4_parser_t *parser)
 {
diff --git a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_visualobject.c b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_visualobject.c
index 35a352d..acfb8fa 100644
--- a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_visualobject.c
+++ b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_mp4_visualobject.c
@@ -1,7 +1,4 @@
 #include "viddec_mp4_visualobject.h"
-#ifdef ANDROID
-#include "viddec_types.h"
-#endif
 
 static inline uint8_t mp4_pvt_isValid_verID(uint8_t id)
 {
diff --git a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_types.h b/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_types.h
deleted file mode 100644
index 98d4ce8..0000000
--- a/mix_vbp/viddec_fw/fw/codecs/mp4/parser/viddec_types.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef __VIDDEC_TYPES_H__
-#define __VIDDEC_TYPES_H__
-
-#define true    1
-#define false   0
-
-#endif //__VIDDEC_TYPES_H__
diff --git a/mix_vbp/viddec_fw/fw/parser/main.c b/mix_vbp/viddec_fw/fw/parser/main.c
index 4ba89f7..1bb368a 100644
--- a/mix_vbp/viddec_fw/fw/parser/main.c
+++ b/mix_vbp/viddec_fw/fw/parser/main.c
@@ -1,8 +1,3 @@
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
 #include "fw_pvt.h"
 #include "viddec_fw_parser_ipclib_config.h"
 #include "viddec_fw_common_defs.h"
diff --git a/mix_vbp/viddec_fw/fw/parser/vbp_h264_parser.c b/mix_vbp/viddec_fw/fw/parser/vbp_h264_parser.c
index 38392e1..e62c411 100644
--- a/mix_vbp/viddec_fw/fw/parser/vbp_h264_parser.c
+++ b/mix_vbp/viddec_fw/fw/parser/vbp_h264_parser.c
@@ -6,12 +6,6 @@
  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.
  */
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
-
 #include <glib.h>
 #include <dlfcn.h>
 
diff --git a/mix_vbp/viddec_fw/fw/parser/vbp_loader.c b/mix_vbp/viddec_fw/fw/parser/vbp_loader.c
index cfcad5b..27a2dd0 100644
--- a/mix_vbp/viddec_fw/fw/parser/vbp_loader.c
+++ b/mix_vbp/viddec_fw/fw/parser/vbp_loader.c
@@ -6,12 +6,6 @@
  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.
  */
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
-
 #include <glib.h>
 
 #include "vbp_loader.h"
diff --git a/mix_vbp/viddec_fw/fw/parser/vbp_loader.h b/mix_vbp/viddec_fw/fw/parser/vbp_loader.h
index 00a921c..e266ea6 100644
--- a/mix_vbp/viddec_fw/fw/parser/vbp_loader.h
+++ b/mix_vbp/viddec_fw/fw/parser/vbp_loader.h
@@ -29,11 +29,6 @@
 #ifndef uint32
 typedef unsigned int uint32;
 #endif
-#ifndef ANDROID
-#ifndef bool
-typedef int bool;
-#endif
-#endif
 
 typedef void *Handle;
 
diff --git a/mix_vbp/viddec_fw/fw/parser/vbp_mp42_parser.c b/mix_vbp/viddec_fw/fw/parser/vbp_mp42_parser.c
index 85b32e0..7a65dbe 100644
--- a/mix_vbp/viddec_fw/fw/parser/vbp_mp42_parser.c
+++ b/mix_vbp/viddec_fw/fw/parser/vbp_mp42_parser.c
@@ -6,11 +6,6 @@
  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.
  */
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
 
 #include <glib.h>
 #include <dlfcn.h>
diff --git a/mix_vbp/viddec_fw/fw/parser/vbp_utils.c b/mix_vbp/viddec_fw/fw/parser/vbp_utils.c
index 275f43c..a26a9f1 100644
--- a/mix_vbp/viddec_fw/fw/parser/vbp_utils.c
+++ b/mix_vbp/viddec_fw/fw/parser/vbp_utils.c
@@ -5,10 +5,6 @@
 
  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.
  */
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
 
 #include <glib.h>
 #include <dlfcn.h>
diff --git a/mix_vbp/viddec_fw/fw/parser/vbp_vc1_parser.c b/mix_vbp/viddec_fw/fw/parser/vbp_vc1_parser.c
index d43ada6..af16e8d 100644
--- a/mix_vbp/viddec_fw/fw/parser/vbp_vc1_parser.c
+++ b/mix_vbp/viddec_fw/fw/parser/vbp_vc1_parser.c
@@ -6,13 +6,6 @@
  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.
  */
 
-
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
-
 #include <glib.h>
 #include <dlfcn.h>
 #include <string.h>
diff --git a/mix_vbp/viddec_fw/fw/parser/viddec_emit.c b/mix_vbp/viddec_fw/fw/parser/viddec_emit.c
index 2bae85b..12ddfe9 100644
--- a/mix_vbp/viddec_fw/fw/parser/viddec_emit.c
+++ b/mix_vbp/viddec_fw/fw/parser/viddec_emit.c
@@ -1,8 +1,4 @@
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
 
 #include "viddec_emitter.h"
 #include "viddec_fw_workload.h"
diff --git a/mix_vbp/viddec_fw/fw/parser/viddec_pm.c b/mix_vbp/viddec_fw/fw/parser/viddec_pm.c
index 8671ef3..42cc3e9 100644
--- a/mix_vbp/viddec_fw/fw/parser/viddec_pm.c
+++ b/mix_vbp/viddec_fw/fw/parser/viddec_pm.c
@@ -1,9 +1,4 @@
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
 #include "viddec_pm.h"
 #include "viddec_fw_debug.h"
 #include "viddec_fw_common_defs.h"
diff --git a/mix_vbp/viddec_fw/fw/parser/viddec_pm_flush.c b/mix_vbp/viddec_fw/fw/parser/viddec_pm_flush.c
index 4458834..9d5c132 100644
--- a/mix_vbp/viddec_fw/fw/parser/viddec_pm_flush.c
+++ b/mix_vbp/viddec_fw/fw/parser/viddec_pm_flush.c
@@ -1,7 +1,3 @@
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
 
 #include "fw_pvt.h"
 #include "viddec_fw_parser_ipclib_config.h"
diff --git a/mix_vbp/viddec_fw/fw/parser/viddec_pm_parser_ops.c b/mix_vbp/viddec_fw/fw/parser/viddec_pm_parser_ops.c
index 06c6cbd..9d488fe 100644
--- a/mix_vbp/viddec_fw/fw/parser/viddec_pm_parser_ops.c
+++ b/mix_vbp/viddec_fw/fw/parser/viddec_pm_parser_ops.c
@@ -1,9 +1,4 @@
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
 #include "viddec_pm.h"
 #include "viddec_fw_debug.h"
 #include "viddec_parser_ops.h"
diff --git a/mix_vbp/viddec_fw/fw/parser/viddec_pm_tags.c b/mix_vbp/viddec_fw/fw/parser/viddec_pm_tags.c
index df7d502..baa8330 100644
--- a/mix_vbp/viddec_fw/fw/parser/viddec_pm_tags.c
+++ b/mix_vbp/viddec_fw/fw/parser/viddec_pm_tags.c
@@ -1,9 +1,4 @@
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
 #include "viddec_pm.h"
 #include "viddec_fw_debug.h"
 #include "viddec_fw_common_defs.h"
diff --git a/mix_vbp/viddec_fw/fw/parser/viddec_pm_utils_bstream.c b/mix_vbp/viddec_fw/fw/parser/viddec_pm_utils_bstream.c
index a90242a..cecaac3 100644
--- a/mix_vbp/viddec_fw/fw/parser/viddec_pm_utils_bstream.c
+++ b/mix_vbp/viddec_fw/fw/parser/viddec_pm_utils_bstream.c
@@ -1,9 +1,4 @@
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
 #include "viddec_pm_utils_bstream.h"
 #include "viddec_fw_debug.h"
 
diff --git a/mix_vbp/viddec_fw/fw/parser/viddec_pm_utils_list.c b/mix_vbp/viddec_fw/fw/parser/viddec_pm_utils_list.c
index adacf2c..d6f6adf 100644
--- a/mix_vbp/viddec_fw/fw/parser/viddec_pm_utils_list.c
+++ b/mix_vbp/viddec_fw/fw/parser/viddec_pm_utils_list.c
@@ -1,9 +1,4 @@
 
-#ifdef ANDROID
-#define true 1
-#define false 0
-#endif
-
 #include "viddec_pm_utils_list.h"
 #include "viddec_fw_debug.h"
 
diff --git a/mix_vbp/viddec_fw/include/viddec_fw_common_defs.h b/mix_vbp/viddec_fw/include/viddec_fw_common_defs.h
index acca3ce..5cbbab1 100644
--- a/mix_vbp/viddec_fw/include/viddec_fw_common_defs.h
+++ b/mix_vbp/viddec_fw/include/viddec_fw_common_defs.h
@@ -211,6 +211,10 @@
 #define false 0
 #endif
 
+#ifndef bool
+typedef int bool;
+#endif
+
 #endif 
 /* end of #ifdef VBP */
 
diff --git a/mix_video/ChangeLog b/mix_video/ChangeLog
index 2f7a06c..654fed0 100644
--- a/mix_video/ChangeLog
+++ b/mix_video/ChangeLog
@@ -1,3 +1,8 @@
+2010-09-29 Andy Qiu <junhai.qiu@intel.com>
+		* Supported FLV playback
+		* Re-factored frame manager
+		* Changed version number to 0.1.20
+
 2010-09-15 Tao Tao <tao.q.tao@intel.com>
 
 		* Merged the changes for Android
diff --git a/mix_video/configure.ac b/mix_video/configure.ac
index 14f9ac2..ec50fd4 100644
--- a/mix_video/configure.ac
+++ b/mix_video/configure.ac
@@ -2,7 +2,7 @@
 
 AC_CONFIG_MACRO_DIR(m4)
 
-UMG_MIX_VERSION(mixvideo, MIXVIDEO, 0, 1, 19)
+UMG_MIX_VERSION(mixvideo, MIXVIDEO, 0, 1, 20)
 
 dnl AM_MAINTAINER_MODE provides the option to enable maintainer mode
 AM_MAINTAINER_MODE
diff --git a/mix_video/mixvideo.spec b/mix_video/mixvideo.spec
index df31162..f8f1947 100644
--- a/mix_video/mixvideo.spec
+++ b/mix_video/mixvideo.spec
@@ -6,7 +6,7 @@
 
 Summary: MIX Video
 Name: mixvideo
-Version: 0.1.19
+Version: 0.1.20
 Release: 1
 Source0: %{name}-%{version}.tar.bz2
 NoSource: 0
@@ -42,27 +42,40 @@
 
 %prep
 %setup -q
+
 %build
 ./autogen.sh
 ./configure --prefix=%{_prefix}
 make
+
 %install
 make DESTDIR=$RPM_BUILD_ROOT install
+
 %clean
 rm -rf $RPM_BUILD_ROOT
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
 %files
 %defattr(-,root,root)
-%{_prefix}/lib/libmixvideo.so*
+%{_prefix}/lib/libmixvideo.so.*
 
 %files devel
 %defattr(-,root,root)
 %{_prefix}/include/mix
+%{_prefix}/lib/libmixvideo.so
 %{_prefix}/lib/*.la
 %{_prefix}/lib/pkgconfig/mixvideo.pc
 
 %files int-devel
 %defattr(-,root,root)
+%{_prefix}/lib/libmixvideo.so
 %{_prefix}/include/mixvideoint
 %{_prefix}/lib/pkgconfig/mixvideoint.pc
 
+%changelog
+* Mon Sep 13 2010 John Q Public <umg@intel.com> 0.0
+- Dummy changelog to satisfy rpmlint.
 
diff --git a/mix_video/src/mixframemanager.c b/mix_video/src/mixframemanager.c
index 0a843e6..6be0ace 100644
--- a/mix_video/src/mixframemanager.c
+++ b/mix_video/src/mixframemanager.c
@@ -13,7 +13,7 @@
 
 #define INITIAL_FRAME_ARRAY_SIZE 	16
 
-// Assume only one backward reference is used. This will hold up to 2 frames before forcing 
+// Assume only one backward reference is used. This will hold up to 2 frames before forcing
 // the earliest frame out of queue.
 #define MIX_MAX_ENQUEUE_SIZE        2
 
@@ -101,10 +101,10 @@
 
 	MIX_RESULT ret = MIX_RESULT_SUCCESS;
 
-	if (!MIX_IS_FRAMEMANAGER(fm) || 
+	if (!MIX_IS_FRAMEMANAGER(fm) ||
 	    mode <= MIX_DISPLAY_ORDER_UNKNOWN ||
-	    mode >= MIX_DISPLAY_ORDER_LAST || 
-	    framerate_numerator <= 0 || 
+	    mode >= MIX_DISPLAY_ORDER_LAST ||
+	    framerate_numerator <= 0 ||
 	    framerate_denominator <= 0) {
 		return MIX_RESULT_INVALID_PARAM;
 	}
@@ -259,7 +259,7 @@
     {
 		return MIX_RESULT_FAIL;
     }
-    
+
 	g_mutex_lock(fm->lock);
 
 	fm->max_enqueue_size = size;
@@ -286,12 +286,12 @@
         // Refer to H.264 spec: log2_max_pic_order_cnt_lsb_minus4. Max pic order will never be less than 16.
 		return MIX_RESULT_INVALID_PARAM;
     }
-    
+
 	g_mutex_lock(fm->lock);
 
     // max_picture_number is exclusie (range from 0 to num - 1).
     // Note that this number may not be reliable if encoder does not conform to the spec, as of this, the
-    // implementaion will not automatically roll-over fm->next_frame_picnumber when it reaches 
+    // implementaion will not automatically roll-over fm->next_frame_picnumber when it reaches
     // fm->max_picture_number.
 	fm->max_picture_number = num;
 	LOG_V("max picture number is %d\n", num);
@@ -322,7 +322,7 @@
         fm->frame_list = g_slist_remove(fm->frame_list, (gconstpointer)frame);
         mix_videoframe_unref(frame);
 	    LOG_V("one frame is flushed\n");
-    };     
+    };
 
 	fm->eos = FALSE;
 	fm->is_first_frame = TRUE;
@@ -377,16 +377,16 @@
     }
 #endif
 
-	g_mutex_lock(fm->lock);	
+	g_mutex_lock(fm->lock);
     fm->frame_list = g_slist_append(fm->frame_list, (gpointer)mvf);
 	g_mutex_unlock(fm->lock);
-	
+
     LOG_V("End\n");
 
 	return ret;
 }
 
-void mix_framemanager_update_timestamp(MixFrameManager *fm, MixVideoFrame *mvf) 
+void mix_framemanager_update_timestamp(MixFrameManager *fm, MixVideoFrame *mvf)
 {
     // this function finds the lowest time stamp in the list and assign it to the dequeued video frame,
     // if that timestamp is smaller than the timestamp of dequeued video frame.
@@ -399,7 +399,7 @@
         // nothing to update
         return;
     }
-    
+
     // find video frame with the smallest timestamp, take rollover into account when
     // comparing timestamp.
     for (i = 0; i < len; i++)
@@ -408,19 +408,19 @@
         mix_videoframe_get_timestamp(p, &ts);
         if (i == 0 ||
             (ts < min_ts && min_ts - ts < TS_ROLLOVER_THRESHOLD) ||
-            (ts > min_ts && ts - min_ts > TS_ROLLOVER_THRESHOLD))        
+            (ts > min_ts && ts - min_ts > TS_ROLLOVER_THRESHOLD))
         {
             min_ts = ts;
             min_p = p;
-        }       
+        }
     }
 
     mix_videoframe_get_timestamp(mvf, &ts);
     if ((ts < min_ts && min_ts - ts < TS_ROLLOVER_THRESHOLD) ||
-        (ts > min_ts && ts - min_ts > TS_ROLLOVER_THRESHOLD)) 
+        (ts > min_ts && ts - min_ts > TS_ROLLOVER_THRESHOLD))
     {
         // frame to be updated has smaller time stamp
-    }  
+    }
     else
     {
         // time stamp needs to be monotonically non-decreasing so swap timestamp.
@@ -432,7 +432,7 @@
 }
 
 
-MIX_RESULT mix_framemanager_pictype_based_dequeue(MixFrameManager *fm, MixVideoFrame **mvf) 
+MIX_RESULT mix_framemanager_pictype_based_dequeue(MixFrameManager *fm, MixVideoFrame **mvf)
 {
     int i, num_i_or_p;
     MixVideoFrame *p, *first_i_or_p;
@@ -441,7 +441,7 @@
 
     num_i_or_p = 0;
     first_i_or_p = NULL;
-    
+
     for (i = 0; i < len; i++)
     {
         p = (MixVideoFrame*)g_slist_nth_data(fm->frame_list, i);
@@ -455,15 +455,15 @@
             *mvf = p;
             LOG_V("B frame is dequeued.\n");
             return MIX_RESULT_SUCCESS;
-        }  
-        
+        }
+
         if (type != TYPE_I && type != TYPE_P)
         {
-            // this should never happen 
+            // this should never happen
             LOG_E("Frame typs is invalid!!!\n");
             fm->frame_list = g_slist_remove(fm->frame_list, (gconstpointer)p);
             mix_videoframe_unref(p);
-            return MIX_RESULT_FRAME_NOTAVAIL;                       
+            return MIX_RESULT_FRAME_NOTAVAIL;
         }
         num_i_or_p++;
         if (first_i_or_p == NULL)
@@ -472,7 +472,7 @@
         }
     }
 
-    // if there are more than one reference frame in the list, the first one is dequeued. 
+    // if there are more than one reference frame in the list, the first one is dequeued.
     if (num_i_or_p > 1 || fm->eos)
     {
         if (first_i_or_p == NULL)
@@ -493,40 +493,40 @@
         else
         {
             LOG_V("P frame is dequeued.\n");
-        }                    
+        }
 #endif
-        return MIX_RESULT_SUCCESS;            
+        return MIX_RESULT_SUCCESS;
     }
-    
-    return MIX_RESULT_FRAME_NOTAVAIL;   
+
+    return MIX_RESULT_FRAME_NOTAVAIL;
 }
 
-MIX_RESULT mix_framemanager_timestamp_based_dequeue(MixFrameManager *fm, MixVideoFrame **mvf) 
+MIX_RESULT mix_framemanager_timestamp_based_dequeue(MixFrameManager *fm, MixVideoFrame **mvf)
 {
     int i, len;
     MixVideoFrame *p, *p_out_of_dated;
     guint64 ts, ts_next_pending, ts_out_of_dated;
     guint64 tolerance = fm->frame_timestamp_delta/4;
 
-retry:    
+retry:
     // len may be changed during retry!
     len = g_slist_length(fm->frame_list);
-    ts_next_pending = (guint64)-1; 
+    ts_next_pending = (guint64)-1;
     ts_out_of_dated = 0;
     p_out_of_dated = NULL;
-    
-    
+
+
     for (i = 0; i < len; i++)
     {
         p = (MixVideoFrame*)g_slist_nth_data(fm->frame_list, i);
         mix_videoframe_get_timestamp(p, &ts);
-        if (ts >= fm->last_frame_timestamp && 
+        if (ts >= fm->last_frame_timestamp &&
             ts <= fm->next_frame_timestamp + tolerance)
         {
             fm->frame_list = g_slist_remove(fm->frame_list, (gconstpointer)p);
             *mvf = p;
             mix_videoframe_get_timestamp(p, &(fm->last_frame_timestamp));
-            fm->next_frame_timestamp = fm->last_frame_timestamp + fm->frame_timestamp_delta;            
+            fm->next_frame_timestamp = fm->last_frame_timestamp + fm->frame_timestamp_delta;
             LOG_V("frame is dequeud, ts = %"G_GINT64_FORMAT".\n", ts);
             return MIX_RESULT_SUCCESS;
         }
@@ -536,7 +536,7 @@
         {
             ts_next_pending = ts;
         }
-        if (ts < fm->last_frame_timestamp && 
+        if (ts < fm->last_frame_timestamp &&
             ts >= ts_out_of_dated)
         {
             // video frame that is most recently out-of-dated.
@@ -544,10 +544,10 @@
             // the "next frame" criteria, and the one with larger timestamp is dequeued first.
             ts_out_of_dated = ts;
             p_out_of_dated = p;
-        }        
+        }
     }
 
-    if (p_out_of_dated && 
+    if (p_out_of_dated &&
         fm->last_frame_timestamp - ts_out_of_dated < TS_ROLLOVER_THRESHOLD)
     {
         fm->frame_list = g_slist_remove(fm->frame_list, (gconstpointer)p_out_of_dated);
@@ -556,10 +556,10 @@
             ts_out_of_dated, fm->last_frame_timestamp);
         return MIX_RESULT_FRAME_NOTAVAIL;
     }
-    
+
     if (len <= fm->max_enqueue_size && fm->eos == FALSE)
     {
-        LOG_V("no frame is dequeued, expected ts = %"G_GINT64_FORMAT", next pending ts = %"G_GINT64_FORMAT".(List size = %d)\n", 
+        LOG_V("no frame is dequeued, expected ts = %"G_GINT64_FORMAT", next pending ts = %"G_GINT64_FORMAT".(List size = %d)\n",
             fm->next_frame_timestamp, ts_next_pending, len);
         return MIX_RESULT_FRAME_NOTAVAIL;
     }
@@ -569,13 +569,13 @@
     {
         LOG_V("timestamp has gap, jumping from %"G_GINT64_FORMAT" to %"G_GINT64_FORMAT".\n",
                 fm->next_frame_timestamp, ts_next_pending);
-                
+
         fm->next_frame_timestamp = ts_next_pending;
         goto retry;
     }
 
     // time stamp roll-over
-    LOG_V("time stamp is rolled over, resetting next frame timestamp from %"G_GINT64_FORMAT" to 0.\n", 
+    LOG_V("time stamp is rolled over, resetting next frame timestamp from %"G_GINT64_FORMAT" to 0.\n",
         fm->next_frame_timestamp);
 
     fm->next_frame_timestamp = 0;
@@ -587,19 +587,18 @@
     return MIX_RESULT_FAIL;
 }
 
-MIX_RESULT mix_framemanager_picnumber_based_dequeue(MixFrameManager *fm, MixVideoFrame **mvf) 
+MIX_RESULT mix_framemanager_picnumber_based_dequeue(MixFrameManager *fm, MixVideoFrame **mvf)
 {
     int i, len;
     MixVideoFrame* p;
-    guint32 picnum, smallest_picnum;
+    guint32 picnum;
     guint32 next_picnum_pending;
 
     len = g_slist_length(fm->frame_list);
 
-retry:    
+retry:
     next_picnum_pending = (guint32)-1;
-    smallest_picnum = (guint32)-1;
-    
+
     for (i = 0; i < len; i++)
     {
         p = (MixVideoFrame*)g_slist_nth_data(fm->frame_list, i);
@@ -608,11 +607,11 @@
         {
             fm->frame_list = g_slist_remove(fm->frame_list, (gconstpointer)p);
             mix_framemanager_update_timestamp(fm, p);
-            *mvf = p;           
+            *mvf = p;
             LOG_V("frame is dequeued, poc = %d.\n", fm->next_frame_picnumber);
             fm->next_frame_picnumber++;
             //if (fm->next_frame_picnumber == fm->max_picture_number)
-            //    fm->next_frame_picnumber = 0;            
+            //    fm->next_frame_picnumber = 0;
             return MIX_RESULT_SUCCESS;
         }
 
@@ -623,42 +622,36 @@
         }
 
         if (picnum < fm->next_frame_picnumber &&
-            picnum < smallest_picnum)
+            fm->next_frame_picnumber - picnum < 8)
         {
-            smallest_picnum = picnum;
+            // the smallest value of "max_pic_order_cnt_lsb_minus4" is 16. If the distance of "next frame pic number"
+            // to the pic number  in the list is less than half of 16, it is safe to assume that pic number
+            // is reset when a new IDR is encoded. (where pic numbfer of top or bottom field must be 0, subclause 8.2.1).
+            LOG_V("picture number is reset to %d, next pic number is %d, next pending number is %d.\n",
+                    picnum, fm->next_frame_picnumber, next_picnum_pending);
+            break;
         }
     }
 
-    if (smallest_picnum != (guint32)-1 && fm->next_frame_picnumber - smallest_picnum < 8)
-    {
-        // the smallest value of "max_pic_order_cnt_lsb_minus4" is 16. If the distance of "next frame pic number"  
-        // to the smallest pic number  in the list is less than half of 16, it is safely to assume that pic number
-        // is reset when an new IDR is encoded. (where pic numbfer of top or bottom field must be 0, subclause 8.2.1).
-        LOG_V("next frame number is reset from %d to 0, smallest picnumber in list (size = %d) is %d.\n",
-            fm->next_frame_picnumber, len, smallest_picnum);
-        fm->next_frame_picnumber = 0;
-        goto retry;
-    }
-    
     if (len <= fm->max_enqueue_size && fm->eos == FALSE)
     {
-        LOG_V("No frame is dequeued. Expected POC = %d, next pending POC = %d. (List size = %d)\n", 
+        LOG_V("No frame is dequeued. Expected POC = %d, next pending POC = %d. (List size = %d)\n",
                 fm->next_frame_picnumber, next_picnum_pending, len);
         return MIX_RESULT_FRAME_NOTAVAIL;
     }
 
     // picture number  has gap
-    if (next_picnum_pending != -1)
+    if (next_picnum_pending != (guint32)-1)
     {
         LOG_V("picture number has gap, jumping from %d to %d.\n",
                 fm->next_frame_picnumber, next_picnum_pending);
-                
+
         fm->next_frame_picnumber = next_picnum_pending;
         goto retry;
     }
 
     // picture number roll-over
-    LOG_V("picture number is rolled over, resetting next picnum from %d to 0.\n", 
+    LOG_V("picture number is rolled over, resetting next picnum from %d to 0.\n",
         fm->next_frame_picnumber);
 
     fm->next_frame_picnumber = 0;
@@ -700,29 +693,29 @@
         {
             LOG_V("No frame is dequeued as queue is empty!\n");
             ret = MIX_RESULT_FRAME_NOTAVAIL;
-        }            
+        }
 	}
 	else if (fm->is_first_frame)
 	{
 	    // dequeue the first entry in the list. Not need to update the time stamp as
 	    // the list should contain only one frame.
-#ifdef MIX_LOG_ENABLE	    
+#ifdef MIX_LOG_ENABLE
     	if (g_slist_length(fm->frame_list) != 1)
     	{
-    	    LOG_W("length of list is not equal to 1 for the first frame.\n");    	    
+    	    LOG_W("length of list is not equal to 1 for the first frame.\n");
     	}
-#endif    	
+#endif
         *mvf = (MixVideoFrame*) g_slist_nth_data(fm->frame_list, 0);
         fm->frame_list = g_slist_remove(fm->frame_list, (gconstpointer)(*mvf));
 
         if (fm->mode == MIX_DISPLAY_ORDER_TIMESTAMP)
-        {            
-            mix_videoframe_get_timestamp(*mvf, &(fm->last_frame_timestamp));             
+        {
+            mix_videoframe_get_timestamp(*mvf, &(fm->last_frame_timestamp));
             fm->next_frame_timestamp = fm->last_frame_timestamp + fm->frame_timestamp_delta;
             LOG_V("The first frame is dequeued, ts = %"G_GINT64_FORMAT"\n", fm->last_frame_timestamp);
         }
         else if (fm->mode == MIX_DISPLAY_ORDER_PICNUMBER)
-        {            
+        {
             mix_videoframe_get_displayorder(*mvf, &(fm->next_frame_picnumber));
             LOG_V("The first frame is dequeued, POC = %d\n", fm->next_frame_picnumber);
             fm->next_frame_picnumber++;
@@ -731,15 +724,15 @@
         }
         else
         {
-#ifdef MIX_LOG_ENABLE     
+#ifdef MIX_LOG_ENABLE
             MixFrameType type;
             mix_videoframe_get_frame_type(*mvf, &type);
             LOG_V("The first frame is dequeud, frame type is %d.\n", type);
-#endif            
+#endif
         }
 	    fm->is_first_frame = FALSE;
-	    
-        ret = MIX_RESULT_SUCCESS;	       
+
+        ret = MIX_RESULT_SUCCESS;
 	}
 	else
 	{
@@ -758,14 +751,14 @@
             ret = mix_framemanager_pictype_based_dequeue(fm, mvf);
             break;
 
-        case MIX_DISPLAY_ORDER_FIFO:        
+        case MIX_DISPLAY_ORDER_FIFO:
             *mvf = (MixVideoFrame*) g_slist_nth_data(fm->frame_list, 0);
             fm->frame_list = g_slist_remove(fm->frame_list, (gconstpointer)(*mvf));
-            ret = MIX_RESULT_SUCCESS;          
+            ret = MIX_RESULT_SUCCESS;
             LOG_V("One frame is dequeued.\n");
             break;
-            
-        default:         
+
+        default:
             LOG_E("Invalid frame order mode\n");
             ret = MIX_RESULT_FAIL;
             break;
@@ -791,7 +784,7 @@
 		return MIX_RESULT_NOT_INIT;
 	}
 
-	g_mutex_lock(fm->lock);		
+	g_mutex_lock(fm->lock);
 	fm->eos = TRUE;
 	LOG_V("EOS is received.\n");
 	g_mutex_unlock(fm->lock);
diff --git a/mix_video/src/mixvideoformat_h264.c b/mix_video/src/mixvideoformat_h264.c
index 6464177..04d517d 100644
--- a/mix_video/src/mixvideoformat_h264.c
+++ b/mix_video/src/mixvideoformat_h264.c
@@ -18,8 +18,6 @@
 static int mix_video_h264_counter = 0;
 #endif /* MIX_LOG_ENABLE */
 
-#define DECODER_ROBUSTNESS
-
 /* The parent class. The pointer will be saved
  * in this class's initialization. The pointer
  * can be used for chaining method call if needed.
@@ -40,6 +38,9 @@
 	/* These are all public because MixVideoFormat objects are completely internal to MixVideo,
 		no need for private members  */
 	self->dpb_surface_table = NULL;
+#ifdef DECODER_ROBUSTNESS
+	self->last_decoded_frame = NULL;
+#endif
 
 	/* NOTE: we don't need to do this here.
 	 * This just demostrates how to access
@@ -165,7 +166,7 @@
     VAConfigAttrib attrib;
 
     MixVideoFormat *parent = MIX_VIDEOFORMAT(mix);
-    MixVideoFormat_H264 *self = MIX_VIDEOFORMAT_H264(mix);  
+    MixVideoFormat_H264 *self = MIX_VIDEOFORMAT_H264(mix);
 
     if (parent->va_initialized)
     {
@@ -183,11 +184,11 @@
     //Initialize and save the VA config ID
     //We use high profile for all kinds of H.264 profiles (baseline, main and high)
     vret = vaCreateConfig(
-        parent->va_display, 
-        VAProfileH264High, 
-        VAEntrypointVLD, 
-        &attrib, 
-        1, 
+        parent->va_display,
+        VAProfileH264High,
+        VAEntrypointVLD,
+        &attrib,
+        1,
         &(parent->va_config));
 
     if (vret != VA_STATUS_SUCCESS)
@@ -207,7 +208,7 @@
     //Adding 1 to work around VBLANK issue, and another 1 to compensate cached frame that
     // will not start decoding until a new frame is received.
     parent->va_num_surfaces = 1 + 1 + parent->extra_surfaces + (((num_ref_pictures + 3) <
-        MIX_VIDEO_H264_SURFACE_NUM) ? 
+        MIX_VIDEO_H264_SURFACE_NUM) ?
         (num_ref_pictures + 3)
         : MIX_VIDEO_H264_SURFACE_NUM);
 
@@ -219,17 +220,17 @@
         goto cleanup;
     }
 
-    LOG_V( "Codec data says picture size is %d x %d\n", 
-        (data->pic_data[0].pic_parms->picture_width_in_mbs_minus1 + 1) * 16, 
+    LOG_V( "Codec data says picture size is %d x %d\n",
+        (data->pic_data[0].pic_parms->picture_width_in_mbs_minus1 + 1) * 16,
         (data->pic_data[0].pic_parms->picture_height_in_mbs_minus1 + 1) * 16);
     LOG_V( "getcaps says picture size is %d x %d\n", parent->picture_width, parent->picture_height);
 
     vret = vaCreateSurfaces(
-        parent->va_display, 
-        (data->pic_data[0].pic_parms->picture_width_in_mbs_minus1 + 1) * 16, 
-        (data->pic_data[0].pic_parms->picture_height_in_mbs_minus1 + 1) * 16, 
+        parent->va_display,
+        (data->pic_data[0].pic_parms->picture_width_in_mbs_minus1 + 1) * 16,
+        (data->pic_data[0].pic_parms->picture_height_in_mbs_minus1 + 1) * 16,
         VA_RT_FORMAT_YUV420,
-        parent->va_num_surfaces, 
+        parent->va_num_surfaces,
         parent->va_surfaces);
 
     if (vret != VA_STATUS_SUCCESS)
@@ -244,8 +245,8 @@
     //Initialize the surface pool
     ret = mix_surfacepool_initialize(
         parent->surfacepool,
-        parent->va_surfaces, 
-        parent->va_num_surfaces, 
+        parent->va_surfaces,
+        parent->va_num_surfaces,
         parent->va_display);
 
     switch (ret)
@@ -265,16 +266,16 @@
         int max = (int)pow(2, data->codec_data->log2_max_pic_order_cnt_lsb_minus4 + 4);
         mix_framemanager_set_max_picture_number(parent->framemgr, max);
     }
-    
+
     //Initialize and save the VA context ID
     //Note: VA_PROGRESSIVE libva flag is only relevant to MPEG2
     vret = vaCreateContext(
-        parent->va_display, 
+        parent->va_display,
         parent->va_config,
-        parent->picture_width, 
+        parent->picture_width,
         parent->picture_height,
         0,  // no flag set
-        parent->va_surfaces, 
+        parent->va_surfaces,
         parent->va_num_surfaces,
         &(parent->va_context));
 
@@ -288,7 +289,7 @@
     parent->va_initialized = TRUE;
 
 cleanup:
-    /* nothing to clean up */      
+    /* nothing to clean up */
 
     return ret;
 
@@ -296,20 +297,20 @@
 
 
 MIX_RESULT mix_videofmt_h264_update_ref_pic_list(
-    MixVideoFormat *mix, 
+    MixVideoFormat *mix,
     VAPictureParameterBufferH264* picture_params,
     VASliceParameterBufferH264* slice_params)
 {
-    MixVideoFormat_H264 *self = MIX_VIDEOFORMAT_H264(mix);  
-    
+    MixVideoFormat_H264 *self = MIX_VIDEOFORMAT_H264(mix);
+
     //Do slice parameters
-    
+
     //First patch up the List0 and List1 surface IDs
     int j = 0;
-    guint poc = 0;   
+    guint poc = 0;
     gpointer video_frame = NULL;
     MIX_RESULT ret = MIX_RESULT_SUCCESS;
-    
+
     for (; j <= slice_params->num_ref_idx_l0_active_minus1; j++)
     {
         if (!(slice_params->RefPicList0[j].flags & VA_PICTURE_H264_INVALID))
@@ -318,20 +319,20 @@
             video_frame = g_hash_table_lookup(self->dpb_surface_table, (gpointer)poc);
             if (video_frame == NULL)
             {
-                LOG_E("unable to find surface of picture %d (current picture %d).", 
+                LOG_E("unable to find surface of picture %d (current picture %d).",
                     poc, mix_videofmt_h264_get_poc(&(picture_params->CurrPic)));
                 ret = MIX_RESULT_DROPFRAME;  //return non-fatal error
                 goto cleanup;
             }
             else
             {
-                slice_params->RefPicList0[j].picture_id = 
+                slice_params->RefPicList0[j].picture_id =
                     ((MixVideoFrame *)video_frame)->frame_id;
             }
         }
-    
+
     }
-    
+
     if ((slice_params->slice_type == 1) || (slice_params->slice_type == 6))
     {
         for (j = 0; j <= slice_params->num_ref_idx_l1_active_minus1; j++)
@@ -342,14 +343,14 @@
                 video_frame = g_hash_table_lookup(self->dpb_surface_table, (gpointer)poc);
                 if (video_frame == NULL)
                 {
-                    LOG_E("unable to find surface of picture %d (current picture %d).", 
+                    LOG_E("unable to find surface of picture %d (current picture %d).",
                     poc, mix_videofmt_h264_get_poc(&(picture_params->CurrPic)));
                     ret = MIX_RESULT_DROPFRAME;  //return non-fatal error
                     goto cleanup;
                 }
                 else
-                {                       
-                    slice_params->RefPicList1[j].picture_id = 
+                {
+                    slice_params->RefPicList1[j].picture_id =
                         ((MixVideoFrame *)video_frame)->frame_id;
                 }
             }
@@ -368,7 +369,7 @@
     vbp_data_h264 *data,
     int picture_index,
     int slice_index)
-{  
+{
     MIX_RESULT ret = MIX_RESULT_SUCCESS;
     VAStatus vret = VA_STATUS_SUCCESS;
     VADisplay vadisplay = NULL;
@@ -409,7 +410,7 @@
             }
 
             // for interlace content, top field may be valid only after the second field is parsed
-            mix_videoframe_set_displayorder(mix->video_frame, pic_params->CurrPic.TopFieldOrderCnt);            
+            mix_videoframe_set_displayorder(mix->video_frame, pic_params->CurrPic.TopFieldOrderCnt);
         }
 
         gulong surface = 0;
@@ -417,7 +418,7 @@
         LOG_V("mix->video_frame = 0x%x\n", mix->video_frame);
 
         //Get our surface ID from the frame object
-        ret = mix_videoframe_get_frame_id(mix->video_frame, &surface);    
+        ret = mix_videoframe_get_frame_id(mix->video_frame, &surface);
         if (ret != MIX_RESULT_SUCCESS)
         {
             LOG_E( "Error getting surface ID from frame object\n");
@@ -453,7 +454,7 @@
             goto cleanup;
         }
 
-        // vaBeginPicture needs a matching vaEndPicture 
+        // vaBeginPicture needs a matching vaEndPicture
         mix->end_picture_pending = TRUE;
 
 #else
@@ -468,7 +469,7 @@
             goto cleanup;
         }
 
-        // vaBeginPicture needs a matching vaEndPicture 
+        // vaBeginPicture needs a matching vaEndPicture
         mix->end_picture_pending = TRUE;
 
         LOG_V( "Updating DPB for libva\n");
@@ -496,7 +497,7 @@
 
         //First the picture parameter buffer
         vret = vaCreateBuffer(
-            vadisplay, 
+            vadisplay,
             vacontext,
             VAPictureParameterBufferType,
             sizeof(VAPictureParameterBufferH264),
@@ -532,7 +533,7 @@
             LOG_E( "Video driver returned error from vaCreateBuffer\n");
             goto cleanup;
         }
-        buffer_id_cnt++;           
+        buffer_id_cnt++;
     }
 
 #ifndef DECODER_ROBUSTNESS
@@ -556,7 +557,7 @@
     LOG_V( "Creating libva slice parameter buffer\n");
 
     vret = vaCreateBuffer(
-        vadisplay, 
+        vadisplay,
         vacontext,
         VASliceParameterBufferType,
         sizeof(VASliceParameterBufferH264),
@@ -581,11 +582,11 @@
     // offset to the actual slice data is provided in
     // slice_data_offset in VASliceParameterBufferH264
 
-    LOG_V( "Creating libva slice data buffer, using slice address %x, with offset %d and size %u\n", 
+    LOG_V( "Creating libva slice data buffer, using slice address %x, with offset %d and size %u\n",
         (guint)slice_data->buffer_addr, slice_params->slice_data_offset, slice_data->slice_size);
 
     vret = vaCreateBuffer(
-        vadisplay, 
+        vadisplay,
         vacontext,
         VASliceDataBufferType,
         slice_data->slice_size, //size
@@ -629,13 +630,17 @@
 
 
 MIX_RESULT mix_videofmt_h264_decode_end(
-    MixVideoFormat *mix, 
+    MixVideoFormat *mix,
     gboolean drop_picture)
 {
-    MIX_RESULT ret = MIX_RESULT_SUCCESS;    
+    MIX_RESULT ret = MIX_RESULT_SUCCESS;
     VAStatus vret = VA_STATUS_SUCCESS;
     MixVideoFormat* parent = MIX_VIDEOFORMAT(mix);
-    //MixVideoFormat_H264 *self = MIX_VIDEOFORMAT_H264(mix);  
+#ifdef DECODER_ROBUSTNESS
+    MixVideoFormat_H264 *self = MIX_VIDEOFORMAT_H264(mix);
+#else
+    //MixVideoFormat_H264 *self = MIX_VIDEOFORMAT_H264(mix);
+#endif
 
     LOG_V("Begin\n");
 
@@ -647,7 +652,7 @@
             LOG_E("Unexpected: video_frame is not unreferenced.\n");
         }
         goto cleanup;
-    }    
+    }
 
     if (parent->video_frame == NULL)
     {
@@ -655,8 +660,8 @@
         LOG_E("Unexpected: video_frame has been unreferenced.\n");
         goto cleanup;
     }
-    
-	LOG_V( "Calling vaEndPicture\n");    
+
+	LOG_V( "Calling vaEndPicture\n");
     vret = vaEndPicture(parent->va_display, parent->va_context);
 
     if (vret != VA_STATUS_SUCCESS)
@@ -689,8 +694,15 @@
         goto cleanup;
     }
 
-	LOG_V( "Enqueueing the frame with frame manager, timestamp %"G_GINT64_FORMAT"\n", 
-	    parent->current_timestamp);
+	LOG_V( "Enqueueing the frame with frame manager, timestamp %"G_GINT64_FORMAT"\n",
+	    parent->video_frame->timestamp);
+
+#ifdef DECODER_ROBUSTNESS
+	if (self->last_decoded_frame)
+		mix_videoframe_unref(self->last_decoded_frame);
+	self->last_decoded_frame = parent->video_frame;
+	mix_videoframe_ref(self->last_decoded_frame);
+#endif
 
     //Enqueue the decoded frame using frame manager
     ret = mix_framemanager_enqueue(parent->framemgr, parent->video_frame);
@@ -709,7 +721,7 @@
 cleanup:
     if (parent->video_frame)
     {
-        /* this always indicates an error */        
+        /* this always indicates an error */
         mix_videoframe_unref(parent->video_frame);
         parent->video_frame = NULL;
     }
@@ -721,7 +733,7 @@
 
 
 MIX_RESULT mix_videofmt_h264_decode_continue(
-    MixVideoFormat *mix, 
+    MixVideoFormat *mix,
     vbp_data_h264 *data)
 {
     MIX_RESULT ret = MIX_RESULT_SUCCESS;
@@ -745,26 +757,26 @@
             ret = MIX_RESULT_FAIL;
             LOG_E("pic_data->slc_data is NULL.\n");
             goto cleanup;
-        }	
+        }
 
         if (pic_data->num_slices == 0)
         {
             ret = MIX_RESULT_FAIL;
             LOG_E("pic_data->num_slices == 0.\n");
             goto cleanup;
-        }	    
+        }
 
-	    LOG_V( "num_slices is %d\n", pic_data->num_slices);        
+	    LOG_V( "num_slices is %d\n", pic_data->num_slices);
         for (j = 0; j < pic_data->num_slices; j++)
         {
-    	    LOG_V( "Decoding slice %d\n", j);        
+    	    LOG_V( "Decoding slice %d\n", j);
 	        ret = mix_videofmt_h264_decode_a_slice(mix, data, i, j);
             if (ret != 	MIX_RESULT_SUCCESS)
             {
                 LOG_E( "mix_videofmt_h264_decode_a_slice failed, error =  %#X.", ret);
                 goto cleanup;
-           }			  
-        }		
+           }
+        }
     }
 
 cleanup:
@@ -776,9 +788,9 @@
 
 
 MIX_RESULT mix_videofmt_h264_set_frame_type(
-    MixVideoFormat *mix, 
+    MixVideoFormat *mix,
     vbp_data_h264 *data)
-{    
+{
     MIX_RESULT ret = MIX_RESULT_SUCCESS;
 
     //Set the picture type (I, B or P frame)
@@ -810,7 +822,7 @@
     //Do not have to check for B frames after a seek
     //Note:  Demux should seek to IDR (instantaneous decoding refresh) frame, otherwise
     //  DPB will not be correct and frames may come in with invalid references
-    //  This will be detected when DPB is checked for valid mapped surfaces and 
+    //  This will be detected when DPB is checked for valid mapped surfaces and
     //  error returned from there.
 
 	LOG_V( "frame type is %d\n", frame_type);
@@ -828,14 +840,14 @@
 
 
 MIX_RESULT mix_videofmt_h264_set_frame_structure(
-    MixVideoFormat *mix, 
+    MixVideoFormat *mix,
     vbp_data_h264 *data)
-{    
+{
     MIX_RESULT ret = MIX_RESULT_SUCCESS;
 
     if (data->pic_data[0].pic_parms->CurrPic.flags & VA_PICTURE_H264_TOP_FIELD)
     {
-        mix_videoframe_set_frame_structure(mix->video_frame, VA_BOTTOM_FIELD | VA_TOP_FIELD); 
+        mix_videoframe_set_frame_structure(mix->video_frame, VA_BOTTOM_FIELD | VA_TOP_FIELD);
     }
     else
     {
@@ -847,7 +859,7 @@
 
 
 MIX_RESULT mix_videofmt_h264_decode_begin(
-    MixVideoFormat *mix, 
+    MixVideoFormat *mix,
     vbp_data_h264 *data)
 {
     MIX_RESULT ret = MIX_RESULT_SUCCESS;
@@ -859,7 +871,7 @@
     if (ret != MIX_RESULT_SUCCESS)
     {
         LOG_E( "Error getting frame from surfacepool\n");
-        return ret; 
+        return ret;
     }
 
     /* the following calls will always succeed */
@@ -874,10 +886,10 @@
     mix_videoframe_set_discontinuity(mix->video_frame, mix->discontinuity_frame_in_progress);
 
     //Set the timestamp
-    mix_videoframe_set_timestamp(mix->video_frame, mix->current_timestamp);	
+    mix_videoframe_set_timestamp(mix->video_frame, mix->current_timestamp);
 
     // Set displayorder
-    ret = mix_videoframe_set_displayorder(mix->video_frame, 
+    ret = mix_videoframe_set_displayorder(mix->video_frame,
         data->pic_data[0].pic_parms->CurrPic.TopFieldOrderCnt);
     if(ret != MIX_RESULT_SUCCESS)
     {
@@ -894,10 +906,10 @@
 
 
 MIX_RESULT mix_videofmt_h264_decode_a_buffer(
-    MixVideoFormat *mix, 
+    MixVideoFormat *mix,
     MixBuffer * bufin,
     guint64 ts,
-    gboolean discontinuity) 
+    gboolean discontinuity)
 {
     uint32 pret = 0;
     MixVideoFormat *parent = NULL;
@@ -909,8 +921,8 @@
     parent = MIX_VIDEOFORMAT(mix);
 
     LOG_V( "Calling parse for current frame, parse handle %d\n", (int)parent->parser_handle);
-    pret = vbp_parse(parent->parser_handle, 
-        bufin->data, 
+    pret = vbp_parse(parent->parser_handle,
+        bufin->data,
         bufin->size,
         FALSE);
 
@@ -938,7 +950,7 @@
     {
         ret = MIX_RESULT_SUCCESS;
         LOG_V("SPS or PPS is not available.\n");
-        goto cleanup;      
+        goto cleanup;
     }
 
     if (parent->va_initialized == FALSE)
@@ -946,9 +958,9 @@
         LOG_V("try initializing VA...\n");
         ret = mix_videofmt_h264_initialize_va(parent, data);
         if (ret != MIX_RESULT_SUCCESS)
-        {         
+        {
             LOG_V("mix_videofmt_h264_initialize_va failed.\n");
-            goto cleanup; 
+            goto cleanup;
         }
     }
 
@@ -957,10 +969,10 @@
     {
         ret = MIX_RESULT_SUCCESS;
         LOG_V("slice is not available.\n");
-        goto cleanup;      
+        goto cleanup;
     }
-    
-    guint64 last_ts = parent->current_timestamp;    
+
+    guint64 last_ts = parent->current_timestamp;
     parent->current_timestamp = ts;
     parent->discontinuity_frame_in_progress = discontinuity;
 
@@ -971,18 +983,18 @@
         // finish decoding the last frame
         ret = mix_videofmt_h264_decode_end(parent, FALSE);
         if (ret != MIX_RESULT_SUCCESS)
-        {         
+        {
             LOG_V("mix_videofmt_h264_decode_end failed.\n");
-            goto cleanup; 
+            goto cleanup;
         }
 
         // start decoding a new frame
-        ret = mix_videofmt_h264_decode_begin(parent, data); 
+        ret = mix_videofmt_h264_decode_begin(parent, data);
         if (ret != MIX_RESULT_SUCCESS)
-        {         
+        {
             LOG_V("mix_videofmt_h264_decode_begin failed.\n");
-            goto cleanup; 
-        }        
+            goto cleanup;
+        }
     }
     else
     {
@@ -990,10 +1002,10 @@
         LOG_V("partial frame handling...\n");
         ret = mix_videofmt_h264_decode_continue(parent, data);
         if (ret != MIX_RESULT_SUCCESS)
-        {         
+        {
             LOG_V("mix_videofmt_h264_decode_continue failed.\n");
-            goto cleanup; 
-        }        
+            goto cleanup;
+        }
     }
 
     cleanup:
@@ -1004,7 +1016,7 @@
 }
 
 
-MIX_RESULT mix_videofmt_h264_initialize(MixVideoFormat *mix, 
+MIX_RESULT mix_videofmt_h264_initialize(MixVideoFormat *mix,
 		MixVideoConfigParamsDec * config_params,
         MixFrameManager * frame_mgr,
 		MixBufferPool * input_buf_pool,
@@ -1032,7 +1044,7 @@
 
     if (parent_class->initialize) {
         ret = parent_class->initialize(mix, config_params,
-            frame_mgr, input_buf_pool, surface_pool, 
+            frame_mgr, input_buf_pool, surface_pool,
             va_display);
     }
 
@@ -1064,9 +1076,9 @@
 
     //Create our table of Decoded Picture Buffer "in use" surfaces
     self->dpb_surface_table = g_hash_table_new_full(
-        NULL, 
-        NULL, 
-        mix_videofmt_h264_destroy_DPB_key, 
+        NULL,
+        NULL,
+        mix_videofmt_h264_destroy_DPB_key,
         mix_videofmt_h264_destroy_DPB_value);
 
     if (self->dpb_surface_table == NULL)
@@ -1085,7 +1097,7 @@
         ret = MIX_RESULT_FAIL;
         LOG_E( "Cannot get extra surface allocation setting\n");
         goto cleanup;
-    }    
+    }
 
 	LOG_V( "Before vbp_open\n");
     //Load the bitstream parser
@@ -1115,7 +1127,7 @@
 
     pret = vbp_parse(
         parent->parser_handle,
-        header->data, 
+        header->data,
         header->data_size,
         TRUE);
 
@@ -1144,8 +1156,13 @@
     pic_width_in_codec_data  = (data->pic_data[0].pic_parms->picture_width_in_mbs_minus1 + 1) * 16;
     pic_height_in_codec_data = (data->pic_data[0].pic_parms->picture_height_in_mbs_minus1 + 1) * 16;
     mix_videoconfigparamsdec_set_picture_res (config_params, pic_width_in_codec_data, pic_height_in_codec_data);
-    parent->picture_width  = pic_width_in_codec_data;
-    parent->picture_height = pic_height_in_codec_data;
+
+    if (parent->picture_width == 0 || parent->picture_height == 0)
+    {
+        // Update picture resolution only if it is not set. The derived picture res from mbs may not be accurate.
+        parent->picture_width  = pic_width_in_codec_data;
+        parent->picture_height = pic_height_in_codec_data;
+    }
 
     ret = mix_videofmt_h264_initialize_va(mix, data);
     if (ret != MIX_RESULT_SUCCESS)
@@ -1154,7 +1171,6 @@
         goto cleanup;
     }
 
-
     cleanup:
     if (ret != MIX_RESULT_SUCCESS) {
         pret = vbp_close(parent->parser_handle);
@@ -1182,9 +1198,9 @@
 }
 
 MIX_RESULT mix_videofmt_h264_decode(
-    MixVideoFormat *mix, 
+    MixVideoFormat *mix,
     MixBuffer * bufin[],
-    gint bufincnt, 
+    gint bufincnt,
     MixVideoDecodeParams * decode_params) {
 
     int i = 0;
@@ -1239,11 +1255,11 @@
 
     for (i = 0; i < bufincnt; i++)
     {
-		LOG_V( "Decoding a buf %x, size %d\n", (guint)bufin[i]->data, bufin[i]->size);  
-		    
+		LOG_V( "Decoding a buf %x, size %d\n", (guint)bufin[i]->data, bufin[i]->size);
+
         // decode a buffer at a time
         ret = mix_videofmt_h264_decode_a_buffer(
-            mix, 
+            mix,
             bufin[i],
             ts,
             discontinuity);
@@ -1252,7 +1268,7 @@
         {
             LOG_E("mix_videofmt_h264_decode_a_buffer failed.\n");
             goto cleanup;
-        }        
+        }
     }
 
 
@@ -1296,7 +1312,7 @@
 
     // drop any decode-pending picture, and ignore return value
     mix_videofmt_h264_decode_end(mix, TRUE);
-	
+
 	//Clear parse_in_progress flag and current timestamp
     mix->parse_in_progress = FALSE;
 	mix->discontinuity_frame_in_progress = FALSE;
@@ -1343,7 +1359,7 @@
 
     // finished decoding the pending frame
     mix_videofmt_h264_decode_end(mix, FALSE);
-    
+
     g_mutex_unlock(mix->objectlock);
 
 	//Call Frame Manager with _eos()
@@ -1385,9 +1401,9 @@
 
 #define HACK_DPB
 #ifdef HACK_DPB
-static inline MIX_RESULT mix_videofmt_h264_hack_dpb(MixVideoFormat *mix, 
+static inline MIX_RESULT mix_videofmt_h264_hack_dpb(MixVideoFormat *mix,
 					vbp_picture_data_h264* pic_data
-					) 
+					)
 {
 
 	gboolean found = FALSE;
@@ -1402,9 +1418,9 @@
 	for (i = 0; i < 16; i++)
 	{
 		pic_params->ReferenceFrames[i].picture_id = VA_INVALID_SURFACE;
-		pic_params->ReferenceFrames[i].frame_idx = -1; 
-		pic_params->ReferenceFrames[i].TopFieldOrderCnt = -1; 
-		pic_params->ReferenceFrames[i].BottomFieldOrderCnt = -1; 
+		pic_params->ReferenceFrames[i].frame_idx = -1;
+		pic_params->ReferenceFrames[i].TopFieldOrderCnt = -1;
+		pic_params->ReferenceFrames[i].BottomFieldOrderCnt = -1;
 		pic_params->ReferenceFrames[i].flags = VA_PICTURE_H264_INVALID;  //assuming we don't need to OR with existing flags
 	}
 
@@ -1417,7 +1433,7 @@
 		pRefList = pic_data->slc_data[i].slc_parms.RefPicList0;
 		for (list = 0; list < 2; list++)
 		{
-			for (j = 0; j < 32; j++)  
+			for (j = 0; j < 32; j++)
 			{
 				if (pRefList[j].flags & VA_PICTURE_H264_INVALID)
 				{
@@ -1443,20 +1459,41 @@
 					guint poc = mix_videofmt_h264_get_poc(&(pRefList[j]));
 					gpointer video_frame = g_hash_table_lookup(self->dpb_surface_table, (gpointer)poc);
 
+#ifdef DECODER_ROBUSTNESS
+					if (!video_frame)
+					{
+						if (!self->last_decoded_frame)
+						{
+							//No saved reference frame, can't recover this one
+							return MIX_RESULT_DROPFRAME;
+						}
+
+						pic_params->ReferenceFrames[pic_params->num_ref_frames].picture_id =
+							((MixVideoFrame *)self->last_decoded_frame)->frame_id;
+						LOG_V( "Reference frame not found, substituting %d\n", pic_params->ReferenceFrames[pic_params->num_ref_frames].picture_id);
+
+					}
+					else
+					{
+						pic_params->ReferenceFrames[pic_params->num_ref_frames].picture_id =
+							((MixVideoFrame *)video_frame)->frame_id;
+					}
+#else
 					if (!video_frame) return MIX_RESULT_DROPFRAME; //return non-fatal error
 
-					pic_params->ReferenceFrames[pic_params->num_ref_frames].picture_id = 
+					pic_params->ReferenceFrames[pic_params->num_ref_frames].picture_id =
 						((MixVideoFrame *)video_frame)->frame_id;
+#endif
 
         			LOG_V( "Inserting frame id %d into DPB\n", pic_params->ReferenceFrames[pic_params->num_ref_frames].picture_id);
 
-					pic_params->ReferenceFrames[pic_params->num_ref_frames].flags = 
+					pic_params->ReferenceFrames[pic_params->num_ref_frames].flags =
 						pRefList[j].flags;
-					pic_params->ReferenceFrames[pic_params->num_ref_frames].frame_idx = 
+					pic_params->ReferenceFrames[pic_params->num_ref_frames].frame_idx =
 						pRefList[j].frame_idx;
-					pic_params->ReferenceFrames[pic_params->num_ref_frames].TopFieldOrderCnt = 
+					pic_params->ReferenceFrames[pic_params->num_ref_frames].TopFieldOrderCnt =
 						pRefList[j].TopFieldOrderCnt;
-					pic_params->ReferenceFrames[pic_params->num_ref_frames++].BottomFieldOrderCnt = 
+					pic_params->ReferenceFrames[pic_params->num_ref_frames++].BottomFieldOrderCnt =
 						pRefList[j].BottomFieldOrderCnt;
 				}
 
@@ -1469,9 +1506,9 @@
 }
 #endif
 
-	
 
-MIX_RESULT mix_videofmt_h264_handle_ref_frames(MixVideoFormat *mix, 
+
+MIX_RESULT mix_videofmt_h264_handle_ref_frames(MixVideoFormat *mix,
 					VAPictureParameterBufferH264* pic_params,
 					MixVideoFrame * current_frame
 					) {
@@ -1550,11 +1587,11 @@
 	pic_params->CurrPic.picture_id = current_frame->frame_id;
 
 	//Check to see if current frame is a reference frame
-	if ((pic_params->CurrPic.flags & VA_PICTURE_H264_SHORT_TERM_REFERENCE) || 
+	if ((pic_params->CurrPic.flags & VA_PICTURE_H264_SHORT_TERM_REFERENCE) ||
         (pic_params->CurrPic.flags & VA_PICTURE_H264_LONG_TERM_REFERENCE))
 	{
 		//Get current frame's POC
-		poc = mix_videofmt_h264_get_poc(&(pic_params->CurrPic));	
+		poc = mix_videofmt_h264_get_poc(&(pic_params->CurrPic));
 
 		//Increment the reference count for this frame
 		mix_videoframe_ref(current_frame);
@@ -1569,7 +1606,7 @@
 	return MIX_RESULT_SUCCESS;
 }
 
-MIX_RESULT mix_videofmt_h264_cleanup_ref_frame(MixVideoFormat *mix, 
+MIX_RESULT mix_videofmt_h264_cleanup_ref_frame(MixVideoFormat *mix,
 					VAPictureParameterBufferH264* pic_params,
 					MixVideoFrame * current_frame
 					) {
@@ -1593,10 +1630,9 @@
 	if ((pic_params->CurrPic.flags & VA_PICTURE_H264_SHORT_TERM_REFERENCE) || (pic_params->CurrPic.flags & VA_PICTURE_H264_LONG_TERM_REFERENCE))
 	{
 		//Get current frame's POC
-		poc = mix_videofmt_h264_get_poc(&(pic_params->CurrPic));	
+		poc = mix_videofmt_h264_get_poc(&(pic_params->CurrPic));
 
-		//Decrement the reference count for this frame
-//		mix_videoframe_unref(current_frame);
+		//We don't need to decrement the ref count for the video frame here; it's done elsewhere
 
 		LOG_V( "Removing poc %d, surfaceID %d\n", poc, (gint)current_frame->frame_id);
 		//Remove this frame from the DPB surface table
@@ -1639,7 +1675,7 @@
 		vaPic = &(((VAPictureParameterBufferH264*)user_data)->ReferenceFrames[i]);
 		if (vaPic->flags & VA_PICTURE_H264_INVALID)
 			continue;
-			
+
 		if ((guint)key == vaPic->TopFieldOrderCnt ||
 			(guint)key == vaPic->BottomFieldOrderCnt)
 		{
@@ -1673,7 +1709,7 @@
 }
 
 
-MIX_RESULT mix_videofmt_h264_release_input_buffers(MixVideoFormat *mix, 
+MIX_RESULT mix_videofmt_h264_release_input_buffers(MixVideoFormat *mix,
 					guint64 timestamp
 					) {
 
diff --git a/mix_video/src/mixvideoformat_h264.h b/mix_video/src/mixvideoformat_h264.h
index b6d062e..84bfc78 100644
--- a/mix_video/src/mixvideoformat_h264.h
+++ b/mix_video/src/mixvideoformat_h264.h
@@ -12,6 +12,8 @@
 #include "mixvideoformat.h"
 #include "mixvideoframe_private.h"
 
+#define DECODER_ROBUSTNESS
+
 G_BEGIN_DECLS
 
 #define MIX_VIDEO_H264_SURFACE_NUM       20
@@ -37,6 +39,10 @@
 
 	/*< private > */
 	GHashTable *dpb_surface_table;
+#ifdef DECODER_ROBUSTNESS
+	//Can improve which frame is used for this at a later time
+	MixVideoFrame  *last_decoded_frame;  //last surface decoded, to be used as reference frame when reference frames are missing
+#endif
 };
 
 /**
@@ -90,7 +96,7 @@
 
 /* H.264 vmethods */
 MIX_RESULT mix_videofmt_h264_getcaps(MixVideoFormat *mix, GString *msg);
-MIX_RESULT mix_videofmt_h264_initialize(MixVideoFormat *mix, 
+MIX_RESULT mix_videofmt_h264_initialize(MixVideoFormat *mix,
 				  MixVideoConfigParamsDec * config_params,
 				  MixFrameManager * frame_mgr,
 				  MixBufferPool * input_buf_pool,
@@ -110,12 +116,12 @@
 
 
 MIX_RESULT mix_videofmt_h264_process_decode(MixVideoFormat *mix,
-                                        vbp_data_h264 *data, 
+                                        vbp_data_h264 *data,
 					guint64 timestamp,
 					gboolean discontinuity);
 
 
-MIX_RESULT mix_videofmt_h264_release_input_buffers(MixVideoFormat *mix, 
+MIX_RESULT mix_videofmt_h264_release_input_buffers(MixVideoFormat *mix,
 					guint64 timestamp);
 
 
diff --git a/mix_video/src/mixvideoformatenc_h264.c b/mix_video/src/mixvideoformatenc_h264.c
index 336b4d8..32e1bdb 100644
--- a/mix_video/src/mixvideoformatenc_h264.c
+++ b/mix_video/src/mixvideoformatenc_h264.c
@@ -1117,6 +1117,8 @@
     slice_height += 15;
     slice_height &= (~15);
 
+    slice_num = mix->slice_num = (parent->picture_height + 15) / slice_height;
+
 #if 1 		 
     va_status = vaCreateBuffer (parent->va_display, parent->va_context, 
             VAEncSliceParameterBufferType,