1 /*
2  * Copyright (C) 2001 CodeFactory AB
3  * Copyright (C) 2001 Thomas Nyberg <thomas@codefactory.se>
4  * Copyright (C) 2001-2002 Andy Wingo <apwingo@eos.ncsu.edu>
5  * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the Free
19  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25 
26 #include "gstalsasink.h"
27 #include "gstalsasrc.h"
28 #include "gstalsamidisrc.h"
29 
30 #include <gst/gst-i18n-plugin.h>
31 
32 GST_DEBUG_CATEGORY (alsa_debug);
33 
34 /* ALSA debugging wrapper */
35 /* *INDENT-OFF* */
36 G_GNUC_PRINTF (5, 6)
37 /* *INDENT-ON* */
38 static void
gst_alsa_error_wrapper(const char * file,int line,const char * function,int err,const char * fmt,...)39 gst_alsa_error_wrapper (const char *file, int line, const char *function,
40     int err, const char *fmt, ...)
41 {
42 #ifndef GST_DISABLE_GST_DEBUG
43   va_list args;
44   gchar *str;
45 
46   va_start (args, fmt);
47   str = g_strdup_vprintf (fmt, args);
48   va_end (args);
49   /* FIXME: use GST_LEVEL_ERROR here? Currently warning is used because we're
50    * able to catch enough of the errors that would be printed otherwise
51    */
52   gst_debug_log (alsa_debug, GST_LEVEL_WARNING, file, function, line, NULL,
53       "alsalib error: %s%s%s", str, err ? ": " : "",
54       err ? snd_strerror (err) : "");
55   g_free (str);
56 #endif
57 }
58 
59 static gboolean
plugin_init(GstPlugin * plugin)60 plugin_init (GstPlugin * plugin)
61 {
62   int err;
63 
64   if (!gst_element_register (plugin, "alsasrc", GST_RANK_PRIMARY,
65           GST_TYPE_ALSA_SRC))
66     return FALSE;
67   if (!gst_element_register (plugin, "alsasink", GST_RANK_PRIMARY,
68           GST_TYPE_ALSA_SINK))
69     return FALSE;
70   if (!gst_element_register (plugin, "alsamidisrc", GST_RANK_PRIMARY,
71           GST_TYPE_ALSA_MIDI_SRC))
72     return FALSE;
73 
74   GST_DEBUG_CATEGORY_INIT (alsa_debug, "alsa", 0, "alsa plugins");
75 
76 #ifdef ENABLE_NLS
77   GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
78       LOCALEDIR);
79   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
80   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
81 #endif
82 
83   err = snd_lib_error_set_handler (gst_alsa_error_wrapper);
84   if (err != 0)
85     GST_WARNING ("failed to set alsa error handler");
86 
87   return TRUE;
88 }
89 
90 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
91     GST_VERSION_MINOR,
92     alsa,
93     "ALSA plugin library",
94     plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
95