-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.go
105 lines (83 loc) · 1.82 KB
/
channel.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
package psip
import (
"github.com/mh-orange/ts"
"github.com/mh-orange/ts/psi"
)
const (
MODULATION_8VSB = 0x04
)
type Channel interface {
ShortName() string
MajorNumber() uint16
MinorNumber() uint16
ModulationMode() uint8
CarrierFrequency() uint32
TSID() uint16
Program() uint16
ETMLocation() uint8
AccessControlled() bool
Hidden() bool
HideGuide() bool
ServiceType() uint8
SourceID() uint16
DescriptorsLength() int
Descriptors() []psi.Descriptor
Length() int
CRC() []byte
}
type channel []byte
const (
c_minimum_length = 32
c_major_offset = 14
)
func (c channel) ShortName() string {
return ts.Utf16ToString(c, 0, 14)
}
func (c channel) MajorNumber() uint16 {
return ts.Uimsbf16(c[14:16], 16) >> 2 & 0x3ff
}
func (c channel) MinorNumber() uint16 {
return ts.Uimsbf16(c[15:17], 10)
}
func (c channel) ModulationMode() uint8 {
return ts.Uimsbf8(c[17])
}
func (c channel) CarrierFrequency() uint32 {
return ts.Uimsbf32(c[18:22], 32)
}
func (c channel) TSID() uint16 {
return ts.Uimsbf16(c[22:24], 16)
}
func (c channel) Program() uint16 {
return ts.Uimsbf16(c[24:26], 16)
}
func (c channel) ETMLocation() uint8 {
return ts.Uimsbf8(c[26]) >> 6
}
func (c channel) AccessControlled() bool {
return ts.Bool(c[26], 5)
}
func (c channel) Hidden() bool {
return ts.Bool(c[26], 4)
}
func (c channel) HideGuide() bool {
return ts.Bool(c[26], 1)
}
func (c channel) ServiceType() uint8 {
return ts.Uimsbf8(c[27])
}
func (c channel) SourceID() uint16 {
return ts.Uimsbf16(c[28:30], 16)
}
func (c channel) DescriptorsLength() int {
return int(c[30]&0x03)<<8 | int(c[31])
}
func (c channel) Descriptors() []psi.Descriptor {
return psi.Descriptors(c[32 : 32+c.DescriptorsLength()])
}
func (c channel) CRC() []byte {
return c[len(c)-4 : len(c)]
}
func (c channel) Length() int {
return 36 + c.DescriptorsLength()
}