@@ -85,26 +85,29 @@ class OSCContainerEncoder : public AudioEncoder {
85
85
// / Returns the sequence number of the next packet
86
86
uint64_t getSequenceNumber () { return packet_count; }
87
87
88
- protected:
89
- uint64_t packet_count = 0 ;
90
- int repeat_info = 0 ;
91
- bool is_active = false ;
92
- AudioEncoder *p_codec = nullptr ;
93
- Print *p_out = nullptr ;
94
-
95
- void writeAudio (const uint8_t *data, size_t len, uint64_t packet) {
88
+ // / Writes the audio with the indicated sequence number to the output.
89
+ // / To be called to resend missing data
90
+ void writeAudio (const uint8_t *data, size_t len, uint64_t sequenceNumber) {
96
91
LOGD (" writeAudio: %d" , (int )len);
97
92
uint8_t osc_data[len + 20 ]; // 20 is guess to cover address & fmt
98
93
OSCData osc{osc_data, sizeof (osc_data)};
99
94
osc.setAddress (" /audio/data" );
100
95
osc.setFormat (" ttb" );
101
96
osc.write ((uint64_t )millis ());
102
97
// we use a uint64_t for a sequence number
103
- osc.write (packet );
98
+ osc.write (sequenceNumber );
104
99
osc.write (data, len);
105
100
p_out->write (osc_data, osc.size ());
106
101
}
107
102
103
+ protected:
104
+ uint64_t packet_count = 0 ;
105
+ int repeat_info = 0 ;
106
+ bool is_active = false ;
107
+ AudioEncoder *p_codec = nullptr ;
108
+ Print *p_out = nullptr ;
109
+
110
+
108
111
void writeAudioInfo (AudioInfo info, const char *mime) {
109
112
LOGD (" writeAudioInfo" );
110
113
uint8_t osc_data[100 ];
@@ -175,22 +178,27 @@ class OSCContainerDecoder : public ContainerDecoder {
175
178
176
179
// / Adds an new parser callback for a specific address matching string
177
180
void addParserCallback (const char *address,
178
- bool (*callback)(OSCData &data, void *ref),
179
- OSCCompare compare = OSCCompare::Matches) {
181
+ bool (*callback)(OSCData &data, void *ref),
182
+ OSCCompare compare = OSCCompare::Matches) {
180
183
osc.addCallback (address, callback, compare);
181
184
}
182
185
183
- // / Replace the write to the decoder with a callback:
186
+ // / Replace the write to the decoder with a callback:
184
187
void setWriteCallback (bool (*write_callback)(uint64_t time, uint64_t seq,
185
188
uint8_t *data, size_t len,
186
189
void *ref)) {
187
190
this ->write_callback = write_callback;
188
191
}
189
192
193
+ // / Callback to be called when data is missing
194
+ void setMissingDataCallback (void (*missing_data_callback)(uint64_t from_seq,
195
+ uint64_t to_seq, void * ref)) {
196
+ this ->missing_data_callback = missing_data_callback;
197
+ }
198
+
190
199
// / Provide a reference object to the callback
191
200
void setReference (void *ref) { this ->ref = ref; }
192
201
193
-
194
202
protected:
195
203
bool is_active = false ;
196
204
AudioDecoder *p_codec = nullptr ;
@@ -203,13 +211,24 @@ class OSCContainerDecoder : public ContainerDecoder {
203
211
// / Return false to complete the processing w/o writing to the decoder
204
212
bool (*write_callback)(uint64_t time, uint64_t seq, uint8_t *data, size_t len,
205
213
void *ref) = nullptr;
214
+ void (*missing_data_callback)(uint64_t from_seq, uint64_t to_seq,
215
+ void *ref) = missingDataCallback;
206
216
void *ref = nullptr ;
207
217
218
+ // / Default callback for missing data: just log the missing range
219
+ static void missingDataCallback (uint64_t from_seq, uint64_t to_seq, void * ref) {
220
+ LOGW (" Missing sequence numbers %d - %d" , from_seq, to_seq);
221
+ }
222
+
208
223
static bool parseData (OSCData &osc, void *ref) {
209
224
uint64_t time = osc.readTime ();
210
225
uint64_t seq = osc.readTime ();
211
226
OSCBinaryData data = osc.readData ();
212
227
OSCContainerDecoder *self = static_cast <OSCContainerDecoder *>(ref);
228
+ // Check for missing sequence numbers
229
+ if (self->seq_no + 1 != seq) {
230
+ self->missing_data_callback (self->seq_no + 1 , seq - 1 , self->ref );
231
+ }
213
232
// store the actual sequence number
214
233
self->seq_no = seq;
215
234
// call write callbak if defined
@@ -221,6 +240,7 @@ class OSCContainerDecoder : public ContainerDecoder {
221
240
if (self->p_codec != nullptr ) {
222
241
self->p_codec ->write (data.data , data.len );
223
242
}
243
+
224
244
return true ;
225
245
}
226
246
0 commit comments