Fix warnings on Windows

This commit is contained in:
badaix 2020-04-10 12:19:27 +02:00
parent 30753f9f61
commit ade0ee7be3
13 changed files with 67 additions and 63 deletions

View file

@ -68,7 +68,8 @@ EXTERN_C const PROPERTYKEY DECLSPEC_SELECTANY PKEY_Device_FriendlyName = {{0xa45
throw SnapException(ss.str()); \ 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); HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
CHECK_HR(hr); CHECK_HR(hr);

View file

@ -78,7 +78,7 @@ x = 1,000016667 / (1,000016667 - 1)
soxr_ = nullptr; soxr_ = nullptr;
} }
// initialize the buffer with 20ms (~latency of the reampler) // 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 #endif
} }
@ -101,7 +101,7 @@ void Stream::setRealSampleRate(double sampleRate)
} }
else 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"; // 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 resampled_chunk = new msg::PcmChunk(format_, 0);
auto us = chrono::duration_cast<chrono::microseconds>(resampled_start.time_since_epoch()).count(); auto us = chrono::duration_cast<chrono::microseconds>(resampled_start.time_since_epoch()).count();
resampled_chunk->timestamp.sec = us / 1000000; resampled_chunk->timestamp.sec = static_cast<int32_t>(us / 1000000);
resampled_chunk->timestamp.usec = us % 1000000; resampled_chunk->timestamp.usec = static_cast<int32_t>(us % 1000000);
// copy from the resample_buffer to the resampled chunk // 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); resampled_chunk->payload = (char*)realloc(resampled_chunk->payload, resampled_chunk->payloadSize);
memcpy(resampled_chunk->payload, resample_buffer_.data(), 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) if (odone == resample_buffer_framesize)
{ {
// buffer for resampled data too small, add space for 5ms // 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() LOG(DEBUG, LOG_TAG) << "Resample buffer completely filled, adding space for 5ms; new buffer size: " << resample_buffer_.size()
<< " bytes\n"; << " bytes\n";
} }
@ -247,7 +247,7 @@ cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, uint32_t frame
if (framesCorrection < 0 && frames + framesCorrection <= 0) if (framesCorrection < 0 && frames + framesCorrection <= 0)
{ {
// Avoid underflow in new char[] constructor. // Avoid underflow in new char[] constructor.
framesCorrection = -frames + 1; framesCorrection = -static_cast<int32_t>(frames) + 1;
} }
if (framesCorrection == 0) if (framesCorrection == 0)
@ -272,7 +272,7 @@ cs::time_point_clk Stream::getNextPlayerChunk(void* outputBuffer, uint32_t frame
slices = max; slices = max;
} }
// Size of each slice. The last slice may be bigger. // 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 // LOG(TRACE, LOG_TAG) << "getNextPlayerChunk, frames: " << frames << ", correction: " << framesCorrection << " (" << toRead << "), slices: " << slices
// << "\n"; // << "\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); buffer_.add(age);
miniBuffer_.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) // 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 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 // 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); bool result = (silent_frames <= frames);
silent_frames = std::min(silent_frames, frames); silent_frames = std::min(silent_frames, frames);
LOG(DEBUG, LOG_TAG) << "Silent frames: " << silent_frames << ", 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()); updateBuffers(age.count());
// print sync stats // update median_ and shortMedian_ and print sync stats
if (now != lastUpdate_) if (now != lastUpdate_)
{ {
lastUpdate_ = now; lastUpdate_ = now;
@ -488,7 +488,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
} }
catch (int e) catch (int e)
{ {
LOG(INFO) << "Exception\n"; LOG(INFO, LOG_TAG) << "Exception: " << e << "\n";
hard_sync_ = true; hard_sync_ = true;
return false; return false;
} }

View file

@ -82,7 +82,7 @@ private:
/// @param frames the number of requested frames /// @param frames the number of requested frames
void getSilentPlayerChunk(void* outputBuffer, uint32_t frames) const; void getSilentPlayerChunk(void* outputBuffer, uint32_t frames) const;
void updateBuffers(int age); void updateBuffers(chronos::usec::rep age);
void resetBuffers(); void resetBuffers();
void setRealSampleRate(double sampleRate); void setRealSampleRate(double sampleRate);
@ -95,8 +95,8 @@ private:
DoubleBuffer<chronos::usec::rep> buffer_; DoubleBuffer<chronos::usec::rep> buffer_;
std::shared_ptr<msg::PcmChunk> chunk_; std::shared_ptr<msg::PcmChunk> chunk_;
int median_; chronos::usec::rep median_;
int shortMedian_; chronos::usec::rep shortMedian_;
time_t lastUpdate_; time_t lastUpdate_;
uint32_t playedFrames_; uint32_t playedFrames_;
int32_t correctAfterXFrames_; int32_t correctAfterXFrames_;

View file

@ -22,7 +22,7 @@
TimeProvider::TimeProvider() : diffToServer_(0) 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)) if (!diffBuffer_.empty() && (std::abs(now.tv_sec - lastTimeSync) > 60))
{ {
LOG(INFO) << "Last time sync older than a minute. Clearing time buffer\n"; 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(); diffBuffer_.clear();
} }
lastTimeSync = now.tv_sec; lastTimeSync = now.tv_sec;

View file

@ -95,7 +95,9 @@
/// External logger macros /// External logger macros
// usage: LOG(SEVERITY) or LOG(SEVERITY, TAG) // usage: LOG(SEVERITY) or LOG(SEVERITY, TAG)
// e.g.: LOG(NOTICE) or LOG(NOTICE, "my 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 #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 #define SLOG(...) AIXLOG_INTERNAL__LOG_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__) << TIMESTAMP << SPECIAL << FUNC
// usage: COLOR(TEXT_COLOR, BACKGROUND_COLOR) or COLOR(TEXT_COLOR) // usage: COLOR(TEXT_COLOR, BACKGROUND_COLOR) or COLOR(TEXT_COLOR)

