Initialize Tizen 2.3
[framework/multimedia/gst-openmax.git] / wearable / omx / gstomx_volume.c
1 /*
2  * Copyright (C) 2007-2009 Nokia Corporation.
3  * Copyright (C) 2008 NXP.
4  *
5  * Author: Frederik Vernelen <frederik.vernelen@nxp.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation
10  * version 2.1 of the License.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  */
22
23 #include "gstomx_volume.h"
24 #include "gstomx_base_filter.h"
25 #include "gstomx.h"
26
27 GSTOMX_BOILERPLATE (GstOmxVolume, gst_omx_volume, GstOmxBaseFilter,
28     GST_OMX_BASE_FILTER_TYPE);
29
30 static void instance_init (GstElement * element);
31
32 static void
33 type_base_init (gpointer g_class)
34 {
35   GstElementClass *element_class;
36
37   element_class = GST_ELEMENT_CLASS (g_class);
38
39   gst_element_class_set_details_simple (element_class,
40       "OpenMAX IL Volume component",
41       "Filter/Effect/Audio",
42       "Changes the volume with OpenMAX IL", "Frederik Vernelen");
43
44   gst_element_class_add_pad_template (element_class,
45       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
46           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
47
48   gst_element_class_add_pad_template (element_class,
49       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
50           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
51 }
52
53 static void
54 type_class_init (gpointer g_class, gpointer class_data)
55 {
56   GstOmxBaseFilterClass *basefilter_class;
57
58   basefilter_class = GST_OMX_BASE_FILTER_CLASS (g_class);
59   basefilter_class->instance_init = instance_init;
60 }
61
62 static void
63 settings_changed_cb (GOmxCore * core)
64 {
65   GstOmxBaseFilter *omx_base;
66   guint rate;
67   guint channels;
68
69   omx_base = core->object;
70
71   GST_DEBUG_OBJECT (omx_base, "settings changed");
72
73   {
74     OMX_AUDIO_PARAM_PCMMODETYPE param;
75
76     G_OMX_INIT_PARAM (param);
77
78     param.nPortIndex = omx_base->out_port->port_index;
79     OMX_GetParameter (omx_base->gomx->omx_handle, OMX_IndexParamAudioPcm,
80         &param);
81
82     rate = param.nSamplingRate;
83     channels = param.nChannels;
84     if (rate == 0) {
85             /** @todo: this shouldn't happen. */
86       GST_WARNING_OBJECT (omx_base, "Bad samplerate");
87       rate = 44100;
88     }
89   }
90
91   {
92     GstCaps *new_caps;
93
94     new_caps = gst_caps_new_simple ("audio/x-raw-int",
95         "width", G_TYPE_INT, 16,
96         "depth", G_TYPE_INT, 16,
97         "rate", G_TYPE_INT, rate,
98         "signed", G_TYPE_BOOLEAN, TRUE,
99         "endianness", G_TYPE_INT, G_BYTE_ORDER,
100         "channels", G_TYPE_INT, channels, NULL);
101
102     GST_INFO_OBJECT (omx_base, "caps are: %" GST_PTR_FORMAT, new_caps);
103     gst_pad_set_caps (omx_base->srcpad, new_caps);
104   }
105 }
106
107 static void
108 instance_private_value_init(GstElement * element)
109 {
110   GstOmxBaseFilter *omx_base;
111
112   omx_base = GST_OMX_BASE_FILTER (element);
113
114   omx_base->gomx->settings_changed_cb = settings_changed_cb;
115 }
116
117 static void
118 instance_init (GstElement * element)
119 {
120   GST_OMX_BASE_FILTER_CLASS (parent_class)->instance_init(element);
121
122   instance_private_value_init(element);
123 }
124
125 static void
126 type_instance_init (GTypeInstance * instance, gpointer g_class)
127 {
128   instance_private_value_init(GST_ELEMENT(instance));
129 }