1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2018, Intel Corporation
3 *
4 * Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * 3. Neither the name of the copyright holder nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
24 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGDECE
31 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
32 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 /**
36 * SECTION: element-msdkmpeg2dec
37 * @title: msdkmpeg2dec
38 * @short_description: Intel MSDK MPEG2 decoder
39 *
40 * MPEG2 video decoder based on Intel MFX
41 *
42 * ## Example launch line
43 * ```
44 * gst-launch-1.0 filesrc location=sample.mpeg2 ! mpegvideoparse ! msdkmpeg2dec ! glimagesink
45 * ```
46 *
47 * Since: 1.14
48 *
49 */
50
51 #ifdef HAVE_CONFIG_H
52 # include <config.h>
53 #endif
54
55 #include "gstmsdkmpeg2dec.h"
56
57 GST_DEBUG_CATEGORY_EXTERN (gst_msdkmpeg2dec_debug);
58 #define GST_CAT_DEFAULT gst_msdkmpeg2dec_debug
59
60 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
61 GST_PAD_SINK,
62 GST_PAD_ALWAYS,
63 GST_STATIC_CAPS ("video/mpeg, "
64 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
65 "mpegversion = (int) 2, " "systemstream = (boolean) false")
66 );
67
68 #define gst_msdkmpeg2dec_parent_class parent_class
69 G_DEFINE_TYPE (GstMsdkMPEG2Dec, gst_msdkmpeg2dec, GST_TYPE_MSDKDEC);
70
71 static gboolean
gst_msdkmpeg2dec_configure(GstMsdkDec * decoder)72 gst_msdkmpeg2dec_configure (GstMsdkDec * decoder)
73 {
74 GstMsdkMPEG2Dec *mpeg2dec = GST_MSDKMPEG2DEC (decoder);
75 decoder->param.mfx.CodecId = MFX_CODEC_MPEG2;
76
77 /* This is a deprecated attribute in msdk-2017 version, but some
78 * customers still using this for low-latency streaming of non-b-frame
79 * encoded streams */
80 decoder->param.mfx.DecodedOrder = mpeg2dec->output_order;
81 return TRUE;
82 }
83
84 static void
gst_msdkdec_mpeg2_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)85 gst_msdkdec_mpeg2_set_property (GObject * object, guint prop_id,
86 const GValue * value, GParamSpec * pspec)
87 {
88 GstMsdkMPEG2Dec *thiz = GST_MSDKMPEG2DEC (object);
89 GstState state;
90
91 GST_OBJECT_LOCK (thiz);
92 state = GST_STATE (thiz);
93
94 if (!gst_msdkdec_prop_check_state (state, pspec)) {
95 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
96 GST_OBJECT_UNLOCK (thiz);
97 return;
98 }
99 switch (prop_id) {
100 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
101 thiz->output_order = g_value_get_enum (value);
102 break;
103 default:
104 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
105 break;
106 }
107 GST_OBJECT_UNLOCK (thiz);
108 return;
109 }
110
111 static void
gst_msdkdec_mpeg2_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)112 gst_msdkdec_mpeg2_get_property (GObject * object, guint prop_id, GValue * value,
113 GParamSpec * pspec)
114 {
115 GstMsdkMPEG2Dec *thiz = GST_MSDKMPEG2DEC (object);
116
117 GST_OBJECT_LOCK (thiz);
118 switch (prop_id) {
119 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
120 g_value_set_enum (value, thiz->output_order);
121 break;
122 default:
123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
124 break;
125 }
126 GST_OBJECT_UNLOCK (thiz);
127 }
128
129 static void
gst_msdkmpeg2dec_class_init(GstMsdkMPEG2DecClass * klass)130 gst_msdkmpeg2dec_class_init (GstMsdkMPEG2DecClass * klass)
131 {
132 GObjectClass *gobject_class;
133 GstElementClass *element_class;
134 GstMsdkDecClass *decoder_class;
135
136 gobject_class = G_OBJECT_CLASS (klass);
137 element_class = GST_ELEMENT_CLASS (klass);
138 decoder_class = GST_MSDKDEC_CLASS (klass);
139
140 gobject_class->set_property = gst_msdkdec_mpeg2_set_property;
141 gobject_class->get_property = gst_msdkdec_mpeg2_get_property;
142
143 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkmpeg2dec_configure);
144
145 gst_element_class_set_static_metadata (element_class,
146 "Intel MSDK MPEG2 decoder",
147 "Codec/Decoder/Video/Hardware",
148 "MPEG2 video decoder based on " MFX_API_SDK,
149 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
150
151 gst_msdkdec_prop_install_output_oder_property (gobject_class);
152
153 gst_element_class_add_static_pad_template (element_class, &sink_factory);
154 }
155
156 static void
gst_msdkmpeg2dec_init(GstMsdkMPEG2Dec * thiz)157 gst_msdkmpeg2dec_init (GstMsdkMPEG2Dec * thiz)
158 {
159 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;
160 }
161