@@ -66,16 +66,21 @@ class OggContainerDecoder : public AudioDecoder {
66
66
void begin () override {
67
67
LOGD (LOG_METHOD);
68
68
if (p_oggz == nullptr ) {
69
- p_oggz = oggz_new (OGGZ_READ | OGGZ_NONSTRICT | OGGZ_AUTO);
69
+ p_oggz = oggz_new (OGGZ_READ | OGGZ_AUTO); // OGGZ_NONSTRICT
70
70
is_open = true ;
71
+ // Callback to Replace standard IO
72
+ if (oggz_io_set_read (p_oggz, ogg_io_read, this )!=0 ){
73
+ LOGE (" oggz_io_set_read" );
74
+ is_open = false ;
75
+ }
71
76
// Callback
72
77
if (oggz_set_read_callback (p_oggz, -1 , read_packet, this )!=0 ){
73
78
LOGE (" oggz_set_read_callback" );
74
79
is_open = false ;
75
80
}
76
- // Callback to Replace standard IO
77
- if (oggz_io_set_read (p_oggz, ogg_io_read , this )!=0 ){
78
- LOGE (" oggz_io_set_read " );
81
+
82
+ if (oggz_set_read_page (p_oggz, - 1 , read_page , this )!=0 ){
83
+ LOGE (" oggz_set_read_page " );
79
84
is_open = false ;
80
85
}
81
86
}
@@ -125,13 +130,14 @@ class OggContainerDecoder : public AudioDecoder {
125
130
bool is_open = false ;
126
131
long pos = 0 ;
127
132
128
- // Final Stream Callback
133
+ // Final Stream Callback -> write data to requested output destination
129
134
static size_t ogg_io_read (void *user_handle, void *buf, size_t n) {
130
135
LOGI (" ogg_io_read: %u" , n);
131
136
OggContainerDecoder *self = (OggContainerDecoder *)user_handle;
132
137
int len = self->buffer .readArray ((uint8_t *)buf, n);
133
138
self->pos += len;
134
139
return len;
140
+ // return self->p_print->write((uint8_t *)buf, n);
135
141
}
136
142
137
143
// Process full packet
@@ -147,11 +153,20 @@ class OggContainerDecoder : public AudioDecoder {
147
153
self->endOfSegment (op);
148
154
} else {
149
155
LOGI (" process audio packet" );
150
- self->p_print ->write (op->packet , op->bytes );
156
+ int eff = self->p_print ->write (op->packet , op->bytes );
157
+ if (eff!=result){
158
+ LOGE (" Incomplere write" );
159
+ }
151
160
}
152
161
return result;
153
162
}
154
163
164
+
165
+ static int read_page (OGGZ *oggz, const ogg_page *og, long serialno, void *user_data){
166
+ LOGI (" read_page: %u" , og->body_len );
167
+ return og->body_len ;
168
+ }
169
+
155
170
virtual void beginOfSegment (ogg_packet *op) {
156
171
LOGD (" bos" );
157
172
if (op->bytes >= sizeof (cfg)) {
@@ -225,7 +240,7 @@ class OggContainerEncoder : public AudioEncoder {
225
240
LOGD (LOG_METHOD);
226
241
is_open = true ;
227
242
if (p_oggz == nullptr ) {
228
- p_oggz = oggz_new (OGGZ_WRITE | OGGZ_NONSTRICT);
243
+ p_oggz = oggz_new (OGGZ_WRITE | OGGZ_NONSTRICT | OGGZ_AUTO );
229
244
serialno = oggz_serialno_new (p_oggz);
230
245
oggz_io_set_write (p_oggz, ogg_io_write, this );
231
246
packetno = 0 ;
@@ -266,7 +281,7 @@ class OggContainerEncoder : public AudioEncoder {
266
281
op.b_o_s = false ;
267
282
op.e_o_s = false ;
268
283
op.packetno = packetno++;
269
- if (!writePacket (op)) {
284
+ if (!writePacket (op, OGGZ_FLUSH_AFTER )) {
270
285
return 0 ;
271
286
}
272
287
0 commit comments