Tag Parser: ogg/oggcontainer.h Source File

Tag Parser 12.5.2 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
oggcontainer.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_OGGCONTAINER_H
2#define TAG_PARSER_OGGCONTAINER_H
3
4#include "./oggiterator.h"
5#include "./oggpage.h"
6#include "./oggstream.h"
7
8#include "../vorbis/vorbiscomment.h"
9
10#include "../genericcontainer.h"
11
12#include <tuple>
13#include <unordered_map>
14
16namespace CppUtilities {
17template <std::size_t bufferSize> class CopyHelper;
18}
20
21namespace TagParser {
22
23class MediaFileInfo;
24class OggContainer;
25
29 struct TAG_PARSER_EXPORT OggParameter {
30 constexpr OggParameter();
31 void set(std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat streamFormat = GeneralMediaFormat::Vorbis);
32
33 std::size_t firstPageIndex;
34 std::size_t firstSegmentIndex;
35 std::size_t lastPageIndex;
36 std::size_t lastSegmentIndex;
37 GeneralMediaFormat streamFormat;
38 bool lastMetaDataBlock;
39 bool removed;
40};
41
46 constexpr OggParameter::OggParameter()
47 : firstPageIndex(0)
48 , firstSegmentIndex(0)
49 , lastPageIndex(0)
50 , lastSegmentIndex(0)
51 , streamFormat(GeneralMediaFormat::Vorbis)
52 , lastMetaDataBlock(false)
53 , removed(false)
54{
55}
56
61 inline void OggParameter::set(std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat streamFormat)
62{
63 firstPageIndex = lastPageIndex = pageIndex;
64 firstSegmentIndex = lastSegmentIndex = segmentIndex;
65 this->lastMetaDataBlock = lastMetaDataBlock;
66 this->streamFormat = streamFormat;
67}
68
69 class TAG_PARSER_EXPORT OggVorbisComment final : public VorbisComment {
70 friend class OggContainer;
71
72public:
73 OggVorbisComment();
74
75 static constexpr TagType tagType = TagType::OggVorbisComment;
76 static constexpr std::string_view tagName = "Ogg Vorbis comment";
77 TagType type() const override;
78 std::string_view typeName() const override;
79 bool supportsTarget() const override;
80
81 OggParameter &oggParams();
82 const OggParameter &oggParams() const;
83
84private:
85 OggParameter m_oggParams;
86};
87
91 inline OggVorbisComment::OggVorbisComment()
92{
93}
94
95 inline TagType OggVorbisComment::type() const
96{
97 return TagType::OggVorbisComment;
98}
99
107 inline bool OggVorbisComment::supportsTarget() const
108{
109 return true;
110}
111
118 inline OggParameter &OggVorbisComment::oggParams()
119{
120 return m_oggParams;
121}
122
129 inline const OggParameter &OggVorbisComment::oggParams() const
130{
131 return m_oggParams;
132}
133
134 class TAG_PARSER_EXPORT OggContainer final : public GenericContainer<MediaFileInfo, OggVorbisComment, OggStream, OggPage> {
135 friend class OggStream;
136
137public:
138 OggContainer(MediaFileInfo &fileInfo, std::uint64_t startOffset);
139 ~OggContainer() override;
140
141 bool isChecksumValidationEnabled() const;
142 void setChecksumValidationEnabled(bool enabled);
143 void reset() override;
144
145 OggVorbisComment *createTag(const TagTarget &target) override;
146 OggVorbisComment *tag(std::size_t index) override;
147 std::size_t tagCount() const override;
148 bool removeTag(Tag *tag) override;
149 void removeAllTags() override;
150
151protected:
152 void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress) override;
153 void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress) override;
154 void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress) override;
155 void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress) override;
156
157private:
158 void announceComment(
159 std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat mediaFormat = GeneralMediaFormat::Vorbis);
160 void makeVorbisCommentSegment(std::stringstream &buffer, CppUtilities::CopyHelper<65307> &copyHelper, std::vector<std::uint32_t> &newSegmentSizes,
161 VorbisComment *comment, OggParameter *params, Diagnostics &diag);
162
163 std::unordered_map<std::uint32_t, std::vector<std::unique_ptr<OggStream>>::size_type> m_streamsBySerialNo;
164
165 OggIterator m_iterator;
166 bool m_validateChecksums;
167};
168
177 inline bool OggContainer::isChecksumValidationEnabled() const
178{
179 return m_validateChecksums;
180}
181
186 inline void OggContainer::setChecksumValidationEnabled(bool enabled)
187{
188 m_validateChecksums = enabled;
189}
190
191} // namespace TagParser
192
193#endif // TAG_PARSER_OGGCONTAINER_H
TagParser::AbortableProgressFeedback
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
Definition progressfeedback.h:186
TagParser::AbstractContainer::startOffset
std::uint64_t startOffset() const
Returns the start offset in the related stream.
Definition abstractcontainer.h:154
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition diagnostics.h:156
TagParser::GenericContainer< MediaFileInfo, OggVorbisComment, OggStream, OggPage >::GenericContainer
GenericContainer(MediaFileInfo &fileInfo, std::uint64_t startOffset)
Definition genericcontainer.h:71
TagParser::GenericContainer< MediaFileInfo, OggVorbisComment, OggStream, OggPage >::fileInfo
MediaFileInfo & fileInfo() const
Definition genericcontainer.h:114
TagParser::MediaFileInfo
The MediaFileInfo class allows to read and write tag information providing a container/tag format ind...
Definition mediafileinfo.h:83
TagParser::OggContainer
Implementation of TagParser::AbstractContainer for Ogg files.
Definition oggcontainer.h:134
TagParser::OggContainer::internalParseTags
void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress) override
Internally called to parse the tags.
Definition oggcontainer.cpp:279
TagParser::OggContainer::setChecksumValidationEnabled
void setChecksumValidationEnabled(bool enabled)
Sets whether checksum validation is enabled.
Definition oggcontainer.h:186
TagParser::OggContainer::tag
OggVorbisComment * tag(std::size_t index) override
Returns the tag with the specified index.
Definition oggcontainer.cpp:124
TagParser::OggContainer::tagCount
std::size_t tagCount() const override
Returns the number of tags attached to the container.
Definition oggcontainer.cpp:138
TagParser::OggContainer::isChecksumValidationEnabled
bool isChecksumValidationEnabled() const
Returns whether checksum validation is enabled.
Definition oggcontainer.h:177
TagParser::OggContainer::internalParseTracks
void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress) override
Internally called to parse the tracks.
Definition oggcontainer.cpp:360
TagParser::OggContainer::OggContainer
OggContainer(MediaFileInfo &fileInfo, std::uint64_t startOffset)
Constructs a new container for the specified stream at the specified startOffset.
Definition oggcontainer.cpp:48
TagParser::OggContainer::internalParseHeader
void internalParseHeader(Diagnostics &diag, AbortableProgressFeedback &progress) override
Internally called to parse the header.
Definition oggcontainer.cpp:188
TagParser::OggContainer::removeAllTags
void removeAllTags() override
Actually just flags all tags as removed and clears all assigned fields.
Definition oggcontainer.cpp:180
TagParser::OggContainer::createTag
OggVorbisComment * createTag(const TagTarget &target) override
Creates a new tag.
Definition oggcontainer.cpp:74
TagParser::OggContainer::reset
void reset() override
Discards all parsing results.
Definition oggcontainer.cpp:59
TagParser::OggContainer::OggStream
friend class OggStream
Definition oggcontainer.h:135
TagParser::OggContainer::internalMakeFile
void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress) override
Internally called to make the file.
Definition oggcontainer.cpp:424
TagParser::OggContainer::removeTag
bool removeTag(Tag *tag) override
Actually just flags the specified tag as removed and clears all assigned fields.
Definition oggcontainer.cpp:158
TagParser::OggIterator
The OggIterator class helps iterating through all segments of an Ogg bitstream.
Definition oggiterator.h:11
TagParser::OggVorbisComment
Specialization of TagParser::VorbisComment for Vorbis comments inside an Ogg stream.
Definition oggcontainer.h:69
TagParser::OggVorbisComment::OggContainer
friend class OggContainer
Definition oggcontainer.h:70
TagParser::OggVorbisComment::oggParams
OggParameter & oggParams()
Returns the Ogg parameter for the comment.
Definition oggcontainer.h:118
TagParser::OggVorbisComment::tagName
static constexpr std::string_view tagName
Definition oggcontainer.h:76
TagParser::OggVorbisComment::type
TagType type() const override
Returns the type of the tag as TagParser::TagType.
Definition oggcontainer.h:95
TagParser::OggVorbisComment::supportsTarget
bool supportsTarget() const override
Returns true; the target is used to specify the stream.
Definition oggcontainer.h:107
TagParser::OggVorbisComment::tagType
static constexpr TagType tagType
Definition oggcontainer.h:75
TagParser::OggVorbisComment::OggVorbisComment
OggVorbisComment()
Constructs a new Ogg Vorbis comment.
Definition oggcontainer.h:91
TagParser::OggVorbisComment::typeName
std::string_view typeName() const override
Returns the type name of the tag as C-style string.
Definition oggcontainer.cpp:26
TagParser::TagTarget
The TagTarget class specifies the target of a tag.
Definition tagtarget.h:20
TagParser::Tag
The Tag class is used to store, read and write tag information.
Definition tag.h:179
TagParser::VorbisComment
Implementation of TagParser::Tag for Vorbis comments.
Definition vorbiscomment.h:27
TagParser::VorbisComment::VorbisComment
VorbisComment()
Constructs a new Vorbis comment.
Definition vorbiscomment.h:70
genericcontainer.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
CppUtilities
Definition abstractcontainer.h:16
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::TagType
TagType
Specifies the tag type.
Definition tagtype.h:11
TagParser::TagType::OggVorbisComment
@ OggVorbisComment
Definition tagtype.h:18
TagParser::GeneralMediaFormat
GeneralMediaFormat
The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4,...
Definition mediaformat.h:30
TagParser::GeneralMediaFormat::Vorbis
@ Vorbis
Definition mediaformat.h:96
oggiterator.h
oggpage.h
oggstream.h
TagParser::OggParameter
The OggParameter struct holds the Ogg parameter for a VorbisComment.
Definition oggcontainer.h:29
TagParser::OggParameter::lastMetaDataBlock
bool lastMetaDataBlock
Definition oggcontainer.h:38
TagParser::OggParameter::streamFormat
GeneralMediaFormat streamFormat
Definition oggcontainer.h:37
TagParser::OggParameter::lastPageIndex
std::size_t lastPageIndex
Definition oggcontainer.h:35
TagParser::OggParameter::lastSegmentIndex
std::size_t lastSegmentIndex
Definition oggcontainer.h:36
TagParser::OggParameter::OggParameter
constexpr OggParameter()
Creates new parameters.
Definition oggcontainer.h:46
TagParser::OggParameter::firstSegmentIndex
std::size_t firstSegmentIndex
Definition oggcontainer.h:34
TagParser::OggParameter::set
void set(std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat streamFormat=GeneralMediaFormat::Vorbis)
Sets the firstPageIndex/lastPageIndex, the firstSegmentIndex/lastSegmentIndex, whether the associated...
Definition oggcontainer.h:61
TagParser::OggParameter::firstPageIndex
std::size_t firstPageIndex
Definition oggcontainer.h:33
TagParser::OggParameter::removed
bool removed
Definition oggcontainer.h:39
vorbiscomment.h