add suffix 0.10 to package name, fix build failure.
[profile/ivi/gst-openmax0.10.git] / omx / gstomx_adpcmenc.c
1 /*
2  * Copyright (C) 2007-2009 Nokia Corporation.
3  *
4  * Author: Felipe Contreras <felipe.contreras@nokia.com>
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
8  * License as published by the Free Software Foundation
9  * version 2.1 of the License.
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 Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21
22 #include "gstomx_adpcmenc.h"
23 #include "gstomx_base_filter.h"
24 #include "gstomx.h"
25
26 GSTOMX_BOILERPLATE (GstOmxAdpcmEnc, gst_omx_adpcmenc, GstOmxBaseFilter,
27     GST_OMX_BASE_FILTER_TYPE);
28
29 static void
30 type_base_init (gpointer g_class)
31 {
32   GstElementClass *element_class;
33
34   element_class = GST_ELEMENT_CLASS (g_class);
35
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");
40
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")));
44
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")));
48 }
49
50 static void
51 type_class_init (gpointer g_class, gpointer class_data)
52 {
53 }
54
55 static void
56 settings_changed_cb (GOmxCore * core)
57 {
58   GstOmxBaseFilter *omx_base;
59   guint rate;
60
61   omx_base = core->object;
62
63   GST_DEBUG_OBJECT (omx_base, "settings changed");
64
65   {
66     OMX_AUDIO_PARAM_ADPCMTYPE param;
67
68     G_OMX_INIT_PARAM (param);
69
70     param.nPortIndex = omx_base->out_port->port_index;
71     OMX_GetParameter (omx_base->gomx->omx_handle, OMX_IndexParamAudioAdpcm,
72         &param);
73
74     rate = param.nSampleRate;
75   }
76
77   {
78     GstCaps *new_caps;
79
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);
83
84     GST_INFO_OBJECT (omx_base, "caps are: %" GST_PTR_FORMAT, new_caps);
85     gst_pad_set_caps (omx_base->srcpad, new_caps);
86   }
87 }
88
89 static gboolean
90 sink_setcaps (GstPad * pad, GstCaps * caps)
91 {
92   GstCaps *peer_caps;
93   GstStructure *structure;
94   GstOmxBaseFilter *omx_base;
95   GOmxCore *gomx;
96   gint rate = 0;
97   gboolean ret = TRUE;
98
99   omx_base = GST_OMX_BASE_FILTER (GST_PAD_PARENT (pad));
100   gomx = (GOmxCore *) omx_base->gomx;
101
102   GST_INFO_OBJECT (omx_base, "setcaps (sink): %" GST_PTR_FORMAT, caps);
103
104   peer_caps = gst_pad_peer_get_caps (omx_base->srcpad);
105
106   g_return_val_if_fail (peer_caps, FALSE);
107
108   GST_INFO_OBJECT (omx_base, "setcaps (sink): peercaps: %" GST_PTR_FORMAT,
109       peer_caps);
110
111   if (gst_caps_get_size (peer_caps) >= 1) {
112     structure = gst_caps_get_structure (peer_caps, 0);
113
114     gst_structure_get_int (structure, "rate", &rate);
115   } else {
116     structure = gst_caps_get_structure (caps, 0);
117
118     gst_structure_get_int (structure, "rate", &rate);
119   }
120
121   /* Input port configuration. */
122   {
123     OMX_AUDIO_PARAM_PCMMODETYPE param;
124
125     G_OMX_INIT_PARAM (param);
126
127     param.nPortIndex = omx_base->in_port->port_index;
128     OMX_GetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, &param);
129
130     param.nSamplingRate = rate;
131
132     OMX_SetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, &param);
133   }
134
135   /* set caps on the srcpad */
136   {
137     GstCaps *tmp_caps;
138     GstStructure *tmp_structure;
139
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);
143
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);
147
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);
151     }
152
153     gst_caps_unref (tmp_caps);
154   }
155
156   ret = gst_pad_set_caps (pad, caps);
157
158   gst_caps_unref (peer_caps);
159
160   return ret;
161 }
162
163 static void
164 type_instance_init (GTypeInstance * instance, gpointer g_class)
165 {
166   GstOmxBaseFilter *omx_base;
167
168   omx_base = GST_OMX_BASE_FILTER (instance);
169
170   omx_base->gomx->settings_changed_cb = settings_changed_cb;
171
172   gst_pad_set_setcaps_function (omx_base->sinkpad, sink_setcaps);
173 }