28343
|
1 /*
|
|
2 * null audio output driver
|
|
3 *
|
|
4 * This file is part of MPlayer.
|
|
5 *
|
|
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.
|
|
10 *
|
|
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.
|
|
15 *
|
|
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.
|
|
19 */
|
|
20
|
954
|
21 #include <stdio.h>
|
|
22 #include <stdlib.h>
|
4428
|
23 #include <sys/time.h>
|
954
|
24
|
14479
|
25 #include "config.h"
|
14245
|
26 #include "libaf/af_format.h"
|
954
|
27 #include "audio_out.h"
|
|
28 #include "audio_out_internal.h"
|
|
29
|
29263
|
30 static const ao_info_t info =
|
954
|
31 {
|
|
32 "Null audio output",
|
|
33 "null",
|
15755
|
34 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
|
954
|
35 ""
|
|
36 };
|
|
37
|
|
38 LIBAO_EXTERN(null)
|
|
39
|
4424
|
40 struct timeval last_tv;
|
|
41 int buffer;
|
|
42
|
17566
|
43 static void drain(void){
|
29263
|
44
|
4424
|
45 struct timeval now_tv;
|
|
46 int temp, temp2;
|
|
47
|
|
48 gettimeofday(&now_tv, 0);
|
|
49 temp = now_tv.tv_sec - last_tv.tv_sec;
|
|
50 temp *= ao_data.bps;
|
29263
|
51
|
4424
|
52 temp2 = now_tv.tv_usec - last_tv.tv_usec;
|
|
53 temp2 /= 1000;
|
|
54 temp2 *= ao_data.bps;
|
|
55 temp2 /= 1000;
|
|
56 temp += temp2;
|
|
57
|
|
58 buffer-=temp;
|
|
59 if (buffer<0) buffer=0;
|
|
60
|
5946
|
61 if(temp>0) last_tv = now_tv;//mplayer is fast
|
4424
|
62 }
|
954
|
63
|
|
64 // to set/get/query special features/parameters
|
9633
|
65 static int control(int cmd,void *arg){
|
954
|
66 return -1;
|
|
67 }
|
|
68
|
|
69 // open & setup audio device
|
|
70 // return: 1=success 0=fail
|
|
71 static int init(int rate,int channels,int format,int flags){
|
|
72
|
25195
|
73 int samplesize = af_fmt2bits(format) / 8;
|
25194
|
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;
|
4424
|
77 ao_data.channels=channels;
|
|
78 ao_data.samplerate=rate;
|
|
79 ao_data.format=format;
|
25194
|
80 ao_data.bps=channels*rate*samplesize;
|
4424
|
81 buffer=0;
|
|
82 gettimeofday(&last_tv, 0);
|
954
|
83
|
4424
|
84 return 1;
|
954
|
85 }
|
|
86
|
|
87 // close audio device
|
12145
|
88 static void uninit(int immed){
|
954
|
89
|
|
90 }
|
|
91
|
|
92 // stop playing and empty buffers (for seeking/pause)
|
17566
|
93 static void reset(void){
|
4424
|
94 buffer=0;
|
954
|
95 }
|
|
96
|
1038
|
97 // stop playing, keep buffers (for pause)
|
17566
|
98 static void audio_pause(void)
|
1038
|
99 {
|
|
100 // for now, just call reset();
|
|
101 reset();
|
|
102 }
|
|
103
|
|
104 // resume playing, after audio_pause()
|
17566
|
105 static void audio_resume(void)
|
1038
|
106 {
|
|
107 }
|
|
108
|
954
|
109 // return: how many bytes can be played without blocking
|
17566
|
110 static int get_space(void){
|
954
|
111
|
4424
|
112 drain();
|
|
113 return ao_data.buffersize - buffer;
|
954
|
114 }
|
|
115
|
|
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){
|
|
120
|
4424
|
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;
|
954
|
126 }
|
|
127
|
3095
|
128 // return: delay in seconds between first and last sample in buffer
|
17566
|
129 static float get_delay(void){
|
954
|
130
|
4424
|
131 drain();
|
|
132 return (float) buffer / (float) ao_data.bps;
|
954
|
133 }
|