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 <mfxstructures.h>
37 #include <mfxjpeg.h>
38 
39 #include "gstmsdkmjpegdec.h"
40 
41 #include <gst/pbutils/pbutils.h>
42 
43 GST_DEBUG_CATEGORY_EXTERN (gst_msdkmjpegdec_debug);
44 #define GST_CAT_DEFAULT gst_msdkmjpegdec_debug
45 
46 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
47     GST_PAD_SINK,
48     GST_PAD_ALWAYS,
49     GST_STATIC_CAPS ("image/jpeg, "
50         "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], parsed = true ")
51     );
52 
53 #define gst_msdkmjpegdec_parent_class parent_class
54 G_DEFINE_TYPE (GstMsdkMJPEGDec, gst_msdkmjpegdec, GST_TYPE_MSDKDEC);
55 
56 static gboolean
gst_msdkmjpegdec_configure(GstMsdkDec * decoder)57 gst_msdkmjpegdec_configure (GstMsdkDec * decoder)
58 {
59   decoder->param.mfx.CodecId = MFX_CODEC_JPEG;
60 
61   /* HACK to make sure MSDK won't crash while handling non-interleaved samples */
62   /* setting MFX_SCANTYPE_UNKNOWN (== 0) causing issues for
63      non-interleaved samples. Usage of MFXVideoDECODE_DecodeHeader
64      also doesn't seems to fix the issue. But even if we hardcode
65      the InterleaveDec to MFX_SCANTYPE_NONINTERLEAVED, msdk seems to be taking care
66      of Interleaved samples, so let's hardcode it for now */
67   decoder->param.mfx.InterleavedDec = MFX_SCANTYPE_NONINTERLEAVED;
68   return TRUE;
69 }
70 
71 static void
gst_msdkmjpegdec_class_init(GstMsdkMJPEGDecClass * klass)72 gst_msdkmjpegdec_class_init (GstMsdkMJPEGDecClass * klass)
73 {
74   GstElementClass *element_class;
75   GstMsdkDecClass *decoder_class;
76 
77   element_class = GST_ELEMENT_CLASS (klass);
78   decoder_class = GST_MSDKDEC_CLASS (klass);
79 
80   decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_configure);
81 
82   gst_element_class_set_static_metadata (element_class,
83       "Intel MSDK MJPEG decoder",
84       "Codec/Decoder/Video/Hardware",
85       "MJPEG video decoder based on Intel Media SDK",
86       "Scott D Phillips <scott.d.phillips@intel.com>");
87 
88   gst_element_class_add_static_pad_template (element_class, &sink_factory);
89 }
90 
91 static void
gst_msdkmjpegdec_init(GstMsdkMJPEGDec * thiz)92 gst_msdkmjpegdec_init (GstMsdkMJPEGDec * thiz)
93 {
94 }
95