mirror of
https://github.com/badaix/snapcast.git
synced 2025-08-04 09:08:47 +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
|
@ -1,2 +1 @@
|
|||
add_library(common STATIC daemon.cpp sampleFormat.cpp)
|
||||
add_subdirectory(message)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef ENDIAN_H
|
||||
#define ENDIAN_H
|
||||
#ifndef ENDIAN_HPP
|
||||
#define ENDIAN_HPP
|
||||
|
||||
#ifdef IS_BIG_ENDIAN
|
||||
# define SWAP_16(x) (__builtin_bswap16(x))
|
||||
|
@ -16,7 +16,7 @@ namespace endian
|
|||
|
||||
template <typename T>
|
||||
T swap(const T&);
|
||||
|
||||
|
||||
template <>
|
||||
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
|
||||
{
|
||||
public:
|
||||
PcmChunk(const SampleFormat& sampleFormat, size_t ms);
|
||||
PcmChunk(const PcmChunk& pcmChunk);
|
||||
PcmChunk();
|
||||
virtual ~PcmChunk();
|
||||
PcmChunk(const SampleFormat& sampleFormat, size_t ms) :
|
||||
WireChunk(sampleFormat.rate*sampleFormat.frameSize*ms / 1000),
|
||||
format(sampleFormat),
|
||||
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
|
||||
{
|
||||
|
|
|
@ -51,6 +51,9 @@
|
|||
#include <IOKit/IOCFPlugIn.h>
|
||||
#include <IOKit/IOTypes.h>
|
||||
#endif
|
||||
#ifdef ANDROID
|
||||
#include <sys/system_properties.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace strutils = utils::string;
|
||||
|
@ -74,9 +77,13 @@ static std::string execGetOutput(const std::string& cmd)
|
|||
|
||||
|
||||
#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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue