Skip to content

Commit aa4046e

Browse files
committed
2 parents 17744b9 + a65aedb commit aa4046e

File tree

6 files changed

+39
-37
lines changed

6 files changed

+39
-37
lines changed

src/AudioTools/AudioCodecs/AudioCodecsBase.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ class AudioDecoder : public AudioWriter, public AudioInfoSource {
5959
/// custom id to be used by application
6060
int id;
6161

62+
Print* getOutput(){
63+
return p_print;
64+
}
65+
6266
protected:
6367
Print *p_print = nullptr;
6468
AudioInfo info;

src/AudioTools/AudioCodecs/MultiDecoder.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,17 @@ class MultiDecoder : public AudioDecoder {
4040
/// Adds a decoder that will be selected by it's mime type
4141
void addDecoder(AudioDecoder& decoder, const char* mime) {
4242
DecoderInfo info{mime, &decoder};
43+
decoder.addNotifyAudioChange(*this);
4344
decoders.push_back(info);
4445
}
4546

47+
virtual void setOutput(Print &out_stream) override {
48+
p_print = &out_stream;
49+
for (int j = 0; j < decoders.size(); j++) {
50+
decoders[j].decoder->setOutput(out_stream);
51+
}
52+
}
53+
4654
/// selects the actual decoder by mime type - this is usually called
4755
/// automatically from the determined mime type
4856
bool selectDecoder(const char* mime) {
@@ -57,16 +65,16 @@ class MultiDecoder : public AudioDecoder {
5765
// find the corresponding decoder
5866
for (int j = 0; j < decoders.size(); j++) {
5967
DecoderInfo info = decoders[j];
60-
if (StrView(info.mime).equalsIgnoreCase(mime)) {
61-
LOGI("New decoder found for %s", info.mime);
68+
if (StrView(info.mime).equals(mime)) {
69+
LOGI("New decoder found for %s (%s)", info.mime, mime);
6270
actual_decoder = info;
63-
actual_decoder.decoder->begin();
64-
result = true;
65-
// define output
66-
if (p_print!=nullptr){
67-
actual_decoder.decoder->addNotifyAudioChange(*this);
71+
// define output if it has not been defined
72+
if (p_print!=nullptr
73+
&& actual_decoder.decoder->getOutput()==nullptr){
6874
actual_decoder.decoder->setOutput(*p_print);
6975
}
76+
actual_decoder.decoder->begin();
77+
result = true;
7078
}
7179
}
7280
return result;

src/AudioTools/CoreAudio/AudioHttp/HttpHeader.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ struct HttpHeaderLine {
4949
HttpHeaderLine(const char* k) { key = k; }
5050
};
5151

52-
/**
53-
* @brief workng buffer on the heap
54-
*/
55-
56-
static Vector<char> temp_buffer{0};
57-
5852
/**
5953
* @brief In a http request and reply we need to process header information.
6054
* With this API we can define and query the header information. The individual
@@ -302,7 +296,7 @@ class HttpHeader {
302296
bool isRedirectStatus() { return status_code >= 300 && status_code < 400; }
303297

304298
/// release static temp buffer
305-
static void end() { temp_buffer.resize(0); }
299+
void end() { temp_buffer.resize(0); }
306300

307301
/// Set the timout
308302
void setTimeout(int timeoutMs) { timeout_ms = timeoutMs; }
@@ -313,6 +307,11 @@ class HttpHeader {
313307
/// Defines the protocol: e.g. HTTP/1.1
314308
void setProtocol(const char* protocal) { protocol_str = protocal; }
315309

310+
/// Resizes the internal read buffer
311+
void resize(int bufferSize){
312+
temp_buffer.resize(bufferSize);
313+
}
314+
316315
protected:
317316
int status_code = UNDEFINED;
318317
bool is_written = false;
@@ -329,9 +328,9 @@ class HttpHeader {
329328
HttpLineReader reader;
330329
const char* CRLF = "\r\n";
331330
int timeout_ms = URL_CLIENT_TIMEOUT;
331+
Vector<char> temp_buffer{HTTP_MAX_LEN};
332332

333333
char* tempBuffer() {
334-
temp_buffer.resize(HTTP_MAX_LEN);
335334
temp_buffer.clear();
336335
return temp_buffer.data();
337336
}

src/AudioTools/CoreAudio/AudioHttp/HttpRequest.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class HttpRequest : public BaseStream {
2929

3030
HttpRequest() = default;
3131

32-
~HttpRequest() { HttpHeader::end(); }
32+
~HttpRequest() { end(); }
3333

3434
HttpRequest(Client &client) { setClient(client); }
3535

src/AudioTools/CoreAudio/AudioMetaData/MetaDataICY.h

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ class MetaDataICY : public AbstractMetaData {
3535
setIcyMetaInt(metaint);
3636
}
3737

38-
~MetaDataICY(){
39-
if (metaData!=nullptr) delete[]metaData;
40-
}
38+
virtual ~MetaDataICY() {}
4139

4240
/// Defines the ICE metaint value which is provided by the web call!
4341
virtual void setIcyMetaInt(int value) override {
@@ -139,7 +137,7 @@ class MetaDataICY : public AbstractMetaData {
139137
currentStatus = ProcessMetaData;
140138
metaData[metaDataPos++]=ch;
141139
if (metaDataPos>=metaDataLen){
142-
processMetaData(metaData, metaDataLen);
140+
processMetaData(metaData.data(), metaDataLen);
143141
LOGI("Metadata ended")
144142
nextStatus = ProcessData;
145143
}
@@ -152,7 +150,7 @@ class MetaDataICY : public AbstractMetaData {
152150
Status nextStatus = ProcessData;
153151
Status currentStatus = ProcessData;
154152
void (*callback)(MetaDataType info, const char* str, int len) = nullptr;
155-
char* metaData=nullptr;
153+
Vector<char> metaData{0};
156154
int totalData = 0;
157155
int mp3_blocksize = 0;
158156
int metaDataMaxLen = 0;
@@ -168,6 +166,7 @@ class MetaDataICY : public AbstractMetaData {
168166
virtual void clear() {
169167
nextStatus = ProcessData;
170168
totalData = 0;
169+
metaData.resize(0);
171170
metaDataLen = 0;
172171
metaDataPos = 0;
173172
dataLen = 0;
@@ -192,21 +191,9 @@ class MetaDataICY : public AbstractMetaData {
192191
/// allocates the memory to store the metadata / we support changing sizes
193192
virtual void setupMetaData(int meta_size) {
194193
TRACED();
195-
if (meta_size>0){
196-
if (metaData==nullptr){
197-
metaData = new char[meta_size+1];
198-
metaDataMaxLen = meta_size;
199-
LOGD("metaDataMaxLen: %d", metaDataMaxLen);
200-
} else {
201-
if (meta_size>metaDataMaxLen){
202-
delete [] metaData;
203-
metaData = new char[meta_size+1];
204-
metaDataMaxLen = meta_size;
205-
LOGD("metaDataMaxLen: %d", metaDataMaxLen);
206-
}
207-
}
208-
memset(metaData, 0, meta_size);
209-
}
194+
metaData.resize(meta_size+1);
195+
metaDataMaxLen = meta_size;
196+
memset(metaData.data(), 0, meta_size+1);
210197
}
211198

212199
/// e.g. StreamTitle=' House Bulldogs - But your love (Radio Edit)';StreamUrl='';

src/AudioTools/CoreAudio/MimeDetector.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,18 @@ class MimeDetector {
6464
const uint8_t* start = (const uint8_t*)data;
6565
if (start[0] == 0xFF && start[1] == 0xF1) {
6666
mime = "audio/aac";
67-
} else if (memcmp(start, "ID3", 3)==0 || start[0] == 0xFF || start[0] == 0xFE) {
67+
} else if (memcmp(start, "ID3", 3)==0
68+
|| start[0] == 0xFF || start[0] == 0xFE) {
6869
mime = "audio/mpeg";
6970
} else if (memcmp(start, "RIFF", 4)==0) {
7071
mime = "audio/vnd.wave";
7172
} else if (memcmp(start, "OggS", 4)==0) {
7273
mime = "audio/ogg";
7374
}
7475
}
76+
if (mime != nullptr) {
77+
LOGI("Determined mime: %s", mime);
78+
}
7579
return mime;
7680
}
7781
};

0 commit comments

Comments
 (0)