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
gst_msdkmjpegdec_configure(GstMsdkDec * decoder)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 return TRUE;
93 }
94
95 static gboolean
gst_msdkmjpegdec_post_configure(GstMsdkDec * decoder)96 gst_msdkmjpegdec_post_configure (GstMsdkDec * decoder)
97 {
98 /* Set the output color format based on the input color format */
99 switch (decoder->param.mfx.JPEGChromaFormat) {
100 case MFX_CHROMAFORMAT_YUV422:
101 decoder->param.mfx.FrameInfo.FourCC = MFX_FOURCC_YUY2;
102 decoder->param.mfx.FrameInfo.ChromaFormat =
103 decoder->param.mfx.JPEGChromaFormat;
104 break;
105 default:
106 break;
107 }
108
109 return TRUE;
110 }
111
112 static void
gst_msdkmjpegdec_class_init(GstMsdkMJPEGDecClass * klass)113 gst_msdkmjpegdec_class_init (GstMsdkMJPEGDecClass * klass)
114 {
115 GstElementClass *element_class;
116 GstMsdkDecClass *decoder_class;
117
118 element_class = GST_ELEMENT_CLASS (klass);
119 decoder_class = GST_MSDKDEC_CLASS (klass);
120
121 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_configure);
122 decoder_class->post_configure =
123 GST_DEBUG_FUNCPTR (gst_msdkmjpegdec_post_configure);
124
125 gst_element_class_set_static_metadata (element_class,
126 "Intel MSDK MJPEG decoder",
127 "Codec/Decoder/Video/Hardware",
128 "MJPEG video decoder based on " MFX_API_SDK,
129 "Scott D Phillips <scott.d.phillips@intel.com>");
130
131 gst_element_class_add_static_pad_template (element_class, &sink_factory);
132 gst_element_class_add_static_pad_template (element_class, &src_factory);
133 }
134
135 static void
gst_msdkmjpegdec_init(GstMsdkMJPEGDec * thiz)136 gst_msdkmjpegdec_init (GstMsdkMJPEGDec * thiz)
137 {
138 }
139