Add a comment that explains why this header has no multiple inclusion guards.
[mplayer/greg.git] / libao2 / audio_out.c
blob2cc3d4dc6b48ca6e01f3e38974c4a2ce5cd60fb8
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "config.h"
6 #include "audio_out.h"
8 #include "mp_msg.h"
9 #include "help_mp.h"
10 #include "mplayer.h" /* for exit_player() */
12 // there are some globals:
13 ao_data_t ao_data={0,0,0,0,OUTBURST,-1,0};
14 char *ao_subdevice = NULL;
16 #ifdef USE_OSS_AUDIO
17 extern ao_functions_t audio_out_oss;
18 #endif
19 #ifdef MACOSX
20 extern ao_functions_t audio_out_macosx;
21 #endif
22 #ifdef USE_ARTS
23 extern ao_functions_t audio_out_arts;
24 #endif
25 #ifdef USE_ESD
26 extern ao_functions_t audio_out_esd;
27 #endif
28 #ifdef USE_PULSE
29 extern ao_functions_t audio_out_pulse;
30 #endif
31 #ifdef USE_JACK
32 extern ao_functions_t audio_out_jack;
33 #endif
34 #ifdef USE_OPENAL
35 extern ao_functions_t audio_out_openal;
36 #endif
37 extern ao_functions_t audio_out_null;
38 #ifdef HAVE_ALSA5
39 extern ao_functions_t audio_out_alsa5;
40 #endif
41 #ifdef HAVE_ALSA9
42 extern ao_functions_t audio_out_alsa;
43 #endif
44 #ifdef HAVE_ALSA1X
45 extern ao_functions_t audio_out_alsa;
46 #endif
47 #ifdef HAVE_NAS
48 extern ao_functions_t audio_out_nas;
49 #endif
50 #ifdef HAVE_SDL
51 extern ao_functions_t audio_out_sdl;
52 #endif
53 #ifdef USE_SUN_AUDIO
54 extern ao_functions_t audio_out_sun;
55 #endif
56 #ifdef USE_SGI_AUDIO
57 extern ao_functions_t audio_out_sgi;
58 #endif
59 #ifdef HAVE_WIN32WAVEOUT
60 extern ao_functions_t audio_out_win32;
61 #endif
62 #ifdef HAVE_DIRECTX
63 extern ao_functions_t audio_out_dsound;
64 #endif
65 #ifdef HAVE_DXR2
66 extern ao_functions_t audio_out_dxr2;
67 #endif
68 #ifdef HAVE_IVTV
69 extern ao_functions_t audio_out_ivtv;
70 #endif
71 #ifdef HAVE_V4L2_DECODER
72 extern ao_functions_t audio_out_v4l2;
73 #endif
74 extern ao_functions_t audio_out_mpegpes;
75 extern ao_functions_t audio_out_pcm;
76 extern ao_functions_t audio_out_pss;
78 ao_functions_t* audio_out_drivers[] =
80 // native:
81 #ifdef HAVE_DIRECTX
82 &audio_out_dsound,
83 #endif
84 #ifdef HAVE_WIN32WAVEOUT
85 &audio_out_win32,
86 #endif
87 #ifdef MACOSX
88 &audio_out_macosx,
89 #endif
90 #ifdef USE_OSS_AUDIO
91 &audio_out_oss,
92 #endif
93 #ifdef HAVE_ALSA1X
94 &audio_out_alsa,
95 #endif
96 #ifdef HAVE_ALSA9
97 &audio_out_alsa,
98 #endif
99 #ifdef HAVE_ALSA5
100 &audio_out_alsa5,
101 #endif
102 #ifdef USE_SGI_AUDIO
103 &audio_out_sgi,
104 #endif
105 #ifdef USE_SUN_AUDIO
106 &audio_out_sun,
107 #endif
108 // wrappers:
109 #ifdef USE_ARTS
110 &audio_out_arts,
111 #endif
112 #ifdef USE_ESD
113 &audio_out_esd,
114 #endif
115 #ifdef USE_PULSE
116 &audio_out_pulse,
117 #endif
118 #ifdef USE_JACK
119 &audio_out_jack,
120 #endif
121 #ifdef HAVE_NAS
122 &audio_out_nas,
123 #endif
124 #ifdef HAVE_SDL
125 &audio_out_sdl,
126 #endif
127 #ifdef USE_OPENAL
128 &audio_out_openal,
129 #endif
130 &audio_out_mpegpes,
131 #ifdef HAVE_DXR2
132 &audio_out_dxr2,
133 #endif
134 #ifdef HAVE_IVTV
135 &audio_out_ivtv,
136 #endif
137 #ifdef HAVE_V4L2_DECODER
138 &audio_out_v4l2,
139 #endif
140 &audio_out_null,
141 // should not be auto-selected:
142 &audio_out_pcm,
143 NULL
146 void list_audio_out(void){
147 int i=0;
148 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AvailableAudioOutputDrivers);
149 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_OUTPUTS\n");
150 while (audio_out_drivers[i]) {
151 const ao_info_t *info = audio_out_drivers[i++]->info;
152 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\t%s\t%s\n", info->short_name, info->name);
154 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
157 ao_functions_t* init_best_audio_out(char** ao_list,int use_plugin,int rate,int channels,int format,int flags){
158 int i;
159 // first try the preferred drivers, with their optional subdevice param:
160 if(ao_list && ao_list[0])
161 while(ao_list[0][0]){
162 char* ao=ao_list[0];
163 int ao_len;
164 if (strncmp(ao, "alsa9", 5) == 0 || strncmp(ao, "alsa1x", 6) == 0) {
165 mp_msg(MSGT_AO, MSGL_FATAL, MSGTR_AO_ALSA9_1x_Removed);
166 exit_player(NULL);
168 if (ao_subdevice) {
169 free(ao_subdevice);
170 ao_subdevice = NULL;
172 ao_subdevice=strchr(ao,':');
173 if(ao_subdevice){
174 ao_len = ao_subdevice - ao;
175 ao_subdevice = strdup(&ao[ao_len + 1]);
177 else
178 ao_len = strlen(ao);
179 for(i=0;audio_out_drivers[i];i++){
180 ao_functions_t* audio_out=audio_out_drivers[i];
181 if(!strncmp(audio_out->info->short_name,ao,ao_len)){
182 // name matches, try it
183 if(audio_out->init(rate,channels,format,flags))
184 return audio_out; // success!
187 // continue...
188 ++ao_list;
189 if(!(ao_list[0])) return NULL; // do NOT fallback to others
191 if (ao_subdevice) {
192 free(ao_subdevice);
193 ao_subdevice = NULL;
195 // now try the rest...
196 for(i=0;audio_out_drivers[i];i++){
197 ao_functions_t* audio_out=audio_out_drivers[i];
198 // if(audio_out->control(AOCONTROL_QUERY_FORMAT, (int)format) == CONTROL_TRUE)
199 if(audio_out->init(rate,channels,format,flags))
200 return audio_out; // success!
202 return NULL;