10l fix by Jindrich Makovicka
[mplayer/greg.git] / libao2 / audio_out.c
blob08165975c982076bfb1fc59f6d5fdf18832f9d0b
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 #include "../config.h"
6 #include "audio_out.h"
7 #include "afmt.h"
9 #include "../mp_msg.h"
10 #include "../help_mp.h"
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 USE_ARTS
20 extern ao_functions_t audio_out_arts;
21 #endif
22 #ifdef USE_ESD
23 extern ao_functions_t audio_out_esd;
24 #endif
25 extern ao_functions_t audio_out_null;
26 #ifdef HAVE_ALSA5
27 extern ao_functions_t audio_out_alsa5;
28 #endif
29 #ifdef HAVE_ALSA9
30 extern ao_functions_t audio_out_alsa9;
31 #endif
32 #ifdef HAVE_ALSA1X
33 extern ao_functions_t audio_out_alsa1x;
34 #endif
35 #ifdef HAVE_NAS
36 extern ao_functions_t audio_out_nas;
37 #endif
38 #ifdef HAVE_SDL
39 extern ao_functions_t audio_out_sdl;
40 #endif
41 #ifdef USE_SUN_AUDIO
42 extern ao_functions_t audio_out_sun;
43 #endif
44 #ifdef USE_SGI_AUDIO
45 extern ao_functions_t audio_out_sgi;
46 #endif
47 #ifdef HAVE_WIN32WAVEOUT
48 extern ao_functions_t audio_out_win32;
49 #endif
50 #ifdef MACOSX
51 extern ao_functions_t audio_out_macosx;
52 #endif
53 #ifdef HAVE_DXR2
54 extern ao_functions_t audio_out_dxr2;
55 #endif
56 extern ao_functions_t audio_out_mpegpes;
57 extern ao_functions_t audio_out_pcm;
58 extern ao_functions_t audio_out_pss;
59 extern ao_functions_t audio_out_plugin;
61 ao_functions_t* audio_out_drivers[] =
63 // vo-related: will fail unless you also do -vo mpegpes/dxr2
64 &audio_out_mpegpes,
65 #ifdef HAVE_DXR2
66 &audio_out_dxr2,
67 #endif
68 // native:
69 #ifdef HAVE_WIN32WAVEOUT
70 &audio_out_win32,
71 #endif
72 #ifdef MACOSX
73 &audio_out_macosx,
74 #endif
75 #ifdef USE_OSS_AUDIO
76 &audio_out_oss,
77 #endif
78 #ifdef HAVE_ALSA1X
79 &audio_out_alsa1x,
80 #endif
81 #ifdef HAVE_ALSA9
82 &audio_out_alsa9,
83 #endif
84 #ifdef HAVE_ALSA5
85 &audio_out_alsa5,
86 #endif
87 #ifdef USE_SGI_AUDIO
88 &audio_out_sgi,
89 #endif
90 #ifdef USE_SUN_AUDIO
91 &audio_out_sun,
92 #endif
93 // wrappers:
94 #ifdef USE_ARTS
95 &audio_out_arts,
96 #endif
97 #ifdef USE_ESD
98 &audio_out_esd,
99 #endif
100 #ifdef HAVE_NAS
101 &audio_out_nas,
102 #endif
103 #ifdef HAVE_SDL
104 &audio_out_sdl,
105 #endif
106 &audio_out_null,
107 // should not be auto-selected:
108 &audio_out_pcm,
109 &audio_out_plugin,
110 NULL
113 void list_audio_out(){
114 int i=0;
115 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AvailableAudioOutputDrivers);
116 while (audio_out_drivers[i]) {
117 const ao_info_t *info = audio_out_drivers[i++]->info;
118 printf("\t%s\t%s\n", info->short_name, info->name);
120 printf("\n");
123 ao_functions_t* init_best_audio_out(char** ao_list,int use_plugin,int rate,int channels,int format,int flags){
124 int i;
125 // first try the preferred drivers, with their optional subdevice param:
126 if(ao_list && ao_list[0])
127 while(ao_list[0][0]){
128 char* ao=strdup(ao_list[0]);
129 ao_subdevice=strchr(ao,':');
130 if(ao_subdevice){
131 ao_subdevice[0]=0;
132 ++ao_subdevice;
134 for(i=0;audio_out_drivers[i];i++){
135 ao_functions_t* audio_out=audio_out_drivers[i];
136 if(!strcmp(audio_out->info->short_name,ao)){
137 // name matches, try it
138 if(use_plugin){
139 audio_out_plugin.control(AOCONTROL_SET_PLUGIN_DRIVER,audio_out);
140 audio_out=&audio_out_plugin;
142 if(audio_out->init(rate,channels,format,flags))
143 return audio_out; // success!
146 // continue...
147 ++ao_list;
148 if(!(ao_list[0])) return NULL; // do NOT fallback to others
150 // now try the rest...
151 ao_subdevice=NULL;
152 for(i=0;audio_out_drivers[i];i++){
153 ao_functions_t* audio_out=audio_out_drivers[i];
154 if(use_plugin){
155 audio_out_plugin.control(AOCONTROL_SET_PLUGIN_DRIVER,audio_out);
156 audio_out=&audio_out_plugin;
158 if(audio_out->init(rate,channels,format,flags))
159 return audio_out; // success!
161 return NULL;