added "TARGET=MAC" and dummy CoreAudio player

This commit is contained in:
Johannes Pohl 2016-09-11 20:51:01 +02:00
parent 875bbf9551
commit 71e0a89e29
8 changed files with 119 additions and 5 deletions

View file

@ -10,7 +10,7 @@ else
endif
CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function -O3 -pthread -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -I../externals/asio/asio/include -I../externals/popl/include
CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function -O3 -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -I../externals/asio/asio/include -I../externals/popl/include
OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o decoder/pcmDecoder.o decoder/oggDecoder.o decoder/flacDecoder.o controller.o ../message/pcmChunk.o ../common/log.o ../common/sampleFormat.o
ifeq ($(ENDIAN), BIG)
@ -21,22 +21,30 @@ ifeq ($(TARGET), ANDROID)
CXX = $(NDK_DIR)/bin/arm-linux-androideabi-g++
STRIP = $(NDK_DIR)/bin/arm-linux-androideabi-strip
CXXFLAGS += -DANDROID -DNO_CPP11_STRING -fPIC -DHAS_TREMOR -DHAS_OPENSL -I$(NDK_DIR)/include
CXXFLAGS += -pthread -DANDROID -DNO_CPP11_STRING -fPIC -DHAS_TREMOR -DHAS_OPENSL -I$(NDK_DIR)/include
LDFLAGS = -L$(NDK_DIR)/lib -pie -lvorbisidec -logg -lFLAC -lOpenSLES
OBJ += player/openslPlayer.o
else ifeq ($(TARGET), OPENWRT)
STRIP = echo
CXXFLAGS += -DNO_CPP11_STRING -DHAS_TREMOR -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
CXXFLAGS += -pthread -DNO_CPP11_STRING -DHAS_TREMOR -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
LDFLAGS = -lasound -lvorbisidec -logg -lFLAC -lavahi-client -lavahi-common -latomic
OBJ += player/alsaPlayer.o browseAvahi.o
else ifeq ($(TARGET), MAC)
CXX = /usr/bin/g++
STRIP = strip
CXXFLAGS += -DHAS_TREMOR -DHAS_COREAUDIO -DFREEBSD -I/usr/local/include -Wno-unused-local-typedef
LDFLAGS = -logg -lvorbisidec -lFLAC -L/usr/local/lib -framework AudioToolbox -framework CoreFoundation
OBJ += player/coreAudioPlayer.o
else
CXX = /usr/bin/g++
STRIP = strip
CXXFLAGS += -DHAS_OGG -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
CXXFLAGS += -pthread -DHAS_OGG -DHAS_ALSA -DHAS_AVAHI -DHAS_DAEMON
LDFLAGS = -lrt -lasound -logg -lvorbis -lFLAC -lavahi-client -lavahi-common -static-libgcc -static-libstdc++
OBJ += player/alsaPlayer.o browseAvahi.o

View file

@ -116,6 +116,8 @@ void Controller::onMessageReceived(ClientConnection* connection, const msg::Base
player_.reset(new AlsaPlayer(pcmDevice_, stream_.get()));
#elif HAS_OPENSL
player_.reset(new OpenslPlayer(pcmDevice_, stream_.get()));
#elif HAS_COREAUDIO
player_.reset(new CoreAudioPlayer(pcmDevice_, stream_.get()));
#else
throw SnapException("No ALSA or OPENSL support");
#endif

View file

@ -29,6 +29,8 @@
#include "player/alsaPlayer.h"
#elif HAS_OPENSL
#include "player/openslPlayer.h"
#elif HAS_COREAUDIO
#include "player/coreAudioPlayer.h"
#endif
#include "clientConnection.h"
#include "stream.h"

View file

@ -0,0 +1,50 @@
/***
This file is part of snapcast
Copyright (C) 2014-2016 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <AudioToolbox/AudioQueue.h>
#include <CoreAudio/CoreAudioTypes.h>
#include <CoreFoundation/CFRunLoop.h>
#include "coreAudioPlayer.h"
//http://stackoverflow.com/questions/4863811/how-to-use-audioqueue-to-play-a-sound-for-mac-osx-in-c
//https://gist.github.com/andormade/1360885
CoreAudioPlayer::CoreAudioPlayer(const PcmDevice& pcmDevice, Stream* stream) : Player(pcmDevice, stream)
{
}
CoreAudioPlayer::~CoreAudioPlayer()
{
}
void CoreAudioPlayer::worker()
{
while (active_)
{
usleep(100*1000);
}
}

View file

@ -0,0 +1,42 @@
/***
This file is part of snapcast
Copyright (C) 2014-2016 Johannes Pohl
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef CORE_AUDIO_PLAYER_H
#define CORE_AUDIO_PLAYER_H
#include "player.h"
/// Audio Player
/**
* Audio player implementation using CoreAudio
*/
class CoreAudioPlayer : public Player
{
public:
CoreAudioPlayer(const PcmDevice& pcmDevice, Stream* stream);
virtual ~CoreAudioPlayer();
protected:
virtual void worker();
};
#endif

View file

@ -41,7 +41,7 @@ void TimeProvider::setDiffToServer(double ms)
gettimeofday(&now, NULL);
/// clear diffBuffer if last update is older than a minute
if (!diffBuffer_.empty() && (abs(now.tv_sec - lastTimeSync) > 60))
if (!diffBuffer_.empty() && (std::abs(now.tv_sec - lastTimeSync) > 60))
{
logO << "Last time sync older than a minute. Clearing time buffer\n";
diffToServer_ = ms*1000;

View file

@ -48,9 +48,15 @@ namespace chronos
inline static long getTickCount()
{
#ifdef __MACH__
struct timeval now;
gettimeofday(&now, NULL);
return now.tv_sec*1000 + now.tv_usec / 1000;
#else
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return now.tv_sec*1000 + now.tv_nsec / 1000000;
#endif
}
template <class Rep, class Period>

View file

@ -91,3 +91,7 @@ libflac8
libogg0
libvorbis0a
libvorbisenc2
*Mac
brew install autoconf automake pkg-config libtool