mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-06 10:09:33 +02:00
move pcmChunk implementation into header
This commit is contained in:
parent
54a8ca824f
commit
b26bd41aff
10 changed files with 65 additions and 100 deletions
|
@ -7,7 +7,7 @@ set(CLIENT_SOURCES
|
||||||
decoder/pcmDecoder.cpp
|
decoder/pcmDecoder.cpp
|
||||||
player/player.cpp)
|
player/player.cpp)
|
||||||
|
|
||||||
set(CLIENT_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} common message)
|
set(CLIENT_LIBRARIES ${CMAKE_THREAD_LIBS_INIT} common)
|
||||||
|
|
||||||
set(CLIENT_INCLUDE
|
set(CLIENT_INCLUDE
|
||||||
${CMAKE_SOURCE_DIR}/client
|
${CMAKE_SOURCE_DIR}/client
|
||||||
|
|
|
@ -36,7 +36,7 @@ DEBUG=-O3
|
||||||
|
|
||||||
CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function $(DEBUG) -DHAS_FLAC -DHAS_OGG -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -isystem ../externals/asio/asio/include -I../externals/popl/include -I../externals/aixlog/include -I../externals -I../common
|
CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function $(DEBUG) -DHAS_FLAC -DHAS_OGG -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -isystem ../externals/asio/asio/include -I../externals/popl/include -I../externals/aixlog/include -I../externals -I../common
|
||||||
LDFLAGS = -logg -lFLAC
|
LDFLAGS = -logg -lFLAC
|
||||||
OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o decoder/pcmDecoder.o decoder/oggDecoder.o decoder/flacDecoder.o controller.o ../common/message/pcmChunk.o ../common/sampleFormat.o
|
OBJ = snapClient.o stream.o clientConnection.o timeProvider.o player/player.o decoder/pcmDecoder.o decoder/oggDecoder.o decoder/flacDecoder.o controller.o ../common/sampleFormat.o
|
||||||
|
|
||||||
|
|
||||||
ifneq (,$(TARGET))
|
ifneq (,$(TARGET))
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
add_library(common STATIC daemon.cpp sampleFormat.cpp)
|
add_library(common STATIC daemon.cpp sampleFormat.cpp)
|
||||||
add_subdirectory(message)
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#ifndef ENDIAN_H
|
#ifndef ENDIAN_HPP
|
||||||
#define ENDIAN_H
|
#define ENDIAN_HPP
|
||||||
|
|
||||||
#ifdef IS_BIG_ENDIAN
|
#ifdef IS_BIG_ENDIAN
|
||||||
# define SWAP_16(x) (__builtin_bswap16(x))
|
# define SWAP_16(x) (__builtin_bswap16(x))
|
||||||
|
@ -16,7 +16,7 @@ namespace endian
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T swap(const T&);
|
T swap(const T&);
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline int8_t swap(const int8_t& val)
|
inline int8_t swap(const int8_t& val)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
add_library(message STATIC pcmChunk.cpp)
|
|
|
@ -1,83 +0,0 @@
|
||||||
/***
|
|
||||||
This file is part of snapcast
|
|
||||||
Copyright (C) 2014-2018 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 <string.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include "pcmChunk.h"
|
|
||||||
#include "aixlog.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
namespace msg
|
|
||||||
{
|
|
||||||
|
|
||||||
PcmChunk::PcmChunk(const SampleFormat& sampleFormat, size_t ms) : WireChunk(sampleFormat.rate*sampleFormat.frameSize*ms / 1000), format(sampleFormat), idx_(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PcmChunk::PcmChunk(const PcmChunk& pcmChunk) : WireChunk(pcmChunk), format(pcmChunk.format), idx_(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PcmChunk::PcmChunk() : WireChunk(), idx_(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PcmChunk::~PcmChunk()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int PcmChunk::seek(int frames)
|
|
||||||
{
|
|
||||||
if ((frames < 0) && (-frames > (int)idx_))
|
|
||||||
frames = -idx_;
|
|
||||||
|
|
||||||
idx_ += frames;
|
|
||||||
if (idx_ > getFrameCount())
|
|
||||||
idx_ = getFrameCount();
|
|
||||||
|
|
||||||
return idx_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int PcmChunk::readFrames(void* outputBuffer, size_t frameCount)
|
|
||||||
{
|
|
||||||
//logd << "read: " << frameCount << ", total: " << (wireChunk->length / format.frameSize) << ", idx: " << idx;// << std::endl;
|
|
||||||
int result = frameCount;
|
|
||||||
if (idx_ + frameCount > (payloadSize / format.frameSize))
|
|
||||||
result = (payloadSize / format.frameSize) - idx_;
|
|
||||||
|
|
||||||
//logd << ", from: " << format.frameSize*idx << ", to: " << format.frameSize*idx + format.frameSize*result;
|
|
||||||
if (outputBuffer != NULL)
|
|
||||||
memcpy((char*)outputBuffer, (char*)(payload) + format.frameSize*idx_, format.frameSize*result);
|
|
||||||
|
|
||||||
idx_ += result;
|
|
||||||
//logd << ", new idx: " << idx << ", result: " << result << ", wireChunk->length: " << wireChunk->length << ", format.frameSize: " << format.frameSize << "\n";//std::endl;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,56 @@ namespace msg
|
||||||
class PcmChunk : public WireChunk
|
class PcmChunk : public WireChunk
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PcmChunk(const SampleFormat& sampleFormat, size_t ms);
|
PcmChunk(const SampleFormat& sampleFormat, size_t ms) :
|
||||||
PcmChunk(const PcmChunk& pcmChunk);
|
WireChunk(sampleFormat.rate*sampleFormat.frameSize*ms / 1000),
|
||||||
PcmChunk();
|
format(sampleFormat),
|
||||||
virtual ~PcmChunk();
|
idx_(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PcmChunk(const PcmChunk& pcmChunk) :
|
||||||
|
WireChunk(pcmChunk),
|
||||||
|
format(pcmChunk.format),
|
||||||
|
idx_(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PcmChunk() : WireChunk(), idx_(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~PcmChunk()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int readFrames(void* outputBuffer, size_t frameCount)
|
||||||
|
{
|
||||||
|
//logd << "read: " << frameCount << ", total: " << (wireChunk->length / format.frameSize) << ", idx: " << idx;// << std::endl;
|
||||||
|
int result = frameCount;
|
||||||
|
if (idx_ + frameCount > (payloadSize / format.frameSize))
|
||||||
|
result = (payloadSize / format.frameSize) - idx_;
|
||||||
|
|
||||||
|
//logd << ", from: " << format.frameSize*idx << ", to: " << format.frameSize*idx + format.frameSize*result;
|
||||||
|
if (outputBuffer != NULL)
|
||||||
|
memcpy((char*)outputBuffer, (char*)(payload) + format.frameSize*idx_, format.frameSize*result);
|
||||||
|
|
||||||
|
idx_ += result;
|
||||||
|
//logd << ", new idx: " << idx << ", result: " << result << ", wireChunk->length: " << wireChunk->length << ", format.frameSize: " << format.frameSize << "\n";//std::endl;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int seek(int frames)
|
||||||
|
{
|
||||||
|
if ((frames < 0) && (-frames > (int)idx_))
|
||||||
|
frames = -idx_;
|
||||||
|
|
||||||
|
idx_ += frames;
|
||||||
|
if (idx_ > getFrameCount())
|
||||||
|
idx_ = getFrameCount();
|
||||||
|
|
||||||
|
return idx_;
|
||||||
|
}
|
||||||
|
|
||||||
int readFrames(void* outputBuffer, size_t frameCount);
|
|
||||||
int seek(int frames);
|
|
||||||
|
|
||||||
virtual chronos::time_point_clk start() const
|
virtual chronos::time_point_clk start() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,6 +51,9 @@
|
||||||
#include <IOKit/IOCFPlugIn.h>
|
#include <IOKit/IOCFPlugIn.h>
|
||||||
#include <IOKit/IOTypes.h>
|
#include <IOKit/IOTypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef ANDROID
|
||||||
|
#include <sys/system_properties.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
namespace strutils = utils::string;
|
namespace strutils = utils::string;
|
||||||
|
@ -74,9 +77,13 @@ static std::string execGetOutput(const std::string& cmd)
|
||||||
|
|
||||||
|
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
static std::string getProp(const std::string& prop)
|
static std::string getProp(const std::string& key, const std::string& def = "")
|
||||||
{
|
{
|
||||||
return execGetOutput("getprop " + prop);
|
std::string result(def);
|
||||||
|
char cresult[PROP_VALUE_MAX+1];
|
||||||
|
if (__system_property_get(key.c_str(), cresult) > 0)
|
||||||
|
result = cresult;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ set(SERVER_SOURCES
|
||||||
set(SERVER_LIBRARIES
|
set(SERVER_LIBRARIES
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
${FLAC_LIBRARIES}
|
${FLAC_LIBRARIES}
|
||||||
common message)
|
common)
|
||||||
|
|
||||||
set(SERVER_INCLUDE
|
set(SERVER_INCLUDE
|
||||||
${CMAKE_SOURCE_DIR}/server
|
${CMAKE_SOURCE_DIR}/server
|
||||||
|
|
|
@ -36,7 +36,7 @@ DEBUG=-O3
|
||||||
|
|
||||||
CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function $(DEBUG) -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -isystem ../externals/asio/asio/include -I../externals/popl/include -I../externals/aixlog/include -I../externals -I../common
|
CXXFLAGS += $(ADD_CFLAGS) -std=c++0x -Wall -Wno-unused-function $(DEBUG) -DHAS_FLAC -DHAS_OGG -DHAS_VORBIS -DHAS_VORBIS_ENC -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -isystem ../externals/asio/asio/include -I../externals/popl/include -I../externals/aixlog/include -I../externals -I../common
|
||||||
LDFLAGS = -lvorbis -lvorbisenc -logg -lFLAC
|
LDFLAGS = -lvorbis -lvorbisenc -logg -lFLAC
|
||||||
OBJ = snapServer.o config.o controlServer.o controlSession.o jsonrp.o streamServer.o streamSession.o streamreader/streamUri.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o streamreader/processStream.o streamreader/airplayStream.o streamreader/spotifyStream.o streamreader/watchdog.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o ../common/sampleFormat.o ../common/message/pcmChunk.o ../common/base64.o
|
OBJ = snapServer.o config.o controlServer.o controlSession.o jsonrp.o streamServer.o streamSession.o streamreader/streamUri.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o streamreader/processStream.o streamreader/airplayStream.o streamreader/spotifyStream.o streamreader/watchdog.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o ../common/sampleFormat.o ../common/base64.o
|
||||||
|
|
||||||
ifneq (,$(TARGET))
|
ifneq (,$(TARGET))
|
||||||
CXXFLAGS += -D$(TARGET)
|
CXXFLAGS += -D$(TARGET)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue