1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2017, Intel Corporation
3 * Copyright (c) 2017, Igalia S.L.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright notice,
10 * this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright notice,
13 * this list of conditions and the following disclaimer in the documentation
14 * and/or other materials provided with the distribution.
15 *
16 * 3. Neither the name of the copyright holder nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGDECE
29 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /**
34 * SECTION:element-msdkvp8dec
35 * @title: msdkvp8dec
36 * @short_description: Intel MSDK VP8 decoder
37 *
38 * VP8 video decoder based on Intel MFX
39 *
40 * ## Example launch line
41 * ```
42 * gst-launch-1.0 filesrc location=sample.webm ! matroskademux ! msdkvp8dec ! glimagesink
43 * ```
44 *
45 * Since: 1.14
46 *
47 */
48
49 #ifdef HAVE_CONFIG_H
50 # include <config.h>
51 #endif
52
53 #include "gstmsdkvp8dec.h"
54
55 #include <mfxvp8.h>
56
57 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvp8dec_debug);
58 #define GST_CAT_DEFAULT gst_msdkvp8dec_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/x-vp8")
64 );
65
66 #define gst_msdkvp8dec_parent_class parent_class
67 G_DEFINE_TYPE (GstMsdkVP8Dec, gst_msdkvp8dec, GST_TYPE_MSDKDEC);
68
69 static gboolean
gst_msdkvp8dec_configure(GstMsdkDec * decoder)70 gst_msdkvp8dec_configure (GstMsdkDec * decoder)
71 {
72 GstMsdkVP8Dec *vp8dec = GST_MSDKVP8DEC (decoder);
73 mfxSession session;
74 const mfxPluginUID *uid;
75
76 session = gst_msdk_context_get_session (decoder->context);
77
78 uid = &MFX_PLUGINID_VP8D_HW;
79
80 if (!gst_msdk_load_plugin (session, uid, 1, "msdkvp8dec"))
81 return FALSE;
82
83 decoder->param.mfx.CodecId = MFX_CODEC_VP8;
84 /* Replaced with width and height rounded up to 16 */
85 decoder->param.mfx.FrameInfo.Width =
86 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.CropW);
87 decoder->param.mfx.FrameInfo.Height =
88 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.CropH);
89
90 /* This is a deprecated attribute in msdk-2017 version, but some
91 * customers still using this for low-latency streaming of non-b-frame
92 * encoded streams */
93 decoder->param.mfx.DecodedOrder = vp8dec->output_order;
94 return TRUE;
95 }
96
97 static void
gst_msdkdec_vp8_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)98 gst_msdkdec_vp8_set_property (GObject * object, guint prop_id,
99 const GValue * value, GParamSpec * pspec)
100 {
101 GstMsdkVP8Dec *thiz = GST_MSDKVP8DEC (object);
102 GstState state;
103
104 GST_OBJECT_LOCK (thiz);
105 state = GST_STATE (thiz);
106
107 if (!gst_msdkdec_prop_check_state (state, pspec)) {
108 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
109 GST_OBJECT_UNLOCK (thiz);
110 return;
111 }
112 switch (prop_id) {
113 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
114 thiz->output_order = g_value_get_enum (value);
115 break;
116 default:
117 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
118 break;
119 }
120 GST_OBJECT_UNLOCK (thiz);
121 return;
122 }
123
124 static void
gst_msdkdec_vp8_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)125 gst_msdkdec_vp8_get_property (GObject * object, guint prop_id, GValue * value,
126 GParamSpec * pspec)
127 {
128 GstMsdkVP8Dec *thiz = GST_MSDKVP8DEC (object);
129
130 GST_OBJECT_LOCK (thiz);
131 switch (prop_id) {
132 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
133 g_value_set_enum (value, thiz->output_order);
134 break;
135 default:
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137 break;
138 }
139 GST_OBJECT_UNLOCK (thiz);
140 }
141
142 static gboolean
gst_msdkvp8dec_preinit_decoder(GstMsdkDec * decoder)143 gst_msdkvp8dec_preinit_decoder (GstMsdkDec * decoder)
144 {
145 decoder->param.mfx.FrameInfo.Width =
146 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.Width);
147 decoder->param.mfx.FrameInfo.Height =
148 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.Height);
149
150 decoder->param.mfx.FrameInfo.PicStruct =
151 decoder->param.mfx.FrameInfo.PicStruct ? decoder->param.mfx.
152 FrameInfo.PicStruct : MFX_PICSTRUCT_PROGRESSIVE;
153
154 return TRUE;
155 }
156
157 static gboolean
gst_msdkvp8dec_postinit_decoder(GstMsdkDec * decoder)158 gst_msdkvp8dec_postinit_decoder (GstMsdkDec * decoder)
159 {
160 /* Force the structure to MFX_PICSTRUCT_PROGRESSIVE if it is unknow to
161 * work-around MSDK issue:
162 * https://github.com/Intel-Media-SDK/MediaSDK/issues/1139
163 */
164 if (decoder->param.mfx.FrameInfo.PicStruct == MFX_PICSTRUCT_UNKNOWN)
165 decoder->param.mfx.FrameInfo.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
166
167 return TRUE;
168 }
169
170 static void
gst_msdkvp8dec_class_init(GstMsdkVP8DecClass * klass)171 gst_msdkvp8dec_class_init (GstMsdkVP8DecClass * klass)
172 {
173 GObjectClass *gobject_class;
174 GstElementClass *element_class;
175 GstMsdkDecClass *decoder_class;
176
177 gobject_class = G_OBJECT_CLASS (klass);
178 element_class = GST_ELEMENT_CLASS (klass);
179 decoder_class = GST_MSDKDEC_CLASS (klass);
180
181 gobject_class->set_property = gst_msdkdec_vp8_set_property;
182 gobject_class->get_property = gst_msdkdec_vp8_get_property;
183
184 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkvp8dec_configure);
185 decoder_class->preinit_decoder =
186 GST_DEBUG_FUNCPTR (gst_msdkvp8dec_preinit_decoder);
187 decoder_class->postinit_decoder =
188 GST_DEBUG_FUNCPTR (gst_msdkvp8dec_postinit_decoder);
189
190 gst_element_class_set_static_metadata (element_class,
191 "Intel MSDK VP8 decoder",
192 "Codec/Decoder/Video/Hardware",
193 "VP8 video decoder based on " MFX_API_SDK,
194 "Hyunjun Ko <zzoon@igalia.com>");
195
196 gst_msdkdec_prop_install_output_oder_property (gobject_class);
197
198 gst_element_class_add_static_pad_template (element_class, &sink_factory);
199 }
200
201 static void
gst_msdkvp8dec_init(GstMsdkVP8Dec * thiz)202 gst_msdkvp8dec_init (GstMsdkVP8Dec * thiz)
203 {
204 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;
205 }
206