Tag Parser  6.4.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 MEDIA_OGGCONTAINER_H
2 #define MEDIA_OGGCONTAINER_H
3 
4 #include "./oggpage.h"
5 #include "./oggstream.h"
6 #include "./oggiterator.h"
7 
8 #include "../vorbis/vorbiscomment.h"
9 
10 #include "../genericcontainer.h"
11 
12 #include <unordered_map>
13 #include <tuple>
14 
15 namespace IoUtilities {
16 template<std::size_t bufferSize>
17 class CopyHelper;
18 }
19 
20 namespace Media {
21 
22 class MediaFileInfo;
23 class OggContainer;
24 
29 {
30  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;
39  bool removed;
40 };
41 
46 inline OggParameter::OggParameter() :
47  firstPageIndex(0),
48  firstSegmentIndex(0),
49  lastPageIndex(0),
50  lastSegmentIndex(0),
51  lastMetaDataBlock(false),
52  streamFormat(GeneralMediaFormat::Vorbis),
53  removed(false)
54 {}
55 
60 inline void OggParameter::set(std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat streamFormat)
61 {
62  firstPageIndex = lastPageIndex = pageIndex;
63  firstSegmentIndex = lastSegmentIndex = segmentIndex;
64  this->lastMetaDataBlock = lastMetaDataBlock;
65  this->streamFormat = streamFormat;
66 }
67 
69 {
70  friend class OggContainer;
71 
72 public:
74  TagType type() const;
75  const char *typeName() const;
76  bool supportsTarget() const;
77 
78  OggParameter &oggParams();
79  const OggParameter &oggParams() const;
80 
81 private:
82  OggParameter m_oggParams;
83 };
84 
89 {}
90 
92 {
94 }
95 
101 {
102  return true;
103 }
104 
112 {
113  return m_oggParams;
114 }
115 
123 {
124  return m_oggParams;
125 }
126 
127 class TAG_PARSER_EXPORT OggContainer : public GenericContainer<MediaFileInfo, OggVorbisComment, OggStream, OggPage>
128 {
129  friend class OggStream;
130 
131 public:
132  OggContainer(MediaFileInfo &fileInfo, uint64 startOffset);
133  ~OggContainer();
134 
135  bool isChecksumValidationEnabled() const;
136  void setChecksumValidationEnabled(bool enabled);
137  void reset();
138 
139  OggVorbisComment *createTag(const TagTarget &target);
140  OggVorbisComment *tag(std::size_t index);
141  std::size_t tagCount() const;
142  bool removeTag(Tag *tag);
143  void removeAllTags();
144 
145 protected:
146  void internalParseHeader();
147  void internalParseTags();
148  void internalParseTracks();
149  void internalMakeFile();
150 
151 private:
152  void announceComment(std::size_t pageIndex, std::size_t segmentIndex, bool lastMetaDataBlock, GeneralMediaFormat mediaFormat = GeneralMediaFormat::Vorbis);
153  void makeVorbisCommentSegment(std::stringstream &buffer, IoUtilities::CopyHelper<65307> &copyHelper, std::vector<uint32> &newSegmentSizes, VorbisComment *comment, OggParameter *params);
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 }
184 
185 #endif // MEDIA_OGGCONTAINER_H
GeneralMediaFormat
The GeneralMediaFormat enum specifies the general format of media data (PCM, MPEG-4, PNG, ...).
Definition: mediaformat.h:29
void setChecksumValidationEnabled(bool enabled)
Sets whether checksum validation is enabled.
Definition: oggcontainer.h:178
Implementation of Media::Tag for Vorbis comments.
Definition: vorbiscomment.h:15
OggParameter & oggParams()
Returns the OGG parameter for the comment.
Definition: oggcontainer.h:111
The GenericContainer class helps parsing header, track, tag and chapter information of a file...
Specialization of Media::VorbisComment for Vorbis comments inside an OGG stream.
Definition: oggcontainer.h:68
std::size_t lastSegmentIndex
Definition: oggcontainer.h:36
GeneralMediaFormat streamFormat
Definition: oggcontainer.h:38
Contains utility classes helping to read and write streams.
std::size_t firstPageIndex
Definition: oggcontainer.h:33
Implementation of Media::AbstractTrack for OGG streams.
Definition: oggstream.h:13
The Tag class is used to store, read and write tag information.
Definition: tag.h:98
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:60
bool isChecksumValidationEnabled() const
Returns whether checksum validation is enabled.
Definition: oggcontainer.h:169
TagType type() const
Returns the type of the tag as Media::TagType.
Definition: oggcontainer.h:91
bool supportsTarget() const
Returns true; the target is used to specifiy the stream.
Definition: oggcontainer.h:100
The MediaFileInfo class allows to read and write tag information providing a container/tag format ind...
Definition: mediafileinfo.h:53
TagType
Specifies the tag type.
Definition: tag.h:21
OggVorbisComment()
Constructs a new OGG Vorbis comment.
Definition: oggcontainer.h:88
Implementation of Media::AbstractContainer for OGG files.
Definition: oggcontainer.h:127
The OggIterator class helps iterating through all segments of an OGG bitstream.
Definition: oggiterator.h:11
std::size_t firstSegmentIndex
Definition: oggcontainer.h:34
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:31
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
The OggParameter struct holds the OGG parameter for a VorbisComment.
Definition: oggcontainer.h:28
std::size_t lastPageIndex
Definition: oggcontainer.h:35
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
TAG_PARSER_EXPORT const char * comment()