@@ -349,6 +349,7 @@ func (period *Period) addAdaptationSet(as *AdaptationSet) error {
349349// Adds a ContentProtection tag at the root level of an AdaptationSet.
350350// This ContentProtection tag does not include signaling for any particular DRM scheme.
351351// defaultKIDHex - Default Key ID as a Hex String.
352+ // Deprecated: This function improperly formats UUIDs, use AddNewContentProtectionRoot2 instead.
352353func (as * AdaptationSet ) AddNewContentProtectionRoot (defaultKIDHex string ) (* CENCContentProtection , error ) {
353354 if len (defaultKIDHex ) != 32 || defaultKIDHex == "" {
354355 return nil , ErrInvalidDefaultKID
@@ -371,6 +372,31 @@ func (as *AdaptationSet) AddNewContentProtectionRoot(defaultKIDHex string) (*CEN
371372 return cp , nil
372373}
373374
375+ // Adds a ContentProtection tag at the root level of an AdaptationSet.
376+ // This ContentProtection tag does not include signaling for any particular DRM scheme.
377+ // defaultKIDHex - Default Key ID as a Hex String.
378+ func (as * AdaptationSet ) AddNewContentProtectionRoot2 (defaultKIDHex string ) (* CENCContentProtection , error ) {
379+ if len (defaultKIDHex ) != 32 || defaultKIDHex == "" {
380+ return nil , ErrInvalidDefaultKID
381+ }
382+ 383+ // Convert the KID into the correct format
384+ defaultKID := strings .ToLower (defaultKIDHex [0 :8 ] + "-" + defaultKIDHex [8 :12 ] + "-" + defaultKIDHex [12 :16 ] + "-" + defaultKIDHex [16 :20 ] + "-" + defaultKIDHex [20 :32 ])
385+ 386+ cp := & CENCContentProtection {
387+ DefaultKID : Strptr (defaultKID ),
388+ Value : Strptr (CONTENT_PROTECTION_ROOT_VALUE ),
389+ }
390+ cp .SchemeIDURI = Strptr (CONTENT_PROTECTION_ROOT_SCHEME_ID_URI )
391+ cp .XMLNS = Strptr (CENC_XMLNS )
392+ 393+ err := as .AddContentProtection (cp )
394+ if err != nil {
395+ return nil , err
396+ }
397+ return cp , nil
398+ }
399+ 374400// AddNewContentProtectionSchemeWidevine adds a new content protection scheme for Widevine DRM to the adaptation set. With
375401// a <cenc:pssh> element that contains a Base64 encoded PSSH box
376402// wvHeader - binary representation of Widevine Header
0 commit comments