aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2016-07-19 07:22:43 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2016-07-19 07:22:43 +0000
commit5cc2fd08ae492ac9eba82675326475f88e40d8d2 (patch)
treec0aca10334764ba1c9a2befe0f8fdbc40546bf11 /src
parentf7426acabe8ab4f89783bbc042e1724a56dce917 (diff)
downloadqmmp-5cc2fd08ae492ac9eba82675326475f88e40d8d2.tar.gz
qmmp-5cc2fd08ae492ac9eba82675326475f88e40d8d2.tar.bz2
qmmp-5cc2fd08ae492ac9eba82675326475f88e40d8d2.zip
sndfile plugin: using QIODevice-based input
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@6581 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src')
-rw-r--r--src/plugins/Input/sndfile/decoder_sndfile.cpp73
-rw-r--r--src/plugins/Input/sndfile/decoder_sndfile.h4
-rw-r--r--src/plugins/Input/sndfile/decodersndfilefactory.cpp11
3 files changed, 68 insertions, 20 deletions
diff --git a/src/plugins/Input/sndfile/decoder_sndfile.cpp b/src/plugins/Input/sndfile/decoder_sndfile.cpp
index 4a6b9ab19..182e809d8 100644
--- a/src/plugins/Input/sndfile/decoder_sndfile.cpp
+++ b/src/plugins/Input/sndfile/decoder_sndfile.cpp
@@ -25,12 +25,58 @@
#include <qmmp/output.h>
#include "decoder_sndfile.h"
+// Callbacks
+
+sf_count_t sndfile_sf_vio_get_filelen(void *data)
+{
+ return ((QIODevice*) data)->size();
+}
+
+sf_count_t sndfile_sf_vio_seek(sf_count_t offset, int whence, void *data)
+{
+ QIODevice *input = (QIODevice *)data;
+ if(input->isSequential())
+ return -1;
+
+ qint64 start = 0;
+ switch (whence)
+ {
+ case SEEK_END:
+ start = input->size();
+ break;
+ case SEEK_CUR:
+ start = input->pos();
+ break;
+ case SEEK_SET:
+ default:
+ start = 0;
+ }
+
+ if(input->seek(start + offset))
+ return start + offset;
+ return -1;
+}
+
+sf_count_t sndfile_sf_vio_read(void *ptr, sf_count_t count, void *data)
+{
+ return ((QIODevice*) data)->read((char *)ptr, count);
+}
+
+sf_count_t sndfile_sf_vio_write(const void *, sf_count_t, void *)
+{
+ return -1;
+}
+
+sf_count_t sndfile_sf_vio_tell(void *data)
+{
+ return ((QIODevice*) data)->pos();
+}
+
// Decoder class
-DecoderSndFile::DecoderSndFile(const QString &path)
- : Decoder()
+DecoderSndFile::DecoderSndFile(QIODevice *input) : Decoder(input)
{
- m_path = path;
+ //m_path = input;
m_bitrate = 0;
m_totalTime = 0;
m_sndfile = 0;
@@ -49,22 +95,27 @@ bool DecoderSndFile::initialize()
SF_INFO snd_info;
memset (&snd_info, 0, sizeof(snd_info));
- snd_info.format=0;
-#ifdef Q_OS_WIN
- m_sndfile = sf_wchar_open(reinterpret_cast<LPCWSTR>(m_path.utf16()), SFM_READ, &snd_info);
-#else
- m_sndfile = sf_open(m_path.toLocal8Bit().constData(), SFM_READ, &snd_info);
-#endif
+ snd_info.format = 0;
+
+ //setup callbacks
+ m_vio.get_filelen = sndfile_sf_vio_get_filelen;
+ m_vio.seek = sndfile_sf_vio_seek;
+ m_vio.read = sndfile_sf_vio_read;
+ m_vio.write = sndfile_sf_vio_write;
+ m_vio.tell = sndfile_sf_vio_tell;
+
+ m_sndfile = sf_open_virtual(&m_vio, SFM_READ, &snd_info, input());
+
if (!m_sndfile)
{
- qWarning("DecoderSndFile: failed to open: %s", qPrintable(m_path));
+ qWarning("DecoderSndFile: unable to open");
return false;
}
m_freq = snd_info.samplerate;
int chan = snd_info.channels;
m_totalTime = snd_info.frames * 1000 / m_freq;
- m_bitrate = QFileInfo(m_path).size () * 8.0 / m_totalTime + 0.5;
+ m_bitrate = input()->size () * 8.0 / m_totalTime + 0.5;
if((snd_info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_FLOAT)
sf_command (m_sndfile, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
diff --git a/src/plugins/Input/sndfile/decoder_sndfile.h b/src/plugins/Input/sndfile/decoder_sndfile.h
index 1d3811971..b1a7459cd 100644
--- a/src/plugins/Input/sndfile/decoder_sndfile.h
+++ b/src/plugins/Input/sndfile/decoder_sndfile.h
@@ -32,7 +32,7 @@
class DecoderSndFile : public Decoder
{
public:
- DecoderSndFile(const QString &path);
+ DecoderSndFile(QIODevice *input);
virtual ~DecoderSndFile();
// Standard Decoder API
@@ -51,7 +51,7 @@ private:
int m_bitrate;
quint32 m_freq;
qint64 m_totalTime;
- QString m_path;
+ SF_VIRTUAL_IO m_vio;
};
diff --git a/src/plugins/Input/sndfile/decodersndfilefactory.cpp b/src/plugins/Input/sndfile/decodersndfilefactory.cpp
index bf062aa55..90cb00711 100644
--- a/src/plugins/Input/sndfile/decodersndfilefactory.cpp
+++ b/src/plugins/Input/sndfile/decodersndfilefactory.cpp
@@ -29,14 +29,12 @@
#include "decoder_sndfile.h"
#include "decodersndfilefactory.h"
-
// DecoderSndFileFactory
-
bool DecoderSndFileFactory::supports(const QString &source) const
{
if (source.endsWith(".wav", Qt::CaseInsensitive))
{
- //try top open the file
+ //try to open the file
SF_INFO snd_info;
#ifdef Q_OS_WIN
SNDFILE *sndfile = sf_wchar_open(reinterpret_cast<LPCWSTR>(source.utf16()), SFM_READ, &snd_info);
@@ -75,14 +73,13 @@ const DecoderProperties DecoderSndFileFactory::properties() const
properties.shortName = "sndfile";
properties.hasAbout = true;
properties.hasSettings = false;
- properties.noInput = true;
- properties.protocols << "file";
+ properties.noInput = false;
return properties;
}
-Decoder *DecoderSndFileFactory::create(const QString &path, QIODevice *)
+Decoder *DecoderSndFileFactory::create(const QString &path, QIODevice *input)
{
- return new DecoderSndFile(path);
+ return new DecoderSndFile(input);
}
QList<FileInfo *> DecoderSndFileFactory::createPlayList(const QString &fileName, bool useMetaData, QStringList *)