gst/law/: Ref caps before passing to gst_pad_template_new(), since that takes ownership.
[platform/upstream/gst-plugins-good.git] / gst / law / alaw.c
1 /* GStreamer PCM/A-Law conversions
2  *
3  * This library is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU Library General Public
5  * License as published by the Free Software Foundation; either
6  * version 2.1 of the License, or (at your option) any later version.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * Library General Public License for more details.
12  *
13  * You should have received a copy of the GNU Library General Public
14  * License along with this library; if not, write to the
15  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16  * Boston, MA 02111-1307, USA.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include "alaw-encode.h"
24 #include "alaw-decode.h"
25
26 static GstCaps *
27 alaw_factory (void)
28 {
29   return gst_caps_new_simple ("audio/x-alaw",
30       "rate", GST_TYPE_INT_RANGE, 8000, 192000,
31       "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
32 }
33
34 static GstCaps *
35 linear_factory (void)
36 {
37   return gst_caps_new_simple ("audio/x-raw-int",
38       "width", G_TYPE_INT, 16,
39       "depth", G_TYPE_INT, 16,
40       "endianness", G_TYPE_INT, G_BYTE_ORDER,
41       "signed", G_TYPE_BOOLEAN, TRUE,
42       "rate", GST_TYPE_INT_RANGE, 8000, 192000,
43       "channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
44 }
45
46 GstPadTemplate *alawenc_src_template, *alawenc_sink_template;
47 GstPadTemplate *alawdec_src_template, *alawdec_sink_template;
48
49 static gboolean
50 plugin_init (GstPlugin * plugin)
51 {
52   GstCaps *alaw_caps, *linear_caps;
53
54   alaw_caps = alaw_factory ();
55   linear_caps = linear_factory ();
56
57   gst_caps_ref (alaw_caps);
58   gst_caps_ref (linear_caps);
59   alawenc_src_template =
60       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, alaw_caps);
61   alawenc_sink_template =
62       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, linear_caps);
63
64   gst_caps_ref (alaw_caps);
65   gst_caps_ref (linear_caps);
66   alawdec_src_template =
67       gst_pad_template_new ("src", GST_PAD_SRC, GST_PAD_ALWAYS, linear_caps);
68   alawdec_sink_template =
69       gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, alaw_caps);
70
71   gst_caps_unref (alaw_caps);
72   gst_caps_unref (linear_caps);
73
74   if (!gst_element_register (plugin, "alawenc",
75           GST_RANK_NONE, GST_TYPE_ALAW_ENC) ||
76       !gst_element_register (plugin, "alawdec",
77           GST_RANK_PRIMARY, GST_TYPE_ALAW_DEC))
78     return FALSE;
79
80   return TRUE;
81 }
82
83 /* FIXME 0.11: merge alaw and mulaw into one plugin? */
84 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
85     GST_VERSION_MINOR,
86     "alaw",
87     "ALaw audio conversion routines",
88     plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)