mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-20 20:46:16 +02:00
Added dummy classes for spotify stream reader
This commit is contained in:
parent
accb15c98f
commit
17879618c7
10 changed files with 223 additions and 6 deletions
1
externals/vorbis
vendored
Submodule
1
externals/vorbis
vendored
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 143caf4023a90c09a5eb685fdd46fb9b9c36b1ee
|
|
@ -10,7 +10,7 @@ else
|
||||||
endif
|
endif
|
||||||
|
|
||||||
CXXFLAGS += -std=c++0x -Wall -Wno-unused-function -O3 -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -I../externals/asio/asio/include -I../externals/popl/include
|
CXXFLAGS += -std=c++0x -Wall -Wno-unused-function -O3 -DASIO_STANDALONE -DVERSION=\"$(VERSION)\" -I. -I.. -I../externals/asio/asio/include -I../externals/popl/include
|
||||||
OBJ = snapServer.o config.o controlServer.o controlSession.o streamServer.o streamSession.o json/jsonrpc.o streamreader/streamUri.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o ../common/log.o ../common/sampleFormat.o ../message/pcmChunk.o
|
OBJ = snapServer.o config.o controlServer.o controlSession.o streamServer.o streamSession.o json/jsonrpc.o streamreader/streamUri.o streamreader/streamManager.o streamreader/pcmStream.o streamreader/pipeStream.o streamreader/fileStream.o streamreader/processStream.o streamreader/spotifyStream.o encoder/encoderFactory.o encoder/flacEncoder.o encoder/pcmEncoder.o encoder/oggEncoder.o ../common/log.o ../common/sampleFormat.o ../message/pcmChunk.o
|
||||||
|
|
||||||
ifeq ($(ENDIAN), BIG)
|
ifeq ($(ENDIAN), BIG)
|
||||||
CXXFLAGS += -DIS_BIG_ENDIAN
|
CXXFLAGS += -DIS_BIG_ENDIAN
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
#ifndef FILE_READER_H
|
#ifndef FILE_STREAM_H
|
||||||
#define FILE_READER_H
|
#define FILE_STREAM_H
|
||||||
|
|
||||||
#include "pcmStream.h"
|
#include "pcmStream.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
#ifndef PCM_READER_H
|
#ifndef PCM_STREAM_H
|
||||||
#define PCM_READER_H
|
#define PCM_STREAM_H
|
||||||
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
|
@ -24,9 +24,9 @@
|
||||||
|
|
||||||
#include "pipeStream.h"
|
#include "pipeStream.h"
|
||||||
#include "encoder/encoderFactory.h"
|
#include "encoder/encoderFactory.h"
|
||||||
#include "common/log.h"
|
|
||||||
#include "common/snapException.h"
|
#include "common/snapException.h"
|
||||||
#include "common/strCompat.h"
|
#include "common/strCompat.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
86
server/streamreader/processStream.cpp
Normal file
86
server/streamreader/processStream.cpp
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
/***
|
||||||
|
This file is part of snapcast
|
||||||
|
Copyright (C) 2014-2016 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 <unistd.h>
|
||||||
|
|
||||||
|
#include "processStream.h"
|
||||||
|
#include "common/log.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ProcessStream::ProcessStream(PcmListener* pcmListener, const StreamUri& uri) : PcmStream(pcmListener, uri)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ProcessStream::~ProcessStream()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ProcessStream::worker()
|
||||||
|
{
|
||||||
|
timeval tvChunk;
|
||||||
|
std::unique_ptr<msg::PcmChunk> chunk(new msg::PcmChunk(sampleFormat_, pcmReadMs_));
|
||||||
|
|
||||||
|
setState(kPlaying);
|
||||||
|
|
||||||
|
while (active_)
|
||||||
|
{
|
||||||
|
gettimeofday(&tvChunk, NULL);
|
||||||
|
tvEncodedChunk_ = tvChunk;
|
||||||
|
long nextTick = chronos::getTickCount();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
while (active_)
|
||||||
|
{
|
||||||
|
chunk->timestamp.sec = tvChunk.tv_sec;
|
||||||
|
chunk->timestamp.usec = tvChunk.tv_usec;
|
||||||
|
size_t toRead = chunk->payloadSize;
|
||||||
|
size_t count = 0;
|
||||||
|
|
||||||
|
//// read
|
||||||
|
|
||||||
|
encoder_->encode(chunk.get());
|
||||||
|
nextTick += pcmReadMs_;
|
||||||
|
chronos::addUs(tvChunk, pcmReadMs_ * 1000);
|
||||||
|
long currentTick = chronos::getTickCount();
|
||||||
|
|
||||||
|
if (nextTick >= currentTick)
|
||||||
|
{
|
||||||
|
usleep((nextTick - currentTick) * 1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gettimeofday(&tvChunk, NULL);
|
||||||
|
tvEncodedChunk_ = tvChunk;
|
||||||
|
pcmListener_->onResync(this, currentTick - nextTick);
|
||||||
|
nextTick = currentTick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const std::exception& e)
|
||||||
|
{
|
||||||
|
logE << "Exception: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
server/streamreader/processStream.h
Normal file
43
server/streamreader/processStream.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/***
|
||||||
|
This file is part of snapcast
|
||||||
|
Copyright (C) 2014-2016 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/>.
|
||||||
|
***/
|
||||||
|
|
||||||
|
#ifndef PROCESS_STREAM_H
|
||||||
|
#define PROCESS_STREAM_H
|
||||||
|
|
||||||
|
#include "pcmStream.h"
|
||||||
|
|
||||||
|
|
||||||
|
/// Starts an external process and reads and PCM data from stdout
|
||||||
|
/**
|
||||||
|
* Starts an external process, reads PCM data from stdout, and passes the data to an encoder.
|
||||||
|
* Implements EncoderListener to get the encoded data.
|
||||||
|
* Data is passed to the PcmListener
|
||||||
|
*/
|
||||||
|
class ProcessStream : public PcmStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// ctor. Encoded PCM data is passed to the PipeListener
|
||||||
|
ProcessStream(PcmListener* pcmListener, const StreamUri& uri);
|
||||||
|
virtual ~ProcessStream();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void worker();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
35
server/streamreader/spotifyStream.cpp
Normal file
35
server/streamreader/spotifyStream.cpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/***
|
||||||
|
This file is part of snapcast
|
||||||
|
Copyright (C) 2014-2016 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 "spotifyStream.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
SpotifyStream::SpotifyStream(PcmListener* pcmListener, const StreamUri& uri) : ProcessStream(pcmListener, uri)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SpotifyStream::~SpotifyStream()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
40
server/streamreader/spotifyStream.h
Normal file
40
server/streamreader/spotifyStream.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/***
|
||||||
|
This file is part of snapcast
|
||||||
|
Copyright (C) 2014-2016 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/>.
|
||||||
|
***/
|
||||||
|
|
||||||
|
#ifndef SPOTIFY_STREAM_H
|
||||||
|
#define SPOTIFY_STREAM_H
|
||||||
|
|
||||||
|
#include "processStream.h"
|
||||||
|
|
||||||
|
|
||||||
|
/// Starts librespot and reads and PCM data from stdout
|
||||||
|
/**
|
||||||
|
* Starts librespot, reads PCM data from stdout, and passes the data to an encoder.
|
||||||
|
* Implements EncoderListener to get the encoded data.
|
||||||
|
* Data is passed to the PcmListener
|
||||||
|
*/
|
||||||
|
class SpotifyStream : public ProcessStream
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// ctor. Encoded PCM data is passed to the PipeListener
|
||||||
|
SpotifyStream(PcmListener* pcmListener, const StreamUri& uri);
|
||||||
|
virtual ~SpotifyStream();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
|
@ -17,6 +17,8 @@
|
||||||
***/
|
***/
|
||||||
|
|
||||||
#include "streamManager.h"
|
#include "streamManager.h"
|
||||||
|
#include "spotifyStream.h"
|
||||||
|
#include "processStream.h"
|
||||||
#include "pipeStream.h"
|
#include "pipeStream.h"
|
||||||
#include "fileStream.h"
|
#include "fileStream.h"
|
||||||
#include "common/utils.h"
|
#include "common/utils.h"
|
||||||
|
@ -62,6 +64,16 @@ PcmStream* StreamManager::addStream(const std::string& uri)
|
||||||
streams_.push_back(make_shared<FileStream>(pcmListener_, streamUri));
|
streams_.push_back(make_shared<FileStream>(pcmListener_, streamUri));
|
||||||
return streams_.back().get();
|
return streams_.back().get();
|
||||||
}
|
}
|
||||||
|
else if (streamUri.scheme == "process")
|
||||||
|
{
|
||||||
|
streams_.push_back(make_shared<ProcessStream>(pcmListener_, streamUri));
|
||||||
|
return streams_.back().get();
|
||||||
|
}
|
||||||
|
else if (streamUri.scheme == "spotify")
|
||||||
|
{
|
||||||
|
streams_.push_back(make_shared<SpotifyStream>(pcmListener_, streamUri));
|
||||||
|
return streams_.back().get();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw SnapException("Unknown stream type: " + streamUri.scheme);
|
throw SnapException("Unknown stream type: " + streamUri.scheme);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue