encoder/*: use std::byte instead of uint8_t

This commit is contained in:
Max Kellermann 2022-07-11 22:30:04 +02:00
parent c34f6ed8c0
commit 53acf7ae82
6 changed files with 26 additions and 28 deletions

View File

@ -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;

View File

@ -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<uint8_t> output_buffer;
DynamicFifoBuffer<std::byte> 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 */

View File

@ -20,23 +20,21 @@
#include "NullEncoderPlugin.hxx"
#include "../EncoderAPI.hxx"
#include "util/DynamicFifoBuffer.hxx"
#include "util/Compiler.h"
class NullEncoder final : public Encoder {
DynamicFifoBuffer<uint8_t> buffer;
DynamicFifoBuffer<std::byte> 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);
}
};

View File

@ -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

View File

@ -44,15 +44,15 @@ class ShineEncoder final : public Encoder {
int16_t *stereo[CHANNELS];
DynamicFifoBuffer<uint8_t> output_buffer;
DynamicFifoBuffer<std::byte> 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);

View File

@ -30,7 +30,7 @@
class WaveEncoder final : public Encoder {
unsigned bits;
DynamicFifoBuffer<uint8_t> buffer;
DynamicFifoBuffer<std::byte> 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,