@@ -6510,24 +6510,28 @@ int32_t Audio::newInBuffStart(int32_t m_resumeFilePos){
65106510
65116511 if (m_resumeFilePos < (int32_t )m_audioDataStart) m_resumeFilePos = m_audioDataStart;
65126512 if (m_resumeFilePos >= (int32_t )m_audioDataStart + m_audioDataSize) {return - 1 ;}
6513- int buffFillSize = min (m_audioDataSize - m_resumeFilePos, UINT16_MAX);
6513+ int32_t buffFillSize = min (m_audioDataSize - m_resumeFilePos, UINT16_MAX);
65146514
65156515 m_f_lockInBuffer = true ; // lock the buffer, the InBuffer must not be re-entered in playAudioData()
65166516 while (m_f_audioTaskIsDecoding) vTaskDelay (1 ); // We can't reset the InBuffer while the decoding is in progress
6517- InBuff.resetBuffer ();
65186517 int res = audioFileSeek (m_resumeFilePos);
65196518 m_f_allDataReceived = false ;
6520-
6521- uint16_t rd = buffFillSize;
6522- while (rd > 0 ){
6523- int r = audioFileRead (InBuff.getReadPtr (), rd);
6524- if (r < 0 ) { /* AUDIO_LOG_ERROR("r < 0");*/ continue ;}
6525- rd -= r;
6526- log_w (" rd %i, r %i, len %i" , rd, r, buffFillSize);
6519+ InBuff.resetBuffer ();
6520+ uint16_t remaining = buffFillSize;
6521+ int32_t offset = 0 ;
6522+ uint32_t timeOut = millis ();
6523+ while (remaining > 0 ) {
6524+ int bytesRead = audioFileRead (InBuff.getReadPtr () + offset, remaining);
6525+ if (bytesRead <= 0 ) {
6526+ if (millis () > timeOut + 2000 ){AUDIO_LOG_ERROR (" timeout, not enough data from host" ); buffFillSize = offset; break ;}
6527+ continue ; // ggf. Sleep oder Timeout prüfen, um Endlosschleife zu vermeiden
6528+ }
6529+ remaining -= bytesRead;
6530+ offset += bytesRead;
65276531 }
65286532 InBuff.bytesWritten (buffFillSize);
65296533
6530- int32_t offset = -1 ;
6534+ offset = -1 ;
65316535 if (m_codec == CODEC_OPUS || m_codec == CODEC_VORBIS) {if (InBuff.bufferFilled () < 0xFFFF ) return - 1 ;} // ogg frame <= 64kB
65326536 if (m_codec == CODEC_WAV) {while ((m_resumeFilePos % 4 ) != 0 ){m_resumeFilePos++; offset++; if (m_resumeFilePos >= m_audioFileSize) goto exit;}} // must divisible by four
65336537 if (m_codec == CODEC_MP3) {offset = mp3_correctResumeFilePos (); if (offset == -1 ) goto exit; MP3Decoder_ClearBuffer ();}
0 commit comments