encoder(h264,h263,mpeg4): changed styles, names
[vaapi:windyuan-gstreamer-vaapi.git] / gst / vaapi / gstvaapiencode_h263.c
1 /*
2  *  gstvaapiencode_h263.c - VA-API H.263 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_h263.h"
23 #include "gst/vaapi/gstvaapiencoder_h263.h"
24
25 GST_DEBUG_CATEGORY_STATIC (gst_vaapi_h263_encode_debug);
26 #define GST_CAT_DEFAULT gst_vaapi_h263_encode_debug
27
28 #define GST_VAAPI_ENCODE_GET_PRIVATE(obj)  (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GST_TYPE_VAAPI_ENCODE, GstVaapiEncodePrivate))
29
30 static const char gst_vaapi_encode_h263_sink_caps_str[] =
31     GST_VAAPI_SURFACE_CAPS;
32
33 static const GstElementDetails gst_vaapi_encode_h263_details =
34     GST_ELEMENT_DETAILS(
35       "VA-API h263 encoder",
36       "Codec/Encoder/Video",
37       "A VA-API based h263 encoder",
38       "Feng Yuan <feng.yuan@intel.com>");
39
40
41 static const char gst_vaapi_encode_h263_src_caps_str[] =
42     GST_CAPS_CODEC("video/x-h263");
43
44 static GstStaticPadTemplate gst_vaapi_encode_h263_sink_factory =
45     GST_STATIC_PAD_TEMPLATE(
46         "sink",
47         GST_PAD_SINK,
48         GST_PAD_ALWAYS,
49         GST_STATIC_CAPS(gst_vaapi_encode_h263_sink_caps_str));
50
51 static GstStaticPadTemplate gst_vaapi_encode_h263_src_factory =
52     GST_STATIC_PAD_TEMPLATE(
53         "src",
54         GST_PAD_SRC,
55         GST_PAD_ALWAYS,
56         GST_STATIC_CAPS(gst_vaapi_encode_h263_src_caps_str));
57
58 static void gst_vaapi_encode_h263_set_property(GObject *object, guint prop_id,
59     const GValue *value, GParamSpec *pspec);
60 static void gst_vaapi_encode_h263_get_property (GObject * object, guint prop_id,
61     GValue * value, GParamSpec * pspec);
62
63 /* h263 encode */
64 GST_BOILERPLATE(
65     GstVaapiEncodeH263,
66     gst_vaapi_encode_h263,
67     GstVaapiEncode,
68     GST_TYPE_VAAPI_ENCODE);
69
70 enum {
71     H263_PROP_0,
72     H263_PROP_BITRATE,
73     H263_PROP_INTRA_PERIOD,
74     H263_PROP_INIT_QP,
75     H263_PROP_MIN_QP,
76 };
77
78
79 static void
80 gst_vaapi_encode_h263_base_init(gpointer klass)
81 {
82   GstElementClass * const element_class = GST_ELEMENT_CLASS(klass);
83
84   gst_element_class_set_details(element_class, &gst_vaapi_encode_h263_details);
85
86   /* sink pad */
87   gst_element_class_add_pad_template(
88       element_class,
89       gst_static_pad_template_get(&gst_vaapi_encode_h263_sink_factory)
90   );
91
92   /* src pad */
93   gst_element_class_add_pad_template(
94       element_class,
95       gst_static_pad_template_get(&gst_vaapi_encode_h263_src_factory)
96   );
97 }
98
99 static void
100 gst_vaapi_encode_h263_class_init(GstVaapiEncodeH263Class *klass)
101 {
102   GObjectClass * const object_class = G_OBJECT_CLASS(klass);
103
104   GST_DEBUG_CATEGORY_INIT (gst_vaapi_h263_encode_debug, "vaapih263encode", 0,
105       "vaapih263encode element");
106
107   GST_DEBUG_CATEGORY_INIT (gst_vaapi_h263_encode_debug, "vaapih263encode", 0,
108       "vaapih263encode element");
109
110   /* object_class->finalize      = gst_vaapi_encode_h263_finalize; */
111   object_class->set_property  = gst_vaapi_encode_h263_set_property;
112   object_class->get_property  = gst_vaapi_encode_h263_get_property;
113
114   g_object_class_install_property (object_class, H263_PROP_BITRATE,
115         g_param_spec_uint ("bitrate",
116             "H263 encoding bitrate",
117             "H263 encoding bitrate, 10k~100M, (0, auto-calculate)",
118             0,
119             100*1000*1000,
120             0,
121             G_PARAM_READWRITE));
122   g_object_class_install_property (object_class, H263_PROP_INTRA_PERIOD,
123         g_param_spec_uint ("intra-period",
124             "H263 encoding intra-period",
125             "H263 encoding intra-period",
126             1,
127             300,
128             H263_DEFAULT_INTRA_PERIOD,
129             G_PARAM_READWRITE));
130   g_object_class_install_property (object_class, H263_PROP_INIT_QP,
131         g_param_spec_uint ("init-qp",
132             "H263 init-qp",
133             "H263 init-qp",
134             1,
135             51,
136             H263_DEFAULT_INIT_QP,
137             G_PARAM_READWRITE));
138   g_object_class_install_property (object_class, H263_PROP_MIN_QP,
139         g_param_spec_uint ("min-qp",
140             "H263 min-qp",
141             "H263 min-qp",
142             1,
143             51,
144             H263_DEFAULT_MIN_QP,
145             G_PARAM_READWRITE));
146
147 }
148
149 static void
150 gst_vaapi_encode_h263_init(GstVaapiEncodeH263 *h263_encode, GstVaapiEncodeH263Class *klass)
151 {
152   GstVaapiEncode *encode = GST_VAAPI_ENCODE(h263_encode);
153   encode->encoder = GST_VAAPI_ENCODER(gst_vaapi_encoder_h263_new());
154   ENCODER_ASSERT(encode->encoder);
155 }
156
157 static void
158 gst_vaapi_encode_h263_set_property(GObject *object, guint prop_id,
159     const GValue *value, GParamSpec *pspec)
160 {
161   GstVaapiEncode *encode = GST_VAAPI_ENCODE(object);
162   GstVaapiEncoderH263 *h263encoder = GST_VAAPI_ENCODER_H263(encode->encoder);
163
164   ENCODER_ASSERT(h263encoder);
165
166   switch (prop_id) {
167     case H263_PROP_BITRATE: {
168       h263encoder->bitrate = g_value_get_uint(value);
169     }
170       break;
171
172     case H263_PROP_INTRA_PERIOD: {
173       h263encoder->intra_period = g_value_get_uint(value);
174     }
175       break;
176
177     case H263_PROP_INIT_QP: {
178       h263encoder->init_qp = g_value_get_uint(value);
179     }
180       break;
181
182     case H263_PROP_MIN_QP: {
183       h263encoder->min_qp = g_value_get_uint(value);
184     }
185       break;
186
187     default:
188       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
189       break;
190   }
191 }
192
193 static void
194 gst_vaapi_encode_h263_get_property (GObject * object, guint prop_id,
195     GValue * value, GParamSpec * pspec)
196 {
197   GstVaapiEncode *encode = GST_VAAPI_ENCODE(object);
198   GstVaapiEncoderH263 *h263encoder = GST_VAAPI_ENCODER_H263(encode->encoder);
199   ENCODER_ASSERT(h263encoder);
200
201   switch (prop_id) {
202     case H263_PROP_BITRATE:
203       g_value_set_uint (value, h263encoder->bitrate);
204       break;
205
206     case H263_PROP_INTRA_PERIOD:
207       g_value_set_uint (value, h263encoder->intra_period);
208       break;
209
210     case H263_PROP_INIT_QP:
211       g_value_set_uint (value, h263encoder->init_qp);
212       break;
213
214     case H263_PROP_MIN_QP:
215       g_value_set_uint (value, h263encoder->min_qp);
216       break;
217
218     default:
219       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
220       break;
221   }
222 }
223