sync with en/mplayer.1 rev. 30611
[mplayer/glamo.git] / libao2 / audio_out.c
blobfc47c82ea7d1f35f63e2d695e6ef4ce216bf3d57
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
23 #include "config.h"
24 #include "audio_out.h"
26 #include "mp_msg.h"
27 #include "help_mp.h"
28 #include "mp_core.h" /* for exit_player() */
30 // there are some globals:
31 ao_data_t ao_data={0,0,0,0,OUTBURST,-1,0};
32 char *ao_subdevice = NULL;
34 extern const ao_functions_t audio_out_oss;
35 extern const ao_functions_t audio_out_coreaudio;
36 extern const ao_functions_t audio_out_arts;
37 extern const ao_functions_t audio_out_esd;
38 extern const ao_functions_t audio_out_pulse;
39 extern const ao_functions_t audio_out_jack;
40 extern const ao_functions_t audio_out_openal;
41 extern const ao_functions_t audio_out_null;
42 extern const ao_functions_t audio_out_alsa5;
43 extern const ao_functions_t audio_out_alsa;
44 extern const ao_functions_t audio_out_nas;
45 extern const ao_functions_t audio_out_sdl;
46 extern const ao_functions_t audio_out_sun;
47 extern const ao_functions_t audio_out_sgi;
48 extern const ao_functions_t audio_out_win32;
49 extern const ao_functions_t audio_out_dsound;
50 extern const ao_functions_t audio_out_kai;
51 extern const ao_functions_t audio_out_dart;
52 extern const ao_functions_t audio_out_dxr2;
53 extern const ao_functions_t audio_out_ivtv;
54 extern const ao_functions_t audio_out_v4l2;
55 extern const ao_functions_t audio_out_mpegpes;
56 extern const ao_functions_t audio_out_pcm;
57 extern const ao_functions_t audio_out_pss;
59 const ao_functions_t* const audio_out_drivers[] =
61 // native:
62 #ifdef CONFIG_DIRECTX
63 &audio_out_dsound,
64 #endif
65 #ifdef CONFIG_WIN32WAVEOUT
66 &audio_out_win32,
67 #endif
68 #ifdef CONFIG_KAI
69 &audio_out_kai,
70 #endif
71 #ifdef CONFIG_DART
72 &audio_out_dart,
73 #endif
74 #ifdef CONFIG_COREAUDIO
75 &audio_out_coreaudio,
76 #endif
77 #ifdef CONFIG_OSS_AUDIO
78 &audio_out_oss,
79 #endif
80 #ifdef CONFIG_ALSA
81 &audio_out_alsa,
82 #endif
83 #ifdef CONFIG_ALSA5
84 &audio_out_alsa5,
85 #endif
86 #ifdef CONFIG_SGI_AUDIO
87 &audio_out_sgi,
88 #endif
89 #ifdef CONFIG_SUN_AUDIO
90 &audio_out_sun,
91 #endif
92 // wrappers:
93 #ifdef CONFIG_ARTS
94 &audio_out_arts,
95 #endif
96 #ifdef CONFIG_ESD
97 &audio_out_esd,
98 #endif
99 #ifdef CONFIG_PULSE
100 &audio_out_pulse,
101 #endif
102 #ifdef CONFIG_JACK
103 &audio_out_jack,
104 #endif
105 #ifdef CONFIG_NAS
106 &audio_out_nas,
107 #endif
108 #ifdef CONFIG_SDL
109 &audio_out_sdl,
110 #endif
111 #ifdef CONFIG_OPENAL
112 &audio_out_openal,
113 #endif
114 &audio_out_mpegpes,
115 #ifdef CONFIG_DXR2
116 &audio_out_dxr2,
117 #endif
118 #ifdef CONFIG_IVTV
119 &audio_out_ivtv,
120 #endif
121 #ifdef CONFIG_V4L2_DECODER
122 &audio_out_v4l2,
123 #endif
124 &audio_out_null,
125 // should not be auto-selected:
126 &audio_out_pcm,
127 NULL
130 void list_audio_out(void){
131 int i=0;
132 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AvailableAudioOutputDrivers);
133 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_OUTPUTS\n");
134 while (audio_out_drivers[i]) {
135 const ao_info_t *info = audio_out_drivers[i++]->info;
136 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\t%s\t%s\n", info->short_name, info->name);
138 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
141 const ao_functions_t* init_best_audio_out(char** ao_list,int use_plugin,int rate,int channels,int format,int flags){
142 int i;
143 // first try the preferred drivers, with their optional subdevice param:
144 if(ao_list && ao_list[0])
145 while(ao_list[0][0]){
146 char* ao=ao_list[0];
147 int ao_len;
148 if (strncmp(ao, "alsa9", 5) == 0 || strncmp(ao, "alsa1x", 6) == 0) {
149 mp_msg(MSGT_AO, MSGL_FATAL, MSGTR_AO_ALSA9_1x_Removed);
150 exit_player(EXIT_NONE);
152 if (ao_subdevice) {
153 free(ao_subdevice);
154 ao_subdevice = NULL;
156 ao_subdevice=strchr(ao,':');
157 if(ao_subdevice){
158 ao_len = ao_subdevice - ao;
159 ao_subdevice = strdup(&ao[ao_len + 1]);
161 else
162 ao_len = strlen(ao);
164 mp_msg(MSGT_AO, MSGL_V, MSGTR_AO_TryingPreferredAudioDriver,
165 ao_len, ao, ao_subdevice ? ao_subdevice : "[none]");
167 for(i=0;audio_out_drivers[i];i++){
168 const ao_functions_t* audio_out=audio_out_drivers[i];
169 if(!strncmp(audio_out->info->short_name,ao,ao_len)){
170 // name matches, try it
171 if(audio_out->init(rate,channels,format,flags))
172 return audio_out; // success!
173 else
174 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_FailedInit, ao);
175 break;
178 if (!audio_out_drivers[i]) // we searched through the entire list
179 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_NoSuchDriver, ao_len, ao);
180 // continue...
181 ++ao_list;
182 if(!(ao_list[0])) return NULL; // do NOT fallback to others
184 if (ao_subdevice) {
185 free(ao_subdevice);
186 ao_subdevice = NULL;
189 mp_msg(MSGT_AO, MSGL_V, MSGTR_AO_TryingEveryKnown);
191 // now try the rest...
192 for(i=0;audio_out_drivers[i];i++){
193 const ao_functions_t* audio_out=audio_out_drivers[i];
194 // if(audio_out->control(AOCONTROL_QUERY_FORMAT, (int)format) == CONTROL_TRUE)
195 if(audio_out->init(rate,channels,format,flags))
196 return audio_out; // success!
198 return NULL;