Mercurial > mplayer.hg
annotate libao2/ao_null.c @ 36955:d1ece1312aaa
Synced with help_mp-en.h rev. 36987
author | jrash |
---|---|
date | Sun, 23 Mar 2014 16:44:42 +0000 |
parents | ba55ceb04748 |
children |
rev | line source |
---|---|
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
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
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 | |
34265
ba55ceb04748
ao_null: mark global variables only used within the file as static
diego
parents:
29263
diff
changeset
|
40 static struct timeval last_tv; |
ba55ceb04748
ao_null: mark global variables only used within the file as static
diego
parents:
29263
diff
changeset
|
41 static int buffer; |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
42 |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15755
diff
changeset
|
43 static void drain(void){ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
44 |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
45 struct timeval now_tv; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
46 int temp, temp2; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
47 |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
48 gettimeofday(&now_tv, 0); |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
49 temp = now_tv.tv_sec - last_tv.tv_sec; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
50 temp *= ao_data.bps; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28823
diff
changeset
|
51 |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
52 temp2 = now_tv.tv_usec - last_tv.tv_usec; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
53 temp2 /= 1000; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
54 temp2 *= ao_data.bps; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
55 temp2 /= 1000; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
56 temp += temp2; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
57 |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
58 buffer-=temp; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
59 if (buffer<0) buffer=0; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
60 |
5946
9243f7464324
timer didn't update if mplayer is too fast (no video)
iive
parents:
4428
diff
changeset
|
61 if(temp>0) last_tv = now_tv;//mplayer is fast |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
62 } |
954 | 63 |
64 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
7472
diff
changeset
|
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
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
77 ao_data.channels=channels; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
78 ao_data.samplerate=rate; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
79 ao_data.format=format; |
25194 | 80 ao_data.bps=channels*rate*samplesize; |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
81 buffer=0; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
82 gettimeofday(&last_tv, 0); |
954 | 83 |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
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
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15755
diff
changeset
|
93 static void reset(void){ |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
94 buffer=0; |
954 | 95 } |
96 | |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
97 // stop playing, keep buffers (for pause) |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15755
diff
changeset
|
98 static void audio_pause(void) |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
99 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
100 // for now, just call reset(); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
101 reset(); |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
102 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
103 |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
104 // resume playing, after audio_pause() |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15755
diff
changeset
|
105 static void audio_resume(void) |
1038
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
106 { |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
107 } |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
108 |
954 | 109 // return: how many bytes can be played without blocking |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15755
diff
changeset
|
110 static int get_space(void){ |
954 | 111 |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
112 drain(); |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
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
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
121 int maxbursts = (ao_data.buffersize - buffer) / ao_data.outburst; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
122 int playbursts = len / ao_data.outburst; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
123 int bursts = playbursts > maxbursts ? maxbursts : playbursts; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
124 buffer += bursts * ao_data.outburst; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
125 return bursts * ao_data.outburst; |
954 | 126 } |
127 | |
3095 | 128 // return: delay in seconds between first and last sample in buffer |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
15755
diff
changeset
|
129 static float get_delay(void){ |
954 | 130 |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
131 drain(); |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
132 return (float) buffer / (float) ao_data.bps; |
954 | 133 } |