From 53acf7ae8250950418556b7a36cc98f15090933e Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 11 Jul 2022 22:30:04 +0200 Subject: [PATCH] encoder/*: use std::byte instead of uint8_t --- src/encoder/ToOutputStream.cxx | 2 +- src/encoder/plugins/FlacEncoderPlugin.cxx | 9 ++++----- src/encoder/plugins/NullEncoderPlugin.cxx | 10 ++++------ src/encoder/plugins/OpusEncoderPlugin.cxx | 6 +++--- src/encoder/plugins/ShineEncoderPlugin.cxx | 12 ++++++------ src/encoder/plugins/WaveEncoderPlugin.cxx | 15 ++++++++------- 6 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/encoder/ToOutputStream.cxx b/src/encoder/ToOutputStream.cxx index a30d67291..0926f45cc 100644 --- a/src/encoder/ToOutputStream.cxx +++ b/src/encoder/ToOutputStream.cxx @@ -27,7 +27,7 @@ EncoderToOutputStream(OutputStream &os, Encoder &encoder) while (true) { /* read from the encoder */ - char buffer[32768]; + std::byte buffer[32768]; size_t nbytes = encoder.Read(buffer, sizeof(buffer)); if (nbytes == 0) return; diff --git a/src/encoder/plugins/FlacEncoderPlugin.cxx b/src/encoder/plugins/FlacEncoderPlugin.cxx index d55715db5..d40a05295 100644 --- a/src/encoder/plugins/FlacEncoderPlugin.cxx +++ b/src/encoder/plugins/FlacEncoderPlugin.cxx @@ -45,7 +45,7 @@ class FlacEncoder final : public Encoder { * This buffer will hold encoded data from libFLAC until it is * picked up with flac_encoder_read(). */ - DynamicFifoBuffer output_buffer; + DynamicFifoBuffer output_buffer{8192}; public: FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, unsigned _compression, bool _oggflac, bool _oggchaining); @@ -74,7 +74,7 @@ public: void Write(const void *data, size_t length) override; size_t Read(void *dest, size_t length) noexcept override { - return output_buffer.Read((uint8_t *)dest, length); + return output_buffer.Read((std::byte *)dest, length); } private: @@ -85,7 +85,7 @@ private: [[maybe_unused]] unsigned current_frame, void *client_data) noexcept { auto &encoder = *(FlacEncoder *)client_data; - encoder.output_buffer.Append((const uint8_t *)data, bytes); + encoder.output_buffer.Append((const std::byte *)data, bytes); return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; } }; @@ -165,8 +165,7 @@ flac_encoder_setup(FLAC__StreamEncoder *fse, unsigned compression, FlacEncoder::FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, unsigned _compression, bool _oggflac, bool _oggchaining) :Encoder(_oggchaining), audio_format(_audio_format), fse(_fse), - compression(_compression), - output_buffer(8192) + compression(_compression) { /* this immediately outputs data through callback */ diff --git a/src/encoder/plugins/NullEncoderPlugin.cxx b/src/encoder/plugins/NullEncoderPlugin.cxx index 2486629c4..dd44fe276 100644 --- a/src/encoder/plugins/NullEncoderPlugin.cxx +++ b/src/encoder/plugins/NullEncoderPlugin.cxx @@ -20,23 +20,21 @@ #include "NullEncoderPlugin.hxx" #include "../EncoderAPI.hxx" #include "util/DynamicFifoBuffer.hxx" -#include "util/Compiler.h" class NullEncoder final : public Encoder { - DynamicFifoBuffer buffer; + DynamicFifoBuffer buffer{8192}; public: NullEncoder() - :Encoder(false), - buffer(8192) {} + :Encoder(false) {} /* virtual methods from class Encoder */ void Write(const void *data, size_t length) override { - buffer.Append((const uint8_t *)data, length); + buffer.Append((const std::byte *)data, length); } size_t Read(void *dest, size_t length) override { - return buffer.Read((uint8_t *)dest, length); + return buffer.Read((std::byte *)dest, length); } }; diff --git a/src/encoder/plugins/OpusEncoderPlugin.cxx b/src/encoder/plugins/OpusEncoderPlugin.cxx index 3df05c9f9..24eacda0f 100644 --- a/src/encoder/plugins/OpusEncoderPlugin.cxx +++ b/src/encoder/plugins/OpusEncoderPlugin.cxx @@ -40,7 +40,7 @@ class OpusEncoder final : public OggEncoder { const size_t buffer_frames, buffer_size; size_t buffer_position = 0; - uint8_t *const buffer; + std::byte *const buffer; ::OpusEncoder *const enc; @@ -155,7 +155,7 @@ OpusEncoder::OpusEncoder(AudioFormat &_audio_format, ::OpusEncoder *_enc, bool _ frame_size(_audio_format.GetFrameSize()), buffer_frames(_audio_format.sample_rate / 50), buffer_size(frame_size * buffer_frames), - buffer(new uint8_t[buffer_size]), + buffer(new std::byte[buffer_size]), enc(_enc) { opus_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&lookahead)); @@ -274,7 +274,7 @@ OpusEncoder::WriteSilence(unsigned fill_frames) void OpusEncoder::Write(const void *_data, size_t length) { - const auto *data = (const uint8_t *)_data; + const auto *data = (const std::byte *)_data; if (lookahead > 0) { /* generate some silence at the beginning of the diff --git a/src/encoder/plugins/ShineEncoderPlugin.cxx b/src/encoder/plugins/ShineEncoderPlugin.cxx index 198c49376..b7072238b 100644 --- a/src/encoder/plugins/ShineEncoderPlugin.cxx +++ b/src/encoder/plugins/ShineEncoderPlugin.cxx @@ -44,15 +44,15 @@ class ShineEncoder final : public Encoder { int16_t *stereo[CHANNELS]; - DynamicFifoBuffer output_buffer; + DynamicFifoBuffer output_buffer{BUFFER_INIT_SIZE}; public: ShineEncoder(AudioFormat _audio_format, shine_t _shine) noexcept :Encoder(false), audio_format(_audio_format), shine(_shine), frame_size(shine_samples_per_pass(shine)), - stereo{new int16_t[frame_size], new int16_t[frame_size]}, - output_buffer(BUFFER_INIT_SIZE) {} + stereo{new int16_t[frame_size], new int16_t[frame_size]} + {} ~ShineEncoder() noexcept override { if (input_pos > SHINE_MAX_SAMPLES) { @@ -78,7 +78,7 @@ public: void Write(const void *data, size_t length) override; size_t Read(void *dest, size_t length) noexcept override { - return output_buffer.Read((uint8_t *)dest, length); + return output_buffer.Read((std::byte *)dest, length); } }; @@ -152,7 +152,7 @@ ShineEncoder::WriteChunk(bool flush) } int written; - const uint8_t *out = + const auto out = (const std::byte *) shine_encode_buffer(shine, stereo, &written); if (written > 0) @@ -196,7 +196,7 @@ ShineEncoder::Flush() WriteChunk(true); int written; - const uint8_t *data = shine_flush(shine, &written); + const auto data = (const std::byte *)shine_flush(shine, &written); if (written > 0) output_buffer.Append(data, written); diff --git a/src/encoder/plugins/WaveEncoderPlugin.cxx b/src/encoder/plugins/WaveEncoderPlugin.cxx index 7cb8635da..322e89417 100644 --- a/src/encoder/plugins/WaveEncoderPlugin.cxx +++ b/src/encoder/plugins/WaveEncoderPlugin.cxx @@ -30,7 +30,7 @@ class WaveEncoder final : public Encoder { unsigned bits; - DynamicFifoBuffer buffer; + DynamicFifoBuffer buffer{8192}; public: explicit WaveEncoder(AudioFormat &audio_format) noexcept; @@ -39,7 +39,7 @@ public: void Write(const void *data, size_t length) override; size_t Read(void *dest, size_t length) noexcept override { - return buffer.Read((uint8_t *)dest, length); + return buffer.Read((std::byte *)dest, length); } }; @@ -102,8 +102,7 @@ wave_encoder_init([[maybe_unused]] const ConfigBlock &block) } WaveEncoder::WaveEncoder(AudioFormat &audio_format) noexcept - :Encoder(false), - buffer(8192) + :Encoder(false) { assert(audio_format.IsValid()); @@ -186,7 +185,7 @@ pcm24_to_wave(uint8_t *dst8, const uint32_t *src32, size_t length) noexcept void WaveEncoder::Write(const void *src, size_t length) { - uint8_t *dst = buffer.Write(length); + std::byte *dst = buffer.Write(length); if (IsLittleEndian()) { switch (bits) { @@ -196,7 +195,8 @@ WaveEncoder::Write(const void *src, size_t length) memcpy(dst, src, length); break; case 24: - length = pcm24_to_wave(dst, (const uint32_t *)src, length); + length = pcm24_to_wave((uint8_t *)dst, + (const uint32_t *)src, length); break; } } else { @@ -209,7 +209,8 @@ WaveEncoder::Write(const void *src, size_t length) (const uint16_t *)src, length); break; case 24: - length = pcm24_to_wave(dst, (const uint32_t *)src, length); + length = pcm24_to_wave((uint8_t *)dst, + (const uint32_t *)src, length); break; case 32: length = pcm32_to_wave((uint32_t *)dst,