2 * gstvaapidecoder_h265.c - H.265 decoder
4 * Copyright (C) 2015 Intel Corporation
5 * Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301 USA
24 * SECTION:gstvaapidecoder_h265
25 * @short_description: H.265 decoder
30 #include <gst/base/gstadapter.h>
31 #include <gst/codecparsers/gsth265parser.h>
32 #include "gstvaapidecoder_h265.h"
33 #include "gstvaapidecoder_objects.h"
34 #include "gstvaapidecoder_priv.h"
35 #include "gstvaapidisplay_priv.h"
36 #include "gstvaapiobject_priv.h"
37 #include "gstvaapiutils_h265_priv.h"
40 #include "gstvaapidebug.h"
42 /* Defined to 1 if strict ordering of DPB is needed. Only useful for debug */
43 #define USE_STRICT_DPB_ORDERING 0
45 typedef struct _GstVaapiDecoderH265Private GstVaapiDecoderH265Private;
46 typedef struct _GstVaapiDecoderH265Class GstVaapiDecoderH265Class;
47 typedef struct _GstVaapiFrameStore GstVaapiFrameStore;
48 typedef struct _GstVaapiFrameStoreClass GstVaapiFrameStoreClass;
49 typedef struct _GstVaapiParserInfoH265 GstVaapiParserInfoH265;
50 typedef struct _GstVaapiPictureH265 GstVaapiPictureH265;
52 static gboolean nal_is_slice (guint8 nal_type);
54 /* ------------------------------------------------------------------------- */
55 /* --- H.265 Parser Info --- */
56 /* ------------------------------------------------------------------------- */
59 * Extended decoder unit flags:
61 * @GST_VAAPI_DECODER_UNIT_AU_START: marks the start of an access unit.
62 * @GST_VAAPI_DECODER_UNIT_AU_END: marks the end of an access unit.
66 GST_VAAPI_DECODER_UNIT_FLAG_AU_START =
67 (GST_VAAPI_DECODER_UNIT_FLAG_LAST << 0),
68 GST_VAAPI_DECODER_UNIT_FLAG_AU_END = (GST_VAAPI_DECODER_UNIT_FLAG_LAST << 1),
70 GST_VAAPI_DECODER_UNIT_FLAGS_AU = (GST_VAAPI_DECODER_UNIT_FLAG_AU_START |
71 GST_VAAPI_DECODER_UNIT_FLAG_AU_END),
74 #define GST_VAAPI_PARSER_INFO_H265(obj) \
75 ((GstVaapiParserInfoH265 *)(obj))
77 struct _GstVaapiParserInfoH265
79 GstVaapiMiniObject parent_instance;
86 /* Fix SEI parsing in codecparser, have to use GArry like h264parser */
87 GstH265SEIMessage sei;
88 GstH265SliceHdr slice_hdr;
91 guint flags; // Same as decoder unit flags (persistent)
95 gst_vaapi_parser_info_h265_finalize (GstVaapiParserInfoH265 * pi)
97 if (nal_is_slice (pi->nalu.type))
98 gst_h265_slice_hdr_free (&pi->data.slice_hdr);
100 switch (pi->nalu.type) {
101 case GST_H265_NAL_VPS:
102 case GST_H265_NAL_SPS:
103 case GST_H265_NAL_PPS:
105 case GST_H265_NAL_PREFIX_SEI:
106 case GST_H265_NAL_SUFFIX_SEI:
107 gst_h265_sei_free (&pi->data.sei);
113 static inline const GstVaapiMiniObjectClass *
114 gst_vaapi_parser_info_h265_class (void)
116 static const GstVaapiMiniObjectClass GstVaapiParserInfoH265Class = {
117 .size = sizeof (GstVaapiParserInfoH265),
118 .finalize = (GDestroyNotify) gst_vaapi_parser_info_h265_finalize
120 return &GstVaapiParserInfoH265Class;
123 static inline GstVaapiParserInfoH265 *
124 gst_vaapi_parser_info_h265_new (void)
126 return (GstVaapiParserInfoH265 *)
127 gst_vaapi_mini_object_new (gst_vaapi_parser_info_h265_class ());
130 #define gst_vaapi_parser_info_h265_ref(pi) \
131 gst_vaapi_mini_object_ref(GST_VAAPI_MINI_OBJECT(pi))
133 #define gst_vaapi_parser_info_h265_unref(pi) \
134 gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(pi))
136 #define gst_vaapi_parser_info_h265_replace(old_pi_ptr, new_pi) \
137 gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_pi_ptr), \
138 (GstVaapiMiniObject *)(new_pi))
140 /* ------------------------------------------------------------------------- */
141 /* --- H.265 Pictures --- */
142 /* ------------------------------------------------------------------------- */
145 * Extended picture flags:
147 * @GST_VAAPI_PICTURE_FLAG_IDR: flag that specifies an IDR picture
148 * @GST_VAAPI_PICTURE_FLAG_AU_START: flag that marks the start of an
150 * @GST_VAAPI_PICTURE_FLAG_AU_END: flag that marks the end of an
152 * @GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_BEFORE: flag indicate the inclusion
153 * of picture in RefPicSetStCurrBefore reference list
154 * @GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_AFTER: flag indicate the inclusion
155 * of picture in RefPictSetStCurrAfter reference list
156 * @GST_VAAPI_PICTURE_FLAG_RPS_ST_FOLL: flag indicate the inclusion
157 * of picture in RefPicSetStFoll reference list
158 * @GST_VAAPI_PICTURE_FLAG_RPS_LT_CURR: flag indicate the inclusion
159 * of picture in RefPicSetLtCurr reference list
160 * @GST_VAAPI_PICTURE_FLAG_RPS_LT_FOLL: flag indicate the inclusion
161 * of picture in RefPicSetLtFoll reference list
162 * @GST_VAAPI_PICTURE_FLAG_SHORT_TERM_REFERENCE: flag that specifies
163 * "used for short-term reference"
164 * @GST_VAAPI_PICTURE_FLAG_LONG_TERM_REFERENCE: flag that specifies
165 * "used for long-term reference"
166 * @GST_VAAPI_PICTURE_FLAGS_REFERENCE: mask covering any kind of
167 * reference picture (short-term reference or long-term reference)
171 GST_VAAPI_PICTURE_FLAG_IDR = (GST_VAAPI_PICTURE_FLAG_LAST << 0),
172 GST_VAAPI_PICTURE_FLAG_REFERENCE2 = (GST_VAAPI_PICTURE_FLAG_LAST << 1),
173 GST_VAAPI_PICTURE_FLAG_AU_START = (GST_VAAPI_PICTURE_FLAG_LAST << 4),
174 GST_VAAPI_PICTURE_FLAG_AU_END = (GST_VAAPI_PICTURE_FLAG_LAST << 5),
175 GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_BEFORE =
176 (GST_VAAPI_PICTURE_FLAG_LAST << 6),
177 GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_AFTER = (GST_VAAPI_PICTURE_FLAG_LAST << 7),
178 GST_VAAPI_PICTURE_FLAG_RPS_ST_FOLL = (GST_VAAPI_PICTURE_FLAG_LAST << 8),
179 GST_VAAPI_PICTURE_FLAG_RPS_LT_CURR = (GST_VAAPI_PICTURE_FLAG_LAST << 9),
180 GST_VAAPI_PICTURE_FLAG_RPS_LT_FOLL = (GST_VAAPI_PICTURE_FLAG_LAST << 10),
182 GST_VAAPI_PICTURE_FLAG_SHORT_TERM_REFERENCE =
183 (GST_VAAPI_PICTURE_FLAG_REFERENCE),
184 GST_VAAPI_PICTURE_FLAG_LONG_TERM_REFERENCE =
185 (GST_VAAPI_PICTURE_FLAG_REFERENCE | GST_VAAPI_PICTURE_FLAG_REFERENCE2),
186 GST_VAAPI_PICTURE_FLAGS_REFERENCE =
187 (GST_VAAPI_PICTURE_FLAG_SHORT_TERM_REFERENCE |
188 GST_VAAPI_PICTURE_FLAG_LONG_TERM_REFERENCE),
190 GST_VAAPI_PICTURE_FLAGS_RPS_ST =
191 (GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_BEFORE |
192 GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_AFTER |
193 GST_VAAPI_PICTURE_FLAG_RPS_ST_FOLL),
194 GST_VAAPI_PICTURE_FLAGS_RPS_LT =
195 (GST_VAAPI_PICTURE_FLAG_RPS_LT_CURR | GST_VAAPI_PICTURE_FLAG_RPS_LT_FOLL),
198 #define GST_VAAPI_PICTURE_IS_IDR(picture) \
199 (GST_VAAPI_PICTURE_FLAG_IS_SET(picture, GST_VAAPI_PICTURE_FLAG_IDR))
201 #define GST_VAAPI_PICTURE_IS_SHORT_TERM_REFERENCE(picture) \
202 ((GST_VAAPI_PICTURE_FLAGS(picture) & \
203 GST_VAAPI_PICTURE_FLAGS_REFERENCE) == \
204 GST_VAAPI_PICTURE_FLAG_SHORT_TERM_REFERENCE)
206 #define GST_VAAPI_PICTURE_IS_LONG_TERM_REFERENCE(picture) \
207 ((GST_VAAPI_PICTURE_FLAGS(picture) & \
208 GST_VAAPI_PICTURE_FLAGS_REFERENCE) == \
209 GST_VAAPI_PICTURE_FLAG_LONG_TERM_REFERENCE)
211 #define GST_VAAPI_PICTURE_H265(picture) \
212 ((GstVaapiPictureH265 *)(picture))
214 struct _GstVaapiPictureH265
216 GstVaapiPicture base;
217 GstH265SliceHdr *last_slice_hdr;
219 gint32 poc; // PicOrderCntVal (8.3.1)
220 gint32 poc_lsb; // slice_pic_order_cnt_lsb
221 guint32 pic_latency_cnt; // PicLatencyCount
223 guint output_needed:1;
224 guint NoRaslOutputFlag:1;
225 guint NoOutputOfPriorPicsFlag:1;
226 guint RapPicFlag:1; // nalu type between 16 and 21
227 guint IntraPicFlag:1; // Intra pic (only Intra slices)
230 GST_VAAPI_CODEC_DEFINE_TYPE (GstVaapiPictureH265, gst_vaapi_picture_h265);
233 gst_vaapi_picture_h265_destroy (GstVaapiPictureH265 * picture)
235 gst_vaapi_picture_destroy (GST_VAAPI_PICTURE (picture));
239 gst_vaapi_picture_h265_create (GstVaapiPictureH265 * picture,
240 const GstVaapiCodecObjectConstructorArgs * args)
242 if (!gst_vaapi_picture_create (GST_VAAPI_PICTURE (picture), args))
245 picture->poc = G_MAXINT32;
246 picture->output_needed = FALSE;
250 static inline GstVaapiPictureH265 *
251 gst_vaapi_picture_h265_new (GstVaapiDecoderH265 * decoder)
253 return (GstVaapiPictureH265 *)
254 gst_vaapi_codec_object_new (&GstVaapiPictureH265Class,
255 GST_VAAPI_CODEC_BASE (decoder), NULL,
256 sizeof (VAPictureParameterBufferHEVC), NULL, 0, 0);
260 gst_vaapi_picture_h265_set_reference (GstVaapiPictureH265 * picture,
261 guint reference_flags)
265 GST_VAAPI_PICTURE_FLAG_UNSET (picture,
266 GST_VAAPI_PICTURE_FLAGS_RPS_ST | GST_VAAPI_PICTURE_FLAGS_RPS_LT);
267 GST_VAAPI_PICTURE_FLAG_UNSET (picture, GST_VAAPI_PICTURE_FLAGS_REFERENCE);
268 GST_VAAPI_PICTURE_FLAG_SET (picture, reference_flags);
271 /* ------------------------------------------------------------------------- */
272 /* --- Frame Buffers (DPB) --- */
273 /* ------------------------------------------------------------------------- */
275 struct _GstVaapiFrameStore
278 GstVaapiMiniObject parent_instance;
280 GstVaapiPictureH265 *buffer;
284 gst_vaapi_frame_store_finalize (gpointer object)
286 GstVaapiFrameStore *const fs = object;
288 gst_vaapi_picture_replace (&fs->buffer, NULL);
291 static GstVaapiFrameStore *
292 gst_vaapi_frame_store_new (GstVaapiPictureH265 * picture)
294 GstVaapiFrameStore *fs;
296 static const GstVaapiMiniObjectClass GstVaapiFrameStoreClass = {
297 sizeof (GstVaapiFrameStore),
298 gst_vaapi_frame_store_finalize
301 fs = (GstVaapiFrameStore *)
302 gst_vaapi_mini_object_new (&GstVaapiFrameStoreClass);
306 fs->buffer = gst_vaapi_picture_ref (picture);
311 static inline gboolean
312 gst_vaapi_frame_store_has_reference (GstVaapiFrameStore * fs)
314 if (GST_VAAPI_PICTURE_IS_REFERENCE (fs->buffer))
319 #define gst_vaapi_frame_store_ref(fs) \
320 gst_vaapi_mini_object_ref(GST_VAAPI_MINI_OBJECT(fs))
322 #define gst_vaapi_frame_store_unref(fs) \
323 gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(fs))
325 #define gst_vaapi_frame_store_replace(old_fs_p, new_fs) \
326 gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_fs_p), \
327 (GstVaapiMiniObject *)(new_fs))
329 /* ------------------------------------------------------------------------- */
330 /* --- H.265 Decoder --- */
331 /* ------------------------------------------------------------------------- */
333 #define GST_VAAPI_DECODER_H265_CAST(decoder) \
334 ((GstVaapiDecoderH265 *)(decoder))
338 GST_H265_VIDEO_STATE_GOT_VPS = 1 << 0,
339 GST_H265_VIDEO_STATE_GOT_SPS = 1 << 1,
340 GST_H265_VIDEO_STATE_GOT_PPS = 1 << 2,
341 GST_H265_VIDEO_STATE_GOT_SLICE = 1 << 3,
343 GST_H265_VIDEO_STATE_VALID_PICTURE_HEADERS =
344 (GST_H265_VIDEO_STATE_GOT_SPS | GST_H265_VIDEO_STATE_GOT_PPS),
345 GST_H265_VIDEO_STATE_VALID_PICTURE =
346 (GST_H265_VIDEO_STATE_VALID_PICTURE_HEADERS |
347 GST_H265_VIDEO_STATE_GOT_SLICE)
350 struct _GstVaapiDecoderH265Private
352 GstH265Parser *parser;
355 GstVaapiStreamAlignH265 stream_alignment;
356 GstVaapiPictureH265 *current_picture;
357 GstVaapiParserInfoH265 *vps[GST_H265_MAX_VPS_COUNT];
358 GstVaapiParserInfoH265 *active_vps;
359 GstVaapiParserInfoH265 *sps[GST_H265_MAX_SPS_COUNT];
360 GstVaapiParserInfoH265 *active_sps;
361 GstVaapiParserInfoH265 *pps[GST_H265_MAX_PPS_COUNT];
362 GstVaapiParserInfoH265 *active_pps;
363 GstVaapiParserInfoH265 *prev_pi;
364 GstVaapiParserInfoH265 *prev_slice_pi;
365 GstVaapiParserInfoH265 *prev_independent_slice_pi;
366 GstVaapiFrameStore **dpb;
370 GstVaapiProfile profile;
371 GstVaapiEntrypoint entrypoint;
372 GstVaapiChromaType chroma_type;
374 GstVaapiPictureH265 *RefPicSetStCurrBefore[16];
375 GstVaapiPictureH265 *RefPicSetStCurrAfter[16];
376 GstVaapiPictureH265 *RefPicSetStFoll[16];
377 GstVaapiPictureH265 *RefPicSetLtCurr[16];
378 GstVaapiPictureH265 *RefPicSetLtFoll[16];
380 GstVaapiPictureH265 *RefPicList0[16];
381 guint RefPicList0_count;
382 GstVaapiPictureH265 *RefPicList1[16];
383 guint RefPicList1_count;
385 guint32 SpsMaxLatencyPictures;
387 guint nal_length_size;
389 guint pic_width_in_luma_samples; //sps->pic_width_in_luma_samples
390 guint pic_height_in_luma_samples; //sps->pic_height_in_luma_samples
391 guint pic_structure; // pic_struct (from SEI pic_timing() or inferred)
392 gint32 poc; // PicOrderCntVal
393 gint32 poc_msb; // PicOrderCntMsb
394 gint32 poc_lsb; // pic_order_cnt_lsb (from slice_header())
395 gint32 prev_poc_msb; // prevPicOrderCntMsb
396 gint32 prev_poc_lsb; // prevPicOrderCntLsb
397 gint32 prev_tid0pic_poc_lsb;
398 gint32 prev_tid0pic_poc_msb;
399 gint32 PocStCurrBefore[16];
400 gint32 PocStCurrAfter[16];
401 gint32 PocStFoll[16];
402 gint32 PocLtCurr[16];
403 gint32 PocLtFoll[16];
404 guint NumPocStCurrBefore;
405 guint NumPocStCurrAfter;
409 guint NumPocTotalCurr;
413 guint progressive_sequence:1;
417 * GstVaapiDecoderH265:
419 * A decoder based on H265.
421 struct _GstVaapiDecoderH265
424 GstVaapiDecoder parent_instance;
425 GstVaapiDecoderH265Private priv;
429 * GstVaapiDecoderH265Class:
431 * A decoder class based on H265.
433 struct _GstVaapiDecoderH265Class
436 GstVaapiDecoderClass parent_class;
439 #define RSV_VCL_N10 10
440 #define RSV_VCL_N12 12
441 #define RSV_VCL_N14 14
444 nal_is_idr (guint8 nal_type)
446 if ((nal_type == GST_H265_NAL_SLICE_IDR_W_RADL) ||
447 (nal_type == GST_H265_NAL_SLICE_IDR_N_LP))
453 nal_is_irap (guint8 nal_type)
455 if ((nal_type >= GST_H265_NAL_SLICE_BLA_W_LP) &&
456 (nal_type <= RESERVED_IRAP_NAL_TYPE_MAX))
462 nal_is_bla (guint8 nal_type)
464 if ((nal_type >= GST_H265_NAL_SLICE_BLA_W_LP) &&
465 (nal_type <= GST_H265_NAL_SLICE_BLA_N_LP))
471 nal_is_radl (guint8 nal_type)
473 if ((nal_type >= GST_H265_NAL_SLICE_RADL_N) &&
474 (nal_type <= GST_H265_NAL_SLICE_RADL_R))
480 nal_is_rasl (guint8 nal_type)
482 if ((nal_type >= GST_H265_NAL_SLICE_RASL_N) &&
483 (nal_type <= GST_H265_NAL_SLICE_RASL_R))
489 nal_is_slice (guint8 nal_type)
491 if ((nal_type >= GST_H265_NAL_SLICE_TRAIL_N) &&
492 (nal_type <= GST_H265_NAL_SLICE_CRA_NUT))
498 nal_is_ref (guint8 nal_type)
500 gboolean ret = FALSE;
502 case GST_H265_NAL_SLICE_TRAIL_N:
503 case GST_H265_NAL_SLICE_TSA_N:
504 case GST_H265_NAL_SLICE_STSA_N:
505 case GST_H265_NAL_SLICE_RADL_N:
506 case GST_H265_NAL_SLICE_RASL_N:
519 /* Activates the supplied PPS */
521 ensure_pps (GstVaapiDecoderH265 * decoder, GstH265PPS * pps)
523 GstVaapiDecoderH265Private *const priv = &decoder->priv;
524 GstVaapiParserInfoH265 *const pi = priv->pps[pps->id];
525 gst_vaapi_parser_info_h265_replace (&priv->active_pps, pi);
526 return pi ? &pi->data.pps : NULL;
529 /* Returns the active PPS */
530 static inline GstH265PPS *
531 get_pps (GstVaapiDecoderH265 * decoder)
533 GstVaapiParserInfoH265 *const pi = decoder->priv.active_pps;
534 return pi ? &pi->data.pps : NULL;
537 /* Activate the supplied SPS */
539 ensure_sps (GstVaapiDecoderH265 * decoder, GstH265SPS * sps)
541 GstVaapiDecoderH265Private *const priv = &decoder->priv;
542 GstVaapiParserInfoH265 *const pi = priv->sps[sps->id];
543 gst_vaapi_parser_info_h265_replace (&priv->active_sps, pi);
544 return pi ? &pi->data.sps : NULL;
547 /* Returns the active SPS */
548 static inline GstH265SPS *
549 get_sps (GstVaapiDecoderH265 * decoder)
551 GstVaapiParserInfoH265 *const pi = decoder->priv.active_sps;
552 return pi ? &pi->data.sps : NULL;
555 /* Activate the supplied VPS */
557 ensure_vps (GstVaapiDecoderH265 * decoder, GstH265VPS * vps)
559 GstVaapiDecoderH265Private *const priv = &decoder->priv;
560 GstVaapiParserInfoH265 *const pi = priv->vps[vps->id];
561 gst_vaapi_parser_info_h265_replace (&priv->active_vps, pi);
562 return pi ? &pi->data.vps : NULL;
565 /* Returns the active VPS */
566 static inline GstH265VPS *
567 get_vps (GstVaapiDecoderH265 * decoder)
569 GstVaapiParserInfoH265 *const pi = decoder->priv.active_vps;
570 return pi ? &pi->data.vps : NULL;
573 /* Get number of reference frames to use */
575 get_max_dec_frame_buffering (GstH265SPS * sps)
577 guint max_dec_frame_buffering;
578 GstVaapiLevelH265 level;
579 const GstVaapiH265LevelLimits *level_limits;
580 level = gst_vaapi_utils_h265_get_level (sps->profile_tier_level.level_idc);
581 level_limits = gst_vaapi_utils_h265_get_level_limits (level);
582 if (G_UNLIKELY (!level_limits)) {
583 GST_FIXME ("unsupported level_idc value (%d)",
584 sps->profile_tier_level.level_idc);
585 max_dec_frame_buffering = 16;
587 /* Fixme: Add limit check based on Annex A */
588 return MAX (1, (sps->max_dec_pic_buffering_minus1[0] + 1));
592 dpb_remove_index (GstVaapiDecoderH265 * decoder, gint index)
594 GstVaapiDecoderH265Private *const priv = &decoder->priv;
595 guint i, num_frames = --priv->dpb_count;
596 if (USE_STRICT_DPB_ORDERING) {
597 for (i = index; i < num_frames; i++)
598 gst_vaapi_frame_store_replace (&priv->dpb[i], priv->dpb[i + 1]);
599 } else if (index != num_frames)
600 gst_vaapi_frame_store_replace (&priv->dpb[index], priv->dpb[num_frames]);
601 gst_vaapi_frame_store_replace (&priv->dpb[num_frames], NULL);
605 dpb_output (GstVaapiDecoderH265 * decoder, GstVaapiFrameStore * fs)
607 GstVaapiPictureH265 *picture;
608 g_return_val_if_fail (fs != NULL, FALSE);
610 picture = fs->buffer;
611 g_return_val_if_fail (picture != NULL, FALSE);
613 picture->output_needed = FALSE;
614 return gst_vaapi_picture_output (GST_VAAPI_PICTURE_CAST (picture));
617 /* Get the dpb picture having the specifed poc or poc_lsb */
618 static GstVaapiPictureH265 *
619 dpb_get_picture (GstVaapiDecoderH265 * decoder, gint poc, gboolean match_lsb)
621 GstVaapiDecoderH265Private *const priv = &decoder->priv;
622 GstVaapiPictureH265 *picture = NULL;
625 for (i = 0; i < priv->dpb_count; i++) {
626 GstVaapiFrameStore *const fs = priv->dpb[i];
627 picture = fs->buffer;
629 if (picture && GST_VAAPI_PICTURE_FLAG_IS_SET (picture,
630 GST_VAAPI_PICTURE_FLAGS_REFERENCE)) {
632 if (picture->poc_lsb == poc)
635 if (picture->poc == poc)
643 /* Get the dpb picture having the specifed poc and shor/long ref flags */
644 static GstVaapiPictureH265 *
645 dpb_get_ref_picture (GstVaapiDecoderH265 * decoder, gint poc, gboolean is_short)
647 GstVaapiDecoderH265Private *const priv = &decoder->priv;
648 GstVaapiPictureH265 *picture = NULL;
651 for (i = 0; i < priv->dpb_count; i++) {
652 GstVaapiFrameStore *const fs = priv->dpb[i];
653 picture = fs->buffer;
655 if (picture && picture->poc == poc) {
656 if (is_short && GST_VAAPI_PICTURE_IS_SHORT_TERM_REFERENCE (picture))
659 else if (GST_VAAPI_PICTURE_IS_LONG_TERM_REFERENCE (picture))
667 /* Finds the picture with the lowest POC that needs to be output */
669 dpb_find_lowest_poc (GstVaapiDecoderH265 * decoder,
670 GstVaapiPictureH265 ** found_picture_ptr)
672 GstVaapiDecoderH265Private *const priv = &decoder->priv;
673 GstVaapiPictureH265 *found_picture = NULL;
674 GstVaapiPictureH265 *tmp_picture = NULL;
675 guint i, found_index;
677 for (i = 0; i < priv->dpb_count; i++) {
678 GstVaapiFrameStore *const fs = priv->dpb[i];
679 tmp_picture = fs->buffer;
680 if (tmp_picture && !tmp_picture->output_needed)
682 if (!found_picture) {
683 found_picture = tmp_picture;
686 if (found_picture->poc > tmp_picture->poc) {
687 found_picture = tmp_picture;
692 if (found_picture_ptr)
693 *found_picture_ptr = found_picture;
694 return found_picture ? found_index : -1;
698 dpb_bump (GstVaapiDecoderH265 * decoder, GstVaapiPictureH265 * picture)
700 GstVaapiDecoderH265Private *const priv = &decoder->priv;
701 GstVaapiPictureH265 *found_picture;
705 found_index = dpb_find_lowest_poc (decoder, &found_picture);
709 success = dpb_output (decoder, priv->dpb[found_index]);
711 if (!gst_vaapi_frame_store_has_reference (priv->dpb[found_index]))
712 dpb_remove_index (decoder, found_index);
718 dpb_clear (GstVaapiDecoderH265 * decoder, gboolean hard_flush)
720 GstVaapiDecoderH265Private *const priv = &decoder->priv;
721 GstVaapiPictureH265 *pic;
725 for (i = 0; i < priv->dpb_count; i++)
726 dpb_remove_index (decoder, i);
729 /* Remove unused pictures from DPB */
731 while (i < priv->dpb_count) {
732 GstVaapiFrameStore *const fs = priv->dpb[i];
734 if (!pic->output_needed && !gst_vaapi_frame_store_has_reference (fs))
735 dpb_remove_index (decoder, i);
743 dpb_flush (GstVaapiDecoderH265 * decoder)
745 /* Output any frame remaining in DPB */
746 while (dpb_bump (decoder, NULL));
747 dpb_clear (decoder, TRUE);
751 dpb_get_num_need_output (GstVaapiDecoderH265 * decoder)
753 GstVaapiDecoderH265Private *const priv = &decoder->priv;
754 guint i = 0, n_output_needed = 0;
756 while (i < priv->dpb_count) {
757 GstVaapiFrameStore *const fs = priv->dpb[i];
758 if (fs->buffer->output_needed)
763 return n_output_needed;
767 check_latency_cnt (GstVaapiDecoderH265 * decoder)
769 GstVaapiPictureH265 *tmp_pic;
771 GstVaapiDecoderH265Private *const priv = &decoder->priv;
773 while (i < priv->dpb_count) {
774 GstVaapiFrameStore *const fs = priv->dpb[i];
775 tmp_pic = fs->buffer;
776 if (tmp_pic->output_needed) {
777 if (tmp_pic->pic_latency_cnt >= priv->SpsMaxLatencyPictures)
787 dpb_add (GstVaapiDecoderH265 * decoder, GstVaapiPictureH265 * picture)
789 GstVaapiFrameStore *fs;
790 GstVaapiPictureH265 *tmp_pic;
792 GstVaapiDecoderH265Private *const priv = &decoder->priv;
793 GstH265SPS *const sps = get_sps (decoder);
796 while (i < priv->dpb_count) {
797 GstVaapiFrameStore *const fs = priv->dpb[i];
798 tmp_pic = fs->buffer;
799 if (tmp_pic->output_needed)
800 tmp_pic->pic_latency_cnt += 1;
804 if (picture->output_flag) {
805 picture->output_needed = 1;
806 picture->pic_latency_cnt = 0;
808 picture->output_needed = 0;
810 /* set pic as short_term_ref */
811 gst_vaapi_picture_h265_set_reference (picture,
812 GST_VAAPI_PICTURE_FLAG_SHORT_TERM_REFERENCE);
814 /* C.5.2.4 "Bumping" process */
815 while ((dpb_get_num_need_output (decoder) >
816 sps->max_num_reorder_pics[sps->max_sub_layers_minus1])
817 || (sps->max_latency_increase_plus1[sps->max_sub_layers_minus1]
818 && check_latency_cnt (decoder)))
819 dpb_bump (decoder, picture);
821 /* Create new frame store */
822 fs = gst_vaapi_frame_store_new (picture);
825 gst_vaapi_frame_store_replace (&priv->dpb[priv->dpb_count++], fs);
826 gst_vaapi_frame_store_unref (fs);
833 dpb_init (GstVaapiDecoderH265 * decoder, GstVaapiPictureH265 * picture,
834 GstVaapiParserInfoH265 * pi)
836 GstVaapiDecoderH265Private *const priv = &decoder->priv;
837 GstH265SPS *const sps = get_sps (decoder);
839 /* Fixme: Not required?? */
840 if (nal_is_idr (pi->nalu.type))
841 while (dpb_bump (decoder, picture));
844 if (picture->IntraPicFlag &&
845 picture->NoRaslOutputFlag /*&& Fixme: Not picture0 */ ) {
846 if (picture->NoOutputOfPriorPicsFlag)
847 dpb_clear (decoder, TRUE);
849 dpb_clear (decoder, FALSE);
851 dpb_clear (decoder, FALSE);
852 while ((dpb_get_num_need_output (decoder) >
853 sps->max_num_reorder_pics[sps->max_sub_layers_minus1])
854 || (sps->max_latency_increase_plus1[sps->max_sub_layers_minus1]
855 && check_latency_cnt (decoder))
856 || (priv->dpb_count >=
857 (sps->max_dec_pic_buffering_minus1[sps->max_sub_layers_minus1] +
859 dpb_bump (decoder, picture);
867 dpb_reset (GstVaapiDecoderH265 * decoder, guint dpb_size)
869 GstVaapiDecoderH265Private *const priv = &decoder->priv;
870 if (dpb_size > priv->dpb_size_max) {
871 priv->dpb = g_try_realloc_n (priv->dpb, dpb_size, sizeof (*priv->dpb));
874 memset (&priv->dpb[priv->dpb_size_max], 0,
875 (dpb_size - priv->dpb_size_max) * sizeof (*priv->dpb));
876 priv->dpb_size_max = dpb_size;
878 priv->dpb_size = dpb_size;
879 GST_DEBUG ("DPB size %u", priv->dpb_size);
883 static GstVaapiDecoderStatus
884 get_status (GstH265ParserResult result)
886 GstVaapiDecoderStatus status;
888 case GST_H265_PARSER_OK:
889 status = GST_VAAPI_DECODER_STATUS_SUCCESS;
891 case GST_H265_PARSER_NO_NAL_END:
892 status = GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
894 case GST_H265_PARSER_ERROR:
895 status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
898 status = GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
905 gst_vaapi_decoder_h265_close (GstVaapiDecoderH265 * decoder)
907 GstVaapiDecoderH265Private *const priv = &decoder->priv;
908 gst_vaapi_picture_replace (&priv->current_picture, NULL);
909 gst_vaapi_parser_info_h265_replace (&priv->prev_slice_pi, NULL);
910 gst_vaapi_parser_info_h265_replace (&priv->prev_independent_slice_pi, NULL);
911 gst_vaapi_parser_info_h265_replace (&priv->prev_pi, NULL);
913 dpb_clear (decoder, TRUE);
916 gst_h265_parser_free (priv->parser);
922 gst_vaapi_decoder_h265_open (GstVaapiDecoderH265 * decoder)
924 GstVaapiDecoderH265Private *const priv = &decoder->priv;
925 gst_vaapi_decoder_h265_close (decoder);
926 priv->parser = gst_h265_parser_new ();
933 gst_vaapi_decoder_h265_destroy (GstVaapiDecoder * base_decoder)
935 GstVaapiDecoderH265 *const decoder =
936 GST_VAAPI_DECODER_H265_CAST (base_decoder);
937 GstVaapiDecoderH265Private *const priv = &decoder->priv;
939 gst_vaapi_decoder_h265_close (decoder);
943 for (i = 0; i < G_N_ELEMENTS (priv->pps); i++)
944 gst_vaapi_parser_info_h265_replace (&priv->pps[i], NULL);
945 gst_vaapi_parser_info_h265_replace (&priv->active_pps, NULL);
946 for (i = 0; i < G_N_ELEMENTS (priv->sps); i++)
947 gst_vaapi_parser_info_h265_replace (&priv->sps[i], NULL);
948 gst_vaapi_parser_info_h265_replace (&priv->active_sps, NULL);
949 for (i = 0; i < G_N_ELEMENTS (priv->vps); i++)
950 gst_vaapi_parser_info_h265_replace (&priv->vps[i], NULL);
951 gst_vaapi_parser_info_h265_replace (&priv->active_vps, NULL);
955 gst_vaapi_decoder_h265_create (GstVaapiDecoder * base_decoder)
957 GstVaapiDecoderH265 *const decoder =
958 GST_VAAPI_DECODER_H265_CAST (base_decoder);
959 GstVaapiDecoderH265Private *const priv = &decoder->priv;
960 priv->profile = GST_VAAPI_PROFILE_UNKNOWN;
961 priv->entrypoint = GST_VAAPI_ENTRYPOINT_VLD;
962 priv->chroma_type = GST_VAAPI_CHROMA_TYPE_YUV420;
963 priv->progressive_sequence = TRUE;
969 fill_profiles (GstVaapiProfile profiles[16], guint * n_profiles_ptr,
970 GstVaapiProfile profile)
972 guint n_profiles = *n_profiles_ptr;
973 profiles[n_profiles++] = profile;
975 case GST_VAAPI_PROFILE_H265_MAIN:
976 profiles[n_profiles++] = GST_VAAPI_PROFILE_H265_MAIN10;
978 case GST_VAAPI_PROFILE_H265_MAIN_STILL_PICTURE:
979 profiles[n_profiles++] = GST_VAAPI_PROFILE_H265_MAIN;
980 profiles[n_profiles++] = GST_VAAPI_PROFILE_H265_MAIN10;
985 *n_profiles_ptr = n_profiles;
988 static GstVaapiProfile
989 get_profile (GstVaapiDecoderH265 * decoder, GstH265SPS * sps, guint dpb_size)
991 GstVaapiDecoderH265Private *const priv = &decoder->priv;
992 GstVaapiDisplay *const display = GST_VAAPI_DECODER_DISPLAY (decoder);
993 GstVaapiProfile profile, profiles[3];
994 guint i, n_profiles = 0;
996 gst_vaapi_utils_h265_get_profile (sps->profile_tier_level.profile_idc);
998 return GST_VAAPI_PROFILE_UNKNOWN;
999 fill_profiles (profiles, &n_profiles, profile);
1001 case GST_VAAPI_PROFILE_H265_MAIN10:
1002 if (sps->profile_tier_level.profile_compatibility_flag[1]) { // A.2.3.2 (main profile)
1003 fill_profiles (profiles, &n_profiles, GST_VAAPI_PROFILE_H265_MAIN);
1010 /* If the preferred profile (profiles[0]) matches one that we already
1011 found, then just return it now instead of searching for it again */
1012 if (profiles[0] == priv->profile)
1013 return priv->profile;
1014 for (i = 0; i < n_profiles; i++) {
1015 if (gst_vaapi_display_has_decoder (display, profiles[i], priv->entrypoint))
1018 return GST_VAAPI_PROFILE_UNKNOWN;
1021 static GstVaapiDecoderStatus
1022 ensure_context (GstVaapiDecoderH265 * decoder, GstH265SPS * sps)
1024 GstVaapiDecoder *const base_decoder = GST_VAAPI_DECODER_CAST (decoder);
1025 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1026 GstVaapiContextInfo info;
1027 GstVaapiProfile profile;
1028 GstVaapiChromaType chroma_type;
1029 gboolean reset_context = FALSE;
1032 dpb_size = get_max_dec_frame_buffering (sps);
1033 if (priv->dpb_size < dpb_size) {
1034 GST_DEBUG ("DPB size increased");
1035 reset_context = TRUE;
1038 profile = get_profile (decoder, sps, dpb_size);
1040 GST_ERROR ("unsupported profile_idc %u",
1041 sps->profile_tier_level.profile_idc);
1042 return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_PROFILE;
1045 if (!priv->profile || (priv->profile != profile)) {
1046 GST_DEBUG ("profile changed");
1047 reset_context = TRUE;
1048 priv->profile = profile;
1051 chroma_type = gst_vaapi_utils_h265_get_chroma_type (sps->chroma_format_idc);
1053 GST_ERROR ("unsupported chroma_format_idc %u", sps->chroma_format_idc);
1054 return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_CHROMA_FORMAT;
1057 if (priv->chroma_type != chroma_type) {
1058 GST_DEBUG ("chroma format changed");
1059 reset_context = TRUE;
1060 priv->chroma_type = chroma_type;
1063 if (priv->pic_width_in_luma_samples != sps->pic_width_in_luma_samples ||
1064 priv->pic_height_in_luma_samples != sps->pic_height_in_luma_samples) {
1065 GST_DEBUG ("size changed");
1066 reset_context = TRUE;
1067 priv->pic_width_in_luma_samples = sps->pic_width_in_luma_samples;
1068 priv->pic_height_in_luma_samples = sps->pic_height_in_luma_samples;
1071 priv->progressive_sequence = 1; /*Fixme */
1072 gst_vaapi_decoder_set_interlaced (base_decoder, !priv->progressive_sequence);
1073 gst_vaapi_decoder_set_pixel_aspect_ratio (base_decoder,
1074 sps->vui_params.par_n, sps->vui_params.par_d);
1075 if (!reset_context && priv->has_context)
1076 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1078 /* XXX: fix surface size when cropping is implemented */
1079 info.profile = priv->profile;
1080 info.entrypoint = priv->entrypoint;
1081 info.chroma_type = priv->chroma_type;
1082 info.width = sps->width;
1083 info.height = sps->height;
1084 info.ref_frames = dpb_size;
1086 if (!gst_vaapi_decoder_ensure_context (GST_VAAPI_DECODER (decoder), &info))
1087 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
1088 priv->has_context = TRUE;
1091 if (!dpb_reset (decoder, dpb_size))
1092 return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
1094 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1098 fill_iq_matrix_4x4 (VAIQMatrixBufferHEVC * iq_matrix,
1099 GstH265ScalingList * scaling_list)
1102 g_assert (G_N_ELEMENTS (iq_matrix->ScalingList4x4) == 6);
1103 g_assert (G_N_ELEMENTS (iq_matrix->ScalingList4x4[0]) == 16);
1104 for (i = 0; i < G_N_ELEMENTS (iq_matrix->ScalingList4x4); i++) {
1105 gst_h265_quant_matrix_4x4_get_raster_from_zigzag (iq_matrix->ScalingList4x4
1106 [i], scaling_list->scaling_lists_4x4[i]);
1111 fill_iq_matrix_8x8 (VAIQMatrixBufferHEVC * iq_matrix,
1112 GstH265ScalingList * scaling_list)
1115 g_assert (G_N_ELEMENTS (iq_matrix->ScalingList8x8) == 6);
1116 g_assert (G_N_ELEMENTS (iq_matrix->ScalingList8x8[0]) == 64);
1117 for (i = 0; i < G_N_ELEMENTS (iq_matrix->ScalingList8x8); i++) {
1118 gst_h265_quant_matrix_8x8_get_raster_from_zigzag (iq_matrix->ScalingList8x8
1119 [i], scaling_list->scaling_lists_8x8[i]);
1124 fill_iq_matrix_16x16 (VAIQMatrixBufferHEVC * iq_matrix,
1125 GstH265ScalingList * scaling_list)
1128 g_assert (G_N_ELEMENTS (iq_matrix->ScalingList16x16) == 6);
1129 g_assert (G_N_ELEMENTS (iq_matrix->ScalingList16x16[0]) == 64);
1130 for (i = 0; i < G_N_ELEMENTS (iq_matrix->ScalingList16x16); i++) {
1131 gst_h265_quant_matrix_16x16_get_raster_from_zigzag
1132 (iq_matrix->ScalingList16x16[i], scaling_list->scaling_lists_16x16[i]);
1137 fill_iq_matrix_32x32 (VAIQMatrixBufferHEVC * iq_matrix,
1138 GstH265ScalingList * scaling_list)
1141 g_assert (G_N_ELEMENTS (iq_matrix->ScalingList32x32) == 2);
1142 g_assert (G_N_ELEMENTS (iq_matrix->ScalingList32x32[0]) == 64);
1143 for (i = 0; i < G_N_ELEMENTS (iq_matrix->ScalingList32x32); i++) {
1144 gst_h265_quant_matrix_32x32_get_raster_from_zigzag
1145 (iq_matrix->ScalingList32x32[i], scaling_list->scaling_lists_32x32[i]);
1150 fill_iq_matrix_dc_16x16 (VAIQMatrixBufferHEVC * iq_matrix,
1151 GstH265ScalingList * scaling_list)
1154 for (i = 0; i < 6; i++)
1155 iq_matrix->ScalingListDC16x16[i] =
1156 scaling_list->scaling_list_dc_coef_minus8_16x16[i] + 8;
1160 fill_iq_matrix_dc_32x32 (VAIQMatrixBufferHEVC * iq_matrix,
1161 GstH265ScalingList * scaling_list)
1164 for (i = 0; i < 2; i++)
1165 iq_matrix->ScalingListDC32x32[i] =
1166 scaling_list->scaling_list_dc_coef_minus8_32x32[i] + 8;
1169 static GstVaapiDecoderStatus
1170 ensure_quant_matrix (GstVaapiDecoderH265 * decoder,
1171 GstVaapiPictureH265 * picture)
1173 GstVaapiPicture *const base_picture = &picture->base;
1174 GstH265PPS *const pps = get_pps (decoder);
1175 GstH265SPS *const sps = get_sps (decoder);
1176 GstH265ScalingList *scaling_list = NULL;
1177 VAIQMatrixBufferHEVC *iq_matrix;
1180 (pps->scaling_list_data_present_flag ||
1181 (sps->scaling_list_enabled_flag
1182 && !sps->scaling_list_data_present_flag)))
1183 scaling_list = &pps->scaling_list;
1184 else if (sps && sps->scaling_list_enabled_flag
1185 && sps->scaling_list_data_present_flag)
1186 scaling_list = &sps->scaling_list;
1188 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1190 base_picture->iq_matrix = GST_VAAPI_IQ_MATRIX_NEW (HEVC, decoder);
1191 if (!base_picture->iq_matrix) {
1192 GST_ERROR ("failed to allocate IQ matrix");
1193 return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
1195 iq_matrix = base_picture->iq_matrix->param;
1197 /* Only supporting 4:2:0 */
1198 if (sps->chroma_format_idc != 1)
1199 return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_CHROMA_FORMAT;
1201 fill_iq_matrix_4x4 (iq_matrix, scaling_list);
1202 fill_iq_matrix_8x8 (iq_matrix, scaling_list);
1203 fill_iq_matrix_16x16 (iq_matrix, scaling_list);
1204 fill_iq_matrix_32x32 (iq_matrix, scaling_list);
1205 fill_iq_matrix_dc_16x16 (iq_matrix, scaling_list);
1206 fill_iq_matrix_dc_32x32 (iq_matrix, scaling_list);
1208 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1211 static inline gboolean
1212 is_valid_state (guint state, guint ref_state)
1214 return (state & ref_state) == ref_state;
1217 static GstVaapiDecoderStatus
1218 decode_current_picture (GstVaapiDecoderH265 * decoder)
1220 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1221 GstVaapiPictureH265 *const picture = priv->current_picture;
1223 if (!is_valid_state (priv->decoder_state, GST_H265_VIDEO_STATE_VALID_PICTURE)) {
1227 priv->decoder_state = 0;
1228 /*Fixme: Use SEI header values */
1229 priv->pic_structure = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
1232 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1234 if (!gst_vaapi_picture_decode (GST_VAAPI_PICTURE_CAST (picture)))
1237 if (!dpb_add (decoder, picture))
1240 gst_vaapi_picture_replace (&priv->current_picture, NULL);
1241 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1244 gst_vaapi_picture_replace (&priv->current_picture, NULL);
1245 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
1247 priv->decoder_state = 0;
1248 priv->pic_structure = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
1249 return GST_VAAPI_DECODER_STATUS_DROP_FRAME;
1252 static GstVaapiDecoderStatus
1253 parse_vps (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1255 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1256 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1257 GstH265VPS *const vps = &pi->data.vps;
1258 GstH265ParserResult result;
1260 GST_DEBUG ("parse VPS");
1261 priv->parser_state = 0;
1263 memset (vps, 0, sizeof (GstH265VPS));
1265 result = gst_h265_parser_parse_vps (priv->parser, &pi->nalu, vps);
1266 if (result != GST_H265_PARSER_OK)
1267 return get_status (result);
1269 priv->parser_state |= GST_H265_VIDEO_STATE_GOT_VPS;
1270 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1273 static GstVaapiDecoderStatus
1274 parse_sps (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1276 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1277 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1278 GstH265SPS *const sps = &pi->data.sps;
1279 GstH265ParserResult result;
1281 GST_DEBUG ("parse SPS");
1282 priv->parser_state = 0;
1284 memset (sps, 0, sizeof (GstH265SPS));
1286 result = gst_h265_parser_parse_sps (priv->parser, &pi->nalu, sps, TRUE);
1287 if (result != GST_H265_PARSER_OK)
1288 return get_status (result);
1290 priv->parser_state |= GST_H265_VIDEO_STATE_GOT_SPS;
1291 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1295 static GstVaapiDecoderStatus
1296 parse_pps (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1298 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1299 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1300 GstH265PPS *const pps = &pi->data.pps;
1301 GstH265ParserResult result;
1303 GST_DEBUG ("parse PPS");
1304 priv->parser_state &= GST_H265_VIDEO_STATE_GOT_SPS;
1306 memset (pps, 0, sizeof (GstH265PPS));
1308 result = gst_h265_parser_parse_pps (priv->parser, &pi->nalu, pps);
1309 if (result != GST_H265_PARSER_OK)
1310 return get_status (result);
1312 priv->parser_state |= GST_H265_VIDEO_STATE_GOT_PPS;
1313 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1316 static GstVaapiDecoderStatus
1317 parse_sei (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1319 GST_FIXME ("Parse SEI, Not implemented !");
1321 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1322 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1323 GstH265SEIMessage *sei = &pi->data.sei;
1324 GstH265ParserResult result;
1325 GST_DEBUG ("parse SEI");
1326 result = gst_h265_parser_parse_sei (priv->parser, &pi->nalu, sei);
1327 if (result != GST_H265_PARSER_OK) {
1328 GST_WARNING ("failed to parse SEI messages");
1329 return get_status (result);
1332 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1335 static GstVaapiDecoderStatus
1336 parse_slice (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1338 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1339 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1340 GstH265SliceHdr *const slice_hdr = &pi->data.slice_hdr;
1341 GstH265ParserResult result;
1343 GST_DEBUG ("parse slice");
1344 priv->parser_state &= (GST_H265_VIDEO_STATE_GOT_SPS |
1345 GST_H265_VIDEO_STATE_GOT_PPS);
1347 slice_hdr->short_term_ref_pic_set_idx = 0;
1349 memset (slice_hdr, 0, sizeof (GstH265SliceHdr));
1351 result = gst_h265_parser_parse_slice_hdr (priv->parser, &pi->nalu, slice_hdr);
1352 if (result != GST_H265_PARSER_OK)
1353 return get_status (result);
1355 priv->parser_state |= GST_H265_VIDEO_STATE_GOT_SLICE;
1356 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1359 static GstVaapiDecoderStatus
1360 decode_vps (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1362 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1363 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1364 GstH265VPS *const vps = &pi->data.vps;
1366 GST_DEBUG ("decode VPS");
1368 gst_vaapi_parser_info_h265_replace (&priv->vps[vps->id], pi);
1370 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1373 static GstVaapiDecoderStatus
1374 decode_sps (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1376 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1377 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1378 GstH265SPS *const sps = &pi->data.sps;
1380 GST_DEBUG ("decode SPS");
1382 if (sps->max_latency_increase_plus1[sps->max_sub_layers_minus1])
1383 priv->SpsMaxLatencyPictures =
1384 sps->max_num_reorder_pics[sps->max_sub_layers_minus1] +
1385 sps->max_latency_increase_plus1[sps->max_sub_layers_minus1] - 1;
1387 gst_vaapi_parser_info_h265_replace (&priv->sps[sps->id], pi);
1389 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1392 static GstVaapiDecoderStatus
1393 decode_pps (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1395 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1396 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1397 GstH265PPS *const pps = &pi->data.pps;
1399 GST_DEBUG ("decode PPS");
1401 gst_vaapi_parser_info_h265_replace (&priv->pps[pps->id], pi);
1403 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1406 static GstVaapiDecoderStatus
1407 decode_sei (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
1409 GST_FIXME ("Decode SEI, Not implemented!");
1411 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1412 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
1413 GstH265SEIMessage *sei = &pi->data.sei;
1415 GST_DEBUG ("decode SEI messages");
1416 switch (sei->payloadType) {
1417 case GST_H265_SEI_PIC_TIMING:{
1418 GstH265PicTiming *pic_timing = &sei->payload.pic_timing;
1419 /* Fix: only if vps->frame_field_info_present_flag */
1420 priv->pic_structure = pic_timing->pic_struct;
1427 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1430 static GstVaapiDecoderStatus
1431 decode_sequence_end (GstVaapiDecoderH265 * decoder)
1433 GstVaapiDecoderStatus status;
1434 GST_DEBUG ("decode sequence-end");
1435 status = decode_current_picture (decoder);
1436 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
1438 dpb_flush (decoder);
1439 return GST_VAAPI_DECODER_STATUS_SUCCESS;
1442 /* 8.3.1 - Decoding process for picture order count */
1444 init_picture_poc (GstVaapiDecoderH265 * decoder,
1445 GstVaapiPictureH265 * picture, GstVaapiParserInfoH265 * pi)
1447 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1448 GstH265SliceHdr *const slice_hdr = &pi->data.slice_hdr;
1449 GstH265SPS *const sps = get_sps (decoder);
1450 const gint32 MaxPicOrderCntLsb =
1451 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
1452 guint8 nal_type = pi->nalu.type;
1453 guint8 temporal_id = pi->nalu.temporal_id_plus1 - 1;
1455 GST_DEBUG ("decode PicOrderCntVal");
1457 priv->prev_poc_lsb = priv->poc_lsb;
1458 priv->prev_poc_msb = priv->poc_msb;
1460 if (!nal_is_irap (nal_type) && picture->NoRaslOutputFlag) {
1461 priv->prev_poc_lsb = priv->prev_tid0pic_poc_lsb;
1462 priv->prev_poc_msb = priv->prev_tid0pic_poc_msb;
1465 /* Finding PicOrderCntMsb */
1466 if (nal_is_irap (nal_type) && picture->NoRaslOutputFlag)
1470 if ((slice_hdr->pic_order_cnt_lsb < priv->prev_poc_lsb) &&
1471 ((priv->prev_poc_lsb - slice_hdr->pic_order_cnt_lsb) >=
1472 (MaxPicOrderCntLsb / 2)))
1473 priv->poc_msb = priv->prev_poc_msb + MaxPicOrderCntLsb;
1475 else if ((slice_hdr->pic_order_cnt_lsb > priv->prev_poc_lsb) &&
1476 ((slice_hdr->pic_order_cnt_lsb - priv->prev_poc_lsb) >
1477 (MaxPicOrderCntLsb / 2)))
1478 priv->poc_msb = priv->prev_poc_msb - MaxPicOrderCntLsb;
1481 priv->poc_msb = priv->prev_poc_msb;
1485 priv->poc = picture->poc = priv->poc_msb + slice_hdr->pic_order_cnt_lsb;
1486 priv->poc_lsb = picture->poc_lsb = slice_hdr->pic_order_cnt_lsb;
1488 if (nal_is_idr (nal_type)) {
1490 picture->poc_lsb = 0;
1493 priv->prev_poc_lsb = 0;
1494 priv->prev_poc_msb = 0;
1495 priv->prev_tid0pic_poc_lsb = 0;
1496 priv->prev_tid0pic_poc_msb = 0;
1500 picture->base.poc = picture->poc;
1501 GST_DEBUG ("PicOrderCntVal %d", picture->base.poc);
1503 if (!temporal_id && !nal_is_rasl (nal_type) &&
1504 !nal_is_radl (nal_type) && nal_is_ref (nal_type)) {
1505 priv->prev_tid0pic_poc_lsb = slice_hdr->pic_order_cnt_lsb;
1506 priv->prev_tid0pic_poc_msb = priv->poc_msb;
1511 init_picture_refs (GstVaapiDecoderH265 * decoder,
1512 GstVaapiPictureH265 * picture, GstH265SliceHdr * slice_hdr)
1514 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1515 guint32 NumRpsCurrTempList0 = 0, NumRpsCurrTempList1 = 0;
1516 GstVaapiPictureH265 *RefPicListTemp0[16] = { NULL, }, *RefPicListTemp1[16] = {
1519 guint num_ref_idx_l0_active_minus1 = 0;
1520 guint num_ref_idx_l1_active_minus1 = 0;
1521 GstH265RefPicListModification *ref_pic_list_modification;
1524 memset (priv->RefPicList0, 0, sizeof (GstVaapiPictureH265 *) * 16);
1525 memset (priv->RefPicList1, 0, sizeof (GstVaapiPictureH265 *) * 16);
1526 priv->RefPicList0_count = priv->RefPicList1_count = 0;
1528 if ((slice_hdr->type != GST_H265_B_SLICE) &&
1529 (slice_hdr->type != GST_H265_P_SLICE))
1532 if (slice_hdr->dependent_slice_segment_flag) {
1533 GstH265SliceHdr *tmp = &priv->prev_independent_slice_pi->data.slice_hdr;
1534 num_ref_idx_l0_active_minus1 = tmp->num_ref_idx_l0_active_minus1;
1535 num_ref_idx_l1_active_minus1 = tmp->num_ref_idx_l1_active_minus1;
1536 ref_pic_list_modification = &tmp->ref_pic_list_modification;
1539 num_ref_idx_l0_active_minus1 = slice_hdr->num_ref_idx_l0_active_minus1;
1540 num_ref_idx_l1_active_minus1 = slice_hdr->num_ref_idx_l1_active_minus1;
1541 ref_pic_list_modification = &slice_hdr->ref_pic_list_modification;
1542 type = slice_hdr->type;
1545 NumRpsCurrTempList0 =
1546 MAX ((num_ref_idx_l0_active_minus1 + 1), priv->NumPocTotalCurr);
1547 NumRpsCurrTempList1 =
1548 MAX ((num_ref_idx_l1_active_minus1 + 1), priv->NumPocTotalCurr);
1551 while (rIdx < NumRpsCurrTempList0) {
1552 for (i = 0; i < priv->NumPocStCurrBefore && rIdx < NumRpsCurrTempList0;
1554 RefPicListTemp0[rIdx] = priv->RefPicSetStCurrBefore[i];
1555 for (i = 0; i < priv->NumPocStCurrAfter && rIdx < NumRpsCurrTempList0;
1557 RefPicListTemp0[rIdx] = priv->RefPicSetStCurrAfter[i];
1558 for (i = 0; i < priv->NumPocLtCurr && rIdx < NumRpsCurrTempList0;
1560 RefPicListTemp0[rIdx] = priv->RefPicSetLtCurr[i];
1563 /* construct RefPicList0 (8-9) */
1564 for (rIdx = 0; rIdx <= num_ref_idx_l0_active_minus1; rIdx++)
1565 priv->RefPicList0[rIdx] =
1566 ref_pic_list_modification->ref_pic_list_modification_flag_l0 ?
1567 RefPicListTemp0[ref_pic_list_modification->list_entry_l0[rIdx]] :
1568 RefPicListTemp0[rIdx];
1569 priv->RefPicList0_count = rIdx;
1571 if (type == GST_H265_B_SLICE) {
1575 while (rIdx < NumRpsCurrTempList1) {
1576 for (i = 0; i < priv->NumPocStCurrAfter && rIdx < NumRpsCurrTempList1;
1578 RefPicListTemp1[rIdx] = priv->RefPicSetStCurrAfter[i];
1579 for (i = 0; i < priv->NumPocStCurrBefore && rIdx < NumRpsCurrTempList1;
1581 RefPicListTemp1[rIdx] = priv->RefPicSetStCurrBefore[i];
1582 for (i = 0; i < priv->NumPocLtCurr && rIdx < NumRpsCurrTempList1;
1584 RefPicListTemp1[rIdx] = priv->RefPicSetLtCurr[i];
1587 /* construct RefPicList1 (8-10) */
1588 for (rIdx = 0; rIdx <= num_ref_idx_l1_active_minus1; rIdx++)
1589 priv->RefPicList1[rIdx] =
1590 ref_pic_list_modification->ref_pic_list_modification_flag_l1 ?
1591 RefPicListTemp1[ref_pic_list_modification->list_entry_l1
1592 [rIdx]] : RefPicListTemp1[rIdx];
1593 priv->RefPicList1_count = rIdx;
1598 init_picture (GstVaapiDecoderH265 * decoder,
1599 GstVaapiPictureH265 * picture, GstVaapiParserInfoH265 * pi)
1601 GstVaapiPicture *const base_picture = &picture->base;
1602 GstH265SliceHdr *const slice_hdr = &pi->data.slice_hdr;
1604 base_picture->pts = GST_VAAPI_DECODER_CODEC_FRAME (decoder)->pts;
1605 base_picture->type = GST_VAAPI_PICTURE_TYPE_NONE;
1607 if (nal_is_idr (pi->nalu.type)) {
1608 GST_DEBUG ("<IDR>");
1609 GST_VAAPI_PICTURE_FLAG_SET (picture, GST_VAAPI_PICTURE_FLAG_IDR);
1612 if (nal_is_irap (pi->nalu.type))
1613 picture->IntraPicFlag = TRUE;
1615 if (pi->nalu.type >= GST_H265_NAL_SLICE_BLA_W_LP &&
1616 pi->nalu.type <= GST_H265_NAL_SLICE_CRA_NUT)
1617 picture->RapPicFlag = TRUE;
1619 /*Fixme: Use SEI header values */
1620 base_picture->structure = GST_VAAPI_PICTURE_STRUCTURE_FRAME;
1621 picture->structure = base_picture->structure;
1623 /*NoRaslOutputFlag ==1 if the current picture is
1626 3) a CRA picture that is the first access unit in the bitstream (Fixme: Not yet added)
1627 4) first picture that follows an end of sequence NAL unit in decoding order (Fixme: Not yet added)
1628 5) has HandleCraAsBlaFlag == 1 (Fixme: Not yet added)
1630 if (nal_is_idr (pi->nalu.type) || nal_is_bla (pi->nalu.type) ||
1631 pi->nalu.type == GST_H265_NAL_SLICE_CRA_NUT) {
1632 picture->NoRaslOutputFlag = 1;
1635 if (nal_is_rasl (pi->
1636 nalu.type) /* Fixme: || NoRaslOutPutFlag of asso irap=1 */ )
1637 picture->output_flag = FALSE;
1639 picture->output_flag = slice_hdr->pic_output_flag;
1641 init_picture_poc (decoder, picture, pi);
1644 if (nal_is_irap (pi->nalu.type)
1645 && picture->NoRaslOutputFlag && picture->poc /*&& Fixme: Not picture0 */ ) {
1647 if (pi->nalu.type == GST_H265_NAL_SLICE_CRA_NUT)
1648 picture->NoOutputOfPriorPicsFlag = 1;
1650 picture->NoOutputOfPriorPicsFlag =
1651 slice_hdr->no_output_of_prior_pics_flag;
1658 vaapi_init_picture (VAPictureHEVC * pic)
1660 pic->picture_id = VA_INVALID_SURFACE;
1661 pic->pic_order_cnt = 0;
1662 pic->flags = VA_PICTURE_HEVC_INVALID;
1666 vaapi_fill_picture (VAPictureHEVC * pic, GstVaapiPictureH265 * picture,
1667 guint picture_structure)
1670 if (!picture_structure)
1671 picture_structure = picture->structure;
1673 pic->picture_id = picture->base.surface_id;
1674 pic->pic_order_cnt = picture->poc;
1677 /* Set the VAPictureHEVC flags */
1678 if (GST_VAAPI_PICTURE_IS_LONG_TERM_REFERENCE (picture))
1679 pic->flags |= VA_PICTURE_HEVC_LONG_TERM_REFERENCE;
1681 if (GST_VAAPI_PICTURE_FLAG_IS_SET (picture,
1682 GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_BEFORE))
1683 pic->flags |= VA_PICTURE_HEVC_RPS_ST_CURR_BEFORE;
1685 else if (GST_VAAPI_PICTURE_FLAG_IS_SET (picture,
1686 GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_AFTER))
1687 pic->flags |= VA_PICTURE_HEVC_RPS_ST_CURR_AFTER;
1689 else if (GST_VAAPI_PICTURE_FLAG_IS_SET (picture,
1690 GST_VAAPI_PICTURE_FLAG_RPS_LT_CURR))
1691 pic->flags |= VA_PICTURE_HEVC_RPS_LT_CURR;
1693 switch (picture_structure) {
1694 case GST_VAAPI_PICTURE_STRUCTURE_FRAME:
1696 case GST_VAAPI_PICTURE_STRUCTURE_TOP_FIELD:
1697 pic->flags |= VA_PICTURE_HEVC_FIELD_PIC;
1699 case GST_VAAPI_PICTURE_STRUCTURE_BOTTOM_FIELD:
1700 pic->flags |= VA_PICTURE_HEVC_FIELD_PIC;
1701 pic->flags |= VA_PICTURE_HEVC_BOTTOM_FIELD;
1709 get_index_for_RefPicListX (VAPictureHEVC * ReferenceFrames,
1710 GstVaapiPictureH265 * pic)
1714 for (i = 0; i < 15; i++) {
1715 if ((ReferenceFrames[i].picture_id != VA_INVALID_ID) && pic) {
1716 if ((ReferenceFrames[i].pic_order_cnt == pic->poc) &&
1717 (ReferenceFrames[i].picture_id == pic->base.surface_id)) {
1726 fill_picture (GstVaapiDecoderH265 * decoder, GstVaapiPictureH265 * picture)
1728 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1729 GstVaapiPicture *const base_picture = &picture->base;
1730 GstH265PPS *const pps = get_pps (decoder);
1731 GstH265SPS *const sps = get_sps (decoder);
1732 VAPictureParameterBufferHEVC *const pic_param = base_picture->param;
1735 pic_param->pic_fields.value = 0;
1736 pic_param->slice_parsing_fields.value = 0;
1738 /* Fill in VAPictureHEVC */
1739 vaapi_fill_picture (&pic_param->CurrPic, picture, 0);
1740 /* Fill in ReferenceFrames */
1741 for (i = 0, n = 0; i < priv->dpb_count; i++) {
1742 GstVaapiFrameStore *const fs = priv->dpb[i];
1743 if ((gst_vaapi_frame_store_has_reference (fs)))
1744 vaapi_fill_picture (&pic_param->ReferenceFrames[n++], fs->buffer,
1745 fs->buffer->structure);
1746 if (n >= G_N_ELEMENTS (pic_param->ReferenceFrames))
1749 for (; n < G_N_ELEMENTS (pic_param->ReferenceFrames); n++)
1750 vaapi_init_picture (&pic_param->ReferenceFrames[n]);
1753 #define COPY_FIELD(s, f) \
1754 pic_param->f = (s)->f
1755 #define COPY_BFM(a, s, f) \
1756 pic_param->a.bits.f = (s)->f
1758 COPY_FIELD (sps, pic_width_in_luma_samples);
1759 COPY_FIELD (sps, pic_height_in_luma_samples);
1760 COPY_BFM (pic_fields, sps, chroma_format_idc);
1761 COPY_BFM (pic_fields, sps, separate_colour_plane_flag);
1762 COPY_BFM (pic_fields, sps, pcm_enabled_flag);
1763 COPY_BFM (pic_fields, sps, scaling_list_enabled_flag);
1764 COPY_BFM (pic_fields, pps, transform_skip_enabled_flag);
1765 COPY_BFM (pic_fields, sps, amp_enabled_flag);
1766 COPY_BFM (pic_fields, sps, strong_intra_smoothing_enabled_flag);
1767 COPY_BFM (pic_fields, pps, sign_data_hiding_enabled_flag);
1768 COPY_BFM (pic_fields, pps, constrained_intra_pred_flag);
1769 COPY_BFM (pic_fields, pps, cu_qp_delta_enabled_flag);
1770 COPY_BFM (pic_fields, pps, weighted_pred_flag);
1771 COPY_BFM (pic_fields, pps, weighted_bipred_flag);
1772 COPY_BFM (pic_fields, pps, transquant_bypass_enabled_flag);
1773 COPY_BFM (pic_fields, pps, tiles_enabled_flag);
1774 COPY_BFM (pic_fields, pps, entropy_coding_sync_enabled_flag);
1775 pic_param->pic_fields.bits.pps_loop_filter_across_slices_enabled_flag =
1776 pps->loop_filter_across_slices_enabled_flag;
1777 COPY_BFM (pic_fields, pps, loop_filter_across_tiles_enabled_flag);
1778 COPY_BFM (pic_fields, sps, pcm_loop_filter_disabled_flag);
1779 /* Fix: Assign value based on sps_max_num_reorder_pics */
1780 pic_param->pic_fields.bits.NoPicReorderingFlag = 0;
1781 /* Fix: Enable if picture has no B slices */
1782 pic_param->pic_fields.bits.NoBiPredFlag = 0;
1784 pic_param->sps_max_dec_pic_buffering_minus1 =
1785 sps->max_dec_pic_buffering_minus1[0];
1786 COPY_FIELD (sps, bit_depth_luma_minus8);
1787 COPY_FIELD (sps, bit_depth_chroma_minus8);
1788 COPY_FIELD (sps, pcm_sample_bit_depth_luma_minus1);
1789 COPY_FIELD (sps, pcm_sample_bit_depth_chroma_minus1);
1790 COPY_FIELD (sps, log2_min_luma_coding_block_size_minus3);
1791 COPY_FIELD (sps, log2_diff_max_min_luma_coding_block_size);
1792 COPY_FIELD (sps, log2_min_transform_block_size_minus2);
1793 COPY_FIELD (sps, log2_diff_max_min_transform_block_size);
1794 COPY_FIELD (sps, log2_min_pcm_luma_coding_block_size_minus3);
1795 COPY_FIELD (sps, log2_diff_max_min_pcm_luma_coding_block_size);
1796 COPY_FIELD (sps, max_transform_hierarchy_depth_intra);
1797 COPY_FIELD (sps, max_transform_hierarchy_depth_inter);
1798 COPY_FIELD (pps, init_qp_minus26);
1799 COPY_FIELD (pps, diff_cu_qp_delta_depth);
1800 pic_param->pps_cb_qp_offset = pps->cb_qp_offset;
1801 pic_param->pps_cr_qp_offset = pps->cr_qp_offset;
1802 COPY_FIELD (pps, log2_parallel_merge_level_minus2);
1803 COPY_FIELD (pps, num_tile_columns_minus1);
1804 COPY_FIELD (pps, num_tile_rows_minus1);
1805 for (i = 0; i < 19; i++)
1806 pic_param->column_width_minus1[i] = pps->column_width_minus1[i];
1807 for (i = 0; i < 21; i++)
1808 pic_param->row_height_minus1[i] = pps->row_height_minus1[i];
1810 COPY_BFM (slice_parsing_fields, pps, lists_modification_present_flag);
1811 COPY_BFM (slice_parsing_fields, sps, long_term_ref_pics_present_flag);
1812 pic_param->slice_parsing_fields.bits.sps_temporal_mvp_enabled_flag =
1813 sps->temporal_mvp_enabled_flag;
1814 COPY_BFM (slice_parsing_fields, pps, cabac_init_present_flag);
1815 COPY_BFM (slice_parsing_fields, pps, output_flag_present_flag);
1816 COPY_BFM (slice_parsing_fields, pps, dependent_slice_segments_enabled_flag);
1817 pic_param->slice_parsing_fields.
1818 bits.pps_slice_chroma_qp_offsets_present_flag =
1819 pps->slice_chroma_qp_offsets_present_flag;
1820 COPY_BFM (slice_parsing_fields, sps, sample_adaptive_offset_enabled_flag);
1821 COPY_BFM (slice_parsing_fields, pps, deblocking_filter_override_enabled_flag);
1822 pic_param->slice_parsing_fields.bits.pps_disable_deblocking_filter_flag =
1823 pps->deblocking_filter_disabled_flag;
1824 COPY_BFM (slice_parsing_fields, pps,
1825 slice_segment_header_extension_present_flag);
1826 pic_param->slice_parsing_fields.bits.RapPicFlag = picture->RapPicFlag;
1827 pic_param->slice_parsing_fields.bits.IdrPicFlag =
1828 GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_IDR);
1829 pic_param->slice_parsing_fields.bits.IntraPicFlag = picture->IntraPicFlag;
1831 COPY_FIELD (sps, log2_max_pic_order_cnt_lsb_minus4);
1832 COPY_FIELD (sps, num_short_term_ref_pic_sets);
1833 pic_param->num_long_term_ref_pic_sps = sps->num_long_term_ref_pics_sps;
1834 COPY_FIELD (pps, num_ref_idx_l0_default_active_minus1);
1835 COPY_FIELD (pps, num_ref_idx_l1_default_active_minus1);
1836 pic_param->pps_beta_offset_div2 = pps->beta_offset_div2;
1837 pic_param->pps_tc_offset_div2 = pps->tc_offset_div2;
1838 COPY_FIELD (pps, num_extra_slice_header_bits);
1840 /*Fixme: Set correct value as mentioned in va_dec_hevc.h */
1841 pic_param->st_rps_bits = 0;
1845 /* Detection of the first VCL NAL unit of a coded picture (7.4.2.4.5 ) */
1847 is_new_picture (GstVaapiParserInfoH265 * pi, GstVaapiParserInfoH265 * prev_pi)
1849 GstH265SliceHdr *const slice_hdr = &pi->data.slice_hdr;
1854 if (slice_hdr->first_slice_segment_in_pic_flag)
1860 /* Detection of a new access unit, assuming we are already in presence
1862 static inline gboolean
1863 is_new_access_unit (GstVaapiParserInfoH265 * pi,
1864 GstVaapiParserInfoH265 * prev_pi)
1871 has_entry_in_rps (GstVaapiPictureH265 * dpb_pic,
1872 GstVaapiPictureH265 ** rps_list, guint rps_list_length)
1876 if (!dpb_pic || !rps_list || !rps_list_length)
1879 for (i = 0; i < rps_list_length; i++) {
1880 if (rps_list[i]->poc == dpb_pic->poc)
1886 /* the derivation process for the RPS and the picture marking */
1888 derive_and_mark_rps (GstVaapiDecoderH265 * decoder,
1889 GstVaapiPictureH265 * picture, GstVaapiParserInfoH265 * pi,
1890 gint32 * CurrDeltaPocMsbPresentFlag, gint32 * FollDeltaPocMsbPresentFlag)
1893 GstVaapiPictureH265 *dpb_pic = NULL;
1894 GstVaapiDecoderH265Private *const priv = &decoder->priv;
1896 memset (priv->RefPicSetLtCurr, 0, sizeof (GstVaapiPictureH265 *) * 16);
1897 memset (priv->RefPicSetLtFoll, 0, sizeof (GstVaapiPictureH265 *) * 16);
1898 memset (priv->RefPicSetStCurrBefore, 0, sizeof (GstVaapiPictureH265 *) * 16);
1899 memset (priv->RefPicSetStCurrAfter, 0, sizeof (GstVaapiPictureH265 *) * 16);
1900 memset (priv->RefPicSetStFoll, 0, sizeof (GstVaapiPictureH265 *) * 16);
1903 for (i = 0; i < priv->NumPocLtCurr; i++) {
1904 if (!CurrDeltaPocMsbPresentFlag[i]) {
1905 dpb_pic = dpb_get_picture (decoder, priv->PocLtCurr[i], TRUE);
1907 priv->RefPicSetLtCurr[i] = dpb_pic;
1909 priv->RefPicSetLtCurr[i] = NULL;
1911 dpb_pic = dpb_get_picture (decoder, priv->PocLtCurr[i], FALSE);
1913 priv->RefPicSetLtCurr[i] = dpb_pic;
1915 priv->RefPicSetLtCurr[i] = NULL;
1919 priv->RefPicSetLtCurr[i] = NULL;
1921 for (i = 0; i < priv->NumPocLtFoll; i++) {
1922 if (!FollDeltaPocMsbPresentFlag[i]) {
1923 dpb_pic = dpb_get_picture (decoder, priv->PocLtFoll[i], TRUE);
1925 priv->RefPicSetLtFoll[i] = dpb_pic;
1927 priv->RefPicSetLtFoll[i] = NULL;
1929 dpb_pic = dpb_get_picture (decoder, priv->PocLtFoll[i], FALSE);
1931 priv->RefPicSetLtFoll[i] = dpb_pic;
1933 priv->RefPicSetLtFoll[i] = NULL;
1937 priv->RefPicSetLtFoll[i] = NULL;
1939 /* Mark all ref pics in RefPicSetLtCurr and RefPicSetLtFol as long_term_refs */
1940 for (i = 0; i < priv->NumPocLtCurr; i++) {
1941 if (priv->RefPicSetLtCurr[i])
1942 gst_vaapi_picture_h265_set_reference (priv->RefPicSetLtCurr[i],
1943 GST_VAAPI_PICTURE_FLAG_LONG_TERM_REFERENCE |
1944 GST_VAAPI_PICTURE_FLAG_RPS_LT_CURR);
1946 for (i = 0; i < priv->NumPocLtFoll; i++) {
1947 if (priv->RefPicSetLtFoll[i])
1948 gst_vaapi_picture_h265_set_reference (priv->RefPicSetLtFoll[i],
1949 GST_VAAPI_PICTURE_FLAG_LONG_TERM_REFERENCE |
1950 GST_VAAPI_PICTURE_FLAG_RPS_LT_FOLL);
1954 for (i = 0; i < priv->NumPocStCurrBefore; i++) {
1955 dpb_pic = dpb_get_ref_picture (decoder, priv->PocStCurrBefore[i], TRUE);
1957 gst_vaapi_picture_h265_set_reference (dpb_pic,
1958 GST_VAAPI_PICTURE_FLAG_SHORT_TERM_REFERENCE |
1959 GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_BEFORE);
1960 priv->RefPicSetStCurrBefore[i] = dpb_pic;
1962 priv->RefPicSetStCurrBefore[i] = NULL;
1965 priv->RefPicSetStCurrBefore[i] = NULL;
1967 for (i = 0; i < priv->NumPocStCurrAfter; i++) {
1968 dpb_pic = dpb_get_ref_picture (decoder, priv->PocStCurrAfter[i], TRUE);
1970 gst_vaapi_picture_h265_set_reference (dpb_pic,
1971 GST_VAAPI_PICTURE_FLAG_SHORT_TERM_REFERENCE |
1972 GST_VAAPI_PICTURE_FLAG_RPS_ST_CURR_AFTER);
1973 priv->RefPicSetStCurrAfter[i] = dpb_pic;
1975 priv->RefPicSetStCurrAfter[i] = NULL;
1978 priv->RefPicSetStCurrAfter[i] = NULL;
1980 for (i = 0; i < priv->NumPocStFoll; i++) {
1981 dpb_pic = dpb_get_ref_picture (decoder, priv->PocStFoll[i], TRUE);
1983 gst_vaapi_picture_h265_set_reference (dpb_pic,
1984 GST_VAAPI_PICTURE_FLAG_SHORT_TERM_REFERENCE |
1985 GST_VAAPI_PICTURE_FLAG_RPS_ST_FOLL);
1986 priv->RefPicSetStFoll[i] = dpb_pic;
1988 priv->RefPicSetStFoll[i] = NULL;
1991 priv->RefPicSetStFoll[i] = NULL;
1993 /* Mark all dpb pics not beloging to RefPicSet*[] as unused for ref */
1994 for (i = 0; i < priv->dpb_count; i++) {
1995 dpb_pic = priv->dpb[i]->buffer;
1997 !has_entry_in_rps (dpb_pic, priv->RefPicSetLtCurr, priv->NumPocLtCurr)
1998 && !has_entry_in_rps (dpb_pic, priv->RefPicSetLtFoll,
2000 && !has_entry_in_rps (dpb_pic, priv->RefPicSetStCurrAfter,
2001 priv->NumPocStCurrAfter)
2002 && !has_entry_in_rps (dpb_pic, priv->RefPicSetStCurrBefore,
2003 priv->NumPocStCurrBefore)
2004 && !has_entry_in_rps (dpb_pic, priv->RefPicSetStFoll,
2005 priv->NumPocStFoll))
2006 gst_vaapi_picture_h265_set_reference (dpb_pic, 0);
2010 /* Decoding process for reference picture set (8.3.2) */
2012 decode_ref_pic_set (GstVaapiDecoderH265 * decoder,
2013 GstVaapiPictureH265 * picture, GstVaapiParserInfoH265 * pi)
2016 gint32 CurrDeltaPocMsbPresentFlag[16] = { 0, };
2017 gint32 FollDeltaPocMsbPresentFlag[16] = { 0, };
2018 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2019 GstH265SliceHdr *const slice_hdr = &pi->data.slice_hdr;
2020 GstH265SPS *const sps = get_sps (decoder);
2021 const gint32 MaxPicOrderCntLsb =
2022 1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4);
2024 /* if it is an irap pic, set all ref pics in dpb as unused for ref */
2025 if (nal_is_irap (pi->nalu.type) && picture->NoRaslOutputFlag) {
2026 for (i = 0; i < priv->dpb_count; i++) {
2027 GstVaapiFrameStore *const fs = priv->dpb[i];
2028 gst_vaapi_picture_h265_set_reference (fs->buffer, 0);
2032 /* Reset everything for IDR */
2033 if (nal_is_idr (pi->nalu.type)) {
2034 memset (priv->PocStCurrBefore, 0, sizeof (guint) * 16);
2035 memset (priv->PocStCurrAfter, 0, sizeof (guint) * 16);
2036 memset (priv->PocStFoll, 0, sizeof (guint) * 16);
2037 memset (priv->PocLtCurr, 0, sizeof (guint) * 16);
2038 memset (priv->PocLtFoll, 0, sizeof (guint) * 16);
2039 priv->NumPocStCurrBefore = priv->NumPocStCurrAfter = priv->NumPocStFoll = 0;
2040 priv->NumPocLtCurr = priv->NumPocLtFoll = 0;
2042 GstH265ShortTermRefPicSet *stRefPic;
2043 gint32 num_lt_pics, pocLt, PocLsbLt[16] = { 0, }
2044 , UsedByCurrPicLt[16] = {
2046 gint32 DeltaPocMsbCycleLt[16] = { 0, };
2047 gint numtotalcurr = 0;
2049 /* this is based on CurrRpsIdx described in spec */
2050 if (!slice_hdr->short_term_ref_pic_set_sps_flag)
2051 stRefPic = &slice_hdr->short_term_ref_pic_sets;
2052 else if (sps->num_short_term_ref_pic_sets)
2054 &sps->short_term_ref_pic_set[slice_hdr->short_term_ref_pic_set_idx];
2057 for (i = 0, j = 0, k = 0; i < stRefPic->NumNegativePics; i++) {
2058 if (stRefPic->UsedByCurrPicS0[i]) {
2059 priv->PocStCurrBefore[j++] = picture->poc + stRefPic->DeltaPocS0[i];
2062 priv->PocStFoll[k++] = picture->poc + stRefPic->DeltaPocS0[i];
2064 priv->NumPocStCurrBefore = j;
2065 for (i = 0, j = 0; i < stRefPic->NumPositivePics; i++) {
2066 if (stRefPic->UsedByCurrPicS1[i]) {
2067 priv->PocStCurrAfter[j++] = picture->poc + stRefPic->DeltaPocS1[i];
2070 priv->PocStFoll[k++] = picture->poc + stRefPic->DeltaPocS1[i];
2072 priv->NumPocStCurrAfter = j;
2073 priv->NumPocStFoll = k;
2074 num_lt_pics = slice_hdr->num_long_term_sps + slice_hdr->num_long_term_pics;
2075 /* The variables PocLsbLt[i] and UsedByCurrPicLt[i] are derived as follows: */
2076 for (i = 0; i < num_lt_pics; i++) {
2077 if (i < slice_hdr->num_long_term_sps) {
2078 PocLsbLt[i] = sps->lt_ref_pic_poc_lsb_sps[slice_hdr->lt_idx_sps[i]];
2079 UsedByCurrPicLt[i] =
2080 sps->used_by_curr_pic_lt_sps_flag[slice_hdr->lt_idx_sps[i]];
2082 PocLsbLt[i] = slice_hdr->poc_lsb_lt[i];
2083 UsedByCurrPicLt[i] = slice_hdr->used_by_curr_pic_lt_flag[i];
2085 if (UsedByCurrPicLt[i])
2089 priv->NumPocTotalCurr = numtotalcurr;
2091 /* The variable DeltaPocMsbCycleLt[i] is derived as follows: (7-38) */
2092 for (i = 0; i < num_lt_pics; i++) {
2093 if (i == 0 || i == slice_hdr->num_long_term_sps)
2094 DeltaPocMsbCycleLt[i] = slice_hdr->delta_poc_msb_cycle_lt[i];
2096 DeltaPocMsbCycleLt[i] =
2097 slice_hdr->delta_poc_msb_cycle_lt[i] + DeltaPocMsbCycleLt[i - 1];
2101 for (i = 0, j = 0, k = 0; i < num_lt_pics; i++) {
2102 pocLt = PocLsbLt[i];
2103 if (slice_hdr->delta_poc_msb_present_flag[i])
2105 picture->poc - DeltaPocMsbCycleLt[i] * MaxPicOrderCntLsb -
2106 slice_hdr->pic_order_cnt_lsb;
2107 if (UsedByCurrPicLt[i]) {
2108 priv->PocLtCurr[j] = pocLt;
2109 CurrDeltaPocMsbPresentFlag[j++] =
2110 slice_hdr->delta_poc_msb_present_flag[i];
2112 priv->PocLtFoll[k] = pocLt;
2113 FollDeltaPocMsbPresentFlag[k++] =
2114 slice_hdr->delta_poc_msb_present_flag[i];
2117 priv->NumPocLtCurr = j;
2118 priv->NumPocLtFoll = k;
2122 /* the derivation process for the RPS and the picture marking */
2123 derive_and_mark_rps (decoder, picture, pi, CurrDeltaPocMsbPresentFlag,
2124 FollDeltaPocMsbPresentFlag);
2129 static GstVaapiDecoderStatus
2130 decode_picture (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
2132 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2133 GstVaapiParserInfoH265 *pi = unit->parsed_info;
2134 GstH265SliceHdr *const slice_hdr = &pi->data.slice_hdr;
2135 GstH265PPS *const pps = ensure_pps (decoder, slice_hdr->pps);
2136 GstH265SPS *const sps = ensure_sps (decoder, slice_hdr->pps->sps);
2137 GstVaapiPictureH265 *picture;
2138 GstVaapiDecoderStatus status;
2140 g_return_val_if_fail (pps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN);
2141 g_return_val_if_fail (sps != NULL, GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN);
2143 status = ensure_context (decoder, sps);
2144 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2147 priv->decoder_state = 0;
2149 /* Create new picture */
2150 picture = gst_vaapi_picture_h265_new (decoder);
2152 GST_ERROR ("failed to allocate picture");
2153 return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
2156 gst_vaapi_picture_replace (&priv->current_picture, picture);
2157 gst_vaapi_picture_unref (picture);
2159 /* Update cropping rectangle */
2160 /* Fixme: Add cropping rectangle, fix needed in codecparser */
2162 status = ensure_quant_matrix (decoder, picture);
2163 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS) {
2164 GST_ERROR ("failed to reset quantizer matrix");
2168 if (!init_picture (decoder, picture, pi))
2169 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
2171 if (!decode_ref_pic_set (decoder, picture, pi))
2172 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
2174 /* Fixme: if pic is BLA or CRA,and have NoRaslOutputFlag == 1,
2175 invoke 8.3.3 as described in specification for generating
2176 unavailable reference pictures */
2178 if (!dpb_init (decoder, picture, pi))
2179 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
2181 if (!fill_picture (decoder, picture))
2182 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
2184 priv->decoder_state = pi->state;
2185 return GST_VAAPI_DECODER_STATUS_SUCCESS;
2189 get_slice_data_byte_offset (GstH265SliceHdr * slice_hdr, guint nal_header_bytes)
2192 epb_count = slice_hdr->n_emulation_prevention_bytes;
2193 return nal_header_bytes + (slice_hdr->header_size + 7) / 8 - epb_count;
2197 clip3 (gint x, gint y, gint z)
2207 fill_pred_weight_table (GstVaapiDecoderH265 * decoder,
2208 GstVaapiSlice * slice, GstH265SliceHdr * slice_hdr)
2210 VASliceParameterBufferHEVC *const slice_param = slice->param;
2211 GstH265PPS *const pps = get_pps (decoder);
2212 GstH265SPS *const sps = get_sps (decoder);
2213 GstH265PredWeightTable *const w = &slice_hdr->pred_weight_table;
2214 gint chroma_weight, chroma_log2_weight_denom;
2217 slice_param->luma_log2_weight_denom = 0;
2218 slice_param->delta_chroma_log2_weight_denom = 0;
2220 if ((pps->weighted_pred_flag && GST_H265_IS_P_SLICE (slice_hdr)) ||
2221 (pps->weighted_bipred_flag && GST_H265_IS_B_SLICE (slice_hdr))) {
2223 slice_param->luma_log2_weight_denom = w->luma_log2_weight_denom;
2224 if (!sps->chroma_format_idc)
2225 slice_param->delta_chroma_log2_weight_denom =
2226 w->delta_chroma_log2_weight_denom;
2228 chroma_log2_weight_denom =
2229 slice_param->luma_log2_weight_denom +
2230 slice_param->delta_chroma_log2_weight_denom;
2232 for (i = 0; i <= slice_param->num_ref_idx_l0_active_minus1; i++) {
2233 if (slice_hdr->pred_weight_table.luma_weight_l0_flag[i]) {
2234 slice_param->delta_luma_weight_l0[i] = w->delta_luma_weight_l0[i];
2235 slice_param->luma_offset_l0[i] = w->luma_offset_l0[i];
2237 if (slice_hdr->pred_weight_table.chroma_weight_l0_flag[i]) {
2238 for (j = 0; j < 2; j++) {
2239 slice_param->delta_chroma_weight_l0[i][j] =
2240 w->delta_chroma_weight_l0[i][j];
2241 /* Find ChromaWeightL0 */
2243 (1 << chroma_log2_weight_denom) + w->delta_chroma_weight_l0[i][j];
2245 slice_param->ChromaOffsetL0[i][j] = clip3 (-128, 127,
2246 (w->delta_chroma_offset_l0[i][j] -
2247 ((128 * chroma_weight) >> chroma_log2_weight_denom)));
2252 if (GST_H265_IS_B_SLICE (slice_hdr)) {
2253 for (i = 0; i <= slice_param->num_ref_idx_l1_active_minus1; i++) {
2254 if (slice_hdr->pred_weight_table.luma_weight_l1_flag[i]) {
2255 slice_param->delta_luma_weight_l1[i] = w->delta_luma_weight_l1[i];
2256 slice_param->luma_offset_l1[i] = w->luma_offset_l1[i];
2258 if (slice_hdr->pred_weight_table.chroma_weight_l1_flag[i]) {
2259 for (j = 0; j < 2; j++) {
2260 slice_param->delta_chroma_weight_l1[i][j] =
2261 w->delta_chroma_weight_l1[i][j];
2262 /* Find ChromaWeightL1 */
2264 (1 << chroma_log2_weight_denom) +
2265 w->delta_chroma_weight_l1[i][j];
2266 slice_param->ChromaOffsetL1[i][j] =
2268 (w->delta_chroma_offset_l1[i][j] -
2269 ((128 * chroma_weight) >> chroma_log2_weight_denom)));
2275 /* Fixme: Optimize */
2277 for (i = 0; i < 15; i++) {
2278 slice_param->delta_luma_weight_l0[i] = 0;
2279 slice_param->luma_offset_l0[i] = 0;
2280 slice_param->delta_luma_weight_l1[i] = 0;
2281 slice_param->luma_offset_l1[i] = 0;
2283 for (i = 0; i < 15; i++) {
2284 for (j = 0; j < 2; j++) {
2285 slice_param->delta_chroma_weight_l0[i][j] = 0;
2286 slice_param->ChromaOffsetL0[i][j] = 0;
2287 slice_param->delta_chroma_weight_l1[i][j] = 0;
2288 slice_param->ChromaOffsetL1[i][j] = 0;
2296 fill_RefPicList (GstVaapiDecoderH265 * decoder,
2297 GstVaapiPictureH265 * picture, GstVaapiSlice * slice,
2298 GstH265SliceHdr * slice_hdr)
2300 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2301 VASliceParameterBufferHEVC *const slice_param = slice->param;
2302 GstVaapiPicture *const base_picture = &picture->base;
2303 VAPictureParameterBufferHEVC *const pic_param = base_picture->param;
2304 guint i, num_ref_lists = 0, j;
2306 slice_param->num_ref_idx_l0_active_minus1 = 0;
2307 slice_param->num_ref_idx_l1_active_minus1 = 0;
2308 for (j = 0; j < 2; j++)
2309 for (i = 0; i < 15; i++)
2310 slice_param->RefPicList[j][i] = 0xFF;
2312 if (GST_H265_IS_B_SLICE (slice_hdr))
2314 else if (GST_H265_IS_I_SLICE (slice_hdr))
2319 if (num_ref_lists < 1)
2322 slice_param->num_ref_idx_l0_active_minus1 =
2323 slice_hdr->num_ref_idx_l0_active_minus1;
2324 slice_param->num_ref_idx_l1_active_minus1 =
2325 slice_hdr->num_ref_idx_l1_active_minus1;
2327 for (i = 0; i < priv->RefPicList0_count; i++)
2328 slice_param->RefPicList[0][i] =
2329 get_index_for_RefPicListX (pic_param->ReferenceFrames,
2330 priv->RefPicList0[i]);
2332 slice_param->RefPicList[0][i] = 0xFF;
2334 if (num_ref_lists < 2)
2337 for (i = 0; i < priv->RefPicList1_count; i++)
2338 slice_param->RefPicList[1][i] =
2339 get_index_for_RefPicListX (pic_param->ReferenceFrames,
2340 priv->RefPicList1[i]);
2342 slice_param->RefPicList[1][i] = 0xFF;
2348 fill_slice (GstVaapiDecoderH265 * decoder,
2349 GstVaapiPictureH265 * picture, GstVaapiSlice * slice,
2350 GstVaapiParserInfoH265 * pi, GstVaapiDecoderUnit * unit)
2352 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2353 VASliceParameterBufferHEVC *const slice_param = slice->param;
2354 GstH265SliceHdr *slice_hdr = &pi->data.slice_hdr;
2356 /* Fill in VASliceParameterBufferH265 */
2357 slice_param->LongSliceFlags.value = 0;
2358 slice_param->slice_data_byte_offset =
2359 get_slice_data_byte_offset (slice_hdr, pi->nalu.header_bytes);
2361 slice_param->slice_segment_address = slice_hdr->segment_address;
2363 #define COPY_LFF(f) \
2364 slice_param->LongSliceFlags.fields.f = (slice_hdr)->f
2366 if (GST_VAAPI_PICTURE_FLAG_IS_SET (picture, GST_VAAPI_PICTURE_FLAG_AU_END))
2367 slice_param->LongSliceFlags.fields.LastSliceOfPic = 1;
2369 slice_param->LongSliceFlags.fields.LastSliceOfPic = 0;
2371 COPY_LFF (dependent_slice_segment_flag);
2373 /* use most recent independent slice segment header syntax elements
2374 * for filling the missing fields in dependent slice segment header */
2375 if (slice_hdr->dependent_slice_segment_flag)
2376 slice_hdr = &priv->prev_independent_slice_pi->data.slice_hdr;
2378 COPY_LFF (mvd_l1_zero_flag);
2379 COPY_LFF (cabac_init_flag);
2380 COPY_LFF (collocated_from_l0_flag);
2381 slice_param->LongSliceFlags.fields.color_plane_id =
2382 slice_hdr->colour_plane_id;
2383 slice_param->LongSliceFlags.fields.slice_type = slice_hdr->type;
2384 slice_param->LongSliceFlags.fields.slice_sao_luma_flag =
2385 slice_hdr->sao_luma_flag;
2386 slice_param->LongSliceFlags.fields.slice_sao_chroma_flag =
2387 slice_hdr->sao_chroma_flag;
2388 slice_param->LongSliceFlags.fields.slice_temporal_mvp_enabled_flag =
2389 slice_hdr->temporal_mvp_enabled_flag;
2390 slice_param->LongSliceFlags.fields.slice_deblocking_filter_disabled_flag =
2391 slice_hdr->deblocking_filter_disabled_flag;
2392 slice_param->LongSliceFlags.
2393 fields.slice_loop_filter_across_slices_enabled_flag =
2394 slice_hdr->loop_filter_across_slices_enabled_flag;
2396 if (!slice_hdr->temporal_mvp_enabled_flag)
2397 slice_param->collocated_ref_idx = 0xFF;
2399 slice_param->collocated_ref_idx = slice_hdr->collocated_ref_idx;
2401 slice_param->num_ref_idx_l0_active_minus1 =
2402 slice_hdr->num_ref_idx_l0_active_minus1;
2403 slice_param->num_ref_idx_l1_active_minus1 =
2404 slice_hdr->num_ref_idx_l1_active_minus1;
2405 slice_param->slice_qp_delta = slice_hdr->qp_delta;
2406 slice_param->slice_cb_qp_offset = slice_hdr->cb_qp_offset;
2407 slice_param->slice_cr_qp_offset = slice_hdr->cr_qp_offset;
2408 slice_param->slice_beta_offset_div2 = slice_hdr->beta_offset_div2;
2409 slice_param->slice_tc_offset_div2 = slice_hdr->tc_offset_div2;
2410 slice_param->five_minus_max_num_merge_cand =
2411 slice_hdr->five_minus_max_num_merge_cand;
2413 if (!fill_RefPicList (decoder, picture, slice, slice_hdr))
2416 if (!fill_pred_weight_table (decoder, slice, slice_hdr))
2422 static GstVaapiDecoderStatus
2423 decode_slice (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
2425 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2426 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
2427 GstVaapiPictureH265 *const picture = priv->current_picture;
2428 GstH265SliceHdr *const slice_hdr = &pi->data.slice_hdr;
2429 GstVaapiSlice *slice;
2430 GstBuffer *const buffer =
2431 GST_VAAPI_DECODER_CODEC_FRAME (decoder)->input_buffer;
2432 GstMapInfo map_info;
2434 GST_DEBUG ("slice (%u bytes)", pi->nalu.size);
2435 if (!is_valid_state (pi->state, GST_H265_VIDEO_STATE_VALID_PICTURE_HEADERS)) {
2436 GST_WARNING ("failed to receive enough headers to decode slice");
2437 return GST_VAAPI_DECODER_STATUS_SUCCESS;
2440 if (!ensure_pps (decoder, slice_hdr->pps)) {
2441 GST_ERROR ("failed to activate PPS");
2442 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
2445 if (!ensure_sps (decoder, slice_hdr->pps->sps)) {
2446 GST_ERROR ("failed to activate SPS");
2447 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
2450 if (!gst_buffer_map (buffer, &map_info, GST_MAP_READ)) {
2451 GST_ERROR ("failed to map buffer");
2452 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
2455 /* Check wether this is the first/last slice in the current access unit */
2456 if (pi->flags & GST_VAAPI_DECODER_UNIT_FLAG_AU_START)
2457 GST_VAAPI_PICTURE_FLAG_SET (picture, GST_VAAPI_PICTURE_FLAG_AU_START);
2459 if (pi->flags & GST_VAAPI_DECODER_UNIT_FLAG_AU_END)
2460 GST_VAAPI_PICTURE_FLAG_SET (picture, GST_VAAPI_PICTURE_FLAG_AU_END);
2462 slice = GST_VAAPI_SLICE_NEW (HEVC, decoder,
2463 (map_info.data + unit->offset + pi->nalu.offset), pi->nalu.size);
2465 gst_buffer_unmap (buffer, &map_info);
2467 GST_ERROR ("failed to allocate slice");
2468 return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
2471 init_picture_refs (decoder, picture, slice_hdr);
2473 if (!fill_slice (decoder, picture, slice, pi, unit)) {
2474 gst_vaapi_mini_object_unref (GST_VAAPI_MINI_OBJECT (slice));
2475 return GST_VAAPI_DECODER_STATUS_ERROR_UNKNOWN;
2478 gst_vaapi_picture_add_slice (GST_VAAPI_PICTURE_CAST (picture), slice);
2479 picture->last_slice_hdr = slice_hdr;
2480 priv->decoder_state |= GST_H265_VIDEO_STATE_GOT_SLICE;
2481 return GST_VAAPI_DECODER_STATUS_SUCCESS;
2485 scan_for_start_code (GstAdapter * adapter, guint ofs, guint size, guint32 * scp)
2487 return (gint) gst_adapter_masked_scan_uint32_peek (adapter,
2488 0xffffff00, 0x00000100, ofs, size, scp);
2491 static GstVaapiDecoderStatus
2492 decode_unit (GstVaapiDecoderH265 * decoder, GstVaapiDecoderUnit * unit)
2494 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2495 GstVaapiParserInfoH265 *const pi = unit->parsed_info;
2496 GstVaapiDecoderStatus status;
2497 priv->decoder_state |= pi->state;
2498 switch (pi->nalu.type) {
2499 case GST_H265_NAL_VPS:
2500 status = decode_vps (decoder, unit);
2502 case GST_H265_NAL_SPS:
2503 status = decode_sps (decoder, unit);
2505 case GST_H265_NAL_PPS:
2506 status = decode_pps (decoder, unit);
2508 case GST_H265_NAL_SLICE_TRAIL_N:
2509 case GST_H265_NAL_SLICE_TRAIL_R:
2510 case GST_H265_NAL_SLICE_TSA_N:
2511 case GST_H265_NAL_SLICE_TSA_R:
2512 case GST_H265_NAL_SLICE_STSA_N:
2513 case GST_H265_NAL_SLICE_STSA_R:
2514 case GST_H265_NAL_SLICE_RADL_N:
2515 case GST_H265_NAL_SLICE_RADL_R:
2516 case GST_H265_NAL_SLICE_RASL_N:
2517 case GST_H265_NAL_SLICE_RASL_R:
2518 case GST_H265_NAL_SLICE_BLA_W_LP:
2519 case GST_H265_NAL_SLICE_BLA_W_RADL:
2520 case GST_H265_NAL_SLICE_BLA_N_LP:
2521 case GST_H265_NAL_SLICE_IDR_W_RADL:
2522 case GST_H265_NAL_SLICE_IDR_N_LP:
2523 case GST_H265_NAL_SLICE_CRA_NUT:
2524 status = decode_slice (decoder, unit);
2526 case GST_H265_NAL_EOS:
2527 case GST_H265_NAL_EOB:
2528 status = decode_sequence_end (decoder);
2530 case GST_H265_NAL_SUFFIX_SEI:
2531 case GST_H265_NAL_PREFIX_SEI:
2532 status = decode_sei (decoder, unit);
2535 GST_WARNING ("unsupported NAL unit type %d", pi->nalu.type);
2536 status = GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
2542 static GstVaapiDecoderStatus
2543 gst_vaapi_decoder_h265_decode_codec_data (GstVaapiDecoder *
2544 base_decoder, const guchar * buf, guint buf_size)
2546 GstVaapiDecoderH265 *const decoder =
2547 GST_VAAPI_DECODER_H265_CAST (base_decoder);
2548 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2549 GstVaapiDecoderStatus status;
2550 GstVaapiDecoderUnit unit;
2551 GstVaapiParserInfoH265 *pi = NULL;
2552 GstH265ParserResult result;
2553 guint num_nal_arrays, num_nals;
2555 unit.parsed_info = NULL;
2557 return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
2559 GST_ERROR ("failed to decode codec-data, not in hvcC format");
2560 return GST_VAAPI_DECODER_STATUS_ERROR_BITSTREAM_PARSER;
2563 priv->nal_length_size = (buf[21] & 0x03) + 1;
2564 GST_DEBUG ("nal length size %u", priv->nal_length_size);
2565 num_nal_arrays = buf[22];
2567 for (i = 0; i < num_nal_arrays; i++) {
2568 num_nals = GST_READ_UINT16_BE (buf + ofs + 1);
2569 for (j = 0; j < num_nals; j++) {
2570 pi = gst_vaapi_parser_info_h265_new ();
2572 return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
2573 unit.parsed_info = pi;
2574 result = gst_h265_parser_identify_nalu_hevc (priv->parser,
2575 buf, ofs + 3, buf_size, 2, &pi->nalu);
2576 if (result != GST_H265_PARSER_OK) {
2577 status = get_status (result);
2581 switch (pi->nalu.type) {
2582 case GST_H265_NAL_VPS:
2583 status = parse_vps (decoder, &unit);
2584 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2586 status = decode_vps (decoder, &unit);
2587 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2590 case GST_H265_NAL_SPS:
2591 status = parse_sps (decoder, &unit);
2592 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2594 status = decode_sps (decoder, &unit);
2595 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2598 case GST_H265_NAL_PPS:
2599 status = parse_pps (decoder, &unit);
2600 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2602 status = decode_pps (decoder, &unit);
2603 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2607 gst_vaapi_parser_info_h265_replace (&pi, NULL);
2611 priv->is_hvcC = TRUE;
2612 status = GST_VAAPI_DECODER_STATUS_SUCCESS;
2614 gst_vaapi_parser_info_h265_replace (&pi, NULL);
2618 static GstVaapiDecoderStatus
2619 ensure_decoder (GstVaapiDecoderH265 * decoder)
2621 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2622 GstVaapiDecoderStatus status;
2623 if (!priv->is_opened) {
2624 priv->is_opened = gst_vaapi_decoder_h265_open (decoder);
2625 if (!priv->is_opened)
2626 return GST_VAAPI_DECODER_STATUS_ERROR_UNSUPPORTED_CODEC;
2628 gst_vaapi_decoder_decode_codec_data (GST_VAAPI_DECODER_CAST (decoder));
2629 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2632 return GST_VAAPI_DECODER_STATUS_SUCCESS;
2635 static GstVaapiDecoderStatus
2636 gst_vaapi_decoder_h265_parse (GstVaapiDecoder * base_decoder,
2637 GstAdapter * adapter, gboolean at_eos, GstVaapiDecoderUnit * unit)
2639 GstVaapiDecoderH265 *const decoder =
2640 GST_VAAPI_DECODER_H265_CAST (base_decoder);
2641 GstVaapiDecoderH265Private *const priv = &decoder->priv;
2642 GstVaapiParserState *const ps = GST_VAAPI_PARSER_STATE (base_decoder);
2643 GstVaapiParserInfoH265 *pi;
2644 GstVaapiDecoderStatus status;
2645 GstH265ParserResult result;
2647 guint i, size, buf_size, nalu_size, flags;
2650 gboolean at_au_end = FALSE;
2651 status = ensure_decoder (decoder);
2652 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2654 switch (priv->stream_alignment) {
2655 case GST_VAAPI_STREAM_ALIGN_H265_NALU:
2656 case GST_VAAPI_STREAM_ALIGN_H265_AU:
2657 size = gst_adapter_available_fast (adapter);
2660 size = gst_adapter_available (adapter);
2664 if (priv->is_hvcC) {
2665 if (size < priv->nal_length_size)
2666 return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
2667 buf = (guchar *) & start_code;
2668 g_assert (priv->nal_length_size <= sizeof (start_code));
2669 gst_adapter_copy (adapter, buf, 0, priv->nal_length_size);
2671 for (i = 0; i < priv->nal_length_size; i++)
2672 nalu_size = (nalu_size << 8) | buf[i];
2673 buf_size = priv->nal_length_size + nalu_size;
2674 if (size < buf_size)
2675 return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
2676 else if (priv->stream_alignment == GST_VAAPI_STREAM_ALIGN_H265_AU)
2677 at_au_end = (buf_size == size);
2680 return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
2681 if (priv->stream_alignment == GST_VAAPI_STREAM_ALIGN_H265_NALU)
2684 ofs = scan_for_start_code (adapter, 0, size, NULL);
2686 return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
2688 gst_adapter_flush (adapter, ofs);
2692 ofs2 = ps->input_offset2 - ofs - 4;
2695 ofs = G_UNLIKELY (size < ofs2 + 4) ? -1 :
2696 scan_for_start_code (adapter, ofs2, size - ofs2, NULL);
2698 // Assume the whole NAL unit is present if end-of-stream
2699 // or stream buffers aligned on access unit boundaries
2700 if (priv->stream_alignment == GST_VAAPI_STREAM_ALIGN_H265_AU)
2703 ps->input_offset2 = size;
2704 return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
2711 ps->input_offset2 = 0;
2712 buf = (guchar *) gst_adapter_map (adapter, buf_size);
2714 return GST_VAAPI_DECODER_STATUS_ERROR_NO_DATA;
2715 unit->size = buf_size;
2716 pi = gst_vaapi_parser_info_h265_new ();
2718 return GST_VAAPI_DECODER_STATUS_ERROR_ALLOCATION_FAILED;
2719 gst_vaapi_decoder_unit_set_parsed_info (unit,
2720 pi, (GDestroyNotify) gst_vaapi_mini_object_unref);
2722 result = gst_h265_parser_identify_nalu_hevc (priv->parser,
2723 buf, 0, buf_size, priv->nal_length_size, &pi->nalu);
2725 result = gst_h265_parser_identify_nalu_unchecked (priv->parser,
2726 buf, 0, buf_size, &pi->nalu);
2727 status = get_status (result);
2728 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2730 switch (pi->nalu.type) {
2731 case GST_H265_NAL_VPS:
2732 status = parse_vps (decoder, unit);
2734 case GST_H265_NAL_SPS:
2735 status = parse_sps (decoder, unit);
2737 case GST_H265_NAL_PPS:
2738 status = parse_pps (decoder, unit);
2740 case GST_H265_NAL_PREFIX_SEI:
2741 case GST_H265_NAL_SUFFIX_SEI:
2742 status = parse_sei (decoder, unit);
2744 case GST_H265_NAL_SLICE_TRAIL_N:
2745 case GST_H265_NAL_SLICE_TRAIL_R:
2746 case GST_H265_NAL_SLICE_TSA_N:
2747 case GST_H265_NAL_SLICE_TSA_R:
2748 case GST_H265_NAL_SLICE_STSA_N:
2749 case GST_H265_NAL_SLICE_STSA_R:
2750 case GST_H265_NAL_SLICE_RADL_N:
2751 case GST_H265_NAL_SLICE_RADL_R:
2752 case GST_H265_NAL_SLICE_RASL_N:
2753 case GST_H265_NAL_SLICE_RASL_R:
2754 case GST_H265_NAL_SLICE_BLA_W_LP:
2755 case GST_H265_NAL_SLICE_BLA_W_RADL:
2756 case GST_H265_NAL_SLICE_BLA_N_LP:
2757 case GST_H265_NAL_SLICE_IDR_W_RADL:
2758 case GST_H265_NAL_SLICE_IDR_N_LP:
2759 case GST_H265_NAL_SLICE_CRA_NUT:
2760 status = parse_slice (decoder, unit);
2763 status = GST_VAAPI_DECODER_STATUS_SUCCESS;
2766 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2770 flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_END |
2771 GST_VAAPI_DECODER_UNIT_FLAG_AU_END;
2773 switch (pi->nalu.type) {
2774 case GST_H265_NAL_AUD:
2775 flags |= GST_VAAPI_DECODER_UNIT_FLAG_AU_START;
2776 flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_START;
2778 case GST_H265_NAL_FD:
2779 flags |= GST_VAAPI_DECODER_UNIT_FLAG_SKIP;
2781 case GST_H265_NAL_EOB:
2782 flags |= GST_VAAPI_DECODER_UNIT_FLAG_STREAM_END;
2784 case GST_H265_NAL_SUFFIX_SEI:
2785 case GST_H265_NAL_EOS:
2786 flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_END;
2787 flags |= GST_VAAPI_DECODER_UNIT_FLAG_AU_END;
2789 case GST_H265_NAL_VPS:
2790 case GST_H265_NAL_SPS:
2791 case GST_H265_NAL_PPS:
2792 case GST_H265_NAL_PREFIX_SEI:
2793 flags |= GST_VAAPI_DECODER_UNIT_FLAG_AU_START;
2794 flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_START;
2796 case GST_H265_NAL_SLICE_TRAIL_N:
2797 case GST_H265_NAL_SLICE_TRAIL_R:
2798 case GST_H265_NAL_SLICE_TSA_N:
2799 case GST_H265_NAL_SLICE_TSA_R:
2800 case GST_H265_NAL_SLICE_STSA_N:
2801 case GST_H265_NAL_SLICE_STSA_R:
2802 case GST_H265_NAL_SLICE_RADL_N:
2803 case GST_H265_NAL_SLICE_RADL_R:
2804 case GST_H265_NAL_SLICE_RASL_N:
2805 case GST_H265_NAL_SLICE_RASL_R:
2806 case GST_H265_NAL_SLICE_BLA_W_LP:
2807 case GST_H265_NAL_SLICE_BLA_W_RADL:
2808 case GST_H265_NAL_SLICE_BLA_N_LP:
2809 case GST_H265_NAL_SLICE_IDR_W_RADL:
2810 case GST_H265_NAL_SLICE_IDR_N_LP:
2811 case GST_H265_NAL_SLICE_CRA_NUT:
2812 flags |= GST_VAAPI_DECODER_UNIT_FLAG_SLICE;
2813 if (priv->prev_pi &&
2814 (priv->prev_pi->flags & GST_VAAPI_DECODER_UNIT_FLAG_AU_END)) {
2815 flags |= GST_VAAPI_DECODER_UNIT_FLAG_AU_START |
2816 GST_VAAPI_DECODER_UNIT_FLAG_FRAME_START;
2817 } else if (is_new_picture (pi, priv->prev_slice_pi)) {
2818 flags |= GST_VAAPI_DECODER_UNIT_FLAG_FRAME_START;
2819 if (is_new_access_unit (pi, priv->prev_slice_pi))
2820 flags |= GST_VAAPI_DECODER_UNIT_FLAG_AU_START;
2822 gst_vaapi_parser_info_h265_replace (&priv->prev_slice_pi, pi);
2823 if (!pi->data.slice_hdr.dependent_slice_segment_flag)
2824 gst_vaapi_parser_info_h265_replace (&priv->prev_independent_slice_pi,
2831 if ((flags & GST_VAAPI_DECODER_UNIT_FLAGS_AU) && priv->prev_slice_pi)
2832 priv->prev_slice_pi->flags |= GST_VAAPI_DECODER_UNIT_FLAG_AU_END;
2833 GST_VAAPI_DECODER_UNIT_FLAG_SET (unit, flags);
2834 pi->nalu.data = NULL;
2835 pi->state = priv->parser_state;
2837 gst_vaapi_parser_info_h265_replace (&priv->prev_pi, pi);
2838 return GST_VAAPI_DECODER_STATUS_SUCCESS;
2841 static GstVaapiDecoderStatus
2842 gst_vaapi_decoder_h265_decode (GstVaapiDecoder * base_decoder,
2843 GstVaapiDecoderUnit * unit)
2845 GstVaapiDecoderH265 *const decoder =
2846 GST_VAAPI_DECODER_H265_CAST (base_decoder);
2847 GstVaapiDecoderStatus status;
2848 status = ensure_decoder (decoder);
2849 if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
2851 return decode_unit (decoder, unit);
2854 static GstVaapiDecoderStatus
2855 gst_vaapi_decoder_h265_start_frame (GstVaapiDecoder * base_decoder,
2856 GstVaapiDecoderUnit * unit)
2858 GstVaapiDecoderH265 *const decoder =
2859 GST_VAAPI_DECODER_H265_CAST (base_decoder);
2860 return decode_picture (decoder, unit);
2863 static GstVaapiDecoderStatus
2864 gst_vaapi_decoder_h265_end_frame (GstVaapiDecoder * base_decoder)
2866 GstVaapiDecoderH265 *const decoder =
2867 GST_VAAPI_DECODER_H265_CAST (base_decoder);
2869 return decode_current_picture (decoder);
2872 static GstVaapiDecoderStatus
2873 gst_vaapi_decoder_h265_flush (GstVaapiDecoder * base_decoder)
2875 GstVaapiDecoderH265 *const decoder =
2876 GST_VAAPI_DECODER_H265_CAST (base_decoder);
2877 dpb_flush (decoder);
2878 return GST_VAAPI_DECODER_STATUS_SUCCESS;
2882 gst_vaapi_decoder_h265_class_init (GstVaapiDecoderH265Class * klass)
2884 GstVaapiMiniObjectClass *const object_class =
2885 GST_VAAPI_MINI_OBJECT_CLASS (klass);
2886 GstVaapiDecoderClass *const decoder_class = GST_VAAPI_DECODER_CLASS (klass);
2887 object_class->size = sizeof (GstVaapiDecoderH265);
2888 object_class->finalize = (GDestroyNotify) gst_vaapi_decoder_finalize;
2889 decoder_class->create = gst_vaapi_decoder_h265_create;
2890 decoder_class->destroy = gst_vaapi_decoder_h265_destroy;
2891 decoder_class->parse = gst_vaapi_decoder_h265_parse;
2892 decoder_class->decode = gst_vaapi_decoder_h265_decode;
2893 decoder_class->start_frame = gst_vaapi_decoder_h265_start_frame;
2894 decoder_class->end_frame = gst_vaapi_decoder_h265_end_frame;
2895 decoder_class->flush = gst_vaapi_decoder_h265_flush;
2896 decoder_class->decode_codec_data = gst_vaapi_decoder_h265_decode_codec_data;
2899 static inline const GstVaapiDecoderClass *
2900 gst_vaapi_decoder_h265_class (void)
2902 static GstVaapiDecoderH265Class g_class;
2903 static gsize g_class_init = FALSE;
2904 if (g_once_init_enter (&g_class_init)) {
2905 gst_vaapi_decoder_h265_class_init (&g_class);
2906 g_once_init_leave (&g_class_init, TRUE);
2908 return GST_VAAPI_DECODER_CLASS (&g_class);
2912 * gst_vaapi_decoder_h265_set_alignment:
2913 * @decoder: a #GstVaapiDecoderH265
2914 * @alignment: the #GstVaapiStreamAlignH265
2916 * Specifies how stream buffers are aligned / fed, i.e. the boundaries
2917 * of each buffer that is supplied to the decoder. This could be no
2918 * specific alignment, NAL unit boundaries, or access unit boundaries.
2921 gst_vaapi_decoder_h265_set_alignment (GstVaapiDecoderH265 * decoder,
2922 GstVaapiStreamAlignH265 alignment)
2924 g_return_if_fail (decoder != NULL);
2925 decoder->priv.stream_alignment = alignment;
2929 * gst_vaapi_decoder_h265_new:
2930 * @display: a #GstVaapiDisplay
2931 * @caps: a #GstCaps holding codec information
2933 * Creates a new #GstVaapiDecoder for MPEG-2 decoding. The @caps can
2934 * hold extra information like codec-data and pictured coded size.
2936 * Return value: the newly allocated #GstVaapiDecoder object
2939 gst_vaapi_decoder_h265_new (GstVaapiDisplay * display, GstCaps * caps)
2941 return gst_vaapi_decoder_new (gst_vaapi_decoder_h265_class (), display, caps);