Skip to content

Commit 3db0d48

Browse files
authored
Support edition, chapter and attachment UIDs in Matroska simple tags (#1311)
1 parent de6e2b1 commit 3db0d48

9 files changed

Lines changed: 257 additions & 20 deletions

File tree

examples/matroskareader.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ int main(int argc, char *argv[])
5151
TagLib::Utils::formatString("%llu",trackUid).toCString(false)
5252
);
5353
}
54+
if(auto editionUid = t.editionUid()) {
55+
PRINT_PRETTY("Edition UID",
56+
TagLib::Utils::formatString("%llu",editionUid).toCString(false)
57+
);
58+
}
59+
if(auto chapterUid = t.chapterUid()) {
60+
PRINT_PRETTY("Chapter UID",
61+
TagLib::Utils::formatString("%llu",chapterUid).toCString(false)
62+
);
63+
}
64+
if(auto attachmentUid = t.attachmentUid()) {
65+
PRINT_PRETTY("Attachment UID",
66+
TagLib::Utils::formatString("%llu",attachmentUid).toCString(false)
67+
);
68+
}
5469
const TagLib::String &language = t.language();
5570
PRINT_PRETTY("Language", !language.isEmpty() ? language.toCString(false) : "Not set");
5671

taglib/matroska/ebml/ebmlelement.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ std::unique_ptr<EBML::Element> EBML::Element::factory(File &file)
8484
RETURN_ELEMENT_FOR_CASE(Id::MkCodecID);
8585
RETURN_ELEMENT_FOR_CASE(Id::MkTagTargetTypeValue);
8686
RETURN_ELEMENT_FOR_CASE(Id::MkTagTrackUID);
87+
RETURN_ELEMENT_FOR_CASE(Id::MkTagEditionUID);
88+
RETURN_ELEMENT_FOR_CASE(Id::MkTagChapterUID);
89+
RETURN_ELEMENT_FOR_CASE(Id::MkTagAttachmentUID);
8790
RETURN_ELEMENT_FOR_CASE(Id::MkTagsLanguageDefault);
8891
RETURN_ELEMENT_FOR_CASE(Id::MkAttachedFileUID);
8992
RETURN_ELEMENT_FOR_CASE(Id::MkSeekPosition);

taglib/matroska/ebml/ebmlelement.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ namespace TagLib
4848
MkTagTargets = 0x63C0,
4949
MkTagTargetTypeValue = 0x68CA,
5050
MkTagTrackUID = 0x63C5,
51+
MkTagEditionUID = 0x63C9,
52+
MkTagChapterUID = 0x63C4,
53+
MkTagAttachmentUID = 0x63C6,
5154
MkSimpleTag = 0x67C8,
5255
MkTagName = 0x45A3,
5356
MkTagLanguage = 0x447A,
@@ -181,6 +184,9 @@ namespace TagLib
181184
template <> struct GetElementTypeById<Element::Id::MkCodecID> { using type = Latin1StringElement; };
182185
template <> struct GetElementTypeById<Element::Id::MkTagTargetTypeValue> { using type = UIntElement; };
183186
template <> struct GetElementTypeById<Element::Id::MkTagTrackUID> { using type = UIntElement; };
187+
template <> struct GetElementTypeById<Element::Id::MkTagEditionUID> { using type = UIntElement; };
188+
template <> struct GetElementTypeById<Element::Id::MkTagChapterUID> { using type = UIntElement; };
189+
template <> struct GetElementTypeById<Element::Id::MkTagAttachmentUID> { using type = UIntElement; };
184190
template <> struct GetElementTypeById<Element::Id::MkAttachedFileUID> { using type = UIntElement; };
185191
template <> struct GetElementTypeById<Element::Id::MkSeekPosition> { using type = UIntElement; };
186192
template <> struct GetElementTypeById<Element::Id::MkTimestampScale> { using type = UIntElement; };

