From 4b8af7b18c86aa37d5f1bc55cd4bdfb64a10f62e Mon Sep 17 00:00:00 2001 From: liuyanhit <849578660@qq.com> Date: Wed, 23 Feb 2022 17:49:58 +0800 Subject: [PATCH] add attrPublishTime, as publishTime must be present for @type='dynamic' (#84) Co-authored-by: liuyanhit --- mpd/mpd.go | 2 ++ mpd/mpd_attr.go | 13 +++++++++++++ mpd/mpd_test.go | 5 ++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mpd/mpd.go b/mpd/mpd.go index ffac1cd..57e718b 100644 --- a/mpd/mpd.go +++ b/mpd/mpd.go @@ -441,6 +441,8 @@ func NewDynamicMPD(profile DashProfile, availabilityStartTime, minBufferTime str mpd.MinimumUpdatePeriod = attr.GetStrptr() case *attrMediaPresentationDuration: mpd.MediaPresentationDuration = attr.GetStrptr() + case *attrPublishTime: + mpd.PublishTime = attr.GetStrptr() } } diff --git a/mpd/mpd_attr.go b/mpd/mpd_attr.go index 152ce9c..c64514a 100644 --- a/mpd/mpd_attr.go +++ b/mpd/mpd_attr.go @@ -42,3 +42,16 @@ func (attr *attrMediaPresentationDuration) GetStrptr() *string { func AttrMediaPresentationDuration(value string) AttrMPD { return &attrMediaPresentationDuration{strptr: &value} } + +type attrPublishTime struct { + strptr *string +} + +func (attr *attrPublishTime) GetStrptr() *string { + return attr.strptr +} + +// AttrPublishTime returns AttrMPD object for NewMPD +func AttrPublishTime(value string) AttrMPD { + return &attrPublishTime{strptr: &value} +} diff --git a/mpd/mpd_test.go b/mpd/mpd_test.go index 073b37c..5240108 100644 --- a/mpd/mpd_test.go +++ b/mpd/mpd_test.go @@ -15,6 +15,7 @@ const ( VALID_MEDIA_PRESENTATION_DURATION string = "PT6M16S" VALID_MIN_BUFFER_TIME string = "PT1.97S" VALID_AVAILABILITY_START_TIME string = "1970-01-01T00:00:00Z" + VALID_PUBLISH_TIME string = "2020-03-12T10:39:45Z" VALID_MINIMUM_UPDATE_PERIOD string = "PT5S" VALID_SCAN_TYPE string = "progressive" VALID_SEGMENT_ALIGNMENT bool = true @@ -73,7 +74,8 @@ func TestNewMPDLive(t *testing.T) { func TestNewDynamicMPDLive(t *testing.T) { m := NewDynamicMPD(DASH_PROFILE_LIVE, VALID_AVAILABILITY_START_TIME, VALID_MIN_BUFFER_TIME, AttrMediaPresentationDuration(VALID_MEDIA_PRESENTATION_DURATION), - AttrMinimumUpdatePeriod(VALID_MINIMUM_UPDATE_PERIOD)) + AttrMinimumUpdatePeriod(VALID_MINIMUM_UPDATE_PERIOD), + AttrPublishTime(VALID_PUBLISH_TIME)) require.NotNil(t, m) expectedMPD := &MPD{ XMLNs: Strptr("urn:mpeg:dash:schema:mpd:2011"), @@ -86,6 +88,7 @@ func TestNewDynamicMPDLive(t *testing.T) { period: &Period{}, Periods: []*Period{{}}, UTCTiming: &DescriptorType{}, + PublishTime: Strptr(VALID_PUBLISH_TIME), } expectedString, err := expectedMPD.WriteToString()