tagparser/flac/flacmetadata.h

306 lines
7.1 KiB
C
Raw Normal View History

#ifndef TAG_PARSER_FLACMETADATAHEADER_H
#define TAG_PARSER_FLACMETADATAHEADER_H
2016-05-14 00:24:01 +02:00
2016-08-29 15:43:05 +02:00
#include "../global.h"
2016-05-14 00:24:01 +02:00
#include <c++utilities/conversion/types.h>
#include <iostream>
namespace TagParser {
2016-05-14 00:24:01 +02:00
class TagValue;
/*!
* \brief The FlacMetaDataBlockType enum specifies the type of FlacMetaDataBlockHeader.
*/
2018-03-07 01:17:50 +01:00
enum class FlacMetaDataBlockType : byte { StreamInfo = 0, Padding, Application, SeekTable, VorbisComment, CuseSheet, Picture };
2016-05-14 00:24:01 +02:00
2018-03-07 01:17:50 +01:00
constexpr bool operator==(byte lhs, FlacMetaDataBlockType type)
2016-05-14 00:24:01 +02:00
{
return lhs == static_cast<byte>(type);
}
2018-03-07 01:17:50 +01:00
constexpr bool operator!=(byte lhs, FlacMetaDataBlockType type)
2016-05-14 00:24:01 +02:00
{
return lhs != static_cast<byte>(type);
}
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT FlacMetaDataBlockHeader {
2016-05-14 00:24:01 +02:00
public:
2018-07-10 14:11:11 +02:00
constexpr FlacMetaDataBlockHeader();
2016-05-14 00:24:01 +02:00
void parseHeader(const char *buffer);
void makeHeader(std::ostream &outputStream);
2018-07-10 14:11:11 +02:00
constexpr byte isLast() const;
2016-05-14 00:24:01 +02:00
void setLast(byte last);
2018-07-10 14:11:11 +02:00
constexpr byte type() const;
2016-05-14 00:24:01 +02:00
void setType(FlacMetaDataBlockType type);
2018-07-10 14:11:11 +02:00
constexpr uint32 dataSize() const;
2016-05-14 00:24:01 +02:00
void setDataSize(uint32 dataSize);
private:
byte m_last;
byte m_type;
uint32 m_dataSize;
};
/*!
* \brief Constructs a new FLAC "METADATA_BLOCK_HEADER".
*/
2018-07-10 14:11:11 +02:00
constexpr FlacMetaDataBlockHeader::FlacMetaDataBlockHeader()
2018-03-07 01:17:50 +01:00
: m_last(0)
, m_type(0)
, m_dataSize(0)
{
}
2016-05-14 00:24:01 +02:00
/*!
* \brief Returns whether this is the last metadata block before the audio blocks.
2016-05-16 20:56:53 +02:00
* \remarks The default value is 0/false.
2016-05-14 00:24:01 +02:00
*/
2018-07-10 14:11:11 +02:00
constexpr byte FlacMetaDataBlockHeader::isLast() const
2016-05-14 00:24:01 +02:00
{
return m_last;
}
/*!
* \brief Sets whether this is the last metadata block before the audio blocks.
*/
inline void FlacMetaDataBlockHeader::setLast(byte last)
{
m_last = last;
}
/*!
* \brief Returns the block type.
* \sa FlacMetaDataBlockType
*/
2018-07-10 14:11:11 +02:00
constexpr byte FlacMetaDataBlockHeader::type() const
2016-05-14 00:24:01 +02:00
{
return m_type;
}
/*!
* \brief Sets the block type.
*/
inline void FlacMetaDataBlockHeader::setType(FlacMetaDataBlockType type)
{
m_type = static_cast<byte>(type);
}
/*!
* \brief Returns the length in bytes of the meta data (excluding the size of the header itself).
*/
2018-07-10 14:11:11 +02:00
constexpr uint32 FlacMetaDataBlockHeader::dataSize() const
2016-05-14 00:24:01 +02:00
{
return m_dataSize;
}
/*!
* \brief Sets the length in bytes of the meta data (excluding the size of the header itself).
* \remarks Max value is (2^24 - 1).
*/
inline void FlacMetaDataBlockHeader::setDataSize(uint32 dataSize)
{
m_dataSize = dataSize;
}
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT FlacMetaDataBlockStreamInfo {
2016-05-14 00:24:01 +02:00
public:
2018-07-10 14:11:11 +02:00
constexpr FlacMetaDataBlockStreamInfo();
2016-05-14 00:24:01 +02:00
void parse(const char *buffer);
2018-07-10 14:11:11 +02:00
constexpr uint16 minBlockSize() const;
constexpr uint16 maxBlockSize() const;
constexpr uint32 minFrameSize() const;
constexpr uint32 maxFrameSize() const;
constexpr uint32 samplingFrequency() const;
constexpr byte channelCount() const;
constexpr byte bitsPerSample() const;
constexpr uint64 totalSampleCount() const;
constexpr const char *md5Sum() const;
2016-05-14 00:24:01 +02:00
private:
uint16 m_minBlockSize;
uint16 m_maxBlockSize;
uint32 m_minFrameSize;
uint32 m_maxFrameSize;
uint32 m_samplingFrequency;
byte m_channelCount;
byte m_bitsPerSample;
uint64 m_totalSampleCount;
char m_md5Sum[16];
};
/*!
* \brief Constructs a new FLAC "METADATA_BLOCK_STREAMINFO".
*/
2018-07-10 14:11:11 +02:00
constexpr FlacMetaDataBlockStreamInfo::FlacMetaDataBlockStreamInfo()
2018-03-07 01:17:50 +01:00
: m_minBlockSize(0)
, m_maxBlockSize(0)
, m_minFrameSize(0)
, m_maxFrameSize(0)
, m_samplingFrequency(0)
, m_channelCount(0)
, m_bitsPerSample(0)
, m_totalSampleCount(0)
, m_md5Sum{ 0 }
{
}
2016-05-14 00:24:01 +02:00
/*!
* \brief Returns the minimum block size (in samples) used in the stream.
*/
2018-07-10 14:11:11 +02:00
constexpr uint16 FlacMetaDataBlockStreamInfo::minBlockSize() const
2016-05-14 00:24:01 +02:00
{
return m_minBlockSize;
}
/*!
* \brief Returns the maximum block size (in samples) used in the stream.
*
* (Minimum blocksize == maximum blocksize) implies a fixed-blocksize stream.
*/
2018-07-10 14:11:11 +02:00
constexpr uint16 FlacMetaDataBlockStreamInfo::maxBlockSize() const
2016-05-14 00:24:01 +02:00
{
return m_maxBlockSize;
}
/*!
* \brief Returns the minimum frame size (in bytes) used in the stream.
*
* May be 0 to imply the value is not known.
*/
2018-07-10 14:11:11 +02:00
constexpr uint32 FlacMetaDataBlockStreamInfo::minFrameSize() const
2016-05-14 00:24:01 +02:00
{
return m_minFrameSize;
}
/*!
* \brief The maximum frame size (in bytes) used in the stream.
*
* May be 0 to imply the value is not known.
*/
2018-07-10 14:11:11 +02:00
constexpr uint32 FlacMetaDataBlockStreamInfo::maxFrameSize() const
2016-05-14 00:24:01 +02:00
{
return m_maxFrameSize;
}
/*!
* \brief Returns the sampling frequency in Hz.
*
* Though 20 bits are available, the maximum sample rate is limited by the
* structure of frame headers to 655350Hz. Also, a value of 0 is invalid.
*/
2018-07-10 14:11:11 +02:00
constexpr uint32 FlacMetaDataBlockStreamInfo::samplingFrequency() const
2016-05-14 00:24:01 +02:00
{
return m_samplingFrequency;
}
/*!
* \brief Returns the number of channels.
*
* FLAC supports from 1 to 8 channels .
*/
2018-07-10 14:11:11 +02:00
constexpr byte FlacMetaDataBlockStreamInfo::channelCount() const
2016-05-14 00:24:01 +02:00
{
return m_channelCount;
}
/*!
* \brief Returns the bits per sample.
*
* FLAC supports from 4 to 32 bits per sample.
* Currently the reference encoder and decoders only support up
* to 24 bits per sample.
*/
2018-07-10 14:11:11 +02:00
constexpr byte FlacMetaDataBlockStreamInfo::bitsPerSample() const
2016-05-14 00:24:01 +02:00
{
return m_bitsPerSample;
}
/*!
* \brief Returns the total samples in stream.
*
* 'Samples' means inter-channel sample, i.e. one second of 44.1Khz audio
* will have 44100 samples regardless of the number of channels.
*
* A value of zero here means the number of total samples is unknown.
*/
2018-07-10 14:11:11 +02:00
constexpr uint64 FlacMetaDataBlockStreamInfo::totalSampleCount() const
2016-05-14 00:24:01 +02:00
{
return m_totalSampleCount;
}
/*!
* \brief Returns the MD5 signature of the unencoded audio data.
*
* This allows the decoder to determine if an error exists in the
* audio data even when the error does not result in an invalid bitstream.
*/
2018-07-10 14:11:11 +02:00
constexpr const char *FlacMetaDataBlockStreamInfo::md5Sum() const
2016-05-14 00:24:01 +02:00
{
return m_md5Sum;
}
2018-03-07 01:17:50 +01:00
class TAG_PARSER_EXPORT FlacMetaDataBlockPicture {
2016-05-14 00:24:01 +02:00
public:
FlacMetaDataBlockPicture(TagValue &tagValue);
2016-05-16 20:56:53 +02:00
void parse(std::istream &inputStream, uint32 maxSize);
2016-05-14 00:24:01 +02:00
uint32 requiredSize() const;
void make(std::ostream &outputStream);
uint32 pictureType() const;
void setPictureType(uint32 pictureType);
TagValue &value();
private:
uint32 m_pictureType;
TagValue &m_value;
};
/*!
* \brief Constructs a new FLAC "METADATA_BLOCK_PICTURE".
*
* The picture is read from/stored to the specified \a tagValue.
* The FlacMetaDataBlockPicture does not take ownership over
* the specified \a tagValue.
*/
2018-03-07 01:17:50 +01:00
inline FlacMetaDataBlockPicture::FlacMetaDataBlockPicture(TagValue &tagValue)
: m_pictureType(0)
, m_value(tagValue)
{
}
2016-05-14 00:24:01 +02:00
/*!
* \brief Returns the picture type according to the ID3v2 APIC frame.
*/
inline uint32 FlacMetaDataBlockPicture::pictureType() const
{
return m_pictureType;
}
/*!
* \brief Sets the picture type according to the ID3v2 APIC frame.
*/
inline void FlacMetaDataBlockPicture::setPictureType(uint32 pictureType)
{
m_pictureType = pictureType;
}
/*!
* \brief Returns the tag value the picture is read from/stored to.
*/
inline TagValue &FlacMetaDataBlockPicture::value()
{
return m_value;
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser
2016-05-14 00:24:01 +02:00
#endif // TAG_PARSER_FLACMETADATAHEADER_H