1 /* GStreamer Intel MSDK plugin
2 * Copyright (c) 2018, Intel Corporation
5 * Sreerenj Balachandran <sreerenj.balachandran@intel.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright notice,
14 * this list of conditions and the following disclaimer in the documentation
15 * and/or other materials provided with the distribution.
17 * 3. Neither the name of the copyright holder nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGDECE
30 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 * SECTION: element-msdkvc1dec
37 * @short_description: Intel MSDK VC1 decoder
39 * VC1/WMV video decoder based on Intel MFX
41 * ## Example launch line
43 * gst-launch-1.0 filesrc location=video.wmv ! asfdemux ! vc1parse ! msdkvc1dec ! videoconvert ! xvimagesink
54 #include "gstmsdkvc1dec.h"
56 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvc1dec_debug);
57 #define GST_CAT_DEFAULT gst_msdkvc1dec_debug
59 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
62 GST_STATIC_CAPS ("video/x-wmv, "
63 "framerate = (fraction) [0/1, MAX], "
64 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
65 "wmvversion= (int) 3, "
66 "format= (string) WMV3, "
67 "header-format= (string) none, "
68 "stream-format= (string) sequence-layer-frame-layer, "
69 "profile = (string) {simple, main}" ";"
71 "framerate = (fraction) [0/1, MAX], "
72 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
73 "wmvversion= (int) 3, "
74 "format= (string) WVC1, "
75 "header-format= (string) asf, "
76 "stream-format= (string) bdu, " "profile = (string) advanced" ";")
79 #define gst_msdkvc1dec_parent_class parent_class
80 G_DEFINE_TYPE (GstMsdkVC1Dec, gst_msdkvc1dec, GST_TYPE_MSDKDEC);
83 gst_msdkvc1dec_configure (GstMsdkDec * decoder)
85 GstMsdkVC1Dec *vc1dec = GST_MSDKVC1DEC (decoder);
88 GstStructure *structure;
89 const gchar *profile_str;
91 caps = decoder->input_state->caps;
95 structure = gst_caps_get_structure (caps, 0);
99 decoder->param.mfx.CodecId = MFX_CODEC_VC1;
101 profile_str = gst_structure_get_string (structure, "profile");
103 if (!strcmp (profile_str, "simple"))
104 decoder->param.mfx.CodecProfile = MFX_PROFILE_VC1_SIMPLE;
105 else if (!strcmp (profile_str, "main"))
106 decoder->param.mfx.CodecProfile = MFX_PROFILE_VC1_MAIN;
108 decoder->param.mfx.CodecProfile = MFX_PROFILE_VC1_ADVANCED;
109 /* asf advanced profile codec-data has 1 byte in the beginning
110 * which is the ASF binding byte. MediaSDK can't recognize this
111 * byte, so discard it */
112 if (decoder->input_state->codec_data) {
113 buffer = gst_buffer_copy_region (decoder->input_state->codec_data,
114 GST_BUFFER_COPY_DEEP | GST_BUFFER_COPY_MEMORY, 1,
115 gst_buffer_get_size (decoder->input_state->codec_data) - 1);
116 gst_adapter_push (decoder->adapter, buffer);
119 gst_video_decoder_set_packetized (GST_VIDEO_DECODER (decoder), FALSE);
122 /* This is a deprecated attribute in msdk-2017 version, but some
123 * customers still using this for low-latency streaming of non-b-frame
125 decoder->param.mfx.DecodedOrder = vc1dec->output_order;
130 gst_msdkdec_vc1_set_property (GObject * object, guint prop_id,
131 const GValue * value, GParamSpec * pspec)
133 GstMsdkVC1Dec *thiz = GST_MSDKVC1DEC (object);
136 GST_OBJECT_LOCK (thiz);
137 state = GST_STATE (thiz);
139 if (!gst_msdkdec_prop_check_state (state, pspec)) {
140 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
141 GST_OBJECT_UNLOCK (thiz);
145 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
146 thiz->output_order = g_value_get_enum (value);
149 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
152 GST_OBJECT_UNLOCK (thiz);
157 gst_msdkdec_vc1_get_property (GObject * object, guint prop_id, GValue * value,
160 GstMsdkVC1Dec *thiz = GST_MSDKVC1DEC (object);
162 GST_OBJECT_LOCK (thiz);
164 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
165 g_value_set_enum (value, thiz->output_order);
168 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171 GST_OBJECT_UNLOCK (thiz);
175 gst_msdkvc1dec_preinit_decoder (GstMsdkDec * decoder)
177 decoder->param.mfx.FrameInfo.Width =
178 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.Width);
179 decoder->param.mfx.FrameInfo.Height =
180 GST_ROUND_UP_32 (decoder->param.mfx.FrameInfo.Height);
186 gst_msdkvc1dec_class_init (GstMsdkVC1DecClass * klass)
188 GObjectClass *gobject_class;
189 GstElementClass *element_class;
190 GstMsdkDecClass *decoder_class;
192 gobject_class = G_OBJECT_CLASS (klass);
193 element_class = GST_ELEMENT_CLASS (klass);
194 decoder_class = GST_MSDKDEC_CLASS (klass);
196 gobject_class->set_property = gst_msdkdec_vc1_set_property;
197 gobject_class->get_property = gst_msdkdec_vc1_get_property;
199 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkvc1dec_configure);
200 decoder_class->preinit_decoder =
201 GST_DEBUG_FUNCPTR (gst_msdkvc1dec_preinit_decoder);
203 gst_element_class_set_static_metadata (element_class,
204 "Intel MSDK VC1 decoder",
205 "Codec/Decoder/Video/Hardware",
206 "VC1/WMV video decoder based on " MFX_API_SDK,
207 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
209 gst_msdkdec_prop_install_output_oder_property (gobject_class);
211 gst_element_class_add_static_pad_template (element_class, &sink_factory);
215 gst_msdkvc1dec_init (GstMsdkVC1Dec * thiz)
217 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;