Add support multiple PPS in a row for H264 payloader
This commit is contained in:
+18
-29
@@ -4,8 +4,8 @@ import "encoding/binary"
|
|||||||
|
|
||||||
// Payloader payloads H264 packets
|
// Payloader payloads H264 packets
|
||||||
type Payloader struct {
|
type Payloader struct {
|
||||||
IsAVC bool
|
IsAVC bool
|
||||||
spsNalu, ppsNalu []byte
|
stapANalu []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -92,36 +92,25 @@ func (p *Payloader) Payload(mtu uint16, payload []byte) [][]byte {
|
|||||||
naluType := nalu[0] & naluTypeBitmask
|
naluType := nalu[0] & naluTypeBitmask
|
||||||
naluRefIdc := nalu[0] & naluRefIdcBitmask
|
naluRefIdc := nalu[0] & naluRefIdcBitmask
|
||||||
|
|
||||||
switch {
|
switch naluType {
|
||||||
case naluType == audNALUType || naluType == fillerNALUType:
|
case audNALUType, fillerNALUType:
|
||||||
return
|
return
|
||||||
case naluType == spsNALUType:
|
case spsNALUType, ppsNALUType:
|
||||||
p.spsNalu = nalu
|
if p.stapANalu == nil {
|
||||||
return
|
p.stapANalu = []byte{outputStapAHeader}
|
||||||
case naluType == ppsNALUType:
|
|
||||||
p.ppsNalu = nalu
|
|
||||||
return
|
|
||||||
case p.spsNalu != nil && p.ppsNalu != nil:
|
|
||||||
// Pack current NALU with SPS and PPS as STAP-A
|
|
||||||
spsLen := make([]byte, 2)
|
|
||||||
binary.BigEndian.PutUint16(spsLen, uint16(len(p.spsNalu)))
|
|
||||||
|
|
||||||
ppsLen := make([]byte, 2)
|
|
||||||
binary.BigEndian.PutUint16(ppsLen, uint16(len(p.ppsNalu)))
|
|
||||||
|
|
||||||
stapANalu := []byte{outputStapAHeader}
|
|
||||||
stapANalu = append(stapANalu, spsLen...)
|
|
||||||
stapANalu = append(stapANalu, p.spsNalu...)
|
|
||||||
stapANalu = append(stapANalu, ppsLen...)
|
|
||||||
stapANalu = append(stapANalu, p.ppsNalu...)
|
|
||||||
if len(stapANalu) <= int(mtu) {
|
|
||||||
out := make([]byte, len(stapANalu))
|
|
||||||
copy(out, stapANalu)
|
|
||||||
payloads = append(payloads, out)
|
|
||||||
}
|
}
|
||||||
|
p.stapANalu = append(p.stapANalu, byte(len(nalu)>>8), byte(len(nalu)))
|
||||||
|
p.stapANalu = append(p.stapANalu, nalu...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
p.spsNalu = nil
|
if p.stapANalu != nil {
|
||||||
p.ppsNalu = nil
|
// Pack current NALU with SPS and PPS as STAP-A
|
||||||
|
// Supports multiple PPS in a row
|
||||||
|
if len(p.stapANalu) <= int(mtu) {
|
||||||
|
payloads = append(payloads, p.stapANalu)
|
||||||
|
}
|
||||||
|
p.stapANalu = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Single NALU
|
// Single NALU
|
||||||
|
|||||||
Reference in New Issue
Block a user