Skip to content

Commit a51f65e

Browse files
committed
EncodedAudioStream: invalid AudioInfo
1 parent 012f50b commit a51f65e

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/AudioTools/AudioCodecs/AudioEncoded.h

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,35 @@ class EncodedAudioOutput : public ModifyingOutput {
7878

7979
AudioInfo defaultConfig() {
8080
AudioInfo cfg;
81-
cfg.channels = 2;
82-
cfg.sample_rate = 44100;
83-
cfg.bits_per_sample = 16;
8481
return cfg;
8582
}
8683

8784
virtual void setAudioInfo(AudioInfo newInfo) override {
8885
TRACED();
89-
if (this->cfg != newInfo && newInfo.channels != 0 &&
90-
newInfo.sample_rate != 0) {
86+
if (this->cfg != newInfo && newInfo) {
9187
this->cfg = newInfo;
9288
decoder_ptr->setAudioInfo(cfg);
9389
encoder_ptr->setAudioInfo(cfg);
9490
}
9591
}
9692

93+
/// Provide audio info from decoder if relevant
94+
AudioInfo audioInfo() override {
95+
// return info from decoder if avilable
96+
if (decoder_ptr != undefined && *decoder_ptr){
97+
AudioInfo info = decoder_ptr->audioInfo();
98+
if (info) return info;
99+
}
100+
return ModifyingOutput::audioInfo();
101+
}
102+
97103
/// Defines the output
98104
void setOutput(Print *outputStream) {
99105
ptr_out = outputStream;
100-
if (decoder_ptr != nullptr) {
106+
if (decoder_ptr != undefined) {
101107
decoder_ptr->setOutput(*ptr_out);
102108
}
103-
if (encoder_ptr != nullptr) {
109+
if (encoder_ptr != undefined) {
104110
encoder_ptr->setOutput(*ptr_out);
105111
}
106112
}
@@ -121,7 +127,7 @@ class EncodedAudioOutput : public ModifyingOutput {
121127

122128
void setEncoder(AudioEncoder *encoder) {
123129
if (encoder == nullptr) {
124-
encoder = CodecNOP::instance();
130+
encoder = undefined;
125131
}
126132
encoder_ptr = encoder;
127133
writer_ptr = encoder;
@@ -134,7 +140,7 @@ class EncodedAudioOutput : public ModifyingOutput {
134140

135141
void setDecoder(AudioDecoder *decoder) {
136142
if (decoder == nullptr) {
137-
decoder = CodecNOP::instance();
143+
decoder = undefined;
138144
}
139145
decoder_ptr = decoder;
140146
writer_ptr = decoder;
@@ -152,9 +158,10 @@ class EncodedAudioOutput : public ModifyingOutput {
152158
TRACED();
153159
// Setup notification
154160
if (to_notify != nullptr) {
155-
decoder_ptr->removeNotifyAudioChange(*to_notify);
156161
decoder_ptr->addNotifyAudioChange(*to_notify);
157162
}
163+
// Get notifications from decoder
164+
decoder_ptr->addNotifyAudioChange(*this);
158165
if (decoder_ptr != undefined || encoder_ptr != undefined) {
159166
active = true;
160167
if (!decoder_ptr->begin(cfg)) active = false;
@@ -236,13 +243,6 @@ class EncodedAudioOutput : public ModifyingOutput {
236243
return *this;
237244
}
238245

239-
/// Provide audio info from decoder if relevant
240-
AudioInfo audioInfo() override {
241-
if (decoder_ptr != undefined){
242-
return decoder_ptr->audioInfo();
243-
}
244-
return ModifyingOutput::audioInfo();
245-
}
246246

247247
protected:
248248
// AudioInfo info;
@@ -358,6 +358,7 @@ class EncodedAudioStream : public ReformatBaseStream {
358358
// is_output_notify = false;
359359
setupReader();
360360
ReformatBaseStream::begin();
361+
enc_out.addNotifyAudioChange(*this);
361362
return enc_out.begin(audioInfo());
362363
}
363364

@@ -397,7 +398,14 @@ class EncodedAudioStream : public ReformatBaseStream {
397398
return *this;
398399
};
399400

400-
AudioInfo audioInfo() override { return enc_out.audioInfo(); }
401+
AudioInfo audioInfo() override {
402+
return enc_out.audioInfo();;
403+
}
404+
405+
void setAudioInfo(AudioInfo newInfo) override {
406+
ReformatBaseStream::setAudioInfo(newInfo);
407+
enc_out.setAudioInfo(newInfo);
408+
}
401409

402410
protected:
403411
EncodedAudioOutput enc_out;

0 commit comments

Comments
 (0)