@@ -552,17 +552,17 @@ int32_t MP3Decoder::findSyncWord(uint8_t* buf, int32_t nBytes) {
552552 // };
553553
554554 typedef struct {
555- uint8_t mpeg_version; // 0=MPEG2.5, 1=reserved, 2=MPEG2, 3=MPEG1
556- uint8_t layer; // 0=reserved, 1=Layer III, 2=Layer II, 3=Layer I
557- bool crc_protected;
558- uint8_t bitrate_idx;
559- uint8_t sample_rate_idx;
560- bool padding;
561- uint8_t channel_mode;
562- uint32_t frame_length = 0 ; // cytes
563- uint16_t sample_rate_hz; // the actual sampling rate in Hz
564- uint16_t bitrate_kbps; // the actual bit rate in Kbps
565- uint16_t samples_per_frame;
555+ uint8_t mpeg_version = 0 ; // 0=MPEG2.5, 1=reserved, 2=MPEG2, 3=MPEG1
556+ uint8_t layer = 0 ; // 0=reserved, 1=Layer III, 2=Layer II, 3=Layer I
557+ bool crc_protected = 0 ;
558+ uint8_t bitrate_idx = 0 ;
559+ uint8_t sample_rate_idx = 0 ;
560+ bool padding = 0 ;
561+ uint8_t channel_mode = 0 ;
562+ uint32_t frame_length = 0 ; // cytes
563+ uint16_t sample_rate_hz = 0 ; // the actual sampling rate in Hz
564+ uint16_t bitrate_kbps = 0 ; // the actual bit rate in Kbps
565+ uint16_t samples_per_frame = 0 ;
566566 } Mp3FrameHeader_sync_t;
567567
568568 // SamplingFrequenz-Lookup tables(Beispiel für MPEG1, MPEG2, MPEG2.5)
@@ -644,7 +644,7 @@ int32_t MP3Decoder::findSyncWord(uint8_t* buf, int32_t nBytes) {
644644 uint16_t sample_rate_hz = 0 ;
645645
646646 // Mapping from MPEG version to sampling rate table
647- uint8_t sr_table_idx;
647+ uint8_t sr_table_idx = 0 ;
648648 if (header_info->mpeg_version == 3 )
649649 sr_table_idx = 0 ; // MPEG 1 (0b11)
650650 else if (header_info->mpeg_version == 2 )
@@ -1093,11 +1093,31 @@ int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
10931093 // Skip fake frames
10941094 int frameLen = IsLikelyRealFrame (inbuf, *bytesLeft);
10951095
1096+ if (m_invalid_frame.start == true && m_invalid_frame.timer + 3000 > millis ()) m_invalid_frame.start = false ;
1097+
10961098 if (frameLen <= 0 ) {
10971099 int skip = -frameLen;
10981100 if (skip > 0 && skip <= *bytesLeft) {
10991101 *bytesLeft -= skip;
11001102 MP3_LOG_DEBUG (" Fakeframe, size %i" , frameLen);
1103+
1104+ if (m_invalid_frame.start == false ) { // fake frames control
1105+ m_invalid_frame.start = true ;
1106+ m_invalid_frame.timer = millis ();
1107+ m_invalid_frame.count1 = 0 ;
1108+ m_invalid_frame.count2 = 0 ;
1109+ } else {
1110+ m_invalid_frame.count1 ++;
1111+ if (m_invalid_frame.start && m_invalid_frame.timer + 1000 < millis ()) { m_invalid_frame.count2 ++; }
1112+ if (m_invalid_frame.start && m_invalid_frame.timer + 2000 < millis ()) {
1113+ if (m_invalid_frame.count1 > 5 && m_invalid_frame.count2 > 5 ) {
1114+ // network error
1115+ m_invalid_frame.start = false ;
1116+ return MP3_NEED_RESTART;
1117+ }
1118+ }
1119+ }
1120+
11011121 return MP3_NONE; // fakeframe
11021122 }
11031123 // inbuf empty or unusable
@@ -1146,7 +1166,7 @@ int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
11461166 if (m_MP3DecInfo->nSlots > *bytesLeft) {
11471167 MP3ClearBadFrame (outbuf);
11481168 MP3_LOG_DEBUG (" MP3, indata underflow" );
1149- return MP3_NONE ;
1169+ return MP3_MAIN_DATA_UNDERFLOW ;
11501170 }
11511171
11521172 /* fill main data buffer with enough new data for this frame */
0 commit comments