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_adpcmenc.h"
23 #include "gstomx_base_filter.h"
26 GSTOMX_BOILERPLATE (GstOmxAdpcmEnc, gst_omx_adpcmenc, GstOmxBaseFilter,
27 GST_OMX_BASE_FILTER_TYPE);
30 type_base_init (gpointer g_class)
32 GstElementClass *element_class;
34 element_class = GST_ELEMENT_CLASS (g_class);
36 gst_element_class_set_details_simple (element_class,
37 "OpenMAX IL ADPCM audio encoder",
38 "Codec/Encoder/Audio",
39 "Encodes audio in ADPCM format with OpenMAX IL", "Felipe Contreras");
41 gst_element_class_add_pad_template (element_class,
42 gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
43 gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
45 gst_element_class_add_pad_template (element_class,
46 gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
47 gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
51 type_class_init (gpointer g_class, gpointer class_data)
56 settings_changed_cb (GOmxCore * core)
58 GstOmxBaseFilter *omx_base;
61 omx_base = core->object;
63 GST_DEBUG_OBJECT (omx_base, "settings changed");
66 OMX_AUDIO_PARAM_ADPCMTYPE param;
68 G_OMX_INIT_PARAM (param);
70 param.nPortIndex = omx_base->out_port->port_index;
71 OMX_GetParameter (omx_base->gomx->omx_handle, OMX_IndexParamAudioAdpcm,
74 rate = param.nSampleRate;
80 new_caps = gst_caps_new_simple ("audio/x-adpcm",
81 "layout", G_TYPE_STRING, "dvi",
82 "rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, 1, NULL);
84 GST_INFO_OBJECT (omx_base, "caps are: %" GST_PTR_FORMAT, new_caps);
85 gst_pad_set_caps (omx_base->srcpad, new_caps);
90 sink_setcaps (GstPad * pad, GstCaps * caps)
93 GstStructure *structure;
94 GstOmxBaseFilter *omx_base;
99 omx_base = GST_OMX_BASE_FILTER (GST_PAD_PARENT (pad));
100 gomx = (GOmxCore *) omx_base->gomx;
102 GST_INFO_OBJECT (omx_base, "setcaps (sink): %" GST_PTR_FORMAT, caps);
104 peer_caps = gst_pad_peer_get_caps (omx_base->srcpad);
106 g_return_val_if_fail (peer_caps, FALSE);
108 GST_INFO_OBJECT (omx_base, "setcaps (sink): peercaps: %" GST_PTR_FORMAT,
111 if (gst_caps_get_size (peer_caps) >= 1) {
112 structure = gst_caps_get_structure (peer_caps, 0);
114 gst_structure_get_int (structure, "rate", &rate);
116 structure = gst_caps_get_structure (caps, 0);
118 gst_structure_get_int (structure, "rate", &rate);
121 /* Input port configuration. */
123 OMX_AUDIO_PARAM_PCMMODETYPE param;
125 G_OMX_INIT_PARAM (param);
127 param.nPortIndex = omx_base->in_port->port_index;
128 OMX_GetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, ¶m);
130 param.nSamplingRate = rate;
132 OMX_SetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, ¶m);
135 /* set caps on the srcpad */
138 GstStructure *tmp_structure;
140 tmp_caps = gst_pad_get_allowed_caps (omx_base->srcpad);
141 tmp_caps = gst_caps_make_writable (tmp_caps);
142 gst_caps_truncate (tmp_caps);
144 tmp_structure = gst_caps_get_structure (tmp_caps, 0);
145 gst_structure_fixate_field_nearest_int (tmp_structure, "rate", rate);
146 gst_pad_fixate_caps (omx_base->srcpad, tmp_caps);
148 if (gst_caps_is_fixed (tmp_caps)) {
149 GST_INFO_OBJECT (omx_base, "fixated to: %" GST_PTR_FORMAT, tmp_caps);
150 gst_pad_set_caps (omx_base->srcpad, tmp_caps);
153 gst_caps_unref (tmp_caps);
156 ret = gst_pad_set_caps (pad, caps);
158 gst_caps_unref (peer_caps);
164 type_instance_init (GTypeInstance * instance, gpointer g_class)
166 GstOmxBaseFilter *omx_base;
168 omx_base = GST_OMX_BASE_FILTER (instance);
170 omx_base->gomx->settings_changed_cb = settings_changed_cb;
172 gst_pad_set_setcaps_function (omx_base->sinkpad, sink_setcaps);