kwave
18.07.70
|
#include <RIFFParser.h>
Public Slots | |
void | cancel () |
Signals | |
void | action (const QString &name) |
void | progress (int percent) |
Public Member Functions | |
RIFFParser (QIODevice &device, const QStringList &main_chunks, const QStringList &known_subchunks) | |
virtual | ~RIFFParser () |
bool | parse () |
bool | parse (Kwave::RIFFChunk *parent, quint32 offset, quint32 length) |
bool | isSane () |
void | dumpStructure () |
Kwave::RIFFChunk * | findChunk (const QByteArray &path) |
unsigned int | chunkCount (const QByteArray &path) |
Kwave::RIFFChunk * | findMissingChunk (const QByteArray &name) |
void | repair () |
Protected Member Functions | |
QByteArray | read4ByteString (qint64 offset) |
Kwave::RIFFChunk::ChunkType | guessType (const QByteArray &name) |
bool | isValidName (const char *name) |
bool | isKnownName (const QByteArray &name) |
void | detectEndianness () |
Kwave::RIFFChunk * | addChunk (Kwave::RIFFChunk *parent, const QByteArray &name, const QByteArray &format, quint32 length, quint32 phys_offset, quint32 phys_length, Kwave::RIFFChunk::ChunkType type) |
bool | addGarbageChunk (Kwave::RIFFChunk *parent, quint32 offset, quint32 length) |
bool | addEmptyChunk (Kwave::RIFFChunk *parent, const QByteArray &name, quint32 offset) |
void | listAllChunks (Kwave::RIFFChunk &parent, Kwave::RIFFChunkList &list) |
Kwave::RIFFChunk * | chunkAt (quint32 offset) |
QList< quint32 > | scanForName (const QByteArray &name, quint32 offset, quint32 length, int progress_start=0, int progress_count=1) |
Private Member Functions | |
void | collectGarbage () |
bool | joinGarbageToEmpty () |
void | fixGarbageEnds () |
void | discardGarbage (Kwave::RIFFChunk &chunk) |
Private Attributes | |
QIODevice & | m_dev |
Kwave::RIFFChunk | m_root |
QStringList | m_main_chunk_names |
QStringList | m_sub_chunk_names |
Kwave::byte_order_t | m_endianness |
bool | m_cancel |
Definition at line 38 of file RIFFParser.h.
Kwave::RIFFParser::RIFFParser | ( | QIODevice & | device, |
const QStringList & | main_chunks, | ||
const QStringList & | known_subchunks | ||
) |
Constructor.
device | QIODevice to parse through. |
main_chunks | list of known names of main chunks |
known_subchunks | list of known subchunks |
Definition at line 58 of file RIFFParser.cpp.
References m_root, Kwave::RIFFChunk::Root, and Kwave::RIFFChunk::setType().
|
virtual |
|
signal |
emits the name of the currently performed action
Referenced by detectEndianness(), and findMissingChunk().
|
protected |
Creates and adds a new chunk. Will be parented to the first non-garbage chunk.
parent | pointer to the parent node (or null if root node) |
name | the 4-byte name of the chunk |
format | the 4-byte format specifier, only valid for main chunks, contains invalid data in sub-chunks |
length | size of the chunk's data |
phys_offset | start of the chunk name in the source |
phys_length | length allocated in the source (file) |
type | chunk type, |
Definition at line 235 of file RIFFParser.cpp.
References Kwave::RIFFChunk::Garbage, m_root, Kwave::RIFFChunk::parent(), Kwave::RIFFChunk::physStart(), Kwave::RIFFChunk::setType(), Kwave::RIFFChunk::subChunks(), and Kwave::RIFFChunk::type().
Referenced by addEmptyChunk(), addGarbageChunk(), and parse().
|
protected |
Adds a chunk with a valid name and no length information.
parent | pointer to the parent node |
name | the valid name of the chunk |
offset | start of the chunk name in the source |
Definition at line 293 of file RIFFParser.cpp.
References addChunk(), and Kwave::RIFFChunk::Empty.
Referenced by parse().
|
protected |
Adds a chunk that has no valid name and thus is not recognized. It is assumed that it only contains undecodeable garbage without any valid name, length or other header information.
parent | pointer to the parent node |
offset | start of the chunk name in the source |
length | length of the garbage area in bytes |
Definition at line 278 of file RIFFParser.cpp.
References addChunk(), Kwave::RIFFChunk::Garbage, and name.
Referenced by parse().
|
slot |
|
protected |
Returns a pointer to a chunk that starts at a given offset or zero if none found.
offset | the start position (physical start) |
Definition at line 534 of file RIFFParser.cpp.
References listAllChunks(), m_root, and Kwave::RIFFChunk::physStart().
Referenced by parse().
unsigned int Kwave::RIFFParser::chunkCount | ( | const QByteArray & | path | ) |
Returns the number of times a chunk is present
Definition at line 463 of file RIFFParser.cpp.
References listAllChunks(), m_root, Kwave::RIFFChunk::name(), and Kwave::RIFFChunk::path().
Referenced by Kwave::WavDecoder::open().
|
private |
clear all main chunks that contain only garbage and convert them into garbage chunks
Definition at line 632 of file RIFFParser.cpp.
References Kwave::RIFFChunk::Garbage, listAllChunks(), m_cancel, m_root, Kwave::RIFFChunk::physEnd(), Kwave::RIFFChunk::physStart(), Kwave::RIFFChunk::setLength(), Kwave::RIFFChunk::setType(), Kwave::RIFFChunk::subChunks(), and Kwave::RIFFChunk::type().
Referenced by repair().
|
protected |
Tries to detect the endianness of the source. If successful, the endianness will be set. If failed, will be set to "Unknown".
Definition at line 107 of file RIFFParser.cpp.
References _, action(), Kwave::BigEndian, Kwave::LittleEndian, m_cancel, m_dev, m_endianness, m_main_chunk_names, m_root, m_sub_chunk_names, name, Kwave::RIFFChunk::physLength(), Kwave::RIFFChunk::physStart(), progress(), read4ByteString(), scanForName(), and Kwave::UnknownEndian.
Referenced by parse().
|
private |
Discards all garbage sub-chunks
Definition at line 796 of file RIFFParser.cpp.
References Kwave::RIFFChunk::Garbage, m_cancel, Kwave::RIFFChunk::subChunks(), and Kwave::RIFFChunk::type().
Referenced by repair().
void Kwave::RIFFParser::dumpStructure | ( | ) |
Dumps the structure of all chunks, useful for debugging.
Definition at line 431 of file RIFFParser.cpp.
References Kwave::RIFFChunk::dumpStructure(), and m_root.
Referenced by Kwave::WavDecoder::open().
Kwave::RIFFChunk * Kwave::RIFFParser::findChunk | ( | const QByteArray & | path | ) |
Tries to find a chunk in the tree of parsed chunks, only accepting a full match.
path | the full path of the chunk to be searched |
Definition at line 443 of file RIFFParser.cpp.
References listAllChunks(), m_root, Kwave::RIFFChunk::name(), and Kwave::RIFFChunk::path().
Referenced by Kwave::WavDecoder::open().
Kwave::RIFFChunk * Kwave::RIFFParser::findMissingChunk | ( | const QByteArray & | name | ) |
Tries very hard to find a missing chunk by stepping through the whole file or source.
name | the 4-byte name of the chunk |
Definition at line 544 of file RIFFParser.cpp.
References action(), Kwave::RIFFChunk::Garbage, listAllChunks(), m_cancel, m_root, parse(), Kwave::RIFFChunk::physEnd(), Kwave::RIFFChunk::physLength(), Kwave::RIFFChunk::physStart(), progress(), scanForName(), and Kwave::RIFFChunk::type().
Referenced by Kwave::WavDecoder::open().
|
private |
fixes the end of garbage chunks to no longer overlap valid chunks
Definition at line 682 of file RIFFParser.cpp.
References Kwave::RIFFChunk::Garbage, Kwave::RIFFChunk::isChildOf(), listAllChunks(), m_cancel, m_root, Kwave::RIFFChunk::name(), Kwave::RIFFChunk::physEnd(), Kwave::RIFFChunk::physStart(), Kwave::RIFFChunk::setLength(), and Kwave::RIFFChunk::type().
Referenced by repair().
|
protected |
Tries to find the chunk name in the list of known main chunk names and returns RIFFChunk::Main if successful. Otherwise returns RIFFChunk::Sub or RIFFChunk::Garbage if the chunk name is not valid.
name | the name of the chunk |
Definition at line 91 of file RIFFParser.cpp.
References Kwave::RIFFChunk::Garbage, isValidName(), m_main_chunk_names, Kwave::RIFFChunk::Main, and Kwave::RIFFChunk::Sub.
Referenced by joinGarbageToEmpty(), and parse().
|
protected |
Returns true if the given chunk name is known as main or sub chunk
Definition at line 99 of file RIFFParser.cpp.
References m_main_chunk_names, and m_sub_chunk_names.
Referenced by joinGarbageToEmpty().
bool Kwave::RIFFParser::isSane | ( | ) |
Returns true if the source contains no structural errors and no garbage or empty chunks.
Definition at line 437 of file RIFFParser.cpp.
References Kwave::RIFFChunk::isSane(), and m_root.
Referenced by Kwave::WavDecoder::open().
|
protected |
Returns true if the given chunk name is valid
Definition at line 76 of file RIFFParser.cpp.
Referenced by guessType(), and parse().
|
private |
joins garbage to previous empty chunks. If a chunk follows a previously empty chunk with an unknown name it will be joined too.
Definition at line 731 of file RIFFParser.cpp.
References Kwave::RIFFChunk::dataLength(), Kwave::RIFFChunk::dataStart(), Kwave::RIFFChunk::Empty, Kwave::RIFFChunk::Garbage, guessType(), isKnownName(), listAllChunks(), m_cancel, m_root, Kwave::RIFFChunk::Main, Kwave::RIFFChunk::name(), Kwave::RIFFChunk::parent(), parse(), Kwave::RIFFChunk::physLength(), Kwave::RIFFChunk::physStart(), read4ByteString(), Kwave::RIFFChunk::setFormat(), Kwave::RIFFChunk::setLength(), Kwave::RIFFChunk::setType(), Kwave::RIFFChunk::subChunks(), and Kwave::RIFFChunk::type().
Referenced by repair().
|
protected |
Recursively creates a "flat" list of all chunks.
parent | node to start with |
list | receives references to the chunks |
Definition at line 525 of file RIFFParser.cpp.
References Kwave::RIFFChunk::subChunks().
Referenced by chunkAt(), chunkCount(), collectGarbage(), findChunk(), findMissingChunk(), fixGarbageEnds(), and joinGarbageToEmpty().
bool Kwave::RIFFParser::parse | ( | ) |
Parses the whole source.
Definition at line 219 of file RIFFParser.cpp.
References detectEndianness(), m_dev, m_endianness, m_root, toUint32(), and Kwave::UnknownEndian.
Referenced by findMissingChunk(), joinGarbageToEmpty(), Kwave::WavDecoder::open(), and parse().
bool Kwave::RIFFParser::parse | ( | Kwave::RIFFChunk * | parent, |
quint32 | offset, | ||
quint32 | length | ||
) |
Parses a range of the source and adds all found chunks to a list of chunks. Also parses recursively for sub-chunks and builds a tree.
parent | pointer to the parent node |
offset | start of the chunk name in the source |
length | size of the area where to search |
Definition at line 304 of file RIFFParser.cpp.
References addChunk(), addEmptyChunk(), addGarbageChunk(), chunkAt(), Kwave::RIFFChunk::dataLength(), Kwave::RIFFChunk::dataStart(), guessType(), isValidName(), m_cancel, m_dev, m_endianness, m_root, Kwave::RIFFChunk::Main, Kwave::RIFFChunk::name(), name, parse(), Kwave::RIFFChunk::path(), Kwave::RIFFChunk::physEnd(), Kwave::RIFFChunk::physLength(), read4ByteString(), Kwave::RIFFChunk::setType(), Kwave::RIFFChunk::Sub, Kwave::RIFFChunk::subChunks(), and SYSTEM_ENDIANNES.
|
signal |
emits a progress in percent
Referenced by detectEndianness(), findMissingChunk(), and scanForName().
|
protected |
Reads a 4-byte string from the source device at a given offset. The current source position will be set to 4 bytes after the given offset afterwards.
offset | position within the source, no range checks! |
Definition at line 208 of file RIFFParser.cpp.
References m_dev.
Referenced by detectEndianness(), joinGarbageToEmpty(), and parse().
void Kwave::RIFFParser::repair | ( | ) |
Tries to repair the RIFF file by solving inconsistencies
Definition at line 603 of file RIFFParser.cpp.
References collectGarbage(), discardGarbage(), fixGarbageEnds(), joinGarbageToEmpty(), m_cancel, and m_root.
Referenced by Kwave::WavDecoder::open().
|
protected |
Performs a scan for a 4-character chunk name over a range of the source. Also emits progress bar info from [(start/count) ... ((start+1)/count-1)]
name | the name of the chunk to be found |
offset | position for start of the scan |
length | number of bytes to scan |
progress_start | start of the progress [0..progress_count-1] |
progress_count | number of progress sections |
Definition at line 484 of file RIFFParser.cpp.
References m_cancel, m_dev, and progress().
Referenced by detectEndianness(), and findMissingChunk().
|
private |
can be set to true in order to cancel a running operation
Definition at line 271 of file RIFFParser.h.
Referenced by cancel(), collectGarbage(), detectEndianness(), discardGarbage(), findMissingChunk(), fixGarbageEnds(), joinGarbageToEmpty(), parse(), repair(), and scanForName().
|
private |
I/O device with the source of the file
Definition at line 256 of file RIFFParser.h.
Referenced by detectEndianness(), parse(), read4ByteString(), and scanForName().
|
private |
endianness of the RIFF file, auto-detected
Definition at line 268 of file RIFFParser.h.
Referenced by detectEndianness(), and parse().
|
private |
list of known names of main chunks
Definition at line 262 of file RIFFParser.h.
Referenced by detectEndianness(), guessType(), and isKnownName().
|
private |
root chunk of the source
Definition at line 259 of file RIFFParser.h.
Referenced by addChunk(), chunkAt(), chunkCount(), collectGarbage(), detectEndianness(), dumpStructure(), findChunk(), findMissingChunk(), fixGarbageEnds(), isSane(), joinGarbageToEmpty(), parse(), repair(), and RIFFParser().
|
private |
list of known names of sub chunks
Definition at line 265 of file RIFFParser.h.
Referenced by detectEndianness(), and isKnownName().