mirror of
https://github.com/aler9/gortsplib
synced 2025-10-27 01:00:32 +08:00
add resetFragments() to all fragment-based decoders (#637)
This commit is contained in:
@@ -41,24 +41,29 @@ func (d *Decoder) Init() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Decoder) resetFragments() {
|
||||
d.fragments = d.fragments[:0]
|
||||
d.fragmentsSize = 0
|
||||
}
|
||||
|
||||
// Decode decodes a VP8 frame from a RTP packet.
|
||||
func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, error) {
|
||||
var vpkt codecs.VP8Packet
|
||||
_, err := vpkt.Unmarshal(pkt.Payload)
|
||||
if err != nil {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.resetFragments()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if vpkt.PID != 0 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("packets containing single partitions are not supported")
|
||||
}
|
||||
|
||||
var frame []byte
|
||||
|
||||
if vpkt.S == 1 {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.resetFragments()
|
||||
d.firstPacketReceived = true
|
||||
|
||||
if !pkt.Marker {
|
||||
@@ -69,7 +74,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, error) {
|
||||
|
||||
frame = vpkt.Payload
|
||||
} else {
|
||||
if len(d.fragments) == 0 {
|
||||
if d.fragmentsSize == 0 {
|
||||
if !d.firstPacketReceived {
|
||||
return nil, ErrNonStartingPacketAndNoPrevious
|
||||
}
|
||||
@@ -80,7 +85,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, error) {
|
||||
d.fragmentsSize += len(vpkt.Payload)
|
||||
|
||||
if d.fragmentsSize > vp8.MaxFrameSize {
|
||||
d.fragments = d.fragments[:0] // discard pending fragments
|
||||
d.resetFragments()
|
||||
return nil, fmt.Errorf("frame size (%d) is too big, maximum is %d", d.fragmentsSize, vp8.MaxFrameSize)
|
||||
}
|
||||
|
||||
@@ -91,7 +96,7 @@ func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, error) {
|
||||
}
|
||||
|
||||
frame = joinFragments(d.fragments, d.fragmentsSize)
|
||||
d.fragments = d.fragments[:0]
|
||||
d.resetFragments()
|
||||
}
|
||||
|
||||
return frame, nil
|
||||
|
||||
Reference in New Issue
Block a user