mirror of
https://github.com/badaix/snapcast.git
synced 2025-04-29 18:27:12 +02:00
77 lines
2.2 KiB
C++
77 lines
2.2 KiB
C++
/***
|
|
This file is part of snapcast
|
|
Copyright (C) 2015 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 CONTROLLER_H
|
|
#define CONTROLLER_H
|
|
|
|
#include <thread>
|
|
#include <atomic>
|
|
#include "decoder/decoder.h"
|
|
#include "message/message.h"
|
|
#include "player/pcmDevice.h"
|
|
#ifdef ANDROID
|
|
#include "player/openslPlayer.h"
|
|
#else
|
|
#include "player/alsaPlayer.h"
|
|
#endif
|
|
#include "clientConnection.h"
|
|
#include "stream.h"
|
|
|
|
|
|
/// Forwards PCM data to the audio player
|
|
/**
|
|
* Sets up a connection to the server (using ClientConnection)
|
|
* Sets up the audio decoder and player. Decodes audio feeds PCM to the audio stream buffer
|
|
* Does timesync with the server
|
|
*/
|
|
class Controller : public MessageReceiver
|
|
{
|
|
public:
|
|
Controller();
|
|
void start(const PcmDevice& pcmDevice, const std::string& host, size_t port, size_t latency);
|
|
void stop();
|
|
|
|
/// Implementation of MessageReceiver.
|
|
/// ClientConnection passes messages from the server through these callbacks
|
|
virtual void onMessageReceived(ClientConnection* connection, const msg::BaseMessage& baseMessage, char* buffer);
|
|
|
|
/// Implementation of MessageReceiver.
|
|
/// Used for async exception reporting
|
|
virtual void onException(ClientConnection* connection, const std::exception& exception);
|
|
|
|
private:
|
|
void worker();
|
|
bool sendTimeSyncMessage(long after = 1000);
|
|
std::atomic<bool> active_;
|
|
std::thread* controllerThread_;
|
|
ClientConnection* clientConnection_;
|
|
Stream* stream_;
|
|
std::string ip_;
|
|
std::shared_ptr<msg::SampleFormat> sampleFormat_;
|
|
Decoder* decoder_;
|
|
PcmDevice pcmDevice_;
|
|
size_t latency_;
|
|
std::unique_ptr<Player> player_;
|
|
|
|
std::exception exception_;
|
|
bool asyncException_;
|
|
};
|
|
|
|
|
|
#endif
|
|
|