encoder/*: use std::byte instead of uint8_t
This commit is contained in:
parent
c34f6ed8c0
commit
53acf7ae82
@ -27,7 +27,7 @@ EncoderToOutputStream(OutputStream &os, Encoder &encoder)
|
|||||||
while (true) {
|
while (true) {
|
||||||
/* read from the encoder */
|
/* read from the encoder */
|
||||||
|
|
||||||
char buffer[32768];
|
std::byte buffer[32768];
|
||||||
size_t nbytes = encoder.Read(buffer, sizeof(buffer));
|
size_t nbytes = encoder.Read(buffer, sizeof(buffer));
|
||||||
if (nbytes == 0)
|
if (nbytes == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -45,7 +45,7 @@ class FlacEncoder final : public Encoder {
|
|||||||
* This buffer will hold encoded data from libFLAC until it is
|
* This buffer will hold encoded data from libFLAC until it is
|
||||||
* picked up with flac_encoder_read().
|
* picked up with flac_encoder_read().
|
||||||
*/
|
*/
|
||||||
DynamicFifoBuffer<uint8_t> output_buffer;
|
DynamicFifoBuffer<std::byte> output_buffer{8192};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, unsigned _compression, bool _oggflac, bool _oggchaining);
|
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;
|
void Write(const void *data, size_t length) override;
|
||||||
|
|
||||||
size_t Read(void *dest, size_t length) noexcept 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:
|
private:
|
||||||
@ -85,7 +85,7 @@ private:
|
|||||||
[[maybe_unused]] unsigned current_frame,
|
[[maybe_unused]] unsigned current_frame,
|
||||||
void *client_data) noexcept {
|
void *client_data) noexcept {
|
||||||
auto &encoder = *(FlacEncoder *)client_data;
|
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;
|
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)
|
FlacEncoder::FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse, unsigned _compression, bool _oggflac, bool _oggchaining)
|
||||||
:Encoder(_oggchaining),
|
:Encoder(_oggchaining),
|
||||||
audio_format(_audio_format), fse(_fse),
|
audio_format(_audio_format), fse(_fse),
|
||||||
compression(_compression),
|
compression(_compression)
|
||||||
output_buffer(8192)
|
|
||||||
{
|
{
|
||||||
/* this immediately outputs data through callback */
|
/* this immediately outputs data through callback */
|
||||||
|
|
||||||
|
@ -20,23 +20,21 @@
|
|||||||
#include "NullEncoderPlugin.hxx"
|
#include "NullEncoderPlugin.hxx"
|
||||||
#include "../EncoderAPI.hxx"
|
#include "../EncoderAPI.hxx"
|
||||||
#include "util/DynamicFifoBuffer.hxx"
|
#include "util/DynamicFifoBuffer.hxx"
|
||||||
#include "util/Compiler.h"
|
|
||||||
|
|
||||||
class NullEncoder final : public Encoder {
|
class NullEncoder final : public Encoder {
|
||||||
DynamicFifoBuffer<uint8_t> buffer;
|
DynamicFifoBuffer<std::byte> buffer{8192};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NullEncoder()
|
NullEncoder()
|
||||||
:Encoder(false),
|
:Encoder(false) {}
|
||||||
buffer(8192) {}
|
|
||||||
|
|
||||||
/* virtual methods from class Encoder */
|
/* virtual methods from class Encoder */
|
||||||
void Write(const void *data, size_t length) override {
|
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 {
|
size_t Read(void *dest, size_t length) override {
|
||||||
return buffer.Read((uint8_t *)dest, length);
|
return buffer.Read((std::byte *)dest, length);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class OpusEncoder final : public OggEncoder {
|
|||||||
|
|
||||||
const size_t buffer_frames, buffer_size;
|
const size_t buffer_frames, buffer_size;
|
||||||
size_t buffer_position = 0;
|
size_t buffer_position = 0;
|
||||||
uint8_t *const buffer;
|
std::byte *const buffer;
|
||||||
|
|
||||||
::OpusEncoder *const enc;
|
::OpusEncoder *const enc;
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ OpusEncoder::OpusEncoder(AudioFormat &_audio_format, ::OpusEncoder *_enc, bool _
|
|||||||
frame_size(_audio_format.GetFrameSize()),
|
frame_size(_audio_format.GetFrameSize()),
|
||||||
buffer_frames(_audio_format.sample_rate / 50),
|
buffer_frames(_audio_format.sample_rate / 50),
|
||||||
buffer_size(frame_size * buffer_frames),
|
buffer_size(frame_size * buffer_frames),
|
||||||
buffer(new uint8_t[buffer_size]),
|
buffer(new std::byte[buffer_size]),
|
||||||
enc(_enc)
|
enc(_enc)
|
||||||
{
|
{
|
||||||
opus_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&lookahead));
|
opus_encoder_ctl(enc, OPUS_GET_LOOKAHEAD(&lookahead));
|
||||||
@ -274,7 +274,7 @@ OpusEncoder::WriteSilence(unsigned fill_frames)
|
|||||||
void
|
void
|
||||||
OpusEncoder::Write(const void *_data, size_t length)
|
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) {
|
if (lookahead > 0) {
|
||||||
/* generate some silence at the beginning of the
|
/* generate some silence at the beginning of the
|
||||||
|
@ -44,15 +44,15 @@ class ShineEncoder final : public Encoder {
|
|||||||
|
|
||||||
int16_t *stereo[CHANNELS];
|
int16_t *stereo[CHANNELS];
|
||||||
|
|
||||||
DynamicFifoBuffer<uint8_t> output_buffer;
|
DynamicFifoBuffer<std::byte> output_buffer{BUFFER_INIT_SIZE};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ShineEncoder(AudioFormat _audio_format, shine_t _shine) noexcept
|
ShineEncoder(AudioFormat _audio_format, shine_t _shine) noexcept
|
||||||
:Encoder(false),
|
:Encoder(false),
|
||||||
audio_format(_audio_format), shine(_shine),
|
audio_format(_audio_format), shine(_shine),
|
||||||
frame_size(shine_samples_per_pass(shine)),
|
frame_size(shine_samples_per_pass(shine)),
|
||||||
stereo{new int16_t[frame_size], new int16_t[frame_size]},
|
stereo{new int16_t[frame_size], new int16_t[frame_size]}
|
||||||
output_buffer(BUFFER_INIT_SIZE) {}
|
{}
|
||||||
|
|
||||||
~ShineEncoder() noexcept override {
|
~ShineEncoder() noexcept override {
|
||||||
if (input_pos > SHINE_MAX_SAMPLES) {
|
if (input_pos > SHINE_MAX_SAMPLES) {
|
||||||
@ -78,7 +78,7 @@ public:
|
|||||||
void Write(const void *data, size_t length) override;
|
void Write(const void *data, size_t length) override;
|
||||||
|
|
||||||
size_t Read(void *dest, size_t length) noexcept 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;
|
int written;
|
||||||
const uint8_t *out =
|
const auto out = (const std::byte *)
|
||||||
shine_encode_buffer(shine, stereo, &written);
|
shine_encode_buffer(shine, stereo, &written);
|
||||||
|
|
||||||
if (written > 0)
|
if (written > 0)
|
||||||
@ -196,7 +196,7 @@ ShineEncoder::Flush()
|
|||||||
WriteChunk(true);
|
WriteChunk(true);
|
||||||
|
|
||||||
int written;
|
int written;
|
||||||
const uint8_t *data = shine_flush(shine, &written);
|
const auto data = (const std::byte *)shine_flush(shine, &written);
|
||||||
|
|
||||||
if (written > 0)
|
if (written > 0)
|
||||||
output_buffer.Append(data, written);
|
output_buffer.Append(data, written);
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
class WaveEncoder final : public Encoder {
|
class WaveEncoder final : public Encoder {
|
||||||
unsigned bits;
|
unsigned bits;
|
||||||
|
|
||||||
DynamicFifoBuffer<uint8_t> buffer;
|
DynamicFifoBuffer<std::byte> buffer{8192};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit WaveEncoder(AudioFormat &audio_format) noexcept;
|
explicit WaveEncoder(AudioFormat &audio_format) noexcept;
|
||||||
@ -39,7 +39,7 @@ public:
|
|||||||
void Write(const void *data, size_t length) override;
|
void Write(const void *data, size_t length) override;
|
||||||
|
|
||||||
size_t Read(void *dest, size_t length) noexcept 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
|
WaveEncoder::WaveEncoder(AudioFormat &audio_format) noexcept
|
||||||
:Encoder(false),
|
:Encoder(false)
|
||||||
buffer(8192)
|
|
||||||
{
|
{
|
||||||
assert(audio_format.IsValid());
|
assert(audio_format.IsValid());
|
||||||
|
|
||||||
@ -186,7 +185,7 @@ pcm24_to_wave(uint8_t *dst8, const uint32_t *src32, size_t length) noexcept
|
|||||||
void
|
void
|
||||||
WaveEncoder::Write(const void *src, size_t length)
|
WaveEncoder::Write(const void *src, size_t length)
|
||||||
{
|
{
|
||||||
uint8_t *dst = buffer.Write(length);
|
std::byte *dst = buffer.Write(length);
|
||||||
|
|
||||||
if (IsLittleEndian()) {
|
if (IsLittleEndian()) {
|
||||||
switch (bits) {
|
switch (bits) {
|
||||||
@ -196,7 +195,8 @@ WaveEncoder::Write(const void *src, size_t length)
|
|||||||
memcpy(dst, src, length);
|
memcpy(dst, src, length);
|
||||||
break;
|
break;
|
||||||
case 24:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -209,7 +209,8 @@ WaveEncoder::Write(const void *src, size_t length)
|
|||||||
(const uint16_t *)src, length);
|
(const uint16_t *)src, length);
|
||||||
break;
|
break;
|
||||||
case 24:
|
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;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
length = pcm32_to_wave((uint32_t *)dst,
|
length = pcm32_to_wave((uint32_t *)dst,
|
||||||
|
Loading…
Reference in New Issue
Block a user