defuze.me
Client
|
00001 /************************************************************************** 00002 ** defuze.me Epitech Innovative Project 00003 ** 00004 ** Copyright 2010-2011 00005 ** Athena Calmettes - Jocelyn De La Rosa - Francois Gaillard 00006 ** Adrien Jarthon - Alexandre Moore - Luc Peres - Arnaud Sellier 00007 ** 00008 ** All rights reserved. 00009 **************************************************************************/ 00010 00011 #ifndef AUDIODECODER_HPP 00012 #define AUDIODECODER_HPP 00013 00014 #include <QIODevice> 00015 #include <QFile> 00016 #include <QAudioOutput> 00017 #include <QObject> 00018 #include <QTimer> 00019 #include <QAudioDeviceInfo> 00020 #include <QBuffer> 00021 #include <QMutex> 00022 00023 #include "ffmpeg.hpp" 00024 #include "audiocore.hpp" 00025 #include "audioio.hpp" 00026 00027 namespace Player 00028 { 00029 class AudioPlayer; 00030 } 00031 namespace Audio 00032 { 00033 class AudioCore; 00034 00035 enum FileFormat 00036 { 00037 FormatNoAudio = -1, 00038 FormatMP3, 00039 FormatWMA, 00040 FormatOGG, 00041 FormatWAV, 00042 FormatFLAC, 00043 FormatAAC, 00044 FormatUnknown 00045 }; 00046 00052 class AudioDecoder : public QObject 00053 { 00054 friend AudioDecoder* AudioCore::newAudioDecoder(QString playerName); 00055 00056 Q_OBJECT 00057 public: 00058 enum DecoderState 00059 { 00060 BadFormat = -2, 00061 NoFile = -1, 00062 Iddle, 00063 Decoding, 00064 Stopped 00065 }; 00066 00067 ~AudioDecoder(); 00068 00069 void openFile(QString path); 00070 void closeFile(); 00071 00072 void start(); 00073 void stop(); 00074 00075 void setPlayingPosition(quint64 position); 00076 qint64 getPlayingPosition() const; 00077 QAudioFormat& getFormat(); 00078 int bytesToSeconds(int bytes) const; 00079 00080 int duration() const; 00081 DecoderState state() const; 00082 bool isInit() const; 00083 00084 static FileFormat getFileFormat(const QString& path); 00085 void run(); 00086 00087 qint64 bytesAvailable() const; 00088 00089 void setPlayer(const Player::AudioPlayer* player); 00090 bool isPlayerPlaying() const; 00091 qint64 readDecodedFrame(char *data, qint64 maxlen); 00092 signals: 00093 void decodingFinished(); 00094 00095 private: 00096 AudioDecoder(QString, AudioCore *audioCore); 00097 00098 QAudioFormat format; 00099 AudioCore *_audioCore; 00100 00101 AVFormatContext *aFormatCtx; 00102 int audioStream; 00103 AVCodecContext *aCodecCtx; 00104 AVCodec *aCodec; 00105 AVPacket packet; 00106 short *audioBuf; 00107 int out_size; 00108 00109 bool init; 00110 DecoderState _state; 00111 qint64 playingPosition; 00112 qint64 decodingPosition; 00113 QBuffer decodedBuffer; 00114 QMutex mutex; 00115 00116 const Player::AudioPlayer* _player; 00117 00118 void initCodec(); 00119 void initVars(); 00120 void setFormat(); 00121 void decodeFrame(); 00122 }; 00123 } 00124 00125 #endif // AUDIODECODER_HPP