2 * Copyright (C) 2020 Igalia, S.L.
3 * Author: Víctor Jáquez <vjaquez@igalia.com>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the0
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * SECTION:element-vavp9dec
24 * @short_description: A VA-API based VP9 video decoder
26 * vavp9dec decodes VP9 bitstreams to VA surfaces using the
27 * installed and chosen [VA-API](https://01.org/linuxmedia/vaapi)
30 * The decoding surfaces can be mapped onto main memory as video
33 * ## Example launch line
35 * gst-launch-1.0 filesrc location=sample.webm ! parsebin ! vavp9dec ! autovideosink
46 #include "gstvavp9dec.h"
48 #include "gstvabasedec.h"
50 GST_DEBUG_CATEGORY_STATIC (gst_va_vp9dec_debug);
51 #ifndef GST_DISABLE_GST_DEBUG
52 #define GST_CAT_DEFAULT gst_va_vp9dec_debug
54 #define GST_CAT_DEFAULT NULL
57 #define GST_VA_VP9_DEC(obj) ((GstVaVp9Dec *) obj)
58 #define GST_VA_VP9_DEC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_FROM_INSTANCE (obj), GstVaVp9DecClass))
59 #define GST_VA_VP9_DEC_CLASS(klass) ((GstVaVp9DecClass *) klass)
61 typedef struct _GstVaVp9Dec GstVaVp9Dec;
62 typedef struct _GstVaVp9DecClass GstVaVp9DecClass;
64 struct _GstVaVp9DecClass
66 GstVaBaseDecClass parent_class;
72 GstVp9Segmentation segmentation[GST_VP9_MAX_SEGMENTS];
75 static GstElementClass *parent_class = NULL;
78 static const gchar *src_caps_str =
79 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_VA,
81 GST_VIDEO_CAPS_MAKE ("{ NV12 }");
84 static const gchar *sink_caps_str = "video/x-vp9";
87 _get_rtformat (GstVaVp9Dec * self, GstVP9Profile profile,
88 GstVp9BitDepth bit_depth, gint subsampling_x, gint subsampling_y)
91 case GST_VP9_PROFILE_0:
92 return VA_RT_FORMAT_YUV420;
93 case GST_VP9_PROFILE_1:
94 if (subsampling_x == 1 && subsampling_y == 0)
95 return VA_RT_FORMAT_YUV422;
96 else if (subsampling_x == 0 && subsampling_y == 0)
97 return VA_RT_FORMAT_YUV444;
99 case GST_VP9_PROFILE_2:
100 if (bit_depth == GST_VP9_BIT_DEPTH_10)
101 return VA_RT_FORMAT_YUV420_10;
102 else if (bit_depth == GST_VP9_BIT_DEPTH_12)
103 return VA_RT_FORMAT_YUV420_12;
105 case GST_VP9_PROFILE_3:
106 if (subsampling_x == 1 && subsampling_y == 0) {
107 if (bit_depth == GST_VP9_BIT_DEPTH_10)
108 return VA_RT_FORMAT_YUV422_10;
109 else if (bit_depth == GST_VP9_BIT_DEPTH_12)
110 return VA_RT_FORMAT_YUV422_12;
111 } else if (subsampling_x == 0 && subsampling_y == 0) {
112 if (bit_depth == GST_VP9_BIT_DEPTH_10)
113 return VA_RT_FORMAT_YUV444_10;
114 else if (bit_depth == GST_VP9_BIT_DEPTH_12)
115 return VA_RT_FORMAT_YUV444_12;
122 GST_ERROR_OBJECT (self, "Unsupported chroma format");
127 _get_profile (GstVaVp9Dec * self, GstVP9Profile profile)
130 case GST_VP9_PROFILE_0:
131 return VAProfileVP9Profile0;
132 case GST_VP9_PROFILE_1:
133 return VAProfileVP9Profile1;
134 case GST_VP9_PROFILE_2:
135 return VAProfileVP9Profile2;
136 case GST_VP9_PROFILE_3:
137 return VAProfileVP9Profile3;
142 GST_ERROR_OBJECT (self, "Unsupported profile");
143 return VAProfileNone;
147 gst_va_vp9_new_sequence (GstVp9Decoder * decoder,
148 const GstVp9FrameHeader * frame_hdr, gint max_dpb_size)
150 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
151 GstVaVp9Dec *self = GST_VA_VP9_DEC (decoder);
152 GstVideoInfo *info = &base->output_info;
154 gboolean negotiation_needed = FALSE;
157 profile = _get_profile (self, frame_hdr->profile);
158 if (profile == VAProfileNone)
159 return GST_FLOW_NOT_NEGOTIATED;
161 if (!gst_va_decoder_has_profile (base->decoder, profile)) {
162 GST_ERROR_OBJECT (self, "Profile %s is not supported",
163 gst_va_profile_name (profile));
164 return GST_FLOW_NOT_NEGOTIATED;
167 rt_format = _get_rtformat (self, frame_hdr->profile, frame_hdr->bit_depth,
168 frame_hdr->subsampling_x, frame_hdr->subsampling_y);
170 return GST_FLOW_NOT_NEGOTIATED;
172 if (!gst_va_decoder_config_is_equal (base->decoder, profile,
173 rt_format, frame_hdr->width, frame_hdr->height)) {
174 base->profile = profile;
175 GST_VIDEO_INFO_WIDTH (info) = base->width = frame_hdr->width;
176 GST_VIDEO_INFO_HEIGHT (info) = base->height = frame_hdr->height;
177 base->rt_format = rt_format;
178 negotiation_needed = TRUE;
181 base->min_buffers = GST_VP9_REF_FRAMES;
182 base->need_negotiation = negotiation_needed;
183 g_clear_pointer (&base->input_state, gst_video_codec_state_unref);
184 base->input_state = gst_video_codec_state_ref (decoder->input_state);
190 _check_resolution_change (GstVaVp9Dec * self, GstVp9Picture * picture)
192 GstVaBaseDec *base = GST_VA_BASE_DEC (self);
193 GstVideoInfo *info = &base->output_info;
194 const GstVp9FrameHeader *frame_hdr = &picture->frame_hdr;
196 if ((base->width != frame_hdr->width) || base->height != frame_hdr->height) {
197 GST_VIDEO_INFO_WIDTH (info) = base->width = frame_hdr->width;
198 GST_VIDEO_INFO_HEIGHT (info) = base->height = frame_hdr->height;
200 base->need_negotiation = TRUE;
201 if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) {
202 GST_ERROR_OBJECT (self, "Resolution changed, but failed to"
203 " negotiate with downstream");
204 return GST_FLOW_NOT_NEGOTIATED;
206 /* @TODO: if negotiation fails, decoder should resize output
207 * frame. For that we would need an auxiliar allocator, and
208 * later use GstVaFilter or GstVideoConverter. */
216 gst_va_vp9_dec_new_picture (GstVp9Decoder * decoder,
217 GstVideoCodecFrame * frame, GstVp9Picture * picture)
220 GstVaVp9Dec *self = GST_VA_VP9_DEC (decoder);
221 GstVaDecodePicture *pic;
222 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
224 ret = _check_resolution_change (self, picture);
225 if (ret != GST_FLOW_OK)
228 ret = gst_va_base_dec_prepare_output_frame (base, frame);
229 if (ret != GST_FLOW_OK)
232 pic = gst_va_decode_picture_new (base->decoder, frame->output_buffer);
234 gst_vp9_picture_set_user_data (picture, pic,
235 (GDestroyNotify) gst_va_decode_picture_free);
237 GST_LOG_OBJECT (self, "New va decode picture %p - %#x", pic,
238 gst_va_decode_picture_get_surface (pic));
244 GST_WARNING_OBJECT (self, "Failed to allocated output buffer, return %s",
245 gst_flow_get_name (ret));
250 static inline gboolean
251 _fill_param (GstVp9Decoder * decoder, GstVp9Picture * picture, GstVp9Dpb * dpb)
253 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
254 GstVaDecodePicture *va_pic;
255 const GstVp9FrameHeader *frame_hdr = &picture->frame_hdr;
256 const GstVp9LoopFilterParams *lfp = &frame_hdr->loop_filter_params;
257 const GstVp9SegmentationParams *sp = &frame_hdr->segmentation_params;
258 VADecPictureParameterBufferVP9 pic_param;
262 pic_param = (VADecPictureParameterBufferVP9) {
263 .frame_width = base->width,
264 .frame_height = base->height,
267 .subsampling_x = frame_hdr->subsampling_x,
268 .subsampling_y = frame_hdr->subsampling_x,
269 .frame_type = frame_hdr->frame_type,
270 .show_frame = frame_hdr->show_frame,
271 .error_resilient_mode = frame_hdr->error_resilient_mode,
272 .intra_only = frame_hdr->intra_only,
273 .allow_high_precision_mv = frame_hdr->allow_high_precision_mv,
274 .mcomp_filter_type = frame_hdr->interpolation_filter,
275 .frame_parallel_decoding_mode = frame_hdr->frame_parallel_decoding_mode,
276 .reset_frame_context = frame_hdr->reset_frame_context,
277 .refresh_frame_context = frame_hdr->refresh_frame_context,
278 .frame_context_idx = frame_hdr->frame_context_idx,
280 .segmentation_enabled = sp->segmentation_enabled,
281 .segmentation_temporal_update = sp->segmentation_temporal_update,
282 .segmentation_update_map = sp->segmentation_update_map,
285 frame_hdr->ref_frame_idx[GST_VP9_REF_FRAME_LAST - 1],
286 .last_ref_frame_sign_bias =
287 frame_hdr->ref_frame_sign_bias[GST_VP9_REF_FRAME_LAST],
289 frame_hdr->ref_frame_idx[GST_VP9_REF_FRAME_GOLDEN - 1],
290 .golden_ref_frame_sign_bias =
291 frame_hdr->ref_frame_sign_bias[GST_VP9_REF_FRAME_GOLDEN],
293 frame_hdr->ref_frame_idx[GST_VP9_REF_FRAME_ALTREF - 1],
294 .alt_ref_frame_sign_bias =
295 frame_hdr->ref_frame_sign_bias[GST_VP9_REF_FRAME_ALTREF],
297 .lossless_flag = frame_hdr->lossless_flag,
300 .filter_level = lfp->loop_filter_level,
301 .sharpness_level = lfp->loop_filter_sharpness,
302 .log2_tile_rows = frame_hdr->tile_rows_log2,
303 .log2_tile_columns = frame_hdr->tile_cols_log2,
305 .frame_header_length_in_bytes = frame_hdr->frame_header_length_in_bytes,
306 .first_partition_size = frame_hdr->header_size_in_bytes,
308 .profile = frame_hdr->profile,
309 .bit_depth = frame_hdr->bit_depth
313 memcpy (pic_param.mb_segment_tree_probs, sp->segmentation_tree_probs,
314 sizeof (sp->segmentation_tree_probs));
316 if (sp->segmentation_temporal_update) {
317 memcpy (pic_param.segment_pred_probs, sp->segmentation_pred_prob,
318 sizeof (sp->segmentation_pred_prob));
320 memset (pic_param.segment_pred_probs, 255,
321 sizeof (pic_param.segment_pred_probs));
324 for (i = 0; i < GST_VP9_REF_FRAMES; i++) {
325 if (dpb->pic_list[i]) {
326 GstVaDecodePicture *va_pic =
327 gst_vp9_picture_get_user_data (dpb->pic_list[i]);
329 pic_param.reference_frames[i] =
330 gst_va_decode_picture_get_surface (va_pic);
332 pic_param.reference_frames[i] = VA_INVALID_ID;
336 va_pic = gst_vp9_picture_get_user_data (picture);
338 return gst_va_decoder_add_param_buffer (base->decoder, va_pic,
339 VAPictureParameterBufferType, &pic_param, sizeof (pic_param));
343 _update_segmentation (GstVaVp9Dec * self, GstVp9FrameHeader * header)
345 const GstVp9LoopFilterParams *lfp = &header->loop_filter_params;
346 const GstVp9QuantizationParams *qp = &header->quantization_params;
347 const GstVp9SegmentationParams *sp = &header->segmentation_params;
348 guint8 n_shift = lfp->loop_filter_level >> 5;
351 for (i = 0; i < GST_VP9_MAX_SEGMENTS; i++) {
352 gint16 luma_dc_quant_scale;
353 gint16 luma_ac_quant_scale;
354 gint16 chroma_dc_quant_scale;
355 gint16 chroma_ac_quant_scale;
357 guint8 lvl_lookup[GST_VP9_MAX_REF_LF_DELTAS][GST_VP9_MAX_MODE_LF_DELTAS];
358 gint lvl_seg = lfp->loop_filter_level;
360 /* 8.6.1 Dequantization functions */
361 qindex = gst_vp9_get_qindex (sp, qp, i);
362 luma_dc_quant_scale =
363 gst_vp9_get_dc_quant (qindex, qp->delta_q_y_dc, header->bit_depth);
364 luma_ac_quant_scale = gst_vp9_get_ac_quant (qindex, 0, header->bit_depth);
365 chroma_dc_quant_scale =
366 gst_vp9_get_dc_quant (qindex, qp->delta_q_uv_dc, header->bit_depth);
367 chroma_ac_quant_scale =
368 gst_vp9_get_ac_quant (qindex, qp->delta_q_uv_ac, header->bit_depth);
370 if (!lfp->loop_filter_level) {
371 memset (lvl_lookup, 0, sizeof (lvl_lookup));
373 /* 8.8.1 Loop filter frame init process */
374 if (gst_vp9_seg_feature_active (sp, i, GST_VP9_SEG_LVL_ALT_L)) {
375 if (sp->segmentation_abs_or_delta_update) {
376 lvl_seg = sp->feature_data[i][GST_VP9_SEG_LVL_ALT_L];
378 lvl_seg += sp->feature_data[i][GST_VP9_SEG_LVL_ALT_L];
381 lvl_seg = CLAMP (lvl_seg, 0, GST_VP9_MAX_LOOP_FILTER);
384 if (!lfp->loop_filter_delta_enabled) {
385 memset (lvl_lookup, lvl_seg, sizeof (lvl_lookup));
388 gint intra_lvl = lvl_seg +
389 (lfp->loop_filter_ref_deltas[GST_VP9_REF_FRAME_INTRA] << n_shift);
391 memcpy (lvl_lookup, self->segmentation[i].filter_level,
392 sizeof (lvl_lookup));
394 lvl_lookup[GST_VP9_REF_FRAME_INTRA][0] =
395 CLAMP (intra_lvl, 0, GST_VP9_MAX_LOOP_FILTER);
396 for (ref = GST_VP9_REF_FRAME_LAST; ref < GST_VP9_REF_FRAME_MAX; ref++) {
397 for (mode = 0; mode < GST_VP9_MAX_MODE_LF_DELTAS; mode++) {
398 intra_lvl = lvl_seg + (lfp->loop_filter_ref_deltas[ref] << n_shift)
399 + (lfp->loop_filter_mode_deltas[mode] << n_shift);
400 lvl_lookup[ref][mode] =
401 CLAMP (intra_lvl, 0, GST_VP9_MAX_LOOP_FILTER);
408 self->segmentation[i] = (GstVp9Segmentation) {
409 .luma_dc_quant_scale = luma_dc_quant_scale,
410 .luma_ac_quant_scale = luma_ac_quant_scale,
411 .chroma_dc_quant_scale = chroma_dc_quant_scale,
412 .chroma_ac_quant_scale = chroma_ac_quant_scale,
414 .reference_frame_enabled = sp->feature_enabled[i][GST_VP9_SEG_LVL_REF_FRAME],
415 .reference_frame = sp->feature_data[i][GST_VP9_SEG_LVL_REF_FRAME],
416 .reference_skip = sp->feature_enabled[i][GST_VP9_SEG_SEG_LVL_SKIP],
420 memcpy (self->segmentation[i].filter_level, lvl_lookup,
421 sizeof (lvl_lookup));
425 static inline gboolean
426 _fill_slice (GstVp9Decoder * decoder, GstVp9Picture * picture)
428 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
429 GstVaVp9Dec *self = GST_VA_VP9_DEC (decoder);
430 GstVaDecodePicture *va_pic;
431 const GstVp9Segmentation *seg;
432 VASliceParameterBufferVP9 slice_param;
435 _update_segmentation (self, &picture->frame_hdr);
438 slice_param = (VASliceParameterBufferVP9) {
439 .slice_data_size = picture->size,
440 .slice_data_offset = 0,
441 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
445 for (i = 0; i < GST_VP9_MAX_SEGMENTS; i++) {
446 seg = &self->segmentation[i];
449 slice_param.seg_param[i] = (VASegmentParameterVP9) {
450 .segment_flags.fields = {
451 .segment_reference_enabled = seg->reference_frame_enabled,
452 .segment_reference = seg->reference_frame,
453 .segment_reference_skipped = seg->reference_skip,
455 .luma_dc_quant_scale = seg->luma_dc_quant_scale,
456 .luma_ac_quant_scale = seg->luma_ac_quant_scale,
457 .chroma_dc_quant_scale = seg->chroma_dc_quant_scale,
458 .chroma_ac_quant_scale = seg->chroma_ac_quant_scale,
462 memcpy (slice_param.seg_param[i].filter_level, seg->filter_level,
463 sizeof (slice_param.seg_param[i].filter_level));
466 va_pic = gst_vp9_picture_get_user_data (picture);
468 return gst_va_decoder_add_slice_buffer (base->decoder, va_pic, &slice_param,
469 sizeof (slice_param), (gpointer) picture->data, picture->size);
473 gst_va_vp9_decode_picture (GstVp9Decoder * decoder, GstVp9Picture * picture,
476 if (_fill_param (decoder, picture, dpb) && _fill_slice (decoder, picture))
479 return GST_FLOW_ERROR;
483 gst_va_vp9_dec_end_picture (GstVp9Decoder * decoder, GstVp9Picture * picture)
485 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
486 GstVaDecodePicture *va_pic;
488 GST_LOG_OBJECT (base, "end picture %p", picture);
490 va_pic = gst_vp9_picture_get_user_data (picture);
492 if (!gst_va_decoder_decode (base->decoder, va_pic))
493 return GST_FLOW_ERROR;
499 gst_va_vp9_dec_output_picture (GstVp9Decoder * decoder,
500 GstVideoCodecFrame * frame, GstVp9Picture * picture)
502 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
503 GstVaVp9Dec *self = GST_VA_VP9_DEC (decoder);
504 GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
507 GST_LOG_OBJECT (self, "Outputting picture %p", picture);
509 ret = gst_va_base_dec_process_output (base, frame, picture->discont_state, 0);
510 gst_vp9_picture_unref (picture);
513 return gst_video_decoder_finish_frame (vdec, frame);
514 return GST_FLOW_ERROR;
517 static GstVp9Picture *
518 gst_va_vp9_dec_duplicate_picture (GstVp9Decoder * decoder,
519 GstVideoCodecFrame * frame, GstVp9Picture * picture)
521 GstVaDecodePicture *va_pic, *va_dup;
522 GstVp9Picture *new_picture;
524 if (_check_resolution_change (GST_VA_VP9_DEC (decoder), picture) !=
529 va_pic = gst_vp9_picture_get_user_data (picture);
530 va_dup = gst_va_decode_picture_dup (va_pic);
532 new_picture = gst_vp9_picture_new ();
533 new_picture->frame_hdr = picture->frame_hdr;
535 frame->output_buffer = gst_buffer_ref (va_dup->gstbuffer);
537 gst_vp9_picture_set_user_data (picture, va_dup,
538 (GDestroyNotify) gst_va_decode_picture_free);
544 gst_va_vp9_dec_negotiate (GstVideoDecoder * decoder)
546 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
547 GstVaVp9Dec *self = GST_VA_VP9_DEC (decoder);
550 /* Ignore downstream renegotiation request. */
551 if (!base->need_negotiation)
554 base->need_negotiation = FALSE;
557 /* VP9 profile entry should have the ability to handle dynamical
558 * resolution changes. If only the resolution changes, we should not
559 * re-create the config and context. */
560 if (gst_va_decoder_is_open (base->decoder)) {
561 VAProfile cur_profile;
563 gint cur_width, cur_height;
565 if (!gst_va_decoder_get_config (base->decoder, &cur_profile,
566 &cur_rtformat, &cur_width, &cur_height))
569 if (base->profile == cur_profile && base->rt_format == cur_rtformat) {
570 if (!gst_va_decoder_update_frame_size (base->decoder, base->width,
574 GST_INFO_OBJECT (self, "dynamical resolution changes from %dx%d to"
575 " %dx%d", cur_width, cur_height, base->width, base->height);
579 if (!gst_va_decoder_close (base->decoder))
585 if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
588 if (!gst_va_decoder_set_frame_size (base->decoder, base->width,
593 if (!gst_va_base_dec_set_output_state (base))
596 return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
600 gst_va_vp9_dec_dispose (GObject * object)
602 gst_va_base_dec_close (GST_VIDEO_DECODER (object));
603 G_OBJECT_CLASS (parent_class)->dispose (object);
607 gst_va_vp9_dec_class_init (gpointer g_class, gpointer class_data)
609 GstCaps *src_doc_caps, *sink_doc_caps;
610 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
611 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
612 GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_CLASS (g_class);
613 GstVp9DecoderClass *vp9_class = GST_VP9_DECODER_CLASS (g_class);
614 struct CData *cdata = class_data;
617 if (cdata->description) {
618 long_name = g_strdup_printf ("VA-API VP9 Decoder in %s",
621 long_name = g_strdup ("VA-API VP9 Decoder");
624 gst_element_class_set_metadata (element_class, long_name,
625 "Codec/Decoder/Video/Hardware", "VA-API based VP9 video decoder",
626 "Víctor Jáquez <vjaquez@igalia.com>");
628 sink_doc_caps = gst_caps_from_string (sink_caps_str);
629 src_doc_caps = gst_caps_from_string (src_caps_str);
631 parent_class = g_type_class_peek_parent (g_class);
634 * GstVaVp9Dec:device-path:
636 * It shows the DRM device path used for the VA operation, if any.
640 gst_va_base_dec_class_init (GST_VA_BASE_DEC_CLASS (g_class), VP9,
641 cdata->render_device_path, cdata->sink_caps, cdata->src_caps,
642 src_doc_caps, sink_doc_caps);
644 gobject_class->dispose = gst_va_vp9_dec_dispose;
646 decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_va_vp9_dec_negotiate);
648 vp9_class->new_sequence = GST_DEBUG_FUNCPTR (gst_va_vp9_new_sequence);
649 vp9_class->new_picture = GST_DEBUG_FUNCPTR (gst_va_vp9_dec_new_picture);
650 vp9_class->decode_picture = GST_DEBUG_FUNCPTR (gst_va_vp9_decode_picture);
651 vp9_class->end_picture = GST_DEBUG_FUNCPTR (gst_va_vp9_dec_end_picture);
652 vp9_class->output_picture = GST_DEBUG_FUNCPTR (gst_va_vp9_dec_output_picture);
653 vp9_class->duplicate_picture =
654 GST_DEBUG_FUNCPTR (gst_va_vp9_dec_duplicate_picture);
657 g_free (cdata->description);
658 g_free (cdata->render_device_path);
659 gst_caps_unref (cdata->src_caps);
660 gst_caps_unref (cdata->sink_caps);
665 gst_va_vp9_dec_init (GTypeInstance * instance, gpointer g_class)
667 gst_va_base_dec_init (GST_VA_BASE_DEC (instance), GST_CAT_DEFAULT);
670 /* This element doesn't parse supreframes. Let's delegate it to the
673 _complete_sink_caps (GstCaps * sinkcaps)
675 gst_caps_set_simple (sinkcaps, "alignment", G_TYPE_STRING, "frame", NULL);
676 return gst_caps_ref (sinkcaps);
680 _register_debug_category (gpointer data)
682 GST_DEBUG_CATEGORY_INIT (gst_va_vp9dec_debug, "vavp9dec", 0,
689 gst_va_vp9_dec_register (GstPlugin * plugin, GstVaDevice * device,
690 GstCaps * sink_caps, GstCaps * src_caps, guint rank)
692 static GOnce debug_once = G_ONCE_INIT;
694 GTypeInfo type_info = {
695 .class_size = sizeof (GstVaVp9DecClass),
696 .class_init = gst_va_vp9_dec_class_init,
697 .instance_size = sizeof (GstVaVp9Dec),
698 .instance_init = gst_va_vp9_dec_init,
702 gchar *type_name, *feature_name;
704 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
705 g_return_val_if_fail (GST_IS_VA_DEVICE (device), FALSE);
706 g_return_val_if_fail (GST_IS_CAPS (sink_caps), FALSE);
707 g_return_val_if_fail (GST_IS_CAPS (src_caps), FALSE);
709 cdata = g_new (struct CData, 1);
710 cdata->description = NULL;
711 cdata->render_device_path = g_strdup (device->render_device_path);
712 cdata->sink_caps = _complete_sink_caps (sink_caps);
713 cdata->src_caps = gst_caps_ref (src_caps);
715 /* class data will be leaked if the element never gets instantiated */
716 GST_MINI_OBJECT_FLAG_SET (sink_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
717 GST_MINI_OBJECT_FLAG_SET (src_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
719 type_info.class_data = cdata;
721 /* The first decoder to be registered should use a constant name,
722 * like vavp9dec, for any additional decoders, we create unique
723 * names, using inserting the render device name. */
724 if (device->index == 0) {
725 type_name = g_strdup ("GstVaVp9Dec");
726 feature_name = g_strdup ("vavp9dec");
728 gchar *basename = g_path_get_basename (device->render_device_path);
729 type_name = g_strdup_printf ("GstVa%sVp9Dec", basename);
730 feature_name = g_strdup_printf ("va%svp9dec", basename);
731 cdata->description = basename;
733 /* lower rank for non-first device */
738 g_once (&debug_once, _register_debug_category, NULL);
740 type = g_type_register_static (GST_TYPE_VP9_DECODER,
741 type_name, &type_info, 0);
743 ret = gst_element_register (plugin, feature_name, rank, type);
746 g_free (feature_name);