Tizen 2.0 Release
[framework/multimedia/gstreamer-vaapi.git] / gst / vaapi / gstvaapiencode_mpeg4.c
1 /*
2  *  gstvaapiencode_mpeg4.c - VA-API MPEG-4 encoder
3  *
4  *  Copyright (C) 2011 Intel Corporation
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Lesser General Public License
8  *  as published by the Free Software Foundation; either version 2.1
9  *  of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Lesser General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Lesser General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  *  Boston, MA 02110-1301 USA
20  */
21
22 #include "gstvaapiencode_mpeg4.h"
23 #include "gst/vaapi/gstvaapiencoder_mpeg4.h"
24
25 GST_DEBUG_CATEGORY_STATIC (gst_vaapi_encode_mpeg4_debug);
26 #define GST_CAT_DEFAULT gst_vaapi_encode_mpeg4_debug
27
28
29 static const char gst_vaapi_encode_mpeg4_sink_caps_str[] =
30     GST_VAAPI_SURFACE_CAPS "; "
31     GST_VAAPI_BUFFER_SHARING_CAPS;
32
33 static const GstElementDetails gst_vaapi_encode_mpeg4_details =
34     GST_ELEMENT_DETAILS(
35         "VA-API mpeg4 encoder",
36         "Codec/Encoder/Video",
37         "A VA-API based mpeg4 encoder",
38         "Feng Yuan<feng.yuan@intel.com>");
39
40
41 static const char gst_vaapi_encode_mpeg4_src_caps_str[] =
42     GST_CAPS_CODEC("video/mpeg, mpegversion=4");
43
44 static GstStaticPadTemplate gst_vaapi_encode_mpeg4_sink_factory =
45     GST_STATIC_PAD_TEMPLATE(
46         "sink",
47         GST_PAD_SINK,
48         GST_PAD_ALWAYS,
49         GST_STATIC_CAPS(gst_vaapi_encode_mpeg4_sink_caps_str));
50
51 static GstStaticPadTemplate gst_vaapi_encode_mpeg4_src_factory =
52     GST_STATIC_PAD_TEMPLATE(
53         "src",
54         GST_PAD_SRC,
55         GST_PAD_ALWAYS,
56         GST_STATIC_CAPS(gst_vaapi_encode_mpeg4_src_caps_str));
57
58
59 /* mpeg4 encode */
60 GST_BOILERPLATE(
61     GstVaapiEncodeMpeg4,
62     gst_vaapi_encode_mpeg4,
63     GstVaapiEncode,
64     GST_TYPE_VAAPI_ENCODE)
65
66 enum {
67     MPEG4_PROP_0,
68     MPEG4_PROP_PROFILE,
69     MPEG4_PROP_BITRATE,
70     MPEG4_PROP_INTRA_PERIOD,
71     MPEG4_PROP_INIT_QP,
72     MPEG4_PROP_MIN_QP,
73 };
74
75 static void
76 gst_vaapi_encode_mpeg4_init(
77     GstVaapiEncodeMpeg4 *mpeg4_encode,
78     GstVaapiEncodeMpeg4Class *klass)
79 {
80   GstVaapiEncode *encode = GST_VAAPI_ENCODE(mpeg4_encode);
81   encode->encoder = GST_VAAPI_ENCODER(gst_vaapi_encoder_mpeg4_new());
82   ENCODER_ASSERT(encode->encoder);
83 }
84
85 static void
86 gst_vaapi_encode_mpeg4_finalize(GObject *object)
87 {
88   //GstVaapiEncodeMpeg4 * const mpeg4_encode = GST_VAAPI_ENCODE_MPEG4(object);
89   G_OBJECT_CLASS(parent_class)->finalize(object);
90 }
91
92 static void
93 gst_vaapi_encode_mpeg4_set_property(
94     GObject *object,
95     guint prop_id,
96     const GValue *value,
97     GParamSpec *pspec
98 )
99 {
100   GstVaapiEncode *encode = GST_VAAPI_ENCODE(object);
101   GstVaapiEncoderMpeg4 *mpeg4encoder = GST_VAAPI_ENCODER_MPEG4(encode->encoder);
102
103   ENCODER_ASSERT(mpeg4encoder);
104
105   switch (prop_id) {
106     case MPEG4_PROP_PROFILE: {
107       mpeg4encoder->profile = g_value_get_uint(value);
108     }
109       break;
110
111     case MPEG4_PROP_BITRATE: {
112       mpeg4encoder->bitrate = g_value_get_uint(value);
113     }
114       break;
115
116     case MPEG4_PROP_INTRA_PERIOD: {
117       mpeg4encoder->intra_period = g_value_get_uint(value);
118     }
119       break;
120
121     case MPEG4_PROP_INIT_QP: {
122       mpeg4encoder->init_qp = g_value_get_uint(value);
123     }
124       break;
125
126     case MPEG4_PROP_MIN_QP: {
127       mpeg4encoder->min_qp = g_value_get_uint(value);
128     }
129       break;
130
131     default:
132       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
133       break;
134   }
135 }
136
137 static void
138 gst_vaapi_encode_mpeg4_get_property(
139     GObject * object,
140     guint prop_id,
141     GValue * value,
142     GParamSpec * pspec
143 )
144 {
145   GstVaapiEncode *encode = GST_VAAPI_ENCODE(object);
146   GstVaapiEncoderMpeg4 *mpeg4encoder = GST_VAAPI_ENCODER_MPEG4(encode->encoder);
147   ENCODER_ASSERT(mpeg4encoder);
148
149   switch (prop_id) {
150     case MPEG4_PROP_PROFILE:
151       g_value_set_uint (value, mpeg4encoder->profile);
152       break;
153
154     case MPEG4_PROP_BITRATE:
155       g_value_set_uint (value, mpeg4encoder->bitrate);
156       break;
157
158     case MPEG4_PROP_INTRA_PERIOD:
159       g_value_set_uint (value, mpeg4encoder->intra_period);
160       break;
161
162     case MPEG4_PROP_INIT_QP:
163       g_value_set_uint (value, mpeg4encoder->init_qp);
164       break;
165
166     case MPEG4_PROP_MIN_QP:
167       g_value_set_uint (value, mpeg4encoder->min_qp);
168       break;
169
170     default:
171       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
172       break;
173   }
174 }
175
176 static void
177 gst_vaapi_encode_mpeg4_base_init(gpointer klass)
178 {
179   GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
180
181   gst_element_class_set_details(element_class, &gst_vaapi_encode_mpeg4_details);
182
183   /* sink pad */
184   gst_element_class_add_pad_template(
185       element_class,
186       gst_static_pad_template_get(&gst_vaapi_encode_mpeg4_sink_factory)
187   );
188
189   /* src pad */
190   gst_element_class_add_pad_template(
191       element_class,
192       gst_static_pad_template_get(&gst_vaapi_encode_mpeg4_src_factory)
193   );
194 }
195
196 static void
197 gst_vaapi_encode_mpeg4_class_init(GstVaapiEncodeMpeg4Class *klass)
198 {
199   GObjectClass * const object_class = G_OBJECT_CLASS(klass);
200
201   GST_DEBUG_CATEGORY_INIT (gst_vaapi_encode_mpeg4_debug,
202                            "vaapimpeg4encode",
203                            0,
204                            "vaapimpeg4encode element");
205
206   object_class->finalize      = gst_vaapi_encode_mpeg4_finalize;
207   object_class->set_property  = gst_vaapi_encode_mpeg4_set_property;
208   object_class->get_property  = gst_vaapi_encode_mpeg4_get_property;
209
210
211   g_object_class_install_property (
212       object_class,
213       MPEG4_PROP_PROFILE,
214       g_param_spec_uint (
215           "profile",
216           "MPEG4 Profile",
217           "Profile supports: 2(Baseline), 3(ASP)",
218           2,
219           3,
220           2,
221           G_PARAM_READWRITE));
222
223   g_object_class_install_property (
224       object_class,
225       MPEG4_PROP_BITRATE,
226       g_param_spec_uint (
227           "bitrate",
228           "MPEG4 encoding bitrate(kpbs)",
229           "MPEG4 encoding bitrate(kpbs), (0, auto-calculate)",
230           0,
231           100*1024,
232           0,
233           G_PARAM_READWRITE));
234
235   g_object_class_install_property (
236       object_class,
237       MPEG4_PROP_INTRA_PERIOD,
238       g_param_spec_uint (
239           "intra-period",
240           "MPEG4 encoding intra-period",
241           "MPEG4 encoding intra-period",
242           1,
243           300,
244           MPEG4_DEFAULT_INTRA_PERIOD,
245           G_PARAM_READWRITE));
246
247   g_object_class_install_property (
248       object_class,
249       MPEG4_PROP_INIT_QP,
250       g_param_spec_uint (
251           "init-qp",
252           "MPEG4 init-qp",
253           "MPEG4 init-qp",
254           1,
255           51,
256           MPEG4_DEFAULT_INIT_QP,
257           G_PARAM_READWRITE));
258
259   g_object_class_install_property (
260       object_class,
261       MPEG4_PROP_MIN_QP,
262       g_param_spec_uint (
263           "min-qp",
264           "MPEG4 min-qp",
265           "MPEG4 min-qp",
266           1,
267           51,
268           MPEG4_DEFAULT_MIN_QP,
269           G_PARAM_READWRITE));
270 }