From 8480b834b3fb4b1b82b3ccf0147e71468dbc8198 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 4 Jul 2019 22:44:36 +0200 Subject: [PATCH] encoder/Interface: add `noexcept` --- src/encoder/EncoderInterface.hxx | 10 +++++----- src/encoder/plugins/FlacEncoderPlugin.cxx | 12 ++++++------ src/encoder/plugins/LameEncoderPlugin.cxx | 12 ++++++------ src/encoder/plugins/OggEncoder.hxx | 2 +- src/encoder/plugins/OpusEncoderPlugin.cxx | 18 +++++++++--------- src/encoder/plugins/ShineEncoderPlugin.cxx | 8 ++++---- src/encoder/plugins/TwolameEncoderPlugin.cxx | 10 +++++----- src/encoder/plugins/VorbisEncoderPlugin.cxx | 4 ++-- src/encoder/plugins/WaveEncoderPlugin.cxx | 14 +++++++------- 9 files changed, 45 insertions(+), 45 deletions(-) diff --git a/src/encoder/EncoderInterface.hxx b/src/encoder/EncoderInterface.hxx index aab9f0b54..a676d8907 100644 --- a/src/encoder/EncoderInterface.hxx +++ b/src/encoder/EncoderInterface.hxx @@ -33,11 +33,11 @@ class Encoder { const bool implements_tag; public: - explicit Encoder(bool _implements_tag) + explicit Encoder(bool _implements_tag) noexcept :implements_tag(_implements_tag) {} - virtual ~Encoder() {} + virtual ~Encoder() noexcept {} - bool ImplementsTag() const { + bool ImplementsTag() const noexcept { return implements_tag; } @@ -111,7 +111,7 @@ public: class PreparedEncoder { public: - virtual ~PreparedEncoder() {} + virtual ~PreparedEncoder() noexcept {} /** * Opens the object. You must call this prior to using it. @@ -134,7 +134,7 @@ public: * * @return an constant string, nullptr on failure */ - virtual const char *GetMimeType() const { + virtual const char *GetMimeType() const noexcept { return nullptr; } }; diff --git a/src/encoder/plugins/FlacEncoderPlugin.cxx b/src/encoder/plugins/FlacEncoderPlugin.cxx index 6fdf7bf56..c42b6df50 100644 --- a/src/encoder/plugins/FlacEncoderPlugin.cxx +++ b/src/encoder/plugins/FlacEncoderPlugin.cxx @@ -47,7 +47,7 @@ class FlacEncoder final : public Encoder { public: FlacEncoder(AudioFormat _audio_format, FLAC__StreamEncoder *_fse); - ~FlacEncoder() override { + ~FlacEncoder() noexcept override { FLAC__stream_encoder_delete(fse); } @@ -62,7 +62,7 @@ public: void Write(const void *data, size_t length) override; - size_t Read(void *dest, size_t length) override { + size_t Read(void *dest, size_t length) noexcept override { return output_buffer.Read((uint8_t *)dest, length); } @@ -72,7 +72,7 @@ private: size_t bytes, gcc_unused unsigned samples, gcc_unused unsigned current_frame, - void *client_data) { + void *client_data) noexcept { auto &encoder = *(FlacEncoder *)client_data; encoder.output_buffer.Append((const uint8_t *)data, bytes); return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; @@ -88,7 +88,7 @@ public: /* virtual methods from class PreparedEncoder */ Encoder *Open(AudioFormat &audio_format) override; - const char *GetMimeType() const override { + const char *GetMimeType() const noexcept override { return "audio/flac"; } }; @@ -185,7 +185,7 @@ PreparedFlacEncoder::Open(AudioFormat &audio_format) } static inline void -pcm8_to_flac(int32_t *out, const int8_t *in, unsigned num_samples) +pcm8_to_flac(int32_t *out, const int8_t *in, unsigned num_samples) noexcept { while (num_samples > 0) { *out++ = *in++; @@ -194,7 +194,7 @@ pcm8_to_flac(int32_t *out, const int8_t *in, unsigned num_samples) } static inline void -pcm16_to_flac(int32_t *out, const int16_t *in, unsigned num_samples) +pcm16_to_flac(int32_t *out, const int16_t *in, unsigned num_samples) noexcept { while (num_samples > 0) { *out++ = *in++; diff --git a/src/encoder/plugins/LameEncoderPlugin.cxx b/src/encoder/plugins/LameEncoderPlugin.cxx index 18f615f63..8bbab6504 100644 --- a/src/encoder/plugins/LameEncoderPlugin.cxx +++ b/src/encoder/plugins/LameEncoderPlugin.cxx @@ -42,15 +42,15 @@ class LameEncoder final : public Encoder { public: LameEncoder(const AudioFormat _audio_format, - lame_global_flags *_gfp) + lame_global_flags *_gfp) noexcept :Encoder(false), audio_format(_audio_format), gfp(_gfp) {} - ~LameEncoder() override; + ~LameEncoder() noexcept override; /* virtual methods from class Encoder */ void Write(const void *data, size_t length) override; - size_t Read(void *dest, size_t length) override; + size_t Read(void *dest, size_t length) noexcept override; }; class PreparedLameEncoder final : public PreparedEncoder { @@ -63,7 +63,7 @@ public: /* virtual methods from class PreparedEncoder */ Encoder *Open(AudioFormat &audio_format) override; - const char *GetMimeType() const override { + const char *GetMimeType() const noexcept override { return "audio/mpeg"; } }; @@ -159,7 +159,7 @@ PreparedLameEncoder::Open(AudioFormat &audio_format) return new LameEncoder(audio_format, gfp); } -LameEncoder::~LameEncoder() +LameEncoder::~LameEncoder() noexcept { lame_close(gfp); } @@ -193,7 +193,7 @@ LameEncoder::Write(const void *data, size_t length) } size_t -LameEncoder::Read(void *dest, size_t length) +LameEncoder::Read(void *dest, size_t length) noexcept { const auto begin = output_begin; assert(begin <= output_end); diff --git a/src/encoder/plugins/OggEncoder.hxx b/src/encoder/plugins/OggEncoder.hxx index c17516e35..eeaa2ae1d 100644 --- a/src/encoder/plugins/OggEncoder.hxx +++ b/src/encoder/plugins/OggEncoder.hxx @@ -50,7 +50,7 @@ public: flush = true; } - size_t Read(void *dest, size_t length) override { + size_t Read(void *dest, size_t length) noexcept override { ogg_page page; bool success = stream.PageOut(page); if (!success) { diff --git a/src/encoder/plugins/OpusEncoderPlugin.cxx b/src/encoder/plugins/OpusEncoderPlugin.cxx index b94bd2495..472f954f2 100644 --- a/src/encoder/plugins/OpusEncoderPlugin.cxx +++ b/src/encoder/plugins/OpusEncoderPlugin.cxx @@ -55,7 +55,7 @@ class OpusEncoder final : public OggEncoder { public: OpusEncoder(AudioFormat &_audio_format, ::OpusEncoder *_enc, bool _chaining); - ~OpusEncoder() override; + ~OpusEncoder() noexcept override; /* virtual methods from class Encoder */ void End() override; @@ -68,9 +68,9 @@ private: void DoEncode(bool eos); void WriteSilence(unsigned fill_frames); - void GenerateHeaders(const Tag *tag); - void GenerateHead(); - void GenerateTags(const Tag *tag); + void GenerateHeaders(const Tag *tag) noexcept; + void GenerateHead() noexcept; + void GenerateTags(const Tag *tag) noexcept; }; class PreparedOpusEncoder final : public PreparedEncoder { @@ -85,7 +85,7 @@ public: /* virtual methods from class PreparedEncoder */ Encoder *Open(AudioFormat &audio_format) override; - const char *GetMimeType() const override { + const char *GetMimeType() const noexcept override { return "audio/ogg"; } }; @@ -178,7 +178,7 @@ PreparedOpusEncoder::Open(AudioFormat &audio_format) return new OpusEncoder(audio_format, enc, chaining); } -OpusEncoder::~OpusEncoder() +OpusEncoder::~OpusEncoder() noexcept { delete[] buffer; opus_encoder_destroy(enc); @@ -277,14 +277,14 @@ OpusEncoder::Write(const void *_data, size_t length) } void -OpusEncoder::GenerateHeaders(const Tag *tag) +OpusEncoder::GenerateHeaders(const Tag *tag) noexcept { GenerateHead(); GenerateTags(tag); } void -OpusEncoder::GenerateHead() +OpusEncoder::GenerateHead() noexcept { unsigned char header[19]; memcpy(header, "OpusHead", 8); @@ -308,7 +308,7 @@ OpusEncoder::GenerateHead() } void -OpusEncoder::GenerateTags(const Tag *tag) +OpusEncoder::GenerateTags(const Tag *tag) noexcept { const char *version = opus_get_version_string(); size_t version_length = strlen(version); diff --git a/src/encoder/plugins/ShineEncoderPlugin.cxx b/src/encoder/plugins/ShineEncoderPlugin.cxx index 9eb098e98..eaf9d48fd 100644 --- a/src/encoder/plugins/ShineEncoderPlugin.cxx +++ b/src/encoder/plugins/ShineEncoderPlugin.cxx @@ -48,14 +48,14 @@ class ShineEncoder final : public Encoder { DynamicFifoBuffer output_buffer; public: - ShineEncoder(AudioFormat _audio_format, shine_t _shine) + 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) {} - ~ShineEncoder() override { + ~ShineEncoder() noexcept override { if (input_pos > SHINE_MAX_SAMPLES) { /* write zero chunk */ input_pos = 0; @@ -78,7 +78,7 @@ public: void Write(const void *data, size_t length) override; - size_t Read(void *dest, size_t length) override { + size_t Read(void *dest, size_t length) noexcept override { return output_buffer.Read((uint8_t *)dest, length); } }; @@ -92,7 +92,7 @@ public: /* virtual methods from class PreparedEncoder */ Encoder *Open(AudioFormat &audio_format) override; - const char *GetMimeType() const override { + const char *GetMimeType() const noexcept override { return "audio/mpeg"; } }; diff --git a/src/encoder/plugins/TwolameEncoderPlugin.cxx b/src/encoder/plugins/TwolameEncoderPlugin.cxx index 456b89b57..496c6f79a 100644 --- a/src/encoder/plugins/TwolameEncoderPlugin.cxx +++ b/src/encoder/plugins/TwolameEncoderPlugin.cxx @@ -53,7 +53,7 @@ public: twolame_options *_options) :Encoder(false), audio_format(_audio_format), options(_options) {} - ~TwolameEncoder() override; + ~TwolameEncoder() noexcept override; /* virtual methods from class Encoder */ @@ -66,7 +66,7 @@ public: } void Write(const void *data, size_t length) override; - size_t Read(void *dest, size_t length) override; + size_t Read(void *dest, size_t length) noexcept override; }; class PreparedTwolameEncoder final : public PreparedEncoder { @@ -79,7 +79,7 @@ public: /* virtual methods from class PreparedEncoder */ Encoder *Open(AudioFormat &audio_format) override; - const char *GetMimeType() const override { + const char *GetMimeType() const noexcept override { return "audio/mpeg"; } }; @@ -179,7 +179,7 @@ PreparedTwolameEncoder::Open(AudioFormat &audio_format) return new TwolameEncoder(audio_format, options); } -TwolameEncoder::~TwolameEncoder() +TwolameEncoder::~TwolameEncoder() noexcept { twolame_close(&options); } @@ -205,7 +205,7 @@ TwolameEncoder::Write(const void *data, size_t length) } size_t -TwolameEncoder::Read(void *dest, size_t length) +TwolameEncoder::Read(void *dest, size_t length) noexcept { assert(output_buffer_position <= output_buffer_length); diff --git a/src/encoder/plugins/VorbisEncoderPlugin.cxx b/src/encoder/plugins/VorbisEncoderPlugin.cxx index ce7153763..ff1d3428c 100644 --- a/src/encoder/plugins/VorbisEncoderPlugin.cxx +++ b/src/encoder/plugins/VorbisEncoderPlugin.cxx @@ -38,7 +38,7 @@ class VorbisEncoder final : public OggEncoder { public: VorbisEncoder(float quality, int bitrate, AudioFormat &_audio_format); - virtual ~VorbisEncoder() { + ~VorbisEncoder() noexcept override { vorbis_block_clear(&vb); vorbis_dsp_clear(&vd); vorbis_info_clear(&vi); @@ -70,7 +70,7 @@ public: /* virtual methods from class PreparedEncoder */ Encoder *Open(AudioFormat &audio_format) override; - const char *GetMimeType() const override { + const char *GetMimeType() const noexcept override { return "audio/ogg"; } }; diff --git a/src/encoder/plugins/WaveEncoderPlugin.cxx b/src/encoder/plugins/WaveEncoderPlugin.cxx index 1fe270fc5..11883ef64 100644 --- a/src/encoder/plugins/WaveEncoderPlugin.cxx +++ b/src/encoder/plugins/WaveEncoderPlugin.cxx @@ -33,12 +33,12 @@ class WaveEncoder final : public Encoder { DynamicFifoBuffer buffer; public: - WaveEncoder(AudioFormat &audio_format); + WaveEncoder(AudioFormat &audio_format) noexcept; /* virtual methods from class Encoder */ void Write(const void *data, size_t length) override; - size_t Read(void *dest, size_t length) override { + size_t Read(void *dest, size_t length) noexcept override { return buffer.Read((uint8_t *)dest, length); } }; @@ -49,7 +49,7 @@ class PreparedWaveEncoder final : public PreparedEncoder { return new WaveEncoder(audio_format); } - const char *GetMimeType() const override { + const char *GetMimeType() const noexcept override { return "audio/wav"; } }; @@ -72,7 +72,7 @@ struct WaveHeader { static void fill_wave_header(WaveHeader *header, int channels, int bits, - int freq, int block_size) + int freq, int block_size) noexcept { int data_size = 0x0FFFFFFF; @@ -102,7 +102,7 @@ wave_encoder_init(gcc_unused const ConfigBlock &block) return new PreparedWaveEncoder(); } -WaveEncoder::WaveEncoder(AudioFormat &audio_format) +WaveEncoder::WaveEncoder(AudioFormat &audio_format) noexcept :Encoder(false), buffer(8192) { @@ -157,7 +157,7 @@ pcm16_to_wave(uint16_t *dst16, const uint16_t *src16, size_t length) } static size_t -pcm32_to_wave(uint32_t *dst32, const uint32_t *src32, size_t length) +pcm32_to_wave(uint32_t *dst32, const uint32_t *src32, size_t length) noexcept { size_t cnt = length >> 2; while (cnt > 0){ @@ -168,7 +168,7 @@ pcm32_to_wave(uint32_t *dst32, const uint32_t *src32, size_t length) } static size_t -pcm24_to_wave(uint8_t *dst8, const uint32_t *src32, size_t length) +pcm24_to_wave(uint8_t *dst8, const uint32_t *src32, size_t length) noexcept { uint32_t value; uint8_t *dst_old = dst8;