taglib/matroska/ebml/ebmlmktags.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ std::unique_ptr<Matroska::Tag> EBML::MkTags::parse() const
6969
// Parse the <Targets> element
7070
Matroska::SimpleTag::TargetTypeValue targetTypeValue = Matroska::SimpleTag::TargetTypeValue::None;
7171
unsigned long long trackUid = 0;
72+
unsigned long long edtionUid = 0;
73+
unsigned long long chapterUid = 0;
74+
unsigned long long attachmentUid = 0;
7275
if(targets) {
7376
for(const auto &targetsChild : *targets) {
7477
if(const Id id = targetsChild->getId(); id == Id::MkTagTargetTypeValue
@@ -80,6 +83,15 @@ std::unique_ptr<Matroska::Tag> EBML::MkTags::parse() const
8083
else if(id == Id::MkTagTrackUID) {
8184
trackUid = element_cast<Id::MkTagTrackUID>(targetsChild)->getValue();
8285
}
86+
else if(id == Id::MkTagEditionUID) {
87+
edtionUid = element_cast<Id::MkTagEditionUID>(targetsChild)->getValue();
88+
}
89+
else if(id == Id::MkTagChapterUID) {
90+
chapterUid = element_cast<Id::MkTagChapterUID>(targetsChild)->getValue();
91+
}
92+
else if(id == Id::MkTagAttachmentUID) {
93+
attachmentUid = element_cast<Id::MkTagAttachmentUID>(targetsChild)->getValue();
94+
}
8395
}
8496
}
8597

@@ -109,10 +121,10 @@ std::unique_ptr<Matroska::Tag> EBML::MkTags::parse() const
109121
mTag->addSimpleTag(tagValueString
110122
? Matroska::SimpleTag(tagName, *tagValueString,
111123
targetTypeValue, language, defaultLanguageFlag,
112-
trackUid)
124+
trackUid, edtionUid, chapterUid, attachmentUid)
113125
: Matroska::SimpleTag(tagName, *tagValueBinary,
114126
targetTypeValue, language, defaultLanguageFlag,
115-
trackUid));
127+
trackUid, edtionUid, chapterUid, attachmentUid));
116128
}
117129
}
118130
return mTag;

taglib/matroska/matroskasimpletag.cpp

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,26 @@ class Matroska::SimpleTag::SimpleTagPrivate
3030
public:
3131
SimpleTagPrivate(const String &name, const String &value,
3232
TargetTypeValue targetTypeValue, const String &language, bool defaultLanguage,
33-
unsigned long long trackUid) :
33+
unsigned long long trackUid, unsigned long long editionUid,
34+
unsigned long long chapterUid, unsigned long long attachmentUid) :
3435
value(value), name(name), language(language), trackUid(trackUid),
36+
editionUid(editionUid), chapterUid(chapterUid), attachmentUid(attachmentUid),
3537
targetTypeValue(targetTypeValue), defaultLanguageFlag(defaultLanguage) {}
3638
SimpleTagPrivate(const String &name, const ByteVector &value,
3739
TargetTypeValue targetTypeValue, const String &language, bool defaultLanguage,
38-
unsigned long long trackUid) :
40+
unsigned long long trackUid, unsigned long long editionUid,
41+
unsigned long long chapterUid, unsigned long long attachmentUid) :
3942
value(value), name(name), language(language), trackUid(trackUid),
43+
editionUid(editionUid), chapterUid(chapterUid), attachmentUid(attachmentUid),
4044
targetTypeValue(targetTypeValue), defaultLanguageFlag(defaultLanguage) {}
4145

4246
const std::variant<String, ByteVector> value;
4347
const String name;
4448
const String language;
4549
const unsigned long long trackUid;
50+
const unsigned long long editionUid;
51+
const unsigned long long chapterUid;
52+
const unsigned long long attachmentUid;
4653
const TargetTypeValue targetTypeValue;
4754
const bool defaultLanguageFlag;
4855
};
@@ -56,7 +63,19 @@ Matroska::SimpleTag::SimpleTag(const String &name, const String &value,
5663
const String &language, bool defaultLanguage,
5764
unsigned long long trackUid) :
5865
d(std::make_unique<SimpleTagPrivate>(name, value, targetTypeValue,
59-
language, defaultLanguage, trackUid))
66+
language, defaultLanguage, trackUid, 0, 0, 0))
67+
{
68+
}
69+
70+
Matroska::SimpleTag::SimpleTag(const String &name, const String &value,
71+
TargetTypeValue targetTypeValue,
72+
const String &language, bool defaultLanguage,
73+
unsigned long long trackUid,
74+
unsigned long long editionUid,
75+
unsigned long long chapterUid,
76+
unsigned long long attachmentUid) :
77+
d(std::make_unique<SimpleTagPrivate>(name, value, targetTypeValue,
78+
language, defaultLanguage, trackUid, editionUid, chapterUid, attachmentUid))
6079
{
6180
}
6281

