| 223 | } |
| 224 | |
| 225 | bool Mp3StreamDecoderImpl::fillBuffer() { |
| 226 | // Shift remaining data to beginning of buffer |
| 227 | if (mBufferPos > 0 && mBufferFilled > mBufferPos) { |
| 228 | fl::size remaining = mBufferFilled - mBufferPos; |
| 229 | for (fl::size i = 0; i < remaining; i++) { |
| 230 | mBuffer[i] = mBuffer[mBufferPos + i]; |
| 231 | } |
| 232 | mBufferFilled = remaining; |
| 233 | mBufferPos = 0; |
| 234 | } else if (mBufferPos >= mBufferFilled) { |
| 235 | mBufferPos = 0; |
| 236 | mBufferFilled = 0; |
| 237 | } |
| 238 | |
| 239 | // Fill the rest of the buffer from stream |
| 240 | fl::size spaceAvailable = BUFFER_SIZE - mBufferFilled; |
| 241 | if (spaceAvailable > 0 && mStream && mStream->available(1)) { |
| 242 | fl::size bytesRead = mStream->read(mBuffer.data() + mBufferFilled, spaceAvailable); |
| 243 | mBufferFilled += bytesRead; |
| 244 | return bytesRead > 0; |
| 245 | } |
| 246 | |
| 247 | return mBufferFilled > mBufferPos; |
| 248 | } |
| 249 | |
| 250 | bool Mp3StreamDecoderImpl::findAndDecodeFrame(audio::Sample* out_sample) { |
| 251 | if (!mDecoder) { |