diff --git a/mpd/fixtures/location.mpd b/mpd/fixtures/location.mpd new file mode 100644 index 0000000..2d1bff6 --- /dev/null +++ b/mpd/fixtures/location.mpd @@ -0,0 +1,4 @@ + + + https://example.com/location.mpd + diff --git a/mpd/mpd.go b/mpd/mpd.go index 3b786e7..0bcfb91 100644 --- a/mpd/mpd.go +++ b/mpd/mpd.go @@ -79,6 +79,7 @@ type MPD struct { TimeShiftBufferDepth *string `xml:"timeShiftBufferDepth,attr"` SuggestedPresentationDelay *Duration `xml:"suggestedPresentationDelay,attr,omitempty"` BaseURL string `xml:"BaseURL,omitempty"` + Location string `xml:"Location,omitempty"` period *Period Periods []*Period `xml:"Period,omitempty"` UTCTiming *DescriptorType `xml:"UTCTiming,omitempty"` @@ -127,25 +128,25 @@ type CommonAttributesAndElements struct { type AdaptationSet struct { CommonAttributesAndElements - XMLName xml.Name `xml:"AdaptationSet"` - ID *string `xml:"id,attr"` - SegmentAlignment *bool `xml:"segmentAlignment,attr"` - Lang *string `xml:"lang,attr"` - Group *string `xml:"group,attr"` - PAR *string `xml:"par,attr"` - MinBandwidth *string `xml:"minBandwidth,attr"` - MaxBandwidth *string `xml:"maxBandwidth,attr"` - MinWidth *string `xml:"minWidth,attr"` - MaxWidth *string `xml:"maxWidth,attr"` - MinHeight *string `xml:"minHeight,attr"` - MaxHeight *string `xml:"maxHeight,attr"` - ContentType *string `xml:"contentType,attr"` - ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here - Roles []*Role `xml:"Role,omitempty"` - SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"` - SegmentList *SegmentList `xml:"SegmentList,omitempty"` - SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only - Representations []*Representation `xml:"Representation,omitempty"` + XMLName xml.Name `xml:"AdaptationSet"` + ID *string `xml:"id,attr"` + SegmentAlignment *bool `xml:"segmentAlignment,attr"` + Lang *string `xml:"lang,attr"` + Group *string `xml:"group,attr"` + PAR *string `xml:"par,attr"` + MinBandwidth *string `xml:"minBandwidth,attr"` + MaxBandwidth *string `xml:"maxBandwidth,attr"` + MinWidth *string `xml:"minWidth,attr"` + MaxWidth *string `xml:"maxWidth,attr"` + MinHeight *string `xml:"minHeight,attr"` + MaxHeight *string `xml:"maxHeight,attr"` + ContentType *string `xml:"contentType,attr"` + ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here + Roles []*Role `xml:"Role,omitempty"` + SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"` + SegmentList *SegmentList `xml:"SegmentList,omitempty"` + SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only + Representations []*Representation `xml:"Representation,omitempty"` AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"` } @@ -153,25 +154,25 @@ func (as *AdaptationSet) UnmarshalXML(d *xml.Decoder, start xml.StartElement) er adaptationSet := struct { CommonAttributesAndElements - XMLName xml.Name `xml:"AdaptationSet"` - ID *string `xml:"id,attr"` - SegmentAlignment *bool `xml:"segmentAlignment,attr"` - Lang *string `xml:"lang,attr"` - Group *string `xml:"group,attr"` - PAR *string `xml:"par,attr"` - MinBandwidth *string `xml:"minBandwidth,attr"` - MaxBandwidth *string `xml:"maxBandwidth,attr"` - MinWidth *string `xml:"minWidth,attr"` - MaxWidth *string `xml:"maxWidth,attr"` - MinHeight *string `xml:"minHeight,attr"` - MaxHeight *string `xml:"maxHeight,attr"` - ContentType *string `xml:"contentType,attr"` - ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here - Roles []*Role `xml:"Role,omitempty"` - SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"` - SegmentList *SegmentList `xml:"SegmentList,omitempty"` - SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only - Representations []*Representation `xml:"Representation,omitempty"` + XMLName xml.Name `xml:"AdaptationSet"` + ID *string `xml:"id,attr"` + SegmentAlignment *bool `xml:"segmentAlignment,attr"` + Lang *string `xml:"lang,attr"` + Group *string `xml:"group,attr"` + PAR *string `xml:"par,attr"` + MinBandwidth *string `xml:"minBandwidth,attr"` + MaxBandwidth *string `xml:"maxBandwidth,attr"` + MinWidth *string `xml:"minWidth,attr"` + MaxWidth *string `xml:"maxWidth,attr"` + MinHeight *string `xml:"minHeight,attr"` + MaxHeight *string `xml:"maxHeight,attr"` + ContentType *string `xml:"contentType,attr"` + ContentProtection []ContentProtectioner `xml:"ContentProtection,omitempty"` // Common attribute, can be deprecated here + Roles []*Role `xml:"Role,omitempty"` + SegmentBase *SegmentBase `xml:"SegmentBase,omitempty"` + SegmentList *SegmentList `xml:"SegmentList,omitempty"` + SegmentTemplate *SegmentTemplate `xml:"SegmentTemplate,omitempty"` // Live Profile Only + Representations []*Representation `xml:"Representation,omitempty"` AccessibilityElems []*Accessibility `xml:"Accessibility,omitempty"` }{} diff --git a/mpd/mpd_test.go b/mpd/mpd_test.go index 6358c0f..7fbae4b 100644 --- a/mpd/mpd_test.go +++ b/mpd/mpd_test.go @@ -6,6 +6,7 @@ import ( . "github.com/zencoder/go-dash/helpers/ptrs" "github.com/zencoder/go-dash/helpers/require" + "github.com/zencoder/go-dash/helpers/testfixtures" ) const ( @@ -41,6 +42,7 @@ const ( VALID_SUBTITLE_ID string = "subtitle_en" VALID_SUBTITLE_URL string = "http://example.com/content/sintel/subtitles/subtitles_en.vtt" VALID_ROLE string = "main" + VALID_LOCATION string = "https://example.com/location.mpd" ) func TestNewMPDLive(t *testing.T) { @@ -484,3 +486,30 @@ func TestAddNewAccessibilityElement(t *testing.T) { require.EqualStringPtr(t, Strptr((string)(ACCESSIBILITY_ELEMENT_SCHEME_DESCRIPTIVE_AUDIO)), elem.SchemeIdUri) require.EqualStringPtr(t, Strptr("1"), elem.Value) } + +func TestLocationWriteToString(t *testing.T) { + m := &MPD{ + XMLNs: Strptr("urn:mpeg:dash:schema:mpd:2011"), + Profiles: Strptr((string)(DASH_PROFILE_LIVE)), + Type: Strptr("dynamic"), + AvailabilityStartTime: Strptr(VALID_AVAILABILITY_START_TIME), + MinimumUpdatePeriod: Strptr(VALID_MINIMUM_UPDATE_PERIOD), + PublishTime: Strptr(VALID_AVAILABILITY_START_TIME), + Location: VALID_LOCATION, + } + + got, err := m.WriteToString() + require.NoError(t, err) + + testfixtures.CompareFixture(t, "fixtures/location.mpd", got) +} + +func TestReadLocation(t *testing.T) { + m, err := ReadFromFile("fixtures/location.mpd") + require.NoError(t, err) + + got, err := m.WriteToString() + require.NoError(t, err) + + testfixtures.CompareFixture(t, "fixtures/location.mpd", got) +}