diff --git a/src/engine/sidechain/enginenetworkstream.cpp b/src/engine/sidechain/enginenetworkstream.cpp index 2bd59e09d81..b09da5e51af 100644 --- a/src/engine/sidechain/enginenetworkstream.cpp +++ b/src/engine/sidechain/enginenetworkstream.cpp @@ -228,7 +228,7 @@ qint64 EngineNetworkStream::getNetworkTimeUs() { #endif } -void EngineNetworkStream::addWorker(QSharedPointer pWorker) { +void EngineNetworkStream::addWorker(QSharedPointer pWorker) { m_pWorker = pWorker; m_pWorker->setOutputFifo(m_pOutputFifo); } diff --git a/src/engine/sidechain/enginenetworkstream.h b/src/engine/sidechain/enginenetworkstream.h index e13e4a17356..a796d60de19 100644 --- a/src/engine/sidechain/enginenetworkstream.h +++ b/src/engine/sidechain/enginenetworkstream.h @@ -3,7 +3,7 @@ #include "util/types.h" #include "util/fifo.h" -#include "engine/sidechain/sidechainworker.h" +#include "engine/sidechain/networkstreamworker.h" class EngineNetworkStream { public: @@ -34,7 +34,7 @@ class EngineNetworkStream { static qint64 getNetworkTimeUs(); - void addWorker(QSharedPointer pWorker); + void addWorker(QSharedPointer pWorker); private: void scheduleWorker(); @@ -47,7 +47,7 @@ class EngineNetworkStream { qint64 m_streamStartTimeUs; qint64 m_streamFramesWritten; qint64 m_streamFramesRead; - QSharedPointer m_pWorker; + QSharedPointer m_pWorker; int m_writeOverflowCount; }; diff --git a/src/engine/sidechain/engineshoutcast.cpp b/src/engine/sidechain/engineshoutcast.cpp index 9c67848073a..a7f62ac9bfe 100644 --- a/src/engine/sidechain/engineshoutcast.cpp +++ b/src/engine/sidechain/engineshoutcast.cpp @@ -71,11 +71,11 @@ EngineShoutcast::EngineShoutcast(ConfigObject* _config) signal(SIGPIPE, SIG_IGN); #endif - m_pShoutcastStatus->set(SIDECHAINWORKER_STATE_DISCONNECTED); + m_pShoutcastStatus->set(NETWORKSTREAMWORKER_STATE_DISCONNECTED); m_pShoutcastNeedUpdateFromPrefs = new ControlObject( ConfigKey(SHOUTCAST_PREF_KEY,"update_from_prefs")); - setState(SIDECHAINWORKER_STATE_INIT); + setState(NETWORKSTREAMWORKER_STATE_INIT); // Initialize libshout shout_init(); @@ -114,7 +114,7 @@ EngineShoutcast::~EngineShoutcast() { bool EngineShoutcast::serverDisconnect() { m_bThreadQuit = true; wait(); - setState(SIDECHAINWORKER_STATE_DISCONNECTED); + setState(NETWORKSTREAMWORKER_STATE_DISCONNECTED); return false; // if no connection has been established, nothing can be disconnected } @@ -137,7 +137,7 @@ QByteArray EngineShoutcast::encodeString(const QString& string) { void EngineShoutcast::updateFromPreferences() { qDebug() << "EngineShoutcast: updating from preferences"; - setState(SIDECHAINWORKER_STATE_BUSY); + setState(NETWORKSTREAMWORKER_STATE_BUSY); m_pShoutcastNeedUpdateFromPrefs->set(0.0); m_format_is_mp3 = false; @@ -357,12 +357,12 @@ void EngineShoutcast::updateFromPreferences() { delete m_encoder; m_encoder = NULL; } - setState(SIDECHAINWORKER_STATE_READY); + setState(NETWORKSTREAMWORKER_STATE_READY); } bool EngineShoutcast::serverConnect() { start(); - setState(SICECHAINWORKER_STATE_CONNECTING); + setState(NETWORKSTREAMWORKER_STATE_CONNECTING); return true; } @@ -370,7 +370,7 @@ bool EngineShoutcast::processConnect() { // set to busy in case another thread calls one of the other // EngineShoutcast calls m_iShoutStatus = SHOUTERR_BUSY; - m_pShoutcastStatus->set(SICECHAINWORKER_STATE_CONNECTING); + m_pShoutcastStatus->set(NETWORKSTREAMWORKER_STATE_CONNECTING); // reset the number of failures to zero m_iShoutFailures = 0; // set to a high number to automatically update the metadata @@ -399,7 +399,7 @@ bool EngineShoutcast::processConnect() { m_iShoutStatus = shout_open(m_pShout); if (m_iShoutStatus == SHOUTERR_SUCCESS) { m_iShoutStatus = SHOUTERR_CONNECTED; - setState(SICECHAINWORKER_STATE_CONNECTED); + setState(NETWORKSTREAMWORKER_STATE_CONNECTED); } if ((m_iShoutStatus == SHOUTERR_BUSY) || @@ -415,25 +415,25 @@ bool EngineShoutcast::processConnect() { if (m_pShout) { shout_close(m_pShout); } - setState(SIDECHAINWORKER_STATE_ERROR); + setState(NETWORKSTREAMWORKER_STATE_ERROR); m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY,"enabled"),ConfigValue("0")); - m_pShoutcastStatus->set(SIDECHAINWORKER_STATE_DISCONNECTED); + m_pShoutcastStatus->set(NETWORKSTREAMWORKER_STATE_DISCONNECTED); return false; } m_iShoutFailures = 0; int timeout = 0; while (m_iShoutStatus == SHOUTERR_BUSY && timeout < TIMEOUT) { - setState(SIDECHAINWORKER_STATE_WAITING); + setState(NETWORKSTREAMWORKER_STATE_WAITING); qDebug() << "Connection pending. Sleeping..."; sleep(1); m_iShoutStatus = shout_get_connected(m_pShout); ++ timeout; } if (m_iShoutStatus == SHOUTERR_CONNECTED) { - setState(SIDECHAINWORKER_STATE_READY); + setState(NETWORKSTREAMWORKER_STATE_READY); qDebug() << "***********Connected to streaming server..."; - m_pShoutcastStatus->set(SICECHAINWORKER_STATE_CONNECTED); + m_pShoutcastStatus->set(NETWORKSTREAMWORKER_STATE_CONNECTED); // Signal user also that we are connected infoDialog(tr("Mixxx has successfully connected to the streaming server"), ""); @@ -443,14 +443,14 @@ bool EngineShoutcast::processConnect() { return true; } - setState(SIDECHAINWORKER_STATE_ERROR); + setState(NETWORKSTREAMWORKER_STATE_ERROR); //otherwise disable shoutcast in preferences m_pConfig->set(ConfigKey(SHOUTCAST_PREF_KEY,"enabled"),ConfigValue("0")); if (m_pShout) { shout_close(m_pShout); //errorDialog(tr("Mixxx could not connect to the server"), tr("Please check your connection to the Internet and verify that your username and password are correct.")); } - m_pShoutcastStatus->set(SIDECHAINWORKER_STATE_DISCONNECTED); + m_pShoutcastStatus->set(NETWORKSTREAMWORKER_STATE_DISCONNECTED); return false; } @@ -458,7 +458,7 @@ void EngineShoutcast::processDisconnect() { if (isConnected()) { // We are conneced but shoutcast is disabled. Disconnect. shout_close(m_pShout); - m_pShoutcastStatus->set(SIDECHAINWORKER_STATE_DISCONNECTED); + m_pShoutcastStatus->set(NETWORKSTREAMWORKER_STATE_DISCONNECTED); infoDialog(tr("Mixxx has successfully disconnected from the streaming server"), ""); } @@ -525,7 +525,7 @@ void EngineShoutcast::write(unsigned char *header, unsigned char *body, void EngineShoutcast::process(const CSAMPLE* pBuffer, const int iBufferSize) { - setState(SIDECHAINWORKER_STATE_BUSY); + setState(NETWORKSTREAMWORKER_STATE_BUSY); // If we are here then the user wants to be connected (shoutcast is enabled // in the preferences). @@ -559,7 +559,7 @@ void EngineShoutcast::process(const CSAMPLE* pBuffer, const int iBufferSize) { if (metaDataHasChanged()) { updateMetaData(); } - setState(SIDECHAINWORKER_STATE_READY); + setState(NETWORKSTREAMWORKER_STATE_READY); } bool EngineShoutcast::metaDataHasChanged() { @@ -700,7 +700,7 @@ void EngineShoutcast::errorDialog(QString text, QString detailedError) { props->setDefaultButton(QMessageBox::Close); props->setModal(false); ErrorDialogHandler::instance()->requestErrorDialog(props); - setState(SIDECHAINWORKER_STATE_ERROR); + setState(NETWORKSTREAMWORKER_STATE_ERROR); } void EngineShoutcast::infoDialog(QString text, QString detailedInfo) { @@ -730,10 +730,10 @@ void EngineShoutcast::run() { QThread::currentThread()->setObjectName(QString("EngineShoutcast %1").arg(++id)); qDebug() << "EngineShoutcast::run: starting thread"; - setState(SIDECHAINWORKER_STATE_BUSY); + setState(NETWORKSTREAMWORKER_STATE_BUSY); processConnect(); - setState(SIDECHAINWORKER_STATE_WAITING); + setState(NETWORKSTREAMWORKER_STATE_WAITING); DEBUG_ASSERT_AND_HANDLE(m_pOutputFifo) { return; } @@ -741,7 +741,7 @@ void EngineShoutcast::run() { m_pOutputFifo->flushReadData(m_pOutputFifo->readAvailable()); } m_threadWaiting = true; - setState(SIDECHAINWORKER_STATE_READY); + setState(NETWORKSTREAMWORKER_STATE_READY); for(;;) { m_readSema.acquire(); // Check to see if Shoutcast is enabled, and pass the samples off to be diff --git a/src/engine/sidechain/engineshoutcast.h b/src/engine/sidechain/engineshoutcast.h index 7c3158a35b2..2fe01729889 100644 --- a/src/engine/sidechain/engineshoutcast.h +++ b/src/engine/sidechain/engineshoutcast.h @@ -31,7 +31,7 @@ #include "controlobjectthread.h" #include "controlobjectslave.h" #include "encoder/encodercallback.h" -#include "engine/sidechain/sidechainworker.h" +#include "engine/sidechain/networkstreamworker.h" #include "errordialoghandler.h" #include "trackinfoobject.h" #include "util/fifo.h" @@ -45,7 +45,8 @@ typedef struct shout shout_t; struct _util_dict; typedef struct _util_dict shout_metadata_t; -class EngineShoutcast : public QThread, public EncoderCallback, public SideChainWorker { +class EngineShoutcast : + public QThread, public EncoderCallback, public NetworkStreamWorker { Q_OBJECT public: EngineShoutcast(ConfigObject* _config); diff --git a/src/engine/sidechain/sidechainworker.h b/src/engine/sidechain/sidechainworker.h index 11384e3f440..ad44194fd96 100644 --- a/src/engine/sidechain/sidechainworker.h +++ b/src/engine/sidechain/sidechainworker.h @@ -2,67 +2,13 @@ #define SIDECHAINWORKER_H #include "util/types.h" -#include "util/fifo.h" - -/* - * States: - * Error Something errornous has happenned and can't go on - * New First state before init - * Init Initing state don't feed anything in this state - * Waiting Waiting something not ready yet - * Busy Is busy doing something can't process anything new - * Ready Functioning ok - * Reading Reading something and can't do anything else - * Writing Writing something and can't do anything else - * Connected Is connected to storage or server - * Connecting Trying to connect storate or server - * Disconnected Ain't connected to storage or server - * - * First state should be SIDECHAINWORKER_STATE_UNKNOWN and - * if state handling ain't supported by SideChainWorker-class - * then 'SIDECHAINWORKER_STATE_NEW' should be treated as - * SIDECHAINWORKER_STATE_READY. Newly written SideChainWorker-class - * should support state handling at leas this SIDECHAINWORKER_STATE_READY state. - */ - -enum SidechaingStates { - SIDECHAINWORKER_STATE_ERROR = -1, - SIDECHAINWORKER_STATE_NEW, - SIDECHAINWORKER_STATE_INIT, - SIDECHAINWORKER_STATE_WAITING, - SIDECHAINWORKER_STATE_BUSY, - SIDECHAINWORKER_STATE_READY, - SIDECHAINWORKER_STATE_READING, - SIDECHAINWORKER_STATE_WRITING, - SICECHAINWORKER_STATE_CONNECTED, - SICECHAINWORKER_STATE_CONNECTING, - SIDECHAINWORKER_STATE_DISCONNECTED -}; class SideChainWorker { public: - SideChainWorker() : - m_iSideChainWorkerState(SIDECHAINWORKER_STATE_NEW) { } + SideChainWorker() { } virtual ~SideChainWorker() { } virtual void process(const CSAMPLE* pBuffer, const int iBufferSize) = 0; virtual void shutdown() = 0; - virtual void outputAvailable() { - }; - virtual void setOutputFifo(FIFO* pOutputFifo) { - Q_UNUSED(pOutputFifo); - }; - virtual bool threadWaiting() { - return false; - } - virtual int getState() { - return m_iSideChainWorkerState; - } -protected: - virtual void setState(int state) { - m_iSideChainWorkerState = state; - } -private: - int m_iSideChainWorkerState; }; #endif /* SIDECHAINWORKER_H */