aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Input
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-07-15 16:08:15 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2009-07-15 16:08:15 +0000
commit6247dd72364b35e986e2cef0c7ad543af82763be (patch)
tree545c39b4cea36f3b3078a390d541bb55c11722c1 /src/plugins/Input
parentdb0834220d3c3e11c77d24de356cdd975343442d (diff)
downloadqmmp-6247dd72364b35e986e2cef0c7ad543af82763be.tar.gz
qmmp-6247dd72364b35e986e2cef0c7ad543af82763be.tar.bz2
qmmp-6247dd72364b35e986e2cef0c7ad543af82763be.zip
enabled flac plugin
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@1038 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Input')
-rw-r--r--src/plugins/Input/CMakeLists.txt2
-rw-r--r--src/plugins/Input/Input.pro2
-rw-r--r--src/plugins/Input/cue/decoder_cue.cpp11
-rw-r--r--src/plugins/Input/flac/cueparser.cpp6
-rw-r--r--src/plugins/Input/flac/decoder_flac.cpp198
-rw-r--r--src/plugins/Input/flac/decoder_flac.h26
6 files changed, 37 insertions, 208 deletions
diff --git a/src/plugins/Input/CMakeLists.txt b/src/plugins/Input/CMakeLists.txt
index dbc902087..7d8e4ad65 100644
--- a/src/plugins/Input/CMakeLists.txt
+++ b/src/plugins/Input/CMakeLists.txt
@@ -21,7 +21,7 @@ add_subdirectory(mad)
ENDIF(USE_MAD AND TAGLIB_FOUND)
IF(USE_FLAC AND TAGLIB_FOUND)
-#add_subdirectory(flac)
+add_subdirectory(flac)
ENDIF(USE_FLAC AND TAGLIB_FOUND)
IF(USE_VORBIS AND TAGLIB_FOUND)
diff --git a/src/plugins/Input/Input.pro b/src/plugins/Input/Input.pro
index 4678d29dd..dd13c80d7 100644
--- a/src/plugins/Input/Input.pro
+++ b/src/plugins/Input/Input.pro
@@ -20,7 +20,7 @@ contains(CONFIG, MUSEPACK_PLUGIN){
}
contains(CONFIG, FLAC_PLUGIN){
- #SUBDIRS += flac
+ SUBDIRS += flac
message(***********************)
message(* FLAC plugin enabled *)
message(***********************)
diff --git a/src/plugins/Input/cue/decoder_cue.cpp b/src/plugins/Input/cue/decoder_cue.cpp
index 6064025e6..b9da9a6df 100644
--- a/src/plugins/Input/cue/decoder_cue.cpp
+++ b/src/plugins/Input/cue/decoder_cue.cpp
@@ -260,20 +260,18 @@ void DecoderCUE::proccessFinish()
{
if(nextUrlRequest(m_nextUrl))
{
- qDebug("DecoderCUE: using next url");
+ qDebug("DecoderCUE: going to next track");
int track = m_nextUrl.section("#", -1).toInt();
- qDebug("==%d", track);
QString p = QUrl(m_nextUrl).path();
p.replace(QString(QUrl::toPercentEncoding("#")), "#");
p.replace(QString(QUrl::toPercentEncoding("%")), "%");
- //update decoder's fragment
+ //update current fragment
CUEParser parser(p);
m_length = parser.length(track);
m_offset = parser.offset(track);
m_decoder->mutex()->lock();
- qDebug("%lld == %lld", m_offset, m_length);
m_decoder->setFragment(m_offset, m_length);
- m_output2->seek(0);
+ m_output2->seek(0); //reset time counter
m_decoder->mutex()->unlock();
// find next track
if(track <= parser.count() - 1)
@@ -284,7 +282,8 @@ void DecoderCUE::proccessFinish()
if(QUrl(m_nextUrl).path() != p)
m_nextUrl.clear();
//change track
- emit playbackFinished();
+ finish();
+ //send metadata
QMap<Qmmp::MetaData, QString> metaData = parser.info(track)->metaData();
stateHandler()->dispatch(metaData);
}
diff --git a/src/plugins/Input/flac/cueparser.cpp b/src/plugins/Input/flac/cueparser.cpp
index bedaadd52..f2582cbec 100644
--- a/src/plugins/Input/flac/cueparser.cpp
+++ b/src/plugins/Input/flac/cueparser.cpp
@@ -69,10 +69,10 @@ CUEParser::CUEParser(const QByteArray &array, const QString &fileName)
}
else if (words[0] == "INDEX")
{
- if (m_infoList.isEmpty())
+ if (m_infoList.isEmpty() || words[1] != "01")
continue;
- m_infoList.last ().setLength(getLength(words[2]));
- m_offsets.last() = getLength(words[2]);
+ m_infoList.last ().setLength(getLength(words[2]));
+ m_offsets.last() = getLength(words[2]);
}
else if (words[0] == "REM")
{
diff --git a/src/plugins/Input/flac/decoder_flac.cpp b/src/plugins/Input/flac/decoder_flac.cpp
index 372635511..3ec7b3c5c 100644
--- a/src/plugins/Input/flac/decoder_flac.cpp
+++ b/src/plugins/Input/flac/decoder_flac.cpp
@@ -29,7 +29,6 @@
#include <taglib/xiphcomment.h>
#include <taglib/tmap.h>
-#include <qmmp/constants.h>
#include <qmmp/buffer.h>
#include <qmmp/output.h>
#include <qmmp/recycler.h>
@@ -261,21 +260,6 @@ DecoderFLAC::DecoderFLAC(QObject *parent, DecoderFactory *d, QIODevice *i, Outpu
: Decoder(parent, d, i, o)
{
inited = FALSE;
- user_stop = FALSE;
- stat = 0;
- output_buf = 0;
- output_bytes = 0;
- output_at = 0;
- bks = 0;
- done = FALSE;
- m_finish = FALSE;
- len = 0;
- freq = 0;
- bitrate = 0;
- seekTime = -1.0;
- m_totalTime = 0.0;
- chan = 0;
- output_size = 0;
m_data = 0;
m_path = path;
@@ -297,69 +281,11 @@ DecoderFLAC::~DecoderFLAC()
delete data();
m_data = 0;
}
-
- if (output_buf)
- delete [] output_buf;
- output_buf = 0;
-}
-
-
-void DecoderFLAC::stop()
-{
- user_stop = TRUE;
}
-
-void DecoderFLAC::flush(bool final)
-{
- //qDebug("DecoderFLAC: flush()");
- ulong min = final ? 0 : bks;
-
- while ((! done && ! m_finish) && output_bytes > min)
- {
- output()->recycler()->mutex()->lock();
-
- while ((! done && ! m_finish) && output()->recycler()->full())
- {
- mutex()->unlock();
-
- output()->recycler()->cond()->wait(output()->recycler()->mutex());
-
- mutex()->lock();
- done = user_stop;
- }
-
- if (user_stop || m_finish)
- {
- inited = FALSE;
- done = TRUE;
- }
- else
- {
- output_bytes -= produceSound(output_buf, output_bytes, bitrate, chan);
- output_size += bks;
- output_at = output_bytes;
- }
-
- if (output()->recycler()->full())
- {
- output()->recycler()->cond()->wakeOne();
- }
-
- output()->recycler()->mutex()->unlock();
- }
-}
-
-
bool DecoderFLAC::initialize()
{
- bks = Buffer::size();
- inited = user_stop = done = m_finish = FALSE;
- len = freq = bitrate = 0;
- stat = chan = 0;
- output_size = 0;
- seekTime = -1.0;
- m_totalTime = 0.0;
+ inited = FALSE;
if (!data()->input)
{
@@ -403,11 +329,6 @@ bool DecoderFLAC::initialize()
}
}
- if (! output_buf)
- output_buf = new char[globalBufferSize];
- output_at = 0;
- output_bytes = 0;
-
if (!data()->input->isOpen())
{
if (!data()->input->open(QIODevice::ReadOnly))
@@ -416,12 +337,6 @@ bool DecoderFLAC::initialize()
}
}
-
- if (! output_buf)
- output_buf = new char[globalBufferSize];
- output_at = 0;
- output_bytes = 0;
-
if (! data()->input->isOpen())
{
if (! data()->input->open(QIODevice::ReadOnly))
@@ -461,7 +376,6 @@ bool DecoderFLAC::initialize()
data()->ok = 0;
return FALSE;
}
- chan = data()->channels;
if (data()->bits_per_sample == 24)
configure(data()->sample_rate, data()->channels, 32);
else
@@ -469,15 +383,17 @@ bool DecoderFLAC::initialize()
m_totalTime = data()->length;
inited = TRUE;
- if (m_offset)
- seekTime = m_offset;
+ /*if (m_offset)
+ seekTime = m_offset;*/
if (m_length)
+ {
m_totalTime = m_length;
+ setFragment(m_offset, m_length);
+ }
qDebug("DecoderFLAC: initialize succes");
return TRUE;
}
-
qint64 DecoderFLAC::totalTime()
{
if (! inited)
@@ -486,22 +402,29 @@ qint64 DecoderFLAC::totalTime()
return m_totalTime;
}
+int DecoderFLAC::bitrate()
+{
+ return data()->bitrate;
+}
-void DecoderFLAC::seek(qint64 pos)
+void DecoderFLAC::seekAudio(qint64 time)
{
- if (m_totalTime > 0)
- seekTime = pos + m_offset;
+ FLAC__uint64 target_sample;
+ target_sample = (FLAC__uint64)((time/(double)data()->length) * (double)data()->total_samples);
+ FLAC__stream_decoder_seek_absolute(data()->decoder, target_sample);
}
+qint64 DecoderFLAC::readAudio(char *data, qint64 maxSize)
+{
+ return flac_decode (this, (char *) (data), maxSize);
+}
void DecoderFLAC::deinit()
{
if (data())
FLAC__stream_decoder_finish (data()->decoder);
- inited = user_stop = done = m_finish = FALSE;
- len = freq = bitrate = 0;
- stat = chan = 0;
- output_size = 0;
+ inited = FALSE;
+
if (!input() && data()->input) //delete internal input only
{
data()->input->close();
@@ -509,84 +432,3 @@ void DecoderFLAC::deinit()
data()->input = 0;
};
}
-
-void DecoderFLAC::run()
-{
- mutex()->lock ();
-
- if (!inited)
- {
- mutex()->unlock();
- return;
- }
- mutex()->unlock();
-
- while (!done && !m_finish)
- {
- mutex()->lock ();
- // decode
-
- if (seekTime >= 0.0)
- {
- FLAC__uint64 target_sample;
-
- target_sample = (FLAC__uint64)((seekTime/(double)data()->length) *
- (double)data()->total_samples);
-
- FLAC__stream_decoder_seek_absolute(data()->decoder,
- target_sample);
- seekTime = -1.0;
- }
- len = flac_decode (this, (char *) (output_buf + output_at), bks);
-
- if (len > 0)
- {
- bitrate = data()->bitrate;
- output_at += len;
- output_bytes += len;
-
- if (output())
- flush();
-
- }
- else if (len == 0)
- {
- flush(TRUE);
-
- if (output())
- {
- output()->recycler()->mutex()->lock ();
- // end of stream
- while (! output()->recycler()->empty() && ! user_stop)
- {
- output()->recycler()->cond()->wakeOne();
- mutex()->unlock();
- output()->recycler()->cond()->wait(output()->recycler()->mutex());
- mutex()->lock ();
- }
- output()->recycler()->mutex()->unlock();
- }
-
- done = TRUE;
- m_finish = !user_stop;
- }
- else
- {
- // error while read
- qWarning("DecoderFLAC: Error while decoding stream, File appears to be "
- "corrupted");
- m_finish = TRUE;
- }
- if (m_length && (StateHandler::instance()->elapsed() >= m_length))
- m_finish = TRUE;
- mutex()->unlock();
- }
-
- mutex()->lock ();
-
- if (m_finish)
- finish();
-
- mutex()->unlock();
- deinit();
-}
diff --git a/src/plugins/Input/flac/decoder_flac.h b/src/plugins/Input/flac/decoder_flac.h
index e6036232e..75f0d84cf 100644
--- a/src/plugins/Input/flac/decoder_flac.h
+++ b/src/plugins/Input/flac/decoder_flac.h
@@ -65,8 +65,7 @@ public:
// Standard Decoder API
bool initialize();
qint64 totalTime();
- void seek(qint64);
- void stop();
+ int bitrate();
struct flac_data *data()
{
@@ -75,33 +74,22 @@ public:
private:
- // thread run function
- void run();
+ // Standard Decoder API
+ qint64 readAudio(char *data, qint64 maxSize);
+ void seekAudio(qint64 time);
+
struct flac_data *m_data;
// helper functions
- void flush(bool = FALSE);
void deinit();
- bool inited, user_stop;
- int stat;
-
- // output buffer
- char *output_buf;
- ulong output_bytes, output_at;
-
// FLAC Decoder
- //FLAC__SeekableStreamDecoder *m_flacDecoder;
FLAC__StreamDecoder *m_flacDecoder;
- unsigned int bks;
- bool done, m_finish;
- long len, freq, bitrate;
- int chan;
- unsigned long output_size;
- double m_totalTime, seekTime;
+ qint64 m_totalTime;
QString m_path;
qint64 m_offset;
qint64 m_length;
+ bool inited;
};