]> git.sesse.net Git - vlc/blob - plugins/alsa/alsa.c
* Ported Glide and MGA plugins to the new module API. MGA never worked,
[vlc] / plugins / alsa / alsa.c
1 /*****************************************************************************
2  * alsa.c : alsa plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000 VideoLAN
5  *
6  * Authors:
7  *  Henri Fallon <henri@videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #define MODULE_NAME alsa
25 #include "modules_inner.h"
26
27 /*****************************************************************************
28  * Preamble
29  *****************************************************************************/
30
31 #include "defs.h"
32
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <sys/asoundlib.h>                                    /* for alsa :) */
36 #include <linux/asound.h>
37 #include <fcntl.h>
38 #include <stdlib.h>                                      /* malloc(), free() */
39
40 #include "config.h"
41 #include "common.h"                                     /* boolean_t, byte_t */
42 #include "threads.h"
43 #include "mtime.h"
44
45 #include "interface.h"
46
47 #include "main.h"
48
49 #include "modules.h"
50
51 /*****************************************************************************
52  * Build configuration tree.
53  *****************************************************************************/
54 MODULE_CONFIG_START
55     ADD_COMMENT( "Yeah, alsa rocks !" )
56 MODULE_CONFIG_END     
57
58 /*****************************************************************************
59  * Capabilities defined in the other files.
60  *****************************************************************************/
61 void _M( aout_getfunctions )( function_list_t * p_function_list );
62
63 /*****************************************************************************
64  * InitModule: get the module structure and configuration.
65  *****************************************************************************
66  * We have to fill psz_name, psz_longname and psz_version. These variables
67  * will be strdup()ed later by the main application because the module can
68  * be unloaded later to save memory, and we want to be able to access this
69  * data even after the module has been unloaded.
70  *****************************************************************************/
71 MODULE_INIT
72 {
73     p_module->psz_name = MODULE_STRING;
74     p_module->psz_longname = "Alsa audio module";
75     p_module->psz_version = VERSION;
76     p_module->i_capabilities =  MODULE_CAPABILITY_NULL
77                                 | MODULE_CAPABILITY_AOUT;
78     return( 0 );
79 }
80     
81
82 /*****************************************************************************
83  * ActivateModule: set the module to an usable state.
84  *****************************************************************************
85  * This function fills the capability functions and the configuration
86  * structure. Once ActivateModule() has been called, the i_usage can
87  * be set to 0 and calls to NeedModule() be made to increment it. To unload
88  * the module, one has to wait until i_usage == 0 and call DeactivateModule().
89  *****************************************************************************/
90 MODULE_ACTIVATE
91 {
92     p_module->p_functions = malloc( sizeof( module_functions_t ) );
93     if( p_module->p_functions == NULL )
94     {
95         return( -1 );
96     }
97
98     _M( aout_getfunctions )( &p_module->p_functions->aout );
99     
100     p_module->p_config = p_config;
101     
102     return( 0 );
103 }
104
105
106 /*****************************************************************************
107  * DeactivateModule: make sure the module can be unloaded.
108  *****************************************************************************
109  * This function must only be called when i_usage == 0. If it successfully
110  * returns, i_usage can be set to -1 and the module unloaded. Be careful to
111  * lock usage_lock during the whole process.
112  *****************************************************************************/
113 MODULE_DEACTIVATE
114 {
115     free( p_module->p_functions );
116
117     return( 0 );
118 }
119