Tag Parser  10.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 std::string_view tagName = "OGG Vorbis comment";
75  TagType type() const override;
76  std::string_view 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 final : 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, AbortableProgressFeedback &progress) override;
148  void internalParseTags(Diagnostics &diag, AbortableProgressFeedback &progress) override;
149  void internalParseTracks(Diagnostics &diag, AbortableProgressFeedback &progress) 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
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks.
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
The GenericContainer class helps parsing header, track, tag and chapter information of a file.
The MediaFileInfo class allows to read and write tag information providing a container/tag format ind...
Definition: mediafileinfo.h:74
Implementation of TagParser::AbstractContainer for OGG files.
Definition: oggcontainer.h:129
void setChecksumValidationEnabled(bool enabled)
Sets whether checksum validation is enabled.
Definition: oggcontainer.h:181
bool isChecksumValidationEnabled() const
Returns whether checksum validation is enabled.
Definition: oggcontainer.h:172
The OggIterator class helps iterating through all segments of an OGG bitstream.
Definition: oggiterator.h:11
Implementation of TagParser::AbstractTrack for OGG streams.
Definition: oggstream.h:13
Specialization of TagParser::VorbisComment for Vorbis comments inside an OGG stream.
Definition: oggcontainer.h:67
OggParameter & oggParams()
Returns the OGG parameter for the comment.
Definition: oggcontainer.h:113
TagType type() const override
Returns the type of the tag as TagParser::TagType.
Definition: oggcontainer.h:93
bool supportsTarget() const override
Returns true; the target is used to specifiy the stream.
Definition: oggcontainer.h:102
OggVorbisComment()
Constructs a new OGG Vorbis comment.
Definition: oggcontainer.h:89
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:20
The Tag class is used to store, read and write tag information.
Definition: tag.h:108
Implementation of TagParser::Tag for Vorbis comments.
Definition: vorbiscomment.h:25
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
constexpr TAG_PARSER_EXPORT std::string_view comment()
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagType
Specifies the tag type.
Definition: tag.h:20
GeneralMediaFormat
The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4,...
Definition: mediaformat.h:30
The OggParameter struct holds the OGG parameter for a VorbisComment.
Definition: oggcontainer.h:27
GeneralMediaFormat streamFormat
Definition: oggcontainer.h:35
std::size_t lastPageIndex
Definition: oggcontainer.h:33
std::size_t lastSegmentIndex
Definition: oggcontainer.h:34
constexpr OggParameter()
Creates new parameters.
Definition: oggcontainer.h:44
std::size_t firstSegmentIndex
Definition: oggcontainer.h:32
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
std::size_t firstPageIndex
Definition: oggcontainer.h:31