File indexing completed on 2024-05-05 04:48:35
0001 /**************************************************************************************** 0002 * Copyright (c) 2010 Sergey Ivanov <123kash@gmail.com> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef MUSICDNSAUDIODECODER_H 0018 #define MUSICDNSAUDIODECODER_H 0019 0020 #include "core/meta/forward_declarations.h" 0021 0022 #include <ThreadWeaver/Job> 0023 0024 #define DEFAULT_SAMPLE_LENGTH 135000 0025 #define MIN_SAMPLE_LENGTH 10000 0026 0027 class DecodedAudioData 0028 { 0029 public: 0030 DecodedAudioData(); 0031 ~DecodedAudioData(); 0032 0033 int sRate(); 0034 void setSampleRate( const int sampleRate ); 0035 0036 quint8 channels(); 0037 void setChannels( const quint8 channels ); 0038 0039 int length(); 0040 qint64 duration(); 0041 void addTime( const qint64 ms ); 0042 0043 const char *data(); 0044 0045 void appendData( const quint8 *data, int length ); 0046 DecodedAudioData &operator<< ( const quint8 &byte ); 0047 0048 void flush(); 0049 0050 private: 0051 int m_sRate; 0052 quint8 m_channels; 0053 qint64 m_duration; 0054 0055 QByteArray *m_data; 0056 }; 0057 0058 class MusicDNSAudioDecoder : public QObject, public ThreadWeaver::Job 0059 { 0060 Q_OBJECT 0061 public: 0062 explicit MusicDNSAudioDecoder( const Meta::TrackList &tracks, const int sampleLength = DEFAULT_SAMPLE_LENGTH ); 0063 ~MusicDNSAudioDecoder() override; 0064 0065 void run(ThreadWeaver::JobPointer self = QSharedPointer<ThreadWeaver::Job>(), ThreadWeaver::Thread *thread = nullptr) override; 0066 0067 Q_SIGNALS: 0068 void trackDecoded( const Meta::TrackPtr, const QString ); 0069 0070 /** This signal is emitted when this job is being processed by a thread. */ 0071 void started(ThreadWeaver::JobPointer); 0072 /** This signal is emitted when the job has been finished (no matter if it succeeded or not). */ 0073 void done(ThreadWeaver::JobPointer); 0074 /** This job has failed. 0075 * This signal is emitted when success() returns false after the job is executed. */ 0076 void failed(ThreadWeaver::JobPointer); 0077 0078 private: 0079 int decode( const QString &fileName, DecodedAudioData *data, const int length ); 0080 0081 Meta::TrackList m_tracks; 0082 int m_sampleLength; 0083 0084 protected: 0085 void defaultBegin(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override; 0086 void defaultEnd(const ThreadWeaver::JobPointer& job, ThreadWeaver::Thread *thread) override; 0087 0088 }; 0089 0090 #endif // MUSICDNSAUDIODECODER_H