h265parser: Fix short_term_ref_pic_set() size calculation
authorSeungha Yang <seungha@centricular.com>
Fri, 11 Mar 2022 11:46:11 +0000 (20:46 +0900)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 7 Apr 2022 18:46:12 +0000 (18:46 +0000)
This field is used by DXVA/NVDEC/VA, and each specification
describes (NVDEC is not well documented) that it's the number of
bits used in short_term_ref_pic_set().

DXVA doesn't explicitly mention that whether the size of
emulation preventation bytes (EPB) is inclusive or not, but
VA is clearly specifying that it's the size after removing
EPB. Excluding EPB size here makes more sense therefore.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1930>

subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth265parser.c
subprojects/gst-plugins-bad/gst-libs/gst/codecparsers/gsth265parser.h

index 74fc25c..bcc4d84 100644 (file)
@@ -2512,12 +2512,16 @@ gst_h265_parser_parse_slice_hdr (GstH265Parser * parser,
       READ_UINT8 (&nr, slice->short_term_ref_pic_set_sps_flag, 1);
       if (!slice->short_term_ref_pic_set_sps_flag) {
         guint pos = nal_reader_get_pos (&nr);
+        guint epb_pos = nal_reader_get_epb_count (&nr);
+
         if (!gst_h265_parser_parse_short_term_ref_pic_sets
             (&slice->short_term_ref_pic_sets, &nr,
                 sps->num_short_term_ref_pic_sets, sps))
           goto error;
 
-        slice->short_term_ref_pic_set_size = nal_reader_get_pos (&nr) - pos;
+        slice->short_term_ref_pic_set_size =
+            (nal_reader_get_pos (&nr) - pos) -
+            (8 * (nal_reader_get_epb_count (&nr) - epb_pos));
       } else if (sps->num_short_term_ref_pic_sets > 1) {
         const guint n = ceil_log2 (sps->num_short_term_ref_pic_sets);
         READ_UINT8 (&nr, slice->short_term_ref_pic_set_idx, n);
index 0d80c19..ba94ac7 100644 (file)
@@ -1460,7 +1460,8 @@ struct _GstH265SliceHdr
   /* Number of emulation prevention bytes (EPB) in this slice_header() */
   guint n_emulation_prevention_bytes;
 
-  /* Size of short_term_ref_pic_set() in bits */
+  /* Size of short_term_ref_pic_set() after emulation preventation bytes are
+   * removed, in bits */
   guint short_term_ref_pic_set_size;
 };