1 /************************************************************************* 2 FlacDecoder.h - decoder for FLAC data 3 ------------------- 4 begin : Tue Feb 28 2004 5 copyright : (C) 2004 by Thomas Eschenbacher 6 email : Thomas.Eschenbacher@gmx.de 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #ifndef FLAC_DECODER_H 19 #define FLAC_DECODER_H 20 21 #include "config.h" 22 23 #include <QList> 24 #include <QMap> 25 #include <QObject> 26 #include <QString> 27 #include <QStringList> 28 29 #include <FLAC++/decoder.h> 30 #include <FLAC++/metadata.h> 31 #include <FLAC/format.h> 32 33 #include "libkwave/Decoder.h" 34 #include "libkwave/FileInfo.h" 35 #include "libkwave/VorbisCommentMap.h" 36 37 class QWidget; 38 class QIODevice; 39 40 namespace Kwave 41 { 42 class FlacDecoder: public Kwave::Decoder, 43 protected FLAC::Decoder::Stream 44 { 45 public: 46 /** Constructor */ 47 FlacDecoder(); 48 49 /** Destructor */ 50 virtual ~FlacDecoder() Q_DECL_OVERRIDE; 51 52 /** Returns a new instance of the decoder */ 53 virtual Kwave::Decoder *instance() Q_DECL_OVERRIDE; 54 55 /** 56 * Opens the source and decodes the header information. 57 * @param widget a widget that can be used for displaying 58 * message boxes or dialogs 59 * @param source file or other source with a stream of bytes 60 * @return true if succeeded, false on errors 61 */ 62 virtual bool open(QWidget *widget, QIODevice &source) Q_DECL_OVERRIDE; 63 64 /** 65 * Decodes a stream of bytes into a MultiWriter 66 * @param widget a widget that can be used for displaying 67 * message boxes or dialogs 68 * @param dst MultiWriter that receives the audio data 69 * @return true if succeeded, false on errors 70 */ 71 virtual bool decode(QWidget *widget, Kwave::MultiWriter &dst) 72 Q_DECL_OVERRIDE; 73 74 /** 75 * Closes the source. 76 */ 77 virtual void close() Q_DECL_OVERRIDE; 78 79 protected: 80 81 /** 82 * Parse information about the stream, like sample rate, resolution, 83 * channels etc... 84 * 85 * @param stream_info FLAC metadata with stream information 86 */ 87 void parseStreamInfo(const FLAC::Metadata::StreamInfo &stream_info); 88 89 /** 90 * Parse vorbis comments 91 * 92 * @param vorbis_comments list of vorbis comments, can be empty 93 */ 94 void parseVorbisComments( 95 const FLAC::Metadata::VorbisComment &vorbis_comments); 96 97 /** 98 * FLAC decoder interface: read callback. 99 * 100 * @param buffer the byte buffer to be filled 101 * @param bytes pointer with the number of bytes to be read, 102 * can be modified 103 * @return read state 104 */ 105 virtual ::FLAC__StreamDecoderReadStatus read_callback( 106 FLAC__byte buffer[], size_t *bytes) Q_DECL_OVERRIDE; 107 108 /** 109 * FLAC decoder interface: write callback. 110 * 111 * @param frame a FLAC frame structure 112 * @param buffer a buffer that contains the decoded samples 113 * @return FLAC stream decoder write state 114 */ 115 virtual ::FLAC__StreamDecoderWriteStatus write_callback( 116 const ::FLAC__Frame *frame, 117 const FLAC__int32 *const buffer[]) Q_DECL_OVERRIDE; 118 119 /** 120 * FLAC decoder interface: callback for processing meta data. 121 * 122 * @param metadata the FLAC meta data to be parsed 123 */ 124 virtual void metadata_callback(const ::FLAC__StreamMetadata *metadata) 125 Q_DECL_OVERRIDE; 126 127 /** 128 * FLAC decoder interface: error callback. 129 * 130 * @param status the FLAC status 131 */ 132 virtual void error_callback(::FLAC__StreamDecoderErrorStatus status) 133 Q_DECL_OVERRIDE; 134 135 private: 136 137 /** source of the audio data */ 138 QIODevice *m_source; 139 140 /** destination of the audio data */ 141 Kwave::MultiWriter *m_dest; 142 143 /** map for translating vorbis comments to FileInfo properties */ 144 Kwave::VorbisCommentMap m_vorbis_comment_map; 145 146 }; 147 } 148 149 #endif /* FLAC_DECODER_H */ 150 151 //*************************************************************************** 152 //*************************************************************************** 153