Skip to content

Commit 2f93b14

Browse files
authored
Multiperiod dash check for existing period to add new period (#86)
1 parent a79aec8 commit 2f93b14

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

examples/ondemand.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func exampleOndemand() {
3737

3838
thumbnailsAS, _ := m.AddNewAdaptationSetThumbnails(mpd.DASH_MIME_TYPE_IMAGE_JPEG)
3939
_, _ = thumbnailsAS.SetNewSegmentTemplateThumbnails(1801800, "$RepresentationID$/$Number$.jpg", 0, 30000)
40-
_, _ = thumbnailsAS.AddNewRepresentationThumbnails("thumbnails", "5x4","http://dashif.org/guidelines/thumbnail_tile", 50000, 1600, 720)
40+
_, _ = thumbnailsAS.AddNewRepresentationThumbnails("thumbnails", "5x4", "http://dashif.org/guidelines/thumbnail_tile", 50000, 1600, 720)
4141

4242
mpdStr, _ := m.WriteToString()
4343
fmt.Println(mpdStr)

mpd/mpd.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,9 @@ func NewDynamicMPD(profile DashProfile, availabilityStartTime, minBufferTime str
449449

450450
// AddNewPeriod creates a new Period and make it the currently active one.
451451
func (m *MPD) AddNewPeriod() *Period {
452+
if m.period != nil && m.period.ID == "" && m.period.AdaptationSets == nil {
453+
return m.GetCurrentPeriod()
454+
}
452455
period := &Period{}
453456
m.Periods = append(m.Periods, period)
454457
m.period = period
@@ -490,7 +493,7 @@ func (m *MPD) AddNewAdaptationSetThumbnailsWithID(id, mimeType string) (*Adaptat
490493

491494
func (period *Period) AddNewAdaptationSetThumbnailsWithID(id, mimeType string) (*AdaptationSet, error) {
492495
as := &AdaptationSet{
493-
ID: Strptr(id),
496+
ID: Strptr(id),
494497
ContentType: Strptr(DASH_CONTENT_TYPE_IMAGE),
495498
CommonAttributesAndElements: CommonAttributesAndElements{
496499
MimeType: Strptr(mimeType),
@@ -963,7 +966,7 @@ func (as *AdaptationSet) SetNewSegmentTemplateThumbnails(duration int64, media s
963966
// width - width of the video (i.e. 1280).
964967
// height - height of the video (i.e 720).
965968
// uri -
966-
func (as *AdaptationSet) AddNewRepresentationThumbnails(id, val, uri string,bandwidth, width, height int64) (*Representation, error) {
969+
func (as *AdaptationSet) AddNewRepresentationThumbnails(id, val, uri string, bandwidth, width, height int64) (*Representation, error) {
967970
r := &Representation{
968971
Bandwidth: Int64ptr(bandwidth),
969972
ID: Strptr(id),

mpd/mpd_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package mpd
33
import (
44
"encoding/base64"
55
"path/filepath"
6+
"strconv"
67
"testing"
78

89
. "github.com/zencoder/go-dash/helpers/ptrs"
@@ -95,6 +96,34 @@ func TestNewDynamicMPDLive(t *testing.T) {
9596
require.EqualString(t, expectedString, actualString)
9697
}
9798

99+
func TestNewMPDMultiPeriod(t *testing.T) {
100+
m := NewMPD(DASH_PROFILE_LIVE, VALID_MEDIA_PRESENTATION_DURATION, VALID_MIN_BUFFER_TIME,
101+
AttrAvailabilityStartTime(VALID_AVAILABILITY_START_TIME))
102+
require.NotNil(t, m)
103+
for i := 0; i < 2; i++ {
104+
period := m.AddNewPeriod()
105+
period.ID = strconv.Itoa(i)
106+
}
107+
108+
expectedMPD := &MPD{
109+
XMLNs: Strptr("urn:mpeg:dash:schema:mpd:2011"),
110+
Profiles: Strptr((string)(DASH_PROFILE_LIVE)),
111+
Type: Strptr("static"),
112+
MediaPresentationDuration: Strptr(VALID_MEDIA_PRESENTATION_DURATION),
113+
MinBufferTime: Strptr(VALID_MIN_BUFFER_TIME),
114+
AvailabilityStartTime: Strptr(VALID_AVAILABILITY_START_TIME),
115+
period: nil,
116+
Periods: []*Period{{ID: "0"}, {ID: "1"}},
117+
}
118+
119+
expectedString, err := expectedMPD.WriteToString()
120+
require.NoError(t, err)
121+
actualString, err := m.WriteToString()
122+
require.NoError(t, err)
123+
124+
require.EqualString(t, expectedString, actualString)
125+
}
126+
98127
func TestContentProtection_ImplementsInterface(t *testing.T) {
99128
cp := (*ContentProtectioner)(nil)
100129
require.Implements(t, cp, &ContentProtection{})

0 commit comments

Comments
 (0)