adding flac
[platform/upstream/gst-plugins-good.git] / ext / flac / gstflac.c
1 /* Gnome-Streamer
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_typefind   (GstBuffer *buf, gpointer private);
28
29 GstPadTemplate *dec_src_template, *dec_sink_template; 
30 GstPadTemplate *enc_src_template, *enc_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_typefind,
66 };
67
68 static GstCaps* 
69 flac_typefind (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_typefind", "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   gst_plugin_set_longname (plugin, "The FLAC Lossless compressor Codec");
88
89   /* create an elementfactory for the flacenc element */
90   enc = gst_elementfactory_new ("flacenc", GST_TYPE_FLACENC,
91                                 &flacenc_details);
92   g_return_val_if_fail (enc != NULL, FALSE);
93
94   raw_caps = raw_caps_factory ();
95   flac_caps = flac_caps_factory ();
96
97   /* register sink pads */
98   enc_sink_template = gst_padtemplate_new ("sink", GST_PAD_SINK, 
99                                               GST_PAD_ALWAYS, 
100                                               raw_caps, NULL);
101   gst_elementfactory_add_padtemplate (enc, enc_sink_template);
102
103   /* register src pads */
104   enc_src_template = gst_padtemplate_new ("src", GST_PAD_SRC, 
105                                              GST_PAD_ALWAYS, 
106                                              flac_caps, NULL);
107   gst_elementfactory_add_padtemplate (enc, enc_src_template);
108
109   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (enc));
110
111   /* create an elementfactory for the flacdec element */
112   dec = gst_elementfactory_new("flacdec",GST_TYPE_FLACDEC,
113                                &flacdec_details);
114   g_return_val_if_fail(dec != NULL, FALSE);
115  
116   /* register sink pads */
117   dec_sink_template = gst_padtemplate_new ("sink", GST_PAD_SINK, 
118                                               GST_PAD_ALWAYS, 
119                                               flac_caps, NULL);
120   gst_elementfactory_add_padtemplate (dec, dec_sink_template);
121
122   /* register src pads */
123   dec_src_template = gst_padtemplate_new ("src", GST_PAD_SRC, 
124                                              GST_PAD_ALWAYS, 
125                                              raw_caps, NULL);
126   gst_elementfactory_add_padtemplate (dec, dec_src_template);
127   
128   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (dec));
129
130   type = gst_typefactory_new (&flacdefinition);
131   gst_plugin_add_feature (plugin, GST_PLUGIN_FEATURE (type));
132
133   return TRUE;
134 }
135
136 GstPluginDesc plugin_desc = {
137   GST_VERSION_MAJOR,
138   GST_VERSION_MINOR,
139   "flac",
140   plugin_init
141 };