cleanup: Silence compilation warnings on MinGW-w64
[mplayer.git] / libao2 / ao_null.c
blobfddc2f6ad335061d3a9e3e863a030281898d4f66
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>
24 #include "talloc.h"
26 #include "config.h"
27 #include "osdep/timer.h"
28 #include "libaf/af_format.h"
29 #include "audio_out.h"
31 struct priv {
32 unsigned last_time;
33 float buffered_bytes;
36 static void drain(struct ao *ao)
38 struct priv *priv = ao->priv;
40 unsigned now = GetTimer();
41 priv->buffered_bytes -= (now - priv->last_time) / 1e6 * ao->bps;
42 if (priv->buffered_bytes < 0)
43 priv->buffered_bytes = 0;
44 priv->last_time = now;
47 static int init(struct ao *ao, char *params)
49 struct priv *priv = talloc_zero(ao, struct priv);
50 ao->priv = priv;
51 int samplesize = af_fmt2bits(ao->format) / 8;
52 ao->outburst = 256 * ao->channels * samplesize;
53 // A "buffer" for about 0.2 seconds of audio
54 ao->buffersize = (int)(ao->samplerate * 0.2 / 256 + 1) * ao->outburst;
55 ao->bps = ao->channels * ao->samplerate * samplesize;
56 priv->last_time = GetTimer();
58 return 0;
61 // close audio device
62 static void uninit(struct ao *ao, bool cut_audio)
66 // stop playing and empty buffers (for seeking/pause)
67 static void reset(struct ao *ao)
69 struct priv *priv = ao->priv;
70 priv->buffered_bytes = 0;
73 // stop playing, keep buffers (for pause)
74 static void pause(struct ao *ao)
76 // for now, just call reset();
77 reset(ao);
80 // resume playing, after audio_pause()
81 static void resume(struct ao *ao)
85 static int get_space(struct ao *ao)
87 struct priv *priv = ao->priv;
89 drain(ao);
90 return ao->buffersize - priv->buffered_bytes;
93 static int play(struct ao *ao, void *data, int len, int flags)
95 struct priv *priv = ao->priv;
97 int maxbursts = (ao->buffersize - priv->buffered_bytes) / ao->outburst;
98 int playbursts = len / ao->outburst;
99 int bursts = playbursts > maxbursts ? maxbursts : playbursts;
100 priv->buffered_bytes += bursts * ao->outburst;
101 return bursts * ao->outburst;
104 static float get_delay(struct ao *ao)
106 struct priv *priv = ao->priv;
108 drain(ao);
109 return priv->buffered_bytes / ao->bps;
112 const struct ao_driver audio_out_null = {
113 .is_new = true,
114 .info = &(const struct ao_info) {
115 "Null audio output",
116 "null",
117 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
120 .init = init,
121 .uninit = uninit,
122 .reset = reset,
123 .get_space = get_space,
124 .play = play,
125 .get_delay = get_delay,
126 .pause = pause,
127 .resume = resume,