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 GstMpegVideoSequenceHdr seq;
77 static GstElementClass *parent_class = NULL;
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 (!base->need_negotiation)
101 base->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,
118 if (format == GST_VIDEO_FORMAT_UNKNOWN)
122 gst_video_decoder_set_output_state (decoder, format,
123 base->width, base->height, mpeg2dec->input_state);
125 if (!self->progressive)
126 base->output_state->info.interlace_mode = GST_VIDEO_INTERLACE_MODE_MIXED;
128 base->output_state->caps = gst_video_info_to_caps (&base->output_state->info);
130 gst_caps_set_features_simple (base->output_state->caps, capsfeatures);
132 GST_INFO_OBJECT (self, "Negotiated caps %" GST_PTR_FORMAT,
133 base->output_state->caps);
135 return GST_VIDEO_DECODER_CLASS (parent_class)->negotiate (decoder);
139 _map_profile (GstMpegVideoProfile profile)
141 VAProfile p = VAProfileNone;
144 case GST_MPEG_VIDEO_PROFILE_SIMPLE:
145 p = VAProfileMPEG2Simple;
147 case GST_MPEG_VIDEO_PROFILE_MAIN:
148 p = VAProfileMPEG2Main;
159 _get_profile (GstVaMpeg2Dec * self, GstMpegVideoProfile profile,
160 const GstMpegVideoSequenceExt * seq_ext,
161 const GstMpegVideoSequenceScalableExt * seq_scalable_ext)
163 GstVaBaseDec *base = GST_VA_BASE_DEC (self);
164 VAProfile hw_profile;
166 hw_profile = _map_profile (profile);
167 if (hw_profile == VAProfileNone)
170 /* promote the profile if hw does not support, until we get one */
172 if (gst_va_decoder_has_profile (base->decoder, hw_profile))
175 /* Otherwise, try to map to a higher profile */
177 case GST_MPEG_VIDEO_PROFILE_SIMPLE:
178 hw_profile = VAProfileMPEG2Main;
180 case GST_MPEG_VIDEO_PROFILE_HIGH:
181 /* Try to map to main profile if no high profile specific bits used */
182 if (!seq_scalable_ext && (seq_ext && seq_ext->chroma_format == 1)) {
183 hw_profile = VAProfileMPEG2Main;
188 GST_ERROR_OBJECT (self, "profile %d is unsupported.", profile);
189 hw_profile = VAProfileNone;
192 } while (hw_profile != VAProfileNone);
198 _get_rtformat (GstVaMpeg2Dec * self, GstMpegVideoChromaFormat chroma_format)
202 switch (chroma_format) {
203 case GST_MPEG_VIDEO_CHROMA_420:
204 ret = VA_RT_FORMAT_YUV420;
206 case GST_MPEG_VIDEO_CHROMA_422:
207 ret = VA_RT_FORMAT_YUV422;
209 case GST_MPEG_VIDEO_CHROMA_444:
210 ret = VA_RT_FORMAT_YUV444;
213 GST_ERROR_OBJECT (self, "Unsupported chroma format: %d ", chroma_format);
221 gst_va_mpeg2_dec_new_sequence (GstMpeg2Decoder * decoder,
222 const GstMpegVideoSequenceHdr * seq,
223 const GstMpegVideoSequenceExt * seq_ext,
224 const GstMpegVideoSequenceDisplayExt * seq_display_ext,
225 const GstMpegVideoSequenceScalableExt * seq_scalable_ext, gint max_dpb_size)
227 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
228 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
230 GstMpegVideoProfile mpeg_profile;
231 gboolean negotiation_needed = FALSE;
234 gboolean progressive;
239 height = seq->height;
241 width = (width & 0x0fff) | ((guint32) seq_ext->horiz_size_ext << 12);
242 height = (height & 0x0fff) | ((guint32) seq_ext->vert_size_ext << 12);
245 mpeg_profile = GST_MPEG_VIDEO_PROFILE_MAIN;
247 mpeg_profile = seq_ext->profile;
249 profile = _get_profile (self, mpeg_profile, seq_ext, seq_scalable_ext);
250 if (profile == VAProfileNone)
251 return GST_FLOW_NOT_NEGOTIATED;
253 rt_format = _get_rtformat (self,
254 seq_ext ? seq_ext->chroma_format : GST_MPEG_VIDEO_CHROMA_420);
256 return GST_FLOW_NOT_NEGOTIATED;
258 if (!gst_va_decoder_config_is_equal (base->decoder, profile,
259 rt_format, width, height)) {
260 base->profile = profile;
261 base->rt_format = rt_format;
263 base->height = height;
265 negotiation_needed = TRUE;
267 GST_INFO_OBJECT (self, "Format changed to %s [%x] (%dx%d)",
268 gst_va_profile_name (profile), rt_format, base->width, base->height);
271 progressive = seq_ext ? seq_ext->progressive : 1;
272 if (self->progressive != progressive) {
273 self->progressive = progressive;
275 negotiation_needed = TRUE;
276 GST_INFO_OBJECT (self, "Interlaced mode changed to %d", !progressive);
279 base->need_valign = FALSE;
281 base->min_buffers = 2 + 4; /* max num pic references + scratch surfaces */
283 base->need_negotiation = negotiation_needed;
289 gst_va_mpeg2_dec_new_picture (GstMpeg2Decoder * decoder,
290 GstVideoCodecFrame * frame, GstMpeg2Picture * picture)
293 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
294 GstVaDecodePicture *pic;
295 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
296 GstVideoDecoder *vdec = GST_VIDEO_DECODER (decoder);
298 if (base->need_negotiation) {
299 if (!gst_video_decoder_negotiate (vdec)) {
300 GST_ERROR_OBJECT (self, "Failed to negotiate with downstream");
301 return GST_FLOW_NOT_NEGOTIATED;
305 ret = gst_video_decoder_allocate_output_frame (vdec, frame);
306 if (ret != GST_FLOW_OK)
309 pic = gst_va_decode_picture_new (base->decoder, frame->output_buffer);
311 gst_mpeg2_picture_set_user_data (picture, pic,
312 (GDestroyNotify) gst_va_decode_picture_free);
314 GST_LOG_OBJECT (self, "New va decode picture %p - %#x", pic,
315 gst_va_decode_picture_get_surface (pic));
321 GST_WARNING_OBJECT (self, "Failed to allocated output buffer, return %s",
322 gst_flow_get_name (ret));
328 gst_va_mpeg2_dec_new_field_picture (GstMpeg2Decoder * decoder,
329 GstMpeg2Picture * first_field, GstMpeg2Picture * second_field)
331 GstVaDecodePicture *first_pic, *second_pic;
332 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
333 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
335 first_pic = gst_mpeg2_picture_get_user_data (first_field);
337 return GST_FLOW_ERROR;
339 second_pic = gst_va_decode_picture_new (base->decoder, first_pic->gstbuffer);
340 gst_mpeg2_picture_set_user_data (second_field, second_pic,
341 (GDestroyNotify) gst_va_decode_picture_free);
343 GST_LOG_OBJECT (self, "New va decode picture %p - %#x", second_pic,
344 gst_va_decode_picture_get_surface (second_pic));
349 static inline guint32
350 _pack_f_code (guint8 f_code[2][2])
352 return (((guint32) f_code[0][0] << 12)
353 | ((guint32) f_code[0][1] << 8)
354 | ((guint32) f_code[1][0] << 4)
359 _copy_quant_matrix (guint8 dst[64], const guint8 src[64])
361 memcpy (dst, src, 64);
365 gst_va_mpeg2_dec_add_quant_matrix (GstMpeg2Decoder * decoder,
366 GstMpeg2Picture * picture, GstMpeg2Slice * slice)
368 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
369 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
370 GstMpegVideoQuantMatrixExt *const quant_matrix = slice->quant_matrix;
371 guint8 *intra_quant_matrix = NULL;
372 guint8 *non_intra_quant_matrix = NULL;
373 guint8 *chroma_intra_quant_matrix = NULL;
374 guint8 *chroma_non_intra_quant_matrix = NULL;
375 VAIQMatrixBufferMPEG2 iq_matrix = { 0 };
376 GstVaDecodePicture *va_pic;
378 intra_quant_matrix = self->seq.intra_quantizer_matrix;
379 non_intra_quant_matrix = self->seq.non_intra_quantizer_matrix;
382 if (quant_matrix->load_intra_quantiser_matrix)
383 intra_quant_matrix = quant_matrix->intra_quantiser_matrix;
384 if (quant_matrix->load_non_intra_quantiser_matrix)
385 non_intra_quant_matrix = quant_matrix->non_intra_quantiser_matrix;
386 if (quant_matrix->load_chroma_intra_quantiser_matrix)
387 chroma_intra_quant_matrix = quant_matrix->chroma_intra_quantiser_matrix;
388 if (quant_matrix->load_chroma_non_intra_quantiser_matrix)
389 chroma_non_intra_quant_matrix =
390 quant_matrix->chroma_non_intra_quantiser_matrix;
393 iq_matrix.load_intra_quantiser_matrix = intra_quant_matrix != NULL;
394 if (intra_quant_matrix)
395 _copy_quant_matrix (iq_matrix.intra_quantiser_matrix, intra_quant_matrix);
397 iq_matrix.load_non_intra_quantiser_matrix = non_intra_quant_matrix != NULL;
398 if (non_intra_quant_matrix)
399 _copy_quant_matrix (iq_matrix.non_intra_quantiser_matrix,
400 non_intra_quant_matrix);
402 iq_matrix.load_chroma_intra_quantiser_matrix =
403 chroma_intra_quant_matrix != NULL;
404 if (chroma_intra_quant_matrix)
405 _copy_quant_matrix (iq_matrix.chroma_intra_quantiser_matrix,
406 chroma_intra_quant_matrix);
408 iq_matrix.load_chroma_non_intra_quantiser_matrix =
409 chroma_non_intra_quant_matrix != NULL;
410 if (chroma_non_intra_quant_matrix)
411 _copy_quant_matrix (iq_matrix.chroma_non_intra_quantiser_matrix,
412 chroma_non_intra_quant_matrix);
414 va_pic = gst_mpeg2_picture_get_user_data (picture);
415 return gst_va_decoder_add_param_buffer (base->decoder, va_pic,
416 VAIQMatrixBufferType, &iq_matrix, sizeof (iq_matrix));
419 static inline uint32_t
420 _is_frame_start (GstMpeg2Picture * picture)
422 return (!picture->first_field
423 || (picture->structure == GST_MPEG_VIDEO_PICTURE_STRUCTURE_FRAME))
427 static inline VASurfaceID
428 _get_surface_id (GstMpeg2Picture * picture)
430 GstVaDecodePicture *va_pic;
433 return VA_INVALID_ID;
435 va_pic = gst_mpeg2_picture_get_user_data (picture);
437 return VA_INVALID_ID;
438 return gst_va_decode_picture_get_surface (va_pic);
442 gst_va_mpeg2_dec_start_picture (GstMpeg2Decoder * decoder,
443 GstMpeg2Picture * picture, GstMpeg2Slice * slice,
444 GstMpeg2Picture * prev_picture, GstMpeg2Picture * next_picture)
446 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
447 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
448 GstVaDecodePicture *va_pic;
449 VAPictureParameterBufferMPEG2 pic_param;
451 va_pic = gst_mpeg2_picture_get_user_data (picture);
454 pic_param = (VAPictureParameterBufferMPEG2) {
455 .horizontal_size = base->width,
456 .vertical_size = base->height,
457 .forward_reference_picture = VA_INVALID_ID,
458 .backward_reference_picture = VA_INVALID_ID,
459 .picture_coding_type = slice->pic_hdr->pic_type,
460 .f_code = _pack_f_code (slice->pic_ext->f_code),
461 .picture_coding_extension.bits = {
462 .is_first_field = _is_frame_start (picture),
463 .intra_dc_precision = slice->pic_ext->intra_dc_precision,
464 .picture_structure = slice->pic_ext->picture_structure,
465 .top_field_first = slice->pic_ext->top_field_first,
466 .frame_pred_frame_dct = slice->pic_ext->frame_pred_frame_dct,
467 .concealment_motion_vectors = slice->pic_ext->concealment_motion_vectors,
468 .q_scale_type = slice->pic_ext->q_scale_type,
469 .intra_vlc_format = slice->pic_ext->intra_vlc_format,
470 .alternate_scan = slice->pic_ext->alternate_scan,
471 .repeat_first_field = slice->pic_ext->repeat_first_field,
472 .progressive_frame = slice->pic_ext->progressive_frame,
477 switch (picture->type) {
478 case GST_MPEG_VIDEO_PICTURE_TYPE_B:{
479 VASurfaceID surface = _get_surface_id (next_picture);
480 if (surface == VA_INVALID_ID) {
481 GST_WARNING_OBJECT (self, "Missing the backward reference picture");
482 if (GST_VA_DISPLAY_IS_IMPLEMENTATION (base->display, MESA_GALLIUM))
483 return GST_FLOW_ERROR;
484 else if (GST_VA_DISPLAY_IS_IMPLEMENTATION (base->display, INTEL_IHD))
485 surface = gst_va_decode_picture_get_surface (va_pic);
487 pic_param.backward_reference_picture = surface;
490 case GST_MPEG_VIDEO_PICTURE_TYPE_P:{
491 VASurfaceID surface = _get_surface_id (prev_picture);
492 if (surface == VA_INVALID_ID) {
493 GST_WARNING_OBJECT (self, "Missing the forward reference picture");
494 if (GST_VA_DISPLAY_IS_IMPLEMENTATION (base->display, MESA_GALLIUM))
495 return GST_FLOW_ERROR;
496 else if (GST_VA_DISPLAY_IS_IMPLEMENTATION (base->display, INTEL_IHD))
497 surface = gst_va_decode_picture_get_surface (va_pic);
499 pic_param.forward_reference_picture = surface;
505 if (!gst_va_decoder_add_param_buffer (base->decoder, va_pic,
506 VAPictureParameterBufferType, &pic_param, sizeof (pic_param)))
507 return GST_FLOW_ERROR;
509 if (!gst_va_mpeg2_dec_add_quant_matrix (decoder, picture, slice))
510 return GST_FLOW_ERROR;
516 gst_va_mpeg2_dec_decode_slice (GstMpeg2Decoder * decoder,
517 GstMpeg2Picture * picture, GstMpeg2Slice * slice)
519 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
520 GstMpegVideoSliceHdr *header = &slice->header;
521 GstMpegVideoPacket *packet = &slice->packet;
522 GstVaDecodePicture *va_pic;
523 VASliceParameterBufferMPEG2 slice_param;
526 slice_param = (VASliceParameterBufferMPEG2) {
527 .slice_data_size = slice->size,
528 .slice_data_offset = 0,
529 .slice_data_flag = VA_SLICE_DATA_FLAG_ALL,
530 .macroblock_offset = header->header_size + 32,
531 .slice_horizontal_position = header->mb_column,
532 .slice_vertical_position = header->mb_row,
533 .quantiser_scale_code = header->quantiser_scale_code,
534 .intra_slice_flag = header->intra_slice,
538 va_pic = gst_mpeg2_picture_get_user_data (picture);
539 if (!gst_va_decoder_add_slice_buffer (base->decoder, va_pic,
540 &slice_param, sizeof (slice_param),
541 (guint8 *) (packet->data + slice->sc_offset), slice->size))
542 return GST_FLOW_ERROR;
548 gst_va_mpeg2_dec_end_picture (GstMpeg2Decoder * decoder,
549 GstMpeg2Picture * picture)
551 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
552 GstVaDecodePicture *va_pic;
554 GST_LOG_OBJECT (base, "end picture %p, (poc %d)",
555 picture, picture->pic_order_cnt);
557 va_pic = gst_mpeg2_picture_get_user_data (picture);
559 if (!gst_va_decoder_decode (base->decoder, va_pic))
560 return GST_FLOW_ERROR;
566 gst_va_mpeg2_dec_output_picture (GstMpeg2Decoder * decoder,
567 GstVideoCodecFrame * frame, GstMpeg2Picture * picture)
569 GstVaBaseDec *base = GST_VA_BASE_DEC (decoder);
570 GstVaMpeg2Dec *self = GST_VA_MPEG2_DEC (decoder);
572 GST_LOG_OBJECT (self,
573 "Outputting picture %p (poc %d)", picture, picture->pic_order_cnt);
575 if (base->copy_frames)
576 gst_va_base_dec_copy_output_buffer (base, frame);
578 if (picture->buffer_flags != 0) {
579 gboolean interlaced =
580 (picture->buffer_flags & GST_VIDEO_BUFFER_FLAG_INTERLACED) != 0;
581 gboolean tff = (picture->buffer_flags & GST_VIDEO_BUFFER_FLAG_TFF) != 0;
583 GST_TRACE_OBJECT (self,
584 "apply buffer flags 0x%x (interlaced %d, top-field-first %d)",
585 picture->buffer_flags, interlaced, tff);
586 GST_BUFFER_FLAG_SET (frame->output_buffer, picture->buffer_flags);
589 gst_mpeg2_picture_unref (picture);
591 return gst_video_decoder_finish_frame (GST_VIDEO_DECODER (self), frame);
595 gst_va_mpeg2_dec_init (GTypeInstance * instance, gpointer g_class)
597 gst_va_base_dec_init (GST_VA_BASE_DEC (instance), GST_CAT_DEFAULT);
601 gst_va_mpeg2_dec_dispose (GObject * object)
603 gst_va_base_dec_close (GST_VIDEO_DECODER (object));
604 G_OBJECT_CLASS (parent_class)->dispose (object);
608 gst_va_mpeg2_dec_class_init (gpointer g_class, gpointer class_data)
610 GstCaps *src_doc_caps, *sink_doc_caps;
611 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
612 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
613 GstMpeg2DecoderClass *mpeg2decoder_class = GST_MPEG2_DECODER_CLASS (g_class);
614 GstVideoDecoderClass *decoder_class = GST_VIDEO_DECODER_CLASS (g_class);
615 struct CData *cdata = class_data;
618 if (cdata->description) {
619 long_name = g_strdup_printf ("VA-API Mpeg2 Decoder in %s",
622 long_name = g_strdup ("VA-API Mpeg2 Decoder");
625 gst_element_class_set_metadata (element_class, long_name,
626 "Codec/Decoder/Video/Hardware",
627 "VA-API based Mpeg2 video decoder", "He Junyan <junyan.he@intel.com>");
629 sink_doc_caps = gst_caps_from_string (sink_caps_str);
630 src_doc_caps = gst_caps_from_string (src_caps_str);
632 parent_class = g_type_class_peek_parent (g_class);
635 * GstVaMpeg2Dec:device-path:
637 * It shows the DRM device path used for the VA operation, if any.
641 gst_va_base_dec_class_init (GST_VA_BASE_DEC_CLASS (g_class), MPEG2,
642 cdata->render_device_path, cdata->sink_caps, cdata->src_caps,
643 src_doc_caps, sink_doc_caps);
645 gobject_class->dispose = gst_va_mpeg2_dec_dispose;
647 decoder_class->negotiate = GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_negotiate);
649 mpeg2decoder_class->new_sequence =
650 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_new_sequence);
651 mpeg2decoder_class->new_picture =
652 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_new_picture);
653 mpeg2decoder_class->new_field_picture =
654 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_new_field_picture);
655 mpeg2decoder_class->start_picture =
656 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_start_picture);
657 mpeg2decoder_class->decode_slice =
658 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_decode_slice);
659 mpeg2decoder_class->end_picture =
660 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_end_picture);
661 mpeg2decoder_class->output_picture =
662 GST_DEBUG_FUNCPTR (gst_va_mpeg2_dec_output_picture);
665 g_free (cdata->description);
666 g_free (cdata->render_device_path);
667 gst_caps_unref (cdata->src_caps);
668 gst_caps_unref (cdata->sink_caps);
673 _register_debug_category (gpointer data)
675 GST_DEBUG_CATEGORY_INIT (gst_va_mpeg2dec_debug, "vampeg2dec", 0,
682 gst_va_mpeg2_dec_register (GstPlugin * plugin, GstVaDevice * device,
683 GstCaps * sink_caps, GstCaps * src_caps, guint rank)
685 static GOnce debug_once = G_ONCE_INIT;
687 GTypeInfo type_info = {
688 .class_size = sizeof (GstVaMpeg2DecClass),
689 .class_init = gst_va_mpeg2_dec_class_init,
690 .instance_size = sizeof (GstVaMpeg2Dec),
691 .instance_init = gst_va_mpeg2_dec_init,
695 gchar *type_name, *feature_name;
697 g_return_val_if_fail (GST_IS_PLUGIN (plugin), FALSE);
698 g_return_val_if_fail (GST_IS_VA_DEVICE (device), FALSE);
699 g_return_val_if_fail (GST_IS_CAPS (sink_caps), FALSE);
700 g_return_val_if_fail (GST_IS_CAPS (src_caps), FALSE);
702 cdata = g_new (struct CData, 1);
703 cdata->description = NULL;
704 cdata->render_device_path = g_strdup (device->render_device_path);
705 cdata->sink_caps = gst_caps_ref (sink_caps);
706 cdata->src_caps = gst_caps_ref (src_caps);
708 /* class data will be leaked if the element never gets instantiated */
709 GST_MINI_OBJECT_FLAG_SET (cdata->sink_caps,
710 GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
711 GST_MINI_OBJECT_FLAG_SET (src_caps, GST_MINI_OBJECT_FLAG_MAY_BE_LEAKED);
713 type_info.class_data = cdata;
715 /* The first decoder to be registered should use a constant name,
716 * like vampeg2dec, for any additional decoders, we create unique
717 * names, using inserting the render device name. */
718 if (device->index == 0) {
719 type_name = g_strdup ("GstVaMpeg2Dec");
720 feature_name = g_strdup ("vampeg2dec");
722 gchar *basename = g_path_get_basename (device->render_device_path);
723 type_name = g_strdup_printf ("GstVa%sMpeg2Dec", basename);
724 feature_name = g_strdup_printf ("va%smpeg2dec", basename);
725 cdata->description = basename;
727 /* lower rank for non-first device */
732 g_once (&debug_once, _register_debug_category, NULL);
734 type = g_type_register_static (GST_TYPE_MPEG2_DECODER,
735 type_name, &type_info, 0);
737 ret = gst_element_register (plugin, feature_name, rank, type);
740 g_free (feature_name);