2 * Copyright (C) 2007-2009 Nokia Corporation.
4 * Author: Felipe Contreras <felipe.contreras@nokia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation
9 * version 2.1 of the License.
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.
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 Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "gstomx_base_videoenc.h"
25 #include <string.h> /* for strcmp */
33 #define DEFAULT_BITRATE 0
35 GSTOMX_BOILERPLATE (GstOmxBaseVideoEnc, gst_omx_base_videoenc, GstOmxBaseFilter,
36 GST_OMX_BASE_FILTER_TYPE);
39 type_base_init (gpointer g_class)
44 set_property (GObject * obj,
45 guint prop_id, const GValue * value, GParamSpec * pspec)
47 GstOmxBaseVideoEnc *self;
49 self = GST_OMX_BASE_VIDEOENC (obj);
53 self->bitrate = g_value_get_uint (value);
56 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
62 get_property (GObject * obj, guint prop_id, GValue * value, GParamSpec * pspec)
64 GstOmxBaseVideoEnc *self;
66 self = GST_OMX_BASE_VIDEOENC (obj);
70 /** @todo propagate this to OpenMAX when processing. */
71 g_value_set_uint (value, self->bitrate);
74 G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
80 type_class_init (gpointer g_class, gpointer class_data)
82 GObjectClass *gobject_class;
84 gobject_class = G_OBJECT_CLASS (g_class);
86 /* Properties stuff */
88 gobject_class->set_property = set_property;
89 gobject_class->get_property = get_property;
91 g_object_class_install_property (gobject_class, ARG_BITRATE,
92 g_param_spec_uint ("bitrate", "Bit-rate",
94 0, G_MAXUINT, DEFAULT_BITRATE,
95 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
100 sink_setcaps (GstPad * pad, GstCaps * caps)
102 GstStructure *structure;
103 GstOmxBaseVideoEnc *self;
104 GstOmxBaseFilter *omx_base;
106 OMX_COLOR_FORMATTYPE color_format = OMX_COLOR_FormatUnused;
109 const GValue *framerate = NULL;
111 self = GST_OMX_BASE_VIDEOENC (GST_PAD_PARENT (pad));
112 omx_base = GST_OMX_BASE_FILTER (self);
113 gomx = (GOmxCore *) omx_base->gomx;
115 GST_INFO_OBJECT (self, "setcaps (sink): %" GST_PTR_FORMAT, caps);
117 g_return_val_if_fail (gst_caps_get_size (caps) == 1, FALSE);
119 structure = gst_caps_get_structure (caps, 0);
121 gst_structure_get_int (structure, "width", &width);
122 gst_structure_get_int (structure, "height", &height);
124 if (strcmp (gst_structure_get_name (structure), "video/x-raw-yuv") == 0) {
127 framerate = gst_structure_get_value (structure, "framerate");
129 self->framerate_num = gst_value_get_fraction_numerator (framerate);
130 self->framerate_denom = gst_value_get_fraction_denominator (framerate);
133 if (gst_structure_get_fourcc (structure, "format", &fourcc)) {
135 case GST_MAKE_FOURCC ('I', '4', '2', '0'):
136 case GST_MAKE_FOURCC ('S', '4', '2', '0'):
137 color_format = OMX_COLOR_FormatYUV420PackedPlanar;
139 case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
140 color_format = OMX_COLOR_FormatYCbYCr;
142 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
143 color_format = OMX_COLOR_FormatCbYCrY;
145 /* Add extended_color_format */
146 case GST_MAKE_FOURCC ('S', 'T', '1', '2'):
147 color_format = OMX_EXT_COLOR_FormatNV12TPhysicalAddress;
149 case GST_MAKE_FOURCC ('S', 'N', '1', '2'):
150 color_format = OMX_EXT_COLOR_FormatNV12LPhysicalAddress;
157 OMX_PARAM_PORTDEFINITIONTYPE param;
159 G_OMX_INIT_PARAM (param);
161 /* Input port configuration. */
163 param.nPortIndex = omx_base->in_port->port_index;
164 OMX_GetParameter (gomx->omx_handle, OMX_IndexParamPortDefinition, ¶m);
166 param.format.video.nFrameWidth = width;
167 param.format.video.nFrameHeight = height;
168 param.format.video.eColorFormat = color_format;
170 /* convert to Q.16 */
171 param.format.video.xFramerate =
172 (gst_value_get_fraction_numerator (framerate) << 16) /
173 gst_value_get_fraction_denominator (framerate);
176 OMX_SetParameter (gomx->omx_handle, OMX_IndexParamPortDefinition, ¶m);
179 G_OMX_INIT_PARAM (param);
181 param.nPortIndex = omx_base->out_port->port_index;
182 OMX_GetParameter (gomx->omx_handle, OMX_IndexParamPortDefinition, ¶m);
184 param.nBufferSize = MAX(param.nBufferSize, width * height * 3 / 2);
185 OMX_SetParameter (gomx->omx_handle, OMX_IndexParamPortDefinition, ¶m);
188 return gst_pad_set_caps (pad, caps);
192 omx_setup (GstOmxBaseFilter * omx_base)
194 GstOmxBaseVideoEnc *self;
197 self = GST_OMX_BASE_VIDEOENC (omx_base);
198 gomx = (GOmxCore *) omx_base->gomx;
200 GST_INFO_OBJECT (omx_base, "begin");
203 OMX_PARAM_PORTDEFINITIONTYPE param;
205 G_OMX_INIT_PARAM (param);
207 /* Output port configuration. */
209 param.nPortIndex = omx_base->out_port->port_index;
210 OMX_GetParameter (gomx->omx_handle, OMX_IndexParamPortDefinition, ¶m);
212 param.format.video.eCompressionFormat = self->compression_format;
214 if (self->bitrate != 0)
215 param.format.video.nBitrate = self->bitrate;
217 OMX_SetParameter (gomx->omx_handle, OMX_IndexParamPortDefinition, ¶m);
222 if (omx_base->use_state_tuning && omx_base->sink_set_caps) {
223 sink_setcaps(omx_base->sinkpad, omx_base->sink_set_caps);
226 GST_INFO_OBJECT (omx_base, "end");
230 type_instance_init (GTypeInstance * instance, gpointer g_class)
232 GstOmxBaseFilter *omx_base;
233 GstOmxBaseVideoEnc *self;
235 omx_base = GST_OMX_BASE_FILTER (instance);
236 self = GST_OMX_BASE_VIDEOENC (instance);
238 omx_base->omx_setup = omx_setup;
240 gst_pad_set_setcaps_function (omx_base->sinkpad, sink_setcaps);
242 self->bitrate = DEFAULT_BITRATE;