1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2016, Intel Corporation
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
14 *
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGDECE
28 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /**
33 * SECTION:element-msdkh265dec
34 * @title: msdkh265dec
35 * @short_description: Intel MSDK H265 decoder
36 *
37 * H265 video decoder based on Intel MFX
38 *
39 * ## Example launch line
40 * ```
41 * gst-launch-1.0 filesrc location=sample.h265 ! h265parse ! msdkh265dec ! glimagesink
42 * ```
43 *
44 * Since: 1.12
45 *
46 */
47
48 #ifdef HAVE_CONFIG_H
49 # include <config.h>
50 #endif
51
52 #include "gstmsdkh265dec.h"
53 #include "gstmsdkvideomemory.h"
54
55 GST_DEBUG_CATEGORY_EXTERN (gst_msdkh265dec_debug);
56 #define GST_CAT_DEFAULT gst_msdkh265dec_debug
57
58 #define COMMON_FORMAT \
59 "{ NV12, P010_10LE, YUY2, Y210, VUYA, Y410, P012_LE, Y212_LE, Y412_LE }"
60
61 /* TODO: update both sink and src dynamically */
62 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
63 GST_PAD_SINK,
64 GST_PAD_ALWAYS,
65 GST_STATIC_CAPS ("video/x-h265, "
66 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
67 "stream-format = (string) byte-stream , alignment = (string) au ")
68 );
69
70 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
71 GST_PAD_SRC,
72 GST_PAD_ALWAYS,
73 GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
74 );
75
76 #define gst_msdkh265dec_parent_class parent_class
77 G_DEFINE_TYPE (GstMsdkH265Dec, gst_msdkh265dec, GST_TYPE_MSDKDEC);
78
79 static gboolean
gst_msdkh265dec_configure(GstMsdkDec * decoder)80 gst_msdkh265dec_configure (GstMsdkDec * decoder)
81 {
82 GstMsdkH265Dec *h265dec = GST_MSDKH265DEC (decoder);
83 mfxSession session;
84 const mfxPluginUID *uid;
85
86 session = gst_msdk_context_get_session (decoder->context);
87
88 if (decoder->hardware)
89 uid = &MFX_PLUGINID_HEVCD_HW;
90 else
91 uid = &MFX_PLUGINID_HEVCD_SW;
92
93 if (!gst_msdk_load_plugin (session, uid, 1, "msdkh265dec"))
94 return FALSE;
95
96 decoder->param.mfx.CodecId = MFX_CODEC_HEVC;
97
98 /* This is a deprecated attribute in msdk-2017 version, but some
99 * customers still using this for low-latency streaming of non-b-frame
100 * encoded streams */
101 decoder->param.mfx.DecodedOrder = h265dec->output_order;
102
103 #if (MFX_VERSION >= 1025)
104 if (decoder->report_error) {
105 decoder->error_report.Header.BufferId = MFX_EXTBUFF_DECODE_ERROR_REPORT;
106 decoder->error_report.Header.BufferSz = sizeof (decoder->error_report);
107 decoder->error_report.ErrorTypes = 0;
108 gst_msdkdec_add_bs_extra_param (decoder,
109 (mfxExtBuffer *) & decoder->error_report);
110 }
111 #endif
112
113 return TRUE;
114 }
115
116 static void
gst_msdkdec_h265_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)117 gst_msdkdec_h265_set_property (GObject * object, guint prop_id,
118 const GValue * value, GParamSpec * pspec)
119 {
120 GstMsdkH265Dec *thiz = GST_MSDKH265DEC (object);
121 #if (MFX_VERSION >= 1025)
122 GstMsdkDec *dec = GST_MSDKDEC (object);
123 #endif
124 GstState state;
125
126 GST_OBJECT_LOCK (thiz);
127 state = GST_STATE (thiz);
128
129 if (!gst_msdkdec_prop_check_state (state, pspec)) {
130 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
131 GST_OBJECT_UNLOCK (thiz);
132 return;
133 }
134 switch (prop_id) {
135 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
136 thiz->output_order = g_value_get_enum (value);
137 break;
138 #if (MFX_VERSION >= 1025)
139 case GST_MSDKDEC_PROP_ERROR_REPORT:
140 dec->report_error = g_value_get_boolean (value);
141 break;
142 #endif
143 default:
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145 break;
146 }
147 GST_OBJECT_UNLOCK (thiz);
148 return;
149 }
150
151 static void
gst_msdkdec_h265_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)152 gst_msdkdec_h265_get_property (GObject * object, guint prop_id, GValue * value,
153 GParamSpec * pspec)
154 {
155 GstMsdkH265Dec *thiz = GST_MSDKH265DEC (object);
156 #if (MFX_VERSION >= 1025)
157 GstMsdkDec *dec = GST_MSDKDEC (object);
158 #endif
159
160 GST_OBJECT_LOCK (thiz);
161 switch (prop_id) {
162 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
163 g_value_set_enum (value, thiz->output_order);
164 break;
165 #if (MFX_VERSION >= 1025)
166 case GST_MSDKDEC_PROP_ERROR_REPORT:
167 g_value_set_boolean (value, dec->report_error);
168 break;
169 #endif
170 default:
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172 break;
173 }
174 GST_OBJECT_UNLOCK (thiz);
175 }
176
177 static void
gst_msdkh265dec_class_init(GstMsdkH265DecClass * klass)178 gst_msdkh265dec_class_init (GstMsdkH265DecClass * klass)
179 {
180 GObjectClass *gobject_class;
181 GstElementClass *element_class;
182 GstMsdkDecClass *decoder_class;
183
184 gobject_class = G_OBJECT_CLASS (klass);
185 element_class = GST_ELEMENT_CLASS (klass);
186 decoder_class = GST_MSDKDEC_CLASS (klass);
187
188 gobject_class->set_property = gst_msdkdec_h265_set_property;
189 gobject_class->get_property = gst_msdkdec_h265_get_property;
190
191 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkh265dec_configure);
192
193 gst_element_class_set_static_metadata (element_class,
194 "Intel MSDK H265 decoder",
195 "Codec/Decoder/Video/Hardware",
196 "H265 video decoder based on " MFX_API_SDK,
197 "Scott D Phillips <scott.d.phillips@intel.com>");
198
199 gst_msdkdec_prop_install_output_oder_property (gobject_class);
200
201 #if (MFX_VERSION >= 1025)
202 gst_msdkdec_prop_install_error_report_property (gobject_class);
203 #endif
204
205 gst_element_class_add_static_pad_template (element_class, &sink_factory);
206 gst_element_class_add_static_pad_template (element_class, &src_factory);
207 }
208
209 static void
gst_msdkh265dec_init(GstMsdkH265Dec * thiz)210 gst_msdkh265dec_init (GstMsdkH265Dec * thiz)
211 {
212 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;
213 }
214