Commit 67a8eedc authored by Max Kellermann's avatar Max Kellermann

output/ao: round write_size down to a multiple of the frame size

parent be65c7d5
...@@ -13,6 +13,7 @@ ver 0.21 (not yet released) ...@@ -13,6 +13,7 @@ ver 0.21 (not yet released)
* output * output
- alsa: non-blocking mode - alsa: non-blocking mode
- alsa: change "dop" and "allowed_formats" settings at runtime - alsa: change "dop" and "allowed_formats" settings at runtime
- ao: fix crash bug due to partial frames
- shout: support the Shine encoder plugin - shout: support the Shine encoder plugin
- sndio: remove support for the broken RoarAudio sndio emulation - sndio: remove support for the broken RoarAudio sndio emulation
* mixer * mixer
......
...@@ -52,6 +52,8 @@ class AoOutput final : AudioOutput, SafeSingleton<AoInit> { ...@@ -52,6 +52,8 @@ class AoOutput final : AudioOutput, SafeSingleton<AoInit> {
ao_option *options = nullptr; ao_option *options = nullptr;
ao_device *device; ao_device *device;
size_t frame_size;
AoOutput(const ConfigBlock &block); AoOutput(const ConfigBlock &block);
~AoOutput(); ~AoOutput();
...@@ -162,6 +164,8 @@ AoOutput::Open(AudioFormat &audio_format) ...@@ -162,6 +164,8 @@ AoOutput::Open(AudioFormat &audio_format)
break; break;
} }
frame_size = audio_format.GetFrameSize();
format.rate = audio_format.sample_rate; format.rate = audio_format.sample_rate;
format.byte_format = AO_FMT_NATIVE; format.byte_format = AO_FMT_NATIVE;
format.channels = audio_format.channels; format.channels = audio_format.channels;
...@@ -180,8 +184,18 @@ AoOutput::Close() noexcept ...@@ -180,8 +184,18 @@ AoOutput::Close() noexcept
size_t size_t
AoOutput::Play(const void *chunk, size_t size) AoOutput::Play(const void *chunk, size_t size)
{ {
if (size > write_size) assert(size % frame_size == 0);
size = write_size;
if (size > write_size) {
/* round down to a multiple of the frame size */
size = (write_size / frame_size) * frame_size;
if (size < frame_size)
/* no matter how small "write_size" was
configured, we must pass at least one frame
to libao */
size = frame_size;
}
/* For whatever reason, libao wants a non-const pointer. /* For whatever reason, libao wants a non-const pointer.
Let's hope it does not write to the buffer, and use the Let's hope it does not write to the buffer, and use the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment