Skip to content

Commit

Permalink
Merge pull request #191 from Dash-Industry-Forum/fix-multiperiod-publ…
Browse files Browse the repository at this point in the history
…ishTime

fix: publishTime for multiperiod MPD
  • Loading branch information
tobbee authored May 25, 2024
2 parents 5db86ec + b74b425 commit f4b5a33
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- correct low-latency MPD update time for SegmentTimeline
- fix patch response for multiperiod segment-timeline
- fix publishTime for multiperiod SegmentTemplate with Number

## [1.3.0] - 2024-04-23

Expand Down
18 changes: 18 additions & 0 deletions cmd/livesim2/app/livempd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"math"
"net/url"
"strings"
"time"

"github.com/Dash-Industry-Forum/livesim2/pkg/scte35"
m "github.com/Eyevinn/dash-mpd/mpd"
Expand Down Expand Up @@ -241,6 +242,11 @@ func LiveMPD(a *asset, mpdName string, cfg *ResponseConfig, nowMS int) (*m.MPD,
return nil, fmt.Errorf("splitPeriods: %w", err)
}

mpd.PublishTime, err = lastPeriodStartTime(mpd)
if err != nil {
return nil, fmt.Errorf("lastPeriodStartTime: %w", err)
}

if afterStop {
mpdDurS := *cfg.StopTimeS - cfg.StartTimeS
makeMPDStatic(mpd, mpdDurS)
Expand All @@ -251,6 +257,18 @@ func LiveMPD(a *asset, mpdName string, cfg *ResponseConfig, nowMS int) (*m.MPD,
return mpd, nil
}

// lastSegInfo returns the absolute startTime of the last Period.
func lastPeriodStartTime(mpd *m.MPD) (m.DateTime, error) {
lastPeriod := mpd.Periods[len(mpd.Periods)-1]
lastRelStartS := time.Duration(*lastPeriod.Start).Seconds()
ast, err := mpd.AvailabilityStartTime.ConvertToSeconds()
if err != nil {
return "", err
}
lastAbsStart := ast + lastRelStartS
return m.ConvertToDateTime(lastAbsStart), nil
}

func addPatchLocation(mpd *m.MPD, cfg *ResponseConfig) {
// Still live. Add patch location if specified
if cfg.PatchTTL > 0 {
Expand Down
13 changes: 13 additions & 0 deletions cmd/livesim2/app/livempd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ func TestPublishTime(t *testing.T) {
segTimelineTime bool
availabilityStartTime int
availabilityTimeOffset float64
periodsPerHour int
nowMS int
wantedPublishTime string
}{
Expand Down Expand Up @@ -473,6 +474,15 @@ func TestPublishTime(t *testing.T) {
nowMS: 0,
wantedPublishTime: "1970-01-01T00:00:00Z",
},
{
desc: "SegmentTemplate with $Number$, at period start",
asset: "testpic_2s",
mpdName: "Manifest.mpd",
segTimelineTime: false,
periodsPerHour: 60,
nowMS: 120_000,
wantedPublishTime: "1970-01-01T00:02:00Z",
},
{
desc: "LL SegmentTimeline, early not yet available MPD",
asset: "testpic_2s",
Expand Down Expand Up @@ -509,6 +519,9 @@ func TestPublishTime(t *testing.T) {
cfg.ChunkDurS = Ptr(2 - tc.availabilityTimeOffset)
cfg.AvailabilityTimeCompleteFlag = false
}
if tc.periodsPerHour > 0 {
cfg.PeriodsPerHour = Ptr(tc.periodsPerHour)
}
err := verifyAndFillConfig(cfg, tc.nowMS)
require.NoError(t, err)
liveMPD, err := LiveMPD(asset, tc.mpdName, cfg, tc.nowMS)
Expand Down

0 comments on commit f4b5a33

Please sign in to comment.