taglist, plugins: fix compiler warnings with GLib >= 2.76
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / msdk / gstmsdkh264dec.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  /**
33  * SECTION: element-msdkh264dec
34  * @title: msdkh264dec
35  * @short_description: Intel MSDK H264 decoder
36  *
37  * H264 video decoder based on Intel MFX
38  *
39  * ## Example launch line
40  * ```
41  * gst-launch-1.0 filesrc location=sample.h264 ! h264parse ! msdkh264dec ! glimagesink
42  * ```
43  *
44  * Since: 1.12
45  *
46  */
47
48 #ifdef HAVE_CONFIG_H
49 #  include <config.h>
50 #endif
51
52 #include "gstmsdkh264dec.h"
53
54 GST_DEBUG_CATEGORY_EXTERN (gst_msdkh264dec_debug);
55 #define GST_CAT_DEFAULT gst_msdkh264dec_debug
56
57 #define COMMON_FORMAT "{ NV12, BGRA, BGRx }"
58
59 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
60     GST_PAD_SINK,
61     GST_PAD_ALWAYS,
62     GST_STATIC_CAPS ("video/x-h264, "
63         "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
64         "stream-format = (string) byte-stream , alignment = (string) au , "
65         "profile = (string) { high, progressive-high, constrained-high, main, baseline, constrained-baseline }")
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_msdkh264dec_parent_class parent_class
75 G_DEFINE_TYPE (GstMsdkH264Dec, gst_msdkh264dec, GST_TYPE_MSDKDEC);
76
77 static gboolean
78 gst_msdkh264dec_configure (GstMsdkDec * decoder)
79 {
80   GstMsdkH264Dec *h264dec = GST_MSDKH264DEC (decoder);
81
82   decoder->param.mfx.CodecId = MFX_CODEC_AVC;
83
84   /* This is a deprecated attribute in msdk-2017 version, but some
85    * customers still using this for low-latency streaming of non-b-frame
86    * encoded streams */
87   decoder->param.mfx.DecodedOrder = h264dec->output_order;
88
89 #if (MFX_VERSION >= 1025)
90   if (decoder->report_error) {
91     decoder->error_report.Header.BufferId = MFX_EXTBUFF_DECODE_ERROR_REPORT;
92     decoder->error_report.Header.BufferSz = sizeof (decoder->error_report);
93     decoder->error_report.ErrorTypes = 0;
94     gst_msdkdec_add_bs_extra_param (decoder,
95         (mfxExtBuffer *) & decoder->error_report);
96   }
97 #endif
98
99   return TRUE;
100 }
101
102 static void
103 gst_msdkdec_h264_set_property (GObject * object, guint prop_id,
104     const GValue * value, GParamSpec * pspec)
105 {
106   GstMsdkH264Dec *thiz = GST_MSDKH264DEC (object);
107 #if (MFX_VERSION >= 1025)
108   GstMsdkDec *dec = GST_MSDKDEC (object);
109 #endif
110   GstState state;
111
112   GST_OBJECT_LOCK (thiz);
113   state = GST_STATE (thiz);
114
115   if (!gst_msdkdec_prop_check_state (state, pspec)) {
116     GST_WARNING_OBJECT (thiz, "setting property in wrong state");
117     GST_OBJECT_UNLOCK (thiz);
118     return;
119   }
120   switch (prop_id) {
121     case GST_MSDKDEC_PROP_OUTPUT_ORDER:
122       thiz->output_order = g_value_get_enum (value);
123       break;
124 #if (MFX_VERSION >= 1025)
125     case GST_MSDKDEC_PROP_ERROR_REPORT:
126       dec->report_error = g_value_get_boolean (value);
127       break;
128 #endif
129     default:
130       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
131       break;
132   }
133   GST_OBJECT_UNLOCK (thiz);
134   return;
135 }
136
137 static void
138 gst_msdkdec_h264_get_property (GObject * object, guint prop_id, GValue * value,
139     GParamSpec * pspec)
140 {
141   GstMsdkH264Dec *thiz = GST_MSDKH264DEC (object);
142 #if (MFX_VERSION >= 1025)
143   GstMsdkDec *dec = GST_MSDKDEC (object);
144 #endif
145
146   GST_OBJECT_LOCK (thiz);
147   switch (prop_id) {
148     case GST_MSDKDEC_PROP_OUTPUT_ORDER:
149       g_value_set_enum (value, thiz->output_order);
150       break;
151 #if (MFX_VERSION >= 1025)
152     case GST_MSDKDEC_PROP_ERROR_REPORT:
153       g_value_set_boolean (value, dec->report_error);
154       break;
155 #endif
156     default:
157       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158       break;
159   }
160   GST_OBJECT_UNLOCK (thiz);
161 }
162
163 static void
164 gst_msdkh264dec_class_init (GstMsdkH264DecClass * klass)
165 {
166   GObjectClass *gobject_class;
167   GstElementClass *element_class;
168   GstMsdkDecClass *decoder_class;
169
170   gobject_class = G_OBJECT_CLASS (klass);
171   element_class = GST_ELEMENT_CLASS (klass);
172   decoder_class = GST_MSDKDEC_CLASS (klass);
173
174   gobject_class->set_property = gst_msdkdec_h264_set_property;
175   gobject_class->get_property = gst_msdkdec_h264_get_property;
176
177   decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkh264dec_configure);
178
179   gst_element_class_set_static_metadata (element_class,
180       "Intel MSDK H264 decoder",
181       "Codec/Decoder/Video/Hardware",
182       "H264 video decoder based on " MFX_API_SDK,
183       "Scott D Phillips <scott.d.phillips@intel.com>");
184
185   gst_msdkdec_prop_install_output_oder_property (gobject_class);
186
187 #if (MFX_VERSION >= 1025)
188   gst_msdkdec_prop_install_error_report_property (gobject_class);
189 #endif
190
191   gst_element_class_add_static_pad_template (element_class, &sink_factory);
192   gst_element_class_add_static_pad_template (element_class, &src_factory);
193 }
194
195 static void
196 gst_msdkh264dec_init (GstMsdkH264Dec * thiz)
197 {
198   thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;
199 }