h26{4,5}parse: expose chroma format and bit depth in caps
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 6 Nov 2017 11:39:32 +0000 (12:39 +0100)
committerNicolas Dufresne <nicolas.dufresne@collabora.com>
Wed, 24 Jan 2018 16:50:54 +0000 (11:50 -0500)
This information could be used for example to pick a decoder supporting
a specific chroma and/or bit depth, like 4:2:2 10 bits.
It can also be used to inform earlier decoder about the format it is
about to decode.

https://bugzilla.gnome.org/show_bug.cgi?id=792039

gst/videoparsers/gsth264parse.c
gst/videoparsers/gsth265parse.c

index 7003caf..f53a559 100644 (file)
@@ -1825,6 +1825,8 @@ gst_h264_parse_update_src_caps (GstH264Parse * h264parse, GstCaps * caps)
       const gchar *caps_mview_mode = NULL;
       GstVideoMultiviewMode mview_mode = h264parse->multiview_mode;
       GstVideoMultiviewFlags mview_flags = h264parse->multiview_flags;
+      const gchar *chroma_format = NULL;
+      guint bit_depth_chroma;
 
       fps_num = h264parse->fps_num;
       fps_den = h264parse->fps_den;
@@ -1900,6 +1902,32 @@ gst_h264_parse_update_src_caps (GstH264Parse * h264parse, GstCaps * caps)
       if (s && !gst_structure_has_field (s, "interlace-mode"))
         gst_caps_set_simple (caps, "interlace-mode", G_TYPE_STRING,
             gst_video_interlace_mode_to_string (imode), NULL);
+
+      bit_depth_chroma = sps->bit_depth_chroma_minus8 + 8;
+
+      switch (sps->chroma_format_idc) {
+        case 0:
+          chroma_format = "4:0:0";
+          bit_depth_chroma = 0;
+          break;
+        case 1:
+          chroma_format = "4:2:0";
+          break;
+        case 2:
+          chroma_format = "4:2:2";
+          break;
+        case 3:
+          chroma_format = "4:4:4";
+          break;
+        default:
+          break;
+      }
+
+      if (chroma_format)
+        gst_caps_set_simple (caps,
+            "chroma-format", G_TYPE_STRING, chroma_format,
+            "bit-depth-luma", G_TYPE_UINT, sps->bit_depth_luma_minus8 + 8,
+            "bit-depth-chroma", G_TYPE_UINT, bit_depth_chroma, NULL);
     }
   }
 
index 7800b15..ba8fbe7 100644 (file)
@@ -1456,6 +1456,8 @@ gst_h265_parse_update_src_caps (GstH265Parse * h265parse, GstCaps * caps)
     caps = gst_caps_copy (sink_caps);
   } else {
     gint crop_width, crop_height;
+    const gchar *chroma_format = NULL;
+    guint bit_depth_chroma;
 
     if (sps->conformance_window_flag) {
       crop_width = sps->crop_rect_width;
@@ -1536,6 +1538,32 @@ gst_h265_parse_update_src_caps (GstH265Parse * h265parse, GstCaps * caps)
         gst_base_parse_set_latency (GST_BASE_PARSE (h265parse), latency,
             latency);
       }
+
+      bit_depth_chroma = sps->bit_depth_chroma_minus8 + 8;
+
+      switch (sps->chroma_format_idc) {
+        case 0:
+          chroma_format = "4:0:0";
+          bit_depth_chroma = 0;
+          break;
+        case 1:
+          chroma_format = "4:2:0";
+          break;
+        case 2:
+          chroma_format = "4:2:2";
+          break;
+        case 3:
+          chroma_format = "4:4:4";
+          break;
+        default:
+          break;
+      }
+
+      if (chroma_format)
+        gst_caps_set_simple (caps, "chroma-format", G_TYPE_STRING,
+            chroma_format, "bit-depth-luma", G_TYPE_UINT,
+            sps->bit_depth_luma_minus8 + 8, "bit-depth-chroma", G_TYPE_UINT,
+            bit_depth_chroma, NULL);
     }
   }