report stream state

This commit is contained in:
badaix 2016-03-06 22:30:23 +01:00
parent cd2daa2cf9
commit 94629f9909
9 changed files with 79 additions and 12 deletions

View file

@ -32,7 +32,7 @@ using namespace std;
PcmReader::PcmReader(PcmListener* pcmListener, const ReaderUri& uri) : pcmListener_(pcmListener), uri_(uri), pcmReadMs_(20)
PcmReader::PcmReader(PcmListener* pcmListener, const ReaderUri& uri) : pcmListener_(pcmListener), uri_(uri), pcmReadMs_(20), state_(kIdle)
{
EncoderFactory encoderFactory;
if (uri_.query.find("codec") == uri_.query.end())
@ -104,6 +104,22 @@ void PcmReader::stop()
}
ReaderState PcmReader::getState() const
{
return state_;
}
void PcmReader::setState(const ReaderState& newState)
{
if (newState != state_)
{
state_ = newState;
pcmListener_->onStateChanged(this, newState);
}
}
void PcmReader::onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, double duration)
{
// logO << "onChunkEncoded: " << duration << " us\n";
@ -116,3 +132,22 @@ void PcmReader::onChunkEncoded(const Encoder* encoder, msg::PcmChunk* chunk, dou
pcmListener_->onChunkRead(this, chunk, duration);
}
json PcmReader::toJson() const
{
string state("idle");
if (state_ == kIdle)
state = "idle";
else if (state_ == kPlaying)
state = "playing";
else if (state_ == kDisabled)
state = "disabled";
json j = {
{"uri", uri_.toJson()},
{"id", uri_.id()},
{"status", state}
};
return j;
}