Add explanatory comments to the #endif part of multiple inclusion guards.
[mplayer/greg.git] / libao2 / ao_null.c
blobfc81af6588959f58d409bdf8cebd129c2cc354cd
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/time.h>
5 #include "config.h"
6 #include "libaf/af_format.h"
7 #include "audio_out.h"
8 #include "audio_out_internal.h"
10 static ao_info_t info =
12 "Null audio output",
13 "null",
14 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
18 LIBAO_EXTERN(null)
20 struct timeval last_tv;
21 int buffer;
23 static void drain(void){
25 struct timeval now_tv;
26 int temp, temp2;
28 gettimeofday(&now_tv, 0);
29 temp = now_tv.tv_sec - last_tv.tv_sec;
30 temp *= ao_data.bps;
32 temp2 = now_tv.tv_usec - last_tv.tv_usec;
33 temp2 /= 1000;
34 temp2 *= ao_data.bps;
35 temp2 /= 1000;
36 temp += temp2;
38 buffer-=temp;
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){
46 return -1;
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;
61 buffer=0;
62 gettimeofday(&last_tv, 0);
64 return 1;
67 // close audio device
68 static void uninit(int immed){
72 // stop playing and empty buffers (for seeking/pause)
73 static void reset(void){
74 buffer=0;
77 // stop playing, keep buffers (for pause)
78 static void audio_pause(void)
80 // for now, just call reset();
81 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){
92 drain();
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){
111 drain();
112 return (float) buffer / (float) ao_data.bps;