aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2007-08-21 19:13:47 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2007-08-21 19:13:47 +0000
commited3828f0df1bcef66b036ce1831a0aed87ed5482 (patch)
tree33c21269d4c2556c67a7db22b71c55cb604950db /lib
parentf19a1f3ea9aa8080b15b384bbe73896e4407ac41 (diff)
downloadqmmp-ed3828f0df1bcef66b036ce1831a0aed87ed5482.tar.gz
qmmp-ed3828f0df1bcef66b036ce1831a0aed87ed5482.tar.bz2
qmmp-ed3828f0df1bcef66b036ce1831a0aed87ed5482.zip
added shoutcast title update
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@119 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'lib')
-rw-r--r--lib/downloader.cpp31
-rw-r--r--lib/downloader.h6
-rw-r--r--lib/filetag.h1
-rw-r--r--lib/soundcore.cpp14
-rw-r--r--lib/soundcore.h8
-rw-r--r--lib/streamreader.cpp76
-rw-r--r--lib/streamreader.h14
7 files changed, 62 insertions, 88 deletions
diff --git a/lib/downloader.cpp b/lib/downloader.cpp
index 56564419c..e025e4f52 100644
--- a/lib/downloader.cpp
+++ b/lib/downloader.cpp
@@ -19,7 +19,7 @@
***************************************************************************/
#include <QApplication>
-
+#include <QStringList>
#include "downloader.h"
@@ -261,15 +261,18 @@ qint64 Downloader::readBuffer(char* data, qint64 maxlen)
return 0;
}
+const QString &Downloader::title() const
+{
+ return m_title;
+}
+
void Downloader::readICYMetaData()
{
uint8_t packet_size;
m_metacount = 0;
m_mutex.lock();
readBuffer((char *)&packet_size, sizeof(packet_size));
- if (packet_size == 0)
- qDebug("zero");
- else
+ if (packet_size != 0)
{
int size = packet_size * 16;
char packet[size];
@@ -280,9 +283,25 @@ void Downloader::readICYMetaData()
m_mutex.lock();
}
readBuffer(packet, size);
- qDebug(packet);
-
+ 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("'");
+ emit titleChanged ();
+ break;
+ }
+ }
+}
diff --git a/lib/downloader.h b/lib/downloader.h
index 308fca83a..13be0121e 100644
--- a/lib/downloader.h
+++ b/lib/downloader.h
@@ -56,15 +56,21 @@ public:
QString contentType();
void abort();
int bytesAvailable();
+ const QString& title() const;
+
+signals:
+ void titleChanged ();
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;
protected:
void run();
diff --git a/lib/filetag.h b/lib/filetag.h
index c2d36a842..f75facfa0 100644
--- a/lib/filetag.h
+++ b/lib/filetag.h
@@ -62,7 +62,6 @@ public:
private:
QMap <uint, QString> m_strValues;
QMap <uint, uint> m_numValues;
-
};
#endif
diff --git a/lib/soundcore.cpp b/lib/soundcore.cpp
index afa03d61f..8c59d015b 100644
--- a/lib/soundcore.cpp
+++ b/lib/soundcore.cpp
@@ -54,11 +54,11 @@ SoundCore::SoundCore(QObject *parent)
QList<OutputFactory*> *outputFactories = Output::outputFactories();
foreach(OutputFactory* of, *outputFactories)
- qApp->installTranslator(of->createTranslator(this));
+ qApp->installTranslator(of->createTranslator(this));
QList<DecoderFactory*> *decoderFactories = Decoder::decoderFactories();
foreach(DecoderFactory* df, *decoderFactories)
- qApp->installTranslator(df->createTranslator(this));
+ qApp->installTranslator(df->createTranslator(this));
}
@@ -73,9 +73,11 @@ bool SoundCore::play(const QString &source)
m_error = DecoderError;
return FALSE;
}
- if(source.left(4) == "http")
+ if (source.left(4) == "http")
{
m_input = new StreamReader(source, this);
+ connect(m_input, SIGNAL(titleChanged(const QString&)),
+ SIGNAL(titleChanged(const QString&)));
}
else
m_input = new QFile(source);
@@ -97,7 +99,7 @@ bool SoundCore::play(const QString &source)
m_error = DecoderError;
- if(m_vis)
+ if (m_vis)
{
m_vis->setOutput(m_output);
m_output->addVisual(m_vis);
@@ -146,7 +148,7 @@ uint SoundCore::error()
void SoundCore::stop()
{
- if(m_block)
+ if (m_block)
return;
m_paused = FALSE;
if (m_decoder && m_decoder->isRunning())
@@ -188,7 +190,7 @@ void SoundCore::stop()
{
m_output->uninitialize();
}
-
+
//display->setTime(0);
if (m_decoder)
{
diff --git a/lib/soundcore.h b/lib/soundcore.h
index 7e9d7369f..7e88942f7 100644
--- a/lib/soundcore.h
+++ b/lib/soundcore.h
@@ -150,6 +150,14 @@ signals:
*/
void outputStateChanged(const OutputState& state);
+ /*!
+ * This signal is emited when the title of the stream changes.
+ * The argument \b title is the new title of the stream.
+ * Signal emits with the shoutcast server stream only.
+ * For another servers use decoderStateChanged()
+ */
+ void titleChanged(const QString& title);
+
private:
Decoder* m_decoder;
Output* m_output;
diff --git a/lib/streamreader.cpp b/lib/streamreader.cpp
index e1af3201f..914846335 100644
--- a/lib/streamreader.cpp
+++ b/lib/streamreader.cpp
@@ -27,11 +27,13 @@ StreamReader::StreamReader(const QString &name, QObject *parent)
: QIODevice(parent)
{
m_downloader = new Downloader(this, name);
+ connect(m_downloader, SIGNAL(titleChanged()),SLOT(updateTitle()));
}
StreamReader::~StreamReader()
{
m_downloader->abort();
+ qDebug("StreamReader::~StreamReader()");
}
bool StreamReader::atEnd () const
@@ -56,8 +58,6 @@ bool StreamReader::canReadLine () const
void StreamReader::close ()
{
- //m_httpRequestAborted = TRUE;
- //m_http->close();
m_downloader->abort();
}
@@ -71,17 +71,13 @@ bool StreamReader::open ( OpenMode mode )
if (mode != QIODevice::ReadOnly)
return FALSE;
downloadFile();
- //if (m_httpRequestAborted)
- //return TRUE;
setOpenMode(QIODevice::ReadOnly);
- return TRUE;
+ if (m_downloader->isRunning())
+ return TRUE;
+ else
+ return FALSE;
}
-/*qint64 StreamReader::pos () const
-{
- return m_pos;
-}*/
-
bool StreamReader::reset ()
{
QIODevice::reset();
@@ -123,73 +119,19 @@ qint64 StreamReader::writeData(const char*, qint64)
void StreamReader::downloadFile()
{
- m_httpRequestAborted = FALSE;
- //qDebug("StreamReader: connecting...");
- //m_httpGetId = m_http->get(m_url.path(), 0);
qDebug("StreamReader: buffering...");
- /*while (m_http->bytesAvailable () < BUFFER_SIZE*0.5 && !m_httpRequestAborted)
- {
- qApp->processEvents();
- }*/
m_downloader->start();
- while (m_downloader->bytesAvailable () < BUFFER_SIZE*0.5 &&
- m_downloader->isRunning())
+ while (m_downloader->bytesAvailable () < BUFFER_SIZE*0.5 && m_downloader->isRunning ())
{
qApp->processEvents();
- //qDebug("StreamReader: bytes: %d",m_downloader->bytesAvailable ());
//sleep(1);
}
qDebug("StreamReader: ready");
}
-void StreamReader::cancelDownload()
+void StreamReader::updateTitle()
{
- m_httpRequestAborted = true;
- //&& !m_httpRequestAborted->abort();
-}
-
-void StreamReader::httpRequestFinished(int requestId, bool error)
-{
- if (m_httpRequestAborted)
- {
- return;
- }
-
- if (requestId != m_httpGetId)
- return;
-
- if (error)
- {
- //qDebug(qPrintable(QString("StreamReader: %1").arg(m_http->errorString())));
- m_httpRequestAborted = TRUE;
- }
- else
- {
- qDebug("StreamReader: end of file");
- }
-
-}
-
-void StreamReader::updateDataReadProgress(int bytesRead, int totalBytes)
-{
- m_pos = bytesRead;
- m_size = totalBytes;
- fillBuffer();
-}
-
-void StreamReader::fillBuffer()
-{
- /*if (m_http->bytesAvailable () > BUFFER_SIZE && !m_httpRequestAborted)
- {
- while (m_http->bytesAvailable () > BUFFER_SIZE*0.75 && !m_httpRequestAborted)
- {
- qDebug("StreamReader: skipping data...");
- char *data = new char[BUFFER_SIZE/20];
- m_http->read (data, BUFFER_SIZE/20);
- qApp->processEvents();
- delete data;
- }
- }*/
+ emit titleChanged(m_downloader->title());
}
const QString &StreamReader::contentType()
diff --git a/lib/streamreader.h b/lib/streamreader.h
index 9b0af5df7..906ddd2ac 100644
--- a/lib/streamreader.h
+++ b/lib/streamreader.h
@@ -23,6 +23,7 @@
#include <QObject>
#include <QIODevice>
#include <QUrl>
+
#define BUFFER_SIZE 524288
class QFileInfo;
@@ -62,24 +63,21 @@ public:
*/
const QString &contentType();
+signals:
+ void titleChanged(const QString&);
+
protected:
qint64 readData(char*, qint64);
qint64 writeData(const char*, qint64);
private slots:
- void downloadFile();
- void cancelDownload();
- void httpRequestFinished(int, bool);
- void updateDataReadProgress(int bytesRead, int totalBytes);
+ void updateTitle();
private:
+ void downloadFile();
void fillBuffer();
QUrl m_url;
- bool m_httpRequestAborted;
- int m_httpGetId;
- int m_pos;
- int m_size;
QString m_contentType;
Downloader *m_downloader;
};