Skip to content

Commit

Permalink
refactor: make less structures public
Browse files Browse the repository at this point in the history
  • Loading branch information
tobbee committed Sep 21, 2023
1 parent 602936c commit ba6f5d7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"golangci",
"gzipped",
"healthz",
"htmpl",
"httpiso",
"IDURI",
"imsc",
Expand Down Expand Up @@ -100,11 +101,14 @@
"timewise",
"timewvtt",
"Tkhd",
"tlnr",
"Traf",
"Trak",
"Trun",
"tsbd",
"TTML",
"ttmpl",
"urlgen",
"urlprefix",
"UTCMS",
"vodroot",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ be able to generate streams with a huge number of
parameter variations. Currently, not all parameters of [livesim1][1] are implemented,
but there are also new parameters like the generated subtitles mentioned above.

The [URL wiki page][urlparams] lists what is available.
The [URL wiki page][urlparams] lists what is available and the served page `/urlgen`
makes it easy to construct URLs to play the content with specific parameters set.

Beside `livesim2` there is a tool called `dashfetcher` in this repo.
That tool can be used to download the MPD and all segments of a DASH VoD asset.
Expand Down
20 changes: 10 additions & 10 deletions cmd/livesim2/app/handler_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import (
"strings"
)

type AssetsInfo struct {
type assetsInfo struct {
Host string
PlayURL string
Assets []*AssetInfo
Assets []*assetInfo
}

type AssetInfo struct {
type assetInfo struct {
Path string
LoopDurMS int
MPDs []MPDInfo
MPDs []mpdInfo
}

type MPDInfo struct {
type mpdInfo struct {
Path string
Desc string
Dur string
Expand All @@ -40,15 +40,15 @@ func (s *Server) assetsHandlerFunc(w http.ResponseWriter, r *http.Request) {
})
fh := fullHost(s.Cfg.Host, r)
playURL := schemePrefix(fh) + s.Cfg.PlayURL
aInfo := AssetsInfo{
aInfo := assetsInfo{
Host: fh,
PlayURL: playURL,
Assets: make([]*AssetInfo, 0, len(assets)),
Assets: make([]*assetInfo, 0, len(assets)),
}
for _, asset := range assets {
mpds := make([]MPDInfo, 0, len(asset.MPDs))
mpds := make([]mpdInfo, 0, len(asset.MPDs))
for _, mpd := range asset.MPDs {
mpds = append(mpds, MPDInfo{
mpds = append(mpds, mpdInfo{
Path: mpd.Name,
Desc: mpd.Title,
Dur: mpd.Dur,
Expand All @@ -57,7 +57,7 @@ func (s *Server) assetsHandlerFunc(w http.ResponseWriter, r *http.Request) {
sort.Slice(mpds, func(i, j int) bool {
return mpds[i].Path < mpds[j].Path
})
assetInfo := AssetInfo{
assetInfo := assetInfo{
Path: asset.AssetPath,
LoopDurMS: asset.LoopDurMS,
MPDs: mpds,
Expand Down
111 changes: 59 additions & 52 deletions cmd/livesim2/app/handler_urlgen.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright 2023, DASH-Industry Forum. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.md file.

package app

import (
Expand All @@ -19,15 +23,15 @@ func (s *Server) urlGenHandlerFunc(w http.ResponseWriter, r *http.Request) {
})
fh := fullHost(s.Cfg.Host, r)
playURL := schemePrefix(fh) + s.Cfg.PlayURL
aInfo := AssetsInfo{
aInfo := assetsInfo{
Host: fh,
PlayURL: playURL,
Assets: make([]*AssetInfo, 0, len(assets)),
Assets: make([]*assetInfo, 0, len(assets)),
}
for _, asset := range assets {
mpds := make([]MPDInfo, 0, len(asset.MPDs))
mpds := make([]mpdInfo, 0, len(asset.MPDs))
for _, mpd := range asset.MPDs {
mpds = append(mpds, MPDInfo{
mpds = append(mpds, mpdInfo{
Path: mpd.Name,
Desc: mpd.Title,
Dur: mpd.Dur,
Expand All @@ -36,7 +40,7 @@ func (s *Server) urlGenHandlerFunc(w http.ResponseWriter, r *http.Request) {
sort.Slice(mpds, func(i, j int) bool {
return mpds[i].Path < mpds[j].Path
})
assetInfo := AssetInfo{
assetInfo := assetInfo{
Path: asset.AssetPath,
LoopDurMS: asset.LoopDurMS,
MPDs: mpds,
Expand Down Expand Up @@ -77,10 +81,10 @@ func (s *Server) urlGenHandlerFunc(w http.ResponseWriter, r *http.Request) {
}
}

func mpdsFromAssetInfo(a *AssetInfo) []MPDwithSelect {
mpds := make([]MPDwithSelect, len(a.MPDs))
func mpdsFromAssetInfo(a *assetInfo) []mpdWithSelect {
mpds := make([]mpdWithSelect, len(a.MPDs))
for i, mpd := range a.MPDs {
mpds[i] = MPDwithSelect{Name: mpd.Path}
mpds[i] = mpdWithSelect{Name: mpd.Path}
}
return mpds
}
Expand All @@ -94,9 +98,9 @@ type urlGenData struct {
PlayURL string
URL string
Host string
Assets []AssetWithSelect
MPDs []MPDwithSelect
Stl STL
Assets []assetWithSelect
MPDs []mpdWithSelect
Stl segmentTimelineType
Tsbd int // time-shift buffer depth in seconds
MinimumUpdatePeriodS string
SuggestedPresentationDelayS string
Expand All @@ -121,8 +125,8 @@ type urlGenData struct {
var initData urlGenData

func init() {
initData.Assets = []AssetWithSelect{
{AssetPath: "Choose an asset...", MPDs: []MPDwithSelect{{Name: "Choose an asset first"}}},
initData.Assets = []assetWithSelect{
{AssetPath: "Choose an asset...", MPDs: []mpdWithSelect{{Name: "Choose an asset first"}}},
}
initData.Stl = Number
initData.Tsbd = defaultTimeShiftBufferDepthS
Expand All @@ -131,62 +135,65 @@ func init() {
initData.TimeSubsReg = defaultTimeSubsReg
}

type AssetWithSelect struct {
type assetWithSelect struct {
AssetPath string
Selected bool
MPDs []MPDwithSelect
MPDs []mpdWithSelect
}

type MPDwithSelect struct {
type mpdWithSelect struct {
Name string
Selected bool
}

type STL string
type segmentTimelineType string

const (
Number STL = "nr"
TimelineTime STL = "tlt"
TimelineNumber STL = "tlnr"
Number segmentTimelineType = "nr"
TimelineTime segmentTimelineType = "tlt"
TimelineNumber segmentTimelineType = "tlnr"
)

func createInitData(r *http.Request, aInfo AssetsInfo) (data urlGenData, err error) {
func createInitData(r *http.Request, aInfo assetsInfo) (data urlGenData, err error) {
data = initData
data.Assets = make([]AssetWithSelect, 0, len(aInfo.Assets)+1)
data.Assets = make([]assetWithSelect, 0, len(aInfo.Assets)+1)
data.MPDs = nil
data.Assets = append(data.Assets, AssetWithSelect{AssetPath: "Choose an asset...", Selected: true, MPDs: []MPDwithSelect{{Name: "Choose an asset first"}}})
data.Assets = append(data.Assets, assetWithSelect{
AssetPath: "Choose an asset...", Selected: true,
MPDs: []mpdWithSelect{{Name: "Choose an asset first"}},
})
for i := range aInfo.Assets {
data.Assets = append(data.Assets, AssetWithSelect{AssetPath: aInfo.Assets[i].Path})
data.Assets = append(data.Assets, assetWithSelect{AssetPath: aInfo.Assets[i].Path})
}
data.Host = aInfo.Host
return data, nil
}

func createURL(r *http.Request, aInfo AssetsInfo) (data urlGenData, err error) {
qVals := r.URL.Query()
func createURL(r *http.Request, aInfo assetsInfo) (data urlGenData, err error) {
q := r.URL.Query()
var sb strings.Builder // Used to build URL
asset := qVals.Get("asset")
mpd := qVals.Get("mpd")
asset := q.Get("asset")
mpd := q.Get("mpd")
// fmt.Println("create", asset, mpd)
data = initData
data.Assets = make([]AssetWithSelect, 0, len(aInfo.Assets))
data.Assets = make([]assetWithSelect, 0, len(aInfo.Assets))
data.MPDs = nil
for i := range aInfo.Assets {
a := AssetWithSelect{AssetPath: aInfo.Assets[i].Path}
a := assetWithSelect{AssetPath: aInfo.Assets[i].Path}
if a.AssetPath == asset {
a.Selected = true
data.MPDs = make([]MPDwithSelect, 0, len(a.MPDs)+1)
data.MPDs = make([]mpdWithSelect, 0, len(a.MPDs)+1)
for j := range aInfo.Assets[i].MPDs {
name := aInfo.Assets[i].MPDs[j].Path
selected := name == mpd
data.MPDs = append(data.MPDs, MPDwithSelect{Name: name, Selected: selected})
data.MPDs = append(data.MPDs, mpdWithSelect{Name: name, Selected: selected})
}
}
data.Assets = append(data.Assets, a)
}
sb.WriteString(aInfo.Host)
sb.WriteString("/livesim2/")
stl := STL(qVals.Get("stl"))
stl := segmentTimelineType(q.Get("stl"))
switch stl {
case Number:
data.Stl = Number
Expand All @@ -199,7 +206,7 @@ func createURL(r *http.Request, aInfo AssetsInfo) (data urlGenData, err error) {
default:
fmt.Printf("Bad stl: %s\n", stl)
}
tsbd := qVals.Get("tsbd")
tsbd := q.Get("tsbd")
if tsbd != "" {
t, err := strconv.Atoi(tsbd)
if err != nil {
Expand All @@ -210,47 +217,47 @@ func createURL(r *http.Request, aInfo AssetsInfo) (data urlGenData, err error) {
sb.WriteString(fmt.Sprintf("tsbd_%d/", t))
}
}
ato := qVals.Get("ato")
ato := q.Get("ato")
if ato != "" {
data.Ato = ato
sb.WriteString(fmt.Sprintf("ato_%s/", ato))
}
mup := qVals.Get("mup")
mup := q.Get("mup")
if mup != "" {
data.MinimumUpdatePeriodS = mup
sb.WriteString(fmt.Sprintf("mup_%s/", mup))
}
spd := qVals.Get("spd")
spd := q.Get("spd")
if spd != "" {
data.SuggestedPresentationDelayS = spd
sb.WriteString(fmt.Sprintf("spd_%s/", spd))
}
startNR := qVals.Get("snr")
startNR := q.Get("snr")
if startNR != "" {
data.StartNR = startNR
sb.WriteString(fmt.Sprintf("snr_%s/", startNR))
}
utc := qVals.Get("utc")
utc := q.Get("utc")
if utc != "" {
data.UTCTiming = utc
sb.WriteString(fmt.Sprintf("utc_%s/", utc))
}
periods := qVals.Get("periods")
periods := q.Get("periods")
if periods != "" {
data.Periods = periods
sb.WriteString(fmt.Sprintf("periods_%s/", periods))
}
continuous := qVals.Get("continuous")
continuous := q.Get("continuous")
if continuous != "" {
data.Continuous = true
sb.WriteString("continuous_1/")
}
chunkDur := qVals.Get("chunkdur")
chunkDur := q.Get("chunkdur")
if chunkDur != "" {
data.ChunkDur = chunkDur
sb.WriteString(fmt.Sprintf("chunkdur_%s/", chunkDur))
}
if llTarget := qVals.Get("ltgt"); llTarget != "" {
if llTarget := q.Get("ltgt"); llTarget != "" {
lt, err := strconv.Atoi(llTarget)
if err != nil {
panic("bad ltgt")
Expand All @@ -260,47 +267,47 @@ func createURL(r *http.Request, aInfo AssetsInfo) (data urlGenData, err error) {
sb.WriteString(fmt.Sprintf("ltgt_%d/", lt))
}
}
start := qVals.Get("start")
start := q.Get("start")
if start != "" {
data.Start = start
sb.WriteString(fmt.Sprintf("start_%s/", start))
}
stop := qVals.Get("stop")
stop := q.Get("stop")
if stop != "" {
data.Stop = stop
sb.WriteString(fmt.Sprintf("stop_%s/", stop))
}
startRel := qVals.Get("startrel")
startRel := q.Get("startrel")
if startRel != "" {
data.StartRel = startRel
sb.WriteString(fmt.Sprintf("startrel_%s/", startRel))
}
stopRel := qVals.Get("stoprel")
stopRel := q.Get("stoprel")
if stopRel != "" {
data.StopRel = stopRel
sb.WriteString(fmt.Sprintf("stoprel_%s/", stopRel))
}
timeSubsStpp := qVals.Get("timesubsstpp")
timeSubsStpp := q.Get("timesubsstpp")
if timeSubsStpp != "" {
data.TimeSubsStpp = timeSubsStpp
sb.WriteString(fmt.Sprintf("timesubsstpp_%s/", timeSubsStpp))
}
timeSubsWvtt := qVals.Get("timesubswvtt")
timeSubsWvtt := q.Get("timesubswvtt")
if timeSubsWvtt != "" {
data.TimeSubsWvtt = timeSubsWvtt
sb.WriteString(fmt.Sprintf("timesubswvtt_%s/", timeSubsWvtt))
}
timeSubsDur := qVals.Get("timesubsdur")
timeSubsDur := q.Get("timesubsdur")
if timeSubsDur != "" && timeSubsDur != defaultTimeSubsDur {
data.TimeSubsDur = timeSubsDur
sb.WriteString(fmt.Sprintf("timesubsdur_%s/", timeSubsDur))
}
timeSubsReg := qVals.Get("timesubsreg")
timeSubsReg := q.Get("timesubsreg")
if timeSubsReg != "" && timeSubsReg != defaultTimeSubsReg {
data.TimeSubsReg = timeSubsReg
sb.WriteString(fmt.Sprintf("timesubsreg_%s/", timeSubsReg))
}
scte35 := qVals.Get("scte35")
scte35 := q.Get("scte35")
if scte35 != "" {
data.Scte35Var = scte35
sb.WriteString(fmt.Sprintf("scte35_%s/", scte35))
Expand Down
2 changes: 1 addition & 1 deletion cmd/livesim2/app/templates/welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ <h4>Useful local URLs</h4>
<p>The following URLs should work at {{.Host}}. Some of them provides streaming URLs or even URLs that start
a DASH player with the corresponding asset URL. Others provide information about the server.</p>
<ul>
<li><a href="{{.Host}}/assets">/assets</a> provides a list of all loaded assets and their MPDs</li>
<li><a href="{{.Host}}/urlgen">/urlgen</a> is a form to generate URLs for live streaming from this host</li>
<li><a href="{{.Host}}/assets">/assets</a> provides a list of all loaded assets and their MPDs</li>
<li><a href="https://github.com/Dash-Industry-Forum/livesim2/wiki/URL-Parameters">livesim2-wiki</a> compares url parameters between livesim2 and livesim1</li>
<li><a href="{{.Host}}/vod">/vod</a> provides a list of all VoD assets and their MPDs</li>
<li><a href="{{.Host}}/healthz">/healthz</a> to check if server is running</li>
Expand Down
2 changes: 1 addition & 1 deletion internal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var (
commitDate string = "1692891745" // commitDate in Epoch seconds (can be filled/updated in during build)
)

// GetVersion - get version, commitHash, commitDate, expirationDate depending on what is inserted
// GetVersion - get version, commitHash and commitDate depending on what is inserted
func GetVersion() string {
seconds, _ := strconv.Atoi(commitDate)
msg := commitVersion
Expand Down

0 comments on commit ba6f5d7

Please sign in to comment.