@@ -65,7 +84,19 @@ Matroska::SimpleTag::SimpleTag(const String &name, const ByteVector &value,
6584
const String &language, bool defaultLanguage,
6685
unsigned long long trackUid) :
6786
d(std::make_unique<SimpleTagPrivate>(name, value, targetTypeValue,
68-
language, defaultLanguage, trackUid))
87+
language, defaultLanguage, trackUid, 0, 0, 0))
88+
{
89+
}
90+
91+
Matroska::SimpleTag::SimpleTag(const String &name, const ByteVector &value,
92+
TargetTypeValue targetTypeValue,
93+
const String &language, bool defaultLanguage,
94+
unsigned long long trackUid,
95+
unsigned long long editionUid,
96+
unsigned long long chapterUid,
97+
unsigned long long attachmentUid) :
98+
d(std::make_unique<SimpleTagPrivate>(name, value, targetTypeValue,
99+
language, defaultLanguage, trackUid, editionUid, chapterUid, attachmentUid))
69100
{
70101
}
71102

@@ -118,6 +149,21 @@ unsigned long long Matroska::SimpleTag::trackUid() const
118149
return d->trackUid;
119150
}
120151

152+
unsigned long long Matroska::SimpleTag::editionUid() const
153+
{
154+
return d->editionUid;
155+
}
156+
157+
unsigned long long Matroska::SimpleTag::chapterUid() const
158+
{
159+
return d->chapterUid;
160+
}
161+
162+
unsigned long long Matroska::SimpleTag::attachmentUid() const
163+
{
164+
return d->attachmentUid;
165+
}
166+
121167
Matroska::SimpleTag::ValueType Matroska::SimpleTag::type() const
122168
{
123169
return std::holds_alternative<ByteVector>(d->value) ? BinaryType : StringType;

taglib/matroska/matroskasimpletag.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ namespace TagLib {
6060
const String &language = String(), bool defaultLanguage = true,
6161
unsigned long long trackUid = 0);
6262

63+
/*!
64+
* Construct a string simple tag.
65+
*/
66+
// BIC: merge with constructor above
67+
SimpleTag(const String& name, const String& value, TargetTypeValue targetTypeValue, const String& language,
68+
bool defaultLanguage, unsigned long long trackUid, unsigned long long editionUid,
69+
unsigned long long chapterUid = 0, unsigned long long attachmentUid = 0);
70+
6371
/*!
6472
* Construct a binary simple tag.
6573
*/
@@ -68,6 +76,14 @@ namespace TagLib {
6876
const String &language = String(), bool defaultLanguage = true,
6977
unsigned long long trackUid = 0);
7078

79+
/*!
80+
* Construct a binary simple tag.
81+
*/
82+
// BIC: merge with constructor above
83+
SimpleTag(const String& name, const ByteVector& value, TargetTypeValue targetTypeValue, const String& language,
84+
bool defaultLanguage, unsigned long long trackUid, unsigned long long editionUid,
85+
unsigned long long chapterUid = 0, unsigned long long attachmentUid = 0);
86+
7187
/*!
7288
* Construct a simple tag as a copy of \a other.
7389
*/
@@ -124,6 +140,24 @@ namespace TagLib {
124140
*/
125141
unsigned long long trackUid() const;
126142

143+
/*!
144+
* Returns the UID that identifies the edition that the tags belong to,
145+
* zero if not defined, the tag applies to all editions
146+
*/
147+
unsigned long long editionUid() const;
148+
149+
/*!
150+
* Returns the UID that identifies the chapter that the tags belong to,
151+
* zero if not defined, the tag applies to all chapters
152+
*/
153+
unsigned long long chapterUid() const;
154+
155+
/*!
156+
* Returns the UID that identifies the attachment that the tags belong to,
157+
* zero if not defined, the tag applies to all attachments
158+
*/
159+
unsigned long long attachmentUid() const;
160+
127161
/*!
128162
* Returns the type of the value.
129163
*/

0 commit comments

Comments
 (0)