mirror of
https://github.com/badaix/snapcast.git
synced 2025-07-21 10:27:39 +02:00
PCM reader is configured by URI
This commit is contained in:
parent
c4094a2175
commit
a9015edb22
9 changed files with 108 additions and 84 deletions
|
@ -24,6 +24,7 @@
|
|||
#include "pcmReader.h"
|
||||
#include "../encoder/encoderFactory.h"
|
||||
#include "common/utils.h"
|
||||
#include "common/compat.h"
|
||||
#include "common/snapException.h"
|
||||
#include "common/log.h"
|
||||
|
||||
|
@ -35,6 +36,7 @@ ReaderUri::ReaderUri(const std::string& uri)
|
|||
{
|
||||
// https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
|
||||
// scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
|
||||
// would be more elegant with regex. Not yet supported on my dev machine's gcc 4.8 :(
|
||||
size_t pos;
|
||||
this->uri = uri;
|
||||
string tmp(uri);
|
||||
|
@ -44,7 +46,7 @@ ReaderUri::ReaderUri(const std::string& uri)
|
|||
throw invalid_argument("missing ':'");
|
||||
scheme = tmp.substr(0, pos);
|
||||
tmp = tmp.substr(pos + 1);
|
||||
// logD << "scheme: '" << scheme << "' tmp: '" << tmp << "'\n";
|
||||
logE << "scheme: '" << scheme << "' tmp: '" << tmp << "'\n";
|
||||
|
||||
if (tmp.find("//") != 0)
|
||||
throw invalid_argument("missing host separator: '//'");
|
||||
|
@ -54,9 +56,9 @@ ReaderUri::ReaderUri(const std::string& uri)
|
|||
if (pos == string::npos)
|
||||
throw invalid_argument("missing path separator: '/'");
|
||||
host = tmp.substr(0, pos);
|
||||
tmp = tmp.substr(pos + 1);
|
||||
tmp = tmp.substr(pos);
|
||||
path = tmp;
|
||||
// logD << "host: '" << host << "' tmp: '" << tmp << "' path: '" << path << "'\n";
|
||||
logE << "host: '" << host << "' tmp: '" << tmp << "' path: '" << path << "'\n";
|
||||
|
||||
pos = tmp.find('?');
|
||||
if (pos == string::npos)
|
||||
|
@ -65,7 +67,7 @@ ReaderUri::ReaderUri(const std::string& uri)
|
|||
path = tmp.substr(0, pos);
|
||||
tmp = tmp.substr(pos + 1);
|
||||
string queryStr = tmp;
|
||||
// logD << "path: '" << path << "' tmp: '" << tmp << "' query: '" << queryStr << "'\n";
|
||||
logE << "path: '" << path << "' tmp: '" << tmp << "' query: '" << queryStr << "'\n";
|
||||
|
||||
pos = tmp.find('#');
|
||||
if (pos != string::npos)
|
||||
|
@ -73,7 +75,7 @@ ReaderUri::ReaderUri(const std::string& uri)
|
|||
queryStr = tmp.substr(0, pos);
|
||||
tmp = tmp.substr(pos + 1);
|
||||
fragment = tmp;
|
||||
// logD << "query: '" << queryStr << "' fragment: '" << fragment << "' tmp: '" << tmp << "'\n";
|
||||
logE << "query: '" << queryStr << "' fragment: '" << fragment << "' tmp: '" << tmp << "'\n";
|
||||
}
|
||||
|
||||
vector<string> keyValueList = split(queryStr, '&');
|
||||
|
@ -89,10 +91,24 @@ ReaderUri::ReaderUri(const std::string& uri)
|
|||
}
|
||||
|
||||
|
||||
PcmReader::PcmReader(PcmListener* pcmListener, const msg::SampleFormat& sampleFormat, const std::string& codec, const std::string& fifoName, size_t pcmReadMs) : pcmListener_(pcmListener), sampleFormat_(sampleFormat), pcmReadMs_(pcmReadMs)
|
||||
PcmReader::PcmReader(PcmListener* pcmListener, const ReaderUri& uri) : pcmListener_(pcmListener), uri_(uri), pcmReadMs_(20)
|
||||
{
|
||||
EncoderFactory encoderFactory;
|
||||
encoder_.reset(encoderFactory.createEncoder(codec));
|
||||
if (uri_.query.find("codec") == uri_.query.end())
|
||||
throw SnapException("Stream URI must have a codec");
|
||||
encoder_.reset(encoderFactory.createEncoder(uri_.query["codec"]));
|
||||
|
||||
if (uri_.query.find("name") == uri_.query.end())
|
||||
throw SnapException("Stream URI must have a name");
|
||||
name_ = uri_.query["name"];
|
||||
|
||||
if (uri_.query.find("sampleformat") == uri_.query.end())
|
||||
throw SnapException("Stream URI must have a sampleformat");
|
||||
sampleFormat_ = SampleFormat(uri_.query["sampleformat"]);
|
||||
logE << "PcmReader sampleFormat: " << sampleFormat_.getFormat() << "\n";
|
||||
|
||||
if (uri_.query.find("buffer_ms") != uri_.query.end())
|
||||
pcmReadMs_ = cpt::stoul(uri_.query["buffer_ms"]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -108,8 +124,27 @@ msg::Header* PcmReader::getHeader()
|
|||
}
|
||||
|
||||
|
||||
const ReaderUri& PcmReader::getUri() const
|
||||
{
|
||||
return uri_;
|
||||
}
|
||||
|
||||
|
||||
const std::string& PcmReader::getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
|
||||
const SampleFormat& PcmReader::getSampleFormat() const
|
||||
{
|
||||
return sampleFormat_;
|
||||
}
|
||||
|
||||
|
||||
void PcmReader::start()
|
||||
{
|
||||
logE << "PcmReader start: " << sampleFormat_.getFormat() << "\n";
|
||||
encoder_->init(this, sampleFormat_);
|
||||
active_ = true;
|
||||
readerThread_ = thread(&PcmReader::worker, this);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue