1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*************************************************************************
MP3Decoder.h - decoder for MP3 data
-------------------
begin : Wed Aug 07 2002
copyright : (C) 2002 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef MP3_DECODER_H
#define MP3_DECODER_H
#include "config.h"
#include <mad.h> // needs libmad-devel package
#include <id3/globals.h>
#include <QString>
#include "libkwave/Decoder.h"
#include "libkwave/FileInfo.h"
#include "ID3_PropertyMap.h"
class ID3_Frame;
class ID3_Tag;
class QWidget;
namespace Kwave
{
class MP3Decoder: public Kwave::Decoder
{
public:
/** Constructor */
MP3Decoder();
/** Destructor */
~MP3Decoder() override;
/** Returns a new instance of the decoder */
Kwave::Decoder *instance() override;
/**
* Opens the source and decodes the header information.
* @param widget a widget that can be used for displaying
* message boxes or dialogs
* @param source file or other source with a stream of bytes
* @return true if succeeded, false on errors
*/
bool open(QWidget *widget, QIODevice &source) override;
/**
* Decodes a stream of bytes into a MultiWriter
* @param widget a widget that can be used for displaying
* message boxes or dialogs
* @param dst MultiWriter that receives the audio data
* @return true if succeeded, false on errors
*/
virtual bool decode(QWidget *widget, Kwave::MultiWriter &dst)
override;
/**
* Closes the source.
*/
void close() override;
/** Callback for filling libmad's input buffer */
enum mad_flow fillInput(struct mad_stream *stream);
/** Calback for processing libmad's output */
enum mad_flow processOutput(void *data,
struct mad_header const *header,
struct mad_pcm *pcm);
/** Callback for handling stream errors */
enum mad_flow handleError(void *data, struct mad_stream *stream,
struct mad_frame *frame);
private:
/** parse MP3 headers */
bool parseMp3Header(const Mp3_Headerinfo &header, QWidget *widget);
/** parse all known ID3 tags */
bool parseID3Tags(ID3_Tag &tag);
/**
* parse a ID3 frame into a string
* @param frame a ID3 frame
* @return QString with the content
*/
QString parseId3Frame2String(const ID3_Frame *frame);
private:
/** property - to - ID3 mapping */
ID3_PropertyMap m_property_map;
/** source of the raw mp3 data */
QIODevice *m_source;
/** destination of the audio data */
Kwave::MultiWriter *m_dest;
/** buffer for libmad */
unsigned char *m_buffer;
/** size of m_buffer in bytes */
int m_buffer_size;
/** number of prepended bytes / id3v2 tag */
size_t m_prepended_bytes;
/** number of appended bytes / id3v1 tag */
size_t m_appended_bytes;
/** number of failures */
unsigned int m_failures;
/** widget used for displaying error messages */
QWidget *m_parent_widget;
};
}
#endif /* MP3_DECODER_H */
//***************************************************************************
//***************************************************************************
|