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