File indexing completed on 2024-12-08 07:26:07

0001 /*
0002 
0003     SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "k3bmpcdecoder.h"
0009 #include "k3bmpcwrapper.h"
0010 #include "k3bplugin_i18n.h"
0011 
0012 #include <config-k3b.h>
0013 
0014 K_PLUGIN_CLASS_WITH_JSON(K3bMpcDecoderFactory, "k3bmpcdecoder.json")
0015 
0016 K3bMpcDecoderFactory::K3bMpcDecoderFactory( QObject* parent, const QVariantList& )
0017     : K3b::AudioDecoderFactory( parent )
0018 {
0019 }
0020 
0021 
0022 K3bMpcDecoderFactory::~K3bMpcDecoderFactory()
0023 {
0024 }
0025 
0026 
0027 K3b::AudioDecoder* K3bMpcDecoderFactory::createDecoder( QObject* parent
0028     ) const
0029 {
0030     return new K3bMpcDecoder( parent );
0031 }
0032 
0033 
0034 bool K3bMpcDecoderFactory::canDecode( const QUrl& url )
0035 {
0036     K3bMpcWrapper w;
0037     return w.open( url.toLocalFile() );
0038 }
0039 
0040 
0041 
0042 
0043 
0044 
0045 K3bMpcDecoder::K3bMpcDecoder( QObject* parent  )
0046     : K3b::AudioDecoder( parent )
0047 {
0048     m_mpc = new K3bMpcWrapper();
0049 }
0050 
0051 
0052 K3bMpcDecoder::~K3bMpcDecoder()
0053 {
0054     delete m_mpc;
0055 }
0056 
0057 
0058 QString K3bMpcDecoder::fileType() const
0059 {
0060     return i18n("Musepack");
0061 }
0062 
0063 
0064 bool K3bMpcDecoder::analyseFileInternal( K3b::Msf& frames, int& samplerate, int& ch )
0065 {
0066     if( m_mpc->open( filename() ) ) {
0067         frames = m_mpc->length();
0068         samplerate = m_mpc->samplerate();
0069         ch = m_mpc->channels();
0070 
0071         // call addTechnicalInfo and addMetaInfo here
0072 
0073         return true;
0074     }
0075     else
0076         return false;
0077 }
0078 
0079 
0080 bool K3bMpcDecoder::initDecoderInternal()
0081 {
0082     return m_mpc->open( filename() );
0083 }
0084 
0085 
0086 bool K3bMpcDecoder::seekInternal( const K3b::Msf& msf )
0087 {
0088     return m_mpc->seek( msf );
0089 }
0090 
0091 
0092 int K3bMpcDecoder::decodeInternal( char* _data, int maxLen )
0093 {
0094     return m_mpc->decode( _data, maxLen );
0095 }
0096 
0097 
0098 #include "k3bmpcdecoder.moc"
0099 
0100 #include "moc_k3bmpcdecoder.cpp"