tizen beta release
[profile/ivi/gst-openmax0.10.git] / omx / gstomx_adpcmdec.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_adpcmdec.h"
23 #include "gstomx_base_filter.h"
24 #include "gstomx.h"
25
26 /* should this class extend GstOmxBaseAudioDec? */
27 GSTOMX_BOILERPLATE (GstOmxAdpcmDec, gst_omx_adpcmdec, GstOmxBaseFilter,
28     GST_OMX_BASE_FILTER_TYPE);
29
30 static void
31 type_base_init (gpointer g_class)
32 {
33   GstElementClass *element_class;
34
35   element_class = GST_ELEMENT_CLASS (g_class);
36
37   gst_element_class_set_details_simple (element_class,
38       "OpenMAX IL ADPCM audio decoder",
39       "Codec/Decoder/Audio",
40       "Decodes audio in ADPCM format with OpenMAX IL", "Felipe Contreras");
41
42   gst_element_class_add_pad_template (element_class,
43       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
44           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
45
46   gst_element_class_add_pad_template (element_class,
47       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
48           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
49 }
50
51 static void
52 type_class_init (gpointer g_class, gpointer class_data)
53 {
54 }
55
56 static gboolean
57 sink_setcaps (GstPad * pad, GstCaps * caps)
58 {
59   GstStructure *structure;
60   GstOmxBaseFilter *omx_base;
61   GOmxCore *gomx;
62   gint rate = 0;
63
64   omx_base = GST_OMX_BASE_FILTER (GST_PAD_PARENT (pad));
65   gomx = (GOmxCore *) omx_base->gomx;
66
67   GST_INFO_OBJECT (omx_base, "setcaps (sink): %" GST_PTR_FORMAT, caps);
68
69   structure = gst_caps_get_structure (caps, 0);
70
71   gst_structure_get_int (structure, "rate", &rate);
72
73   /* Input port configuration. */
74   {
75     OMX_AUDIO_PARAM_PCMMODETYPE param;
76
77     G_OMX_INIT_PARAM (param);
78
79     param.nPortIndex = omx_base->out_port->port_index;
80     OMX_GetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, &param);
81
82     param.nSamplingRate = rate;
83
84     OMX_SetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, &param);
85   }
86
87   /* set caps on the srcpad */
88   {
89     GstCaps *tmp_caps;
90
91     tmp_caps = gst_pad_get_allowed_caps (omx_base->srcpad);
92     tmp_caps = gst_caps_make_writable (tmp_caps);
93     gst_caps_truncate (tmp_caps);
94
95     gst_pad_fixate_caps (omx_base->srcpad, tmp_caps);
96
97     if (gst_caps_is_fixed (tmp_caps)) {
98       GST_INFO_OBJECT (omx_base, "fixated to: %" GST_PTR_FORMAT, tmp_caps);
99       gst_pad_set_caps (omx_base->srcpad, tmp_caps);
100     }
101
102     gst_caps_unref (tmp_caps);
103   }
104
105   return gst_pad_set_caps (pad, caps);
106 }
107
108 static void
109 type_instance_init (GTypeInstance * instance, gpointer g_class)
110 {
111   GstOmxBaseFilter *omx_base;
112
113   omx_base = GST_OMX_BASE_FILTER (instance);
114
115   gst_pad_set_setcaps_function (omx_base->sinkpad, sink_setcaps);
116 }