annotate libaf/af_channels.c @ 36506:0f2c90b69a12

vo_bl: Use strcspn
author reimar
date Sat, 18 Jan 2014 13:14:54 +0000
parents 2b9bc3c2933d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28229
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
1 /*
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
2 * Audio filter that adds and removes channels, according to the
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
3 * command line parameter channels. It is stupid and can only add
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
4 * silence or copy channels, not mix or filter.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
5 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
6 * This file is part of MPlayer.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
7 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
9 * it under the terms of the GNU General Public License as published by
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
11 * (at your option) any later version.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
12 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
16 * GNU General Public License for more details.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
17 *
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
18 * You should have received a copy of the GNU General Public License along
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
21 */
72d0b1444141 Replace informal license notices by standard license header
diego
parents: 24888
diff changeset
22
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
23 #include <stdio.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
24 #include <stdlib.h>
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
25 #include <string.h>
7975
6e03baea602f Adding compile problem fix from Gabucino
anders
parents: 7615
diff changeset
26 #include <inttypes.h>
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
27
36395
2b9bc3c2933d Remove some macros and switch to libavutil equivalents.
reimar
parents: 34174
diff changeset
28 #include "libavutil/common.h"
34174
a93891202051 Add missing mp_msg.h #includes, remove some unnecessary ones.
diego
parents: 29263
diff changeset
29 #include "mp_msg.h"
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
30 #include "af.h"
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
31
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
32 #define FR 0
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
33 #define TO 1
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
34
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
35 typedef struct af_channels_s{
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
36 int route[AF_NCH][2];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
37 int nr;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
38 int router;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
39 }af_channels_t;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
40
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
41 // Local function for copying data
8711
906f7a2dc085 sig 11 fix in reinit and resample + spelling error fixes
anders
parents: 8607
diff changeset
42 static void copy(void* in, void* out, int ins, int inos,int outs, int outos, int len, int bps)
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
43 {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
44 switch(bps){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
45 case 1:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
46 int8_t* tin = (int8_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
47 int8_t* tout = (int8_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
48 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
49 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
50 len = len/ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
51 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
52 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
53 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
54 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
55 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
56 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
57 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
58 case 2:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
59 int16_t* tin = (int16_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
60 int16_t* tout = (int16_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
61 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
62 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
63 len = len/(2*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
64 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
65 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
66 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
67 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
68 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
69 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
70 }
12913
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
71 case 3:{
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
72 int8_t* tin = (int8_t*)in;
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
73 int8_t* tout = (int8_t*)out;
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
74 tin += 3 * inos;
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
75 tout += 3 * outos;
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
76 len = len / ( 3 * ins);
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
77 while (len--) {
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
78 tout[0] = tin[0];
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
79 tout[1] = tin[1];
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
80 tout[2] = tin[2];
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
81 tin += 3 * ins;
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
82 tout += 3 * outs;
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
83 }
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
84 break;
e7309a3b65f6 support for 24 bit audio
reimar
parents: 12008
diff changeset
85 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
86 case 4:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
87 int32_t* tin = (int32_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
88 int32_t* tout = (int32_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
89 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
90 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
91 len = len/(4*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
92 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
93 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
94 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
95 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
96 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
97 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
98 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
99 case 8:{
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
100 int64_t* tin = (int64_t*)in;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
101 int64_t* tout = (int64_t*)out;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
102 tin += inos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
103 tout += outos;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
104 len = len/(8*ins);
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
105 while(len--){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
106 *tout=*tin;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
107 tin +=ins;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
108 tout+=outs;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
109 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
110 break;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
111 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
112 default:
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
113 mp_msg(MSGT_AFILTER, MSGL_ERR, "[channels] Unsupported number of bytes/sample: %i"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
114 " please report this error on the MPlayer mailing list. \n",bps);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
115 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
116 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
117
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
118 // Make sure the routes are sane
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
119 static int check_routes(af_channels_t* s, int nin, int nout)
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
120 {
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
121 int i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
122 if((s->nr < 1) || (s->nr > AF_NCH)){
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
123 mp_msg(MSGT_AFILTER, MSGL_ERR, "[channels] The number of routing pairs must be"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
124 " between 1 and %i. Current value is %i\n",AF_NCH,s->nr);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
125 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
126 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
127
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
128 for(i=0;i<s->nr;i++){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
129 if((s->route[i][FR] >= nin) || (s->route[i][TO] >= nout)){
29049
8c706ce21c6f Remove af_msg special-casing API in libaf.
bircoph
parents: 28229
diff changeset
130 mp_msg(MSGT_AFILTER, MSGL_ERR, "[channels] Invalid routing in pair nr. %i.\n", i);
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
131 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
132 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
133 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
134 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
135 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
136
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
137 // Initialization and runtime control
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
138 static int control(struct af_instance_s* af, int cmd, void* arg)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
139 {
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
140 af_channels_t* s = af->setup;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
141 switch(cmd){
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
142 case AF_CONTROL_REINIT:
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
143
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
144 // Set default channel assignment
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
145 if(!s->router){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
146 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
147 // Make sure this filter isn't redundant
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
148 if(af->data->nch == ((af_data_t*)arg)->nch)
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
149 return AF_DETACH;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
150
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
151 // If mono: fake stereo
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
152 if(((af_data_t*)arg)->nch == 1){
36395
2b9bc3c2933d Remove some macros and switch to libavutil equivalents.
reimar
parents: 34174
diff changeset
153 s->nr = FFMIN(af->data->nch,2);
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
154 for(i=0;i<s->nr;i++){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
155 s->route[i][FR] = 0;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
156 s->route[i][TO] = i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
157 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
158 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
159 else{
36395
2b9bc3c2933d Remove some macros and switch to libavutil equivalents.
reimar
parents: 34174
diff changeset
160 s->nr = FFMIN(af->data->nch, ((af_data_t*)arg)->nch);
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
161 for(i=0;i<s->nr;i++){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
162 s->route[i][FR] = i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
163 s->route[i][TO] = i;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
164 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
165 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
166 }
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
167
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
168 af->data->rate = ((af_data_t*)arg)->rate;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
169 af->data->format = ((af_data_t*)arg)->format;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
170 af->data->bps = ((af_data_t*)arg)->bps;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22748
diff changeset
171 af->mul = (double)af->data->nch / ((af_data_t*)arg)->nch;
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
172 return check_routes(s,((af_data_t*)arg)->nch,af->data->nch);
7998
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
173 case AF_CONTROL_COMMAND_LINE:{
d48a06d07afb Adding commandline options for filters and fixing stupid bug in cfg
anders
parents: 7975
diff changeset
174 int nch = 0;
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
175 int n = 0;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
176 // Check number of channels and number of routing pairs
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
177 sscanf(arg, "%i:%i%n", &nch, &s->nr, &n);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
178
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
179 // If router scan commandline for routing pairs
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
180 if(s->nr){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
181 char* cp = &((char*)arg)[n];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
182 int ch = 0;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
183 // Sanity check
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
184 if((s->nr < 1) || (s->nr > AF_NCH)){
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
185 mp_msg(MSGT_AFILTER, MSGL_ERR, "[channels] The number of routing pairs must be"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
186 " between 1 and %i. Current value is %i\n",AF_NCH,s->nr);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
187 }
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
188 s->router = 1;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
189 // Scan for pairs on commandline
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
190 while((*cp == ':') && (ch < s->nr)){
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
191 sscanf(cp, ":%i:%i%n" ,&s->route[ch][FR], &s->route[ch][TO], &n);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
192 mp_msg(MSGT_AFILTER, MSGL_V, "[channels] Routing from channel %i to"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
193 " channel %i\n",s->route[ch][FR],s->route[ch][TO]);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
194 cp = &cp[n];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
195 ch++;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
196 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
197 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
198
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
199 if(AF_OK != af->control(af,AF_CONTROL_CHANNELS | AF_CONTROL_SET ,&nch))
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
200 return AF_ERROR;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
201 return AF_OK;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
202 }
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
203 case AF_CONTROL_CHANNELS | AF_CONTROL_SET:
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
204 // Reinit must be called after this function has been called
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
205
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
206 // Sanity check
12008
8631b43c9d82 10l - replace 6 with AF_NCH
henry
parents: 8711
diff changeset
207 if(((int*)arg)[0] <= 0 || ((int*)arg)[0] > AF_NCH){
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
208 mp_msg(MSGT_AFILTER, MSGL_ERR, "[channels] The number of output channels must be"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
209 " between 1 and %i. Current value is %i\n",AF_NCH,((int*)arg)[0]);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
210 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
211 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
212
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
213 af->data->nch=((int*)arg)[0];
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
214 if(!s->router)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
215 mp_msg(MSGT_AFILTER, MSGL_V, "[channels] Changing number of channels"
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
216 " to %i\n",af->data->nch);
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
217 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
218 case AF_CONTROL_CHANNELS | AF_CONTROL_GET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
219 *(int*)arg = af->data->nch;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
220 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
221 case AF_CONTROL_CHANNELS_ROUTING | AF_CONTROL_SET:{
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
222 int ch = ((af_control_ext_t*)arg)->ch;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
223 int* route = ((af_control_ext_t*)arg)->arg;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
224 s->route[ch][FR] = route[FR];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
225 s->route[ch][TO] = route[TO];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
226 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
227 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
228 case AF_CONTROL_CHANNELS_ROUTING | AF_CONTROL_GET:{
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
229 int ch = ((af_control_ext_t*)arg)->ch;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
230 int* route = ((af_control_ext_t*)arg)->arg;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
231 route[FR] = s->route[ch][FR];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
232 route[TO] = s->route[ch][TO];
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
233 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
234 }
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
235 case AF_CONTROL_CHANNELS_NR | AF_CONTROL_SET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
236 s->nr = *(int*)arg;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
237 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
238 case AF_CONTROL_CHANNELS_NR | AF_CONTROL_GET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
239 *(int*)arg = s->nr;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
240 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
241 case AF_CONTROL_CHANNELS_ROUTER | AF_CONTROL_SET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
242 s->router = *(int*)arg;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
243 return AF_OK;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
244 case AF_CONTROL_CHANNELS_ROUTER | AF_CONTROL_GET:
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
245 *(int*)arg = s->router;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
246 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
247 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
248 return AF_UNKNOWN;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
249 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
250
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
251 // Deallocate memory
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
252 static void uninit(struct af_instance_s* af)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
253 {
22179
ecf562795caf Fix memory leaks.
uau
parents: 14433
diff changeset
254 free(af->setup);
ecf562795caf Fix memory leaks.
uau
parents: 14433
diff changeset
255 if (af->data)
ecf562795caf Fix memory leaks.
uau
parents: 14433
diff changeset
256 free(af->data->audio);
ecf562795caf Fix memory leaks.
uau
parents: 14433
diff changeset
257 free(af->data);
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
258 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
259
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
260 // Filter data through filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
261 static af_data_t* play(struct af_instance_s* af, af_data_t* data)
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
262 {
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
263 af_data_t* c = data; // Current working data
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
264 af_data_t* l = af->data; // Local data
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
265 af_channels_t* s = af->setup;
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
266 int i;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
267
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
268 if(AF_OK != RESIZE_LOCAL_BUFFER(af,data))
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
269 return NULL;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
270
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
271 // Reset unused channels
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22748
diff changeset
272 memset(l->audio,0,c->len / c->nch * l->nch);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
273
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
274 if(AF_OK == check_routes(s,c->nch,l->nch))
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
275 for(i=0;i<s->nr;i++)
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
276 copy(c->audio,l->audio,c->nch,s->route[i][FR],
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
277 l->nch,s->route[i][TO],c->len,c->bps);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29049
diff changeset
278
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
279 // Set output data
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
280 c->audio = l->audio;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22748
diff changeset
281 c->len = c->len / c->nch * l->nch;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
282 c->nch = l->nch;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
283
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
284 return c;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
285 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
286
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
287 // Allocate memory and set function pointers
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 22179
diff changeset
288 static int af_open(af_instance_t* af){
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
289 af->control=control;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
290 af->uninit=uninit;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
291 af->play=play;
24888
b2402b4f0afa libaf: change filter input/output ratio calculations
uau
parents: 22748
diff changeset
292 af->mul=1;
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
293 af->data=calloc(1,sizeof(af_data_t));
8607
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
294 af->setup=calloc(1,sizeof(af_channels_t));
d6f40a06867b Changes includes:
anders
parents: 8167
diff changeset
295 if((af->data == NULL) || (af->setup == NULL))
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
296 return AF_ERROR;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
297 return AF_OK;
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
298 }
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
299
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
300 // Description of this filter
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
301 af_info_t af_info_channels = {
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
302 "Insert or remove channels",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
303 "channels",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
304 "Anders",
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
305 "",
7615
c67328dd459a Adding Support for non-reentrant audio filters
anders
parents: 7590
diff changeset
306 AF_FLAGS_REENTRANT,
22746
fd6f824ef894 Rename open to af_open so as not to conflict with a previous header definition.
diego
parents: 22179
diff changeset
307 af_open
7568
d08513b9fed6 Adding new audio output filter layer libaf
anders
parents:
diff changeset
308 };