mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-03 16:48:52 +02:00
code review changes: use NOMINMAX hack, audio backend android only, move windows time defs to time_defs.hpp
This commit is contained in:
parent
9737c1ac44
commit
bd373dc09c
5 changed files with 40 additions and 71 deletions
|
@ -207,12 +207,9 @@ if(WIN32)
|
|||
find_package(FLAC REQUIRED)
|
||||
find_package(Ogg REQUIRED)
|
||||
find_package(Vorbis REQUIRED)
|
||||
find_package(Opus)
|
||||
if(OPUS_FOUND)
|
||||
add_definitions("-DHAS_OPUS")
|
||||
endif()
|
||||
find_package(Opus REQUIRED)
|
||||
add_definitions(-DNTDDI_VERSION=0x06020000 -D_WIN32_WINNT=0x0602 -DWINVER=0x0602 -DWINDOWS -DWIN32_LEAN_AND_MEAN -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_WARNINGS )
|
||||
add_definitions(-DHAS_OGG -DHAS_VORBIS -DHAS_FLAC -DHAS_VORBIS_ENC -DHAS_WASAPI)
|
||||
add_definitions(-DHAS_OGG -DHAS_VORBIS -DHAS_FLAC -DHAS_VORBIS_ENC -DHAS_WASAPI -DHAS_OPUS)
|
||||
endif()
|
||||
|
||||
add_subdirectory(common)
|
||||
|
|
|
@ -111,7 +111,9 @@ int main(int argc, char** argv)
|
|||
/*auto latencyValue =*/op.add<Value<int>>("", "latency", "latency of the PCM device", 0, &settings.player.latency);
|
||||
/*auto instanceValue =*/op.add<Value<size_t>>("i", "instance", "instance id", 1, &settings.instance);
|
||||
/*auto hostIdValue =*/op.add<Value<string>>("", "hostID", "unique host id", "", &settings.host_id);
|
||||
#ifdef ANDROID
|
||||
op.add<Value<string>>("", "player", "audio backend", "", &settings.player.player_name);
|
||||
#endif
|
||||
#ifdef HAS_SOXR
|
||||
auto sample_format = op.add<Value<string>>("", "sampleformat", "resample audio stream to <rate>:<bits>:<channels>", "");
|
||||
#endif
|
||||
|
@ -241,7 +243,6 @@ int main(int argc, char** argv)
|
|||
#endif
|
||||
|
||||
#ifdef HAS_WASAPI
|
||||
settings.player.player_name = "wasapi";
|
||||
if (wasapi_mode->is_set())
|
||||
{
|
||||
settings.player.wasapi_mode = (strcmp(wasapi_mode->value().c_str(), "exclusive") == 0) ?
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
***/
|
||||
|
||||
#define NOMINMAX
|
||||
|
||||
#include "stream.hpp"
|
||||
#include "common/aixlog.hpp"
|
||||
#include "time_provider.hpp"
|
||||
|
@ -390,7 +392,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
|||
// 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());
|
||||
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
|
||||
<< ", age: " << std::chrono::duration_cast<cs::usec>(age).count() / 1000. << "\n";
|
||||
getSilentPlayerChunk(outputBuffer, silent_frames);
|
||||
|
@ -453,7 +455,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
|||
if ((cs::usec(shortMedian_) > kCorrectionBegin) && (cs::usec(miniMedian) > cs::usec(50)) && (cs::usec(age) > cs::usec(50)))
|
||||
{
|
||||
double rate = (shortMedian_ / 100) * 0.00005;
|
||||
rate = 1.0 - (std::min)(rate, 0.0005);
|
||||
rate = 1.0 - std::min(rate, 0.0005);
|
||||
// LOG(INFO, LOG_TAG) << "Rate: " << rate << "\n";
|
||||
// we are late (age > 0), this means we are not playing fast enough
|
||||
// => the real sample rate seems to be lower, we have to drop some frames
|
||||
|
@ -462,7 +464,7 @@ bool Stream::getPlayerChunk(void* outputBuffer, const cs::usec& outputBufferDacT
|
|||
else if ((cs::usec(shortMedian_) < -kCorrectionBegin) && (cs::usec(miniMedian) < -cs::usec(50)) && (cs::usec(age) < -cs::usec(50)))
|
||||
{
|
||||
double rate = (-shortMedian_ / 100) * 0.00005;
|
||||
rate = 1.0 + (std::min)(rate, 0.0005);
|
||||
rate = 1.0 + std::min(rate, 0.0005);
|
||||
// LOG(INFO, LOG_TAG) << "Rate: " << rate << "\n";
|
||||
// we are early (age > 0), this means we are playing too fast
|
||||
// => the real sample rate seems to be higher, we have to insert some frames
|
||||
|
|
|
@ -30,31 +30,6 @@
|
|||
#endif
|
||||
#include <vector>
|
||||
|
||||
#ifdef WINDOWS // Implementation from http://stackoverflow.com/a/26085827/2510022
|
||||
#include <Windows.h>
|
||||
#include <stdint.h>
|
||||
#include <winsock2.h>
|
||||
|
||||
inline static int gettimeofday(struct timeval* tp, struct timezone* tzp)
|
||||
{
|
||||
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
|
||||
static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);
|
||||
|
||||
SYSTEMTIME system_time;
|
||||
FILETIME file_time;
|
||||
uint64_t time;
|
||||
|
||||
GetSystemTime(&system_time);
|
||||
SystemTimeToFileTime(&system_time, &file_time);
|
||||
time = ((uint64_t)file_time.dwLowDateTime);
|
||||
time += ((uint64_t)file_time.dwHighDateTime) << 32;
|
||||
|
||||
tp->tv_sec = (long)((time - EPOCH) / 10000000L);
|
||||
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
template<typename CharT, typename TraitsT = std::char_traits<CharT> >
|
||||
class vectorwrapbuf : public std::basic_streambuf<CharT, TraitsT>
|
||||
|
@ -96,11 +71,7 @@ struct tv
|
|||
tv()
|
||||
{
|
||||
timeval t;
|
||||
#ifdef WINDOWS
|
||||
gettimeofday(&t, NULL);
|
||||
#else
|
||||
chronos::steadytimeofday(&t);
|
||||
#endif
|
||||
sec = t.tv_sec;
|
||||
usec = t.tv_usec;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,8 @@
|
|||
#ifndef WINDOWS
|
||||
#include <sys/time.h>
|
||||
#else // from the GNU C library implementation of sys/time.h
|
||||
|
||||
#include <Windows.h>
|
||||
#include <stdint.h>
|
||||
#include <winsock2.h>
|
||||
|
||||
#define timersub(a, b, result) \
|
||||
|
@ -45,37 +46,6 @@
|
|||
} while (0)
|
||||
|
||||
#define CLOCK_MONOTONIC 42 // discarded on windows plaforms
|
||||
|
||||
// from http://stackoverflow.com/a/38212960/2510022
|
||||
#define BILLION (1E9)
|
||||
|
||||
static BOOL g_first_time = 1;
|
||||
static LARGE_INTEGER g_counts_per_sec;
|
||||
|
||||
inline static int clock_gettime(int dummy, struct timespec* ct)
|
||||
{
|
||||
LARGE_INTEGER count;
|
||||
|
||||
if (g_first_time)
|
||||
{
|
||||
g_first_time = 0;
|
||||
|
||||
if (0 == QueryPerformanceFrequency(&g_counts_per_sec))
|
||||
{
|
||||
g_counts_per_sec.QuadPart = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ((NULL == ct) || (g_counts_per_sec.QuadPart <= 0) || (0 == QueryPerformanceCounter(&count)))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ct->tv_sec = count.QuadPart / g_counts_per_sec.QuadPart;
|
||||
ct->tv_nsec = ((count.QuadPart % g_counts_per_sec.QuadPart) * BILLION) / g_counts_per_sec.QuadPart;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace chronos
|
||||
|
@ -101,9 +71,35 @@ inline static void timeofday(struct timeval* tv)
|
|||
tv->tv_usec = microsecs.count() % 1000000;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
// Implementation from http://stackoverflow.com/a/26085827/2510022
|
||||
inline static int gettimeofday(struct timeval* tp, struct timezone* tzp)
|
||||
{
|
||||
// Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's
|
||||
static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL);
|
||||
|
||||
SYSTEMTIME system_time;
|
||||
FILETIME file_time;
|
||||
uint64_t time;
|
||||
|
||||
GetSystemTime(&system_time);
|
||||
SystemTimeToFileTime(&system_time, &file_time);
|
||||
time = ((uint64_t)file_time.dwLowDateTime);
|
||||
time += ((uint64_t)file_time.dwHighDateTime) << 32;
|
||||
|
||||
tp->tv_sec = (long)((time - EPOCH) / 10000000L);
|
||||
tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline static void steadytimeofday(struct timeval* tv)
|
||||
{
|
||||
#ifndef WINDOWS
|
||||
timeofday<clk>(tv);
|
||||
#else
|
||||
gettimeofday(tv, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline static void systemtimeofday(struct timeval* tv)
|
||||
|
@ -142,13 +138,15 @@ inline static void addUs(timeval& tv, int us)
|
|||
|
||||
inline static long getTickCount()
|
||||
{
|
||||
#ifdef MACOS
|
||||
#if defined (MACOS)
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
||||
clock_get_time(cclock, &mts);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
return mts.tv_sec * 1000 + mts.tv_nsec / 1000000;
|
||||
#elif defined(WINDOWS)
|
||||
return getTickCount();
|
||||
#else
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue