2 * Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
3 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation
8 * version 2.1 of the License.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "gstomxh263enc.h"
29 GST_DEBUG_CATEGORY_STATIC (gst_omx_h263_enc_debug_category);
30 #define GST_CAT_DEFAULT gst_omx_h263_enc_debug_category
33 static gboolean gst_omx_h263_enc_set_format (GstOMXVideoEnc * enc,
34 GstOMXPort * port, GstVideoCodecState * state);
35 static GstCaps *gst_omx_h263_enc_get_caps (GstOMXVideoEnc * enc,
36 GstOMXPort * port, GstVideoCodecState * state);
43 /* class initialization */
46 GST_DEBUG_CATEGORY_INIT (gst_omx_h263_enc_debug_category, "omxh263enc", 0, \
47 "debug category for gst-omx video encoder base class");
49 G_DEFINE_TYPE_WITH_CODE (GstOMXH263Enc, gst_omx_h263_enc,
50 GST_TYPE_OMX_VIDEO_ENC, DEBUG_INIT);
53 gst_omx_h263_enc_class_init (GstOMXH263EncClass * klass)
55 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
56 GstOMXVideoEncClass *videoenc_class = GST_OMX_VIDEO_ENC_CLASS (klass);
58 videoenc_class->set_format = GST_DEBUG_FUNCPTR (gst_omx_h263_enc_set_format);
59 videoenc_class->get_caps = GST_DEBUG_FUNCPTR (gst_omx_h263_enc_get_caps);
61 videoenc_class->cdata.default_src_template_caps = "video/x-h263, "
62 "width=(int) [ 16, 4096 ], " "height=(int) [ 16, 4096 ]";
64 gst_element_class_set_static_metadata (element_class,
65 "OpenMAX H.263 Video Encoder",
66 "Codec/Encoder/Video/Hardware",
67 "Encode H.263 video streams",
68 "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
70 gst_omx_set_default_role (&videoenc_class->cdata, "video_encoder.h263");
74 gst_omx_h263_enc_init (GstOMXH263Enc * self)
79 gst_omx_h263_enc_set_format (GstOMXVideoEnc * enc, GstOMXPort * port,
80 GstVideoCodecState * state)
82 GstOMXH263Enc *self = GST_OMX_H263_ENC (enc);
84 OMX_PARAM_PORTDEFINITIONTYPE port_def;
85 OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
87 guint profile_id, level_id;
89 gst_omx_port_get_port_definition (GST_OMX_VIDEO_ENC (self)->enc_out_port,
91 port_def.format.video.eCompressionFormat = OMX_VIDEO_CodingH263;
93 gst_omx_port_update_port_definition (GST_OMX_VIDEO_ENC
94 (self)->enc_out_port, &port_def);
95 if (err != OMX_ErrorNone)
98 GST_OMX_INIT_STRUCT (¶m);
99 param.nPortIndex = GST_OMX_VIDEO_ENC (self)->enc_out_port->index;
101 gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc,
102 OMX_IndexParamVideoProfileLevelCurrent, ¶m);
103 if (err != OMX_ErrorNone) {
104 GST_WARNING_OBJECT (self,
105 "Getting profile/level not supported by component");
109 peercaps = gst_pad_peer_query_caps (GST_VIDEO_ENCODER_SRC_PAD (enc),
110 gst_pad_get_pad_template_caps (GST_VIDEO_ENCODER_SRC_PAD (enc)));
114 if (gst_caps_is_empty (peercaps)) {
115 gst_caps_unref (peercaps);
116 GST_ERROR_OBJECT (self, "Empty caps");
120 s = gst_caps_get_structure (peercaps, 0);
121 if (gst_structure_get_uint (s, "profile", &profile_id)) {
122 switch (profile_id) {
124 param.eProfile = OMX_VIDEO_H263ProfileBaseline;
127 param.eProfile = OMX_VIDEO_H263ProfileH320Coding;
130 param.eProfile = OMX_VIDEO_H263ProfileBackwardCompatible;
133 param.eProfile = OMX_VIDEO_H263ProfileISWV2;
136 param.eProfile = OMX_VIDEO_H263ProfileISWV3;
139 param.eProfile = OMX_VIDEO_H263ProfileHighCompression;
142 param.eProfile = OMX_VIDEO_H263ProfileInternet;
145 param.eProfile = OMX_VIDEO_H263ProfileInterlace;
148 param.eProfile = OMX_VIDEO_H263ProfileHighLatency;
151 goto unsupported_profile;
154 if (gst_structure_get_uint (s, "level", &level_id)) {
157 param.eLevel = OMX_VIDEO_H263Level10;
160 param.eLevel = OMX_VIDEO_H263Level20;
163 param.eLevel = OMX_VIDEO_H263Level30;
166 param.eLevel = OMX_VIDEO_H263Level40;
169 param.eLevel = OMX_VIDEO_H263Level50;
172 param.eLevel = OMX_VIDEO_H263Level60;
175 param.eLevel = OMX_VIDEO_H263Level70;
178 goto unsupported_level;
181 gst_caps_unref (peercaps);
185 gst_omx_component_set_parameter (GST_OMX_VIDEO_ENC (self)->enc,
186 OMX_IndexParamVideoProfileLevelCurrent, ¶m);
187 if (err == OMX_ErrorUnsupportedIndex) {
188 GST_WARNING_OBJECT (self,
189 "Setting profile/level not supported by component");
190 } else if (err != OMX_ErrorNone) {
191 GST_ERROR_OBJECT (self,
192 "Error setting profile %u and level %u: %s (0x%08x)",
193 (guint) param.eProfile, (guint) param.eLevel,
194 gst_omx_error_to_string (err), err);
201 GST_ERROR_OBJECT (self, "Unsupported profile %u", profile_id);
202 gst_caps_unref (peercaps);
206 GST_ERROR_OBJECT (self, "Unsupported level %u", level_id);
207 gst_caps_unref (peercaps);
212 gst_omx_h263_enc_get_caps (GstOMXVideoEnc * enc, GstOMXPort * port,
213 GstVideoCodecState * state)
215 GstOMXH263Enc *self = GST_OMX_H263_ENC (enc);
218 OMX_VIDEO_PARAM_PROFILELEVELTYPE param;
219 guint profile, level;
221 caps = gst_caps_new_empty_simple ("video/x-h263");
223 GST_OMX_INIT_STRUCT (¶m);
224 param.nPortIndex = GST_OMX_VIDEO_ENC (self)->enc_out_port->index;
227 gst_omx_component_get_parameter (GST_OMX_VIDEO_ENC (self)->enc,
228 OMX_IndexParamVideoProfileLevelCurrent, ¶m);
229 if (err != OMX_ErrorNone && err != OMX_ErrorUnsupportedIndex) {
230 gst_caps_unref (caps);
234 if (err == OMX_ErrorNone) {
235 switch (param.eProfile) {
236 case OMX_VIDEO_H263ProfileBaseline:
239 case OMX_VIDEO_H263ProfileH320Coding:
242 case OMX_VIDEO_H263ProfileBackwardCompatible:
245 case OMX_VIDEO_H263ProfileISWV2:
248 case OMX_VIDEO_H263ProfileISWV3:
251 case OMX_VIDEO_H263ProfileHighCompression:
254 case OMX_VIDEO_H263ProfileInternet:
257 case OMX_VIDEO_H263ProfileInterlace:
260 case OMX_VIDEO_H263ProfileHighLatency:
264 g_assert_not_reached ();
265 gst_caps_unref (caps);
269 switch (param.eLevel) {
270 case OMX_VIDEO_H263Level10:
273 case OMX_VIDEO_H263Level20:
276 case OMX_VIDEO_H263Level30:
279 case OMX_VIDEO_H263Level40:
282 case OMX_VIDEO_H263Level50:
285 case OMX_VIDEO_H263Level60:
288 case OMX_VIDEO_H263Level70:
292 g_assert_not_reached ();
293 gst_caps_unref (caps);
297 gst_caps_set_simple (caps,
298 "profile", G_TYPE_UINT, profile, "level", G_TYPE_UINT, level, NULL);