tizen beta release
[profile/ivi/gst-openmax0.10.git] / omx / gstomx_g711enc.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_g711enc.h"
23 #include "gstomx_base_filter.h"
24 #include "gstomx.h"
25
26 #include <string.h>             /* for strcmp */
27
28 GSTOMX_BOILERPLATE (GstOmxG711Enc, gst_omx_g711enc, GstOmxBaseFilter,
29     GST_OMX_BASE_FILTER_TYPE);
30
31 static void
32 type_base_init (gpointer g_class)
33 {
34   GstElementClass *element_class;
35
36   element_class = GST_ELEMENT_CLASS (g_class);
37
38   gst_element_class_set_details_simple (element_class,
39       "OpenMAX IL G.711 audio encoder",
40       "Codec/Encoder/Audio",
41       "Encodes audio in G.711 format with OpenMAX IL", "Felipe Contreras");
42
43   gst_element_class_add_pad_template (element_class,
44       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
45           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "sink")));
46
47   gst_element_class_add_pad_template (element_class,
48       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
49           gstomx_template_caps (G_TYPE_FROM_CLASS (g_class), "src")));
50 }
51
52 static void
53 type_class_init (gpointer g_class, gpointer class_data)
54 {
55 }
56
57 static gboolean
58 sink_setcaps (GstPad * pad, GstCaps * caps)
59 {
60   GstCaps *peer_caps;
61   GstStructure *structure;
62   GstOmxBaseFilter *omx_base;
63   GOmxCore *gomx;
64   const gchar *mode;
65   gboolean ret = TRUE;
66
67   omx_base = GST_OMX_BASE_FILTER (GST_PAD_PARENT (pad));
68   gomx = (GOmxCore *) omx_base->gomx;
69
70   GST_INFO_OBJECT (omx_base, "setcaps (sink): %" GST_PTR_FORMAT, caps);
71
72   peer_caps = gst_pad_peer_get_caps (omx_base->srcpad);
73
74   g_return_val_if_fail (peer_caps, FALSE);
75
76   GST_INFO_OBJECT (omx_base, "setcaps (sink): peercaps: %" GST_PTR_FORMAT,
77       peer_caps);
78
79   if (gst_caps_get_size (peer_caps) == 0)
80     goto leave;
81
82   structure = gst_caps_get_structure (peer_caps, 0);
83
84   mode = gst_structure_get_name (structure);
85
86   /* Output port configuration. */
87   {
88     OMX_AUDIO_PARAM_PCMMODETYPE param;
89
90     G_OMX_INIT_PARAM (param);
91
92     param.nPortIndex = omx_base->out_port->port_index;
93     OMX_GetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, &param);
94
95     if (strcmp (mode, "audio/x-alaw") == 0)
96       param.ePCMMode = OMX_AUDIO_PCMModeALaw;
97     else if (strcmp (mode, "audio/x-mulaw") == 0)
98       param.ePCMMode = OMX_AUDIO_PCMModeMULaw;
99
100     OMX_SetParameter (gomx->omx_handle, OMX_IndexParamAudioPcm, &param);
101   }
102
103 leave:
104
105   /* set caps on the srcpad */
106   {
107     GstCaps *tmp_caps;
108
109     tmp_caps = gst_pad_get_allowed_caps (omx_base->srcpad);
110     tmp_caps = gst_caps_make_writable (tmp_caps);
111     gst_caps_truncate (tmp_caps);
112
113     gst_pad_fixate_caps (omx_base->srcpad, tmp_caps);
114
115     if (gst_caps_is_fixed (tmp_caps)) {
116       GST_INFO_OBJECT (omx_base, "fixated to: %" GST_PTR_FORMAT, tmp_caps);
117       gst_pad_set_caps (omx_base->srcpad, tmp_caps);
118     }
119
120     gst_caps_unref (tmp_caps);
121   }
122
123   ret = gst_pad_set_caps (pad, caps);
124
125   gst_caps_unref (peer_caps);
126
127   return ret;
128 }
129
130 static void
131 type_instance_init (GTypeInstance * instance, gpointer g_class)
132 {
133   GstOmxBaseFilter *omx_base;
134
135   omx_base = GST_OMX_BASE_FILTER (instance);
136
137   gst_pad_set_setcaps_function (omx_base->sinkpad, sink_setcaps);
138 }