tizen beta release
[profile/ivi/gst-openmax0.10.git] / omx / gstomx_g729enc.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_g729enc.h"
23 #include "gstomx_base_filter.h"
24 #include "gstomx.h"
25
26 #define DEFAULT_DTX TRUE
27
28 enum
29 {
30   ARG_0,
31   ARG_DTX,
32 };
33
34 GSTOMX_BOILERPLATE (GstOmxG729Enc, gst_omx_g729enc, GstOmxBaseFilter,
35     GST_OMX_BASE_FILTER_TYPE);
36
37 static void
38 type_base_init (gpointer g_class)
39 {
40   GstElementClass *element_class;
41
42   element_class = GST_ELEMENT_CLASS (g_class);
43
44   gst_element_class_set_details_simple (element_class,
45       "OpenMAX IL G.729 audio encoder",
46       "Codec/Encoder/Audio",
47       "Encodes audio in G.729 format with OpenMAX IL", "Felipe Contreras");
48
49   gst_element_class_add_pad_template (element_class,
50       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
51           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
52
53   gst_element_class_add_pad_template (element_class,
54       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
55           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
56 }
57
58 static void
59 set_property (GObject * obj,
60     guint prop_id, const GValue * value, GParamSpec * pspec)
61 {
62   GstOmxG729Enc *self;
63
64   self = GST_OMX_G729ENC (obj);
65
66   switch (prop_id) {
67     case ARG_DTX:
68       self->dtx = g_value_get_boolean (value);
69       break;
70     default:
71       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
72       break;
73   }
74 }
75
76 static void
77 get_property (GObject * obj, guint prop_id, GValue * value, GParamSpec * pspec)
78 {
79   GstOmxG729Enc *self;
80
81   self = GST_OMX_G729ENC (obj);
82
83   switch (prop_id) {
84     case ARG_DTX:
85             /** @todo propagate this to OpenMAX when processing. */
86       g_value_set_boolean (value, self->dtx);
87       break;
88     default:
89       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
90       break;
91   }
92 }
93
94 static void
95 type_class_init (gpointer g_class, gpointer class_data)
96 {
97   GObjectClass *gobject_class;
98
99   gobject_class = G_OBJECT_CLASS (g_class);
100
101   /* Properties stuff */
102   {
103     gobject_class->set_property = set_property;
104     gobject_class->get_property = get_property;
105
106     g_object_class_install_property (gobject_class, ARG_DTX,
107         g_param_spec_boolean ("dtx", "DTX",
108             "Enable DTX",
109             DEFAULT_DTX, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
110   }
111 }
112
113 static gboolean
114 sink_setcaps (GstPad * pad, GstCaps * caps)
115 {
116   GstOmxBaseFilter *omx_base;
117   gboolean ret = TRUE;
118
119   omx_base = GST_OMX_BASE_FILTER (GST_PAD_PARENT (pad));
120
121   GST_INFO_OBJECT (omx_base, "setcaps (sink): %" GST_PTR_FORMAT, caps);
122
123   if (!caps || gst_caps_get_size (caps) == 0)
124     goto refuse_caps;
125
126   /* some extreme checking */
127   if (!gst_pad_accept_caps (pad, caps))
128     goto refuse_caps;
129
130   /* set caps on the srcpad */
131   {
132     GstCaps *tmp_caps;
133
134     /* src template are fixed caps */
135     tmp_caps = gstomx_template_caps (G_TYPE_FROM_INSTANCE (omx_base), "src");
136
137     ret = gst_pad_set_caps (omx_base->srcpad, tmp_caps);
138     gst_caps_unref (tmp_caps);
139   }
140
141   return ret;
142
143   /* ERRORS */
144 refuse_caps:
145   {
146     GST_WARNING_OBJECT (omx_base, "refused caps %" GST_PTR_FORMAT, caps);
147     return FALSE;
148   }
149 }
150
151 static void
152 omx_setup (GstOmxBaseFilter * omx_base)
153 {
154   GstOmxG729Enc *self;
155   GOmxCore *gomx;
156
157   self = GST_OMX_G729ENC (omx_base);
158   gomx = omx_base->gomx;
159
160   GST_INFO_OBJECT (omx_base, "begin");
161
162   {
163     OMX_AUDIO_PARAM_G729TYPE param;
164
165     G_OMX_INIT_PARAM (param);
166
167     param.nPortIndex = omx_base->out_port->port_index;
168     OMX_GetParameter (gomx->omx_handle, OMX_IndexParamAudioG729, &param);
169
170     param.bDTX = self->dtx;
171
172     OMX_SetParameter (gomx->omx_handle, OMX_IndexParamAudioG729, &param);
173   }
174
175   GST_INFO_OBJECT (omx_base, "end");
176 }
177
178 static void
179 type_instance_init (GTypeInstance * instance, gpointer g_class)
180 {
181   GstOmxBaseFilter *omx_base;
182   GstOmxG729Enc *self;
183
184   omx_base = GST_OMX_BASE_FILTER (instance);
185   self = GST_OMX_G729ENC (instance);
186
187   omx_base->omx_setup = omx_setup;
188
189   gst_pad_set_setcaps_function (omx_base->sinkpad, sink_setcaps);
190
191   self->dtx = DEFAULT_DTX;
192 }