documentation: fixed a heap o' typos
[platform/upstream/gstreamer.git] / sys / msdk / gstmsdkvc1dec.c
1 /* GStreamer Intel MSDK plugin
2  * Copyright (c) 2018, Intel Corporation
3  * All rights reserved.
4  *
5  * Sreerenj Balachandran <sreerenj.balachandran@intel.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  *    this list of conditions and the following disclaimer.
12  *
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.
16  *
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.
20  *
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.
32  */
33
34 /* sample pipeline: gst-launch-1.0 filesrc location=video.wmv ! asfdemux ! vc1parse !  msdkvc1dec ! videoconvert ! xvimagesink */
35
36 #ifdef HAVE_CONFIG_H
37 #  include <config.h>
38 #endif
39
40 #include "gstmsdkvc1dec.h"
41
42 GST_DEBUG_CATEGORY_EXTERN (gst_msdkvc1dec_debug);
43 #define GST_CAT_DEFAULT gst_msdkvc1dec_debug
44
45 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink",
46     GST_PAD_SINK,
47     GST_PAD_ALWAYS,
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}" ";"
56         "video/x-wmv, "
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" ";")
63     );
64
65 #define gst_msdkvc1dec_parent_class parent_class
66 G_DEFINE_TYPE (GstMsdkVC1Dec, gst_msdkvc1dec, GST_TYPE_MSDKDEC);
67
68 static gboolean
69 gst_msdkvc1dec_configure (GstMsdkDec * decoder)
70 {
71   GstMsdkVC1Dec *vc1dec = GST_MSDKVC1DEC (decoder);
72   GstBuffer *buffer;
73   GstCaps *caps;
74   GstStructure *structure;
75   const gchar *profile_str;
76
77   caps = decoder->input_state->caps;
78   if (!caps)
79     return FALSE;
80
81   structure = gst_caps_get_structure (caps, 0);
82   if (!structure)
83     return FALSE;
84
85   decoder->postpone_free_surface = TRUE;
86   decoder->param.mfx.CodecId = MFX_CODEC_VC1;
87
88   profile_str = gst_structure_get_string (structure, "profile");
89
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;
94   else {
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);
104     }
105
106     gst_video_decoder_set_packetized (GST_VIDEO_DECODER (decoder), FALSE);
107   }
108
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
111    * encoded streams */
112   decoder->param.mfx.DecodedOrder = vc1dec->output_order;
113   return TRUE;
114 }
115
116 static void
117 gst_msdkdec_vc1_set_property (GObject * object, guint prop_id,
118     const GValue * value, GParamSpec * pspec)
119 {
120   GstMsdkVC1Dec *thiz = GST_MSDKVC1DEC (object);
121   GstState state;
122
123   GST_OBJECT_LOCK (thiz);
124   state = GST_STATE (thiz);
125
126   if (!gst_msdkdec_prop_check_state (state, pspec)) {
127     GST_WARNING_OBJECT (thiz, "setting property in wrong state");
128     GST_OBJECT_UNLOCK (thiz);
129     return;
130   }
131   switch (prop_id) {
132     case GST_MSDKDEC_PROP_OUTPUT_ORDER:
133       thiz->output_order = g_value_get_enum (value);
134       break;
135     default:
136       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137       break;
138   }
139   GST_OBJECT_UNLOCK (thiz);
140   return;
141 }
142
143 static void
144 gst_msdkdec_vc1_get_property (GObject * object, guint prop_id, GValue * value,
145     GParamSpec * pspec)
146 {
147   GstMsdkVC1Dec *thiz = GST_MSDKVC1DEC (object);
148
149   GST_OBJECT_LOCK (thiz);
150   switch (prop_id) {
151     case GST_MSDKDEC_PROP_OUTPUT_ORDER:
152       g_value_set_enum (value, thiz->output_order);
153       break;
154     default:
155       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
156       break;
157   }
158   GST_OBJECT_UNLOCK (thiz);
159 }
160
161 static gboolean
162 gst_msdkvc1dec_preinit_decoder (GstMsdkDec * decoder)
163 {
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);
168
169   return TRUE;
170 }
171
172 static void
173 gst_msdkvc1dec_class_init (GstMsdkVC1DecClass * klass)
174 {
175   GObjectClass *gobject_class;
176   GstElementClass *element_class;
177   GstMsdkDecClass *decoder_class;
178
179   gobject_class = G_OBJECT_CLASS (klass);
180   element_class = GST_ELEMENT_CLASS (klass);
181   decoder_class = GST_MSDKDEC_CLASS (klass);
182
183   gobject_class->set_property = gst_msdkdec_vc1_set_property;
184   gobject_class->get_property = gst_msdkdec_vc1_get_property;
185
186   decoder_class->configure = GST_DEBUG_FUNCPTR (gst_msdkvc1dec_configure);
187   decoder_class->preinit_decoder =
188       GST_DEBUG_FUNCPTR (gst_msdkvc1dec_preinit_decoder);
189
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>");
195
196   gst_msdkdec_prop_install_output_oder_property (gobject_class);
197
198   gst_element_class_add_static_pad_template (element_class, &sink_factory);
199 }
200
201 static void
202 gst_msdkvc1dec_init (GstMsdkVC1Dec * thiz)
203 {
204   thiz->output_order = PROP_OUTPUT_ORDER_DEFAULT;
205 }