Skip to content

Commit 1fc130e

Browse files
committed
MultiDecoder
1 parent efe7bce commit 1fc130e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/AudioTools/AudioCodecs/AudioCodecsBase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class AudioDecoder : public AudioWriter, public AudioInfoSource {
5959
/// custom id to be used by application
6060
int id;
6161

62+
Print* getOutput(){
63+
return p_print;
64+
}
65+
6266
protected:
6367
Print *p_print = nullptr;
6468
AudioInfo info;

src/AudioTools/AudioCodecs/MultiDecoder.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ class MultiDecoder : public AudioDecoder {
4444
decoders.push_back(info);
4545
}
4646

47+
virtual void setOutput(Print &out_stream) override {
48+
p_print = &out_stream;
49+
for (int j = 0; j < decoders.size(); j++) {
50+
decoders[j].decoder->setOutput(out_stream);
51+
}
52+
}
53+
4754
/// selects the actual decoder by mime type - this is usually called
4855
/// automatically from the determined mime type
4956
bool selectDecoder(const char* mime) {
@@ -61,12 +68,13 @@ class MultiDecoder : public AudioDecoder {
6168
if (StrView(info.mime).equalsIgnoreCase(mime)) {
6269
LOGI("New decoder found for %s", info.mime);
6370
actual_decoder = info;
64-
actual_decoder.decoder->begin();
65-
result = true;
66-
// define output
67-
if (p_print!=nullptr){
71+
// define output if it has not been defined
72+
if (p_print!=nullptr
73+
&& actual_decoder.decoder->getOutput()==nullptr){
6874
actual_decoder.decoder->setOutput(*p_print);
6975
}
76+
actual_decoder.decoder->begin();
77+
result = true;
7078
}
7179
}
7280
return result;

0 commit comments

Comments
 (0)