removing warnings as approved by wim
[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 extern GstElementDetails flacenc_details;
25 extern GstElementDetails flacdec_details;
26
27 static GstCaps*         flac_type_find  (GstBuffer *buf, gpointer private);
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         "audio/x-flac",
39         NULL);
40 }
41
42 static GstCaps*
43 raw_caps_factory (void)
44 {
45   return
46    gst_caps_new (
47         "flac_raw",
48         "audio/raw",
49         gst_props_new (
50           "format",             GST_PROPS_STRING ("int"),
51             "law",              GST_PROPS_INT (0),
52             "endianness",       GST_PROPS_INT (G_BYTE_ORDER),
53             "signed",           GST_PROPS_BOOLEAN (TRUE),
54             "width",            GST_PROPS_INT (16),
55             "depth",            GST_PROPS_INT (16),
56             "rate",             GST_PROPS_INT_RANGE (11025, 48000),
57             "channels",         GST_PROPS_INT_RANGE (1, 2),
58             NULL));
59 }
60
61 static GstTypeDefinition flacdefinition = {
62   "flac_audio/x-flac",
63   "audio/x-flac",
64   ".flac",
65   flac_type_find,
66 };
67
68 static GstCaps* 
69 flac_type_find (GstBuffer *buf, gpointer private) 
70 {
71   gulong head = GULONG_FROM_BE (*((gulong *)GST_BUFFER_DATA (buf)));
72
73   if (head  != 0x664C6143)
74     return NULL;
75
76   return gst_caps_new ("flac_type_find", "audio/x-flac", NULL);
77 }
78
79
80 static gboolean
81 plugin_init (GModule *module, GstPlugin *plugin)
82 {
83   GstElementFactory *enc, *dec;
84   GstTypeFactory *type;
85   GstCaps *raw_caps, *flac_caps;
86
87   /* this filter needs the bytestream package */
88   if (!gst_library_load ("gstbytestream"))
89     return FALSE;
90
91   gst_plugin_set_longname (plugin, "The FLAC Lossless compressor Codec");
92
93   /* create an elementfactory for the flacenc element */
94   enc = gst_element_factory_new ("flacenc", GST_TYPE_FLACENC,
95                                 &flacenc_details);
96   g_return_val_if_fail (enc != NULL, FALSE);
97
98   raw_caps = raw_caps_factory ();
99   flac_caps = flac_caps_factory ();
100
101   /* register sink pads */
102   gst_flacenc_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, 
103                                               GST_PAD_ALWAYS, 
104                                               raw_caps, NULL);
105   gst_element_factory_add_pad_template (enc, gst_flacenc_sink_template);
106
107   /* register src pads */
108   gst_flacenc_src_template = gst_pad_template_new ("src", GST_PAD_SRC, 
109                                              GST_PAD_ALWAYS, 
110                                              flac_caps, NULL);
111   gst_element_factory_add_pad_template (enc, gst_flacenc_src_template);
112
113   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (enc));
114
115   /* create an elementfactory for the flacdec element */
116   dec = gst_element_factory_new("flacdec",GST_TYPE_FLACDEC,
117                                &flacdec_details);
118   g_return_val_if_fail(dec != NULL, FALSE);
119   gst_element_factory_set_rank (dec, GST_ELEMENT_RANK_PRIMARY);
120  
121   /* register sink pads */
122   gst_flacdec_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK, 
123                                               GST_PAD_ALWAYS, 
124                                               flac_caps, NULL);
125   gst_element_factory_add_pad_template (dec, gst_flacdec_sink_template);
126
127   /* register src pads */
128   gst_flacdec_src_template = gst_pad_template_new ("src", GST_PAD_SRC, 
129                                              GST_PAD_ALWAYS, 
130                                              raw_caps, NULL);
131   gst_element_factory_add_pad_template (dec, gst_flacdec_src_template);
132   
133   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (dec));
134
135   type = gst_type_factory_new (&flacdefinition);
136   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
137
138   return TRUE;
139 }
140
141 GstPluginDesc plugin_desc = {
142   GST_VERSION_MAJOR,
143   GST_VERSION_MINOR,
144   "flac",
145   plugin_init
146 };