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.
38 #include <mfxplugin.h>
41 #include "gstmsdkvp9dec.h"
42 #include "gstmsdkvideomemory.h"
44 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvp9dec_debug);
45 #define GST_CAT_DEFAULT gst_msdkvp9dec_debug
47 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
50 GST_STATIC_CAPS ("video/x-vp9")
53 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
56 GST_STATIC_CAPS ("video/x-raw, "
57 "format = (string) { NV12 }, "
58 "framerate = (fraction) [0, MAX], "
59 "width = (int) [ 16, MAX ], height = (int) [ 16, MAX ],"
60 "interlace-mode = (string) progressive;"
61 GST_VIDEO_CAPS_MAKE_WITH_FEATURES (GST_CAPS_FEATURE_MEMORY_DMABUF,
65 #define gst_msdkvp9dec_parent_class parent_class
66 G_DEFINE_TYPE (GstMsdkVP9Dec, gst_msdkvp9dec, GST_TYPE_MSDKDEC);
69 gst_msdkvp9dec_configure (GstMsdkDec * decoder)
71 GstMsdkVP9Dec *vp9dec = GST_MSDKVP9DEC (decoder);
74 const mfxPluginUID *uid;
76 session = gst_msdk_context_get_session (decoder->context);
78 uid = &MFX_PLUGINID_VP9D_HW;
80 status = MFXVideoUSER_Load (session, uid, 1);
81 if (status < MFX_ERR_NONE) {
82 GST_ERROR_OBJECT (vp9dec, "Media SDK Plugin load failed (%s)",
83 msdk_status_to_string (status));
85 } else if (status > MFX_ERR_NONE) {
86 GST_WARNING_OBJECT (vp9dec, "Media SDK Plugin load warning: %s",
87 msdk_status_to_string (status));
90 decoder->param.mfx.CodecId = MFX_CODEC_VP9;
91 /* Replaced with width and height rounded up to 16 */
92 decoder->param.mfx.FrameInfo.Width =
93 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.CropW);
94 decoder->param.mfx.FrameInfo.Height =
95 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.CropH);
97 decoder->force_reset_on_res_change = FALSE;
99 /* This is a deprecated attribute in msdk-2017 version, but some
100 * customers still using this for low-latency streaming of non-b-frame
102 decoder->param.mfx.DecodedOrder = vp9dec->output_order;
107 gst_msdkdec_vp9_set_property (GObject * object, guint prop_id,
108 const GValue * value, GParamSpec * pspec)
110 GstMsdkVP9Dec *thiz = GST_MSDKVP9DEC (object);
113 GST_OBJECT_LOCK (thiz);
114 state = GST_STATE (thiz);
116 if (!gst_msdkdec_prop_check_state (state, pspec)) {
117 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
118 GST_OBJECT_UNLOCK (thiz);
122 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
123 thiz->output_order = g_value_get_enum (value);
126 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
129 GST_OBJECT_UNLOCK (thiz);
134 gst_msdkdec_vp9_get_property (GObject * object, guint prop_id, GValue * value,
137 GstMsdkVP9Dec *thiz = GST_MSDKVP9DEC (object);
139 GST_OBJECT_LOCK (thiz);
141 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
142 g_value_set_enum (value, thiz->output_order);
145 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148 GST_OBJECT_UNLOCK (thiz);
152 gst_msdkvp9dec_class_init (GstMsdkVP9DecClass * klass)
154 GObjectClass *gobject_class;
155 GstElementClass *element_class;
156 GstMsdkDecClass *decoder_class;
158 gobject_class = G_OBJECT_CLASS (klass);
159 element_class = GST_ELEMENT_CLASS (klass);
160 decoder_class = GST_MSDKDEC_CLASS (klass);
162 gobject_class->set_property = gst_msdkdec_vp9_set_property;
163 gobject_class->get_property = gst_msdkdec_vp9_get_property;
165 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkvp9dec_configure);
167 gst_element_class_set_static_metadata (element_class,
168 "Intel MSDK VP9 decoder",
169 "Codec/Decoder/Video",
170 "VP9 video decoder based on Intel Media SDK",
171 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
173 gst_msdkdec_prop_install_output_oder_property (gobject_class);
175 gst_element_class_add_static_pad_template (element_class, &sink_factory);
176 gst_element_class_add_static_pad_template (element_class, &src_factory);
180 gst_msdkvp9dec_init (GstMsdkVP9Dec * thiz)
182 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;