3
3
*
4
4
* Created on: Oct 26.2018
5
5
*
6
- * Version 2.0.5k
7
- * Updated on: Aug 23 .2022
6
+ * Version 2.0.6
7
+ * Updated on: Aug 25 .2022
8
8
* Author: Wolle (schreibfaul1)
9
9
*
10
10
*/
@@ -994,7 +994,7 @@ void Audio::showID3Tag(const char* tag, const char* value){
994
994
if (!strcmp (tag, " TRCK" )) sprintf (chbuf, " Track: %s" , value);
995
995
if (!strcmp (tag, " TSSE" )) sprintf (chbuf, " SettingsForEncoding: %s" , value);
996
996
if (!strcmp (tag, " TRDA" )) sprintf (chbuf, " RecordingDates: %s" , value);
997
- if (!strcmp (tag, " TXXX" )) sprintf (chbuf, " UserDefinedText: %s" , value);
997
+ if (!m_f_m3u8data) if (! strcmp (tag, " TXXX" )) sprintf (chbuf, " UserDefinedText: %s" , value);
998
998
if (!strcmp (tag, " TYER" )) sprintf (chbuf, " Year: %s" , value);
999
999
if (!strcmp (tag, " USER" )) sprintf (chbuf, " TermsOfUse: %s" , value);
1000
1000
if (!strcmp (tag, " USLT" )) sprintf (chbuf, " Lyrics: %s" , value);
@@ -1503,9 +1503,9 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
1503
1503
headerSize = 0 ;
1504
1504
ehsz = 0 ;
1505
1505
if (specialIndexOf (data, " ID3" , 4 ) != 0 ) { // ID3 not found
1506
- AUDIO_INFO (" file has no mp3 tag, skip metadata" );
1506
+ if (!m_f_m3u8data) AUDIO_INFO (" file has no mp3 tag, skip metadata" );
1507
1507
m_audioDataSize = m_contentlength;
1508
- AUDIO_INFO (" Audio-Length: %u" , m_audioDataSize);
1508
+ if (!m_f_m3u8data) AUDIO_INFO (" Audio-Length: %u" , m_audioDataSize);
1509
1509
return -1 ; // error, no ID3 signature found
1510
1510
}
1511
1511
ID3version = *(data + 3 );
@@ -1524,9 +1524,8 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
1524
1524
id3Size += 10 ;
1525
1525
1526
1526
// Every read from now may be unsync'd
1527
- AUDIO_INFO (" ID3 framesSize: %i" , id3Size);
1528
-
1529
- AUDIO_INFO (" ID3 version: 2.%i" , ID3version);
1527
+ if (!m_f_m3u8data) AUDIO_INFO (" ID3 framesSize: %i" , id3Size);
1528
+ if (!m_f_m3u8data) AUDIO_INFO (" ID3 version: 2.%i" , ID3version);
1530
1529
1531
1530
if (ID3version == 2 ){
1532
1531
m_controlCounter = 10 ;
@@ -1548,7 +1547,7 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
1548
1547
return 4 ;
1549
1548
}
1550
1549
else {
1551
- AUDIO_INFO (" ID3 normal frames" );
1550
+ if (!m_f_m3u8data) AUDIO_INFO (" ID3 normal frames" );
1552
1551
return 0 ;
1553
1552
}
1554
1553
}
@@ -1723,7 +1722,7 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
1723
1722
else {
1724
1723
m_controlCounter = 100 ; // ok
1725
1724
m_audioDataSize = m_contentlength - m_audioDataStart;
1726
- AUDIO_INFO (" Audio-Length: %u" , m_audioDataSize);
1725
+ if (!m_f_m3u8data) AUDIO_INFO (" Audio-Length: %u" , m_audioDataSize);
1727
1726
if (APIC_seen && audio_id3image){
1728
1727
size_t pos = audiofile.position ();
1729
1728
audio_id3image (audiofile, APIC_pos, APIC_size);
@@ -3263,14 +3262,19 @@ void Audio::processWebStreamTS() {
3263
3262
void Audio::processWebStreamHLS () {
3264
3263
3265
3264
const uint16_t maxFrameSize = InBuff.getMaxBlockSize (); // every mp3/aac frame is not bigger
3265
+ const uint16_t ID3BuffSize = 1024 ;
3266
3266
uint32_t availableBytes; // available bytes in stream
3267
3267
static bool f_tmr_1s;
3268
3268
static bool f_stream; // first audio data received
3269
3269
static int bytesDecoded;
3270
+ static bool firstBytes;
3270
3271
static uint32_t byteCounter; // count received data
3271
3272
static size_t chunkSize = 0 ;
3272
3273
static uint32_t tmr_1s; // timer 1 sec
3273
3274
static uint32_t loopCnt; // count loops if clientbuffer is empty
3275
+ static uint16_t ID3WritePtr;
3276
+ static uint16_t ID3ReadPtr;
3277
+ static uint8_t * ID3Buff;
3274
3278
3275
3279
// first call, set some values to default - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3276
3280
if (m_f_firstCall) { // runs only ont time per connection, prepare for start
@@ -3279,17 +3283,54 @@ void Audio::processWebStreamHLS() {
3279
3283
bytesDecoded = 0 ;
3280
3284
chunkSize = 0 ;
3281
3285
loopCnt = 0 ;
3286
+ ID3WritePtr = 0 ;
3287
+ ID3ReadPtr = 0 ;
3282
3288
tmr_1s = millis ();
3283
3289
m_t0 = millis ();
3284
- m_f_firstCall = false ;
3290
+ m_f_firstCall = false ;
3291
+ firstBytes = true ;
3292
+ ID3Buff = (uint8_t *)malloc (ID3BuffSize);
3293
+ m_controlCounter = 0 ;
3285
3294
}
3286
3295
3287
3296
if (getDatamode () != AUDIO_DATA) return ; // guard
3288
3297
3289
3298
availableBytes = _client->available ();
3290
- if (availableBytes){
3299
+ if (availableBytes){ // an ID3 header could come here
3291
3300
uint8_t readedBytes = 0 ;
3292
- if (m_f_chunked) chunkSize = chunkedDataTransfer (&readedBytes);
3301
+
3302
+ if (m_f_chunked && !chunkSize) {chunkSize = chunkedDataTransfer (&readedBytes); byteCounter += readedBytes;}
3303
+
3304
+ if (firstBytes){
3305
+ if (ID3WritePtr < ID3BuffSize){
3306
+ ID3WritePtr += _client->readBytes (&ID3Buff[ID3WritePtr], ID3BuffSize - ID3WritePtr);
3307
+ return ;
3308
+ }
3309
+ if (m_controlCounter < 100 ){
3310
+ int res = read_ID3_Header (&ID3Buff[ID3ReadPtr], ID3BuffSize - ID3ReadPtr);
3311
+ if (res >= 0 ) ID3ReadPtr += res;
3312
+ if (ID3ReadPtr > ID3BuffSize) {log_e (" buffer overflow" ); stopSong (); return ;}
3313
+ return ;
3314
+ }
3315
+ if (m_controlCounter != 100 ) return ;
3316
+
3317
+ size_t ws = InBuff.writeSpace ();
3318
+ if (ws >= ID3BuffSize - ID3ReadPtr){
3319
+ memcpy (InBuff.getWritePtr (), &ID3Buff[ID3ReadPtr], ID3BuffSize - ID3ReadPtr);
3320
+ InBuff.bytesWritten (ID3BuffSize - ID3ReadPtr);
3321
+ }
3322
+ else {
3323
+ memcpy (InBuff.getWritePtr (), &ID3Buff[ID3ReadPtr], ws);
3324
+ InBuff.bytesWritten (ws);
3325
+ memcpy (InBuff.getWritePtr (), &ID3Buff[ws + ID3ReadPtr], ID3BuffSize - (ID3ReadPtr + ws));
3326
+ InBuff.bytesWritten (ID3BuffSize - (ID3ReadPtr + ws));
3327
+ }
3328
+ if (ID3Buff) free (ID3Buff);
3329
+ byteCounter += ID3BuffSize;
3330
+ ID3Buff = NULL ;
3331
+ firstBytes = false ;
3332
+ }
3333
+
3293
3334
size_t bytesWasWritten = 0 ;
3294
3335
if (InBuff.writeSpace () >= availableBytes){
3295
3336
bytesWasWritten = _client->read (InBuff.getWritePtr (), availableBytes);
@@ -3298,6 +3339,7 @@ void Audio::processWebStreamHLS() {
3298
3339
bytesWasWritten = _client->read (InBuff.getWritePtr (), InBuff.writeSpace ());
3299
3340
}
3300
3341
InBuff.bytesWritten (bytesWasWritten);
3342
+
3301
3343
byteCounter += bytesWasWritten;
3302
3344
if (byteCounter == m_contentlength || byteCounter == chunkSize){
3303
3345
byteCounter = 0 ;
@@ -3342,7 +3384,11 @@ void Audio::processWebStreamHLS() {
3342
3384
}
3343
3385
3344
3386
// play audio data - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
3345
- if (f_stream) playAudioData ();
3387
+ if (f_stream){
3388
+ static uint8_t cnt = 0 ;
3389
+ cnt++;
3390
+ if (cnt == 1 ){playAudioData (); cnt = 0 ;}
3391
+ }
3346
3392
return ;
3347
3393
}
3348
3394
// ---------------------------------------------------------------------------------------------------------------------
0 commit comments