mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-28 17:57:05 +02:00
Fix warnings on Windows
This commit is contained in:
parent
30753f9f61
commit
ade0ee7be3
13 changed files with 67 additions and 63 deletions
|
@ -68,7 +68,8 @@ EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY PKEY_Device_FriendlyName = {{0xa45
|
|||
throw SnapException(ss.str()); \
|
||||
}
|
||||
|
||||
WASAPIPlayer::WASAPIPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream, ClientSettings::SharingMode mode) : Player(pcmDevice, stream), mode_(mode)
|
||||
WASAPIPlayer::WASAPIPlayer(const PcmDevice& pcmDevice, std::shared_ptr<Stream> stream, ClientSettings::SharingMode mode)
|
||||
: Player(pcmDevice, stream), mode_(mode)
|
||||
{
|
||||
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
||||
CHECK_HR(hr);
|
||||
|
|
|
@ -78,7 +78,7 @@ x = 1,000016667 / (1,000016667 - 1)
|
|||
soxr_ = nullptr;
|
||||
}
|
||||
// initialize the buffer with 20ms (~latency of the reampler)
|
||||
resample_buffer_.resize(format_.frameSize() * ceil(format_.msRate()) * 20);
|
||||
resample_buffer_.resize(format_.frameSize() * static_cast<uint16_t>(ceil(format_.msRate() * 20)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ void Stream::setRealSampleRate(double sampleRate)
|
|||
}
|
||||
else
|
||||
{
|
||||
correctAfterXFrames_ = round((format_.rate() / sampleRate) / (format_.rate() / sampleRate - 1.));
|
||||
correctAfterXFrames_ = static_cast<int32_t>(round((format_.rate() / sampleRate) / (format_.rate() / sampleRate - 1.)));
|
||||
// LOG(TRACE, LOG_TAG) << "Correct after X: " << correctAfterXFrames_ << " (Real rate: " << sampleRate << ", rate: " << format_.rate() << ")\n";
|
||||
}
|
||||
}
|
||||
|
@ -170,11 +170,11 @@ void Stream::addChunk(unique_ptr<msg::PcmChunk> chunk)
|
|||
|
||||
auto resampled_chunk = new msg::PcmChunk(format_, 0);
|
||||
auto us = chrono::duration_cast<chrono::microseconds>(resampled_start.time_since_epoch()).count();
|
||||
resampled_chunk->timestamp.sec = us / 1000000;
|
||||
resampled_chunk->timestamp.usec = us % 1000000;
|
||||
resampled_chunk->timestamp.sec = static_cast<int32_t>(us / 1000000);
|
||||
resampled_chunk->timestamp.usec = static_cast<int32_t>(us % 1000000);
|
||||
|
||||
// copy from the resample_buffer to the resampled chunk
|
||||
resampled_chunk->payloadSize = odone * format_.frameSize();
|
||||
resampled_chunk->payloadSize = static_cast<uint32_t>(odone * format_.frameSize());
|
||||
resampled_chunk->payload = (char*)realloc(resampled_chunk->payload, resampled_chunk->payloadSize);
|
||||
memcpy(resampled_chunk->payload, resample_buffer_.data(), resampled_chunk->payloadSize);
|
||||
|
||||
|
@ -196,7 +196,7 @@ void Stream::addChunk(unique_ptr<msg::PcmChunk> chunk)
|
|||
if (odone == resample_buffer_framesize)
|
||||
{
|
||||
// buffer for resampled data too small, add space for 5ms
|
||||
resample_buffer_.resize(resample_buffer_.size() + format_.frameSize() * ceil(format_.msRate()) * 5);
|
||||
resample_buffer_.resize(resample_buffer_.size() + format_.frameSize() * static_cast<uint16_t>(ceil(format_.msRate() * 5)));
|
||||
LOG(DEBUG, LOG_TAG) << "Resample buffer completely filled, adding space for 5ms; new buffer size: " << resample_buffer_.size()
|
||||
<< " bytes\n";
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, uint32_t frame
|
|||
if (framesCorrection < 0 && frames + framesCorrection <= 0)
|
||||
{
|
||||
// Avoid underflow in new char[] constructor.
|
||||
framesCorrection = -frames + 1;
|
||||
framesCorrection = -static_cast<int32_t>(frames) + 1;
|
||||
}
|
||||
|
||||
if (framesCorrection == 0)
|
||||
|
@ -272,7 +272,7 @@ cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, uint32_t frame
|
|||
slices = max;
|
||||
}
|
||||
// Size of each slice. The last slice may be bigger.
|
||||
int size = max / slices;
|
||||
auto size = max / slices;
|
||||
|
||||
// LOG(TRACE, LOG_TAG) << "getNextPlayerChunk, frames: " << frames << ", correction: " << framesCorrection << " (" << toRead << "), slices: " << slices
|
||||
// << "\n";
|
||||
|
@ -307,7 +307,7 @@ cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, uint32_t frame
|
|||
}
|
||||
|
||||
|
||||
void Stream::updateBuffers(int age)
|
||||
void Stream::updateBuffers(chronos::usec::rep age)
|
||||
{
|
||||
buffer_.add(age);
|
||||
miniBuffer_.add(age);
|
||||
|
@ -390,7 +390,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
|||
// e.g. age = -20ms (=> should be played in 20ms)
|
||||
// and the current chunk duration is 50ms, so we need to play 20ms silence (as we don't have data)
|
||||
// and can play 30ms of the stream
|
||||
uint32_t silent_frames = static_cast<size_t>(-chunk_->format.nsRate() * std::chrono::duration_cast<cs::nsec>(age).count());
|
||||
uint32_t silent_frames = static_cast<uint32_t>(-chunk_->format.nsRate() * std::chrono::duration_cast<cs::nsec>(age).count());
|
||||
bool result = (silent_frames <= frames);
|
||||
silent_frames = std::min(silent_frames, frames);
|
||||
LOG(DEBUG, LOG_TAG) << "Silent frames: " << silent_frames << ", frames: " << frames
|
||||
|
@ -474,7 +474,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
|||
|
||||
updateBuffers(age.count());
|
||||
|
||||
// print sync stats
|
||||
// update median_ and shortMedian_ and print sync stats
|
||||
if (now != lastUpdate_)
|
||||
{
|
||||
lastUpdate_ = now;
|
||||
|
@ -488,7 +488,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
|||
}
|
||||
catch (int e)
|
||||
{
|
||||
LOG(INFO) << "Exception\n";
|
||||
LOG(INFO, LOG_TAG) << "Exception: " << e << "\n";
|
||||
hard_sync_ = true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ private:
|
|||
/// @param frames the number of requested frames
|
||||
void getSilentPlayerChunk(void* outputBuffer, uint32_t frames) const;
|
||||
|
||||
void updateBuffers(int age);
|
||||
void updateBuffers(chronos::usec::rep age);
|
||||
void resetBuffers();
|
||||
void setRealSampleRate(double sampleRate);
|
||||
|
||||
|
@ -95,8 +95,8 @@ private:
|
|||
DoubleBuffer<chronos::usec::rep> buffer_;
|
||||
std::shared_ptr<msg::PcmChunk> chunk_;
|
||||
|
||||
int median_;
|
||||
int shortMedian_;
|
||||
chronos::usec::rep median_;
|
||||
chronos::usec::rep shortMedian_;
|
||||
time_t lastUpdate_;
|
||||
uint32_t playedFrames_;
|
||||
int32_t correctAfterXFrames_;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
TimeProvider::TimeProvider() : diffToServer_(0)
|
||||
{
|
||||
diffBuffer_.setSize(100);
|
||||
diffBuffer_.setSize(200);
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,7 +45,7 @@ void TimeProvider::setDiffToServer(double ms)
|
|||
if (!diffBuffer_.empty() && (std::abs(now.tv_sec - lastTimeSync) > 60))
|
||||
{
|
||||
LOG(INFO) << "Last time sync older than a minute. Clearing time buffer\n";
|
||||
diffToServer_ = ms * 1000;
|
||||
diffToServer_ = static_cast<chronos::usec::rep>(ms * 1000);
|
||||
diffBuffer_.clear();
|
||||
}
|
||||
lastTimeSync = now.tv_sec;
|
||||
|
|
|
@ -95,7 +95,9 @@
|
|||
/// External logger macros
|
||||
// usage: LOG(SEVERITY) or LOG(SEVERITY, TAG)
|
||||
// e.g.: LOG(NOTICE) or LOG(NOTICE, "my tag")
|
||||
#ifndef WIN32
|
||||
#define LOG(...) AIXLOG_INTERNAL__LOG_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__) << TIMESTAMP << FUNC
|
||||
#endif
|
||||
#define SLOG(...) AIXLOG_INTERNAL__LOG_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__) << TIMESTAMP << SPECIAL << FUNC
|
||||
|
||||
// usage: COLOR(TEXT_COLOR, BACKGROUND_COLOR) or COLOR(TEXT_COLOR)
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
uint32_t getSize() const override
|
||||
{
|
||||
return sizeof(uint32_t) + codec.size() + sizeof(uint32_t) + payloadSize;
|
||||
return static_cast<uint32_t>(sizeof(uint32_t) + codec.size() + sizeof(uint32_t) + payloadSize);
|
||||
}
|
||||
|
||||
uint32_t payloadSize;
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
|
||||
uint32_t getSize() const override
|
||||
{
|
||||
return sizeof(uint32_t) + msg.dump().size();
|
||||
return static_cast<uint32_t>(sizeof(uint32_t) + msg.dump().size());
|
||||
}
|
||||
|
||||
json msg;
|
||||
|
@ -74,7 +74,7 @@ protected:
|
|||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace msg
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -231,7 +231,7 @@ protected:
|
|||
|
||||
void writeVal(std::ostream& stream, const std::string& val) const
|
||||
{
|
||||
uint32_t size = val.size();
|
||||
uint32_t size = static_cast<uint32_t>(val.size());
|
||||
writeVal(stream, val.c_str(), size);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@ public:
|
|||
}
|
||||
#endif
|
||||
|
||||
int readFrames(void* outputBuffer, size_t frameCount)
|
||||
int readFrames(void* outputBuffer, uint32_t frameCount)
|
||||
{
|
||||
// logd << "read: " << frameCount << ", total: " << (wireChunk->length / format.frameSize()) << ", idx: " << idx;// << std::endl;
|
||||
int result = frameCount;
|
||||
|
@ -77,8 +77,8 @@ public:
|
|||
|
||||
int seek(int frames)
|
||||
{
|
||||
if ((frames < 0) && (-frames > (int)idx_))
|
||||
frames = -idx_;
|
||||
if ((frames < 0) && (-frames > static_cast<int>(idx_)))
|
||||
frames = -static_cast<int>(idx_);
|
||||
|
||||
idx_ += frames;
|
||||
if (idx_ > getFrameCount())
|
||||
|
@ -121,12 +121,12 @@ public:
|
|||
return idx_ >= getFrameCount();
|
||||
}
|
||||
|
||||
inline size_t getFrameCount() const
|
||||
inline uint32_t getFrameCount() const
|
||||
{
|
||||
return (payloadSize / format.frameSize());
|
||||
}
|
||||
|
||||
inline size_t getSampleCount() const
|
||||
inline uint32_t getSampleCount() const
|
||||
{
|
||||
return (payloadSize / format.sampleSize());
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace msg
|
|||
class WireChunk : public BaseMessage
|
||||
{
|
||||
public:
|
||||
WireChunk(size_t size = 0) : BaseMessage(message_type::kWireChunk), payloadSize(size), payload(nullptr)
|
||||
WireChunk(uint32_t size = 0) : BaseMessage(message_type::kWireChunk), payloadSize(size), payload(nullptr)
|
||||
{
|
||||
if (size > 0)
|
||||
payload = (char*)malloc(size * sizeof(char));
|
||||
|
|
|
@ -62,7 +62,8 @@ void SampleFormat::setFormat(const std::string& format)
|
|||
std::vector<std::string> strs;
|
||||
strs = utils::string::split(format, ':');
|
||||
if (strs.size() == 3)
|
||||
setFormat(strs[0] == "*" ? 0 : cpt::stoul(strs[0]), strs[1] == "*" ? 0 : cpt::stoul(strs[1]), strs[2] == "*" ? 0 : cpt::stoul(strs[2]));
|
||||
setFormat(strs[0] == "*" ? 0 : cpt::stoul(strs[0]), strs[1] == "*" ? 0 : static_cast<uint16_t>(cpt::stoul(strs[1])),
|
||||
strs[2] == "*" ? 0 : static_cast<uint16_t>(cpt::stoul(strs[2])));
|
||||
else
|
||||
throw SnapException("sampleformat must be <rate>:<bits>:<channels>");
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ inline static void timeofday(struct timeval* tv)
|
|||
{
|
||||
auto now = Clock::now();
|
||||
auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch());
|
||||
tv->tv_sec = microsecs.count() / 1000000;
|
||||
tv->tv_usec = microsecs.count() % 1000000;
|
||||
tv->tv_sec = static_cast<time_t>(microsecs.count() / 1000000);
|
||||
tv->tv_usec = static_cast<suseconds_t>(microsecs.count() % 1000000);
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
// #include <chrono>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iomanip>
|
||||
#include <iomanip>
|
||||
#include <iterator>
|
||||
#include <locale>
|
||||
#include <memory>
|
||||
|
@ -225,36 +225,36 @@ static std::string getArch()
|
|||
return strutils::trim_copy(arch);
|
||||
}
|
||||
|
||||
|
||||
static long uptime()
|
||||
{
|
||||
#ifndef WINDOWS
|
||||
#ifndef FREEBSD
|
||||
struct sysinfo info;
|
||||
sysinfo(&info);
|
||||
return info.uptime;
|
||||
#else
|
||||
std::string uptime = execGetOutput("sysctl kern.boottime");
|
||||
if ((uptime.find(" sec = ") != std::string::npos) && (uptime.find(",") != std::string::npos))
|
||||
{
|
||||
uptime = strutils::trim_copy(uptime.substr(uptime.find(" sec = ") + 7));
|
||||
uptime.resize(uptime.find(","));
|
||||
timeval now;
|
||||
gettimeofday(&now, NULL);
|
||||
try
|
||||
{
|
||||
return now.tv_sec - cpt::stoul(uptime);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
#endif
|
||||
#else
|
||||
return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::milliseconds(GetTickCount())).count();
|
||||
#endif
|
||||
}
|
||||
// Seems not to be used
|
||||
// static std::chrono::seconds uptime()
|
||||
// {
|
||||
// #ifndef WINDOWS
|
||||
// #ifndef FREEBSD
|
||||
// struct sysinfo info;
|
||||
// sysinfo(&info);
|
||||
// return std::chrono::seconds(info.uptime);
|
||||
// #else
|
||||
// std::string uptime = execGetOutput("sysctl kern.boottime");
|
||||
// if ((uptime.find(" sec = ") != std::string::npos) && (uptime.find(",") != std::string::npos))
|
||||
// {
|
||||
// uptime = strutils::trim_copy(uptime.substr(uptime.find(" sec = ") + 7));
|
||||
// uptime.resize(uptime.find(","));
|
||||
// timeval now;
|
||||
// gettimeofday(&now, NULL);
|
||||
// try
|
||||
// {
|
||||
// return std::chrono::seconds(now.tv_sec - cpt::stoul(uptime));
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
// return 0s;
|
||||
// #endif
|
||||
// #else
|
||||
// return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::milliseconds(GetTickCount()));
|
||||
// #endif
|
||||
// }
|
||||
|
||||
|
||||
/// http://stackoverflow.com/questions/2174768/generating-random-uuids-in-linux
|
||||
|
@ -263,7 +263,7 @@ static std::string generateUUID()
|
|||
static bool initialized(false);
|
||||
if (!initialized)
|
||||
{
|
||||
std::srand(std::time(nullptr));
|
||||
std::srand(static_cast<unsigned int>(std::time(nullptr)));
|
||||
initialized = true;
|
||||
}
|
||||
std::stringstream ss;
|
||||
|
|
Loading…
Add table
Reference in a new issue