@@ -54,24 +54,27 @@ class StreamCopyT {
54
54
StreamCopyT (StreamCopyT const &) = delete ;
55
55
StreamCopyT& operator =(StreamCopyT const &) = delete ;
56
56
57
+ // / (Re)starts the processing
57
58
void begin (){
58
59
is_first = true ;
59
60
LOGI (" buffer_size=%d" ,buffer_size);
60
61
}
61
62
63
+ // / Ends the processing
62
64
void end () {
63
65
this ->from = nullptr ;
64
66
this ->to = nullptr ;
65
67
}
66
68
69
+ // / assign a new output and input stream
67
70
void begin (Print &to, Stream &from){
68
71
this ->from = new AudioStreamWrapper (from);
69
72
this ->to = &to;
70
73
is_first = true ;
71
74
LOGI (" buffer_size=%d" ,buffer_size);
72
75
}
73
76
74
- // assign a new output and input stream
77
+ // / assign a new output and input stream
75
78
void begin (Print &to, AudioStream &from){
76
79
this ->from = &from;
77
80
this ->to = &to;
@@ -87,7 +90,7 @@ class StreamCopyT {
87
90
return to;
88
91
}
89
92
90
- // copies the data from the source to the destination - the result is in bytes
93
+ // / copies the data from the source to the destination - the result is in bytes
91
94
inline size_t copy (){
92
95
TRACED ();
93
96
// if not initialized we do nothing
@@ -100,7 +103,6 @@ class StreamCopyT {
100
103
return 0 ;
101
104
}
102
105
103
-
104
106
size_t result = 0 ;
105
107
size_t delayCount = 0 ;
106
108
size_t len = available ();
@@ -124,7 +126,6 @@ class StreamCopyT {
124
126
125
127
// determine mime
126
128
notifyMime (buffer.data (), bytes_to_read);
127
- is_first = false ;
128
129
129
130
// write data
130
131
result = write (bytes_read, delayCount);
@@ -150,7 +151,7 @@ class StreamCopyT {
150
151
}
151
152
152
153
153
- // / available bytes in the data source
154
+ // / available bytes of the data source
154
155
int available () {
155
156
int result = 0 ;
156
157
if (from!=nullptr ) {
@@ -270,7 +271,7 @@ class StreamCopyT {
270
271
int retryLimit = COPY_RETRY_LIMIT;
271
272
int delay_on_no_data = COPY_DELAY_ON_NODATA;
272
273
273
- // blocking write - until everything is processed
274
+ // / blocking write - until everything is processed
274
275
size_t write (size_t len, size_t &delayCount ){
275
276
if (!buffer || len==0 ) return 0 ;
276
277
size_t total = 0 ;
@@ -299,7 +300,7 @@ class StreamCopyT {
299
300
300
301
// / Update the mime type
301
302
void notifyMime (void * data, size_t len){
302
- if (len>4 ) {
303
+ if (is_first && len>4 ) {
303
304
const uint8_t *start = (const uint8_t *) data;
304
305
actual_mime = " audio/basic" ;
305
306
if (start[0 ]==0xFF && start[1 ]==0xF1 ){
@@ -313,6 +314,7 @@ class StreamCopyT {
313
314
notifyMimeCallback (actual_mime);
314
315
}
315
316
}
317
+ is_first = false ;
316
318
}
317
319
318
320
};
@@ -373,6 +375,7 @@ class StreamCopy : public StreamCopyT<uint8_t> {
373
375
return StreamCopyT<uint8_t >::copy ();
374
376
}
375
377
378
+ // / available bytes of the data source
376
379
int available () {
377
380
return from == nullptr ? 0 : from->available ();
378
381
}
0 commit comments