]> git.sesse.net Git - vlc/blob - plugins/dsp/dsp.c
. Test non bloquant de l'ouverture du dsp � l'initialisation du plugin
[vlc] / plugins / dsp / dsp.c
1 /*****************************************************************************
2  * dsp.c : OSS /dev/dsp plugin for vlc
3  *****************************************************************************
4  * Copyright (C) 2000 VideoLAN
5  *
6  * Authors:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  * 
13  * This program 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
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
21  *****************************************************************************/
22
23 /*****************************************************************************
24  * Preamble
25  *****************************************************************************/
26 #include "defs.h"
27
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <fcntl.h>
31 #include <stdlib.h>                                      /* malloc(), free() */
32 #include <unistd.h>                                               /* close() */
33
34 #include "config.h"
35 #include "common.h"                                     /* boolean_t, byte_t */
36 #include "threads.h"
37 #include "mtime.h"
38 #include "tests.h"
39 #include "plugins.h"
40
41 #include "interface.h"
42 #include "audio_output.h"
43 #include "video.h"
44 #include "video_output.h"
45
46 #include "main.h"
47
48 /*****************************************************************************
49  * Exported prototypes
50  *****************************************************************************/
51 static void aout_GetPlugin( p_aout_thread_t p_aout );
52
53 /* Audio output */
54 int     aout_DspOpen         ( aout_thread_t *p_aout );
55 int     aout_DspReset        ( aout_thread_t *p_aout );
56 int     aout_DspSetFormat    ( aout_thread_t *p_aout );
57 int     aout_DspSetChannels  ( aout_thread_t *p_aout );
58 int     aout_DspSetRate      ( aout_thread_t *p_aout );
59 long    aout_DspGetBufInfo   ( aout_thread_t *p_aout, long l_buffer_info );
60 void    aout_DspPlaySamples  ( aout_thread_t *p_aout, byte_t *buffer,
61                                int i_size );
62 void    aout_DspClose        ( aout_thread_t *p_aout );
63
64 /*****************************************************************************
65  * GetConfig: get the plugin structure and configuration
66  *****************************************************************************/
67 plugin_info_t * GetConfig( void )
68 {
69     int i_fd;
70     plugin_info_t * p_info = (plugin_info_t *) malloc( sizeof(plugin_info_t) );
71
72     p_info->psz_name    = "OSS /dev/dsp";
73     p_info->psz_version = VERSION;
74     p_info->psz_author  = "the VideoLAN team <vlc@videolan.org>";
75
76     p_info->aout_GetPlugin = aout_GetPlugin;
77     p_info->vout_GetPlugin = NULL;
78     p_info->intf_GetPlugin = NULL;
79     p_info->yuv_GetPlugin  = NULL;
80
81     /* Test if the device can be opened */
82     if ( (i_fd = open( main_GetPszVariable( AOUT_DSP_VAR, AOUT_DSP_DEFAULT ),
83                        O_WRONLY|O_NONBLOCK )) < 0 )
84     {
85         p_info->i_score = 0;
86     }
87     else
88     {
89         close( i_fd );
90         p_info->i_score = 0x100;
91     }
92
93     /* If this plugin was requested, score it higher */
94     if( TestMethod( AOUT_METHOD_VAR, "dsp" ) )
95     {
96         p_info->i_score += 0x200;
97     }
98
99     return( p_info );
100 }
101
102 /*****************************************************************************
103  * Following functions are only called through the p_info structure
104  *****************************************************************************/
105
106 static void aout_GetPlugin( p_aout_thread_t p_aout )
107 {
108     p_aout->p_sys_open        = aout_DspOpen;
109     p_aout->p_sys_reset       = aout_DspReset;
110     p_aout->p_sys_setformat   = aout_DspSetFormat;
111     p_aout->p_sys_setchannels = aout_DspSetChannels;
112     p_aout->p_sys_setrate     = aout_DspSetRate;
113     p_aout->p_sys_getbufinfo  = aout_DspGetBufInfo;
114     p_aout->p_sys_playsamples = aout_DspPlaySamples;
115     p_aout->p_sys_close       = aout_DspClose;
116 }
117