mirror of
https://github.com/aler9/gortsplib
synced 2025-10-18 21:14:38 +08:00
add resetFragments() to all fragment-based decoders (#637)
This commit is contained in:
@@ -42,12 +42,16 @@ func (d *Decoder) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Decoder) resetFragments() {
|
||||
d.fragments = d.fragments[:0]
|
||||
d.fragmentsSize = 0
|
||||
}
|
||||
|
||||
// Decode decodes frames from a RTP packet.
|
||||
// It returns the frames and the PTS of the first frame.
|
||||
func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
|
||||
if len(pkt.Payload) < 2 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.fragmentsSize = 0
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("payload is too short")
|
||||
}
|
||||
|
||||
@@ -55,8 +59,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
|
||||
ft := pkt.Payload[0] & 0b11
|
||||
|
||||
if mbz != 0 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.fragmentsSize = 0
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("invalid MBZ: %v", mbz)
|
||||
}
|
||||
|
||||
@@ -64,8 +67,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
|
||||
|
||||
switch ft {
|
||||
case 0:
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.fragmentsSize = 0
|
||||
d.resetFragments()
|
||||
d.firstPacketReceived = true
|
||||
|
||||
buf := pkt.Payload[2:]
|
||||
@@ -91,8 +93,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
|
||||
}
|
||||
|
||||
case 1, 2:
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.fragmentsSize = 0
|
||||
d.resetFragments()
|
||||
|
||||
var syncInfo ac3.SyncInfo
|
||||
err := syncInfo.Unmarshal(pkt.Payload[2:])
|
||||
@@ -122,8 +123,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
|
||||
d.fragmentsExpected -= le
|
||||
|
||||
if d.fragmentsExpected < 0 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.fragmentsSize = 0
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("fragment is too big")
|
||||
}
|
||||
|
||||
@@ -134,8 +134,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([][]byte, error) {
|
||||
}
|
||||
|
||||
frames = [][]byte{joinFragments(d.fragments, d.fragmentsSize)}
|
||||
d.fragments = d.fragments[:0]
|
||||
d.fragmentsSize = 0
|
||||
d.resetFragments()
|
||||
}
|
||||
|
||||
return frames, nil
|
||||
|
Reference in New Issue
Block a user