• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Copyright (C) 2020 Huawei Technologies Co., Ltd.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include "gstalsaelements.h"
28 #include "gstalsadeviceprovider.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 GST_DEVICE_PROVIDER_REGISTER_DEFINE (alsadeviceprovider, "alsadeviceprovider",
60     GST_RANK_SECONDARY, GST_TYPE_ALSA_DEVICE_PROVIDER);
61 
62 void
alsa_element_init(GstPlugin * plugin)63 alsa_element_init (GstPlugin * plugin)
64 {
65   static gsize res = FALSE;
66 
67   if (g_once_init_enter (&res)) {
68     GST_DEBUG_CATEGORY_INIT (alsa_debug, "alsa", 0, "alsa plugins");
69 #ifdef ENABLE_NLS
70     GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
71         LOCALEDIR);
72     bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
73     bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
74 #endif
75     if (snd_lib_error_set_handler (gst_alsa_error_wrapper) != 0)
76       GST_WARNING ("failed to set alsa error handler");
77     g_once_init_leave (&res, TRUE);
78   }
79 }
80