videoparsers: preserve upstream fps and par
authorMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Thu, 25 Oct 2012 09:31:41 +0000 (11:31 +0200)
committerMark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
Thu, 25 Oct 2012 15:07:18 +0000 (17:07 +0200)
Fixes https://bugzilla.gnome.org/show_bug.cgi?id=660866

gst/videoparsers/gsth264parse.c
gst/videoparsers/gstmpegvideoparse.c

index bb9ada9..af32a72 100644 (file)
@@ -1102,6 +1102,7 @@ gst_h264_parse_update_src_caps (GstH264Parse * h264parse, GstCaps * caps)
   GstCaps *sink_caps;
   gboolean modified = FALSE;
   GstBuffer *buf = NULL;
+  GstStructure *s = NULL;
 
   if (G_UNLIKELY (!gst_pad_has_current_caps (GST_BASE_PARSE_SRC_PAD
               (h264parse))))
@@ -1119,6 +1120,8 @@ gst_h264_parse_update_src_caps (GstH264Parse * h264parse, GstCaps * caps)
   /* carry over input caps as much as possible; override with our own stuff */
   if (!sink_caps)
     sink_caps = gst_caps_new_empty_simple ("video/x-h264");
+  else
+    s = gst_caps_get_structure (caps, 0);
 
   sps = h264parse->nalparser->last_sps;
   GST_DEBUG_OBJECT (h264parse, "sps: %p", sps);
@@ -1165,8 +1168,6 @@ gst_h264_parse_update_src_caps (GstH264Parse * h264parse, GstCaps * caps)
             sps->fps_num, sps->fps_den);
         h264parse->fps_num = sps->fps_num;
         h264parse->fps_den = sps->fps_den;
-        gst_base_parse_set_frame_rate (GST_BASE_PARSE (h264parse),
-            h264parse->fps_num, h264parse->fps_den, 0, 0);
         modified = TRUE;
       }
     }
@@ -1198,9 +1199,14 @@ gst_h264_parse_update_src_caps (GstH264Parse * h264parse, GstCaps * caps)
       gst_caps_set_simple (caps, "width", G_TYPE_INT, sps->width,
           "height", G_TYPE_INT, sps->height, NULL);
       /* but not necessarily or reliably this */
-      if (h264parse->fps_num > 0 && h264parse->fps_den > 0)
+      if (h264parse->fps_num > 0 && h264parse->fps_den > 0 &&
+          (!s || !gst_structure_has_field (s, "framerate"))) {
+        GST_INFO_OBJECT (h264parse, "setting framerate in caps");
         gst_caps_set_simple (caps, "framerate",
             GST_TYPE_FRACTION, h264parse->fps_num, h264parse->fps_den, NULL);
+        gst_base_parse_set_frame_rate (GST_BASE_PARSE (h264parse),
+            h264parse->fps_num, h264parse->fps_den, 0, 0);
+      }
     }
   }
 
@@ -1214,7 +1220,8 @@ gst_h264_parse_update_src_caps (GstH264Parse * h264parse, GstCaps * caps)
         gst_h264_parse_get_string (h264parse, FALSE, h264parse->align), NULL);
 
     gst_h264_parse_get_par (h264parse, &par_n, &par_d);
-    if (par_n != 0 && par_d != 0) {
+    if (par_n != 0 && par_d != 0 &&
+        (!s || !gst_structure_has_field (s, "pixel-aspect-ratio"))) {
       GST_INFO_OBJECT (h264parse, "PAR %d/%d", par_n, par_d);
       gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
           par_n, par_d, NULL);
index bb111b0..e3e6fa6 100644 (file)
@@ -626,6 +626,7 @@ static void
 gst_mpegv_parse_update_src_caps (GstMpegvParse * mpvparse)
 {
   GstCaps *caps = NULL;
+  GstStructure *s = NULL;
 
   /* only update if no src caps yet or explicitly triggered */
   if (G_LIKELY (gst_pad_has_current_caps (GST_BASE_PARSE_SRC_PAD (mpvparse)) &&
@@ -636,6 +637,7 @@ gst_mpegv_parse_update_src_caps (GstMpegvParse * mpvparse)
   caps = gst_pad_get_current_caps (GST_BASE_PARSE_SINK_PAD (mpvparse));
   if (caps) {
     caps = gst_caps_make_writable (caps);
+    s = gst_caps_get_structure (caps, 0);
   } else {
     caps = gst_caps_new_empty_simple ("video/mpeg");
   }
@@ -656,8 +658,9 @@ gst_mpegv_parse_update_src_caps (GstMpegvParse * mpvparse)
         "height", G_TYPE_INT, mpvparse->sequencehdr.height, NULL);
   }
 
-  /* perhaps we have  a framerate */
-  if (mpvparse->fps_num > 0 && mpvparse->fps_den > 0) {
+  /* perhaps we have a framerate */
+  if (mpvparse->fps_num > 0 && mpvparse->fps_den > 0 &&
+      (!s || !gst_structure_has_field (s, "framerate"))) {
     gint fps_num = mpvparse->fps_num;
     gint fps_den = mpvparse->fps_den;
     GstClockTime latency = gst_util_uint64_scale (GST_SECOND, fps_den, fps_num);
@@ -670,7 +673,8 @@ gst_mpegv_parse_update_src_caps (GstMpegvParse * mpvparse)
   }
 
   /* or pixel-aspect-ratio */
-  if (mpvparse->sequencehdr.par_w && mpvparse->sequencehdr.par_h > 0) {
+  if (mpvparse->sequencehdr.par_w && mpvparse->sequencehdr.par_h > 0 &&
+      (!s || !gst_structure_has_field (s, "pixel-aspect-ratio"))) {
     gst_caps_set_simple (caps, "pixel-aspect-ratio", GST_TYPE_FRACTION,
         mpvparse->sequencehdr.par_w, mpvparse->sequencehdr.par_h, NULL);
   }