Skip to content

Commit 79d8be2

Browse files
authored
Merge pull request #67 from zencoder/suggestedPresentationDelay
add MPD@suggestedPresentationDelay and AdaptationSet@maxHeight, AdaptationSet@minHeight
2 parents 2358130 + 8101305 commit 79d8be2

File tree

2 files changed

+81
-49
lines changed

2 files changed

+81
-49
lines changed

mpd/mpd.go

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,20 @@ var (
6868
)
6969

7070
type MPD struct {
71-
XMLNs *string `xml:"xmlns,attr"`
72-
Profiles *string `xml:"profiles,attr"`
73-
Type *string `xml:"type,attr"`
74-
MediaPresentationDuration *string `xml:"mediaPresentationDuration,attr"`
75-
MinBufferTime *string `xml:"minBufferTime,attr"`
76-
AvailabilityStartTime *string `xml:"availabilityStartTime,attr,omitempty"`
77-
MinimumUpdatePeriod *string `xml:"minimumUpdatePeriod,attr"`
78-
PublishTime *string `xml:"publishTime,attr"`
79-
TimeShiftBufferDepth *string `xml:"timeShiftBufferDepth,attr"`
80-
BaseURL string `xml:"BaseURL,omitempty"`
81-
period *Period
82-
Periods []*Period `xml:"Period,omitempty"`
83-
UTCTiming *DescriptorType `xml:"UTCTiming,omitempty"`
71+
XMLNs *string `xml:"xmlns,attr"`
72+
Profiles *string `xml:"profiles,attr"`
73+
Type *string `xml:"type,attr"`
74+
MediaPresentationDuration *string `xml:"mediaPresentationDuration,attr"`
75+
MinBufferTime *string `xml:"minBufferTime,attr"`
76+
AvailabilityStartTime *string `xml:"availabilityStartTime,attr,omitempty"`
77+
MinimumUpdatePeriod *string `xml:"minimumUpdatePeriod,attr"`
78+
PublishTime *string `xml:"publishTime,attr"`
79+
TimeShiftBufferDepth *string `xml:"timeShiftBufferDepth,attr"`
80+
SuggestedPresentationDelay *Duration `xml:"suggestedPresentationDelay,attr,omitempty"`
81+
BaseURL string `xml:"BaseURL,omitempty"`
82+
period *Period
83+
Periods []*Period `xml:"Period,omitempty"`
84+
UTCTiming *DescriptorType `xml:"UTCTiming,omitempty"`
8485
}
8586

8687
type Period struct {
@@ -125,47 +126,51 @@ type CommonAttributesAndElements struct {
125126

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

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

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

mpd/mpd_read_write_test.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/zencoder/go-dash/helpers/ptrs"
89
"github.com/zencoder/go-dash/helpers/require"
910
"github.com/zencoder/go-dash/helpers/testfixtures"
1011
)
@@ -89,6 +90,26 @@ func TestNewDynamicMPDLiveWithPeriodStartWriteToString(t *testing.T) {
8990
require.EqualString(t, expectedXML, xmlStr)
9091
}
9192

93+
func TestNewDynamicMPDLiveWithSuggestedPresentationDelayToString(t *testing.T) {
94+
m := NewDynamicMPD(DASH_PROFILE_LIVE, VALID_AVAILABILITY_START_TIME, VALID_MIN_BUFFER_TIME,
95+
AttrMediaPresentationDuration(VALID_MEDIA_PRESENTATION_DURATION),
96+
AttrMinimumUpdatePeriod(VALID_MINIMUM_UPDATE_PERIOD))
97+
98+
// Set first period start time to PT0S
99+
spd := Duration(time.Duration(18) * time.Second)
100+
m.SuggestedPresentationDelay = &spd
101+
102+
xmlStr, err := m.WriteToString()
103+
require.NoError(t, err)
104+
expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
105+
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="dynamic" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S" availabilityStartTime="1970-01-01T00:00:00Z" minimumUpdatePeriod="PT5S" suggestedPresentationDelay="PT18S">
106+
<Period></Period>
107+
<UTCTiming></UTCTiming>
108+
</MPD>
109+
`
110+
require.EqualString(t, expectedXML, xmlStr)
111+
}
112+
92113
func TestNewMPDOnDemandWriteToString(t *testing.T) {
93114
m := NewMPD(DASH_PROFILE_ONDEMAND, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
94115

@@ -122,14 +143,20 @@ func TestAddNewAdaptationSetAudioWriteToString(t *testing.T) {
122143
func TestAddNewAdaptationSetVideoWriteToString(t *testing.T) {
123144
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME)
124145

125-
_, _ = m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
146+
as, err := m.AddNewAdaptationSetVideoWithID("7357", DASH_MIME_TYPE_VIDEO_MP4, VALID_SCAN_TYPE, VALID_SEGMENT_ALIGNMENT, VALID_START_WITH_SAP)
147+
require.NoError(t, err)
148+
149+
as.MinWidth = ptrs.Strptr("720")
150+
as.MaxWidth = ptrs.Strptr("720")
151+
as.MinHeight = ptrs.Strptr("480")
152+
as.MaxHeight = ptrs.Strptr("480")
126153

127154
xmlStr, err := m.WriteToString()
128155
require.NoError(t, err)
129156
expectedXML := `<?xml version="1.0" encoding="UTF-8"?>
130157
<MPD xmlns="urn:mpeg:dash:schema:mpd:2011" profiles="urn:mpeg:dash:profile:isoff-live:2011" type="static" mediaPresentationDuration="PT6M16S" minBufferTime="PT1.97S">
131158
<Period>
132-
<AdaptationSet mimeType="video/mp4" startWithSAP="1" scanType="progressive" id="7357" segmentAlignment="true"></AdaptationSet>
159+
<AdaptationSet mimeType="video/mp4" startWithSAP="1" scanType="progressive" id="7357" segmentAlignment="true" minWidth="720" maxWidth="720" minHeight="480" maxHeight="480"></AdaptationSet>
133160
</Period>
134161
</MPD>
135162
`

0 commit comments

Comments
 (0)