Skip to content

Commit

Permalink
Silence and fix some clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
kcat committed Nov 10, 2024
1 parent 6127f3c commit 68a2d12
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
33 changes: 16 additions & 17 deletions alc/backends/pipewire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ _Pragma("GCC diagnostic pop")

namespace {

template<typename T> [[nodiscard]] constexpr
auto as_const_ptr(T *ptr) noexcept -> std::add_const_t<T>* { return ptr; }

struct PodDynamicBuilder {
private:
std::vector<std::byte> mStorage;
Expand All @@ -152,7 +155,7 @@ struct PodDynamicBuilder {
}

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{[]
Expand Down Expand Up @@ -411,9 +414,10 @@ struct PwStreamDeleter {
};
using PwStreamPtr = std::unique_ptr<pw_stream,PwStreamDeleter>;

/* 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<pw_stream_flags>(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; }
Expand Down Expand Up @@ -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"};
Expand All @@ -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",
Expand Down Expand Up @@ -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<const spa_pod*>(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,
Expand Down Expand Up @@ -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, &params, 1)})
throw al::backend_exception{al::backend_error::DeviceError,
"Error connecting PipeWire stream (res: %d)", res};

Expand Down
3 changes: 2 additions & 1 deletion alc/backends/pulseaudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions examples/alffplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ struct AudioState {
if(mBuffers[0])
alDeleteBuffers(static_cast<ALsizei>(mBuffers.size()), mBuffers.data());

av_freep(mSamples.data());
av_freep(static_cast<void*>(mSamples.data()));
}

static void AL_APIENTRY eventCallbackC(ALenum eventType, ALuint object, ALuint param,
Expand Down Expand Up @@ -682,7 +682,7 @@ int AudioState::decodeFrame()

if(mDecodedFrame->nb_samples > mSamplesMax)
{
av_freep(mSamples.data());
av_freep(static_cast<void*>(mSamples.data()));
av_samples_alloc(mSamples.data(), nullptr, mCodecCtx->ch_layout.nb_channels,
mDecodedFrame->nb_samples, mDstSampleFmt, 0);
mSamplesMax = mDecodedFrame->nb_samples;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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<std::mutex> displock{mDispPtsMutex};
Expand Down

0 comments on commit 68a2d12

Please sign in to comment.