mirror of https://bitbucket.org/ausocean/av.git
changed btb to toByte
This commit is contained in:
parent
cad9078c17
commit
928580eb0b
|
@ -136,25 +136,25 @@ type MpegTsPacket struct {
|
||||||
// channel is empty or we've the packet reaches capacity
|
// channel is empty or we've the packet reaches capacity
|
||||||
func (p *MpegTsPacket) FillPayload(channel chan byte) {
|
func (p *MpegTsPacket) FillPayload(channel chan byte) {
|
||||||
p.Payload = make([]byte, 0, mpegtsPayloadSize)
|
p.Payload = make([]byte, 0, mpegtsPayloadSize)
|
||||||
currentPktLength := 6 + int(btb(p.PCRF))*6 + int(btb(p.OPCRF))*6 +
|
currentPktLength := 6 + int(toByte(p.PCRF))*6 + int(toByte(p.OPCRF))*6 +
|
||||||
int(btb(p.SPF))*1 + int(btb(p.TPDF))*1 + len(p.TPD)
|
int(toByte(p.SPF))*1 + int(toByte(p.TPDF))*1 + len(p.TPD)
|
||||||
// While we're within the mpegts packet size and we still have data we can use
|
// While we're within the mpegts packet size and we still have data we can use
|
||||||
for (currentPktLength+len(p.Payload)) < mpegTsSize && len(channel) > 0 {
|
for (currentPktLength+len(p.Payload)) < mpegTsSize && len(channel) > 0 {
|
||||||
p.Payload = append(p.Payload, <-channel)
|
p.Payload = append(p.Payload, <-channel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// btb is a simple wrapper function for tools.BoolToByte which takes a bool
|
// toByte is a simple wrapper function for tools.BoolToByte which takes a bool
|
||||||
// and returns an equivalent byte
|
// and returns an equivalent byte
|
||||||
func btb(b bool) byte {
|
func toByte(b bool) byte {
|
||||||
return tools.BoolToByte(b)
|
return tools.BoolToByte(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToByteSlice interprets the fields of the ts packet instance and outputs a
|
// ToByteSlice interprets the fields of the ts packet instance and outputs a
|
||||||
// corresponding byte slice
|
// corresponding byte slice
|
||||||
func (p *MpegTsPacket) ToByteSlice() (output []byte) {
|
func (p *MpegTsPacket) ToByteSlice() (output []byte) {
|
||||||
stuffingLength := 182 - len(p.Payload) - len(p.TPD) - int(btb(p.PCRF))*6 -
|
stuffingLength := 182 - len(p.Payload) - len(p.TPD) - int(toByte(p.PCRF))*6 -
|
||||||
int(btb(p.OPCRF))*6 - int(btb(p.SPF))
|
int(toByte(p.OPCRF))*6 - int(toByte(p.SPF))
|
||||||
var stuffing []byte
|
var stuffing []byte
|
||||||
if stuffingLength > 0 {
|
if stuffingLength > 0 {
|
||||||
stuffing = make([]byte, stuffingLength)
|
stuffing = make([]byte, stuffingLength)
|
||||||
|
@ -162,20 +162,20 @@ func (p *MpegTsPacket) ToByteSlice() (output []byte) {
|
||||||
for i := range stuffing {
|
for i := range stuffing {
|
||||||
stuffing[i] = 0xFF
|
stuffing[i] = 0xFF
|
||||||
}
|
}
|
||||||
afl := 1 + int(btb(p.PCRF))*6 + int(btb(p.OPCRF))*6 + int(btb(p.SPF)) + int(btb(p.TPDF)) + len(p.TPD) + len(stuffing)
|
afl := 1 + int(toByte(p.PCRF))*6 + int(toByte(p.OPCRF))*6 + int(toByte(p.SPF)) + int(toByte(p.TPDF)) + len(p.TPD) + len(stuffing)
|
||||||
output = make([]byte, 0, mpegTsSize)
|
output = make([]byte, 0, mpegTsSize)
|
||||||
output = append(output, []byte{
|
output = append(output, []byte{
|
||||||
0x47,
|
0x47,
|
||||||
(btb(p.TEI)<<7 | btb(p.PUSI)<<6 | btb(p.Priority)<<5 | byte((p.PID&0xFF00)>>8)),
|
(toByte(p.TEI)<<7 | toByte(p.PUSI)<<6 | toByte(p.Priority)<<5 | byte((p.PID&0xFF00)>>8)),
|
||||||
byte(p.PID & 0x00FF),
|
byte(p.PID & 0x00FF),
|
||||||
(p.TSC<<6 | p.AFC<<4 | p.CC),
|
(p.TSC<<6 | p.AFC<<4 | p.CC),
|
||||||
}...)
|
}...)
|
||||||
|
|
||||||
if p.AFC == 3 || p.AFC == 2 {
|
if p.AFC == 3 || p.AFC == 2 {
|
||||||
output = append(output, []byte{
|
output = append(output, []byte{
|
||||||
byte(afl), (btb(p.DI)<<7 | btb(p.RAI)<<6 | btb(p.ESPI)<<5 |
|
byte(afl), (toByte(p.DI)<<7 | toByte(p.RAI)<<6 | toByte(p.ESPI)<<5 |
|
||||||
btb(p.PCRF)<<4 | btb(p.OPCRF)<<3 | btb(p.SPF)<<2 |
|
toByte(p.PCRF)<<4 | toByte(p.OPCRF)<<3 | toByte(p.SPF)<<2 |
|
||||||
btb(p.TPDF)<<1 | btb(p.AFEF)),
|
toByte(p.TPDF)<<1 | toByte(p.AFEF)),
|
||||||
}...)
|
}...)
|
||||||
for i := 40; p.PCRF && i >= 0; i -= 8 {
|
for i := 40; p.PCRF && i >= 0; i -= 8 {
|
||||||
output = append(output, byte((p.PCR<<15)>>uint(i)))
|
output = append(output, byte((p.PCR<<15)>>uint(i)))
|
||||||
|
|
Loading…
Reference in New Issue