Tag Parser  7.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  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  , lastMetaDataBlock(false)
50  , streamFormat(GeneralMediaFormat::Vorbis)
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;
73  const char *typeName() const;
74  bool supportsTarget() const;
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
bool isChecksumValidationEnabled() const
Returns whether checksum validation is enabled.
Definition: oggcontainer.h:169
OggVorbisComment()
Constructs a new OGG Vorbis comment.
Definition: oggcontainer.h:86
The OggParameter struct holds the OGG parameter for a VorbisComment.
Definition: oggcontainer.h:27
bool supportsTarget() const
Returns true; the target is used to specifiy the stream.
Definition: oggcontainer.h:99
GeneralMediaFormat
The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4, PNG, ...).
Definition: mediaformat.h:28
TAG_PARSER_EXPORT const char * comment()
OggParameter & oggParams()
Returns the OGG parameter for the comment.
Definition: oggcontainer.h:110
std::size_t lastSegmentIndex
Definition: oggcontainer.h:34
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
TagType type() const
Returns the type of the tag as Media::TagType.
Definition: oggcontainer.h:90
std::size_t lastPageIndex
Definition: oggcontainer.h:33
GeneralMediaFormat streamFormat
Definition: oggcontainer.h:36
TagType
Specifies the tag type.
Definition: tag.h:20
OggParameter()
Creates new parameters.
Definition: oggcontainer.h:44
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
std::size_t firstPageIndex
Definition: oggcontainer.h:31