Tag Parser  9.0.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
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 
15 namespace CppUtilities {
16 template <std::size_t bufferSize> class CopyHelper;
17 }
18 
19 namespace TagParser {
20 
21 class MediaFileInfo;
22 class OggContainer;
23 
28  constexpr OggParameter();
29  void set(std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat streamFormat = GeneralMediaFormat::Vorbis);
30 
31  std::size_t firstPageIndex;
32  std::size_t firstSegmentIndex;
33  std::size_t lastPageIndex;
34  std::size_t lastSegmentIndex;
37  bool removed;
38 };
39 
45  : firstPageIndex(0)
46  , firstSegmentIndex(0)
47  , lastPageIndex(0)
48  , lastSegmentIndex(0)
49  , streamFormat(GeneralMediaFormat::Vorbis)
50  , lastMetaDataBlock(false)
51  , removed(false)
52 {
53 }
54 
59 inline void OggParameter::set(std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat streamFormat)
60 {
61  firstPageIndex = lastPageIndex = pageIndex;
62  firstSegmentIndex = lastSegmentIndex = segmentIndex;
63  this->lastMetaDataBlock = lastMetaDataBlock;
64  this->streamFormat = streamFormat;
65 }
66 
68  friend class OggContainer;
69 
70 public:
72 
73  static constexpr TagType tagType = TagType::OggVorbisComment;
74  static constexpr const char *tagName = "OGG Vorbis comment";
75  TagType type() const override;
76  const char *typeName() const override;
77  bool supportsTarget() const override;
78 
79  OggParameter &oggParams();
80  const OggParameter &oggParams() const;
81 
82 private:
83  OggParameter m_oggParams;
84 };
85 
90 {
91 }
92 
94 {
96 }
97 
103 {
104  return true;
105 }
106 
114 {
115  return m_oggParams;
116 }
117 
125 {
126  return m_oggParams;
127 }
128 
129 class TAG_PARSER_EXPORT OggContainer : public GenericContainer<MediaFileInfo, OggVorbisComment, OggStream, OggPage> {
130  friend class OggStream;
131 
132 public:
133  OggContainer(MediaFileInfo &fileInfo, std::uint64_t startOffset);
134  ~OggContainer() override;
135 
136  bool isChecksumValidationEnabled() const;
137  void setChecksumValidationEnabled(bool enabled);
138  void reset() override;
139 
140  OggVorbisComment *createTag(const TagTarget &target) override;
141  OggVorbisComment *tag(std::size_t index) override;
142  std::size_t tagCount() const override;
143  bool removeTag(Tag *tag) override;
144  void removeAllTags() override;
145 
146 protected:
147  void internalParseHeader(Diagnostics &diag) override;
148  void internalParseTags(Diagnostics &diag) override;
149  void internalParseTracks(Diagnostics &diag) override;
150  void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress) override;
151 
152 private:
153  void announceComment(
154  std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat mediaFormat = GeneralMediaFormat::Vorbis);
155  void makeVorbisCommentSegment(std::stringstream &buffer, CppUtilities::CopyHelper<65307> &copyHelper, std::vector<std::uint32_t> &newSegmentSizes,
156  VorbisComment *comment, OggParameter *params, Diagnostics &diag);
157 
158  std::unordered_map<std::uint32_t, std::vector<std::unique_ptr<OggStream>>::size_type> m_streamsBySerialNo;
159 
160  OggIterator m_iterator;
161  bool m_validateChecksums;
162 };
163 
173 {
174  return m_validateChecksums;
175 }
176 
182 {
183  m_validateChecksums = enabled;
184 }
185 
186 } // namespace TagParser
187 
188 #endif // TAG_PARSER_OGGCONTAINER_H
TagParser::OggContainer::setChecksumValidationEnabled
void setChecksumValidationEnabled(bool enabled)
Sets whether checksum validation is enabled.
Definition: oggcontainer.h:181
TagParser::OggContainer::isChecksumValidationEnabled
bool isChecksumValidationEnabled() const
Returns whether checksum validation is enabled.
Definition: oggcontainer.h:172
TagParser::GeneralMediaFormat
GeneralMediaFormat
The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4,...
Definition: mediaformat.h:29
TagParser::AbortableProgressFeedback
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks....
Definition: progressfeedback.h:186
TagParser::OggIterator
The OggIterator class helps iterating through all segments of an OGG bitstream.
Definition: oggiterator.h:11
TagParser::OggContainer
Implementation of TagParser::AbstractContainer for OGG files.
Definition: oggcontainer.h:129
TagParser::Tag
The Tag class is used to store, read and write tag information.
Definition: tag.h:98
TagParser::Diagnostics
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
TagParser::OggVorbisComment::type
TagType type() const override
Returns the type of the tag as TagParser::TagType.
Definition: oggcontainer.h:93
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::OggParameter
The OggParameter struct holds the OGG parameter for a VorbisComment.
Definition: oggcontainer.h:27
TagParser::OggVorbisComment::OggVorbisComment
OggVorbisComment()
Constructs a new OGG Vorbis comment.
Definition: oggcontainer.h:89
TagParser::OggVorbisComment::oggParams
OggParameter & oggParams()
Returns the OGG parameter for the comment.
Definition: oggcontainer.h:113
TagParser::OggVorbisComment::supportsTarget
bool supportsTarget() const override
Returns true; the target is used to specifiy the stream.
Definition: oggcontainer.h:102
TagParser::OggVorbisComment
Specialization of TagParser::VorbisComment for Vorbis comments inside an OGG stream.
Definition: oggcontainer.h:67
TagParser::OggParameter::OggParameter
constexpr OggParameter()
Creates new parameters.
Definition: oggcontainer.h:44
TagParser::GenericContainer
The GenericContainer class helps parsing header, track, tag and chapter information of a file.
Definition: genericcontainer.h:22
oggstream.h
CppUtilities
Definition: abstractcontainer.h:15
oggiterator.h
oggpage.h
TagParser::OggParameter::firstSegmentIndex
std::size_t firstSegmentIndex
Definition: oggcontainer.h:32
TagParser::OggParameter::streamFormat
GeneralMediaFormat streamFormat
Definition: oggcontainer.h:35
CppUtilities::CopyHelper
Definition: oggcontainer.h:16
TagParser::TagTarget
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:20
TagParser::MatroskaTagIds::comment
constexpr const TAG_PARSER_EXPORT char * comment()
Definition: matroskatagid.h:309
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TagParser::OggParameter::lastMetaDataBlock
bool lastMetaDataBlock
Definition: oggcontainer.h:36
TagParser::OggStream
Implementation of TagParser::AbstractTrack for OGG streams.
Definition: oggstream.h:13
TagParser::OggParameter::removed
bool removed
Definition: oggcontainer.h:37
TagParser::OggParameter::firstPageIndex
std::size_t firstPageIndex
Definition: oggcontainer.h:31
TagParser::OggParameter::lastPageIndex
std::size_t lastPageIndex
Definition: oggcontainer.h:33
TagParser::VorbisComment
Implementation of TagParser::Tag for Vorbis comments.
Definition: vorbiscomment.h:25
TagParser::MediaFileInfo
The MediaFileInfo class allows to read and write tag information providing a container/tag format ind...
Definition: mediafileinfo.h:45
TagParser::TagType::OggVorbisComment
TagParser::OggParameter::lastSegmentIndex
std::size_t lastSegmentIndex
Definition: oggcontainer.h:34
TagParser::GeneralMediaFormat::Vorbis
TagParser::TagType
TagType
Specifies the tag type.
Definition: tag.h:20
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:59