Merge branch 'master' into 0.11
diff --git a/configure.ac b/configure.ac
index 108c2b4..61ed3da 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1203,7 +1203,7 @@
           if test "x$mpeg2enc_headers_ok" = "xyes"; then
             HAVE_MPEG2ENC="yes"
           fi
-          CPP_FLAGS="$CPPFLAGS_GOOD"
+          CPPFLAGS="$CPPFLAGS_GOOD"
           AC_SUBST(MPEG2ENC_CFLAGS)
           AC_SUBST(MPEG2ENC_LIBS)
         ], [
@@ -1231,10 +1231,14 @@
     dnl and mpeg2enc, we check for mplex on its own, too.
     dnl libmplex < 1.9rc? has fuzzy ABI, valgrind and other problems
     PKG_CHECK_MODULES(MPLEX, mjpegtools >= 1.9.0, [
+      dnl HACK because mplex 2.0.0 header files have a spurious 'include config.h'
+      touch config.h
       dnl switch over to c++ to test things
       AC_LANG_CPLUSPLUS
       OLD_CPPFLAGS="$CPPFLAGS"
-      CPPFLAGS="$CPPFLAGS $MPLEX_CFLAGS"
+      dnl HACK as above
+      CPPFLAGS_GOOD="$CPPFLAGS $MPLEX_CFLAGS"
+      CPPFLAGS="$CPPFLAGS_GOOD -I."
       AC_CHECK_HEADER(interact.hpp, [
         MPLEX_LIBS="$MPLEX_LIBS -lmplex2 $LIBM"
         OLD_LIBS="$LIBS"
@@ -1271,6 +1275,7 @@
 }
         ],[
           HAVE_MPLEX="yes"
+          CPPFLAGS="$CPPFLAGS_GOOD"
           AC_SUBST(MPLEX_CFLAGS)
           AC_SUBST(MPLEX_LIBS)
           AC_SUBST(MPLEX_LDFLAGS)
diff --git a/gst-libs/gst/codecparsers/gsth264parser.c b/gst-libs/gst/codecparsers/gsth264parser.c
index b496c0f..87bff4e 100644
--- a/gst-libs/gst/codecparsers/gsth264parser.c
+++ b/gst-libs/gst/codecparsers/gsth264parser.c
@@ -953,7 +953,7 @@
 
   GST_DEBUG ("parsing \"Buffering period\"");
 
-  READ_UE_ALLOWED (nr, sps_id, 0, GST_H264_MAX_SPS_COUNT);
+  READ_UE_ALLOWED (nr, sps_id, 0, GST_H264_MAX_SPS_COUNT - 1);
   sps = gst_h264_parser_get_sps (nalparser, sps_id);
   if (!sps) {
     GST_WARNING ("couldn't find associated sequence parameter set with id: %d",
@@ -1372,7 +1372,7 @@
 
   READ_UINT8 (&nr, sps->level_idc, 8);
 
-  READ_UE_ALLOWED (&nr, sps->id, 0, GST_H264_MAX_SPS_COUNT);
+  READ_UE_ALLOWED (&nr, sps->id, 0, GST_H264_MAX_SPS_COUNT - 1);
 
   if (sps->profile_idc == 100 || sps->profile_idc == 110 ||
       sps->profile_idc == 122 || sps->profile_idc == 244 ||
@@ -1468,7 +1468,10 @@
   sps->width = width;
   sps->height = height;
 
-  if (vui) {
+  sps->fps_num = 0;
+  sps->fps_den = 1;
+
+  if (vui && vui->timing_info_present_flag) {
     /* derive framerate */
     /* FIXME verify / also handle other cases */
     GST_LOG ("Framerate: %u %u %u %u", parse_vui_params,
@@ -1484,8 +1487,6 @@
       GST_LOG ("framerate %d/%d", sps->fps_num, sps->fps_den);
     }
   } else {
-    sps->fps_num = 0;
-    sps->fps_den = 1;
     GST_LOG ("No VUI, unknown framerate");
   }
 
@@ -1523,8 +1524,8 @@
 
   nal_reader_init (&nr, nalu->data + nalu->offset + 1, nalu->size - 1);
 
-  READ_UE_ALLOWED (&nr, pps->id, 0, GST_H264_MAX_PPS_COUNT);
-  READ_UE_ALLOWED (&nr, sps_id, 0, GST_H264_MAX_SPS_COUNT);
+  READ_UE_ALLOWED (&nr, pps->id, 0, GST_H264_MAX_PPS_COUNT - 1);
+  READ_UE_ALLOWED (&nr, sps_id, 0, GST_H264_MAX_SPS_COUNT - 1);
 
   sps = gst_h264_parser_get_sps (nalparser, sps_id);
   if (!sps) {
diff --git a/gst/camerabin2/gstcamerabin2.c b/gst/camerabin2/gstcamerabin2.c
index 8d1de91..eebf120 100644
--- a/gst/camerabin2/gstcamerabin2.c
+++ b/gst/camerabin2/gstcamerabin2.c
@@ -377,6 +377,11 @@
 
   GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
 
+  if (camerabin->post_previews) {
+    /* Count processing of preview images too */
+    GST_CAMERA_BIN2_PROCESSING_INC (camerabin);
+  }
+
   if (camerabin->location)
     location = g_strdup_printf (camerabin->location, capture_index);
 
@@ -929,6 +934,26 @@
 }
 
 static void
+gst_camera_bin_skip_next_preview (GstCameraBin2 * camerabin)
+{
+  gchar *location;
+
+  g_mutex_lock (camerabin->preview_list_mutex);
+  if (camerabin->preview_location_list) {
+    location = camerabin->preview_location_list->data;
+    GST_DEBUG_OBJECT (camerabin, "Skipping preview for %s", location);
+    g_free (location);
+    camerabin->preview_location_list =
+        g_slist_delete_link (camerabin->preview_location_list,
+        camerabin->preview_location_list);
+    GST_CAMERA_BIN2_PROCESSING_DEC (camerabin);
+  } else {
+    GST_WARNING_OBJECT (camerabin, "No previews to skip");
+  }
+  g_mutex_unlock (camerabin->preview_list_mutex);
+}
+
+static void
 gst_camera_bin_handle_message (GstBin * bin, GstMessage * message)
 {
   GstCameraBin2 *camerabin = GST_CAMERA_BIN2_CAST (bin);
@@ -974,6 +999,9 @@
           gst_structure_take_value ((GstStructure *) structure, "location",
               value);
         }
+
+        GST_LOG_OBJECT (bin, "received preview-image message");
+        GST_CAMERA_BIN2_PROCESSING_DEC (GST_CAMERA_BIN2_CAST (bin));
       }
     }
       break;
@@ -987,6 +1015,9 @@
         GST_WARNING_OBJECT (bin, "Capture failed, reason: %s - %s",
             err->message, debug);
         GST_CAMERA_BIN2_PROCESSING_DEC (GST_CAMERA_BIN2_CAST (bin));
+        if (camerabin->post_previews) {
+          gst_camera_bin_skip_next_preview (camerabin);
+        }
       }
     }
       break;
diff --git a/gst/fieldanalysis/gstfieldanalysis.c b/gst/fieldanalysis/gstfieldanalysis.c
index 21b2e0d..bc6e4c5 100644
--- a/gst/fieldanalysis/gstfieldanalysis.c
+++ b/gst/fieldanalysis/gstfieldanalysis.c
@@ -313,9 +313,8 @@
 static gfloat opposite_parity_windowed_comb (GstFieldAnalysis * filter,
     FieldAnalysisFields * fields);
 
-
 static void
-gst_field_analysis_reset (GstFieldAnalysis * filter)
+gst_field_analysis_empty_queue (GstFieldAnalysis * filter)
 {
   if (filter->frames) {
     guint length = g_queue_get_length (filter->frames);
@@ -327,6 +326,12 @@
       length--;
     }
   }
+}
+
+static void
+gst_field_analysis_reset (GstFieldAnalysis * filter)
+{
+  gst_field_analysis_empty_queue (filter);
   GST_DEBUG_OBJECT (filter, "Resetting context");
   memset (filter->results, 0, 2 * sizeof (FieldAnalysis));
   filter->is_telecine = FALSE;
@@ -1711,7 +1716,7 @@
       }
     }
 
-    gst_field_analysis_reset (filter);
+    gst_field_analysis_empty_queue (filter);
 
     if (ret != GST_FLOW_OK) {
       GST_DEBUG_OBJECT (filter,
diff --git a/tests/check/elements/h264parse.c b/tests/check/elements/h264parse.c
index b5423e5..b050263 100644
--- a/tests/check/elements/h264parse.c
+++ b/tests/check/elements/h264parse.c
@@ -328,7 +328,7 @@
 int
 main (int argc, char **argv)
 {
-  int nf;
+  int nf = 0;
 
   Suite *s;
   SRunner *sr;
@@ -354,7 +354,7 @@
   s = h264parse_suite ();
   sr = srunner_create (s);
   srunner_run_all (sr, CK_NORMAL);
-  nf = srunner_ntests_failed (sr);
+  nf += srunner_ntests_failed (sr);
   srunner_free (sr);
 
   /* setup and tweak to handle avc au output */
@@ -366,7 +366,7 @@
   s = h264parse_suite ();
   sr = srunner_create (s);
   srunner_run_all (sr, CK_NORMAL);
-  nf = srunner_ntests_failed (sr);
+  nf += srunner_ntests_failed (sr);
   srunner_free (sr);
 
   /* setup and tweak to handle avc packetized input */
@@ -386,7 +386,7 @@
   s = h264parse_packetized_suite ();
   sr = srunner_create (s);
   srunner_run_all (sr, CK_NORMAL);
-  nf = srunner_ntests_failed (sr);
+  nf += srunner_ntests_failed (sr);
   srunner_free (sr);
 
   return nf;