add output buffer duration
[framework/multimedia/gst-openmax.git] / 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
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 Volume component",
39       "Filter/Effect/Audio",
40       "Changes the volume with OpenMAX IL", "Frederik Vernelen");
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 void
57 settings_changed_cb (GOmxCore * core)
58 {
59   GstOmxBaseFilter *omx_base;
60   guint rate;
61   guint channels;
62
63   omx_base = core->object;
64
65   GST_DEBUG_OBJECT (omx_base, "settings changed");
66
67   {
68     OMX_AUDIO_PARAM_PCMMODETYPE param;
69
70     G_OMX_INIT_PARAM (param);
71
72     param.nPortIndex = omx_base->out_port->port_index;
73     OMX_GetParameter (omx_base->gomx->omx_handle, OMX_IndexParamAudioPcm,
74         &param);
75
76     rate = param.nSamplingRate;
77     channels = param.nChannels;
78     if (rate == 0) {
79             /** @todo: this shouldn't happen. */
80       GST_WARNING_OBJECT (omx_base, "Bad samplerate");
81       rate = 44100;
82     }
83   }
84
85   {
86     GstCaps *new_caps;
87
88     new_caps = gst_caps_new_simple ("audio/x-raw-int",
89         "width", G_TYPE_INT, 16,
90         "depth", G_TYPE_INT, 16,
91         "rate", G_TYPE_INT, rate,
92         "signed", G_TYPE_BOOLEAN, TRUE,
93         "endianness", G_TYPE_INT, G_BYTE_ORDER,
94         "channels", G_TYPE_INT, channels, NULL);
95
96     GST_INFO_OBJECT (omx_base, "caps are: %" GST_PTR_FORMAT, new_caps);
97     gst_pad_set_caps (omx_base->srcpad, new_caps);
98   }
99 }
100
101 static void
102 type_instance_init (GTypeInstance * instance, gpointer g_class)
103 {
104   GstOmxBaseFilter *omx_base;
105
106   omx_base = GST_OMX_BASE_FILTER (instance);
107
108   GST_DEBUG_OBJECT (omx_base, "start");
109
110   omx_base->gomx->settings_changed_cb = settings_changed_cb;
111 }