merge TYPEFIND branch. Major changes:
[platform/upstream/gst-plugins-good.git] / ext / flac / gstflac.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20
21 #include "gstflacenc.h"
22 #include "gstflacdec.h"
23
24 #include "flac_compat.h"
25
26 extern GstElementDetails flacenc_details;
27 extern GstElementDetails flacdec_details;
28
29 GstPadTemplate *gst_flacdec_src_template, *gst_flacdec_sink_template; 
30 GstPadTemplate *gst_flacenc_src_template, *gst_flacenc_sink_template;
31
32 static GstCaps*
33 flac_caps_factory (void)
34 {
35   return
36    gst_caps_new (
37         "flac_flac",
38         "application/x-flac",
39         /*gst_props_new (
40             "rate",             GST_PROPS_INT_RANGE (11025, 48000),
41             "channels",         GST_PROPS_INT_RANGE (1, 2),
42             NULL)*/ NULL);
43 }
44
45 static GstCaps*
46 raw_caps_factory (void)
47 {
48   return
49    gst_caps_new (
50         "flac_raw",
51         "audio/x-raw-int",
52         gst_props_new (
53             "endianness",       GST_PROPS_INT (G_BYTE_ORDER),
54             "signed",           GST_PROPS_BOOLEAN (TRUE),
55             "width",            GST_PROPS_INT (16),
56             "depth",            GST_PROPS_INT (16),
57             "rate",             GST_PROPS_INT_RANGE (11025, 48000),
58             "channels",         GST_PROPS_INT_RANGE (1, 2),
59             NULL));
60 }
61
62 static gboolean
63 plugin_init (GModule *module, GstPlugin *plugin)
64 {
65   GstElementFactory *enc, *dec;
66   GstCaps *raw_caps, *flac_caps;
67
68   if (!gst_library_load ("gstbytestream"))
69     return FALSE;
70
71   gst_plugin_set_longname (plugin, "The FLAC Lossless compressor Codec");
72
73   /* create an elementfactory for the flacenc element */
74   enc = gst_element_factory_new ("flacenc", GST_TYPE_FLACENC,
75                                 &flacenc_details);
76   g_return_val_if_fail (enc != NULL, FALSE);
77
78   raw_caps = raw_caps_factory ();
79   flac_caps = flac_caps_factory ();
80
81   /* register sink pads */
82   gst_flacenc_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, 
83                                               GST_PAD_ALWAYS, 
84                                               raw_caps, NULL);
85   gst_element_factory_add_pad_template (enc, gst_flacenc_sink_template);
86
87   /* register src pads */
88   gst_flacenc_src_template = gst_pad_template_new ("src", GST_PAD_SRC, 
89                                              GST_PAD_ALWAYS, 
90                                              flac_caps, NULL);
91   gst_element_factory_add_pad_template (enc, gst_flacenc_src_template);
92
93   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (enc));
94
95   /* create an elementfactory for the flacdec element */
96   dec = gst_element_factory_new("flacdec",GST_TYPE_FLACDEC,
97                                &flacdec_details);
98   g_return_val_if_fail(dec != NULL, FALSE);
99   gst_element_factory_set_rank (dec, GST_ELEMENT_RANK_PRIMARY);
100  
101   /* register sink pads */
102   gst_flacdec_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, 
103                                               GST_PAD_ALWAYS, 
104                                               flac_caps, NULL);
105   gst_element_factory_add_pad_template (dec, gst_flacdec_sink_template);
106
107   /* register src pads */
108   gst_flacdec_src_template = gst_pad_template_new ("src", GST_PAD_SRC, 
109                                              GST_PAD_ALWAYS, 
110                                              raw_caps, NULL);
111   gst_element_factory_add_pad_template (dec, gst_flacdec_src_template);
112   
113   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (dec));
114
115   return TRUE;
116 }
117
118 GstPluginDesc plugin_desc = {
119   GST_VERSION_MAJOR,
120   GST_VERSION_MINOR,
121   "flac",
122   plugin_init
123 };