2 * Copyright (C) 2020 Intel Corporation
3 * Author: He Junyan <junyan.he@intel.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-vampeg2dec
24 * @short_description: A VA-API based Mpeg2 video decoder
26 * vampeg2dec decodes Mpeg2 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.mpg ! parsebin ! vampeg2dec ! autovideosink
46 #include "gstvampeg2dec.h"
48 #include "gstvabasedec.h"
50 GST_DEBUG_CATEGORY_STATIC (gst_va_mpeg2dec_debug);
51 #ifndef GST_DISABLE_GST_DEBUG
52 #define GST_CAT_DEFAULT gst_va_mpeg2dec_debug
54 #define GST_CAT_DEFAULT NULL
57 #define GST_VA_MPEG2_DEC(obj) ((GstVaMpeg2Dec *) obj)
58 #define GST_VA_MPEG2_DEC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), G_TYPE_FROM_INSTANCE (obj), GstVaMpeg2DecClass))
59 #define GST_VA_MPEG2_DEC_CLASS(klass) ((GstVaMpeg2DecClass *) klass)
61 typedef struct _GstVaMpeg2Dec GstVaMpeg2Dec;
62 typedef struct _GstVaMpeg2DecClass GstVaMpeg2DecClass;
64 struct _GstVaMpeg2DecClass
66 GstVaBaseDecClass parent_class;
74 gboolean need_negotiation;
76 GstMpegVideoSequenceHdr seq;
80 static const gchar *src_caps_str =
81 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_VA,
83 GST_VIDEO_CAPS_MAKE ("{ NV12 }");
86 static const gchar *sink_caps_str = "video/x-mpeg2";
89 gst_va_mpeg2_dec_negotiate (GstVideoDecoder * decoder)
91 GstCapsFeatures *capsfeatures = NULL;
92 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
93 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
94 GstVideoFormat format = GST_VIDEO_FORMAT_UNKNOWN;
95 GstMpeg2Decoder *mpeg2dec = GST_MPEG2_DECODER (decoder);
97 /* Ignore downstream renegotiation request. */
98 if (!self->need_negotiation)
101 self->need_negotiation = FALSE;
103 if (gst_va_decoder_is_open (base->decoder)
104 && !gst_va_decoder_close (base->decoder))
107 if (!gst_va_decoder_open (base->decoder, base->profile, base->rt_format))
110 if (!gst_va_decoder_set_frame_size (base->decoder, base->width, base->height))
113 if (base->output_state)
114 gst_video_codec_state_unref (base->output_state);
116 gst_va_base_dec_get_preferred_format_and_caps_features (base, &format,
120 gst_video_decoder_set_output_state (decoder, format,
121 base->width, base->height, mpeg2dec->input_state);
123 if (!self->progressive)
124 base->output_state->info.interlace_mode = GST_VIDEO_INTERLACE_MODE_MIXED;
126 base->output_state->caps = gst_video_info_to_caps (&base->output_state->info);
128 gst_caps_set_features_simple (base->output_state->caps, capsfeatures);
130 GST_INFO_OBJECT (self, "Negotiated caps %" GST_PTR_FORMAT,
131 base->output_state->caps);
133 return GST_VIDEO_DECODER_CLASS (GST_VA_BASE_DEC_GET_PARENT_CLASS
134 (decoder))->negotiate (decoder);
138 _map_profile (GstMpegVideoProfile profile)
140 VAProfile p = VAProfileNone;
143 case GST_MPEG_VIDEO_PROFILE_SIMPLE:
144 p = VAProfileMPEG2Simple;
146 case GST_MPEG_VIDEO_PROFILE_MAIN:
147 p = VAProfileMPEG2Main;
158 _get_profile (GstVaMpeg2Dec * self, GstMpegVideoProfile profile,
159 const GstMpegVideoSequenceExt * seq_ext,
160 const GstMpegVideoSequenceScalableExt * seq_scalable_ext)
162 GstVaBaseDec *base = GST_VA_BASE_DEC (self);
163 VAProfile hw_profile;
165 hw_profile = _map_profile (profile);
166 if (hw_profile == VAProfileNone)
169 /* promote the profile if hw does not support, until we get one */
171 if (gst_va_decoder_has_profile (base->decoder, hw_profile))
174 /* Otherwise, try to map to a higher profile */
176 case GST_MPEG_VIDEO_PROFILE_SIMPLE:
177 hw_profile = VAProfileMPEG2Main;
179 case GST_MPEG_VIDEO_PROFILE_HIGH:
180 /* Try to map to main profile if no high profile specific bits used */
181 if (!seq_scalable_ext && (seq_ext && seq_ext->chroma_format == 1)) {
182 hw_profile = VAProfileMPEG2Main;
187 GST_ERROR_OBJECT (self, "profile %d is unsupported.", profile);
188 hw_profile = VAProfileNone;
191 } while (hw_profile != VAProfileNone);
197 _get_rtformat (GstVaMpeg2Dec * self, GstMpegVideoChromaFormat chroma_format)
201 switch (chroma_format) {
202 case GST_MPEG_VIDEO_CHROMA_420:
203 ret = VA_RT_FORMAT_YUV420;
205 case GST_MPEG_VIDEO_CHROMA_422:
206 ret = VA_RT_FORMAT_YUV422;
208 case GST_MPEG_VIDEO_CHROMA_444:
209 ret = VA_RT_FORMAT_YUV444;
212 GST_ERROR_OBJECT (self, "Unsupported chroma format: %d ", chroma_format);
220 gst_va_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder,
221 const GstMpegVideoSequenceHdr * seq,
222 const GstMpegVideoSequenceExt * seq_ext,
223 const GstMpegVideoSequenceDisplayExt * seq_display_ext,
224 const GstMpegVideoSequenceScalableExt * seq_scalable_ext)
226 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
227 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
229 GstMpegVideoProfile mpeg_profile;
230 gboolean negotiation_needed = FALSE;
233 gboolean progressive;
238 height = seq->height;
240 width = (width & 0x0fff) | ((guint32) seq_ext->horiz_size_ext << 12);
241 height = (height & 0x0fff) | ((guint32) seq_ext->vert_size_ext << 12);
244 mpeg_profile = GST_MPEG_VIDEO_PROFILE_MAIN;
246 mpeg_profile = seq_ext->profile;
248 profile = _get_profile (self, mpeg_profile, seq_ext, seq_scalable_ext);
249 if (profile == VAProfileNone)
250 return GST_FLOW_NOT_NEGOTIATED;
252 rt_format = _get_rtformat (self,
253 seq_ext ? seq_ext->chroma_format : GST_MPEG_VIDEO_CHROMA_420);
255 return GST_FLOW_NOT_NEGOTIATED;
257 if (!gst_va_decoder_config_is_equal (base->decoder, profile,
258 rt_format, width, height)) {
259 base->profile = profile;
260 base->rt_format = rt_format;
262 base->height = height;
264 negotiation_needed = TRUE;
266 GST_INFO_OBJECT (self, "Format changed to %s [%x] (%dx%d)",
267 gst_va_profile_name (profile), rt_format, base->width, base->height);
270 progressive = seq_ext ? seq_ext->progressive : 1;
271 if (self->progressive != progressive) {
272 self->progressive = progressive;
274 negotiation_needed = TRUE;
275 GST_INFO_OBJECT (self, "Interlaced mode changed to %d", !progressive);
278 base->need_valign = FALSE;
280 base->min_buffers = 2 + 4; /* max num pic references + scratch surfaces */
282 if (negotiation_needed) {
283 self->need_negotiation = TRUE;
284 if (!gst_video_decoder_negotiate (GST_VIDEO_DECODER (self))) {
285 GST_ERROR_OBJECT (self, "Failed to negotiate with downstream");
286 return GST_FLOW_NOT_NEGOTIATED;
294 gst_va_mpeg2_dec_new_picture (GstMpeg2Decoder * decoder,
295 GstVideoCodecFrame * frame, GstMpeg2Picture * picture)
298 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
299 GstVaDecodePicture *pic;
300 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
301 GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
303 ret = gst_video_decoder_allocate_output_frame (vdec, frame);
304 if (ret != GST_FLOW_OK)
307 pic = gst_va_decode_picture_new (base->decoder, frame->output_buffer);
309 gst_mpeg2_picture_set_user_data (picture, pic,
310 (GDestroyNotify) gst_va_decode_picture_free);
312 GST_LOG_OBJECT (self, "New va decode picture %p - %#x", pic,
313 gst_va_decode_picture_get_surface (pic));
319 GST_WARNING_OBJECT (self, "Failed to allocated output buffer, return %s",
320 gst_flow_get_name (ret));
326 gst_va_mpeg2_dec_new_field_picture (GstMpeg2Decoder * decoder,
327 const GstMpeg2Picture * first_field, GstMpeg2Picture * second_field)
329 GstVaDecodePicture *first_pic, *second_pic;
330 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
331 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
333 first_pic = gst_mpeg2_picture_get_user_data ((GstMpeg2Picture *) first_field);
335 return GST_FLOW_ERROR;
337 second_pic = gst_va_decode_picture_new (base->decoder, first_pic->gstbuffer);
338 gst_mpeg2_picture_set_user_data (second_field, second_pic,
339 (GDestroyNotify) gst_va_decode_picture_free);
341 GST_LOG_OBJECT (self, "New va decode picture %p - %#x", second_pic,
342 gst_va_decode_picture_get_surface (second_pic));
347 static inline guint32
348 _pack_f_code (guint8 f_code[2][2])
350 return (((guint32) f_code[0][0] << 12)
351 | ((guint32) f_code[0][1] << 8)
352 | ((guint32) f_code[1][0] << 4)
357 _copy_quant_matrix (guint8 dst[64], const guint8 src[64])
359 memcpy (dst, src, 64);
363 gst_va_mpeg2_dec_add_quant_matrix (GstMpeg2Decoder * decoder,
364 GstMpeg2Picture * picture, GstMpeg2Slice * slice)
366 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
367 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
368 GstMpegVideoQuantMatrixExt *const quant_matrix = slice->quant_matrix;
369 guint8 *intra_quant_matrix = NULL;
370 guint8 *non_intra_quant_matrix = NULL;
371 guint8 *chroma_intra_quant_matrix = NULL;
372 guint8 *chroma_non_intra_quant_matrix = NULL;
373 VAIQMatrixBufferMPEG2 iq_matrix = { 0 };
374 GstVaDecodePicture *va_pic;
376 intra_quant_matrix = self->seq.intra_quantizer_matrix;
377 non_intra_quant_matrix = self->seq.non_intra_quantizer_matrix;
380 if (quant_matrix->load_intra_quantiser_matrix)
381 intra_quant_matrix = quant_matrix->intra_quantiser_matrix;
382 if (quant_matrix->load_non_intra_quantiser_matrix)
383 non_intra_quant_matrix = quant_matrix->non_intra_quantiser_matrix;
384 if (quant_matrix->load_chroma_intra_quantiser_matrix)
385 chroma_intra_quant_matrix = quant_matrix->chroma_intra_quantiser_matrix;
386 if (quant_matrix->load_chroma_non_intra_quantiser_matrix)
387 chroma_non_intra_quant_matrix =
388 quant_matrix->chroma_non_intra_quantiser_matrix;
391 iq_matrix.load_intra_quantiser_matrix = intra_quant_matrix != NULL;
392 if (intra_quant_matrix)
393 _copy_quant_matrix (iq_matrix.intra_quantiser_matrix, intra_quant_matrix);
395 iq_matrix.load_non_intra_quantiser_matrix = non_intra_quant_matrix != NULL;
396 if (non_intra_quant_matrix)
397 _copy_quant_matrix (iq_matrix.non_intra_quantiser_matrix,
398 non_intra_quant_matrix);
400 iq_matrix.load_chroma_intra_quantiser_matrix =
401 chroma_intra_quant_matrix != NULL;
402 if (chroma_intra_quant_matrix)
403 _copy_quant_matrix (iq_matrix.chroma_intra_quantiser_matrix,
404 chroma_intra_quant_matrix);
406 iq_matrix.load_chroma_non_intra_quantiser_matrix =
407 chroma_non_intra_quant_matrix != NULL;
408 if (chroma_non_intra_quant_matrix)
409 _copy_quant_matrix (iq_matrix.chroma_non_intra_quantiser_matrix,
410 chroma_non_intra_quant_matrix);
412 va_pic = gst_mpeg2_picture_get_user_data (picture);
413 return gst_va_decoder_add_param_buffer (base->decoder, va_pic,
414 VAIQMatrixBufferType, &iq_matrix, sizeof (iq_matrix));
417 static inline uint32_t
418 _is_frame_start (GstMpeg2Picture * picture)
420 return (!picture->first_field
421 || (picture->structure == GST_MPEG_VIDEO_PICTURE_STRUCTURE_FRAME))
425 static inline VASurfaceID
426 _get_surface_id (GstMpeg2Picture * picture)
428 GstVaDecodePicture *va_pic;
431 return VA_INVALID_ID;
433 va_pic = gst_mpeg2_picture_get_user_data (picture);
435 return VA_INVALID_ID;
436 return gst_va_decode_picture_get_surface (va_pic);
440 gst_va_mpeg2_dec_start_picture (GstMpeg2Decoder * decoder,
441 GstMpeg2Picture * picture, GstMpeg2Slice * slice,
442 GstMpeg2Picture * prev_picture, GstMpeg2Picture * next_picture)
444 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
445 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
446 GstVaDecodePicture *va_pic;
447 VAPictureParameterBufferMPEG2 pic_param;
449 va_pic = gst_mpeg2_picture_get_user_data (picture);
452 pic_param = (VAPictureParameterBufferMPEG2) {
453 .horizontal_size = base->width,
454 .vertical_size = base->height,
455 .forward_reference_picture = VA_INVALID_ID,
456 .backward_reference_picture = VA_INVALID_ID,
457 .picture_coding_type = slice->pic_hdr->pic_type,
458 .f_code = _pack_f_code (slice->pic_ext->f_code),
459 .picture_coding_extension.bits = {
460 .is_first_field = _is_frame_start (picture),
461 .intra_dc_precision = slice->pic_ext->intra_dc_precision,
462 .picture_structure = slice->pic_ext->picture_structure,
463 .top_field_first = slice->pic_ext->top_field_first,
464 .frame_pred_frame_dct = slice->pic_ext->frame_pred_frame_dct,
465 .concealment_motion_vectors = slice->pic_ext->concealment_motion_vectors,
466 .q_scale_type = slice->pic_ext->q_scale_type,
467 .intra_vlc_format = slice->pic_ext->intra_vlc_format,
468 .alternate_scan = slice->pic_ext->alternate_scan,
469 .repeat_first_field = slice->pic_ext->repeat_first_field,
470 .progressive_frame = slice->pic_ext->progressive_frame,
475 switch (picture->type) {
476 case GST_MPEG_VIDEO_PICTURE_TYPE_B:{
477 VASurfaceID surface = _get_surface_id (next_picture);
478 if (surface == VA_INVALID_ID) {
479 GST_WARNING_OBJECT (self, "Missing the backward reference picture");
480 if (GST_VA_DISPLAY_IS_IMPLEMENTATION (base->display, MESA_GALLIUM))
481 return GST_FLOW_ERROR;
482 else if (GST_VA_DISPLAY_IS_IMPLEMENTATION (base->display, INTEL_IHD))
483 surface = gst_va_decode_picture_get_surface (va_pic);
485 pic_param.backward_reference_picture = surface;
488 case GST_MPEG_VIDEO_PICTURE_TYPE_P:{
489 VASurfaceID surface = _get_surface_id (prev_picture);
490 if (surface == VA_INVALID_ID) {
491 GST_WARNING_OBJECT (self, "Missing the forward reference picture");
492 if (GST_VA_DISPLAY_IS_IMPLEMENTATION (base->display, MESA_GALLIUM))
493 return GST_FLOW_ERROR;
494 else if (GST_VA_DISPLAY_IS_IMPLEMENTATION (base->display, INTEL_IHD))
495 surface = gst_va_decode_picture_get_surface (va_pic);
497 pic_param.forward_reference_picture = surface;
503 if (!gst_va_decoder_add_param_buffer (base->decoder, va_pic,
504 VAPictureParameterBufferType, &pic_param, sizeof (pic_param)))
505 return GST_FLOW_ERROR;
507 if (!gst_va_mpeg2_dec_add_quant_matrix (decoder, picture, slice))
508 return GST_FLOW_ERROR;
514 gst_va_mpeg2_dec_decode_slice (GstMpeg2Decoder * decoder,
515 GstMpeg2Picture * picture, GstMpeg2Slice * slice)
517 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
518 GstMpegVideoSliceHdr *header = &slice->header;
519 GstMpegVideoPacket *packet = &slice->packet;
520 GstVaDecodePicture *va_pic;
521 VASliceParameterBufferMPEG2 slice_param;
523 /* The slice data pass to driver should be a full packet
524 include the start code. The packet->offset return by
525 gst_mpeg_video_parse does not include the start code
526 and so we need to wrap back 4 bytes. */
527 g_assert (packet->offset >= 4);
530 slice_param = (VASliceParameterBufferMPEG2) {
531 .slice_data_size = packet->size + 4 /* start code */,
532 .slice_data_offset = 0,
533 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
534 .macroblock_offset = header->header_size + 32,
535 .slice_horizontal_position = header->mb_column,
536 .slice_vertical_position = header->mb_row,
537 .quantiser_scale_code = header->quantiser_scale_code,
538 .intra_slice_flag = header->intra_slice,
542 va_pic = gst_mpeg2_picture_get_user_data (picture);
543 if (!gst_va_decoder_add_slice_buffer (base->decoder, va_pic,
544 &slice_param, sizeof (slice_param),
545 (guint8 *) (packet->data + packet->offset - 4 /* start code */ ),
546 packet->size + 4 /* start code */ ))
547 return GST_FLOW_ERROR;
553 gst_va_mpeg2_dec_end_picture (GstMpeg2Decoder * decoder,
554 GstMpeg2Picture * picture)
556 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
557 GstVaDecodePicture *va_pic;
559 GST_LOG_OBJECT (base, "end picture %p, (poc %d)",
560 picture, picture->pic_order_cnt);
562 va_pic = gst_mpeg2_picture_get_user_data (picture);
564 if (!gst_va_decoder_decode (base->decoder, va_pic))
565 return GST_FLOW_ERROR;
571 gst_va_mpeg2_dec_output_picture (GstMpeg2Decoder * decoder,
572 GstVideoCodecFrame * frame, GstMpeg2Picture * picture)
574 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
575 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
577 GST_LOG_OBJECT (self,
578 "Outputting picture %p (poc %d)", picture, picture->pic_order_cnt);
580 if (base->copy_frames)
581 gst_va_base_dec_copy_output_buffer (base, frame);
583 if (picture->buffer_flags != 0) {
584 gboolean interlaced =
585 (picture->buffer_flags & GST_VIDEO_BUFFER_FLAG_INTERLACED) != 0;
586 gboolean tff = (picture->buffer_flags & GST_VIDEO_BUFFER_FLAG_TFF) != 0;
588 GST_TRACE_OBJECT (self,
589 "apply buffer flags 0x%x (interlaced %d, top-field-first %d)",
590 picture->buffer_flags, interlaced, tff);
591 GST_BUFFER_FLAG_SET (frame->output_buffer, picture->buffer_flags);
594 gst_mpeg2_picture_unref (picture);
596 return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame);
600 gst_va_mpeg2_dec_init (GTypeInstance * instance, gpointer g_class)
602 gst_va_base_dec_init (GST_VA_BASE_DEC (instance), GST_CAT_DEFAULT);
606 gst_va_mpeg2_dec_dispose (GObject * object)
608 gst_va_base_dec_close (GST_VIDEO_DECODER (object));
609 G_OBJECT_CLASS (GST_VA_BASE_DEC_GET_PARENT_CLASS (object))->dispose (object);
613 gst_va_mpeg2_dec_class_init (gpointer g_class, gpointer class_data)
615 GstCaps *src_doc_caps, *sink_doc_caps;
616 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
617 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
618 GstMpeg2DecoderClass *mpeg2decoder_class = GST_MPEG2_DECODER_CLASS (g_class);
619 GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_CLASS (g_class);
620 struct CData *cdata = class_data;
623 if (cdata->description) {
624 long_name = g_strdup_printf ("VA-API Mpeg2 Decoder in %s",
627 long_name = g_strdup ("VA-API Mpeg2 Decoder");
630 gst_element_class_set_metadata (element_class, long_name,
631 "Codec/Decoder/Video/Hardware",
632 "VA-API based Mpeg2 video decoder", "He Junyan <junyan.he@intel.com>");
634 sink_doc_caps = gst_caps_from_string (sink_caps_str);
635 src_doc_caps = gst_caps_from_string (src_caps_str);
637 gst_va_base_dec_class_init (GST_VA_BASE_DEC_CLASS (g_class), MPEG2,
638 cdata->render_device_path, cdata->sink_caps, cdata->src_caps,
639 src_doc_caps, sink_doc_caps);
641 gobject_class->dispose = gst_va_mpeg2_dec_dispose;
643 decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_negotiate);
645 mpeg2decoder_class->new_sequence =
646 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_new_sequence);
647 mpeg2decoder_class->new_picture =
648 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_new_picture);
649 mpeg2decoder_class->new_field_picture =
650 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_new_field_picture);
651 mpeg2decoder_class->start_picture =
652 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_start_picture);
653 mpeg2decoder_class->decode_slice =
654 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_decode_slice);
655 mpeg2decoder_class->end_picture =
656 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_end_picture);
657 mpeg2decoder_class->output_picture =
658 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_output_picture);
661 g_free (cdata->description);
662 g_free (cdata->render_device_path);
663 gst_caps_unref (cdata->src_caps);
664 gst_caps_unref (cdata->sink_caps);
669 _register_debug_category (gpointer data)
671 GST_DEBUG_CATEGORY_INIT (gst_va_mpeg2dec_debug, "vampeg2dec", 0,
678 gst_va_mpeg2_dec_register (GstPlugin * plugin, GstVaDevice * device,
679 GstCaps * sink_caps, GstCaps * src_caps, guint rank)
681 static GOnce debug_once = G_ONCE_INIT;
683 GTypeInfo type_info = {
684 .class_size = sizeof (GstVaMpeg2DecClass),
685 .class_init = gst_va_mpeg2_dec_class_init,
686 .instance_size = sizeof (GstVaMpeg2Dec),
687 .instance_init = gst_va_mpeg2_dec_init,
691 gchar *type_name, *feature_name;
693 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
694 g_return_val_if_fail (GST_IS_VA_DEVICE (device), FALSE);
695 g_return_val_if_fail (GST_IS_CAPS (sink_caps), FALSE);
696 g_return_val_if_fail (GST_IS_CAPS (src_caps), FALSE);
698 cdata = g_new (struct CData, 1);
699 cdata->description = NULL;
700 cdata->render_device_path = g_strdup (device->render_device_path);
701 cdata->sink_caps = gst_caps_ref (sink_caps);
702 cdata->src_caps = gst_caps_ref (src_caps);
704 /* class data will be leaked if the element never gets instantiated */
705 GST_MINI_OBJECT_FLAG_SET (cdata->sink_caps,
706 GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
707 GST_MINI_OBJECT_FLAG_SET (src_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
709 type_info.class_data = cdata;
711 type_name = g_strdup ("GstVaMpeg2dec");
712 feature_name = g_strdup ("vampeg2dec");
714 /* The first decoder to be registered should use a constant name,
715 * like vampeg2dec, for any additional decoders, we create unique
716 * names, using inserting the render device name. */
717 if (g_type_from_name (type_name)) {
718 gchar *basename = g_path_get_basename (device->render_device_path);
720 g_free (feature_name);
721 type_name = g_strdup_printf ("GstVa%sMpeg2Dec", basename);
722 feature_name = g_strdup_printf ("va%smpeg2dec", basename);
723 cdata->description = basename;
725 /* lower rank for non-first device */
730 g_once (&debug_once, _register_debug_category, NULL);
732 type = g_type_register_static (GST_TYPE_MPEG2_DECODER,
733 type_name, &type_info, 0);
735 ret = gst_element_register (plugin, feature_name, rank, type);
738 g_free (feature_name);