View file

@ -50,7 +50,7 @@ public:
uint32_t getSize() const override 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; uint32_t payloadSize;

View file

@ -47,7 +47,7 @@ public:
uint32_t getSize() const override 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; json msg;
@ -74,7 +74,7 @@ protected:
} }
} }
}; };
} } // namespace msg
#endif #endif

View file

@ -231,7 +231,7 @@ protected:
void writeVal(std::ostream& stream, const std::string& val) const 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); writeVal(stream, val.c_str(), size);
} }

View file

@ -58,7 +58,7 @@ public:
} }
#endif #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; // logd << "read: " << frameCount << ", total: " << (wireChunk->length / format.frameSize()) << ", idx: " << idx;// << std::endl;
int result = frameCount; int result = frameCount;
@ -77,8 +77,8 @@ public:
int seek(int frames) int seek(int frames)
{ {
if ((frames < 0) && (-frames > (int)idx_)) if ((frames < 0) && (-frames > static_cast<int>(idx_)))
frames = -idx_; frames = -static_cast<int>(idx_);
idx_ += frames; idx_ += frames;
if (idx_ > getFrameCount()) if (idx_ > getFrameCount())
@ -121,12 +121,12 @@ public:
return idx_ >= getFrameCount(); return idx_ >= getFrameCount();
} }
inline size_t getFrameCount() const inline uint32_t getFrameCount() const
{ {
return (payloadSize / format.frameSize()); return (payloadSize / format.frameSize());
} }
inline size_t getSampleCount() const inline uint32_t getSampleCount() const
{ {
return (payloadSize / format.sampleSize()); return (payloadSize / format.sampleSize());
} }

View file

@ -39,7 +39,7 @@ namespace msg
class WireChunk : public BaseMessage class WireChunk : public BaseMessage
{ {
public: 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) if (size > 0)
payload = (char*)malloc(size * sizeof(char)); payload = (char*)malloc(size * sizeof(char));

View file

@ -62,7 +62,8 @@ void SampleFormat::setFormat(const std::string& format)
std::vector<std::string> strs; std::vector<std::string> strs;
strs = utils::string::split(format, ':'); strs = utils::string::split(format, ':');
if (strs.size() == 3) 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 else
throw SnapException("sampleformat must be <rate>:<bits>:<channels>"); throw SnapException("sampleformat must be <rate>:<bits>:<channels>");
} }

View file

@ -53,8 +53,8 @@ inline static void timeofday(struct timeval* tv)
{ {
auto now = Clock::now(); auto now = Clock::now();
auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch()); auto microsecs = std::chrono::duration_cast<std::chrono::microseconds>(now.time_since_epoch());
tv->tv_sec = microsecs.count() / 1000000; tv->tv_sec = static_cast<time_t>(microsecs.count() / 1000000);
tv->tv_usec = microsecs.count() % 1000000; tv->tv_usec = static_cast<suseconds_t>(microsecs.count() % 1000000);
} }
#ifdef WINDOWS #ifdef WINDOWS

View file

@ -24,11 +24,11 @@
#include <cctype> #include <cctype>
#include <cerrno> #include <cerrno>
// #include <chrono>
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <iomanip> #include <iomanip>
#include <iomanip>
#include <iterator> #include <iterator>
#include <locale> #include <locale>
#include <memory> #include <memory>
@ -225,36 +225,36 @@ static std::string getArch()
return strutils::trim_copy(arch); return strutils::trim_copy(arch);
} }
// Seems not to be used
static long uptime() // static std::chrono::seconds uptime()
{ // {
#ifndef WINDOWS // #ifndef WINDOWS
#ifndef FREEBSD // #ifndef FREEBSD
struct sysinfo info; // struct sysinfo info;
sysinfo(&info); // sysinfo(&info);
return info.uptime; // return std::chrono::seconds(info.uptime);
#else // #else
std::string uptime = execGetOutput("sysctl kern.boottime"); // std::string uptime = execGetOutput("sysctl kern.boottime");
if ((uptime.find(" sec = ") != std::string::npos) && (uptime.find(",") != std::string::npos)) // if ((uptime.find(" sec = ") != std::string::npos) && (uptime.find(",") != std::string::npos))
{ // {
uptime = strutils::trim_copy(uptime.substr(uptime.find(" sec = ") + 7)); // uptime = strutils::trim_copy(uptime.substr(uptime.find(" sec = ") + 7));
uptime.resize(uptime.find(",")); // uptime.resize(uptime.find(","));
timeval now; // timeval now;
gettimeofday(&now, NULL); // gettimeofday(&now, NULL);
try // try
{ // {
return now.tv_sec - cpt::stoul(uptime); // return std::chrono::seconds(now.tv_sec - cpt::stoul(uptime));
} // }
catch (...) // catch (...)
{ // {
} // }
} // }
return 0; // return 0s;
#endif // #endif
#else // #else
return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::milliseconds(GetTickCount())).count(); // return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::milliseconds(GetTickCount()));
#endif // #endif
} // }
/// http://stackoverflow.com/questions/2174768/generating-random-uuids-in-linux /// http://stackoverflow.com/questions/2174768/generating-random-uuids-in-linux
@ -263,7 +263,7 @@ static std::string generateUUID()
static bool initialized(false); static bool initialized(false);
if (!initialized) if (!initialized)
{ {
std::srand(std::time(nullptr)); std::srand(static_cast<unsigned int>(std::time(nullptr)));
initialized = true; initialized = true;
} }
std::stringstream ss; std::stringstream ss;