Skip to content

Commit a42dc20

Browse files
committed
ContainerOSC
1 parent 95094fc commit a42dc20

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/AudioTools/AudioCodecs/ContainerOSC.h

+24-19
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ class OSCContainerEncoder : public AudioEncoder {
4444

4545
bool begin() override {
4646
TRACED();
47+
if (p_codec == nullptr) return false;
4748
// target.begin();
48-
bool rc = p_codec->begin();
49+
is_active = p_codec->begin();
4950
p_codec->setAudioInfo(audioInfo());
50-
is_beginning = true;
5151
writeAudioInfo();
52-
return rc;
52+
return is_active;
5353
}
5454

5555
void setAudioInfo(AudioInfo info) override {
@@ -68,9 +68,12 @@ class OSCContainerEncoder : public AudioEncoder {
6868
return len;
6969
}
7070

71-
void end() { p_codec->end(); }
71+
void end() {
72+
p_codec->end();
73+
is_active = false;
74+
}
7275

73-
operator bool() { return true; };
76+
operator bool() { return is_active; };
7477

7578
virtual const char *mime() { return "audio/OSC"; };
7679

@@ -81,7 +84,7 @@ class OSCContainerEncoder : public AudioEncoder {
8184
protected:
8285
uint64_t packet_count = 0;
8386
int repeat_info = 0;
84-
bool is_beginning = true;
87+
bool is_active = false;
8588
AudioEncoder *p_codec = nullptr;
8689
Print *p_out = nullptr;
8790

@@ -137,14 +140,15 @@ class OSCContainerDecoder : public ContainerDecoder {
137140

138141
bool begin() {
139142
TRACED();
140-
is_first = true;
143+
if (p_codec == nullptr) return false;
141144
osc.setReference(this);
142145
osc.addCallback("/audio/info", parseInfo, OSCCompare::StartsWith);
143146
osc.addCallback("/audio/data", parseData, OSCCompare::StartsWith);
147+
is_active = true;
144148
return true;
145149
}
146150

147-
void end() { TRACED(); }
151+
void end() { is_active = false; }
148152

149153
size_t write(const uint8_t *data, size_t len) {
150154
LOGD("write: %d", (int)len);
@@ -154,13 +158,13 @@ class OSCContainerDecoder : public ContainerDecoder {
154158
return len;
155159
}
156160

157-
operator bool() { return true; };
161+
operator bool() { return is_active; };
158162

159163
/// Provides the mime type from the encoder
160164
const char *mime() { return mime_str.c_str(); };
161165

162166
protected:
163-
bool is_first = true;
167+
bool is_active = false;
164168
AudioDecoder *p_codec = nullptr;
165169
MultiDecoder *p_multi_decoder = nullptr;
166170
SingleBuffer<uint8_t> buffer{0};
@@ -170,9 +174,9 @@ class OSCContainerDecoder : public ContainerDecoder {
170174

171175
static bool parseData(OSCData &osc, void *ref) {
172176
OSCBinaryData data = osc.readData();
173-
OSCContainerDecoder *decoder = static_cast<OSCContainerDecoder *>(ref);
174-
if (decoder->p_codec != nullptr) {
175-
decoder->p_codec->write(data.data, data.len);
177+
OSCContainerDecoder *self = static_cast<OSCContainerDecoder *>(ref);
178+
if (self->p_codec != nullptr) {
179+
self->p_codec->write(data.data, data.len);
176180
}
177181
return true;
178182
}
@@ -184,13 +188,14 @@ class OSCContainerDecoder : public ContainerDecoder {
184188
info.bits_per_sample = osc.readInt32();
185189
const char *mime = osc.readString();
186190

187-
OSCContainerDecoder *decoder = static_cast<OSCContainerDecoder *>(ref);
188-
if (decoder != nullptr) {
189-
decoder->setAudioInfo(info);
190-
decoder->mime_str = mime;
191+
OSCContainerDecoder *self = static_cast<OSCContainerDecoder *>(ref);
192+
if (self != nullptr) {
193+
self->setAudioInfo(info);
194+
self->mime_str = mime;
195+
LOGI("mime: %s", mime);
191196
// select the right decoder based on the mime type
192-
if (decoder->p_multi_decoder)
193-
decoder->p_multi_decoder->selectDecoder(mime);
197+
if (self->p_multi_decoder != nullptr)
198+
self->p_multi_decoder->selectDecoder(mime);
194199
}
195200

196201
return true;

0 commit comments

Comments
 (0)