1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2018, Intel Corporation
3 * All rights reserved.
4 *
5 * Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
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.
16 *
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.
20 *
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.
32 */
33
34 /**
35 * SECTION: element-msdkvp9dec
36 * @title: msdkvp9dec
37 * @short_description: Intel MSDK VP9 decoderr
38 *
39 * VP9 video decoder based on Intel MFX
40 *
41 * ## Example launch line
42 * ```
43 * gst-launch-1.0 filesrc location=sample.webm ! matroskademux ! msdkvp9dec ! glimagesink
44 * ```
45 *
46 * Since: 1.16
47 *
48 */
49
50 #ifdef HAVE_CONFIG_H
51 # include <config.h>
52 #endif
53
54 #include "gstmsdkvp9dec.h"
55 #include "gstmsdkvideomemory.h"
56
57 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvp9dec_debug);
58 #define GST_CAT_DEFAULT gst_msdkvp9dec_debug
59
60 #define COMMON_FORMAT "{ NV12, P010_10LE, VUYA, Y410, P012_LE, Y412_LE }"
61
62 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
63 GST_PAD_SINK,
64 GST_PAD_ALWAYS,
65 GST_STATIC_CAPS ("video/x-vp9")
66 );
67
68 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
69 GST_PAD_SRC,
70 GST_PAD_ALWAYS,
71 GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
72 );
73
74 #define gst_msdkvp9dec_parent_class parent_class
75 G_DEFINE_TYPE (GstMsdkVP9Dec, gst_msdkvp9dec, GST_TYPE_MSDKDEC);
76
77 static gboolean
gst_msdkvp9dec_configure(GstMsdkDec * decoder)78 gst_msdkvp9dec_configure (GstMsdkDec * decoder)
79 {
80 GstMsdkVP9Dec *vp9dec = GST_MSDKVP9DEC (decoder);
81 mfxSession session;
82 const mfxPluginUID *uid;
83
84 session = gst_msdk_context_get_session (decoder->context);
85
86 uid = &MFX_PLUGINID_VP9D_HW;
87
88 if (!gst_msdk_load_plugin (session, uid, 1, "msdkvp9dec"))
89 return FALSE;
90
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);
97
98 decoder->force_reset_on_res_change = FALSE;
99
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
102 * encoded streams */
103 decoder->param.mfx.DecodedOrder = vp9dec->output_order;
104 return TRUE;
105 }
106
107 static void
gst_msdkdec_vp9_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)108 gst_msdkdec_vp9_set_property (GObject * object, guint prop_id,
109 const GValue * value, GParamSpec * pspec)
110 {
111 GstMsdkVP9Dec *thiz = GST_MSDKVP9DEC (object);
112 GstState state;
113
114 GST_OBJECT_LOCK (thiz);
115 state = GST_STATE (thiz);
116
117 if (!gst_msdkdec_prop_check_state (state, pspec)) {
118 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
119 GST_OBJECT_UNLOCK (thiz);
120 return;
121 }
122 switch (prop_id) {
123 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
124 thiz->output_order = g_value_get_enum (value);
125 break;
126 default:
127 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
128 break;
129 }
130 GST_OBJECT_UNLOCK (thiz);
131 return;
132 }
133
134 static void
gst_msdkdec_vp9_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)135 gst_msdkdec_vp9_get_property (GObject * object, guint prop_id, GValue * value,
136 GParamSpec * pspec)
137 {
138 GstMsdkVP9Dec *thiz = GST_MSDKVP9DEC (object);
139
140 GST_OBJECT_LOCK (thiz);
141 switch (prop_id) {
142 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
143 g_value_set_enum (value, thiz->output_order);
144 break;
145 default:
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
147 break;
148 }
149 GST_OBJECT_UNLOCK (thiz);
150 }
151
152 static gboolean
gst_msdkvp9dec_preinit_decoder(GstMsdkDec * decoder)153 gst_msdkvp9dec_preinit_decoder (GstMsdkDec * decoder)
154 {
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);
159
160 decoder->param.mfx.FrameInfo.PicStruct =
161 decoder->param.mfx.FrameInfo.PicStruct ? decoder->param.mfx.
162 FrameInfo.PicStruct : MFX_PICSTRUCT_PROGRESSIVE;
163
164 return TRUE;
165 }
166
167 static void
gst_msdkvp9dec_class_init(GstMsdkVP9DecClass * klass)168 gst_msdkvp9dec_class_init (GstMsdkVP9DecClass * klass)
169 {
170 GObjectClass *gobject_class;
171 GstElementClass *element_class;
172 GstMsdkDecClass *decoder_class;
173
174 gobject_class = G_OBJECT_CLASS (klass);
175 element_class = GST_ELEMENT_CLASS (klass);
176 decoder_class = GST_MSDKDEC_CLASS (klass);
177
178 gobject_class->set_property = gst_msdkdec_vp9_set_property;
179 gobject_class->get_property = gst_msdkdec_vp9_get_property;
180
181 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkvp9dec_configure);
182 decoder_class->preinit_decoder =
183 GST_DEBUG_FUNCPTR (gst_msdkvp9dec_preinit_decoder);
184
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>");
190
191 gst_msdkdec_prop_install_output_oder_property (gobject_class);
192
193 gst_element_class_add_static_pad_template (element_class, &sink_factory);
194 gst_element_class_add_static_pad_template (element_class, &src_factory);
195 }
196
197 static void
gst_msdkvp9dec_init(GstMsdkVP9Dec * thiz)198 gst_msdkvp9dec_init (GstMsdkVP9Dec * thiz)
199 {
200 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;
201 }
202