Factorize MPlayer/MEncoder version string handling.
[mplayer/glamo.git] / libao2 / ao_null.c
blob17b3bc7e4e37f87bc30bba49dc53acef3d530be6
1 /*
2 * null audio output driver
4 * This file is part of MPlayer.
6 * MPlayer is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * MPlayer is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/time.h>
25 #include "config.h"
26 #include "libaf/af_format.h"
27 #include "audio_out.h"
28 #include "audio_out_internal.h"
30 static const ao_info_t info =
32 "Null audio output",
33 "null",
34 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
38 LIBAO_EXTERN(null)
40 struct timeval last_tv;
41 int buffer;
43 static void drain(void){
45 struct timeval now_tv;
46 int temp, temp2;
48 gettimeofday(&now_tv, 0);
49 temp = now_tv.tv_sec - last_tv.tv_sec;
50 temp *= ao_data.bps;
52 temp2 = now_tv.tv_usec - last_tv.tv_usec;
53 temp2 /= 1000;
54 temp2 *= ao_data.bps;
55 temp2 /= 1000;
56 temp += temp2;
58 buffer-=temp;
59 if (buffer<0) buffer=0;
61 if(temp>0) last_tv = now_tv;//mplayer is fast
64 // to set/get/query special features/parameters
65 static int control(int cmd,void *arg){
66 return -1;
69 // open & setup audio device
70 // return: 1=success 0=fail
71 static int init(int rate,int channels,int format,int flags){
73 int samplesize = af_fmt2bits(format) / 8;
74 ao_data.outburst = 256 * channels * samplesize;
75 // A "buffer" for about 0.2 seconds of audio
76 ao_data.buffersize = (int)(rate * 0.2 / 256 + 1) * ao_data.outburst;
77 ao_data.channels=channels;
78 ao_data.samplerate=rate;
79 ao_data.format=format;
80 ao_data.bps=channels*rate*samplesize;
81 buffer=0;
82 gettimeofday(&last_tv, 0);
84 return 1;
87 // close audio device
88 static void uninit(int immed){
92 // stop playing and empty buffers (for seeking/pause)
93 static void reset(void){
94 buffer=0;
97 // stop playing, keep buffers (for pause)
98 static void audio_pause(void)
100 // for now, just call reset();
101 reset();
104 // resume playing, after audio_pause()
105 static void audio_resume(void)
109 // return: how many bytes can be played without blocking
110 static int get_space(void){
112 drain();
113 return ao_data.buffersize - buffer;
116 // plays 'len' bytes of 'data'
117 // it should round it down to outburst*n
118 // return: number of bytes played
119 static int play(void* data,int len,int flags){
121 int maxbursts = (ao_data.buffersize - buffer) / ao_data.outburst;
122 int playbursts = len / ao_data.outburst;
123 int bursts = playbursts > maxbursts ? maxbursts : playbursts;
124 buffer += bursts * ao_data.outburst;
125 return bursts * ao_data.outburst;
128 // return: delay in seconds between first and last sample in buffer
129 static float get_delay(void){
131 drain();
132 return (float) buffer / (float) ao_data.bps;