-
Notifications
You must be signed in to change notification settings - Fork 50
/
program_map.go
45 lines (37 loc) · 1.05 KB
/
program_map.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
package astits
// programMap represents a program ids map
type programMap struct {
// We use map[uint32] instead map[uint16] as go runtime provide optimized hash functions for (u)int32/64 keys
p map[uint32]uint16 // map[ProgramMapID]ProgramNumber
}
// newProgramMap creates a new program ids map
func newProgramMap() *programMap {
return &programMap{
p: make(map[uint32]uint16),
}
}
// existsUnlocked checks whether the program with this pid exists
func (m programMap) existsUnlocked(pid uint16) (ok bool) {
_, ok = m.p[uint32(pid)]
return
}
// setUnlocked sets a new program id
func (m programMap) setUnlocked(pid, number uint16) {
m.p[uint32(pid)] = number
}
func (m programMap) unsetUnlocked(pid uint16) {
delete(m.p, uint32(pid))
}
func (m programMap) toPATDataUnlocked() *PATData {
d := &PATData{
Programs: make([]*PATProgram, 0, len(m.p)),
TransportStreamID: uint16(PSITableIDPAT),
}
for pid, pnr := range m.p {
d.Programs = append(d.Programs, &PATProgram{
ProgramMapID: uint16(pid),
ProgramNumber: pnr,
})
}
return d
}