Mercurial > mplayer.hg
annotate libao2/ao_sdl.c @ 30419:b77bfd94aaf3
Add missing license headers.
author | diego |
---|---|
date | Sat, 30 Jan 2010 13:49:24 +0000 |
parents | dc1d66a20ec2 |
children | d218228dc74d |
rev | line source |
---|---|
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
1 /* |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
2 * SDLlib audio output driver for MPlayer |
972 | 3 * |
23734 | 4 * Copyleft 2001 by Felix BĆ¼nemann (atmosfear@users.sf.net) |
972 | 5 * |
27509
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
6 * This file is part of MPlayer. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
7 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
11 * (at your option) any later version. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
12 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
16 * GNU General Public License for more details. |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
17 * |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
19 * along with MPlayer; if not, write to the Free Software |
d97a607821f1
Replace casual GPL notices by proper license headers.
diego
parents:
26757
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
972 | 21 */ |
22 | |
966 | 23 #include <stdio.h> |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
24 #include <stdlib.h> |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
25 #include <string.h> |
966 | 26 |
14123 | 27 #include "config.h" |
28 #include "mp_msg.h" | |
29 #include "help_mp.h" | |
8027 | 30 |
966 | 31 #include "audio_out.h" |
32 #include "audio_out_internal.h" | |
14245 | 33 #include "libaf/af_format.h" |
30136 | 34 #ifdef CONFIG_SDL_SDL_H |
35 #include <SDL/SDL.h> | |
36 #else | |
6184 | 37 #include <SDL.h> |
30136 | 38 #endif |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
39 #include "osdep/timer.h" |
966 | 40 |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
41 #include "libavutil/fifo.h" |
972 | 42 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
43 static const ao_info_t info = |
966 | 44 { |
45 "SDLlib audio output", | |
46 "sdl", | |
47 "Felix Buenemann <atmosfear@users.sourceforge.net>", | |
48 "" | |
49 }; | |
50 | |
51 LIBAO_EXTERN(sdl) | |
52 | |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
53 // turn this on if you want to use the slower SDL_MixAudio |
12908
7b9b4f07d2c4
automatic loading of af_volume, original patch by Dan Christiansen (danchr (at) daimi (dot) au (dot) dk)
reimar
parents:
12714
diff
changeset
|
54 #undef USE_SDL_INTERNAL_MIXER |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
55 |
972 | 56 // Samplesize used by the SDLlib AudioSpec struct |
27727
48c1ae64255b
Replace preprocessor check for WIN32 with checks for __MINGW32__ and __CYGWIN__.
diego
parents:
27509
diff
changeset
|
57 #if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__AMIGAOS4__) |
12019
6ede5366bc47
fix compilation with sdl on mingw patch by Nehal <nehalmistry at gmx.net>
faust3
parents:
11750
diff
changeset
|
58 #define SAMPLESIZE 2048 |
12113 | 59 #else |
60 #define SAMPLESIZE 1024 | |
61 #endif | |
972 | 62 |
13832
2f8cfe66dbfd
Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents:
13383
diff
changeset
|
63 #define CHUNK_SIZE 4096 |
2f8cfe66dbfd
Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents:
13383
diff
changeset
|
64 #define NUM_CHUNKS 8 |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
65 #define BUFFSIZE (NUM_CHUNKS * CHUNK_SIZE) |
972 | 66 |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
67 static AVFifoBuffer *buffer; |
972 | 68 |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
69 #ifdef USE_SDL_INTERNAL_MIXER |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
70 static unsigned char volume=SDL_MIX_MAXVOLUME; |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
71 #endif |
972 | 72 |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
73 static int write_buffer(unsigned char* data,int len){ |
29126 | 74 int free = av_fifo_space(buffer); |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
75 if (len > free) len = free; |
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
76 return av_fifo_generic_write(buffer, data, len, NULL); |
13832
2f8cfe66dbfd
Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents:
13383
diff
changeset
|
77 } |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
78 |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
79 #ifdef USE_SDL_INTERNAL_MIXER |
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
80 static void mix_audio(void *dst, void *src, int len) { |
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
81 SDL_MixAudio(dst, src, len, volume); |
972 | 82 } |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
83 #endif |
972 | 84 |
85 static int read_buffer(unsigned char* data,int len){ | |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
86 int buffered = av_fifo_size(buffer); |
13832
2f8cfe66dbfd
Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents:
13383
diff
changeset
|
87 if (len > buffered) len = buffered; |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
88 #ifdef USE_SDL_INTERNAL_MIXER |
29439
02dec439f717
100l, av_fifo_generic_read does not return anything useful, so ignore its
reimar
parents:
29263
diff
changeset
|
89 av_fifo_generic_read(buffer, data, len, mix_audio); |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
90 #else |
29439
02dec439f717
100l, av_fifo_generic_read does not return anything useful, so ignore its
reimar
parents:
29263
diff
changeset
|
91 av_fifo_generic_read(buffer, data, len, NULL); |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
92 #endif |
29439
02dec439f717
100l, av_fifo_generic_read does not return anything useful, so ignore its
reimar
parents:
29263
diff
changeset
|
93 return len; |
972 | 94 } |
95 | |
96 // end ring buffer stuff | |
966 | 97 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
98 |
966 | 99 // to set/get/query special features/parameters |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
8027
diff
changeset
|
100 static int control(int cmd,void *arg){ |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
101 #ifdef USE_SDL_INTERNAL_MIXER |
6184 | 102 switch (cmd) { |
103 case AOCONTROL_GET_VOLUME: | |
104 { | |
105 ao_control_vol_t* vol = (ao_control_vol_t*)arg; | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
106 vol->left = vol->right = volume * 100 / SDL_MIX_MAXVOLUME; |
6184 | 107 return CONTROL_OK; |
108 } | |
109 case AOCONTROL_SET_VOLUME: | |
110 { | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
111 int diff; |
6184 | 112 ao_control_vol_t* vol = (ao_control_vol_t*)arg; |
113 diff = (vol->left+vol->right) / 2; | |
12093
f54d02f6ddbf
let uninit wait until sound is completely played, don't restore volume at exit, fixed ringbuffer bug, patch by Nehal <nehalmistry at gmx.net>\n
faust3
parents:
12027
diff
changeset
|
114 volume = diff * SDL_MIX_MAXVOLUME / 100; |
6184 | 115 return CONTROL_OK; |
116 } | |
117 } | |
12673
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
118 #endif |
c1371fce7267
make the internal sdl mixer optional, idea by Reimar Doffinger
alex
parents:
12440
diff
changeset
|
119 return CONTROL_UNKNOWN; |
966 | 120 } |
121 | |
972 | 122 // SDL Callback function |
123 void outputaudio(void *unused, Uint8 *stream, int len) { | |
124 //SDL_MixAudio(stream, read_buffer(buffers, len), len, SDL_MIX_MAXVOLUME); | |
1066 | 125 //if(!full_buffers) printf("SDL: Buffer underrun!\n"); |
126 | |
972 | 127 read_buffer(stream, len); |
1066 | 128 //printf("SDL: Full Buffers: %i\n", full_buffers); |
966 | 129 } |
130 | |
131 // open & setup audio device | |
132 // return: 1=success 0=fail | |
133 static int init(int rate,int channels,int format,int flags){ | |
134 | |
972 | 135 /* SDL Audio Specifications */ |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
136 SDL_AudioSpec aspec, obtained; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
137 |
972 | 138 /* Allocate ring-buffer memory */ |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
139 buffer = av_fifo_alloc(BUFFSIZE); |
972 | 140 |
14264 | 141 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_SDL_INFO, rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format)); |
983 | 142 |
1189 | 143 if(ao_subdevice) { |
144 setenv("SDL_AUDIODRIVER", ao_subdevice, 1); | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
145 mp_msg(MSGT_AO,MSGL_INFO,MSGTR_AO_SDL_DriverInfo, ao_subdevice); |
1189 | 146 } |
3095 | 147 |
7660 | 148 ao_data.channels=channels; |
149 ao_data.samplerate=rate; | |
150 ao_data.format=format; | |
151 | |
3137 | 152 ao_data.bps=channels*rate; |
14245 | 153 if(format != AF_FORMAT_U8 && format != AF_FORMAT_S8) |
3095 | 154 ao_data.bps*=2; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
155 |
1066 | 156 /* The desired audio format (see SDL_AudioSpec) */ |
157 switch(format) { | |
14245 | 158 case AF_FORMAT_U8: |
1066 | 159 aspec.format = AUDIO_U8; |
160 break; | |
14245 | 161 case AF_FORMAT_S16_LE: |
1066 | 162 aspec.format = AUDIO_S16LSB; |
163 break; | |
14245 | 164 case AF_FORMAT_S16_BE: |
1066 | 165 aspec.format = AUDIO_S16MSB; |
166 break; | |
14245 | 167 case AF_FORMAT_S8: |
1066 | 168 aspec.format = AUDIO_S8; |
169 break; | |
14245 | 170 case AF_FORMAT_U16_LE: |
1066 | 171 aspec.format = AUDIO_U16LSB; |
172 break; | |
14245 | 173 case AF_FORMAT_U16_BE: |
1066 | 174 aspec.format = AUDIO_U16MSB; |
175 break; | |
176 default: | |
12440
56bdb9b7a4bc
use fallback for unsupported formats instead of quitting
reimar
parents:
12151
diff
changeset
|
177 aspec.format = AUDIO_S16LSB; |
14245 | 178 ao_data.format = AF_FORMAT_S16_LE; |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
179 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_SDL_UnsupportedAudioFmt, format); |
1066 | 180 } |
181 | |
966 | 182 /* The desired audio frequency in samples-per-second. */ |
183 aspec.freq = rate; | |
184 | |
185 /* Number of channels (mono/stereo) */ | |
186 aspec.channels = channels; | |
187 | |
188 /* The desired size of the audio buffer in samples. This number should be a power of two, and may be adjusted by the audio driver to a value more suitable for the hardware. Good values seem to range between 512 and 8192 inclusive, depending on the application and CPU speed. Smaller values yield faster response time, but can lead to underflow if the application is doing heavy processing and cannot fill the audio buffer in time. A stereo sample consists of both right and left channels in LR ordering. Note that the number of samples is directly related to time by the following formula: ms = (samples*1000)/freq */ | |
972 | 189 aspec.samples = SAMPLESIZE; |
966 | 190 |
191 /* This should be set to a function that will be called when the audio device is ready for more data. It is passed a pointer to the audio buffer, and the length in bytes of the audio buffer. This function usually runs in a separate thread, and so you should protect data structures that it accesses by calling SDL_LockAudio and SDL_UnlockAudio in your code. The callback prototype is: | |
192 void callback(void *userdata, Uint8 *stream, int len); userdata is the pointer stored in userdata field of the SDL_AudioSpec. stream is a pointer to the audio buffer you want to fill with information and len is the length of the audio buffer in bytes. */ | |
972 | 193 aspec.callback = outputaudio; |
966 | 194 |
195 /* This pointer is passed as the first parameter to the callback function. */ | |
196 aspec.userdata = NULL; | |
197 | |
972 | 198 /* initialize the SDL Audio system */ |
199 if (SDL_Init (SDL_INIT_AUDIO/*|SDL_INIT_NOPARACHUTE*/)) { | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
200 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_SDL_CantInit, SDL_GetError()); |
972 | 201 return 0; |
202 } | |
203 | |
966 | 204 /* Open the audio device and start playing sound! */ |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
205 if(SDL_OpenAudio(&aspec, &obtained) < 0) { |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
206 mp_msg(MSGT_AO,MSGL_ERR,MSGTR_AO_SDL_CantOpenAudio, SDL_GetError()); |
26757
0fdf04b07ecb
cosmetics: Remove pointless parentheses from return statements.
diego
parents:
25335
diff
changeset
|
207 return 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
208 } |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
209 |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
210 /* did we got what we wanted ? */ |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
211 ao_data.channels=obtained.channels; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
212 ao_data.samplerate=obtained.freq; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
213 |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
214 switch(obtained.format) { |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
215 case AUDIO_U8 : |
14245 | 216 ao_data.format = AF_FORMAT_U8; |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
217 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
218 case AUDIO_S16LSB : |
14245 | 219 ao_data.format = AF_FORMAT_S16_LE; |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
220 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
221 case AUDIO_S16MSB : |
14245 | 222 ao_data.format = AF_FORMAT_S16_BE; |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
223 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
224 case AUDIO_S8 : |
14245 | 225 ao_data.format = AF_FORMAT_S8; |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
226 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
227 case AUDIO_U16LSB : |
14245 | 228 ao_data.format = AF_FORMAT_U16_LE; |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
229 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
230 case AUDIO_U16MSB : |
14245 | 231 ao_data.format = AF_FORMAT_U16_BE; |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
232 break; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
233 default: |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12908
diff
changeset
|
234 mp_msg(MSGT_AO,MSGL_WARN,MSGTR_AO_SDL_UnsupportedAudioFmt, obtained.format); |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
235 return 0; |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
236 } |
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
237 |
8027 | 238 mp_msg(MSGT_AO,MSGL_V,"SDL: buf size = %d\n",obtained.size); |
7908
dc96a3eb9fab
Check what we obtain in SDL_OpenAudio() - allows to build the
colin
parents:
7897
diff
changeset
|
239 ao_data.buffersize=obtained.size; |
13887
48ce49693b3c
respect immed uninit flag, initialize ao_data.outburst.
reimar
parents:
13832
diff
changeset
|
240 ao_data.outburst = CHUNK_SIZE; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
241 |
966 | 242 /* unsilence audio, if callback is ready */ |
243 SDL_PauseAudio(0); | |
244 | |
245 return 1; | |
246 } | |
247 | |
248 // close audio device | |
12145 | 249 static void uninit(int immed){ |
8027 | 250 mp_msg(MSGT_AO,MSGL_V,"SDL: Audio Subsystem shutting down!\n"); |
13887
48ce49693b3c
respect immed uninit flag, initialize ao_data.outburst.
reimar
parents:
13832
diff
changeset
|
251 if (!immed) |
14849
d313f591d1a4
aos should respect the immed uninit flag (quit immediatly vs waiting till file
reimar
parents:
14264
diff
changeset
|
252 usec_sleep(get_delay() * 1000 * 1000); |
966 | 253 SDL_CloseAudio(); |
972 | 254 SDL_QuitSubSystem(SDL_INIT_AUDIO); |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
255 av_fifo_free(buffer); |
966 | 256 } |
257 | |
258 // stop playing and empty buffers (for seeking/pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17245
diff
changeset
|
259 static void reset(void){ |
1066 | 260 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
261 //printf("SDL: reset called!\n"); |
1066 | 262 |
13832
2f8cfe66dbfd
Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents:
13383
diff
changeset
|
263 SDL_PauseAudio(1); |
972 | 264 /* Reset ring-buffer state */ |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
265 av_fifo_reset(buffer); |
13832
2f8cfe66dbfd
Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents:
13383
diff
changeset
|
266 SDL_PauseAudio(0); |
966 | 267 } |
268 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
269 // stop playing, keep buffers (for pause) |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17245
diff
changeset
|
270 static void audio_pause(void) |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
271 { |
1070 | 272 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
273 //printf("SDL: audio_pause called!\n"); |
7897
7674e94baff7
Change SDL_(Un)lockAudio to PauseAudio() (works better)
colin
parents:
7660
diff
changeset
|
274 SDL_PauseAudio(1); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
275 |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
276 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
277 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
278 // resume playing, after audio_pause() |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17245
diff
changeset
|
279 static void audio_resume(void) |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
280 { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
281 //printf("SDL: audio_resume called!\n"); |
7897
7674e94baff7
Change SDL_(Un)lockAudio to PauseAudio() (works better)
colin
parents:
7660
diff
changeset
|
282 SDL_PauseAudio(0); |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
283 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
284 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
993
diff
changeset
|
285 |
966 | 286 // return: how many bytes can be played without blocking |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17245
diff
changeset
|
287 static int get_space(void){ |
29126 | 288 return av_fifo_space(buffer); |
966 | 289 } |
290 | |
291 // plays 'len' bytes of 'data' | |
292 // it should round it down to outburst*n | |
293 // return: number of bytes played | |
294 static int play(void* data,int len,int flags){ | |
972 | 295 |
22104 | 296 if (!(flags & AOPLAY_FINAL_CHUNK)) |
12151
75fdb659f5bf
round len to outburst and increment full_buffers at the correct time, patch by Nehal <nehalmistry at gmx.net>
faust3
parents:
12145
diff
changeset
|
297 len = (len/ao_data.outburst)*ao_data.outburst; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
298 #if 0 |
972 | 299 int ret; |
966 | 300 |
972 | 301 /* Audio locking prohibits call of outputaudio */ |
966 | 302 SDL_LockAudio(); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29126
diff
changeset
|
303 // copy audio stream into ring-buffer |
972 | 304 ret = write_buffer(data, len); |
966 | 305 SDL_UnlockAudio(); |
306 | |
972 | 307 return ret; |
308 #else | |
309 return write_buffer(data, len); | |
310 #endif | |
966 | 311 } |
312 | |
3095 | 313 // return: delay in seconds between first and last sample in buffer |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17245
diff
changeset
|
314 static float get_delay(void){ |
28882
15f93fd5cd48
Reuse libavutil fifo code instead of reimplementing it over and over.
reimar
parents:
28823
diff
changeset
|
315 int buffered = av_fifo_size(buffer); // could be less |
13832
2f8cfe66dbfd
Different buffering scheme, avoiding possible races (SDL is using threads!).
reimar
parents:
13383
diff
changeset
|
316 return (float)(buffered + ao_data.buffersize)/(float)ao_data.bps; |
966 | 317 } |
318 | |
319 | |
320 | |
321 | |
322 | |
323 |