@@ -92,11 +92,13 @@ void Matroska::Tag::addSimpleTag(const SimpleTag &tag)
9292}
9393
9494void Matroska::Tag::removeSimpleTag (const String &name,
95- SimpleTag::TargetTypeValue targetTypeValue)
95+ SimpleTag::TargetTypeValue targetTypeValue,
96+ unsigned long long trackUid)
9697{
9798 auto it = std::find_if (d->tags .begin (), d->tags .end (),
98- [&name, targetTypeValue](const SimpleTag &t) {
99- return t.name () == name && t.targetTypeValue () == targetTypeValue;
99+ [&name, targetTypeValue, trackUid](const SimpleTag &t) {
100+ return t.name () == name && t.targetTypeValue () == targetTypeValue &&
101+ t.trackUid () == trackUid;
100102 }
101103 );
102104 if (it != d->tags .end ()) {
@@ -221,11 +223,13 @@ ByteVector Matroska::Tag::renderInternal()
221223 // Build target-based list
222224 for (const auto &tag : std::as_const (d->tags )) {
223225 auto targetTypeValue = tag.targetTypeValue ();
226+ auto trackUid = tag.trackUid ();
224227 auto it = std::find_if (targetList.begin (),
225228 targetList.end (),
226229 [&](const auto &list) {
227230 const auto &simpleTag = list.front ();
228- return simpleTag.targetTypeValue () == targetTypeValue;
231+ return simpleTag.targetTypeValue () == targetTypeValue &&
232+ simpleTag.trackUid () == trackUid;
229233 }
230234 );
231235 if (it == targetList.end ()) {
@@ -239,6 +243,7 @@ ByteVector Matroska::Tag::renderInternal()
239243 for (const auto &list : targetList) {
240244 const auto &frontTag = list.front ();
241245 auto targetTypeValue = frontTag.targetTypeValue ();
246+ auto trackUid = frontTag.trackUid ();
242247 auto tag = EBML::make_unique_element<EBML::Element::Id::MkTag>();
243248
244249 // Build <Tag Targets> element
@@ -248,6 +253,11 @@ ByteVector Matroska::Tag::renderInternal()
248253 element->setValue (static_cast <unsigned int >(targetTypeValue));
249254 targets->appendElement (std::move (element));
250255 }
256+ if (trackUid != 0 ) {
257+ auto element = EBML::make_unique_element<EBML::Element::Id::MkTagTrackUID>();
258+ element->setValue (trackUid);
259+ targets->appendElement (std::move (element));
260+ }
251261 tag->appendElement (std::move (targets));
252262
253263 // Build <Simple Tag> element
@@ -401,7 +411,8 @@ String Matroska::Tag::TagPrivate::getTag(const String &key) const
401411 return t.name () == name
402412 && t.type () == SimpleTag::StringType
403413 && (t.targetTypeValue () == targetTypeValue ||
404- (t.targetTypeValue () == SimpleTag::TargetTypeValue::None && !strict));
414+ (t.targetTypeValue () == SimpleTag::TargetTypeValue::None && !strict))
415+ && t.trackUid () == 0 ;
405416 }
406417 );
407418 return it != tags.end () ? it->toString () : String ();
@@ -411,7 +422,7 @@ PropertyMap Matroska::Tag::properties() const
411422{
412423 PropertyMap properties;
413424 for (const auto &simpleTag : std::as_const (d->tags )) {
414- if (simpleTag.type () == SimpleTag::StringType) {
425+ if (simpleTag.type () == SimpleTag::StringType && simpleTag. trackUid () == 0 ) {
415426 String key = translateTag (simpleTag.name (), simpleTag.targetTypeValue ());
416427 if (!key.isEmpty ())
417428 properties[key].append (simpleTag.toString ());
@@ -428,6 +439,7 @@ PropertyMap Matroska::Tag::setProperties(const PropertyMap &propertyMap)
428439 for (auto it = d->tags .begin (); it != d->tags .end ();) {
429440 String key;
430441 if (it->type () == SimpleTag::StringType &&
442+ it->trackUid () == 0 &&
431443 !(key = translateTag (it->name (), it->targetTypeValue ())).isEmpty ()) {
432444 it = d->tags .erase (it);
433445 setNeedsRender (true );
@@ -468,6 +480,7 @@ StringList Matroska::Tag::complexPropertyKeys() const
468480 StringList keys;
469481 for (const SimpleTag &t : std::as_const (d->tags )) {
470482 if (t.type () != SimpleTag::StringType ||
483+ t.trackUid () != 0 ||
471484 translateTag (t.name (), t.targetTypeValue ()).isEmpty ()) {
472485 keys.append (t.name ());
473486 }
@@ -482,6 +495,7 @@ List<VariantMap> Matroska::Tag::complexProperties(const String& key) const
482495 for (const SimpleTag &t : std::as_const (d->tags )) {
483496 if (t.name () == key &&
484497 (t.type () != SimpleTag::StringType ||
498+ t.trackUid () != 0 ||
485499 translateTag (t.name (), t.targetTypeValue ()).isEmpty ())) {
486500 VariantMap property;
487501 if (t.type () != SimpleTag::StringType) {
@@ -491,7 +505,12 @@ List<VariantMap> Matroska::Tag::complexProperties(const String& key) const
491505 property.insert (" value" , t.toString ());
492506 }
493507 property.insert (" name" , t.name ());
494- property.insert (" targetTypeValue" , t.targetTypeValue ());
508+ if (t.targetTypeValue () != SimpleTag::TargetTypeValue::None) {
509+ property.insert (" targetTypeValue" , t.targetTypeValue ());
510+ }
511+ if (t.trackUid ()) {
512+ property.insert (" trackUid" , t.trackUid ());
513+ }
495514 property.insert (" language" , t.language ());
496515 property.insert (" defaultLanguage" , t.defaultLanguageFlag ());
497516 props.append (property);
@@ -511,6 +530,7 @@ bool Matroska::Tag::setComplexProperties(const String& key, const List<VariantMa
511530 [&key](const SimpleTag &t) {
512531 return t.name () == key &&
513532 (t.type () != SimpleTag::StringType ||
533+ t.trackUid () != 0 ||
514534 translateTag (t.name (), t.targetTypeValue ()).isEmpty ());
515535 }
516536 );
@@ -535,11 +555,12 @@ bool Matroska::Tag::setComplexProperties(const String& key, const List<VariantMa
535555 }
536556 auto language = property.value (" language" ).value <String>();
537557 bool defaultLanguage = property.value (" defaultLanguage" , true ).value <bool >();
558+ auto trackUid = property.value (" trackUid" , 0ULL ).value <unsigned long long >();
538559 d->tags .append (property.contains (" data" )
539560 ? SimpleTag (key, property.value (" data" ).value <ByteVector>(),
540- targetTypeValue, language, defaultLanguage)
561+ targetTypeValue, language, defaultLanguage, trackUid )
541562 : SimpleTag (key, property.value (" value" ).value <String>(),
542- targetTypeValue, language, defaultLanguage));
563+ targetTypeValue, language, defaultLanguage, trackUid ));
543564 setNeedsRender (true );
544565 result = true ;
545566 }
0 commit comments