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 "gstmsdkh264dec.h"
37
38 GST_DEBUG_CATEGORY_EXTERN (gst_msdkh264dec_debug);
39 #define GST_CAT_DEFAULT gst_msdkh264dec_debug
40
41 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
42 GST_PAD_SINK,
43 GST_PAD_ALWAYS,
44 GST_STATIC_CAPS ("video/x-h264, "
45 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
46 "stream-format = (string) byte-stream , alignment = (string) au , "
47 "profile = (string) { high, main, baseline, constrained-baseline }")
48 );
49
50 #define gst_msdkh264dec_parent_class parent_class
51 G_DEFINE_TYPE (GstMsdkH264Dec, gst_msdkh264dec, GST_TYPE_MSDKDEC);
52
53 static gboolean
gst_msdkh264dec_configure(GstMsdkDec * decoder)54 gst_msdkh264dec_configure (GstMsdkDec * decoder)
55 {
56 GstMsdkH264Dec *h264dec = GST_MSDKH264DEC (decoder);
57
58 decoder->param.mfx.CodecId = MFX_CODEC_AVC;
59
60 /* This is a deprecated attribute in msdk-2017 version, but some
61 * customers still using this for low-latency streaming of non-b-frame
62 * encoded streams */
63 decoder->param.mfx.DecodedOrder = h264dec->output_order;
64 return TRUE;
65 }
66
67 static void
gst_msdkdec_h264_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)68 gst_msdkdec_h264_set_property (GObject * object, guint prop_id,
69 const GValue * value, GParamSpec * pspec)
70 {
71 GstMsdkH264Dec *thiz = GST_MSDKH264DEC (object);
72 GstState state;
73
74 GST_OBJECT_LOCK (thiz);
75 state = GST_STATE (thiz);
76
77 if (!gst_msdkdec_prop_check_state (state, pspec)) {
78 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
79 GST_OBJECT_UNLOCK (thiz);
80 return;
81 }
82 switch (prop_id) {
83 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
84 thiz->output_order = g_value_get_enum (value);
85 break;
86 default:
87 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
88 break;
89 }
90 GST_OBJECT_UNLOCK (thiz);
91 return;
92 }
93
94 static void
gst_msdkdec_h264_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)95 gst_msdkdec_h264_get_property (GObject * object, guint prop_id, GValue * value,
96 GParamSpec * pspec)
97 {
98 GstMsdkH264Dec *thiz = GST_MSDKH264DEC (object);
99
100 GST_OBJECT_LOCK (thiz);
101 switch (prop_id) {
102 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
103 g_value_set_enum (value, thiz->output_order);
104 break;
105 default:
106 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
107 break;
108 }
109 GST_OBJECT_UNLOCK (thiz);
110 }
111
112 static void
gst_msdkh264dec_class_init(GstMsdkH264DecClass * klass)113 gst_msdkh264dec_class_init (GstMsdkH264DecClass * klass)
114 {
115 GObjectClass *gobject_class;
116 GstElementClass *element_class;
117 GstMsdkDecClass *decoder_class;
118
119 gobject_class = G_OBJECT_CLASS (klass);
120 element_class = GST_ELEMENT_CLASS (klass);
121 decoder_class = GST_MSDKDEC_CLASS (klass);
122
123 gobject_class->set_property = gst_msdkdec_h264_set_property;
124 gobject_class->get_property = gst_msdkdec_h264_get_property;
125
126 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkh264dec_configure);
127
128 gst_element_class_set_static_metadata (element_class,
129 "Intel MSDK H264 decoder",
130 "Codec/Decoder/Video/Hardware",
131 "H264 video decoder based on Intel Media SDK",
132 "Scott D Phillips <scott.d.phillips@intel.com>");
133
134 gst_msdkdec_prop_install_output_oder_property (gobject_class);
135
136 gst_element_class_add_static_pad_template (element_class, &sink_factory);
137 }
138
139 static void
gst_msdkh264dec_init(GstMsdkH264Dec * thiz)140 gst_msdkh264dec_init (GstMsdkH264Dec * thiz)
141 {
142 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;
143 }
144