tizen beta release
[profile/ivi/gst-openmax0.10.git] / omx / gstomx_audiosink.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_audiosink.h"
23 #include "gstomx.h"
24
25 GSTOMX_BOILERPLATE (GstOmxAudioSink, gst_omx_audiosink, GstOmxBaseSink,
26     GST_OMX_BASE_SINK_TYPE);
27
28 static void
29 type_base_init (gpointer g_class)
30 {
31   GstElementClass *element_class;
32
33   element_class = GST_ELEMENT_CLASS (g_class);
34
35   gst_element_class_set_details_simple (element_class,
36       "OpenMAX IL audiosink element",
37       "Sink/Audio", "Renders audio", "Felipe Contreras");
38
39   gst_element_class_add_pad_template (element_class,
40       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
41           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
42 }
43
44 static gboolean
45 setcaps (GstBaseSink * gst_sink, GstCaps * caps)
46 {
47   GstOmxBaseSink *self;
48   GOmxCore *gomx;
49
50   self = GST_OMX_BASE_SINK (gst_sink);
51   gomx = (GOmxCore *) self->gomx;
52
53   GST_INFO_OBJECT (self, "setcaps (sink): %" GST_PTR_FORMAT, caps);
54
55   g_return_val_if_fail (gst_caps_get_size (caps) == 1, FALSE);
56
57   {
58     GstStructure *structure;
59     gint channels;
60     gint width;
61     gint rate;
62     gboolean is_signed;
63     gboolean is_bigendian;
64
65     structure = gst_caps_get_structure (caps, 0);
66
67     gst_structure_get_int (structure, "channels", &channels);
68     gst_structure_get_int (structure, "width", &width);
69     gst_structure_get_int (structure, "rate", &rate);
70     gst_structure_get_boolean (structure, "signed", &is_signed);
71     {
72       gint endianness;
73       gst_structure_get_int (structure, "endianness", &endianness);
74       is_bigendian = (endianness == 1234) ? FALSE : TRUE;
75     }
76
77     {
78       OMX_AUDIO_PARAM_PCMMODETYPE param;
79
80       G_OMX_INIT_PARAM (param);
81
82       param.nPortIndex = self->in_port->port_index;
83       OMX_GetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, &param);
84
85       param.nChannels = channels;
86       param.eNumData =
87           is_signed ? OMX_NumericalDataSigned : OMX_NumericalDataUnsigned;
88       param.eEndian = is_bigendian ? OMX_EndianBig : OMX_EndianLittle;
89       param.nBitPerSample = width;
90       param.nSamplingRate = rate;
91
92       OMX_SetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, &param);
93     }
94   }
95
96   return TRUE;
97 }
98
99 static void
100 type_class_init (gpointer g_class, gpointer class_data)
101 {
102   GstBaseSinkClass *gst_base_sink_class;
103
104   gst_base_sink_class = GST_BASE_SINK_CLASS (g_class);
105
106   gst_base_sink_class->set_caps = setcaps;
107 }
108
109 static void
110 type_instance_init (GTypeInstance * instance, gpointer g_class)
111 {
112   GstOmxBaseSink *omx_base;
113
114   omx_base = GST_OMX_BASE_SINK (instance);
115
116   GST_DEBUG_OBJECT (omx_base, "start");
117 }