diff options
author | Max Kellermann <max@duempel.org> | 2014-11-11 07:45:31 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-11-11 07:45:31 +0100 |
commit | 4a04f73434ed6953ae1403d6f1eb33a3807e01d7 (patch) | |
tree | 7d46bc50f38374d22bf1495315f5be02b2e221d9 /src/decoder/plugins/OpusDecoderPlugin.cxx | |
parent | 134cb6a0171192b7d621697f84196ce670a3ce21 (diff) | |
download | mpd-4a04f73434ed6953ae1403d6f1eb33a3807e01d7.tar.gz mpd-4a04f73434ed6953ae1403d6f1eb33a3807e01d7.tar.xz mpd-4a04f73434ed6953ae1403d6f1eb33a3807e01d7.zip |
decoder/opus: add constexpr output_buffer_frames
Diffstat (limited to 'src/decoder/plugins/OpusDecoderPlugin.cxx')
-rw-r--r-- | src/decoder/plugins/OpusDecoderPlugin.cxx | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/decoder/plugins/OpusDecoderPlugin.cxx b/src/decoder/plugins/OpusDecoderPlugin.cxx index 97c81984c..9599f7bcf 100644 --- a/src/decoder/plugins/OpusDecoderPlugin.cxx +++ b/src/decoder/plugins/OpusDecoderPlugin.cxx @@ -40,6 +40,12 @@ static constexpr opus_int32 opus_sample_rate = 48000; +/** + * Allocate an output buffer for 16 bit PCM samples big enough to hold + * a quarter second, larger than 120ms required by libopus. + */ +static constexpr unsigned opus_output_buffer_frames = opus_sample_rate / 4; + gcc_pure static bool IsOpusHead(const ogg_packet &packet) @@ -70,7 +76,6 @@ class MPDOpusDecoder { OpusDecoder *opus_decoder; opus_int16 *output_buffer; - unsigned output_size; bool os_initialized; bool found_opus; @@ -86,7 +91,7 @@ public: InputStream &_input_stream) :decoder(_decoder), input_stream(_input_stream), opus_decoder(nullptr), - output_buffer(nullptr), output_size(0), + output_buffer(nullptr), os_initialized(false), found_opus(false) {} ~MPDOpusDecoder(); @@ -264,11 +269,8 @@ MPDOpusDecoder::HandleBOS(const ogg_packet &packet) eos_granulepos > 0, duration); frame_size = audio_format.GetFrameSize(); - /* allocate an output buffer for 16 bit PCM samples big enough - to hold a quarter second, larger than 120ms required by - libopus */ - output_size = audio_format.sample_rate / 4; - output_buffer = new opus_int16[output_size * audio_format.channels]; + output_buffer = new opus_int16[opus_output_buffer_frames + * audio_format.channels]; return decoder_get_command(decoder); } @@ -304,7 +306,7 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet) int nframes = opus_decode(opus_decoder, (const unsigned char*)packet.packet, packet.bytes, - output_buffer, output_size, + output_buffer, opus_output_buffer_frames, 0); if (nframes < 0) { LogError(opus_domain, opus_strerror(nframes)); |