Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarAudio.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-07-29 09:23:27 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2024-07-29 09:23:27 +1000
commite9e87a1c3c74e503d00e5166f91f0b4c81c66e07 (patch)
treed1430ef04d45f56be84f32087ed8e311d51b009d /source/core/StarAudio.cpp
parent8b1a2d6f0c9a1592a5c550ab23f6bf949ce65fc4 (diff)
Avoid crashing when a OGG file is broken (thanks to @kblaschke !)
Also added a name tag to Audio for logging so that it's easier to find the audio asset that's causing it
Diffstat (limited to 'source/core/StarAudio.cpp')
-rw-r--r--source/core/StarAudio.cpp21
1 files changed, 16 insertions, 5 deletions
diff --git a/source/core/StarAudio.cpp b/source/core/StarAudio.cpp
index 2dfdaee..a1f2e62 100644
--- a/source/core/StarAudio.cpp
+++ b/source/core/StarAudio.cpp
@@ -239,17 +239,19 @@ public:
size_t readPartial(int16_t* buffer, size_t bufferSize) {
int bitstream;
- int read;
+ int read = OV_HOLE;
// ov_read takes int parameter, so do some magic here to make sure we don't
// overflow
bufferSize *= 2;
+ do {
#if STAR_LITTLE_ENDIAN
- read = ov_read(&m_vorbisFile, (char*)buffer, bufferSize, 0, 2, 1, &bitstream);
+ read = ov_read(&m_vorbisFile, (char*)buffer, bufferSize, 0, 2, 1, &bitstream);
#else
- read = ov_read(&m_vorbisFile, (char*)buffer, bufferSize, 1, 2, 1, &bitstream);
+ read = ov_read(&m_vorbisFile, (char*)buffer, bufferSize, 1, 2, 1, &bitstream);
#endif
+ } while (read == OV_HOLE);
if (read < 0)
- throw AudioException("Error in Audio::read");
+ throw AudioException::format("Error in Audio::read ({})", read);
// read in bytes, returning number of int16_t samples.
return read / 2;
@@ -349,7 +351,8 @@ private:
ExternalBuffer m_memoryFile;
};
-Audio::Audio(IODevicePtr device) {
+Audio::Audio(IODevicePtr device, String name) {
+ m_name = name;
if (!device->isOpen())
device->open(IOMode::Read);
@@ -579,4 +582,12 @@ size_t Audio::resample(unsigned destinationChannels, unsigned destinationSampleR
}
}
+String const& Audio::name() const {
+ return m_name;
+}
+
+void Audio::setName(String name) {
+ m_name = std::move(name);
+}
+
}