Skip to content

Commit 05e6b89

Browse files
committed
OSCContainerDecoder provide OSCData as argument
1 parent 8a53dfd commit 05e6b89

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/AudioTools/AudioCodecs/ContainerOSC.h

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class OSCContainerEncoder : public AudioEncoder {
153153
void *ref = nullptr;
154154
} osc_out;
155155

156+
/// OUtput AudioInfo via OSC
156157
void writeAudioInfo(AudioInfo info, const char *mime) {
157158
if (is_send_info_active) {
158159
LOGD("writeAudioInfo");
@@ -180,8 +181,14 @@ class OSCContainerEncoder : public AudioEncoder {
180181
class OSCContainerDecoder : public ContainerDecoder {
181182
public:
182183
OSCContainerDecoder() = default;
183-
OSCContainerDecoder(AudioDecoder &decoder) { setDecoder(decoder); }
184-
OSCContainerDecoder(MultiDecoder &decoder) { setDecoder(decoder); }
184+
OSCContainerDecoder(AudioDecoder &decoder, OSCData &osc) {
185+
setDecoder(decoder);
186+
setOSCData(osc);
187+
}
188+
OSCContainerDecoder(MultiDecoder &decoder, OSCData &osc) {
189+
setDecoder(decoder);
190+
setOSCData(osc);
191+
}
185192

186193
void setDecoder(AudioDecoder &decoder) { p_codec = &decoder; }
187194

@@ -190,26 +197,29 @@ class OSCContainerDecoder : public ContainerDecoder {
190197
p_multi_decoder = &decoder;
191198
}
192199

200+
void setOSCData(OSCData &osc) { p_osc = &osc; }
201+
193202
void setOutput(Print &outStream) {
194203
LOGD("OSCContainerDecoder::setOutput")
195204
p_out = &outStream;
196205
}
197206

198207
bool begin() {
199208
TRACED();
200-
if (p_codec == nullptr) return false;
201-
osc.setReference(this);
202-
osc.addCallback("/audio/info", parseInfo, OSCCompare::StartsWith);
203-
osc.addCallback("/audio/data", parseData, OSCCompare::StartsWith);
209+
if (p_codec == nullptr || p_osc == nullptr) return false;
210+
p_osc->setReference(this);
211+
p_osc->addCallback("/audio/info", parseInfo, OSCCompare::StartsWith);
212+
p_osc->addCallback("/audio/data", parseData, OSCCompare::StartsWith);
204213
is_active = true;
205214
return true;
206215
}
207216

208217
void end() { is_active = false; }
209218

210219
size_t write(const uint8_t *data, size_t len) {
220+
if (!is_active) return 0;
211221
LOGD("write: %d", (int)len);
212-
if (!osc.parse((uint8_t *)data, len)) {
222+
if (!p_osc->parse((uint8_t *)data, len)) {
213223
return 0;
214224
}
215225
return len;
@@ -224,10 +234,12 @@ class OSCContainerDecoder : public ContainerDecoder {
224234
uint64_t getSequenceNumber() { return seq_no; }
225235

226236
/// Adds an new parser callback for a specific address matching string
227-
void addParserCallback(const char *address,
237+
bool addParserCallback(const char *address,
228238
bool (*callback)(OSCData &data, void *ref),
229239
OSCCompare compare = OSCCompare::Matches) {
230-
osc.addCallback(address, callback, compare);
240+
if (p_osc == nullptr) return false;
241+
p_osc->addCallback(address, callback, compare);
242+
return true;
231243
}
232244

233245
/// Replace the write to the decoder with a callback:
@@ -253,7 +265,7 @@ class OSCContainerDecoder : public ContainerDecoder {
253265
MultiDecoder *p_multi_decoder = nullptr;
254266
SingleBuffer<uint8_t> buffer{0};
255267
Print *p_out = nullptr;
256-
OSCData osc;
268+
OSCData *p_osc = nullptr;
257269
Str mime_str;
258270
uint64_t seq_no = 0;
259271
/// Return false to complete the processing w/o writing to the decoder

0 commit comments

Comments
 (0)