1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2016, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
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.
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.
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.
33 * SECTION:element-msdkh265dec
35 * @short_description: Intel MSDK H265 decoder
37 * H265 video decoder based on Intel MFX
39 * ## Example launch line
41 * gst-launch-1.0 filesrc location=sample.h265 ! h265parse ! msdkh265dec ! glimagesink
52 #include "gstmsdkh265dec.h"
53 #include "gstmsdkvideomemory.h"
55 GST_DEBUG_CATEGORY_EXTERN (gst_msdkh265dec_debug);
56 #define GST_CAT_DEFAULT gst_msdkh265dec_debug
58 #define COMMON_FORMAT \
59 "{ NV12, P010_10LE, YUY2, Y210, VUYA, Y410, P012_LE, Y212_LE, Y412_LE, BGRA, BGRx }"
61 /* TODO: update both sink and src dynamically */
62 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
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 ")
70 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
73 GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
76 #define gst_msdkh265dec_parent_class parent_class
77 G_DEFINE_TYPE (GstMsdkH265Dec, gst_msdkh265dec, GST_TYPE_MSDKDEC);
80 gst_msdkh265dec_configure (GstMsdkDec * decoder)
82 GstMsdkH265Dec *h265dec = GST_MSDKH265DEC (decoder);
84 const mfxPluginUID *uid;
86 session = gst_msdk_context_get_session (decoder->context);
88 if (decoder->hardware)
89 uid = &MFX_PLUGINID_HEVCD_HW;
91 uid = &MFX_PLUGINID_HEVCD_SW;
93 if (!gst_msdk_load_plugin (session, uid, 1, "msdkh265dec"))
96 decoder->param.mfx.CodecId = MFX_CODEC_HEVC;
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
101 decoder->param.mfx.DecodedOrder = h265dec->output_order;
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);
117 gst_msdkdec_h265_set_property (GObject * object, guint prop_id,
118 const GValue * value, GParamSpec * pspec)
120 GstMsdkH265Dec *thiz = GST_MSDKH265DEC (object);
121 #if (MFX_VERSION >= 1025)
122 GstMsdkDec *dec = GST_MSDKDEC (object);
126 GST_OBJECT_LOCK (thiz);
127 state = GST_STATE (thiz);
129 if (!gst_msdkdec_prop_check_state (state, pspec)) {
130 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
131 GST_OBJECT_UNLOCK (thiz);
135 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
136 thiz->output_order = g_value_get_enum (value);
138 #if (MFX_VERSION >= 1025)
139 case GST_MSDKDEC_PROP_ERROR_REPORT:
140 dec->report_error = g_value_get_boolean (value);
144 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
147 GST_OBJECT_UNLOCK (thiz);
152 gst_msdkdec_h265_get_property (GObject * object, guint prop_id, GValue * value,
155 GstMsdkH265Dec *thiz = GST_MSDKH265DEC (object);
156 #if (MFX_VERSION >= 1025)
157 GstMsdkDec *dec = GST_MSDKDEC (object);
160 GST_OBJECT_LOCK (thiz);
162 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
163 g_value_set_enum (value, thiz->output_order);
165 #if (MFX_VERSION >= 1025)
166 case GST_MSDKDEC_PROP_ERROR_REPORT:
167 g_value_set_boolean (value, dec->report_error);
171 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
174 GST_OBJECT_UNLOCK (thiz);
178 gst_msdkh265dec_class_init (GstMsdkH265DecClass * klass)
180 GObjectClass *gobject_class;
181 GstElementClass *element_class;
182 GstMsdkDecClass *decoder_class;
184 gobject_class = G_OBJECT_CLASS (klass);
185 element_class = GST_ELEMENT_CLASS (klass);
186 decoder_class = GST_MSDKDEC_CLASS (klass);
188 gobject_class->set_property = gst_msdkdec_h265_set_property;
189 gobject_class->get_property = gst_msdkdec_h265_get_property;
191 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkh265dec_configure);
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>");
199 gst_msdkdec_prop_install_output_oder_property (gobject_class);
201 #if (MFX_VERSION >= 1025)
202 gst_msdkdec_prop_install_error_report_property (gobject_class);
205 gst_element_class_add_static_pad_template (element_class, &sink_factory);
206 gst_element_class_add_static_pad_template (element_class, &src_factory);
210 gst_msdkh265dec_init (GstMsdkH265Dec * thiz)
212 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;