00001 /* 00002 Copyright (C) 2008-2010 Lukas Sommer < SommerLuk at gmail dot com > 00003 00004 This program is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU General Public License as 00006 published by the Free Software Foundation; either version 2 of 00007 the License or (at your option) version 3 or any later version 00008 accepted by the membership of KDE e.V. (or its successor approved 00009 by the membership of KDE e.V.), which shall act as a proxy 00010 defined in Section 14 of version 3 of the license. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include "icecast_internalthread.h" 00022 00023 #include <QFile> 00024 #include <QMutexLocker> 00025 00026 icecast_internalThread::icecast_internalThread() 00027 { 00028 } 00029 00030 icecast_internalThread::~icecast_internalThread() 00031 { 00032 wait(); 00033 } 00034 00035 void icecast_internalThread::run() 00036 { 00037 // variables 00038 QXmlStreamReader xml; 00039 QFile yp; 00040 QString tmpFile; 00041 00042 // code 00043 filename_mutex.lock(); 00044 tmpFile = filename; 00045 filename_mutex.unlock(); 00046 yp.setFileName(tmpFile); 00047 yp.open(QIODevice::ReadOnly); 00048 xml.setDevice(&yp); 00049 streamList.clear(); 00050 while (!xml.atEnd()) { 00051 xml.readNext(); 00052 if (xml.isStartElement() && (xml.name() == "entry")) { 00053 readStreamEntry(xml); 00054 }; 00055 }; 00056 emit streamlist_ready(streamList); 00057 } 00058 00059 void icecast_internalThread::readStreamEntry(QXmlStreamReader & reader) 00060 { 00061 streamDirectoryEntry_stream *streamEntry = new streamDirectoryEntry_stream(); 00062 while (!((reader.isEndElement() && (reader.name() == "entry")) || reader.atEnd())) { 00063 reader.readNext(); 00064 if (reader.isStartElement()) { 00065 if (reader.name() == "server_name") { 00066 streamEntry->setName(reader.readElementText()); 00067 } else if (reader.name() == "listen_url") { 00068 streamEntry->setValue(reader.readElementText()); 00069 } else if (reader.name() == "server_type") { 00070 QString m_servertype = reader.readElementText(); 00071 if (m_servertype == "audio/aacp") { 00072 streamEntry->streamType = streamDirectoryEntry_stream::aac_plus; 00073 } else if (m_servertype == "audio/aac") { 00074 streamEntry->streamType = streamDirectoryEntry_stream::aac; 00075 } else if (m_servertype == "audio/mpeg") { 00076 streamEntry->streamType = streamDirectoryEntry_stream::mp3; 00077 } else if (m_servertype == "application/ogg") { 00078 streamEntry->streamType = streamDirectoryEntry_stream::ogg; 00079 } else if (m_servertype == "video/nsv") { 00080 streamEntry->streamType = streamDirectoryEntry_stream::nsv; 00081 } else { 00082 streamEntry->streamType = streamDirectoryEntry_stream::unknown; 00083 }; 00084 } else if (reader.name() == "bitrate") { 00085 streamEntry->bitrate = reader.readElementText().toULongLong(); 00086 if (streamEntry->bitrate >= 1024) { 00087 // Sometimes, the bitrate is given in bit/s instead of kbit/s. 00088 // Furthermore, it's unclear if SI prefixes or binary prefixes 00089 // are used. The calculation we do here is not necesarrily correct, 00090 // but seems to work quite well in practice. 00091 streamEntry->bitrate = streamEntry->bitrate / 1024; 00092 }; 00093 } else if (reader.name() == "current_song") { 00094 streamEntry->currentlyPlaying = !(reader.readElementText().trimmed().isEmpty()); 00095 }; 00096 // "channels" and "samplerate" are also elements that are present, but I don't know 00097 // exactly what they mean. Furthermore, they seem to be always 0. 00098 }; 00099 }; 00100 streamList.append(streamEntry); 00101 } 00102 00103 void icecast_internalThread::setFilename(QString newFilename) 00104 { 00105 QMutexLocker locker(&filename_mutex); 00106 filename = newFilename; 00107 }