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-msdkmjpegdec
34 * @title: msdkmjpegdec
35 * @short_description: Intel MSDK MJPEG decoder
37 * MJPEG video decoder based on Intel MFX
39 * ## Example launch line
41 * gst-launch-1.0 filesrc location=sample.jpg ! jpegparse ! msdkmjpegdec ! glimagesink
52 #include <mfxstructures.h>
55 #include "gstmsdkmjpegdec.h"
56 #include "gstmsdkvideomemory.h"
58 #include <gst/pbutils/pbutils.h>
60 GST_DEBUG_CATEGORY_EXTERN (gst_msdkmjpegdec_debug);
61 #define GST_CAT_DEFAULT gst_msdkmjpegdec_debug
63 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
66 GST_STATIC_CAPS ("image/jpeg, "
67 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], parsed = true ")
70 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
73 GST_STATIC_CAPS (GST_MSDK_CAPS_STR ("{ NV12, YUY2 }", "{ NV12, YUY2 }"))
76 #define gst_msdkmjpegdec_parent_class parent_class
77 G_DEFINE_TYPE (GstMsdkMJPEGDec, gst_msdkmjpegdec, GST_TYPE_MSDKDEC);
80 gst_msdkmjpegdec_configure (GstMsdkDec * decoder)
82 decoder->param.mfx.CodecId = MFX_CODEC_JPEG;
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;
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);
106 gst_msdkmjpegdec_post_configure (GstMsdkDec * decoder)
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;
123 gst_msdkdec_mjpeg_set_property (GObject * object, guint prop_id,
124 const GValue * value, GParamSpec * pspec)
126 GstMsdkMJPEGDec *thiz = GST_MSDKMJPEGDEC (object);
127 #if (MFX_VERSION >= 2006)
128 GstMsdkDec *dec = GST_MSDKDEC (object);
132 GST_OBJECT_LOCK (thiz);
133 state = GST_STATE (thiz);
135 if (!gst_msdkdec_prop_check_state (state, pspec)) {
136 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
137 GST_OBJECT_UNLOCK (thiz);
141 #if (MFX_VERSION >= 2006)
142 case GST_MSDKDEC_PROP_ERROR_REPORT:
143 dec->report_error = g_value_get_boolean (value);
147 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
150 GST_OBJECT_UNLOCK (thiz);
155 gst_msdkdec_mjpeg_get_property (GObject * object, guint prop_id, GValue * value,
158 GstMsdkMJPEGDec *thiz = GST_MSDKMJPEGDEC (object);
159 #if (MFX_VERSION >= 2006)
160 GstMsdkDec *dec = GST_MSDKDEC (object);
163 GST_OBJECT_LOCK (thiz);
165 #if (MFX_VERSION >= 2006)
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_msdkmjpegdec_class_init (GstMsdkMJPEGDecClass * 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_mjpeg_set_property;
189 gobject_class->get_property = gst_msdkdec_mjpeg_get_property;
191 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_configure);
192 decoder_class->post_configure =
193 GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_post_configure);
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>");
201 #if (MFX_VERSION >= 2006)
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_msdkmjpegdec_init (GstMsdkMJPEGDec * thiz)