mirror of
https://github.com/aler9/gortsplib
synced 2025-10-21 14:19:36 +08:00
add resetFragments() to all fragment-based decoders (#637)
This commit is contained in:
@@ -35,8 +35,8 @@ type Decoder struct {
|
||||
MaxDONDiff int
|
||||
|
||||
firstPacketReceived bool
|
||||
fragmentsSize int
|
||||
fragments [][]byte
|
||||
fragmentsSize int
|
||||
|
||||
// for Decode()
|
||||
frameBuffer [][]byte
|
||||
@@ -52,9 +52,14 @@ func (d *Decoder) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Decoder) resetFragments() {
|
||||
d.fragments = d.fragments[:0]
|
||||
d.fragmentsSize = 0
|
||||
}
|
||||
|
||||
func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
||||
if len(pkt.Payload) < 2 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("payload is too short")
|
||||
}
|
||||
|
||||
@@ -63,7 +68,7 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
||||
|
||||
switch typ {
|
||||
case h265.NALUType_AggregationUnit:
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.resetFragments()
|
||||
|
||||
payload := pkt.Payload[2:]
|
||||
|
||||
@@ -95,7 +100,7 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
||||
|
||||
case h265.NALUType_FragmentationUnit:
|
||||
if len(pkt.Payload) < 3 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("payload is too short")
|
||||
}
|
||||
|
||||
@@ -103,7 +108,7 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
||||
end := (pkt.Payload[2] >> 6) & 0x01
|
||||
|
||||
if start == 1 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.resetFragments()
|
||||
|
||||
if end != 0 {
|
||||
return nil, fmt.Errorf("invalid fragmentation unit (can't contain both a start and end bit)")
|
||||
@@ -118,7 +123,7 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
||||
return nil, ErrMorePacketsNeeded
|
||||
}
|
||||
|
||||
if len(d.fragments) == 0 {
|
||||
if d.fragmentsSize == 0 {
|
||||
if !d.firstPacketReceived {
|
||||
return nil, ErrNonStartingPacketAndNoPrevious
|
||||
}
|
||||
@@ -128,7 +133,7 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
||||
|
||||
d.fragmentsSize += len(pkt.Payload[3:])
|
||||
if d.fragmentsSize > h265.MaxAccessUnitSize {
|
||||
d.fragments = d.fragments[:0]
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("NALU size (%d) is too big, maximum is %d", d.fragmentsSize, h265.MaxAccessUnitSize)
|
||||
}
|
||||
|
||||
@@ -139,16 +144,14 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {
|
||||
}
|
||||
|
||||
nalus = [][]byte{joinFragments(d.fragments, d.fragmentsSize)}
|
||||
d.fragments = d.fragments[:0]
|
||||
d.resetFragments()
|
||||
|
||||
case h265.NALUType_PACI:
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.firstPacketReceived = true
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("PACI packets are not supported (yet)")
|
||||
|
||||
default:
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.firstPacketReceived = true
|
||||
d.resetFragments()
|
||||
nalus = [][]byte{pkt.Payload}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user