Fix cast warnings with MSVC

This commit is contained in:
Jonas Kvinge
2025-03-25 00:37:07 +01:00
parent d5281abb22
commit 5e031be42c
59 changed files with 207 additions and 207 deletions

View File

@@ -8,6 +8,9 @@
#include <wrl.h>
#include <windows.foundation.h>
#pragma warning(push)
#pragma warning(disable : 4100)
// eg. TOperation = IAsyncOperationWithProgress<UINT32, UINT32>
// eg. THandler = IAsyncOperationWithProgressCompletedHandler<UINT, UINT>
template<typename TOperation, typename THandler>
@@ -83,3 +86,5 @@ template<typename TResult, typename TProgress>
HRESULT SyncWait(_In_ ABI::Windows::Foundation::IAsyncOperationWithProgress<TResult, TProgress> *pOperation, _In_ DWORD dwMilliseconds = INFINITE) {
return SyncWait<ABI::Windows::Foundation::IAsyncOperationWithProgress<TResult, TProgress>, ABI::Windows::Foundation::IAsyncOperationWithProgressCompletedHandler<TResult, TProgress>>(pOperation, dwMilliseconds);
}
#pragma warning(pop)

View File

@@ -257,17 +257,17 @@ bool operator!=(const FrameFormat &lhs, const FrameFormat &rhs) {
EBUR128State::EBUR128State(const FrameFormat &_dsc) : dsc(_dsc) {
st.reset(ebur128_init(dsc.channels, dsc.samplerate, EBUR128_MODE_I | EBUR128_MODE_LRA));
st.reset(ebur128_init(static_cast<uint>(dsc.channels), static_cast<ulong>(dsc.samplerate), EBUR128_MODE_I | EBUR128_MODE_LRA));
Q_ASSERT(st);
std::vector<GstAudioChannelPosition> positions(dsc.channels, GST_AUDIO_CHANNEL_POSITION_INVALID);
std::vector<GstAudioChannelPosition> positions(static_cast<uint>(dsc.channels), GST_AUDIO_CHANNEL_POSITION_INVALID);
gboolean success = gst_audio_channel_positions_from_mask(dsc.channels, dsc.channel_mask, positions.data());
Q_ASSERT(success);
// Propagate our knowledge of audio channel mapping to libebur128, doing so
// is important because loudness measurement is channel-position dependent.
for (int channel_number = 0; channel_number != dsc.channels; ++channel_number) {
ebur128_set_channel(&*st, channel_number, gst_channel_to_ebur_channel(positions[channel_number]));
ebur128_set_channel(&*st, static_cast<uint>(channel_number), gst_channel_to_ebur_channel(positions[static_cast<uint>(channel_number)]));
}
}
@@ -371,7 +371,7 @@ GstFlowReturn EBUR128AnalysisImpl::NewBufferCallback(GstAppSink *app_sink, gpoin
if (buffer) {
GstMapInfo map;
if (gst_buffer_map(buffer, &map, GST_MAP_READ)) {
me->state->AddFrames(reinterpret_cast<const char*>(map.data), static_cast<qint64>(map.size));
me->state->AddFrames(reinterpret_cast<const char*>(map.data), static_cast<size_t>(map.size));
gst_buffer_unmap(buffer, &map);
}
}

View File

@@ -163,7 +163,7 @@ void EngineBase::ReloadSettings() {
channels_enabled_ = s.value(BackendSettings::kChannelsEnabled, false).toBool();
channels_ = s.value(BackendSettings::kChannels, 0).toInt();
buffer_duration_nanosec_ = s.value(BackendSettings::kBufferDuration, BackendSettings::kDefaultBufferDuration).toLongLong() * kNsecPerMsec;
buffer_duration_nanosec_ = s.value(BackendSettings::kBufferDuration, BackendSettings::kDefaultBufferDuration).toULongLong() * kNsecPerMsec;
buffer_low_watermark_ = s.value(BackendSettings::kBufferLowWatermark, BackendSettings::kDefaultBufferLowWatermark).toDouble();
buffer_high_watermark_ = s.value(BackendSettings::kBufferHighWatermark, BackendSettings::kDefaultBufferHighWatermark).toDouble();

View File

@@ -137,10 +137,10 @@ GstEngine::~GstEngine() {
if (discoverer_) {
if (discovery_discovered_cb_id_ != -1) {
g_signal_handler_disconnect(G_OBJECT(discoverer_), discovery_discovered_cb_id_);
g_signal_handler_disconnect(G_OBJECT(discoverer_), static_cast<gulong>(discovery_discovered_cb_id_));
}
if (discovery_finished_cb_id_ != -1) {
g_signal_handler_disconnect(G_OBJECT(discoverer_), discovery_finished_cb_id_);
g_signal_handler_disconnect(G_OBJECT(discoverer_), static_cast<gulong>(discovery_finished_cb_id_));
}
gst_discoverer_stop(discoverer_);
@@ -244,8 +244,8 @@ bool GstEngine::Load(const QUrl &media_url, const QUrl &stream_url, const Engine
if (!discoverer_) {
discoverer_ = gst_discoverer_new(kDiscoveryTimeoutS * GST_SECOND, nullptr);
if (discoverer_) {
discovery_discovered_cb_id_ = CHECKED_GCONNECT(G_OBJECT(discoverer_), "discovered", &StreamDiscovered, this);
discovery_finished_cb_id_ = CHECKED_GCONNECT(G_OBJECT(discoverer_), "finished", &StreamDiscoveryFinished, this);
discovery_discovered_cb_id_ = static_cast<int>(CHECKED_GCONNECT(G_OBJECT(discoverer_), "discovered", &StreamDiscovered, this));
discovery_finished_cb_id_ = static_cast<int>(CHECKED_GCONNECT(G_OBJECT(discoverer_), "finished", &StreamDiscoveryFinished, this));
gst_discoverer_start(discoverer_);
}
}
@@ -315,7 +315,8 @@ void GstEngine::Stop(const bool stop_after) {
media_url_.clear();
stream_url_.clear(); // To ensure we return Empty from state()
beginning_offset_nanosec_ = end_offset_nanosec_ = 0;
beginning_offset_nanosec_ = 0;
end_offset_nanosec_ = 0;
// Check if we started a fade out. If it isn't finished yet and the user pressed stop, we cancel the fader and just stop the playback.
if (fadeout_pause_pipeline_) {
@@ -751,7 +752,7 @@ void GstEngine::PlayDone(const GstStateChangeReturn ret, const bool pause, const
stream_url = old_pipeline->stream_url();
stream_url.detach();
}
current_pipeline_ = CreatePipeline(media_url, stream_url, redirect_url, beginning_offset_nanosec_, end_offset_nanosec_, old_pipeline->ebur128_loudness_normalizing_gain_db());
current_pipeline_ = CreatePipeline(media_url, stream_url, redirect_url, static_cast<qint64>(beginning_offset_nanosec_), end_offset_nanosec_, old_pipeline->ebur128_loudness_normalizing_gain_db());
FinishPipeline(old_pipeline);
Play(pause, offset_nanosec);
return;
@@ -787,7 +788,7 @@ void GstEngine::BufferingStarted() {
}
void GstEngine::BufferingProgress(const int percent) {
task_manager_->SetTaskProgress(buffering_task_id_, percent, 100);
task_manager_->SetTaskProgress(buffering_task_id_, static_cast<quint64>(percent), 100UL);
}
void GstEngine::BufferingFinished() {

View File

@@ -163,15 +163,6 @@ GstEnginePipeline::GstEnginePipeline(QObject *parent)
equalizer_(nullptr),
equalizer_preamp_(nullptr),
eventprobe_(nullptr),
upstream_events_probe_cb_id_(0),
buffer_probe_cb_id_(0),
pad_probe_cb_id_(0),
element_added_cb_id_(-1),
element_removed_cb_id_(-1),
pad_added_cb_id_(-1),
notify_source_cb_id_(-1),
about_to_finish_cb_id_(-1),
notify_volume_cb_id_(-1),
logged_unsupported_analyzer_format_(false),
about_to_finish_(false),
finish_requested_(false),
@@ -360,52 +351,52 @@ void GstEnginePipeline::Disconnect() {
fader_.reset();
}
if (element_added_cb_id_ != -1) {
g_signal_handler_disconnect(G_OBJECT(audiobin_), element_added_cb_id_);
element_added_cb_id_ = -1;
if (element_added_cb_id_.has_value()) {
g_signal_handler_disconnect(G_OBJECT(audiobin_), element_added_cb_id_.value());
element_added_cb_id_.reset();
}
if (element_removed_cb_id_ != -1) {
g_signal_handler_disconnect(G_OBJECT(audiobin_), element_removed_cb_id_);
element_removed_cb_id_ = -1;
if (element_removed_cb_id_.has_value()) {
g_signal_handler_disconnect(G_OBJECT(audiobin_), element_removed_cb_id_.value());
element_removed_cb_id_.reset();
}
if (pad_added_cb_id_ != -1) {
g_signal_handler_disconnect(G_OBJECT(pipeline_), pad_added_cb_id_);
pad_added_cb_id_ = -1;
if (pad_added_cb_id_.has_value()) {
g_signal_handler_disconnect(G_OBJECT(pipeline_), pad_added_cb_id_.value());
pad_added_cb_id_.reset();
}
if (notify_source_cb_id_ != -1) {
g_signal_handler_disconnect(G_OBJECT(pipeline_), notify_source_cb_id_);
notify_source_cb_id_ = -1;
if (notify_source_cb_id_.has_value()) {
g_signal_handler_disconnect(G_OBJECT(pipeline_), notify_source_cb_id_.value());
notify_source_cb_id_.reset();
}
if (about_to_finish_cb_id_ != -1) {
g_signal_handler_disconnect(G_OBJECT(pipeline_), about_to_finish_cb_id_);
about_to_finish_cb_id_ = -1;
if (about_to_finish_cb_id_.has_value()) {
g_signal_handler_disconnect(G_OBJECT(pipeline_), about_to_finish_cb_id_.value());
about_to_finish_cb_id_.reset();
}
if (notify_volume_cb_id_ != -1) {
g_signal_handler_disconnect(G_OBJECT(volume_), notify_volume_cb_id_);
notify_volume_cb_id_ = -1;
if (notify_volume_cb_id_.has_value()) {
g_signal_handler_disconnect(G_OBJECT(volume_), notify_volume_cb_id_.value());
notify_volume_cb_id_.reset();
}
if (upstream_events_probe_cb_id_ != 0) {
if (upstream_events_probe_cb_id_.has_value()) {
GstPad *pad = gst_element_get_static_pad(eventprobe_, "src");
if (pad) {
gst_pad_remove_probe(pad, upstream_events_probe_cb_id_);
gst_pad_remove_probe(pad, upstream_events_probe_cb_id_.value());
gst_object_unref(pad);
}
upstream_events_probe_cb_id_ = 0;
upstream_events_probe_cb_id_.reset();
}
if (buffer_probe_cb_id_ != 0) {
if (buffer_probe_cb_id_.has_value()) {
GstPad *pad = gst_element_get_static_pad(audioqueueconverter_, "src");
if (pad) {
gst_pad_remove_probe(pad, buffer_probe_cb_id_);
gst_pad_remove_probe(pad, buffer_probe_cb_id_.value());
gst_object_unref(pad);
}
buffer_probe_cb_id_ = 0;
buffer_probe_cb_id_.reset();
}
{
@@ -718,7 +709,7 @@ bool GstEnginePipeline::InitAudioBin(QString &error) {
int last_band_frequency = 0;
for (int i = 0; i < kEqBandCount; ++i) {
const int index_in_eq = i + 1;
GstObject *band = GST_OBJECT(gst_child_proxy_get_child_by_index(GST_CHILD_PROXY(equalizer_), index_in_eq));
GstObject *band = GST_OBJECT(gst_child_proxy_get_child_by_index(GST_CHILD_PROXY(equalizer_), static_cast<guint>(index_in_eq)));
if (band) {
const float frequency = static_cast<float>(kEqBandFrequencies[i]);
const float bandwidth = frequency - static_cast<float>(last_band_frequency);
@@ -943,13 +934,13 @@ void GstEnginePipeline::SetupVolume(GstElement *element) {
if (volume_) {
qLog(Debug) << "Disonnecting volume notify on" << volume_;
g_signal_handler_disconnect(G_OBJECT(volume_), notify_volume_cb_id_);
notify_volume_cb_id_ = -1;
g_signal_handler_disconnect(G_OBJECT(volume_), notify_volume_cb_id_.value());
notify_volume_cb_id_.reset();
volume_ = nullptr;
}
qLog(Debug) << "Connecting volume notify on" << element;
notify_volume_cb_id_ = CHECKED_GCONNECT(G_OBJECT(element), "notify::volume", &NotifyVolumeCallback, this);
notify_volume_cb_id_ = static_cast<glong>(CHECKED_GCONNECT(G_OBJECT(element), "notify::volume", &NotifyVolumeCallback, this));
volume_ = element;
volume_set_ = false;
@@ -1029,10 +1020,10 @@ void GstEnginePipeline::ElementRemovedCallback(GstBin *bin, GstBin *sub_bin, Gst
if (bin != GST_BIN(instance->audiobin_)) return;
if (instance->notify_volume_cb_id_ != -1 && element == instance->volume_) {
if (instance->notify_volume_cb_id_.has_value() && element == instance->volume_) {
qLog(Debug) << "Disconnecting volume notify on" << instance->volume_;
g_signal_handler_disconnect(G_OBJECT(instance->volume_), instance->notify_volume_cb_id_);
instance->notify_volume_cb_id_ = -1;
g_signal_handler_disconnect(G_OBJECT(instance->volume_), instance->notify_volume_cb_id_.value());
instance->notify_volume_cb_id_.reset();
instance->volume_ = nullptr;
instance->volume_set_ = false;
}
@@ -1239,14 +1230,14 @@ GstPadProbeReturn GstEnginePipeline::BufferProbeCallback(GstPad *pad, GstPadProb
int32_t *s = reinterpret_cast<int32_t*>(map_info.data);
int samples = static_cast<int>((map_info.size / sizeof(int32_t)) / channels);
int buf16_size = samples * static_cast<int>(sizeof(int16_t)) * channels;
int16_t *d = static_cast<int16_t*>(g_malloc(buf16_size));
memset(d, 0, buf16_size);
int16_t *d = static_cast<int16_t*>(g_malloc(static_cast<gsize>(buf16_size)));
memset(d, 0, static_cast<size_t>(buf16_size));
for (int i = 0; i < (samples * channels); ++i) {
d[i] = static_cast<int16_t>((s[i] >> 16));
}
gst_buffer_unmap(buf, &map_info);
buf16 = gst_buffer_new_wrapped(d, buf16_size);
GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(samples * sizeof(int16_t) / channels, rate);
buf16 = gst_buffer_new_wrapped(d, static_cast<gsize>(buf16_size));
GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(static_cast<guint64>(samples * sizeof(int16_t) / channels), static_cast<guint64>(rate));
buf = buf16;
instance->logged_unsupported_analyzer_format_ = false;
@@ -1260,15 +1251,15 @@ GstPadProbeReturn GstEnginePipeline::BufferProbeCallback(GstPad *pad, GstPadProb
float *s = reinterpret_cast<float*>(map_info.data);
int samples = static_cast<int>((map_info.size / sizeof(float)) / channels);
int buf16_size = samples * static_cast<int>(sizeof(int16_t)) * channels;
int16_t *d = static_cast<int16_t*>(g_malloc(buf16_size));
memset(d, 0, buf16_size);
int16_t *d = static_cast<int16_t*>(g_malloc(static_cast<gsize>(buf16_size)));
memset(d, 0, static_cast<size_t>(buf16_size));
for (int i = 0; i < (samples * channels); ++i) {
float sample_float = (s[i] * static_cast<float>(32768.0));
d[i] = static_cast<int16_t>(sample_float);
}
gst_buffer_unmap(buf, &map_info);
buf16 = gst_buffer_new_wrapped(d, buf16_size);
GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(samples * sizeof(int16_t) / channels, rate);
buf16 = gst_buffer_new_wrapped(d, static_cast<gsize>(buf16_size));
GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(static_cast<guint64>(samples * sizeof(int16_t) / channels), static_cast<guint64>(rate));
buf = buf16;
instance->logged_unsupported_analyzer_format_ = false;
@@ -1282,16 +1273,16 @@ GstPadProbeReturn GstEnginePipeline::BufferProbeCallback(GstPad *pad, GstPadProb
int8_t *s24e = s24 + map_info.size;
int samples = static_cast<int>((map_info.size / sizeof(int8_t)) / channels);
int buf16_size = samples * static_cast<int>(sizeof(int16_t)) * channels;
int16_t *s16 = static_cast<int16_t*>(g_malloc(buf16_size));
memset(s16, 0, buf16_size);
int16_t *s16 = static_cast<int16_t*>(g_malloc(static_cast<gsize>(buf16_size)));
memset(s16, 0, static_cast<size_t>(buf16_size));
for (int i = 0; i < (samples * channels); ++i) {
s16[i] = *(reinterpret_cast<int16_t*>(s24 + 1));
s24 += 3;
if (s24 >= s24e) break;
}
gst_buffer_unmap(buf, &map_info);
buf16 = gst_buffer_new_wrapped(s16, buf16_size);
GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(samples * sizeof(int16_t) / channels, rate);
buf16 = gst_buffer_new_wrapped(s16, static_cast<gsize>(buf16_size));
GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(static_cast<guint64>(samples * sizeof(int16_t) / channels), static_cast<guint64>(rate));
buf = buf16;
instance->logged_unsupported_analyzer_format_ = false;
@@ -1306,8 +1297,8 @@ GstPadProbeReturn GstEnginePipeline::BufferProbeCallback(GstPad *pad, GstPadProb
int32_t *s32p = s32;
int samples = static_cast<int>((map_info.size / sizeof(int32_t)) / channels);
int buf16_size = samples * static_cast<int>(sizeof(int16_t)) * channels;
int16_t *s16 = static_cast<int16_t*>(g_malloc(buf16_size));
memset(s16, 0, buf16_size);
int16_t *s16 = static_cast<int16_t*>(g_malloc(static_cast<gsize>(buf16_size)));
memset(s16, 0, static_cast<size_t>(buf16_size));
for (int i = 0; i < (samples * channels); ++i) {
int8_t *s24 = reinterpret_cast<int8_t*>(s32p);
s16[i] = *(reinterpret_cast<int16_t*>(s24 + 1));
@@ -1315,8 +1306,8 @@ GstPadProbeReturn GstEnginePipeline::BufferProbeCallback(GstPad *pad, GstPadProb
if (s32p > s32e) break;
}
gst_buffer_unmap(buf, &map_info);
buf16 = gst_buffer_new_wrapped(s16, buf16_size);
GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(samples * sizeof(int16_t) / channels, rate);
buf16 = gst_buffer_new_wrapped(s16, static_cast<gsize>(buf16_size));
GST_BUFFER_DURATION(buf16) = GST_FRAMES_TO_CLOCK_TIME(static_cast<guint64>(samples * sizeof(int16_t) / channels), static_cast<guint64>(rate));
buf = buf16;
instance->logged_unsupported_analyzer_format_ = false;
@@ -2021,7 +2012,7 @@ void GstEnginePipeline::UpdateEqualizer() {
const int index_in_eq = i + 1;
// Offset because of the first dummy band we created.
GstObject *band = GST_OBJECT(gst_child_proxy_get_child_by_index(GST_CHILD_PROXY(equalizer_), index_in_eq));
GstObject *band = GST_OBJECT(gst_child_proxy_get_child_by_index(GST_CHILD_PROXY(equalizer_), static_cast<guint>(index_in_eq)));
g_object_set(G_OBJECT(band), "gain", gain, nullptr);
g_object_unref(G_OBJECT(band));
}

View File

@@ -24,6 +24,8 @@
#include "config.h"
#include <optional>
#include <glib.h>
#include <glib-object.h>
#include <glib/gtypes.h>
@@ -357,15 +359,15 @@ class GstEnginePipeline : public QObject {
GstElement *equalizer_preamp_;
GstElement *eventprobe_;
gulong upstream_events_probe_cb_id_;
gulong buffer_probe_cb_id_;
gulong pad_probe_cb_id_;
glong element_added_cb_id_;
glong element_removed_cb_id_;
glong pad_added_cb_id_;
glong notify_source_cb_id_;
glong about_to_finish_cb_id_;
glong notify_volume_cb_id_;
std::optional<gulong> upstream_events_probe_cb_id_;
std::optional<gulong> buffer_probe_cb_id_;
std::optional<gulong> pad_probe_cb_id_;
std::optional<gulong> element_added_cb_id_;
std::optional<gulong> element_removed_cb_id_;
std::optional<gulong> pad_added_cb_id_;
std::optional<gulong> notify_source_cb_id_;
std::optional<gulong> about_to_finish_cb_id_;
std::optional<gulong> notify_volume_cb_id_;
bool logged_unsupported_analyzer_format_;
mutex_protected<bool> about_to_finish_;

View File

@@ -52,10 +52,17 @@ enum {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4514)
#endif
G_DEFINE_TYPE(GstStrawberryFastSpectrum, gst_strawberry_fastspectrum, GST_TYPE_AUDIO_FILTER)
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
static void gst_strawberry_fastspectrum_finalize(GObject *object);
static void gst_strawberry_fastspectrum_set_property(GObject *object, const guint prop_id, const GValue *value, GParamSpec *pspec);
@@ -395,9 +402,9 @@ static GstFlowReturn gst_strawberry_fastspectrum_transform_ip(GstBaseTransform *
GstStrawberryFastSpectrum *fastspectrum = reinterpret_cast<GstStrawberryFastSpectrum*>(transform);
const guint rate = GST_AUDIO_FILTER_RATE(fastspectrum);
const guint bps = GST_AUDIO_FILTER_BPS(fastspectrum);
const guint64 bpf = GST_AUDIO_FILTER_BPF(fastspectrum);
const guint rate = static_cast<guint>(GST_AUDIO_FILTER_RATE(fastspectrum));
const guint bps = static_cast<guint>(GST_AUDIO_FILTER_BPS(fastspectrum));
const guint64 bpf = static_cast<guint64>(GST_AUDIO_FILTER_BPF(fastspectrum));
const double max_value = static_cast<double>((1UL << ((bps << 3) - 1)) - 1);
const guint bands = fastspectrum->bands;
const guint nfft = 2 * bands - 2;