diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-09-12 20:27:01 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2009-09-12 20:27:01 +0000 |
| commit | a21018491ad5f53521b63dba062e2d7e87efc1c5 (patch) | |
| tree | cd26d1edca01fbd420681405e53214bb96233917 | |
| parent | 8fbf582b60b6267463e6a3dc289b52e49fdc2f83 (diff) | |
| download | qmmp-a21018491ad5f53521b63dba062e2d7e87efc1c5.tar.gz qmmp-a21018491ad5f53521b63dba062e2d7e87efc1c5.tar.bz2 qmmp-a21018491ad5f53521b63dba062e2d7e87efc1c5.zip | |
fixed memory leak
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1208 90c681e8-e032-0410-971d-27865f9a5e38
| -rw-r--r-- | src/plugins/Input/mad/decoder_mad.cpp | 31 | ||||
| -rw-r--r-- | src/plugins/Input/mad/decoder_mad.h | 1 | ||||
| -rw-r--r-- | src/qmmp/abstractengine.h | 2 | ||||
| -rw-r--r-- | src/qmmp/decoder.cpp | 15 | ||||
| -rw-r--r-- | src/qmmp/decoder.h | 7 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.cpp | 52 | ||||
| -rw-r--r-- | src/qmmp/qmmpaudioengine.h | 15 | ||||
| -rw-r--r-- | src/qmmp/soundcore.cpp | 22 | ||||
| -rw-r--r-- | src/qmmp/soundcore.h | 9 |
9 files changed, 64 insertions, 90 deletions
diff --git a/src/plugins/Input/mad/decoder_mad.cpp b/src/plugins/Input/mad/decoder_mad.cpp index bbfd43251..58d21bebd 100644 --- a/src/plugins/Input/mad/decoder_mad.cpp +++ b/src/plugins/Input/mad/decoder_mad.cpp @@ -22,7 +22,7 @@ DecoderMAD::DecoderMAD(QIODevice *i) - : Decoder() + : Decoder(i) { m_inited = false; m_totalTime = 0.; @@ -36,7 +36,6 @@ DecoderMAD::DecoderMAD(QIODevice *i) m_output_at = 0; m_skip_frames = 0; m_eof = false; - m_input = i; } DecoderMAD::~DecoderMAD() @@ -63,7 +62,7 @@ bool DecoderMAD::initialize() m_output_bytes = 0; m_output_at = 0; - if (!m_input) + if (!input()) { qWarning("DecoderMAD: cannot initialize. No input."); return FALSE; @@ -72,18 +71,18 @@ bool DecoderMAD::initialize() if (!m_input_buf) m_input_buf = new char[INPUT_BUFFER_SIZE]; - if (!m_input->isOpen()) + if (!input()->isOpen()) { - if (!m_input->open(QIODevice::ReadOnly)) + if (!input()->open(QIODevice::ReadOnly)) { - qWarning("DecoderMAD: %s", qPrintable(m_input->errorString ())); + qWarning("DecoderMAD: %s", qPrintable(input()->errorString ())); return FALSE; } } - if (m_input->isSequential ()) //for streams only + if (input()->isSequential ()) //for streams only { - TagExtractor extractor(m_input); + TagExtractor extractor(input()); if(!extractor.id3v2tag().isEmpty()) StateHandler::instance()->dispatch(extractor.id3v2tag()); } @@ -212,7 +211,7 @@ bool DecoderMAD::findHeader() memmove (m_input_buf, stream.next_frame, remaining); } - m_input_bytes = m_input->read(m_input_buf + remaining, INPUT_BUFFER_SIZE - remaining); + m_input_bytes = input()->read(m_input_buf + remaining, INPUT_BUFFER_SIZE - remaining); if (m_input_bytes <= 0) break; @@ -235,7 +234,7 @@ bool DecoderMAD::findHeader() } result = TRUE; - if (m_input->isSequential()) + if (input()->isSequential()) break; count ++; @@ -280,9 +279,9 @@ bool DecoderMAD::findHeader() if (!result) return FALSE; - if (!is_vbr && !m_input->isSequential()) + if (!is_vbr && !input()->isSequential()) { - double time = (m_input->size() * 8.0) / (header.bitrate); + double time = (input()->size() * 8.0) / (header.bitrate); double timefrac = (double)time - ((long)(time)); mad_timer_set(&duration, (long)time, (long)(timefrac*100), 100); } @@ -298,7 +297,7 @@ bool DecoderMAD::findHeader() m_channels = MAD_NCHANNELS(&header); m_bitrate = header.bitrate / 1000; mad_header_finish(&header); - m_input->seek(0); + input()->seek(0); m_input_bytes = 0; return TRUE; } @@ -363,8 +362,8 @@ void DecoderMAD::seek(qint64 pos) { if(m_totalTime > 0) { - qint64 seek_pos = qint64(pos * m_input->size() / m_totalTime); - m_input->seek(seek_pos); + qint64 seek_pos = qint64(pos * input()->size() / m_totalTime); + input()->seek(seek_pos); mad_frame_mute(&frame); mad_synth_mute(&synth); stream.error = MAD_ERROR_BUFLEN; @@ -382,7 +381,7 @@ bool DecoderMAD::fillBuffer() m_input_bytes = &m_input_buf[m_input_bytes] - (char *) stream.next_frame; memmove(m_input_buf, stream.next_frame, m_input_bytes); } - int len = m_input->read((char *) m_input_buf + m_input_bytes, INPUT_BUFFER_SIZE - m_input_bytes); + int len = input()->read((char *) m_input_buf + m_input_bytes, INPUT_BUFFER_SIZE - m_input_bytes); if (!len) { qDebug("DecoderMAD: end of file"); diff --git a/src/plugins/Input/mad/decoder_mad.h b/src/plugins/Input/mad/decoder_mad.h index 86369b4d9..68fc35538 100644 --- a/src/plugins/Input/mad/decoder_mad.h +++ b/src/plugins/Input/mad/decoder_mad.h @@ -47,7 +47,6 @@ private: uint m_bitrate; long m_freq, m_len; qint64 m_output_bytes, m_output_at; - QIODevice *m_input; // file input buffer char *m_input_buf; diff --git a/src/qmmp/abstractengine.h b/src/qmmp/abstractengine.h index eed9f9cc3..75829174f 100644 --- a/src/qmmp/abstractengine.h +++ b/src/qmmp/abstractengine.h @@ -42,7 +42,7 @@ public: * Prepares decoder for usage. * Subclass should reimplement this function. */ - virtual bool initialize(QIODevice *input, const QString &source) = 0; + virtual bool initialize(const QString &source, QIODevice *input = 0) = 0; /*! * Returns the total time in milliseconds. * Subclass should reimplement this function. diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp index 68e966dba..73a8816c1 100644 --- a/src/qmmp/decoder.cpp +++ b/src/qmmp/decoder.cpp @@ -8,6 +8,7 @@ #include <QStringList> #include <QApplication> #include <QSettings> +#include <QIODevice> #include <math.h> #include "effect.h" @@ -26,9 +27,16 @@ extern "C" } #include "decoder.h" -Decoder::~Decoder() +Decoder::Decoder(QIODevice *input) : m_input(input) {} +Decoder::~Decoder() +{ + if(m_input) + m_input->deleteLater(); + m_input = 0; +} + void Decoder::configure(quint32 srate, int chan, int bps) { m_parameters = AudioParameters(srate, chan, bps); @@ -39,6 +47,11 @@ const AudioParameters Decoder::audioParameters() return m_parameters; } +QIODevice *Decoder::input() +{ + return m_input; +} + // static methods QList<DecoderFactory*> *Decoder::m_factories = 0; DecoderFactory *Decoder::m_lastFactory = 0; diff --git a/src/qmmp/decoder.h b/src/qmmp/decoder.h index f121e5083..57cfa7f26 100644 --- a/src/qmmp/decoder.h +++ b/src/qmmp/decoder.h @@ -18,6 +18,7 @@ class Decoder; class DecoderFactory; +class QIODevice; /*! @brief The Decoder class provides the base interface class of audio decoders. * @author Brad Hughes <bhughes@trolltech.com> @@ -27,6 +28,10 @@ class Decoder { public: /*! + * + */ + Decoder(QIODevice *input = 0); + /*! * Destructor. */ virtual ~Decoder(); @@ -57,6 +62,7 @@ public: virtual int bitrate() = 0; const AudioParameters audioParameters(); + QIODevice *input(); /*! * Returns \b true if \b file is supported by input plugins, otherwise returns \b false @@ -133,6 +139,7 @@ private: static DecoderFactory *m_lastFactory; static QStringList m_files; AudioParameters m_parameters; + QIODevice *m_input; }; #endif // DECODER_H diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp index 1e05fe348..f3f35b80c 100644 --- a/src/qmmp/qmmpaudioengine.cpp +++ b/src/qmmp/qmmpaudioengine.cpp @@ -35,7 +35,7 @@ extern "C" } QmmpAudioEngine::QmmpAudioEngine(QObject *parent) - : AbstractEngine(parent), m_factory(0), m_input(0), m_output(0), m_eqInited(FALSE), + : AbstractEngine(parent), m_factory(0), m_output(0), m_eqInited(FALSE), m_useEQ(FALSE) { m_output_buf = new unsigned char[Qmmp::globalBufferSize()]; @@ -47,7 +47,6 @@ QmmpAudioEngine::QmmpAudioEngine(QObject *parent) m_bks = Buffer::size(); m_decoder = 0; m_output = 0; - m_input = 0; m_decoder2 = 0; reset(); } @@ -75,7 +74,7 @@ void QmmpAudioEngine::reset() } -bool QmmpAudioEngine::initialize(QIODevice *input, const QString &source) +bool QmmpAudioEngine::initialize(const QString &source, QIODevice *input) { if(m_decoder && isRunning() && m_output && m_output->isRunning()) { @@ -93,7 +92,7 @@ bool QmmpAudioEngine::initialize(QIODevice *input, const QString &source) m_decoder2 = 0; } else - m_decoder2 = 0; + m_decoder2 = 0; stop(); m_source = source; m_output = Output::create(this); @@ -139,11 +138,6 @@ qint64 QmmpAudioEngine::totalTime() return 0; } -QIODevice *QmmpAudioEngine::input() -{ - return m_input; -} - Output *QmmpAudioEngine::output() { return m_output; @@ -353,16 +347,7 @@ void QmmpAudioEngine::run() qint64 len = 0; mutex()->unlock(); - if (QFile::exists(m_source)) //send metadata for local files - { - QList <FileInfo *> list = m_factory->createPlayList(m_source, TRUE); - if (!list.isEmpty()) - { - StateHandler::instance()->dispatch(list[0]->metaData()); - while (!list.isEmpty()) - delete list.takeFirst(); - } - } + sendMetaData(); while (! m_done && ! m_finish) { @@ -398,21 +383,12 @@ void QmmpAudioEngine::run() delete m_decoder; m_decoder = m_decoder2; emit playbackFinished(); - StateHandler::instance()->dispatch(Qmmp::Stopped); + StateHandler::instance()->dispatch(Qmmp::Stopped); //fake stop/start cycle StateHandler::instance()->dispatch(Qmmp::Buffering); StateHandler::instance()->dispatch(Qmmp::Playing); - m_output->seek(0); + m_output->seek(0); //reset counter mutex()->unlock(); - if (QFile::exists(m_source)) //send metadata for local files - { - QList <FileInfo *> list = m_factory->createPlayList(m_source, TRUE); - if (!list.isEmpty()) - { - StateHandler::instance()->dispatch(list[0]->metaData()); - while (!list.isEmpty()) - delete list.takeFirst(); - } - } + sendMetaData(); continue; } @@ -482,3 +458,17 @@ void QmmpAudioEngine::flush(bool final) output()->recycler()->mutex()->unlock(); } } + +void QmmpAudioEngine::sendMetaData() +{ + if (QFile::exists(m_source)) //send metadata for local files + { + QList <FileInfo *> list = m_factory->createPlayList(m_source, TRUE); + if (!list.isEmpty()) + { + StateHandler::instance()->dispatch(list[0]->metaData()); + while (!list.isEmpty()) + delete list.takeFirst(); + } + } +} diff --git a/src/qmmp/qmmpaudioengine.h b/src/qmmp/qmmpaudioengine.h index 74f4c70eb..1cfed931b 100644 --- a/src/qmmp/qmmpaudioengine.h +++ b/src/qmmp/qmmpaudioengine.h @@ -38,13 +38,12 @@ public: QmmpAudioEngine(QObject *parent); ~QmmpAudioEngine(); - bool initialize(QIODevice *input, const QString &source); + bool initialize(const QString &source, QIODevice *input = 0); qint64 totalTime(); void seek(qint64 time); void stop(); int bitrate(); void pause(); - QIODevice *input(); Output *output(); void setEQ(double bands[10], double preamp); void setEQEnabled(bool on); @@ -52,26 +51,20 @@ public: signals: void playbackFinished(); -protected: - void run(); - - -protected slots: +private slots: void finish(); private: + void run(); void reset(); void flush(bool = FALSE); qint64 produceSound(char *data, qint64 size, quint32 brate, int chan); + void sendMetaData(); DecoderFactory *m_factory; QList <Effect*> m_effects; - QIODevice *m_input; Output *m_output; - QMutex m_mutex; - QWaitCondition m_waitCondition; - uint _blksize; bool m_eqInited; bool m_useEQ; diff --git a/src/qmmp/soundcore.cpp b/src/qmmp/soundcore.cpp index cc48a33f1..6d5135c1c 100644 --- a/src/qmmp/soundcore.cpp +++ b/src/qmmp/soundcore.cpp @@ -135,31 +135,13 @@ bool SoundCore::play(const QString &source, bool queue) return FALSE; } -//bool enqueue(const QString &url); - -void SoundCore::setNextUrl(const QString &source) -{ - /*if(m_decoder) - m_decoder->setNextUrl(source);*/ -} - -void SoundCore::clearNextUrl() -{ - /*if(m_decoder) - m_decoder->clearNextUrl();*/ -} - void SoundCore::stop() { m_factory = 0; m_source.clear(); if(m_engine) m_engine->stop(); - if (m_input) - { - m_input->deleteLater(); - m_input = 0; - } + m_input = 0; //update VolumeControl delete m_volumeControl; m_volumeControl = VolumeControl::create(this); @@ -310,7 +292,7 @@ bool SoundCore::decode() connect(m_engine, SIGNAL(playbackFinished()), SIGNAL(finished())); } - if(m_engine->initialize(m_input, m_source)) + if(m_engine->initialize(m_source, m_input)) m_engine->start(); else return FALSE; diff --git a/src/qmmp/soundcore.h b/src/qmmp/soundcore.h index c15bce69b..b8d103ba9 100644 --- a/src/qmmp/soundcore.h +++ b/src/qmmp/soundcore.h @@ -132,15 +132,6 @@ public slots: */ bool play(const QString &source, bool queue = FALSE); /*! - * Tells decoder about next track. It may be useful for gapless playback. - * @param source Url of the next item in the playlist - */ - void setNextUrl(const QString &source); - /*! - * Removes information about next url - */ - void clearNextUrl(); - /*! * Stops playback */ void stop(); |
