@@ -5,64 +5,59 @@ import (
5
5
"github.com/Comcast/gots/packet"
6
6
)
7
7
8
- var emptyByteSlice []byte
9
-
10
8
// Length returns the length of the adaptation field in bytes
11
- func Length (packet packet.Packet ) uint8 {
12
- return uint8 (packet [4 ])
9
+ func Length (pkt * packet.Packet ) uint8 {
10
+ return uint8 (pkt [4 ])
13
11
}
14
12
15
13
// IsDiscontinuous returns the discontinuity indicator for this adaptation field
16
- func IsDiscontinuous (packet packet.Packet ) bool {
17
- return ( packet [5 ] & 0x80 ) != 0
14
+ func IsDiscontinuous (pkt * packet.Packet ) bool {
15
+ return pkt [5 ]& 0x80 != 0
18
16
}
19
17
20
18
// IsRandomAccess returns the random access indicator for this adaptation field
21
- func IsRandomAccess (packet packet.Packet ) bool {
22
- return ( packet [5 ] & 0x40 ) != 0
19
+ func IsRandomAccess (pkt * packet.Packet ) bool {
20
+ return pkt [5 ]& 0x40 != 0
23
21
}
24
22
25
23
// IsESHigherPriority returns true if this elementary stream is
26
24
// high priority. Corresponds to the elementary stream
27
25
// priority indicator.
28
- func IsESHigherPriority (packet packet.Packet ) bool {
29
- return ( packet [5 ] & 0x20 ) != 0
26
+ func IsESHigherPriority (pkt * packet.Packet ) bool {
27
+ return pkt [5 ]& 0x20 != 0
30
28
}
31
29
32
30
// HasPCR returns true when the PCR flag is set
33
- func HasPCR (packet packet.Packet ) bool {
34
- return ( packet [5 ] & 0x10 ) != 0
31
+ func HasPCR (pkt * packet.Packet ) bool {
32
+ return pkt [5 ]& 0x10 != 0
35
33
}
36
34
37
35
// HasOPCR returns true when the OPCR flag is set
38
- func HasOPCR (packet packet.Packet ) bool {
39
- return ( packet [5 ] & 0x08 ) != 0
36
+ func HasOPCR (pkt * packet.Packet ) bool {
37
+ return pkt [5 ]& 0x08 != 0
40
38
}
41
39
42
40
// HasSplicingPoint returns true when the splicing countdown field is present
43
- func HasSplicingPoint (packet packet.Packet ) bool {
44
- return ( packet [5 ] & 0x04 ) != 0
41
+ func HasSplicingPoint (pkt * packet.Packet ) bool {
42
+ return pkt [5 ]& 0x04 != 0
45
43
}
46
44
47
45
// HasTransportPrivateData returns true when the private data field is present
48
- func HasTransportPrivateData (packet packet.Packet ) bool {
49
- return ( packet [5 ] & 0x02 ) != 0
46
+ func HasTransportPrivateData (pkt * packet.Packet ) bool {
47
+ return pkt [5 ]& 0x02 != 0
50
48
}
51
49
52
50
// HasAdaptationFieldExtension returns true if this adaptation field contains an extension field
53
- func HasAdaptationFieldExtension (packet packet.Packet ) bool {
54
- return ( packet [5 ] & 0x01 ) != 0
51
+ func HasAdaptationFieldExtension (pkt * packet.Packet ) bool {
52
+ return pkt [5 ]& 0x01 != 0
55
53
}
56
54
57
55
// EncoderBoundaryPoint returns the byte array located in the optional TransportPrivateData of the (also optional)
58
56
// AdaptationField of the Packet. If either of these optional fields are missing an empty byte array is returned with an error
59
- func EncoderBoundaryPoint (pkt packet.Packet ) ([]byte , error ) {
60
- if badLen (pkt ) {
61
- return emptyByteSlice , gots .ErrInvalidPacketLength
62
- }
57
+ func EncoderBoundaryPoint (pkt * packet.Packet ) ([]byte , error ) {
63
58
hasAdapt , err := packet .ContainsAdaptationField (pkt )
64
59
if err != nil {
65
- return emptyByteSlice , nil
60
+ return nil , nil
66
61
}
67
62
if hasAdapt && Length (pkt ) > 0 && HasTransportPrivateData (pkt ) {
68
63
ebp , err := TransportPrivateData (pkt )
@@ -78,81 +73,64 @@ func EncoderBoundaryPoint(pkt packet.Packet) ([]byte, error) {
78
73
// First 33 bits are PCR base.
79
74
// Next 6 bits are reserved.
80
75
// Final 9 bits are PCR extension.
81
- func PCR (packet packet.Packet ) ([]byte , error ) {
82
- if ! HasPCR (packet ) {
83
- return emptyByteSlice , gots .ErrNoPCR
76
+ func PCR (pkt * packet.Packet ) ([]byte , error ) {
77
+ if ! HasPCR (pkt ) {
78
+ return nil , gots .ErrNoPCR
84
79
}
85
80
offset := 6
86
- return packet [offset : offset + 6 ], nil
81
+ return pkt [offset : offset + 6 ], nil
87
82
}
88
83
89
84
// OPCR is the Original Program Clock Reference.
90
85
// First 33 bits are original PCR base.
91
86
// Next 6 bits are reserved.
92
87
// Final 9 bits are original PCR extension.
93
- func OPCR (packet packet.Packet ) ([]byte , error ) {
94
- if badLen (packet ) {
95
- return emptyByteSlice , gots .ErrInvalidPacketLength
96
- }
97
- if ! HasOPCR (packet ) {
98
- return emptyByteSlice , gots .ErrNoOPCR
88
+ func OPCR (pkt * packet.Packet ) ([]byte , error ) {
89
+ if ! HasOPCR (pkt ) {
90
+ return nil , gots .ErrNoOPCR
99
91
}
100
92
offset := 6
101
- if HasPCR (packet ) {
93
+ if HasPCR (pkt ) {
102
94
offset += 6
103
95
}
104
- return packet [offset : offset + 6 ], nil
96
+ return pkt [offset : offset + 6 ], nil
105
97
}
106
98
107
99
// SpliceCountdown returns a count of how many packets after this one until
108
100
// a splice point occurs or an error if none exist. This function calls
109
101
// HasSplicingPoint to check for the existence of a splice countdown.
110
- func SpliceCountdown (packet packet.Packet ) (uint8 , error ) {
111
- if badLen (packet ) {
112
- return 0 , gots .ErrInvalidPacketLength
113
- }
114
- if ! HasSplicingPoint (packet ) {
102
+ func SpliceCountdown (pkt * packet.Packet ) (uint8 , error ) {
103
+ if ! HasSplicingPoint (pkt ) {
115
104
return 0 , gots .ErrNoSplicePoint
116
105
}
117
106
offset := 6
118
- if HasPCR (packet ) {
107
+ if HasPCR (pkt ) {
119
108
offset += 6
120
109
}
121
- if HasOPCR (packet ) {
110
+ if HasOPCR (pkt ) {
122
111
offset += 6
123
112
}
124
- return packet [offset ], nil
113
+ return pkt [offset ], nil
125
114
}
126
115
127
116
// TransportPrivateData returns the private data from this adaptation field
128
117
// or an empty array and an error if there is none. This function calls
129
118
// HasTransportPrivateData to check for the existence of private data.
130
- func TransportPrivateData (packet packet.Packet ) ([]byte , error ) {
131
- if badLen (packet ) {
132
- return emptyByteSlice , gots .ErrInvalidPacketLength
133
- }
134
- if ! HasTransportPrivateData (packet ) {
135
- return emptyByteSlice , gots .ErrNoPrivateTransportData
119
+ func TransportPrivateData (pkt * packet.Packet ) ([]byte , error ) {
120
+ if ! HasTransportPrivateData (pkt ) {
121
+ return nil , gots .ErrNoPrivateTransportData
136
122
}
137
123
offset := 6
138
- if HasPCR (packet ) {
124
+ if HasPCR (pkt ) {
139
125
offset += 6
140
126
}
141
- if HasOPCR (packet ) {
127
+ if HasOPCR (pkt ) {
142
128
offset += 6
143
129
}
144
- if HasSplicingPoint (packet ) {
130
+ if HasSplicingPoint (pkt ) {
145
131
offset ++
146
132
}
147
- dataLength := uint8 (packet [offset ])
133
+ dataLength := uint8 (pkt [offset ])
148
134
offset ++
149
- return packet [uint8 (offset ) : uint8 (offset )+ dataLength ], nil
150
- }
151
-
152
- // badLen returns true if the packet has invalid length
153
- func badLen (pkt packet.Packet ) bool {
154
- if len (pkt ) != packet .PacketSize {
155
- return true
156
- }
157
- return false
135
+ return pkt [uint8 (offset ) : uint8 (offset )+ dataLength ], nil
158
136
}
0 commit comments