Files
gortsplib/pkg/formatdecenc/rtpsimpleaudio/decoder.go
Alessandro Ros f0540b4eee fix timestamp encode error after some hours (#206)
previous formula was: uint32(a + uint32(b))
this formula overflows two times, while it should overflow once.
new formula is: uint32(uint64(a) + uint64(b))
2023-03-14 17:55:06 +01:00

27 lines
532 B
Go

package rtpsimpleaudio
import (
"time"
"github.com/pion/rtp"
"github.com/aler9/gortsplib/v2/pkg/rtptime"
)
// Decoder is a RTP/simple audio decoder.
type Decoder struct {
SampleRate int
timeDecoder *rtptime.Decoder
}
// Init initializes the decoder.
func (d *Decoder) Init() {
d.timeDecoder = rtptime.NewDecoder(d.SampleRate)
}
// Decode decodes an audio frame from a RTP packet.
func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) {
return pkt.Payload, d.timeDecoder.Decode(pkt.Timestamp), nil
}