Mercurial > mplayer.hg
annotate libao2/ao_null.c @ 16805:50fb26acbcba
processing audio is sometimes essential for a/v sync, so 1000l to
whoever made rawvideo muxer disable audio!!
with this patch, audio is processed but simply thrown away by the
muxer. various 'error' conditions in rawvideo muxer are removed to
make it work. feel free to re-add them if they can be done without
breaking anything, but do not use printf !!!!
btw old behavior can be obtained by manually specifying -nosound.
author | rfelker |
---|---|
date | Wed, 19 Oct 2005 05:44:27 +0000 |
parents | b1b06adc5cd3 |
children | f580a7755ac5 |
rev | line source |
---|---|
954 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
4428 | 3 #include <sys/time.h> |
954 | 4 |
14479 | 5 #include "config.h" |
14245 | 6 #include "libaf/af_format.h" |
954 | 7 #include "audio_out.h" |
8 #include "audio_out_internal.h" | |
9 | |
10 static ao_info_t info = | |
11 { | |
12 "Null audio output", | |
13 "null", | |
15755 | 14 "Tobias Diedrich <ranma+mplayer@tdiedrich.de>", |
954 | 15 "" |
16 }; | |
17 | |
18 LIBAO_EXTERN(null) | |
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 |
7472
c4434bdf6e51
tons of warning fixes, also some 10l bugfixes, including Dominik's PVA bug
arpi
parents:
5946
diff
changeset
|
23 static void drain(){ |
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 | 43 |
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 | 46 return -1; |
47 } | |
48 | |
49 // open & setup audio device | |
50 // return: 1=success 0=fail | |
51 static int init(int rate,int channels,int format,int flags){ | |
52 | |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
53 ao_data.buffersize= 65536; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
54 ao_data.outburst=1024; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
55 ao_data.channels=channels; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
56 ao_data.samplerate=rate; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
57 ao_data.format=format; |
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
58 ao_data.bps=channels*rate; |
14245 | 59 if (format != AF_FORMAT_U8 && format != AF_FORMAT_S8) |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
60 ao_data.bps*=2; |
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 | 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 | 65 } |
66 | |
67 // close audio device | |
12145 | 68 static void uninit(int immed){ |
954 | 69 |
70 } | |
71 | |
72 // stop playing and empty buffers (for seeking/pause) | |
73 static void reset(){ | |
4424
561de830fdf1
working dummy audio driver, patch by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
74 buffer=0; |
954 | 75 } |
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) |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
78 static void audio_pause() |
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() |
b36fb1ae4b53
applied solaris8/netbsd/other fixes patch by J¸«ärgen Keil <jk@tools.de>
arpi_esp
parents:
1010
diff
changeset
|
85 static void audio_resume() |
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 | 89 // return: how many bytes can be played without blocking |
90 static int get_space(){ | |
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 | 94 } |
95 | |
96 // plays 'len' bytes of 'data' | |
97 // it should round it down to outburst*n | |
98 // return: number of bytes played | |
99 static int play(void* data,int len,int flags){ | |
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 | 106 } |
107 | |
3095 | 108 // return: delay in seconds between first and last sample in buffer |
109 static float get_delay(){ | |
954 | 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 | 113 } |