gst_plugins_base/ext/alsa/gstalsaplugin.c
changeset 0 0e761a78d257
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     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., 675 Mass Ave, Cambridge, MA 02139, 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 "gstalsamixerelement.h"
       
    29 
       
    30 #include <gst/gst-i18n-plugin.h>
       
    31 
       
    32 GST_DEBUG_CATEGORY (alsa_debug);
       
    33 
       
    34 /* ALSA debugging wrapper */
       
    35 static void
       
    36 gst_alsa_error_wrapper (const char *file, int line, const char *function,
       
    37     int err, const char *fmt, ...)
       
    38 {
       
    39 #ifndef GST_DISABLE_GST_DEBUG
       
    40   va_list args;
       
    41   gchar *str;
       
    42 
       
    43   va_start (args, fmt);
       
    44   str = g_strdup_vprintf (fmt, args);
       
    45   va_end (args);
       
    46   /* FIXME: use GST_LEVEL_ERROR here? Currently warning is used because we're 
       
    47    * able to catch enough of the errors that would be printed otherwise
       
    48    */
       
    49   gst_debug_log (alsa_debug, GST_LEVEL_WARNING, file, function, line, NULL,
       
    50       "alsalib error: %s%s%s", str, err ? ": " : "",
       
    51       err ? snd_strerror (err) : "");
       
    52   g_free (str);
       
    53 #endif
       
    54 }
       
    55 
       
    56 static gboolean
       
    57 plugin_init (GstPlugin * plugin)
       
    58 {
       
    59   int err;
       
    60 
       
    61   if (!gst_element_register (plugin, "alsamixer", GST_RANK_NONE,
       
    62           GST_TYPE_ALSA_MIXER_ELEMENT))
       
    63     return FALSE;
       
    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 
       
    71   GST_DEBUG_CATEGORY_INIT (alsa_debug, "alsa", 0, "alsa plugins");
       
    72 
       
    73 #if ENABLE_NLS
       
    74   GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
       
    75       LOCALEDIR);
       
    76   bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
       
    77 #endif
       
    78 
       
    79   err = snd_lib_error_set_handler (gst_alsa_error_wrapper);
       
    80   if (err != 0)
       
    81     GST_WARNING ("failed to set alsa error handler");
       
    82 
       
    83   return TRUE;
       
    84 }
       
    85 
       
    86 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
       
    87     GST_VERSION_MINOR,
       
    88     "alsa",
       
    89     "ALSA plugin library",
       
    90     plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)