annotate libao2/ao_null.c @ 27754:08d18fe9da52

Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg. Neither variant is valid C99 syntax, but __asm__ is the most portable variant.
author diego
date Thu, 16 Oct 2008 18:59:27 +0000
parents 1aec672af2d2
children e45b08f2f5d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
1 #include <stdio.h>
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
2 #include <stdlib.h>
4428
3e1378354c2e Compilation fixing
nick
parents: 4424
diff changeset
3 #include <sys/time.h>
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
4
14479
cae0dbeb44bb af_format.h needs config.h to be included first.
reimar
parents: 14245
diff changeset
5 #include "config.h"
14245
815f03b7cee5 removing AFMT_ dependancy
alex
parents: 13383
diff changeset
6 #include "libaf/af_format.h"
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
7 #include "audio_out.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
8 #include "audio_out_internal.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
9
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
10 static ao_info_t info =
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
11 {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
12 "Null audio output",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
13 "null",
15755
b1b06adc5cd3 Fix email address
ranma
parents: 14479
diff changeset
14 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>",
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
15 ""
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
16 };
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
17
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
18 LIBAO_EXTERN(null)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
19
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
20 struct timeval last_tv;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
21 int buffer;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
22
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 15755
diff changeset
23 static void drain(void){
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
24
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
25 struct timeval now_tv;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
26 int temp, temp2;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
27
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
28 gettimeofday(&now_tv, 0);
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
29 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
30 temp *= ao_data.bps;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
31
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
32 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
33 temp2 /= 1000;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
34 temp2 *= ao_data.bps;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
35 temp2 /= 1000;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
36 temp += temp2;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
37
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
38 buffer-=temp;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
39 if (buffer<0) buffer=0;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
40
5946
9243f7464324 timer didn't update if mplayer is too fast (no video)
iive
parents: 4428
diff changeset
41 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
42 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
43
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
44 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 7472
diff changeset
45 static int control(int cmd,void *arg){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
46 return -1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
47 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
48
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
49 // open & setup audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
50 // return: 1=success 0=fail
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
51 static int init(int rate,int channels,int format,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
52
25195
1aec672af2d2 Fix ao_null with float samples
uau
parents: 25194
diff changeset
53 int samplesize = af_fmt2bits(format) / 8;
25194
e816d546c4fe ao_null: Make duration of "buffered" audio constant
uau
parents: 25189
diff changeset
54 ao_data.outburst = 256 * channels * samplesize;
e816d546c4fe ao_null: Make duration of "buffered" audio constant
uau
parents: 25189
diff changeset
55 // A "buffer" for about 0.2 seconds of audio
e816d546c4fe ao_null: Make duration of "buffered" audio constant
uau
parents: 25189
diff changeset
56 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
57 ao_data.channels=channels;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
58 ao_data.samplerate=rate;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
59 ao_data.format=format;
25194
e816d546c4fe ao_null: Make duration of "buffered" audio constant
uau
parents: 25189
diff changeset
60 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
61 buffer=0;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
62 gettimeofday(&last_tv, 0);
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
63
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
64 return 1;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
65 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
66
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
67 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 9633
diff changeset
68 static void uninit(int immed){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
69
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
70 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
71
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
72 // stop playing and empty buffers (for seeking/pause)
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 15755
diff changeset
73 static void reset(void){
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
74 buffer=0;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
75 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
76
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
77 // stop playing, keep buffers (for pause)
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 15755
diff changeset
78 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
79 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
80 // 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
81 reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
82 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
83
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
84 // resume playing, after audio_pause()
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 15755
diff changeset
85 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
86 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
87 }
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
88
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
89 // return: how many bytes can be played without blocking
17566
f580a7755ac5 Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents: 15755
diff changeset
90 static int get_space(void){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
91
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
92 drain();
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
93 return ao_data.buffersize - buffer;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
94 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
95
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
96 // plays 'len' bytes of 'data'
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
97 // it should round it down to outburst*n
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
98 // return: number of bytes played
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
99 static int play(void* data,int len,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
100
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
101 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
102 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
103 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
104 buffer += bursts * ao_data.outburst;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
105 return bursts * ao_data.outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
106 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
107
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1763
diff changeset
108 // 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
109 static float get_delay(void){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
110
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
111 drain();
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
112 return (float) buffer / (float) ao_data.bps;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
113 }