@@ -1142,19 +1142,22 @@ class InputMixer : public AudioStream {
11421142 public:
11431143 InputMixer () = default ;
11441144
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 ) {
11471147 streams.push_back (&in);
11481148 weights.push_back (weight);
11491149 total_weights += weight;
1150+ return streams.indexOf (&in);
11501151 }
11511152
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 ;
11561158 } 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 ;
11581161 }
11591162 }
11601163
@@ -1224,6 +1227,34 @@ class InputMixer : public AudioStream {
12241227 // / abort the read and provide empty data
12251228 void setRetryCount (int retry) { retry_count = retry; }
12261229
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+
12271258 protected:
12281259 Vector<Stream *> streams{0 };
12291260 Vector<int > weights{0 };
0 commit comments