From 68a2d128cece8ca010c8fc152ae7842ed52fc5ba Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sat, 9 Nov 2024 20:52:20 -0800 Subject: [PATCH] Silence and fix some clang-tidy warnings --- alc/backends/pipewire.cpp | 33 ++++++++++++++++----------------- alc/backends/pulseaudio.cpp | 3 ++- examples/alffplay.cpp | 8 ++++---- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/alc/backends/pipewire.cpp b/alc/backends/pipewire.cpp index 7d3719d6..5d2ce650 100644 --- a/alc/backends/pipewire.cpp +++ b/alc/backends/pipewire.cpp @@ -132,6 +132,9 @@ _Pragma("GCC diagnostic pop") namespace { +template [[nodiscard]] constexpr +auto as_const_ptr(T *ptr) noexcept -> std::add_const_t* { return ptr; } + struct PodDynamicBuilder { private: std::vector mStorage; @@ -152,7 +155,7 @@ private: } public: - PodDynamicBuilder(uint32_t initSize=0) : mStorage(initSize) + PodDynamicBuilder(uint32_t initSize=1024) : mStorage(initSize) , mPod{make_pod_builder(mStorage.data(), initSize)} { static constexpr auto callbacks{[] @@ -411,9 +414,10 @@ struct PwStreamDeleter { }; using PwStreamPtr = std::unique_ptr; -/* Enums for bitflags... again... *sigh* */ +/* NOLINTBEGIN(*EnumCastOutOfRange) Enums for bitflags... again... *sigh* */ constexpr pw_stream_flags operator|(pw_stream_flags lhs, pw_stream_flags rhs) noexcept { return static_cast(lhs | al::to_underlying(rhs)); } +/* NOLINTEND(*EnumCastOutOfRange) */ constexpr pw_stream_flags& operator|=(pw_stream_flags &lhs, pw_stream_flags rhs) noexcept { lhs = lhs | rhs; return lhs; } @@ -1652,12 +1656,10 @@ bool PipeWirePlayback::reset() /* Force planar 32-bit float output for playback. This is what PipeWire * handles internally, and it's easier for us too. */ - spa_audio_info_raw info{make_spa_info(mDevice, is51rear, ForceF32Planar)}; - - static constexpr uint32_t pod_buffer_size{1024}; - PodDynamicBuilder b(pod_buffer_size); + auto info = spa_audio_info_raw{make_spa_info(mDevice, is51rear, ForceF32Planar)}; - const spa_pod *params{spa_format_audio_raw_build(b.get(), SPA_PARAM_EnumFormat, &info)}; + auto b = PodDynamicBuilder{}; + auto params = as_const_ptr(spa_format_audio_raw_build(b.get(), SPA_PARAM_EnumFormat, &info)); if(!params) throw al::backend_exception{al::backend_error::DeviceError, "Failed to set PipeWire audio format parameters"}; @@ -1666,7 +1668,7 @@ bool PipeWirePlayback::reset() * be useful? */ auto&& binary = GetProcBinary(); - const char *appname{binary.fname.length() ? binary.fname.c_str() : "OpenAL Soft"}; + const char *appname{!binary.fname.empty() ? binary.fname.c_str() : "OpenAL Soft"}; pw_properties *props{pw_properties_new(PW_KEY_NODE_NAME, appname, PW_KEY_NODE_DESCRIPTION, appname, PW_KEY_MEDIA_TYPE, "Audio", @@ -2083,19 +2085,16 @@ void PipeWireCapture::open(std::string_view name) if(match != devlist.cend()) is51rear = match->mIs51Rear; } - spa_audio_info_raw info{make_spa_info(mDevice, is51rear, UseDevType)}; + auto info = spa_audio_info_raw{make_spa_info(mDevice, is51rear, UseDevType)}; - static constexpr uint32_t pod_buffer_size{1024}; - PodDynamicBuilder b(pod_buffer_size); - - std::array params{static_cast(spa_format_audio_raw_build(b.get(), - SPA_PARAM_EnumFormat, &info))}; - if(!params[0]) + auto b = PodDynamicBuilder{}; + auto params = as_const_ptr(spa_format_audio_raw_build(b.get(), SPA_PARAM_EnumFormat, &info)); + if(!params) throw al::backend_exception{al::backend_error::DeviceError, "Failed to set PipeWire audio format parameters"}; auto&& binary = GetProcBinary(); - const char *appname{binary.fname.length() ? binary.fname.c_str() : "OpenAL Soft"}; + const char *appname{!binary.fname.empty() ? binary.fname.c_str() : "OpenAL Soft"}; pw_properties *props{pw_properties_new( PW_KEY_NODE_NAME, appname, PW_KEY_NODE_DESCRIPTION, appname, @@ -2131,7 +2130,7 @@ void PipeWireCapture::open(std::string_view name) constexpr pw_stream_flags Flags{PW_STREAM_FLAG_AUTOCONNECT | PW_STREAM_FLAG_INACTIVE | PW_STREAM_FLAG_MAP_BUFFERS | PW_STREAM_FLAG_RT_PROCESS}; - if(int res{pw_stream_connect(mStream.get(), PW_DIRECTION_INPUT, PwIdAny, Flags, params.data(), 1)}) + if(int res{pw_stream_connect(mStream.get(), PW_DIRECTION_INPUT, PwIdAny, Flags, ¶ms, 1)}) throw al::backend_exception{al::backend_error::DeviceError, "Error connecting PipeWire stream (res: %d)", res}; diff --git a/alc/backends/pulseaudio.cpp b/alc/backends/pulseaudio.cpp index 51d8fda3..1cceea51 100644 --- a/alc/backends/pulseaudio.cpp +++ b/alc/backends/pulseaudio.cpp @@ -252,7 +252,7 @@ constexpr pa_channel_map MonoChanMap{ }; -/* *grumble* Don't use enums for bitflags. */ +/* NOLINTBEGIN(*EnumCastOutOfRange) *grumble* Don't use enums for bitflags. */ constexpr pa_stream_flags_t operator|(pa_stream_flags_t lhs, pa_stream_flags_t rhs) { return pa_stream_flags_t(lhs | al::to_underlying(rhs)); } constexpr pa_stream_flags_t& operator|=(pa_stream_flags_t &lhs, pa_stream_flags_t rhs) @@ -278,6 +278,7 @@ constexpr pa_context_flags_t& operator|=(pa_context_flags_t &lhs, pa_context_fla constexpr pa_subscription_mask_t operator|(pa_subscription_mask_t lhs, pa_subscription_mask_t rhs) { return pa_subscription_mask_t(lhs | al::to_underlying(rhs)); } +/* NOLINTEND(*EnumCastOutOfRange) */ struct DevMap { diff --git a/examples/alffplay.cpp b/examples/alffplay.cpp index 0a4560ee..4f89ff58 100644 --- a/examples/alffplay.cpp +++ b/examples/alffplay.cpp @@ -342,7 +342,7 @@ struct AudioState { if(mBuffers[0]) alDeleteBuffers(static_cast(mBuffers.size()), mBuffers.data()); - av_freep(mSamples.data()); + av_freep(static_cast(mSamples.data())); } static void AL_APIENTRY eventCallbackC(ALenum eventType, ALuint object, ALuint param, @@ -682,7 +682,7 @@ int AudioState::decodeFrame() if(mDecodedFrame->nb_samples > mSamplesMax) { - av_freep(mSamples.data()); + av_freep(static_cast(mSamples.data())); av_samples_alloc(mSamples.data(), nullptr, mCodecCtx->ch_layout.nb_channels, mDecodedFrame->nb_samples, mDstSampleFmt, 0); mSamplesMax = mDecodedFrame->nb_samples; @@ -1276,7 +1276,7 @@ int AudioState::handler() if(ret == AVErrorEOF) break; } }; - auto sender = std::async(std::launch::async, packet_sender); + auto sender [[maybe_unused]] = std::async(std::launch::async, packet_sender); srclock.lock(); if(alcGetInteger64vSOFT) @@ -1613,7 +1613,7 @@ int VideoState::handler() if(ret == AVErrorEOF) break; } }; - auto sender = std::async(std::launch::async, packet_sender); + auto sender [[maybe_unused]] = std::async(std::launch::async, packet_sender); { std::lock_guard displock{mDispPtsMutex}; -- 2.11.4.GIT