Skip to content

Commit b10269f

Browse files
committed
StreamCopy: make MimeDetector optional to save RAM and Progmem
1 parent feb394d commit b10269f

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/AudioTools/CoreAudio/StreamCopy.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class StreamCopyT {
4949
/// (Re)starts the processing
5050
void begin(){
5151
TRACED();
52-
mime_detector.begin();
52+
if (p_mime_detector!=nullptr) {
53+
p_mime_detector->begin();
54+
};
5355
resize(buffer_size);
5456
if (buffer){
5557
LOGI("buffer_size=%d",buffer_size);
@@ -154,7 +156,9 @@ class StreamCopyT {
154156
}
155157

156158
// determine mime
157-
mime_detector.write(buffer.data(), bytes_to_read);
159+
if (p_mime_detector != nullptr){
160+
p_mime_detector->write(buffer.data(), bytes_to_read);
161+
}
158162

159163
// convert data
160164
if (p_converter!=nullptr) p_converter->convert((uint8_t*)buffer.data(), bytes_read );
@@ -255,11 +259,6 @@ class StreamCopyT {
255259
delay_on_no_data = delayMs;
256260
}
257261

258-
/// Provides the actual mime type, that was determined from the first available data
259-
const char* mime() {
260-
return mime_detector.mime();
261-
}
262-
263262
/// Defines a callback that is notified with the wirtten data
264263
void setCallbackOnWrite(void (*onWrite)(void*obj, void*buffer, size_t len), void* obj){
265264
TRACED();
@@ -345,13 +344,12 @@ class StreamCopyT {
345344
/// Activate the synchronization from the AudioInfo form the source to the target
346345
void setSynchAudioInfo(bool active){
347346
is_sync_audio_info = active;
348-
}
349-
350-
/// Define the callback that will notify about mime changes
351-
void setMimeCallback(void (*callback)(const char*)){
352-
mime_detector.setMimeCallback(callback);
353-
}
347+
}
354348

349+
/// Define a mime detector
350+
void setMimeDetector(MimeDetector &mime){
351+
p_mime_detector = &mime;
352+
}
355353

356354
protected:
357355
Stream *from = nullptr;
@@ -374,7 +372,7 @@ class StreamCopyT {
374372
bool is_sync_audio_info = false;
375373
AudioInfoSupport *p_audio_info_support = nullptr;
376374
BaseConverter* p_converter = nullptr;
377-
MimeDetector mime_detector;
375+
MimeDetector* p_mime_detector = nullptr;
378376

379377
void syncAudioInfo(){
380378
// synchronize audio info

0 commit comments

Comments
 (0)