taglist, plugins: fix compiler warnings with GLib >= 2.76
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / sys / msdk / gstmsdkmjpegdec.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-msdkmjpegdec
34  * @title: msdkmjpegdec
35  * @short_description: Intel MSDK MJPEG decoder
36  *
37  * MJPEG video decoder based on Intel MFX
38  *
39  * ## Example launch line
40  * ```
41  * gst-launch-1.0 filesrc location=sample.jpg ! jpegparse ! msdkmjpegdec ! glimagesink
42  * ```
43  *
44  * Since: 1.12
45  *
46  */
47
48 #ifdef HAVE_CONFIG_H
49 #  include <config.h>
50 #endif
51
52 #include <mfxstructures.h>
53 #include <mfxjpeg.h>
54
55 #include "gstmsdkmjpegdec.h"
56 #include "gstmsdkvideomemory.h"
57
58 #include <gst/pbutils/pbutils.h>
59
60 GST_DEBUG_CATEGORY_EXTERN (gst_msdkmjpegdec_debug);
61 #define GST_CAT_DEFAULT gst_msdkmjpegdec_debug
62
63 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
64     GST_PAD_SINK,
65     GST_PAD_ALWAYS,
66     GST_STATIC_CAPS ("image/jpeg, "
67         "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], parsed = true ")
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 ("{ NV12, YUY2 }", "{ NV12, YUY2 }"))
74     );
75
76 #define gst_msdkmjpegdec_parent_class parent_class
77 G_DEFINE_TYPE (GstMsdkMJPEGDec, gst_msdkmjpegdec, GST_TYPE_MSDKDEC);
78
79 static gboolean
80 gst_msdkmjpegdec_configure (GstMsdkDec * decoder)
81 {
82   decoder->param.mfx.CodecId = MFX_CODEC_JPEG;
83
84   /* HACK to make sure MSDK won't crash while handling non-interleaved samples */
85   /* setting MFX_SCANTYPE_UNKNOWN (== 0) causing issues for
86      non-interleaved samples. Usage of MFXVideoDECODE_DecodeHeader
87      also doesn't seems to fix the issue. But even if we hardcode
88      the InterleaveDec to MFX_SCANTYPE_NONINTERLEAVED, msdk seems to be taking care
89      of Interleaved samples, so let's hardcode it for now */
90   decoder->param.mfx.InterleavedDec = MFX_SCANTYPE_NONINTERLEAVED;
91
92 #if (MFX_VERSION >= 2006)
93   if (decoder->report_error) {
94     decoder->error_report.Header.BufferId = MFX_EXTBUFF_DECODE_ERROR_REPORT;
95     decoder->error_report.Header.BufferSz = sizeof (decoder->error_report);
96     decoder->error_report.ErrorTypes = 0;
97     gst_msdkdec_add_bs_extra_param (decoder,
98         (mfxExtBuffer *) & decoder->error_report);
99   }
100 #endif
101
102   return TRUE;
103 }
104
105 static gboolean
106 gst_msdkmjpegdec_post_configure (GstMsdkDec * decoder)
107 {
108   /* Set the output color format based on the input color format */
109   switch (decoder->param.mfx.JPEGChromaFormat) {
110     case MFX_CHROMAFORMAT_YUV422:
111       decoder->param.mfx.FrameInfo.FourCC = MFX_FOURCC_YUY2;
112       decoder->param.mfx.FrameInfo.ChromaFormat =
113           decoder->param.mfx.JPEGChromaFormat;
114       break;
115     default:
116       break;
117   }
118
119   return TRUE;
120 }
121
122 static void
123 gst_msdkdec_mjpeg_set_property (GObject * object, guint prop_id,
124     const GValue * value, GParamSpec * pspec)
125 {
126   GstMsdkMJPEGDec *thiz = GST_MSDKMJPEGDEC (object);
127 #if (MFX_VERSION >= 2006)
128   GstMsdkDec *dec = GST_MSDKDEC (object);
129 #endif
130   GstState state;
131
132   GST_OBJECT_LOCK (thiz);
133   state = GST_STATE (thiz);
134
135   if (!gst_msdkdec_prop_check_state (state, pspec)) {
136     GST_WARNING_OBJECT (thiz, "setting property in wrong state");
137     GST_OBJECT_UNLOCK (thiz);
138     return;
139   }
140   switch (prop_id) {
141 #if (MFX_VERSION >= 2006)
142     case GST_MSDKDEC_PROP_ERROR_REPORT:
143       dec->report_error = g_value_get_boolean (value);
144       break;
145 #endif
146     default:
147       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148       break;
149   }
150   GST_OBJECT_UNLOCK (thiz);
151   return;
152 }
153
154 static void
155 gst_msdkdec_mjpeg_get_property (GObject * object, guint prop_id, GValue * value,
156     GParamSpec * pspec)
157 {
158   GstMsdkMJPEGDec *thiz = GST_MSDKMJPEGDEC (object);
159 #if (MFX_VERSION >= 2006)
160   GstMsdkDec *dec = GST_MSDKDEC (object);
161 #endif
162
163   GST_OBJECT_LOCK (thiz);
164   switch (prop_id) {
165 #if (MFX_VERSION >= 2006)
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
178 gst_msdkmjpegdec_class_init (GstMsdkMJPEGDecClass * 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_mjpeg_set_property;
189   gobject_class->get_property = gst_msdkdec_mjpeg_get_property;
190
191   decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_configure);
192   decoder_class->post_configure =
193       GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_post_configure);
194
195   gst_element_class_set_static_metadata (element_class,
196       "Intel MSDK MJPEG decoder",
197       "Codec/Decoder/Video/Hardware",
198       "MJPEG video decoder based on " MFX_API_SDK,
199       "Scott D Phillips <scott.d.phillips@intel.com>");
200
201 #if (MFX_VERSION >= 2006)
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
210 gst_msdkmjpegdec_init (GstMsdkMJPEGDec * thiz)
211 {
212 }