-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrepresentation.go
161 lines (155 loc) · 4.33 KB
/
representation.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
package dash
import (
"iter"
"net/url"
"strconv"
)
func (r *Representation) Representation() iter.Seq[Representation] {
return func(yield func(Representation) bool) {
for _, p := range r.adaptation_set.period.mpd.Period {
for _, adapt := range p.AdaptationSet {
for _, represent := range adapt.Representation {
if represent.Id == r.Id {
if adapt.period == nil {
p.set(r.adaptation_set.period.mpd)
adapt.set(&p)
}
represent.set(&adapt)
if !yield(represent) {
return
}
}
}
}
}
}
}
type Representation struct {
Bandwidth int `xml:"bandwidth,attr"`
BaseUrl *Url `xml:"BaseURL"`
Codecs *string `xml:"codecs,attr"`
ContentProtection []ContentProtection
Height *int64 `xml:"height,attr"`
Id string `xml:"id,attr"`
MimeType *string `xml:"mimeType,attr"`
SegmentBase *struct {
Initialization struct {
Range Range `xml:"range,attr"`
}
IndexRange Range `xml:"indexRange,attr"`
}
SegmentList *struct {
Initialization struct {
SourceUrl ListUrl `xml:"sourceURL,attr"`
}
SegmentUrl []struct {
Media ListUrl `xml:"media,attr"`
} `xml:"SegmentURL"`
}
SegmentTemplate *SegmentTemplate
Width *int64 `xml:"width,attr"`
adaptation_set *AdaptationSet
}
func (r *Representation) Segment() iter.Seq[int] {
template := r.SegmentTemplate
var address int
if template.Media.time() {
address = template.PresentationTimeOffset
} else {
address = *template.StartNumber
}
return func(yield func(int) bool) {
if template.SegmentTimeline != nil {
for _, segment := range template.SegmentTimeline.S {
for range 1 + segment.R {
if !yield(address) {
return
}
if template.Media.time() {
address += segment.D
} else {
address++
}
}
}
} else {
segment_count := r.adaptation_set.period.segment_count(template)
for range int64(segment_count) {
if !yield(address) {
return
}
address++
}
}
}
}
func (r *Representation) String() string {
var b []byte
if r.Width != nil {
b = append(b, "width = "...)
b = strconv.AppendInt(b, *r.Width, 10)
}
if r.Height != nil {
if b != nil {
b = append(b, '\n')
}
b = append(b, "height = "...)
b = strconv.AppendInt(b, *r.Height, 10)
}
if b != nil {
b = append(b, '\n')
}
b = append(b, "bandwidth = "...)
b = strconv.AppendInt(b, int64(r.Bandwidth), 10)
if r.Codecs != nil {
b = append(b, "\ncodecs = "...)
b = append(b, *r.Codecs...)
}
b = append(b, "\nmimeType = "...)
b = append(b, *r.MimeType...)
if role := r.adaptation_set.Role; role != nil {
b = append(b, "\nrole = "...)
b = append(b, role.Value...)
}
if lang := r.adaptation_set.Lang; lang != "" {
b = append(b, "\nlang = "...)
b = append(b, lang...)
}
if id := r.adaptation_set.period.Id; id != "" {
b = append(b, "\nperiod = "...)
b = append(b, id...)
}
b = append(b, "\nid = "...)
b = append(b, r.Id...)
return string(b)
}
func (r *Representation) set(adapt *AdaptationSet) {
r.adaptation_set = adapt
if v := r.adaptation_set.period.BaseUrl; v != nil {
if r.BaseUrl == nil {
r.BaseUrl = &Url{&url.URL{}}
}
r.BaseUrl.Url = v.Url.ResolveReference(r.BaseUrl.Url)
}
if r.Codecs == nil {
r.Codecs = r.adaptation_set.Codecs
}
if len(r.ContentProtection) == 0 {
r.ContentProtection = r.adaptation_set.ContentProtection
}
if r.Height == nil {
r.Height = r.adaptation_set.Height
}
if r.MimeType == nil {
r.MimeType = r.adaptation_set.MimeType
}
if r.SegmentTemplate == nil {
r.SegmentTemplate = r.adaptation_set.SegmentTemplate
}
if r.SegmentTemplate != nil {
r.SegmentTemplate.set()
}
if r.Width == nil {
r.Width = r.adaptation_set.Width
}
}