Skip to content

Commit 4c1e141

Browse files
authored
Merge pull request #74 from zencoder/mpd-location
Add support for MPD.Location
2 parents f16be35 + f35fb03 commit 4c1e141

File tree

3 files changed

+72
-38
lines changed

3 files changed

+72
-38
lines changed

mpd/fixtures/location.mpd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="dynamic" availabilityStartTime="1970-01-01T00:00:00Z" minimumUpdatePeriod="PT5S" publishTime="1970-01-01T00:00:00Z">
3+
<Location>https://example.com/location.mpd</Location>
4+
</MPD>

mpd/mpd.go

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type MPD struct {
7979
TimeShiftBufferDepth *string `xml:"timeShiftBufferDepth,attr"`
8080
SuggestedPresentationDelay *Duration `xml:"suggestedPresentationDelay,attr,omitempty"`
8181
BaseURL string `xml:"BaseURL,omitempty"`
82+
Location string `xml:"Location,omitempty"`
8283
period *Period
8384
Periods []*Period `xml:"Period,omitempty"`
8485
UTCTiming *DescriptorType `xml:"UTCTiming,omitempty"`
@@ -127,51 +128,51 @@ type CommonAttributesAndElements struct {
127128

128129
type AdaptationSet struct {
129130
CommonAttributesAndElements
130-
XMLName xml.Name `xml:"AdaptationSet"`
131-
ID *string `xml:"id,attr"`
132-
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
133-
Lang *string `xml:"lang,attr"`
134-
Group *string `xml:"group,attr"`
135-
PAR *string `xml:"par,attr"`
136-
MinBandwidth *string `xml:"minBandwidth,attr"`
137-
MaxBandwidth *string `xml:"maxBandwidth,attr"`
138-
MinWidth *string `xml:"minWidth,attr"`
139-
MaxWidth *string `xml:"maxWidth,attr"`
140-
MinHeight *string `xml:"minHeight,attr"`
141-
MaxHeight *string `xml:"maxHeight,attr"`
142-
ContentType *string `xml:"contentType,attr"`
143-
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
144-
Roles []*Role `xml:"Role,omitempty"`
145-
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
146-
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
147-
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
148-
Representations []*Representation `xml:"Representation,omitempty"`
131+
XMLName xml.Name `xml:"AdaptationSet"`
132+
ID *string `xml:"id,attr"`
133+
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
134+
Lang *string `xml:"lang,attr"`
135+
Group *string `xml:"group,attr"`
136+
PAR *string `xml:"par,attr"`
137+
MinBandwidth *string `xml:"minBandwidth,attr"`
138+
MaxBandwidth *string `xml:"maxBandwidth,attr"`
139+
MinWidth *string `xml:"minWidth,attr"`
140+
MaxWidth *string `xml:"maxWidth,attr"`
141+
MinHeight *string `xml:"minHeight,attr"`
142+
MaxHeight *string `xml:"maxHeight,attr"`
143+
ContentType *string `xml:"contentType,attr"`
144+
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
145+
Roles []*Role `xml:"Role,omitempty"`
146+
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
147+
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
148+
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
149+
Representations []*Representation `xml:"Representation,omitempty"`
149150
AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"`
150151
}
151152

152153
func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
153154

154155
adaptationSet := struct {
155156
CommonAttributesAndElements
156-
XMLName xml.Name `xml:"AdaptationSet"`
157-
ID *string `xml:"id,attr"`
158-
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
159-
Lang *string `xml:"lang,attr"`
160-
Group *string `xml:"group,attr"`
161-
PAR *string `xml:"par,attr"`
162-
MinBandwidth *string `xml:"minBandwidth,attr"`
163-
MaxBandwidth *string `xml:"maxBandwidth,attr"`
164-
MinWidth *string `xml:"minWidth,attr"`
165-
MaxWidth *string `xml:"maxWidth,attr"`
166-
MinHeight *string `xml:"minHeight,attr"`
167-
MaxHeight *string `xml:"maxHeight,attr"`
168-
ContentType *string `xml:"contentType,attr"`
169-
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
170-
Roles []*Role `xml:"Role,omitempty"`
171-
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
172-
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
173-
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
174-
Representations []*Representation `xml:"Representation,omitempty"`
157+
XMLName xml.Name `xml:"AdaptationSet"`
158+
ID *string `xml:"id,attr"`
159+
SegmentAlignment *bool `xml:"segmentAlignment,attr"`
160+
Lang *string `xml:"lang,attr"`
161+
Group *string `xml:"group,attr"`
162+
PAR *string `xml:"par,attr"`
163+
MinBandwidth *string `xml:"minBandwidth,attr"`
164+
MaxBandwidth *string `xml:"maxBandwidth,attr"`
165+
MinWidth *string `xml:"minWidth,attr"`
166+
MaxWidth *string `xml:"maxWidth,attr"`
167+
MinHeight *string `xml:"minHeight,attr"`
168+
MaxHeight *string `xml:"maxHeight,attr"`
169+
ContentType *string `xml:"contentType,attr"`
170+
ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here
171+
Roles []*Role `xml:"Role,omitempty"`
172+
SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"`
173+
SegmentList *SegmentList `xml:"SegmentList,omitempty"`
174+
SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only
175+
Representations []*Representation `xml:"Representation,omitempty"`
175176
AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"`
176177
}{}
177178

mpd/mpd_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
. "github.com/zencoder/go-dash/helpers/ptrs"
88
"github.com/zencoder/go-dash/helpers/require"
9+
"github.com/zencoder/go-dash/helpers/testfixtures"
910
)
1011

1112
const (
@@ -41,6 +42,7 @@ const (
4142
VALID_SUBTITLE_ID string = "subtitle_en"
4243
VALID_SUBTITLE_URL string = "http://example.com/content/sintel/subtitles/subtitles_en.vtt"
4344
VALID_ROLE string = "main"
45+
VALID_LOCATION string = "https://example.com/location.mpd"
4446
)
4547

4648
func TestNewMPDLive(t *testing.T) {
@@ -484,3 +486,30 @@ func TestAddNewAccessibilityElement(t *testing.T) {
484486
require.EqualStringPtr(t, Strptr((string)(ACCESSIBILITY_ELEMENT_SCHEME_DESCRIPTIVE_AUDIO)), elem.SchemeIdUri)
485487
require.EqualStringPtr(t, Strptr("1"), elem.Value)
486488
}
489+
490+
func TestLocationWriteToString(t *testing.T) {
491+
m := &MPD{
492+
XMLNs: Strptr("urn:mpeg:dash:schema:mpd:2011"),
493+
Profiles: Strptr((string)(DASH_PROFILE_LIVE)),
494+
Type: Strptr("dynamic"),
495+
AvailabilityStartTime: Strptr(VALID_AVAILABILITY_START_TIME),
496+
MinimumUpdatePeriod: Strptr(VALID_MINIMUM_UPDATE_PERIOD),
497+
PublishTime: Strptr(VALID_AVAILABILITY_START_TIME),
498+
Location: VALID_LOCATION,
499+
}
500+
501+
got, err := m.WriteToString()
502+
require.NoError(t, err)
503+
504+
testfixtures.CompareFixture(t, "fixtures/location.mpd", got)
505+
}
506+
507+
func TestReadLocation(t *testing.T) {
508+
m, err := ReadFromFile("fixtures/location.mpd")
509+
require.NoError(t, err)
510+
511+
got, err := m.WriteToString()
512+
require.NoError(t, err)
513+
514+
testfixtures.CompareFixture(t, "fixtures/location.mpd", got)
515+
}

0 commit comments

Comments
 (0)