stream notifies about new chunks

This commit is contained in:
badaix 2015-08-18 22:01:08 +02:00
parent 74dab4ca10
commit 446f2a2f34
4 changed files with 25 additions and 3 deletions

View file

@ -201,13 +201,15 @@ void Player::worker()
else else
{ {
logO << "Failed to get chunk\n"; logO << "Failed to get chunk\n";
usleep(100*1000); while (active_ && !stream_->waitForChunk(100))
logD << "Waiting for chunk\n";
} }
} }
} }
vector<PcmDevice> Player::pcm_list(void) { vector<PcmDevice> Player::pcm_list(void)
{
void **hints, **n; void **hints, **n;
char *name, *descr, *io; char *name, *descr, *io;
vector<PcmDevice> result; vector<PcmDevice> result;

View file

@ -74,10 +74,20 @@ void Stream::addChunk(msg::PcmChunk* chunk)
while (chunks_.size() * chunk->duration<cs::msec>().count() > 10000) while (chunks_.size() * chunk->duration<cs::msec>().count() > 10000)
chunks_.pop(); chunks_.pop();
chunks_.push(shared_ptr<msg::PcmChunk>(chunk)); chunks_.push(shared_ptr<msg::PcmChunk>(chunk));
std::unique_lock<std::mutex> lck(cvMutex_);
cv_.notify_one();
// logD << "new chunk: " << chunk_->getDuration() << ", Chunks: " << chunks_.size() << "\n"; // logD << "new chunk: " << chunk_->getDuration() << ", Chunks: " << chunks_.size() << "\n";
} }
bool Stream::waitForChunk(size_t ms) const
{
std::unique_lock<std::mutex> lck(cvMutex_);
cv_.wait_for(lck, std::chrono::milliseconds(ms));
return !chunks_.empty();
}
cs::time_point_hrc Stream::getSilentPlayerChunk(void* outputBuffer, unsigned long framesPerBuffer) cs::time_point_hrc Stream::getSilentPlayerChunk(void* outputBuffer, unsigned long framesPerBuffer)
{ {

View file

@ -54,12 +54,14 @@ public:
/// "Server buffer": playout latency, e.g. 1000ms /// "Server buffer": playout latency, e.g. 1000ms
void setBufferLen(size_t bufferLenMs); void setBufferLen(size_t bufferLenMs);
const msg::SampleFormat& getFormat() const const msg::SampleFormat& getFormat() const
{ {
return format_; return format_;
} }
bool waitForChunk(size_t ms) const;
private: private:
chronos::time_point_hrc getNextPlayerChunk(void* outputBuffer, const chronos::usec& timeout, unsigned long framesPerBuffer); chronos::time_point_hrc getNextPlayerChunk(void* outputBuffer, const chronos::usec& timeout, unsigned long framesPerBuffer);
chronos::time_point_hrc getNextPlayerChunk(void* outputBuffer, const chronos::usec& timeout, unsigned long framesPerBuffer, long framesCorrection); chronos::time_point_hrc getNextPlayerChunk(void* outputBuffer, const chronos::usec& timeout, unsigned long framesPerBuffer, long framesCorrection);
@ -88,6 +90,9 @@ private:
unsigned long playedFrames_; unsigned long playedFrames_;
long correctAfterXFrames_; long correctAfterXFrames_;
chronos::msec bufferMs_; chronos::msec bufferMs_;
mutable std::condition_variable cv_;
mutable std::mutex cvMutex_;
}; };

View file

@ -101,6 +101,11 @@ public:
return queue_.size(); return queue_.size();
} }
bool empty() const
{
return (size() == 0);
}
Queue()=default; Queue()=default;
Queue(const Queue&) = delete; // disable copying Queue(const Queue&) = delete; // disable copying
Queue& operator=(const Queue&) = delete; // disable assignment Queue& operator=(const Queue&) = delete; // disable assignment