From 136f634c6c334fe1f1b77c9640fe49c8204d011f Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Fri, 18 Sep 2009 18:17:29 +0000 Subject: 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 --- src/plugins/CMakeLists.txt | 1 + src/plugins/Input/cue/decoder_cue.cpp | 2 + src/plugins/Transports/CMakeLists.txt | 5 + src/plugins/Transports/Transports.pro | 4 + src/plugins/Transports/http/CMakeLists.txt | 59 ++++ src/plugins/Transports/http/downloader.cpp | 361 +++++++++++++++++++++++ src/plugins/Transports/http/downloader.h | 87 ++++++ src/plugins/Transports/http/http.pro | 33 +++ src/plugins/Transports/http/httpinputfactory.cpp | 38 +++ src/plugins/Transports/http/httpinputfactory.h | 39 +++ src/plugins/Transports/http/httpinputsource.cpp | 51 ++++ src/plugins/Transports/http/httpinputsource.h | 49 +++ src/plugins/Transports/http/streamreader.cpp | 134 +++++++++ src/plugins/Transports/http/streamreader.h | 81 +++++ src/plugins/plugins.pro | 3 +- src/qmmp/CMakeLists.txt | 16 +- src/qmmp/decoder.cpp | 1 - src/qmmp/downloader.cpp | 361 ----------------------- src/qmmp/downloader.h | 87 ------ src/qmmp/effectfactory.h | 4 +- src/qmmp/emptyinputsource.cpp | 44 +++ src/qmmp/emptyinputsource.h | 43 +++ src/qmmp/fileinputsource.cpp | 47 +++ src/qmmp/fileinputsource.h | 45 +++ src/qmmp/inputsource.cpp | 93 ++++-- src/qmmp/inputsource.h | 24 +- src/qmmp/inputsourcefactory.h | 60 ++++ src/qmmp/qmmp.pro | 19 +- src/qmmp/soundcore.cpp | 49 ++- src/qmmp/soundcore.h | 4 +- src/qmmp/streamreader.cpp | 134 --------- src/qmmp/streamreader.h | 81 ----- 32 files changed, 1310 insertions(+), 749 deletions(-) create mode 100644 src/plugins/Transports/CMakeLists.txt create mode 100644 src/plugins/Transports/Transports.pro create mode 100644 src/plugins/Transports/http/CMakeLists.txt create mode 100644 src/plugins/Transports/http/downloader.cpp create mode 100644 src/plugins/Transports/http/downloader.h create mode 100644 src/plugins/Transports/http/http.pro create mode 100644 src/plugins/Transports/http/httpinputfactory.cpp create mode 100644 src/plugins/Transports/http/httpinputfactory.h create mode 100644 src/plugins/Transports/http/httpinputsource.cpp create mode 100644 src/plugins/Transports/http/httpinputsource.h create mode 100644 src/plugins/Transports/http/streamreader.cpp create mode 100644 src/plugins/Transports/http/streamreader.h delete mode 100644 src/qmmp/downloader.cpp delete mode 100644 src/qmmp/downloader.h create mode 100644 src/qmmp/emptyinputsource.cpp create mode 100644 src/qmmp/emptyinputsource.h create mode 100644 src/qmmp/fileinputsource.cpp create mode 100644 src/qmmp/fileinputsource.h create mode 100644 src/qmmp/inputsourcefactory.h delete mode 100644 src/qmmp/streamreader.cpp delete mode 100644 src/qmmp/streamreader.h (limited to 'src') 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/plugins/Transports/http/downloader.cpp b/src/plugins/Transports/http/downloader.cpp new file mode 100644 index 000000000..06653fde9 --- /dev/null +++ b/src/plugins/Transports/http/downloader.cpp @@ -0,0 +1,361 @@ +/*************************************************************************** + * Copyright (C) 2006-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 +#include +#include +#include +#include +#include +#include +#include +#include +#include "downloader.h" + +//curl callbacks +static size_t curl_write_data(void *data, size_t size, size_t nmemb, + void *pointer) +{ + Downloader *dl = (Downloader *)pointer; + dl->mutex()->lock (); + size_t buf_start = dl->stream()->buf_fill; + size_t data_size = size * nmemb; + dl->stream()->buf_fill += data_size; + + dl->stream()->buf = (char *)realloc (dl->stream()->buf, dl->stream()->buf_fill); + memcpy (dl->stream()->buf + buf_start, data, data_size); + dl->mutex()->unlock(); + dl->checkBuffer(); + return data_size; +} + +static size_t curl_header(void *data, size_t size, size_t nmemb, + void *pointer) +{ + Downloader *dl = (Downloader *)pointer; + dl->mutex()->lock (); + size_t data_size = size * nmemb; + if (data_size < 3) + { + dl->mutex()->unlock(); + return data_size; + } + + //qDebug("header received: %s", (char*) data); + QString str = QString::fromAscii((char *) data, data_size); + str = str.trimmed (); + if (str.left(4).contains("HTTP")) + { + qDebug("Downloader: header received"); + //TODO open metadata socket + } + else if (str.left(4).contains("ICY")) + { + qDebug("Downloader: shoutcast header received"); + //dl->stream()->icy_meta_data = TRUE; + } + else + { + QString key = str.left(str.indexOf(":")).trimmed().toLower(); + QString value = str.right(str.size() - str.indexOf(":") - 1).trimmed().toLower(); + dl->stream()->header.insert(key, value); + qDebug("Downloader: key=%s, value=%s",qPrintable(key),qPrintable(value)); + + if (key == "icy-metaint") + { + dl->stream()->icy_metaint = value.toInt(); + dl->stream()->icy_meta_data = TRUE; + } + } + dl->mutex()->unlock(); + return data_size; +} + +int curl_progress(void *pointer, double dltotal, double dlnow, double ultotal, double ulnow) +{ + Q_UNUSED(dltotal); + Q_UNUSED(dlnow); + Q_UNUSED(ultotal); + Q_UNUSED(ulnow); + Downloader *dl = (Downloader *)pointer; + dl->mutex()->lock (); + bool aborted = dl->stream()->aborted; + dl->mutex()->unlock(); + if (aborted) + return -1; + return 0; +} + +Downloader::Downloader(QObject *parent, const QString &url) + : QThread(parent) +{ + m_url = url; + curl_global_init(CURL_GLOBAL_ALL); + m_stream.buf_fill = 0; + m_stream.buf = 0; + m_stream.icy_meta_data = FALSE; + m_stream.aborted = TRUE; + m_stream.icy_metaint = 0; + m_handle = 0; + m_metacount = 0; +} + + +Downloader::~Downloader() +{ + abort(); + curl_global_cleanup(); + m_stream.aborted = TRUE; + m_stream.buf_fill = 0; + if (m_stream.buf) + free(m_stream.buf); + + m_stream.buf = 0; +} + + +qint64 Downloader::read(char* data, qint64 maxlen) +{ + + qint64 len = 0; + m_mutex.lock(); + if (!m_stream.icy_meta_data || m_stream.icy_metaint == 0) + len = readBuffer(data, maxlen); + else + { + qint64 nread = 0; + qint64 to_read; + while (maxlen > nread && m_stream.buf_fill > nread) + { + to_read = qMin(m_stream.icy_metaint - m_metacount, maxlen - nread); + //to_read = (maxlen - nread); + qint64 res = readBuffer(data + nread, to_read); + nread += res; + m_metacount += res; + if (m_metacount == m_stream.icy_metaint) + { + m_metacount = 0; + m_mutex.unlock(); + readICYMetaData(); + m_mutex.lock(); + } + + } + len = nread; + + } + m_mutex.unlock(); + return len; +} + +Stream *Downloader::stream() +{ + return &m_stream; +} + +QMutex *Downloader::mutex() +{ + return &m_mutex; +} + +QString Downloader::contentType() +{ + QString content; + if (m_stream.header.contains("content-type")) + content = m_stream.header.value("content-type"); + return content; +} + +void Downloader::abort() +{ + m_mutex.lock(); + + if (m_stream.aborted) + { + m_mutex.unlock(); + return; + } + m_stream.aborted = TRUE; + m_mutex.unlock(); + wait(); + if (m_handle) + { + curl_easy_cleanup(m_handle); + m_handle = 0; + } +} + +int Downloader::bytesAvailable() +{ + m_mutex.lock(); + int b = m_stream.buf_fill; + m_mutex.unlock(); + return b; +} + +void Downloader::run() +{ + qDebug("Downloader: starting download thread"); + m_handle = curl_easy_init(); + //proxy + QSettings settings ( Qmmp::configFile(), QSettings::IniFormat ); + if (Qmmp::useProxy()) + curl_easy_setopt(m_handle, CURLOPT_PROXY, + strdup((Qmmp::proxy().host() + ":" + + QString("%1").arg(Qmmp::proxy().port())). + toLatin1 ().constData ())); + + if (Qmmp::useProxyAuth()) + curl_easy_setopt(m_handle, CURLOPT_PROXYUSERPWD, + strdup((Qmmp::proxy().userName() + ":" + + Qmmp::proxy().password()). + toLatin1 ().constData ())); + + // Set url to download + curl_easy_setopt(m_handle, CURLOPT_URL, strdup(m_url.toAscii().constData())); + // callback for wrting + curl_easy_setopt(m_handle, CURLOPT_WRITEFUNCTION, curl_write_data); + // Set destination file + curl_easy_setopt(m_handle, CURLOPT_WRITEDATA, this); + curl_easy_setopt(m_handle, CURLOPT_HEADERDATA, this); + curl_easy_setopt(m_handle, CURLOPT_HEADERFUNCTION, curl_header); + // Disable SSL + curl_easy_setopt(m_handle, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_easy_setopt(m_handle, CURLOPT_SSL_VERIFYHOST, 0); + // Enable progress meter + curl_easy_setopt(m_handle, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(m_handle, CURLOPT_PROGRESSDATA, this); + curl_easy_setopt(m_handle, CURLOPT_PROGRESSFUNCTION, curl_progress); + // Any kind of authentication + curl_easy_setopt(m_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); + curl_easy_setopt(m_handle, CURLOPT_VERBOSE, 1); + // Auto referrer + curl_easy_setopt(m_handle, CURLOPT_AUTOREFERER, 1); + // Follow redirections + curl_easy_setopt(m_handle, CURLOPT_FOLLOWLOCATION, 1); + curl_easy_setopt(m_handle, CURLOPT_FAILONERROR, 1); + curl_easy_setopt(m_handle, CURLOPT_MAXREDIRS, 15); + // user agent + 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"); + struct curl_slist *http_headers = curl_slist_append(NULL, "Icy-MetaData: 1"); + curl_easy_setopt(m_handle, CURLOPT_HTTP200ALIASES, http200_aliases); + curl_easy_setopt(m_handle, CURLOPT_HTTPHEADER, http_headers); + m_mutex.lock(); + m_stream.buf_fill = 0; + m_stream.buf = 0; + m_stream.aborted = FALSE; + m_stream.header.clear (); + m_ready = FALSE; + int return_code; + qDebug("Downloader: starting libcurl"); + m_mutex.unlock(); + return_code = curl_easy_perform(m_handle); + qDebug("curl_easy_perform %d", return_code); + qDebug("Downloader: thread finished"); +} + +qint64 Downloader::readBuffer(char* data, qint64 maxlen) +{ + if (m_stream.buf_fill > 0 && !m_stream.aborted) + { + int len = qMin(m_stream.buf_fill, maxlen); + memcpy(data, m_stream.buf, len); + m_stream.buf_fill -= len; + memmove(m_stream.buf, m_stream.buf + len, m_stream.buf_fill); + return len; + } + return 0; +} + +const QString &Downloader::title() const +{ + return m_title; +} + +void Downloader::checkBuffer() +{ + if (m_stream.buf_fill > BUFFER_SIZE && !m_ready) + { + m_ready = TRUE; + qDebug("Downloader: ready"); + emit readyRead(); + } + else if (!m_ready) + { + emit bufferingProgress(100 * m_stream.buf_fill / BUFFER_SIZE); + qApp->processEvents(); + } + +} + +bool Downloader::isReady() +{ + return m_ready; +} + +void Downloader::readICYMetaData() +{ + uint8_t packet_size; + m_metacount = 0; + m_mutex.lock(); + readBuffer((char *)&packet_size, sizeof(packet_size)); + if (packet_size != 0) + { + int size = packet_size * 16; + char packet[size]; + while (m_stream.buf_fill < size && isRunning()) + { + m_mutex.unlock(); + qApp->processEvents(); + m_mutex.lock(); + } + readBuffer(packet, size); + qDebug("Downloader: ICY metadata: %s", packet); + parseICYMetaData(packet); + } + m_mutex.unlock(); + +} + +void Downloader::parseICYMetaData(char *data) +{ + QString str(data); + QStringList list(str.split(";", QString::SkipEmptyParts)); + foreach(QString line, list) + { + if (line.contains("StreamTitle=")) + { + line = line.right(line.size() - line.indexOf("=") - 1).trimmed(); + m_title = line.remove("'"); + if (!m_title.isEmpty()) + { + QMap metaData; + metaData.insert(Qmmp::TITLE, m_title); + metaData.insert(Qmmp::URL, m_url); + StateHandler::instance()->dispatch(metaData); + } + break; + } + } +} diff --git a/src/plugins/Transports/http/downloader.h b/src/plugins/Transports/http/downloader.h new file mode 100644 index 000000000..0ac96786d --- /dev/null +++ b/src/plugins/Transports/http/downloader.h @@ -0,0 +1,87 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 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 DOWNLOADER_H +#define DOWNLOADER_H + +#include +#include +#include +#include + +#include + +#define BUFFER_SIZE 128000 + +/*! @internal + * @author Ilya Kotov + */ +struct Stream +{ + char *buf; + int buf_fill; + QString content_type; + bool aborted; + QMap header; + bool icy_meta_data; + int icy_metaint; +}; +/*! @internal + * @author Ilya Kotov + */ +class Downloader : public QThread +{ + Q_OBJECT +public: + Downloader(QObject *parent, const QString &url); + + ~Downloader(); + + qint64 read(char* data, qint64 maxlen); + Stream *stream(); + QMutex *mutex(); + QString contentType(); + void abort(); + int bytesAvailable(); + const QString& title() const; + void checkBuffer(); + bool isReady(); + +signals: + void readyRead(); + void bufferingProgress(int); + +private: + qint64 readBuffer(char* data, qint64 maxlen); + void readICYMetaData(); + void parseICYMetaData(char *data); + CURL *m_handle; + QMutex m_mutex; + Stream m_stream; + QString m_url; + int m_metacount; + QString m_title; + bool m_ready; + +protected: + void run(); + +}; + +#endif 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 +#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 +#include + +/*! + * @author Ilya Kotov + */ +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 + +class StreamReader; + +/** + @author Ilya Kotov +*/ +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/plugins/Transports/http/streamreader.cpp b/src/plugins/Transports/http/streamreader.cpp new file mode 100644 index 000000000..5d61c76d1 --- /dev/null +++ b/src/plugins/Transports/http/streamreader.cpp @@ -0,0 +1,134 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 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 +#include + +#include "downloader.h" +#include "streamreader.h" + +StreamReader::StreamReader(const QString &name, QObject *parent) + : QIODevice(parent) +{ + m_downloader = new Downloader(this, name); + connect(m_downloader, SIGNAL(readyRead()), SIGNAL(readyRead())); + connect(m_downloader, SIGNAL(bufferingProgress(int)), SIGNAL(bufferingProgress(int))); +} + +StreamReader::~StreamReader() +{ + m_downloader->abort(); + qDebug("StreamReader::~StreamReader()"); +} + +bool StreamReader::atEnd () const +{ + return FALSE; +} + +qint64 StreamReader::bytesAvailable () const +{ + return m_downloader->bytesAvailable (); +} + +qint64 StreamReader::bytesToWrite () const +{ + return -1; +} + +bool StreamReader::canReadLine () const +{ + return FALSE; +} + +void StreamReader::close () +{ + m_downloader->abort(); +} + +bool StreamReader::isSequential () const +{ + return TRUE; +} + +bool StreamReader::open ( OpenMode mode ) +{ + if (mode != QIODevice::ReadOnly) + return FALSE; + //downloadFile(); + setOpenMode(QIODevice::ReadOnly); + if (m_downloader->isReady()) + return TRUE; + else + return FALSE; +} + +bool StreamReader::reset () +{ + QIODevice::reset(); + return TRUE; +} + +bool StreamReader::seek ( qint64 pos ) +{ + QIODevice::seek(pos); + return FALSE; +} + +qint64 StreamReader::size () const +{ + return bytesAvailable (); +} + +bool StreamReader::waitForBytesWritten ( int msecs ) +{ + //usleep(msecs*1000); + return TRUE; +} + +bool StreamReader::waitForReadyRead ( int msecs ) +{ + //usleep(msecs*1000); + return TRUE; +} + +qint64 StreamReader::readData(char* data, qint64 maxlen) +{ + return m_downloader->read (data, maxlen); +} + +qint64 StreamReader::writeData(const char*, qint64) +{ + return 0; +} + +void StreamReader::downloadFile() +{ + m_downloader->start(); +} + +const QString &StreamReader::contentType() +{ + m_downloader->mutex()->lock (); + m_contentType = m_downloader->contentType(); + m_downloader->mutex()->unlock(); + qApp->processEvents(); + qDebug("StreamReader: content type: %s", qPrintable(m_contentType)); + return m_contentType; +} diff --git a/src/plugins/Transports/http/streamreader.h b/src/plugins/Transports/http/streamreader.h new file mode 100644 index 000000000..e73f65389 --- /dev/null +++ b/src/plugins/Transports/http/streamreader.h @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 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 STREAMREADER_H +#define STREAMREADER_H + +#include +#include +#include + +class QFileInfo; + +class Downloader; + +/*! @internal + * @author Ilya Kotov + */ +class StreamReader : public QIODevice +{ + Q_OBJECT +public: + StreamReader(const QString &name, QObject *parent = 0); + + ~StreamReader(); + + /** + * QIODevice API + */ + bool atEnd () const; + qint64 bytesAvailable () const; + qint64 bytesToWrite () const; + bool canReadLine () const; + void close (); + bool isSequential () const; + bool open ( OpenMode mode ); + //qint64 pos () const; + bool reset (); + bool seek ( qint64 pos ); + qint64 size () const; + bool waitForBytesWritten ( int msecs ); + bool waitForReadyRead ( int msecs ); + + /** + * returns content type of a stream + */ + const QString &contentType(); + void downloadFile(); + +signals: + void readyRead(); + void bufferingProgress(int); + +protected: + qint64 readData(char*, qint64); + qint64 writeData(const char*, qint64); + +private: + //void downloadFile(); + void fillBuffer(); + QUrl m_url; + QString m_contentType; + Downloader *m_downloader; +}; + +#endif 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/downloader.cpp b/src/qmmp/downloader.cpp deleted file mode 100644 index 5b076a148..000000000 --- a/src/qmmp/downloader.cpp +++ /dev/null @@ -1,361 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2008 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 -#include -#include -#include -#include -#include -#include - -#include "qmmp.h" -#include "statehandler.h" -#include "downloader.h" - -//curl callbacks -static size_t curl_write_data(void *data, size_t size, size_t nmemb, - void *pointer) -{ - Downloader *dl = (Downloader *)pointer; - dl->mutex()->lock (); - size_t buf_start = dl->stream()->buf_fill; - size_t data_size = size * nmemb; - dl->stream()->buf_fill += data_size; - - dl->stream()->buf = (char *)realloc (dl->stream()->buf, dl->stream()->buf_fill); - memcpy (dl->stream()->buf + buf_start, data, data_size); - dl->mutex()->unlock(); - dl->checkBuffer(); - return data_size; -} - -static size_t curl_header(void *data, size_t size, size_t nmemb, - void *pointer) -{ - Downloader *dl = (Downloader *)pointer; - dl->mutex()->lock (); - size_t data_size = size * nmemb; - if (data_size < 3) - { - dl->mutex()->unlock(); - return data_size; - } - - //qDebug("header received: %s", (char*) data); - QString str = QString::fromAscii((char *) data, data_size); - str = str.trimmed (); - if (str.left(4).contains("HTTP")) - { - qDebug("Downloader: header received"); - //TODO open metadata socket - } - else if (str.left(4).contains("ICY")) - { - qDebug("Downloader: shoutcast header received"); - //dl->stream()->icy_meta_data = TRUE; - } - else - { - QString key = str.left(str.indexOf(":")).trimmed().toLower(); - QString value = str.right(str.size() - str.indexOf(":") - 1).trimmed().toLower(); - dl->stream()->header.insert(key, value); - qDebug("Downloader: key=%s, value=%s",qPrintable(key),qPrintable(value)); - - if (key == "icy-metaint") - { - dl->stream()->icy_metaint = value.toInt(); - dl->stream()->icy_meta_data = TRUE; - } - } - dl->mutex()->unlock(); - return data_size; -} - -int curl_progress(void *pointer, double dltotal, double dlnow, double ultotal, double ulnow) -{ - Q_UNUSED(dltotal); - Q_UNUSED(dlnow); - Q_UNUSED(ultotal); - Q_UNUSED(ulnow); - Downloader *dl = (Downloader *)pointer; - dl->mutex()->lock (); - bool aborted = dl->stream()->aborted; - dl->mutex()->unlock(); - if (aborted) - return -1; - return 0; -} - -Downloader::Downloader(QObject *parent, const QString &url) - : QThread(parent) -{ - m_url = url; - curl_global_init(CURL_GLOBAL_ALL); - m_stream.buf_fill = 0; - m_stream.buf = 0; - m_stream.icy_meta_data = FALSE; - m_stream.aborted = TRUE; - m_stream.icy_metaint = 0; - m_handle = 0; - m_metacount = 0; -} - - -Downloader::~Downloader() -{ - abort(); - curl_global_cleanup(); - m_stream.aborted = TRUE; - m_stream.buf_fill = 0; - if (m_stream.buf) - free(m_stream.buf); - - m_stream.buf = 0; -} - - -qint64 Downloader::read(char* data, qint64 maxlen) -{ - - qint64 len = 0; - m_mutex.lock(); - if (!m_stream.icy_meta_data || m_stream.icy_metaint == 0) - len = readBuffer(data, maxlen); - else - { - qint64 nread = 0; - qint64 to_read; - while (maxlen > nread && m_stream.buf_fill > nread) - { - to_read = qMin(m_stream.icy_metaint - m_metacount, maxlen - nread); - //to_read = (maxlen - nread); - qint64 res = readBuffer(data + nread, to_read); - nread += res; - m_metacount += res; - if (m_metacount == m_stream.icy_metaint) - { - m_metacount = 0; - m_mutex.unlock(); - readICYMetaData(); - m_mutex.lock(); - } - - } - len = nread; - - } - m_mutex.unlock(); - return len; -} - -Stream *Downloader::stream() -{ - return &m_stream; -} - -QMutex *Downloader::mutex() -{ - return &m_mutex; -} - -QString Downloader::contentType() -{ - QString content; - if (m_stream.header.contains("content-type")) - content = m_stream.header.value("content-type"); - return content; -} - -void Downloader::abort() -{ - m_mutex.lock(); - - if (m_stream.aborted) - { - m_mutex.unlock(); - return; - } - m_stream.aborted = TRUE; - m_mutex.unlock(); - wait(); - if (m_handle) - { - curl_easy_cleanup(m_handle); - m_handle = 0; - } -} - -int Downloader::bytesAvailable() -{ - m_mutex.lock(); - int b = m_stream.buf_fill; - m_mutex.unlock(); - return b; -} - -void Downloader::run() -{ - qDebug("Downloader: starting download thread"); - m_handle = curl_easy_init(); - //proxy - QSettings settings ( Qmmp::configFile(), QSettings::IniFormat ); - if (Qmmp::useProxy()) - curl_easy_setopt(m_handle, CURLOPT_PROXY, - strdup((Qmmp::proxy().host() + ":" + - QString("%1").arg(Qmmp::proxy().port())). - toLatin1 ().constData ())); - - if (Qmmp::useProxyAuth()) - curl_easy_setopt(m_handle, CURLOPT_PROXYUSERPWD, - strdup((Qmmp::proxy().userName() + ":" + - Qmmp::proxy().password()). - toLatin1 ().constData ())); - - // Set url to download - curl_easy_setopt(m_handle, CURLOPT_URL, strdup(m_url.toAscii().constData())); - // callback for wrting - curl_easy_setopt(m_handle, CURLOPT_WRITEFUNCTION, curl_write_data); - // Set destination file - curl_easy_setopt(m_handle, CURLOPT_WRITEDATA, this); - curl_easy_setopt(m_handle, CURLOPT_HEADERDATA, this); - curl_easy_setopt(m_handle, CURLOPT_HEADERFUNCTION, curl_header); - // Disable SSL - curl_easy_setopt(m_handle, CURLOPT_SSL_VERIFYPEER, FALSE); - curl_easy_setopt(m_handle, CURLOPT_SSL_VERIFYHOST, 0); - // Enable progress meter - curl_easy_setopt(m_handle, CURLOPT_NOPROGRESS, 0); - curl_easy_setopt(m_handle, CURLOPT_PROGRESSDATA, this); - curl_easy_setopt(m_handle, CURLOPT_PROGRESSFUNCTION, curl_progress); - // Any kind of authentication - curl_easy_setopt(m_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - curl_easy_setopt(m_handle, CURLOPT_VERBOSE, 1); - // Auto referrer - curl_easy_setopt(m_handle, CURLOPT_AUTOREFERER, 1); - // Follow redirections - curl_easy_setopt(m_handle, CURLOPT_FOLLOWLOCATION, 1); - 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); - curl_easy_setopt(m_handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); - - struct curl_slist *http200_aliases = curl_slist_append(NULL, "ICY"); - struct curl_slist *http_headers = curl_slist_append(NULL, "Icy-MetaData: 1"); - curl_easy_setopt(m_handle, CURLOPT_HTTP200ALIASES, http200_aliases); - curl_easy_setopt(m_handle, CURLOPT_HTTPHEADER, http_headers); - m_mutex.lock(); - m_stream.buf_fill = 0; - m_stream.buf = 0; - m_stream.aborted = FALSE; - m_stream.header.clear (); - m_ready = FALSE; - int return_code; - qDebug("Downloader: starting libcurl"); - m_mutex.unlock(); - return_code = curl_easy_perform(m_handle); - qDebug("curl_easy_perform %d", return_code); - qDebug("Downloader: thread finished"); -} - -qint64 Downloader::readBuffer(char* data, qint64 maxlen) -{ - if (m_stream.buf_fill > 0 && !m_stream.aborted) - { - int len = qMin(m_stream.buf_fill, maxlen); - memcpy(data, m_stream.buf, len); - m_stream.buf_fill -= len; - memmove(m_stream.buf, m_stream.buf + len, m_stream.buf_fill); - return len; - } - return 0; -} - -const QString &Downloader::title() const -{ - return m_title; -} - -void Downloader::checkBuffer() -{ - if (m_stream.buf_fill > BUFFER_SIZE && !m_ready) - { - m_ready = TRUE; - qDebug("Downloader: ready"); - emit readyRead(); - } - else if (!m_ready) - { - emit bufferingProgress(100 * m_stream.buf_fill / BUFFER_SIZE); - qApp->processEvents(); - } - -} - -bool Downloader::isReady() -{ - return m_ready; -} - -void Downloader::readICYMetaData() -{ - uint8_t packet_size; - m_metacount = 0; - m_mutex.lock(); - readBuffer((char *)&packet_size, sizeof(packet_size)); - if (packet_size != 0) - { - int size = packet_size * 16; - char packet[size]; - while (m_stream.buf_fill < size && isRunning()) - { - m_mutex.unlock(); - qApp->processEvents(); - m_mutex.lock(); - } - readBuffer(packet, size); - qDebug("Downloader: ICY metadata: %s", packet); - parseICYMetaData(packet); - } - m_mutex.unlock(); - -} - -void Downloader::parseICYMetaData(char *data) -{ - QString str(data); - QStringList list(str.split(";", QString::SkipEmptyParts)); - foreach(QString line, list) - { - if (line.contains("StreamTitle=")) - { - line = line.right(line.size() - line.indexOf("=") - 1).trimmed(); - m_title = line.remove("'"); - if (!m_title.isEmpty()) - { - QMap metaData; - metaData.insert(Qmmp::TITLE, m_title); - metaData.insert(Qmmp::URL, m_url); - StateHandler::instance()->dispatch(metaData); - } - break; - } - } -} diff --git a/src/qmmp/downloader.h b/src/qmmp/downloader.h deleted file mode 100644 index 0ac96786d..000000000 --- a/src/qmmp/downloader.h +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2008 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 DOWNLOADER_H -#define DOWNLOADER_H - -#include -#include -#include -#include - -#include - -#define BUFFER_SIZE 128000 - -/*! @internal - * @author Ilya Kotov - */ -struct Stream -{ - char *buf; - int buf_fill; - QString content_type; - bool aborted; - QMap header; - bool icy_meta_data; - int icy_metaint; -}; -/*! @internal - * @author Ilya Kotov - */ -class Downloader : public QThread -{ - Q_OBJECT -public: - Downloader(QObject *parent, const QString &url); - - ~Downloader(); - - qint64 read(char* data, qint64 maxlen); - Stream *stream(); - QMutex *mutex(); - QString contentType(); - void abort(); - int bytesAvailable(); - const QString& title() const; - void checkBuffer(); - bool isReady(); - -signals: - void readyRead(); - void bufferingProgress(int); - -private: - qint64 readBuffer(char* data, qint64 maxlen); - void readICYMetaData(); - void parseICYMetaData(char *data); - CURL *m_handle; - QMutex m_mutex; - Stream m_stream; - QString m_url; - int m_metacount; - QString m_title; - bool m_ready; - -protected: - void run(); - -}; - -#endif 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 */ 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 +*/ +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 +#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 +*/ +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 -#include "streamreader.h" +#include +#include +#include +#include +#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 *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(m_device)->downloadFile(); - return; + qDebug("InputSource: using fake transport"); + return new EmptyInputSource(url, parent); } - m_isValid = FALSE; } -const QString InputSource::url() +QList *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; + + 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(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 #include +#include #include +#include "inputsourcefactory.h" +/*! + * @author Ilya Kotov + */ 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 *factories(); + signals: - void readyRead(); + void ready(InputSource *); private: QString m_url; - QIODevice *m_device; - bool m_isValid; + static void checkFactories(); + static QList *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 + +class InputSource; + +/*! @brief Helper class to store transport plugin properies. + * @author Ilya Kotov + */ +class InputSourceProperties +{ +public: + QString protocols; /*!< Supported protocols. */ + QString shortName; /*!< Transport plugin name for internal usage */ +}; + + +/*! @brief Transport plugin interface. + * @author Ilya Kotov + */ +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(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 m_pendingSources; }; #endif diff --git a/src/qmmp/streamreader.cpp b/src/qmmp/streamreader.cpp deleted file mode 100644 index 5d61c76d1..000000000 --- a/src/qmmp/streamreader.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2008 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 -#include - -#include "downloader.h" -#include "streamreader.h" - -StreamReader::StreamReader(const QString &name, QObject *parent) - : QIODevice(parent) -{ - m_downloader = new Downloader(this, name); - connect(m_downloader, SIGNAL(readyRead()), SIGNAL(readyRead())); - connect(m_downloader, SIGNAL(bufferingProgress(int)), SIGNAL(bufferingProgress(int))); -} - -StreamReader::~StreamReader() -{ - m_downloader->abort(); - qDebug("StreamReader::~StreamReader()"); -} - -bool StreamReader::atEnd () const -{ - return FALSE; -} - -qint64 StreamReader::bytesAvailable () const -{ - return m_downloader->bytesAvailable (); -} - -qint64 StreamReader::bytesToWrite () const -{ - return -1; -} - -bool StreamReader::canReadLine () const -{ - return FALSE; -} - -void StreamReader::close () -{ - m_downloader->abort(); -} - -bool StreamReader::isSequential () const -{ - return TRUE; -} - -bool StreamReader::open ( OpenMode mode ) -{ - if (mode != QIODevice::ReadOnly) - return FALSE; - //downloadFile(); - setOpenMode(QIODevice::ReadOnly); - if (m_downloader->isReady()) - return TRUE; - else - return FALSE; -} - -bool StreamReader::reset () -{ - QIODevice::reset(); - return TRUE; -} - -bool StreamReader::seek ( qint64 pos ) -{ - QIODevice::seek(pos); - return FALSE; -} - -qint64 StreamReader::size () const -{ - return bytesAvailable (); -} - -bool StreamReader::waitForBytesWritten ( int msecs ) -{ - //usleep(msecs*1000); - return TRUE; -} - -bool StreamReader::waitForReadyRead ( int msecs ) -{ - //usleep(msecs*1000); - return TRUE; -} - -qint64 StreamReader::readData(char* data, qint64 maxlen) -{ - return m_downloader->read (data, maxlen); -} - -qint64 StreamReader::writeData(const char*, qint64) -{ - return 0; -} - -void StreamReader::downloadFile() -{ - m_downloader->start(); -} - -const QString &StreamReader::contentType() -{ - m_downloader->mutex()->lock (); - m_contentType = m_downloader->contentType(); - m_downloader->mutex()->unlock(); - qApp->processEvents(); - qDebug("StreamReader: content type: %s", qPrintable(m_contentType)); - return m_contentType; -} diff --git a/src/qmmp/streamreader.h b/src/qmmp/streamreader.h deleted file mode 100644 index e73f65389..000000000 --- a/src/qmmp/streamreader.h +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006-2008 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 STREAMREADER_H -#define STREAMREADER_H - -#include -#include -#include - -class QFileInfo; - -class Downloader; - -/*! @internal - * @author Ilya Kotov - */ -class StreamReader : public QIODevice -{ - Q_OBJECT -public: - StreamReader(const QString &name, QObject *parent = 0); - - ~StreamReader(); - - /** - * QIODevice API - */ - bool atEnd () const; - qint64 bytesAvailable () const; - qint64 bytesToWrite () const; - bool canReadLine () const; - void close (); - bool isSequential () const; - bool open ( OpenMode mode ); - //qint64 pos () const; - bool reset (); - bool seek ( qint64 pos ); - qint64 size () const; - bool waitForBytesWritten ( int msecs ); - bool waitForReadyRead ( int msecs ); - - /** - * returns content type of a stream - */ - const QString &contentType(); - void downloadFile(); - -signals: - void readyRead(); - void bufferingProgress(int); - -protected: - qint64 readData(char*, qint64); - qint64 writeData(const char*, qint64); - -private: - //void downloadFile(); - void fillBuffer(); - QUrl m_url; - QString m_contentType; - Downloader *m_downloader; -}; - -#endif -- cgit v1.2.3-13-gbd6f