@@ -1142,19 +1142,22 @@ class InputMixer : public AudioStream {
1142
1142
public:
1143
1143
InputMixer () = default ;
1144
1144
1145
- // / Adds a new input stream
1146
- void add (Stream &in, int weight = 100 ) {
1145
+ // / Adds a new input stream and returns it's actual index position
1146
+ int add (Stream &in, int weight = 100 ) {
1147
1147
streams.push_back (&in);
1148
1148
weights.push_back (weight);
1149
1149
total_weights += weight;
1150
+ return streams.indexOf (&in);
1150
1151
}
1151
1152
1152
- // / Replaces a stream at the indicated channel
1153
- void set (int channel, Stream &in) {
1154
- if (channel < size ()) {
1155
- streams[channel] = ∈
1153
+ // / Replaces a stream at the indicated index
1154
+ bool set (int index, Stream &in) {
1155
+ if (index < size ()) {
1156
+ streams[index] = ∈
1157
+ return true ;
1156
1158
} else {
1157
- LOGE (" Invalid channel %d - max is %d" , channel, size () - 1 );
1159
+ LOGE (" Invalid index %d - max is %d" , index, size () - 1 );
1160
+ return false ;
1158
1161
}
1159
1162
}
1160
1163
@@ -1224,6 +1227,34 @@ class InputMixer : public AudioStream {
1224
1227
// / abort the read and provide empty data
1225
1228
void setRetryCount (int retry) { retry_count = retry; }
1226
1229
1230
+ // / Removes a stream by index position
1231
+ bool remove (int idx) {
1232
+ if (idx < 0 || idx >= size ()) {
1233
+ return false ;
1234
+ }
1235
+ streams.erase (idx);
1236
+ return true ;
1237
+ }
1238
+
1239
+ // / Provides the actual index of the stream
1240
+ int indexOf (Stream &stream) { return streams.indexOf (&stream); }
1241
+
1242
+ // / Provides the stream pointer at the indicated index
1243
+ Stream * operator [](int idx) {
1244
+ if (idx < 0 || idx >= size ()) return nullptr ;
1245
+ return streams[idx];
1246
+ }
1247
+
1248
+ // / Provides you the index of the next empty stream. -1 when none is found.
1249
+ int nextEmptyIndex () {
1250
+ for (int i = 0 ; i < streams.size (); i++) {
1251
+ if (streams[i]->available () == 0 ) {
1252
+ return i;
1253
+ }
1254
+ }
1255
+ return -1 ;
1256
+ }
1257
+
1227
1258
protected:
1228
1259
Vector<Stream *> streams{0 };
1229
1260
Vector<int > weights{0 };
0 commit comments