55 "encoding/hex"
66 "encoding/xml"
77 "errors"
8+ "fmt"
89 "strings"
910 "time"
1011
@@ -33,6 +34,12 @@ const (
3334 AUDIO_CHANNEL_CONFIGURATION_MPEG_DOLBY AudioChannelConfigurationScheme = "tag:dolby.com,2014:dash:audio_channel_configuration:2011"
3435)
3536
37+ // AccessibilityElementScheme is the scheme definition for an Accessibility element
38+ type AccessibilityElementScheme string
39+
40+ // Accessibility descriptor values for Audio Description
41+ const ACCESSIBILITY_ELEMENT_SCHEME_DESCRIPTIVE_AUDIO AccessibilityElementScheme = "urn:tva:metadata:cs:AudioPurposeCS:2007"
42+
3643// Constants for some known MIME types, this is a limited list and others can be used.
3744const (
3845 DASH_MIME_TYPE_VIDEO_MP4 string = "video/mp4"
5057 ErrSegmentTemplateLiveProfileOnly = errors .New ("Segment template can only be used with Live Profile" )
5158 ErrSegmentTemplateNil = errors .New ("Segment Template nil " )
5259 ErrRepresentationNil = errors .New ("Representation nil" )
60+ ErrAccessibilityNil = errors .New ("Accessibility nil" )
5361 ErrBaseURLEmpty = errors .New ("Base URL empty" )
5462 ErrSegmentBaseOnDemandProfileOnly = errors .New ("Segment Base can only be used with On-Demand Profile" )
5563 ErrSegmentBaseNil = errors .New ("Segment Base nil" )
@@ -137,6 +145,7 @@ type AdaptationSet struct {
137145 SegmentList * SegmentList `xml:"SegmentList,omitempty"`
138146 SegmentTemplate * SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
139147 Representations []* Representation `xml:"Representation,omitempty"`
148+ AccessibilityElems []* Accessibility `xml:"Accessibility,omitempty"`
140149}
141150
142151func (as * AdaptationSet ) UnmarshalXML (d * xml.Decoder , start xml.StartElement ) error {
@@ -162,6 +171,7 @@ func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er
162171 SegmentList * SegmentList `xml:"SegmentList,omitempty"`
163172 SegmentTemplate * SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
164173 Representations []* Representation `xml:"Representation,omitempty"`
174+ AccessibilityElems []* Accessibility `xml:"Accessibility,omitempty"`
165175 }{}
166176
167177 var (
@@ -245,8 +255,14 @@ func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er
245255 return err
246256 }
247257 representations = append (representations , rp )
258+ case "Accessibility" :
259+ ac := new (Accessibility )
260+ err = d .DecodeElement (ac , & tt )
261+ if err != nil {
262+ return err
263+ }
248264 default :
249- return errors . New ( "Unrecognized element in AdaptationSet" )
265+ return fmt . Errorf ( "unrecognized element in AdaptationSet %q" , tt . Name . Local )
250266 }
251267 case xml.EndElement :
252268 if tt == start .End () {
@@ -440,6 +456,12 @@ type Representation struct {
440456 SegmentTemplate * SegmentTemplate `xml:"SegmentTemplate,omitempty"`
441457}
442458
459+ type Accessibility struct {
460+ AdaptationSet * AdaptationSet `xml:"-"`
461+ SchemeIdUri * string `xml:"schemeIdUri,attr,omitempty"`
462+ Value * string `xml:"value,attr,omitempty"`
463+ }
464+
443465type AudioChannelConfiguration struct {
444466 SchemeIDURI * string `xml:"schemeIdUri,attr"`
445467 // Value will be an int for non-Dolby Schemes, and a hexstring for Dolby Schemes, hence we make it a string
@@ -1024,6 +1046,16 @@ func (as *AdaptationSet) addRepresentation(r *Representation) error {
10241046 return nil
10251047}
10261048
1049+ // Internal helper method for adding an Accessibility element to an AdaptationSet.
1050+ func (as * AdaptationSet ) addAccessibility (a * Accessibility ) error {
1051+ if a == nil {
1052+ return ErrAccessibilityNil
1053+ }
1054+ a .AdaptationSet = as
1055+ as .AccessibilityElems = append (as .AccessibilityElems , a )
1056+ return nil
1057+ }
1058+
10271059// Adds a new Role to an AdaptationSet
10281060// schemeIdUri - Scheme ID URI string (i.e. urn:mpeg:dash:role:2011)
10291061// value - Value for this role, (i.e. caption, subtitle, main, alternate, supplementary, commentary, dub)
@@ -1037,6 +1069,23 @@ func (as *AdaptationSet) AddNewRole(schemeIDURI string, value string) (*Role, er
10371069 return r , nil
10381070}
10391071
1072+ // AddNewAccessibilityElement adds a new accessibility element to an adaptation set
1073+ // schemeIdUri - Scheme ID URI for the Accessibility element (i.e. urn:tva:metadata:cs:AudioPurposeCS:2007)
1074+ // value - specified value based on scheme
1075+ func (as * AdaptationSet ) AddNewAccessibilityElement (scheme AccessibilityElementScheme , val string ) (* Accessibility , error ) {
1076+ accessibility := & Accessibility {
1077+ SchemeIdUri : Strptr ((string )(scheme )),
1078+ Value : Strptr (val ),
1079+ }
1080+
1081+ err := as .addAccessibility (accessibility )
1082+ if err != nil {
1083+ return nil , err
1084+ }
1085+
1086+ return accessibility , nil
1087+ }
1088+
10401089// Sets the BaseURL for a Representation.
10411090// baseURL - Base URL as a string (i.e. 800k/output-audio-und.mp4)
10421091func (r * Representation ) SetNewBaseURL (baseURL string ) error {
0 commit comments