diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-09-18 18:17:29 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-09-18 18:17:29 +0000 |
| commit | 136f634c6c334fe1f1b77c9640fe49c8204d011f (patch) | |
| tree | c5430eeb0b5d1455ef9231a3749fa4d4a1e3862f | |
| parent | e51ee1711dbfe631ed2d54fb63d4d2e59e2ac71c (diff) | |
| download | qmmp-136f634c6c334fe1f1b77c9640fe49c8204d011f.tar.gz qmmp-136f634c6c334fe1f1b77c9640fe49c8204d011f.tar.bz2 qmmp-136f634c6c334fe1f1b77c9640fe49c8204d011f.zip | |
added transport api, moved http into plugin, fixed problems with cue metadata
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1231 90c681e8-e032-0410-971d-27865f9a5e38
29 files changed, 656 insertions, 91 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 71f74a65f..1e3c61250 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,6 +83,10 @@ ENDIF(UNIX) MESSAGE("") +MESSAGE("Transports:") +PRINT_SUMMARY ("HTTP support ......................" USE_CURL CURL_FOUND) + +MESSAGE("") MESSAGE("Input Plugins:") PRINT_SUMMARY ("mp3 support ......................." USE_MAD MAD_FOUND) PRINT_SUMMARY ("FLAC support ......................" USE_FLAC FLAC_FOUND) diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt index 32dc59f34..00eabaad5 100644 --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -6,3 +6,4 @@ add_subdirectory(General) add_subdirectory(PlaylistFormats) add_subdirectory(CommandLineOptions) add_subdirectory(FileDialogs) +add_subdirectory(Transports) diff --git a/src/plugins/Input/cue/decoder_cue.cpp b/src/plugins/Input/cue/decoder_cue.cpp index 944c9911a..cf06438e9 100644 --- a/src/plugins/Input/cue/decoder_cue.cpp +++ b/src/plugins/Input/cue/decoder_cue.cpp @@ -88,6 +88,8 @@ bool DecoderCUE::initialize() audioParameters().channels() * audioParameters().bits() * m_length/8000; m_totalBytes = 0; + + StateHandler::instance()->dispatch(parser.info(track)->metaData()); return TRUE; } diff --git a/src/plugins/Transports/CMakeLists.txt b/src/plugins/Transports/CMakeLists.txt new file mode 100644 index 000000000..1de020fbf --- /dev/null +++ b/src/plugins/Transports/CMakeLists.txt @@ -0,0 +1,5 @@ +SET(USE_CURL TRUE CACHE BOOL "enable/disable curl-based http plugin") + +IF(USE_CURL) +add_subdirectory(http) +ENDIF(USE_CURL) diff --git a/src/plugins/Transports/Transports.pro b/src/plugins/Transports/Transports.pro new file mode 100644 index 000000000..26d09c134 --- /dev/null +++ b/src/plugins/Transports/Transports.pro @@ -0,0 +1,4 @@ +include(../../../qmmp.pri) + +SUBDIRS += http +TEMPLATE = subdirs diff --git a/src/plugins/Transports/http/CMakeLists.txt b/src/plugins/Transports/http/CMakeLists.txt new file mode 100644 index 000000000..939c22b12 --- /dev/null +++ b/src/plugins/Transports/http/CMakeLists.txt @@ -0,0 +1,59 @@ +project(libhttp) + +cmake_minimum_required(VERSION 2.4.7) + +if(COMMAND cmake_policy) + cmake_policy(SET CMP0003 NEW) + cmake_policy(SET CMP0005 NEW) +endif(COMMAND cmake_policy) + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +SET(QT_INCLUDES + ${QT_INCLUDES} + ${CMAKE_CURRENT_BINARY_DIR}/../../../ +) + +# libqmmp +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) + +# libcurl +pkg_search_module(CURL libcurl) +include_directories(${CURL_INCLUDE_DIRS}) +link_directories(${CURL_LIBRARY_DIRS}) + +SET(libhttp_SRCS + streamreader.cpp + downloader.cpp + httpinputfactory.cpp + httpinputsource.cpp +) + +SET(libhttp_MOC_HDRS + downloader.h + httpinputfactory.h + httpinputsource.h + streamreader.h +) + +QT4_WRAP_CPP(libhttp_MOC_SRCS ${libhttp_MOC_HDRS}) + +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +IF(CURL_FOUND) +ADD_LIBRARY(http MODULE ${libhttp_SRCS} ${libhttp_MOC_SRCS}) +add_dependencies(http qmmp) +target_link_libraries(http ${QT_LIBRARIES} -lqmmp ${CURL_LDFLAGS} ${CURL_CFLAGS}) +install(TARGETS http DESTINATION ${LIB_DIR}/qmmp/Transports) +ENDIF(CURL_FOUND) diff --git a/src/qmmp/downloader.cpp b/src/plugins/Transports/http/downloader.cpp index 5b076a148..06653fde9 100644 --- a/src/qmmp/downloader.cpp +++ b/src/plugins/Transports/http/downloader.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2006-2008 by Ilya Kotov * + * Copyright (C) 2006-2009 by Ilya Kotov * * forkotov02@hotmail.ru * * * * This program is free software; you can redistribute it and/or modify * @@ -25,9 +25,8 @@ #include <QMap> #include <stdint.h> #include <stdlib.h> - -#include "qmmp.h" -#include "statehandler.h" +#include <qmmp/qmmp.h> +#include <qmmp/statehandler.h> #include "downloader.h" //curl callbacks @@ -254,7 +253,8 @@ void Downloader::run() curl_easy_setopt(m_handle, CURLOPT_FAILONERROR, 1); curl_easy_setopt(m_handle, CURLOPT_MAXREDIRS, 15); // user agent - curl_easy_setopt(m_handle, CURLOPT_USERAGENT, "qmmp/"QMMP_STR_VERSION); + QString user_agent = QString("qmmp/%1").arg(Qmmp::strVersion()); + curl_easy_setopt(m_handle, CURLOPT_USERAGENT, qPrintable(user_agent)); curl_easy_setopt(m_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); struct curl_slist *http200_aliases = curl_slist_append(NULL, "ICY"); diff --git a/src/qmmp/downloader.h b/src/plugins/Transports/http/downloader.h index 0ac96786d..0ac96786d 100644 --- a/src/qmmp/downloader.h +++ b/src/plugins/Transports/http/downloader.h diff --git a/src/plugins/Transports/http/http.pro b/src/plugins/Transports/http/http.pro new file mode 100644 index 000000000..e9b630e18 --- /dev/null +++ b/src/plugins/Transports/http/http.pro @@ -0,0 +1,33 @@ +include(../../plugins.pri) +HEADERS += downloader.h \ + streamreader.h \ + httpinputfactory.h \ + httpinputsource.h +SOURCES += downloader.cpp \ + streamreader.cpp \ + httpinputfactory.cpp \ + httpinputsource.cpp +win32:HEADERS += ../../../../src/qmmp/inputsource.h \ + ../../../../src/qmmp/inputsourcefactory.h +TARGET = $$PLUGINS_PREFIX/Transports/http +unix:QMAKE_CLEAN = $$PLUGINS_PREFIX/Input/libhttp.so +INCLUDEPATH += ../../../ +CONFIG += release \ + warn_on \ + plugin \ + link_pkgconfig +TEMPLATE = lib +unix { + QMAKE_LIBDIR += ../../../../lib + LIBS += -lqmmp \ + -L/usr/lib + PKGCONFIG += libcurl + isEmpty(LIB_DIR):LIB_DIR = /lib + win32 { + QMAKE_LIBDIR += ../../../../bin + LIBS += -lqmmp0 \ + -lcurldll + } + target.path = $$LIB_DIR/qmmp/Transports + INSTALLS += target +} diff --git a/src/plugins/Transports/http/httpinputfactory.cpp b/src/plugins/Transports/http/httpinputfactory.cpp new file mode 100644 index 000000000..69bfcbb79 --- /dev/null +++ b/src/plugins/Transports/http/httpinputfactory.cpp @@ -0,0 +1,38 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QtPlugin> +#include "httpinputsource.h" +#include "httpinputfactory.h" + +const InputSourceProperties HTTPInputFactory::properties() const +{ + InputSourceProperties p; + p.protocols = "http"; + p.shortName = "http"; + return p; +} + +InputSource *HTTPInputFactory::create(const QString &url, QObject *parent) +{ + return new HTTPInputSource(url, parent); +} +//Q_EXPORT_PLUGIN2(http, HTTPInputFactory); +Q_EXPORT_PLUGIN(HTTPInputFactory); diff --git a/src/plugins/Transports/http/httpinputfactory.h b/src/plugins/Transports/http/httpinputfactory.h new file mode 100644 index 000000000..78e02f1f4 --- /dev/null +++ b/src/plugins/Transports/http/httpinputfactory.h @@ -0,0 +1,39 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef HTTPINPUTFACTORY_H +#define HTTPINPUTFACTORY_H + +#include <QObject> +#include <qmmp/inputsourcefactory.h> + +/*! + * @author Ilya Kotov <forkotov02@hotmail.ru> + */ +class HTTPInputFactory : public QObject, InputSourceFactory +{ +Q_OBJECT +Q_INTERFACES(InputSourceFactory); +public: + const InputSourceProperties properties() const; + InputSource *create(const QString &url, QObject *parent = 0); +}; + +#endif // HTTPINPUTFACTORY_H diff --git a/src/plugins/Transports/http/httpinputsource.cpp b/src/plugins/Transports/http/httpinputsource.cpp new file mode 100644 index 000000000..b8f838d83 --- /dev/null +++ b/src/plugins/Transports/http/httpinputsource.cpp @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "streamreader.h" +#include "httpinputsource.h" + +HTTPInputSource::HTTPInputSource(const QString &url, QObject *parent) : InputSource(url,parent) +{ + m_reader = new StreamReader(url, this); + connect(m_reader, SIGNAL(readyRead()),SLOT(open())); +} + +QIODevice *HTTPInputSource::ioDevice() +{ + return m_reader; +} + +bool HTTPInputSource::initialize() +{ + m_reader->downloadFile(); + return TRUE; +} + +bool HTTPInputSource::isReady() +{ + return m_reader->isOpen(); +} + +void HTTPInputSource::open() +{ + qDebug("open"); + m_reader->open(QIODevice::ReadOnly); + emit(ready(this)); +} diff --git a/src/plugins/Transports/http/httpinputsource.h b/src/plugins/Transports/http/httpinputsource.h new file mode 100644 index 000000000..2c4d32f89 --- /dev/null +++ b/src/plugins/Transports/http/httpinputsource.h @@ -0,0 +1,49 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef HTTPINPUTSOURCE_H +#define HTTPINPUTSOURCE_H + +#include <qmmp/inputsource.h> + +class StreamReader; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class HTTPInputSource : public InputSource +{ +Q_OBJECT +public: + HTTPInputSource(const QString &url, QObject *parent = 0); + + QIODevice *ioDevice(); + bool initialize(); + bool isReady(); + +private slots: + void open(); + +private: + StreamReader *m_reader; + +}; + +#endif // HTTPINPUTSOURCE_H diff --git a/src/qmmp/streamreader.cpp b/src/plugins/Transports/http/streamreader.cpp index 5d61c76d1..5d61c76d1 100644 --- a/src/qmmp/streamreader.cpp +++ b/src/plugins/Transports/http/streamreader.cpp diff --git a/src/qmmp/streamreader.h b/src/plugins/Transports/http/streamreader.h index e73f65389..e73f65389 100644 --- a/src/qmmp/streamreader.h +++ b/src/plugins/Transports/http/streamreader.h diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index ea3c6fc19..dfa993d89 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -1,7 +1,8 @@ SUBDIRS += Input \ Output \ General \ - Visual + Visual \ + Transports unix:SUBDIRS += Effect \ PlaylistFormats \ diff --git a/src/qmmp/CMakeLists.txt b/src/qmmp/CMakeLists.txt index e27326517..a3db3d97a 100644 --- a/src/qmmp/CMakeLists.txt +++ b/src/qmmp/CMakeLists.txt @@ -30,12 +30,6 @@ ENDIF(SVN_VERSION) include_directories(${CMAKE_CURRENT_BINARY_DIR}) -#libcurl - -pkg_check_modules(CURL REQUIRED libcurl) -include_directories(${CURL_INCLUDE_DIRS}) -link_directories(${CURL_LIBRARY_DIRS}) - SET(libqmmp_SRCS visual.cpp recycler.cpp @@ -46,8 +40,6 @@ SET(libqmmp_SRCS equ/iir_cfs.c equ/iir_fpu.c soundcore.cpp - streamreader.cpp - downloader.cpp effect.cpp qmmp.cpp statehandler.cpp @@ -58,6 +50,8 @@ SET(libqmmp_SRCS abstractengine.cpp audioparameters.cpp inputsource.cpp + fileinputsource.cpp + emptyinputsource.cpp ) SET(libqmmp_MOC_HDRS @@ -73,8 +67,6 @@ SET(libqmmp_MOC_HDRS equ/iir.h decoderfactory.h soundcore.h - streamreader.h - downloader.h effectfactory.h effect.h qmmp.h @@ -86,6 +78,8 @@ SET(libqmmp_MOC_HDRS abstractengine.h audioparameters.h inputsource.h + fileinputsource.h + emptyinputsource.h ) SET(libqmmp_DEVEL_HDRS @@ -115,7 +109,7 @@ QT4_WRAP_CPP(libqmmp_MOC_SRCS ${libqmmp_MOC_HDRS}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) ADD_LIBRARY(libqmmp SHARED ${libqmmp_SRCS} ${libqmmp_MOC_SRCS}) -target_link_libraries(libqmmp ${QT_LIBRARIES} ${CURL_LDFLAGS} ${CURL_CFLAGS}) +target_link_libraries(libqmmp ${QT_LIBRARIES}) SET_TARGET_PROPERTIES(libqmmp PROPERTIES VERSION ${QMMP_VERSION} SOVERSION ${QMMP_SOVERSION} OUTPUT_NAME qmmp) install(TARGETS libqmmp LIBRARY DESTINATION ${LIB_DIR} RUNTIME DESTINATION bin diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp index 151a1a23a..90013eeb5 100644 --- a/src/qmmp/decoder.cpp +++ b/src/qmmp/decoder.cpp @@ -18,7 +18,6 @@ #include "output.h" #include "visual.h" #include "decoderfactory.h" -#include "streamreader.h" #include "qmmp.h" extern "C" diff --git a/src/qmmp/effectfactory.h b/src/qmmp/effectfactory.h index b22580e59..ae1762440 100644 --- a/src/qmmp/effectfactory.h +++ b/src/qmmp/effectfactory.h @@ -46,14 +46,14 @@ public: bool hasAbout; /*!< Should be \b true if plugin has about dialog, otherwise returns \b false */ bool hasSettings; /*!< Should be \b true if plugin has settings dialog, otherwise returns \b false */ }; -/*! @brief %Effect plugin interface (effect factory). +/*! @brief Effect plugin interface (effect factory). * @author Ilya Kotov <forkotov02@hotmail.ru> */ class EffectFactory { public: /*! - * Returns general plugin properties. + * Returns effect plugin properties. */ virtual const EffectProperties properties() const = 0; /*! diff --git a/src/qmmp/emptyinputsource.cpp b/src/qmmp/emptyinputsource.cpp new file mode 100644 index 000000000..ebbd30773 --- /dev/null +++ b/src/qmmp/emptyinputsource.cpp @@ -0,0 +1,44 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "emptyinputsource.h" + +EmptyInputSource::EmptyInputSource(const QString &url, QObject *parent) : InputSource(url,parent) +{ + m_ok = FALSE; +} + +QIODevice *EmptyInputSource::ioDevice() +{ + return 0; +} + +bool EmptyInputSource::initialize() +{ + m_ok = TRUE; //check decoders + if(m_ok) + emit ready(this); + return m_ok; +} + +bool EmptyInputSource::isReady() +{ + return m_ok; +} diff --git a/src/qmmp/emptyinputsource.h b/src/qmmp/emptyinputsource.h new file mode 100644 index 000000000..c2c30db7f --- /dev/null +++ b/src/qmmp/emptyinputsource.h @@ -0,0 +1,43 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef EMPTYINPUTSOURCE_H +#define EMPTYINPUTSOURCE_H + +#include "inputsource.h" + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class EmptyInputSource : public InputSource +{ +Q_OBJECT +public: + EmptyInputSource(const QString &url, QObject *parent = 0); + + QIODevice *ioDevice(); + bool initialize(); + bool isReady(); + +private: + bool m_ok; +}; + +#endif // EMPTYINPUTSOURCE_H diff --git a/src/qmmp/fileinputsource.cpp b/src/qmmp/fileinputsource.cpp new file mode 100644 index 000000000..2ea277539 --- /dev/null +++ b/src/qmmp/fileinputsource.cpp @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <QFile> +#include "fileinputsource.h" + +FileInputSource::FileInputSource(const QString &url, QObject *parent) : InputSource(url,parent) +{ + m_file = new QFile(url, this); +} + +QIODevice *FileInputSource::ioDevice() +{ + return m_file; +} + +bool FileInputSource::initialize() +{ + bool ok = m_file->open(QIODevice::ReadOnly); + if(ok) + emit ready(this); + else + qWarning("FileInputSource: error: %s", qPrintable(m_file->errorString())); + return ok; +} + +bool FileInputSource::isReady() +{ + return m_file->isOpen(); +} diff --git a/src/qmmp/fileinputsource.h b/src/qmmp/fileinputsource.h new file mode 100644 index 000000000..5efe2a2b2 --- /dev/null +++ b/src/qmmp/fileinputsource.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef FILEINPUTSOURCE_H +#define FILEINPUTSOURCE_H + +#include "inputsource.h" + +class QFile; + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class FileInputSource : public InputSource +{ +Q_OBJECT +public: + FileInputSource(const QString &url, QObject *parent = 0); + + QIODevice *ioDevice(); + bool initialize(); + bool isReady(); + +private: + QFile *m_file; +}; + +#endif // FILEINPUTSOURCE_H diff --git a/src/qmmp/inputsource.cpp b/src/qmmp/inputsource.cpp index 51eceba4f..b3acd0707 100644 --- a/src/qmmp/inputsource.cpp +++ b/src/qmmp/inputsource.cpp @@ -19,46 +19,95 @@ ***************************************************************************/ #include <QFile> -#include "streamreader.h" +#include <QSettings> +#include <QDir> +#include <QApplication> +#include <QPluginLoader> +#include "qmmp.h" +#include "fileinputsource.h" +#include "emptyinputsource.h" #include "inputsource.h" InputSource::InputSource(const QString &source, QObject *parent) : QObject(parent) { - m_device = 0; - m_isValid = FALSE; m_url = source; - if (source.contains("://")) //url +} + +const QString InputSource::url() +{ + return m_url; +} + +// static methods +QList<InputSourceFactory*> *InputSource::m_factories = 0; +QStringList InputSource::m_files; + +InputSource *InputSource::create(const QString &url, QObject *parent) +{ + checkFactories(); + InputSourceFactory *factory = 0; + if(!url.contains("://")) //local file path doesn't contain "://" { - ; + qDebug("InputSource: using file transport"); + return new FileInputSource(url, parent); } - else if (!QFile::exists(source)) + foreach(InputSourceFactory *f, *m_factories) { - qDebug("InputSource: file doesn't exist"); - return; + QStringList protocols = f->properties().protocols.split(" "); + if(protocols.contains(url.section("://", 0, 0))) + { + factory = f; + break; + } } - else + if(factory) { - m_device = new QFile(source, this); - return; + qDebug("InputSource: using %s transport", qPrintable(url.section("://", 0, 0))); + return factory->create(url, parent); } - if (m_url.section("://",0,0) == "http") + else { - m_device = new StreamReader(source, this); - //connect(m_input, SIGNAL(bufferingProgress(int)), SIGNAL(bufferingProgress(int))); - connect(m_device, SIGNAL(readyRead()),SIGNAL(readyRead())); - qobject_cast<StreamReader *>(m_device)->downloadFile(); - return; + qDebug("InputSource: using fake transport"); + return new EmptyInputSource(url, parent); } - m_isValid = FALSE; } -const QString InputSource::url() +QList<InputSourceFactory*> *InputSource::factories() { - return m_url; + checkFactories(); + return m_factories; } -QIODevice *InputSource::ioDevice() +void InputSource::checkFactories() { - return m_device; + QSettings settings (Qmmp::configFile(), QSettings::IniFormat); + + if (!m_factories) + { + m_files.clear(); + m_factories = new QList<InputSourceFactory *>; + + QDir pluginsDir (Qmmp::pluginsPath()); + pluginsDir.cd("Transports"); + foreach (QString fileName, pluginsDir.entryList(QDir::Files)) + { + QPluginLoader loader(pluginsDir.absoluteFilePath(fileName)); + QObject *plugin = loader.instance(); + if (loader.isLoaded()) + qDebug("InputSource: plugin loaded - %s", qPrintable(fileName)); + else + qWarning("InputSource: %s", qPrintable(loader.errorString ())); + InputSourceFactory *factory = 0; + if (plugin) + factory = qobject_cast<InputSourceFactory *>(plugin); + + if (factory) + { + m_factories->append(factory); + m_files << pluginsDir.absoluteFilePath(fileName); + //qApp->installTranslator(factory->createTranslator(qApp)); + } + } + } } diff --git a/src/qmmp/inputsource.h b/src/qmmp/inputsource.h index cf1f03a62..ce80bc333 100644 --- a/src/qmmp/inputsource.h +++ b/src/qmmp/inputsource.h @@ -23,23 +23,37 @@ #include <QObject> #include <QString> +#include <QStringList> #include <QIODevice> +#include "inputsourcefactory.h" +/*! + * @author Ilya Kotov <forkotov02@hotmail.ru> + */ class InputSource : public QObject { Q_OBJECT public: - InputSource(const QString &source, QObject *parent = 0); - QIODevice *ioDevice(); + InputSource(const QString &url, QObject *parent = 0); + virtual QIODevice *ioDevice() = 0; + virtual bool initialize() = 0; + virtual bool isReady() = 0; const QString url(); + static InputSource *create(const QString &url, QObject *parent = 0); + /*! + * Returns a list of transport factories. + */ + static QList<InputSourceFactory *> *factories(); + signals: - void readyRead(); + void ready(InputSource *); private: QString m_url; - QIODevice *m_device; - bool m_isValid; + static void checkFactories(); + static QList<InputSourceFactory*> *m_factories; + static QStringList m_files; }; #endif // INPUTSOURCE_H diff --git a/src/qmmp/inputsourcefactory.h b/src/qmmp/inputsourcefactory.h new file mode 100644 index 000000000..f74fb3721 --- /dev/null +++ b/src/qmmp/inputsourcefactory.h @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2009 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef INPUTSOURCEFACTORY_H +#define INPUTSOURCEFACTORY_H + +#include <QObject> + +class InputSource; + +/*! @brief Helper class to store transport plugin properies. + * @author Ilya Kotov <forkotov02@hotmail.ru> + */ +class InputSourceProperties +{ +public: + QString protocols; /*!< Supported protocols. */ + QString shortName; /*!< Transport plugin name for internal usage */ +}; + + +/*! @brief Transport plugin interface. + * @author Ilya Kotov <forkotov02@hotmail.ru> + */ +class InputSourceFactory +{ +public: + /*! + * Returns transport plugin properties. + */ + virtual const InputSourceProperties properties() const = 0; + /*! + * Creates transport provided by plugin. + * @param url URL of the stream. + * @param parent Parent object. + */ + virtual InputSource *create(const QString &url, QObject *parent = 0) = 0; +}; + +Q_DECLARE_INTERFACE(InputSourceFactory, "InputSourceFactory/1.0"); + +#endif // INPUTSOURCEFACTORY_H + diff --git a/src/qmmp/qmmp.pro b/src/qmmp/qmmp.pro index 1cbfb1945..a921cba19 100644 --- a/src/qmmp/qmmp.pro +++ b/src/qmmp/qmmp.pro @@ -10,8 +10,6 @@ HEADERS += recycler.h \ equ/iir.h \ decoderfactory.h \ soundcore.h \ - streamreader.h \ - downloader.h \ visual.h \ visualfactory.h \ effect.h \ @@ -25,7 +23,10 @@ HEADERS += recycler.h \ abstractengine.h \ qmmpaudioengine.h \ audioparameters.h \ - inputsource.h + inputsource.h \ + fileinputsource.h \ + emptyinputsource.h \ + inputsourcefactory.h SOURCES += recycler.cpp \ decoder.cpp \ output.cpp \ @@ -33,8 +34,6 @@ SOURCES += recycler.cpp \ equ/iir_cfs.c \ equ/iir_fpu.c \ soundcore.cpp \ - streamreader.cpp \ - downloader.cpp \ visual.cpp \ effect.cpp \ statehandler.cpp \ @@ -46,7 +45,9 @@ SOURCES += recycler.cpp \ abstractengine.cpp \ qmmpaudioengine.cpp \ audioparameters.cpp \ - inputsource.cpp + inputsource.cpp \ + fileinputsource.cpp \ + emptyinputsource.cpp FORMS += unix:TARGET = ../../lib/qmmp win32:TARGET = ../../../bin/qmmp @@ -54,12 +55,10 @@ CONFIG += release \ shared \ warn_on \ qt \ - thread \ - link_pkgconfig + thread + TEMPLATE = lib VERSION = $$QMMP_VERSION -unix:PKGCONFIG += libcurl -win32:LIBS += -lcurldll unix:isEmpty(LIB_DIR):LIB_DIR = /lib unix:DEFINES += LIB_DIR=\\\"$$LIB_DIR\\\" DEFINES += QMMP_VERSION=$$QMMP_VERSION diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index 5f4ea97e1..2a8d3c7a1 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -26,7 +26,6 @@ #include "qmmpaudioengine.h" #include "decoderfactory.h" -#include "streamreader.h" #include "effect.h" #include "statehandler.h" #include "inputsource.h" @@ -76,24 +75,17 @@ bool SoundCore::play(const QString &source, bool queue) if(!queue) stop(); - m_inputSource = new InputSource(source, this); - - if(m_inputSource->ioDevice()) - connect(m_inputSource->ioDevice(), SIGNAL(readyRead()), SLOT(decode())); - else - return decode(); - - StreamReader *reader = qobject_cast<StreamReader *>(m_inputSource->ioDevice()); - if(reader) + InputSource *s = InputSource::create(source, this); + m_pendingSources.append(s); + connect(s, SIGNAL(ready(InputSource *)), SLOT(enqueue(InputSource *))); + bool ok = s->initialize(); + if(!ok) { - connect(reader, SIGNAL(bufferingProgress(int)), SIGNAL(bufferingProgress(int))); - reader->downloadFile(); - m_handler->dispatch(Qmmp::Buffering); - return TRUE; + m_pendingSources.removeAll(s); + s->deleteLater(); + m_handler->dispatch(Qmmp::NormalError); } - else - m_inputSource->ioDevice()->open(QIODevice::ReadOnly); - return decode(); + return ok; } void SoundCore::stop() @@ -176,6 +168,8 @@ void SoundCore::setSoftwareVolume(bool b) connect(m_volumeControl, SIGNAL(volumeChanged(int, int)), SIGNAL(volumeChanged(int, int))); if (m_engine) m_engine->mutex()->unlock(); + qDeleteAll(m_pendingSources); + m_pendingSources.clear(); } bool SoundCore::softwareVolume() @@ -223,16 +217,9 @@ QString SoundCore::metaData(Qmmp::MetaData key) return m_handler->metaData(key); } -bool SoundCore::decode() +bool SoundCore::enqueue(InputSource *s) { - qDebug("ready"); - if(m_inputSource->ioDevice()) - { - if(!m_inputSource->ioDevice()->isOpen()) - m_inputSource->ioDevice()->open(QIODevice::ReadOnly); - disconnect(m_inputSource->ioDevice(), SIGNAL(readyRead()), this, SLOT(decode())); - } - + m_pendingSources.removeAll(s); if(!m_engine) { m_engine = new QmmpAudioEngine(this); @@ -242,20 +229,18 @@ bool SoundCore::decode() setEQ(m_bands, m_preamp); setEQEnabled(m_useEQ); - if(m_engine->enqueue(m_inputSource)) + if(m_engine->enqueue(s)) { - m_source = m_inputSource->url(); - m_inputSource->setParent(m_engine); + m_source = s->url(); + s->setParent(m_engine); m_engine->start(); } else { - delete m_inputSource; + s->deleteLater(); return FALSE; } - qDebug ("ok"); - return TRUE; } diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index aec2ad947..d72d193ae 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -204,7 +204,7 @@ signals: void aboutToFinish(); private slots: - bool decode(); + bool enqueue(InputSource *); private: Decoder* m_decoder; @@ -223,7 +223,7 @@ private: StateHandler *m_handler; VolumeControl *m_volumeControl; QmmpAudioEngine *m_engine; - InputSource *m_inputSource; + QList<InputSource *> m_pendingSources; }; #endif |
