6 #include "libaf/af_format.h"
8 #include "audio_out_internal.h"
10 static ao_info_t info
=
14 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
20 struct timeval last_tv
;
23 static void drain(void){
25 struct timeval now_tv
;
28 gettimeofday(&now_tv
, 0);
29 temp
= now_tv
.tv_sec
- last_tv
.tv_sec
;
32 temp2
= now_tv
.tv_usec
- last_tv
.tv_usec
;
39 if (buffer
<0) buffer
=0;
41 if(temp
>0) last_tv
= now_tv
;//mplayer is fast
44 // to set/get/query special features/parameters
45 static int control(int cmd
,void *arg
){
49 // open & setup audio device
50 // return: 1=success 0=fail
51 static int init(int rate
,int channels
,int format
,int flags
){
53 int samplesize
= af_fmt2bits(format
) / 8;
54 ao_data
.outburst
= 256 * channels
* samplesize
;
55 // A "buffer" for about 0.2 seconds of audio
56 ao_data
.buffersize
= (int)(rate
* 0.2 / 256 + 1) * ao_data
.outburst
;
57 ao_data
.channels
=channels
;
58 ao_data
.samplerate
=rate
;
59 ao_data
.format
=format
;
60 ao_data
.bps
=channels
*rate
*samplesize
;
62 gettimeofday(&last_tv
, 0);
68 static void uninit(int immed
){
72 // stop playing and empty buffers (for seeking/pause)
73 static void reset(void){
77 // stop playing, keep buffers (for pause)
78 static void audio_pause(void)
80 // for now, just call reset();
84 // resume playing, after audio_pause()
85 static void audio_resume(void)
89 // return: how many bytes can be played without blocking
90 static int get_space(void){
93 return ao_data
.buffersize
- buffer
;
96 // plays 'len' bytes of 'data'
97 // it should round it down to outburst*n
98 // return: number of bytes played
99 static int play(void* data
,int len
,int flags
){
101 int maxbursts
= (ao_data
.buffersize
- buffer
) / ao_data
.outburst
;
102 int playbursts
= len
/ ao_data
.outburst
;
103 int bursts
= playbursts
> maxbursts
? maxbursts
: playbursts
;
104 buffer
+= bursts
* ao_data
.outburst
;
105 return bursts
* ao_data
.outburst
;
108 // return: delay in seconds between first and last sample in buffer
109 static float get_delay(void){
112 return (float) buffer
/ (float) ao_data
.bps
;