codecparsers: av1: Add an API to reset the annex_b state only.
authorHe Junyan <junyan.he@intel.com>
Fri, 9 Oct 2020 08:13:28 +0000 (16:13 +0800)
committerVíctor Manuel Jáquez Leal <vjaquez@igalia.com>
Tue, 17 Nov 2020 19:31:09 +0000 (19:31 +0000)
In practice, we encounter streams that have one or more temporal units
error. When that kind of error temporal units is in annex b format, the
whole temporal unit should be discarded.
But the temporal units before it are correct and can be used. More
important, because of the error temporal unit, the parser is in a wrong
state and all later temporal unit are also parsed uncorrectly.
We need to add this API to reset the annex_b state only when we meet
some temporal unit error.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1464>

gst-libs/gst/codecparsers/gstav1parser.c
gst-libs/gst/codecparsers/gstav1parser.h

index e1658df..6e09551 100644 (file)
@@ -568,29 +568,44 @@ gst_av1_parser_reset (GstAV1Parser * parser, gboolean annex_b)
 {
   g_return_if_fail (parser != NULL);
 
-  if (parser->annex_b) {
-    g_assert (parser->temporal_unit_consumed <= parser->temporal_unit_size);
-    if (parser->temporal_unit_consumed < parser->temporal_unit_size)
-      GST_DEBUG ("temporal_unit_consumed: %d, temporal_unit_size:%d, "
-          "discard the left %d bytes for a temporal_unit.",
-          parser->temporal_unit_consumed, parser->temporal_unit_size,
-          parser->temporal_unit_size - parser->temporal_unit_consumed);
-
-    g_assert (parser->frame_unit_consumed <= parser->frame_unit_size);
-    if (parser->frame_unit_consumed < parser->frame_unit_size)
-      GST_DEBUG (" frame_unit_consumed %d, frame_unit_size: %d "
-          "discard the left %d bytes for a frame_unit.",
-          parser->frame_unit_consumed, parser->frame_unit_size,
-          parser->frame_unit_size - parser->frame_unit_consumed);
-  }
+  parser->annex_b = annex_b;
+  if (parser->annex_b)
+    gst_av1_parser_reset_annex_b (parser);
+
+  gst_av1_parse_reset_state (parser, TRUE);
+}
+
+/**
+ * gst_av1_parser_reset_annex_b:
+ * @parser: the #GstAV1Parser
+ *
+ * Only reset the current #GstAV1Parser's annex b context.
+ * The other part of the state is kept.
+ *
+ * Since: 1.20
+ */
+void
+gst_av1_parser_reset_annex_b (GstAV1Parser * parser)
+{
+  g_return_if_fail (parser != NULL);
+  g_return_if_fail (parser->annex_b);
+
+  if (parser->temporal_unit_consumed < parser->temporal_unit_size)
+    GST_DEBUG ("temporal_unit_consumed: %d, temporal_unit_size:%d, "
+        "discard the left %d bytes for a temporal_unit.",
+        parser->temporal_unit_consumed, parser->temporal_unit_size,
+        parser->temporal_unit_size - parser->temporal_unit_consumed);
+
+  if (parser->frame_unit_consumed < parser->frame_unit_size)
+    GST_DEBUG (" frame_unit_consumed %d, frame_unit_size: %d "
+        "discard the left %d bytes for a frame_unit.",
+        parser->frame_unit_consumed, parser->frame_unit_size,
+        parser->frame_unit_size - parser->frame_unit_consumed);
 
   parser->temporal_unit_consumed = 0;
   parser->temporal_unit_size = 0;
   parser->frame_unit_consumed = 0;
   parser->frame_unit_size = 0;
-  parser->annex_b = annex_b;
-
-  gst_av1_parse_reset_state (parser, TRUE);
 }
 
 /* 5.3.2 */
index f8a2d88..afcce6f 100644 (file)
@@ -1777,6 +1777,10 @@ void
 gst_av1_parser_reset (GstAV1Parser * parser, gboolean annex_b);
 
 GST_CODEC_PARSERS_API
+void
+gst_av1_parser_reset_annex_b (GstAV1Parser * parser);
+
+GST_CODEC_PARSERS_API
 GstAV1ParserResult
 gst_av1_parser_identify_one_obu (GstAV1Parser * parser, const guint8 * data,
     guint32 size, GstAV1OBU * obu, guint32 * consumed);