Tag Parser  8.0.1
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 IoUtilities {
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  TagType type() const override;
73  const char *typeName() const override;
74  bool supportsTarget() const override;
75 
76  OggParameter &oggParams();
77  const OggParameter &oggParams() const;
78 
79 private:
80  OggParameter m_oggParams;
81 };
82 
87 {
88 }
89 
91 {
93 }
94 
100 {
101  return true;
102 }
103 
111 {
112  return m_oggParams;
113 }
114 
122 {
123  return m_oggParams;
124 }
125 
126 class TAG_PARSER_EXPORT OggContainer : public GenericContainer<MediaFileInfo, OggVorbisComment, OggStream, OggPage> {
127  friend class OggStream;
128 
129 public:
130  OggContainer(MediaFileInfo &fileInfo, uint64 startOffset);
131  ~OggContainer() override;
132 
133  bool isChecksumValidationEnabled() const;
134  void setChecksumValidationEnabled(bool enabled);
135  void reset() override;
136 
137  OggVorbisComment *createTag(const TagTarget &target) override;
138  OggVorbisComment *tag(std::size_t index) override;
139  std::size_t tagCount() const override;
140  bool removeTag(Tag *tag) override;
141  void removeAllTags() override;
142 
143 protected:
144  void internalParseHeader(Diagnostics &diag) override;
145  void internalParseTags(Diagnostics &diag) override;
146  void internalParseTracks(Diagnostics &diag) override;
147  void internalMakeFile(Diagnostics &diag, AbortableProgressFeedback &progress) override;
148 
149 private:
150  void announceComment(
151  std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat mediaFormat = GeneralMediaFormat::Vorbis);
152  void makeVorbisCommentSegment(std::stringstream &buffer, IoUtilities::CopyHelper<65307> &copyHelper, std::vector<uint32> &newSegmentSizes,
153  VorbisComment *comment, OggParameter *params, Diagnostics &diag);
154 
155  std::unordered_map<uint32, std::vector<std::unique_ptr<OggStream>>::size_type> m_streamsBySerialNo;
156 
157  OggIterator m_iterator;
158  bool m_validateChecksums;
159 };
160 
170 {
171  return m_validateChecksums;
172 }
173 
179 {
180  m_validateChecksums = enabled;
181 }
182 
183 } // namespace TagParser
184 
185 #endif // TAG_PARSER_OGGCONTAINER_H
Specialization of TagParser::VorbisComment for Vorbis comments inside an OGG stream.
Definition: oggcontainer.h:67
The Tag class is used to store, read and write tag information.
Definition: tag.h:95
bool isChecksumValidationEnabled() const
Returns whether checksum validation is enabled.
Definition: oggcontainer.h:169
TagType type() const override
Returns the type of the tag as TagParser::TagType.
Definition: oggcontainer.h:90
OggVorbisComment()
Constructs a new OGG Vorbis comment.
Definition: oggcontainer.h:86
The OggIterator class helps iterating through all segments of an OGG bitstream.
Definition: oggiterator.h:11
The OggParameter struct holds the OGG parameter for a VorbisComment.
Definition: oggcontainer.h:27
GeneralMediaFormat
The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4, PNG, ...).
Definition: mediaformat.h:28
The MediaFileInfo class allows to read and write tag information providing a container/tag format ind...
Definition: mediafileinfo.h:44
OggParameter & oggParams()
Returns the OGG parameter for the comment.
Definition: oggcontainer.h:110
bool supportsTarget() const override
Returns true; the target is used to specifiy the stream.
Definition: oggcontainer.h:99
Implementation of TagParser::AbstractTrack for OGG streams.
Definition: oggstream.h:13
std::size_t lastSegmentIndex
Definition: oggcontainer.h:34
Implementation of TagParser::Tag for Vorbis comments.
Definition: vorbiscomment.h:25
constexpr TAG_PARSER_EXPORT const char * comment()
Implementation of TagParser::AbstractContainer for OGG files.
Definition: oggcontainer.h:126
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
Contains utility classes helping to read and write streams.
std::size_t firstSegmentIndex
Definition: oggcontainer.h:32
void setChecksumValidationEnabled(bool enabled)
Sets whether checksum validation is enabled.
Definition: oggcontainer.h:178
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:21
constexpr OggParameter()
Creates new parameters.
Definition: oggcontainer.h:44
The AbortableProgressFeedback class provides feedback about an ongoing operation via callbacks...
std::size_t lastPageIndex
Definition: oggcontainer.h:33
GeneralMediaFormat streamFormat
Definition: oggcontainer.h:35
TagType
Specifies the tag type.
Definition: tag.h:20
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
std::size_t firstPageIndex
Definition: oggcontainer.h:31
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...