Index: mythmusic/mythmusic.pro =================================================================== RCS file: /var/lib/mythcvs/mythmusic/mythmusic/mythmusic.pro,v retrieving revision 1.23 diff -u -r1.23 mythmusic.pro --- mythmusic/mythmusic.pro 24 Jan 2004 01:04:54 -0000 1.23 +++ mythmusic/mythmusic.pro 8 Feb 2004 16:34:51 -0000 @@ -30,7 +30,7 @@ HEADERS += audiooutput.h buffer.h cddecoder.h cdrip.h constants.h databasebox.h HEADERS += decoder.h flacdecoder.h flacencoder.h maddecoder.h mainvisual.h HEADERS += metadata.h playbackbox.h playlist.h polygon.h output.h recycler.h -HEADERS += streaminput.h synaesthesia.h encoder.h visualize.h avfdecoder.h +HEADERS += streaminput.h synaesthesia.h encoder.h visualize.h avfdecoder.h shoutcaststream.h HEADERS += treecheckitem.h visual.h vorbisdecoder.h vorbisencoder.h polygon.h HEADERS += bumpscope.h globalsettings.h lameencoder.h dbcheck.h HEADERS += goom/filters.h goom/goomconfig.h goom/goom_core.h goom/graphic.h @@ -41,7 +41,7 @@ SOURCES += flacdecoder.cpp flacencoder.cpp maddecoder.cpp main.cpp SOURCES += mainvisual.cpp metadata.cpp playbackbox.cpp playlist.cpp output.cpp SOURCES += recycler.cpp streaminput.cpp encoder.cpp resample.c dbcheck.cpp -SOURCES += synaesthesia.cpp treecheckitem.cpp vorbisdecoder.cpp lameencoder.cpp +SOURCES += synaesthesia.cpp treecheckitem.cpp vorbisdecoder.cpp lameencoder.cpp shoutcaststream.cpp SOURCES += vorbisencoder.cpp visualize.cpp bumpscope.cpp globalsettings.cpp SOURCES += goom/filters.c goom/goom_core.c goom/graphic.c goom/tentacle3d.c SOURCES += goom/ifs.c goom/ifs_display.c goom/lines.c goom/surf3d.c Index: mythmusic/playbackbox.cpp =================================================================== RCS file: /var/lib/mythcvs/mythmusic/mythmusic/playbackbox.cpp,v retrieving revision 1.68 diff -u -r1.68 playbackbox.cpp --- mythmusic/playbackbox.cpp 26 Jan 2004 06:06:45 -0000 1.68 +++ mythmusic/playbackbox.cpp 8 Feb 2004 16:34:53 -0000 @@ -512,8 +512,8 @@ return; } - QUrl sourceurl(playfile); - QString sourcename(playfile); +// QUrl sourceurl(playfile); +// QString sourcename(playfile); bool startoutput = false; @@ -539,25 +539,43 @@ return; } - if (!sourceurl.isLocalFile()) - { - StreamInput streaminput(sourceurl); - streaminput.setup(); - input = streaminput.socket(); - } - else - input = new QFile(playfile); + input = new StreamInput(playfile); + + cout << "'" << playfile.ascii() << "'" << endl; // DEBUG + + if (! input->type()) { + +// if (!sourceurl.isLocalFile()) +// { +// StreamInput streaminput(sourceurl); +// streaminput.setup(); +// input = streaminput.socket(); +// } +// else +// input = new QFile(playfile); + + VERBOSE(VB_PLAYBACK, QString("mythmusic: error reading input " + "file/stream: '%1'").arg(playfile)); + stopAll(); + return; + } + + // filename extension of playfile selects decoder + playfile = input->name(); - if (decoder && !decoder->factory()->supports(sourcename)) +// if (decoder && !decoder->factory()->supports(sourcename)) + if (decoder && !decoder->factory()->supports(playfile)) decoder = 0; if (!decoder) { - decoder = Decoder::create(sourcename, input, output); +// decoder = Decoder::create(sourcename, input, output); + decoder = Decoder::create(playfile, input, output); if (!decoder) { - printf("mythmusic: unsupported fileformat\n"); +// printf("mythmusic: unsupported fileformat\n"); + VERBOSE(VB_PLAYBACK, "mythmusic: unsupported audioformat"); stopAll(); return; } @@ -568,7 +586,7 @@ else { decoder->setInput(input); - decoder->setFilename(sourcename); + decoder->setFilename(playfile);//sourcename); decoder->setOutput(output); } Index: mythmusic/playbackbox.h =================================================================== RCS file: /var/lib/mythcvs/mythmusic/mythmusic/playbackbox.h,v retrieving revision 1.31 diff -u -r1.31 playbackbox.h --- mythmusic/playbackbox.h 26 Aug 2003 15:45:18 -0000 1.31 +++ mythmusic/playbackbox.h 8 Feb 2004 16:34:53 -0000 @@ -15,6 +15,7 @@ class Output; class Decoder; +class StreamInput; class PlaybackBox : public MythThemedDialog { @@ -80,7 +81,8 @@ void CycleVisualizer(void); - QIODevice *input; +// QIODevice *input; + StreamInput *input; Output *output; Decoder *decoder; Index: mythmusic/streaminput.cpp =================================================================== RCS file: /var/lib/mythcvs/mythmusic/mythmusic/streaminput.cpp,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 streaminput.cpp --- mythmusic/streaminput.cpp 31 Jul 2002 05:59:57 -0000 1.1.1.1 +++ mythmusic/streaminput.cpp 8 Feb 2004 16:34:54 -0000 @@ -4,118 +4,229 @@ // warranty, or liability of any kind. // -#include "streaminput.h" +//#include "streaminput.h" -#include +//#include +#include #include +#include +#include +#include +using namespace std; + +#include "streaminput.h" +#include "shoutcaststream.h" +//StreamInput::StreamInput(const QUrl &source) +// : request(0), url(source), sock(0), stage(0) +StreamInput::StreamInput(QString playfile) +{ +//} + mediatype = ""; + medianame = ""; + device = NULL; + + QUrl url(playfile); + + +//void StreamInput::setup() +//{ +// if (! url.isValid()) +// return; + + cout << "new streaminput '" << playfile.ascii() << "'\n"; //DEBUG + if ( url.isValid()) + { + streamurl = url; + QString proto = url.protocol(); + medianame = playfile; + mediatype = "remote"; + +// QString protocol = url.protocol(); +// QString host = url.host(); +// QString path = url.path(); +// int port = url.port(); + + if (url.isLocalFile()) + { + mediatype = "local"; + device = new QFile(playfile); + } + else if (proto == "shoutcast") + { + medianame = "blah.mp3"; + device = new ShoutcastStream(&url); + } +/* + else if (proto == "icecast") + { + medianame = "blah.ogg"; + device = new IcecastStream(playfile); + } +*/ + } +} + +// if (protocol != "mqp" || host.isNull()) +// return; + +StreamInput::~StreamInput() +{ + delete device; +} +/* +bool StreamInput::openSocket(QUrl *source) +{ + QString host = source->host(); + int port = source->port(); + + qApp->lock(); + socket = new QSocket(); + socket->connectToHost(host, port); + qApp->unlock(); + +// if (port == -1) +// port = 42666; + + int i = 0; + while (socket->state() == QSocket::HostLookup || + socket->state() == QSocket::Connecting) + { + qApp->processEvents(); + +// request = ".song " + path.utf8() + "\r\n"; + + i++; + if (i > 500) + break; + usleep(50); + } + + if (socket->state() != QSocket::Connected) + return false; + return true; +} + +void StreamInput::closeSocket() +{ + socket->close(); + delete socket; + + +// sock = new QSocket; +// connect(sock, SIGNAL(error(int)), this, SLOT(error(int))); +// connect(sock, SIGNAL(hostFound()), this, SLOT(hostfound())); +// connect(sock, SIGNAL(connected()), this, SLOT(connected())); +// connect(sock, SIGNAL(readyRead()), this, SLOT(readyread())); +} + +// sock->connectToHost(host, port); + +// while (stage != -1 && stage < 4) { +// qDebug("processing one event: stage %d %d %ld", +// stage, sock->canReadLine(), sock->bytesAvailable()); +// qApp->processOneEvent(); +// } + +void StreamInput::sendRequest(const QString request) +{ + socket->writeBlock(request, request.length()); + socket->flush(); + printf("\'%s\'",request.ascii()); //DEBUG +} + +// qDebug("disconnecting from socket"); +// disconnect(sock, SIGNAL(error(int)), this, SLOT(error(int))); +// disconnect(sock, SIGNAL(hostFound()), this, SLOT(hostfound())); +// disconnect(sock, SIGNAL(connected()), this, SLOT(connected())); +// disconnect(sock, SIGNAL(readyRead()), this, SLOT(readyread())); -StreamInput::StreamInput(const QUrl &source) - : request(0), url(source), sock(0), stage(0) -{ -} - +// if (stage == -1) { + // some sort of error +// delete sock; +// sock = 0; -void StreamInput::setup() +bool StreamInput::readlineSocket(QString &request) { - if (! url.isValid()) - return; - - QString protocol = url.protocol(); - QString host = url.host(); - QString path = url.path(); - int port = url.port(); - - if (protocol != "mqp" || host.isNull()) - return; - - if (port == -1) - port = 42666; - - request = ".song " + path.utf8() + "\r\n"; - - - sock = new QSocket; - connect(sock, SIGNAL(error(int)), this, SLOT(error(int))); - connect(sock, SIGNAL(hostFound()), this, SLOT(hostfound())); - connect(sock, SIGNAL(connected()), this, SLOT(connected())); - connect(sock, SIGNAL(readyRead()), this, SLOT(readyread())); - - sock->connectToHost(host, port); - - while (stage != -1 && stage < 4) { - qDebug("processing one event: stage %d %d %ld", - stage, sock->canReadLine(), sock->bytesAvailable()); - qApp->processOneEvent(); - } - - qDebug("disconnecting from socket"); - disconnect(sock, SIGNAL(error(int)), this, SLOT(error(int))); - disconnect(sock, SIGNAL(hostFound()), this, SLOT(hostfound())); - disconnect(sock, SIGNAL(connected()), this, SLOT(connected())); - disconnect(sock, SIGNAL(readyRead()), this, SLOT(readyread())); - - if (stage == -1) { - // some sort of error - delete sock; - sock = 0; + int i = 0; + while (socket->state() == QSocket::Connected) + { + if (socket->canReadLine()) + { + request = socket->readLine(); + return true; + } + i++; + if (i > 500) + break; + usleep(50); } + return false; } -void StreamInput::hostfound() +//void StreamInput::hostfound() +*/ +bool StreamInput::open(int mode) { - qDebug("host found"); - stage = 1; +// qDebug("host found"); +// stage = 1; + if (mediatype == "local") + return device->open(mode); + return true; } - -void StreamInput::connected() +//void StreamInput::connected() +void StreamInput::close() { - qDebug("connected... sending request '%s' %d", request.data(), request.length()); +// qDebug("connected... sending request '%s' %d", request.data(), request.length()); - sock->writeBlock(request.data(), request.length()); - sock->flush(); +// sock->writeBlock(request.data(), request.length()); +// sock->flush(); - stage = 2; +// stage = 2; + device->close(); } -void StreamInput::readyread() +//void StreamInput::readyread() +void StreamInput::flush() { - if (stage == 2) { - qDebug("readyread... checking response"); - - if (! sock->canReadLine()) { - stage = -1; - qDebug("can't read line"); - return; - } + device->flush(); +} - QString line = sock->readLine(); - if (line.isEmpty()) { - stage = -1; - qDebug("line is empty"); - return; - } +Q_ULONG StreamInput::size() const +{ + return device->size(); +} - if (line.left(5) != "*GOOD") { - qDebug("server error response: %s", line.latin1()); - stage = -1; - return; - } +Q_LONG StreamInput::readBlock(char *data, Q_ULONG maxlen ) +{ + cout << "streaminput: readBlock\n"; //DEBUG + return device->readBlock(data, maxlen); +} - stage = 3; - } else if (sock->bytesAvailable() > 65536 || sock->atEnd()) { - stage = 4; - } +Q_LONG StreamInput::writeBlock(const char *data, Q_ULONG len) +{ + return device->writeBlock(data, len); } +Q_LONG StreamInput::readLine(char *data, Q_ULONG maxlen) +{ + return device->readLine(data, maxlen); +} -void StreamInput::error(int err) +int StreamInput::getch() { - qDebug("socket error: %d", err); + return device->getch(); +} - stage = -1; +int StreamInput::putch(int ch) +{ + return device->putch(ch); } +int StreamInput::ungetch(int ch) +{ + return device->ungetch(ch); +} Index: mythmusic/streaminput.h =================================================================== RCS file: /var/lib/mythcvs/mythmusic/mythmusic/streaminput.h,v retrieving revision 1.1.1.1 diff -u -r1.1.1.1 streaminput.h --- mythmusic/streaminput.h 31 Jul 2002 05:59:57 -0000 1.1.1.1 +++ mythmusic/streaminput.h 8 Feb 2004 16:34:54 -0000 @@ -7,35 +7,47 @@ #ifndef INPUT_H #define INPUT_H -class StreamInput; - +#include #include #include -class StreamInput : public QObject +class StreamInput : public QIODevice { - Q_OBJECT public: - StreamInput(const QUrl &); - - QIODevice *socket() { return sock; } - - void setup(); - - -private slots: - void hostfound(); - void connected(); - void readyread(); - void error(int); - + StreamInput(QString playfile); + ~StreamInput(); -private: - QCString request; - QUrl url; - QSocket *sock; - int stage; + bool open( int mode ); + void close(); + void flush(); + + Q_ULONG size() const; + + Q_LONG readBlock( char *data, Q_ULONG maxlen ); + Q_LONG writeBlock( const char *data, Q_ULONG len ); + Q_LONG readLine( char *data, Q_ULONG maxlen ); + + int getch(); + int putch( int ch); + int ungetch( int ch); + + QString type() { return mediatype; } + QString name() { return medianame; } + //virtual bool initialize() = 0; + //virtual bool start() = 0; + + private: +/* + bool openSocket(QUrl *source); + void closeSocket(); + void sendRequest(const QString request); + bool readlineSocket(QString &request); +*/ + QIODevice *device; + QUrl streamurl; + QString mediatype; + QString medianame; };