Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mpd/fixtures/location.mpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<Location>https://example.com/location.mpd</Location>
</MPD>
77 changes: 39 additions & 38 deletions mpd/mpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -127,51 +128,51 @@ 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"`
}

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

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"`
}{}

Expand Down
29 changes: 29 additions & 0 deletions mpd/mpd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}