57 constexpr size_t chunkBytes = 10 * 1024 * 1024;
58 if (bytesPerFrame == 0)
61 const uint64_t chunkFrames =
std::max<uint64_t>(1, chunkBytes / bytesPerFrame);
66 uint64_t totalFramesRead = 0;
67 while (totalFramesRead < declaredFrameCount) {
68 const uint64_t framesToRead =
69 std::min(chunkFrames, declaredFrameCount - totalFramesRead);
70 const uint64_t bytesToRead = framesToRead * bytesPerFrame;
71 const qsizetype oldSize = result.size();
72 if (bytesToRead > uint64_t(QByteArray::maxSize() - oldSize))
75 result.resizeForOverwrite(oldSize + qsizetype(bytesToRead));
76 const uint64_t framesRead = readFrames(framesToRead, result.data() + oldSize);
77 Q_ASSERT(framesRead <= framesToRead);
78 result.resize(oldSize + qsizetype(framesRead * bytesPerFrame));
80 totalFramesRead += framesRead;
81 if (framesRead < framesToRead)
84 if (totalFramesRead != declaredFrameCount)
88 QT_CATCH(
const std::bad_alloc &)
96class QDrWavAudioDecoder
final :
public QPlatformAudioDecoder
124 using QDrWavDecodeResult = QtMultimediaPrivate::QDrWavDecodeResult;
126 QDrWavDecodeResult loadAndDecodeFile(
const QUrl &, QIODevice *,
const QAudioFormat &,
127 std::shared_ptr<
std::atomic_bool> decodingStopped);
130 void onDecodeFinished(QDrWavDecodeResult,
const std::atomic_bool &decodingStopped);
133 QIODevice *m_sourceDevice =
nullptr;
134 QAudioFormat m_audioFormat;
137 QAudioBuffer m_buffer;
139 std::shared_ptr<
std::atomic_bool> m_decodingStopped;