Mercurial > mplayer.hg
annotate libao2/ao_pcm.c @ 30080:3cfe91f729d7
Subtitle are now also available without video, so remove that
check from the subtitle property handling.
author | reimar |
---|---|
date | Sun, 27 Dec 2009 14:07:29 +0000 |
parents | 4eae69f3f4f4 |
children | 02b9c1a452e1 |
rev | line source |
---|---|
28343 | 1 /* |
2 * PCM 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 | |
6237 | 21 #include "config.h" |
22 | |
1107 | 23 #include <stdio.h> |
24 #include <stdlib.h> | |
6237 | 25 #include <string.h> |
1107 | 26 |
21372 | 27 #include "libavutil/common.h" |
21507
fa99b3d31d13
Hack around libavutil/bswap.h compilation problems due to always_inline undefined.
reimar
parents:
21372
diff
changeset
|
28 #include "mpbswap.h" |
14298
3c818342a02b
Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents:
14264
diff
changeset
|
29 #include "subopt-helper.h" |
14245 | 30 #include "libaf/af_format.h" |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
25097
diff
changeset
|
31 #include "libaf/reorder_ch.h" |
1107 | 32 #include "audio_out.h" |
33 #include "audio_out_internal.h" | |
14123 | 34 #include "mp_msg.h" |
35 #include "help_mp.h" | |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
36 |
29269
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
37 #ifdef __MINGW32__ |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
38 // for GetFileType to detect pipes |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
39 #include <windows.h> |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
40 #endif |
1107 | 41 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
42 static const ao_info_t info = |
1107 | 43 { |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
44 "RAW PCM/WAVE file writer audio output", |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
45 "pcm", |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
46 "Atmosfear", |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
47 "" |
1107 | 48 }; |
49 | |
50 LIBAO_EXTERN(pcm) | |
51 | |
4914
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
52 extern int vo_pts; |
de4074ab4e5f
good-looking fix by Tobias Diedrich <td@informatik.uni-hannover.de>
arpi
parents:
3095
diff
changeset
|
53 |
14298
3c818342a02b
Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents:
14264
diff
changeset
|
54 static char *ao_outputfilename = NULL; |
3c818342a02b
Add -ao pcm suboptions and remove -aofile and -waveheader options.
reimar
parents:
14264
diff
changeset
|
55 static int ao_pcm_waveheader = 1; |
18092
96fdfbad5b1a
-ao pcm:fast suboption for faster-than-realtime dumping
reimar
parents:
17566
diff
changeset
|
56 static int fast = 0; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
57 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
58 #define WAV_ID_RIFF 0x46464952 /* "RIFF" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
59 #define WAV_ID_WAVE 0x45564157 /* "WAVE" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
60 #define WAV_ID_FMT 0x20746d66 /* "fmt " */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
61 #define WAV_ID_DATA 0x61746164 /* "data" */ |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
62 #define WAV_ID_PCM 0x0001 |
26604
9946e4a6e457
Support 32 bit float and integer formats in ao_pcm.c
reimar
parents:
25315
diff
changeset
|
63 #define WAV_ID_FLOAT_PCM 0x0003 |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
64 |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
65 struct WaveHeader |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
66 { |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
67 uint32_t riff; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
68 uint32_t file_length; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
69 uint32_t wave; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
70 uint32_t fmt; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
71 uint32_t fmt_length; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
72 uint16_t fmt_tag; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
73 uint16_t channels; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
74 uint32_t sample_rate; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
75 uint32_t bytes_per_second; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
76 uint16_t block_align; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
77 uint16_t bits; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
78 uint32_t data; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
79 uint32_t data_length; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
80 }; |
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
81 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
82 /* init with default values */ |
21250
7b1ab00ef2eb
le2me_32 is no longer a macro on PPC, and in general does not have to
reimar
parents:
18500
diff
changeset
|
83 static struct WaveHeader wavhdr; |
29002
b7367b035fdd
Add forgotten "static" to new data_length variable in ao_pcm
reimar
parents:
29001
diff
changeset
|
84 static uint64_t data_length; |
1112
b1cf1087ec33
Added support for writing wave files and specifying filename to write to.
atmosfear
parents:
1107
diff
changeset
|
85 |
1107 | 86 static FILE *fp = NULL; |
87 | |
88 // to set/get/query special features/parameters | |
9633
12b1790038b0
64bit libao2 fix by Jens Axboe <mplayer-dev@kernel.dk>
alex
parents:
9277
diff
changeset
|
89 static int control(int cmd,void *arg){ |
1107 | 90 return -1; |
91 } | |
92 | |
93 // open & setup audio device | |
94 // return: 1=success 0=fail | |
95 static int init(int rate,int channels,int format,int flags){ | |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
96 int bits; |
29586
2eff450157cd
The suboption parser now takes a const options list, so mark them all const.
reimar
parents:
29401
diff
changeset
|
97 const opt_t subopts[] = { |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
98 {"waveheader", OPT_ARG_BOOL, &ao_pcm_waveheader, NULL}, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
99 {"file", OPT_ARG_MSTRZ, &ao_outputfilename, NULL}, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
100 {"fast", OPT_ARG_BOOL, &fast, NULL}, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
101 {NULL} |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
102 }; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
103 // set defaults |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
104 ao_pcm_waveheader = 1; |
18488
b23c0e341e3e
Move setting the output filename after the suboption parsing, otherwise it
diego
parents:
18092
diff
changeset
|
105 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
106 if (subopt_parse(ao_subdevice, subopts) != 0) { |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
107 return 0; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
108 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
109 if (!ao_outputfilename){ |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
110 ao_outputfilename = |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
111 strdup(ao_pcm_waveheader?"audiodump.wav":"audiodump.pcm"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
112 } |
18488
b23c0e341e3e
Move setting the output filename after the suboption parsing, otherwise it
diego
parents:
18092
diff
changeset
|
113 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
114 bits=8; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
115 switch(format){ |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
116 case AF_FORMAT_S32_BE: |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
117 format=AF_FORMAT_S32_LE; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
118 case AF_FORMAT_S32_LE: |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
119 bits=32; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
120 break; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
121 case AF_FORMAT_FLOAT_BE: |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
122 format=AF_FORMAT_FLOAT_LE; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
123 case AF_FORMAT_FLOAT_LE: |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
124 bits=32; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
125 break; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
126 case AF_FORMAT_S8: |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
127 format=AF_FORMAT_U8; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
128 case AF_FORMAT_U8: |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
129 break; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
130 case AF_FORMAT_AC3: |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
131 bits=16; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
132 break; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
133 default: |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
134 format=AF_FORMAT_S16_LE; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
135 bits=16; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
136 break; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
137 } |
7658 | 138 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
139 ao_data.outburst = 65536; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
140 ao_data.buffersize= 2*65536; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
141 ao_data.channels=channels; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
142 ao_data.samplerate=rate; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
143 ao_data.format=format; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
144 ao_data.bps=channels*rate*(bits/8); |
7658 | 145 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
146 wavhdr.riff = le2me_32(WAV_ID_RIFF); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
147 wavhdr.wave = le2me_32(WAV_ID_WAVE); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
148 wavhdr.fmt = le2me_32(WAV_ID_FMT); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
149 wavhdr.fmt_length = le2me_32(16); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
150 wavhdr.fmt_tag = le2me_16(format == AF_FORMAT_FLOAT_LE ? WAV_ID_FLOAT_PCM : WAV_ID_PCM); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
151 wavhdr.channels = le2me_16(ao_data.channels); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
152 wavhdr.sample_rate = le2me_32(ao_data.samplerate); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
153 wavhdr.bytes_per_second = le2me_32(ao_data.bps); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
154 wavhdr.bits = le2me_16(bits); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
155 wavhdr.block_align = le2me_16(ao_data.channels * (bits / 8)); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
156 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
157 wavhdr.data = le2me_32(WAV_ID_DATA); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
158 wavhdr.data_length=le2me_32(0x7ffff000); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
159 wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr) - 8; |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
160 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
161 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_FileInfo, ao_outputfilename, |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
162 (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate, |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
163 (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format)); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
164 mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_PCM_HintInfo); |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
165 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
166 fp = fopen(ao_outputfilename, "wb"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
167 if(fp) { |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
168 if(ao_pcm_waveheader){ /* Reserve space for wave header */ |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
169 fwrite(&wavhdr,sizeof(wavhdr),1,fp); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
170 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
171 return 1; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
172 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
173 mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_PCM_CantOpenOutputFile, |
13383
c1955840883d
mp_msg transition of unmaintained audio output drivers.
ivo
parents:
12145
diff
changeset
|
174 ao_outputfilename); |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
175 return 0; |
1107 | 176 } |
177 | |
178 // close audio device | |
12145 | 179 static void uninit(int immed){ |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
180 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
181 if(ao_pcm_waveheader){ /* Rewrite wave header */ |
29269
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
182 int broken_seek = 0; |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
183 #ifdef __MINGW32__ |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
184 // Windows, in its usual idiocy "emulates" seeks on pipes so it always looks |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
185 // like they work. So we have to detect them brute-force. |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
186 broken_seek = GetFileType((HANDLE)_get_osfhandle(_fileno(fp))) != FILE_TYPE_DISK; |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
187 #endif |
4d9de809b174
Add a hack to detect when we are writing into a Windows pipe since the fseek
reimar
parents:
29263
diff
changeset
|
188 if (broken_seek || fseek(fp, 0, SEEK_SET) != 0) |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
189 mp_msg(MSGT_AO, MSGL_ERR, "Could not seek to start, WAV size headers not updated!\n"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
190 else if (data_length > 0x7ffff000) |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
191 mp_msg(MSGT_AO, MSGL_ERR, "File larger than allowed for WAV files, may play truncated!\n"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
192 else { |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
193 wavhdr.file_length = data_length + sizeof(wavhdr) - 8; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
194 wavhdr.file_length = le2me_32(wavhdr.file_length); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
195 wavhdr.data_length = le2me_32(data_length); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
196 fwrite(&wavhdr,sizeof(wavhdr),1,fp); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
197 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
198 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
199 fclose(fp); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
200 if (ao_outputfilename) |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
201 free(ao_outputfilename); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
202 ao_outputfilename = NULL; |
1107 | 203 } |
204 | |
205 // stop playing and empty buffers (for seeking/pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
206 static void reset(void){ |
1107 | 207 |
208 } | |
209 | |
210 // stop playing, keep buffers (for pause) | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
211 static void audio_pause(void) |
1107 | 212 { |
213 // for now, just call reset(); | |
214 reset(); | |
215 } | |
216 | |
217 // resume playing, after audio_pause() | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
218 static void audio_resume(void) |
1107 | 219 { |
220 } | |
221 | |
222 // return: how many bytes can be played without blocking | |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
223 static int get_space(void){ |
1107 | 224 |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
225 if(vo_pts) |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
226 return ao_data.pts < vo_pts + fast * 30000 ? ao_data.outburst : 0; |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
227 return ao_data.outburst; |
1107 | 228 } |
229 | |
230 // plays 'len' bytes of 'data' | |
231 // it should round it down to outburst*n | |
232 // return: number of bytes played | |
233 static int play(void* data,int len,int flags){ | |
234 | |
7658 | 235 // let libaf to do the conversion... |
236 #if 0 | |
29401
f01023c524c3
Replace WORDS_BIGENDIAN by HAVE_BIGENDIAN in all internal code.
diego
parents:
29269
diff
changeset
|
237 //#if HAVE_BIGENDIAN |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
238 if (ao_data.format == AFMT_S16_LE) { |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
239 unsigned short *buffer = (unsigned short *) data; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
240 register int i; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
241 for(i = 0; i < len/2; ++i) { |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
242 buffer[i] = le2me_16(buffer[i]); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
243 } |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
244 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
245 #endif |
7658 | 246 |
29826 | 247 if (ao_data.channels == 5 || ao_data.channels == 6 || ao_data.channels == 8) { |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
248 int frame_size = le2me_16(wavhdr.bits) / 8; |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
249 len -= len % (frame_size * ao_data.channels); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
250 reorder_channel_nch(data, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
251 AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
252 ao_data.channels, |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
253 len / frame_size, frame_size); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
254 } |
25315
dfa8a510c81c
Fix all current known multi-channel wrong order problems by adding
ulion
parents:
25097
diff
changeset
|
255 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
256 //printf("PCM: Writing chunk!\n"); |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
257 fwrite(data,len,1,fp); |
5837
7e082f42497a
- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.
atmos4
parents:
4914
diff
changeset
|
258 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
259 if(ao_pcm_waveheader) |
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
260 data_length += len; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
29002
diff
changeset
|
261 |
29001
1bb13b69cc9e
Whitespace-only cosmetics: use consistent indentation in ao_pcm.c
reimar
parents:
29000
diff
changeset
|
262 return len; |
1107 | 263 } |
264 | |
3095 | 265 // return: delay in seconds between first and last sample in buffer |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16243
diff
changeset
|
266 static float get_delay(void){ |
1107 | 267 |
3095 | 268 return 0.0; |
1107 | 269 } |
270 | |
271 | |
272 | |
273 | |
274 | |
275 |