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" )
@@ -117,46 +125,48 @@ type CommonAttributesAndElements struct {
117125
118126type AdaptationSet struct {
119127 CommonAttributesAndElements
120- XMLName xml.Name `xml:"AdaptationSet"`
121- ID * string `xml:"id,attr"`
122- SegmentAlignment * bool `xml:"segmentAlignment,attr"`
123- Lang * string `xml:"lang,attr"`
124- Group * string `xml:"group,attr"`
125- PAR * string `xml:"par,attr"`
126- MinBandwidth * string `xml:"minBandwidth,attr"`
127- MaxBandwidth * string `xml:"maxBandwidth,attr"`
128- MinWidth * string `xml:"minWidth,attr"`
129- MaxWidth * string `xml:"maxWidth,attr"`
130- ContentType * string `xml:"contentType,attr"`
131- ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
132- Roles []* Role `xml:"Role,omitempty"`
133- SegmentBase * SegmentBase `xml:"SegmentBase,omitempty"`
134- SegmentList * SegmentList `xml:"SegmentList,omitempty"`
135- SegmentTemplate * SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
136- Representations []* Representation `xml:"Representation,omitempty"`
128+ XMLName xml.Name `xml:"AdaptationSet"`
129+ ID * string `xml:"id,attr"`
130+ SegmentAlignment * bool `xml:"segmentAlignment,attr"`
131+ Lang * string `xml:"lang,attr"`
132+ Group * string `xml:"group,attr"`
133+ PAR * string `xml:"par,attr"`
134+ MinBandwidth * string `xml:"minBandwidth,attr"`
135+ MaxBandwidth * string `xml:"maxBandwidth,attr"`
136+ MinWidth * string `xml:"minWidth,attr"`
137+ MaxWidth * string `xml:"maxWidth,attr"`
138+ ContentType * string `xml:"contentType,attr"`
139+ ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
140+ Roles []* Role `xml:"Role,omitempty"`
141+ SegmentBase * SegmentBase `xml:"SegmentBase,omitempty"`
142+ SegmentList * SegmentList `xml:"SegmentList,omitempty"`
143+ SegmentTemplate * SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
144+ Representations []* Representation `xml:"Representation,omitempty"`
145+ AccessibilityElems []* Accessibility `xml:"Accessibility,omitempty"`
137146}
138147
139148func (as * AdaptationSet ) UnmarshalXML (d * xml.Decoder , start xml.StartElement ) error {
140149
141150 adaptationSet := struct {
142151 CommonAttributesAndElements
143- XMLName xml.Name `xml:"AdaptationSet"`
144- ID * string `xml:"id,attr"`
145- SegmentAlignment * bool `xml:"segmentAlignment,attr"`
146- Lang * string `xml:"lang,attr"`
147- Group * string `xml:"group,attr"`
148- PAR * string `xml:"par,attr"`
149- MinBandwidth * string `xml:"minBandwidth,attr"`
150- MaxBandwidth * string `xml:"maxBandwidth,attr"`
151- MinWidth * string `xml:"minWidth,attr"`
152- MaxWidth * string `xml:"maxWidth,attr"`
153- ContentType * string `xml:"contentType,attr"`
154- ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
155- Roles []* Role `xml:"Role,omitempty"`
156- SegmentBase * SegmentBase `xml:"SegmentBase,omitempty"`
157- SegmentList * SegmentList `xml:"SegmentList,omitempty"`
158- SegmentTemplate * SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
159- Representations []* Representation `xml:"Representation,omitempty"`
152+ XMLName xml.Name `xml:"AdaptationSet"`
153+ ID * string `xml:"id,attr"`
154+ SegmentAlignment * bool `xml:"segmentAlignment,attr"`
155+ Lang * string `xml:"lang,attr"`
156+ Group * string `xml:"group,attr"`
157+ PAR * string `xml:"par,attr"`
158+ MinBandwidth * string `xml:"minBandwidth,attr"`
159+ MaxBandwidth * string `xml:"maxBandwidth,attr"`
160+ MinWidth * string `xml:"minWidth,attr"`
161+ MaxWidth * string `xml:"maxWidth,attr"`
162+ ContentType * string `xml:"contentType,attr"`
163+ ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
164+ Roles []* Role `xml:"Role,omitempty"`
165+ SegmentBase * SegmentBase `xml:"SegmentBase,omitempty"`
166+ SegmentList * SegmentList `xml:"SegmentList,omitempty"`
167+ SegmentTemplate * SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
168+ Representations []* Representation `xml:"Representation,omitempty"`
169+ AccessibilityElems []* Accessibility `xml:"Accessibility,omitempty"`
160170 }{}
161171
162172 var (
@@ -240,8 +250,14 @@ func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er
240250 return err
241251 }
242252 representations = append (representations , rp )
253+ case "Accessibility" :
254+ ac := new (Accessibility )
255+ err = d .DecodeElement (ac , & tt )
256+ if err != nil {
257+ return err
258+ }
243259 default :
244- return errors . New ( "Unrecognized element in AdaptationSet" )
260+ return fmt . Errorf ( "unrecognized element in AdaptationSet %q" , tt . Name . Local )
245261 }
246262 case xml.EndElement :
247263 if tt == start .End () {
@@ -435,6 +451,12 @@ type Representation struct {
435451 SegmentTemplate * SegmentTemplate `xml:"SegmentTemplate,omitempty"`
436452}
437453
454+ type Accessibility struct {
455+ AdaptationSet * AdaptationSet `xml:"-"`
456+ SchemeIdUri * string `xml:"schemeIdUri,attr,omitempty"`
457+ Value * string `xml:"value,attr,omitempty"`
458+ }
459+ 438460type AudioChannelConfiguration struct {
439461 SchemeIDURI * string `xml:"schemeIdUri,attr"`
440462 // Value will be an int for non-Dolby Schemes, and a hexstring for Dolby Schemes, hence we make it a string
@@ -1019,6 +1041,16 @@ func (as *AdaptationSet) addRepresentation(r *Representation) error {
10191041 return nil
10201042}
10211043
1044+ // Internal helper method for adding an Accessibility element to an AdaptationSet.
1045+ func (as * AdaptationSet ) addAccessibility (a * Accessibility ) error {
1046+ if a == nil {
1047+ return ErrAccessibilityNil
1048+ }
1049+ a .AdaptationSet = as
1050+ as .AccessibilityElems = append (as .AccessibilityElems , a )
1051+ return nil
1052+ }
1053+ 10221054// Adds a new Role to an AdaptationSet
10231055// schemeIdUri - Scheme ID URI string (i.e. urn:mpeg:dash:role:2011)
10241056// value - Value for this role, (i.e. caption, subtitle, main, alternate, supplementary, commentary, dub)
@@ -1032,6 +1064,23 @@ func (as *AdaptationSet) AddNewRole(schemeIDURI string, value string) (*Role, er
10321064 return r , nil
10331065}
10341066
1067+ // AddNewAccessibilityElement adds a new accessibility element to an adaptation set
1068+ // schemeIdUri - Scheme ID URI for the Accessibility element (i.e. urn:tva:metadata:cs:AudioPurposeCS:2007)
1069+ // value - specified value based on scheme
1070+ func (as * AdaptationSet ) AddNewAccessibilityElement (scheme AccessibilityElementScheme , val string ) (* Accessibility , error ) {
1071+ accessibility := & Accessibility {
1072+ SchemeIdUri : Strptr ((string )(scheme )),
1073+ Value : Strptr (val ),
1074+ }
1075+ 1076+ err := as .addAccessibility (accessibility )
1077+ if err != nil {
1078+ return nil , err
1079+ }
1080+ 1081+ return accessibility , nil
1082+ }
1083+ 10351084// Sets the BaseURL for a Representation.
10361085// baseURL - Base URL as a string (i.e. 800k/output-audio-und.mp4)
10371086func (r * Representation ) SetNewBaseURL (baseURL string ) error {
0 commit comments