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.
34 /* sample pipeline: gst-launch-1.0 filesrc location=video.wmv ! asfdemux ! vc1parse ! msdkvc1dec ! videoconvert ! xvimagesink */
40 #include "gstmsdkvc1dec.h"
42 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvc1dec_debug);
43 #define GST_CAT_DEFAULT gst_msdkvc1dec_debug
45 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
48 GST_STATIC_CAPS ("video/x-wmv, "
49 "framerate = (fraction) [0/1, MAX], "
50 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
51 "wmvversion= (int) 3, "
52 "format= (string) WMV3, "
53 "header-format= (string) none, "
54 "stream-format= (string) sequence-layer-frame-layer, "
55 "profile = (string) {simple, main}" ";"
57 "framerate = (fraction) [0/1, MAX], "
58 "width = (int) [ 1, MAX ], height = (int) [ 1, MAX ], "
59 "wmvversion= (int) 3, "
60 "format= (string) WVC1, "
61 "header-format= (string) asf, "
62 "stream-format= (string) bdu, " "profile = (string) advanced" ";")
65 #define gst_msdkvc1dec_parent_class parent_class
66 G_DEFINE_TYPE (GstMsdkVC1Dec, gst_msdkvc1dec, GST_TYPE_MSDKDEC);
69 gst_msdkvc1dec_configure (GstMsdkDec * decoder)
71 GstMsdkVC1Dec *vc1dec = GST_MSDKVC1DEC (decoder);
74 GstStructure *structure;
75 const gchar *profile_str;
77 caps = decoder->input_state->caps;
81 structure = gst_caps_get_structure (caps, 0);
85 decoder->postpone_free_surface = TRUE;
86 decoder->param.mfx.CodecId = MFX_CODEC_VC1;
88 profile_str = gst_structure_get_string (structure, "profile");
90 if (!strcmp (profile_str, "simple"))
91 decoder->param.mfx.CodecProfile = MFX_PROFILE_VC1_SIMPLE;
92 else if (!strcmp (profile_str, "main"))
93 decoder->param.mfx.CodecProfile = MFX_PROFILE_VC1_MAIN;
95 decoder->param.mfx.CodecProfile = MFX_PROFILE_VC1_ADVANCED;
96 /* asf advanced profile codec-data has 1 byte in the beginning
97 * which is the ASF binding byte. MediaSDK can't recognize this
98 * byte, so discard it */
99 if (decoder->input_state->codec_data) {
100 buffer = gst_buffer_copy_region (decoder->input_state->codec_data,
101 GST_BUFFER_COPY_DEEP | GST_BUFFER_COPY_MEMORY, 1,
102 gst_buffer_get_size (decoder->input_state->codec_data) - 1);
103 gst_adapter_push (decoder->adapter, buffer);
106 gst_video_decoder_set_packetized (GST_VIDEO_DECODER (decoder), FALSE);
109 /* This is a deprecated attribute in msdk-2017 version, but some
110 * customers still using this for low-latency streaming of non-b-frame
112 decoder->param.mfx.DecodedOrder = vc1dec->output_order;
117 gst_msdkdec_vc1_set_property (GObject * object, guint prop_id,
118 const GValue * value, GParamSpec * pspec)
120 GstMsdkVC1Dec *thiz = GST_MSDKVC1DEC (object);
123 GST_OBJECT_LOCK (thiz);
124 state = GST_STATE (thiz);
126 if (!gst_msdkdec_prop_check_state (state, pspec)) {
127 GST_WARNING_OBJECT (thiz, "setting property in wrong state");
128 GST_OBJECT_UNLOCK (thiz);
132 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
133 thiz->output_order = g_value_get_enum (value);
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
139 GST_OBJECT_UNLOCK (thiz);
144 gst_msdkdec_vc1_get_property (GObject * object, guint prop_id, GValue * value,
147 GstMsdkVC1Dec *thiz = GST_MSDKVC1DEC (object);
149 GST_OBJECT_LOCK (thiz);
151 case GST_MSDKDEC_PROP_OUTPUT_ORDER:
152 g_value_set_enum (value, thiz->output_order);
155 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
158 GST_OBJECT_UNLOCK (thiz);
162 gst_msdkvc1dec_preinit_decoder (GstMsdkDec * decoder)
164 decoder->param.mfx.FrameInfo.Width =
165 GST_ROUND_UP_16 (decoder->param.mfx.FrameInfo.Width);
166 decoder->param.mfx.FrameInfo.Height =
167 GST_ROUND_UP_32 (decoder->param.mfx.FrameInfo.Height);
173 gst_msdkvc1dec_class_init (GstMsdkVC1DecClass * klass)
175 GObjectClass *gobject_class;
176 GstElementClass *element_class;
177 GstMsdkDecClass *decoder_class;
179 gobject_class = G_OBJECT_CLASS (klass);
180 element_class = GST_ELEMENT_CLASS (klass);
181 decoder_class = GST_MSDKDEC_CLASS (klass);
183 gobject_class->set_property = gst_msdkdec_vc1_set_property;
184 gobject_class->get_property = gst_msdkdec_vc1_get_property;
186 decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkvc1dec_configure);
187 decoder_class->preinit_decoder =
188 GST_DEBUG_FUNCPTR (gst_msdkvc1dec_preinit_decoder);
190 gst_element_class_set_static_metadata (element_class,
191 "Intel MSDK VC1 decoder",
192 "Codec/Decoder/Video/Hardware",
193 "VC1/WMV video decoder based on Intel Media SDK",
194 "Sreerenj Balachandran <sreerenj.balachandran@intel.com>");
196 gst_msdkdec_prop_install_output_oder_property (gobject_class);
198 gst_element_class_add_static_pad_template (element_class, &sink_factory);
202 gst_msdkvc1dec_init (GstMsdkVC1Dec * thiz)
204 thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;