annotate libao2/ao_null.c @ 13556:1b2b37c0bd4d

-alang needs a language code, not a country code.
author diego
date Tue, 05 Oct 2004 10:13:08 +0000
parents c1955840883d
children 815f03b7cee5
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
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
5 #include "afmt.h"
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
6 #include "audio_out.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
7 #include "audio_out_internal.h"
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
8
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
9 static ao_info_t info =
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
10 {
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
11 "Null audio output",
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
12 "null",
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
13 "Tobias Diedrich",
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
14 ""
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 LIBAO_EXTERN(null)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
18
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
19 struct timeval last_tv;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
20 int buffer;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
21
7472
c4434bdf6e51 tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents: 5946
diff changeset
22 static void drain(){
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
23
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
24 struct timeval now_tv;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
25 int temp, temp2;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
26
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
27 gettimeofday(&now_tv, 0);
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
28 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
29 temp *= ao_data.bps;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
30
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
31 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
32 temp2 /= 1000;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
33 temp2 *= ao_data.bps;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
34 temp2 /= 1000;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
35 temp += temp2;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
36
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
37 buffer-=temp;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
38 if (buffer<0) buffer=0;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
39
5946
9243f7464324 timer didn't update if mplayer is too fast (no video)
iive
parents: 4428
diff changeset
40 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
41 }
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
42
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
43 // to set/get/query special features/parameters
9633
12b1790038b0 64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents: 7472
diff changeset
44 static int control(int cmd,void *arg){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
45 return -1;
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
46 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
47
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
48 // open & setup audio device
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
49 // return: 1=success 0=fail
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
50 static int init(int rate,int channels,int format,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
51
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
52 ao_data.buffersize= 65536;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
53 ao_data.outburst=1024;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
54 ao_data.channels=channels;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
55 ao_data.samplerate=rate;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
56 ao_data.format=format;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
57 ao_data.bps=channels*rate;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
58 if (format != AFMT_U8 && format != AFMT_S8)
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
59 ao_data.bps*=2;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
60 buffer=0;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
61 gettimeofday(&last_tv, 0);
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
62
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
63 return 1;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
64 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
65
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
66 // close audio device
12145
99798c3cdb93 uninit immed flag
alex
parents: 9633
diff changeset
67 static void uninit(int immed){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
68
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 // stop playing and empty buffers (for seeking/pause)
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
72 static void reset(){
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
73 buffer=0;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
74 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
75
1038
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
76 // stop playing, keep buffers (for pause)
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
77 static void audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
78 {
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
79 // 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
80 reset();
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
81 }
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 // resume playing, after audio_pause()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
84 static void audio_resume()
b36fb1ae4b53 applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents: 1010
diff changeset
85 {
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
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
88 // return: how many bytes can be played without blocking
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
89 static int get_space(){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
90
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
91 drain();
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
92 return ao_data.buffersize - buffer;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
93 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
94
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
95 // plays 'len' bytes of 'data'
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
96 // it should round it down to outburst*n
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
97 // return: number of bytes played
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
98 static int play(void* data,int len,int flags){
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
99
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
100 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
101 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
102 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
103 buffer += bursts * ao_data.outburst;
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
104 return bursts * ao_data.outburst;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
105 }
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
106
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1763
diff changeset
107 // return: delay in seconds between first and last sample in buffer
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 1763
diff changeset
108 static float get_delay(){
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
109
4424
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
110 drain();
561de830fdf1 working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents: 3095
diff changeset
111 return (float) buffer / (float) ao_data.bps;
954
db20b90dd34d audio out drivers
arpi_esp
parents:
diff changeset
112 }