Skip to content

Commit beb5ea4

Browse files
authored
enable ID3 header for m3u8 streams
as a result, the AAC decoder finds the first syncronword with pinpoint accuracy
1 parent b227d76 commit beb5ea4

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/Audio.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
*
44
* Created on: Oct 26.2018
55
*
6-
* Version 2.0.4c
7-
* Updated on: Jul 09.2022
6+
* Version 2.0.4d
7+
* Updated on: Jul 11.2022
88
* Author: Wolle (schreibfaul1)
99
*
1010
*/
@@ -1346,7 +1346,7 @@ int Audio::read_FLAC_Header(uint8_t *data, size_t len) {
13461346
return 0;
13471347
}
13481348
//---------------------------------------------------------------------------------------------------------------------
1349-
int Audio::read_MP3_Header(uint8_t *data, size_t len) {
1349+
int Audio::read_ID3_Header(uint8_t *data, size_t len) {
13501350

13511351
static size_t id3Size;
13521352
static size_t headerSize;
@@ -2661,7 +2661,7 @@ void Audio::processLocalFile() {
26612661
}
26622662
}
26632663
if(m_codec == CODEC_MP3){
2664-
int res = read_MP3_Header(InBuff.getReadPtr(), bytesCanBeRead);
2664+
int res = read_ID3_Header(InBuff.getReadPtr(), bytesCanBeRead);
26652665
if(res >= 0) bytesDecoded = res;
26662666
else{ // error, skip header
26672667
m_controlCounter = 100;
@@ -2957,15 +2957,15 @@ void Audio::processWebStream() {
29572957
}
29582958

29592959
// if we have a webfile, read the file header first - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2960-
if(m_f_webfile && m_controlCounter != 100 && m_playlistFormat != FORMAT_M3U8){ // m3u8call, audiochunk has no header
2960+
if(m_f_webfile && m_controlCounter != 100 ){ // m3u8call, audiochunk has no header
29612961
if(InBuff.bufferFilled() < maxFrameSize) return;
29622962
if(m_codec == CODEC_WAV){
29632963
int res = read_WAV_Header(InBuff.getReadPtr(), InBuff.bufferFilled());
29642964
if(res >= 0) bytesDecoded = res;
29652965
else{stopSong(); return;}
29662966
}
29672967
if(m_codec == CODEC_MP3){
2968-
int res = read_MP3_Header(InBuff.getReadPtr(), InBuff.bufferFilled());
2968+
int res = read_ID3_Header(InBuff.getReadPtr(), InBuff.bufferFilled());
29692969
if(res >= 0) bytesDecoded = res;
29702970
else{m_controlCounter = 100;} // error, skip header
29712971
}
@@ -2977,11 +2977,17 @@ void Audio::processWebStream() {
29772977
if(m_codec == CODEC_FLAC){
29782978
int res = read_FLAC_Header(InBuff.getReadPtr(), InBuff.bufferFilled());
29792979
if(res >= 0) bytesDecoded = res;
2980-
else{stopSong(); return;} // error, skip header
2980+
else{stopSong(); return;} // error, skip header
29812981
}
2982-
if(m_codec == CODEC_AAC){ // aac has no header
2983-
m_controlCounter = 100;
2984-
return;
2982+
if(m_codec == CODEC_AAC){ // aac has no header
2983+
if(m_playlistFormat == FORMAT_M3U8){ // except m3u8 stream
2984+
int res = read_ID3_Header(InBuff.getReadPtr(), InBuff.bufferFilled());
2985+
if(res >= 0) bytesDecoded = res;
2986+
else m_controlCounter = 100;
2987+
}
2988+
else{
2989+
m_controlCounter = 100;
2990+
}
29852991
}
29862992
InBuff.bytesWasRead(bytesDecoded);
29872993
return;
@@ -3387,7 +3393,7 @@ bool Audio::parseContentType(char* ct) {
33873393

33883394
if(!strcmp(ct, "audio/aac")) ct_val = CT_AAC;
33893395
if(!strcmp(ct, "audio/x-aac")) ct_val = CT_AAC;
3390-
if(!strcmp(ct, "audio/aacp")) ct_val = CT_AACP;
3396+
if(!strcmp(ct, "audio/aacp")) ct_val = CT_AAC;
33913397
if(!strcmp(ct, "audio/mp4")) ct_val = CT_M4A;
33923398
if(!strcmp(ct, "audio/m4a")) ct_val = CT_M4A;
33933399

@@ -3411,7 +3417,7 @@ bool Audio::parseContentType(char* ct) {
34113417
if(!strcmp(ct, "text/html")) ct_val = CT_TXT;
34123418
if(!strcmp(ct, "text/plain")) ct_val = CT_TXT;
34133419

3414-
if(ct_val == CT_NONE || ct_val == CT_AACP){
3420+
if(ct_val == CT_NONE){
34153421
AUDIO_INFO("ContentType %s not supported", ct);
34163422
return false; // nothing valid had been seen
34173423
}

src/Audio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Audio.h
33
*
44
* Created on: Oct 26,2018
5-
* Updated on: Jul 08,2022
5+
* Updated on: Jul 11,2022
66
* Author: Wolle (schreibfaul1)
77
*/
88

@@ -232,7 +232,7 @@ class Audio : private AudioBuffer{
232232
void unicode2utf8(char* buff, uint32_t len);
233233
int read_WAV_Header(uint8_t* data, size_t len);
234234
int read_FLAC_Header(uint8_t *data, size_t len);
235-
int read_MP3_Header(uint8_t* data, size_t len);
235+
int read_ID3_Header(uint8_t* data, size_t len);
236236
int read_M4A_Header(uint8_t* data, size_t len);
237237
int read_OGG_Header(uint8_t *data, size_t len);
238238
bool setSampleRate(uint32_t hz);

0 commit comments

Comments
 (0)