Skip to content

Commit 674acdd

Browse files
committed
StreamCopy Comments
1 parent da65ee8 commit 674acdd

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/AudioTools/StreamCopy.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,27 @@ class StreamCopyT {
5454
StreamCopyT(StreamCopyT const&) = delete;
5555
StreamCopyT& operator=(StreamCopyT const&) = delete;
5656

57+
/// (Re)starts the processing
5758
void begin(){
5859
is_first = true;
5960
LOGI("buffer_size=%d",buffer_size);
6061
}
6162

63+
/// Ends the processing
6264
void end() {
6365
this->from = nullptr;
6466
this->to = nullptr;
6567
}
6668

69+
/// assign a new output and input stream
6770
void begin(Print &to, Stream &from){
6871
this->from = new AudioStreamWrapper(from);
6972
this->to = &to;
7073
is_first = true;
7174
LOGI("buffer_size=%d",buffer_size);
7275
}
7376

74-
// assign a new output and input stream
77+
/// assign a new output and input stream
7578
void begin(Print &to, AudioStream &from){
7679
this->from = &from;
7780
this->to = &to;
@@ -87,7 +90,7 @@ class StreamCopyT {
8790
return to;
8891
}
8992

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
9194
inline size_t copy(){
9295
TRACED();
9396
// if not initialized we do nothing
@@ -100,7 +103,6 @@ class StreamCopyT {
100103
return 0;
101104
}
102105

103-
104106
size_t result = 0;
105107
size_t delayCount = 0;
106108
size_t len = available();
@@ -124,7 +126,6 @@ class StreamCopyT {
124126

125127
// determine mime
126128
notifyMime(buffer.data(), bytes_to_read);
127-
is_first = false;
128129

129130
// write data
130131
result = write(bytes_read, delayCount);
@@ -150,7 +151,7 @@ class StreamCopyT {
150151
}
151152

152153

153-
/// available bytes in the data source
154+
/// available bytes of the data source
154155
int available() {
155156
int result = 0;
156157
if (from!=nullptr) {
@@ -270,7 +271,7 @@ class StreamCopyT {
270271
int retryLimit = COPY_RETRY_LIMIT;
271272
int delay_on_no_data = COPY_DELAY_ON_NODATA;
272273

273-
// blocking write - until everything is processed
274+
/// blocking write - until everything is processed
274275
size_t write(size_t len, size_t &delayCount ){
275276
if (!buffer || len==0) return 0;
276277
size_t total = 0;
@@ -299,7 +300,7 @@ class StreamCopyT {
299300

300301
/// Update the mime type
301302
void notifyMime(void* data, size_t len){
302-
if (len>4) {
303+
if (is_first && len>4) {
303304
const uint8_t *start = (const uint8_t *) data;
304305
actual_mime = "audio/basic";
305306
if (start[0]==0xFF && start[1]==0xF1){
@@ -313,6 +314,7 @@ class StreamCopyT {
313314
notifyMimeCallback(actual_mime);
314315
}
315316
}
317+
is_first = false;
316318
}
317319

318320
};
@@ -373,6 +375,7 @@ class StreamCopy : public StreamCopyT<uint8_t> {
373375
return StreamCopyT<uint8_t>::copy();
374376
}
375377

378+
/// available bytes of the data source
376379
int available() {
377380
return from == nullptr ? 0 : from->available();
378381
}

0 commit comments

Comments
 (0)