documentation: fixed a heap o' typos
[platform/upstream/gstreamer.git] / sys / msdk / gstmsdkh265dec.c
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 #ifdef HAVE_CONFIG_H
33 #  include <config.h>
34 #endif
35
36 #include <mfxplugin.h>
37
38 #include "gstmsdkh265dec.h"
39 #include "gstmsdkvideomemory.h"
40
41 GST_DEBUG_CATEGORY_EXTERN (gst_msdkh265dec_debug);
42 #define GST_CAT_DEFAULT gst_msdkh265dec_debug
43
44 #define COMMON_FORMAT "{ NV12, P010_10LE, YUY2, Y210, VUYA, Y410 }"
45
46 /* TODO: update both sink and src dynamically */
47 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
48     GST_PAD_SINK,
49     GST_PAD_ALWAYS,
50     GST_STATIC_CAPS ("video/x-h265, "
51         "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
52         "stream-format = (string) byte-stream , alignment = (string) au ")
53     );
54
55 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
56     GST_PAD_SRC,
57     GST_PAD_ALWAYS,
58     GST_STATIC_CAPS (GST_MSDK_CAPS_STR (COMMON_FORMAT, COMMON_FORMAT))
59     );
60
61 #define gst_msdkh265dec_parent_class parent_class
62 G_DEFINE_TYPE (GstMsdkH265Dec, gst_msdkh265dec, GST_TYPE_MSDKDEC);
63
64 static gboolean
65 gst_msdkh265dec_configure (GstMsdkDec * decoder)
66 {
67   GstMsdkH265Dec *h265dec = GST_MSDKH265DEC (decoder);
68   mfxSession session;
69   mfxStatus status;
70   const mfxPluginUID *uid;
71
72   session = gst_msdk_context_get_session (decoder->context);
73
74   if (decoder->hardware)
75     uid = &MFX_PLUGINID_HEVCD_HW;
76   else
77     uid = &MFX_PLUGINID_HEVCD_SW;
78
79   status = MFXVideoUSER_Load (session, uid, 1);
80   if (status < MFX_ERR_NONE) {
81     GST_ERROR_OBJECT (h265dec, "Media SDK Plugin load failed (%s)",
82         msdk_status_to_string (status));
83     return FALSE;
84   } else if (status > MFX_ERR_NONE) {
85     GST_WARNING_OBJECT (h265dec, "Media SDK Plugin load warning: %s",
86         msdk_status_to_string (status));
87   }
88
89   decoder->param.mfx.CodecId = MFX_CODEC_HEVC;
90
91   /* This is a deprecated attribute in msdk-2017 version, but some
92    * customers still using this for low-latency streaming of non-b-frame
93    * encoded streams */
94   decoder->param.mfx.DecodedOrder = h265dec->output_order;
95   return TRUE;
96 }
97
98 static void
99 gst_msdkdec_h265_set_property (GObject * object, guint prop_id,
100     const GValue * value, GParamSpec * pspec)
101 {
102   GstMsdkH265Dec *thiz = GST_MSDKH265DEC (object);
103   GstState state;
104
105   GST_OBJECT_LOCK (thiz);
106   state = GST_STATE (thiz);
107
108   if (!gst_msdkdec_prop_check_state (state, pspec)) {
109     GST_WARNING_OBJECT (thiz, "setting property in wrong state");
110     GST_OBJECT_UNLOCK (thiz);
111     return;
112   }
113   switch (prop_id) {
114     case GST_MSDKDEC_PROP_OUTPUT_ORDER:
115       thiz->output_order = g_value_get_enum (value);
116       break;
117     default:
118       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
119       break;
120   }
121   GST_OBJECT_UNLOCK (thiz);
122   return;
123 }
124
125 static void
126 gst_msdkdec_h265_get_property (GObject * object, guint prop_id, GValue * value,
127     GParamSpec * pspec)
128 {
129   GstMsdkH265Dec *thiz = GST_MSDKH265DEC (object);
130
131   GST_OBJECT_LOCK (thiz);
132   switch (prop_id) {
133     case GST_MSDKDEC_PROP_OUTPUT_ORDER:
134       g_value_set_enum (value, thiz->output_order);
135       break;
136     default:
137       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
138       break;
139   }
140   GST_OBJECT_UNLOCK (thiz);
141 }
142
143 static void
144 gst_msdkh265dec_class_init (GstMsdkH265DecClass * klass)
145 {
146   GObjectClass *gobject_class;
147   GstElementClass *element_class;
148   GstMsdkDecClass *decoder_class;
149
150   gobject_class = G_OBJECT_CLASS (klass);
151   element_class = GST_ELEMENT_CLASS (klass);
152   decoder_class = GST_MSDKDEC_CLASS (klass);
153
154   gobject_class->set_property = gst_msdkdec_h265_set_property;
155   gobject_class->get_property = gst_msdkdec_h265_get_property;
156
157   decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkh265dec_configure);
158
159   gst_element_class_set_static_metadata (element_class,
160       "Intel MSDK H265 decoder",
161       "Codec/Decoder/Video/Hardware",
162       "H265 video decoder based on Intel Media SDK",
163       "Scott D Phillips <scott.d.phillips@intel.com>");
164
165   gst_msdkdec_prop_install_output_oder_property (gobject_class);
166
167   gst_element_class_add_static_pad_template (element_class, &sink_factory);
168   gst_element_class_add_static_pad_template (element_class, &src_factory);
169 }
170
171 static void
172 gst_msdkh265dec_init (GstMsdkH265Dec * thiz)
173 {
174   thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;
175 }