1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
|
#include "mpg123.h"
void audio_info_struct_init(struct audio_info_struct *ai)
{
#ifdef AUDIO_USES_FD
ai->fn = -1;
#endif
#ifdef SGI
#if 0
ALconfig config;
ALport port;
#endif
#endif
ai->rate = -1;
ai->gain = -1;
ai->output = -1;
#ifdef ALSA
ai->handle = NULL;
ai->alsa_format.format = -1;
ai->alsa_format.rate = -1;
ai->alsa_format.channels = -1;
#endif
ai->device = NULL;
ai->channels = -1;
ai->format = -1;
}
#define NUM_CHANNELS 2
#define NUM_ENCODINGS 6
#define NUM_RATES 10
struct audio_name audio_val2name[NUM_ENCODINGS+1] = {
{ AUDIO_FORMAT_SIGNED_16 , "signed 16 bit" , "s16 " } ,
{ AUDIO_FORMAT_UNSIGNED_16, "unsigned 16 bit" , "u16 " } ,
{ AUDIO_FORMAT_UNSIGNED_8 , "unsigned 8 bit" , "u8 " } ,
{ AUDIO_FORMAT_SIGNED_8 , "signed 8 bit" , "s8 " } ,
{ AUDIO_FORMAT_ULAW_8 , "mu-law (8 bit)" , "ulaw " } ,
{ AUDIO_FORMAT_ALAW_8 , "a-law (8 bit)" , "alaw " } ,
{ -1 , NULL }
};
#if 0
static char *channel_name[NUM_CHANNELS] =
{ "mono" , "stereo" };
#endif
static int channels[NUM_CHANNELS] = { 1 , 2 };
static int rates[NUM_RATES] = {
8000, 11025, 12000,
16000, 22050, 24000,
32000, 44100, 48000,
8000 /* 8000 = dummy for user forced */
};
static int encodings[NUM_ENCODINGS] = {
AUDIO_FORMAT_SIGNED_16,
AUDIO_FORMAT_UNSIGNED_16,
AUDIO_FORMAT_UNSIGNED_8,
AUDIO_FORMAT_SIGNED_8,
AUDIO_FORMAT_ULAW_8,
AUDIO_FORMAT_ALAW_8
};
static char capabilities[NUM_CHANNELS][NUM_ENCODINGS][NUM_RATES];
void audio_capabilities(struct audio_info_struct *ai)
{
int fmts;
int i,j,k,k1=NUM_RATES-1;
struct audio_info_struct ai1 = *ai;
if (param.outmode != DECODE_AUDIO) {
memset(capabilities,1,sizeof(capabilities));
return;
}
memset(capabilities,0,sizeof(capabilities));
if(param.force_rate) {
rates[NUM_RATES-1] = param.force_rate;
k1 = NUM_RATES;
}
#ifndef NO_DECODE_AUDIO
if(audio_open(&ai1) < 0) {
perror("audio");
exit(1);
}
#endif
for(i=0;i<NUM_CHANNELS;i++) {
for(j=0;j<NUM_RATES;j++) {
ai1.channels = channels[i];
ai1.rate = rates[j];
fmts = audio_get_formats(&ai1);
if(fmts < 0)
continue;
for(k=0;k<NUM_ENCODINGS;k++) {
if((fmts & encodings[k]) == encodings[k])
capabilities[i][k][j] = 1;
}
}
}
#ifndef NO_DECODE_AUDIO
audio_close(&ai1);
#endif
if(param.verbose > 1) {
fprintf(stderr,"\nAudio capabilities:\n |");
for(j=0;j<NUM_ENCODINGS;j++) {
fprintf(stderr," %5s |",audio_val2name[j].sname);
}
fprintf(stderr,"\n --------------------------------------------------------\n");
for(k=0;k<k1;k++) {
fprintf(stderr," %5d |",rates[k]);
for(j=0;j<NUM_ENCODINGS;j++) {
if(capabilities[0][j][k]) {
if(capabilities[1][j][k])
fprintf(stderr," M/S |");
else
fprintf(stderr," M |");
}
else if(capabilities[1][j][k])
fprintf(stderr," S |");
else
fprintf(stderr," |");
}
fprintf(stderr,"\n");
}
fprintf(stderr,"\n");
}
}
static int rate2num(int r)
{
int i;
for(i=0;i<NUM_RATES;i++)
if(rates[i] == r)
return i;
return -1;
}
static int audio_fit_cap_helper(struct audio_info_struct *ai,int rn,int f0,int f2,int c)
{
int i;
if(rn >= 0) {
for(i=f0;i<f2;i++) {
if(capabilities[c][i][rn]) {
ai->rate = rates[rn];
ai->format = encodings[i];
ai->channels = channels[c];
return 1;
}
}
}
return 0;
}
/*
* c=num of channels of stream
* r=rate of stream
*/
void audio_fit_capabilities(struct audio_info_struct *ai,int c,int r)
{
int rn;
int f0=0;
int save_channels = c;
int save_rate = r;
if(param.force_8bit) {
f0 = 2;
}
c--; /* stereo=1 ,mono=0 */
if(param.force_mono >= 0)
c = 0;
if(param.force_stereo)
c = 1;
if(param.force_rate) {
rn = rate2num(param.force_rate);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
if(c == 1 && !param.force_stereo)
c = 0;
else if(c == 0 && !param.force_mono)
c = 1;
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
}
else {
rn = rate2num(r>>0);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r<<1);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r<<2);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r>>1);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r>>2);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r>>0);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
rn = rate2num(r<<1);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
rn = rate2num(r<<2);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
rn = rate2num(r>>1);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
rn = rate2num(r>>2);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
if(c == 1 && !param.force_stereo)
c = 0;
else if(c == 0 && !param.force_mono)
c = 1;
rn = rate2num(r>>0);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r<<1);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r<<2);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r>>1);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r>>2);
if(audio_fit_cap_helper(ai,rn,f0,2,c))
return;
rn = rate2num(r>>0);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
rn = rate2num(r<<1);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
rn = rate2num(r<<2);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
rn = rate2num(r>>1);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
rn = rate2num(r>>2);
if(audio_fit_cap_helper(ai,rn,2,NUM_ENCODINGS,c))
return;
}
fprintf(stderr,"\nAudiodevice: No supported audio rate found for %d Hz and %d channels !\n",save_rate,save_channels);
fprintf(stderr,"Use '-vv' to list all possible audio rates and\n");
fprintf(stderr,"choose a supported rate with the '-r <rate>' option.\n");
exit(1);
}
char *audio_encoding_name(int format)
{
int i;
for(i=0;i<NUM_ENCODINGS;i++) {
if(audio_val2name[i].val == format)
return audio_val2name[i].name;
}
return "Unknown";
}
#if !defined(SOLARIS) && !defined(__NetBSD__) && !defined(AIX_UMS) || defined(NAS)
void audio_queueflush(struct audio_info_struct *ai)
{
}
#endif
|