Tizen 2.1 base
[profile/ivi/gst-openmax0.10.git] / omx / gstomx_base_audiodec.c
1 /*
2  * Copyright (C) 2009 Texas Instruments, Inc.
3  *
4  * Author: Rob Clark <rob@ti.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_base_audiodec.h"
23 #include "gstomx.h"
24
25 enum
26 {
27   ARG_0,
28   ARG_USE_STATETUNING, /* STATE_TUNING */
29 };
30
31 GSTOMX_BOILERPLATE (GstOmxBaseAudioDec, gst_omx_base_audiodec, GstOmxBaseFilter,
32     GST_OMX_BASE_FILTER_TYPE);
33
34 static void
35 type_base_init (gpointer g_class)
36 {
37 }
38
39 /* MODIFICATION: add state tuning property */
40 static void
41 set_property (GObject * obj,
42     guint prop_id, const GValue * value, GParamSpec * pspec)
43 {
44   GstOmxBaseAudioDec *self;
45
46   self = GST_OMX_BASE_AUDIODEC (obj);
47
48   switch (prop_id) {
49     /* STATE_TUNING */
50     case ARG_USE_STATETUNING:
51       self->omx_base.use_state_tuning = g_value_get_boolean(value);
52       break;
53     default:
54       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
55       break;
56   }
57 }
58
59 static void
60 get_property (GObject * obj, guint prop_id, GValue * value, GParamSpec * pspec)
61 {
62   GstOmxBaseAudioDec *self;
63
64   self = GST_OMX_BASE_AUDIODEC (obj);
65
66   switch (prop_id) {
67     /* STATE_TUNING */
68     case ARG_USE_STATETUNING:
69       g_value_set_boolean(value, self->omx_base.use_state_tuning);
70       break;
71     default:
72       G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
73       break;
74   }
75 }
76
77 static void
78 type_class_init (gpointer g_class, gpointer class_data)
79 {
80   GObjectClass *gobject_class;
81 //  GstOmxBaseFilterClass *basefilter_class;
82
83   gobject_class = G_OBJECT_CLASS (g_class);
84 //  basefilter_class = GST_OMX_BASE_FILTER_CLASS (g_class);
85
86   /* Properties stuff */
87   {
88     gobject_class->set_property = set_property;
89     gobject_class->get_property = get_property;
90
91     /* STATE_TUNING */
92     g_object_class_install_property (gobject_class, ARG_USE_STATETUNING,
93         g_param_spec_boolean ("state-tuning", "start omx component in gst paused state",
94         "Whether or not to use state-tuning feature",
95         FALSE, G_PARAM_READWRITE));
96   }
97 }
98
99 static void
100 settings_changed_cb (GOmxCore * core)
101 {
102   GstOmxBaseFilter *omx_base;
103   guint rate;
104   guint channels;
105
106   omx_base = core->object;
107
108   GST_DEBUG_OBJECT (omx_base, "settings changed");
109
110   {
111     OMX_AUDIO_PARAM_PCMMODETYPE param;
112
113     G_OMX_INIT_PARAM (param);
114
115     param.nPortIndex = omx_base->out_port->port_index;
116     OMX_GetParameter (omx_base->gomx->omx_handle, OMX_IndexParamAudioPcm,
117         &param);
118
119     rate = param.nSamplingRate;
120     channels = param.nChannels;
121     if (rate == 0) {
122             /** @todo: this shouldn't happen. */
123       GST_WARNING_OBJECT (omx_base, "Bad samplerate");
124       rate = 44100;
125     }
126   }
127
128   {
129     GstCaps *new_caps;
130
131     new_caps = gst_caps_new_simple ("audio/x-raw-int",
132         "width", G_TYPE_INT, 16,
133         "depth", G_TYPE_INT, 16,
134         "rate", G_TYPE_INT, rate,
135         "signed", G_TYPE_BOOLEAN, TRUE,
136         "endianness", G_TYPE_INT, G_BYTE_ORDER,
137         "channels", G_TYPE_INT, channels, NULL);
138
139     GST_INFO_OBJECT (omx_base, "caps are: %" GST_PTR_FORMAT, new_caps);
140     gst_pad_set_caps (omx_base->srcpad, new_caps);
141   }
142 }
143
144 static void
145 type_instance_init (GTypeInstance * instance, gpointer g_class)
146 {
147   GstOmxBaseFilter *omx_base;
148
149   omx_base = GST_OMX_BASE_FILTER (instance);
150
151   GST_DEBUG_OBJECT (omx_base, "start");
152
153   omx_base->gomx->settings_changed_cb = settings_changed_cb;
154 }