Unverified Commit 8d416ae3 authored by Wolle's avatar Wolle Committed by GitHub
parent 092a722a
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
* *
* Created on: Oct 26.2018 * Created on: Oct 26.2018
* *
* Version 2.0.5c * Version 2.0.5d
* Updated on: Jul 31.2022 * Updated on: Aug 01.2022
* Author: Wolle (schreibfaul1) * Author: Wolle (schreibfaul1)
* *
*/ */
...@@ -303,6 +303,7 @@ void Audio::setDefaults() { ...@@ -303,6 +303,7 @@ void Audio::setDefaults() {
if(m_m3u8_lastEntry) {free(m_m3u8_lastEntry); m_m3u8_lastEntry = NULL;} // free if stream is not m3u8 if(m_m3u8_lastEntry) {free(m_m3u8_lastEntry); m_m3u8_lastEntry = NULL;} // free if stream is not m3u8
vector_clear_and_shrink(m_playlistURL); vector_clear_and_shrink(m_playlistURL);
vector_clear_and_shrink(m_playlistContent); vector_clear_and_shrink(m_playlistContent);
m_hashQueue.clear(); m_hashQueue.shrink_to_fit(); // uint32_t vector
client.stop(); client.stop();
client.flush(); // release memory client.flush(); // release memory
clientsecure.stop(); clientsecure.stop();
...@@ -582,6 +583,7 @@ bool Audio::httpPrint(const char* host) { ...@@ -582,6 +583,7 @@ bool Audio::httpPrint(const char* host) {
setDatamode(HTTP_RESPONSE_HEADER); // Handle header setDatamode(HTTP_RESPONSE_HEADER); // Handle header
m_streamType = ST_WEBSTREAM; m_streamType = ST_WEBSTREAM;
m_contentlength = 0;
if(hostwoext) {free(hostwoext); hostwoext = NULL;} if(hostwoext) {free(hostwoext); hostwoext = NULL;}
if(extension) {free(extension); extension = NULL;} if(extension) {free(extension); extension = NULL;}
...@@ -2322,8 +2324,8 @@ void Audio::loop() { ...@@ -2322,8 +2324,8 @@ void Audio::loop() {
} }
break; break;
case AUDIO_DATA: case AUDIO_DATA:
if(m_f_ts) processWebStreamTS(); if(m_f_ts) processWebStreamTS(); // aac or aacp with ts packets
else processWebStreamHLS(); else processWebStreamHLS(); // aac or aacp normal stream
if(f_noNewHost){ if(f_noNewHost){
m_f_continue = false; m_f_continue = false;
if(timestamp2 < millis()) { if(timestamp2 < millis()) {
...@@ -2369,9 +2371,10 @@ bool Audio::readPlayListData() { ...@@ -2369,9 +2371,10 @@ bool Audio::readPlayListData() {
pl[pos] = _client->read(); pl[pos] = _client->read();
if(pl[pos] == '\n') {pl[pos] = '\0'; pos++; break;} if(pl[pos] == '\n') {pl[pos] = '\0'; pos++; break;}
// if(pl[pos] == '&' ) {pl[pos] = '\0'; pos++; break;} // if(pl[pos] == '&' ) {pl[pos] = '\0'; pos++; break;}
if(pl[pos] == '\r') {pl[pos] = '\0'; pos++; break;} if(pl[pos] == '\r') {pl[pos] = '\0'; pos++; continue;;}
pos++; pos++;
if(pos == 510) {pl[pos] = '\0'; break;} if(pos == 511){ pos--; ctl++; continue;}
if(pos == 510) {pl[pos] = '\0';}
} }
ctl += pos; ctl += pos;
if(pos) {pl[pos] = '\0'; break;} if(pos) {pl[pos] = '\0'; break;}
...@@ -2629,26 +2632,30 @@ const char* Audio::parsePlaylist_M3U8(){ ...@@ -2629,26 +2632,30 @@ const char* Audio::parsePlaylist_M3U8(){
tmp = strdup(m_playlistContent[i]); tmp = strdup(m_playlistContent[i]);
} }
if(!m_m3u8_lastEntry){ // first init uint32_t hash = simpleHash(tmp);
m_playlistURL.insert(m_playlistURL.begin(), strdup((const char*)(tmp))); if(m_hashQueue.size() == 0){
m_m3u8_lastEntry = strdup(tmp); m_hashQueue.insert(m_hashQueue.begin(), hash);
if(m_f_Log) log_i("insert %s", tmp); m_playlistURL.insert(m_playlistURL.begin(), strdup(tmp));
continue;
}
if(strcmp(tmp, m_m3u8_lastEntry) > 0 || strlen(tmp) > strlen(m_m3u8_lastEntry)){ // next sequence?,
//strcmp: '2.aac'>'1.aac' or strlen '10.aac'>'9.aac'
m_playlistURL.insert(m_playlistURL.begin(), strdup((const char*)(tmp)));
if(m_m3u8_lastEntry){free(m_m3u8_lastEntry); m_m3u8_lastEntry = strdup(tmp);}
assert(m_m3u8_lastEntry != tmp); // no free space in task?
if(m_f_Log) log_i("insert %s", tmp);
} }
else{ else{
if(m_f_Log) log_i("file already known %s", m_playlistContent[i]); bool known = false;
for(int i = 0; i< m_hashQueue.size(); i++){
if(hash == m_hashQueue[i]){
if(m_f_Log) log_i("file already known %s", tmp);
known = true;
}
}
if(!known){
m_hashQueue.insert(m_hashQueue.begin(), hash);
m_playlistURL.insert(m_playlistURL.begin(), strdup(tmp));
}
} }
if(m_hashQueue.size() > 20) m_hashQueue.pop_back();
if(tmp){free(tmp); tmp = NULL;} if(tmp){free(tmp); tmp = NULL;}
if(m_playlistURL.size() == 100){ if(m_playlistURL.size() == 20){
ESP_LOGD("", "can't stuff anymore"); ESP_LOGD("", "can't stuff anymore");
break; break;
} }
...@@ -3445,10 +3452,10 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque ...@@ -3445,10 +3452,10 @@ bool Audio::parseHttpResponseHeader() { // this is the response to a GET / reque
if(b < 0x20) continue; if(b < 0x20) continue;
rhl[pos] = b; rhl[pos] = b;
pos++; pos++;
if(pos == 511){pos = 510; continue;}
if(pos == 510){ if(pos == 510){
rhl[pos] = '\0'; rhl[pos] = '\0';
if(m_f_Log) log_i("responseHeaderline overflow"); if(m_f_Log) log_i("responseHeaderline overflow");
break;
} }
} // inner while } // inner while
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* Audio.h * Audio.h
* *
* Created on: Oct 28,2018 * Created on: Oct 28,2018
* Updated on: Jul 31,2022 * Updated on: Aug 01,2022
* Author: Wolle (schreibfaul1) * Author: Wolle (schreibfaul1)
*/ */
...@@ -399,6 +399,15 @@ private: ...@@ -399,6 +399,15 @@ private:
vec.clear(); vec.clear();
vec.shrink_to_fit(); vec.shrink_to_fit();
} }
uint32_t simpleHash(const char* str){
if(str == NULL) return 0;
uint32_t hash = 0;
for(int i=0; i<strlen(str); i++){
if(str[i] < 32) continue; // ignore control sign
hash += (str[i] - 31) * i * 32;
}
return hash;
}
private: private:
const char *codecname[9] = {"unknown", "WAV", "MP3", "AAC", "M4A", "FLAC", "OGG", "OGG FLAC", "OPUS"}; const char *codecname[9] = {"unknown", "WAV", "MP3", "AAC", "M4A", "FLAC", "OGG", "OGG FLAC", "OPUS"};
...@@ -434,14 +443,15 @@ private: ...@@ -434,14 +443,15 @@ private:
int pids[4]; int pids[4];
} pid_array; } pid_array;
File audiofile; // @suppress("Abstract class cannot be instantiated") File audiofile; // @suppress("Abstract class cannot be instantiated")
WiFiClient client; // @suppress("Abstract class cannot be instantiated") WiFiClient client; // @suppress("Abstract class cannot be instantiated")
WiFiClientSecure clientsecure; // @suppress("Abstract class cannot be instantiated") WiFiClientSecure clientsecure; // @suppress("Abstract class cannot be instantiated")
WiFiClient* _client = nullptr; WiFiClient* _client = nullptr;
i2s_config_t m_i2s_config = {}; // stores values for I2S driver i2s_config_t m_i2s_config = {}; // stores values for I2S driver
i2s_pin_config_t m_pin_config = {}; i2s_pin_config_t m_pin_config = {};
std::vector<char*> m_playlistContent; // m3u8 playlist buffer std::vector<char*> m_playlistContent; // m3u8 playlist buffer
std::vector<char*> m_playlistURL; // m3u8 streamURLs buffer std::vector<char*> m_playlistURL; // m3u8 streamURLs buffer
std::vector<uint32_t> m_hashQueue;
const size_t m_frameSizeWav = 1600; const size_t m_frameSizeWav = 1600;
const size_t m_frameSizeMP3 = 1600; const size_t m_frameSizeMP3 = 1600;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment