Close /dev/tty again on uninit.
[mplayer/glamo.git] / libao2 / audio_out.c
blobfc41a73e5717440fa8050f3129b7f1f833323d2d
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 "mplayer.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_dart;
51 extern const ao_functions_t audio_out_dxr2;
52 extern const ao_functions_t audio_out_ivtv;
53 extern const ao_functions_t audio_out_v4l2;
54 extern const ao_functions_t audio_out_mpegpes;
55 extern const ao_functions_t audio_out_pcm;
56 extern const ao_functions_t audio_out_pss;
58 const ao_functions_t* const audio_out_drivers[] =
60 // native:
61 #ifdef CONFIG_DIRECTX
62 &audio_out_dsound,
63 #endif
64 #ifdef CONFIG_WIN32WAVEOUT
65 &audio_out_win32,
66 #endif
67 #ifdef CONFIG_DART
68 &audio_out_dart,
69 #endif
70 #ifdef CONFIG_COREAUDIO
71 &audio_out_coreaudio,
72 #endif
73 #ifdef CONFIG_OSS_AUDIO
74 &audio_out_oss,
75 #endif
76 #ifdef CONFIG_ALSA
77 &audio_out_alsa,
78 #endif
79 #ifdef CONFIG_ALSA5
80 &audio_out_alsa5,
81 #endif
82 #ifdef CONFIG_SGI_AUDIO
83 &audio_out_sgi,
84 #endif
85 #ifdef CONFIG_SUN_AUDIO
86 &audio_out_sun,
87 #endif
88 // wrappers:
89 #ifdef CONFIG_ARTS
90 &audio_out_arts,
91 #endif
92 #ifdef CONFIG_ESD
93 &audio_out_esd,
94 #endif
95 #ifdef CONFIG_PULSE
96 &audio_out_pulse,
97 #endif
98 #ifdef CONFIG_JACK
99 &audio_out_jack,
100 #endif
101 #ifdef CONFIG_NAS
102 &audio_out_nas,
103 #endif
104 #ifdef CONFIG_SDL
105 &audio_out_sdl,
106 #endif
107 #ifdef CONFIG_OPENAL
108 &audio_out_openal,
109 #endif
110 &audio_out_mpegpes,
111 #ifdef CONFIG_DXR2
112 &audio_out_dxr2,
113 #endif
114 #ifdef CONFIG_IVTV
115 &audio_out_ivtv,
116 #endif
117 #ifdef CONFIG_V4L2_DECODER
118 &audio_out_v4l2,
119 #endif
120 &audio_out_null,
121 // should not be auto-selected:
122 &audio_out_pcm,
123 NULL
126 void list_audio_out(void){
127 int i=0;
128 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AvailableAudioOutputDrivers);
129 mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_AUDIO_OUTPUTS\n");
130 while (audio_out_drivers[i]) {
131 const ao_info_t *info = audio_out_drivers[i++]->info;
132 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\t%s\t%s\n", info->short_name, info->name);
134 mp_msg(MSGT_GLOBAL, MSGL_INFO,"\n");
137 const ao_functions_t* init_best_audio_out(char** ao_list,int use_plugin,int rate,int channels,int format,int flags){
138 int i;
139 // first try the preferred drivers, with their optional subdevice param:
140 if(ao_list && ao_list[0])
141 while(ao_list[0][0]){
142 char* ao=ao_list[0];
143 int ao_len;
144 if (strncmp(ao, "alsa9", 5) == 0 || strncmp(ao, "alsa1x", 6) == 0) {
145 mp_msg(MSGT_AO, MSGL_FATAL, MSGTR_AO_ALSA9_1x_Removed);
146 exit_player(NULL);
148 if (ao_subdevice) {
149 free(ao_subdevice);
150 ao_subdevice = NULL;
152 ao_subdevice=strchr(ao,':');
153 if(ao_subdevice){
154 ao_len = ao_subdevice - ao;
155 ao_subdevice = strdup(&ao[ao_len + 1]);
157 else
158 ao_len = strlen(ao);
160 mp_msg(MSGT_AO, MSGL_V, MSGTR_AO_TryingPreferredAudioDriver,
161 ao_len, ao, ao_subdevice ? ao_subdevice : "[none]");
163 for(i=0;audio_out_drivers[i];i++){
164 const ao_functions_t* audio_out=audio_out_drivers[i];
165 if(!strncmp(audio_out->info->short_name,ao,ao_len)){
166 // name matches, try it
167 if(audio_out->init(rate,channels,format,flags))
168 return audio_out; // success!
169 else
170 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_FailedInit, ao);
171 break;
174 if (!audio_out_drivers[i]) // we searched through the entire list
175 mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_NoSuchDriver, ao_len, ao);
176 // continue...
177 ++ao_list;
178 if(!(ao_list[0])) return NULL; // do NOT fallback to others
180 if (ao_subdevice) {
181 free(ao_subdevice);
182 ao_subdevice = NULL;
185 mp_msg(MSGT_AO, MSGL_V, MSGTR_AO_TryingEveryKnown);
187 // now try the rest...
188 for(i=0;audio_out_drivers[i];i++){
189 const ao_functions_t* audio_out=audio_out_drivers[i];
190 // if(audio_out->control(AOCONTROL_QUERY_FORMAT, (int)format) == CONTROL_TRUE)
191 if(audio_out->init(rate,channels,format,flags))
192 return audio_out; // success!
194 return NULL;