1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2018, Intel Corporation
5 * Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * 3. Neither the name of the copyright holder nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGDECE
30 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * SECTION: element-msdkvp9dec
37 * @short_description: Intel MSDK VP9 decoderr
39 * VP9 video decoder based on Intel MFX
41 * ## Example launch line
43 * gst-launch-1.0 filesrc location=sample.webm ! matroskademux ! msdkvp9dec ! glimagesink
54 #include "gstmsdkvp9dec.h"
55 #include "gstmsdkvideomemory.h"
57 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvp9dec_debug);
58 #define GST_CAT_DEFAULT gst_msdkvp9dec_debug
60 #define COMMON_FORMAT "{ NV12, P010_10LE, VUYA, Y410, P012_LE, Y412_LE }"
62 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
65 GST_STATIC_CAPS ("video/x-vp9")
68 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
71 GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
74 #define gst_msdkvp9dec_parent_class parent_class
75 G_DEFINE_TYPE (GstMsdkVP9Dec, gst_msdkvp9dec, GST_TYPE_MSDKDEC);
78 gst_msdkvp9dec_configure (GstMsdkDec * decoder)
80 GstMsdkVP9Dec *vp9dec = GST_MSDKVP9DEC (decoder);
82 const mfxPluginUID *uid;
84 session = gst_msdk_context_get_session (decoder->context);
86 uid = &MFX_PLUGINID_VP9D_HW;
88 if (!gst_msdk_load_plugin (session, uid, 1, "msdkvp9dec"))
91 decoder->param.mfx.CodecId = MFX_CODEC_VP9;
92 /* Replaced with width and height rounded up to 16 */
93 decoder->param.mfx.FrameInfo.Width =
94 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.CropW);
95 decoder->param.mfx.FrameInfo.Height =
96 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.CropH);
98 decoder->force_reset_on_res_change = FALSE;
100 /* This is a deprecated attribute in msdk-2017 version, but some
101 * customers still using this for low-latency streaming of non-b-frame
103 decoder->param.mfx.DecodedOrder = vp9dec->output_order;
108 gst_msdkdec_vp9_set_property (GObject * object, guint prop_id,
109 const GValue * value, GParamSpec * pspec)
111 GstMsdkVP9Dec *thiz = GST_MSDKVP9DEC (object);
114 GST_OBJECT_LOCK (thiz);
115 state = GST_STATE (thiz);
117 if (!gst_msdkdec_prop_check_state (state, pspec)) {
118 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
119 GST_OBJECT_UNLOCK (thiz);
123 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
124 thiz->output_order = g_value_get_enum (value);
127 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
130 GST_OBJECT_UNLOCK (thiz);
135 gst_msdkdec_vp9_get_property (GObject * object, guint prop_id, GValue * value,
138 GstMsdkVP9Dec *thiz = GST_MSDKVP9DEC (object);
140 GST_OBJECT_LOCK (thiz);
142 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
143 g_value_set_enum (value, thiz->output_order);
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
149 GST_OBJECT_UNLOCK (thiz);
153 gst_msdkvp9dec_preinit_decoder (GstMsdkDec * decoder)
155 decoder->param.mfx.FrameInfo.Width =
156 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.Width);
157 decoder->param.mfx.FrameInfo.Height =
158 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.Height);
160 decoder->param.mfx.FrameInfo.PicStruct =
161 decoder->param.mfx.FrameInfo.PicStruct ? decoder->param.mfx.
162 FrameInfo.PicStruct : MFX_PICSTRUCT_PROGRESSIVE;
168 gst_msdkvp9dec_class_init (GstMsdkVP9DecClass * klass)
170 GObjectClass *gobject_class;
171 GstElementClass *element_class;
172 GstMsdkDecClass *decoder_class;
174 gobject_class = G_OBJECT_CLASS (klass);
175 element_class = GST_ELEMENT_CLASS (klass);
176 decoder_class = GST_MSDKDEC_CLASS (klass);
178 gobject_class->set_property = gst_msdkdec_vp9_set_property;
179 gobject_class->get_property = gst_msdkdec_vp9_get_property;
181 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkvp9dec_configure);
182 decoder_class->preinit_decoder =
183 GST_DEBUG_FUNCPTR (gst_msdkvp9dec_preinit_decoder);
185 gst_element_class_set_static_metadata (element_class,
186 "Intel MSDK VP9 decoder",
187 "Codec/Decoder/Video/Hardware",
188 "VP9 video decoder based on " MFX_API_SDK,
189 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
191 gst_msdkdec_prop_install_output_oder_property (gobject_class);
193 gst_element_class_add_static_pad_template (element_class, &sink_factory);
194 gst_element_class_add_static_pad_template (element_class, &src_factory);
198 gst_msdkvp9dec_init (GstMsdkVP9Dec * thiz)
200 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;