diff --git a/client/player/wasapi_player.cpp b/client/player/wasapi_player.cpp index a9256c5b..2a94e8c2 100644 --- a/client/player/wasapi_player.cpp +++ b/client/player/wasapi_player.cpp @@ -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, ClientSettings::SharingMode mode) : Player(pcmDevice, stream), mode_(mode) +WASAPIPlayer::WASAPIPlayer(const PcmDevice& pcmDevice, std::shared_ptr stream, ClientSettings::SharingMode mode) + : Player(pcmDevice, stream), mode_(mode) { HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); CHECK_HR(hr); diff --git a/client/stream.cpp b/client/stream.cpp index eefd280f..22db37f7 100644 --- a/client/stream.cpp +++ b/client/stream.cpp @@ -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(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(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 chunk) auto resampled_chunk = new msg::PcmChunk(format_, 0); auto us = chrono::duration_cast(resampled_start.time_since_epoch()).count(); - resampled_chunk->timestamp.sec = us / 1000000; - resampled_chunk->timestamp.usec = us % 1000000; + resampled_chunk->timestamp.sec = static_cast(us / 1000000); + resampled_chunk->timestamp.usec = static_cast(us % 1000000); // copy from the resample_buffer to the resampled chunk - resampled_chunk->payloadSize = odone * format_.frameSize(); + resampled_chunk->payloadSize = static_cast(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 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(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(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(-chunk_->format.nsRate() * std::chrono::duration_cast(age).count()); + uint32_t silent_frames = static_cast(-chunk_->format.nsRate() * std::chrono::duration_cast(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; } diff --git a/client/stream.hpp b/client/stream.hpp index 2306fd33..a5b75079 100644 --- a/client/stream.hpp +++ b/client/stream.hpp @@ -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 buffer_; std::shared_ptr chunk_; - int median_; - int shortMedian_; + chronos::usec::rep median_; + chronos::usec::rep shortMedian_; time_t lastUpdate_; uint32_t playedFrames_; int32_t correctAfterXFrames_; diff --git a/client/time_provider.cpp b/client/time_provider.cpp index 41658e5d..a9b6facb 100644 --- a/client/time_provider.cpp +++ b/client/time_provider.cpp @@ -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(ms * 1000); diffBuffer_.clear(); } lastTimeSync = now.tv_sec; diff --git a/common/aixlog.hpp b/common/aixlog.hpp index 8a7a8df2..3ddf73be 100644 --- a/common/aixlog.hpp +++ b/common/aixlog.hpp @@ -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) diff --git a/common/message/codec_header.hpp b/common/message/codec_header.hpp index 7ebe414b..33d3b4a7 100644 --- a/common/message/codec_header.hpp +++ b/common/message/codec_header.hpp @@ -50,7 +50,7 @@ public: uint32_t getSize() const override { - return sizeof(uint32_t) + codec.size() + sizeof(uint32_t) + payloadSize; + return static_cast(sizeof(uint32_t) + codec.size() + sizeof(uint32_t) + payloadSize); } uint32_t payloadSize; diff --git a/common/message/json_message.hpp b/common/message/json_message.hpp index fccb135a..ffd29551 100644 --- a/common/message/json_message.hpp +++ b/common/message/json_message.hpp @@ -47,7 +47,7 @@ public: uint32_t getSize() const override { - return sizeof(uint32_t) + msg.dump().size(); + return static_cast(sizeof(uint32_t) + msg.dump().size()); } json msg; @@ -74,7 +74,7 @@ protected: } } }; -} +} // namespace msg #endif diff --git a/common/message/message.hpp b/common/message/message.hpp index 0d117069..9ee9c1d8 100644 --- a/common/message/message.hpp +++ b/common/message/message.hpp @@ -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(val.size()); writeVal(stream, val.c_str(), size); } diff --git a/common/message/pcm_chunk.hpp b/common/message/pcm_chunk.hpp index 8b9275f9..f8ca7cf3 100644 --- a/common/message/pcm_chunk.hpp +++ b/common/message/pcm_chunk.hpp @@ -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(idx_))) + frames = -static_cast(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()); } diff --git a/common/message/wire_chunk.hpp b/common/message/wire_chunk.hpp index 62ed5906..028ea5ea 100644 --- a/common/message/wire_chunk.hpp +++ b/common/message/wire_chunk.hpp @@ -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)); diff --git a/common/sample_format.cpp b/common/sample_format.cpp index 9b8901a3..d48f4a63 100644 --- a/common/sample_format.cpp +++ b/common/sample_format.cpp @@ -62,7 +62,8 @@ void SampleFormat::setFormat(const std::string& format) std::vector 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(cpt::stoul(strs[1])), + strs[2] == "*" ? 0 : static_cast(cpt::stoul(strs[2]))); else throw SnapException("sampleformat must be ::"); } diff --git a/common/time_defs.hpp b/common/time_defs.hpp index bc5a926a..43bf193e 100644 --- a/common/time_defs.hpp +++ b/common/time_defs.hpp @@ -53,8 +53,8 @@ inline static void timeofday(struct timeval* tv) { auto now = Clock::now(); auto microsecs = std::chrono::duration_cast(now.time_since_epoch()); - tv->tv_sec = microsecs.count() / 1000000; - tv->tv_usec = microsecs.count() % 1000000; + tv->tv_sec = static_cast(microsecs.count() / 1000000); + tv->tv_usec = static_cast(microsecs.count() % 1000000); } #ifdef WINDOWS diff --git a/common/utils.hpp b/common/utils.hpp index e0dace48..680273e9 100644 --- a/common/utils.hpp +++ b/common/utils.hpp @@ -24,11 +24,11 @@ #include #include +// #include #include #include #include #include -#include #include #include #include @@ -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::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::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(std::time(nullptr))); initialized = true; } std::stringstream ss;